mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-30 21:04:13 +02:00
gtype: Add g_type_interface_instantiatable_prerequisite()
This function returns the most specific instantiatable type that is a prerequisite for a given interface. This type is necessary in particular when dealing with GValues because a GValue contains an instance of a type. This commit includes tests for the new API.
This commit is contained in:
committed by
Philip Withnall
parent
e1b5afb7c0
commit
98f0a5a7da
@@ -40,6 +40,63 @@ foo_default_init (FooInterface *iface)
|
||||
{
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GTypeInterface g_iface;
|
||||
} BaaInterface;
|
||||
|
||||
GType baa_get_type (void);
|
||||
|
||||
G_DEFINE_INTERFACE (Baa, baa, G_TYPE_INVALID)
|
||||
|
||||
static void
|
||||
baa_default_init (BaaInterface *iface)
|
||||
{
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GTypeInterface g_iface;
|
||||
} BooInterface;
|
||||
|
||||
GType boo_get_type (void);
|
||||
|
||||
G_DEFINE_INTERFACE_WITH_CODE (Boo, boo, G_TYPE_INVALID,
|
||||
g_type_interface_add_prerequisite (g_define_type_id, baa_get_type ()))
|
||||
|
||||
static void
|
||||
boo_default_init (BooInterface *iface)
|
||||
{
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GTypeInterface g_iface;
|
||||
} BibiInterface;
|
||||
|
||||
GType bibi_get_type (void);
|
||||
|
||||
G_DEFINE_INTERFACE (Bibi, bibi, G_TYPE_INITIALLY_UNOWNED)
|
||||
|
||||
static void
|
||||
bibi_default_init (BibiInterface *iface)
|
||||
{
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GTypeInterface g_iface;
|
||||
} BozoInterface;
|
||||
|
||||
GType bozo_get_type (void);
|
||||
|
||||
G_DEFINE_INTERFACE_WITH_CODE (Bozo, bozo, G_TYPE_INVALID,
|
||||
g_type_interface_add_prerequisite (g_define_type_id, foo_get_type ());
|
||||
g_type_interface_add_prerequisite (g_define_type_id, bibi_get_type ()))
|
||||
|
||||
static void
|
||||
bozo_default_init (BozoInterface *iface)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
test_interface_prerequisite (void)
|
||||
{
|
||||
@@ -52,6 +109,7 @@ test_interface_prerequisite (void)
|
||||
g_assert_cmpint (n_prereqs, ==, 2);
|
||||
g_assert (prereqs[0] == bar_get_type ());
|
||||
g_assert (prereqs[1] == G_TYPE_OBJECT);
|
||||
g_assert (g_type_interface_instantiatable_prerequisite (foo_get_type ()) == G_TYPE_OBJECT);
|
||||
|
||||
iface = g_type_default_interface_ref (foo_get_type ());
|
||||
parent = g_type_interface_peek_parent (iface);
|
||||
@@ -59,6 +117,11 @@ test_interface_prerequisite (void)
|
||||
g_type_default_interface_unref (iface);
|
||||
|
||||
g_free (prereqs);
|
||||
|
||||
g_assert_cmpint (g_type_interface_instantiatable_prerequisite (baa_get_type ()), ==, G_TYPE_INVALID);
|
||||
g_assert_cmpint (g_type_interface_instantiatable_prerequisite (boo_get_type ()), ==, G_TYPE_INVALID);
|
||||
|
||||
g_assert_cmpint (g_type_interface_instantiatable_prerequisite (bozo_get_type ()), ==, G_TYPE_INITIALLY_UNOWNED);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
Reference in New Issue
Block a user