Skip to content

Commit eba1735

Browse files
committed
Add tests for sfImage
1 parent 8f44a6f commit eba1735

File tree

7 files changed

+58
-1
lines changed

7 files changed

+58
-1
lines changed

test/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ add_executable(test-csfml-graphics
4848
Graphics/BlendMode.test.cpp
4949
Graphics/Color.test.cpp
5050
Graphics/CoordinateType.test.cpp
51+
Graphics/Image.test.cpp
5152
Graphics/PrimitiveType.test.cpp
5253
Graphics/Rect.test.cpp
5354
Graphics/RenderStates.test.cpp
@@ -59,7 +60,7 @@ add_executable(test-csfml-graphics
5960
)
6061
target_link_libraries(test-csfml-graphics PRIVATE csfml-graphics Catch2::Catch2WithMain SFML::Graphics)
6162
set_target_warnings(test-csfml-graphics)
62-
catch_discover_tests(test-csfml-graphics)
63+
catch_discover_tests(test-csfml-graphics WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
6364

6465
add_executable(test-csfml-network
6566
Network/Ftp.test.cpp

test/Graphics/Image.test.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <CSFML/Graphics/Image.h>
2+
3+
#include <catch2/catch_test_macros.hpp>
4+
#include <catch2/generators/catch_generators.hpp>
5+
6+
TEST_CASE("[Graphics] sfImage")
7+
{
8+
SECTION("sfImage_create")
9+
{
10+
const sfImage* image = sfImage_create({100, 100});
11+
REQUIRE(image);
12+
const auto size = sfImage_getSize(image);
13+
CHECK(size.x == 100);
14+
CHECK(size.y == 100);
15+
const auto pixel = sfImage_getPixel(image, {50, 50});
16+
CHECK(pixel.r == sfBlack.r);
17+
CHECK(pixel.g == sfBlack.g);
18+
CHECK(pixel.b == sfBlack.b);
19+
CHECK(pixel.a == sfBlack.a);
20+
CHECK(sfImage_getPixelsPtr(image));
21+
sfImage_destroy(image);
22+
}
23+
24+
SECTION("sfImage_createFromColor")
25+
{
26+
const sfImage* image = sfImage_createFromColor({100, 100}, sfMagenta);
27+
REQUIRE(image);
28+
const auto size = sfImage_getSize(image);
29+
CHECK(size.x == 100);
30+
CHECK(size.y == 100);
31+
const auto pixel = sfImage_getPixel(image, {50, 50});
32+
CHECK(pixel.r == sfMagenta.r);
33+
CHECK(pixel.g == sfMagenta.g);
34+
CHECK(pixel.b == sfMagenta.b);
35+
CHECK(pixel.a == sfMagenta.a);
36+
CHECK(sfImage_getPixelsPtr(image));
37+
sfImage_destroy(image);
38+
}
39+
40+
SECTION("sfImage_createFromFile")
41+
{
42+
const auto filename = std::string("Graphics/sfml-logo-big.") + GENERATE("bmp", "gif", "jpg", "png", "psd");
43+
INFO("Filename: " << filename);
44+
const sfImage* image = sfImage_createFromFile(filename.c_str());
45+
REQUIRE(image);
46+
const auto size = sfImage_getSize(image);
47+
CHECK(size.x == 1001);
48+
CHECK(size.y == 304);
49+
const auto pixel = sfImage_getPixel(image, {0, 0});
50+
CHECK(pixel.r == sfWhite.r);
51+
CHECK(pixel.g == sfWhite.g);
52+
CHECK(pixel.b == sfWhite.b);
53+
CHECK(sfImage_getPixelsPtr(image));
54+
sfImage_destroy(image);
55+
}
56+
}

test/Graphics/sfml-logo-big.bmp

892 KB
Binary file not shown.

test/Graphics/sfml-logo-big.gif

38.3 KB
Loading

test/Graphics/sfml-logo-big.jpg

20.8 KB
Loading

test/Graphics/sfml-logo-big.png

35.4 KB
Loading

test/Graphics/sfml-logo-big.psd

1.74 MB
Binary file not shown.

0 commit comments

Comments
 (0)