conform: Add operators tests for ClutterColor
authorEmmanuele Bassi <ebassi@linux.intel.com>
Thu, 14 Jan 2010 14:07:04 +0000 (14:07 +0000)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Thu, 14 Jan 2010 14:07:04 +0000 (14:07 +0000)
The clutter_color_add() and clutter_color_subtract() functions are
lacking unit testing to catch eventual regressions.

.gitignore
tests/conform/test-color.c
tests/conform/test-conform-main.c

index b63cce8..7153377 100644 (file)
@@ -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
index a19323b..71b0807 100644 (file)
@@ -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);
+}
index 26c0451..72d69b9 100644 (file)
@@ -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);