Add a test for signals returning interface types

Add a test for a signal returning interface types, using
the generic marshaller. This will hopefully exercise newly
added code in value_from_ffi_type().
This commit is contained in:
Matthias Clasen 2020-10-28 12:37:37 -04:00 committed by Philip Withnall
parent 52357aac44
commit 0b1f909691

View File

@ -135,6 +135,47 @@ static GType flags_type;
static guint simple_id; static guint simple_id;
static guint simple2_id; static guint simple2_id;
typedef struct {
GTypeInterface g_iface;
} FooInterface;
GType foo_get_type (void);
G_DEFINE_INTERFACE (Foo, foo, G_TYPE_OBJECT)
static void
foo_default_init (FooInterface *iface)
{
}
typedef struct {
GObject parent;
} Baa;
typedef struct {
GObjectClass parent_class;
} BaaClass;
static void
baa_init_foo (FooInterface *iface)
{
}
GType baa_get_type (void);
G_DEFINE_TYPE_WITH_CODE (Baa, baa, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (foo_get_type (), baa_init_foo))
static void
baa_init (Baa *baa)
{
}
static void
baa_class_init (BaaClass *class)
{
}
typedef struct _Test Test; typedef struct _Test Test;
typedef struct _TestClass TestClass; typedef struct _TestClass TestClass;
@ -257,6 +298,14 @@ test_class_init (TestClass *klass)
NULL, NULL,
G_TYPE_UINT, G_TYPE_UINT,
0); 0);
g_signal_new ("generic-marshaller-interface-return",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
NULL,
foo_get_type (),
0);
s = g_signal_new ("va-marshaller-uint-return", s = g_signal_new ("va-marshaller-uint-return",
G_TYPE_FROM_CLASS (klass), G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
@ -754,6 +803,35 @@ test_generic_marshaller_signal_uint_return (void)
g_object_unref (test); g_object_unref (test);
} }
static gpointer
on_generic_marshaller_interface_return (Test *test)
{
return g_object_new (baa_get_type (), NULL);
}
static void
test_generic_marshaller_signal_interface_return (void)
{
Test *test;
guint id;
gpointer retval;
test = g_object_new (test_get_type (), NULL);
/* Test return value -30 */
id = g_signal_connect (test,
"generic-marshaller-interface-return",
G_CALLBACK (on_generic_marshaller_interface_return),
NULL);
g_signal_emit_by_name (test, "generic-marshaller-interface-return", &retval);
g_assert_true (g_type_check_instance_is_a ((GTypeInstance*)retval, foo_get_type ()));
g_object_unref (retval);
g_signal_handler_disconnect (test, id);
g_object_unref (test);
}
static const GSignalInvocationHint dont_use_this = { 0, }; static const GSignalInvocationHint dont_use_this = { 0, };
static void static void
@ -1082,6 +1160,7 @@ test_introspection (void)
"generic-marshaller-int-return", "generic-marshaller-int-return",
"va-marshaller-int-return", "va-marshaller-int-return",
"generic-marshaller-uint-return", "generic-marshaller-uint-return",
"generic-marshaller-interface-return",
"va-marshaller-uint-return", "va-marshaller-uint-return",
"variant-changed-no-slot", "variant-changed-no-slot",
"variant-changed", "variant-changed",
@ -1495,6 +1574,7 @@ main (int argc,
g_test_add_func ("/gobject/signals/generic-marshaller-enum-return-unsigned", test_generic_marshaller_signal_enum_return_unsigned); g_test_add_func ("/gobject/signals/generic-marshaller-enum-return-unsigned", test_generic_marshaller_signal_enum_return_unsigned);
g_test_add_func ("/gobject/signals/generic-marshaller-int-return", test_generic_marshaller_signal_int_return); g_test_add_func ("/gobject/signals/generic-marshaller-int-return", test_generic_marshaller_signal_int_return);
g_test_add_func ("/gobject/signals/generic-marshaller-uint-return", test_generic_marshaller_signal_uint_return); g_test_add_func ("/gobject/signals/generic-marshaller-uint-return", test_generic_marshaller_signal_uint_return);
g_test_add_func ("/gobject/signals/generic-marshaller-interface-return", test_generic_marshaller_signal_interface_return);
g_test_add_func ("/gobject/signals/custom-marshaller", test_custom_marshaller); g_test_add_func ("/gobject/signals/custom-marshaller", test_custom_marshaller);
g_test_add_func ("/gobject/signals/connect", test_connect); g_test_add_func ("/gobject/signals/connect", test_connect);
g_test_add_func ("/gobject/signals/emission-hook", test_emission_hook); g_test_add_func ("/gobject/signals/emission-hook", test_emission_hook);