2 #include "everything.h"
6 gboolean test_boolean (gboolean in)
11 gint8 test_int8 (gint8 in)
16 guint8 test_uint8 (guint8 in)
21 gint16 test_int16 (gint16 in)
26 guint16 test_uint16 (guint16 in)
31 gint32 test_int32 (gint32 in)
36 guint32 test_uint32 (guint32 in)
41 gint64 test_int64 (gint64 in)
46 guint64 test_uint64 (guint64 in)
51 gshort test_short (gshort in)
56 gushort test_ushort (gushort in)
61 gint test_int (gint in)
66 guint test_uint (guint in)
71 glong test_long (glong in)
76 gulong test_ulong (gulong in)
81 gssize test_ssize (gssize in)
86 gsize test_size (gsize in)
91 gfloat test_float (gfloat in)
96 gdouble test_double (gdouble in)
102 time_t test_timet (time_t in)
107 GType test_gtype (GType in)
112 int test_closure (GClosure *closure)
114 GValue return_value = {0, };
117 g_value_init (&return_value, G_TYPE_INT);
119 g_closure_invoke (closure,
124 ret = g_value_get_int (&return_value);
126 g_value_unset(&return_value);
131 int test_closure_one_arg (GClosure *closure, int arg)
133 GValue return_value = {0, };
137 g_value_init (&return_value, G_TYPE_INT);
139 memset (&arguments[0], 0, sizeof (arguments));
140 g_value_init (&arguments[0], G_TYPE_INT);
141 g_value_set_int (&arguments[0], arg);
143 g_closure_invoke (closure,
148 ret = g_value_get_int (&return_value);
150 g_value_unset(&return_value);
151 g_value_unset(&arguments[0]);
158 * @v: (transfer none): a GValue expected to contain an int
160 * Return value: the int contained in the GValue.
162 int test_int_value_arg(const GValue *v) {
165 i = g_value_get_int (v);
175 * Return value: (transfer none): the int wrapped in a GValue.
177 const GValue *test_value_return(int i) {
178 memset(&value, '\0', sizeof(GValue));
180 g_value_init (&value, G_TYPE_INT);
181 g_value_set_int (&value, i);
187 /************************************************************************/
189 /* insert BLACK HEART SUIT to ensure UTF-8 doesn't get mangled */
190 static const char utf8_const[] = "const \xe2\x99\xa5 utf8";
191 static const char utf8_nonconst[] = "nonconst \xe2\x99\xa5 utf8";
194 * test_utf8_const_return:
195 * Return value: <const char*> UTF-8 string
197 G_CONST_RETURN char *test_utf8_const_return (void)
199 /* transfer mode none */
204 * test_utf8_nonconst_return:
205 * Return value: <char*> UTF-8 string
207 char *test_utf8_nonconst_return (void)
209 /* transfer mode full */
210 return g_strdup (utf8_nonconst);
213 void test_utf8_nonconst_in (char *in)
215 /* transfer mode full */
216 g_assert (strcmp (in, utf8_nonconst) == 0);
220 void test_utf8_const_in (const char *in)
222 /* transfer mode none */
223 g_assert (strcmp (in, utf8_const) == 0);
228 * @out: (out) (transfer full):
230 void test_utf8_out (char **out)
232 /* out parameter, transfer mode full */
233 *out = g_strdup (utf8_nonconst);
240 void test_utf8_inout (char **inout)
242 /* inout parameter, transfer mode full */
243 g_assert (strcmp (*inout, utf8_const) == 0);
245 *inout = g_strdup (utf8_nonconst);
249 * test_filename_return:
251 * Return value: (element-type filename) (transfer full): list of strings
253 GSList *test_filename_return (void)
255 GSList *filenames = NULL;
256 filenames = g_slist_prepend (filenames, g_filename_from_utf8("/etc/fstab", -1, NULL, NULL, NULL));
257 filenames = g_slist_prepend (filenames, g_filename_from_utf8("åäö", -1, NULL, NULL, NULL));
261 /* in arguments after out arguments */
269 test_int_out_utf8 (int *length, const char *in)
271 *length = g_utf8_strlen(in, -1);
275 /* multiple output arguments */
278 * test_multi_double_args:
284 test_multi_double_args (gdouble in, gdouble *one, gdouble *two)
292 * @out0: (out) (transfer full): a copy of "first"
293 * @out1: (out) (transfer full): a copy of "second"
296 test_utf8_out_out (char **out0, char **out1)
298 *out0 = g_strdup ("first");
299 *out1 = g_strdup ("second");
303 * test_utf8_out_nonconst_return:
304 * @out: (out) (transfer full): a copy of "second"
306 * Returns: (transfer full): a copy of "first"
309 test_utf8_out_nonconst_return (char **out)
311 *out = g_strdup ("second");
312 return g_strdup ("first");
316 /* non-basic-types */
318 static const char *test_sequence[] = {"1", "2", "3"};
325 * @ints: (array length=n_ints): List of ints
328 test_array_int_in (int n_ints, int *ints)
331 for (i = 0; i < n_ints; i++)
337 * test_array_int_out:
338 * @n_ints: (out): the length of @ints
339 * @ints: (out) (array length=n_ints) (transfer full): a list of 5 integers, from 0 to 4 in consecutive order
342 test_array_int_out (int *n_ints, int **ints)
346 *ints = g_malloc0(sizeof(**ints) * *n_ints);
347 for (i = 1; i < *n_ints; i++)
348 (*ints)[i] = (*ints)[i-1] + 1;
352 * test_array_int_inout:
353 * @n_ints: (inout): the length of @ints
354 * @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
357 test_array_int_inout (int *n_ints, int **ints)
361 for (i = 1; i < *n_ints; i++) {
362 (*ints)[i-1] = (*ints)[i] + 1;
368 *ints = g_realloc(*ints, sizeof(**ints) * *n_ints);
372 * test_array_gint8_in:
374 * @ints: (array length=n_ints): List of ints
377 test_array_gint8_in (int n_ints, gint8 *ints)
380 for (i = 0; i < n_ints; i++)
386 * test_array_gint16_in:
388 * @ints: (array length=n_ints): List of ints
391 test_array_gint16_in (int n_ints, gint16 *ints)
394 for (i = 0; i < n_ints; i++)
400 * test_array_gint32_in:
402 * @ints: (array length=n_ints): List of ints
405 test_array_gint32_in (int n_ints, gint32 *ints)
409 for (i = 0; i < n_ints; i++)
415 * test_array_gint64_in:
417 * @ints: (array length=n_ints): List of ints
420 test_array_gint64_in (int n_ints, gint64 *ints)
424 for (i = 0; i < n_ints; i++)
431 * @arr: (array zero-terminated=1) (transfer none):
434 test_strv_in (char **arr)
436 if (g_strv_length (arr) != 3)
438 if (strcmp (arr[0], "1") != 0)
440 if (strcmp (arr[1], "2") != 0)
442 if (strcmp (arr[2], "3") != 0)
448 * test_strv_in_container:
449 * @arr: (array zero-terminated=1) (transfer container):
452 test_strv_in_container (char **arr)
454 gboolean result = test_strv_in (arr);
460 * test_array_gtype_in:
462 * @types: (array length=n_types): List of types
463 * Return value: string representation of provided types
466 test_array_gtype_in (int n_types, GType *types)
471 string = g_string_new ("[");
472 for (i = 0; i < n_types; i++)
474 g_string_append (string, g_type_name (types[i]));
475 g_string_append_c (string, ',');
477 g_string_append_c (string, ']');
478 return g_string_free (string, FALSE);
484 * No annotations here. We want the default to Do The Right Thing.
491 char **ret = g_new (char *, n);
492 ret[i++] = g_strdup ("thanks");
493 ret[i++] = g_strdup ("for");
494 ret[i++] = g_strdup ("all");
495 ret[i++] = g_strdup ("the");
496 ret[i++] = g_strdup ("fish");
503 * test_strv_out_container:
505 * Return value: (array zero-terminated=1) (transfer container):
508 test_strv_out_container (void)
510 char **ret = g_new (char *, 4);
520 * @retp: (array zero-terminated=1) (out) (transfer container):
523 test_strv_outarg (char ***retp)
525 char **ret = g_new (char *, 4);
534 * test_array_fixed_size_int_in:
535 * @ints: (array fixed-size=5): a list of 5 integers
537 * Returns: the sum of the items in @ints
540 test_array_fixed_size_int_in (int *ints)
543 for (i = 0; i < 5; i++)
549 * test_array_fixed_size_int_out:
550 * @ints: (out) (array fixed-size=5) (transfer full): a list of 5 integers ranging from 0 to 4
553 test_array_fixed_size_int_out (int **ints)
556 *ints = g_malloc0(sizeof(**ints) * 5);
557 for (i = 1; i < 5; i++)
558 (*ints)[i] = (*ints)[i-1] + 1;
562 * test_array_fixed_size_int_return:
563 * Returns: (array fixed-size=5) (transfer full): a list of 5 integers ranging from 0 to 4
566 test_array_fixed_size_int_return (void)
569 ints = g_malloc0(sizeof(*ints) * 5);
570 for (i = 1; i < 5; i++)
571 ints[i] = ints[i-1] + 1;
576 * test_array_int_in_take:
578 * @ints: (array length=n_ints) (transfer full): List of ints
580 int test_array_int_in_take (int n_ints, int *ints)
583 for (i = 0; i < n_ints; i++)
592 * No annotations here. We want the default to Do The Right Thing.
595 test_strv_out_c (void)
597 static char **ret = NULL;
600 ret = test_strv_out ();
602 return (const char * const *) ret;
606 * test_array_int_full_out:
607 * @len: length of the returned array.
608 * Returns: (array length=len) (transfer full): a new array of integers.
611 test_array_int_full_out(int *len) {
614 result = g_malloc0(sizeof(*result) * (*len));
615 for (i=1; i < (*len); i++)
616 result[i] = result[i-1] + 1;
621 * test_array_int_none_out:
622 * @len: length of the returned array.
623 * Returns: (array length=len) (transfer none): a static array of integers.
626 test_array_int_none_out(int *len) {
627 static int result[5] = { 1, 2, 3, 4, 5 };
634 /************************************************************************/
637 static /*const*/ GList *test_sequence_list()
639 static GList *list = NULL;
642 for (i = 0; i < G_N_ELEMENTS(test_sequence); ++i) {
643 list = g_list_prepend (list, (gpointer)test_sequence[i]);
645 list = g_list_reverse (list);
652 * @in: (element-type utf8) (transfer full):
654 void test_glist_free (GList *in)
656 g_list_foreach (in, (GFunc)g_free, NULL);
661 * test_glist_nothing_return:
663 * Return value: (element-type utf8) (transfer none):
665 G_CONST_RETURN GList *test_glist_nothing_return (void)
667 return test_sequence_list ();
671 * test_glist_nothing_return2:
673 * Return value: (element-type utf8) (transfer none):
675 GList *test_glist_nothing_return2 (void)
677 return test_sequence_list ();
681 * test_glist_container_return:
683 * Return value: (element-type utf8) (transfer container):
685 GList *test_glist_container_return (void)
687 return g_list_copy (test_sequence_list ());
691 * test_glist_everything_return:
693 * Return value: (element-type utf8) (transfer full):
695 GList *test_glist_everything_return (void)
700 list = g_list_copy (test_sequence_list ());
701 for (l = list; l != NULL; l = l->next)
702 l->data = g_strdup (l->data);
706 static void assert_test_sequence_list (const GList *in)
711 for (i = 0, l = in; l != NULL; ++i, l = l->next) {
712 g_assert (i < G_N_ELEMENTS(test_sequence));
713 g_assert (strcmp (l->data, test_sequence[i]) == 0);
715 g_assert (i == G_N_ELEMENTS(test_sequence));
719 * test_glist_nothing_in:
720 * @in: (element-type utf8):
722 void test_glist_nothing_in (const GList *in)
724 assert_test_sequence_list (in);
728 * test_glist_nothing_in2:
729 * @in: (element-type utf8):
731 void test_glist_nothing_in2 (GList *in)
733 assert_test_sequence_list (in);
737 * test_glist_container_in:
738 * @in: (element-type utf8) (transfer container):
740 void test_glist_container_in (GList *in)
742 assert_test_sequence_list (in);
747 * test_glist_everything_in:
748 * @in: (element-type utf8) (transfer full):
750 void test_glist_everything_in (GList *in)
752 assert_test_sequence_list (in);
753 test_glist_free (in);
756 /************************************************************************/
759 static /*const*/ GSList *test_sequence_slist()
761 static GSList *list = NULL;
764 for (i = 0; i < G_N_ELEMENTS(test_sequence); ++i) {
765 list = g_slist_prepend (list, (gpointer)test_sequence[i]);
767 list = g_slist_reverse (list);
774 * @in: (element-type utf8) (transfer full):
776 void test_gslist_free (GSList *in)
778 g_slist_foreach (in, (GFunc)g_free, NULL);
783 * test_gslist_nothing_return:
785 * Return value: (element-type utf8) (transfer none):
787 G_CONST_RETURN GSList *test_gslist_nothing_return (void)
789 return test_sequence_slist ();
793 * test_gslist_nothing_return2:
795 * Return value: (element-type utf8) (transfer none):
797 GSList *test_gslist_nothing_return2 (void)
799 return test_sequence_slist ();
803 * test_gslist_container_return:
805 * Return value: (element-type utf8) (transfer container):
807 GSList *test_gslist_container_return (void)
809 return g_slist_copy (test_sequence_slist ());
813 * test_gslist_everything_return:
815 * Return value: (element-type utf8) (transfer full):
817 GSList *test_gslist_everything_return (void)
822 list = g_slist_copy (test_sequence_slist ());
823 for (l = list; l != NULL; l = l->next)
824 l->data = g_strdup (l->data);
828 static void assert_test_sequence_slist (const GSList *in)
833 for (i = 0, l = in; l != NULL; ++i, l = l->next) {
834 g_assert (i < G_N_ELEMENTS(test_sequence));
835 g_assert (strcmp (l->data, test_sequence[i]) == 0);
837 g_assert (i == G_N_ELEMENTS(test_sequence));
841 * test_gslist_nothing_in:
842 * @in: (element-type utf8):
844 void test_gslist_nothing_in (const GSList *in)
846 assert_test_sequence_slist (in);
850 * test_gslist_nothing_in2:
851 * @in: (element-type utf8):
853 void test_gslist_nothing_in2 (GSList *in)
855 assert_test_sequence_slist (in);
859 * test_gslist_container_in:
860 * @in: (element-type utf8) (transfer container):
862 void test_gslist_container_in (GSList *in)
864 assert_test_sequence_slist (in);
869 * test_gslist_everything_in:
870 * @in: (element-type utf8) (transfer full):
872 void test_gslist_everything_in (GSList *in)
874 assert_test_sequence_slist (in);
875 test_gslist_free (in);
878 /************************************************************************/
881 static char *table_data[3][2] = {
882 { "foo", "bar" }, { "baz", "bat" }, { "qux", "quux" }
885 static GHashTable *test_table_ghash_new_container()
889 hash = g_hash_table_new(g_str_hash, g_str_equal);
891 g_hash_table_insert(hash, table_data[i][0], table_data[i][1]);
895 static GHashTable *test_table_ghash_new_full()
899 hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
901 g_hash_table_insert(hash,
902 g_strdup(table_data[i][0]),
903 g_strdup(table_data[i][1]));
907 static /*const*/ GHashTable *test_table_ghash_const()
909 static GHashTable *hash = NULL;
911 hash = test_table_ghash_new_container();
918 * @in: (transfer full) (element-type utf8 utf8)
920 void test_ghash_free (GHashTable *in)
922 /* keys and values are deleted iff an appropriate element destroy function
924 g_hash_table_unref(in);
928 * test_ghash_null_return:
930 * Return value: (element-type utf8 utf8) (transfer none) (allow-none):
932 G_CONST_RETURN GHashTable *test_ghash_null_return (void)
938 * test_ghash_nothing_return:
940 * Return value: (element-type utf8 utf8) (transfer none):
942 G_CONST_RETURN GHashTable *test_ghash_nothing_return (void)
944 return test_table_ghash_const ();
948 * test_ghash_nothing_return2:
950 * Return value: (element-type utf8 utf8) (transfer none):
952 GHashTable *test_ghash_nothing_return2 (void)
954 return test_table_ghash_const ();
958 * test_ghash_container_return:
960 * Return value: (element-type utf8 utf8) (transfer container):
962 GHashTable *test_ghash_container_return (void)
964 return test_table_ghash_new_container ();
968 * test_ghash_everything_return:
970 * Return value: (element-type utf8 utf8) (transfer full):
972 GHashTable *test_ghash_everything_return (void)
974 return test_table_ghash_new_full ();
977 static void assert_test_table_ghash (const GHashTable *in)
979 GHashTable *h = test_table_ghash_const();
983 g_assert(g_hash_table_size(h) ==
984 g_hash_table_size((GHashTable*)in));
986 g_hash_table_iter_init(&iter, (GHashTable*)in);
987 while (g_hash_table_iter_next (&iter, &key, &value))
988 g_assert( strcmp(g_hash_table_lookup(h, (char*)key), (char*)value) == 0);
992 * test_ghash_null_in:
993 * @in: (element-type utf8 utf8) (allow-none):
995 void test_ghash_null_in (const GHashTable *in)
997 g_assert (in == NULL);
1001 * test_ghash_nothing_in:
1002 * @in: (element-type utf8 utf8):
1004 void test_ghash_nothing_in (const GHashTable *in)
1006 assert_test_table_ghash (in);
1010 * test_ghash_nothing_in2:
1011 * @in: (element-type utf8 utf8):
1013 void test_ghash_nothing_in2 (GHashTable *in)
1015 assert_test_table_ghash (in);
1019 * test_ghash_container_in:
1020 * @in: (transfer container) (element-type utf8 utf8):
1022 void test_ghash_container_in (GHashTable *in)
1024 assert_test_table_ghash (in);
1025 /* be careful and explicitly steal all the elements from the ghash before
1027 g_hash_table_steal_all (in);
1028 g_hash_table_destroy (in);
1031 static gboolean ghash_freer(gpointer key, gpointer value, gpointer user_data) {
1038 * test_ghash_everything_in:
1039 * @in: (transfer full) (element-type utf8 utf8):
1041 void test_ghash_everything_in (GHashTable *in)
1043 assert_test_table_ghash (in);
1044 /* free the elements, then free the container. Don't rely on the
1045 * GHashTable's key/value destructor functions. */
1046 g_hash_table_foreach_steal (in, ghash_freer, NULL);
1047 /* okay, dealloc the hash table. */
1048 g_hash_table_destroy (in);
1051 /* Nested collection types */
1054 * test_ghash_nested_everything_return:
1055 * Specify nested parameterized types directly with the (type ) annotation.
1057 * Return value: (type GLib.HashTable<utf8,GLib.HashTable<utf8,utf8>>) (transfer full):
1060 test_ghash_nested_everything_return (void)
1063 hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
1064 (void (*) (gpointer)) g_hash_table_destroy);
1065 g_hash_table_insert(hash, g_strdup("wibble"), test_table_ghash_new_full());
1070 * test_ghash_nested_everything_return2:
1071 * Another way of specifying nested parameterized types: using the
1072 * element-type annotation.
1074 * Return value: (element-type utf8 GLib.HashTable<utf8,utf8>) (transfer full):
1077 test_ghash_nested_everything_return2 (void)
1079 return test_ghash_nested_everything_return();
1082 /************************************************************************/
1089 test_enum_get_type (void)
1091 static GType etype = 0;
1092 if (G_UNLIKELY(etype == 0)) {
1093 static const GEnumValue values[] = {
1094 { TEST_VALUE1, "TEST_VALUE1", "value1" },
1095 { TEST_VALUE2, "TEST_VALUE2", "value2" },
1096 { TEST_VALUE3, "TEST_VALUE3", "value3" },
1099 etype = g_enum_register_static (g_intern_static_string ("TestEnum"), values);
1106 test_flags_get_type (void)
1108 static GType etype = 0;
1109 if (G_UNLIKELY(etype == 0)) {
1110 static const GFlagsValue values[] = {
1111 { TEST_FLAG1, "TEST_FLAG1", "flag1" },
1112 { TEST_FLAG2, "TEST_FLAG2", "flag2" },
1113 { TEST_FLAG3, "TEST_FLAG3", "flag3" },
1116 etype = g_flags_register_static (g_intern_static_string ("TestFlags"), values);
1123 test_enum_param(TestEnum e)
1128 ec = g_type_class_ref (test_enum_get_type ());
1129 ev = g_enum_get_value (ec, e);
1130 g_type_class_unref (ec);
1132 return ev->value_nick;
1138 * test_struct_a_clone:
1140 * @a_out: the cloned structure
1142 * Make a copy of a TestStructA
1145 test_struct_a_clone (TestStructA *a,
1152 * test_struct_b_clone:
1154 * @b_out: the cloned structure
1156 * Make a copy of a TestStructB
1159 test_struct_b_clone (TestStructB *b,
1165 /* plain-old-data boxed types */
1168 test_simple_boxed_a_copy (TestSimpleBoxedA *a)
1170 TestSimpleBoxedA *new_a = g_slice_new (TestSimpleBoxedA);
1178 test_simple_boxed_a_free (TestSimpleBoxedA *a)
1180 g_slice_free (TestSimpleBoxedA, a);
1184 test_simple_boxed_a_get_type (void)
1186 static GType our_type = 0;
1189 our_type = g_boxed_type_register_static (g_intern_static_string ("TestSimpleBoxedA"),
1190 (GBoxedCopyFunc)test_simple_boxed_a_copy,
1191 (GBoxedFreeFunc)test_simple_boxed_a_free);
1196 test_simple_boxed_b_copy (TestSimpleBoxedB *b)
1198 TestSimpleBoxedB *new_b = g_slice_new (TestSimpleBoxedB);
1206 test_simple_boxed_a_equals (TestSimpleBoxedA *a,
1207 TestSimpleBoxedA *other_a)
1209 return (a->some_int == other_a->some_int &&
1210 a->some_int8 == other_a->some_int8 &&
1211 a->some_double == other_a->some_double);
1214 const TestSimpleBoxedA*
1215 test_simple_boxed_a_const_return (void)
1217 static TestSimpleBoxedA simple_a = {
1225 test_simple_boxed_b_free (TestSimpleBoxedB *a)
1227 g_slice_free (TestSimpleBoxedB, a);
1231 test_simple_boxed_b_get_type (void)
1233 static GType our_type = 0;
1236 our_type = g_boxed_type_register_static (g_intern_static_string ("TestSimpleBoxedB"),
1237 (GBoxedCopyFunc)test_simple_boxed_b_copy,
1238 (GBoxedFreeFunc)test_simple_boxed_b_free);
1244 struct _TestBoxedPrivate
1250 test_boxed_new (void)
1252 TestBoxed *boxed = g_slice_new0(TestBoxed);
1253 boxed->priv = g_slice_new0(TestBoxedPrivate);
1254 boxed->priv->magic = 0xdeadbeef;
1260 test_boxed_copy (TestBoxed *boxed)
1262 TestBoxed *new_boxed = test_boxed_new();
1263 TestBoxedPrivate *save;
1265 save = new_boxed->priv;
1266 *new_boxed = *boxed;
1267 new_boxed->priv = save;
1273 test_boxed_equals (TestBoxed *boxed,
1276 return (other->some_int8 == boxed->some_int8 &&
1277 test_simple_boxed_a_equals(&other->nested_a, &boxed->nested_a));
1281 test_boxed_free (TestBoxed *boxed)
1283 g_assert (boxed->priv->magic == 0xdeadbeef);
1285 g_slice_free (TestBoxedPrivate, boxed->priv);
1286 g_slice_free (TestBoxed, boxed);
1290 test_boxed_get_type (void)
1292 static GType our_type = 0;
1295 our_type = g_boxed_type_register_static (g_intern_static_string ("TestBoxed"),
1296 (GBoxedCopyFunc)test_boxed_copy,
1297 (GBoxedFreeFunc)test_boxed_free);
1301 G_DEFINE_TYPE(TestObj, test_obj, G_TYPE_OBJECT);
1305 PROP_TEST_OBJ_BARE = 1,
1310 test_obj_set_property (GObject *object,
1312 const GValue *value,
1315 TestObj *self = TEST_OBJECT (object);
1317 switch (property_id)
1319 case PROP_TEST_OBJ_BARE:
1320 test_obj_set_bare (self, g_value_get_object (value));
1323 case PROP_TEST_OBJ_BOXED:
1325 test_boxed_free (self->boxed);
1326 self->boxed = g_value_dup_boxed (value);
1330 /* We don't have any other property... */
1331 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1337 test_obj_get_property (GObject *object,
1342 TestObj *self = TEST_OBJECT (object);
1344 switch (property_id)
1346 case PROP_TEST_OBJ_BARE:
1347 g_value_set_object (value, self->bare);
1350 case PROP_TEST_OBJ_BOXED:
1351 g_value_set_boxed (value, self->boxed);
1355 /* We don't have any other property... */
1356 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1362 test_obj_dispose (GObject *gobject)
1364 TestObj *self = TEST_OBJECT (gobject);
1368 g_object_unref (self->bare);
1375 test_boxed_free (self->boxed);
1379 /* Chain up to the parent class */
1380 G_OBJECT_CLASS (test_obj_parent_class)->dispose (gobject);
1384 test_obj_default_matrix (TestObj *obj, const char *somestr)
1390 test_obj_class_init (TestObjClass *klass)
1392 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1394 GType param_types[1];
1396 klass->test_signal =
1397 g_signal_newv ("test",
1398 G_TYPE_FROM_CLASS (gobject_class),
1399 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1401 NULL /* accumulator */,
1402 NULL /* accumulator data */,
1403 g_cclosure_marshal_VOID__VOID,
1404 G_TYPE_NONE /* return_type */,
1406 NULL /* param_types */);
1408 param_types[0] = test_simple_boxed_a_get_type() | G_SIGNAL_TYPE_STATIC_SCOPE;
1409 klass->test_signal_with_static_scope_arg =
1410 g_signal_newv ("test-with-static-scope-arg",
1411 G_TYPE_FROM_CLASS (gobject_class),
1412 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1414 NULL /* accumulator */,
1415 NULL /* accumulator data */,
1416 g_cclosure_marshal_VOID__BOXED,
1417 G_TYPE_NONE /* return_type */,
1421 gobject_class->set_property = test_obj_set_property;
1422 gobject_class->get_property = test_obj_get_property;
1423 gobject_class->dispose = test_obj_dispose;
1425 pspec = g_param_spec_object ("bare",
1427 "A contained object",
1430 g_object_class_install_property (gobject_class,
1434 pspec = g_param_spec_boxed ("boxed",
1436 "A contained boxed struct",
1439 g_object_class_install_property (gobject_class,
1440 PROP_TEST_OBJ_BOXED,
1443 klass->matrix = test_obj_default_matrix;
1447 test_obj_init (TestObj *obj)
1454 test_obj_new_from_file (const char *x, GError **error)
1456 return g_object_new (TEST_TYPE_OBJ, NULL);
1460 * test_obj_set_bare:
1461 * @bare: (allow-none):
1464 test_obj_set_bare (TestObj *obj, GObject *bare)
1467 g_object_unref (obj->bare);
1470 g_object_ref (obj->bare);
1474 test_obj_instance_method (TestObj *obj)
1480 test_obj_static_method (int x)
1486 * test_obj_torture_signature_0:
1497 test_obj_torture_signature_0 (TestObj *obj,
1507 *q = g_utf8_strlen (foo, -1) + m;
1511 * test_obj_torture_signature_1:
1521 * This function throws an error if m is odd.
1524 test_obj_torture_signature_1 (TestObj *obj,
1535 *q = g_utf8_strlen (foo, -1) + m;
1538 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "m is odd");
1543 * test_obj_do_matrix:
1545 * @somestr: Meaningless string
1547 * This method is virtual. Notably its name differs from the virtual
1548 * slot name, which makes it useful for testing bindings handle this
1554 test_obj_do_matrix (TestObj *obj, const char *somestr)
1556 return TEST_OBJ_GET_CLASS (obj)->matrix (obj, somestr);
1559 typedef struct _CallbackInfo CallbackInfo;
1561 struct _CallbackInfo
1563 TestCallbackUserData callback;
1564 GDestroyNotify notify;
1569 G_DEFINE_TYPE(TestSubObj, test_sub_obj, TEST_TYPE_OBJ);
1572 test_sub_obj_class_init (TestSubObjClass *klass)
1577 test_sub_obj_init (TestSubObj *obj)
1584 return g_object_new (TEST_TYPE_SUB_OBJ, NULL);
1588 test_sub_obj_instance_method (TestSubObj *obj)
1594 test_sub_obj_unset_bare (TestSubObj *obj)
1596 test_obj_set_bare(TEST_OBJECT(obj), NULL);
1602 * @callback: (scope call) (allow-none):
1606 test_callback (TestCallback callback)
1608 if (callback != NULL)
1614 * test_callback_user_data:
1615 * @callback: (scope call):
1617 * Call - callback parameter persists for the duration of the method
1618 * call and can be released on return.
1621 test_callback_user_data (TestCallbackUserData callback,
1624 return callback(user_data);
1627 static GSList *notified_callbacks = NULL;
1630 * test_callback_destroy_notify:
1631 * @callback: (scope notified):
1633 * Notified - callback persists until a DestroyNotify delegate
1637 test_callback_destroy_notify (TestCallbackUserData callback,
1639 GDestroyNotify notify)
1644 retval = callback(user_data);
1646 info = g_slice_new(CallbackInfo);
1647 info->callback = callback;
1648 info->notify = notify;
1649 info->user_data = user_data;
1651 notified_callbacks = g_slist_prepend(notified_callbacks, info);
1657 * test_callback_thaw_notifications:
1659 * Invokes all callbacks installed by #test_callback_destroy_notify(),
1660 * adding up their return values, and removes them, invoking the
1661 * corresponding destroy notfications.
1663 * Return value: Sum of the return values of the invoked callbacks.
1666 test_callback_thaw_notifications (void)
1671 for (node = notified_callbacks; node != NULL; node = node->next)
1673 CallbackInfo *info = node->data;
1674 retval += info->callback (info->user_data);
1676 info->notify (info->user_data);
1677 g_slice_free (CallbackInfo, info);
1680 g_slist_free (notified_callbacks);
1681 notified_callbacks = NULL;
1686 static GSList *async_callbacks = NULL;
1689 * test_callback_async:
1690 * @callback: (scope async):
1694 test_callback_async (TestCallbackUserData callback,
1699 info = g_slice_new(CallbackInfo);
1700 info->callback = callback;
1701 info->user_data = user_data;
1703 async_callbacks = g_slist_prepend(async_callbacks, info);
1707 * test_callback_thaw_async:
1710 test_callback_thaw_async (void)
1715 for (node = async_callbacks; node != NULL; node = node->next)
1717 CallbackInfo *info = node->data;
1718 retval = info->callback (info->user_data);
1719 g_slice_free (CallbackInfo, info);
1722 g_slist_free (async_callbacks);
1723 async_callbacks = NULL;
1728 * test_callback_infinite:
1729 * @callback: (scope infinite):
1731 * Infinite - callback persists forever.
1734 static GSList *infinite_callbacks = NULL;
1737 test_callback_infinite (TestCallbackUserData callback,
1740 infinite_callbacks = g_slist_prepend(infinite_callbacks, callback);
1742 return callback(user_data);
1748 test_interface_class_init(void *g_iface)
1753 test_interface_get_type(void)
1755 static GType type = 0;
1757 type = g_type_register_static_simple (G_TYPE_INTERFACE,
1758 "EverythingTestInterface",
1759 sizeof (TestInterfaceIface),
1760 (GClassInitFunc) test_interface_class_init,
1767 /* gobject with non-standard prefix */
1768 G_DEFINE_TYPE(TestWi8021x, test_wi_802_1x, G_TYPE_OBJECT);
1772 PROP_TEST_WI_802_1X_TESTBOOL = 1
1776 test_wi_802_1x_set_property (GObject *object,
1778 const GValue *value,
1781 TestWi8021x *self = TEST_WI_802_1X (object);
1783 switch (property_id)
1785 case PROP_TEST_WI_802_1X_TESTBOOL:
1786 test_wi_802_1x_set_testbool (self, g_value_get_boolean (value));
1790 /* We don't have any other property... */
1791 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1797 test_wi_802_1x_get_property (GObject *object,
1802 TestWi8021x *self = TEST_WI_802_1X (object);
1804 switch (property_id)
1806 case PROP_TEST_WI_802_1X_TESTBOOL:
1807 g_value_set_boolean (value, test_wi_802_1x_get_testbool (self));
1811 /* We don't have any other property... */
1812 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1818 test_wi_802_1x_dispose (GObject *gobject)
1820 /* Chain up to the parent class */
1821 G_OBJECT_CLASS (test_wi_802_1x_parent_class)->dispose (gobject);
1825 test_wi_802_1x_class_init (TestWi8021xClass *klass)
1827 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1830 gobject_class->set_property = test_wi_802_1x_set_property;
1831 gobject_class->get_property = test_wi_802_1x_get_property;
1832 gobject_class->dispose = test_wi_802_1x_dispose;
1834 pspec = g_param_spec_boolean ("testbool",
1835 "Nick for testbool",
1836 "Blurb for testbool",
1839 g_object_class_install_property (gobject_class,
1840 PROP_TEST_WI_802_1X_TESTBOOL,
1845 test_wi_802_1x_init (TestWi8021x *obj)
1847 obj->testbool = TRUE;
1851 test_wi_802_1x_new (void)
1853 return g_object_new (TEST_TYPE_WI_802_1X, NULL);
1857 test_wi_802_1x_set_testbool (TestWi8021x *obj, gboolean val)
1859 obj->testbool = val;
1863 test_wi_802_1x_get_testbool (TestWi8021x *obj)
1865 return obj->testbool;
1869 test_wi_802_1x_static_method (int x)
1875 * test_torture_signature_0:
1885 test_torture_signature_0 (int x,
1894 *q = g_utf8_strlen (foo, -1) + m;
1898 * test_torture_signature_1:
1907 * This function throws an error if m is odd.
1910 test_torture_signature_1 (int x,
1920 *q = g_utf8_strlen (foo, -1) + m;
1923 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "m is odd");
1928 * test_torture_signature_2:
1941 test_torture_signature_2 (int x,
1942 TestCallbackUserData callback,
1944 GDestroyNotify notify,
1953 *q = g_utf8_strlen (foo, -1) + m;