diff --git a/test/Graphics/Color.cpp b/test/Graphics/Color.cpp index b50684b79..f7b77a2cc 100644 --- a/test/Graphics/Color.cpp +++ b/test/Graphics/Color.cpp @@ -3,6 +3,7 @@ #include #include +#include TEST_CASE("[Graphics] sf::Color") { @@ -152,4 +153,27 @@ TEST_CASE("[Graphics] sf::Color") static_assert(sf::Color::Black == sf::Color(0, 0, 0, 255)); } + + SUBCASE("Reinterpret as std::uint8_t*") + { + static_assert(sizeof(sf::Color) == 4); + static_assert(alignof(sf::Color) == 1); + + const std::vector pixels = {{10, 11, 12, 13}, {14, 15, 16, 17}, {18, 19, 20, 21}}; + const std::uint8_t* begin = reinterpret_cast(pixels.data()); + CHECK(begin[0] == pixels[0].r); + CHECK(begin[1] == pixels[0].g); + CHECK(begin[2] == pixels[0].b); + CHECK(begin[3] == pixels[0].a); + + CHECK(begin[4] == pixels[1].r); + CHECK(begin[5] == pixels[1].g); + CHECK(begin[6] == pixels[1].b); + CHECK(begin[7] == pixels[1].a); + + CHECK(begin[8] == pixels[2].r); + CHECK(begin[9] == pixels[2].g); + CHECK(begin[10] == pixels[2].b); + CHECK(begin[11] == pixels[2].a); + } }