From 28543ecd970a2f067e17043e3e35d6478144f811 Mon Sep 17 00:00:00 2001 From: Thomas BERNARD Date: Wed, 13 Nov 2019 23:41:35 +0100 Subject: [PATCH] add tests for CPC_compare_colors() --- src/tests/testlist.h | 1 + src/tests/tests.c | 48 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/tests/testlist.h b/src/tests/testlist.h index 6f537b49..2e3bcc7f 100644 --- a/src/tests/testlist.h +++ b/src/tests/testlist.h @@ -2,4 +2,5 @@ * TEST(function_to_test) */ TEST(MOTO_MAP_pack) +TEST(CPC_compare_colors) diff --git a/src/tests/tests.c b/src/tests/tests.c index 008db0c9..e7c04306 100644 --- a/src/tests/tests.c +++ b/src/tests/tests.c @@ -26,11 +26,11 @@ ///@file tests.c /// Unit tests. /// -/// TODO : make a test binary and include the tests to the constant-integration #include #include #include "../struct.h" +#include "../oldies.h" #include "../gfx2log.h" /** @@ -83,3 +83,49 @@ int Test_MOTO_MAP_pack(void) } return 1; // test OK } + +int Test_CPC_compare_colors(void) +{ + unsigned int r, g, b; + T_Components c1, c2; + for (r = 0; r < 16; r++) + { + for (g = 0; g < 16; g++) + { + for (b = 0; b < 16; b++) + { + c1.R = r * 0x11; + c1.G = g * 0x11; + c1.B = b * 0x11; + if (!CPC_compare_colors(&c1, &c1)) + return 0; // same colors should be recognized as identical !!! + c2.R = ((r + 6) & 15) * 0x11; + c2.G = c1.G; + c2.B = c1.B; + if (CPC_compare_colors(&c1, &c2)) + { + GFX2_Log(GFX2_ERROR, "#%02x%02x%02x <> #%02x%02x%02x\n", + c1.R, c1.G, c1.B, c2.R, c2.G, c2.B); + return 0; // Should be differents ! + } + c2.R = c1.R; + c2.G = ((g + 6) & 15) * 0x11; + if (CPC_compare_colors(&c1, &c2)) + { + GFX2_Log(GFX2_ERROR, "#%02x%02x%02x <> #%02x%02x%02x\n", + c1.R, c1.G, c1.B, c2.R, c2.G, c2.B); + return 0; // Should be differents ! + } + c2.G = c1.G; + c2.B = ((b + 6) & 15) * 0x11; + if (CPC_compare_colors(&c1, &c2)) + { + GFX2_Log(GFX2_ERROR, "#%02x%02x%02x <> #%02x%02x%02x\n", + c1.R, c1.G, c1.B, c2.R, c2.G, c2.B); + return 0; // Should be differents ! + } + } + } + } + return 1; // test OK +}