Test case for g_type_add_interface_check().
authorOwen Taylor <otaylor@redhat.com>
Thu, 2 Oct 2003 05:28:00 +0000 (05:28 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Thu, 2 Oct 2003 05:28:00 +0000 (05:28 +0000)
Thu Oct  2 01:15:46 2003  Owen Taylor  <otaylor@redhat.com>

        * tests/gobject/ifacecheck.c: Test case for
        g_type_add_interface_check().

        * tests/gobject/ifaceinit.c: Add #undef G_DISABLE_ASSERT.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
tests/gobject/Makefile.am
tests/gobject/ifacecheck.c [new file with mode: 0644]
tests/gobject/ifaceinit.c

index e1db198..3edb2e8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Oct  2 01:15:46 2003  Owen Taylor  <otaylor@redhat.com>
+
+       * 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  <otaylor@redhat.com>
 
        * tests/gobject/ifaceinherit.c: Remove some tests that
@@ -5,11 +12,6 @@ Thu Oct  2 01:11:39 2003  Owen Taylor  <otaylor@redhat.com>
        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  <otaylor@redhat.com>
-
-       * tests/gobject/ifaceinherit.c (main): Remove some tests
-       that 
-
 Thu Oct  2 00:02:55 2003  Owen Taylor  <otaylor@redhat.com>
 
        * tests/gobject/Makefile.am test/gobject/ifaceinherit.c:
index e1db198..3edb2e8 100644 (file)
@@ -1,3 +1,10 @@
+Thu Oct  2 01:15:46 2003  Owen Taylor  <otaylor@redhat.com>
+
+       * 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  <otaylor@redhat.com>
 
        * tests/gobject/ifaceinherit.c: Remove some tests that
@@ -5,11 +12,6 @@ Thu Oct  2 01:11:39 2003  Owen Taylor  <otaylor@redhat.com>
        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  <otaylor@redhat.com>
-
-       * tests/gobject/ifaceinherit.c (main): Remove some tests
-       that 
-
 Thu Oct  2 00:02:55 2003  Owen Taylor  <otaylor@redhat.com>
 
        * tests/gobject/Makefile.am test/gobject/ifaceinherit.c:
index e1db198..3edb2e8 100644 (file)
@@ -1,3 +1,10 @@
+Thu Oct  2 01:15:46 2003  Owen Taylor  <otaylor@redhat.com>
+
+       * 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  <otaylor@redhat.com>
 
        * tests/gobject/ifaceinherit.c: Remove some tests that
@@ -5,11 +12,6 @@ Thu Oct  2 01:11:39 2003  Owen Taylor  <otaylor@redhat.com>
        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  <otaylor@redhat.com>
-
-       * tests/gobject/ifaceinherit.c (main): Remove some tests
-       that 
-
 Thu Oct  2 00:02:55 2003  Owen Taylor  <otaylor@redhat.com>
 
        * tests/gobject/Makefile.am test/gobject/ifaceinherit.c:
index e1db198..3edb2e8 100644 (file)
@@ -1,3 +1,10 @@
+Thu Oct  2 01:15:46 2003  Owen Taylor  <otaylor@redhat.com>
+
+       * 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  <otaylor@redhat.com>
 
        * tests/gobject/ifaceinherit.c: Remove some tests that
@@ -5,11 +12,6 @@ Thu Oct  2 01:11:39 2003  Owen Taylor  <otaylor@redhat.com>
        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  <otaylor@redhat.com>
-
-       * tests/gobject/ifaceinherit.c (main): Remove some tests
-       that 
-
 Thu Oct  2 00:02:55 2003  Owen Taylor  <otaylor@redhat.com>
 
        * tests/gobject/Makefile.am test/gobject/ifaceinherit.c:
index e1db198..3edb2e8 100644 (file)
@@ -1,3 +1,10 @@
+Thu Oct  2 01:15:46 2003  Owen Taylor  <otaylor@redhat.com>
+
+       * 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  <otaylor@redhat.com>
 
        * tests/gobject/ifaceinherit.c: Remove some tests that
@@ -5,11 +12,6 @@ Thu Oct  2 01:11:39 2003  Owen Taylor  <otaylor@redhat.com>
        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  <otaylor@redhat.com>
-
-       * tests/gobject/ifaceinherit.c (main): Remove some tests
-       that 
-
 Thu Oct  2 00:02:55 2003  Owen Taylor  <otaylor@redhat.com>
 
        * tests/gobject/Makefile.am test/gobject/ifaceinherit.c:
index e1db198..3edb2e8 100644 (file)
@@ -1,3 +1,10 @@
+Thu Oct  2 01:15:46 2003  Owen Taylor  <otaylor@redhat.com>
+
+       * 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  <otaylor@redhat.com>
 
        * tests/gobject/ifaceinherit.c: Remove some tests that
@@ -5,11 +12,6 @@ Thu Oct  2 01:11:39 2003  Owen Taylor  <otaylor@redhat.com>
        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  <otaylor@redhat.com>
-
-       * tests/gobject/ifaceinherit.c (main): Remove some tests
-       that 
-
 Thu Oct  2 00:02:55 2003  Owen Taylor  <otaylor@redhat.com>
 
        * tests/gobject/Makefile.am test/gobject/ifaceinherit.c:
index 41ae14a..992a7a9 100644 (file)
@@ -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 (file)
index 0000000..4572deb
--- /dev/null
@@ -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 <string.h>
+
+#include <glib-object.h>
+
+#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;
+}
index 5d2686a..eaa6d35 100644 (file)
 
 #undef G_LOG_DOMAIN
 #define        G_LOG_DOMAIN "TestIfaceInit"
-#include       <glib-object.h>
+
+#undef G_DISABLE_ASSERT
+#undef G_DISABLE_CHECKS
+#undef G_DISABLE_CAST_CHECKS
+
+#include <glib-object.h>
 
 #include "testcommon.h"