1 #include <glib-object.h>
2 #include "marshalers.h"
5 TEST_ENUM_NEGATIVE = -30,
12 TEST_UNSIGNED_ENUM_FOO = 1,
13 TEST_UNSIGNED_ENUM_BAR = 42
14 /* Don't test 0x80000000 for now- nothing appears to do this in
15 * practice, and it triggers GValue/GEnum bugs on ppc64.
20 test_enum_get_type (void)
22 static volatile gsize g_define_type_id__volatile = 0;
24 if (g_once_init_enter (&g_define_type_id__volatile))
26 static const GEnumValue values[] = {
27 { TEST_ENUM_NEGATIVE, "TEST_ENUM_NEGATIVE", "negative" },
28 { TEST_ENUM_NONE, "TEST_ENUM_NONE", "none" },
29 { TEST_ENUM_FOO, "TEST_ENUM_FOO", "foo" },
30 { TEST_ENUM_BAR, "TEST_ENUM_BAR", "bar" },
33 GType g_define_type_id =
34 g_enum_register_static (g_intern_static_string ("TestEnum"), values);
35 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
38 return g_define_type_id__volatile;
42 test_unsigned_enum_get_type (void)
44 static volatile gsize g_define_type_id__volatile = 0;
46 if (g_once_init_enter (&g_define_type_id__volatile))
48 static const GEnumValue values[] = {
49 { TEST_UNSIGNED_ENUM_FOO, "TEST_UNSIGNED_ENUM_FOO", "foo" },
50 { TEST_UNSIGNED_ENUM_BAR, "TEST_UNSIGNED_ENUM_BAR", "bar" },
53 GType g_define_type_id =
54 g_enum_register_static (g_intern_static_string ("TestUnsignedEnum"), values);
55 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
58 return g_define_type_id__volatile;
62 static const GEnumValue my_enum_values[] =
64 { 1, "the first value", "one" },
68 static const GFlagsValue my_flag_values[] =
70 { 1, "the first value", "one" },
74 static GType enum_type;
75 static GType flags_type;
77 static guint simple_id;
79 typedef struct _Test Test;
80 typedef struct _TestClass TestClass;
84 GObject parent_instance;
87 static void all_types_handler (Test *test, int i, gboolean b, char c, guchar uc, guint ui, glong l, gulong ul, gint e, guint f, float fl, double db, char *str, GParamSpec *param, GBytes *bytes, gpointer ptr, Test *obj, GVariant *var, gint64 i64, guint64 ui64);
91 GObjectClass parent_class;
93 void (* variant_changed) (Test *, GVariant *);
94 void (* all_types) (Test *test, int i, gboolean b, char c, guchar uc, guint ui, glong l, gulong ul, gint e, guint f, float fl, double db, char *str, GParamSpec *param, GBytes *bytes, gpointer ptr, Test *obj, GVariant *var, gint64 i64, guint64 ui64);
95 void (* all_types_null) (Test *test, int i, gboolean b, char c, guchar uc, guint ui, glong l, gulong ul, gint e, guint f, float fl, double db, char *str, GParamSpec *param, GBytes *bytes, gpointer ptr, Test *obj, GVariant *var, gint64 i64, guint64 ui64);
98 static GType test_get_type (void);
99 G_DEFINE_TYPE (Test, test, G_TYPE_OBJECT)
102 test_init (Test *test)
107 test_class_init (TestClass *klass)
111 enum_type = g_enum_register_static ("MyEnum", my_enum_values);
112 flags_type = g_flags_register_static ("MyFlag", my_flag_values);
114 klass->all_types = all_types_handler;
116 simple_id = g_signal_new ("simple",
117 G_TYPE_FROM_CLASS (klass),
124 g_signal_new ("generic-marshaller-1",
125 G_TYPE_FROM_CLASS (klass),
132 G_TYPE_CHAR, G_TYPE_UCHAR, G_TYPE_INT, G_TYPE_LONG, G_TYPE_POINTER, G_TYPE_DOUBLE, G_TYPE_FLOAT);
133 g_signal_new ("generic-marshaller-2",
134 G_TYPE_FROM_CLASS (klass),
141 G_TYPE_INT, test_enum_get_type(), G_TYPE_INT, test_unsigned_enum_get_type (), G_TYPE_INT);
142 g_signal_new ("generic-marshaller-enum-return-signed",
143 G_TYPE_FROM_CLASS (klass),
148 test_enum_get_type(),
150 g_signal_new ("generic-marshaller-enum-return-unsigned",
151 G_TYPE_FROM_CLASS (klass),
156 test_unsigned_enum_get_type(),
158 g_signal_new ("generic-marshaller-int-return",
159 G_TYPE_FROM_CLASS (klass),
166 s = g_signal_new ("va-marshaller-int-return",
167 G_TYPE_FROM_CLASS (klass),
174 g_signal_set_va_marshaller (s, G_TYPE_FROM_CLASS (klass),
176 g_signal_new ("generic-marshaller-uint-return",
177 G_TYPE_FROM_CLASS (klass),
184 s = g_signal_new ("va-marshaller-uint-return",
185 G_TYPE_FROM_CLASS (klass),
192 g_signal_set_va_marshaller (s, G_TYPE_FROM_CLASS (klass),
194 g_signal_new ("variant-changed-no-slot",
195 G_TYPE_FROM_CLASS (klass),
196 G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
199 g_cclosure_marshal_VOID__VARIANT,
203 g_signal_new ("variant-changed",
204 G_TYPE_FROM_CLASS (klass),
205 G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT,
206 G_STRUCT_OFFSET (TestClass, variant_changed),
208 g_cclosure_marshal_VOID__VARIANT,
212 g_signal_new ("all-types",
213 G_TYPE_FROM_CLASS (klass),
215 G_STRUCT_OFFSET (TestClass, all_types),
217 test_VOID__INT_BOOLEAN_CHAR_UCHAR_UINT_LONG_ULONG_ENUM_FLAGS_FLOAT_DOUBLE_STRING_PARAM_BOXED_POINTER_OBJECT_VARIANT_INT64_UINT64,
239 s = g_signal_new ("all-types-va",
240 G_TYPE_FROM_CLASS (klass),
242 G_STRUCT_OFFSET (TestClass, all_types),
244 test_VOID__INT_BOOLEAN_CHAR_UCHAR_UINT_LONG_ULONG_ENUM_FLAGS_FLOAT_DOUBLE_STRING_PARAM_BOXED_POINTER_OBJECT_VARIANT_INT64_UINT64,
266 g_signal_set_va_marshaller (s, G_TYPE_FROM_CLASS (klass),
267 test_VOID__INT_BOOLEAN_CHAR_UCHAR_UINT_LONG_ULONG_ENUM_FLAGS_FLOAT_DOUBLE_STRING_PARAM_BOXED_POINTER_OBJECT_VARIANT_INT64_UINT64v);
269 g_signal_new ("all-types-generic",
270 G_TYPE_FROM_CLASS (klass),
272 G_STRUCT_OFFSET (TestClass, all_types),
296 g_signal_new ("all-types-null",
297 G_TYPE_FROM_CLASS (klass),
299 G_STRUCT_OFFSET (TestClass, all_types_null),
301 test_VOID__INT_BOOLEAN_CHAR_UCHAR_UINT_LONG_ULONG_ENUM_FLAGS_FLOAT_DOUBLE_STRING_PARAM_BOXED_POINTER_OBJECT_VARIANT_INT64_UINT64,
323 g_signal_new ("all-types-empty",
324 G_TYPE_FROM_CLASS (klass),
328 test_VOID__INT_BOOLEAN_CHAR_UCHAR_UINT_LONG_ULONG_ENUM_FLAGS_FLOAT_DOUBLE_STRING_PARAM_BOXED_POINTER_OBJECT_VARIANT_INT64_UINT64,
353 test_variant_signal (void)
358 /* Tests that the signal emission consumes the variant,
359 * even if there are no handlers connected.
362 test = g_object_new (test_get_type (), NULL);
364 v = g_variant_new_boolean (TRUE);
366 g_assert (g_variant_is_floating (v));
367 g_signal_emit_by_name (test, "variant-changed-no-slot", v);
368 g_assert (!g_variant_is_floating (v));
371 v = g_variant_new_boolean (TRUE);
373 g_assert (g_variant_is_floating (v));
374 g_signal_emit_by_name (test, "variant-changed", v);
375 g_assert (!g_variant_is_floating (v));
378 g_object_unref (test);
382 on_generic_marshaller_1 (Test *obj,
392 g_assert_cmpint (v_schar, ==, 42);
393 g_assert_cmpint (v_uchar, ==, 43);
394 g_assert_cmpint (v_int, ==, 4096);
395 g_assert_cmpint (v_long, ==, 8192);
396 g_assert (v_pointer == NULL);
397 g_assert_cmpfloat (v_double, >, 0.0);
398 g_assert_cmpfloat (v_double, <, 1.0);
399 g_assert_cmpfloat (v_float, >, 5.0);
400 g_assert_cmpfloat (v_float, <, 6.0);
404 test_generic_marshaller_signal_1 (void)
407 test = g_object_new (test_get_type (), NULL);
409 g_signal_connect (test, "generic-marshaller-1", G_CALLBACK (on_generic_marshaller_1), NULL);
411 g_signal_emit_by_name (test, "generic-marshaller-1", 42, 43, 4096, 8192, NULL, 0.5, 5.5);
413 g_object_unref (test);
417 on_generic_marshaller_2 (Test *obj,
421 TestUnsignedEnum v_uenum,
424 g_assert_cmpint (v_int1, ==, 42);
425 g_assert_cmpint (v_enum, ==, TEST_ENUM_BAR);
426 g_assert_cmpint (v_int2, ==, 43);
427 g_assert_cmpint (v_uenum, ==, TEST_UNSIGNED_ENUM_BAR);
428 g_assert_cmpint (v_int3, ==, 44);
432 test_generic_marshaller_signal_2 (void)
435 test = g_object_new (test_get_type (), NULL);
437 g_signal_connect (test, "generic-marshaller-2", G_CALLBACK (on_generic_marshaller_2), NULL);
439 g_signal_emit_by_name (test, "generic-marshaller-2", 42, TEST_ENUM_BAR, 43, TEST_UNSIGNED_ENUM_BAR, 44);
441 g_object_unref (test);
445 on_generic_marshaller_enum_return_signed_1 (Test *obj)
447 return TEST_ENUM_NEGATIVE;
451 on_generic_marshaller_enum_return_signed_2 (Test *obj)
453 return TEST_ENUM_BAR;
457 test_generic_marshaller_signal_enum_return_signed (void)
463 test = g_object_new (test_get_type (), NULL);
465 /* Test return value NEGATIVE */
466 id = g_signal_connect (test,
467 "generic-marshaller-enum-return-signed",
468 G_CALLBACK (on_generic_marshaller_enum_return_signed_1),
470 g_signal_emit_by_name (test, "generic-marshaller-enum-return-signed", &retval);
471 g_assert_cmpint (retval, ==, TEST_ENUM_NEGATIVE);
472 g_signal_handler_disconnect (test, id);
474 /* Test return value BAR */
476 id = g_signal_connect (test,
477 "generic-marshaller-enum-return-signed",
478 G_CALLBACK (on_generic_marshaller_enum_return_signed_2),
480 g_signal_emit_by_name (test, "generic-marshaller-enum-return-signed", &retval);
481 g_assert_cmpint (retval, ==, TEST_ENUM_BAR);
482 g_signal_handler_disconnect (test, id);
484 g_object_unref (test);
487 static TestUnsignedEnum
488 on_generic_marshaller_enum_return_unsigned_1 (Test *obj)
490 return TEST_UNSIGNED_ENUM_FOO;
493 static TestUnsignedEnum
494 on_generic_marshaller_enum_return_unsigned_2 (Test *obj)
496 return TEST_UNSIGNED_ENUM_BAR;
500 test_generic_marshaller_signal_enum_return_unsigned (void)
504 TestUnsignedEnum retval = 0;
506 test = g_object_new (test_get_type (), NULL);
508 /* Test return value FOO */
509 id = g_signal_connect (test,
510 "generic-marshaller-enum-return-unsigned",
511 G_CALLBACK (on_generic_marshaller_enum_return_unsigned_1),
513 g_signal_emit_by_name (test, "generic-marshaller-enum-return-unsigned", &retval);
514 g_assert_cmpint (retval, ==, TEST_UNSIGNED_ENUM_FOO);
515 g_signal_handler_disconnect (test, id);
517 /* Test return value BAR */
519 id = g_signal_connect (test,
520 "generic-marshaller-enum-return-unsigned",
521 G_CALLBACK (on_generic_marshaller_enum_return_unsigned_2),
523 g_signal_emit_by_name (test, "generic-marshaller-enum-return-unsigned", &retval);
524 g_assert_cmpint (retval, ==, TEST_UNSIGNED_ENUM_BAR);
525 g_signal_handler_disconnect (test, id);
527 g_object_unref (test);
530 /**********************/
533 on_generic_marshaller_int_return_signed_1 (Test *obj)
539 on_generic_marshaller_int_return_signed_2 (Test *obj)
545 test_generic_marshaller_signal_int_return (void)
551 test = g_object_new (test_get_type (), NULL);
553 /* Test return value -30 */
554 id = g_signal_connect (test,
555 "generic-marshaller-int-return",
556 G_CALLBACK (on_generic_marshaller_int_return_signed_1),
558 g_signal_emit_by_name (test, "generic-marshaller-int-return", &retval);
559 g_assert_cmpint (retval, ==, -30);
560 g_signal_handler_disconnect (test, id);
562 /* Test return value positive */
564 id = g_signal_connect (test,
565 "generic-marshaller-int-return",
566 G_CALLBACK (on_generic_marshaller_int_return_signed_2),
568 g_signal_emit_by_name (test, "generic-marshaller-int-return", &retval);
569 g_assert_cmpint (retval, ==, 2);
570 g_signal_handler_disconnect (test, id);
572 /* Same test for va marshaller */
574 /* Test return value -30 */
575 id = g_signal_connect (test,
576 "va-marshaller-int-return",
577 G_CALLBACK (on_generic_marshaller_int_return_signed_1),
579 g_signal_emit_by_name (test, "va-marshaller-int-return", &retval);
580 g_assert_cmpint (retval, ==, -30);
581 g_signal_handler_disconnect (test, id);
583 /* Test return value positive */
585 id = g_signal_connect (test,
586 "va-marshaller-int-return",
587 G_CALLBACK (on_generic_marshaller_int_return_signed_2),
589 g_signal_emit_by_name (test, "va-marshaller-int-return", &retval);
590 g_assert_cmpint (retval, ==, 2);
591 g_signal_handler_disconnect (test, id);
593 g_object_unref (test);
597 on_generic_marshaller_uint_return_1 (Test *obj)
603 on_generic_marshaller_uint_return_2 (Test *obj)
609 test_generic_marshaller_signal_uint_return (void)
615 test = g_object_new (test_get_type (), NULL);
617 id = g_signal_connect (test,
618 "generic-marshaller-uint-return",
619 G_CALLBACK (on_generic_marshaller_uint_return_1),
621 g_signal_emit_by_name (test, "generic-marshaller-uint-return", &retval);
622 g_assert_cmpint (retval, ==, 1);
623 g_signal_handler_disconnect (test, id);
626 id = g_signal_connect (test,
627 "generic-marshaller-uint-return",
628 G_CALLBACK (on_generic_marshaller_uint_return_2),
630 g_signal_emit_by_name (test, "generic-marshaller-uint-return", &retval);
631 g_assert_cmpint (retval, ==, G_MAXUINT);
632 g_signal_handler_disconnect (test, id);
634 /* Same test for va marshaller */
636 id = g_signal_connect (test,
637 "va-marshaller-uint-return",
638 G_CALLBACK (on_generic_marshaller_uint_return_1),
640 g_signal_emit_by_name (test, "va-marshaller-uint-return", &retval);
641 g_assert_cmpint (retval, ==, 1);
642 g_signal_handler_disconnect (test, id);
645 id = g_signal_connect (test,
646 "va-marshaller-uint-return",
647 G_CALLBACK (on_generic_marshaller_uint_return_2),
649 g_signal_emit_by_name (test, "va-marshaller-uint-return", &retval);
650 g_assert_cmpint (retval, ==, G_MAXUINT);
651 g_signal_handler_disconnect (test, id);
653 g_object_unref (test);
656 static int all_type_handlers_count = 0;
659 all_types_handler (Test *test, int i, gboolean b, char c, guchar uc, guint ui, glong l, gulong ul, gint e, guint f, float fl, double db, char *str, GParamSpec *param, GBytes *bytes, gpointer ptr, Test *obj, GVariant *var, gint64 i64, guint64 ui64)
661 all_type_handlers_count++;
663 g_assert_cmpint (i, ==, 42);
664 g_assert_cmpint (b, ==, TRUE);
665 g_assert_cmpint (c, ==, 17);
666 g_assert_cmpuint (uc, ==, 140);
667 g_assert_cmpuint (ui, ==, G_MAXUINT - 42);
668 g_assert_cmpint (l, ==, -1117);
669 g_assert_cmpuint (ul, ==, G_MAXULONG - 999);
670 g_assert_cmpint (e, ==, 1);
671 g_assert_cmpuint (f, ==, 0);
672 g_assert_cmpfloat (fl, ==, 0.25);
673 g_assert_cmpfloat (db, ==, 1.5);
674 g_assert_cmpstr (str, ==, "Test");
675 g_assert_cmpstr (g_param_spec_get_nick (param), ==, "nick");
676 g_assert_cmpstr (g_bytes_get_data (bytes, NULL), ==, "Blah");
677 g_assert (ptr == &enum_type);
678 g_assert_cmpuint (g_variant_get_uint16 (var), == , 99);
679 g_assert_cmpint (i64, ==, G_MAXINT64 - 1234);
680 g_assert_cmpuint (ui64, ==, G_MAXUINT64 - 123456);
684 all_types_handler_cb (Test *test, int i, gboolean b, char c, guchar uc, guint ui, glong l, gulong ul, gint e, guint f, float fl, double db, char *str, GParamSpec *param, GBytes *bytes, gpointer ptr, Test *obj, GVariant *var, gint64 i64, guint64 ui64, gpointer user_data)
686 g_assert (user_data == &flags_type);
687 all_types_handler (test, i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, obj, var, i64, ui64);
691 test_all_types (void)
699 guint ui = G_MAXUINT - 42;
701 gulong ul = G_MAXULONG - 999;
707 GParamSpec *param = g_param_spec_long ("param", "nick", "blurb", 0, 10, 4, 0);
708 GBytes *bytes = g_bytes_new_static ("Blah", 5);
709 gpointer ptr = &enum_type;
710 GVariant *var = g_variant_new_uint16 (99);
713 g_variant_ref_sink (var);
714 i64 = G_MAXINT64 - 1234;
715 ui64 = G_MAXUINT64 - 123456;
717 test = g_object_new (test_get_type (), NULL);
719 all_type_handlers_count = 0;
721 g_signal_emit_by_name (test, "all-types",
722 i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, test, var, i64, ui64);
723 g_signal_emit_by_name (test, "all-types-va",
724 i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, test, var, i64, ui64);
725 g_signal_emit_by_name (test, "all-types-generic",
726 i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, test, var, i64, ui64);
727 g_signal_emit_by_name (test, "all-types-empty",
728 i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, test, var, i64, ui64);
729 g_signal_emit_by_name (test, "all-types-null",
730 i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, test, var, i64, ui64);
732 g_assert_cmpint (all_type_handlers_count, ==, 3);
734 all_type_handlers_count = 0;
736 g_signal_connect (test, "all-types", G_CALLBACK (all_types_handler_cb), &flags_type);
737 g_signal_connect (test, "all-types-va", G_CALLBACK (all_types_handler_cb), &flags_type);
738 g_signal_connect (test, "all-types-generic", G_CALLBACK (all_types_handler_cb), &flags_type);
739 g_signal_connect (test, "all-types-empty", G_CALLBACK (all_types_handler_cb), &flags_type);
740 g_signal_connect (test, "all-types-null", G_CALLBACK (all_types_handler_cb), &flags_type);
742 g_signal_emit_by_name (test, "all-types",
743 i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, test, var, i64, ui64);
744 g_signal_emit_by_name (test, "all-types-va",
745 i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, test, var, i64, ui64);
746 g_signal_emit_by_name (test, "all-types-generic",
747 i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, test, var, i64, ui64);
748 g_signal_emit_by_name (test, "all-types-empty",
749 i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, test, var, i64, ui64);
750 g_signal_emit_by_name (test, "all-types-null",
751 i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, test, var, i64, ui64);
753 g_assert_cmpint (all_type_handlers_count, ==, 3 + 5);
755 all_type_handlers_count = 0;
757 g_signal_connect (test, "all-types", G_CALLBACK (all_types_handler_cb), &flags_type);
758 g_signal_connect (test, "all-types-va", G_CALLBACK (all_types_handler_cb), &flags_type);
759 g_signal_connect (test, "all-types-generic", G_CALLBACK (all_types_handler_cb), &flags_type);
760 g_signal_connect (test, "all-types-empty", G_CALLBACK (all_types_handler_cb), &flags_type);
761 g_signal_connect (test, "all-types-null", G_CALLBACK (all_types_handler_cb), &flags_type);
763 g_signal_emit_by_name (test, "all-types",
764 i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, test, var, i64, ui64);
765 g_signal_emit_by_name (test, "all-types-va",
766 i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, test, var, i64, ui64);
767 g_signal_emit_by_name (test, "all-types-generic",
768 i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, test, var, i64, ui64);
769 g_signal_emit_by_name (test, "all-types-empty",
770 i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, test, var, i64, ui64);
771 g_signal_emit_by_name (test, "all-types-null",
772 i, b, c, uc, ui, l, ul, e, f, fl, db, str, param, bytes, ptr, test, var, i64, ui64);
774 g_assert_cmpint (all_type_handlers_count, ==, 3 + 5 + 5);
776 g_object_unref (test);
777 g_param_spec_unref (param);
778 g_bytes_unref (bytes);
779 g_variant_unref (var);
788 test = g_object_new (test_get_type (), NULL);
790 g_object_connect (test,
791 "signal::generic-marshaller-int-return",
792 G_CALLBACK (on_generic_marshaller_int_return_signed_1),
794 "object-signal::va-marshaller-int-return",
795 G_CALLBACK (on_generic_marshaller_int_return_signed_2),
798 g_signal_emit_by_name (test, "generic-marshaller-int-return", &retval);
799 g_assert_cmpint (retval, ==, -30);
800 g_signal_emit_by_name (test, "va-marshaller-int-return", &retval);
801 g_assert_cmpint (retval, ==, 2);
803 g_object_disconnect (test,
805 G_CALLBACK (on_generic_marshaller_int_return_signed_1),
807 "any-signal::va-marshaller-int-return",
808 G_CALLBACK (on_generic_marshaller_int_return_signed_2),
812 g_object_unref (test);
816 simple_handler1 (GObject *sender,
819 g_object_unref (target);
823 simple_handler2 (GObject *sender,
826 g_object_unref (target);
830 test_destroy_target_object (void)
832 Test *sender, *target1, *target2;
834 sender = g_object_new (test_get_type (), NULL);
835 target1 = g_object_new (test_get_type (), NULL);
836 target2 = g_object_new (test_get_type (), NULL);
837 g_signal_connect_object (sender, "simple", G_CALLBACK (simple_handler1), target1, 0);
838 g_signal_connect_object (sender, "simple", G_CALLBACK (simple_handler2), target2, 0);
839 g_signal_emit_by_name (sender, "simple");
840 g_object_unref (sender);
844 hook_func (GSignalInvocationHint *ihint,
846 const GValue *params,
857 test_emission_hook (void)
859 GObject *test1, *test2;
863 test1 = g_object_new (test_get_type (), NULL);
864 test2 = g_object_new (test_get_type (), NULL);
866 hook = g_signal_add_emission_hook (simple_id, 0, hook_func, &count, NULL);
867 g_assert_cmpint (count, ==, 0);
868 g_signal_emit_by_name (test1, "simple");
869 g_assert_cmpint (count, ==, 1);
870 g_signal_emit_by_name (test2, "simple");
871 g_assert_cmpint (count, ==, 2);
872 g_signal_remove_emission_hook (simple_id, hook);
873 g_signal_emit_by_name (test1, "simple");
874 g_assert_cmpint (count, ==, 2);
878 in_set (const gchar *s,
883 for (i = 0; set[i]; i++)
885 if (g_strcmp0 (s, set[i]) == 0)
893 test_introspection (void)
899 const gchar *names[] = {
901 "generic-marshaller-1",
902 "generic-marshaller-2",
903 "generic-marshaller-enum-return-signed",
904 "generic-marshaller-enum-return-unsigned",
905 "generic-marshaller-int-return",
906 "va-marshaller-int-return",
907 "generic-marshaller-uint-return",
908 "va-marshaller-uint-return",
909 "variant-changed-no-slot",
920 ids = g_signal_list_ids (test_get_type (), &n_ids);
921 g_assert_cmpuint (n_ids, ==, g_strv_length ((gchar**)names));
923 for (i = 0; i < n_ids; i++)
925 name = g_signal_name (ids[i]);
926 g_assert (in_set (name, names));
929 g_signal_query (simple_id, &query);
930 g_assert_cmpuint (query.signal_id, ==, simple_id);
931 g_assert_cmpstr (query.signal_name, ==, "simple");
932 g_assert (query.itype == test_get_type ());
933 g_assert (query.signal_flags == G_SIGNAL_RUN_LAST);
934 g_assert (query.return_type == G_TYPE_NONE);
935 g_assert_cmpuint (query.n_params, ==, 0);
939 test_handler (gpointer instance, gpointer data)
947 test_block_handler (void)
949 GObject *test1, *test2;
952 gulong handler1, handler;
954 test1 = g_object_new (test_get_type (), NULL);
955 test2 = g_object_new (test_get_type (), NULL);
957 handler1 = g_signal_connect (test1, "simple", G_CALLBACK (test_handler), &count1);
958 g_signal_connect (test2, "simple", G_CALLBACK (test_handler), &count2);
960 handler = g_signal_handler_find (test1, G_SIGNAL_MATCH_ID, simple_id, 0, NULL, NULL, NULL);
962 g_assert (handler == handler1);
964 g_assert_cmpint (count1, ==, 0);
965 g_assert_cmpint (count2, ==, 0);
967 g_signal_emit_by_name (test1, "simple");
968 g_signal_emit_by_name (test2, "simple");
970 g_assert_cmpint (count1, ==, 1);
971 g_assert_cmpint (count2, ==, 1);
973 g_signal_handler_block (test1, handler1);
975 g_signal_emit_by_name (test1, "simple");
976 g_signal_emit_by_name (test2, "simple");
978 g_assert_cmpint (count1, ==, 1);
979 g_assert_cmpint (count2, ==, 2);
981 g_signal_handler_unblock (test1, handler1);
983 g_signal_emit_by_name (test1, "simple");
984 g_signal_emit_by_name (test2, "simple");
986 g_assert_cmpint (count1, ==, 2);
987 g_assert_cmpint (count2, ==, 3);
989 g_assert_cmpuint (g_signal_handlers_block_matched (test1, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, test_block_handler, NULL), ==, 0);
990 g_assert_cmpuint (g_signal_handlers_block_matched (test2, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, test_handler, NULL), ==, 1);
992 g_signal_emit_by_name (test1, "simple");
993 g_signal_emit_by_name (test2, "simple");
995 g_assert_cmpint (count1, ==, 3);
996 g_assert_cmpint (count2, ==, 3);
998 g_signal_handlers_unblock_matched (test2, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, test_handler, NULL);
1000 g_object_unref (test1);
1001 g_object_unref (test2);
1005 stop_emission (gpointer instance, gpointer data)
1007 g_signal_stop_emission (instance, simple_id, 0);
1011 stop_emission_by_name (gpointer instance, gpointer data)
1013 g_signal_stop_emission_by_name (instance, "simple");
1017 dont_reach (gpointer instance, gpointer data)
1019 g_assert_not_reached ();
1023 test_stop_emission (void)
1028 test1 = g_object_new (test_get_type (), NULL);
1029 handler = g_signal_connect (test1, "simple", G_CALLBACK (stop_emission), NULL);
1030 g_signal_connect_after (test1, "simple", G_CALLBACK (dont_reach), NULL);
1032 g_signal_emit_by_name (test1, "simple");
1034 g_signal_handler_disconnect (test1, handler);
1035 g_signal_connect (test1, "simple", G_CALLBACK (stop_emission_by_name), NULL);
1037 g_signal_emit_by_name (test1, "simple");
1039 g_object_unref (test1);
1048 g_test_init (&argc, &argv, NULL);
1050 g_test_add_func ("/gobject/signals/all-types", test_all_types);
1051 g_test_add_func ("/gobject/signals/variant", test_variant_signal);
1052 g_test_add_func ("/gobject/signals/destroy-target-object", test_destroy_target_object);
1053 g_test_add_func ("/gobject/signals/generic-marshaller-1", test_generic_marshaller_signal_1);
1054 g_test_add_func ("/gobject/signals/generic-marshaller-2", test_generic_marshaller_signal_2);
1055 g_test_add_func ("/gobject/signals/generic-marshaller-enum-return-signed", test_generic_marshaller_signal_enum_return_signed);
1056 g_test_add_func ("/gobject/signals/generic-marshaller-enum-return-unsigned", test_generic_marshaller_signal_enum_return_unsigned);
1057 g_test_add_func ("/gobject/signals/generic-marshaller-int-return", test_generic_marshaller_signal_int_return);
1058 g_test_add_func ("/gobject/signals/generic-marshaller-uint-return", test_generic_marshaller_signal_uint_return);
1059 g_test_add_func ("/gobject/signals/connect", test_connect);
1060 g_test_add_func ("/gobject/signals/emission-hook", test_emission_hook);
1061 g_test_add_func ("/gobject/signals/introspection", test_introspection);
1062 g_test_add_func ("/gobject/signals/block-handler", test_block_handler);
1063 g_test_add_func ("/gobject/signals/stop-emission", test_stop_emission);
1065 return g_test_run ();