conform: Add the beginnings of a ClutterScript test suite
authorEmmanuele Bassi <ebassi@linux.intel.com>
Wed, 4 Nov 2009 11:50:45 +0000 (11:50 +0000)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Wed, 4 Nov 2009 11:50:45 +0000 (11:50 +0000)
ClutterScript is a very complicated piece of machinery, with a
parser that has custom variations on top of the basic JSON
format; it could also be extended in the future, so if we don't
want to introduce regressions or break existing ClutterScript
definitions, we'd better have a conformance test suite.

.gitignore
tests/conform/Makefile.am
tests/conform/test-conform-main.c
tests/conform/test-script-parser.c [new file with mode: 0644]
tests/data/Makefile.am
tests/data/test-script-single.json [new file with mode: 0644]

index 7f824c2..5b4e47a 100644 (file)
@@ -218,6 +218,7 @@ TAGS
 /tests/conform/test-cogl-readpixels
 /tests/conform/test-cogl-viewport
 /tests/conform/test-texture-fbo
+/tests/conform/test-script-single
 /tests/micro-bench/test-text-perf
 /tests/micro-bench/test-text
 /tests/micro-bench/test-picking
index 9983db3..7139ccd 100644 (file)
@@ -39,6 +39,7 @@ test_conformance_SOURCES =            \
        test-cogl-viewport.c            \
        test-cogl-offscreen.c           \
        test-cogl-readpixels.c          \
+       test-script-parser.c            \
         $(NULL)
 
 # For convenience, this provides a way to easily run individual unit tests:
index 315af74..e588ee7 100644 (file)
@@ -185,5 +185,7 @@ main (int argc, char **argv)
   TEST_CONFORM_SIMPLE ("/cogl", test_cogl_offscreen);
   TEST_CONFORM_SIMPLE ("/cogl", test_cogl_readpixels);
 
+  TEST_CONFORM_SIMPLE ("/script", test_script_single);
+
   return g_test_run ();
 }
diff --git a/tests/conform/test-script-parser.c b/tests/conform/test-script-parser.c
new file mode 100644 (file)
index 0000000..929f7bc
--- /dev/null
@@ -0,0 +1,33 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include <clutter/clutter.h>
+
+#include "test-conform-common.h"
+
+void
+test_script_single (TestConformSimpleFixture *fixture,
+                    gconstpointer dummy)
+{
+  ClutterScript *script = clutter_script_new ();
+  GObject *actor = NULL;
+  GError *error = NULL;
+  ClutterActor *rect;
+  gchar *test_file;
+
+  test_file = clutter_test_get_data_file ("test-script-single.json");
+  clutter_script_load_from_file (script, test_file, &error);
+  g_assert (error == NULL);
+
+  actor = clutter_script_get_object (script, "test");
+  g_assert (CLUTTER_IS_RECTANGLE (actor));
+
+  rect = CLUTTER_ACTOR (actor);
+  g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 50.0);
+  g_assert_cmpfloat (clutter_actor_get_y (rect), ==, 100.0);
+
+  g_object_unref (script);
+
+  clutter_actor_destroy (rect);
+  g_free (test_file);
+}
index a367ed8..3a47ed0 100644 (file)
@@ -1,6 +1,9 @@
-EXTRA_DIST = \
-       redhand.png \
-       redhand_alpha.png \
-       light0.png \
-       test-script.json
+NULL =
 
+EXTRA_DIST = \
+       redhand.png             \
+       redhand_alpha.png       \
+       light0.png              \
+       test-script.json        \
+       test-script-single.json \
+       $(NULL)
diff --git a/tests/data/test-script-single.json b/tests/data/test-script-single.json
new file mode 100644 (file)
index 0000000..e20a318
--- /dev/null
@@ -0,0 +1,10 @@
+{
+  "type" : "ClutterRectangle",
+  "id" : "test",
+  "width" : 50.0,
+  "height" : 100.0,
+  "x" : 100.0,
+  "y" : 100.0,
+  "color" : "#ffccdd",
+  "name" : "Test Rectangle"
+}