From 3e61c90b595c5508a6d9c87478174ca6c450c134 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Thu, 2 Oct 2003 05:28:00 +0000 Subject: [PATCH] Test case for g_type_add_interface_check(). Thu Oct 2 01:15:46 2003 Owen Taylor * tests/gobject/ifacecheck.c: Test case for g_type_add_interface_check(). * tests/gobject/ifaceinit.c: Add #undef G_DISABLE_ASSERT. --- ChangeLog | 12 ++-- ChangeLog.pre-2-10 | 12 ++-- ChangeLog.pre-2-12 | 12 ++-- ChangeLog.pre-2-4 | 12 ++-- ChangeLog.pre-2-6 | 12 ++-- ChangeLog.pre-2-8 | 12 ++-- tests/gobject/Makefile.am | 1 + tests/gobject/ifacecheck.c | 169 +++++++++++++++++++++++++++++++++++++++++++++ tests/gobject/ifaceinit.c | 7 +- 9 files changed, 218 insertions(+), 31 deletions(-) create mode 100644 tests/gobject/ifacecheck.c diff --git a/ChangeLog b/ChangeLog index e1db198..3edb2e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Oct 2 01:15:46 2003 Owen Taylor + + * tests/gobject/ifacecheck.c: Test case for + g_type_add_interface_check(). + + * tests/gobject/ifaceinit.c: Add #undef G_DISABLE_ASSERT. + Thu Oct 2 01:11:39 2003 Owen Taylor * tests/gobject/ifaceinherit.c: Remove some tests that @@ -5,11 +12,6 @@ Thu Oct 2 01:11:39 2003 Owen Taylor a test for adding an interface first to the child class, then to the parent class. -Thu Oct 2 01:08:13 2003 Owen Taylor - - * tests/gobject/ifaceinherit.c (main): Remove some tests - that - Thu Oct 2 00:02:55 2003 Owen Taylor * tests/gobject/Makefile.am test/gobject/ifaceinherit.c: diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index e1db198..3edb2e8 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +Thu Oct 2 01:15:46 2003 Owen Taylor + + * tests/gobject/ifacecheck.c: Test case for + g_type_add_interface_check(). + + * tests/gobject/ifaceinit.c: Add #undef G_DISABLE_ASSERT. + Thu Oct 2 01:11:39 2003 Owen Taylor * tests/gobject/ifaceinherit.c: Remove some tests that @@ -5,11 +12,6 @@ Thu Oct 2 01:11:39 2003 Owen Taylor a test for adding an interface first to the child class, then to the parent class. -Thu Oct 2 01:08:13 2003 Owen Taylor - - * tests/gobject/ifaceinherit.c (main): Remove some tests - that - Thu Oct 2 00:02:55 2003 Owen Taylor * tests/gobject/Makefile.am test/gobject/ifaceinherit.c: diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index e1db198..3edb2e8 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,10 @@ +Thu Oct 2 01:15:46 2003 Owen Taylor + + * tests/gobject/ifacecheck.c: Test case for + g_type_add_interface_check(). + + * tests/gobject/ifaceinit.c: Add #undef G_DISABLE_ASSERT. + Thu Oct 2 01:11:39 2003 Owen Taylor * tests/gobject/ifaceinherit.c: Remove some tests that @@ -5,11 +12,6 @@ Thu Oct 2 01:11:39 2003 Owen Taylor a test for adding an interface first to the child class, then to the parent class. -Thu Oct 2 01:08:13 2003 Owen Taylor - - * tests/gobject/ifaceinherit.c (main): Remove some tests - that - Thu Oct 2 00:02:55 2003 Owen Taylor * tests/gobject/Makefile.am test/gobject/ifaceinherit.c: diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index e1db198..3edb2e8 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,10 @@ +Thu Oct 2 01:15:46 2003 Owen Taylor + + * tests/gobject/ifacecheck.c: Test case for + g_type_add_interface_check(). + + * tests/gobject/ifaceinit.c: Add #undef G_DISABLE_ASSERT. + Thu Oct 2 01:11:39 2003 Owen Taylor * tests/gobject/ifaceinherit.c: Remove some tests that @@ -5,11 +12,6 @@ Thu Oct 2 01:11:39 2003 Owen Taylor a test for adding an interface first to the child class, then to the parent class. -Thu Oct 2 01:08:13 2003 Owen Taylor - - * tests/gobject/ifaceinherit.c (main): Remove some tests - that - Thu Oct 2 00:02:55 2003 Owen Taylor * tests/gobject/Makefile.am test/gobject/ifaceinherit.c: diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index e1db198..3edb2e8 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +Thu Oct 2 01:15:46 2003 Owen Taylor + + * tests/gobject/ifacecheck.c: Test case for + g_type_add_interface_check(). + + * tests/gobject/ifaceinit.c: Add #undef G_DISABLE_ASSERT. + Thu Oct 2 01:11:39 2003 Owen Taylor * tests/gobject/ifaceinherit.c: Remove some tests that @@ -5,11 +12,6 @@ Thu Oct 2 01:11:39 2003 Owen Taylor a test for adding an interface first to the child class, then to the parent class. -Thu Oct 2 01:08:13 2003 Owen Taylor - - * tests/gobject/ifaceinherit.c (main): Remove some tests - that - Thu Oct 2 00:02:55 2003 Owen Taylor * tests/gobject/Makefile.am test/gobject/ifaceinherit.c: diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index e1db198..3edb2e8 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +Thu Oct 2 01:15:46 2003 Owen Taylor + + * tests/gobject/ifacecheck.c: Test case for + g_type_add_interface_check(). + + * tests/gobject/ifaceinit.c: Add #undef G_DISABLE_ASSERT. + Thu Oct 2 01:11:39 2003 Owen Taylor * tests/gobject/ifaceinherit.c: Remove some tests that @@ -5,11 +12,6 @@ Thu Oct 2 01:11:39 2003 Owen Taylor a test for adding an interface first to the child class, then to the parent class. -Thu Oct 2 01:08:13 2003 Owen Taylor - - * tests/gobject/ifaceinherit.c (main): Remove some tests - that - Thu Oct 2 00:02:55 2003 Owen Taylor * tests/gobject/Makefile.am test/gobject/ifaceinherit.c: diff --git a/tests/gobject/Makefile.am b/tests/gobject/Makefile.am index 41ae14a..992a7a9 100644 --- a/tests/gobject/Makefile.am +++ b/tests/gobject/Makefile.am @@ -47,6 +47,7 @@ LDADD = $(libgobject) libtestgobject.la test_programs = \ accumulator \ defaultiface \ + ifacecheck \ ifaceinit \ ifaceinherit \ override diff --git a/tests/gobject/ifacecheck.c b/tests/gobject/ifacecheck.c new file mode 100644 index 0000000..4572deb --- /dev/null +++ b/tests/gobject/ifacecheck.c @@ -0,0 +1,169 @@ +/* GObject - GLib Type, Object, Parameter and Signal Library + * Copyright (C) 2001, 2003 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#undef G_LOG_DOMAIN +#define G_LOG_DOMAIN "TestIfaceCheck" + +#undef G_DISABLE_ASSERT +#undef G_DISABLE_CHECKS +#undef G_DISABLE_CAST_CHECKS + +#include + +#include + +#include "testcommon.h" + +/* This test tests g_type_add_interface_check_func(), which allows + * installing a post-initialization check function. + */ + +#define TEST_TYPE_IFACE (test_iface_get_type ()) +#define TEST_IFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TEST_TYPE_IFACE, TestIfaceClass)) +typedef struct _TestIfaceClass TestIfaceClass; + +struct _TestIfaceClass +{ + GTypeInterface base_iface; + GString *history; +}; + +static void +test_iface_base_init (TestIfaceClass *iface) +{ + if (iface->history) + g_string_free (iface->history, TRUE); + iface->history = g_string_new (NULL); +} + +static DEFINE_IFACE(TestIface, test_iface, test_iface_base_init, NULL) + +/* + * TestObject1 + */ +#define TEST_TYPE_OBJECT1 (test_object1_get_type ()) +typedef struct _GObject TestObject1; +typedef struct _GObjectClass TestObject1Class; + +static DEFINE_TYPE_FULL (TestObject1, test_object1, + NULL, NULL, NULL, + G_TYPE_OBJECT, + INTERFACE (NULL, TEST_TYPE_IFACE)) + +/* + * TestObject2 + */ +#define TEST_TYPE_OBJECT2 (test_object2_get_type ()) +typedef struct _GObject TestObject2; +typedef struct _GObjectClass TestObject2Class; + +static DEFINE_TYPE_FULL (TestObject2, test_object2, + NULL, NULL, NULL, + G_TYPE_OBJECT, + INTERFACE (NULL, TEST_TYPE_IFACE)) + +/* + * TestObject3 + */ +#define TEST_TYPE_OBJECT3 (test_object3_get_type ()) +typedef struct _GObject TestObject3; +typedef struct _GObjectClass TestObject3Class; + +static DEFINE_TYPE_FULL (TestObject3, test_object3, + NULL, NULL, NULL, + G_TYPE_OBJECT, + INTERFACE (NULL, TEST_TYPE_IFACE)) + +/* + * TestObject4 + */ +#define TEST_TYPE_OBJECT4 (test_object4_get_type ()) +typedef struct _GObject TestObject4; +typedef struct _GObjectClass TestObject4Class; + + +static DEFINE_TYPE_FULL (TestObject4, test_object4, + NULL, NULL, NULL, + G_TYPE_OBJECT, {}) + +static void +check_func (gpointer check_data, + gpointer g_iface) +{ + TestIfaceClass *iface = g_iface; + + g_string_append (iface->history, check_data); +} + +int +main (int argc, + char *argv[]) +{ + TestIfaceClass *iface; + GObject *object; + char *string1 = "A"; + char *string2 = "B"; + + g_type_init (); + + /* Basic check of interfaces added before class_init time + */ + g_type_add_interface_check (string1, check_func); + + object = g_object_new (TEST_TYPE_OBJECT1, NULL); + iface = TEST_IFACE_GET_CLASS (object); + g_assert (strcmp (iface->history->str, "A") == 0); + g_object_unref (object); + + /* Add a second check function + */ + g_type_add_interface_check (string2, check_func); + + object = g_object_new (TEST_TYPE_OBJECT2, NULL); + iface = TEST_IFACE_GET_CLASS (object); + g_assert (strcmp (iface->history->str, "AB") == 0); + g_object_unref (object); + + /* Remove the first check function + */ + g_type_remove_interface_check (string1, check_func); + + object = g_object_new (TEST_TYPE_OBJECT3, NULL); + iface = TEST_IFACE_GET_CLASS (object); + g_assert (strcmp (iface->history->str, "B") == 0); + g_object_unref (object); + + /* Test interfaces added after class_init time + */ + g_type_class_ref (TEST_TYPE_OBJECT4); + { + static GInterfaceInfo const iface = { + NULL, NULL, NULL + }; + + g_type_add_interface_static (TEST_TYPE_OBJECT4, TEST_TYPE_IFACE, &iface); + } + + object = g_object_new (TEST_TYPE_OBJECT4, NULL); + iface = TEST_IFACE_GET_CLASS (object); + g_assert (strcmp (iface->history->str, "B") == 0); + g_object_unref (object); + + return 0; +} diff --git a/tests/gobject/ifaceinit.c b/tests/gobject/ifaceinit.c index 5d2686a..eaa6d35 100644 --- a/tests/gobject/ifaceinit.c +++ b/tests/gobject/ifaceinit.c @@ -19,7 +19,12 @@ #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "TestIfaceInit" -#include + +#undef G_DISABLE_ASSERT +#undef G_DISABLE_CHECKS +#undef G_DISABLE_CAST_CHECKS + +#include #include "testcommon.h" -- 2.7.4