diff options
author | Alexander Larsson <alexl@redhat.com> | 2009-11-26 11:54:44 +0100 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2009-11-26 11:54:44 +0100 |
commit | 36646f46ab07dec3d5a2ce0c9ba1932587528ca8 (patch) | |
tree | 9be16c07c48fed4b6f552ebe9e06faaa7088d783 /tests | |
parent | 7d51c96e5e39e8f3b403884f286ef781f0c952d6 (diff) |
Add test for G_IMPLEMENT_INTERFACE_DYNAMIC
Diffstat (limited to 'tests')
-rw-r--r-- | 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 2a5415e43..bef42ee73 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); |