From 457faaffb7092d56dcee37383a778fae431b6dac Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Tue, 1 Jun 2010 17:27:59 +0100 Subject: [PATCH] conform: Adds a test-cogl-object conformance test This tests the new cogl_object_get/set_user_data API --- tests/conform/Makefile.am | 1 + tests/conform/test-cogl-object.c | 86 +++++++++++++++++++++++++++++++ tests/conform/test-conform-main.c | 1 + 3 files changed, 88 insertions(+) create mode 100644 tests/conform/test-cogl-object.c diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am index 28f607414..e9d1e57a8 100644 --- a/tests/conform/Makefile.am +++ b/tests/conform/Makefile.am @@ -30,6 +30,7 @@ test_conformance_SOURCES = \ test-cogl-wrap-modes.c \ test-cogl-pixel-buffer.c \ test-cogl-path.c \ + test-cogl-object.c \ test-path.c \ test-pick.c \ test-clutter-rectangle.c \ diff --git a/tests/conform/test-cogl-object.c b/tests/conform/test-cogl-object.c new file mode 100644 index 000000000..4fb1922c2 --- /dev/null +++ b/tests/conform/test-cogl-object.c @@ -0,0 +1,86 @@ + +#include +#include +#include + +#include "test-conform-common.h" + +CoglUserDataKey private_key0; +CoglUserDataKey private_key1; +CoglUserDataKey private_key2; + +static int user_data0; +static int user_data1; +static int user_data2; + +static int destroy0_count = 0; +static int destroy1_count = 0; +static int destroy2_count = 0; + +static void +destroy0_cb (void *user_data) +{ + g_assert (user_data == &user_data0); + destroy0_count++; +} + +static void +destroy1_cb (void *user_data) +{ + g_assert (user_data == &user_data1); + destroy1_count++; +} + +static void +destroy2_cb (void *user_data) +{ + g_assert (user_data == &user_data2); + destroy2_count++; +} + +void +test_cogl_object (TestConformSimpleFixture *fixture, + gconstpointer data) +{ + CoglPath *path; + + /* Assuming that COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES == 2 + * test associating 2 pointers to private data with an object */ + cogl_path_new (); + path = cogl_get_path (); + + cogl_object_set_user_data (COGL_OBJECT (path), + &private_key0, + &user_data0, + destroy0_cb); + + cogl_object_set_user_data (COGL_OBJECT (path), + &private_key1, + &user_data1, + destroy1_cb); + + cogl_object_set_user_data (COGL_OBJECT (path), + &private_key2, + &user_data2, + destroy2_cb); + + cogl_object_set_user_data (COGL_OBJECT (path), + &private_key1, + NULL, + destroy1_cb); + + cogl_object_set_user_data (COGL_OBJECT (path), + &private_key1, + &user_data1, + destroy1_cb); + + cogl_object_unref (path); + + g_assert_cmpint (destroy0_count, ==, 1); + g_assert_cmpint (destroy1_count, ==, 2); + g_assert_cmpint (destroy2_count, ==, 1); + + if (g_test_verbose ()) + g_print ("OK\n"); +} + diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c index 9a10a4c4a..7b0aa6bce 100644 --- a/tests/conform/test-conform-main.c +++ b/tests/conform/test-conform-main.c @@ -189,6 +189,7 @@ main (int argc, char **argv) TEST_CONFORM_SIMPLE ("/behaviours", test_behaviours); + TEST_CONFORM_SIMPLE ("/cogl", test_cogl_object); TEST_CONFORM_SIMPLE ("/cogl", test_cogl_fixed); TEST_CONFORM_SIMPLE ("/cogl", test_cogl_backface_culling); TEST_CONFORM_SIMPLE ("/cogl", test_cogl_materials);