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));
260 /* in arguments after out arguments */
268 test_int_out_utf8 (int *length, const char *in)
270 *length = g_utf8_strlen(in, -1);
274 /* multiple output arguments */
277 * test_multi_double_args:
283 test_multi_double_args (gdouble in, gdouble *one, gdouble *two)
291 * @out0: (out) (transfer full): a copy of "first"
292 * @out1: (out) (transfer full): a copy of "second"
295 test_utf8_out_out (char **out0, char **out1)
297 *out0 = g_strdup ("first");
298 *out1 = g_strdup ("second");
302 * test_utf8_out_nonconst_return:
303 * @out: (out) (transfer full): a copy of "second"
305 * Returns: (transfer full): a copy of "first"
308 test_utf8_out_nonconst_return (char **out)
310 *out = g_strdup ("second");
311 return g_strdup ("first");
315 /* non-basic-types */
317 static const char *test_sequence[] = {"1", "2", "3"};
324 * @ints: (array length=n_ints): List of ints
327 test_array_int_in (int n_ints, int *ints)
330 for (i = 0; i < n_ints; i++)
336 * test_array_int_out:
337 * @n_ints: (out): the length of @ints
338 * @ints: (out) (array length=n_ints) (transfer full): a list of 5 integers, from 0 to 4 in consecutive order
341 test_array_int_out (int *n_ints, int **ints)
345 *ints = g_malloc0(sizeof(**ints) * *n_ints);
346 for (i = 1; i < *n_ints; i++)
347 (*ints)[i] = (*ints)[i-1] + 1;
351 * test_array_int_inout:
352 * @n_ints: (inout): the length of @ints
353 * @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
356 test_array_int_inout (int *n_ints, int **ints)
360 for (i = 1; i < *n_ints; i++) {
361 (*ints)[i-1] = (*ints)[i] + 1;
367 *ints = g_realloc(*ints, sizeof(**ints) * *n_ints);
371 * test_array_gint8_in:
373 * @ints: (array length=n_ints): List of ints
376 test_array_gint8_in (int n_ints, gint8 *ints)
379 for (i = 0; i < n_ints; i++)
385 * test_array_gint16_in:
387 * @ints: (array length=n_ints): List of ints
390 test_array_gint16_in (int n_ints, gint16 *ints)
393 for (i = 0; i < n_ints; i++)
399 * test_array_gint32_in:
401 * @ints: (array length=n_ints): List of ints
404 test_array_gint32_in (int n_ints, gint32 *ints)
408 for (i = 0; i < n_ints; i++)
414 * test_array_gint64_in:
416 * @ints: (array length=n_ints): List of ints
419 test_array_gint64_in (int n_ints, gint64 *ints)
423 for (i = 0; i < n_ints; i++)
430 * @arr: (array zero-terminated=1) (transfer none):
433 test_strv_in (char **arr)
435 if (g_strv_length (arr) != 3)
437 if (strcmp (arr[0], "1") != 0)
439 if (strcmp (arr[1], "2") != 0)
441 if (strcmp (arr[2], "3") != 0)
447 * test_strv_in_container:
448 * @arr: (array zero-terminated=1) (transfer container):
451 test_strv_in_container (char **arr)
453 gboolean result = test_strv_in (arr);
459 * test_array_gtype_in:
461 * @types: (array length=n_types): List of types
462 * Return value: string representation of provided types
465 test_array_gtype_in (int n_types, GType *types)
470 string = g_string_new ("[");
471 for (i = 0; i < n_types; i++)
473 g_string_append (string, g_type_name (types[i]));
474 g_string_append_c (string, ',');
476 g_string_append_c (string, ']');
477 return g_string_free (string, FALSE);
483 * No annotations here. We want the default to Do The Right Thing.
490 char **ret = g_new (char *, n);
491 ret[i++] = g_strdup ("thanks");
492 ret[i++] = g_strdup ("for");
493 ret[i++] = g_strdup ("all");
494 ret[i++] = g_strdup ("the");
495 ret[i++] = g_strdup ("fish");
502 * test_strv_out_container:
504 * Return value: (array zero-terminated=1) (transfer container):
507 test_strv_out_container (void)
509 char **ret = g_new (char *, 4);
519 * @retp: (array zero-terminated=1) (out) (transfer container):
522 test_strv_outarg (char ***retp)
524 char **ret = g_new (char *, 4);
533 * test_array_fixed_size_int_in:
534 * @ints: (array fixed-size=5): a list of 5 integers
536 * Returns: the sum of the items in @ints
539 test_array_fixed_size_int_in (int *ints)
542 for (i = 0; i < 5; i++)
548 * test_array_fixed_size_int_out:
549 * @ints: (out) (array fixed-size=5) (transfer full): a list of 5 integers ranging from 0 to 4
552 test_array_fixed_size_int_out (int **ints)
555 *ints = g_malloc0(sizeof(**ints) * 5);
556 for (i = 1; i < 5; i++)
557 (*ints)[i] = (*ints)[i-1] + 1;
561 * test_array_fixed_size_int_return:
562 * Returns: (array fixed-size=5) (transfer full): a list of 5 integers ranging from 0 to 4
565 test_array_fixed_size_int_return (void)
568 ints = g_malloc0(sizeof(*ints) * 5);
569 for (i = 1; i < 5; i++)
570 ints[i] = ints[i-1] + 1;
575 * test_array_int_in_take:
577 * @ints: (array length=n_ints) (transfer full): List of ints
579 int test_array_int_in_take (int n_ints, int *ints)
582 for (i = 0; i < n_ints; i++)
591 * No annotations here. We want the default to Do The Right Thing.
594 test_strv_out_c (void)
596 static char **ret = NULL;
599 ret = test_strv_out ();
601 return (const char * const *) ret;
605 * test_array_int_full_out:
606 * @len: length of the returned array.
607 * Returns: (array length=len) (transfer full): a new array of integers.
610 test_array_int_full_out(int *len) {
613 result = g_malloc0(sizeof(*result) * (*len));
614 for (i=1; i < (*len); i++)
615 result[i] = result[i-1] + 1;
620 * test_array_int_none_out:
621 * @len: length of the returned array.
622 * Returns: (array length=len) (transfer none): a static array of integers.
625 test_array_int_none_out(int *len) {
626 static int result[5] = { 1, 2, 3, 4, 5 };
633 /************************************************************************/
636 static /*const*/ GList *test_sequence_list()
638 static GList *list = NULL;
641 for (i = 0; i < G_N_ELEMENTS(test_sequence); ++i) {
642 list = g_list_prepend (list, (gpointer)test_sequence[i]);
644 list = g_list_reverse (list);
651 * @in: (element-type utf8) (transfer full):
653 void test_glist_free (GList *in)
655 g_list_foreach (in, (GFunc)g_free, NULL);
660 * test_glist_nothing_return:
662 * Return value: (element-type utf8) (transfer none):
664 G_CONST_RETURN GList *test_glist_nothing_return (void)
666 return test_sequence_list ();
670 * test_glist_nothing_return2:
672 * Return value: (element-type utf8) (transfer none):
674 GList *test_glist_nothing_return2 (void)
676 return test_sequence_list ();
680 * test_glist_container_return:
682 * Return value: (element-type utf8) (transfer container):
684 GList *test_glist_container_return (void)
686 return g_list_copy (test_sequence_list ());
690 * test_glist_everything_return:
692 * Return value: (element-type utf8) (transfer full):
694 GList *test_glist_everything_return (void)
699 list = g_list_copy (test_sequence_list ());
700 for (l = list; l != NULL; l = l->next)
701 l->data = g_strdup (l->data);
705 static void assert_test_sequence_list (const GList *in)
710 for (i = 0, l = in; l != NULL; ++i, l = l->next) {
711 g_assert (i < G_N_ELEMENTS(test_sequence));
712 g_assert (strcmp (l->data, test_sequence[i]) == 0);
714 g_assert (i == G_N_ELEMENTS(test_sequence));
718 * test_glist_nothing_in:
719 * @in: (element-type utf8):
721 void test_glist_nothing_in (const GList *in)
723 assert_test_sequence_list (in);
727 * test_glist_nothing_in2:
728 * @in: (element-type utf8):
730 void test_glist_nothing_in2 (GList *in)
732 assert_test_sequence_list (in);
736 * test_glist_container_in:
737 * @in: (element-type utf8) (transfer container):
739 void test_glist_container_in (GList *in)
741 assert_test_sequence_list (in);
746 * test_glist_everything_in:
747 * @in: (element-type utf8) (transfer full):
749 void test_glist_everything_in (GList *in)
751 assert_test_sequence_list (in);
752 test_glist_free (in);
755 /************************************************************************/
758 static /*const*/ GSList *test_sequence_slist()
760 static GSList *list = NULL;
763 for (i = 0; i < G_N_ELEMENTS(test_sequence); ++i) {
764 list = g_slist_prepend (list, (gpointer)test_sequence[i]);
766 list = g_slist_reverse (list);
773 * @in: (element-type utf8) (transfer full):
775 void test_gslist_free (GSList *in)
777 g_slist_foreach (in, (GFunc)g_free, NULL);
782 * test_gslist_nothing_return:
784 * Return value: (element-type utf8) (transfer none):
786 G_CONST_RETURN GSList *test_gslist_nothing_return (void)
788 return test_sequence_slist ();
792 * test_gslist_nothing_return2:
794 * Return value: (element-type utf8) (transfer none):
796 GSList *test_gslist_nothing_return2 (void)
798 return test_sequence_slist ();
802 * test_gslist_container_return:
804 * Return value: (element-type utf8) (transfer container):
806 GSList *test_gslist_container_return (void)
808 return g_slist_copy (test_sequence_slist ());
812 * test_gslist_everything_return:
814 * Return value: (element-type utf8) (transfer full):
816 GSList *test_gslist_everything_return (void)
821 list = g_slist_copy (test_sequence_slist ());
822 for (l = list; l != NULL; l = l->next)
823 l->data = g_strdup (l->data);
827 static void assert_test_sequence_slist (const GSList *in)
832 for (i = 0, l = in; l != NULL; ++i, l = l->next) {
833 g_assert (i < G_N_ELEMENTS(test_sequence));
834 g_assert (strcmp (l->data, test_sequence[i]) == 0);
836 g_assert (i == G_N_ELEMENTS(test_sequence));
840 * test_gslist_nothing_in:
841 * @in: (element-type utf8):
843 void test_gslist_nothing_in (const GSList *in)
845 assert_test_sequence_slist (in);
849 * test_gslist_nothing_in2:
850 * @in: (element-type utf8):
852 void test_gslist_nothing_in2 (GSList *in)
854 assert_test_sequence_slist (in);
858 * test_gslist_container_in:
859 * @in: (element-type utf8) (transfer container):
861 void test_gslist_container_in (GSList *in)
863 assert_test_sequence_slist (in);
868 * test_gslist_everything_in:
869 * @in: (element-type utf8) (transfer full):
871 void test_gslist_everything_in (GSList *in)
873 assert_test_sequence_slist (in);
874 test_gslist_free (in);
877 /************************************************************************/
880 static char *table_data[3][2] = {
881 { "foo", "bar" }, { "baz", "bat" }, { "qux", "quux" }
884 static GHashTable *test_table_ghash_new_container()
888 hash = g_hash_table_new(g_str_hash, g_str_equal);
890 g_hash_table_insert(hash, table_data[i][0], table_data[i][1]);
894 static GHashTable *test_table_ghash_new_full()
898 hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
900 g_hash_table_insert(hash,
901 g_strdup(table_data[i][0]),
902 g_strdup(table_data[i][1]));
906 static /*const*/ GHashTable *test_table_ghash_const()
908 static GHashTable *hash = NULL;
910 hash = test_table_ghash_new_container();
917 * @in: (transfer full) (element-type utf8 utf8)
919 void test_ghash_free (GHashTable *in)
921 /* keys and values are deleted iff an appropriate element destroy function
923 g_hash_table_unref(in);
927 * test_ghash_null_return:
929 * Return value: (element-type utf8 utf8) (transfer none) (allow-none):
931 G_CONST_RETURN GHashTable *test_ghash_null_return (void)
937 * test_ghash_nothing_return:
939 * Return value: (element-type utf8 utf8) (transfer none):
941 G_CONST_RETURN GHashTable *test_ghash_nothing_return (void)
943 return test_table_ghash_const ();
947 * test_ghash_nothing_return2:
949 * Return value: (element-type utf8 utf8) (transfer none):
951 GHashTable *test_ghash_nothing_return2 (void)
953 return test_table_ghash_const ();
957 * test_ghash_container_return:
959 * Return value: (element-type utf8 utf8) (transfer container):
961 GHashTable *test_ghash_container_return (void)
963 return test_table_ghash_new_container ();
967 * test_ghash_everything_return:
969 * Return value: (element-type utf8 utf8) (transfer full):
971 GHashTable *test_ghash_everything_return (void)
973 return test_table_ghash_new_full ();
976 static void assert_test_table_ghash (const GHashTable *in)
978 GHashTable *h = test_table_ghash_const();
982 g_assert(g_hash_table_size(h) ==
983 g_hash_table_size((GHashTable*)in));
985 g_hash_table_iter_init(&iter, (GHashTable*)in);
986 while (g_hash_table_iter_next (&iter, &key, &value))
987 g_assert( strcmp(g_hash_table_lookup(h, (char*)key), (char*)value) == 0);
991 * test_ghash_null_in:
992 * @in: (element-type utf8 utf8) (allow-none):
994 void test_ghash_null_in (const GHashTable *in)
996 g_assert (in == NULL);
1000 * test_ghash_nothing_in:
1001 * @in: (element-type utf8 utf8):
1003 void test_ghash_nothing_in (const GHashTable *in)
1005 assert_test_table_ghash (in);
1009 * test_ghash_nothing_in2:
1010 * @in: (element-type utf8 utf8):
1012 void test_ghash_nothing_in2 (GHashTable *in)
1014 assert_test_table_ghash (in);
1018 * test_ghash_container_in:
1019 * @in: (transfer container) (element-type utf8 utf8):
1021 void test_ghash_container_in (GHashTable *in)
1023 assert_test_table_ghash (in);
1024 /* be careful and explicitly steal all the elements from the ghash before
1026 g_hash_table_steal_all (in);
1027 g_hash_table_destroy (in);
1030 static gboolean ghash_freer(gpointer key, gpointer value, gpointer user_data) {
1037 * test_ghash_everything_in:
1038 * @in: (transfer full) (element-type utf8 utf8):
1040 void test_ghash_everything_in (GHashTable *in)
1042 assert_test_table_ghash (in);
1043 /* free the elements, then free the container. Don't rely on the
1044 * GHashTable's key/value destructor functions. */
1045 g_hash_table_foreach_steal (in, ghash_freer, NULL);
1046 /* okay, dealloc the hash table. */
1047 g_hash_table_destroy (in);
1050 /* Nested collection types */
1053 * test_ghash_nested_everything_return:
1054 * Specify nested parameterized types directly with the (type ) annotation.
1056 * Return value: (type GLib.HashTable<utf8,GLib.HashTable<utf8,utf8>>) (transfer full):
1059 test_ghash_nested_everything_return (void)
1062 hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
1063 (void (*) (gpointer)) g_hash_table_destroy);
1064 g_hash_table_insert(hash, g_strdup("wibble"), test_table_ghash_new_full());
1069 * test_ghash_nested_everything_return2:
1070 * Another way of specifying nested parameterized types: using the
1071 * element-type annotation.
1073 * Return value: (element-type utf8 GLib.HashTable<utf8,utf8>) (transfer full):
1076 test_ghash_nested_everything_return2 (void)
1078 return test_ghash_nested_everything_return();
1081 /************************************************************************/
1088 test_enum_get_type (void)
1090 static GType etype = 0;
1091 if (G_UNLIKELY(etype == 0)) {
1092 static const GEnumValue values[] = {
1093 { TEST_VALUE1, "TEST_VALUE1", "value1" },
1094 { TEST_VALUE2, "TEST_VALUE2", "value2" },
1095 { TEST_VALUE3, "TEST_VALUE3", "value3" },
1098 etype = g_enum_register_static (g_intern_static_string ("TestEnum"), values);
1105 test_flags_get_type (void)
1107 static GType etype = 0;
1108 if (G_UNLIKELY(etype == 0)) {
1109 static const GFlagsValue values[] = {
1110 { TEST_FLAG1, "TEST_FLAG1", "flag1" },
1111 { TEST_FLAG2, "TEST_FLAG2", "flag2" },
1112 { TEST_FLAG3, "TEST_FLAG3", "flag3" },
1115 etype = g_flags_register_static (g_intern_static_string ("TestFlags"), values);
1122 test_enum_param(TestEnum e)
1127 ec = g_type_class_ref (test_enum_get_type ());
1128 ev = g_enum_get_value (ec, e);
1129 g_type_class_unref (ec);
1131 return ev->value_nick;
1137 * test_struct_a_clone:
1139 * @a_out: the cloned structure
1141 * Make a copy of a TestStructA
1144 test_struct_a_clone (TestStructA *a,
1151 * test_struct_b_clone:
1153 * @b_out: the cloned structure
1155 * Make a copy of a TestStructB
1158 test_struct_b_clone (TestStructB *b,
1164 /* plain-old-data boxed types */
1167 test_simple_boxed_a_copy (TestSimpleBoxedA *a)
1169 TestSimpleBoxedA *new_a = g_slice_new (TestSimpleBoxedA);
1177 test_simple_boxed_a_free (TestSimpleBoxedA *a)
1179 g_slice_free (TestSimpleBoxedA, a);
1183 test_simple_boxed_a_get_type (void)
1185 static GType our_type = 0;
1188 our_type = g_boxed_type_register_static (g_intern_static_string ("TestSimpleBoxedA"),
1189 (GBoxedCopyFunc)test_simple_boxed_a_copy,
1190 (GBoxedFreeFunc)test_simple_boxed_a_free);
1195 test_simple_boxed_b_copy (TestSimpleBoxedB *b)
1197 TestSimpleBoxedB *new_b = g_slice_new (TestSimpleBoxedB);
1205 test_simple_boxed_a_equals (TestSimpleBoxedA *a,
1206 TestSimpleBoxedA *other_a)
1208 return (a->some_int == other_a->some_int &&
1209 a->some_int8 == other_a->some_int8 &&
1210 a->some_double == other_a->some_double);
1213 const TestSimpleBoxedA*
1214 test_simple_boxed_a_const_return (void)
1216 static TestSimpleBoxedA simple_a = {
1224 test_simple_boxed_b_free (TestSimpleBoxedB *a)
1226 g_slice_free (TestSimpleBoxedB, a);
1230 test_simple_boxed_b_get_type (void)
1232 static GType our_type = 0;
1235 our_type = g_boxed_type_register_static (g_intern_static_string ("TestSimpleBoxedB"),
1236 (GBoxedCopyFunc)test_simple_boxed_b_copy,
1237 (GBoxedFreeFunc)test_simple_boxed_b_free);
1243 struct _TestBoxedPrivate
1249 test_boxed_new (void)
1251 TestBoxed *boxed = g_slice_new0(TestBoxed);
1252 boxed->priv = g_slice_new0(TestBoxedPrivate);
1253 boxed->priv->magic = 0xdeadbeef;
1259 test_boxed_copy (TestBoxed *boxed)
1261 TestBoxed *new_boxed = test_boxed_new();
1262 TestBoxedPrivate *save;
1264 save = new_boxed->priv;
1265 *new_boxed = *boxed;
1266 new_boxed->priv = save;
1272 test_boxed_equals (TestBoxed *boxed,
1275 return (other->some_int8 == boxed->some_int8 &&
1276 test_simple_boxed_a_equals(&other->nested_a, &boxed->nested_a));
1280 test_boxed_free (TestBoxed *boxed)
1282 g_assert (boxed->priv->magic == 0xdeadbeef);
1284 g_slice_free (TestBoxedPrivate, boxed->priv);
1285 g_slice_free (TestBoxed, boxed);
1289 test_boxed_get_type (void)
1291 static GType our_type = 0;
1294 our_type = g_boxed_type_register_static (g_intern_static_string ("TestBoxed"),
1295 (GBoxedCopyFunc)test_boxed_copy,
1296 (GBoxedFreeFunc)test_boxed_free);
1300 G_DEFINE_TYPE(TestObj, test_obj, G_TYPE_OBJECT);
1304 PROP_TEST_OBJ_BARE = 1,
1309 test_obj_set_property (GObject *object,
1311 const GValue *value,
1314 TestObj *self = TEST_OBJECT (object);
1316 switch (property_id)
1318 case PROP_TEST_OBJ_BARE:
1319 test_obj_set_bare (self, g_value_get_object (value));
1322 case PROP_TEST_OBJ_BOXED:
1324 test_boxed_free (self->boxed);
1325 self->boxed = g_value_dup_boxed (value);
1329 /* We don't have any other property... */
1330 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1336 test_obj_get_property (GObject *object,
1341 TestObj *self = TEST_OBJECT (object);
1343 switch (property_id)
1345 case PROP_TEST_OBJ_BARE:
1346 g_value_set_object (value, self->bare);
1349 case PROP_TEST_OBJ_BOXED:
1350 g_value_set_boxed (value, self->boxed);
1354 /* We don't have any other property... */
1355 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1361 test_obj_dispose (GObject *gobject)
1363 TestObj *self = TEST_OBJECT (gobject);
1367 g_object_unref (self->bare);
1374 test_boxed_free (self->boxed);
1378 /* Chain up to the parent class */
1379 G_OBJECT_CLASS (test_obj_parent_class)->dispose (gobject);
1383 test_obj_default_matrix (TestObj *obj, const char *somestr)
1389 test_obj_class_init (TestObjClass *klass)
1391 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1393 GType param_types[1];
1395 klass->test_signal =
1396 g_signal_newv ("test",
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__VOID,
1403 G_TYPE_NONE /* return_type */,
1405 NULL /* param_types */);
1407 param_types[0] = test_simple_boxed_a_get_type() | G_SIGNAL_TYPE_STATIC_SCOPE;
1408 klass->test_signal_with_static_scope_arg =
1409 g_signal_newv ("test-with-static-scope-arg",
1410 G_TYPE_FROM_CLASS (gobject_class),
1411 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1413 NULL /* accumulator */,
1414 NULL /* accumulator data */,
1415 g_cclosure_marshal_VOID__BOXED,
1416 G_TYPE_NONE /* return_type */,
1420 gobject_class->set_property = test_obj_set_property;
1421 gobject_class->get_property = test_obj_get_property;
1422 gobject_class->dispose = test_obj_dispose;
1424 pspec = g_param_spec_object ("bare",
1426 "A contained object",
1429 g_object_class_install_property (gobject_class,
1433 pspec = g_param_spec_boxed ("boxed",
1435 "A contained boxed struct",
1438 g_object_class_install_property (gobject_class,
1439 PROP_TEST_OBJ_BOXED,
1442 klass->matrix = test_obj_default_matrix;
1446 test_obj_init (TestObj *obj)
1453 test_obj_new_from_file (const char *x, GError **error)
1455 return g_object_new (TEST_TYPE_OBJ, NULL);
1459 * test_obj_set_bare:
1460 * @bare: (allow-none):
1463 test_obj_set_bare (TestObj *obj, GObject *bare)
1466 g_object_unref (obj->bare);
1469 g_object_ref (obj->bare);
1473 test_obj_instance_method (TestObj *obj)
1479 test_obj_static_method (int x)
1485 * test_obj_do_matrix:
1487 * @somestr: Meaningless string
1489 * This method is virtual. Notably its name differs from the virtual
1490 * slot name, which makes it useful for testing bindings handle this
1496 test_obj_do_matrix (TestObj *obj, const char *somestr)
1498 return TEST_OBJ_GET_CLASS (obj)->matrix (obj, somestr);
1501 typedef struct _CallbackInfo CallbackInfo;
1503 struct _CallbackInfo
1505 TestCallbackUserData callback;
1506 GDestroyNotify notify;
1511 G_DEFINE_TYPE(TestSubObj, test_sub_obj, TEST_TYPE_OBJ);
1514 test_sub_obj_class_init (TestSubObjClass *klass)
1519 test_sub_obj_init (TestSubObj *obj)
1526 return g_object_new (TEST_TYPE_SUB_OBJ, NULL);
1530 test_sub_obj_instance_method (TestSubObj *obj)
1536 test_sub_obj_unset_bare (TestSubObj *obj)
1538 test_obj_set_bare(TEST_OBJECT(obj), NULL);
1544 * @callback: (scope call) (allow-none):
1548 test_callback (TestCallback callback)
1550 if (callback != NULL)
1556 * test_callback_user_data:
1557 * @callback: (scope call):
1559 * Call - callback parameter persists for the duration of the method
1560 * call and can be released on return.
1563 test_callback_user_data (TestCallbackUserData callback,
1566 return callback(user_data);
1569 static GSList *notified_callbacks = NULL;
1572 * test_callback_destroy_notify:
1573 * @callback: (scope notified):
1575 * Notified - callback persists until a DestroyNotify delegate
1579 test_callback_destroy_notify (TestCallbackUserData callback,
1581 GDestroyNotify notify)
1586 retval = callback(user_data);
1588 info = g_slice_new(CallbackInfo);
1589 info->callback = callback;
1590 info->notify = notify;
1591 info->user_data = user_data;
1593 notified_callbacks = g_slist_prepend(notified_callbacks, info);
1599 * test_callback_thaw_notifications:
1601 * Invokes all callbacks installed by #test_callback_destroy_notify(),
1602 * adding up their return values, and removes them, invoking the
1603 * corresponding destroy notfications.
1605 * Return value: Sum of the return values of the invoked callbacks.
1608 test_callback_thaw_notifications (void)
1613 for (node = notified_callbacks; node != NULL; node = node->next)
1615 CallbackInfo *info = node->data;
1616 retval += info->callback (info->user_data);
1618 info->notify (info->user_data);
1619 g_slice_free (CallbackInfo, info);
1622 g_slist_free (notified_callbacks);
1623 notified_callbacks = NULL;
1628 static GSList *async_callbacks = NULL;
1631 * test_callback_async:
1632 * @callback: (scope async):
1636 test_callback_async (TestCallbackUserData callback,
1641 info = g_slice_new(CallbackInfo);
1642 info->callback = callback;
1643 info->user_data = user_data;
1645 async_callbacks = g_slist_prepend(async_callbacks, info);
1649 * test_callback_thaw_async:
1652 test_callback_thaw_async (void)
1657 for (node = async_callbacks; node != NULL; node = node->next)
1659 CallbackInfo *info = node->data;
1660 retval = info->callback (info->user_data);
1661 g_slice_free (CallbackInfo, info);
1664 g_slist_free (async_callbacks);
1665 async_callbacks = NULL;
1670 * test_callback_infinite:
1671 * @callback: (scope infinite):
1673 * Infinite - callback persists forever.
1676 static GSList *infinite_callbacks = NULL;
1679 test_callback_infinite (TestCallbackUserData callback,
1682 infinite_callbacks = g_slist_prepend(infinite_callbacks, callback);
1684 return callback(user_data);
1690 test_interface_class_init(void *g_iface)
1695 test_interface_get_type(void)
1697 static GType type = 0;
1699 type = g_type_register_static_simple (G_TYPE_INTERFACE,
1700 "EverythingTestInterface",
1701 sizeof (TestInterfaceIface),
1702 (GClassInitFunc) test_interface_class_init,
1709 /* gobject with non-standard prefix */
1710 G_DEFINE_TYPE(TestWi8021x, test_wi_802_1x, G_TYPE_OBJECT);
1714 PROP_TEST_WI_802_1X_TESTBOOL = 1
1718 test_wi_802_1x_set_property (GObject *object,
1720 const GValue *value,
1723 TestWi8021x *self = TEST_WI_802_1X (object);
1725 switch (property_id)
1727 case PROP_TEST_WI_802_1X_TESTBOOL:
1728 test_wi_802_1x_set_testbool (self, g_value_get_boolean (value));
1732 /* We don't have any other property... */
1733 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1739 test_wi_802_1x_get_property (GObject *object,
1744 TestWi8021x *self = TEST_WI_802_1X (object);
1746 switch (property_id)
1748 case PROP_TEST_WI_802_1X_TESTBOOL:
1749 g_value_set_boolean (value, test_wi_802_1x_get_testbool (self));
1753 /* We don't have any other property... */
1754 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1760 test_wi_802_1x_dispose (GObject *gobject)
1762 /* Chain up to the parent class */
1763 G_OBJECT_CLASS (test_wi_802_1x_parent_class)->dispose (gobject);
1767 test_wi_802_1x_class_init (TestWi8021xClass *klass)
1769 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1772 gobject_class->set_property = test_wi_802_1x_set_property;
1773 gobject_class->get_property = test_wi_802_1x_get_property;
1774 gobject_class->dispose = test_wi_802_1x_dispose;
1776 pspec = g_param_spec_boolean ("testbool",
1777 "Nick for testbool",
1778 "Blurb for testbool",
1781 g_object_class_install_property (gobject_class,
1782 PROP_TEST_WI_802_1X_TESTBOOL,
1787 test_wi_802_1x_init (TestWi8021x *obj)
1789 obj->testbool = TRUE;
1793 test_wi_802_1x_new (void)
1795 return g_object_new (TEST_TYPE_WI_802_1X, NULL);
1799 test_wi_802_1x_set_testbool (TestWi8021x *obj, gboolean val)
1801 obj->testbool = val;
1805 test_wi_802_1x_get_testbool (TestWi8021x *obj)
1807 return obj->testbool;
1811 test_wi_802_1x_static_method (int x)