Debian Codegraph @

subprojects/gobject-introspection-tests/regress.c

raw
1 /*
2 SPDX-License-Identifier: GPL-2.0-or-later AND LGPL-2.0-or-later AND MIT
3 SPDX-FileCopyrightText: 2008-2015 Colin Walters <[email protected]>
4 SPDX-FileCopyrightText: 2008 Johan Bilien
5 SPDX-FileCopyrightText: 2008 Lucas Almeida Rocha
6 SPDX-FileCopyrightText: 2008, 2010 Owen W. Taylor
7 SPDX-FileCopyrightText: 2008 Tommi Komulainen
8 SPDX-FileCopyrightText: 2009 Andreas Rottmann <[email protected]>
9 SPDX-FileCopyrightText: 2009 Havoc Pennington
10 SPDX-FileCopyrightText: 2009-2010 Johan Dahlin
11 SPDX-FileCopyrightText: 2009-2011 litl, LLC
12 SPDX-FileCopyrightText: 2009 Mark Lee
13 SPDX-FileCopyrightText: 2009 Maxim Ermilov
14 SPDX-FileCopyrightText: 2009 Simon van der Linden
15 SPDX-FileCopyrightText: 2009-2010 Sugar Labs
16 SPDX-FileCopyrightText: 2010-2012, 2015 Collabora, Ltd.
17 SPDX-FileCopyrightText: 2010 Jonathan Matthew
18 SPDX-FileCopyrightText: 2010 Zach Goldberg
19 SPDX-FileCopyrightText: 2011-2012, 2014 Giovanni Campagna
20 SPDX-FileCopyrightText: 2011-2013 Martin Pitt
21 SPDX-FileCopyrightText: 2011 Pavel Holejsovsky
22 SPDX-FileCopyrightText: 2011, 2024 Red Hat, Inc.
23 SPDX-FileCopyrightText: 2011 Xavier Claessens
24 SPDX-FileCopyrightText: 2012 Bastian Winkler
25 SPDX-FileCopyrightText: 2012 Canonical Ltd.
26 SPDX-FileCopyrightText: 2012 Coeus Group
27 SPDX-FileCopyrightText: 2012 Dieter Verfaillie
28 SPDX-FileCopyrightText: 2012 Jasper St. Pierre
29 SPDX-FileCopyrightText: 2012 Jon Nordby
30 SPDX-FileCopyrightText: 2012 Paolo Borelli
31 SPDX-FileCopyrightText: 2012 Simon Feltman
32 SPDX-FileCopyrightText: 2012 Torsten Schönfeld
33 SPDX-FileCopyrightText: 2014-2015 RIFT.io, Inc.
34 SPDX-FileCopyrightText: 2015, 2018 Christoph Reiter
35 SPDX-FileCopyrightText: 2015 Debarshi Ray
36 SPDX-FileCopyrightText: 2015 Ben Iofel
37 SPDX-FileCopyrightText: 2016 Lionel Landwerlin
38 SPDX-FileCopyrightText: 2016-2019, 2024 Philip Chimento <[email protected]>
39 SPDX-FileCopyrightText: 2017 Endless Mobile, Inc.
40 SPDX-FileCopyrightText: 2017 Rico Tzschichholz
41 SPDX-FileCopyrightText: 2018-2019 Tomasz Miąsko
42 SPDX-FileCopyrightText: 2019, 2021 Emmanuele Bassi
43 SPDX-FileCopyrightText: 2021, 2023 Marco Trevisan
44 SPDX-FileCopyrightText: 2023 Evan Welsh
45 SPDX-FileCopyrightText: 2024 Simon McVittie
46 */
47
48 #include <stdlib.h>
49 #include <string.h>
50
51 #include <glib-object.h>
52 #include <gobject/gvaluecollector.h>
53
54 #ifndef GI_TEST_DISABLE_CAIRO
55 #include <cairo-gobject.h>
56 #include <cairo.h>
57 #endif /* GI_TEST_DISABLE_CAIRO */
58
59 #include "regress.h"
60
61 /* return annotations */
62
63 /**
64 * regress_test_return_allow_none:
65 *
66 * Returns: (allow-none):
67 */
68 char *
69 regress_test_return_allow_none (void)
70 {
71 return NULL;
72 }
73
74 /**
75 * regress_test_return_nullable:
76 *
77 * Returns: (nullable):
78 */
79 char *
80 regress_test_return_nullable (void)
81 {
82 return NULL;
83 }
84
85 /* basic types */
86 gboolean
87 regress_test_boolean (gboolean in)
88 {
89 return in;
90 }
91
92 gboolean
93 regress_test_boolean_true (gboolean in)
94 {
95 g_assert_true (in);
96 return in;
97 }
98
99 gboolean
100 regress_test_boolean_false (gboolean in)
101 {
102 g_assert_false (in);
103 return in;
104 }
105
106 gint8
107 regress_test_int8 (gint8 in)
108 {
109 return in;
110 }
111
112 guint8
113 regress_test_uint8 (guint8 in)
114 {
115 return in;
116 }
117
118 gint16
119 regress_test_int16 (gint16 in)
120 {
121 return in;
122 }
123
124 guint16
125 regress_test_uint16 (guint16 in)
126 {
127 return in;
128 }
129
130 gint32
131 regress_test_int32 (gint32 in)
132 {
133 return in;
134 }
135
136 guint32
137 regress_test_uint32 (guint32 in)
138 {
139 return in;
140 }
141
142 gint64
143 regress_test_int64 (gint64 in)
144 {
145 return in;
146 }
147
148 guint64
149 regress_test_uint64 (guint64 in)
150 {
151 return in;
152 }
153
154 gshort
155 regress_test_short (gshort in)
156 {
157 return in;
158 }
159
160 gushort
161 regress_test_ushort (gushort in)
162 {
163 return in;
164 }
165
166 gint
167 regress_test_int (gint in)
168 {
169 return in;
170 }
171
172 guint
173 regress_test_uint (guint in)
174 {
175 return in;
176 }
177
178 glong
179 regress_test_long (glong in)
180 {
181 return in;
182 }
183
184 gulong
185 regress_test_ulong (gulong in)
186 {
187 return in;
188 }
189
190 gssize
191 regress_test_ssize (gssize in)
192 {
193 return in;
194 }
195
196 gsize
197 regress_test_size (gsize in)
198 {
199 return in;
200 }
201
202 gfloat
203 regress_test_float (gfloat in)
204 {
205 return in;
206 }
207
208 gdouble
209 regress_test_double (gdouble in)
210 {
211 return in;
212 }
213
214 gunichar
215 regress_test_unichar (gunichar in)
216 {
217 return in;
218 }
219
220 time_t
221 regress_test_timet (time_t in)
222 {
223 return in;
224 }
225
226 off_t
227 regress_test_offt (off_t in)
228 {
229 return in;
230 }
231
232 GType
233 regress_test_gtype (GType in)
234 {
235 return in;
236 }
237
238 int
239 regress_test_closure (GClosure *closure)
240 {
241 GValue return_value = {
242 0,
243 };
244 int ret;
245
246 g_value_init (&return_value, G_TYPE_INT);
247
248 g_closure_invoke (closure,
249 &return_value,
250 0, NULL,
251 NULL);
252
253 ret = g_value_get_int (&return_value);
254
255 g_value_unset (&return_value);
256
257 return ret;
258 }
259
260 int
261 regress_test_closure_one_arg (GClosure *closure, int arg)
262 {
263 GValue return_value = {
264 0,
265 };
266 GValue arguments[1];
267 int ret;
268
269 g_value_init (&return_value, G_TYPE_INT);
270
271 memset (&arguments[0], 0, sizeof (arguments));
272 g_value_init (&arguments[0], G_TYPE_INT);
273 g_value_set_int (&arguments[0], arg);
274
275 g_closure_invoke (closure,
276 &return_value,
277 1, arguments,
278 NULL);
279
280 ret = g_value_get_int (&return_value);
281
282 g_value_unset (&return_value);
283 g_value_unset (&arguments[0]);
284
285 return ret;
286 }
287
288 /**
289 * regress_test_closure_variant:
290 * @closure: GClosure which takes one GVariant and returns a GVariant
291 * @arg: (allow-none) (transfer none): a GVariant passed as argument to @closure
292 *
293 * Return value: (transfer full): the return value of @closure
294 */
295 GVariant *
296 regress_test_closure_variant (GClosure *closure, GVariant *arg)
297 {
298 GValue return_value = {
299 0,
300 };
301 GValue arguments[1] = { {
302 0,
303 } };
304 GVariant *ret;
305
306 g_value_init (&return_value, G_TYPE_VARIANT);
307
308 g_value_init (&arguments[0], G_TYPE_VARIANT);
309 g_value_set_variant (&arguments[0], arg);
310
311 g_closure_invoke (closure,
312 &return_value,
313 1, arguments,
314 NULL);
315
316 ret = g_value_get_variant (&return_value);
317 if (ret != NULL)
318 g_variant_ref (ret);
319
320 g_value_unset (&return_value);
321 g_value_unset (&arguments[0]);
322
323 return ret;
324 }
325
326 /**
327 * regress_test_value_arg:
328 * @v: (transfer none): a GValue expected to contain an int
329 *
330 * Return value: the int contained in the GValue.
331 */
332 int
333 regress_test_int_value_arg (const GValue *v)
334 {
335 int i;
336
337 i = g_value_get_int (v);
338
339 return i;
340 }
341
342 static GValue global_value;
343 /**
344 * regress_test_value_return:
345 * @i: an int
346 *
347 * Return value: (transfer none): the int wrapped in a GValue.
348 */
349 const GValue *
350 regress_test_value_return (int i)
351 {
352 memset (&global_value, '\0', sizeof (GValue));
353
354 g_value_init (&global_value, G_TYPE_INT);
355 g_value_set_int (&global_value, i);
356
357 return &global_value;
358 }
359
360 /************************************************************************/
361 /* foreign structs */
362
363 #ifndef GI_TEST_DISABLE_CAIRO
364 /**
365 * regress_test_cairo_context_full_return:
366 *
367 * Returns: (transfer full):
368 */
369 cairo_t *
370 regress_test_cairo_context_full_return (void)
371 {
372 cairo_surface_t *surface;
373 cairo_t *cr;
374 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 10, 10);
375 cr = cairo_create (surface);
376 cairo_surface_destroy (surface);
377 return cr;
378 }
379
380 /**
381 * regress_test_cairo_context_none_in:
382 * @context: (transfer none):
383 */
384 void
385 regress_test_cairo_context_none_in (cairo_t *context)
386 {
387 cairo_surface_t *surface = cairo_get_target (context);
388
389 g_assert (cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32);
390 g_assert (cairo_image_surface_get_width (surface) == 10);
391 g_assert (cairo_image_surface_get_height (surface) == 10);
392 }
393
394 /**
395 * regress_test_cairo_surface_none_return:
396 *
397 * Returns: (transfer none):
398 */
399 cairo_surface_t *
400 regress_test_cairo_surface_none_return (void)
401 {
402 static cairo_surface_t *surface;
403
404 if (surface == NULL)
405 {
406 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 10, 10);
407 }
408
409 return surface;
410 }
411
412 /**
413 * regress_test_cairo_surface_full_return:
414 *
415 * Returns: (transfer full):
416 */
417 cairo_surface_t *
418 regress_test_cairo_surface_full_return (void)
419 {
420 return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 10, 10);
421 }
422
423 /**
424 * regress_test_cairo_surface_none_in:
425 * @surface: (transfer none):
426 */
427 void
428 regress_test_cairo_surface_none_in (cairo_surface_t *surface)
429 {
430 g_assert (cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32);
431 g_assert (cairo_image_surface_get_width (surface) == 10);
432 g_assert (cairo_image_surface_get_height (surface) == 10);
433 }
434
435 /**
436 * regress_test_cairo_surface_full_out:
437 * @surface: (out) (transfer full):
438 */
439 void
440 regress_test_cairo_surface_full_out (cairo_surface_t **surface)
441 {
442 *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 10, 10);
443 }
444 #endif /* GI_TEST_DISABLE_CAIRO */
445
446 /**
447 * regress_test_gvariant_i:
448 *
449 * Returns: (transfer none): New variant
450 */
451 GVariant *
452 regress_test_gvariant_i (void)
453 {
454 return g_variant_new_int32 (1);
455 }
456
457 /**
458 * regress_test_gvariant_s:
459 *
460 * Returns: (transfer none): New variant
461 */
462 GVariant *
463 regress_test_gvariant_s (void)
464 {
465 return g_variant_new_string ("one");
466 }
467
468 /**
469 * regress_test_gvariant_asv:
470 *
471 * Returns: (transfer none): New variant
472 */
473 GVariant *
474 regress_test_gvariant_asv (void)
475 {
476 GVariantBuilder b;
477
478 g_variant_builder_init (&b, G_VARIANT_TYPE ("a{sv}"));
479
480 g_variant_builder_add (&b, "{sv}", "name", g_variant_new_string ("foo"));
481 g_variant_builder_add (&b, "{sv}", "timeout", g_variant_new_int32 (10));
482
483 return g_variant_builder_end (&b);
484 }
485
486 /**
487 * regress_test_gvariant_v:
488 *
489 * Returns: (transfer none): New variant
490 */
491 GVariant *
492 regress_test_gvariant_v (void)
493 {
494 return g_variant_new_variant (g_variant_new_string ("contents"));
495 }
496
497 /**
498 * regress_test_gvariant_as:
499 *
500 * Returns: (transfer none): New variant
501 */
502 GVariant *
503 regress_test_gvariant_as (void)
504 {
505 const char *as[] = { "one", "two", "three", NULL };
506
507 return g_variant_new_strv (as, -1);
508 }
509
510 /************************************************************************/
511 /* utf8 */
512 /* insert BLACK HEART SUIT to ensure UTF-8 doesn't get mangled */
513 static const char utf8_const[] = "const \xe2\x99\xa5 utf8";
514 static const char utf8_nonconst[] = "nonconst \xe2\x99\xa5 utf8";
515
516 /**
517 * regress_test_utf8_const_return:
518 *
519 * Return value: UTF-8 string
520 */
521 const char *
522 regress_test_utf8_const_return (void)
523 {
524 /* transfer mode none */
525 return utf8_const;
526 }
527
528 /**
529 * regress_test_utf8_nonconst_return:
530 *
531 * Return value: (transfer full): UTF-8 string
532 */
533 char *
534 regress_test_utf8_nonconst_return (void)
535 {
536 return g_strdup (utf8_nonconst);
537 }
538
539 /**
540 * regress_test_utf8_const_in:
541 *
542 */
543 void
544 regress_test_utf8_const_in (const char *in)
545 {
546 /* transfer mode none */
547 g_assert (strcmp (in, utf8_const) == 0);
548 }
549
550 /**
551 * regress_test_utf8_out:
552 * @out: (out) (transfer full):
553 */
554 void
555 regress_test_utf8_out (char **out)
556 {
557 /* out parameter, transfer mode full */
558 *out = g_strdup (utf8_nonconst);
559 }
560
561 /**
562 * regress_test_utf8_inout:
563 * @inout: (inout) (transfer full):
564 */
565 void
566 regress_test_utf8_inout (char **inout)
567 {
568 /* inout parameter, transfer mode full */
569 g_assert (strcmp (*inout, utf8_const) == 0);
570 g_free (*inout);
571 *inout = g_strdup (utf8_nonconst);
572 }
573
574 /**
575 * regress_test_filename_return:
576 *
577 * Return value: (element-type filename) (transfer full): list of strings
578 */
579 GSList *
580 regress_test_filename_return (void)
581 {
582 GSList *filenames = NULL;
583 filenames = g_slist_prepend (filenames, g_filename_from_utf8 ("/etc/fstab", -1, NULL, NULL, NULL));
584 filenames = g_slist_prepend (filenames, g_filename_from_utf8 ("åäö", -1, NULL, NULL, NULL));
585 return filenames;
586 }
587
588 /* in arguments after out arguments */
589
590 /**
591 * regress_test_int_out_utf8:
592 * @length: (out):
593 * @in:
594 */
595 void
596 regress_test_int_out_utf8 (int *length, const char *in)
597 {
598 *length = g_utf8_strlen (in, -1);
599 }
600
601 /* multiple output arguments */
602
603 /**
604 * regress_test_multi_double_args:
605 * @in:
606 * @one: (out):
607 * @two: (out):
608 */
609 void
610 regress_test_multi_double_args (gdouble in, gdouble *one, gdouble *two)
611 {
612 *one = in * 2;
613 *two = in * 3;
614 }
615
616 /**
617 * regress_test_utf8_out_out:
618 * @out0: (out) (transfer full): a copy of "first"
619 * @out1: (out) (transfer full): a copy of "second"
620 */
621 void
622 regress_test_utf8_out_out (char **out0, char **out1)
623 {
624 *out0 = g_strdup ("first");
625 *out1 = g_strdup ("second");
626 }
627
628 /**
629 * regress_test_utf8_out_nonconst_return:
630 * @out: (out) (transfer full): a copy of "second"
631 *
632 * Returns: (transfer full): a copy of "first"
633 */
634 char *
635 regress_test_utf8_out_nonconst_return (char **out)
636 {
637 *out = g_strdup ("second");
638 return g_strdup ("first");
639 }
640
641 /**
642 * regress_test_utf8_null_in:
643 * @in: (allow-none):
644 */
645 void
646 regress_test_utf8_null_in (char *in)
647 {
648 g_assert (in == NULL);
649 }
650
651 /**
652 * regress_test_utf8_null_out:
653 * @char_out: (allow-none) (out):
654 */
655 void
656 regress_test_utf8_null_out (char **char_out)
657 {
658 *char_out = NULL;
659 }
660
661 /* non-basic-types */
662
663 static const char *test_sequence[] = { "1", "2", "3" };
664
665 /* array */
666
667 /**
668 * regress_test_array_int_in:
669 * @n_ints:
670 * @ints: (array length=n_ints): List of ints
671 */
672 int
673 regress_test_array_int_in (int n_ints, int *ints)
674 {
675 int i, sum = 0;
676 for (i = 0; i < n_ints; i++)
677 sum += ints[i];
678 return sum;
679 }
680
681 /**
682 * regress_test_array_int_out:
683 * @n_ints: (out): the length of @ints
684 * @ints: (out) (array length=n_ints) (transfer full): a list of 5 integers, from 0 to 4 in consecutive order
685 */
686 void
687 regress_test_array_int_out (int *n_ints, int **ints)
688 {
689 int i;
690 *n_ints = 5;
691 *ints = g_malloc0 (sizeof (**ints) * *n_ints);
692 for (i = 1; i < *n_ints; i++)
693 (*ints)[i] = (*ints)[i - 1] + 1;
694 }
695
696 /**
697 * regress_test_array_int_inout:
698 * @n_ints: (inout): the length of @ints
699 * @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
700 */
701 void
702 regress_test_array_int_inout (int *n_ints, int **ints)
703 {
704 int i;
705 int *new_ints;
706
707 if (0 < *n_ints)
708 {
709 *n_ints -= 1;
710 new_ints = g_malloc (sizeof (**ints) * *n_ints);
711 for (i = 0; i < *n_ints; i++)
712 new_ints[i] = (*ints)[i + 1] + 1;
713
714 g_free (*ints);
715 *ints = new_ints;
716 }
717 }
718
719 /**
720 * regress_test_array_gint8_in:
721 * @n_ints:
722 * @ints: (array length=n_ints): List of ints
723 */
724 int
725 regress_test_array_gint8_in (int n_ints, gint8 *ints)
726 {
727 int i, sum = 0;
728 for (i = 0; i < n_ints; i++)
729 sum += ints[i];
730 return sum;
731 }
732
733 /**
734 * regress_test_array_gint16_in:
735 * @n_ints:
736 * @ints: (array length=n_ints): List of ints
737 */
738 int
739 regress_test_array_gint16_in (int n_ints, gint16 *ints)
740 {
741 int i, sum = 0;
742 for (i = 0; i < n_ints; i++)
743 sum += ints[i];
744 return sum;
745 }
746
747 /**
748 * regress_test_array_gint32_in:
749 * @n_ints:
750 * @ints: (array length=n_ints): List of ints
751 */
752 gint32
753 regress_test_array_gint32_in (int n_ints, gint32 *ints)
754 {
755 int i;
756 gint32 sum = 0;
757 for (i = 0; i < n_ints; i++)
758 sum += ints[i];
759 return sum;
760 }
761
762 /**
763 * regress_test_array_gint64_in:
764 * @n_ints:
765 * @ints: (array length=n_ints): List of ints
766 */
767 gint64
768 regress_test_array_gint64_in (int n_ints, gint64 *ints)
769 {
770 int i;
771 gint64 sum = 0;
772 for (i = 0; i < n_ints; i++)
773 sum += ints[i];
774 return sum;
775 }
776
777 /**
778 * regress_test_strv_in:
779 * @arr: (array zero-terminated=1) (transfer none):
780 */
781 gboolean
782 regress_test_strv_in (char **arr)
783 {
784 if (g_strv_length (arr) != 3)
785 return FALSE;
786 if (strcmp (arr[0], "1") != 0)
787 return FALSE;
788 if (strcmp (arr[1], "2") != 0)
789 return FALSE;
790 if (strcmp (arr[2], "3") != 0)
791 return FALSE;
792 return TRUE;
793 }
794
795 /**
796 * regress_test_array_gtype_in:
797 * @n_types:
798 * @types: (array length=n_types): List of types
799 *
800 * Return value: (transfer full): string representation of provided types
801 */
802 char *
803 regress_test_array_gtype_in (int n_types, GType *types)
804 {
805 GString *string;
806 int i;
807
808 string = g_string_new ("[");
809 for (i = 0; i < n_types; i++)
810 {
811 g_string_append (string, g_type_name (types[i]));
812 g_string_append_c (string, ',');
813 }
814 g_string_append_c (string, ']');
815 return g_string_free (string, FALSE);
816 }
817
818 /**
819 * regress_test_strv_out:
820 *
821 * Returns: (transfer full):
822 */
823 char **
824 regress_test_strv_out (void)
825 {
826 int i = 0;
827 int n = 6;
828 char **ret = g_new (char *, n);
829 ret[i++] = g_strdup ("thanks");
830 ret[i++] = g_strdup ("for");
831 ret[i++] = g_strdup ("all");
832 ret[i++] = g_strdup ("the");
833 ret[i++] = g_strdup ("fish");
834 ret[i++] = NULL;
835 g_assert (i == n);
836 return ret;
837 }
838
839 /**
840 * regress_test_strv_out_container:
841 *
842 * Return value: (array zero-terminated=1) (transfer container):
843 */
844 const char **
845 regress_test_strv_out_container (void)
846 {
847 const char **ret = g_new (const char *, 4);
848 ret[0] = "1";
849 ret[1] = "2";
850 ret[2] = "3";
851 ret[3] = NULL;
852 return ret;
853 }
854
855 /**
856 * regress_test_strv_outarg:
857 * @retp: (array zero-terminated=1) (out) (transfer container):
858 */
859 void
860 regress_test_strv_outarg (const char ***retp)
861 {
862 const char **ret = g_new (const char *, 4);
863 ret[0] = "1";
864 ret[1] = "2";
865 ret[2] = "3";
866 ret[3] = NULL;
867 *retp = ret;
868 }
869
870 /**
871 * regress_test_array_fixed_size_int_in:
872 * @ints: (array fixed-size=5): a list of 5 integers
873 *
874 * Returns: the sum of the items in @ints
875 */
876 int
877 regress_test_array_fixed_size_int_in (int *ints)
878 {
879 int i, sum = 0;
880 for (i = 0; i < 5; i++)
881 sum += ints[i];
882 return sum;
883 }
884
885 /**
886 * regress_test_array_fixed_size_int_out:
887 * @ints: (out) (array fixed-size=5) (transfer full): a list of 5 integers ranging from 0 to 4
888 */
889 void
890 regress_test_array_fixed_size_int_out (int **ints)
891 {
892 int i;
893 *ints = g_malloc0 (sizeof (**ints) * 5);
894 for (i = 1; i < 5; i++)
895 (*ints)[i] = (*ints)[i - 1] + 1;
896 }
897
898 /**
899 * regress_test_array_fixed_size_int_return:
900 *
901 * Returns: (array fixed-size=5) (transfer full): a list of 5 integers ranging from 0 to 4
902 */
903 int *
904 regress_test_array_fixed_size_int_return (void)
905 {
906 int i, *ints;
907 ints = g_malloc0 (sizeof (*ints) * 5);
908 for (i = 1; i < 5; i++)
909 ints[i] = ints[i - 1] + 1;
910 return ints;
911 }
912
913 /**
914 * regress_test_array_static_in_int
915 * @x: (array fixed-size=10): a list of 10 integers
916 */
917 #if (defined(__GNUC__) || defined(__clang__)) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
918 void
919 regress_test_array_static_in_int (int x[static 10] G_GNUC_UNUSED)
920 {
921 }
922 #else
923 void
924 regress_test_array_static_in_int (int x[10])
925 {
926 }
927 #endif
928
929 /**
930 * regress_test_strv_out_c:
931 *
932 * Returns: (transfer none):
933 */
934 const char *const *
935 regress_test_strv_out_c (void)
936 {
937 static char **ret = NULL;
938
939 if (ret == NULL)
940 ret = regress_test_strv_out ();
941
942 return (const char *const *) ret;
943 }
944
945 /**
946 * regress_test_array_int_full_out:
947 * @len: length of the returned array.
948 *
949 * Returns: (array length=len) (transfer full): a new array of integers.
950 */
951 int *
952 regress_test_array_int_full_out (int *len)
953 {
954 int *result, i;
955 *len = 5;
956 result = g_malloc0 (sizeof (*result) * (*len));
957 for (i = 1; i < (*len); i++)
958 result[i] = result[i - 1] + 1;
959 return result;
960 }
961
962 /**
963 * regress_test_array_int_none_out:
964 * @len: length of the returned array.
965 *
966 * Returns: (array length=len) (transfer none): a static array of integers.
967 */
968 int *
969 regress_test_array_int_none_out (int *len)
970 {
971 static int result[5] = { 1, 2, 3, 4, 5 };
972 *len = 5;
973 return result;
974 }
975
976 /**
977 * regress_test_array_int_null_in:
978 * @arr: (array length=len) (allow-none):
979 * @len: length
980 */
981 void
982 regress_test_array_int_null_in (int *arr,
983 int len G_GNUC_UNUSED)
984 {
985 g_assert (arr == NULL);
986 }
987
988 /**
989 * regress_test_array_int_null_out:
990 * @arr: (out) (array length=len) (allow-none):
991 * @len: (out) : length
992 */
993 void
994 regress_test_array_int_null_out (int **arr, int *len)
995 {
996 *arr = NULL;
997 *len = 0;
998 }
999
1000 /* interface */
1001
1002 /************************************************************************/
1003 /* GList */
1004
1005 static /*const*/ GList *
1006 regress_test_sequence_list (void)
1007 {
1008 static GList *list = NULL;
1009 if (!list)
1010 {
1011 gsize i;
1012 for (i = 0; i < G_N_ELEMENTS (test_sequence); ++i)
1013 {
1014 list = g_list_prepend (list, (gpointer) test_sequence[i]);
1015 }
1016 list = g_list_reverse (list);
1017 }
1018 return list;
1019 }
1020
1021 /**
1022 * regress_test_glist_nothing_return:
1023 *
1024 * Return value: (element-type utf8) (transfer none):
1025 */
1026 const GList *
1027 regress_test_glist_nothing_return (void)
1028 {
1029 return regress_test_sequence_list ();
1030 }
1031
1032 /**
1033 * regress_test_glist_nothing_return2:
1034 *
1035 * Return value: (element-type utf8) (transfer none):
1036 */
1037 GList *
1038 regress_test_glist_nothing_return2 (void)
1039 {
1040 return regress_test_sequence_list ();
1041 }
1042
1043 /**
1044 * regress_test_glist_container_return:
1045 *
1046 * Return value: (element-type utf8) (transfer container):
1047 */
1048 GList *
1049 regress_test_glist_container_return (void)
1050 {
1051 return g_list_copy (regress_test_sequence_list ());
1052 }
1053
1054 /**
1055 * regress_test_glist_everything_return:
1056 *
1057 * Return value: (element-type utf8) (transfer full):
1058 */
1059 GList *
1060 regress_test_glist_everything_return (void)
1061 {
1062 GList *list;
1063 GList *l;
1064
1065 list = g_list_copy (regress_test_sequence_list ());
1066 for (l = list; l != NULL; l = l->next)
1067 l->data = g_strdup (l->data);
1068 return list;
1069 }
1070
1071 static void
1072 regress_assert_test_sequence_list (const GList *in)
1073 {
1074 const GList *l;
1075 gsize i;
1076
1077 for (i = 0, l = in; l != NULL; ++i, l = l->next)
1078 {
1079 g_assert (i < G_N_ELEMENTS (test_sequence));
1080 g_assert (strcmp (l->data, test_sequence[i]) == 0);
1081 }
1082 g_assert (i == G_N_ELEMENTS (test_sequence));
1083 }
1084
1085 /**
1086 * regress_test_glist_gtype_container_in:
1087 * @in: (element-type GType) (transfer container):
1088 */
1089 void
1090 regress_test_glist_gtype_container_in (GList *in)
1091 {
1092 GList *l = in;
1093
1094 g_assert (GPOINTER_TO_SIZE (l->data) == REGRESS_TEST_TYPE_OBJ);
1095 l = l->next;
1096 g_assert (GPOINTER_TO_SIZE (l->data) == REGRESS_TEST_TYPE_SUB_OBJ);
1097 l = l->next;
1098 g_assert (l == NULL);
1099
1100 g_list_free (in);
1101 }
1102
1103 /**
1104 * regress_test_glist_nothing_in:
1105 * @in: (element-type utf8):
1106 */
1107 void
1108 regress_test_glist_nothing_in (const GList *in)
1109 {
1110 regress_assert_test_sequence_list (in);
1111 }
1112
1113 /**
1114 * regress_test_glist_nothing_in2:
1115 * @in: (element-type utf8):
1116 */
1117 void
1118 regress_test_glist_nothing_in2 (GList *in)
1119 {
1120 regress_assert_test_sequence_list (in);
1121 }
1122
1123 /**
1124 * regress_test_glist_null_in:
1125 * @in: (element-type utf8) (allow-none):
1126 */
1127 void
1128 regress_test_glist_null_in (GList *in)
1129 {
1130 g_assert (in == NULL);
1131 }
1132
1133 /**
1134 * regress_test_glist_null_out:
1135 * @out_list: (out) (element-type utf8) (allow-none):
1136 */
1137 void
1138 regress_test_glist_null_out (GList **out_list)
1139 {
1140 *out_list = NULL;
1141 }
1142
1143 /************************************************************************/
1144 /* GSList */
1145
1146 static /*const*/ GSList *
1147 regress_test_sequence_slist (void)
1148 {
1149 static GSList *list = NULL;
1150 if (!list)
1151 {
1152 gsize i;
1153 for (i = 0; i < G_N_ELEMENTS (test_sequence); ++i)
1154 {
1155 list = g_slist_prepend (list, (gpointer) test_sequence[i]);
1156 }
1157 list = g_slist_reverse (list);
1158 }
1159 return list;
1160 }
1161
1162 /**
1163 * regress_test_gslist_nothing_return:
1164 *
1165 * Return value: (element-type utf8) (transfer none):
1166 */
1167 const GSList *
1168 regress_test_gslist_nothing_return (void)
1169 {
1170 return regress_test_sequence_slist ();
1171 }
1172
1173 /**
1174 * regress_test_gslist_nothing_return2:
1175 *
1176 * Return value: (element-type utf8) (transfer none):
1177 */
1178 GSList *
1179 regress_test_gslist_nothing_return2 (void)
1180 {
1181 return regress_test_sequence_slist ();
1182 }
1183
1184 /**
1185 * regress_test_gslist_container_return:
1186 *
1187 * Return value: (element-type utf8) (transfer container):
1188 */
1189 GSList *
1190 regress_test_gslist_container_return (void)
1191 {
1192 return g_slist_copy (regress_test_sequence_slist ());
1193 }
1194
1195 /**
1196 * regress_test_gslist_everything_return:
1197 *
1198 * Return value: (element-type utf8) (transfer full):
1199 */
1200 GSList *
1201 regress_test_gslist_everything_return (void)
1202 {
1203 GSList *list;
1204 GSList *l;
1205
1206 list = g_slist_copy (regress_test_sequence_slist ());
1207 for (l = list; l != NULL; l = l->next)
1208 l->data = g_strdup (l->data);
1209 return list;
1210 }
1211
1212 static void
1213 regress_assert_test_sequence_slist (const GSList *in)
1214 {
1215 const GSList *l;
1216 gsize i;
1217
1218 for (i = 0, l = in; l != NULL; ++i, l = l->next)
1219 {
1220 g_assert (i < G_N_ELEMENTS (test_sequence));
1221 g_assert (strcmp (l->data, test_sequence[i]) == 0);
1222 }
1223 g_assert (i == G_N_ELEMENTS (test_sequence));
1224 }
1225
1226 /**
1227 * regress_test_gslist_nothing_in:
1228 * @in: (element-type utf8):
1229 */
1230 void
1231 regress_test_gslist_nothing_in (const GSList *in)
1232 {
1233 regress_assert_test_sequence_slist (in);
1234 }
1235
1236 /**
1237 * regress_test_gslist_nothing_in2:
1238 * @in: (element-type utf8):
1239 */
1240 void
1241 regress_test_gslist_nothing_in2 (GSList *in)
1242 {
1243 regress_assert_test_sequence_slist (in);
1244 }
1245
1246 /**
1247 * regress_test_gslist_null_in:
1248 * @in: (element-type utf8) (allow-none):
1249 */
1250 void
1251 regress_test_gslist_null_in (GSList *in)
1252 {
1253 g_assert (in == NULL);
1254 }
1255
1256 /**
1257 * regress_test_gslist_null_out:
1258 * @out_list: (out) (element-type utf8) (allow-none):
1259 */
1260 void
1261 regress_test_gslist_null_out (GSList **out_list)
1262 {
1263 *out_list = NULL;
1264 }
1265
1266 /************************************************************************/
1267 /* GHash */
1268
1269 static const char *table_data[3][2] = {
1270 { "foo", "bar" }, { "baz", "bat" }, { "qux", "quux" }
1271 };
1272
1273 static GHashTable *
1274 regress_test_table_ghash_new_container (void)
1275 {
1276 GHashTable *hash;
1277 int i;
1278 hash = g_hash_table_new (g_str_hash, g_str_equal);
1279 for (i = 0; i < 3; i++)
1280 g_hash_table_insert (hash,
1281 (gpointer) table_data[i][0],
1282 (gpointer) table_data[i][1]);
1283 return hash;
1284 }
1285
1286 static GHashTable *
1287 regress_test_table_ghash_new_full (void)
1288 {
1289 GHashTable *hash;
1290 int i;
1291 hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
1292 for (i = 0; i < 3; i++)
1293 g_hash_table_insert (hash,
1294 g_strdup (table_data[i][0]),
1295 g_strdup (table_data[i][1]));
1296 return hash;
1297 }
1298
1299 static /*const*/ GHashTable *
1300 regress_test_table_ghash_const (void)
1301 {
1302 static GHashTable *hash = NULL;
1303 if (!hash)
1304 {
1305 hash = regress_test_table_ghash_new_container ();
1306 }
1307 return hash;
1308 }
1309
1310 /**
1311 * regress_test_ghash_null_return:
1312 *
1313 * Return value: (element-type utf8 utf8) (transfer none) (allow-none):
1314 */
1315 const GHashTable *
1316 regress_test_ghash_null_return (void)
1317 {
1318 return NULL;
1319 }
1320
1321 /**
1322 * regress_test_ghash_nothing_return:
1323 *
1324 * Return value: (element-type utf8 utf8) (transfer none):
1325 */
1326 const GHashTable *
1327 regress_test_ghash_nothing_return (void)
1328 {
1329 return regress_test_table_ghash_const ();
1330 }
1331
1332 /**
1333 * regress_test_ghash_nothing_return2:
1334 *
1335 * Return value: (element-type utf8 utf8) (transfer none):
1336 */
1337 GHashTable *
1338 regress_test_ghash_nothing_return2 (void)
1339 {
1340 return regress_test_table_ghash_const ();
1341 }
1342
1343 static GValue *
1344 g_value_new (GType type)
1345 {
1346 GValue *value = g_slice_new0 (GValue);
1347 g_value_init (value, type);
1348 return value;
1349 }
1350
1351 static void
1352 g_value_free (GValue *value)
1353 {
1354 g_value_unset (value);
1355 g_slice_free (GValue, value);
1356 }
1357
1358 static const gchar *string_array[] = {
1359 "first",
1360 "second",
1361 "third",
1362 NULL
1363 };
1364
1365 /**
1366 * regress_test_ghash_gvalue_return:
1367 *
1368 * Return value: (element-type utf8 GValue) (transfer none):
1369 */
1370 GHashTable *
1371 regress_test_ghash_gvalue_return (void)
1372 {
1373 static GHashTable *hash = NULL;
1374
1375 if (hash == NULL)
1376 {
1377 GValue *value;
1378 hash = g_hash_table_new_full (g_str_hash, g_str_equal,
1379 g_free, (GDestroyNotify) g_value_free);
1380
1381 value = g_value_new (G_TYPE_INT);
1382 g_value_set_int (value, 12);
1383 g_hash_table_insert (hash, g_strdup ("integer"), value);
1384
1385 value = g_value_new (G_TYPE_BOOLEAN);
1386 g_value_set_boolean (value, TRUE);
1387 g_hash_table_insert (hash, g_strdup ("boolean"), value);
1388
1389 value = g_value_new (G_TYPE_STRING);
1390 g_value_set_string (value, "some text");
1391 g_hash_table_insert (hash, g_strdup ("string"), value);
1392
1393 value = g_value_new (G_TYPE_STRV);
1394 g_value_set_boxed (value, string_array);
1395 g_hash_table_insert (hash, g_strdup ("strings"), value);
1396
1397 value = g_value_new (REGRESS_TEST_TYPE_FLAGS);
1398 g_value_set_flags (value, REGRESS_TEST_FLAG1 | REGRESS_TEST_FLAG3);
1399 g_hash_table_insert (hash, g_strdup ("flags"), value);
1400
1401 value = g_value_new (regress_test_enum_get_type ());
1402 g_value_set_enum (value, REGRESS_TEST_VALUE2);
1403 g_hash_table_insert (hash, g_strdup ("enum"), value);
1404 }
1405
1406 return hash;
1407 }
1408
1409 /**
1410 * regress_test_ghash_gvalue_in:
1411 * @hash: (element-type utf8 GValue): the hash table returned by
1412 * regress_test_ghash_gvalue_return().
1413 */
1414 void
1415 regress_test_ghash_gvalue_in (GHashTable *hash)
1416 {
1417 GValue *value;
1418 const gchar **strings;
1419 int i;
1420
1421 g_assert (hash != NULL);
1422
1423 value = g_hash_table_lookup (hash, "integer");
1424 g_assert (value != NULL);
1425 g_assert (G_VALUE_HOLDS_INT (value));
1426 g_assert (g_value_get_int (value) == 12);
1427
1428 value = g_hash_table_lookup (hash, "boolean");
1429 g_assert (value != NULL);
1430 g_assert (G_VALUE_HOLDS_BOOLEAN (value));
1431 g_assert (g_value_get_boolean (value) == TRUE);
1432
1433 value = g_hash_table_lookup (hash, "string");
1434 g_assert (value != NULL);
1435 g_assert (G_VALUE_HOLDS_STRING (value));
1436 g_assert (strcmp (g_value_get_string (value), "some text") == 0);
1437
1438 value = g_hash_table_lookup (hash, "strings");
1439 g_assert (value != NULL);
1440 g_assert (G_VALUE_HOLDS (value, G_TYPE_STRV));
1441 strings = g_value_get_boxed (value);
1442 g_assert (strings != NULL);
1443 for (i = 0; string_array[i] != NULL; i++)
1444 g_assert (strcmp (strings[i], string_array[i]) == 0);
1445
1446 value = g_hash_table_lookup (hash, "flags");
1447 g_assert (value != NULL);
1448 g_assert (G_VALUE_HOLDS_FLAGS (value));
1449 g_assert (g_value_get_flags (value) == (REGRESS_TEST_FLAG1 | REGRESS_TEST_FLAG3));
1450
1451 value = g_hash_table_lookup (hash, "enum");
1452 g_assert (value != NULL);
1453 g_assert (G_VALUE_HOLDS_ENUM (value));
1454 g_assert (g_value_get_enum (value) == REGRESS_TEST_VALUE2);
1455 }
1456
1457 /**
1458 * regress_test_ghash_container_return:
1459 *
1460 * Return value: (element-type utf8 utf8) (transfer container):
1461 */
1462 GHashTable *
1463 regress_test_ghash_container_return (void)
1464 {
1465 return regress_test_table_ghash_new_container ();
1466 }
1467
1468 /**
1469 * regress_test_ghash_everything_return:
1470 *
1471 * Return value: (element-type utf8 utf8) (transfer full):
1472 */
1473 GHashTable *
1474 regress_test_ghash_everything_return (void)
1475 {
1476 return regress_test_table_ghash_new_full ();
1477 }
1478
1479 static void
1480 assert_test_table_ghash (const GHashTable *in)
1481 {
1482 GHashTable *h = regress_test_table_ghash_const ();
1483 GHashTableIter iter;
1484 gpointer key, value;
1485
1486 g_assert (g_hash_table_size (h) ==
1487 g_hash_table_size ((GHashTable *) in));
1488
1489 g_hash_table_iter_init (&iter, (GHashTable *) in);
1490 while (g_hash_table_iter_next (&iter, &key, &value))
1491 g_assert (strcmp (g_hash_table_lookup (h, (char *) key), (char *) value) == 0);
1492 }
1493
1494 /**
1495 * regress_test_ghash_null_in:
1496 * @in: (element-type utf8 utf8) (allow-none):
1497 */
1498 void
1499 regress_test_ghash_null_in (const GHashTable *in)
1500 {
1501 g_assert (in == NULL);
1502 }
1503
1504 /**
1505 * regress_test_ghash_null_out:
1506 * @out: (element-type utf8 utf8) (allow-none) (out):
1507 */
1508 void
1509 regress_test_ghash_null_out (const GHashTable **out)
1510 {
1511 *out = NULL;
1512 }
1513
1514 /**
1515 * regress_test_ghash_nothing_in:
1516 * @in: (element-type utf8 utf8):
1517 */
1518 void
1519 regress_test_ghash_nothing_in (const GHashTable *in)
1520 {
1521 assert_test_table_ghash (in);
1522 }
1523
1524 /**
1525 * regress_test_ghash_nothing_in2:
1526 * @in: (element-type utf8 utf8):
1527 */
1528 void
1529 regress_test_ghash_nothing_in2 (GHashTable *in)
1530 {
1531 assert_test_table_ghash (in);
1532 }
1533
1534 /* Nested collection types */
1535
1536 /**
1537 * regress_test_ghash_nested_everything_return:
1538 *
1539 * Specify nested parameterized types directly with the (type ) annotation.
1540 *
1541 * Return value: (type GLib.HashTable<utf8,GLib.HashTable<utf8,utf8>>) (transfer full):
1542 */
1543 GHashTable *
1544 regress_test_ghash_nested_everything_return (void)
1545 {
1546 GHashTable *hash;
1547 hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
1548 (void (*) (gpointer)) g_hash_table_destroy);
1549 g_hash_table_insert (hash, g_strdup ("wibble"), regress_test_table_ghash_new_full ());
1550 return hash;
1551 }
1552
1553 /**
1554 * regress_test_ghash_nested_everything_return2:
1555 *
1556 * Another way of specifying nested parameterized types: using the
1557 * element-type annotation.
1558 *
1559 * Return value: (element-type utf8 GLib.HashTable<utf8,utf8>) (transfer full):
1560 */
1561 GHashTable *
1562 regress_test_ghash_nested_everything_return2 (void)
1563 {
1564 return regress_test_ghash_nested_everything_return ();
1565 }
1566
1567 /************************************************************************/
1568
1569 /**
1570 * regress_test_garray_container_return:
1571 *
1572 * Returns: (transfer container) (type GLib.PtrArray) (element-type utf8):
1573 */
1574 GPtrArray *
1575 regress_test_garray_container_return (void)
1576 {
1577 GPtrArray *array;
1578
1579 array = g_ptr_array_new_with_free_func (g_free);
1580 g_ptr_array_add (array, g_strdup ("regress"));
1581
1582 return array;
1583 }
1584
1585 /**
1586 * regress_test_garray_full_return:
1587 *
1588 * Returns: (transfer full) (type GLib.PtrArray) (element-type utf8):
1589 */
1590 GPtrArray *
1591 regress_test_garray_full_return (void)
1592 {
1593 GPtrArray *array;
1594
1595 array = g_ptr_array_new ();
1596 g_ptr_array_add (array, g_strdup ("regress"));
1597
1598 return array;
1599 }
1600
1601 /************************************************************************/
1602
1603 /* error? */
1604
1605 /* enums / flags */
1606
1607 /**
1608 * NUM_REGRESS_FOO: (skip)
1609 *
1610 * num of elements in RegressFoo
1611 */
1612
1613 GType
1614 regress_test_enum_get_type (void)
1615 {
1616 static GType etype = 0;
1617 if (G_UNLIKELY (etype == 0))
1618 {
1619 static const GEnumValue values[] = {
1620 { REGRESS_TEST_VALUE1, "REGRESS_TEST_VALUE1", "value1" },
1621 { REGRESS_TEST_VALUE2, "REGRESS_TEST_VALUE2", "value2" },
1622 { REGRESS_TEST_VALUE3, "REGRESS_TEST_VALUE3", "value3" },
1623 { REGRESS_TEST_VALUE4, "REGRESS_TEST_VALUE4", "value4" },
1624 { REGRESS_TEST_VALUE5, "REGRESS_TEST_VALUE5", "value5" },
1625 { 0, NULL, NULL }
1626 };
1627 etype = g_enum_register_static (g_intern_static_string ("RegressTestEnum"), values);
1628 }
1629
1630 return etype;
1631 }
1632
1633 GType
1634 regress_test_enum_unsigned_get_type (void)
1635 {
1636 static GType etype = 0;
1637 if (G_UNLIKELY (etype == 0))
1638 {
1639 static const GEnumValue values[] = {
1640 { REGRESS_TEST_UNSIGNED_VALUE1, "REGRESS_TEST_UNSIGNED_VALUE1", "value1" },
1641 { REGRESS_TEST_UNSIGNED_VALUE2, "REGRESS_TEST_UNSIGNED_VALUE2", "value2" },
1642 { 0, NULL, NULL }
1643 };
1644 etype = g_enum_register_static (g_intern_static_string ("RegressTestEnumUnsigned"), values);
1645 }
1646
1647 return etype;
1648 }
1649
1650 GType
1651 regress_test_flags_get_type (void)
1652 {
1653 static GType etype = 0;
1654 if (G_UNLIKELY (etype == 0))
1655 {
1656 static const GFlagsValue values[] = {
1657 { REGRESS_TEST_FLAG1, "TEST_FLAG1", "flag1" },
1658 { REGRESS_TEST_FLAG2, "TEST_FLAG2", "flag2" },
1659 { REGRESS_TEST_FLAG3, "TEST_FLAG3", "flag3" },
1660 { 0, NULL, NULL }
1661 };
1662 etype = g_flags_register_static (g_intern_static_string ("RegressTestFlags"), values);
1663 }
1664
1665 return etype;
1666 }
1667
1668 const gchar *
1669 regress_test_enum_param (RegressTestEnum e)
1670 {
1671 GEnumValue *ev;
1672 GEnumClass *ec;
1673
1674 ec = g_type_class_ref (regress_test_enum_get_type ());
1675 ev = g_enum_get_value (ec, e);
1676 g_type_class_unref (ec);
1677
1678 return ev->value_nick;
1679 }
1680
1681 const gchar *
1682 regress_test_unsigned_enum_param (RegressTestEnumUnsigned e)
1683 {
1684 GEnumValue *ev;
1685 GEnumClass *ec;
1686
1687 ec = g_type_class_ref (regress_test_enum_unsigned_get_type ());
1688 ev = g_enum_get_value (ec, e);
1689 g_type_class_unref (ec);
1690
1691 return ev->value_nick;
1692 }
1693
1694 /**
1695 * regress_global_get_flags_out:
1696 * @v: (out): A flags value
1697 *
1698 */
1699 void
1700 regress_global_get_flags_out (RegressTestFlags *v)
1701 {
1702 *v = REGRESS_TEST_FLAG1 | REGRESS_TEST_FLAG3;
1703 }
1704
1705 /* error domains */
1706
1707 GType
1708 regress_test_error_get_type (void)
1709 {
1710 static GType etype = 0;
1711 if (G_UNLIKELY (etype == 0))
1712 {
1713 static const GEnumValue values[] = {
1714 { REGRESS_TEST_ERROR_CODE1, "REGRESS_TEST_ERROR_CODE1", "code1" },
1715 { REGRESS_TEST_ERROR_CODE2, "REGRESS_TEST_ERROR_CODE2", "code2" },
1716 { REGRESS_TEST_ERROR_CODE3, "REGRESS_TEST_ERROR_CODE3", "code3" },
1717 { 0, NULL, NULL }
1718 };
1719 etype = g_enum_register_static (g_intern_static_string ("RegressTestError"), values);
1720 }
1721
1722 return etype;
1723 }
1724
1725 GQuark
1726 regress_test_error_quark (void)
1727 {
1728 return g_quark_from_static_string ("regress-test-error");
1729 }
1730
1731 GType
1732 regress_test_abc_error_get_type (void)
1733 {
1734 static GType etype = 0;
1735 if (G_UNLIKELY (etype == 0))
1736 {
1737 static const GEnumValue values[] = {
1738 { REGRESS_TEST_ABC_ERROR_CODE1, "REGRESS_TEST_ABC_ERROR_CODE1", "code1" },
1739 { REGRESS_TEST_ABC_ERROR_CODE2, "REGRESS_TEST_ABC_ERROR_CODE2", "code2" },
1740 { REGRESS_TEST_ABC_ERROR_CODE3, "REGRESS_TEST_ABC_ERROR_CODE3", "code3" },
1741 { 0, NULL, NULL }
1742 };
1743 etype = g_enum_register_static (g_intern_static_string ("RegressTestABCError"), values);
1744 }
1745
1746 return etype;
1747 }
1748
1749 GQuark
1750 regress_test_abc_error_quark (void)
1751 {
1752 return g_quark_from_static_string ("regress-test-abc-error");
1753 }
1754
1755 GType
1756 regress_test_unconventional_error_get_type (void)
1757 {
1758 static GType etype = 0;
1759 if (G_UNLIKELY (etype == 0))
1760 {
1761 static const GEnumValue values[] = {
1762 { REGRESS_TEST_OTHER_ERROR_CODE1, "REGRESS_TEST_OTHER_ERROR_CODE1", "code1" },
1763 { REGRESS_TEST_OTHER_ERROR_CODE2, "REGRESS_TEST_OTHER_ERROR_CODE2", "code2" },
1764 { REGRESS_TEST_OTHER_ERROR_CODE3, "REGRESS_TEST_OTHER_ERROR_CODE3", "code3" },
1765 { 0, NULL, NULL }
1766 };
1767 etype = g_enum_register_static (g_intern_static_string ("RegressTestOtherError"), values);
1768 }
1769
1770 return etype;
1771 }
1772
1773 GQuark
1774 regress_test_unconventional_error_quark (void)
1775 {
1776 return g_quark_from_static_string ("regress-test-other-error");
1777 }
1778
1779 GQuark
1780 regress_test_def_error_quark (void)
1781 {
1782 return g_quark_from_static_string ("regress-test-def-error");
1783 }
1784
1785 GQuark
1786 regress_atest_error_quark (void)
1787 {
1788 return g_quark_from_static_string ("regress-atest-error");
1789 }
1790
1791 /* structures */
1792
1793 /**
1794 * regress_test_struct_a_clone:
1795 * @a: the structure
1796 * @a_out: (out caller-allocates): the cloned structure
1797 *
1798 * Make a copy of a RegressTestStructA
1799 */
1800 void
1801 regress_test_struct_a_clone (RegressTestStructA *a,
1802 RegressTestStructA *a_out)
1803 {
1804 *a_out = *a;
1805 }
1806
1807 /**
1808 * regress_test_struct_a_parse:
1809 * @a_out: (out caller-allocates): the structure that is to be filled
1810 * @string: ignored
1811 */
1812 void
1813 regress_test_struct_a_parse (RegressTestStructA *a_out,
1814 const gchar *string G_GNUC_UNUSED)
1815 {
1816 a_out->some_int = 23;
1817 }
1818
1819 /**
1820 * regress_test_array_struct_out:
1821 * @arr: (out) (array length=len) (transfer full):
1822 * @len: (out)
1823 *
1824 * This is similar to gdk_keymap_get_entries_for_keyval().
1825 */
1826 void
1827 regress_test_array_struct_out (RegressTestStructA **arr, int *len)
1828 {
1829 *arr = g_new0 (RegressTestStructA, 3);
1830 (*arr)[0].some_int = 22;
1831 (*arr)[1].some_int = 33;
1832 (*arr)[2].some_int = 44;
1833 *len = 3;
1834 }
1835
1836 /**
1837 * regress_test_struct_b_clone:
1838 * @b: the structure
1839 * @b_out: (out): the cloned structure
1840 *
1841 * Make a copy of a RegressTestStructB
1842 */
1843 void
1844 regress_test_struct_b_clone (RegressTestStructB *b,
1845 RegressTestStructB *b_out)
1846 {
1847 *b_out = *b;
1848 }
1849
1850 /* plain-old-data boxed types */
1851
1852 RegressTestSimpleBoxedA *
1853 regress_test_simple_boxed_a_copy (RegressTestSimpleBoxedA *a)
1854 {
1855 RegressTestSimpleBoxedA *new_a = g_slice_new (RegressTestSimpleBoxedA);
1856
1857 *new_a = *a;
1858
1859 return new_a;
1860 }
1861
1862 static void
1863 regress_test_simple_boxed_a_free (RegressTestSimpleBoxedA *a)
1864 {
1865 g_slice_free (RegressTestSimpleBoxedA, a);
1866 }
1867
1868 GType
1869 regress_test_simple_boxed_a_get_gtype (void)
1870 {
1871 static GType our_type = 0;
1872
1873 if (our_type == 0)
1874 our_type = g_boxed_type_register_static (g_intern_static_string ("RegressTestSimpleBoxedA"),
1875 (GBoxedCopyFunc) regress_test_simple_boxed_a_copy,
1876 (GBoxedFreeFunc) regress_test_simple_boxed_a_free);
1877 return our_type;
1878 }
1879
1880 RegressTestSimpleBoxedB *
1881 regress_test_simple_boxed_b_copy (RegressTestSimpleBoxedB *b)
1882 {
1883 RegressTestSimpleBoxedB *new_b = g_slice_new (RegressTestSimpleBoxedB);
1884
1885 *new_b = *b;
1886
1887 return new_b;
1888 }
1889
1890 gboolean
1891 regress_test_simple_boxed_a_equals (RegressTestSimpleBoxedA *a,
1892 RegressTestSimpleBoxedA *other_a)
1893 {
1894 return (a->some_int == other_a->some_int &&
1895 a->some_int8 == other_a->some_int8 &&
1896 a->some_double == other_a->some_double);
1897 }
1898
1899 const RegressTestSimpleBoxedA *
1900 regress_test_simple_boxed_a_const_return (void)
1901 {
1902 static RegressTestSimpleBoxedA simple_a = {
1903 5, 6, 7.0, REGRESS_TEST_VALUE1
1904 };
1905
1906 return &simple_a;
1907 }
1908
1909 static void
1910 regress_test_simple_boxed_b_free (RegressTestSimpleBoxedB *a)
1911 {
1912 g_slice_free (RegressTestSimpleBoxedB, a);
1913 }
1914
1915 GType
1916 regress_test_simple_boxed_b_get_type (void)
1917 {
1918 static GType our_type = 0;
1919
1920 if (our_type == 0)
1921 our_type = g_boxed_type_register_static (g_intern_static_string ("RegressTestSimpleBoxedB"),
1922 (GBoxedCopyFunc) regress_test_simple_boxed_b_copy,
1923 (GBoxedFreeFunc) regress_test_simple_boxed_b_free);
1924 return our_type;
1925 }
1926
1927 /* opaque boxed */
1928
1929 struct _RegressTestBoxedPrivate
1930 {
1931 guint magic;
1932 };
1933
1934 /**
1935 * regress_test_boxed_new:
1936 *
1937 * Returns: (transfer full):
1938 */
1939 RegressTestBoxed *
1940 regress_test_boxed_new (void)
1941 {
1942 RegressTestBoxed *boxed = g_slice_new0 (RegressTestBoxed);
1943 boxed->priv = g_slice_new0 (RegressTestBoxedPrivate);
1944 boxed->priv->magic = 0xdeadbeef;
1945
1946 return boxed;
1947 }
1948
1949 /**
1950 * regress_test_boxed_new_alternative_constructor1:
1951 *
1952 * Returns: (transfer full):
1953 */
1954 RegressTestBoxed *
1955 regress_test_boxed_new_alternative_constructor1 (int i)
1956 {
1957 RegressTestBoxed *boxed = g_slice_new0 (RegressTestBoxed);
1958 boxed->priv = g_slice_new0 (RegressTestBoxedPrivate);
1959 boxed->priv->magic = 0xdeadbeef;
1960 boxed->some_int8 = i;
1961
1962 return boxed;
1963 }
1964
1965 /**
1966 * regress_test_boxed_new_alternative_constructor2:
1967 *
1968 * Returns: (transfer full):
1969 */
1970 RegressTestBoxed *
1971 regress_test_boxed_new_alternative_constructor2 (int i, int j)
1972 {
1973 RegressTestBoxed *boxed = g_slice_new0 (RegressTestBoxed);
1974 boxed->priv = g_slice_new0 (RegressTestBoxedPrivate);
1975 boxed->priv->magic = 0xdeadbeef;
1976 boxed->some_int8 = i + j;
1977
1978 return boxed;
1979 }
1980
1981 /**
1982 * regress_test_boxed_new_alternative_constructor3:
1983 *
1984 * Returns: (transfer full):
1985 */
1986 RegressTestBoxed *
1987 regress_test_boxed_new_alternative_constructor3 (char *s)
1988 {
1989 RegressTestBoxed *boxed = g_slice_new0 (RegressTestBoxed);
1990 boxed->priv = g_slice_new0 (RegressTestBoxedPrivate);
1991 boxed->priv->magic = 0xdeadbeef;
1992 boxed->some_int8 = atoi (s);
1993
1994 return boxed;
1995 }
1996
1997 /**
1998 * regress_test_boxed_copy:
1999 *
2000 * Returns: (transfer full):
2001 */
2002 RegressTestBoxed *
2003 regress_test_boxed_copy (RegressTestBoxed *boxed)
2004 {
2005 RegressTestBoxed *new_boxed = regress_test_boxed_new ();
2006 RegressTestBoxedPrivate *save;
2007
2008 save = new_boxed->priv;
2009 *new_boxed = *boxed;
2010 new_boxed->priv = save;
2011
2012 return new_boxed;
2013 }
2014
2015 gboolean
2016 regress_test_boxed_equals (RegressTestBoxed *boxed,
2017 RegressTestBoxed *other)
2018 {
2019 return (other->some_int8 == boxed->some_int8 &&
2020 regress_test_simple_boxed_a_equals (&other->nested_a, &boxed->nested_a));
2021 }
2022
2023 void
2024 regress_test_boxeds_not_a_method (RegressTestBoxed *boxed G_GNUC_UNUSED)
2025 {
2026 }
2027
2028 void
2029 regress_test_boxeds_not_a_static (void)
2030 {
2031 }
2032
2033 static void
2034 regress_test_boxed_free (RegressTestBoxed *boxed)
2035 {
2036 g_assert (boxed->priv->magic == 0xdeadbeef);
2037
2038 g_slice_free (RegressTestBoxedPrivate, boxed->priv);
2039 g_slice_free (RegressTestBoxed, boxed);
2040 }
2041
2042 GType
2043 regress_test_boxed_get_type (void)
2044 {
2045 static GType our_type = 0;
2046
2047 if (our_type == 0)
2048 our_type = g_boxed_type_register_static (g_intern_static_string ("RegressTestBoxed"),
2049 (GBoxedCopyFunc) regress_test_boxed_copy,
2050 (GBoxedFreeFunc) regress_test_boxed_free);
2051 return our_type;
2052 }
2053
2054 RegressTestBoxedB *
2055 regress_test_boxed_b_new (gint8 some_int8, glong some_long)
2056 {
2057 RegressTestBoxedB *boxed;
2058
2059 boxed = g_slice_new (RegressTestBoxedB);
2060 boxed->some_int8 = some_int8;
2061 boxed->some_long = some_long;
2062
2063 return boxed;
2064 }
2065
2066 RegressTestBoxedB *
2067 regress_test_boxed_b_copy (RegressTestBoxedB *boxed)
2068 {
2069 return regress_test_boxed_b_new (boxed->some_int8, boxed->some_long);
2070 }
2071
2072 static void
2073 regress_test_boxed_b_free (RegressTestBoxedB *boxed)
2074 {
2075 g_slice_free (RegressTestBoxedB, boxed);
2076 }
2077
2078 G_DEFINE_BOXED_TYPE (RegressTestBoxedB,
2079 regress_test_boxed_b,
2080 regress_test_boxed_b_copy,
2081 regress_test_boxed_b_free);
2082
2083 RegressTestBoxedC *
2084 regress_test_boxed_c_new (void)
2085 {
2086 RegressTestBoxedC *boxed;
2087
2088 boxed = g_slice_new (RegressTestBoxedC);
2089 boxed->refcount = 1;
2090 boxed->another_thing = 42; /* what else */
2091
2092 return boxed;
2093 }
2094
2095 gboolean
2096 regress_test_boxed_c_name_conflict (RegressTestBoxedC *boxed)
2097 {
2098 return boxed->name_conflict;
2099 }
2100
2101 static RegressTestBoxedC *
2102 regress_test_boxed_c_ref (RegressTestBoxedC *boxed)
2103 {
2104 g_atomic_int_inc (&boxed->refcount);
2105 return boxed;
2106 }
2107
2108 static void
2109 regress_test_boxed_c_unref (RegressTestBoxedC *boxed)
2110 {
2111 if (g_atomic_int_dec_and_test (&boxed->refcount))
2112 {
2113 g_slice_free (RegressTestBoxedC, boxed);
2114 }
2115 }
2116
2117 G_DEFINE_BOXED_TYPE (RegressTestBoxedC,
2118 regress_test_boxed_c,
2119 regress_test_boxed_c_ref,
2120 regress_test_boxed_c_unref);
2121
2122 struct _RegressTestBoxedD
2123 {
2124 char *a_string;
2125 gint a_int;
2126 };
2127
2128 RegressTestBoxedD *
2129 regress_test_boxed_d_new (const char *a_string, int a_int)
2130 {
2131 RegressTestBoxedD *boxed;
2132
2133 boxed = g_slice_new (RegressTestBoxedD);
2134 boxed->a_string = g_strdup (a_string);
2135 boxed->a_int = a_int;
2136
2137 return boxed;
2138 }
2139
2140 RegressTestBoxedD *
2141 regress_test_boxed_d_copy (RegressTestBoxedD *boxed)
2142 {
2143 RegressTestBoxedD *ret;
2144
2145 ret = g_slice_new (RegressTestBoxedD);
2146 ret->a_string = g_strdup (boxed->a_string);
2147 ret->a_int = boxed->a_int;
2148
2149 return ret;
2150 }
2151
2152 void
2153 regress_test_boxed_d_free (RegressTestBoxedD *boxed)
2154 {
2155 g_free (boxed->a_string);
2156 g_slice_free (RegressTestBoxedD, boxed);
2157 }
2158
2159 int
2160 regress_test_boxed_d_get_magic (RegressTestBoxedD *boxed)
2161 {
2162 return strlen (boxed->a_string) + boxed->a_int;
2163 }
2164
2165 G_DEFINE_BOXED_TYPE (RegressTestBoxedD,
2166 regress_test_boxed_d,
2167 regress_test_boxed_d_copy,
2168 regress_test_boxed_d_free);
2169
2170 G_DEFINE_TYPE (RegressTestObj, regress_test_obj, G_TYPE_OBJECT);
2171
2172 enum
2173 {
2174 PROP_TEST_OBJ_BARE = 1,
2175 PROP_TEST_OBJ_BOXED,
2176 PROP_TEST_OBJ_HASH_TABLE,
2177 PROP_TEST_OBJ_LIST,
2178 PROP_TEST_OBJ_PPTRARRAY,
2179 PROP_TEST_OBJ_HASH_TABLE_OLD,
2180 PROP_TEST_OBJ_LIST_OLD,
2181 PROP_TEST_OBJ_INT,
2182 PROP_TEST_OBJ_FLOAT,
2183 PROP_TEST_OBJ_DOUBLE,
2184 PROP_TEST_OBJ_STRING,
2185 PROP_TEST_OBJ_GTYPE,
2186 PROP_TEST_OBJ_NAME_CONFLICT,
2187 PROP_TEST_OBJ_BYTE_ARRAY,
2188 PROP_TEST_OBJ_UNICHAR,
2189 PROP_TEST_OBJ_WRITE_ONLY,
2190 };
2191
2192 static void
2193 regress_test_obj_set_property (GObject *object,
2194 guint property_id,
2195 const GValue *value,
2196 GParamSpec *pspec)
2197 {
2198 RegressTestObj *self = REGRESS_TEST_OBJECT (object);
2199 GList *list;
2200
2201 switch (property_id)
2202 {
2203 case PROP_TEST_OBJ_BARE:
2204 regress_test_obj_set_bare (self, g_value_get_object (value));
2205 break;
2206
2207 case PROP_TEST_OBJ_BOXED:
2208 if (self->boxed)
2209 regress_test_boxed_free (self->boxed);
2210 self->boxed = g_value_dup_boxed (value);
2211 break;
2212
2213 case PROP_TEST_OBJ_HASH_TABLE:
2214 case PROP_TEST_OBJ_HASH_TABLE_OLD:
2215 if (self->hash_table)
2216 g_hash_table_unref (self->hash_table);
2217 self->hash_table = g_hash_table_ref (g_value_get_boxed (value));
2218 break;
2219
2220 case PROP_TEST_OBJ_LIST:
2221 case PROP_TEST_OBJ_LIST_OLD:
2222 g_list_free_full (self->list, g_free);
2223 list = g_value_get_pointer (value);
2224 self->list = g_list_copy_deep (list, (GCopyFunc) (void *) g_strdup, NULL);
2225 break;
2226
2227 case PROP_TEST_OBJ_INT:
2228 self->some_int8 = g_value_get_int (value);
2229 break;
2230
2231 case PROP_TEST_OBJ_FLOAT:
2232 self->some_float = g_value_get_float (value);
2233 break;
2234
2235 case PROP_TEST_OBJ_DOUBLE:
2236 self->some_double = g_value_get_double (value);
2237 break;
2238
2239 case PROP_TEST_OBJ_STRING:
2240 g_clear_pointer (&self->string, g_free);
2241 self->string = g_value_dup_string (value);
2242 break;
2243
2244 case PROP_TEST_OBJ_GTYPE:
2245 self->gtype = g_value_get_gtype (value);
2246 break;
2247
2248 case PROP_TEST_OBJ_NAME_CONFLICT:
2249 self->name_conflict = g_value_get_int (value);
2250 break;
2251
2252 case PROP_TEST_OBJ_BYTE_ARRAY:
2253 self->byte_array = g_value_get_boxed (value);
2254 break;
2255
2256 case PROP_TEST_OBJ_UNICHAR:
2257 self->unichar = g_value_get_uint (value);
2258 break;
2259
2260 case PROP_TEST_OBJ_WRITE_ONLY:
2261 if (g_value_get_boolean (value))
2262 self->some_int8 = 0;
2263 break;
2264
2265 default:
2266 /* We don't have any other property... */
2267 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2268 break;
2269 }
2270 }
2271
2272 static void
2273 regress_test_obj_get_property (GObject *object,
2274 guint property_id,
2275 GValue *value,
2276 GParamSpec *pspec)
2277 {
2278 RegressTestObj *self = REGRESS_TEST_OBJECT (object);
2279
2280 switch (property_id)
2281 {
2282 case PROP_TEST_OBJ_BARE:
2283 g_value_set_object (value, self->bare);
2284 break;
2285
2286 case PROP_TEST_OBJ_BOXED:
2287 g_value_set_boxed (value, self->boxed);
2288 break;
2289
2290 case PROP_TEST_OBJ_HASH_TABLE:
2291 case PROP_TEST_OBJ_HASH_TABLE_OLD:
2292 if (self->hash_table != NULL)
2293 g_hash_table_ref (self->hash_table);
2294 g_value_set_boxed (value, self->hash_table);
2295 break;
2296
2297 case PROP_TEST_OBJ_LIST:
2298 case PROP_TEST_OBJ_LIST_OLD:
2299 g_value_set_pointer (value, self->list);
2300 break;
2301
2302 case PROP_TEST_OBJ_INT:
2303 g_value_set_int (value, self->some_int8);
2304 break;
2305
2306 case PROP_TEST_OBJ_FLOAT:
2307 g_value_set_float (value, self->some_float);
2308 break;
2309
2310 case PROP_TEST_OBJ_DOUBLE:
2311 g_value_set_double (value, self->some_double);
2312 break;
2313
2314 case PROP_TEST_OBJ_STRING:
2315 g_value_set_string (value, self->string);
2316 break;
2317
2318 case PROP_TEST_OBJ_GTYPE:
2319 g_value_set_gtype (value, self->gtype);
2320 break;
2321
2322 case PROP_TEST_OBJ_NAME_CONFLICT:
2323 g_value_set_int (value, self->name_conflict);
2324 break;
2325
2326 case PROP_TEST_OBJ_BYTE_ARRAY:
2327 g_value_set_boxed (value, self->byte_array);
2328 break;
2329
2330 case PROP_TEST_OBJ_UNICHAR:
2331 g_value_set_uint (value, self->unichar);
2332 break;
2333
2334 default:
2335 /* We don't have any other property... */
2336 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2337 break;
2338 }
2339 }
2340
2341 static void
2342 regress_test_obj_dispose (GObject *gobject)
2343 {
2344 RegressTestObj *self = REGRESS_TEST_OBJECT (gobject);
2345
2346 if (self->bare)
2347 {
2348 g_object_unref (self->bare);
2349
2350 self->bare = NULL;
2351 }
2352
2353 if (self->boxed)
2354 {
2355 regress_test_boxed_free (self->boxed);
2356 self->boxed = NULL;
2357 }
2358
2359 if (self->list)
2360 {
2361 g_list_free_full (self->list, g_free);
2362 self->list = NULL;
2363 }
2364
2365 g_clear_pointer (&self->hash_table, g_hash_table_unref);
2366 g_clear_pointer (&self->string, g_free);
2367
2368 /* Chain up to the parent class */
2369 G_OBJECT_CLASS (regress_test_obj_parent_class)->dispose (gobject);
2370 }
2371
2372 static int
2373 regress_test_obj_default_matrix (RegressTestObj *obj G_GNUC_UNUSED,
2374 const char *somestr G_GNUC_UNUSED)
2375 {
2376 return 42;
2377 }
2378
2379 enum
2380 {
2381 REGRESS_TEST_OBJ_SIGNAL_SIG_NEW_WITH_ARRAY_PROP,
2382 REGRESS_TEST_OBJ_SIGNAL_SIG_NEW_WITH_ARRAY_LEN_PROP,
2383 REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_HASH_PROP,
2384 REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_STRV,
2385 REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_STRV_FULL,
2386 REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_OBJ,
2387 REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_OBJ_FULL,
2388 REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_FOREIGN_STRUCT,
2389 REGRESS_TEST_OBJ_SIGNAL_FIRST,
2390 REGRESS_TEST_OBJ_SIGNAL_CLEANUP,
2391 REGRESS_TEST_OBJ_SIGNAL_ALL,
2392 REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_INT64_PROP,
2393 REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_UINT64_PROP,
2394 REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_INTARRAY_RET,
2395 REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_INOUT_INT,
2396 REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_GERROR,
2397 N_REGRESS_TEST_OBJ_SIGNALS
2398 };
2399
2400 static guint regress_test_obj_signals[N_REGRESS_TEST_OBJ_SIGNALS] = { 0 };
2401
2402 static void
2403 regress_test_obj_class_init (RegressTestObjClass *klass)
2404 {
2405 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
2406 GParamSpec *pspec;
2407 GType param_types[1];
2408
2409 klass->test_signal =
2410 g_signal_newv ("test",
2411 G_TYPE_FROM_CLASS (gobject_class),
2412 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
2413 NULL /* closure */,
2414 NULL /* accumulator */,
2415 NULL /* accumulator data */,
2416 g_cclosure_marshal_VOID__VOID,
2417 G_TYPE_NONE /* return_type */,
2418 0 /* n_params */,
2419 NULL /* param_types */);
2420
2421 param_types[0] = regress_test_simple_boxed_a_get_gtype () | G_SIGNAL_TYPE_STATIC_SCOPE;
2422 klass->test_signal_with_static_scope_arg =
2423 g_signal_newv ("test-with-static-scope-arg",
2424 G_TYPE_FROM_CLASS (gobject_class),
2425 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
2426 NULL /* closure */,
2427 NULL /* accumulator */,
2428 NULL /* accumulator data */,
2429 g_cclosure_marshal_VOID__BOXED,
2430 G_TYPE_NONE /* return_type */,
2431 1 /* n_params */,
2432 param_types);
2433
2434 /**
2435 * RegressTestObj::sig-with-array-prop:
2436 * @self: an object
2437 * @arr: (type GArray) (element-type uint): numbers
2438 *
2439 * This test signal is like TelepathyGlib's
2440 * TpChannel:: group-members-changed-detailed:
2441 */
2442 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_NEW_WITH_ARRAY_PROP] =
2443 g_signal_new ("sig-with-array-prop",
2444 G_TYPE_FROM_CLASS (gobject_class),
2445 G_SIGNAL_RUN_LAST,
2446 0,
2447 NULL,
2448 NULL,
2449 g_cclosure_marshal_VOID__BOXED,
2450 G_TYPE_NONE,
2451 1,
2452 G_TYPE_ARRAY);
2453
2454 /**
2455 * RegressTestObj::sig-with-array-len-prop:
2456 * @self: an object
2457 * @arr: (array length=len) (element-type uint) (allow-none): numbers, or %NULL
2458 * @len: length of @arr, or 0
2459 *
2460 * This test signal similar to GSettings::change-event.
2461 * You can use this with regress_test_obj_emit_sig_with_array_len_prop(), or
2462 * raise from the introspection client language.
2463 */
2464 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_NEW_WITH_ARRAY_LEN_PROP] =
2465 g_signal_new ("sig-with-array-len-prop",
2466 G_TYPE_FROM_CLASS (gobject_class),
2467 G_SIGNAL_RUN_LAST,
2468 0,
2469 NULL,
2470 NULL,
2471 NULL,
2472 G_TYPE_NONE,
2473 2,
2474 G_TYPE_POINTER,
2475 G_TYPE_INT);
2476
2477 /**
2478 * RegressTestObj::sig-with-hash-prop:
2479 * @self: an object
2480 * @hash: (element-type utf8 GObject.Value):
2481 *
2482 * This test signal is like TelepathyGlib's
2483 * TpAccount::status-changed
2484 */
2485 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_HASH_PROP] =
2486 g_signal_new ("sig-with-hash-prop",
2487 G_TYPE_FROM_CLASS (gobject_class),
2488 G_SIGNAL_RUN_LAST,
2489 0,
2490 NULL,
2491 NULL,
2492 g_cclosure_marshal_VOID__BOXED,
2493 G_TYPE_NONE,
2494 1,
2495 G_TYPE_HASH_TABLE);
2496
2497 /**
2498 * RegressTestObj::sig-with-strv:
2499 * @self: an object
2500 * @strs: strings
2501 *
2502 * Test GStrv as a param.
2503 */
2504 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_STRV] =
2505 g_signal_new ("sig-with-strv",
2506 G_TYPE_FROM_CLASS (gobject_class),
2507 G_SIGNAL_RUN_LAST,
2508 0,
2509 NULL,
2510 NULL,
2511 g_cclosure_marshal_VOID__BOXED,
2512 G_TYPE_NONE,
2513 1,
2514 G_TYPE_STRV);
2515
2516 /**
2517 * RegressTestObj::sig-with-strv-full:
2518 * @self: an object
2519 * @strs: (transfer full): strings
2520 *
2521 * Test GStrv as a param.
2522 */
2523 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_STRV_FULL] =
2524 g_signal_new ("sig-with-strv-full",
2525 G_TYPE_FROM_CLASS (gobject_class),
2526 G_SIGNAL_RUN_LAST,
2527 0,
2528 NULL,
2529 NULL,
2530 g_cclosure_marshal_VOID__BOXED,
2531 G_TYPE_NONE,
2532 1,
2533 G_TYPE_STRV);
2534
2535 /**
2536 * RegressTestObj::sig-with-obj:
2537 * @self: an object
2538 * @obj: (transfer none): A newly created RegressTestObj
2539 *
2540 * Test transfer none GObject as a param (tests refcounting).
2541 * Use with regress_test_obj_emit_sig_with_obj
2542 */
2543 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_OBJ] =
2544 g_signal_new ("sig-with-obj",
2545 G_TYPE_FROM_CLASS (gobject_class),
2546 G_SIGNAL_RUN_LAST,
2547 0,
2548 NULL,
2549 NULL,
2550 g_cclosure_marshal_VOID__OBJECT,
2551 G_TYPE_NONE,
2552 1,
2553 G_TYPE_OBJECT);
2554
2555 /**
2556 * RegressTestObj::sig-with-obj-full:
2557 * @self: an object
2558 * @obj: (transfer full): A newly created RegressTestObj
2559 *
2560 * Test transfer full GObject as a param (tests refcounting).
2561 * Use with regress_test_obj_emit_sig_with_obj_full
2562 */
2563 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_OBJ_FULL] =
2564 g_signal_new ("sig-with-obj-full",
2565 G_TYPE_FROM_CLASS (gobject_class),
2566 G_SIGNAL_RUN_LAST,
2567 0,
2568 NULL,
2569 NULL,
2570 g_cclosure_marshal_VOID__OBJECT,
2571 G_TYPE_NONE,
2572 1,
2573 G_TYPE_OBJECT);
2574
2575 #ifndef GI_TEST_DISABLE_CAIRO
2576 /**
2577 * RegressTestObj::sig-with-foreign-struct:
2578 * @self: an object
2579 * @cr: (transfer none): A cairo context.
2580 */
2581 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_FOREIGN_STRUCT] =
2582 g_signal_new ("sig-with-foreign-struct",
2583 G_TYPE_FROM_CLASS (gobject_class),
2584 G_SIGNAL_RUN_LAST,
2585 0,
2586 NULL,
2587 NULL,
2588 NULL,
2589 G_TYPE_NONE,
2590 1,
2591 CAIRO_GOBJECT_TYPE_CONTEXT);
2592 #endif /* GI_TEST_DISABLE_CAIRO */
2593
2594 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_FIRST] =
2595 g_signal_new ("first",
2596 G_TYPE_FROM_CLASS (gobject_class),
2597 G_SIGNAL_RUN_FIRST,
2598 0,
2599 NULL,
2600 NULL,
2601 g_cclosure_marshal_VOID__VOID,
2602 G_TYPE_NONE,
2603 0);
2604
2605 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_CLEANUP] =
2606 g_signal_new ("cleanup",
2607 G_TYPE_FROM_CLASS (gobject_class),
2608 G_SIGNAL_RUN_CLEANUP,
2609 0,
2610 NULL,
2611 NULL,
2612 g_cclosure_marshal_VOID__VOID,
2613 G_TYPE_NONE,
2614 0);
2615
2616 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_ALL] =
2617 g_signal_new ("all",
2618 G_TYPE_FROM_CLASS (gobject_class),
2619 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_ACTION | G_SIGNAL_NO_HOOKS,
2620 0,
2621 NULL,
2622 NULL,
2623 g_cclosure_marshal_VOID__VOID,
2624 G_TYPE_NONE,
2625 0);
2626
2627 /**
2628 * RegressTestObj::sig-with-int64-prop:
2629 * @self: an object
2630 * @i: an integer
2631 *
2632 * You can use this with regress_test_obj_emit_sig_with_int64, or raise from
2633 * the introspection client langage.
2634 */
2635 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_INT64_PROP] =
2636 g_signal_new ("sig-with-int64-prop",
2637 G_TYPE_FROM_CLASS (gobject_class),
2638 G_SIGNAL_RUN_LAST,
2639 0,
2640 NULL,
2641 NULL,
2642 g_cclosure_marshal_VOID__BOXED,
2643 G_TYPE_INT64,
2644 1,
2645 G_TYPE_INT64);
2646
2647 /**
2648 * RegressTestObj::sig-with-uint64-prop:
2649 * @self: an object
2650 * @i: an integer
2651 *
2652 * You can use this with regress_test_obj_emit_sig_with_uint64, or raise from
2653 * the introspection client langage.
2654 */
2655 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_UINT64_PROP] =
2656 g_signal_new ("sig-with-uint64-prop",
2657 G_TYPE_FROM_CLASS (gobject_class),
2658 G_SIGNAL_RUN_LAST,
2659 0,
2660 NULL,
2661 NULL,
2662 g_cclosure_marshal_VOID__BOXED,
2663 G_TYPE_UINT64,
2664 1,
2665 G_TYPE_UINT64);
2666
2667 /**
2668 * RegressTestObj::sig-with-intarray-ret:
2669 * @self: an object
2670 * @i: an integer
2671 *
2672 * Returns: (array zero-terminated=1) (element-type gint) (transfer full):
2673 */
2674 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_INTARRAY_RET] =
2675 g_signal_new ("sig-with-intarray-ret",
2676 G_TYPE_FROM_CLASS (gobject_class),
2677 G_SIGNAL_RUN_LAST,
2678 0,
2679 NULL,
2680 NULL,
2681 g_cclosure_marshal_VOID__BOXED,
2682 G_TYPE_ARRAY,
2683 1,
2684 G_TYPE_INT);
2685
2686 /**
2687 * RegressTestObj::sig-with-inout-int
2688 * @self: The object that emitted the signal
2689 * @position: (inout) (type int): The position, in characters, at which to
2690 * insert the new text. This is an in-out paramter. After the signal
2691 * emission is finished, it should point after the newly inserted text.
2692 *
2693 * This signal is modeled after GtkEditable::insert-text.
2694 */
2695 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_INOUT_INT] =
2696 g_signal_new ("sig-with-inout-int",
2697 G_TYPE_FROM_CLASS (gobject_class),
2698 G_SIGNAL_RUN_LAST,
2699 0,
2700 NULL,
2701 NULL,
2702 NULL,
2703 G_TYPE_NONE,
2704 1,
2705 G_TYPE_POINTER);
2706
2707 /**
2708 * RegressTestObj::sig-with-gerror:
2709 * @self: The object that emitted the signal
2710 * @error: (nullable) (type GLib.Error): A #GError if something went wrong
2711 * internally in @self. You must not free this #GError.
2712 *
2713 * This signal is modeled after #GstDiscoverer::discovered, and is added to
2714 * exercise the path of a #GError being marshalled as a boxed type instead of
2715 * an exception in the introspected language.
2716 *
2717 * Use via regress_test_obj_emit_sig_with_error() and
2718 * regress_test_obj_emit_sig_with_null_error(), or emit via the introspected
2719 * language.
2720 */
2721 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_GERROR] =
2722 g_signal_new ("sig-with-gerror", G_TYPE_FROM_CLASS (klass),
2723 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
2724 g_cclosure_marshal_generic, G_TYPE_NONE, 1,
2725 G_TYPE_ERROR | G_SIGNAL_TYPE_STATIC_SCOPE);
2726
2727 gobject_class->set_property = regress_test_obj_set_property;
2728 gobject_class->get_property = regress_test_obj_get_property;
2729 gobject_class->dispose = regress_test_obj_dispose;
2730
2731 pspec = g_param_spec_object ("bare",
2732 "Bare property",
2733 "A contained object",
2734 G_TYPE_OBJECT,
2735 G_PARAM_READWRITE);
2736 g_object_class_install_property (gobject_class,
2737 PROP_TEST_OBJ_BARE,
2738 pspec);
2739
2740 pspec = g_param_spec_boxed ("boxed",
2741 "Boxed property",
2742 "A contained boxed struct",
2743 REGRESS_TEST_TYPE_BOXED,
2744 G_PARAM_READWRITE);
2745 g_object_class_install_property (gobject_class,
2746 PROP_TEST_OBJ_BOXED,
2747 pspec);
2748
2749 /**
2750 * RegressTestObj:hash-table: (type GLib.HashTable(utf8,gint8)) (transfer container)
2751 */
2752 pspec = g_param_spec_boxed ("hash-table",
2753 "GHashTable property",
2754 "A contained GHashTable",
2755 G_TYPE_HASH_TABLE,
2756 G_PARAM_READWRITE);
2757 g_object_class_install_property (gobject_class,
2758 PROP_TEST_OBJ_HASH_TABLE,
2759 pspec);
2760
2761 /**
2762 * RegressTestObj:list: (type GLib.List(utf8)) (transfer none) (default-value NULL)
2763 */
2764 pspec = g_param_spec_pointer ("list",
2765 "GList property",
2766 "A contained GList",
2767 G_PARAM_READWRITE);
2768 g_object_class_install_property (gobject_class,
2769 PROP_TEST_OBJ_LIST,
2770 pspec);
2771
2772 /**
2773 * RegressTestObj:pptrarray: (type GLib.PtrArray(utf8)) (transfer none)
2774 */
2775 pspec = g_param_spec_pointer ("pptrarray",
2776 "PtrArray property as a pointer",
2777 "Test annotating with GLib.PtrArray",
2778 G_PARAM_READWRITE);
2779 g_object_class_install_property (gobject_class,
2780 PROP_TEST_OBJ_PPTRARRAY,
2781 pspec);
2782
2783 /**
2784 * RegressTestObj:hash-table-old: (type GLib.HashTable<utf8,gint8>) (transfer container)
2785 */
2786 pspec = g_param_spec_boxed ("hash-table-old",
2787 "GHashTable property with <>",
2788 "A contained GHashTable with <>",
2789 G_TYPE_HASH_TABLE,
2790 G_PARAM_READWRITE);
2791 g_object_class_install_property (gobject_class,
2792 PROP_TEST_OBJ_HASH_TABLE_OLD,
2793 pspec);
2794
2795 /**
2796 * RegressTestObj:list-old: (type GLib.List<utf8>) (transfer none)
2797 */
2798 pspec = g_param_spec_pointer ("list-old",
2799 "GList property with ()",
2800 "A contained GList with <>",
2801 G_PARAM_READWRITE);
2802 g_object_class_install_property (gobject_class,
2803 PROP_TEST_OBJ_LIST_OLD,
2804 pspec);
2805
2806 /**
2807 * RegressTestObj:int:
2808 */
2809 pspec = g_param_spec_int ("int",
2810 "int property",
2811 "A contained int",
2812 G_MININT,
2813 G_MAXINT,
2814 0,
2815 G_PARAM_READWRITE);
2816 g_object_class_install_property (gobject_class,
2817 PROP_TEST_OBJ_INT,
2818 pspec);
2819
2820 /**
2821 * RegressTestObj:float:
2822 */
2823 pspec = g_param_spec_float ("float",
2824 "float property",
2825 "A contained float",
2826 G_MINFLOAT,
2827 G_MAXFLOAT,
2828 1.0f,
2829 G_PARAM_READWRITE);
2830 g_object_class_install_property (gobject_class,
2831 PROP_TEST_OBJ_FLOAT,
2832 pspec);
2833
2834 /**
2835 * RegressTestObj:double:
2836 */
2837 pspec = g_param_spec_double ("double",
2838 "double property",
2839 "A contained double",
2840 G_MINDOUBLE,
2841 G_MAXDOUBLE,
2842 1.0,
2843 G_PARAM_READWRITE);
2844 g_object_class_install_property (gobject_class,
2845 PROP_TEST_OBJ_DOUBLE,
2846 pspec);
2847
2848 /**
2849 * RegressTestObj:string: (setter set_string) (getter get_string)
2850 */
2851 pspec = g_param_spec_string ("string",
2852 "string property",
2853 "A contained string",
2854 NULL,
2855 G_PARAM_READWRITE);
2856 g_object_class_install_property (gobject_class,
2857 PROP_TEST_OBJ_STRING,
2858 pspec);
2859
2860 /**
2861 * RegressTestObj:gtype: (default-value G_TYPE_INVALID)
2862 */
2863 pspec = g_param_spec_gtype ("gtype",
2864 "GType property",
2865 "A GType property",
2866 G_TYPE_NONE,
2867 G_PARAM_READWRITE);
2868 g_object_class_install_property (gobject_class,
2869 PROP_TEST_OBJ_GTYPE,
2870 pspec);
2871
2872 /**
2873 * RegressTestObj:name-conflict:
2874 */
2875 pspec = g_param_spec_int ("name-conflict",
2876 "name-conflict property",
2877 "A property name that conflicts with a method",
2878 G_MININT,
2879 G_MAXINT,
2880 42,
2881 G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
2882 g_object_class_install_property (gobject_class,
2883 PROP_TEST_OBJ_NAME_CONFLICT,
2884 pspec);
2885
2886 /**
2887 * RegressTestObj:byte-array:
2888 */
2889 pspec = g_param_spec_boxed ("byte-array",
2890 "GByteArray property",
2891 "A contained byte array without any element-type annotations",
2892 G_TYPE_BYTE_ARRAY,
2893 G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
2894 g_object_class_install_property (gobject_class,
2895 PROP_TEST_OBJ_BYTE_ARRAY,
2896 pspec);
2897
2898 /**
2899 * RegressTestObj:unichar:
2900 */
2901 pspec = g_param_spec_unichar ("unichar",
2902 "unichar code point",
2903 "An unichar (UTF-32 or UCS-4) code point",
2904 0,
2905 G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
2906 g_object_class_install_property (gobject_class,
2907 PROP_TEST_OBJ_UNICHAR,
2908 pspec);
2909
2910 /**
2911 * RegressTestObj:write-only:
2912 */
2913 pspec = g_param_spec_boolean ("write-only", "Write-only property",
2914 "A write-only bool property that resets the value of TestObj:int to 0 when true",
2915 FALSE, G_PARAM_WRITABLE);
2916 g_object_class_install_property (gobject_class, PROP_TEST_OBJ_WRITE_ONLY, pspec);
2917
2918 klass->matrix = regress_test_obj_default_matrix;
2919 }
2920
2921 static void
2922 regress_test_obj_init (RegressTestObj *obj)
2923 {
2924 obj->bare = NULL;
2925 obj->boxed = NULL;
2926 obj->hash_table = NULL;
2927 obj->gtype = G_TYPE_INVALID;
2928 }
2929
2930 /**
2931 * regress_test_obj_new: (constructor)
2932 * @obj: A #RegressTestObj
2933 */
2934 RegressTestObj *
2935 regress_test_obj_new (RegressTestObj *obj G_GNUC_UNUSED)
2936 {
2937 return g_object_new (REGRESS_TEST_TYPE_OBJ, NULL);
2938 }
2939
2940 /**
2941 * regress_constructor: (constructor)
2942 *
2943 */
2944 RegressTestObj *
2945 regress_constructor (void)
2946 {
2947 return g_object_new (REGRESS_TEST_TYPE_OBJ, NULL);
2948 }
2949
2950 /**
2951 * regress_test_obj_new_from_file:
2952 */
2953 RegressTestObj *
2954 regress_test_obj_new_from_file (const char *x G_GNUC_UNUSED,
2955 GError **error G_GNUC_UNUSED)
2956 {
2957 return g_object_new (REGRESS_TEST_TYPE_OBJ, NULL);
2958 }
2959
2960 /**
2961 * regress_test_obj_set_bare:
2962 * @bare: (allow-none):
2963 */
2964 void
2965 regress_test_obj_set_bare (RegressTestObj *obj, GObject *bare)
2966 {
2967 if (obj->bare)
2968 g_object_unref (obj->bare);
2969 obj->bare = bare;
2970 if (obj->bare)
2971 g_object_ref (obj->bare);
2972 }
2973
2974 /**
2975 * regress_test_obj_set_string: (set-property string)
2976 * @obj:
2977 * @str:
2978 */
2979 void
2980 regress_test_obj_set_string (RegressTestObj *obj, const char *str)
2981 {
2982 if (g_strcmp0 (str, obj->string) == 0)
2983 return;
2984
2985 g_free (obj->string);
2986 obj->string = g_strdup (str);
2987 g_object_notify (G_OBJECT (obj), "string");
2988 }
2989
2990 /**
2991 * regress_test_obj_get_string: (get-property string)
2992 * @obj:
2993 *
2994 * Returns: (transfer none):
2995 */
2996 const char *
2997 regress_test_obj_get_string (RegressTestObj *obj)
2998 {
2999 return obj->string;
3000 }
3001
3002 void
3003 regress_test_obj_emit_sig_with_obj (RegressTestObj *obj)
3004 {
3005 RegressTestObj *obj_param = regress_constructor ();
3006 g_object_set (obj_param, "int", 3, NULL);
3007 g_signal_emit_by_name (obj, "sig-with-obj", obj_param);
3008 g_object_unref (obj_param);
3009 }
3010
3011 void
3012 regress_test_obj_emit_sig_with_obj_full (RegressTestObj *obj)
3013 {
3014 RegressTestObj *obj_param = regress_constructor ();
3015 g_object_set (obj_param, "int", 5, NULL);
3016 g_signal_emit (obj,
3017 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_OBJ_FULL],
3018 0, g_steal_pointer (&obj_param));
3019 }
3020
3021 #if GLIB_CHECK_VERSION(2, 68, 0)
3022 void
3023 regress_test_obj_emit_sig_with_gstrv_full (RegressTestObj *obj)
3024 {
3025 GStrvBuilder *builder = g_strv_builder_new ();
3026 g_strv_builder_add_many (builder, "foo", "bar", "baz", NULL);
3027 g_signal_emit (obj,
3028 regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_STRV_FULL],
3029 0, g_strv_builder_end (builder));
3030 g_strv_builder_unref (builder);
3031 }
3032 #endif
3033
3034 #ifndef GI_TEST_DISABLE_CAIRO
3035 void
3036 regress_test_obj_emit_sig_with_foreign_struct (RegressTestObj *obj)
3037 {
3038 cairo_t *cr = regress_test_cairo_context_full_return ();
3039 g_signal_emit_by_name (obj, "sig-with-foreign-struct", cr);
3040 cairo_destroy (cr);
3041 }
3042 #endif /* GI_TEST_DISABLE_CAIRO */
3043
3044 void
3045 regress_test_obj_emit_sig_with_int64 (RegressTestObj *obj)
3046 {
3047 gint64 ret = 0;
3048 RegressTestObj *obj_param = regress_constructor ();
3049 g_signal_emit_by_name (obj, "sig-with-int64-prop", G_MAXINT64, &ret);
3050 g_object_unref (obj_param);
3051 g_assert (ret == G_MAXINT64);
3052 }
3053
3054 void
3055 regress_test_obj_emit_sig_with_uint64 (RegressTestObj *obj)
3056 {
3057 guint64 ret = 0;
3058 RegressTestObj *obj_param = regress_constructor ();
3059 g_signal_emit_by_name (obj, "sig-with-uint64-prop", G_MAXUINT64, &ret);
3060 g_object_unref (obj_param);
3061 g_assert (ret == G_MAXUINT64);
3062 }
3063
3064 /**
3065 * regress_test_obj_emit_sig_with_array_len_prop:
3066 */
3067 void
3068 regress_test_obj_emit_sig_with_array_len_prop (RegressTestObj *obj)
3069 {
3070 int arr[] = { 0, 1, 2, 3, 4 };
3071 g_signal_emit_by_name (obj, "sig-with-array-len-prop", &arr, 5);
3072 }
3073
3074 /**
3075 * regress_test_obj_emit_sig_with_inout_int:
3076 * @obj: The object to emit the signal.
3077 *
3078 * The signal handler must increment the inout parameter by 1.
3079 */
3080 void
3081 regress_test_obj_emit_sig_with_inout_int (RegressTestObj *obj)
3082 {
3083 int inout = 42;
3084 g_signal_emit_by_name (obj, "sig-with-inout-int", &inout);
3085 g_assert_cmpint (inout, ==, 43);
3086 }
3087
3088 /**
3089 * regress_test_obj_emit_sig_with_error:
3090 * @self: The object to emit the signal.
3091 */
3092 void
3093 regress_test_obj_emit_sig_with_error (RegressTestObj *self)
3094 {
3095 GError *err = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED,
3096 "Something failed");
3097 g_signal_emit_by_name (self, "sig-with-gerror", err);
3098 g_error_free (err);
3099 }
3100
3101 /**
3102 * regress_test_obj_emit_sig_with_null_error:
3103 * @self: The object to emit the signal.
3104 */
3105 void
3106 regress_test_obj_emit_sig_with_null_error (RegressTestObj *self)
3107 {
3108 g_signal_emit_by_name (self, "sig-with-gerror", NULL);
3109 }
3110
3111 int
3112 regress_test_obj_instance_method (RegressTestObj *obj G_GNUC_UNUSED)
3113 {
3114 return -1;
3115 }
3116
3117 /**
3118 * regress_test_obj_instance_method_full:
3119 * @obj: (transfer full):
3120 *
3121 */
3122 void
3123 regress_test_obj_instance_method_full (RegressTestObj *obj)
3124 {
3125 g_object_unref (obj);
3126 }
3127
3128 double
3129 regress_test_obj_static_method (int x)
3130 {
3131 return x;
3132 }
3133
3134 /**
3135 * regress_forced_method: (method)
3136 * @obj: A #RegressTestObj
3137 *
3138 */
3139 void
3140 regress_forced_method (RegressTestObj *obj G_GNUC_UNUSED)
3141 {
3142 }
3143
3144 /**
3145 * regress_test_obj_torture_signature_0:
3146 * @obj: A #RegressTestObj
3147 * @x:
3148 * @y: (out):
3149 * @z: (out):
3150 * @foo:
3151 * @q: (out):
3152 * @m:
3153 *
3154 */
3155 void
3156 regress_test_obj_torture_signature_0 (RegressTestObj *obj G_GNUC_UNUSED,
3157 int x,
3158 double *y,
3159 int *z,
3160 const char *foo,
3161 int *q,
3162 guint m)
3163 {
3164 *y = x;
3165 *z = x * 2;
3166 *q = g_utf8_strlen (foo, -1) + m;
3167 }
3168
3169 /**
3170 * regress_test_obj_torture_signature_1:
3171 * @obj: A #RegressTestObj
3172 * @x:
3173 * @y: (out):
3174 * @z: (out):
3175 * @foo:
3176 * @q: (out):
3177 * @m:
3178 * @error: A #GError
3179 *
3180 * This function throws an error if m is odd.
3181 */
3182 gboolean
3183 regress_test_obj_torture_signature_1 (RegressTestObj *obj G_GNUC_UNUSED,
3184 int x,
3185 double *y,
3186 int *z,
3187 const char *foo,
3188 int *q,
3189 guint m,
3190 GError **error)
3191 {
3192 *y = x;
3193 *z = x * 2;
3194 *q = g_utf8_strlen (foo, -1) + m;
3195 if (m % 2 == 0)
3196 return TRUE;
3197 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "m is odd");
3198 return FALSE;
3199 }
3200
3201 /**
3202 * regress_test_obj_skip_return_val:
3203 * @obj: a #RegressTestObj
3204 * @a: Parameter.
3205 * @out_b: (out): A return value.
3206 * @c: Other parameter.
3207 * @inout_d: (inout): Will be incremented.
3208 * @out_sum: (out): Return value.
3209 * @num1: Number.
3210 * @num2: Number.
3211 * @error: Return location for error.
3212 *
3213 * Check that the return value is skipped
3214 *
3215 * Returns: (skip): %TRUE if the call succeeds, %FALSE if @error is set.
3216 */
3217 gboolean
3218 regress_test_obj_skip_return_val (RegressTestObj *obj G_GNUC_UNUSED,
3219 gint a,
3220 gint *out_b,
3221 gdouble c G_GNUC_UNUSED,
3222 gint *inout_d,
3223 gint *out_sum,
3224 gint num1,
3225 gint num2,
3226 GError **error G_GNUC_UNUSED)
3227 {
3228 if (out_b != NULL)
3229 *out_b = a + 1;
3230 if (inout_d != NULL)
3231 *inout_d = *inout_d + 1;
3232 if (out_sum != NULL)
3233 *out_sum = num1 + 10 * num2;
3234 return TRUE;
3235 }
3236
3237 /**
3238 * regress_test_obj_skip_return_val_no_out:
3239 * @obj: a #RegressTestObj
3240 * @a: Parameter.
3241 * @error: Return location for error.
3242 *
3243 * Check that the return value is skipped. Succeed if a is nonzero, otherwise
3244 * raise an error.
3245 *
3246 * Returns: (skip): %TRUE if the call succeeds, %FALSE if @error is set.
3247 */
3248 gboolean
3249 regress_test_obj_skip_return_val_no_out (RegressTestObj *obj G_GNUC_UNUSED,
3250 gint a,
3251 GError **error)
3252 {
3253 if (a == 0)
3254 {
3255 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "a is zero");
3256 return FALSE;
3257 }
3258 else
3259 {
3260 return TRUE;
3261 }
3262 }
3263
3264 /**
3265 * regress_test_obj_skip_param:
3266 * @obj: A #RegressTestObj.
3267 * @a: Parameter.
3268 * @out_b: (out): Return value.
3269 * @c: (skip): Other parameter.
3270 * @inout_d: (inout): Will be incremented.
3271 * @out_sum: (out): Return value.
3272 * @num1: Number.
3273 * @num2: Number.
3274 * @error: Return location for error.
3275 *
3276 * Check that a parameter is skipped
3277 *
3278 * Returns: %TRUE if the call succeeds, %FALSE if @error is set.
3279 */
3280 gboolean
3281 regress_test_obj_skip_param (RegressTestObj *obj G_GNUC_UNUSED,
3282 gint a,
3283 gint *out_b,
3284 gdouble c G_GNUC_UNUSED,
3285 gint *inout_d,
3286 gint *out_sum,
3287 gint num1,
3288 gint num2,
3289 GError **error G_GNUC_UNUSED)
3290 {
3291 if (out_b != NULL)
3292 *out_b = a + 1;
3293 if (inout_d != NULL)
3294 *inout_d = *inout_d + 1;
3295 if (out_sum != NULL)
3296 *out_sum = num1 + 10 * num2;
3297 return TRUE;
3298 }
3299
3300 /**
3301 * regress_test_obj_skip_out_param:
3302 * @obj: A #RegressTestObj.
3303 * @a: Parameter.
3304 * @out_b: (out) (skip): Return value.
3305 * @c: Other parameter.
3306 * @inout_d: (inout): Will be incremented.
3307 * @out_sum: (out): Return value.
3308 * @num1: Number.
3309 * @num2: Number.
3310 * @error: Return location for error.
3311 *
3312 * Check that the out value is skipped
3313 *
3314 * Returns: %TRUE if the call succeeds, %FALSE if @error is set.
3315 */
3316 gboolean
3317 regress_test_obj_skip_out_param (RegressTestObj *obj G_GNUC_UNUSED,
3318 gint a,
3319 gint *out_b,
3320 gdouble c G_GNUC_UNUSED,
3321 gint *inout_d,
3322 gint *out_sum,
3323 gint num1,
3324 gint num2,
3325 GError **error G_GNUC_UNUSED)
3326 {
3327 if (out_b != NULL)
3328 *out_b = a + 1;
3329 if (inout_d != NULL)
3330 *inout_d = *inout_d + 1;
3331 if (out_sum != NULL)
3332 *out_sum = num1 + 10 * num2;
3333 return TRUE;
3334 }
3335
3336 /**
3337 * regress_test_obj_skip_inout_param:
3338 * @obj: A #RegressTestObj.
3339 * @a: Parameter.
3340 * @out_b: (out): Return value.
3341 * @c: Other parameter.
3342 * @inout_d: (inout) (skip): Will be incremented.
3343 * @out_sum: (out): Return value.
3344 * @num1: Number.
3345 * @num2: Number.
3346 * @error: Return location for error.
3347 *
3348 * Check that the out value is skipped
3349 *
3350 * Returns: %TRUE if the call succeeds, %FALSE if @error is set.
3351 */
3352 gboolean
3353 regress_test_obj_skip_inout_param (RegressTestObj *obj G_GNUC_UNUSED,
3354 gint a,
3355 gint *out_b,
3356 gdouble c G_GNUC_UNUSED,
3357 gint *inout_d,
3358 gint *out_sum,
3359 gint num1,
3360 gint num2,
3361 GError **error G_GNUC_UNUSED)
3362 {
3363 if (out_b != NULL)
3364 *out_b = a + 1;
3365 if (inout_d != NULL)
3366 *inout_d = *inout_d + 1;
3367 if (out_sum != NULL)
3368 *out_sum = num1 + 10 * num2;
3369 return TRUE;
3370 }
3371
3372 /**
3373 * regress_test_obj_do_matrix: (virtual matrix)
3374 * @obj: A #RegressTestObj
3375 * @somestr: Meaningless string
3376 *
3377 * This method is virtual. Notably its name differs from the virtual
3378 * slot name, which makes it useful for testing bindings handle this
3379 * case.
3380 */
3381 int
3382 regress_test_obj_do_matrix (RegressTestObj *obj, const char *somestr)
3383 {
3384 return REGRESS_TEST_OBJ_GET_CLASS (obj)->matrix (obj, somestr);
3385 }
3386
3387 /**
3388 * regress_func_obj_null_in:
3389 * @obj: (allow-none): A #RegressTestObj
3390 */
3391 void
3392 regress_func_obj_null_in (RegressTestObj *obj G_GNUC_UNUSED)
3393 {
3394 }
3395
3396 /**
3397 * regress_test_obj_null_out:
3398 * @obj: (allow-none) (out): A #RegressTestObj
3399 */
3400 void
3401 regress_test_obj_null_out (RegressTestObj **obj)
3402 {
3403 if (obj)
3404 *obj = NULL;
3405 }
3406
3407 /**
3408 * regress_func_obj_nullable_in:
3409 * @obj: (nullable): A #RegressTestObj
3410 */
3411 void
3412 regress_func_obj_nullable_in (RegressTestObj *obj G_GNUC_UNUSED)
3413 {
3414 }
3415
3416 /**
3417 * regress_test_obj_not_nullable_typed_gpointer_in:
3418 * @obj: A #RegressTestObj
3419 * @input: (type GObject): some #GObject
3420 */
3421 void
3422 regress_test_obj_not_nullable_typed_gpointer_in (RegressTestObj *obj G_GNUC_UNUSED,
3423 gpointer input G_GNUC_UNUSED)
3424 {
3425 }
3426
3427 /**
3428 * regress_test_obj_not_nullable_element_typed_gpointer_in:
3429 * @obj: A #RegressTestObj
3430 * @input: (element-type guint8) (array length=count): some uint8 array
3431 * @count: length of @input
3432 */
3433 void
3434 regress_test_obj_not_nullable_element_typed_gpointer_in (RegressTestObj *obj G_GNUC_UNUSED,
3435 gpointer input G_GNUC_UNUSED,
3436 guint count G_GNUC_UNUSED)
3437 {
3438 }
3439
3440 /**
3441 * regress_test_obj_name_conflict:
3442 * @obj: A #RegressTestObj
3443 */
3444 void
3445 regress_test_obj_name_conflict (RegressTestObj *obj G_GNUC_UNUSED)
3446 {
3447 }
3448
3449 /**
3450 * regress_test_array_fixed_out_objects:
3451 * @objs: (out) (array fixed-size=2) (transfer full): An array of #RegressTestObj
3452 */
3453 void
3454 regress_test_array_fixed_out_objects (RegressTestObj ***objs)
3455 {
3456 RegressTestObj **values = (RegressTestObj **) g_new (gpointer, 2);
3457
3458 values[0] = regress_constructor ();
3459 values[1] = regress_constructor ();
3460
3461 *objs = values;
3462 }
3463
3464 typedef struct _CallbackInfo CallbackInfo;
3465
3466 struct _CallbackInfo
3467 {
3468 RegressTestCallbackUserData callback;
3469 GDestroyNotify notify;
3470 gpointer user_data;
3471 };
3472
3473 static void
3474 regress_test_sub_obj_iface_init (RegressTestInterfaceIface *iface G_GNUC_UNUSED)
3475 {
3476 }
3477
3478 enum
3479 {
3480 PROP_TEST_SUB_OBJ_NUMBER = 1,
3481 PROP_TEST_SUB_OBJ_BOOLEAN,
3482 };
3483
3484 G_DEFINE_TYPE_WITH_CODE (RegressTestSubObj, regress_test_sub_obj, REGRESS_TEST_TYPE_OBJ, G_IMPLEMENT_INTERFACE (REGRESS_TEST_TYPE_INTERFACE, regress_test_sub_obj_iface_init));
3485
3486 static void
3487 regress_test_sub_obj_set_property (GObject *object,
3488 guint property_id,
3489 const GValue *value,
3490 GParamSpec *pspec)
3491 {
3492 RegressTestSubObj *self = REGRESS_TEST_SUB_OBJECT (object);
3493
3494 switch (property_id)
3495 {
3496 case PROP_TEST_SUB_OBJ_NUMBER:
3497 self->number = g_value_get_int (value);
3498 break;
3499
3500 case PROP_TEST_SUB_OBJ_BOOLEAN:
3501 self->boolean = g_value_get_boolean (value);
3502 break;
3503
3504 default:
3505 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
3506 }
3507 }
3508
3509 static void
3510 regress_test_sub_obj_get_property (GObject *object,
3511 guint property_id,
3512 GValue *value,
3513 GParamSpec *pspec)
3514 {
3515 RegressTestSubObj *self = REGRESS_TEST_SUB_OBJECT (object);
3516
3517 switch (property_id)
3518 {
3519 case PROP_TEST_SUB_OBJ_NUMBER:
3520 g_value_set_int (value, self->number);
3521 break;
3522
3523 case PROP_TEST_SUB_OBJ_BOOLEAN:
3524 g_value_set_boolean (value, self->boolean);
3525 break;
3526
3527 default:
3528 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
3529 }
3530 }
3531
3532 static void
3533 regress_test_sub_obj_class_init (RegressTestSubObjClass *klass)
3534 {
3535 const guint flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS;
3536 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
3537 gobject_class->get_property = regress_test_sub_obj_get_property;
3538 gobject_class->set_property = regress_test_sub_obj_set_property;
3539
3540 g_object_class_install_property (gobject_class, PROP_TEST_SUB_OBJ_BOOLEAN,
3541 g_param_spec_boolean ("boolean", "Boolean", "Boolean",
3542 TRUE, flags));
3543
3544 g_object_class_override_property (gobject_class, PROP_TEST_SUB_OBJ_NUMBER,
3545 "number");
3546 }
3547
3548 static void
3549 regress_test_sub_obj_init (RegressTestSubObj *self G_GNUC_UNUSED)
3550 {
3551 }
3552
3553 RegressTestObj *
3554 regress_test_sub_obj_new (void)
3555 {
3556 return g_object_new (REGRESS_TEST_TYPE_SUB_OBJ, NULL);
3557 }
3558
3559 int
3560 regress_test_sub_obj_instance_method (RegressTestSubObj *self G_GNUC_UNUSED)
3561 {
3562 return 0;
3563 }
3564
3565 void
3566 regress_test_sub_obj_unset_bare (RegressTestSubObj *obj)
3567 {
3568 regress_test_obj_set_bare (REGRESS_TEST_OBJECT (obj), NULL);
3569 }
3570
3571 /* RegressTestFundamental */
3572
3573 /**
3574 * regress_test_fundamental_object_ref:
3575 *
3576 * Returns: (transfer full): A new #RegressTestFundamentalObject
3577 */
3578 RegressTestFundamentalObject *
3579 regress_test_fundamental_object_ref (RegressTestFundamentalObject *fundamental_object)
3580 {
3581 g_return_val_if_fail (fundamental_object != NULL, NULL);
3582 g_atomic_int_inc (&fundamental_object->refcount);
3583
3584 return fundamental_object;
3585 }
3586
3587 static void
3588 regress_test_fundamental_object_free (RegressTestFundamentalObject *fundamental_object)
3589 {
3590 RegressTestFundamentalObjectClass *mo_class;
3591 regress_test_fundamental_object_ref (fundamental_object);
3592
3593 mo_class = REGRESS_TEST_FUNDAMENTAL_OBJECT_GET_CLASS (fundamental_object);
3594 mo_class->finalize (fundamental_object);
3595
3596 if (G_LIKELY (g_atomic_int_dec_and_test (&fundamental_object->refcount)))
3597 {
3598 g_type_free_instance ((GTypeInstance *) fundamental_object);
3599 }
3600 }
3601
3602 void
3603 regress_test_fundamental_object_unref (RegressTestFundamentalObject *fundamental_object)
3604 {
3605 g_return_if_fail (fundamental_object != NULL);
3606 g_return_if_fail (fundamental_object->refcount > 0);
3607
3608 if (G_UNLIKELY (g_atomic_int_dec_and_test (&fundamental_object->refcount)))
3609 {
3610 regress_test_fundamental_object_free (fundamental_object);
3611 }
3612 }
3613
3614 static void
3615 regress_test_fundamental_object_replace (RegressTestFundamentalObject **olddata, RegressTestFundamentalObject *newdata)
3616 {
3617 RegressTestFundamentalObject *olddata_val;
3618
3619 g_return_if_fail (olddata != NULL);
3620
3621 olddata_val = g_atomic_pointer_get ((gpointer *) olddata);
3622
3623 if (olddata_val == newdata)
3624 return;
3625
3626 if (newdata)
3627 regress_test_fundamental_object_ref (newdata);
3628
3629 while (!g_atomic_pointer_compare_and_exchange ((gpointer *) olddata,
3630 olddata_val, newdata))
3631 {
3632 olddata_val = g_atomic_pointer_get ((gpointer *) olddata);
3633 }
3634
3635 if (olddata_val)
3636 regress_test_fundamental_object_unref (olddata_val);
3637 }
3638
3639 static void
3640 regress_test_value_fundamental_object_init (GValue *value)
3641 {
3642 value->data[0].v_pointer = NULL;
3643 }
3644
3645 static void
3646 regress_test_value_fundamental_object_free (GValue *value)
3647 {
3648 if (value->data[0].v_pointer)
3649 {
3650 regress_test_fundamental_object_unref (REGRESS_TEST_FUNDAMENTAL_OBJECT_CAST (value->data[0].v_pointer));
3651 }
3652 }
3653
3654 static void
3655 regress_test_value_fundamental_object_copy (const GValue *src_value, GValue *dest_value)
3656 {
3657 if (src_value->data[0].v_pointer)
3658 {
3659 dest_value->data[0].v_pointer =
3660 regress_test_fundamental_object_ref (REGRESS_TEST_FUNDAMENTAL_OBJECT_CAST (src_value->data[0].v_pointer));
3661 }
3662 else
3663 {
3664 dest_value->data[0].v_pointer = NULL;
3665 }
3666 }
3667
3668 static gpointer
3669 regress_test_value_fundamental_object_peek_pointer (const GValue *value)
3670 {
3671 return value->data[0].v_pointer;
3672 }
3673
3674 static gchar *
3675 regress_test_value_fundamental_object_collect (GValue *value,
3676 guint n_collect_values,
3677 GTypeCValue *collect_values,
3678 guint collect_flags G_GNUC_UNUSED)
3679 {
3680 g_assert (n_collect_values > 0);
3681
3682 if (collect_values[0].v_pointer)
3683 {
3684 value->data[0].v_pointer =
3685 regress_test_fundamental_object_ref (collect_values[0].v_pointer);
3686 }
3687 else
3688 {
3689 value->data[0].v_pointer = NULL;
3690 }
3691
3692 return NULL;
3693 }
3694
3695 static gchar *
3696 regress_test_value_fundamental_object_lcopy (const GValue *value,
3697 guint n_collect_values,
3698 GTypeCValue *collect_values,
3699 guint collect_flags)
3700 {
3701 gpointer *fundamental_object_p;
3702
3703 g_assert (n_collect_values > 0);
3704
3705 fundamental_object_p = collect_values[0].v_pointer;
3706
3707 if (!fundamental_object_p)
3708 {
3709 return g_strdup_printf ("value location for '%s' passed as NULL",
3710 G_VALUE_TYPE_NAME (value));
3711 }
3712
3713 if (!value->data[0].v_pointer)
3714 *fundamental_object_p = NULL;
3715 else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
3716 *fundamental_object_p = value->data[0].v_pointer;
3717 else
3718 *fundamental_object_p = regress_test_fundamental_object_ref (value->data[0].v_pointer);
3719
3720 return NULL;
3721 }
3722
3723 static void
3724 regress_test_fundamental_object_finalize (RegressTestFundamentalObject *self G_GNUC_UNUSED)
3725 {
3726 }
3727
3728 static RegressTestFundamentalObject *
3729 regress_test_fundamental_object_copy_default (const RegressTestFundamentalObject *self G_GNUC_UNUSED)
3730 {
3731 g_warning ("RegressTestFundamentalObject classes must implement RegressTestFundamentalObject::copy");
3732 return NULL;
3733 }
3734
3735 static void
3736 regress_test_fundamental_object_class_init (gpointer g_class,
3737 gpointer class_data G_GNUC_UNUSED)
3738 {
3739 RegressTestFundamentalObjectClass *mo_class = REGRESS_TEST_FUNDAMENTAL_OBJECT_CLASS (g_class);
3740
3741 mo_class->copy = regress_test_fundamental_object_copy_default;
3742 mo_class->finalize = regress_test_fundamental_object_finalize;
3743 }
3744
3745 static void
3746 regress_test_fundamental_object_init (GTypeInstance *instance,
3747 gpointer klass G_GNUC_UNUSED)
3748 {
3749 RegressTestFundamentalObject *fundamental_object = REGRESS_TEST_FUNDAMENTAL_OBJECT_CAST (instance);
3750
3751 fundamental_object->refcount = 1;
3752 }
3753
3754 /**
3755 * RegressTestFundamentalObject: (ref-func regress_test_fundamental_object_ref) (unref-func regress_test_fundamental_object_unref) (set-value-func regress_test_value_set_fundamental_object) (get-value-func regress_test_value_get_fundamental_object)
3756 */
3757
3758 GType
3759 regress_test_fundamental_object_get_type (void)
3760 {
3761 static GType _test_fundamental_object_type = 0;
3762
3763 if (G_UNLIKELY (_test_fundamental_object_type == 0))
3764 {
3765 static const GTypeValueTable value_table = {
3766 regress_test_value_fundamental_object_init,
3767 regress_test_value_fundamental_object_free,
3768 regress_test_value_fundamental_object_copy,
3769 regress_test_value_fundamental_object_peek_pointer,
3770 (char *) "p",
3771 regress_test_value_fundamental_object_collect,
3772 (char *) "p",
3773 regress_test_value_fundamental_object_lcopy
3774 };
3775 static const GTypeInfo fundamental_object_info = {
3776 sizeof (RegressTestFundamentalObjectClass),
3777 NULL, NULL,
3778 regress_test_fundamental_object_class_init,
3779 NULL,
3780 NULL,
3781 sizeof (RegressTestFundamentalObject),
3782 0,
3783 (GInstanceInitFunc) regress_test_fundamental_object_init,
3784 &value_table
3785 };
3786 static const GTypeFundamentalInfo fundamental_object_fundamental_info = {
3787 (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE |
3788 G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE)
3789 };
3790
3791 _test_fundamental_object_type = g_type_fundamental_next ();
3792 g_type_register_fundamental (_test_fundamental_object_type, "RegressTestFundamentalObject",
3793 &fundamental_object_info, &fundamental_object_fundamental_info, G_TYPE_FLAG_ABSTRACT);
3794 }
3795
3796 return _test_fundamental_object_type;
3797 }
3798
3799 /**
3800 * regress_test_value_set_fundamental_object: (skip)
3801 * @value:
3802 * @fundamental_object:
3803 */
3804 void
3805 regress_test_value_set_fundamental_object (GValue *value, RegressTestFundamentalObject *fundamental_object)
3806 {
3807 gpointer *pointer_p;
3808
3809 g_return_if_fail (REGRESS_TEST_VALUE_HOLDS_FUNDAMENTAL_OBJECT (value));
3810 g_return_if_fail (fundamental_object == NULL || REGRESS_TEST_IS_FUNDAMENTAL_OBJECT (fundamental_object));
3811
3812 pointer_p = &value->data[0].v_pointer;
3813
3814 regress_test_fundamental_object_replace ((RegressTestFundamentalObject **) pointer_p, fundamental_object);
3815 }
3816
3817 /**
3818 * regress_test_value_get_fundamental_object: (skip)
3819 * @value:
3820 */
3821 RegressTestFundamentalObject *
3822 regress_test_value_get_fundamental_object (const GValue *value)
3823 {
3824 g_return_val_if_fail (REGRESS_TEST_VALUE_HOLDS_FUNDAMENTAL_OBJECT (value), NULL);
3825
3826 return value->data[0].v_pointer;
3827 }
3828
3829 static RegressTestFundamentalObjectClass *parent_class = NULL;
3830
3831 G_DEFINE_TYPE (RegressTestFundamentalSubObject, regress_test_fundamental_sub_object, REGRESS_TEST_TYPE_FUNDAMENTAL_OBJECT);
3832
3833 static RegressTestFundamentalSubObject *
3834 _regress_test_fundamental_sub_object_copy (RegressTestFundamentalSubObject *fundamental_sub_object)
3835 {
3836 RegressTestFundamentalSubObject *copy;
3837
3838 copy = regress_test_fundamental_sub_object_new (NULL);
3839 copy->data = g_strdup (fundamental_sub_object->data);
3840 return copy;
3841 }
3842
3843 static void
3844 regress_test_fundamental_sub_object_finalize (RegressTestFundamentalSubObject *fundamental_sub_object)
3845 {
3846 g_return_if_fail (fundamental_sub_object != NULL);
3847
3848 g_free (fundamental_sub_object->data);
3849 regress_test_fundamental_object_finalize (REGRESS_TEST_FUNDAMENTAL_OBJECT (fundamental_sub_object));
3850 }
3851
3852 static void
3853 regress_test_fundamental_sub_object_class_init (RegressTestFundamentalSubObjectClass *klass)
3854 {
3855 parent_class = g_type_class_peek_parent (klass);
3856
3857 klass->fundamental_object_class.copy = (RegressTestFundamentalObjectCopyFunction) _regress_test_fundamental_sub_object_copy;
3858 klass->fundamental_object_class.finalize =
3859 (RegressTestFundamentalObjectFinalizeFunction) regress_test_fundamental_sub_object_finalize;
3860 }
3861
3862 static void
3863 regress_test_fundamental_sub_object_init (RegressTestFundamentalSubObject *self G_GNUC_UNUSED)
3864 {
3865 }
3866
3867 /**
3868 * regress_test_fundamental_sub_object_new:
3869 */
3870 RegressTestFundamentalSubObject *
3871 regress_test_fundamental_sub_object_new (const char *data)
3872 {
3873 RegressTestFundamentalSubObject *object;
3874
3875 object = (RegressTestFundamentalSubObject *) g_type_create_instance (regress_test_fundamental_sub_object_get_type ());
3876 object->data = g_strdup (data);
3877 return object;
3878 }
3879
3880 /**/
3881
3882 #define regress_test_fundamental_hidden_sub_object_get_type \
3883 _regress_test_fundamental_hidden_sub_object_get_type
3884
3885 GType regress_test_fundamental_hidden_sub_object_get_type (void);
3886
3887 typedef struct _RegressTestFundamentalHiddenSubObject RegressTestFundamentalHiddenSubObject;
3888 typedef struct _GObjectClass RegressTestFundamentalHiddenSubObjectClass;
3889 struct _RegressTestFundamentalHiddenSubObject
3890 {
3891 RegressTestFundamentalObject parent_instance;
3892 };
3893
3894 G_DEFINE_TYPE (RegressTestFundamentalHiddenSubObject,
3895 regress_test_fundamental_hidden_sub_object,
3896 REGRESS_TEST_TYPE_FUNDAMENTAL_OBJECT);
3897
3898 static void
3899 regress_test_fundamental_hidden_sub_object_init (RegressTestFundamentalHiddenSubObject *self G_GNUC_UNUSED)
3900 {
3901 }
3902
3903 static void
3904 regress_test_fundamental_hidden_sub_object_class_init (RegressTestFundamentalHiddenSubObjectClass *klass G_GNUC_UNUSED)
3905 {
3906 }
3907
3908 /**
3909 * regress_test_create_fundamental_hidden_class_instance:
3910 *
3911 * Return value: (transfer full):
3912 */
3913 RegressTestFundamentalObject *
3914 regress_test_create_fundamental_hidden_class_instance (void)
3915 {
3916 return (RegressTestFundamentalObject *) g_type_create_instance (_regress_test_fundamental_hidden_sub_object_get_type ());
3917 }
3918
3919 /**
3920 * RegressTestFundamentalObjectNoGetSetFunc: (ref-func regress_test_fundamental_object_ref) (unref-func regress_test_fundamental_object_unref)
3921 *
3922 * Just like a #RegressTestFundamentalObject but without gvalue setter and getter
3923 */
3924
3925 static void
3926 regress_test_fundamental_object_no_get_set_func_finalize (RegressTestFundamentalObjectNoGetSetFunc *self)
3927 {
3928 g_clear_pointer (&self->data, g_free);
3929 }
3930
3931 static RegressTestFundamentalObjectNoGetSetFunc *
3932 regress_test_fundamental_object_no_get_set_func_copy (RegressTestFundamentalObjectNoGetSetFunc *self)
3933 {
3934 return regress_test_fundamental_object_no_get_set_func_new (self->data);
3935 }
3936
3937 static void
3938 regress_test_fundamental_object_no_get_set_func_class_init (gpointer g_class,
3939 gpointer class_data G_GNUC_UNUSED)
3940 {
3941 RegressTestFundamentalObjectClass *mo_class = (RegressTestFundamentalObjectClass *) (g_class);
3942
3943 mo_class->copy = (RegressTestFundamentalObjectCopyFunction) regress_test_fundamental_object_no_get_set_func_copy;
3944 mo_class->finalize = (RegressTestFundamentalObjectFinalizeFunction) regress_test_fundamental_object_no_get_set_func_finalize;
3945 }
3946
3947 static void
3948 regress_test_fundamental_object_no_get_set_func_init (GTypeInstance *instance,
3949 gpointer klass G_GNUC_UNUSED)
3950 {
3951 RegressTestFundamentalObject *object = (RegressTestFundamentalObject *) (instance);
3952 object->refcount = 1;
3953 }
3954
3955 GType
3956 regress_test_fundamental_object_no_get_set_func_get_type (void)
3957 {
3958 static GType _test_fundamental_object_type = 0;
3959
3960 if (G_UNLIKELY (_test_fundamental_object_type == 0))
3961 {
3962 static const GTypeValueTable value_table = {
3963 regress_test_value_fundamental_object_init,
3964 regress_test_value_fundamental_object_free,
3965 regress_test_value_fundamental_object_copy,
3966 regress_test_value_fundamental_object_peek_pointer,
3967 (char *) "p",
3968 regress_test_value_fundamental_object_collect,
3969 (char *) "p",
3970 regress_test_value_fundamental_object_lcopy
3971 };
3972 static const GTypeInfo fundamental_object_info = {
3973 sizeof (RegressTestFundamentalObjectNoGetSetFuncClass),
3974 NULL, NULL,
3975 regress_test_fundamental_object_no_get_set_func_class_init,
3976 NULL,
3977 NULL,
3978 sizeof (RegressTestFundamentalObjectNoGetSetFunc),
3979 0,
3980 (GInstanceInitFunc) regress_test_fundamental_object_no_get_set_func_init,
3981 &value_table
3982 };
3983 static const GTypeFundamentalInfo fundamental_object_fundamental_info = {
3984 (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE |
3985 G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE)
3986 };
3987
3988 _test_fundamental_object_type = g_type_fundamental_next ();
3989 g_type_register_fundamental (_test_fundamental_object_type, "RegressTestFundamentalObjectNoGetSetFunc",
3990 &fundamental_object_info, &fundamental_object_fundamental_info, 0);
3991 }
3992
3993 return _test_fundamental_object_type;
3994 }
3995
3996 /**
3997 * regress_test_fundamental_object_no_get_set_func_new:
3998 *
3999 * Return value: (transfer full):
4000 */
4001 RegressTestFundamentalObjectNoGetSetFunc *
4002 regress_test_fundamental_object_no_get_set_func_new (const char *data)
4003 {
4004 RegressTestFundamentalObjectNoGetSetFunc *object;
4005
4006 object = (RegressTestFundamentalObjectNoGetSetFunc *) g_type_create_instance (regress_test_fundamental_object_no_get_set_func_get_type ());
4007 object->data = g_strdup (data);
4008
4009 return object;
4010 }
4011
4012 const char *
4013 regress_test_fundamental_object_no_get_set_func_get_data (RegressTestFundamentalObjectNoGetSetFunc *fundamental)
4014 {
4015 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (fundamental, regress_test_fundamental_object_no_get_set_func_get_type ()), NULL);
4016
4017 return fundamental->data;
4018 }
4019
4020 G_DEFINE_TYPE (RegressTestFundamentalSubObjectNoGetSetFunc, regress_test_fundamental_sub_object_no_get_set_func, regress_test_fundamental_object_no_get_set_func_get_type ());
4021
4022 static void
4023 regress_test_fundamental_sub_object_no_get_set_func_class_init (RegressTestFundamentalSubObjectNoGetSetFuncClass *klass G_GNUC_UNUSED)
4024 {
4025 }
4026
4027 static void
4028 regress_test_fundamental_sub_object_no_get_set_func_init (RegressTestFundamentalSubObjectNoGetSetFunc *self G_GNUC_UNUSED)
4029 {
4030 }
4031
4032 /**
4033 * regress_test_fundamental_sub_object_no_get_set_func_new:
4034 *
4035 * Return value: (transfer full):
4036 */
4037 RegressTestFundamentalSubObjectNoGetSetFunc *
4038 regress_test_fundamental_sub_object_no_get_set_func_new (const char *data)
4039 {
4040 RegressTestFundamentalSubObjectNoGetSetFunc *object;
4041 RegressTestFundamentalObjectNoGetSetFunc *parent_object;
4042
4043 object = (RegressTestFundamentalSubObjectNoGetSetFunc *) g_type_create_instance (regress_test_fundamental_sub_object_no_get_set_func_get_type ());
4044 parent_object = (RegressTestFundamentalObjectNoGetSetFunc *) object;
4045 parent_object->data = g_strdup (data);
4046
4047 return object;
4048 }
4049
4050 static void
4051 fundamental_object_no_get_set_func_transform_to_compatible_with_fundamental_sub_object (const GValue *src_value,
4052 GValue *dest_value)
4053 {
4054 RegressTestFundamentalObjectNoGetSetFunc *src_object;
4055 RegressTestFundamentalSubObject *dest_object;
4056
4057 g_return_if_fail (G_VALUE_TYPE (src_value) == regress_test_fundamental_object_no_get_set_func_get_type ());
4058 g_return_if_fail (G_VALUE_TYPE (dest_value) == regress_test_fundamental_sub_object_get_type ());
4059
4060 src_object = g_value_peek_pointer (src_value);
4061 dest_object = regress_test_fundamental_sub_object_new (src_object->data);
4062
4063 g_value_set_instance (dest_value, dest_object);
4064 regress_test_fundamental_object_unref ((RegressTestFundamentalObject *) dest_object);
4065 }
4066
4067 void
4068 regress_test_fundamental_object_no_get_set_func_make_compatible_with_fundamental_sub_object (void)
4069 {
4070 g_value_register_transform_func (
4071 regress_test_fundamental_object_no_get_set_func_get_type (),
4072 regress_test_fundamental_sub_object_get_type (),
4073 fundamental_object_no_get_set_func_transform_to_compatible_with_fundamental_sub_object);
4074 }
4075
4076 /**
4077 * regress_test_callback:
4078 * @callback: (scope call) (allow-none):
4079 *
4080 **/
4081 int
4082 regress_test_callback (RegressTestCallback callback)
4083 {
4084 if (callback != NULL)
4085 return callback ();
4086 return 0;
4087 }
4088
4089 /**
4090 * regress_test_multi_callback:
4091 * @callback: (scope call) (allow-none):
4092 *
4093 **/
4094 int
4095 regress_test_multi_callback (RegressTestCallback callback)
4096 {
4097 int sum = 0;
4098 if (callback != NULL)
4099 {
4100 sum += callback ();
4101 sum += callback ();
4102 }
4103
4104 return sum;
4105 }
4106
4107 /**
4108 * regress_test_array_callback:
4109 * @callback: (scope call):
4110 *
4111 **/
4112 int
4113 regress_test_array_callback (RegressTestCallbackArray callback)
4114 {
4115 static const char *strings[] = { "one", "two", "three" };
4116 static int ints[] = { -1, 0, 1, 2 };
4117 int sum = 0;
4118
4119 sum += callback (ints, 4, strings, 3);
4120 sum += callback (ints, 4, strings, 3);
4121
4122 return sum;
4123 }
4124
4125 /**
4126 * regress_test_array_inout_callback:
4127 * @callback: (scope call):
4128 *
4129 */
4130 int
4131 regress_test_array_inout_callback (RegressTestCallbackArrayInOut callback)
4132 {
4133 int *ints;
4134 int length;
4135
4136 ints = g_new (int, 5);
4137 for (length = 0; length < 5; ++length)
4138 ints[length] = length - 2;
4139
4140 callback (&ints, &length);
4141
4142 g_assert_cmpint (length, ==, 4);
4143 for (length = 0; length < 4; ++length)
4144 g_assert_cmpint (ints[length], ==, length - 1);
4145
4146 callback (&ints, &length);
4147
4148 g_assert_cmpint (length, ==, 3);
4149 for (length = 0; length < 3; ++length)
4150 g_assert_cmpint (ints[length], ==, length);
4151
4152 g_free (ints);
4153 return length;
4154 }
4155
4156 /**
4157 * regress_test_simple_callback:
4158 * @callback: (scope call) (allow-none):
4159 *
4160 **/
4161 void
4162 regress_test_simple_callback (RegressTestSimpleCallback callback)
4163 {
4164 if (callback != NULL)
4165 callback ();
4166
4167 return;
4168 }
4169
4170 /**
4171 * regress_test_noptr_callback:
4172 * @callback: (scope call) (allow-none):
4173 *
4174 **/
4175 void
4176 regress_test_noptr_callback (RegressTestNoPtrCallback callback)
4177 {
4178 if (callback != NULL)
4179 callback ();
4180
4181 return;
4182 }
4183
4184 /**
4185 * regress_test_callback_user_data:
4186 * @callback: (scope call):
4187 * @user_data: (not nullable):
4188 *
4189 * Call - callback parameter persists for the duration of the method
4190 * call and can be released on return.
4191 **/
4192 int
4193 regress_test_callback_user_data (RegressTestCallbackUserData callback,
4194 gpointer user_data)
4195 {
4196 return callback (user_data);
4197 }
4198
4199 /**
4200 * regress_test_callback_return_full:
4201 * @callback: (scope call):
4202 *
4203 **/
4204 void
4205 regress_test_callback_return_full (RegressTestCallbackReturnFull callback)
4206 {
4207 RegressTestObj *obj;
4208
4209 obj = callback ();
4210 g_object_unref (obj);
4211 }
4212
4213 static GSList *notified_callbacks = NULL;
4214
4215 /**
4216 * regress_test_callback_destroy_notify:
4217 * @callback: (scope notified):
4218 *
4219 * Notified - callback persists until a DestroyNotify delegate
4220 * is invoked.
4221 **/
4222 int
4223 regress_test_callback_destroy_notify (RegressTestCallbackUserData callback,
4224 gpointer user_data,
4225 GDestroyNotify notify)
4226 {
4227 int retval;
4228 CallbackInfo *info;
4229
4230 retval = callback (user_data);
4231
4232 info = g_slice_new (CallbackInfo);
4233 info->callback = callback;
4234 info->notify = notify;
4235 info->user_data = user_data;
4236
4237 notified_callbacks = g_slist_prepend (notified_callbacks, info);
4238
4239 return retval;
4240 }
4241
4242 /**
4243 * regress_test_callback_destroy_notify_no_user_data:
4244 * @callback: (scope notified):
4245 *
4246 * Adds a scope notified callback with no user data. This can invoke an error
4247 * condition in bindings which needs to be tested.
4248 **/
4249 int
4250 regress_test_callback_destroy_notify_no_user_data (RegressTestCallbackUserData callback,
4251 GDestroyNotify notify)
4252 {
4253 return regress_test_callback_destroy_notify (callback, NULL, notify);
4254 }
4255
4256 /**
4257 * regress_test_callback_thaw_notifications:
4258 *
4259 * Invokes all callbacks installed by #test_callback_destroy_notify(),
4260 * adding up their return values, and removes them, invoking the
4261 * corresponding destroy notfications.
4262 *
4263 * Return value: Sum of the return values of the invoked callbacks.
4264 */
4265 int
4266 regress_test_callback_thaw_notifications (void)
4267 {
4268 int retval = 0;
4269 GSList *node;
4270
4271 for (node = notified_callbacks; node != NULL; node = node->next)
4272 {
4273 CallbackInfo *info = node->data;
4274 retval += info->callback (info->user_data);
4275 if (info->notify)
4276 info->notify (info->user_data);
4277 g_slice_free (CallbackInfo, info);
4278 }
4279
4280 g_slist_free (notified_callbacks);
4281 notified_callbacks = NULL;
4282
4283 return retval;
4284 }
4285
4286 static GSList *async_callbacks = NULL;
4287
4288 /**
4289 * regress_test_callback_async:
4290 * @callback: (scope async):
4291 *
4292 **/
4293 void
4294 regress_test_callback_async (RegressTestCallbackUserData callback,
4295 gpointer user_data)
4296 {
4297 CallbackInfo *info;
4298
4299 info = g_slice_new (CallbackInfo);
4300 info->callback = callback;
4301 info->user_data = user_data;
4302
4303 async_callbacks = g_slist_prepend (async_callbacks, info);
4304 }
4305
4306 /**
4307 * regress_test_callback_thaw_async:
4308 */
4309 int
4310 regress_test_callback_thaw_async (void)
4311 {
4312 int retval = 0;
4313 GSList *node;
4314
4315 for (node = async_callbacks; node != NULL; node = node->next)
4316 {
4317 CallbackInfo *info = node->data;
4318 retval = info->callback (info->user_data);
4319 g_slice_free (CallbackInfo, info);
4320 }
4321
4322 g_slist_free (async_callbacks);
4323 async_callbacks = NULL;
4324 return retval;
4325 }
4326
4327 void
4328 regress_test_async_ready_callback (GAsyncReadyCallback callback)
4329 {
4330 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
4331 GSimpleAsyncResult *result = g_simple_async_result_new (NULL, callback, NULL,
4332 regress_test_async_ready_callback);
4333 g_simple_async_result_complete_in_idle (result);
4334 g_object_unref (result);
4335 G_GNUC_END_IGNORE_DEPRECATIONS
4336 }
4337
4338 static GSList *async_function_tasks;
4339
4340 /**
4341 * regress_test_function_async:
4342 *
4343 */
4344 void
4345 regress_test_function_async (int io_priority G_GNUC_UNUSED,
4346 GCancellable *cancellable,
4347 GAsyncReadyCallback callback,
4348 gpointer user_data)
4349 {
4350 GTask *task = g_task_new (NULL, cancellable, callback, user_data);
4351
4352 async_function_tasks = g_slist_prepend (async_function_tasks, task);
4353 }
4354
4355 /**
4356 * regress_test_function_thaw_async:
4357 *
4358 * Returns: the number of callbacks that were thawed.
4359 */
4360 int
4361 regress_test_function_thaw_async (void)
4362 {
4363 int retval = 0;
4364 GSList *node;
4365
4366 for (node = async_function_tasks; node != NULL; node = node->next)
4367 {
4368 GTask *task = node->data;
4369 g_task_return_boolean (task, TRUE);
4370 g_object_unref (task);
4371 retval++;
4372 }
4373
4374 g_slist_free (async_function_tasks);
4375 async_function_tasks = NULL;
4376 return retval;
4377 }
4378
4379 /**
4380 * regress_test_function_finish:
4381 *
4382 */
4383 gboolean
4384 regress_test_function_finish (GAsyncResult *res, GError **error)
4385 {
4386 return g_task_propagate_boolean (G_TASK(res), error);
4387 }
4388
4389 /**
4390 * regress_test_function_sync:
4391 *
4392 */
4393 gboolean
4394 regress_test_function_sync (int io_priority G_GNUC_UNUSED)
4395 {
4396 return TRUE;
4397 }
4398
4399 /**
4400 * regress_test_obj_instance_method_callback:
4401 * @callback: (scope call) (allow-none):
4402 *
4403 **/
4404 void
4405 regress_test_obj_instance_method_callback (RegressTestObj *self G_GNUC_UNUSED,
4406 RegressTestCallback callback)
4407 {
4408 if (callback != NULL)
4409 callback ();
4410 }
4411
4412 /**
4413 * regress_test_obj_static_method_callback:
4414 * @callback: (scope call) (allow-none):
4415 *
4416 **/
4417 void
4418 regress_test_obj_static_method_callback (RegressTestCallback callback)
4419 {
4420 if (callback != NULL)
4421 callback ();
4422 }
4423
4424 /**
4425 * regress_test_obj_new_callback:
4426 * @callback: (scope notified):
4427 **/
4428 RegressTestObj *
4429 regress_test_obj_new_callback (RegressTestCallbackUserData callback, gpointer user_data, GDestroyNotify notify)
4430 {
4431 CallbackInfo *info;
4432
4433 callback (user_data);
4434
4435 info = g_slice_new (CallbackInfo);
4436 info->callback = callback;
4437 info->notify = notify;
4438 info->user_data = user_data;
4439
4440 notified_callbacks = g_slist_prepend (notified_callbacks, info);
4441
4442 return g_object_new (REGRESS_TEST_TYPE_OBJ, NULL);
4443 }
4444
4445 static GSList *async_constructor_tasks;
4446
4447 /**
4448 * regress_test_obj_new_async:
4449 *
4450 */
4451 void
4452 regress_test_obj_new_async (const char *x G_GNUC_UNUSED,
4453 GCancellable *cancellable,
4454 GAsyncReadyCallback callback,
4455 gpointer user_data)
4456 {
4457 GTask *task = g_task_new (NULL, cancellable, callback, user_data);
4458
4459 async_constructor_tasks = g_slist_prepend (async_constructor_tasks, task);
4460 }
4461
4462 /**
4463 * regress_test_obj_constructor_thaw_async:
4464 *
4465 * Returns: the number of callbacks that were thawed.
4466 */
4467 int
4468 regress_test_obj_constructor_thaw_async (void)
4469 {
4470 int retval = 0;
4471 GSList *node;
4472
4473 for (node = async_constructor_tasks; node != NULL; node = node->next)
4474 {
4475 GTask *task = node->data;
4476 RegressTestObj *obj = g_object_new (REGRESS_TEST_TYPE_OBJ, NULL);
4477 g_task_return_pointer (task, obj, g_object_unref);
4478 g_object_unref (task);
4479 retval++;
4480 }
4481
4482 g_slist_free (async_constructor_tasks);
4483 async_constructor_tasks = NULL;
4484 return retval;
4485 }
4486
4487 /**
4488 * regress_test_obj_new_finish:
4489 *
4490 */
4491 RegressTestObj *
4492 regress_test_obj_new_finish (GAsyncResult *res, GError **error)
4493 {
4494 return g_task_propagate_pointer (G_TASK (res), error);
4495 }
4496
4497 /**
4498 * regress_test_hash_table_callback:
4499 * @data: (element-type utf8 gint): GHashTable that gets passed to callback
4500 * @callback: (scope call):
4501 **/
4502 void
4503 regress_test_hash_table_callback (GHashTable *data, RegressTestCallbackHashtable callback)
4504 {
4505 callback (data);
4506 }
4507
4508 /**
4509 * regress_test_gerror_callback:
4510 * @callback: (scope call):
4511 **/
4512 void
4513 regress_test_gerror_callback (RegressTestCallbackGError callback)
4514 {
4515 GError *error;
4516
4517 error = g_error_new_literal (G_IO_ERROR,
4518 G_IO_ERROR_NOT_SUPPORTED,
4519 "regression test error");
4520 callback (error);
4521 g_error_free (error);
4522 }
4523
4524 /**
4525 * regress_test_null_gerror_callback:
4526 * @callback: (scope call):
4527 **/
4528 void
4529 regress_test_null_gerror_callback (RegressTestCallbackGError callback)
4530 {
4531 callback (NULL);
4532 }
4533
4534 /**
4535 * regress_test_owned_gerror_callback:
4536 * @callback: (scope call):
4537 **/
4538 void
4539 regress_test_owned_gerror_callback (RegressTestCallbackOwnedGError callback)
4540 {
4541 GError *error;
4542
4543 error = g_error_new_literal (G_IO_ERROR,
4544 G_IO_ERROR_PERMISSION_DENIED,
4545 "regression test owned error");
4546 callback (error);
4547 }
4548
4549 /**
4550 * regress_test_skip_unannotated_callback: (skip)
4551 * @callback: No annotation here
4552 *
4553 * Should not emit a warning:
4554 * https://bugzilla.gnome.org/show_bug.cgi?id=685399
4555 */
4556 void
4557 regress_test_skip_unannotated_callback (RegressTestCallback callback G_GNUC_UNUSED)
4558 {
4559 }
4560
4561 /* interface */
4562
4563 typedef RegressTestInterfaceIface RegressTestInterfaceInterface;
4564 G_DEFINE_INTERFACE (RegressTestInterface, regress_test_interface, G_TYPE_OBJECT)
4565
4566 static void
4567 regress_test_interface_default_init (RegressTestInterfaceIface *iface)
4568 {
4569 const guint flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS;
4570 static gboolean initialized = FALSE;
4571 if (initialized)
4572 return;
4573
4574 /**
4575 * RegressTestInterface::interface-signal:
4576 * @self: the object which emitted the signal
4577 * @ptr: (type int): the code must look up the signal with
4578 * g_interface_info_find_signal() in order to get this to work.
4579 */
4580 g_signal_new ("interface-signal", REGRESS_TEST_TYPE_INTERFACE,
4581 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL,
4582 G_TYPE_NONE, 1, G_TYPE_POINTER);
4583
4584 /**
4585 * RegressTestInterface:number:
4586 */
4587 g_object_interface_install_property (iface,
4588 g_param_spec_int ("number", "Number", "Number",
4589 0, 10, 0, flags));
4590
4591 initialized = TRUE;
4592 }
4593
4594 /**
4595 * regress_test_interface_emit_signal:
4596 * @self: the object to emit the signal
4597 */
4598 void
4599 regress_test_interface_emit_signal (RegressTestInterface *self)
4600 {
4601 g_signal_emit_by_name (self, "interface-signal", NULL);
4602 }
4603
4604 /* gobject with non-standard prefix */
4605 G_DEFINE_TYPE (RegressTestWi8021x, regress_test_wi_802_1x, G_TYPE_OBJECT);
4606
4607 enum
4608 {
4609 PROP_TEST_WI_802_1X_TESTBOOL = 1
4610 };
4611
4612 static void
4613 regress_test_wi_802_1x_set_property (GObject *object,
4614 guint property_id,
4615 const GValue *value,
4616 GParamSpec *pspec)
4617 {
4618 RegressTestWi8021x *self = REGRESS_TEST_WI_802_1X (object);
4619
4620 switch (property_id)
4621 {
4622 case PROP_TEST_WI_802_1X_TESTBOOL:
4623 regress_test_wi_802_1x_set_testbool (self, g_value_get_boolean (value));
4624 break;
4625
4626 default:
4627 /* We don't have any other property... */
4628 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
4629 break;
4630 }
4631 }
4632
4633 static void
4634 regress_test_wi_802_1x_get_property (GObject *object,
4635 guint property_id,
4636 GValue *value,
4637 GParamSpec *pspec)
4638 {
4639 RegressTestWi8021x *self = REGRESS_TEST_WI_802_1X (object);
4640
4641 switch (property_id)
4642 {
4643 case PROP_TEST_WI_802_1X_TESTBOOL:
4644 g_value_set_boolean (value, regress_test_wi_802_1x_get_testbool (self));
4645 break;
4646
4647 default:
4648 /* We don't have any other property... */
4649 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
4650 break;
4651 }
4652 }
4653
4654 static void
4655 regress_test_wi_802_1x_dispose (GObject *gobject)
4656 {
4657 /* Chain up to the parent class */
4658 G_OBJECT_CLASS (regress_test_wi_802_1x_parent_class)->dispose (gobject);
4659 }
4660
4661 static void
4662 regress_test_wi_802_1x_class_init (RegressTestWi8021xClass *klass)
4663 {
4664 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
4665 GParamSpec *pspec;
4666
4667 gobject_class->set_property = regress_test_wi_802_1x_set_property;
4668 gobject_class->get_property = regress_test_wi_802_1x_get_property;
4669 gobject_class->dispose = regress_test_wi_802_1x_dispose;
4670
4671 pspec = g_param_spec_boolean ("testbool",
4672 "Nick for testbool",
4673 "Blurb for testbool",
4674 TRUE,
4675 G_PARAM_READWRITE);
4676 g_object_class_install_property (gobject_class,
4677 PROP_TEST_WI_802_1X_TESTBOOL,
4678 pspec);
4679 }
4680
4681 static void
4682 regress_test_wi_802_1x_init (RegressTestWi8021x *obj)
4683 {
4684 obj->testbool = TRUE;
4685 }
4686
4687 RegressTestWi8021x *
4688 regress_test_wi_802_1x_new (void)
4689 {
4690 return g_object_new (REGRESS_TEST_TYPE_WI_802_1X, NULL);
4691 }
4692
4693 void
4694 regress_test_wi_802_1x_set_testbool (RegressTestWi8021x *obj, gboolean val)
4695 {
4696 obj->testbool = val;
4697 }
4698
4699 gboolean
4700 regress_test_wi_802_1x_get_testbool (RegressTestWi8021x *obj)
4701 {
4702 return obj->testbool;
4703 }
4704
4705 int
4706 regress_test_wi_802_1x_static_method (int x)
4707 {
4708 return 2 * x;
4709 }
4710
4711 /* floating gobject */
4712 G_DEFINE_TYPE (RegressTestFloating, regress_test_floating, G_TYPE_INITIALLY_UNOWNED);
4713
4714 static void
4715 regress_test_floating_finalize (GObject *object)
4716 {
4717 g_assert (!g_object_is_floating (object));
4718
4719 G_OBJECT_CLASS (regress_test_floating_parent_class)->finalize (object);
4720 }
4721
4722 static void
4723 regress_test_floating_class_init (RegressTestFloatingClass *klass)
4724 {
4725 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
4726 gobject_class->finalize = regress_test_floating_finalize;
4727 }
4728
4729 static void
4730 regress_test_floating_init (RegressTestFloating *self G_GNUC_UNUSED)
4731 {
4732 }
4733
4734 /**
4735 * regress_test_floating_new:
4736 *
4737 * Returns:: A new floating #RegressTestFloating
4738 */
4739 RegressTestFloating *
4740 regress_test_floating_new (void)
4741 {
4742 return g_object_new (REGRESS_TEST_TYPE_FLOATING, NULL);
4743 }
4744
4745 /**
4746 * regress_test_torture_signature_0:
4747 * @x:
4748 * @y: (out):
4749 * @z: (out):
4750 * @foo:
4751 * @q: (out):
4752 * @m:
4753 *
4754 */
4755 void
4756 regress_test_torture_signature_0 (int x,
4757 double *y,
4758 int *z,
4759 const char *foo,
4760 int *q,
4761 guint m)
4762 {
4763 *y = x;
4764 *z = x * 2;
4765 *q = g_utf8_strlen (foo, -1) + m;
4766 }
4767
4768 /**
4769 * regress_test_torture_signature_1:
4770 * @x:
4771 * @y: (out):
4772 * @z: (out):
4773 * @foo:
4774 * @q: (out):
4775 * @m:
4776 * @error: A #GError
4777 *
4778 * This function throws an error if m is odd.
4779 */
4780 gboolean
4781 regress_test_torture_signature_1 (int x,
4782 double *y,
4783 int *z,
4784 const char *foo,
4785 int *q,
4786 guint m,
4787 GError **error)
4788 {
4789 *y = x;
4790 *z = x * 2;
4791 *q = g_utf8_strlen (foo, -1) + m;
4792 if (m % 2 == 0)
4793 return TRUE;
4794 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "m is odd");
4795 return FALSE;
4796 }
4797
4798 /**
4799 * regress_test_torture_signature_2:
4800 * @x:
4801 * @callback:
4802 * @user_data:
4803 * @notify:
4804 * @y: (out):
4805 * @z: (out):
4806 * @foo:
4807 * @q: (out):
4808 * @m:
4809 *
4810 */
4811 void
4812 regress_test_torture_signature_2 (int x,
4813 RegressTestCallbackUserData callback,
4814 gpointer user_data,
4815 GDestroyNotify notify,
4816 double *y,
4817 int *z,
4818 const char *foo,
4819 int *q,
4820 guint m)
4821 {
4822 *y = x;
4823 *z = x * 2;
4824 *q = g_utf8_strlen (foo, -1) + m;
4825 callback (user_data);
4826 notify (user_data);
4827 }
4828
4829 /**
4830 * regress_test_date_in_gvalue:
4831 *
4832 * Returns: (transfer full):
4833 */
4834 GValue *
4835 regress_test_date_in_gvalue (void)
4836 {
4837 GValue *value = g_new0 (GValue, 1);
4838 GDate *date = g_date_new_dmy (5, 12, 1984);
4839
4840 g_value_init (value, G_TYPE_DATE);
4841 g_value_take_boxed (value, date);
4842
4843 return value;
4844 }
4845
4846 /**
4847 * regress_test_strv_in_gvalue:
4848 *
4849 * Returns: (transfer full):
4850 */
4851 GValue *
4852 regress_test_strv_in_gvalue (void)
4853 {
4854 GValue *value = g_new0 (GValue, 1);
4855 const char *strv[] = { "one", "two", "three", NULL };
4856
4857 g_value_init (value, G_TYPE_STRV);
4858 g_value_set_boxed (value, strv);
4859
4860 return value;
4861 }
4862
4863 /**
4864 * regress_test_null_strv_in_gvalue:
4865 *
4866 * Returns: (transfer full):
4867 */
4868 GValue *
4869 regress_test_null_strv_in_gvalue (void)
4870 {
4871 GValue *value = g_new0 (GValue, 1);
4872 const char **strv = NULL;
4873
4874 g_value_init (value, G_TYPE_STRV);
4875 g_value_set_boxed (value, strv);
4876
4877 return value;
4878 }
4879
4880 /**
4881 * regress_test_multiline_doc_comments:
4882 *
4883 * This is a function.
4884 *
4885 * It has multiple lines in the documentation.
4886 *
4887 * The sky is blue.
4888 *
4889 * You will give me your credit card number.
4890 */
4891 void
4892 regress_test_multiline_doc_comments (void)
4893 {
4894 }
4895
4896 /**
4897 * regress_test_nested_parameter:
4898 * @a: An integer
4899 *
4900 * <informaltable>
4901 * <tgroup cols="3">
4902 * <thead>
4903 * <row>
4904 * <entry>Syntax</entry>
4905 * <entry>Explanation</entry>
4906 * <entry>Examples</entry>
4907 * </row>
4908 * </thead>
4909 * <tbody>
4910 * <row>
4911 * <entry>rgb(@r, @g, @b)</entry>
4912 * <entry>An opaque color; @r, @g, @b can be either integers between
4913 * 0 and 255 or percentages</entry>
4914 * <entry><literallayout>rgb(128, 10, 54)
4915 * rgb(20%, 30%, 0%)</literallayout></entry>
4916 * </row>
4917 * <row>
4918 * <entry>rgba(@r, @g, @b, @a)</entry>
4919 * <entry>A translucent color; @r, @g, @b are as in the previous row,
4920 * @a is a floating point number between 0 and 1</entry>
4921 * <entry><literallayout>rgba(255, 255, 0, 0.5)</literallayout></entry>
4922 * </row>
4923 * </tbody>
4924 * </tgroup>
4925 * </informaltable>
4926 *
4927 * What we're testing here is that the scanner ignores the @a nested inside XML.
4928 */
4929 void
4930 regress_test_nested_parameter (int a G_GNUC_UNUSED)
4931 {
4932 }
4933
4934 /**
4935 * regress_introspectable_via_alias:
4936 *
4937 */
4938 void
4939 regress_introspectable_via_alias (RegressPtrArrayAlias *data G_GNUC_UNUSED)
4940 {
4941 }
4942
4943 /**
4944 * regress_not_introspectable_via_alias:
4945 *
4946 */
4947 void
4948 regress_not_introspectable_via_alias (RegressVaListAlias ok G_GNUC_UNUSED)
4949 {
4950 }
4951
4952 /**
4953 * regress_aliased_caller_alloc:
4954 * @boxed: (out):
4955 */
4956 void
4957 regress_aliased_caller_alloc (RegressAliasedTestBoxed *boxed)
4958 {
4959 boxed->priv = g_slice_new0 (RegressTestBoxedPrivate);
4960 boxed->priv->magic = 0xdeadbeef;
4961 }
4962
4963 void
4964 regress_test_struct_fixed_array_frob (RegressTestStructFixedArray *str)
4965 {
4966 guint i;
4967 str->just_int = 7;
4968
4969 for (i = 0; i < G_N_ELEMENTS (str->array); i++)
4970 str->array[i] = 42 + i;
4971 }
4972
4973 /**
4974 * regress_has_parameter_named_attrs:
4975 * @foo: some int
4976 * @attributes: (type guint32) (array fixed-size=32): list of attributes
4977 *
4978 * This test case mirrors GnomeKeyringPasswordSchema from
4979 * libgnome-keyring.
4980 */
4981 void
4982 regress_has_parameter_named_attrs (int foo G_GNUC_UNUSED,
4983 gpointer attributes G_GNUC_UNUSED)
4984 {
4985 }
4986
4987 /**
4988 * regress_test_versioning:
4989 *
4990 * Since: 1.32.1: Actually, this function was introduced earlier
4991 * than this, but it didn't do anything before this version.
4992 * Deprecated: 1.33.3: This function has been deprecated,
4993 * because it sucks. Use foobar instead.
4994 * Stability: Unstable: Maybe someday we will find the time
4995 * to stabilize this function. Who knows?
4996 */
4997 void
4998 regress_test_versioning (void)
4999 {
5000 }
5001
5002 void
5003 regress_like_xkl_config_item_set_name (RegressLikeXklConfigItem *self,
5004 char const *name)
5005 {
5006 strncpy (self->name, name, sizeof (self->name) - 1);
5007 self->name[sizeof (self->name) - 1] = '\0';
5008 }
5009
5010 /**
5011 * regress_get_variant:
5012 *
5013 * Returns: (transfer floating): A new variant
5014 */
5015 GVariant *
5016 regress_get_variant (void)
5017 {
5018 return g_variant_new_int32 (42);
5019 }
5020
5021 /**
5022 * regress_test_array_struct_out_none:
5023 * @arr: (out) (array length=len) (transfer none): An array
5024 * @len: (out): Length of @arr
5025 *
5026 * Test flat array output with transfer none.
5027 *
5028 * Similar to:
5029 * - mm_modem_peek_ports() with structs
5030 * - gdk_query_visual_types() with enums
5031 * - gdk_event_get_axes() with doubles
5032 */
5033 void
5034 regress_test_array_struct_out_none (RegressTestStructA **arr, gsize *len)
5035 {
5036 static RegressTestStructA array[3] = {
5037 { .some_int = 111 },
5038 { .some_int = 222 },
5039 { .some_int = 333 },
5040 };
5041
5042 *arr = array;
5043 *len = 3;
5044 }
5045
5046 /**
5047 * regress_test_array_struct_out_container:
5048 * @arr: (out) (array length=len) (transfer container): An array
5049 * @len: (out): Length of @arr
5050 *
5051 * Test flat array output with transfer container.
5052 *
5053 * Similar to pango_layout_get_log_attrs().
5054 */
5055 void
5056 regress_test_array_struct_out_container (RegressTestStructA **arr, gsize *len)
5057 {
5058
5059 *arr = g_new0 (RegressTestStructA, 5);
5060 (*arr)[0].some_int = 11;
5061 (*arr)[1].some_int = 13;
5062 (*arr)[2].some_int = 17;
5063 (*arr)[3].some_int = 19;
5064 (*arr)[4].some_int = 23;
5065 *len = 5;
5066 }
5067
5068 /**
5069 * regress_test_array_struct_out_full_fixed:
5070 * @arr: (out) (array fixed-size=4) (transfer full): An array
5071 *
5072 * Test flat fixed-size array output with transfer full.
5073 */
5074 void
5075 regress_test_array_struct_out_full_fixed (RegressTestStructA **arr)
5076 {
5077 *arr = g_new0 (RegressTestStructA, 4);
5078 (*arr)[0].some_int = 2;
5079 (*arr)[1].some_int = 3;
5080 (*arr)[2].some_int = 5;
5081 (*arr)[3].some_int = 7;
5082 }
5083
5084 /**
5085 * regress_test_array_struct_out_caller_alloc:
5086 * @arr: (out caller-allocates) (array length=len): An array
5087 * @len: Length of @arr
5088 *
5089 * Test flat caller-allocated array output.
5090 *
5091 * Similar to g_main_context_query().
5092 */
5093 void
5094 regress_test_array_struct_out_caller_alloc (RegressTestStructA *arr, gsize len)
5095 {
5096 guint i;
5097
5098 g_assert (arr != NULL);
5099
5100 memset (arr, 0, sizeof (RegressTestStructA) * len);
5101 for (i = 0; i != len; ++i)
5102 arr[i].some_int = 111 * (i + 1);
5103 }
5104
5105 /**
5106 * regress_test_array_struct_in_full:
5107 * @arr: (in) (array length=len) (transfer full): An array
5108 * @len: Length of @arr
5109 *
5110 * Test flat array input with transfer full.
5111 *
5112 * Similar to:
5113 * - gsf_property_settings_free() with structs but they contain pointers
5114 * - g_byte_array_new_take() with guint8s
5115 */
5116 void
5117 regress_test_array_struct_in_full (RegressTestStructA *arr, gsize len)
5118 {
5119 g_assert_cmpint (len, ==, 2);
5120 g_assert_cmpint (arr[0].some_int, ==, 201);
5121 g_assert_cmpint (arr[1].some_int, ==, 202);
5122 g_free (arr);
5123 }
5124
5125 /**
5126 * regress_test_array_struct_in_none:
5127 * @arr: (in) (array length=len) (transfer none): An array.
5128 * @len: Length of @arr
5129 *
5130 * Test flat array input with transfer none.
5131 *
5132 * Similar to g_main_context_check() or gtk_target_list_new().
5133 */
5134 void
5135 regress_test_array_struct_in_none (RegressTestStructA *arr, gsize len)
5136 {
5137 g_assert_cmpint (len, ==, 3);
5138 g_assert_cmpint (arr[0].some_int, ==, 301);
5139 g_assert_cmpint (arr[1].some_int, ==, 302);
5140 g_assert_cmpint (arr[2].some_int, ==, 303);
5141 }
5142
5143 static GSList *async_method_tasks;
5144
5145 /**
5146 * regress_test_obj_function_async:
5147 *
5148 */
5149 void
5150 regress_test_obj_function_async (RegressTestObj *self,
5151 int io_priority G_GNUC_UNUSED,
5152 GCancellable *cancellable,
5153 GAsyncReadyCallback callback,
5154 gpointer user_data)
5155 {
5156 GTask *task = g_task_new (self, cancellable, callback, user_data);
5157
5158 async_method_tasks = g_slist_prepend (async_method_tasks, task);
5159 }
5160
5161 /**
5162 * regress_test_obj_function_thaw_async:
5163 * @self:
5164 *
5165 * Returns: the number of callbacks that were thawed.
5166 */
5167 int
5168 regress_test_obj_function_thaw_async (RegressTestObj *self G_GNUC_UNUSED)
5169 {
5170 int retval = 0;
5171 GSList *node;
5172
5173 for (node = async_method_tasks; node != NULL; node = node->next)
5174 {
5175 GTask *task = node->data;
5176 g_task_return_boolean (task, TRUE);
5177 g_object_unref (task);
5178 retval++;
5179 }
5180
5181 g_slist_free (async_method_tasks);
5182 async_method_tasks = NULL;
5183 return retval;
5184 }
5185
5186 /**
5187 * regress_test_obj_function_finish:
5188 *
5189 */
5190 gboolean
5191 regress_test_obj_function_finish (RegressTestObj *self G_GNUC_UNUSED, GAsyncResult *res, GError **error)
5192 {
5193 return g_task_propagate_boolean (G_TASK(res), error);
5194 }
5195
5196 /**
5197 * regress_test_obj_function_sync:
5198 *
5199 */
5200 gboolean
5201 regress_test_obj_function_sync (RegressTestObj *self G_GNUC_UNUSED, int io_priority G_GNUC_UNUSED)
5202 {
5203 return TRUE;
5204 }
5205
5206
5207 /**
5208 * regress_test_obj_function2:
5209 * @self: a #RegressTestObj
5210 * @io_priority: a number
5211 * @cancellable: (nullable): a #GCancellable, or %NULL
5212 * @test_cb: (nullable) (scope notified) (closure test_data): match reporting callback
5213 * @test_data: user data for @test_cb
5214 * @test_destroy: (destroy test_data): Destroy notify for @match_data
5215 * @callback: the function to call on completion
5216 * @user_data: the data to pass to @callback
5217 *
5218 * This is an example taken from FPrint: `fp_device_verify`.
5219 */
5220 void
5221 regress_test_obj_function2 (RegressTestObj *self,
5222 int io_priority G_GNUC_UNUSED,
5223 GCancellable *cancellable,
5224 RegressTestCallbackUserData test_cb,
5225 gpointer test_data,
5226 GDestroyNotify test_destroy,
5227 GAsyncReadyCallback callback,
5228 gpointer user_data)
5229 {
5230 GTask *task = g_task_new (self, cancellable, callback, user_data);
5231
5232 async_method_tasks = g_slist_prepend (async_method_tasks, task);
5233
5234 if (test_cb != NULL)
5235 test_cb (test_data);
5236
5237 if (test_destroy != NULL)
5238 test_destroy (test_data);
5239 }
5240
5241 /**
5242 * regress_test_obj_function2_finish:
5243 * @self: A #TestObj
5244 * @result: A #GAsyncResult
5245 * @match: (out): An extra parameter, similar to `fp_device_verify_finish()`
5246 * @some_obj: (out) (transfer full) (nullable): An output object, or %NULL to ignore
5247 * @error: Return location for errors, or %NULL to ignore
5248 *
5249 * Finish function for `regress_test_obj_function2_async()`.
5250 *
5251 * Returns: %FALSE on error, %TRUE otherwise
5252 */
5253 gboolean
5254 regress_test_obj_function2_finish (RegressTestObj *self G_GNUC_UNUSED,
5255 GAsyncResult *result,
5256 gboolean *match,
5257 GObject **some_obj,
5258 GError **error)
5259 {
5260 gboolean res = g_task_propagate_boolean (G_TASK (result), error);
5261
5262 *match = res;
5263 if (some_obj)
5264 *some_obj = NULL;
5265
5266 return res;
5267 }
5268
5269 /**
5270 * regress_test_obj_function2_sync:
5271 *
5272 */
5273 gboolean
5274 regress_test_obj_function2_sync (RegressTestObj *self G_GNUC_UNUSED, int io_priority G_GNUC_UNUSED)
5275 {
5276 return TRUE;
5277 }
5278
5279 G_DEFINE_FLAGS_TYPE (RegressTestDiscontinuousFlags, regress_test_discontinuous_flags, G_DEFINE_ENUM_VALUE (REGRESS_TEST_DISCONTINUOUS_FLAG1, "discontinuous1"), G_DEFINE_ENUM_VALUE (REGRESS_TEST_DISCONTINUOUS_FLAG2, "discontinuous2"))
5280
5281 /**
5282 * regress_test_discontinuous_1_with_private_values:
5283 *
5284 * Returns: REGRESS_TEST_DISCONTINUOUS_FLAG1 with a private value lower than the smallest RegressTestDiscontinuousFlags enum value.
5285 */
5286 RegressTestDiscontinuousFlags
5287 regress_test_discontinuous_1_with_private_values (void)
5288 {
5289 return 1 << 3 | REGRESS_TEST_DISCONTINUOUS_FLAG1;
5290 }
5291
5292 /**
5293 * regress_test_discontinuous_2_with_private_values:
5294 *
5295 * Returns: REGRESS_TEST_DISCONTINUOUS_FLAG2 with a private value higher than the largest RegressTestDiscontinuousFlags enum value.
5296 */
5297 RegressTestDiscontinuousFlags
5298 regress_test_discontinuous_2_with_private_values (void)
5299 {
5300 return 1 << 30 | REGRESS_TEST_DISCONTINUOUS_FLAG2;
5301 }