Add test for G_IMPLEMENT_INTERFACE_DYNAMIC

This commit is contained in:
Alexander Larsson 2009-11-26 11:54:44 +01:00
parent 7d51c96e5e
commit 36646f46ab

View File

@ -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);