Skip to content

Commit a53d14f

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

File tree

7 files changed

+60
-1
lines changed

7 files changed

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

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)