3 #include "everything.h"
7 gboolean test_boolean (gboolean in)
12 gint8 test_int8 (gint8 in)
17 guint8 test_uint8 (guint8 in)
22 gint16 test_int16 (gint16 in)
27 guint16 test_uint16 (guint16 in)
32 gint32 test_int32 (gint32 in)
37 guint32 test_uint32 (guint32 in)
42 gint64 test_int64 (gint64 in)
47 guint64 test_uint64 (guint64 in)
52 gshort test_short (gshort in)
57 gushort test_ushort (gushort in)
62 gint test_int (gint in)
67 guint test_uint (guint in)
72 glong test_long (glong in)
77 gulong test_ulong (gulong in)
82 gssize test_ssize (gssize in)
87 gsize test_size (gsize in)
92 gfloat test_float (gfloat in)
97 gdouble test_double (gdouble in)
103 time_t test_timet (time_t in)
108 GType test_gtype (GType in)
113 int test_closure (GClosure *closure)
115 GValue return_value = {0, };
118 g_value_init (&return_value, G_TYPE_INT);
120 g_closure_invoke (closure,
125 ret = g_value_get_int (&return_value);
127 g_value_unset(&return_value);
132 int test_closure_one_arg (GClosure *closure, int arg)
134 GValue return_value = {0, };
138 g_value_init (&return_value, G_TYPE_INT);
140 memset (&arguments[0], 0, sizeof (arguments));
141 g_value_init (&arguments[0], G_TYPE_INT);
142 g_value_set_int (&arguments[0], arg);
144 g_closure_invoke (closure,
149 ret = g_value_get_int (&return_value);
151 g_value_unset(&return_value);
152 g_value_unset(&arguments[0]);
159 * @v: (transfer none): a GValue expected to contain an int
161 * Return value: the int contained in the GValue.
163 int test_int_value_arg(const GValue *v) {
166 i = g_value_get_int (v);
176 * Return value: (transfer none): the int wrapped in a GValue.
178 const GValue *test_value_return(int i) {
179 memset(&value, '\0', sizeof(GValue));
181 g_value_init (&value, G_TYPE_INT);
182 g_value_set_int (&value, i);
188 /************************************************************************/
190 /* insert BLACK HEART SUIT to ensure UTF-8 doesn't get mangled */
191 static const char utf8_const[] = "const \xe2\x99\xa5 utf8";
192 static const char utf8_nonconst[] = "nonconst \xe2\x99\xa5 utf8";
195 * test_utf8_const_return:
196 * Return value: <const char*> UTF-8 string
198 G_CONST_RETURN char *test_utf8_const_return (void)
200 /* transfer mode none */
205 * test_utf8_nonconst_return:
206 * Return value: <char*> UTF-8 string
208 char *test_utf8_nonconst_return (void)
210 /* transfer mode full */
211 return g_strdup (utf8_nonconst);
214 void test_utf8_nonconst_in (char *in)
216 /* transfer mode full */
217 g_assert (strcmp (in, utf8_nonconst) == 0);
221 void test_utf8_const_in (const char *in)
223 /* transfer mode none */
224 g_assert (strcmp (in, utf8_const) == 0);
229 * @out: (out) (transfer full):
231 void test_utf8_out (char **out)
233 /* out parameter, transfer mode full */
234 *out = g_strdup (utf8_nonconst);
241 void test_utf8_inout (char **inout)
243 /* inout parameter, transfer mode full */
244 g_assert (strcmp (*inout, utf8_const) == 0);
246 *inout = g_strdup (utf8_nonconst);
250 * test_filename_return:
252 * Return value: (element-type filename) (transfer full): list of strings
254 GSList *test_filename_return (void)
256 GSList *filenames = NULL;
257 filenames = g_slist_prepend (filenames, g_filename_from_utf8("/etc/fstab", -1, NULL, NULL, NULL));
258 filenames = g_slist_prepend (filenames, g_filename_from_utf8("åäö", -1, NULL, NULL, NULL));
262 /* in arguments after out arguments */
270 test_int_out_utf8 (int *length, const char *in)
272 *length = g_utf8_strlen(in, -1);
276 /* multiple output arguments */
279 * test_multi_double_args:
285 test_multi_double_args (gdouble in, gdouble *one, gdouble *two)
293 * @out0: (out) (transfer full): a copy of "first"
294 * @out1: (out) (transfer full): a copy of "second"
297 test_utf8_out_out (char **out0, char **out1)
299 *out0 = g_strdup ("first");
300 *out1 = g_strdup ("second");
304 * test_utf8_out_nonconst_return:
305 * @out: (out) (transfer full): a copy of "second"
307 * Returns: (transfer full): a copy of "first"
310 test_utf8_out_nonconst_return (char **out)
312 *out = g_strdup ("second");
313 return g_strdup ("first");
317 /* non-basic-types */
319 static const char *test_sequence[] = {"1", "2", "3"};
326 * @ints: (array length=n_ints): List of ints
329 test_array_int_in (int n_ints, int *ints)
332 for (i = 0; i < n_ints; i++)
338 * test_array_int_out:
339 * @n_ints: (out): the length of @ints
340 * @ints: (out) (array length=n_ints) (transfer full): a list of 5 integers, from 0 to 4 in consecutive order
343 test_array_int_out (int *n_ints, int **ints)
347 *ints = g_malloc0(sizeof(**ints) * *n_ints);
348 for (i = 1; i < *n_ints; i++)
349 (*ints)[i] = (*ints)[i-1] + 1;
353 * test_array_int_inout:
354 * @n_ints: (inout): the length of @ints
355 * @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
358 test_array_int_inout (int *n_ints, int **ints)
362 for (i = 1; i < *n_ints; i++) {
363 (*ints)[i-1] = (*ints)[i] + 1;
369 *ints = g_realloc(*ints, sizeof(**ints) * *n_ints);
373 * test_array_gint8_in:
375 * @ints: (array length=n_ints): List of ints
378 test_array_gint8_in (int n_ints, gint8 *ints)
381 for (i = 0; i < n_ints; i++)
387 * test_array_gint16_in:
389 * @ints: (array length=n_ints): List of ints
392 test_array_gint16_in (int n_ints, gint16 *ints)
395 for (i = 0; i < n_ints; i++)
401 * test_array_gint32_in:
403 * @ints: (array length=n_ints): List of ints
406 test_array_gint32_in (int n_ints, gint32 *ints)
410 for (i = 0; i < n_ints; i++)
416 * test_array_gint64_in:
418 * @ints: (array length=n_ints): List of ints
421 test_array_gint64_in (int n_ints, gint64 *ints)
425 for (i = 0; i < n_ints; i++)
432 * @arr: (array zero-terminated=1) (transfer none):
435 test_strv_in (char **arr)
437 if (g_strv_length (arr) != 3)
439 if (strcmp (arr[0], "1") != 0)
441 if (strcmp (arr[1], "2") != 0)
443 if (strcmp (arr[2], "3") != 0)
449 * test_strv_in_container:
450 * @arr: (array zero-terminated=1) (transfer container):
453 test_strv_in_container (char **arr)
455 gboolean result = test_strv_in (arr);
461 * test_array_gtype_in:
463 * @types: (array length=n_types): List of types
464 * Return value: string representation of provided types
467 test_array_gtype_in (int n_types, GType *types)
472 string = g_string_new ("[");
473 for (i = 0; i < n_types; i++)
475 g_string_append (string, g_type_name (types[i]));
476 g_string_append_c (string, ',');
478 g_string_append_c (string, ']');
479 return g_string_free (string, FALSE);
485 * No annotations here. We want the default to Do The Right Thing.
492 char **ret = g_new (char *, n);
493 ret[i++] = g_strdup ("thanks");
494 ret[i++] = g_strdup ("for");
495 ret[i++] = g_strdup ("all");
496 ret[i++] = g_strdup ("the");
497 ret[i++] = g_strdup ("fish");
504 * test_strv_out_container:
506 * Return value: (array zero-terminated=1) (transfer container):
509 test_strv_out_container (void)
511 char **ret = g_new (char *, 4);
521 * @retp: (array zero-terminated=1) (out) (transfer container):
524 test_strv_outarg (char ***retp)
526 char **ret = g_new (char *, 4);
535 * test_array_fixed_size_int_in:
536 * @ints: (array fixed-size=5): a list of 5 integers
538 * Returns: the sum of the items in @ints
541 test_array_fixed_size_int_in (int *ints)
544 for (i = 0; i < 5; i++)
550 * test_array_fixed_size_int_out:
551 * @ints: (out) (array fixed-size=5) (transfer full): a list of 5 integers ranging from 0 to 4
554 test_array_fixed_size_int_out (int **ints)
557 *ints = g_malloc0(sizeof(**ints) * 5);
558 for (i = 1; i < 5; i++)
559 (*ints)[i] = (*ints)[i-1] + 1;
563 * test_array_fixed_size_int_return:
564 * Returns: (array fixed-size=5) (transfer full): a list of 5 integers ranging from 0 to 4
567 test_array_fixed_size_int_return (void)
570 ints = g_malloc0(sizeof(*ints) * 5);
571 for (i = 1; i < 5; i++)
572 ints[i] = ints[i-1] + 1;
577 * test_array_int_in_take:
579 * @ints: (array length=n_ints) (transfer full): List of ints
581 int test_array_int_in_take (int n_ints, int *ints)
584 for (i = 0; i < n_ints; i++)
593 * No annotations here. We want the default to Do The Right Thing.
596 test_strv_out_c (void)
598 static char **ret = NULL;
601 ret = test_strv_out ();
603 return (const char * const *) ret;
607 * test_array_int_full_out:
608 * @len: length of the returned array.
609 * Returns: (array length=len) (transfer full): a new array of integers.
612 test_array_int_full_out(int *len) {
615 result = g_malloc0(sizeof(*result) * (*len));
616 for (i=1; i < (*len); i++)
617 result[i] = result[i-1] + 1;
622 * test_array_int_none_out:
623 * @len: length of the returned array.
624 * Returns: (array length=len) (transfer none): a static array of integers.
627 test_array_int_none_out(int *len) {
628 static int result[5] = { 1, 2, 3, 4, 5 };
635 /************************************************************************/
638 static /*const*/ GList *test_sequence_list()
640 static GList *list = NULL;
643 for (i = 0; i < G_N_ELEMENTS(test_sequence); ++i) {
644 list = g_list_prepend (list, (gpointer)test_sequence[i]);
646 list = g_list_reverse (list);
653 * @in: (element-type utf8) (transfer full):
655 void test_glist_free (GList *in)
657 g_list_foreach (in, (GFunc)g_free, NULL);
662 * test_glist_nothing_return:
664 * Return value: (element-type utf8) (transfer none):
666 G_CONST_RETURN GList *test_glist_nothing_return (void)
668 return test_sequence_list ();
672 * test_glist_nothing_return2:
674 * Return value: (element-type utf8) (transfer none):
676 GList *test_glist_nothing_return2 (void)
678 return test_sequence_list ();
682 * test_glist_container_return:
684 * Return value: (element-type utf8) (transfer container):
686 GList *test_glist_container_return (void)
688 return g_list_copy (test_sequence_list ());
692 * test_glist_everything_return:
694 * Return value: (element-type utf8) (transfer full):
696 GList *test_glist_everything_return (void)
701 list = g_list_copy (test_sequence_list ());
702 for (l = list; l != NULL; l = l->next)
703 l->data = g_strdup (l->data);
707 static void assert_test_sequence_list (const GList *in)
712 for (i = 0, l = in; l != NULL; ++i, l = l->next) {
713 g_assert (i < G_N_ELEMENTS(test_sequence));
714 g_assert (strcmp (l->data, test_sequence[i]) == 0);
716 g_assert (i == G_N_ELEMENTS(test_sequence));
720 * test_glist_nothing_in:
721 * @in: (element-type utf8):
723 void test_glist_nothing_in (const GList *in)
725 assert_test_sequence_list (in);
729 * test_glist_nothing_in2:
730 * @in: (element-type utf8):
732 void test_glist_nothing_in2 (GList *in)
734 assert_test_sequence_list (in);
738 * test_glist_container_in:
739 * @in: (element-type utf8) (transfer container):
741 void test_glist_container_in (GList *in)
743 assert_test_sequence_list (in);
748 * test_glist_everything_in:
749 * @in: (element-type utf8) (transfer full):
751 void test_glist_everything_in (GList *in)
753 assert_test_sequence_list (in);
754 test_glist_free (in);
757 /************************************************************************/
760 static /*const*/ GSList *test_sequence_slist()
762 static GSList *list = NULL;
765 for (i = 0; i < G_N_ELEMENTS(test_sequence); ++i) {
766 list = g_slist_prepend (list, (gpointer)test_sequence[i]);
768 list = g_slist_reverse (list);
775 * @in: (element-type utf8) (transfer full):
777 void test_gslist_free (GSList *in)
779 g_slist_foreach (in, (GFunc)g_free, NULL);
784 * test_gslist_nothing_return:
786 * Return value: (element-type utf8) (transfer none):
788 G_CONST_RETURN GSList *test_gslist_nothing_return (void)
790 return test_sequence_slist ();
794 * test_gslist_nothing_return2:
796 * Return value: (element-type utf8) (transfer none):
798 GSList *test_gslist_nothing_return2 (void)
800 return test_sequence_slist ();
804 * test_gslist_container_return:
806 * Return value: (element-type utf8) (transfer container):
808 GSList *test_gslist_container_return (void)
810 return g_slist_copy (test_sequence_slist ());
814 * test_gslist_everything_return:
816 * Return value: (element-type utf8) (transfer full):
818 GSList *test_gslist_everything_return (void)
823 list = g_slist_copy (test_sequence_slist ());
824 for (l = list; l != NULL; l = l->next)
825 l->data = g_strdup (l->data);
829 static void assert_test_sequence_slist (const GSList *in)
834 for (i = 0, l = in; l != NULL; ++i, l = l->next) {
835 g_assert (i < G_N_ELEMENTS(test_sequence));
836 g_assert (strcmp (l->data, test_sequence[i]) == 0);
838 g_assert (i == G_N_ELEMENTS(test_sequence));
842 * test_gslist_nothing_in:
843 * @in: (element-type utf8):
845 void test_gslist_nothing_in (const GSList *in)
847 assert_test_sequence_slist (in);
851 * test_gslist_nothing_in2:
852 * @in: (element-type utf8):
854 void test_gslist_nothing_in2 (GSList *in)
856 assert_test_sequence_slist (in);
860 * test_gslist_container_in:
861 * @in: (element-type utf8) (transfer container):
863 void test_gslist_container_in (GSList *in)
865 assert_test_sequence_slist (in);
870 * test_gslist_everything_in:
871 * @in: (element-type utf8) (transfer full):
873 void test_gslist_everything_in (GSList *in)
875 assert_test_sequence_slist (in);
876 test_gslist_free (in);
879 /************************************************************************/
882 static char *table_data[3][2] = {
883 { "foo", "bar" }, { "baz", "bat" }, { "qux", "quux" }
886 static GHashTable *test_table_ghash_new_container()
890 hash = g_hash_table_new(g_str_hash, g_str_equal);
892 g_hash_table_insert(hash, table_data[i][0], table_data[i][1]);
896 static GHashTable *test_table_ghash_new_full()
900 hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
902 g_hash_table_insert(hash,
903 g_strdup(table_data[i][0]),
904 g_strdup(table_data[i][1]));
908 static /*const*/ GHashTable *test_table_ghash_const()
910 static GHashTable *hash = NULL;
912 hash = test_table_ghash_new_container();
919 * @in: (transfer full) (element-type utf8 utf8)
921 void test_ghash_free (GHashTable *in)
923 /* keys and values are deleted iff an appropriate element destroy function
925 g_hash_table_unref(in);
929 * test_ghash_null_return:
931 * Return value: (element-type utf8 utf8) (transfer none) (allow-none):
933 G_CONST_RETURN GHashTable *test_ghash_null_return (void)
939 * test_ghash_nothing_return:
941 * Return value: (element-type utf8 utf8) (transfer none):
943 G_CONST_RETURN GHashTable *test_ghash_nothing_return (void)
945 return test_table_ghash_const ();
949 * test_ghash_nothing_return2:
951 * Return value: (element-type utf8 utf8) (transfer none):
953 GHashTable *test_ghash_nothing_return2 (void)
955 return test_table_ghash_const ();
959 * test_ghash_container_return:
961 * Return value: (element-type utf8 utf8) (transfer container):
963 GHashTable *test_ghash_container_return (void)
965 return test_table_ghash_new_container ();
969 * test_ghash_everything_return:
971 * Return value: (element-type utf8 utf8) (transfer full):
973 GHashTable *test_ghash_everything_return (void)
975 return test_table_ghash_new_full ();
978 static void assert_test_table_ghash (const GHashTable *in)
980 GHashTable *h = test_table_ghash_const();
984 g_assert(g_hash_table_size(h) ==
985 g_hash_table_size((GHashTable*)in));
987 g_hash_table_iter_init(&iter, (GHashTable*)in);
988 while (g_hash_table_iter_next (&iter, &key, &value))
989 g_assert( strcmp(g_hash_table_lookup(h, (char*)key), (char*)value) == 0);
993 * test_ghash_null_in:
994 * @in: (element-type utf8 utf8) (allow-none):
996 void test_ghash_null_in (const GHashTable *in)
998 g_assert (in == NULL);
1002 * test_ghash_nothing_in:
1003 * @in: (element-type utf8 utf8):
1005 void test_ghash_nothing_in (const GHashTable *in)
1007 assert_test_table_ghash (in);
1011 * test_ghash_nothing_in2:
1012 * @in: (element-type utf8 utf8):
1014 void test_ghash_nothing_in2 (GHashTable *in)
1016 assert_test_table_ghash (in);
1020 * test_ghash_container_in:
1021 * @in: (transfer container) (element-type utf8 utf8):
1023 void test_ghash_container_in (GHashTable *in)
1025 assert_test_table_ghash (in);
1026 /* be careful and explicitly steal all the elements from the ghash before
1028 g_hash_table_steal_all (in);
1029 g_hash_table_destroy (in);
1032 static gboolean ghash_freer(gpointer key, gpointer value, gpointer user_data) {
1039 * test_ghash_everything_in:
1040 * @in: (transfer full) (element-type utf8 utf8):
1042 void test_ghash_everything_in (GHashTable *in)
1044 assert_test_table_ghash (in);
1045 /* free the elements, then free the container. Don't rely on the
1046 * GHashTable's key/value destructor functions. */
1047 g_hash_table_foreach_steal (in, ghash_freer, NULL);
1048 /* okay, dealloc the hash table. */
1049 g_hash_table_destroy (in);
1052 /* Nested collection types */
1055 * test_ghash_nested_everything_return:
1056 * Specify nested parameterized types directly with the (type ) annotation.
1058 * Return value: (type GLib.HashTable<utf8,GLib.HashTable<utf8,utf8>>) (transfer full):
1061 test_ghash_nested_everything_return (void)
1064 hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
1065 (void (*) (gpointer)) g_hash_table_destroy);
1066 g_hash_table_insert(hash, g_strdup("wibble"), test_table_ghash_new_full());
1071 * test_ghash_nested_everything_return2:
1072 * Another way of specifying nested parameterized types: using the
1073 * element-type annotation.
1075 * Return value: (element-type utf8 GLib.HashTable<utf8,utf8>) (transfer full):
1078 test_ghash_nested_everything_return2 (void)
1080 return test_ghash_nested_everything_return();
1083 /************************************************************************/
1090 test_enum_get_type (void)
1092 static GType etype = 0;
1093 if (G_UNLIKELY(etype == 0)) {
1094 static const GEnumValue values[] = {
1095 { TEST_VALUE1, "TEST_VALUE1", "value1" },
1096 { TEST_VALUE2, "TEST_VALUE2", "value2" },
1097 { TEST_VALUE3, "TEST_VALUE3", "value3" },
1100 etype = g_enum_register_static (g_intern_static_string ("TestEnum"), values);
1107 test_flags_get_type (void)
1109 static GType etype = 0;
1110 if (G_UNLIKELY(etype == 0)) {
1111 static const GFlagsValue values[] = {
1112 { TEST_FLAG1, "TEST_FLAG1", "flag1" },
1113 { TEST_FLAG2, "TEST_FLAG2", "flag2" },
1114 { TEST_FLAG3, "TEST_FLAG3", "flag3" },
1117 etype = g_flags_register_static (g_intern_static_string ("TestFlags"), values);
1124 test_enum_param(TestEnum e)
1129 ec = g_type_class_ref (test_enum_get_type ());
1130 ev = g_enum_get_value (ec, e);
1131 g_type_class_unref (ec);
1133 return ev->value_nick;
1139 * test_struct_a_clone:
1141 * @a_out: the cloned structure
1143 * Make a copy of a TestStructA
1146 test_struct_a_clone (TestStructA *a,
1153 * test_struct_b_clone:
1155 * @b_out: the cloned structure
1157 * Make a copy of a TestStructB
1160 test_struct_b_clone (TestStructB *b,
1166 /* plain-old-data boxed types */
1169 test_simple_boxed_a_copy (TestSimpleBoxedA *a)
1171 TestSimpleBoxedA *new_a = g_slice_new (TestSimpleBoxedA);
1179 test_simple_boxed_a_free (TestSimpleBoxedA *a)
1181 g_slice_free (TestSimpleBoxedA, a);
1185 test_simple_boxed_a_get_type (void)
1187 static GType our_type = 0;
1190 our_type = g_boxed_type_register_static (g_intern_static_string ("TestSimpleBoxedA"),
1191 (GBoxedCopyFunc)test_simple_boxed_a_copy,
1192 (GBoxedFreeFunc)test_simple_boxed_a_free);
1197 test_simple_boxed_b_copy (TestSimpleBoxedB *b)
1199 TestSimpleBoxedB *new_b = g_slice_new (TestSimpleBoxedB);
1207 test_simple_boxed_a_equals (TestSimpleBoxedA *a,
1208 TestSimpleBoxedA *other_a)
1210 return (a->some_int == other_a->some_int &&
1211 a->some_int8 == other_a->some_int8 &&
1212 a->some_double == other_a->some_double);
1215 const TestSimpleBoxedA*
1216 test_simple_boxed_a_const_return (void)
1218 static TestSimpleBoxedA simple_a = {
1226 test_simple_boxed_b_free (TestSimpleBoxedB *a)
1228 g_slice_free (TestSimpleBoxedB, a);
1232 test_simple_boxed_b_get_type (void)
1234 static GType our_type = 0;
1237 our_type = g_boxed_type_register_static (g_intern_static_string ("TestSimpleBoxedB"),
1238 (GBoxedCopyFunc)test_simple_boxed_b_copy,
1239 (GBoxedFreeFunc)test_simple_boxed_b_free);
1245 struct _TestBoxedPrivate
1251 test_boxed_new (void)
1253 TestBoxed *boxed = g_slice_new0(TestBoxed);
1254 boxed->priv = g_slice_new0(TestBoxedPrivate);
1255 boxed->priv->magic = 0xdeadbeef;
1261 test_boxed_new_alternative_constructor1 (int i)
1263 TestBoxed *boxed = g_slice_new0(TestBoxed);
1264 boxed->priv = g_slice_new0(TestBoxedPrivate);
1265 boxed->priv->magic = 0xdeadbeef;
1266 boxed->some_int8 = i;
1272 test_boxed_new_alternative_constructor2 (int i, int j)
1274 TestBoxed *boxed = g_slice_new0(TestBoxed);
1275 boxed->priv = g_slice_new0(TestBoxedPrivate);
1276 boxed->priv->magic = 0xdeadbeef;
1277 boxed->some_int8 = i + j;
1283 test_boxed_new_alternative_constructor3 (char *s)
1285 TestBoxed *boxed = g_slice_new0(TestBoxed);
1286 boxed->priv = g_slice_new0(TestBoxedPrivate);
1287 boxed->priv->magic = 0xdeadbeef;
1288 boxed->some_int8 = atoi(s);
1294 test_boxed_copy (TestBoxed *boxed)
1296 TestBoxed *new_boxed = test_boxed_new();
1297 TestBoxedPrivate *save;
1299 save = new_boxed->priv;
1300 *new_boxed = *boxed;
1301 new_boxed->priv = save;
1307 test_boxed_equals (TestBoxed *boxed,
1310 return (other->some_int8 == boxed->some_int8 &&
1311 test_simple_boxed_a_equals(&other->nested_a, &boxed->nested_a));
1315 test_boxed_free (TestBoxed *boxed)
1317 g_assert (boxed->priv->magic == 0xdeadbeef);
1319 g_slice_free (TestBoxedPrivate, boxed->priv);
1320 g_slice_free (TestBoxed, boxed);
1324 test_boxed_get_type (void)
1326 static GType our_type = 0;
1329 our_type = g_boxed_type_register_static (g_intern_static_string ("TestBoxed"),
1330 (GBoxedCopyFunc)test_boxed_copy,
1331 (GBoxedFreeFunc)test_boxed_free);
1335 G_DEFINE_TYPE(TestObj, test_obj, G_TYPE_OBJECT);
1339 PROP_TEST_OBJ_BARE = 1,
1344 test_obj_set_property (GObject *object,
1346 const GValue *value,
1349 TestObj *self = TEST_OBJECT (object);
1351 switch (property_id)
1353 case PROP_TEST_OBJ_BARE:
1354 test_obj_set_bare (self, g_value_get_object (value));
1357 case PROP_TEST_OBJ_BOXED:
1359 test_boxed_free (self->boxed);
1360 self->boxed = g_value_dup_boxed (value);
1364 /* We don't have any other property... */
1365 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1371 test_obj_get_property (GObject *object,
1376 TestObj *self = TEST_OBJECT (object);
1378 switch (property_id)
1380 case PROP_TEST_OBJ_BARE:
1381 g_value_set_object (value, self->bare);
1384 case PROP_TEST_OBJ_BOXED:
1385 g_value_set_boxed (value, self->boxed);
1389 /* We don't have any other property... */
1390 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1396 test_obj_dispose (GObject *gobject)
1398 TestObj *self = TEST_OBJECT (gobject);
1402 g_object_unref (self->bare);
1409 test_boxed_free (self->boxed);
1413 /* Chain up to the parent class */
1414 G_OBJECT_CLASS (test_obj_parent_class)->dispose (gobject);
1418 test_obj_default_matrix (TestObj *obj, const char *somestr)
1424 test_obj_class_init (TestObjClass *klass)
1426 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1428 GType param_types[1];
1430 klass->test_signal =
1431 g_signal_newv ("test",
1432 G_TYPE_FROM_CLASS (gobject_class),
1433 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1435 NULL /* accumulator */,
1436 NULL /* accumulator data */,
1437 g_cclosure_marshal_VOID__VOID,
1438 G_TYPE_NONE /* return_type */,
1440 NULL /* param_types */);
1442 param_types[0] = test_simple_boxed_a_get_type() | G_SIGNAL_TYPE_STATIC_SCOPE;
1443 klass->test_signal_with_static_scope_arg =
1444 g_signal_newv ("test-with-static-scope-arg",
1445 G_TYPE_FROM_CLASS (gobject_class),
1446 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1448 NULL /* accumulator */,
1449 NULL /* accumulator data */,
1450 g_cclosure_marshal_VOID__BOXED,
1451 G_TYPE_NONE /* return_type */,
1455 gobject_class->set_property = test_obj_set_property;
1456 gobject_class->get_property = test_obj_get_property;
1457 gobject_class->dispose = test_obj_dispose;
1459 pspec = g_param_spec_object ("bare",
1461 "A contained object",
1464 g_object_class_install_property (gobject_class,
1468 pspec = g_param_spec_boxed ("boxed",
1470 "A contained boxed struct",
1473 g_object_class_install_property (gobject_class,
1474 PROP_TEST_OBJ_BOXED,
1477 klass->matrix = test_obj_default_matrix;
1481 test_obj_init (TestObj *obj)
1488 test_obj_new_from_file (const char *x, GError **error)
1490 return g_object_new (TEST_TYPE_OBJ, NULL);
1494 * test_obj_set_bare:
1495 * @bare: (allow-none):
1498 test_obj_set_bare (TestObj *obj, GObject *bare)
1501 g_object_unref (obj->bare);
1504 g_object_ref (obj->bare);
1508 test_obj_instance_method (TestObj *obj)
1514 test_obj_static_method (int x)
1520 * test_obj_torture_signature_0:
1531 test_obj_torture_signature_0 (TestObj *obj,
1541 *q = g_utf8_strlen (foo, -1) + m;
1545 * test_obj_torture_signature_1:
1555 * This function throws an error if m is odd.
1558 test_obj_torture_signature_1 (TestObj *obj,
1569 *q = g_utf8_strlen (foo, -1) + m;
1572 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "m is odd");
1577 * test_obj_do_matrix:
1579 * @somestr: Meaningless string
1581 * This method is virtual. Notably its name differs from the virtual
1582 * slot name, which makes it useful for testing bindings handle this
1588 test_obj_do_matrix (TestObj *obj, const char *somestr)
1590 return TEST_OBJ_GET_CLASS (obj)->matrix (obj, somestr);
1593 typedef struct _CallbackInfo CallbackInfo;
1595 struct _CallbackInfo
1597 TestCallbackUserData callback;
1598 GDestroyNotify notify;
1603 G_DEFINE_TYPE(TestSubObj, test_sub_obj, TEST_TYPE_OBJ);
1606 test_sub_obj_class_init (TestSubObjClass *klass)
1611 test_sub_obj_init (TestSubObj *obj)
1618 return g_object_new (TEST_TYPE_SUB_OBJ, NULL);
1622 test_sub_obj_instance_method (TestSubObj *obj)
1628 test_sub_obj_unset_bare (TestSubObj *obj)
1630 test_obj_set_bare(TEST_OBJECT(obj), NULL);
1636 * @callback: (scope call) (allow-none):
1640 test_callback (TestCallback callback)
1642 if (callback != NULL)
1648 * test_callback_user_data:
1649 * @callback: (scope call):
1651 * Call - callback parameter persists for the duration of the method
1652 * call and can be released on return.
1655 test_callback_user_data (TestCallbackUserData callback,
1658 return callback(user_data);
1661 static GSList *notified_callbacks = NULL;
1664 * test_callback_destroy_notify:
1665 * @callback: (scope notified):
1667 * Notified - callback persists until a DestroyNotify delegate
1671 test_callback_destroy_notify (TestCallbackUserData callback,
1673 GDestroyNotify notify)
1678 retval = callback(user_data);
1680 info = g_slice_new(CallbackInfo);
1681 info->callback = callback;
1682 info->notify = notify;
1683 info->user_data = user_data;
1685 notified_callbacks = g_slist_prepend(notified_callbacks, info);
1691 * test_callback_thaw_notifications:
1693 * Invokes all callbacks installed by #test_callback_destroy_notify(),
1694 * adding up their return values, and removes them, invoking the
1695 * corresponding destroy notfications.
1697 * Return value: Sum of the return values of the invoked callbacks.
1700 test_callback_thaw_notifications (void)
1705 for (node = notified_callbacks; node != NULL; node = node->next)
1707 CallbackInfo *info = node->data;
1708 retval += info->callback (info->user_data);
1710 info->notify (info->user_data);
1711 g_slice_free (CallbackInfo, info);
1714 g_slist_free (notified_callbacks);
1715 notified_callbacks = NULL;
1720 static GSList *async_callbacks = NULL;
1723 * test_callback_async:
1724 * @callback: (scope async):
1728 test_callback_async (TestCallbackUserData callback,
1733 info = g_slice_new(CallbackInfo);
1734 info->callback = callback;
1735 info->user_data = user_data;
1737 async_callbacks = g_slist_prepend(async_callbacks, info);
1741 * test_callback_thaw_async:
1744 test_callback_thaw_async (void)
1749 for (node = async_callbacks; node != NULL; node = node->next)
1751 CallbackInfo *info = node->data;
1752 retval = info->callback (info->user_data);
1753 g_slice_free (CallbackInfo, info);
1756 g_slist_free (async_callbacks);
1757 async_callbacks = NULL;
1762 * test_callback_infinite:
1763 * @callback: (scope infinite):
1765 * Infinite - callback persists forever.
1768 static GSList *infinite_callbacks = NULL;
1771 test_callback_infinite (TestCallbackUserData callback,
1774 infinite_callbacks = g_slist_prepend(infinite_callbacks, callback);
1776 return callback(user_data);
1782 test_interface_class_init(void *g_iface)
1787 test_interface_get_type(void)
1789 static GType type = 0;
1791 type = g_type_register_static_simple (G_TYPE_INTERFACE,
1792 "EverythingTestInterface",
1793 sizeof (TestInterfaceIface),
1794 (GClassInitFunc) test_interface_class_init,
1801 /* gobject with non-standard prefix */
1802 G_DEFINE_TYPE(TestWi8021x, test_wi_802_1x, G_TYPE_OBJECT);
1806 PROP_TEST_WI_802_1X_TESTBOOL = 1
1810 test_wi_802_1x_set_property (GObject *object,
1812 const GValue *value,
1815 TestWi8021x *self = TEST_WI_802_1X (object);
1817 switch (property_id)
1819 case PROP_TEST_WI_802_1X_TESTBOOL:
1820 test_wi_802_1x_set_testbool (self, g_value_get_boolean (value));
1824 /* We don't have any other property... */
1825 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1831 test_wi_802_1x_get_property (GObject *object,
1836 TestWi8021x *self = TEST_WI_802_1X (object);
1838 switch (property_id)
1840 case PROP_TEST_WI_802_1X_TESTBOOL:
1841 g_value_set_boolean (value, test_wi_802_1x_get_testbool (self));
1845 /* We don't have any other property... */
1846 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1852 test_wi_802_1x_dispose (GObject *gobject)
1854 /* Chain up to the parent class */
1855 G_OBJECT_CLASS (test_wi_802_1x_parent_class)->dispose (gobject);
1859 test_wi_802_1x_class_init (TestWi8021xClass *klass)
1861 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1864 gobject_class->set_property = test_wi_802_1x_set_property;
1865 gobject_class->get_property = test_wi_802_1x_get_property;
1866 gobject_class->dispose = test_wi_802_1x_dispose;
1868 pspec = g_param_spec_boolean ("testbool",
1869 "Nick for testbool",
1870 "Blurb for testbool",
1873 g_object_class_install_property (gobject_class,
1874 PROP_TEST_WI_802_1X_TESTBOOL,
1879 test_wi_802_1x_init (TestWi8021x *obj)
1881 obj->testbool = TRUE;
1885 test_wi_802_1x_new (void)
1887 return g_object_new (TEST_TYPE_WI_802_1X, NULL);
1891 test_wi_802_1x_set_testbool (TestWi8021x *obj, gboolean val)
1893 obj->testbool = val;
1897 test_wi_802_1x_get_testbool (TestWi8021x *obj)
1899 return obj->testbool;
1903 test_wi_802_1x_static_method (int x)
1909 * test_torture_signature_0:
1919 test_torture_signature_0 (int x,
1928 *q = g_utf8_strlen (foo, -1) + m;
1932 * test_torture_signature_1:
1941 * This function throws an error if m is odd.
1944 test_torture_signature_1 (int x,
1954 *q = g_utf8_strlen (foo, -1) + m;
1957 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "m is odd");
1962 * test_torture_signature_2:
1975 test_torture_signature_2 (int x,
1976 TestCallbackUserData callback,
1978 GDestroyNotify notify,
1987 *q = g_utf8_strlen (foo, -1) + m;