mirror of
https://github.com/SFML/CSFML.git
synced 2025-10-17 16:23:04 +08:00
Add tests for sfImage
This commit is contained in:
@@ -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
|
||||
|
56
test/Graphics/Image.test.cpp
Normal file
56
test/Graphics/Image.test.cpp
Normal 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);
|
||||
}
|
||||
}
|
BIN
test/Graphics/sfml-logo-big.bmp
Normal file
BIN
test/Graphics/sfml-logo-big.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 892 KiB |
BIN
test/Graphics/sfml-logo-big.gif
Normal file
BIN
test/Graphics/sfml-logo-big.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
BIN
test/Graphics/sfml-logo-big.jpg
Normal file
BIN
test/Graphics/sfml-logo-big.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
BIN
test/Graphics/sfml-logo-big.png
Normal file
BIN
test/Graphics/sfml-logo-big.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
BIN
test/Graphics/sfml-logo-big.psd
Normal file
BIN
test/Graphics/sfml-logo-big.psd
Normal file
Binary file not shown.
Reference in New Issue
Block a user