From 4967a4c28fe72179eb31eb6371f09db0c84bc887 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Mon, 26 Feb 2024 14:51:25 -0700 Subject: [PATCH] Add tests for `sf::Texture::loadFromImage` --- test/Graphics/Texture.test.cpp | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/Graphics/Texture.test.cpp b/test/Graphics/Texture.test.cpp index 043c6f3fc..3d92b8c5d 100644 --- a/test/Graphics/Texture.test.cpp +++ b/test/Graphics/Texture.test.cpp @@ -81,6 +81,44 @@ TEST_CASE("[Graphics] sf::Texture", runDisplayTests()) CHECK(texture.getNativeHandle() != 0); } + SECTION("loadFromImage()") + { + SECTION("Empty image") + { + const sf::Image image; + sf::Texture texture; + REQUIRE(!texture.loadFromImage(image)); + REQUIRE(!texture.loadFromImage(image, {{0, 0}, {1, 1}})); + } + + SECTION("Subarea of image") + { + sf::Image image; + image.create(sf::Vector2u(10, 15)); + sf::Texture texture; + + SECTION("Non-truncated area") + { + REQUIRE(texture.loadFromImage(image, {{0, 0}, {5, 10}})); + CHECK(texture.getSize() == sf::Vector2u(5, 10)); + } + + SECTION("Truncated area (negative position)") + { + REQUIRE(texture.loadFromImage(image, {{-5, -5}, {4, 8}})); + CHECK(texture.getSize() == sf::Vector2u(4, 8)); + } + + SECTION("Truncated area (width/height too big)") + { + REQUIRE(texture.loadFromImage(image, {{5, 5}, {12, 18}})); + CHECK(texture.getSize() == sf::Vector2u(5, 10)); + } + + CHECK(texture.getNativeHandle() != 0); + } + } + SECTION("Copy semantics") { constexpr std::uint8_t red[] = {0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF};