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);