From 12b004b0e7e13ca64d7d35cd3fe083f582b7aa09 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 2 Feb 2010 12:56:04 +0000 Subject: [PATCH] tests: Add an initial Behaviour conformance suite The coverage of the Behaviour sub-classes is currently abysmal. An initial test suite for Behaviours should at least verify that the accessors and the constructors are doing the right thing. This initial test suite just verifies the BehaviourOpacity sub-class, but it already bumps up the overall coverage by 2%. --- .gitignore | 1 + tests/conform/Makefile.am | 1 + tests/conform/test-behaviours.c | 87 +++++++++++++++++++++++++++++++++++++++ tests/conform/test-conform-main.c | 2 + 4 files changed, 91 insertions(+) create mode 100644 tests/conform/test-behaviours.c diff --git a/.gitignore b/.gitignore index 04932be..82da73a 100644 --- a/.gitignore +++ b/.gitignore @@ -241,6 +241,7 @@ TAGS /tests/conform/test-actor-destruction /tests/conform/test-color-operators /tests/conform/test-cogl-texture-mipmaps +/tests/conform/test-behaviours /tests/micro-bench/test-text-perf /tests/micro-bench/test-text /tests/micro-bench/test-picking diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am index 3ae1cc7..81d19da 100644 --- a/tests/conform/Makefile.am +++ b/tests/conform/Makefile.am @@ -43,6 +43,7 @@ test_conformance_SOURCES = \ test-texture-fbo.c \ test-script-parser.c \ test-actor-destroy.c \ + test-behaviours.c \ $(NULL) # For convenience, this provides a way to easily run individual unit tests: diff --git a/tests/conform/test-behaviours.c b/tests/conform/test-behaviours.c new file mode 100644 index 0000000..669e14f --- /dev/null +++ b/tests/conform/test-behaviours.c @@ -0,0 +1,87 @@ +#include +#include + +#include "test-conform-common.h" + +typedef struct _BehaviourFixture BehaviourFixture; + +typedef void (* BehaviourTestFunc) (BehaviourFixture *fixture); + +struct _BehaviourFixture +{ + ClutterTimeline *timeline; + ClutterAlpha *alpha; + ClutterActor *rect; +}; + +static void +opacity_behaviour (BehaviourFixture *fixture) +{ + ClutterBehaviour *behaviour; + guint8 start, end; + + behaviour = clutter_behaviour_opacity_new (fixture->alpha, 0, 255); + g_assert (CLUTTER_IS_BEHAVIOUR_OPACITY (behaviour)); + + clutter_behaviour_opacity_get_bounds (CLUTTER_BEHAVIOUR_OPACITY (behaviour), + &start, + &end); + + if (g_test_verbose ()) + g_print ("BehaviourOpacity:bounds = %d, %d (expected: 0, 255)\n", + start, + end); + + g_assert_cmpint (start, ==, 0); + g_assert_cmpint (end, ==, 255); + + clutter_behaviour_opacity_set_bounds (CLUTTER_BEHAVIOUR_OPACITY (behaviour), + 255, + 0); + + start = 0; + g_object_get (G_OBJECT (behaviour), "opacity-start", &start, NULL); + + if (g_test_verbose ()) + g_print ("BehaviourOpacity:start = %d (expected: 255)\n", start); + + g_assert_cmpint (start, ==, 255); + + g_object_unref (behaviour); +} + +static const struct +{ + const gchar *desc; + BehaviourTestFunc func; +} behaviour_tests[] = { + { "BehaviourOpacity", opacity_behaviour } +}; + +static const gint n_behaviour_tests = G_N_ELEMENTS (behaviour_tests); + +void +test_behaviours (TestConformSimpleFixture *fixture, + gconstpointer dummy) +{ + BehaviourFixture b_fixture; + gint i; + + b_fixture.timeline = clutter_timeline_new (1000); + b_fixture.alpha = clutter_alpha_new_full (b_fixture.timeline, CLUTTER_LINEAR); + b_fixture.rect = clutter_rectangle_new (); + + g_object_ref_sink (b_fixture.alpha); + g_object_unref (b_fixture.timeline); + + for (i = 0; i < n_behaviour_tests; i++) + { + if (g_test_verbose ()) + g_print ("Testing: %s\n", behaviour_tests[i].desc); + + behaviour_tests[i].func (&b_fixture); + } + + g_object_unref (b_fixture.alpha); + clutter_actor_destroy (b_fixture.rect); +} diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c index a090dc6..e733110 100644 --- a/tests/conform/test-conform-main.c +++ b/tests/conform/test-conform-main.c @@ -178,6 +178,8 @@ main (int argc, char **argv) TEST_CONFORM_SIMPLE ("/script", test_script_animation); TEST_CONFORM_SIMPLE ("/script", test_script_named_object); + TEST_CONFORM_SIMPLE ("/behaviours", test_behaviours); + TEST_CONFORM_SIMPLE ("/cogl", test_cogl_fixed); TEST_CONFORM_SIMPLE ("/cogl", test_cogl_backface_culling); TEST_CONFORM_SIMPLE ("/cogl", test_cogl_materials); -- 2.7.4