From c6ce9c338966188248c3c1ae7b10480205fe20bf Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 14 Jan 2010 14:07:04 +0000 Subject: [PATCH] conform: Add operators tests for ClutterColor The clutter_color_add() and clutter_color_subtract() functions are lacking unit testing to catch eventual regressions. --- .gitignore | 1 + tests/conform/test-color.c | 57 +++++++++++++++++++++++++++++++ tests/conform/test-conform-main.c | 1 + 3 files changed, 59 insertions(+) diff --git a/.gitignore b/.gitignore index b63cce8ce..715337746 100644 --- a/.gitignore +++ b/.gitignore @@ -239,6 +239,7 @@ TAGS /tests/conform/test-script-animation /tests/conform/test-script-named-object /tests/conform/test-actor-destruction +/tests/conform/test-color-operators /tests/micro-bench/test-text-perf /tests/micro-bench/test-text /tests/micro-bench/test-picking diff --git a/tests/conform/test-color.c b/tests/conform/test-color.c index a19323bd9..71b080736 100644 --- a/tests/conform/test-color.c +++ b/tests/conform/test-color.c @@ -166,3 +166,60 @@ test_color_to_string (TestConformSimpleFixture *fixture, g_free (str); } + +void +test_color_operators (TestConformSimpleFixture *fixture, + gconstpointer data) +{ + ClutterColor op1, op2; + ClutterColor res; + + clutter_color_from_pixel (&op1, 0xff0000ff); + g_assert_cmpint (op1.red, ==, 0xff); + g_assert_cmpint (op1.green, ==, 0); + g_assert_cmpint (op1.blue, ==, 0); + g_assert_cmpint (op1.alpha, ==, 0xff); + + clutter_color_from_pixel (&op2, 0x00ff00ff); + g_assert_cmpint (op2.red, ==, 0); + g_assert_cmpint (op2.green, ==, 0xff); + g_assert_cmpint (op2.blue, ==, 0); + g_assert_cmpint (op2.alpha, ==, 0xff); + + if (g_test_verbose ()) + g_print ("Adding %x, %x; expected result: %x\n", + clutter_color_to_pixel (&op1), + clutter_color_to_pixel (&op2), + 0xffff00ff); + + clutter_color_add (&op1, &op2, &res); + g_assert_cmpint (clutter_color_to_pixel (&res), ==, 0xffff00ff); + + if (g_test_verbose ()) + g_print ("Checking alpha channel on color add\n"); + + op1.alpha = 0xdd; + op2.alpha = 0xcc; + clutter_color_add (&op1, &op2, &res); + g_assert_cmpint (clutter_color_to_pixel (&res), ==, 0xffff00dd); + + clutter_color_from_pixel (&op1, 0xffffffff); + clutter_color_from_pixel (&op2, 0xff00ffff); + + if (g_test_verbose ()) + g_print ("Subtracting %x, %x; expected result: %x\n", + clutter_color_to_pixel (&op1), + clutter_color_to_pixel (&op2), + 0x00ff00ff); + + clutter_color_subtract (&op1, &op2, &res); + g_assert_cmpint (clutter_color_to_pixel (&res), ==, 0x00ff00ff); + + if (g_test_verbose ()) + g_print ("Checking alpha channel on color subtract\n"); + + op1.alpha = 0xdd; + op2.alpha = 0xcc; + clutter_color_subtract (&op1, &op2, &res); + g_assert_cmpint (clutter_color_to_pixel (&res), ==, 0x00ff00cc); +} diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c index 26c045172..72d69b92e 100644 --- a/tests/conform/test-conform-main.c +++ b/tests/conform/test-conform-main.c @@ -160,6 +160,7 @@ main (int argc, char **argv) TEST_CONFORM_SIMPLE ("/color", test_color_from_string); TEST_CONFORM_SIMPLE ("/color", test_color_to_string); TEST_CONFORM_SIMPLE ("/color", test_color_hls_roundtrip); + TEST_CONFORM_SIMPLE ("/color", test_color_operators); TEST_CONFORM_SIMPLE ("/units", test_units_constructors); TEST_CONFORM_SIMPLE ("/units", test_units_string);