1 #include <glib-object.h>
3 typedef struct _Test Test;
4 typedef struct _TestClass TestClass;
8 GObject parent_instance;
13 GObjectClass parent_class;
15 void (* variant_changed) (Test *, GVariant *);
18 static GType test_get_type (void);
19 G_DEFINE_TYPE (Test, test, G_TYPE_OBJECT)
22 test_init (Test *test)
27 test_class_init (TestClass *klass)
29 g_signal_new ("variant-changed-no-slot",
30 G_TYPE_FROM_CLASS (klass),
31 G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
34 g_cclosure_marshal_VOID__VARIANT,
38 g_signal_new ("variant-changed",
39 G_TYPE_FROM_CLASS (klass),
40 G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
41 G_STRUCT_OFFSET (TestClass, variant_changed),
43 g_cclosure_marshal_VOID__VARIANT,
50 test_variant_signal (void)
55 /* Tests that the signal emission consumes the variant,
56 * even if there are no handlers connected.
59 test = g_object_new (test_get_type (), NULL);
61 v = g_variant_new_boolean (TRUE);
63 g_assert (g_variant_is_floating (v));
64 g_signal_emit_by_name (test, "variant-changed-no-slot", v);
65 g_assert (!g_variant_is_floating (v));
68 v = g_variant_new_boolean (TRUE);
70 g_assert (g_variant_is_floating (v));
71 g_signal_emit_by_name (test, "variant-changed", v);
72 g_assert (!g_variant_is_floating (v));
75 g_object_unref (test);
86 g_test_init (&argc, &argv, NULL);
88 g_test_add_func ("/gobject/signals/variant", test_variant_signal);