mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-26 21:16:13 +01:00
Add tests for sfImage
This commit is contained in:
1 parent
8f44a6f424
commit
eba1735c84
7 files changed
+58
-1
No files matched your search
+2
-1
@@ -48,6 +48,7 @@ add_executable(test-csfml-graphics
|
|||||||
Graphics/BlendMode.test.cpp
|
Graphics/BlendMode.test.cpp
|
||||||
Graphics/Color.test.cpp
|
Graphics/Color.test.cpp
|
||||||
Graphics/CoordinateType.test.cpp
|
Graphics/CoordinateType.test.cpp
|
||||||
|
Graphics/Image.test.cpp
|
||||||
Graphics/PrimitiveType.test.cpp
|
Graphics/PrimitiveType.test.cpp
|
||||||
Graphics/Rect.test.cpp
|
Graphics/Rect.test.cpp
|
||||||
Graphics/RenderStates.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)
|
target_link_libraries(test-csfml-graphics PRIVATE csfml-graphics Catch2::Catch2WithMain SFML::Graphics)
|
||||||
set_target_warnings(test-csfml-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
|
add_executable(test-csfml-network
|
||||||
Network/Ftp.test.cpp
|
Network/Ftp.test.cpp
|
||||||
|
|||||||
@@ -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.
Reference in new issue
Block a user