diff --git a/test/Graphics/Image.test.cpp b/test/Graphics/Image.test.cpp index 29c2cc95e..0a6c40b69 100644 --- a/test/Graphics/Image.test.cpp +++ b/test/Graphics/Image.test.cpp @@ -141,6 +141,55 @@ TEST_CASE("[Graphics] sf::Image") } } + SECTION("loadFromMemory()") + { + sf::Image image; + + SECTION("Invalid pointer") + { + CHECK(!image.loadFromMemory(nullptr, 1)); + } + + SECTION("Invalid size") + { + const std::byte byte{0xAB}; + CHECK(!image.loadFromMemory(&byte, 0)); + } + + SECTION("Failed load") + { + std::vector memory; + + SECTION("Empty") + { + memory.clear(); + } + + SECTION("Junk data") + { + memory = {1, 2, 3, 4}; + } + + CHECK(!image.loadFromMemory(memory.data(), memory.size())); + } + + SECTION("Successful load") + { + const auto memory = []() + { + sf::Image savedImage; + savedImage.create({24, 24}, sf::Color::Green); + return savedImage.saveToMemory("png").value(); + }(); + + CHECK(image.loadFromMemory(memory.data(), memory.size())); + CHECK(image.getSize() == sf::Vector2u(24, 24)); + CHECK(image.getPixelsPtr() != nullptr); + CHECK(image.getPixel({0, 0}) == sf::Color::Green); + CHECK(image.getPixel({23, 23}) == sf::Color::Green); + } + } + SECTION("saveToFile()") { sf::Image image;