Added tests for SwapChannels
This commit is contained in:
parent
6534569840
commit
8102148e60
@ -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
83
Test/SwapChannels.cpp
Normal 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;
|
||||
}
|
BIN
Test/TestAssets/base_fuwadera.bmp
Normal file
BIN
Test/TestAssets/base_fuwadera.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 108 KiB |
BIN
Test/TestAssets/base_fuwadera_channelswap_gb.bmp
Normal file
BIN
Test/TestAssets/base_fuwadera_channelswap_gb.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 108 KiB |
BIN
Test/TestAssets/base_fuwadera_channelswap_rb.bmp
Normal file
BIN
Test/TestAssets/base_fuwadera_channelswap_rb.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 108 KiB |
BIN
Test/TestAssets/base_fuwadera_channelswap_rg.bmp
Normal file
BIN
Test/TestAssets/base_fuwadera_channelswap_rg.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 108 KiB |
@ -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.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user