[tests] Add ClutterColor conformance tests
authorEmmanuele Bassi <ebassi@linux.intel.com>
Mon, 1 Jun 2009 17:43:47 +0000 (18:43 +0100)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Mon, 1 Jun 2009 17:43:47 +0000 (18:43 +0100)
Add a conformance test unit for the to_string() and from_string()
methods.

.gitignore
tests/conform/Makefile.am
tests/conform/test-color.c [new file with mode: 0644]
tests/conform/test-conform-main.c

index 917592b..561b69b 100644 (file)
@@ -200,6 +200,8 @@ stamp-h1
 /tests/conform/test-realize-not-recursive
 /tests/conform/test-shown-not-parented
 /tests/conform/test-blend-strings
+/tests/conform/test-color-from-string
+/tests/conform/test-color-to-string
 /tests/conform/test-conformance-result.xml
 /tests/micro-bench/test-text-perf
 /tests/micro-bench/test-text
index 82e104b..be19c04 100644 (file)
@@ -29,6 +29,7 @@ test_conformance_SOURCES =            \
        test-npot-texture.c             \
        test-model.c                    \
        test-blend-strings.c            \
+       test-color.c                    \
         $(NULL)
 
 # For convenience, this provides a way to easily run individual unit tests:
diff --git a/tests/conform/test-color.c b/tests/conform/test-color.c
new file mode 100644 (file)
index 0000000..65dc83f
--- /dev/null
@@ -0,0 +1,71 @@
+#include <stdio.h>
+#include <clutter/clutter.h>
+
+#include "test-conform-common.h"
+
+void
+test_color_from_string (TestConformSimpleFixture *fixture,
+                        gconstpointer data)
+{
+  ClutterColor color;
+
+  clutter_color_from_string (&color, "#ff0000ff");
+  if (g_test_verbose ())
+    {
+      g_print ("color = { %x, %x, %x, %x }, expected = { 0xff, 0, 0, 0xff }\n",
+               color.red,
+               color.green,
+               color.blue,
+               color.alpha);
+    }
+  g_assert (color.red   == 0xff);
+  g_assert (color.green == 0);
+  g_assert (color.blue  == 0);
+  g_assert (color.alpha == 0xff);
+
+  clutter_color_from_string (&color, "#0f0f");
+  if (g_test_verbose ())
+    {
+      g_print ("color = { %x, %x, %x, %x }, expected = { 0, 0xff, 0, 0xff }\n",
+               color.red,
+               color.green,
+               color.blue,
+               color.alpha);
+    }
+  g_assert (color.red   == 0);
+  g_assert (color.green == 0xff);
+  g_assert (color.blue  == 0);
+  g_assert (color.alpha == 0xff);
+
+  clutter_color_from_string (&color, "#0000ff");
+  if (g_test_verbose ())
+    {
+      g_print ("color = { %x, %x, %x, %x }, expected = { 0, 0, 0xff, 0xff }\n",
+               color.red,
+               color.green,
+               color.blue,
+               color.alpha);
+    }
+  g_assert (color.red   == 0);
+  g_assert (color.green == 0);
+  g_assert (color.blue  == 0xff);
+  g_assert (color.alpha == 0xff);
+}
+
+void
+test_color_to_string (TestConformSimpleFixture *fixture,
+                      gconstpointer data)
+{
+  ClutterColor color;
+  gchar *str;
+
+  color.red = 0xcc;
+  color.green = 0xcc;
+  color.blue = 0xcc;
+  color.alpha = 0x22;
+
+  str = clutter_color_to_string (&color);
+  g_assert_cmpstr (str, ==, "#cccccc22");
+
+  g_free (str);
+}
index ff614ae..fc0daac 100644 (file)
@@ -145,5 +145,8 @@ main (int argc, char **argv)
 
   TEST_CONFORM_SIMPLE ("/material", test_blend_strings);
 
+  TEST_CONFORM_SIMPLE ("/color", test_color_from_string);
+  TEST_CONFORM_SIMPLE ("/color", test_color_to_string);
+
   return g_test_run ();
 }