Added tests for SwapChannels

This commit is contained in:
Leonetienne 2022-03-06 14:12:48 +01:00
parent 6534569840
commit 8102148e60
7 changed files with 89 additions and 0 deletions

View File

@ -27,6 +27,7 @@ add_executable(Test
FillChannel.cpp
MirrorHorizontally.cpp
MirrorVertically.cpp
SwapChannels.cpp
)
# Move test images to build dir

83
Test/SwapChannels.cpp Normal file
View File

@ -0,0 +1,83 @@
#include <Bmp.h>
#include <stdexcept>
#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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

View File

@ -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.