[glib] Add test for G_IMPLEMENT_INTERFACE_DYNAMIC
- From: Alexander Larsson <alexl src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glib] Add test for G_IMPLEMENT_INTERFACE_DYNAMIC
- Date: Thu, 26 Nov 2009 10:55:20 +0000 (UTC)
commit 36646f46ab07dec3d5a2ce0c9ba1932587528ca8
Author: Alexander Larsson <alexl redhat com>
Date: Thu Nov 26 11:54:44 2009 +0100
Add test for G_IMPLEMENT_INTERFACE_DYNAMIC
tests/gobject/dynamictype.c | 53 +++++++++++++++++++++++++++++++++++++++---
1 files changed, 49 insertions(+), 4 deletions(-)
---
diff --git a/tests/gobject/dynamictype.c b/tests/gobject/dynamictype.c
index 2a5415e..bef42ee 100644
--- a/tests/gobject/dynamictype.c
+++ b/tests/gobject/dynamictype.c
@@ -34,6 +34,33 @@
static gboolean loaded = FALSE;
+struct _TestIfaceClass
+{
+ GTypeInterface base_iface;
+ guint val;
+};
+
+#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 _TestIface TestIface;
+typedef struct _TestIfaceClass TestIfaceClass;
+
+static void test_iface_base_init (TestIfaceClass *iface);
+static void test_iface_default_init (TestIfaceClass *iface, gpointer class_data);
+
+static DEFINE_IFACE(TestIface, test_iface, test_iface_base_init, test_iface_default_init)
+
+static void
+test_iface_default_init (TestIfaceClass *iface,
+ gpointer class_data)
+{
+}
+
+static void
+test_iface_base_init (TestIfaceClass *iface)
+{
+}
+
#define DYNAMIC_OBJECT_TYPE (dynamic_object_get_type ())
typedef GObject DynamicObject;
@@ -45,7 +72,12 @@ struct _DynamicObjectClass
guint val;
};
-G_DEFINE_DYNAMIC_TYPE(DynamicObject, dynamic_object, G_TYPE_OBJECT);
+static void dynamic_object_iface_init (gpointer g_iface,
+ gpointer iface_data);
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED(DynamicObject, dynamic_object, G_TYPE_OBJECT, 0,
+ G_IMPLEMENT_INTERFACE_DYNAMIC (TEST_TYPE_IFACE,
+ dynamic_object_iface_init));
static void
dynamic_object_class_init (DynamicObjectClass *class)
@@ -60,11 +92,16 @@ dynamic_object_class_finalize (DynamicObjectClass *class)
loaded = FALSE;
}
-static void
-dynamic_object_init (DynamicObject *dynamic_object)
+static void
+dynamic_object_iface_init (gpointer g_iface,
+ gpointer iface_data)
{
}
+static void
+dynamic_object_init (DynamicObject *dynamic_object)
+{
+}
static void
module_register (GTypeModule *module)
@@ -85,6 +122,10 @@ test_dynamic_type (void)
g_assert (class == NULL);
g_assert (!loaded);
+ /* Make sure interfaces work */
+ g_assert (g_type_is_a (DYNAMIC_OBJECT_TYPE,
+ TEST_TYPE_IFACE));
+
/* Ref loads */
class = g_type_class_ref (DYNAMIC_OBJECT_TYPE);
g_assert (class && class->val == 42);
@@ -94,7 +135,11 @@ test_dynamic_type (void)
class = g_type_class_peek (DYNAMIC_OBJECT_TYPE);
g_assert (class && class->val == 42);
g_assert (loaded);
-
+
+ /* Make sure interfaces still work */
+ g_assert (g_type_is_a (DYNAMIC_OBJECT_TYPE,
+ TEST_TYPE_IFACE));
+
/* Unref causes finalize */
g_type_class_unref (class);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]