diff --git a/Test/CMakeLists.txt b/Test/CMakeLists.txt index 4fb73b2..9c84f6e 100644 --- a/Test/CMakeLists.txt +++ b/Test/CMakeLists.txt @@ -27,6 +27,7 @@ add_executable(Test FillChannel.cpp MirrorHorizontally.cpp MirrorVertically.cpp + SwapChannels.cpp ) # Move test images to build dir diff --git a/Test/SwapChannels.cpp b/Test/SwapChannels.cpp new file mode 100644 index 0000000..8c2c9c4 --- /dev/null +++ b/Test/SwapChannels.cpp @@ -0,0 +1,83 @@ +#include +#include +#include "Catch2.h" + +using namespace Leonetienne::BmpPP; +using namespace Eule; + +// Tests that swapping channels works +TEST_CASE(__FILE__"/SwappingChannelsWorks", "[SwapChannels]") +{ + SECTION("R2G") { + // Read an image + BMP bmp("base_fuwadera.bmp"); + + // Swap channels + bmp.SwapChannels(0, 1); + + // Read reference image + const BMP reference("base_fuwadera_channelswap_rg.bmp"); + + // Assert that they are equal + REQUIRE(bmp == reference); + } + + SECTION("R2B") { + // Read an image + BMP bmp("base_fuwadera.bmp"); + + // Swap channels + bmp.SwapChannels(0, 2); + + // Read reference image + const BMP reference("base_fuwadera_channelswap_rb.bmp"); + + // Assert that they are equal + REQUIRE(bmp == reference); + } + + SECTION("G2B") { + // Read an image + BMP bmp("base_fuwadera.bmp"); + + // Swap channels + bmp.SwapChannels(1, 2); + + // Read reference image + const BMP reference("base_fuwadera_channelswap_gb.bmp"); + + // Assert that they are equal + REQUIRE(bmp == reference); + } + + return; +} + +// Tests that swapping selecting a color channel that's out of range produces a runtime error +TEST_CASE(__FILE__"/RuntimeError_on_channel_out_of_range", "[SwapChannels]") +{ + SECTION("RGB_OUT_OF_RANGE") { + BMP bmp(Vector2i(800, 600), Colormode::RGB); + + REQUIRE_THROWS_AS( + bmp.SwapChannels(0, 3) + , std::runtime_error + ); + } + + SECTION("RGBA_OK") { + BMP bmp(Vector2i(800, 600), Colormode::RGBA); + + bmp.SwapChannels(0, 3); + } + + SECTION("RGBA_OUT_OF_RANGE") { + BMP bmp(Vector2i(800, 600), Colormode::RGBA); + + REQUIRE_THROWS_AS( + bmp.SwapChannels(0, 4) + , std::runtime_error + ); + } + return; +} diff --git a/Test/TestAssets/base_fuwadera.bmp b/Test/TestAssets/base_fuwadera.bmp new file mode 100644 index 0000000..26a34fd Binary files /dev/null and b/Test/TestAssets/base_fuwadera.bmp differ diff --git a/Test/TestAssets/base_fuwadera_channelswap_gb.bmp b/Test/TestAssets/base_fuwadera_channelswap_gb.bmp new file mode 100644 index 0000000..b0b3ecd Binary files /dev/null and b/Test/TestAssets/base_fuwadera_channelswap_gb.bmp differ diff --git a/Test/TestAssets/base_fuwadera_channelswap_rb.bmp b/Test/TestAssets/base_fuwadera_channelswap_rb.bmp new file mode 100644 index 0000000..30f5622 Binary files /dev/null and b/Test/TestAssets/base_fuwadera_channelswap_rb.bmp differ diff --git a/Test/TestAssets/base_fuwadera_channelswap_rg.bmp b/Test/TestAssets/base_fuwadera_channelswap_rg.bmp new file mode 100644 index 0000000..fe34194 Binary files /dev/null and b/Test/TestAssets/base_fuwadera_channelswap_rg.bmp differ diff --git a/Test/TestAssets/readme.md b/Test/TestAssets/readme.md index b078ae1..85eecd0 100644 --- a/Test/TestAssets/readme.md +++ b/Test/TestAssets/readme.md @@ -1 +1,6 @@ base*.bmp is always RGB, basea*.bmp is always RGBA. + +# LICENSE +Any images in here are licensed under CC0, Public Domain. +Some i have created myself, some i have found on the interwebz. +