Add tests for sfImage

This commit is contained in:
Chris Thrasher
2025-06-08 22:08:46 -06:00
parent 8f44a6f424
commit eba1735c84
7 changed files with 58 additions and 1 deletions

View File

@@ -48,6 +48,7 @@ add_executable(test-csfml-graphics
Graphics/BlendMode.test.cpp
Graphics/Color.test.cpp
Graphics/CoordinateType.test.cpp
Graphics/Image.test.cpp
Graphics/PrimitiveType.test.cpp
Graphics/Rect.test.cpp
Graphics/RenderStates.test.cpp
@@ -59,7 +60,7 @@ add_executable(test-csfml-graphics
)
target_link_libraries(test-csfml-graphics PRIVATE csfml-graphics Catch2::Catch2WithMain SFML::Graphics)
set_target_warnings(test-csfml-graphics)
catch_discover_tests(test-csfml-graphics)
catch_discover_tests(test-csfml-graphics WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(test-csfml-network
Network/Ftp.test.cpp

View File

@@ -0,0 +1,56 @@
#include <CSFML/Graphics/Image.h>
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
TEST_CASE("[Graphics] sfImage")
{
SECTION("sfImage_create")
{
const sfImage* image = sfImage_create({100, 100});
REQUIRE(image);
const auto size = sfImage_getSize(image);
CHECK(size.x == 100);
CHECK(size.y == 100);
const auto pixel = sfImage_getPixel(image, {50, 50});
CHECK(pixel.r == sfBlack.r);
CHECK(pixel.g == sfBlack.g);
CHECK(pixel.b == sfBlack.b);
CHECK(pixel.a == sfBlack.a);
CHECK(sfImage_getPixelsPtr(image));
sfImage_destroy(image);
}
SECTION("sfImage_createFromColor")
{
const sfImage* image = sfImage_createFromColor({100, 100}, sfMagenta);
REQUIRE(image);
const auto size = sfImage_getSize(image);
CHECK(size.x == 100);
CHECK(size.y == 100);
const auto pixel = sfImage_getPixel(image, {50, 50});
CHECK(pixel.r == sfMagenta.r);
CHECK(pixel.g == sfMagenta.g);
CHECK(pixel.b == sfMagenta.b);
CHECK(pixel.a == sfMagenta.a);
CHECK(sfImage_getPixelsPtr(image));
sfImage_destroy(image);
}
SECTION("sfImage_createFromFile")
{
const auto filename = std::string("Graphics/sfml-logo-big.") + GENERATE("bmp", "gif", "jpg", "png", "psd");
INFO("Filename: " << filename);
const sfImage* image = sfImage_createFromFile(filename.c_str());
REQUIRE(image);
const auto size = sfImage_getSize(image);
CHECK(size.x == 1001);
CHECK(size.y == 304);
const auto pixel = sfImage_getPixel(image, {0, 0});
CHECK(pixel.r == sfWhite.r);
CHECK(pixel.g == sfWhite.g);
CHECK(pixel.b == sfWhite.b);
CHECK(sfImage_getPixelsPtr(image));
sfImage_destroy(image);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 892 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.