|
| 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 | +} |
0 commit comments