2 #include "everything.h"
5 gboolean test_boolean (gboolean in)
10 gint8 test_int8 (gint8 in)
15 guint8 test_uint8 (guint8 in)
20 gint16 test_int16 (gint16 in)
25 guint16 test_uint16 (guint16 in)
30 gint32 test_int32 (gint32 in)
35 guint32 test_uint32 (guint32 in)
40 gint64 test_int64 (gint64 in)
45 guint64 test_uint64 (guint64 in)
50 gshort test_short (gshort in)
55 gushort test_ushort (gushort in)
60 gint test_int (gint in)
65 guint test_uint (guint in)
70 glong test_long (glong in)
75 gulong test_ulong (gulong in)
80 gssize test_ssize (gssize in)
85 gsize test_size (gsize in)
90 gfloat test_float (gfloat in)
95 gdouble test_double (gdouble in)
101 time_t test_timet (time_t in)
106 GType test_gtype (GType in)
111 int test_closure (GClosure *closure)
113 GValue return_value = {0, };
116 g_value_init (&return_value, G_TYPE_INT);
118 g_closure_invoke (closure,
123 ret = g_value_get_int (&return_value);
125 g_value_unset(&return_value);
130 int test_closure_one_arg (GClosure *closure, int arg)
132 GValue return_value = {0, };
136 g_value_init (&return_value, G_TYPE_INT);
138 memset (&arguments[0], 0, sizeof (arguments));
139 g_value_init (&arguments[0], G_TYPE_INT);
140 g_value_set_int (&arguments[0], arg);
142 g_closure_invoke (closure,
147 ret = g_value_get_int (&return_value);
149 g_value_unset(&return_value);
150 g_value_unset(&arguments[0]);
157 * @v: (transfer none): a GValue expected to contain an int
159 * Return value: the int contained in the GValue.
161 int test_int_value_arg(const GValue *v) {
164 i = g_value_get_int (v);
174 * Return value: (transfer none): the int wrapped in a GValue.
176 const GValue *test_value_return(int i) {
177 memset(&value, '\0', sizeof(GValue));
179 g_value_init (&value, G_TYPE_INT);
180 g_value_set_int (&value, i);
186 /************************************************************************/
188 /* insert BLACK HEART SUIT to ensure UTF-8 doesn't get mangled */
189 static const char utf8_const[] = "const \xe2\x99\xa5 utf8";
190 static const char utf8_nonconst[] = "nonconst \xe2\x99\xa5 utf8";
193 * test_utf8_const_return:
194 * Return value: <const char*> UTF-8 string
196 G_CONST_RETURN char *test_utf8_const_return (void)
198 /* transfer mode none */
203 * test_utf8_nonconst_return:
204 * Return value: <char*> UTF-8 string
206 char *test_utf8_nonconst_return (void)
208 /* transfer mode full */
209 return g_strdup (utf8_nonconst);
212 void test_utf8_nonconst_in (char *in)
214 /* transfer mode full */
215 g_assert (strcmp (in, utf8_nonconst) == 0);
219 void test_utf8_const_in (const char *in)
221 /* transfer mode none */
222 g_assert (strcmp (in, utf8_const) == 0);
227 * @out: (out) (transfer full):
229 void test_utf8_out (char **out)
231 /* out parameter, transfer mode full */
232 *out = g_strdup (utf8_nonconst);
239 void test_utf8_inout (char **inout)
241 /* inout parameter, transfer mode full */
242 g_assert (strcmp (*inout, utf8_const) == 0);
244 *inout = g_strdup (utf8_nonconst);
248 * test_filename_return:
250 * Return value: (element-type filename) (transfer full): list of strings
252 GSList *test_filename_return (void)
254 GSList *filenames = NULL;
255 filenames = g_slist_prepend (filenames, g_filename_from_utf8("/etc/fstab", -1, NULL, NULL, NULL));
256 filenames = g_slist_prepend (filenames, g_filename_from_utf8("åäö", -1, NULL, NULL, NULL));
261 /* multiple output arguments */
264 * test_multi_double_args:
270 test_multi_double_args (gdouble in, gdouble *one, gdouble *two)
278 * @out0: (out) (transfer full): a copy of "first"
279 * @out1: (out) (transfer full): a copy of "second"
282 test_utf8_out_out (char **out0, char **out1)
284 *out0 = g_strdup ("first");
285 *out1 = g_strdup ("second");
289 * test_utf8_out_nonconst_return:
290 * @out: (out) (transfer full): a copy of "second"
292 * Returns: (transfer full): a copy of "first"
295 test_utf8_out_nonconst_return (char **out)
297 *out = g_strdup ("second");
298 return g_strdup ("first");
302 /* non-basic-types */
304 static const char *test_sequence[] = {"1", "2", "3"};
311 * @ints: (array length=n_ints): List of ints
314 test_array_int_in (int n_ints, int *ints)
317 for (i = 0; i < n_ints; i++)
323 * test_array_int_out:
324 * @n_ints: (out): the length of @ints
325 * @ints: (out) (array length=n_ints) (transfer full): a list of 5 integers, from 0 to 4 in consecutive order
328 test_array_int_out (int *n_ints, int **ints)
332 *ints = g_malloc0(sizeof(**ints) * *n_ints);
333 for (i = 1; i < *n_ints; i++)
334 (*ints)[i] = (*ints)[i-1] + 1;
338 * test_array_int_inout:
339 * @n_ints: (inout): the length of @ints
340 * @ints: (inout) (array length=n_ints) (transfer full): a list of integers whose items will be increased by 1, except the first that will be dropped
343 test_array_int_inout (int *n_ints, int **ints)
347 for (i = 1; i < *n_ints; i++) {
348 (*ints)[i-1] = (*ints)[i] + 1;
354 *ints = g_realloc(*ints, sizeof(**ints) * *n_ints);
358 * test_array_gint8_in:
360 * @ints: (array length=n_ints): List of ints
363 test_array_gint8_in (int n_ints, gint8 *ints)
366 for (i = 0; i < n_ints; i++)
372 * test_array_gint16_in:
374 * @ints: (array length=n_ints): List of ints
377 test_array_gint16_in (int n_ints, gint16 *ints)
380 for (i = 0; i < n_ints; i++)
386 * test_array_gint32_in:
388 * @ints: (array length=n_ints): List of ints
391 test_array_gint32_in (int n_ints, gint32 *ints)
395 for (i = 0; i < n_ints; i++)
401 * test_array_gint64_in:
403 * @ints: (array length=n_ints): List of ints
406 test_array_gint64_in (int n_ints, gint64 *ints)
410 for (i = 0; i < n_ints; i++)
417 * @arr: (array zero-terminated=1) (transfer none):
420 test_strv_in (char **arr)
422 if (g_strv_length (arr) != 3)
424 if (strcmp (arr[0], "1") != 0)
426 if (strcmp (arr[1], "2") != 0)
428 if (strcmp (arr[2], "3") != 0)
434 * test_strv_in_container:
435 * @arr: (array zero-terminated=1) (transfer container):
438 test_strv_in_container (char **arr)
440 gboolean result = test_strv_in (arr);
446 * test_array_gtype_in:
448 * @types: (array length=n_types): List of types
449 * Return value: string representation of provided types
452 test_array_gtype_in (int n_types, GType *types)
457 string = g_string_new ("[");
458 for (i = 0; i < n_types; i++)
460 g_string_append (string, g_type_name (types[i]));
461 g_string_append_c (string, ',');
463 g_string_append_c (string, ']');
464 return g_string_free (string, FALSE);
470 * No annotations here. We want the default to Do The Right Thing.
477 char **ret = g_new (char *, n);
478 ret[i++] = g_strdup ("thanks");
479 ret[i++] = g_strdup ("for");
480 ret[i++] = g_strdup ("all");
481 ret[i++] = g_strdup ("the");
482 ret[i++] = g_strdup ("fish");
489 * test_strv_out_container:
491 * Return value: (array zero-terminated=1) (transfer container):
494 test_strv_out_container (void)
496 char **ret = g_new (char *, 4);
506 * @retp: (array zero-terminated=1) (out) (transfer container):
509 test_strv_outarg (char ***retp)
511 char **ret = g_new (char *, 4);
520 * test_array_fixed_size_int_in:
521 * @ints: (array fixed-size=5): a list of 5 integers
523 * Returns: the sum of the items in @ints
526 test_array_fixed_size_int_in (int *ints)
529 for (i = 0; i < 5; i++)
535 * test_array_fixed_size_int_out:
536 * @ints: (out) (array fixed-size=5) (transfer full): a list of 5 integers ranging from 0 to 4
539 test_array_fixed_size_int_out (int **ints)
542 *ints = g_malloc0(sizeof(**ints) * 5);
543 for (i = 1; i < 5; i++)
544 (*ints)[i] = (*ints)[i-1] + 1;
548 * test_array_fixed_size_int_return:
549 * Returns: (array fixed-size=5) (transfer full): a list of 5 integers ranging from 0 to 4
552 test_array_fixed_size_int_return (void)
555 ints = g_malloc0(sizeof(*ints) * 5);
556 for (i = 1; i < 5; i++)
557 ints[i] = ints[i-1] + 1;
562 * test_array_int_in_take:
564 * @ints: (array length=n_ints) (transfer full): List of ints
566 int test_array_int_in_take (int n_ints, int *ints)
569 for (i = 0; i < n_ints; i++)
578 * No annotations here. We want the default to Do The Right Thing.
581 test_strv_out_c (void)
583 static char **ret = NULL;
586 ret = test_strv_out ();
588 return (const char * const *) ret;
592 * test_array_int_full_out:
593 * @len: length of the returned array.
594 * Returns: (array length=len) (transfer full): a new array of integers.
597 test_array_int_full_out(int *len) {
600 result = g_malloc0(sizeof(*result) * (*len));
601 for (i=1; i < (*len); i++)
602 result[i] = result[i-1] + 1;
607 * test_array_int_none_out:
608 * @len: length of the returned array.
609 * Returns: (array length=len) (transfer none): a static array of integers.
612 test_array_int_none_out(int *len) {
613 static int result[5] = { 1, 2, 3, 4, 5 };
620 /************************************************************************/
623 static /*const*/ GList *test_sequence_list()
625 static GList *list = NULL;
628 for (i = 0; i < G_N_ELEMENTS(test_sequence); ++i) {
629 list = g_list_prepend (list, (gpointer)test_sequence[i]);
631 list = g_list_reverse (list);
638 * @in: (element-type utf8) (transfer full):
640 void test_glist_free (GList *in)
642 g_list_foreach (in, (GFunc)g_free, NULL);
647 * test_glist_nothing_return:
649 * Return value: (element-type utf8) (transfer none):
651 G_CONST_RETURN GList *test_glist_nothing_return (void)
653 return test_sequence_list ();
657 * test_glist_nothing_return2:
659 * Return value: (element-type utf8) (transfer none):
661 GList *test_glist_nothing_return2 (void)
663 return test_sequence_list ();
667 * test_glist_container_return:
669 * Return value: (element-type utf8) (transfer container):
671 GList *test_glist_container_return (void)
673 return g_list_copy (test_sequence_list ());
677 * test_glist_everything_return:
679 * Return value: (element-type utf8) (transfer full):
681 GList *test_glist_everything_return (void)
686 list = g_list_copy (test_sequence_list ());
687 for (l = list; l != NULL; l = l->next)
688 l->data = g_strdup (l->data);
692 static void assert_test_sequence_list (const GList *in)
697 for (i = 0, l = in; l != NULL; ++i, l = l->next) {
698 g_assert (i < G_N_ELEMENTS(test_sequence));
699 g_assert (strcmp (l->data, test_sequence[i]) == 0);
701 g_assert (i == G_N_ELEMENTS(test_sequence));
705 * test_glist_nothing_in:
706 * @in: (element-type utf8):
708 void test_glist_nothing_in (const GList *in)
710 assert_test_sequence_list (in);
714 * test_glist_nothing_in2:
715 * @in: (element-type utf8):
717 void test_glist_nothing_in2 (GList *in)
719 assert_test_sequence_list (in);
723 * test_glist_container_in:
724 * @in: (element-type utf8) (transfer container):
726 void test_glist_container_in (GList *in)
728 assert_test_sequence_list (in);
733 * test_glist_everything_in:
734 * @in: (element-type utf8) (transfer full):
736 void test_glist_everything_in (GList *in)
738 assert_test_sequence_list (in);
739 test_glist_free (in);
742 /************************************************************************/
745 static /*const*/ GSList *test_sequence_slist()
747 static GSList *list = NULL;
750 for (i = 0; i < G_N_ELEMENTS(test_sequence); ++i) {
751 list = g_slist_prepend (list, (gpointer)test_sequence[i]);
753 list = g_slist_reverse (list);
760 * @in: (element-type utf8) (transfer full):
762 void test_gslist_free (GSList *in)
764 g_slist_foreach (in, (GFunc)g_free, NULL);
769 * test_gslist_nothing_return:
771 * Return value: (element-type utf8) (transfer none):
773 G_CONST_RETURN GSList *test_gslist_nothing_return (void)
775 return test_sequence_slist ();
779 * test_gslist_nothing_return2:
781 * Return value: (element-type utf8) (transfer none):
783 GSList *test_gslist_nothing_return2 (void)
785 return test_sequence_slist ();
789 * test_gslist_container_return:
791 * Return value: (element-type utf8) (transfer container):
793 GSList *test_gslist_container_return (void)
795 return g_slist_copy (test_sequence_slist ());
799 * test_gslist_everything_return:
801 * Return value: (element-type utf8) (transfer full):
803 GSList *test_gslist_everything_return (void)
808 list = g_slist_copy (test_sequence_slist ());
809 for (l = list; l != NULL; l = l->next)
810 l->data = g_strdup (l->data);
814 static void assert_test_sequence_slist (const GSList *in)
819 for (i = 0, l = in; l != NULL; ++i, l = l->next) {
820 g_assert (i < G_N_ELEMENTS(test_sequence));
821 g_assert (strcmp (l->data, test_sequence[i]) == 0);
823 g_assert (i == G_N_ELEMENTS(test_sequence));
827 * test_gslist_nothing_in:
828 * @in: (element-type utf8):
830 void test_gslist_nothing_in (const GSList *in)
832 assert_test_sequence_slist (in);
836 * test_gslist_nothing_in2:
837 * @in: (element-type utf8):
839 void test_gslist_nothing_in2 (GSList *in)
841 assert_test_sequence_slist (in);
845 * test_gslist_container_in:
846 * @in: (element-type utf8) (transfer container):
848 void test_gslist_container_in (GSList *in)
850 assert_test_sequence_slist (in);
855 * test_gslist_everything_in:
856 * @in: (element-type utf8) (transfer full):
858 void test_gslist_everything_in (GSList *in)
860 assert_test_sequence_slist (in);
861 test_gslist_free (in);
864 /************************************************************************/
867 static char *table_data[3][2] = {
868 { "foo", "bar" }, { "baz", "bat" }, { "qux", "quux" }
871 static GHashTable *test_table_ghash_new_container()
875 hash = g_hash_table_new(g_str_hash, g_str_equal);
877 g_hash_table_insert(hash, table_data[i][0], table_data[i][1]);
881 static GHashTable *test_table_ghash_new_full()
885 hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
887 g_hash_table_insert(hash,
888 g_strdup(table_data[i][0]),
889 g_strdup(table_data[i][1]));
893 static /*const*/ GHashTable *test_table_ghash_const()
895 static GHashTable *hash = NULL;
897 hash = test_table_ghash_new_container();
904 * @in: (transfer full) (element-type utf8 utf8)
906 void test_ghash_free (GHashTable *in)
908 /* keys and values are deleted iff an appropriate element destroy function
910 g_hash_table_unref(in);
914 * test_ghash_null_return:
916 * Return value: (element-type utf8 utf8) (transfer none) (allow-none):
918 G_CONST_RETURN GHashTable *test_ghash_null_return (void)
924 * test_ghash_nothing_return:
926 * Return value: (element-type utf8 utf8) (transfer none):
928 G_CONST_RETURN GHashTable *test_ghash_nothing_return (void)
930 return test_table_ghash_const ();
934 * test_ghash_nothing_return2:
936 * Return value: (element-type utf8 utf8) (transfer none):
938 GHashTable *test_ghash_nothing_return2 (void)
940 return test_table_ghash_const ();
944 * test_ghash_container_return:
946 * Return value: (element-type utf8 utf8) (transfer container):
948 GHashTable *test_ghash_container_return (void)
950 return test_table_ghash_new_container ();
954 * test_ghash_everything_return:
956 * Return value: (element-type utf8 utf8) (transfer full):
958 GHashTable *test_ghash_everything_return (void)
960 return test_table_ghash_new_full ();
963 static void assert_test_table_ghash (const GHashTable *in)
965 GHashTable *h = test_table_ghash_const();
969 g_assert(g_hash_table_size(h) ==
970 g_hash_table_size((GHashTable*)in));
972 g_hash_table_iter_init(&iter, (GHashTable*)in);
973 while (g_hash_table_iter_next (&iter, &key, &value))
974 g_assert( strcmp(g_hash_table_lookup(h, (char*)key), (char*)value) == 0);
978 * test_ghash_null_in:
979 * @in: (element-type utf8 utf8) (allow-none):
981 void test_ghash_null_in (const GHashTable *in)
983 g_assert (in == NULL);
987 * test_ghash_nothing_in:
988 * @in: (element-type utf8 utf8):
990 void test_ghash_nothing_in (const GHashTable *in)
992 assert_test_table_ghash (in);
996 * test_ghash_nothing_in2:
997 * @in: (element-type utf8 utf8):
999 void test_ghash_nothing_in2 (GHashTable *in)
1001 assert_test_table_ghash (in);
1005 * test_ghash_container_in:
1006 * @in: (transfer container) (element-type utf8 utf8):
1008 void test_ghash_container_in (GHashTable *in)
1010 assert_test_table_ghash (in);
1011 /* be careful and explicitly steal all the elements from the ghash before
1013 g_hash_table_steal_all (in);
1014 g_hash_table_destroy (in);
1017 static gboolean ghash_freer(gpointer key, gpointer value, gpointer user_data) {
1024 * test_ghash_everything_in:
1025 * @in: (transfer full) (element-type utf8 utf8):
1027 void test_ghash_everything_in (GHashTable *in)
1029 assert_test_table_ghash (in);
1030 /* free the elements, then free the container. Don't rely on the
1031 * GHashTable's key/value destructor functions. */
1032 g_hash_table_foreach_steal (in, ghash_freer, NULL);
1033 /* okay, dealloc the hash table. */
1034 g_hash_table_destroy (in);
1037 /* Nested collection types */
1040 * test_ghash_nested_everything_return:
1041 * Specify nested parameterized types directly with the (type ) annotation.
1043 * Return value: (type GLib.HashTable<utf8,GLib.HashTable<utf8,utf8>>) (transfer full):
1046 test_ghash_nested_everything_return (void)
1049 hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
1050 (void (*) (gpointer)) g_hash_table_destroy);
1051 g_hash_table_insert(hash, g_strdup("wibble"), test_table_ghash_new_full());
1056 * test_ghash_nested_everything_return2:
1057 * Another way of specifying nested parameterized types: using the
1058 * element-type annotation.
1060 * Return value: (element-type utf8 GLib.HashTable<utf8,utf8>) (transfer full):
1063 test_ghash_nested_everything_return2 (void)
1065 return test_ghash_nested_everything_return();
1068 /************************************************************************/
1075 test_enum_get_type (void)
1077 static GType etype = 0;
1078 if (G_UNLIKELY(etype == 0)) {
1079 static const GEnumValue values[] = {
1080 { TEST_VALUE1, "TEST_VALUE1", "value1" },
1081 { TEST_VALUE2, "TEST_VALUE2", "value2" },
1082 { TEST_VALUE3, "TEST_VALUE3", "value3" },
1085 etype = g_enum_register_static (g_intern_static_string ("TestEnum"), values);
1092 test_flags_get_type (void)
1094 static GType etype = 0;
1095 if (G_UNLIKELY(etype == 0)) {
1096 static const GFlagsValue values[] = {
1097 { TEST_FLAG1, "TEST_FLAG1", "flag1" },
1098 { TEST_FLAG2, "TEST_FLAG2", "flag2" },
1099 { TEST_FLAG3, "TEST_FLAG3", "flag3" },
1102 etype = g_flags_register_static (g_intern_static_string ("TestFlags"), values);
1109 test_enum_param(TestEnum e)
1114 ec = g_type_class_ref (test_enum_get_type ());
1115 ev = g_enum_get_value (ec, e);
1116 g_type_class_unref (ec);
1118 return ev->value_nick;
1124 * test_struct_a_clone:
1126 * @a_out: the cloned structure
1128 * Make a copy of a TestStructA
1131 test_struct_a_clone (TestStructA *a,
1138 * test_struct_b_clone:
1140 * @b_out: the cloned structure
1142 * Make a copy of a TestStructB
1145 test_struct_b_clone (TestStructB *b,
1151 /* plain-old-data boxed types */
1154 test_simple_boxed_a_copy (TestSimpleBoxedA *a)
1156 TestSimpleBoxedA *new_a = g_slice_new (TestSimpleBoxedA);
1164 test_simple_boxed_a_free (TestSimpleBoxedA *a)
1166 g_slice_free (TestSimpleBoxedA, a);
1170 test_simple_boxed_a_get_type (void)
1172 static GType our_type = 0;
1175 our_type = g_boxed_type_register_static (g_intern_static_string ("TestSimpleBoxedA"),
1176 (GBoxedCopyFunc)test_simple_boxed_a_copy,
1177 (GBoxedFreeFunc)test_simple_boxed_a_free);
1182 test_simple_boxed_b_copy (TestSimpleBoxedB *b)
1184 TestSimpleBoxedB *new_b = g_slice_new (TestSimpleBoxedB);
1192 test_simple_boxed_a_equals (TestSimpleBoxedA *a,
1193 TestSimpleBoxedA *other_a)
1195 return (a->some_int == other_a->some_int &&
1196 a->some_int8 == other_a->some_int8 &&
1197 a->some_double == other_a->some_double);
1200 const TestSimpleBoxedA*
1201 test_simple_boxed_a_const_return (void)
1203 static TestSimpleBoxedA simple_a = {
1211 test_simple_boxed_b_free (TestSimpleBoxedB *a)
1213 g_slice_free (TestSimpleBoxedB, a);
1217 test_simple_boxed_b_get_type (void)
1219 static GType our_type = 0;
1222 our_type = g_boxed_type_register_static (g_intern_static_string ("TestSimpleBoxedB"),
1223 (GBoxedCopyFunc)test_simple_boxed_b_copy,
1224 (GBoxedFreeFunc)test_simple_boxed_b_free);
1230 struct _TestBoxedPrivate
1236 test_boxed_new (void)
1238 TestBoxed *boxed = g_slice_new0(TestBoxed);
1239 boxed->priv = g_slice_new0(TestBoxedPrivate);
1240 boxed->priv->magic = 0xdeadbeef;
1246 test_boxed_copy (TestBoxed *boxed)
1248 TestBoxed *new_boxed = test_boxed_new();
1249 TestBoxedPrivate *save;
1251 save = new_boxed->priv;
1252 *new_boxed = *boxed;
1253 new_boxed->priv = save;
1259 test_boxed_equals (TestBoxed *boxed,
1262 return (other->some_int8 == boxed->some_int8 &&
1263 test_simple_boxed_a_equals(&other->nested_a, &boxed->nested_a));
1267 test_boxed_free (TestBoxed *boxed)
1269 g_assert (boxed->priv->magic == 0xdeadbeef);
1271 g_slice_free (TestBoxedPrivate, boxed->priv);
1272 g_slice_free (TestBoxed, boxed);
1276 test_boxed_get_type (void)
1278 static GType our_type = 0;
1281 our_type = g_boxed_type_register_static (g_intern_static_string ("TestBoxed"),
1282 (GBoxedCopyFunc)test_boxed_copy,
1283 (GBoxedFreeFunc)test_boxed_free);
1287 G_DEFINE_TYPE(TestObj, test_obj, G_TYPE_OBJECT);
1291 PROP_TEST_OBJ_BARE = 1,
1296 test_obj_set_property (GObject *object,
1298 const GValue *value,
1301 TestObj *self = TEST_OBJECT (object);
1303 switch (property_id)
1305 case PROP_TEST_OBJ_BARE:
1306 test_obj_set_bare (self, g_value_get_object (value));
1309 case PROP_TEST_OBJ_BOXED:
1311 test_boxed_free (self->boxed);
1312 self->boxed = g_value_dup_boxed (value);
1316 /* We don't have any other property... */
1317 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1323 test_obj_get_property (GObject *object,
1328 TestObj *self = TEST_OBJECT (object);
1330 switch (property_id)
1332 case PROP_TEST_OBJ_BARE:
1333 g_value_set_object (value, self->bare);
1336 case PROP_TEST_OBJ_BOXED:
1337 g_value_set_boxed (value, self->boxed);
1341 /* We don't have any other property... */
1342 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1348 test_obj_dispose (GObject *gobject)
1350 TestObj *self = TEST_OBJECT (gobject);
1354 g_object_unref (self->bare);
1361 test_boxed_free (self->boxed);
1365 /* Chain up to the parent class */
1366 G_OBJECT_CLASS (test_obj_parent_class)->dispose (gobject);
1370 test_obj_default_matrix (TestObj *obj, const char *somestr)
1376 test_obj_class_init (TestObjClass *klass)
1378 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1380 GType param_types[1];
1382 klass->test_signal =
1383 g_signal_newv ("test",
1384 G_TYPE_FROM_CLASS (gobject_class),
1385 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1387 NULL /* accumulator */,
1388 NULL /* accumulator data */,
1389 g_cclosure_marshal_VOID__VOID,
1390 G_TYPE_NONE /* return_type */,
1392 NULL /* param_types */);
1394 param_types[0] = test_simple_boxed_a_get_type() | G_SIGNAL_TYPE_STATIC_SCOPE;
1395 klass->test_signal_with_static_scope_arg =
1396 g_signal_newv ("test-with-static-scope-arg",
1397 G_TYPE_FROM_CLASS (gobject_class),
1398 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1400 NULL /* accumulator */,
1401 NULL /* accumulator data */,
1402 g_cclosure_marshal_VOID__BOXED,
1403 G_TYPE_NONE /* return_type */,
1407 gobject_class->set_property = test_obj_set_property;
1408 gobject_class->get_property = test_obj_get_property;
1409 gobject_class->dispose = test_obj_dispose;
1411 pspec = g_param_spec_object ("bare",
1413 "A contained object",
1416 g_object_class_install_property (gobject_class,
1420 pspec = g_param_spec_boxed ("boxed",
1422 "A contained boxed struct",
1425 g_object_class_install_property (gobject_class,
1426 PROP_TEST_OBJ_BOXED,
1429 klass->matrix = test_obj_default_matrix;
1433 test_obj_init (TestObj *obj)
1440 test_obj_new_from_file (const char *x, GError **error)
1442 return g_object_new (TEST_TYPE_OBJ, NULL);
1446 * test_obj_set_bare:
1447 * @bare: (allow-none):
1450 test_obj_set_bare (TestObj *obj, GObject *bare)
1453 g_object_unref (obj->bare);
1456 g_object_ref (obj->bare);
1460 test_obj_instance_method (TestObj *obj)
1466 test_obj_static_method (int x)
1472 * test_obj_do_matrix:
1474 * @somestr: Meaningless string
1476 * This method is virtual. Notably its name differs from the virtual
1477 * slot name, which makes it useful for testing bindings handle this
1483 test_obj_do_matrix (TestObj *obj, const char *somestr)
1485 return TEST_OBJ_GET_CLASS (obj)->matrix (obj, somestr);
1488 typedef struct _CallbackInfo CallbackInfo;
1490 struct _CallbackInfo
1492 TestCallbackUserData callback;
1493 GDestroyNotify notify;
1498 G_DEFINE_TYPE(TestSubObj, test_sub_obj, TEST_TYPE_OBJ);
1501 test_sub_obj_class_init (TestSubObjClass *klass)
1506 test_sub_obj_init (TestSubObj *obj)
1513 return g_object_new (TEST_TYPE_SUB_OBJ, NULL);
1517 test_sub_obj_instance_method (TestSubObj *obj)
1523 test_sub_obj_unset_bare (TestSubObj *obj)
1525 test_obj_set_bare(TEST_OBJECT(obj), NULL);
1531 * @callback: (scope call) (allow-none):
1535 test_callback (TestCallback callback)
1537 if (callback != NULL)
1543 * test_callback_user_data:
1544 * @callback: (scope call):
1546 * Call - callback parameter persists for the duration of the method
1547 * call and can be released on return.
1550 test_callback_user_data (TestCallbackUserData callback,
1553 return callback(user_data);
1556 static GSList *notified_callbacks = NULL;
1559 * test_callback_destroy_notify:
1560 * @callback: (scope notified):
1562 * Notified - callback persists until a DestroyNotify delegate
1566 test_callback_destroy_notify (TestCallbackUserData callback,
1568 GDestroyNotify notify)
1573 retval = callback(user_data);
1575 info = g_slice_new(CallbackInfo);
1576 info->callback = callback;
1577 info->notify = notify;
1578 info->user_data = user_data;
1580 notified_callbacks = g_slist_prepend(notified_callbacks, info);
1586 * test_callback_thaw_notifications:
1588 * Invokes all callbacks installed by #test_callback_destroy_notify(),
1589 * adding up their return values, and removes them, invoking the
1590 * corresponding destroy notfications.
1592 * Return value: Sum of the return values of the invoked callbacks.
1595 test_callback_thaw_notifications (void)
1600 for (node = notified_callbacks; node != NULL; node = node->next)
1602 CallbackInfo *info = node->data;
1603 retval += info->callback (info->user_data);
1605 info->notify (info->user_data);
1606 g_slice_free (CallbackInfo, info);
1609 g_slist_free (notified_callbacks);
1610 notified_callbacks = NULL;
1615 static GSList *async_callbacks = NULL;
1618 * test_callback_async:
1619 * @callback: (scope async):
1623 test_callback_async (TestCallbackUserData callback,
1628 info = g_slice_new(CallbackInfo);
1629 info->callback = callback;
1630 info->user_data = user_data;
1632 async_callbacks = g_slist_prepend(async_callbacks, info);
1636 * test_callback_thaw_async:
1639 test_callback_thaw_async (void)
1644 for (node = async_callbacks; node != NULL; node = node->next)
1646 CallbackInfo *info = node->data;
1647 retval = info->callback (info->user_data);
1648 g_slice_free (CallbackInfo, info);
1651 g_slist_free (async_callbacks);
1652 async_callbacks = NULL;
1657 * test_callback_infinite:
1658 * @callback: (scope infinite):
1660 * Infinite - callback persists forever.
1663 static GSList *infinite_callbacks = NULL;
1666 test_callback_infinite (TestCallbackUserData callback,
1669 infinite_callbacks = g_slist_prepend(infinite_callbacks, callback);
1671 return callback(user_data);
1677 test_interface_class_init(void *g_iface)
1682 test_interface_get_type(void)
1684 static GType type = 0;
1686 type = g_type_register_static_simple (G_TYPE_INTERFACE,
1687 "EverythingTestInterface",
1688 sizeof (TestInterfaceIface),
1689 (GClassInitFunc) test_interface_class_init,
1696 /* gobject with non-standard prefix */
1697 G_DEFINE_TYPE(TestWi8021x, test_wi_802_1x, G_TYPE_OBJECT);
1701 PROP_TEST_WI_802_1X_TESTBOOL = 1
1705 test_wi_802_1x_set_property (GObject *object,
1707 const GValue *value,
1710 TestWi8021x *self = TEST_WI_802_1X (object);
1712 switch (property_id)
1714 case PROP_TEST_WI_802_1X_TESTBOOL:
1715 test_wi_802_1x_set_testbool (self, g_value_get_boolean (value));
1719 /* We don't have any other property... */
1720 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1726 test_wi_802_1x_get_property (GObject *object,
1731 TestWi8021x *self = TEST_WI_802_1X (object);
1733 switch (property_id)
1735 case PROP_TEST_WI_802_1X_TESTBOOL:
1736 g_value_set_boolean (value, test_wi_802_1x_get_testbool (self));
1740 /* We don't have any other property... */
1741 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1747 test_wi_802_1x_dispose (GObject *gobject)
1749 /* Chain up to the parent class */
1750 G_OBJECT_CLASS (test_wi_802_1x_parent_class)->dispose (gobject);
1754 test_wi_802_1x_class_init (TestWi8021xClass *klass)
1756 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1759 gobject_class->set_property = test_wi_802_1x_set_property;
1760 gobject_class->get_property = test_wi_802_1x_get_property;
1761 gobject_class->dispose = test_wi_802_1x_dispose;
1763 pspec = g_param_spec_boolean ("testbool",
1764 "Nick for testbool",
1765 "Blurb for testbool",
1768 g_object_class_install_property (gobject_class,
1769 PROP_TEST_WI_802_1X_TESTBOOL,
1774 test_wi_802_1x_init (TestWi8021x *obj)
1776 obj->testbool = TRUE;
1780 test_wi_802_1x_new (void)
1782 return g_object_new (TEST_TYPE_WI_802_1X, NULL);
1786 test_wi_802_1x_set_testbool (TestWi8021x *obj, gboolean val)
1788 obj->testbool = val;
1792 test_wi_802_1x_get_testbool (TestWi8021x *obj)
1794 return obj->testbool;
1798 test_wi_802_1x_static_method (int x)