[tests] Add initial sizing conformance test suite
authorEmmanuele Bassi <ebassi@linux.intel.com>
Mon, 14 Sep 2009 20:45:51 +0000 (21:45 +0100)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Tue, 15 Sep 2009 10:27:50 +0000 (11:27 +0100)
The size requisition and allocation mechanisms should be thoroughly
tested to avoid unwanted regressions.

For starters, we can test the explicit size setting and the side
effects of calling clutter_actor_set_size().

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

index bd4666f..da9baf1 100644 (file)
@@ -211,6 +211,7 @@ TAGS
 /tests/conform/test-materials
 /tests/conform/test-group-depth-sorting
 /tests/conform/test-conformance-result.xml
+/tests/conform/test-fixed-size
 /tests/micro-bench/test-text-perf
 /tests/micro-bench/test-text
 /tests/micro-bench/test-picking
index cde2591..d8f0b69 100644 (file)
@@ -32,6 +32,7 @@ test_conformance_SOURCES =            \
        test-premult.c                  \
        test-materials.c                \
        test-group.c                    \
+       test-actor-size.c               \
         $(NULL)
 
 # For convenience, this provides a way to easily run individual unit tests:
diff --git a/tests/conform/test-actor-size.c b/tests/conform/test-actor-size.c
new file mode 100644 (file)
index 0000000..ce4e530
--- /dev/null
@@ -0,0 +1,77 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include <clutter/clutter.h>
+
+#include "test-conform-common.h"
+
+void
+test_fixed_size (TestConformSimpleFixture *fixture,
+                 gconstpointer data)
+{
+  ClutterActor *rect;
+  gboolean min_width_set, nat_width_set;
+  gboolean min_height_set, nat_height_set;
+  gfloat min_width, min_height;
+  gfloat nat_width, nat_height;
+
+  rect = clutter_rectangle_new ();
+
+  if (g_test_verbose ())
+    g_print ("Initial size is 0\n");
+
+  g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 0);
+  g_assert_cmpfloat (clutter_actor_get_height (rect), ==, 0);
+
+  clutter_actor_set_size (rect, 100, 100);
+
+  if (g_test_verbose ())
+    g_print ("Explicit size set\n");
+
+  g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 100);
+  g_assert_cmpfloat (clutter_actor_get_height (rect), ==, 100);
+
+  g_object_get (G_OBJECT (rect),
+                "min-width-set", &min_width_set,
+                "min-height-set", &min_height_set,
+                "natural-width-set", &nat_width_set,
+                "natural-height-set", &nat_height_set,
+                NULL);
+
+  if (g_test_verbose ())
+    g_print ("Notification properties\n");
+
+  g_assert (min_width_set && nat_width_set);
+  g_assert (min_height_set && nat_height_set);
+
+  clutter_actor_get_preferred_size (rect,
+                                    &min_width, &min_height,
+                                    &nat_width, &nat_height);
+
+  if (g_test_verbose ())
+    g_print ("Preferred size\n");
+
+  g_assert_cmpfloat (min_width, ==, 100);
+  g_assert_cmpfloat (min_height, ==, 100);
+  g_assert_cmpfloat (min_width, ==, nat_width);
+  g_assert_cmpfloat (min_height, ==, nat_height);
+
+  clutter_actor_set_size (rect, -1, -1);
+
+  if (g_test_verbose ())
+    g_print ("Explicit size unset\n");
+
+  g_object_get (G_OBJECT (rect),
+                "min-width-set", &min_width_set,
+                "min-height-set", &min_height_set,
+                "natural-width-set", &nat_width_set,
+                "natural-height-set", &nat_height_set,
+                NULL);
+  g_assert (!min_width_set && !nat_width_set);
+  g_assert (!min_height_set && !nat_height_set);
+
+  g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 0);
+  g_assert_cmpfloat (clutter_actor_get_height (rect), ==, 0);
+
+  clutter_actor_destroy (rect);
+}
index 1efd432..a690bd6 100644 (file)
@@ -170,5 +170,7 @@ main (int argc, char **argv)
 
   TEST_CONFORM_SIMPLE ("/group", test_group_depth_sorting);
 
+  TEST_CONFORM_SIMPLE ("/sizing", test_fixed_size);
+
   return g_test_run ();
 }