2008-11-12 Emmanuele Bassi <ebassi@linux.intel.com>
authorEmmanuele Bassi <ebassi@openedhand.com>
Wed, 12 Nov 2008 14:41:01 +0000 (14:41 +0000)
committerEmmanuele Bassi <ebassi@openedhand.com>
Wed, 12 Nov 2008 14:41:01 +0000 (14:41 +0000)
* tests/conform/Makefile.am:
* tests/conform/test-conform-main.c:
* tests/conform/test-paint-opacity.c: Add test unit for label,
rectangle and paint opacity.

ChangeLog
tests/conform/Makefile.am
tests/conform/test-conform-main.c
tests/conform/test-paint-opacity.c [new file with mode: 0644]

index 3efcb3d..437bc5e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2008-11-12  Emmanuele Bassi  <ebassi@linux.intel.com>
 
+       * tests/conform/Makefile.am:
+       * tests/conform/test-conform-main.c:
+       * tests/conform/test-paint-opacity.c: Add test unit for label,
+       rectangle and paint opacity.
+
+2008-11-12  Emmanuele Bassi  <ebassi@linux.intel.com>
+
        * clutter/cogl/cogl-color.h:
        * clutter/cogl/cogl-path.h:
        * clutter/cogl/cogl-types.h: 
index 8df4619..010612d 100644 (file)
@@ -18,7 +18,8 @@ test_conformance_SOURCES = \
        test-clutter-entry.c \
        test-clutter-rectangle.c \
        test-clutter-fixed.c \
-        test-actor-invariants.c
+        test-actor-invariants.c \
+        test-paint-opacity.c
 
 # For convenience, this provides a way to easily run individual unit tests:
 .PHONY: wrappers
index ef10cac..82bf769 100644 (file)
@@ -85,7 +85,9 @@ main (int argc, char **argv)
   TEST_CONFORM_SIMPLE ("/mesh", test_mesh_interleved);
   TEST_CONFORM_SIMPLE ("/mesh", test_mesh_mutability);
 
-  g_test_run ();
-  return EXIT_SUCCESS;
-}
+  TEST_CONFORM_SIMPLE ("/opacity", test_label_opacity);
+  TEST_CONFORM_SIMPLE ("/opacity", test_rectangle_opacity);
+  TEST_CONFORM_SIMPLE ("/opacity", test_paint_opacity);
 
+  return g_test_run ();
+}
diff --git a/tests/conform/test-paint-opacity.c b/tests/conform/test-paint-opacity.c
new file mode 100644 (file)
index 0000000..77618a9
--- /dev/null
@@ -0,0 +1,144 @@
+#include <clutter/clutter.h>
+#include <stdlib.h>
+
+#include "test-conform-common.h"
+
+void
+test_label_opacity (TestConformSimpleFixture *fixture,
+                    gpointer                  dummy)
+{
+  ClutterActor *stage;
+  ClutterActor *label;
+  ClutterColor label_color = { 255, 0, 0, 128 };
+  ClutterColor color_check = { 0, };
+
+  stage = clutter_stage_get_default ();
+
+  label = clutter_label_new_with_text ("Sans 18px", "Label, 50% opacity");
+  clutter_label_set_color (CLUTTER_LABEL (label), &label_color);
+
+  if (g_test_verbose ())
+    g_print ("label 50%%.get_color()/1\n");
+  clutter_label_get_color (CLUTTER_LABEL (label), &color_check);
+  g_assert (color_check.alpha == label_color.alpha);
+
+  clutter_container_add (CLUTTER_CONTAINER (stage), label, NULL);
+  clutter_actor_set_position (label, 10, 10);
+
+  if (g_test_verbose ())
+    g_print ("label 50%%.get_color()/2\n");
+  clutter_label_get_color (CLUTTER_LABEL (label), &color_check);
+  g_assert (color_check.alpha == label_color.alpha);
+
+  if (g_test_verbose ())
+    g_print ("label 50%%.get_paint_opacity() = %d\n",
+             clutter_actor_get_paint_opacity (label));
+  g_assert (clutter_actor_get_paint_opacity (label) == 128);
+
+  clutter_actor_destroy (label);
+}
+
+void
+test_rectangle_opacity (TestConformSimpleFixture *fixture,
+                        gpointer                  dummy)
+{
+  ClutterActor *stage;
+  ClutterActor *rect;
+  ClutterColor rect_color = { 0, 0, 255, 255 };
+  ClutterColor color_check = { 0, };
+
+  stage = clutter_stage_get_default ();
+
+  rect = clutter_rectangle_new_with_color (&rect_color);
+  clutter_actor_set_size (rect, 128, 128);
+  clutter_actor_set_position (rect, 150, 90);
+
+  if (g_test_verbose ())
+    g_print ("rect 100%%.get_color()/1\n");
+  clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color_check);
+  g_assert (color_check.alpha == rect_color.alpha);
+
+  clutter_container_add (CLUTTER_CONTAINER (stage), rect, NULL);
+
+  if (g_test_verbose ())
+    g_print ("rect 100%%.get_color()/2\n");
+  clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color_check);
+  g_assert (color_check.alpha == rect_color.alpha);
+
+  if (g_test_verbose ())
+    g_print ("rect 100%%.get_paint_opacity() = %d\n",
+             clutter_actor_get_paint_opacity (rect));
+  g_assert (clutter_actor_get_paint_opacity (rect) == 255);
+
+  clutter_actor_destroy (rect);
+}
+
+void
+test_paint_opacity (TestConformSimpleFixture *fixture,
+                    gpointer                  dummy)
+{
+  ClutterActor *stage, *group1, *group2;
+  ClutterActor *label, *rect;
+  ClutterColor label_color = { 255, 0, 0, 128 };
+  ClutterColor rect_color = { 0, 0, 255, 255 };
+  ClutterColor color_check = { 0, };
+
+  stage = clutter_stage_get_default ();
+
+  group1 = clutter_group_new ();
+  clutter_actor_set_opacity (group1, 128);
+  clutter_container_add (CLUTTER_CONTAINER (stage), group1, NULL);
+  clutter_actor_set_position (group1, 10, 30);
+  clutter_actor_show (group1);
+
+  label = clutter_label_new_with_text ("Sans 18px", "Label+Group, 25% opacity");
+  clutter_label_set_color (CLUTTER_LABEL (label), &label_color);
+
+  if (g_test_verbose ())
+    g_print ("label 50%% + group 50%%.get_color()/1\n");
+  clutter_label_get_color (CLUTTER_LABEL (label), &color_check);
+  g_assert (color_check.alpha == label_color.alpha);
+
+  clutter_container_add (CLUTTER_CONTAINER (group1), label, NULL);
+
+  if (g_test_verbose ())
+    g_print ("label 50%% + group 50%%.get_color()/2\n");
+  clutter_label_get_color (CLUTTER_LABEL (label), &color_check);
+  g_assert (color_check.alpha == label_color.alpha);
+
+  if (g_test_verbose ())
+    g_print ("label 50%% + group 50%%.get_paint_opacity() = %d\n",
+             clutter_actor_get_paint_opacity (label));
+  g_assert (clutter_actor_get_paint_opacity (label) == 64);
+
+  clutter_actor_destroy (label);
+
+  group2 = clutter_group_new ();
+  clutter_container_add (CLUTTER_CONTAINER (group1), group2, NULL);
+  clutter_actor_set_position (group2, 10, 60);
+
+  rect = clutter_rectangle_new_with_color (&rect_color);
+  clutter_actor_set_size (rect, 128, 128);
+
+  if (g_test_verbose ())
+    g_print ("rect 100%% + group 100%% + group 50%%.get_color()/1\n");
+  clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color_check);
+  g_assert (color_check.alpha == rect_color.alpha);
+
+  clutter_container_add (CLUTTER_CONTAINER (group2), rect, NULL);
+
+  if (g_test_verbose ())
+    g_print ("rect 100%% + group 100%% + group 50%%.get_color()/2\n");
+  clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color_check);
+  g_assert (color_check.alpha == rect_color.alpha);
+
+  if (g_test_verbose ())
+    g_print ("rect 100%%.get_paint_opacity() = %d\n",
+             clutter_actor_get_paint_opacity (rect));
+
+  g_assert (clutter_actor_get_paint_opacity (rect) == 128);
+
+  clutter_actor_destroy (rect);
+  clutter_actor_destroy (group2);
+  clutter_actor_destroy (group1);
+}