Imported Upstream version 1.61.1
[platform/upstream/gobject-introspection.git] / tests / gimarshallingtests.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2  *vim: tabstop=4 shiftwidth=4 expandtab
3  */
4
5 /* This file gets installed, so we can't assume config.h is available */
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 #include "gimarshallingtests.h"
11
12 #include <string.h>
13
14 static void gi_marshalling_tests_boxed_struct_free (GIMarshallingTestsBoxedStruct *v);
15
16 /* Booleans */
17
18 gboolean
19 gi_marshalling_tests_boolean_return_true (void)
20 {
21   return TRUE;
22 }
23
24 gboolean
25 gi_marshalling_tests_boolean_return_false (void)
26 {
27   return FALSE;
28 }
29
30 void
31 gi_marshalling_tests_boolean_in_true (gboolean v)
32 {
33   g_assert (v == TRUE);
34 }
35
36 void
37 gi_marshalling_tests_boolean_in_false (gboolean v)
38 {
39   g_assert (v == FALSE);
40 }
41
42 /**
43  * gi_marshalling_tests_boolean_out_true:
44  * @v: (out):
45  */
46 void
47 gi_marshalling_tests_boolean_out_true (gboolean *v)
48 {
49   *v = TRUE;
50 }
51
52 /**
53  * gi_marshalling_tests_boolean_out_false:
54  * @v: (out):
55  */
56 void
57 gi_marshalling_tests_boolean_out_false (gboolean *v)
58 {
59   *v = FALSE;
60 }
61
62 /**
63  * gi_marshalling_tests_boolean_inout_true_false:
64  * @v: (inout):
65  */
66 void
67 gi_marshalling_tests_boolean_inout_true_false (gboolean *v)
68 {
69   g_assert (*v == TRUE);
70   *v = FALSE;
71 }
72
73 /**
74  * gi_marshalling_tests_boolean_inout_false_true:
75  * @v: (inout):
76  */
77 void
78 gi_marshalling_tests_boolean_inout_false_true (gboolean *v)
79 {
80   g_assert (*v == FALSE);
81   *v = TRUE;
82 }
83
84
85 /* Integers */
86
87 gint8
88 gi_marshalling_tests_int8_return_max (void)
89 {
90   return G_MAXINT8;
91 }
92
93 gint8
94 gi_marshalling_tests_int8_return_min (void)
95 {
96   return G_MININT8;
97 }
98
99 void
100 gi_marshalling_tests_int8_in_max (gint8 v)
101 {
102   g_assert_cmpint (v, ==, G_MAXINT8);
103 }
104
105 void
106 gi_marshalling_tests_int8_in_min (gint8 v)
107 {
108   g_assert_cmpint (v, ==, G_MININT8);
109 }
110
111 /**
112  * gi_marshalling_tests_int8_out_max:
113  * @v: (out):
114  */
115 void
116 gi_marshalling_tests_int8_out_max (gint8 *v)
117 {
118   *v = G_MAXINT8;
119 }
120
121 /**
122  * gi_marshalling_tests_int8_out_min:
123  * @v: (out):
124  */
125 void
126 gi_marshalling_tests_int8_out_min (gint8 *v)
127 {
128   *v = G_MININT8;
129 }
130
131 /**
132  * gi_marshalling_tests_int8_inout_max_min:
133  * @v: (inout):
134  */
135 void
136 gi_marshalling_tests_int8_inout_max_min (gint8 *v)
137 {
138   g_assert_cmpint (*v, ==, G_MAXINT8);
139   *v = G_MININT8;
140 }
141
142 /**
143  * gi_marshalling_tests_int8_inout_min_max:
144  * @v: (inout):
145  */
146 void
147 gi_marshalling_tests_int8_inout_min_max (gint8 *v)
148 {
149   g_assert_cmpint (*v, ==, G_MININT8);
150   *v = G_MAXINT8;
151 }
152
153
154 guint8
155 gi_marshalling_tests_uint8_return (void)
156 {
157   return G_MAXUINT8;
158 }
159
160 void
161 gi_marshalling_tests_uint8_in (guint8 v)
162 {
163   g_assert_cmpuint (v, ==, G_MAXUINT8);
164 }
165
166 /**
167  * gi_marshalling_tests_uint8_out:
168  * @v: (out):
169  */
170 void
171 gi_marshalling_tests_uint8_out (guint8 *v)
172 {
173   *v = G_MAXUINT8;
174 }
175
176 /**
177  * gi_marshalling_tests_uint8_inout:
178  * @v: (inout):
179  */
180 void
181 gi_marshalling_tests_uint8_inout (guint8 *v)
182 {
183   g_assert_cmpuint (*v, ==, G_MAXUINT8);
184   *v = 0;
185 }
186
187
188 gint16
189 gi_marshalling_tests_int16_return_max (void)
190 {
191   return G_MAXINT16;
192 }
193
194 gint16
195 gi_marshalling_tests_int16_return_min (void)
196 {
197   return G_MININT16;
198 }
199
200 void
201 gi_marshalling_tests_int16_in_max (gint16 v)
202 {
203   g_assert_cmpint (v, ==, G_MAXINT16);
204 }
205
206 void
207 gi_marshalling_tests_int16_in_min (gint16 v)
208 {
209   g_assert_cmpint (v, ==, G_MININT16);
210 }
211
212 /**
213  * gi_marshalling_tests_int16_out_max:
214  * @v: (out):
215  */
216 void
217 gi_marshalling_tests_int16_out_max (gint16 *v)
218 {
219   *v = G_MAXINT16;
220 }
221
222 /**
223  * gi_marshalling_tests_int16_out_min:
224  * @v: (out):
225  */
226 void
227 gi_marshalling_tests_int16_out_min (gint16 *v)
228 {
229   *v = G_MININT16;
230 }
231
232 /**
233  * gi_marshalling_tests_int16_inout_max_min:
234  * @v: (inout):
235  */
236 void
237 gi_marshalling_tests_int16_inout_max_min (gint16 *v)
238 {
239   g_assert_cmpint (*v, ==, G_MAXINT16);
240   *v = G_MININT16;
241 }
242
243 /**
244  * gi_marshalling_tests_int16_inout_min_max:
245  * @v: (inout):
246  */
247 void
248 gi_marshalling_tests_int16_inout_min_max (gint16 *v)
249 {
250   g_assert_cmpint (*v, ==, G_MININT16);
251   *v = G_MAXINT16;
252 }
253
254
255 guint16
256 gi_marshalling_tests_uint16_return (void)
257 {
258   return G_MAXUINT16;
259 }
260
261 void
262 gi_marshalling_tests_uint16_in (guint16 v)
263 {
264   g_assert_cmpuint (v, ==, G_MAXUINT16);
265 }
266
267 /**
268  * gi_marshalling_tests_uint16_out:
269  * @v: (out):
270  */
271 void
272 gi_marshalling_tests_uint16_out (guint16 *v)
273 {
274   *v = G_MAXUINT16;
275 }
276
277 /**
278  * gi_marshalling_tests_uint16_inout:
279  * @v: (inout):
280  */
281 void
282 gi_marshalling_tests_uint16_inout (guint16 *v)
283 {
284   g_assert_cmpuint (*v, ==, G_MAXUINT16);
285   *v = 0;
286 }
287
288
289 gint32
290 gi_marshalling_tests_int32_return_max (void)
291 {
292   return G_MAXINT32;
293 }
294
295 gint32
296 gi_marshalling_tests_int32_return_min (void)
297 {
298   return G_MININT32;
299 }
300
301 void
302 gi_marshalling_tests_int32_in_max (gint32 v)
303 {
304   g_assert_cmpint (v, ==, G_MAXINT32);
305 }
306
307 void
308 gi_marshalling_tests_int32_in_min (gint32 v)
309 {
310   g_assert_cmpint (v, ==, G_MININT32);
311 }
312
313 /**
314  * gi_marshalling_tests_int32_out_max:
315  * @v: (out):
316  */
317 void
318 gi_marshalling_tests_int32_out_max (gint32 *v)
319 {
320   *v = G_MAXINT32;
321 }
322
323 /**
324  * gi_marshalling_tests_int32_out_min:
325  * @v: (out):
326  */
327 void
328 gi_marshalling_tests_int32_out_min (gint32 *v)
329 {
330   *v = G_MININT32;
331 }
332
333 /**
334  * gi_marshalling_tests_int32_inout_max_min:
335  * @v: (inout):
336  */
337 void
338 gi_marshalling_tests_int32_inout_max_min (gint32 *v)
339 {
340   g_assert_cmpint (*v, ==, G_MAXINT32);
341   *v = G_MININT32;
342 }
343
344 /**
345  * gi_marshalling_tests_int32_inout_min_max:
346  * @v: (inout):
347  */
348 void
349 gi_marshalling_tests_int32_inout_min_max (gint32 *v)
350 {
351   g_assert_cmpint (*v, ==, G_MININT32);
352   *v = G_MAXINT32;
353 }
354
355
356 guint32
357 gi_marshalling_tests_uint32_return (void)
358 {
359   return G_MAXUINT32;
360 }
361
362 void
363 gi_marshalling_tests_uint32_in (guint32 v)
364 {
365   g_assert_cmpuint (v, ==, G_MAXUINT32);
366 }
367
368 /**
369  * gi_marshalling_tests_uint32_out:
370  * @v: (out):
371  */
372 void
373 gi_marshalling_tests_uint32_out (guint32 *v)
374 {
375   *v = G_MAXUINT32;
376 }
377
378 /**
379  * gi_marshalling_tests_uint32_inout:
380  * @v: (inout):
381  */
382 void
383 gi_marshalling_tests_uint32_inout (guint32 *v)
384 {
385   g_assert_cmpuint (*v, ==, G_MAXUINT32);
386   *v = 0;
387 }
388
389
390 gint64
391 gi_marshalling_tests_int64_return_max (void)
392 {
393   return G_MAXINT64;
394 }
395
396 gint64
397 gi_marshalling_tests_int64_return_min (void)
398 {
399   return G_MININT64;
400 }
401
402 void
403 gi_marshalling_tests_int64_in_max (gint64 v)
404 {
405   g_assert_cmpint (v, ==, G_MAXINT64);
406 }
407
408 void
409 gi_marshalling_tests_int64_in_min (gint64 v)
410 {
411   g_assert_cmpint (v, ==, G_MININT64);
412 }
413
414 /**
415  * gi_marshalling_tests_int64_out_max:
416  * @v: (out):
417  */
418 void
419 gi_marshalling_tests_int64_out_max (gint64 *v)
420 {
421   *v = G_MAXINT64;
422 }
423
424 /**
425  * gi_marshalling_tests_int64_out_min:
426  * @v: (out):
427  */
428 void
429 gi_marshalling_tests_int64_out_min (gint64 *v)
430 {
431   *v = G_MININT64;
432 }
433
434 /**
435  * gi_marshalling_tests_int64_inout_max_min:
436  * @v: (inout):
437  */
438 void
439 gi_marshalling_tests_int64_inout_max_min (gint64 *v)
440 {
441   g_assert_cmpint (*v, ==, G_MAXINT64);
442   *v = G_MININT64;
443 }
444
445 /**
446  * gi_marshalling_tests_int64_inout_min_max:
447  * @v: (inout):
448  */
449 void
450 gi_marshalling_tests_int64_inout_min_max (gint64 *v)
451 {
452   g_assert_cmpint (*v, ==, G_MININT64);
453   *v = G_MAXINT64;
454 }
455
456
457 guint64
458 gi_marshalling_tests_uint64_return (void)
459 {
460   return G_MAXUINT64;
461 }
462
463 void
464 gi_marshalling_tests_uint64_in (guint64 v)
465 {
466   g_assert_cmpuint (v, ==, G_MAXUINT64);
467 }
468
469 /**
470  * gi_marshalling_tests_uint64_out:
471  * @v: (out):
472  */
473 void
474 gi_marshalling_tests_uint64_out (guint64 *v)
475 {
476   *v = G_MAXUINT64;
477 }
478
479 /**
480  * gi_marshalling_tests_uint64_inout:
481  * @v: (inout):
482  */
483 void
484 gi_marshalling_tests_uint64_inout (guint64 *v)
485 {
486   g_assert_cmpuint (*v, ==, G_MAXUINT64);
487   *v = 0;
488 }
489
490
491 gshort
492 gi_marshalling_tests_short_return_max (void)
493 {
494   return G_MAXSHORT;
495 }
496
497 gshort
498 gi_marshalling_tests_short_return_min (void)
499 {
500   return G_MINSHORT;
501 }
502
503 void
504 gi_marshalling_tests_short_in_max (gshort short_)
505 {
506   g_assert_cmpint (short_, ==, G_MAXSHORT);
507 }
508
509 void
510 gi_marshalling_tests_short_in_min (gshort short_)
511 {
512   g_assert_cmpint (short_, ==, G_MINSHORT);
513 }
514
515 /**
516  * gi_marshalling_tests_short_out_max:
517  * @short_: (out):
518  */
519 void
520 gi_marshalling_tests_short_out_max (gshort *short_)
521 {
522   *short_ = G_MAXSHORT;
523 }
524
525 /**
526  * gi_marshalling_tests_short_out_min:
527  * @short_: (out):
528  */
529 void
530 gi_marshalling_tests_short_out_min (gshort *short_)
531 {
532   *short_ = G_MINSHORT;
533 }
534
535 /**
536  * gi_marshalling_tests_short_inout_max_min:
537  * @short_: (inout):
538  */
539 void
540 gi_marshalling_tests_short_inout_max_min (gshort *short_)
541 {
542   g_assert_cmpint (*short_, ==, G_MAXSHORT);
543   *short_ = G_MINSHORT;
544 }
545
546 /**
547  * gi_marshalling_tests_short_inout_min_max:
548  * @short_: (inout):
549  */
550 void
551 gi_marshalling_tests_short_inout_min_max (gshort *short_)
552 {
553   g_assert_cmpint (*short_, ==, G_MINSHORT);
554   *short_ = G_MAXSHORT;
555 }
556
557
558 gushort
559 gi_marshalling_tests_ushort_return (void)
560 {
561   return G_MAXUSHORT;
562 }
563
564 void
565 gi_marshalling_tests_ushort_in (gushort ushort_)
566 {
567   g_assert_cmpuint (ushort_, ==, G_MAXUSHORT);
568 }
569
570 /**
571  * gi_marshalling_tests_ushort_out:
572  * @ushort_: (out):
573  */
574 void
575 gi_marshalling_tests_ushort_out (gushort *ushort_)
576 {
577   *ushort_ = G_MAXUSHORT;
578 }
579
580 /**
581  * gi_marshalling_tests_ushort_inout:
582  * @ushort_: (inout):
583  */
584 void
585 gi_marshalling_tests_ushort_inout (gushort *ushort_)
586 {
587   g_assert_cmpuint (*ushort_, ==, G_MAXUSHORT);
588   *ushort_ = 0;
589 }
590
591
592 gint
593 gi_marshalling_tests_int_return_max (void)
594 {
595   return G_MAXINT;
596 }
597
598 gint
599 gi_marshalling_tests_int_return_min (void)
600 {
601   return G_MININT;
602 }
603
604 void
605 gi_marshalling_tests_int_in_max (gint int_)
606 {
607   g_assert_cmpint (int_, ==, G_MAXINT);
608 }
609
610 void
611 gi_marshalling_tests_int_in_min (gint int_)
612 {
613   g_assert_cmpint (int_, ==, G_MININT);
614 }
615
616 /**
617  * gi_marshalling_tests_int_out_max:
618  * @int_: (out):
619  */
620 void
621 gi_marshalling_tests_int_out_max (gint *int_)
622 {
623   *int_ = G_MAXINT;
624 }
625
626 /**
627  * gi_marshalling_tests_int_out_min:
628  * @int_: (out):
629  */
630 void
631 gi_marshalling_tests_int_out_min (gint *int_)
632 {
633   *int_ = G_MININT;
634 }
635
636 /**
637  * gi_marshalling_tests_int_inout_max_min:
638  * @int_: (inout):
639  */
640 void
641 gi_marshalling_tests_int_inout_max_min (gint *int_)
642 {
643   g_assert_cmpint (*int_, ==, G_MAXINT);
644   *int_ = G_MININT;
645 }
646
647 /**
648  * gi_marshalling_tests_int_inout_min_max:
649  * @int_: (inout):
650  */
651 void
652 gi_marshalling_tests_int_inout_min_max (gint *int_)
653 {
654   g_assert_cmpint (*int_, ==, G_MININT);
655   *int_ = G_MAXINT;
656 }
657
658
659 guint
660 gi_marshalling_tests_uint_return (void)
661 {
662   return G_MAXUINT;
663 }
664
665 void
666 gi_marshalling_tests_uint_in (guint uint_)
667 {
668   g_assert_cmpuint (uint_, ==, G_MAXUINT);
669 }
670
671 /**
672  * gi_marshalling_tests_uint_out:
673  * @uint_: (out):
674  */
675 void
676 gi_marshalling_tests_uint_out (guint *uint_)
677 {
678   *uint_ = G_MAXUINT;
679 }
680
681 /**
682  * gi_marshalling_tests_uint_inout:
683  * @uint_: (inout):
684  */
685 void
686 gi_marshalling_tests_uint_inout (guint *uint_)
687 {
688   g_assert_cmpuint (*uint_, ==, G_MAXUINT);
689   *uint_ = 0;
690 }
691
692
693 glong
694 gi_marshalling_tests_long_return_max (void)
695 {
696   return G_MAXLONG;
697 }
698
699 glong
700 gi_marshalling_tests_long_return_min (void)
701 {
702   return G_MINLONG;
703 }
704
705 void
706 gi_marshalling_tests_long_in_max (glong long_)
707 {
708   g_assert_cmpint (long_, ==, G_MAXLONG);
709 }
710
711 void
712 gi_marshalling_tests_long_in_min (glong long_)
713 {
714   g_assert_cmpint (long_, ==, G_MINLONG);
715 }
716
717 /**
718  * gi_marshalling_tests_long_out_max:
719  * @long_: (out):
720  */
721 void
722 gi_marshalling_tests_long_out_max (glong *long_)
723 {
724   *long_ = G_MAXLONG;
725 }
726
727 /**
728  * gi_marshalling_tests_long_out_min:
729  * @long_: (out):
730  */
731 void
732 gi_marshalling_tests_long_out_min (glong *long_)
733 {
734   *long_ = G_MINLONG;
735 }
736
737 /**
738  * gi_marshalling_tests_long_inout_max_min:
739  * @long_: (inout):
740  */
741 void
742 gi_marshalling_tests_long_inout_max_min (glong *long_)
743 {
744   g_assert_cmpint (*long_, ==, G_MAXLONG);
745   *long_ = G_MINLONG;
746 }
747
748 /**
749  * gi_marshalling_tests_long_inout_min_max:
750  * @long_: (inout):
751  */
752 void
753 gi_marshalling_tests_long_inout_min_max (glong *long_)
754 {
755   g_assert_cmpint (*long_, ==, G_MINLONG);
756   *long_ = G_MAXLONG;
757 }
758
759
760 gulong
761 gi_marshalling_tests_ulong_return (void)
762 {
763   return G_MAXULONG;
764 }
765
766 void
767 gi_marshalling_tests_ulong_in (gulong ulong_)
768 {
769   g_assert_cmpuint (ulong_, ==, G_MAXULONG);
770 }
771
772 /**
773  * gi_marshalling_tests_ulong_out:
774  * @ulong_: (out):
775  */
776 void
777 gi_marshalling_tests_ulong_out (gulong *ulong_)
778 {
779   *ulong_ = G_MAXULONG;
780 }
781
782 /**
783  * gi_marshalling_tests_ulong_inout:
784  * @ulong_: (inout):
785  */
786 void
787 gi_marshalling_tests_ulong_inout (gulong *ulong_)
788 {
789   g_assert_cmpuint (*ulong_, ==, G_MAXULONG);
790   *ulong_ = 0;
791 }
792
793
794 gssize
795 gi_marshalling_tests_ssize_return_max (void)
796 {
797   return G_MAXSSIZE;
798 }
799
800 gssize
801 gi_marshalling_tests_ssize_return_min (void)
802 {
803   return G_MINSSIZE;
804 }
805
806 void
807 gi_marshalling_tests_ssize_in_max (gssize ssize)
808 {
809   g_assert_cmpint (ssize, ==, G_MAXSSIZE);
810 }
811
812 void
813 gi_marshalling_tests_ssize_in_min (gssize ssize)
814 {
815   g_assert_cmpint (ssize, ==, G_MINSSIZE);
816 }
817
818 /**
819  * gi_marshalling_tests_ssize_out_max:
820  * @ssize: (out):
821  */
822 void
823 gi_marshalling_tests_ssize_out_max (gssize *ssize)
824 {
825   *ssize = G_MAXSSIZE;
826 }
827
828 /**
829  * gi_marshalling_tests_ssize_out_min:
830  * @ssize: (out):
831  */
832 void
833 gi_marshalling_tests_ssize_out_min (gssize *ssize)
834 {
835   *ssize = G_MINSSIZE;
836 }
837
838 /**
839  * gi_marshalling_tests_ssize_inout_max_min:
840  * @ssize: (inout):
841  */
842 void
843 gi_marshalling_tests_ssize_inout_max_min (gssize *ssize)
844 {
845   g_assert_cmpint (*ssize, ==, G_MAXSSIZE);
846   *ssize = G_MINSSIZE;
847 }
848
849 /**
850  * gi_marshalling_tests_ssize_inout_min_max:
851  * @ssize: (inout):
852  */
853 void
854 gi_marshalling_tests_ssize_inout_min_max (gssize *ssize)
855 {
856   g_assert_cmpint (*ssize, ==, G_MINSSIZE);
857   *ssize = G_MAXSSIZE;
858 }
859
860
861 gsize
862 gi_marshalling_tests_size_return (void)
863 {
864   return G_MAXSIZE;
865 }
866
867 void
868 gi_marshalling_tests_size_in (gsize size)
869 {
870   g_assert_cmpuint (size, ==, G_MAXSIZE);
871 }
872
873 /**
874  * gi_marshalling_tests_size_out:
875  * @size: (out):
876  */
877 void
878 gi_marshalling_tests_size_out (gsize *size)
879 {
880   *size = G_MAXSIZE;
881 }
882
883 /**
884  * gi_marshalling_tests_size_inout:
885  * @size: (inout):
886  */
887 void
888 gi_marshalling_tests_size_inout (gsize *size)
889 {
890   g_assert_cmpuint (*size, ==, G_MAXSIZE);
891   *size = 0;
892 }
893
894
895 gfloat
896 gi_marshalling_tests_float_return (void)
897 {
898   return G_MAXFLOAT;
899 }
900
901 void
902 gi_marshalling_tests_float_in (gfloat v)
903 {
904   g_assert_cmpfloat (v, ==, G_MAXFLOAT);
905 }
906
907 /**
908  * gi_marshalling_tests_float_out:
909  * @v: (out):
910  */
911 void
912 gi_marshalling_tests_float_out (gfloat *v)
913 {
914   *v = G_MAXFLOAT;
915 }
916
917 /**
918  * gi_marshalling_tests_float_inout:
919  * @v: (inout):
920  */
921 void
922 gi_marshalling_tests_float_inout (gfloat *v)
923 {
924   g_assert_cmpfloat (*v, ==, G_MAXFLOAT);
925   *v = G_MINFLOAT;
926 }
927
928
929 gdouble
930 gi_marshalling_tests_double_return (void)
931 {
932   return G_MAXDOUBLE;
933 }
934
935 void
936 gi_marshalling_tests_double_in (gdouble v)
937 {
938   g_assert_cmpfloat (v, ==, G_MAXDOUBLE);
939 }
940
941 /**
942  * gi_marshalling_tests_double_out:
943  * @v: (out):
944  */
945 void
946 gi_marshalling_tests_double_out (gdouble *v)
947 {
948   *v = G_MAXDOUBLE;
949 }
950
951 /**
952  * gi_marshalling_tests_double_inout:
953  * @v: (inout):
954  */
955 void
956 gi_marshalling_tests_double_inout (gdouble *v)
957 {
958   g_assert_cmpfloat (*v, ==, G_MAXDOUBLE);
959   *v = G_MINDOUBLE;
960 }
961
962
963 time_t
964 gi_marshalling_tests_time_t_return (void)
965 {
966   return 1234567890;
967 }
968
969 void
970 gi_marshalling_tests_time_t_in (time_t v)
971 {
972   g_assert_cmpuint (v, ==, 1234567890);
973 }
974
975 /**
976  * gi_marshalling_tests_time_t_out:
977  * @v: (out):
978  */
979 void
980 gi_marshalling_tests_time_t_out (time_t *v)
981 {
982   *v = 1234567890;
983 }
984
985 /**
986  * gi_marshalling_tests_time_t_inout:
987  * @v: (inout):
988  */
989 void
990 gi_marshalling_tests_time_t_inout (time_t *v)
991 {
992   g_assert_cmpuint (*v, ==, 1234567890);
993   *v = 0;
994 }
995
996
997 GType
998 gi_marshalling_tests_gtype_return (void)
999 {
1000   return G_TYPE_NONE;
1001 }
1002
1003 GType
1004 gi_marshalling_tests_gtype_string_return (void)
1005 {
1006   return G_TYPE_STRING;
1007 }
1008
1009 void
1010 gi_marshalling_tests_gtype_in (GType gtype)
1011 {
1012   g_assert (gtype == G_TYPE_NONE);
1013 }
1014
1015 void
1016 gi_marshalling_tests_gtype_string_in (GType gtype)
1017 {
1018   g_assert (gtype == G_TYPE_STRING);
1019 }
1020
1021
1022 /**
1023  * gi_marshalling_tests_gtype_out:
1024  * @gtype: (out):
1025  */
1026 void
1027 gi_marshalling_tests_gtype_out (GType *gtype)
1028 {
1029   *gtype = G_TYPE_NONE;
1030 }
1031
1032 /**
1033  * gi_marshalling_tests_gtype_string_out:
1034  * @gtype: (out):
1035  */
1036 void
1037 gi_marshalling_tests_gtype_string_out (GType *gtype)
1038 {
1039   *gtype = G_TYPE_STRING;
1040 }
1041
1042 /**
1043  * gi_marshalling_tests_gtype_inout:
1044  * @gtype: (inout):
1045  */
1046 void
1047 gi_marshalling_tests_gtype_inout (GType *gtype)
1048 {
1049   g_assert (*gtype == G_TYPE_NONE);
1050   *gtype = G_TYPE_INT;
1051 }
1052
1053
1054 const gchar *
1055 gi_marshalling_tests_utf8_none_return (void)
1056 {
1057   return GI_MARSHALLING_TESTS_CONSTANT_UTF8;
1058 }
1059
1060 gchar *
1061 gi_marshalling_tests_utf8_full_return (void)
1062 {
1063   return g_strdup (GI_MARSHALLING_TESTS_CONSTANT_UTF8);
1064 }
1065
1066 void
1067 gi_marshalling_tests_utf8_none_in (const gchar *utf8)
1068 {
1069   g_assert_cmpstr (GI_MARSHALLING_TESTS_CONSTANT_UTF8, ==, utf8);
1070 }
1071
1072 /**
1073  * gi_marshalling_tests_utf8_as_uint8array_in:
1074  * @array: (array length=len) (element-type guint8): Byte data that happens to be UTF-8
1075  * @len: Length
1076  *
1077  * Takes data that happens to be UTF-8 as a byte array, to test
1078  * binding conversion from their string type (e.g. JavaScript's
1079  * UTF-16) to UTF-8.
1080  */
1081 void
1082 gi_marshalling_tests_utf8_as_uint8array_in (const guint8 *array, gsize len)
1083 {
1084   gsize orig_len = strlen (GI_MARSHALLING_TESTS_CONSTANT_UTF8);
1085   g_assert_cmpint (orig_len, ==, len);
1086   g_assert (memcmp (GI_MARSHALLING_TESTS_CONSTANT_UTF8, array, len) == 0);
1087 }
1088
1089 /**
1090  * gi_marshalling_tests_utf8_none_out:
1091  * @utf8: (out) (transfer none):
1092  */
1093 void
1094 gi_marshalling_tests_utf8_none_out (const gchar **utf8)
1095 {
1096   *utf8 = GI_MARSHALLING_TESTS_CONSTANT_UTF8;
1097 }
1098
1099 /**
1100  * gi_marshalling_tests_utf8_full_out:
1101  * @utf8: (out) (transfer full):
1102  */
1103 void
1104 gi_marshalling_tests_utf8_full_out (gchar **utf8)
1105 {
1106   *utf8 = g_strdup (GI_MARSHALLING_TESTS_CONSTANT_UTF8);
1107 }
1108
1109 /**
1110  * gi_marshalling_tests_utf8_dangling_out:
1111  * @utf8: (out) (transfer full):
1112  */
1113 void
1114 gi_marshalling_tests_utf8_dangling_out (gchar **utf8 G_GNUC_UNUSED)
1115 {
1116   /* Intentionally don't touch the pointer to see how
1117      the bindings handle this case.  Bindings should be
1118      robust against broken C functions and can initialize
1119      even OUT vlues to NULL.
1120    */
1121 }
1122
1123 /**
1124  * gi_marshalling_tests_utf8_none_inout:
1125  * @utf8: (inout) (transfer none):
1126  */
1127 void
1128 gi_marshalling_tests_utf8_none_inout (const gchar **utf8)
1129 {
1130   g_assert_cmpstr (GI_MARSHALLING_TESTS_CONSTANT_UTF8, ==, *utf8);
1131   *utf8 = "";
1132 }
1133
1134 /**
1135  * gi_marshalling_tests_utf8_full_inout:
1136  * @utf8: (inout) (transfer full):
1137  */
1138 void
1139 gi_marshalling_tests_utf8_full_inout (gchar **utf8)
1140 {
1141   g_assert_cmpstr (GI_MARSHALLING_TESTS_CONSTANT_UTF8, ==, *utf8);
1142   g_free (*utf8);
1143   *utf8 = g_strdup ("");
1144 }
1145
1146
1147 /**
1148  * gi_marshalling_tests_init_function:
1149  * @n_args: (inout) (allow-none): number of args
1150  * @argv: (inout) (array length=n_args) (allow-none): args
1151  *
1152  * This is like gtk_init().
1153  */
1154 gboolean
1155 gi_marshalling_tests_init_function (gint *n_args, char ***argv)
1156 {
1157   if (n_args == NULL)
1158     return TRUE;
1159
1160   if (*n_args == 0)
1161     return TRUE;
1162   (*n_args)--;
1163   g_assert (argv != NULL);
1164   /* we have transfer ownership full, so we need to free the element ourself */
1165   g_free ((*argv)[*n_args]);
1166   (*argv)[*n_args] = NULL;
1167   return TRUE;
1168 }
1169
1170 /**
1171  * gi_marshalling_tests_array_fixed_int_return:
1172  *
1173  * Returns: (array fixed-size=4):
1174  */
1175 const gint *
1176 gi_marshalling_tests_array_fixed_int_return (void)
1177 {
1178   static gint ints[] = { -1, 0, 1, 2 };
1179   return ints;
1180 }
1181
1182 /**
1183  * gi_marshalling_tests_array_fixed_short_return:
1184  *
1185  * Returns: (array fixed-size=4):
1186  */
1187 const gshort *
1188 gi_marshalling_tests_array_fixed_short_return (void)
1189 {
1190   static gshort shorts[] = { -1, 0, 1, 2 };
1191   return shorts;
1192 }
1193
1194 /**
1195  * gi_marshalling_tests_array_fixed_int_in:
1196  * @ints: (array fixed-size=4):
1197  */
1198 void
1199 gi_marshalling_tests_array_fixed_int_in (const gint *ints)
1200 {
1201   g_assert_cmpint (ints[0], ==, -1);
1202   g_assert_cmpint (ints[1], ==, 0);
1203   g_assert_cmpint (ints[2], ==, 1);
1204   g_assert_cmpint (ints[3], ==, 2);
1205 }
1206
1207 /**
1208  * gi_marshalling_tests_array_fixed_short_in:
1209  * @shorts: (array fixed-size=4):
1210  */
1211 void
1212 gi_marshalling_tests_array_fixed_short_in (const gshort *shorts)
1213 {
1214   g_assert_cmpint (shorts[0], ==, -1);
1215   g_assert_cmpint (shorts[1], ==, 0);
1216   g_assert_cmpint (shorts[2], ==, 1);
1217   g_assert_cmpint (shorts[3], ==, 2);
1218 }
1219
1220 /**
1221  * gi_marshalling_tests_array_fixed_out:
1222  * @ints: (out) (array fixed-size=4) (transfer none):
1223  */
1224 void
1225 gi_marshalling_tests_array_fixed_out (gint **ints)
1226 {
1227   static gint values[] = { -1, 0, 1, 2 };
1228   *ints = values;
1229 }
1230
1231 /**
1232  * gi_marshalling_tests_array_fixed_out_struct:
1233  * @structs: (out) (array fixed-size=2) (transfer none):
1234  */
1235 void
1236 gi_marshalling_tests_array_fixed_out_struct (GIMarshallingTestsSimpleStruct **structs)
1237 {
1238   static GIMarshallingTestsSimpleStruct *values;
1239
1240   if (values == NULL)
1241     {
1242       values = g_new (GIMarshallingTestsSimpleStruct, 2);
1243
1244       values[0].long_ = 7;
1245       values[0].int8 = 6;
1246
1247       values[1].long_ = 6;
1248       values[1].int8 = 7;
1249     }
1250
1251   *structs = values;
1252 }
1253
1254 /**
1255  * gi_marshalling_tests_array_fixed_inout:
1256  * @ints: (inout) (array fixed-size=4) (transfer none):
1257  */
1258 void
1259 gi_marshalling_tests_array_fixed_inout (gint **ints)
1260 {
1261   static gint values[] = { 2, 1, 0, -1 };
1262
1263   g_assert_cmpint ((*ints)[0], ==, -1);
1264   g_assert_cmpint ((*ints)[1], ==, 0);
1265   g_assert_cmpint ((*ints)[2], ==, 1);
1266   g_assert_cmpint ((*ints)[3], ==, 2);
1267
1268   *ints = values;
1269 }
1270
1271
1272 /**
1273  * gi_marshalling_tests_array_return:
1274  *
1275  * Returns: (array length=length):
1276  */
1277 const gint *
1278 gi_marshalling_tests_array_return (gint *length)
1279 {
1280   static gint ints[] = { -1, 0, 1, 2 };
1281
1282   *length = 4;
1283   return ints;
1284 }
1285
1286 /**
1287  * gi_marshalling_tests_array_return_etc:
1288  * @first:
1289  * @length: (out):
1290  * @last:
1291  * @sum: (out):
1292  *
1293  * Returns: (array length=length):
1294  */
1295 const gint *
1296 gi_marshalling_tests_array_return_etc (gint first, gint *length, gint last, gint *sum)
1297 {
1298   static gint ints[] = { -1, 0, 1, 2 };
1299
1300   ints[0] = first;
1301   ints[3] = last;
1302   *sum = first + last;
1303   *length = 4;
1304   return ints;
1305 }
1306
1307 /**
1308  * gi_marshalling_tests_array_in:
1309  * @ints: (array length=length):
1310  * @length:
1311  */
1312 void
1313 gi_marshalling_tests_array_in (const gint *ints, gint length)
1314 {
1315   g_assert_cmpint (length, ==, 4);
1316   g_assert_cmpint (ints[0], ==, -1);
1317   g_assert_cmpint (ints[1], ==, 0);
1318   g_assert_cmpint (ints[2], ==, 1);
1319   g_assert_cmpint (ints[3], ==, 2);
1320 }
1321
1322 /**
1323  * gi_marshalling_tests_array_in_len_before:
1324  * @length:
1325  * @ints: (array length=length):
1326  */
1327 void
1328 gi_marshalling_tests_array_in_len_before (gint length, const gint *ints)
1329 {
1330   gi_marshalling_tests_array_in (ints, length);
1331 }
1332
1333 /**
1334  * gi_marshalling_tests_array_in_len_zero_terminated:
1335  * @ints: (array length=length zero-terminated):
1336  * @length:
1337  */
1338 void
1339 gi_marshalling_tests_array_in_len_zero_terminated (const gint *ints, gint length)
1340 {
1341   g_assert_cmpint (length, ==, 4);
1342
1343   g_assert_cmpint (ints[0], ==, -1);
1344   g_assert_cmpint (ints[1], ==, 0);
1345   g_assert_cmpint (ints[2], ==, 1);
1346   g_assert_cmpint (ints[3], ==, 2);
1347
1348   /* One past the end, null terminator */
1349   g_assert_cmpint (ints[4], ==, 0);
1350 }
1351
1352 /**
1353  * gi_marshalling_tests_array_string_in:
1354  * @strings: (array length=length):
1355  */
1356 void
1357 gi_marshalling_tests_array_string_in (const gchar **strings, gint length)
1358 {
1359   g_assert_cmpint (length, ==, 2);
1360   g_assert_cmpstr (strings[0], ==, "foo");
1361   g_assert_cmpstr (strings[1], ==, "bar");
1362 }
1363
1364 /**
1365  * gi_marshalling_tests_array_uint8_in:
1366  * @chars: (array length=length):
1367  */
1368 void
1369 gi_marshalling_tests_array_uint8_in (const guint8 *chars, gint length)
1370 {
1371   g_assert_cmpint (length, ==, 4);
1372   g_assert (chars[0] == 'a');
1373   g_assert (chars[1] == 'b');
1374   g_assert (chars[2] == 'c');
1375   g_assert (chars[3] == 'd');
1376 }
1377
1378 /**
1379  * gi_marshalling_tests_array_int64_in:
1380  * @ints: (array length=length):
1381  * @length:
1382  */
1383 void
1384 gi_marshalling_tests_array_int64_in (const gint64 *ints, gint length)
1385 {
1386   g_assert_cmpint (length, ==, 4);
1387   g_assert_cmpint (ints[0], ==, -1);
1388   g_assert_cmpint (ints[1], ==, 0);
1389   g_assert_cmpint (ints[2], ==, 1);
1390   g_assert_cmpint (ints[3], ==, 2);
1391 }
1392
1393 /**
1394  * gi_marshalling_tests_array_uint64_in:
1395  * @ints: (array length=length):
1396  * @length:
1397  */
1398 void
1399 gi_marshalling_tests_array_uint64_in (const guint64 *ints, gint length)
1400 {
1401   g_assert_cmpint (length, ==, 4);
1402   g_assert_cmpint (ints[0], ==, -1);
1403   g_assert_cmpint (ints[1], ==, 0);
1404   g_assert_cmpint (ints[2], ==, 1);
1405   g_assert_cmpint (ints[3], ==, 2);
1406 }
1407
1408 /**
1409  * gi_marshalling_tests_array_unichar_in:
1410  * @chars: (array length=length):
1411  * @length:
1412  */
1413 void
1414 gi_marshalling_tests_array_unichar_in (const gunichar *chars, gint length)
1415 {
1416   int ix;
1417   static const gunichar expected[] = GI_MARSHALLING_TESTS_CONSTANT_UCS4;
1418   g_assert_cmpint (length, ==, 12);
1419   for (ix = 0; ix < length; ix++)
1420     g_assert_cmpuint (chars[ix], ==, expected[ix]);
1421 }
1422
1423 /**
1424  * gi_marshalling_tests_array_bool_in:
1425  * @bools: (array length=length):
1426  * @length:
1427  */
1428 void
1429 gi_marshalling_tests_array_bool_in (const gboolean *bools, gint length)
1430 {
1431   g_assert_cmpint (length, ==, 4);
1432   g_assert_cmpint (bools[0], ==, TRUE);
1433   g_assert_cmpint (bools[1], ==, FALSE);
1434   g_assert_cmpint (bools[2], ==, TRUE);
1435   g_assert_cmpint (bools[3], ==, TRUE);
1436 }
1437
1438 /**
1439  * gi_marshalling_tests_array_struct_in:
1440  * @structs: (array length=length):
1441  */
1442 void
1443 gi_marshalling_tests_array_struct_in (GIMarshallingTestsBoxedStruct **structs, gint length)
1444 {
1445   g_assert_cmpint (length, ==, 3);
1446   g_assert_cmpint (structs[0]->long_, ==, 1);
1447   g_assert_cmpint (structs[1]->long_, ==, 2);
1448   g_assert_cmpint (structs[2]->long_, ==, 3);
1449 }
1450
1451 /**
1452  * gi_marshalling_tests_array_struct_value_in:
1453  * @structs: (array length=length):
1454  */
1455 void
1456 gi_marshalling_tests_array_struct_value_in (GIMarshallingTestsBoxedStruct *structs, gint length)
1457 {
1458   g_assert_cmpint (length, ==, 3);
1459   g_assert_cmpint (structs[0].long_, ==, 1);
1460   g_assert_cmpint (structs[1].long_, ==, 2);
1461   g_assert_cmpint (structs[2].long_, ==, 3);
1462 }
1463
1464 /**
1465  * gi_marshalling_tests_array_simple_struct_in:
1466  * @structs: (array length=length):
1467  */
1468 void
1469 gi_marshalling_tests_array_simple_struct_in (GIMarshallingTestsSimpleStruct *structs, gint length)
1470 {
1471   g_assert_cmpint (length, ==, 3);
1472   g_assert_cmpint (structs[0].long_, ==, 1);
1473   g_assert_cmpint (structs[1].long_, ==, 2);
1474   g_assert_cmpint (structs[2].long_, ==, 3);
1475 }
1476
1477 /**
1478  * gi_marshalling_tests_multi_array_key_value_in:
1479  * @keys: (array length=length):
1480  * @values: (array length=length):
1481  */
1482 void
1483 gi_marshalling_tests_multi_array_key_value_in (gint length, const gchar **keys, const GValue *values)
1484 {
1485   g_assert_cmpint (length, ==, 3);
1486   g_assert_cmpstr ("one", ==, keys[0]);
1487   g_assert_cmpint (g_value_get_int (&values[0]), ==, 1);
1488   g_assert_cmpstr ("two", ==, keys[1]);
1489   g_assert_cmpint (g_value_get_int (&values[1]), ==, 2);
1490   g_assert_cmpstr ("three", ==, keys[2]);
1491   g_assert_cmpint (g_value_get_int (&values[2]), ==, 3);
1492
1493 }
1494
1495 /**
1496  * gi_marshalling_tests_array_struct_take_in:
1497  * @structs: (array length=length) (transfer full):
1498  */
1499 void
1500 gi_marshalling_tests_array_struct_take_in (GIMarshallingTestsBoxedStruct **structs, gint length)
1501 {
1502   gi_marshalling_tests_array_struct_in (structs, length);
1503
1504   /* only really useful if run in valgrind actually */
1505   gi_marshalling_tests_boxed_struct_free (structs[0]);
1506   gi_marshalling_tests_boxed_struct_free (structs[1]);
1507   gi_marshalling_tests_boxed_struct_free (structs[2]);
1508   g_free (structs);
1509 }
1510
1511 /**
1512  * gi_marshalling_tests_array_enum_in:
1513  * @_enum: (array length=length) (transfer none):
1514  * @length:
1515  */
1516 void
1517 gi_marshalling_tests_array_enum_in (GIMarshallingTestsEnum *v, gint length)
1518 {
1519   g_assert_cmpint (length, ==, 3);
1520   g_assert_cmpint (v[0], ==, GI_MARSHALLING_TESTS_ENUM_VALUE1);
1521   g_assert_cmpint (v[1], ==, GI_MARSHALLING_TESTS_ENUM_VALUE2);
1522   g_assert_cmpint (v[2], ==, GI_MARSHALLING_TESTS_ENUM_VALUE3);
1523 }
1524
1525 /**
1526  * gi_marshalling_tests_array_in_guint64_len:
1527  * @ints: (array length=length) (transfer none):
1528  * @length:
1529  */
1530 void
1531 gi_marshalling_tests_array_in_guint64_len (const gint *ints, guint64 length)
1532 {
1533   g_assert_cmpint (length, ==, 4);
1534
1535   gi_marshalling_tests_array_in (ints, length);
1536 }
1537
1538 /**
1539  * gi_marshalling_tests_array_in_guint8_len:
1540  * @ints: (array length=length) (transfer none):
1541  * @length:
1542  */
1543 void
1544 gi_marshalling_tests_array_in_guint8_len (const gint *ints, guint8 length)
1545 {
1546   g_assert_cmpint (length, ==, 4);
1547
1548   gi_marshalling_tests_array_in (ints, length);
1549 }
1550
1551 /**
1552  * gi_marshalling_tests_array_out:
1553  * @ints: (out) (array length=length) (transfer none):
1554  */
1555 void
1556 gi_marshalling_tests_array_out (gint **ints, gint *length)
1557 {
1558   static gint values[] = { -1, 0, 1, 2 };
1559
1560   *length = 4;
1561   *ints = values;
1562 }
1563
1564 /**
1565  * gi_marshalling_tests_array_out_etc:
1566  * @first:
1567  * @ints: (out) (array length=length) (transfer none):
1568  * @length: (out):
1569  * @last:
1570  * @sum: (out):
1571  */
1572 void
1573 gi_marshalling_tests_array_out_etc (gint first, gint **ints, gint *length, gint last, gint *sum)
1574 {
1575   static gint values[] = { -1, 0, 1, 2 };
1576
1577   values[0] = first;
1578   values[3] = last;
1579   *sum = first + last;
1580   *length = 4;
1581   *ints = values;
1582 }
1583
1584 /**
1585  * gi_marshalling_tests_array_bool_out:
1586  * @bools: (out) (array length=length) (transfer none):
1587  */
1588 void
1589 gi_marshalling_tests_array_bool_out (const gboolean **bools, gint *length)
1590 {
1591   static const gboolean values[] = { TRUE, FALSE, TRUE, TRUE };
1592
1593   *length = 4;
1594   *bools = values;
1595 }
1596
1597 /**
1598  * gi_marshalling_tests_array_unichar_out:
1599  * @chars: (out) (array length=length) (transfer none):
1600  */
1601 void
1602 gi_marshalling_tests_array_unichar_out (const gunichar **chars, gint *length)
1603 {
1604   static const gunichar values[] = GI_MARSHALLING_TESTS_CONSTANT_UCS4;
1605   *length = 12;
1606   *chars = values;
1607 }
1608
1609 /**
1610  * gi_marshalling_tests_array_inout:
1611  * @ints: (inout) (array length=length) (transfer none):
1612  * @length: (inout):
1613  */
1614 void
1615 gi_marshalling_tests_array_inout (gint **ints, gint *length)
1616 {
1617   static gint values[] = { -2, -1, 0, 1, 2 };
1618
1619   g_assert_cmpint (*length, ==, 4);
1620   g_assert_cmpint ((*ints)[0], ==, -1);
1621   g_assert_cmpint ((*ints)[1], ==, 0);
1622   g_assert_cmpint ((*ints)[2], ==, 1);
1623   g_assert_cmpint ((*ints)[3], ==, 2);
1624
1625   *length = 5;
1626   *ints = values;
1627 }
1628
1629 /**
1630  * gi_marshalling_tests_array_inout_etc:
1631  * @first:
1632  * @ints: (inout) (array length=length) (transfer none):
1633  * @length: (inout):
1634  * @last:
1635  * @sum: (out):
1636  */
1637 void
1638 gi_marshalling_tests_array_inout_etc (gint first, gint **ints, gint *length, gint last, gint *sum)
1639 {
1640   static gint values[] = { -2, -1, 0, 1, 2 };
1641
1642   g_assert_cmpint (*length, ==, 4);
1643   g_assert_cmpint ((*ints)[0], ==, -1);
1644   g_assert_cmpint ((*ints)[1], ==, 0);
1645   g_assert_cmpint ((*ints)[2], ==, 1);
1646   g_assert_cmpint ((*ints)[3], ==, 2);
1647
1648   values[0] = first;
1649   values[4] = last;
1650   *sum = first + last;
1651   *length = 5;
1652   *ints = values;
1653 }
1654
1655 /**
1656  * gi_marshalling_tests_array_in_nonzero_nonlen:
1657  * @first:
1658  * @chars: (array):
1659  */
1660 void
1661 gi_marshalling_tests_array_in_nonzero_nonlen (gint          first G_GNUC_UNUSED,
1662                                               const guint8 *chars)
1663 {
1664   g_assert (chars[0] == 'a');
1665   g_assert (chars[1] == 'b');
1666   g_assert (chars[2] == 'c');
1667   g_assert (chars[3] == 'd');
1668 }
1669
1670 /**
1671  * gi_marshalling_tests_array_zero_terminated_return:
1672  *
1673  * Returns: (array zero-terminated) (transfer none):
1674  */
1675 const gchar **
1676 gi_marshalling_tests_array_zero_terminated_return (void)
1677 {
1678   static const gchar *values[] = { "0", "1", "2", NULL };
1679   return values;
1680 }
1681
1682 /**
1683  * gi_marshalling_tests_array_zero_terminated_return_null:
1684  *
1685  * Returns: (array zero-terminated) (transfer none):
1686  */
1687 gchar **
1688 gi_marshalling_tests_array_zero_terminated_return_null (void)
1689 {
1690   return NULL;
1691 }
1692
1693 /**
1694  * gi_marshalling_tests_array_zero_terminated_return_struct:
1695  *
1696  * Returns: (array zero-terminated) (transfer full):
1697  */
1698 GIMarshallingTestsBoxedStruct **
1699 gi_marshalling_tests_array_zero_terminated_return_struct (void)
1700 {
1701   GIMarshallingTestsBoxedStruct **ret = (GIMarshallingTestsBoxedStruct **) g_new (gpointer, 4);
1702
1703   ret[0] = gi_marshalling_tests_boxed_struct_new ();
1704   ret[0]->long_ = 42;
1705
1706   ret[1] = gi_marshalling_tests_boxed_struct_new ();
1707   ret[1]->long_ = 43;
1708
1709   ret[2] = gi_marshalling_tests_boxed_struct_new ();
1710   ret[2]->long_ = 44;
1711
1712   ret[3] = NULL;
1713
1714   return ret;
1715 }
1716
1717 /**
1718  * gi_marshalling_tests_array_zero_terminated_return_unichar:
1719  *
1720  * Returns: (array zero-terminated) (transfer full):
1721  */
1722 gunichar *
1723 gi_marshalling_tests_array_zero_terminated_return_unichar (void)
1724 {
1725   static const gunichar value[] = GI_MARSHALLING_TESTS_CONSTANT_UCS4;
1726   gunichar *retval = g_new0(gunichar, 13);
1727   memcpy (retval, value, 12 * sizeof (gunichar));
1728   return retval;
1729 }
1730
1731 /**
1732  * gi_marshalling_tests_array_zero_terminated_in:
1733  * @utf8s: (array zero-terminated) (transfer none):
1734  */
1735 void
1736 gi_marshalling_tests_array_zero_terminated_in (gchar **utf8s)
1737 {
1738   g_assert (g_strv_length (utf8s));
1739   g_assert_cmpstr (utf8s[0], ==, "0");
1740   g_assert_cmpstr (utf8s[1], ==, "1");
1741   g_assert_cmpstr (utf8s[2], ==, "2");
1742 }
1743
1744 /**
1745  * gi_marshalling_tests_array_zero_terminated_out:
1746  * @utf8s: (out) (array zero-terminated) (transfer none):
1747  */
1748 void
1749 gi_marshalling_tests_array_zero_terminated_out (const gchar ***utf8s)
1750 {
1751   static const gchar *values[] = { "0", "1", "2", NULL };
1752   *utf8s = values;
1753 }
1754
1755 /**
1756  * gi_marshalling_tests_array_zero_terminated_inout:
1757  * @utf8s: (inout) (array zero-terminated) (transfer none):
1758  */
1759 void
1760 gi_marshalling_tests_array_zero_terminated_inout (const gchar ***utf8s)
1761 {
1762   static const gchar *values[] = { "-1", "0", "1", "2", NULL };
1763
1764   g_assert (g_strv_length ((gchar **) (*utf8s)));
1765   g_assert_cmpstr ((*utf8s)[0], ==, "0");
1766   g_assert_cmpstr ((*utf8s)[1], ==, "1");
1767   g_assert_cmpstr ((*utf8s)[2], ==, "2");
1768
1769   *utf8s = values;
1770 }
1771
1772 /**
1773  * gi_marshalling_tests_array_gvariant_none_in:
1774  * @variants: (array zero-terminated) (transfer none):
1775  *
1776  * Returns: (array zero-terminated) (transfer none):
1777  */
1778 GVariant **
1779 gi_marshalling_tests_array_gvariant_none_in (GVariant **variants)
1780 {
1781   /* Use a static container to detect if someone tries to free it */
1782   static GVariant *private_container[3] = { NULL, NULL, NULL };
1783
1784   if (private_container[0] == NULL)
1785     {
1786       private_container[0] = g_variant_new_int32 (27);
1787       private_container[1] = g_variant_new_string ("Hello");
1788     }
1789
1790   g_assert (variants != NULL);
1791   g_assert_cmpint (g_variant_get_int32 (variants[0]), ==, 27);
1792   g_assert_cmpstr (g_variant_get_string (variants[1], NULL), ==, "Hello");
1793   g_assert (variants[2] == NULL);
1794
1795   return private_container;
1796 }
1797
1798 /**
1799  * gi_marshalling_tests_array_gvariant_container_in:
1800  * @variants: (array zero-terminated) (transfer container):
1801  *
1802  * Returns: (array zero-terminated) (transfer container):
1803  */
1804 GVariant **
1805 gi_marshalling_tests_array_gvariant_container_in (GVariant **variants)
1806 {
1807   GVariant **container;
1808
1809   g_assert (variants != NULL);
1810   g_assert_cmpint (g_variant_get_int32 (variants[0]), ==, 27);
1811   g_assert_cmpstr (g_variant_get_string (variants[1], NULL), ==, "Hello");
1812   g_assert (variants[2] == NULL);
1813
1814   container = g_new0 (GVariant *, 3);
1815   container[0] = variants[0];
1816   container[1] = variants[1];
1817   g_free (variants);
1818
1819   return container;
1820 }
1821
1822 /**
1823  * gi_marshalling_tests_array_gvariant_full_in:
1824  * @variants: (array zero-terminated) (transfer full):
1825  *
1826  * Returns: (array zero-terminated) (transfer full):
1827  */
1828 GVariant **
1829 gi_marshalling_tests_array_gvariant_full_in (GVariant **variants)
1830 {
1831   GVariant **container;
1832
1833   g_assert (variants != NULL);
1834   g_assert_cmpint (g_variant_get_int32 (variants[0]), ==, 27);
1835   g_assert_cmpstr (g_variant_get_string (variants[1], NULL), ==, "Hello");
1836   g_assert (variants[2] == NULL);
1837
1838   /* To catch different behaviors we reconstruct one variant from scratch,
1839    * while leaving the other untouched. Both approaches are legal with full
1840    * transfer in and out */
1841   container = g_new0 (GVariant *, 3);
1842   container[0] = g_variant_new_int32 (g_variant_get_int32 (variants[0]));
1843   g_variant_unref (variants[0]);
1844   container[1] = variants[1];
1845   g_free (variants);
1846
1847   return container;
1848 }
1849
1850 /**
1851  * gi_marshalling_tests_garray_int_none_return:
1852  *
1853  * Returns: (element-type gint) (transfer none):
1854  */
1855 GArray *
1856 gi_marshalling_tests_garray_int_none_return (void)
1857 {
1858   static GArray *v = NULL;
1859   gint i;
1860
1861   if (v == NULL)
1862     {
1863       v = g_array_new (TRUE, TRUE, sizeof (gint));
1864       for (i = -1; i < 3; i++)
1865         g_array_append_val (v, i);
1866     }
1867
1868   return v;
1869 }
1870
1871 /**
1872  * gi_marshalling_tests_garray_uint64_none_return:
1873  *
1874  * Returns: (element-type guint64) (transfer none):
1875  */
1876 GArray *
1877 gi_marshalling_tests_garray_uint64_none_return (void)
1878 {
1879   static GArray *array = NULL;
1880   guint64 i;
1881
1882   if (array == NULL)
1883     {
1884       array = g_array_new (TRUE, TRUE, sizeof (guint64));
1885       i = 0;
1886       g_array_append_val (array, i);
1887       i = G_MAXUINT64;
1888       g_array_append_val (array, i);
1889     }
1890
1891   return array;
1892 }
1893
1894 /**
1895  * gi_marshalling_tests_garray_utf8_none_return:
1896  *
1897  * Returns: (element-type utf8) (transfer none):
1898  */
1899 GArray *
1900 gi_marshalling_tests_garray_utf8_none_return (void)
1901 {
1902   static GArray *array = NULL;
1903   static const gchar *values[] = { "0", "1", "2", NULL };
1904   gint i;
1905
1906   if (array == NULL)
1907     {
1908       array = g_array_new (TRUE, TRUE, sizeof (gchar *));
1909       for (i = 0; values[i]; i++)
1910         g_array_append_val (array, values[i]);
1911     }
1912
1913   return array;
1914 }
1915
1916 /**
1917  * gi_marshalling_tests_garray_utf8_container_return:
1918  *
1919  * Returns: (element-type utf8) (transfer container):
1920  */
1921 GArray *
1922 gi_marshalling_tests_garray_utf8_container_return (void)
1923 {
1924   GArray *array = NULL;
1925   static const gchar *values[] = { "0", "1", "2", NULL };
1926   gint i;
1927
1928   array = g_array_new (TRUE, TRUE, sizeof (gchar *));
1929   for (i = 0; values[i]; i++)
1930     g_array_append_val (array, values[i]);
1931
1932   return array;
1933 }
1934
1935 /**
1936  * gi_marshalling_tests_garray_utf8_full_return:
1937  *
1938  * Returns: (element-type utf8) (transfer full):
1939  */
1940 GArray *
1941 gi_marshalling_tests_garray_utf8_full_return (void)
1942 {
1943   GArray *array = NULL;
1944   static const gchar *values[] = { "0", "1", "2", NULL };
1945   gint i;
1946
1947   array = g_array_new (TRUE, TRUE, sizeof (gchar *));
1948   for (i = 0; values[i]; i++)
1949     {
1950       gchar *str = g_strdup (values[i]);
1951       g_array_append_val (array, str);
1952     }
1953
1954   return array;
1955 }
1956
1957 /**
1958  * gi_marshalling_tests_garray_boxed_struct_full_return:
1959  *
1960  * Returns: (element-type GIMarshallingTestsBoxedStruct) (transfer full):
1961  */
1962 GArray *
1963 gi_marshalling_tests_garray_boxed_struct_full_return (void)
1964 {
1965   GArray *array = NULL;
1966   static const glong long_values[] = { 42, 43, 44 };
1967   gint i;
1968
1969   array = g_array_new (TRUE, TRUE, sizeof (GIMarshallingTestsBoxedStruct));
1970   for (i = 0; i < 3; i++)
1971     {
1972       GIMarshallingTestsBoxedStruct *new_struct = gi_marshalling_tests_boxed_struct_new ();
1973       new_struct->long_ = long_values[i];
1974       g_array_append_val (array, *new_struct);
1975     }
1976
1977   return array;
1978 }
1979
1980 /**
1981  * gi_marshalling_tests_garray_int_none_in:
1982  * @array_: (element-type gint) (transfer none):
1983  */
1984 void
1985 gi_marshalling_tests_garray_int_none_in (GArray *array_)
1986 {
1987   g_assert_cmpint (array_->len, ==, 4);
1988   g_assert_cmpint (g_array_index (array_, gint, 0), ==, -1);
1989   g_assert_cmpint (g_array_index (array_, gint, 1), ==, 0);
1990   g_assert_cmpint (g_array_index (array_, gint, 2), ==, 1);
1991   g_assert_cmpint (g_array_index (array_, gint, 3), ==, 2);
1992 }
1993
1994 /**
1995  * gi_marshalling_tests_garray_uint64_none_in:
1996  * @array_: (element-type guint64) (transfer none):
1997  */
1998 void
1999 gi_marshalling_tests_garray_uint64_none_in (GArray *array_)
2000 {
2001   g_assert_cmpint (array_->len, ==, 2);
2002   g_assert_cmpint (g_array_index (array_, guint64, 0), ==, 0);
2003   g_assert_cmpint (g_array_index (array_, guint64, 1), ==, G_MAXUINT64);
2004 }
2005
2006 /**
2007  * gi_marshalling_tests_garray_utf8_none_in:
2008  * @array_: (element-type utf8) (transfer none):
2009  */
2010 void
2011 gi_marshalling_tests_garray_utf8_none_in (GArray *array_)
2012 {
2013   g_assert_cmpint (array_->len, ==, 3);
2014   g_assert_cmpstr (g_array_index (array_, gchar *, 0), ==, "0");
2015   g_assert_cmpstr (g_array_index (array_, gchar *, 1), ==, "1");
2016   g_assert_cmpstr (g_array_index (array_, gchar *, 2), ==, "2");
2017 }
2018
2019 /**
2020  * gi_marshalling_tests_garray_utf8_none_out:
2021  * @array_: (out) (element-type utf8) (transfer none):
2022  */
2023 void
2024 gi_marshalling_tests_garray_utf8_none_out (GArray **array_)
2025 {
2026   static GArray *internal = NULL;
2027   static const gchar *values[] = { "0", "1", "2", NULL };
2028   gint i;
2029
2030   if (internal == NULL)
2031     {
2032       internal = g_array_new (TRUE, TRUE, sizeof (gchar *));
2033       for (i = 0; values[i]; i++)
2034         g_array_append_val (internal, values[i]);
2035     }
2036
2037   *array_ = internal;
2038 }
2039
2040 /**
2041  * gi_marshalling_tests_garray_utf8_container_out:
2042  * @array_: (out) (element-type utf8) (transfer container):
2043  */
2044 void
2045 gi_marshalling_tests_garray_utf8_container_out (GArray **array_)
2046 {
2047   static const gchar *values[] = { "0", "1", "2", NULL };
2048   gint i;
2049
2050   *array_ = NULL;
2051
2052   *array_ = g_array_new (TRUE, TRUE, sizeof (gchar *));
2053   for (i = 0; values[i]; i++)
2054     g_array_append_val (*array_, values[i]);
2055 }
2056
2057 /**
2058  * gi_marshalling_tests_garray_utf8_full_out:
2059  * @array_: (out) (element-type utf8) (transfer full):
2060  */
2061 void
2062 gi_marshalling_tests_garray_utf8_full_out (GArray **array_)
2063 {
2064   static const gchar *values[] = { "0", "1", "2", NULL };
2065   gint i;
2066
2067   *array_ = NULL;
2068
2069   *array_ = g_array_new (TRUE, TRUE, sizeof (gchar *));
2070   for (i = 0; values[i]; i++)
2071     {
2072       gchar *str = g_strdup (values[i]);
2073       g_array_append_val (*array_, str);
2074     }
2075 }
2076
2077 /**
2078  * gi_marshalling_tests_garray_utf8_full_out_caller_allocated:
2079  * @array_: (out caller-allocates) (array) (element-type utf8) (transfer full):
2080  */
2081 void
2082 gi_marshalling_tests_garray_utf8_full_out_caller_allocated (GArray *array_)
2083 {
2084   static const gchar *values[] = { "0", "1", "2", NULL };
2085   gint i;
2086
2087   g_array_set_size (array_, 0);
2088   for (i = 0; values[i]; i++)
2089     {
2090       gchar *str = g_strdup (values[i]);
2091       g_array_append_val (array_, str);
2092     }
2093 }
2094
2095 /**
2096  * gi_marshalling_tests_garray_utf8_none_inout:
2097  * @array_: (inout) (element-type utf8) (transfer none):
2098  */
2099 void
2100 gi_marshalling_tests_garray_utf8_none_inout (GArray **array_)
2101 {
2102   static GArray *internal = NULL;
2103   static const gchar *values[] = { "-2", "-1", "0", "1", NULL };
2104   gint i;
2105
2106   g_assert_cmpint ((*array_)->len, ==, 3);
2107   g_assert_cmpstr (g_array_index (*array_, gchar *, 0), ==, "0");
2108   g_assert_cmpstr (g_array_index (*array_, gchar *, 1), ==, "1");
2109   g_assert_cmpstr (g_array_index (*array_, gchar *, 2), ==, "2");
2110
2111   if (internal == NULL)
2112     {
2113       internal = g_array_new (TRUE, TRUE, sizeof (gchar *));
2114       for (i = 0; values[i]; i++)
2115         g_array_append_val (internal, values[i]);
2116     }
2117
2118   *array_ = internal;
2119 }
2120
2121 /**
2122  * gi_marshalling_tests_garray_utf8_container_inout:
2123  * @array_: (inout) (element-type utf8) (transfer container):
2124  */
2125 void
2126 gi_marshalling_tests_garray_utf8_container_inout (GArray **array_)
2127 {
2128   static const gchar *val1 = "-2";
2129   static const gchar *val2 = "-1";
2130   static const gchar *val3 = "0";
2131   static const gchar *val4 = "1";
2132   GArray *result;
2133
2134   g_assert_cmpint ((*array_)->len, ==, 3);
2135   g_assert_cmpstr (g_array_index (*array_, gchar *, 0), ==, "0");
2136   g_assert_cmpstr (g_array_index (*array_, gchar *, 1), ==, "1");
2137   g_assert_cmpstr (g_array_index (*array_, gchar *, 2), ==, "2");
2138
2139   result = g_array_new (TRUE, TRUE, sizeof (gchar *));
2140   g_array_append_val (result, val1);
2141   g_array_append_val (result, val2);
2142   g_array_append_val (result, val3);
2143   g_array_append_val (result, val4);
2144
2145   g_array_unref (*array_);
2146   *array_ = result;
2147 }
2148
2149 /**
2150  * gi_marshalling_tests_garray_utf8_full_inout:
2151  * @array_: (inout) (element-type utf8) (transfer full):
2152  */
2153 void
2154 gi_marshalling_tests_garray_utf8_full_inout (GArray **array_)
2155 {
2156   static const gchar *val1 = "-1";
2157   static const gchar *val2 = "-2";
2158   gchar *val;
2159   GArray *result;
2160
2161   g_assert_cmpint ((*array_)->len, ==, 3);
2162   g_assert_cmpstr (g_array_index (*array_, gchar *, 0), ==, "0");
2163   g_assert_cmpstr (g_array_index (*array_, gchar *, 1), ==, "1");
2164   g_assert_cmpstr (g_array_index (*array_, gchar *, 2), ==, "2");
2165
2166   result = g_array_new (TRUE, TRUE, sizeof (gchar *));
2167   val = g_strdup (val2);
2168   g_array_append_val (result, val);
2169   val = g_strdup (val1);
2170   g_array_append_val (result, val);
2171   val = g_strdup ("0");
2172   g_array_append_val (result, val);
2173   val = g_strdup ("1");
2174   g_array_append_val (result, val);
2175
2176   g_array_unref (*array_);
2177   *array_ = result;
2178 }
2179
2180 /**
2181  * gi_marshalling_tests_garray_bool_none_in:
2182  * @array_: (element-type gboolean) (transfer none):
2183  */
2184 void
2185 gi_marshalling_tests_garray_bool_none_in (GArray *array_)
2186 {
2187   g_assert_cmpint (array_->len, ==, 4);
2188   g_assert_cmpint (g_array_index (array_, gboolean, 0), ==, TRUE);
2189   g_assert_cmpint (g_array_index (array_, gboolean, 1), ==, FALSE);
2190   g_assert_cmpint (g_array_index (array_, gboolean, 2), ==, TRUE);
2191   g_assert_cmpint (g_array_index (array_, gboolean, 3), ==, TRUE);
2192 }
2193
2194 /**
2195  * gi_marshalling_tests_garray_unichar_none_in:
2196  * @array_: (element-type gunichar) (transfer none):
2197  */
2198 void
2199 gi_marshalling_tests_garray_unichar_none_in (GArray *array_)
2200 {
2201   unsigned ix;
2202   static const gunichar expected[] = GI_MARSHALLING_TESTS_CONSTANT_UCS4;
2203   g_assert_cmpint (array_->len, ==, 12);
2204   for (ix = 0; ix < array_->len; ix++)
2205     g_assert_cmpuint (g_array_index (array_, gunichar, ix), ==, expected[ix]);
2206 }
2207
2208 /**
2209  * gi_marshalling_tests_gptrarray_utf8_none_return:
2210  *
2211  * Returns: (element-type utf8) (transfer none):
2212  */
2213 GPtrArray *
2214 gi_marshalling_tests_gptrarray_utf8_none_return (void)
2215 {
2216   static GPtrArray *parray = NULL;
2217   static const gchar *values[] = { "0", "1", "2" };
2218   gint i;
2219
2220   if (parray == NULL)
2221     {
2222       parray = g_ptr_array_new ();
2223       for (i = 0; i < 3; i++)
2224         g_ptr_array_add (parray, (gpointer) values[i]);
2225     }
2226
2227   return parray;
2228 }
2229
2230 /**
2231  * gi_marshalling_tests_gptrarray_utf8_container_return:
2232  *
2233  * Returns: (element-type utf8) (transfer container):
2234  */
2235 GPtrArray *
2236 gi_marshalling_tests_gptrarray_utf8_container_return (void)
2237 {
2238   GPtrArray *parray = NULL;
2239   static const gchar *values[] = { "0", "1", "2", NULL };
2240   gint i;
2241
2242   parray = g_ptr_array_new ();
2243   for (i = 0; values[i]; i++)
2244     g_ptr_array_add (parray, (gpointer) values[i]);
2245
2246   return parray;
2247 }
2248
2249 /**
2250  * gi_marshalling_tests_gptrarray_utf8_full_return:
2251  *
2252  * Returns: (element-type utf8) (transfer full):
2253  */
2254 GPtrArray *
2255 gi_marshalling_tests_gptrarray_utf8_full_return (void)
2256 {
2257   GPtrArray *parray = NULL;
2258   static const gchar *values[] = { "0", "1", "2", NULL };
2259   gint i;
2260
2261   parray = g_ptr_array_new ();
2262   for (i = 0; values[i]; i++)
2263     {
2264       gchar *str = g_strdup (values[i]);
2265       g_ptr_array_add (parray, (gpointer) str);
2266     }
2267
2268   return parray;
2269 }
2270
2271 /**
2272  * gi_marshalling_tests_gptrarray_boxed_struct_full_return:
2273  *
2274  * Returns: (element-type GIMarshallingTestsBoxedStruct) (transfer full):
2275  */
2276 GPtrArray *
2277 gi_marshalling_tests_gptrarray_boxed_struct_full_return (void)
2278 {
2279   GPtrArray *parray = NULL;
2280   static const glong long_values[] = { 42, 43, 44 };
2281   gint i;
2282
2283   parray = g_ptr_array_new ();
2284   for (i = 0; i < 3; i++)
2285     {
2286       GIMarshallingTestsBoxedStruct *new_struct = gi_marshalling_tests_boxed_struct_new ();
2287       new_struct->long_ = long_values[i];
2288       g_ptr_array_add (parray, (gpointer) new_struct);
2289     }
2290
2291   return parray;
2292 }
2293
2294 /**
2295  * gi_marshalling_tests_gptrarray_utf8_none_in:
2296  * @parray_: (element-type utf8) (transfer none):
2297  */
2298 void
2299 gi_marshalling_tests_gptrarray_utf8_none_in (GPtrArray *parray_)
2300 {
2301   g_assert_cmpint (parray_->len, ==, 3);
2302   g_assert_cmpstr (g_ptr_array_index (parray_, 0), ==, "0");
2303   g_assert_cmpstr (g_ptr_array_index (parray_, 1), ==, "1");
2304   g_assert_cmpstr (g_ptr_array_index (parray_, 2), ==, "2");
2305 }
2306
2307 /**
2308  * gi_marshalling_tests_gptrarray_utf8_none_out:
2309  * @parray_: (out) (element-type utf8) (transfer none):
2310  */
2311 void
2312 gi_marshalling_tests_gptrarray_utf8_none_out (GPtrArray **parray_)
2313 {
2314   static GPtrArray *internal = NULL;
2315   static const gchar *values[] = { "0", "1", "2", NULL };
2316   gint i;
2317
2318   if (internal == NULL)
2319     {
2320       internal = g_ptr_array_new ();
2321       for (i = 0; values[i]; i++)
2322         g_ptr_array_add (internal, (gpointer) values[i]);
2323     }
2324
2325   *parray_ = internal;
2326 }
2327
2328 /**
2329  * gi_marshalling_tests_gptrarray_utf8_container_out:
2330  * @parray_: (out) (element-type utf8) (transfer container):
2331  */
2332 void
2333 gi_marshalling_tests_gptrarray_utf8_container_out (GPtrArray **parray_)
2334 {
2335   static const gchar *values[] = { "0", "1", "2", NULL };
2336   gint i;
2337
2338   *parray_ = NULL;
2339
2340   *parray_ = g_ptr_array_new ();
2341   for (i = 0; values[i]; i++)
2342     g_ptr_array_add (*parray_, (gpointer) values[i]);
2343 }
2344
2345 /**
2346  * gi_marshalling_tests_gptrarray_utf8_full_out:
2347  * @parray_: (out) (element-type utf8) (transfer full):
2348  */
2349 void
2350 gi_marshalling_tests_gptrarray_utf8_full_out (GPtrArray **parray_)
2351 {
2352   static const gchar *values[] = { "0", "1", "2", NULL };
2353   gint i;
2354
2355   *parray_ = NULL;
2356
2357   *parray_ = g_ptr_array_new ();
2358   for (i = 0; values[i]; i++)
2359     {
2360       gchar *str = g_strdup (values[i]);
2361       g_ptr_array_add (*parray_, (gpointer) str);
2362     }
2363 }
2364
2365 /**
2366  * gi_marshalling_tests_gptrarray_utf8_none_inout:
2367  * @parray_: (inout) (element-type utf8) (transfer none):
2368  */
2369 void
2370 gi_marshalling_tests_gptrarray_utf8_none_inout (GPtrArray **parray_)
2371 {
2372   static GPtrArray *internal = NULL;
2373   static const gchar *values[] = { "-2", "-1", "0", "1", NULL };
2374   gint i;
2375
2376   g_assert_cmpint ((*parray_)->len, ==, 3);
2377   g_assert_cmpstr (g_ptr_array_index (*parray_, 0), ==, "0");
2378   g_assert_cmpstr (g_ptr_array_index (*parray_, 1), ==, "1");
2379   g_assert_cmpstr (g_ptr_array_index (*parray_, 2), ==, "2");
2380
2381   if (internal == NULL)
2382     {
2383       internal = g_ptr_array_new ();
2384       for (i = 0; values[i]; i++)
2385         g_ptr_array_add (internal, (gpointer) values[i]);
2386     }
2387
2388   *parray_ = internal;
2389 }
2390
2391 /**
2392  * gi_marshalling_tests_gptrarray_utf8_container_inout:
2393  * @parray_: (inout) (element-type utf8) (transfer container):
2394  */
2395 void
2396 gi_marshalling_tests_gptrarray_utf8_container_inout (GPtrArray **parray_)
2397 {
2398   static const gchar *val1 = "-2";
2399   static const gchar *val2 = "-1";
2400   static const gchar *val3 = "0";
2401   static const gchar *val4 = "1";
2402   GPtrArray *result;
2403
2404   g_assert_cmpint ((*parray_)->len, ==, 3);
2405   g_assert_cmpstr (g_ptr_array_index (*parray_, 0), ==, "0");
2406   g_assert_cmpstr (g_ptr_array_index (*parray_, 1), ==, "1");
2407   g_assert_cmpstr (g_ptr_array_index (*parray_, 2), ==, "2");
2408
2409   result = g_ptr_array_new ();
2410   g_ptr_array_add (result, (gpointer) val1);
2411   g_ptr_array_add (result, (gpointer) val2);
2412   g_ptr_array_add (result, (gpointer) val3);
2413   g_ptr_array_add (result, (gpointer) val4);
2414
2415   g_ptr_array_unref (*parray_);
2416   *parray_ = result;
2417 }
2418
2419 /**
2420  * gi_marshalling_tests_gptrarray_utf8_full_inout:
2421  * @parray_: (inout) (element-type utf8) (transfer full):
2422  */
2423 void
2424 gi_marshalling_tests_gptrarray_utf8_full_inout (GPtrArray **parray_)
2425 {
2426   static const gchar *val1 = "-1";
2427   static const gchar *val2 = "-2";
2428   gchar *val;
2429   GPtrArray *result;
2430
2431   g_assert_cmpint ((*parray_)->len, ==, 3);
2432   g_assert_cmpstr (g_ptr_array_index (*parray_, 0), ==, "0");
2433   g_assert_cmpstr (g_ptr_array_index (*parray_, 1), ==, "1");
2434   g_assert_cmpstr (g_ptr_array_index (*parray_, 2), ==, "2");
2435
2436   result = g_ptr_array_new ();
2437   val = g_strdup (val2);
2438   g_ptr_array_add (result, (gpointer) val);
2439   val = g_strdup (val1);
2440   g_ptr_array_add (result, (gpointer) val);
2441   val = g_strdup ("0");
2442   g_ptr_array_add (result, (gpointer) val);
2443   val = g_strdup ("1");
2444   g_ptr_array_add (result, (gpointer) val);
2445
2446   g_ptr_array_unref (*parray_);
2447   *parray_ = result;
2448 }
2449
2450 /**
2451  * gi_marshalling_tests_bytearray_full_return:
2452  *
2453  * Returns: (transfer full):
2454  */
2455 GByteArray *
2456 gi_marshalling_tests_bytearray_full_return (void)
2457 {
2458   GByteArray *array = NULL;
2459   guint8 data[] = { '\0', '1', '\xFF', '3' };
2460
2461   array = g_byte_array_new ();
2462   g_byte_array_append (array, (const guint8 *) data, G_N_ELEMENTS (data));
2463
2464   return array;
2465
2466 }
2467
2468 /**
2469  * gi_marshalling_tests_bytearray_none_in:
2470  * @v: (element-type gint8) (transfer none):
2471  */
2472 void
2473 gi_marshalling_tests_bytearray_none_in (GByteArray *v)
2474 {
2475   g_assert_cmpuint (v->len, ==, 4);
2476   g_assert_cmpuint (g_array_index (v, unsigned char, 0), ==, 0);
2477   g_assert_cmpuint (g_array_index (v, unsigned char, 1), ==, 49);
2478   g_assert_cmpuint (g_array_index (v, unsigned char, 2), ==, 0xFF);
2479   g_assert_cmpuint (g_array_index (v, unsigned char, 3), ==, 51);
2480 }
2481
2482 /**
2483  * gi_marshalling_tests_gbytes_full_return:
2484  *
2485  * Returns: (transfer full):
2486  */
2487 GBytes *
2488 gi_marshalling_tests_gbytes_full_return (void)
2489 {
2490   static guint8 data[] = { 0, 49, 0xFF, 51 };
2491
2492   return g_bytes_new_static (data, G_N_ELEMENTS (data));
2493 }
2494
2495 /**
2496  * gi_marshalling_tests_gbytes_none_in:
2497  */
2498 void
2499 gi_marshalling_tests_gbytes_none_in (GBytes *v)
2500 {
2501   const guint8 *data;
2502   gsize len;
2503   data = g_bytes_get_data (v, &len);
2504
2505   g_assert_cmpuint (len, ==, 4);
2506   g_assert_cmpuint (data[0], ==, 0);
2507   g_assert_cmpuint (data[1], ==, 49);
2508   g_assert_cmpuint (data[2], ==, 0xFF);
2509   g_assert_cmpuint (data[3], ==, 51);
2510 }
2511
2512 /**
2513  * gi_marshalling_tests_gstrv_return:
2514  *
2515  * Returns: (transfer full): an array of strings
2516  */
2517 GStrv
2518 gi_marshalling_tests_gstrv_return (void)
2519 {
2520   GStrv values = g_new0 (gchar *, 4);
2521   values[0] = g_strdup ("0");
2522   values[1] = g_strdup ("1");
2523   values[2] = g_strdup ("2");
2524   values[3] = NULL;
2525   return values;
2526 }
2527
2528 /**
2529  * gi_marshalling_tests_gstrv_in:
2530  * @g_strv:
2531  */
2532 void
2533 gi_marshalling_tests_gstrv_in (GStrv g_strv)
2534 {
2535   g_assert_cmpint (g_strv_length (g_strv), ==, 3);
2536   g_assert_cmpstr (g_strv[0], ==, "0");
2537   g_assert_cmpstr (g_strv[1], ==, "1");
2538   g_assert_cmpstr (g_strv[2], ==, "2");
2539 }
2540
2541 /**
2542  * gi_marshalling_tests_gstrv_out:
2543  * @g_strv: (out) (transfer none):
2544  */
2545 void
2546 gi_marshalling_tests_gstrv_out (GStrv *g_strv)
2547 {
2548   static const gchar *values[] = { "0", "1", "2", NULL };
2549   *g_strv = (gchar **) values;
2550 }
2551
2552 /**
2553  * gi_marshalling_tests_gstrv_inout:
2554  * @g_strv: (inout) (transfer none):
2555  */
2556 void
2557 gi_marshalling_tests_gstrv_inout (GStrv *g_strv)
2558 {
2559   static const gchar *values[] = { "-1", "0", "1", "2", NULL };
2560
2561   g_assert (g_strv_length (*g_strv) == 3);
2562   g_assert (strcmp ((*g_strv)[0], "0") == 0);
2563   g_assert (strcmp ((*g_strv)[1], "1") == 0);
2564   g_assert (strcmp ((*g_strv)[2], "2") == 0);
2565
2566   *g_strv = (gchar **) values;
2567 }
2568
2569 /**
2570  * gi_marshalling_tests_glist_int_none_return:
2571  *
2572  * Returns: (element-type gint) (transfer none):
2573  */
2574 GList *
2575 gi_marshalling_tests_glist_int_none_return (void)
2576 {
2577   static GList *list = NULL;
2578
2579   if (list == NULL)
2580     {
2581       list = g_list_append (list, GINT_TO_POINTER (-1));
2582       list = g_list_append (list, GINT_TO_POINTER (0));
2583       list = g_list_append (list, GINT_TO_POINTER (1));
2584       list = g_list_append (list, GINT_TO_POINTER (2));
2585     }
2586
2587   return list;
2588 }
2589
2590 /**
2591  * gi_marshalling_tests_glist_uint32_none_return:
2592  *
2593  * Returns: (element-type guint32) (transfer none):
2594  */
2595 GList *
2596 gi_marshalling_tests_glist_uint32_none_return (void)
2597 {
2598   static GList *list = NULL;
2599
2600   if (list == NULL)
2601     {
2602       list = g_list_append (list, GUINT_TO_POINTER (0));
2603       list = g_list_append (list, GUINT_TO_POINTER (G_MAXUINT32));
2604     }
2605
2606   return list;
2607 }
2608
2609 /**
2610  * gi_marshalling_tests_glist_utf8_none_return:
2611  *
2612  * Returns: (element-type utf8) (transfer none):
2613  */
2614 GList *
2615 gi_marshalling_tests_glist_utf8_none_return (void)
2616 {
2617   static GList *list = NULL;
2618
2619   if (list == NULL)
2620     {
2621       list = g_list_append (list, (gpointer) "0");
2622       list = g_list_append (list, (gpointer) "1");
2623       list = g_list_append (list, (gpointer) "2");
2624     }
2625
2626   return list;
2627 }
2628
2629 /**
2630  * gi_marshalling_tests_glist_utf8_container_return:
2631  *
2632  * Returns: (element-type utf8) (transfer container):
2633  */
2634 GList *
2635 gi_marshalling_tests_glist_utf8_container_return (void)
2636 {
2637   GList *list = NULL;
2638
2639   list = g_list_append (list, (gpointer) "0");
2640   list = g_list_append (list, (gpointer) "1");
2641   list = g_list_append (list, (gpointer) "2");
2642
2643   return list;
2644 }
2645
2646 /**
2647  * gi_marshalling_tests_glist_utf8_full_return:
2648  *
2649  * Returns: (element-type utf8) (transfer full):
2650  */
2651 GList *
2652 gi_marshalling_tests_glist_utf8_full_return (void)
2653 {
2654   GList *list = NULL;
2655
2656   list = g_list_append (list, g_strdup ("0"));
2657   list = g_list_append (list, g_strdup ("1"));
2658   list = g_list_append (list, g_strdup ("2"));
2659
2660   return list;
2661 }
2662
2663 /**
2664  * gi_marshalling_tests_glist_int_none_in:
2665  * @list: (element-type gint) (transfer none):
2666  */
2667 void
2668 gi_marshalling_tests_glist_int_none_in (GList *list)
2669 {
2670   g_assert_cmpint (g_list_length (list), ==, 4);
2671   g_assert_cmpint (GPOINTER_TO_INT (g_list_nth_data (list, 0)), ==, -1);
2672   g_assert_cmpint (GPOINTER_TO_INT (g_list_nth_data (list, 1)), ==, 0);
2673   g_assert_cmpint (GPOINTER_TO_INT (g_list_nth_data (list, 2)), ==, 1);
2674   g_assert_cmpint (GPOINTER_TO_INT (g_list_nth_data (list, 3)), ==, 2);
2675 }
2676
2677 /**
2678  * gi_marshalling_tests_glist_uint32_none_in:
2679  * @list: (element-type guint32) (transfer none):
2680  */
2681 void
2682 gi_marshalling_tests_glist_uint32_none_in (GList *list)
2683 {
2684   g_assert_cmpint (g_list_length (list), ==, 2);
2685   g_assert_cmpint (GPOINTER_TO_UINT (g_list_nth_data (list, 0)), ==, 0);
2686   g_assert_cmpint (GPOINTER_TO_UINT (g_list_nth_data (list, 1)), ==, G_MAXUINT32);
2687 }
2688
2689 /**
2690  * gi_marshalling_tests_glist_utf8_none_in:
2691  * @list: (element-type utf8) (transfer none):
2692  */
2693 void
2694 gi_marshalling_tests_glist_utf8_none_in (GList *list)
2695 {
2696   g_assert_cmpint (g_list_length (list), ==, 3);
2697   g_assert_cmpint (strcmp (g_list_nth_data (list, 0), "0"), ==, 0);
2698   g_assert_cmpint (strcmp (g_list_nth_data (list, 1), "1"), ==, 0);
2699   g_assert_cmpint (strcmp (g_list_nth_data (list, 2), "2"), ==, 0);
2700 }
2701
2702 /**
2703  * gi_marshalling_tests_glist_utf8_none_out:
2704  * @list: (out) (element-type utf8) (transfer none):
2705  */
2706 void
2707 gi_marshalling_tests_glist_utf8_none_out (GList **list)
2708 {
2709   static GList *values = NULL;
2710
2711   if (values == NULL)
2712     {
2713       values = g_list_append (values, (gpointer) "0");
2714       values = g_list_append (values, (gpointer) "1");
2715       values = g_list_append (values, (gpointer) "2");
2716     }
2717
2718   *list = values;
2719 }
2720
2721 /**
2722  * gi_marshalling_tests_glist_utf8_container_out:
2723  * @list: (out) (element-type utf8) (transfer container):
2724  */
2725 void
2726 gi_marshalling_tests_glist_utf8_container_out (GList **list)
2727 {
2728   *list = NULL;
2729
2730   *list = g_list_append (*list, (gpointer) "0");
2731   *list = g_list_append (*list, (gpointer) "1");
2732   *list = g_list_append (*list, (gpointer) "2");
2733 }
2734
2735 /**
2736  * gi_marshalling_tests_glist_utf8_full_out:
2737  * @list: (out) (element-type utf8) (transfer full):
2738  */
2739 void
2740 gi_marshalling_tests_glist_utf8_full_out (GList **list)
2741 {
2742   *list = NULL;
2743
2744   *list = g_list_append (*list, g_strdup ("0"));
2745   *list = g_list_append (*list, g_strdup ("1"));
2746   *list = g_list_append (*list, g_strdup ("2"));
2747 }
2748
2749 /**
2750  * gi_marshalling_tests_glist_utf8_none_inout:
2751  * @list: (inout) (element-type utf8) (transfer none):
2752  */
2753 void
2754 gi_marshalling_tests_glist_utf8_none_inout (GList **list)
2755 {
2756   static GList *values = NULL;
2757
2758   g_assert_cmpint (g_list_length (*list), ==, 3);
2759   g_assert_cmpstr (g_list_nth_data (*list, 0), ==, "0");
2760   g_assert_cmpstr (g_list_nth_data (*list, 1), ==, "1");
2761   g_assert_cmpstr (g_list_nth_data (*list, 2), ==, "2");
2762
2763   if (values == NULL)
2764     {
2765       values = g_list_append (values, (gpointer) "-2");
2766       values = g_list_append (values, (gpointer) "-1");
2767       values = g_list_append (values, (gpointer) "0");
2768       values = g_list_append (values, (gpointer) "1");
2769     }
2770
2771   *list = values;
2772 }
2773
2774 /**
2775  * gi_marshalling_tests_glist_utf8_container_inout:
2776  * @list: (inout) (element-type utf8) (transfer container):
2777  */
2778 void
2779 gi_marshalling_tests_glist_utf8_container_inout (GList **list)
2780 {
2781   GList *result = NULL;
2782
2783   g_assert_cmpint (g_list_length (*list), ==, 3);
2784   g_assert_cmpstr (g_list_nth_data (*list, 0), ==, "0");
2785   g_assert_cmpstr (g_list_nth_data (*list, 1), ==, "1");
2786   g_assert_cmpstr (g_list_nth_data (*list, 2), ==, "2");
2787
2788   result = g_list_prepend (result, (gpointer) "1");
2789   result = g_list_prepend (result, (gpointer) "0");
2790   result = g_list_prepend (result, (gpointer) "-1");
2791   result = g_list_prepend (result, (gpointer) "-2");
2792
2793   g_list_free (*list);
2794   *list = result;
2795 }
2796
2797 /**
2798  * gi_marshalling_tests_glist_utf8_full_inout:
2799  * @list: (inout) (element-type utf8) (transfer full):
2800  */
2801 void
2802 gi_marshalling_tests_glist_utf8_full_inout (GList **list)
2803 {
2804   GList *result = NULL;
2805
2806   g_assert_cmpint (g_list_length (*list), ==, 3);
2807   g_assert_cmpstr (g_list_nth_data (*list, 0), ==, "0");
2808   g_assert_cmpstr (g_list_nth_data (*list, 1), ==, "1");
2809   g_assert_cmpstr (g_list_nth_data (*list, 2), ==, "2");
2810
2811   result = g_list_prepend (result, g_strdup ("1"));
2812   result = g_list_prepend (result, g_strdup ("0"));
2813   result = g_list_prepend (result, g_strdup ("-1"));
2814   result = g_list_prepend (result, g_strdup ("-2"));
2815
2816   g_list_free_full (*list, g_free);
2817   *list = result;
2818 }
2819
2820
2821 /**
2822  * gi_marshalling_tests_gslist_int_none_return:
2823  *
2824  * Returns: (element-type gint) (transfer none):
2825  */
2826 GSList *
2827 gi_marshalling_tests_gslist_int_none_return (void)
2828 {
2829   static GSList *list = NULL;
2830
2831   if (list == NULL)
2832     {
2833       list = g_slist_prepend (list, GINT_TO_POINTER (-1));
2834       list = g_slist_prepend (list, GINT_TO_POINTER (0));
2835       list = g_slist_prepend (list, GINT_TO_POINTER (1));
2836       list = g_slist_prepend (list, GINT_TO_POINTER (2));
2837       list = g_slist_reverse (list);
2838     }
2839
2840   return list;
2841 }
2842
2843 /**
2844  * gi_marshalling_tests_gslist_utf8_none_return:
2845  *
2846  * Returns: (element-type utf8) (transfer none):
2847  */
2848 GSList *
2849 gi_marshalling_tests_gslist_utf8_none_return (void)
2850 {
2851   static GSList *list = NULL;
2852
2853   if (list == NULL)
2854     {
2855       list = g_slist_prepend (list, (gpointer) "0");
2856       list = g_slist_prepend (list, (gpointer) "1");
2857       list = g_slist_prepend (list, (gpointer) "2");
2858       list = g_slist_reverse (list);
2859     }
2860
2861   return list;
2862 }
2863
2864 /**
2865  * gi_marshalling_tests_gslist_utf8_container_return:
2866  *
2867  * Returns: (element-type utf8) (transfer container):
2868  */
2869 GSList *
2870 gi_marshalling_tests_gslist_utf8_container_return (void)
2871 {
2872   GSList *list = NULL;
2873
2874   list = g_slist_prepend (list, (gpointer) "0");
2875   list = g_slist_prepend (list, (gpointer) "1");
2876   list = g_slist_prepend (list, (gpointer) "2");
2877   list = g_slist_reverse (list);
2878
2879   return list;
2880 }
2881
2882 /**
2883  * gi_marshalling_tests_gslist_utf8_full_return:
2884  *
2885  * Returns: (element-type utf8) (transfer full):
2886  */
2887 GSList *
2888 gi_marshalling_tests_gslist_utf8_full_return (void)
2889 {
2890   GSList *list = NULL;
2891
2892   list = g_slist_prepend (list, g_strdup ("0"));
2893   list = g_slist_prepend (list, g_strdup ("1"));
2894   list = g_slist_prepend (list, g_strdup ("2"));
2895   list = g_slist_reverse (list);
2896
2897   return list;
2898 }
2899
2900 /**
2901  * gi_marshalling_tests_gslist_int_none_in:
2902  * @list: (element-type gint) (transfer none):
2903  */
2904 void
2905 gi_marshalling_tests_gslist_int_none_in (GSList *list)
2906 {
2907   g_assert_cmpint (g_slist_length (list), ==, 4);
2908   g_assert_cmpint (GPOINTER_TO_INT (g_slist_nth_data (list, 0)), ==, -1);
2909   g_assert_cmpint (GPOINTER_TO_INT (g_slist_nth_data (list, 1)), ==, 0);
2910   g_assert_cmpint (GPOINTER_TO_INT (g_slist_nth_data (list, 2)), ==, 1);
2911   g_assert_cmpint (GPOINTER_TO_INT (g_slist_nth_data (list, 3)), ==, 2);
2912 }
2913
2914 /**
2915  * gi_marshalling_tests_gslist_utf8_none_in:
2916  * @list: (element-type utf8) (transfer none):
2917  */
2918 void
2919 gi_marshalling_tests_gslist_utf8_none_in (GSList *list)
2920 {
2921   g_assert_cmpint (g_slist_length (list), ==, 3);
2922   g_assert_cmpstr (g_slist_nth_data (list, 0), ==, "0");
2923   g_assert_cmpstr (g_slist_nth_data (list, 1), ==, "1");
2924   g_assert_cmpstr (g_slist_nth_data (list, 2), ==, "2");
2925 }
2926
2927 /**
2928  * gi_marshalling_tests_gslist_utf8_none_out:
2929  * @list: (out) (element-type utf8) (transfer none):
2930  */
2931 void
2932 gi_marshalling_tests_gslist_utf8_none_out (GSList **list)
2933 {
2934   static GSList *values = NULL;
2935
2936   if (values == NULL)
2937     {
2938       values = g_slist_prepend (values, (gpointer) "0");
2939       values = g_slist_prepend (values, (gpointer) "1");
2940       values = g_slist_prepend (values, (gpointer) "2");
2941       values = g_slist_reverse (values);
2942     }
2943
2944   *list = values;
2945 }
2946
2947 /**
2948  * gi_marshalling_tests_gslist_utf8_container_out:
2949  * @list: (out) (element-type utf8) (transfer container):
2950  */
2951 void
2952 gi_marshalling_tests_gslist_utf8_container_out (GSList **list)
2953 {
2954   *list = NULL;
2955
2956   *list = g_slist_prepend (*list, (gpointer) "0");
2957   *list = g_slist_prepend (*list, (gpointer) "1");
2958   *list = g_slist_prepend (*list, (gpointer) "2");
2959   *list = g_slist_reverse (*list);
2960 }
2961
2962 /**
2963  * gi_marshalling_tests_gslist_utf8_full_out:
2964  * @list: (out) (element-type utf8) (transfer full):
2965  */
2966 void
2967 gi_marshalling_tests_gslist_utf8_full_out (GSList **list)
2968 {
2969   *list = NULL;
2970
2971   *list = g_slist_prepend (*list, g_strdup ("0"));
2972   *list = g_slist_prepend (*list, g_strdup ("1"));
2973   *list = g_slist_prepend (*list, g_strdup ("2"));
2974   *list = g_slist_reverse (*list);
2975 }
2976
2977 /**
2978  * gi_marshalling_tests_gslist_utf8_none_inout:
2979  * @list: (inout) (element-type utf8) (transfer none):
2980  */
2981 void
2982 gi_marshalling_tests_gslist_utf8_none_inout (GSList **list)
2983 {
2984   static GSList *values = NULL;
2985
2986   g_assert_cmpint (g_slist_length (*list), ==, 3);
2987   g_assert_cmpstr (g_slist_nth_data (*list, 0), ==, "0");
2988   g_assert_cmpstr (g_slist_nth_data (*list, 1), ==, "1");
2989   g_assert_cmpstr (g_slist_nth_data (*list, 2), ==, "2");
2990
2991   if (values == NULL)
2992     {
2993       values = g_slist_prepend (values, (gpointer) "-2");
2994       values = g_slist_prepend (values, (gpointer) "-1");
2995       values = g_slist_prepend (values, (gpointer) "0");
2996       values = g_slist_prepend (values, (gpointer) "1");
2997       values = g_slist_reverse (values);
2998     }
2999
3000   *list = values;
3001 }
3002
3003 /**
3004  * gi_marshalling_tests_gslist_utf8_container_inout:
3005  * @list: (inout) (element-type utf8) (transfer container):
3006  */
3007 void
3008 gi_marshalling_tests_gslist_utf8_container_inout (GSList **list)
3009 {
3010   GSList *result = NULL;
3011
3012   g_assert_cmpint (g_slist_length (*list), ==, 3);
3013   g_assert_cmpstr (g_slist_nth_data (*list, 0), ==, "0");
3014   g_assert_cmpstr (g_slist_nth_data (*list, 1), ==, "1");
3015   g_assert_cmpstr (g_slist_nth_data (*list, 2), ==, "2");
3016
3017   result = g_slist_prepend (result, (gpointer) "1");
3018   result = g_slist_prepend (result, (gpointer) "0");
3019   result = g_slist_prepend (result, (gpointer) "-1");
3020   result = g_slist_prepend (result, (gpointer) "-2");
3021
3022   g_slist_free (*list);
3023   *list = result;
3024 }
3025
3026 /**
3027  * gi_marshalling_tests_gslist_utf8_full_inout:
3028  * @list: (inout) (element-type utf8) (transfer full):
3029  */
3030 void
3031 gi_marshalling_tests_gslist_utf8_full_inout (GSList **list)
3032 {
3033   GSList *result = NULL;
3034
3035   g_assert_cmpint (g_slist_length (*list), ==, 3);
3036   g_assert_cmpstr (g_slist_nth_data (*list, 0), ==, "0");
3037   g_assert_cmpstr (g_slist_nth_data (*list, 1), ==, "1");
3038   g_assert_cmpstr (g_slist_nth_data (*list, 2), ==, "2");
3039
3040   result = g_slist_prepend (result, g_strdup ("1"));
3041   result = g_slist_prepend (result, g_strdup ("0"));
3042   result = g_slist_prepend (result, g_strdup ("-1"));
3043   result = g_slist_prepend (result, g_strdup ("-2"));
3044
3045   g_slist_free_full (*list, g_free);
3046   *list = result;
3047 }
3048
3049
3050 /**
3051  * gi_marshalling_tests_ghashtable_int_none_return:
3052  *
3053  * Returns: (element-type gint gint) (transfer none):
3054  */
3055 GHashTable *
3056 gi_marshalling_tests_ghashtable_int_none_return (void)
3057 {
3058   static GHashTable *hash_table = NULL;
3059
3060   if (hash_table == NULL)
3061     {
3062       hash_table = g_hash_table_new (NULL, NULL);
3063       g_hash_table_insert (hash_table, GINT_TO_POINTER (-1), GINT_TO_POINTER (1));
3064       g_hash_table_insert (hash_table, GINT_TO_POINTER (0), GINT_TO_POINTER (0));
3065       g_hash_table_insert (hash_table, GINT_TO_POINTER (1), GINT_TO_POINTER (-1));
3066       g_hash_table_insert (hash_table, GINT_TO_POINTER (2), GINT_TO_POINTER (-2));
3067     }
3068
3069   return hash_table;
3070 }
3071
3072 /**
3073  * gi_marshalling_tests_ghashtable_utf8_none_return:
3074  *
3075  * Returns: (element-type utf8 utf8) (transfer none):
3076  */
3077 GHashTable *
3078 gi_marshalling_tests_ghashtable_utf8_none_return (void)
3079 {
3080   static GHashTable *hash_table = NULL;
3081
3082   if (hash_table == NULL)
3083     {
3084       hash_table = g_hash_table_new (g_str_hash, g_str_equal);
3085       g_hash_table_insert (hash_table, (gpointer) "-1", (gpointer) "1");
3086       g_hash_table_insert (hash_table, (gpointer) "0",  (gpointer) "0");
3087       g_hash_table_insert (hash_table, (gpointer) "1",  (gpointer) "-1");
3088       g_hash_table_insert (hash_table, (gpointer) "2",  (gpointer) "-2");
3089     }
3090
3091   return hash_table;
3092 }
3093
3094 /**
3095  * gi_marshalling_tests_ghashtable_utf8_container_return:
3096  *
3097  * Returns: (element-type utf8 utf8) (transfer container):
3098  */
3099 GHashTable *
3100 gi_marshalling_tests_ghashtable_utf8_container_return (void)
3101 {
3102   GHashTable *hash_table = NULL;
3103
3104   hash_table = g_hash_table_new (g_str_hash, g_str_equal);
3105   g_hash_table_insert (hash_table, (gpointer) "-1", (gpointer) "1");
3106   g_hash_table_insert (hash_table, (gpointer) "0",  (gpointer) "0");
3107   g_hash_table_insert (hash_table, (gpointer) "1",  (gpointer) "-1");
3108   g_hash_table_insert (hash_table, (gpointer) "2",  (gpointer) "-2");
3109
3110   return hash_table;
3111 }
3112
3113 /**
3114  * gi_marshalling_tests_ghashtable_utf8_full_return:
3115  *
3116  * Returns: (element-type utf8 utf8) (transfer full):
3117  */
3118 GHashTable *
3119 gi_marshalling_tests_ghashtable_utf8_full_return (void)
3120 {
3121   GHashTable *hash_table = NULL;
3122
3123   hash_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
3124   g_hash_table_insert (hash_table, g_strdup ("-1"), g_strdup ("1"));
3125   g_hash_table_insert (hash_table, g_strdup ("0"), g_strdup ("0"));
3126   g_hash_table_insert (hash_table, g_strdup ("1"), g_strdup ("-1"));
3127   g_hash_table_insert (hash_table, g_strdup ("2"), g_strdup ("-2"));
3128
3129   return hash_table;
3130 }
3131
3132 /**
3133  * gi_marshalling_tests_ghashtable_int_none_in:
3134  * @hash_table: (element-type gint gint) (transfer none):
3135  */
3136 void
3137 gi_marshalling_tests_ghashtable_int_none_in (GHashTable *hash_table)
3138 {
3139   g_assert_cmpint (GPOINTER_TO_INT (g_hash_table_lookup (hash_table, GINT_TO_POINTER (-1))), ==, 1);
3140   g_assert_cmpint (GPOINTER_TO_INT (g_hash_table_lookup (hash_table, GINT_TO_POINTER (0))), ==, 0);
3141   g_assert_cmpint (GPOINTER_TO_INT (g_hash_table_lookup (hash_table, GINT_TO_POINTER (1))), ==, -1);
3142   g_assert_cmpint (GPOINTER_TO_INT (g_hash_table_lookup (hash_table, GINT_TO_POINTER (2))), ==, -2);
3143 }
3144
3145 /**
3146  * gi_marshalling_tests_ghashtable_utf8_none_in:
3147  * @hash_table: (element-type utf8 utf8) (transfer none):
3148  */
3149 void
3150 gi_marshalling_tests_ghashtable_utf8_none_in (GHashTable *hash_table)
3151 {
3152   g_assert_cmpstr (g_hash_table_lookup (hash_table, "-1"), ==, "1");
3153   g_assert_cmpstr (g_hash_table_lookup (hash_table, "0"), ==, "0");
3154   g_assert_cmpstr (g_hash_table_lookup (hash_table, "1"), ==, "-1");
3155   g_assert_cmpstr (g_hash_table_lookup (hash_table, "2"), ==, "-2");
3156 }
3157
3158 /**
3159  * gi_marshalling_tests_ghashtable_double_in:
3160  * @hash_table: (element-type utf8 double) (transfer none):
3161  *
3162  * Meant to test a value type that doesn't fit inside a pointer.
3163  */
3164 void
3165 gi_marshalling_tests_ghashtable_double_in (GHashTable *hash_table)
3166 {
3167   double *value;
3168
3169   value = g_hash_table_lookup (hash_table, "-1");
3170   g_assert_cmpfloat (*value, ==, -0.1);
3171   value = g_hash_table_lookup (hash_table, "0");
3172   g_assert_cmpfloat (*value, ==, 0.0);
3173   value = g_hash_table_lookup (hash_table, "1");
3174   g_assert_cmpfloat (*value, ==, 0.1);
3175   value = g_hash_table_lookup (hash_table, "2");
3176   g_assert_cmpfloat (*value, ==, 0.2);
3177 }
3178
3179 /**
3180  * gi_marshalling_tests_ghashtable_float_in:
3181  * @hash_table: (element-type utf8 float) (transfer none):
3182  *
3183  * Meant to test a value type that doesn't fit inside a pointer.
3184  */
3185 void
3186 gi_marshalling_tests_ghashtable_float_in (GHashTable *hash_table)
3187 {
3188   float *value;
3189
3190   value = g_hash_table_lookup (hash_table, "-1");
3191   g_assert_cmpfloat (*value, ==, -0.1f);
3192   value = g_hash_table_lookup (hash_table, "0");
3193   g_assert_cmpfloat (*value, ==, 0.0f);
3194   value = g_hash_table_lookup (hash_table, "1");
3195   g_assert_cmpfloat (*value, ==, 0.1f);
3196   value = g_hash_table_lookup (hash_table, "2");
3197   g_assert_cmpfloat (*value, ==, 0.2f);
3198 }
3199
3200 /**
3201  * gi_marshalling_tests_ghashtable_int64_in:
3202  * @hash_table: (element-type utf8 gint64) (transfer none):
3203  *
3204  * Meant to test a value type that doesn't fit inside a pointer.
3205  */
3206 void
3207 gi_marshalling_tests_ghashtable_int64_in (GHashTable *hash_table)
3208 {
3209   gint64 *value;
3210
3211   value = g_hash_table_lookup (hash_table, "-1");
3212   g_assert_cmpint (*value, ==, -1);
3213   value = g_hash_table_lookup (hash_table, "0");
3214   g_assert_cmpint (*value, ==, 0);
3215   value = g_hash_table_lookup (hash_table, "1");
3216   g_assert_cmpint (*value, ==, 1);
3217   value = g_hash_table_lookup (hash_table, "2");
3218   g_assert_cmpint (*value, ==, (gint64) G_MAXUINT32 + 1);
3219 }
3220
3221 /**
3222  * gi_marshalling_tests_ghashtable_uint64_in:
3223  * @hash_table: (element-type utf8 guint64) (transfer none):
3224  *
3225  * Meant to test a value type that doesn't fit inside a pointer.
3226  */
3227 void
3228 gi_marshalling_tests_ghashtable_uint64_in (GHashTable *hash_table)
3229 {
3230   guint64 *value;
3231
3232   value = g_hash_table_lookup (hash_table, "-1");
3233   g_assert_cmpuint (*value, ==, (guint64) G_MAXUINT32 + 1);
3234   value = g_hash_table_lookup (hash_table, "0");
3235   g_assert_cmpuint (*value, ==, 0);
3236   value = g_hash_table_lookup (hash_table, "1");
3237   g_assert_cmpuint (*value, ==, 1);
3238   value = g_hash_table_lookup (hash_table, "2");
3239   g_assert_cmpuint (*value, ==, 2);
3240 }
3241
3242 /**
3243  * gi_marshalling_tests_ghashtable_utf8_none_out:
3244  * @hash_table: (out) (element-type utf8 utf8) (transfer none):
3245  */
3246 void
3247 gi_marshalling_tests_ghashtable_utf8_none_out (GHashTable **hash_table)
3248 {
3249   static GHashTable *new_hash_table = NULL;
3250
3251   if (new_hash_table == NULL)
3252     {
3253       new_hash_table = g_hash_table_new (g_str_hash, g_str_equal);
3254       g_hash_table_insert (new_hash_table, (gpointer) "-1", (gpointer) "1");
3255       g_hash_table_insert (new_hash_table, (gpointer) "0",  (gpointer) "0");
3256       g_hash_table_insert (new_hash_table, (gpointer) "1",  (gpointer) "-1");
3257       g_hash_table_insert (new_hash_table, (gpointer) "2",  (gpointer) "-2");
3258     }
3259
3260   *hash_table = new_hash_table;
3261 }
3262
3263 /**
3264  * gi_marshalling_tests_ghashtable_utf8_container_out:
3265  * @hash_table: (out) (element-type utf8 utf8) (transfer container):
3266  */
3267 void
3268 gi_marshalling_tests_ghashtable_utf8_container_out (GHashTable **hash_table)
3269 {
3270   *hash_table = g_hash_table_new (g_str_hash, g_str_equal);
3271   g_hash_table_insert (*hash_table, (gpointer) "-1", (gpointer) "1");
3272   g_hash_table_insert (*hash_table, (gpointer) "0",  (gpointer) "0");
3273   g_hash_table_insert (*hash_table, (gpointer) "1",  (gpointer) "-1");
3274   g_hash_table_insert (*hash_table, (gpointer) "2",  (gpointer) "-2");
3275 }
3276
3277 /**
3278  * gi_marshalling_tests_ghashtable_utf8_full_out:
3279  * @hash_table: (out) (element-type utf8 utf8) (transfer full):
3280  */
3281 void
3282 gi_marshalling_tests_ghashtable_utf8_full_out (GHashTable **hash_table)
3283 {
3284   *hash_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
3285   g_hash_table_insert (*hash_table, g_strdup ("-1"), g_strdup ("1"));
3286   g_hash_table_insert (*hash_table, g_strdup ("0"), g_strdup ("0"));
3287   g_hash_table_insert (*hash_table, g_strdup ("1"), g_strdup ("-1"));
3288   g_hash_table_insert (*hash_table, g_strdup ("2"), g_strdup ("-2"));
3289 }
3290
3291 /**
3292  * gi_marshalling_tests_ghashtable_utf8_none_inout:
3293  * @hash_table: (inout) (element-type utf8 utf8) (transfer none):
3294  */
3295 void
3296 gi_marshalling_tests_ghashtable_utf8_none_inout (GHashTable **hash_table)
3297 {
3298   static GHashTable *new_hash_table = NULL;
3299
3300   g_assert_cmpstr (g_hash_table_lookup (*hash_table, "-1"), ==, "1");
3301   g_assert_cmpstr (g_hash_table_lookup (*hash_table, "0"), ==, "0");
3302   g_assert_cmpstr (g_hash_table_lookup (*hash_table, "1"), ==, "-1");
3303   g_assert_cmpstr (g_hash_table_lookup (*hash_table, "2"), ==, "-2");
3304
3305   if (new_hash_table == NULL)
3306     {
3307       new_hash_table = g_hash_table_new (g_str_hash, g_str_equal);
3308       g_hash_table_insert (new_hash_table, (gpointer) "-1", (gpointer) "1");
3309       g_hash_table_insert (new_hash_table, (gpointer) "0",  (gpointer) "0");
3310       g_hash_table_insert (new_hash_table, (gpointer) "1",  (gpointer) "1");
3311     }
3312
3313   *hash_table = new_hash_table;
3314 }
3315
3316 /**
3317  * gi_marshalling_tests_ghashtable_utf8_container_inout:
3318  * @hash_table: (inout) (element-type utf8 utf8) (transfer container):
3319  */
3320 void
3321 gi_marshalling_tests_ghashtable_utf8_container_inout (GHashTable **hash_table)
3322 {
3323   GHashTable *result = g_hash_table_new (g_str_hash, g_str_equal);
3324
3325   g_assert_cmpstr (g_hash_table_lookup (*hash_table, "-1"), ==, "1");
3326   g_assert_cmpstr (g_hash_table_lookup (*hash_table, "0"), ==, "0");
3327   g_assert_cmpstr (g_hash_table_lookup (*hash_table, "1"), ==, "-1");
3328   g_assert_cmpstr (g_hash_table_lookup (*hash_table, "2"), ==, "-2");
3329
3330   g_hash_table_insert (result, (gpointer) "-1", (gpointer) "1");
3331   g_hash_table_insert (result, (gpointer) "0",  (gpointer) "0");
3332   g_hash_table_insert (result, (gpointer) "1",  (gpointer) "1");
3333
3334   g_hash_table_unref (*hash_table);
3335   *hash_table = result;
3336 }
3337
3338 /**
3339  * gi_marshalling_tests_ghashtable_utf8_full_inout:
3340  * @hash_table: (inout) (element-type utf8 utf8) (transfer full):
3341  */
3342 void
3343 gi_marshalling_tests_ghashtable_utf8_full_inout (GHashTable **hash_table)
3344 {
3345   GHashTable *result = g_hash_table_new_full (g_str_hash, g_str_equal,
3346                                               g_free, g_free);
3347
3348   g_assert_cmpstr (g_hash_table_lookup (*hash_table, "-1"), ==, "1");
3349   g_assert_cmpstr (g_hash_table_lookup (*hash_table, "0"), ==, "0");
3350   g_assert_cmpstr (g_hash_table_lookup (*hash_table, "1"), ==, "-1");
3351   g_assert_cmpstr (g_hash_table_lookup (*hash_table, "2"), ==, "-2");
3352
3353   g_hash_table_insert (result, g_strdup ("-1"), g_strdup ("1"));
3354   g_hash_table_insert (result, g_strdup ("0"), g_strdup ("0"));
3355   g_hash_table_insert (result, g_strdup ("1"), g_strdup ("1"));
3356
3357   g_hash_table_unref (*hash_table);
3358   *hash_table = result;
3359 }
3360
3361
3362 /**
3363  * gi_marshalling_tests_gvalue_return:
3364  *
3365  * Returns: (transfer none):
3366  */
3367 GValue *
3368 gi_marshalling_tests_gvalue_return (void)
3369 {
3370   static GValue *value = NULL;
3371
3372   if (value == NULL)
3373     {
3374       value = g_new0 (GValue, 1);
3375       g_value_init (value, G_TYPE_INT);
3376       g_value_set_int (value, 42);
3377     }
3378
3379   return value;
3380 }
3381
3382 /**
3383  * gi_marshalling_tests_gvalue_in:
3384  * @value: (transfer none):
3385  */
3386 void
3387 gi_marshalling_tests_gvalue_in (GValue *value)
3388 {
3389   g_assert_cmpint (g_value_get_int (value), ==, 42);
3390 }
3391
3392 /**
3393  * gi_marshalling_tests_gvalue_int64_in:
3394  * @value: (transfer none):
3395  */
3396 void
3397 gi_marshalling_tests_gvalue_int64_in (GValue *value)
3398 {
3399   g_assert_cmpint (g_value_get_int64 (value), ==, G_MAXINT64);
3400 }
3401
3402 /**
3403  * gi_marshalling_tests_gvalue_in_with_type:
3404  * @value: (transfer none):
3405  * @type:
3406  */
3407 void
3408 gi_marshalling_tests_gvalue_in_with_type (GValue *value, GType type)
3409 {
3410   g_assert (g_type_is_a (G_VALUE_TYPE (value), type));
3411 }
3412
3413 /**
3414  * gi_marshalling_tests_gvalue_in_with_modification:
3415  * @value: (transfer none):
3416  *
3417  * Expects a GValue passed by reference which is then modified by
3418  * this function.
3419  */
3420 void
3421 gi_marshalling_tests_gvalue_in_with_modification (GValue *value)
3422 {
3423   g_assert_cmpint (g_value_get_int (value), ==, 42);
3424   g_value_set_int (value, 24);
3425 }
3426
3427 /**
3428  * gi_marshalling_tests_gvalue_in_enum:
3429  * @value: (transfer none):
3430  */
3431 void
3432 gi_marshalling_tests_gvalue_in_enum (GValue *value)
3433 {
3434   g_assert (g_value_get_enum (value) == GI_MARSHALLING_TESTS_ENUM_VALUE3);
3435 }
3436
3437 /**
3438  * gi_marshalling_tests_gvalue_out:
3439  * @value: (out) (transfer none):
3440  */
3441 void
3442 gi_marshalling_tests_gvalue_out (GValue **value)
3443 {
3444   static GValue *new_value = NULL;
3445
3446   if (new_value == NULL)
3447     {
3448       new_value = g_new0 (GValue, 1);
3449       g_value_init (new_value, G_TYPE_INT);
3450       g_value_set_int (new_value, 42);
3451     }
3452
3453   *value = new_value;
3454 }
3455
3456 /**
3457  * gi_marshalling_tests_gvalue_int64_out:
3458  * @value: (out) (transfer none):
3459  */
3460 void
3461 gi_marshalling_tests_gvalue_int64_out (GValue **value)
3462 {
3463   static GValue *new_value = NULL;
3464
3465   if (new_value == NULL)
3466     {
3467       new_value = g_new0 (GValue, 1);
3468       g_value_init (new_value, G_TYPE_INT64);
3469       g_value_set_int64 (new_value, G_MAXINT64);
3470     }
3471
3472   *value = new_value;
3473 }
3474
3475 /**
3476  * gi_marshalling_tests_gvalue_out_caller_allocates:
3477  * @value: (out) (transfer none):
3478  */
3479 void
3480 gi_marshalling_tests_gvalue_out_caller_allocates (GValue *value)
3481 {
3482   g_value_init (value, G_TYPE_INT);
3483   g_value_set_int (value, 42);
3484 }
3485
3486 /**
3487  * gi_marshalling_tests_gvalue_inout:
3488  * @value: (inout) (transfer none):
3489  */
3490 void
3491 gi_marshalling_tests_gvalue_inout (GValue **value)
3492 {
3493   g_assert_cmpint (g_value_get_int (*value), ==, 42);
3494   g_value_unset (*value);
3495   g_value_init (*value, G_TYPE_STRING);
3496   g_value_set_string (*value, "42");
3497 }
3498
3499 /**
3500  * gi_marshalling_tests_gvalue_flat_array:
3501  * @n_values: number of values
3502  * @values: (array length=n_values): an array containing values
3503  */
3504 void
3505 gi_marshalling_tests_gvalue_flat_array (guint n_values, const GValue *values)
3506 {
3507   g_assert (n_values == 3);
3508
3509   g_assert_cmpint (g_value_get_int (&values[0]), ==, 42);
3510   g_assert_cmpstr (g_value_get_string (&values[1]), ==, "42");
3511   g_assert_cmpint (g_value_get_boolean (&values[2]), ==, TRUE);
3512 }
3513
3514 /**
3515  * gi_marshalling_tests_return_gvalue_flat_array:
3516  *
3517  * Returns: (array fixed-size=3) (transfer full): a flat GValue array
3518  */
3519 GValue *
3520 gi_marshalling_tests_return_gvalue_flat_array (void)
3521 {
3522   GValue *array = g_new0 (GValue, 3);
3523
3524   g_value_init (&array[0], G_TYPE_INT);
3525   g_value_set_int (&array[0], 42);
3526
3527   g_value_init (&array[1], G_TYPE_STRING);
3528   g_value_set_static_string (&array[1], "42");
3529
3530   g_value_init (&array[2], G_TYPE_BOOLEAN);
3531   g_value_set_boolean (&array[2], TRUE);
3532
3533   return array;
3534 }
3535
3536 /**
3537  * gi_marshalling_tests_gvalue_flat_array_round_trip:
3538  * @one: The first GValue
3539  * @two: The second GValue
3540  * @three: The third GValue
3541  *
3542  * Returns: (array fixed-size=3) (transfer full): a flat array of [@one, @two, @three]
3543  */
3544 GValue *
3545 gi_marshalling_tests_gvalue_flat_array_round_trip (const GValue one, const GValue two, const GValue three)
3546 {
3547   GValue *array = g_new (GValue, 3);
3548   array[0] = one;
3549   array[1] = two;
3550   array[2] = three;
3551
3552   return array;
3553 }
3554
3555 /**
3556  * gi_marshalling_tests_gclosure_in:
3557  * @closure: (transfer none):
3558  */
3559 void
3560 gi_marshalling_tests_gclosure_in (GClosure *closure)
3561 {
3562   GValue return_value = { 0, };
3563
3564   g_value_init (&return_value, G_TYPE_INT);
3565
3566   g_closure_invoke (closure, &return_value, 0, NULL, NULL);
3567
3568   g_assert_cmpint (g_value_get_int (&return_value), ==, 42);
3569
3570   g_value_unset (&return_value);
3571 }
3572
3573 static gint
3574 _closure_return_42 (void)
3575 {
3576   return 42;
3577 }
3578
3579 static void
3580 _marshal_INT__VOID (GClosure     *closure,
3581                     GValue       *return_value,
3582                     guint         n_param_values G_GNUC_UNUSED,
3583                     const GValue *param_values G_GNUC_UNUSED,
3584                     gpointer      invocation_hint G_GNUC_UNUSED,
3585                     gpointer      marshal_data G_GNUC_UNUSED)
3586 {
3587   typedef gint (*GMarshalFunc_INT__VOID) (void);
3588   register GMarshalFunc_INT__VOID callback;
3589   register GCClosure *cc = (GCClosure *) closure;
3590
3591   callback = (GMarshalFunc_INT__VOID) cc->callback;
3592   g_value_set_int (return_value, callback ());
3593 }
3594
3595 /**
3596  * gi_marshalling_tests_gclosure_return:
3597  *
3598  * Return: a #GClosure
3599  */
3600 GClosure *
3601 gi_marshalling_tests_gclosure_return (void)
3602 {
3603   GClosure *closure = g_cclosure_new ((GCallback) _closure_return_42,
3604                                       NULL, NULL);
3605   g_closure_set_marshal (closure, _marshal_INT__VOID);
3606
3607   return closure;
3608 }
3609
3610
3611 /**
3612  * gi_marshalling_tests_callback_return_value_only:
3613  * @callback: (scope call):
3614  */
3615 glong gi_marshalling_tests_callback_return_value_only (GIMarshallingTestsCallbackReturnValueOnly callback)
3616 {
3617   return callback ();
3618 }
3619
3620 /**
3621  * gi_marshalling_tests_callback_one_out_parameter:
3622  * @callback: (scope call):
3623  * @a: (out):
3624  */
3625 void gi_marshalling_tests_callback_one_out_parameter (GIMarshallingTestsCallbackOneOutParameter callback, gfloat *a)
3626 {
3627   callback (a);
3628 }
3629
3630 /**
3631  * gi_marshalling_tests_callback_multiple_out_parameters:
3632  * @callback: (scope call):
3633  * @a: (out):
3634  * @b: (out):
3635  */
3636 void
3637   gi_marshalling_tests_callback_multiple_out_parameters
3638   (GIMarshallingTestsCallbackMultipleOutParameters callback, gfloat *a, gfloat *b)
3639 {
3640   callback (a, b);
3641 }
3642
3643 /**
3644  * gi_marshalling_tests_callback_return_value_and_one_out_parameter:
3645  * @callback: (scope call):
3646  * @a: (out):
3647  */
3648 glong
3649   gi_marshalling_tests_callback_return_value_and_one_out_parameter
3650   (GIMarshallingTestsCallbackReturnValueAndOneOutParameter callback, glong *a)
3651 {
3652   return callback (a);
3653 }
3654
3655 /**
3656  * gi_marshalling_tests_callback_return_value_and_multiple_out_parameters:
3657  * @callback: (scope call):
3658  * @a: (out):
3659  * @b: (out):
3660  */
3661 glong
3662   gi_marshalling_tests_callback_return_value_and_multiple_out_parameters
3663   (GIMarshallingTestsCallbackReturnValueAndMultipleOutParameters callback, glong *a, glong *b)
3664 {
3665   return callback (a, b);
3666 }
3667
3668
3669
3670 /**
3671  * gi_marshalling_tests_pointer_in_return:
3672  *
3673  * Returns: The same pointer
3674  */
3675 gpointer
3676 gi_marshalling_tests_pointer_in_return (gpointer pointer)
3677 {
3678   return pointer;
3679 }
3680
3681 GType
3682 gi_marshalling_tests_genum_get_type (void)
3683 {
3684   static GType type = 0;
3685   if (G_UNLIKELY (type == 0))
3686     {
3687       static const GEnumValue values[] = {
3688         {GI_MARSHALLING_TESTS_GENUM_VALUE1,
3689          "GI_MARSHALLING_TESTS_GENUM_VALUE1", "value1"},
3690         {GI_MARSHALLING_TESTS_GENUM_VALUE2,
3691          "GI_MARSHALLING_TESTS_GENUM_VALUE2", "value2"},
3692         {GI_MARSHALLING_TESTS_GENUM_VALUE3,
3693          "GI_MARSHALLING_TESTS_GENUM_VALUE3", "value3"},
3694         {0, NULL, NULL}
3695       };
3696       type = g_enum_register_static (g_intern_static_string ("GIMarshallingTestsGEnum"), values);
3697     }
3698
3699   return type;
3700 }
3701
3702 GIMarshallingTestsGEnum
3703 gi_marshalling_tests_genum_returnv (void)
3704 {
3705   return GI_MARSHALLING_TESTS_GENUM_VALUE3;
3706 }
3707
3708 void
3709 gi_marshalling_tests_genum_in (GIMarshallingTestsGEnum v)
3710 {
3711   g_assert_cmpint (v, ==, GI_MARSHALLING_TESTS_GENUM_VALUE3);
3712 }
3713
3714 /**
3715  * gi_marshalling_tests_genum_out:
3716  * @v: (out):
3717  */
3718 void
3719 gi_marshalling_tests_genum_out (GIMarshallingTestsGEnum *v)
3720 {
3721   *v = GI_MARSHALLING_TESTS_GENUM_VALUE3;
3722 }
3723
3724 /**
3725  * gi_marshalling_tests_genum_inout:
3726  * @v: (inout):
3727  */
3728 void
3729 gi_marshalling_tests_genum_inout (GIMarshallingTestsGEnum *v)
3730 {
3731   g_assert_cmpint (*v, ==, GI_MARSHALLING_TESTS_GENUM_VALUE3);
3732   *v = GI_MARSHALLING_TESTS_GENUM_VALUE1;
3733 }
3734
3735
3736 GIMarshallingTestsEnum
3737 gi_marshalling_tests_enum_returnv (void)
3738 {
3739   return GI_MARSHALLING_TESTS_ENUM_VALUE3;
3740 }
3741
3742 void
3743 gi_marshalling_tests_enum_in (GIMarshallingTestsEnum v)
3744 {
3745   g_assert_cmpint (v, ==, GI_MARSHALLING_TESTS_ENUM_VALUE3);
3746 }
3747
3748 /**
3749  * gi_marshalling_tests_enum_out:
3750  * @v: (out):
3751  */
3752 void
3753 gi_marshalling_tests_enum_out (GIMarshallingTestsEnum *v)
3754 {
3755   *v = GI_MARSHALLING_TESTS_ENUM_VALUE3;
3756 }
3757
3758 /**
3759  * gi_marshalling_tests_enum_inout:
3760  * @v: (inout):
3761  */
3762 void
3763 gi_marshalling_tests_enum_inout (GIMarshallingTestsEnum *v)
3764 {
3765   g_assert_cmpint (*v, ==, GI_MARSHALLING_TESTS_ENUM_VALUE3);
3766   *v = GI_MARSHALLING_TESTS_ENUM_VALUE1;
3767 }
3768
3769
3770 GType
3771 gi_marshalling_tests_flags_get_type (void)
3772 {
3773   static GType type = 0;
3774   if (G_UNLIKELY (type == 0))
3775     {
3776       static const GFlagsValue values[] = {
3777         {GI_MARSHALLING_TESTS_FLAGS_VALUE1,
3778          "GI_MARSHALLING_TESTS_FLAGS_VALUE1", "value1"},
3779         {GI_MARSHALLING_TESTS_FLAGS_VALUE2,
3780          "GI_MARSHALLING_TESTS_FLAGS_VALUE2", "value2"},
3781         {GI_MARSHALLING_TESTS_FLAGS_VALUE3,
3782          "GI_MARSHALLING_TESTS_FLAGS_VALUE3", "value3"},
3783         {GI_MARSHALLING_TESTS_FLAGS_MASK, "GI_MARSHALLING_TESTS_FLAGS_MASK",
3784          "mask"},
3785         {GI_MARSHALLING_TESTS_FLAGS_MASK2, "GI_MARSHALLING_TESTS_FLAGS_MASK2",
3786          "mask2"},
3787         {0, NULL, NULL}
3788       };
3789       type = g_flags_register_static (g_intern_static_string ("GIMarshallingTestsFlags"), values);
3790     }
3791
3792   return type;
3793 }
3794
3795 GIMarshallingTestsFlags
3796 gi_marshalling_tests_flags_returnv (void)
3797 {
3798   return GI_MARSHALLING_TESTS_FLAGS_VALUE2;
3799 }
3800
3801 void
3802 gi_marshalling_tests_flags_in (GIMarshallingTestsFlags v)
3803 {
3804   g_assert (v == GI_MARSHALLING_TESTS_FLAGS_VALUE2);
3805 }
3806
3807 void
3808 gi_marshalling_tests_flags_in_zero (GIMarshallingTestsFlags v)
3809 {
3810   g_assert (v == 0);
3811 }
3812
3813 /**
3814  * gi_marshalling_tests_flags_out:
3815  * @v: (out):
3816  */
3817 void
3818 gi_marshalling_tests_flags_out (GIMarshallingTestsFlags *v)
3819 {
3820   *v = GI_MARSHALLING_TESTS_FLAGS_VALUE2;
3821 }
3822
3823 /**
3824  * gi_marshalling_tests_flags_inout:
3825  * @v: (inout):
3826  */
3827 void
3828 gi_marshalling_tests_flags_inout (GIMarshallingTestsFlags *v)
3829 {
3830   g_assert (*v == GI_MARSHALLING_TESTS_FLAGS_VALUE2);
3831   *v = GI_MARSHALLING_TESTS_FLAGS_VALUE1;
3832 }
3833
3834
3835 GIMarshallingTestsNoTypeFlags
3836 gi_marshalling_tests_no_type_flags_returnv (void)
3837 {
3838   return GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE2;
3839 }
3840
3841 void
3842 gi_marshalling_tests_no_type_flags_in (GIMarshallingTestsNoTypeFlags v)
3843 {
3844   g_assert (v == GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE2);
3845 }
3846
3847 void
3848 gi_marshalling_tests_no_type_flags_in_zero (GIMarshallingTestsNoTypeFlags v)
3849 {
3850   g_assert (v == 0);
3851 }
3852
3853 /**
3854  * gi_marshalling_tests_no_type_flags_out:
3855  * @v: (out):
3856  */
3857 void
3858 gi_marshalling_tests_no_type_flags_out (GIMarshallingTestsNoTypeFlags *v)
3859 {
3860   *v = GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE2;
3861 }
3862
3863 /**
3864  * gi_marshalling_tests_no_type_flags_inout:
3865  * @v: (inout):
3866  */
3867 void
3868 gi_marshalling_tests_no_type_flags_inout (GIMarshallingTestsNoTypeFlags *v)
3869 {
3870   g_assert (*v == GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE2);
3871   *v = GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE1;
3872 }
3873
3874
3875 /**
3876  * gi_marshalling_tests_simple_struct_returnv:
3877  *
3878  * Returns: (transfer none):
3879  */
3880 GIMarshallingTestsSimpleStruct *
3881 gi_marshalling_tests_simple_struct_returnv (void)
3882 {
3883   static GIMarshallingTestsSimpleStruct *struct_ = NULL;
3884
3885   if (struct_ == NULL)
3886     {
3887       struct_ = g_new (GIMarshallingTestsSimpleStruct, 1);
3888
3889       struct_->long_ = 6;
3890       struct_->int8 = 7;
3891     }
3892
3893   return struct_;
3894 }
3895
3896 /**
3897  * gi_marshalling_tests_simple_struct_inv:
3898  * @struct_: (transfer none):
3899  */
3900 void
3901 gi_marshalling_tests_simple_struct_inv (GIMarshallingTestsSimpleStruct *struct_)
3902 {
3903   g_assert_cmpint (struct_->long_, ==, 6);
3904   g_assert_cmpint (struct_->int8, ==, 7);
3905 }
3906
3907 void
3908 gi_marshalling_tests_simple_struct_method (GIMarshallingTestsSimpleStruct *struct_)
3909 {
3910   g_assert_cmpint (struct_->long_, ==, 6);
3911   g_assert_cmpint (struct_->int8, ==, 7);
3912 }
3913
3914
3915 GType
3916 gi_marshalling_tests_pointer_struct_get_type (void)
3917 {
3918   static GType type = 0;
3919
3920   if (type == 0)
3921     {
3922       type = g_pointer_type_register_static ("GIMarshallingTestsPointerStruct");
3923     }
3924
3925   return type;
3926 }
3927
3928 /**
3929  * gi_marshalling_tests_pointer_struct_returnv:
3930  *
3931  * Returns: (transfer none):
3932  */
3933 GIMarshallingTestsPointerStruct *
3934 gi_marshalling_tests_pointer_struct_returnv (void)
3935 {
3936   static GIMarshallingTestsPointerStruct *struct_ = NULL;
3937
3938   if (struct_ == NULL)
3939     {
3940       struct_ = g_new (GIMarshallingTestsPointerStruct, 1);
3941
3942       struct_->long_ = 42;
3943     }
3944
3945   return struct_;
3946 }
3947
3948 /**
3949  * gi_marshalling_tests_pointer_struct_inv:
3950  * @struct_: (transfer none):
3951  */
3952 void
3953 gi_marshalling_tests_pointer_struct_inv (GIMarshallingTestsPointerStruct *struct_)
3954 {
3955   g_assert_cmpint (struct_->long_, ==, 42);
3956 }
3957
3958 static GIMarshallingTestsBoxedStruct *
3959 gi_marshalling_tests_boxed_struct_copy (GIMarshallingTestsBoxedStruct *struct_)
3960 {
3961   GIMarshallingTestsBoxedStruct *new_struct;
3962
3963   if (struct_ == NULL)
3964     return NULL;
3965
3966   new_struct = g_slice_new (GIMarshallingTestsBoxedStruct);
3967
3968   *new_struct = *struct_;
3969   new_struct->string_ = g_strdup (struct_->string_);
3970
3971   return new_struct;
3972 }
3973
3974 static void
3975 gi_marshalling_tests_boxed_struct_free (GIMarshallingTestsBoxedStruct *struct_)
3976 {
3977   if (struct_ != NULL)
3978     {
3979       g_free (struct_->string_);
3980       g_slice_free (GIMarshallingTestsBoxedStruct, struct_);
3981     }
3982 }
3983
3984 GType
3985 gi_marshalling_tests_boxed_struct_get_type (void)
3986 {
3987   static GType type = 0;
3988
3989   if (type == 0)
3990     {
3991       type = g_boxed_type_register_static ("GIMarshallingTestsBoxedStruct",
3992                                            (GBoxedCopyFunc)
3993                                            gi_marshalling_tests_boxed_struct_copy,
3994                                            (GBoxedFreeFunc) gi_marshalling_tests_boxed_struct_free);
3995     }
3996
3997   return type;
3998 }
3999
4000 static GType
4001 gi_marshalling_tests_boxed_glist_get_type (void)
4002 {
4003   static GType type = 0;
4004
4005   if (type == 0)
4006     {
4007       type = g_boxed_type_register_static ("GIMarshallingTestsBoxedGList",
4008                                            (GBoxedCopyFunc) g_list_copy, (GBoxedFreeFunc) g_list_free);
4009     }
4010
4011   return type;
4012 }
4013
4014 GIMarshallingTestsBoxedStruct *
4015 gi_marshalling_tests_boxed_struct_new (void)
4016 {
4017   return g_slice_new0 (GIMarshallingTestsBoxedStruct);
4018 }
4019
4020 /**
4021  * gi_marshalling_tests_boxed_struct_returnv:
4022  *
4023  * Returns: (transfer none):
4024  */
4025 GIMarshallingTestsBoxedStruct *
4026 gi_marshalling_tests_boxed_struct_returnv (void)
4027 {
4028   static GIMarshallingTestsBoxedStruct *struct_ = NULL;
4029
4030   if (struct_ == NULL)
4031     {
4032       struct_ = g_new (GIMarshallingTestsBoxedStruct, 1);
4033
4034       struct_->long_ = 42;
4035       struct_->string_ = g_strdup ("hello");
4036       struct_->g_strv = g_new0 (gchar *, 4);
4037       struct_->g_strv[0] = g_strdup ("0");
4038       struct_->g_strv[1] = g_strdup ("1");
4039       struct_->g_strv[2] = g_strdup ("2");
4040       struct_->g_strv[3] = NULL;
4041     }
4042
4043   return struct_;
4044 }
4045
4046 /**
4047  * gi_marshalling_tests_boxed_struct_inv:
4048  * @struct_: (transfer none):
4049  */
4050 void
4051 gi_marshalling_tests_boxed_struct_inv (GIMarshallingTestsBoxedStruct *struct_)
4052 {
4053   g_assert_cmpint (struct_->long_, ==, 42);
4054 }
4055
4056 /**
4057  * gi_marshalling_tests_boxed_struct_out:
4058  * @struct_: (out) (transfer none):
4059  */
4060 void
4061 gi_marshalling_tests_boxed_struct_out (GIMarshallingTestsBoxedStruct **struct_)
4062 {
4063   static GIMarshallingTestsBoxedStruct *new_struct = NULL;
4064
4065   if (new_struct == NULL)
4066     {
4067       new_struct = g_new0 (GIMarshallingTestsBoxedStruct, 1);
4068
4069       new_struct->long_ = 42;
4070     }
4071
4072   *struct_ = new_struct;
4073 }
4074
4075 /**
4076  * gi_marshalling_tests_boxed_struct_inout:
4077  * @struct_: (inout) (transfer full):
4078  */
4079 void
4080 gi_marshalling_tests_boxed_struct_inout (GIMarshallingTestsBoxedStruct **struct_)
4081 {
4082   g_assert_cmpint ((*struct_)->long_, ==, 42);
4083
4084   g_boxed_free (gi_marshalling_tests_boxed_struct_get_type(), *struct_);
4085   (*struct_) = g_slice_new0 (GIMarshallingTestsBoxedStruct);
4086   (*struct_)->long_ = 0;
4087 }
4088
4089 static GIMarshallingTestsUnion *
4090 gi_marshalling_tests_union_copy (GIMarshallingTestsUnion *union_)
4091 {
4092   GIMarshallingTestsUnion *new_union;
4093
4094   new_union = g_slice_new (GIMarshallingTestsUnion);
4095
4096   *new_union = *union_;
4097
4098   return new_union;
4099 }
4100
4101 static void
4102 gi_marshalling_tests_union_free (GIMarshallingTestsUnion *union_)
4103 {
4104   g_slice_free (GIMarshallingTestsUnion, union_);
4105 }
4106
4107 GType
4108 gi_marshalling_tests_union_get_type (void)
4109 {
4110   static GType type = 0;
4111
4112   if (type == 0)
4113     {
4114       type = g_boxed_type_register_static ("GIMarshallingTestsUnion",
4115                                            (GBoxedCopyFunc)
4116                                            gi_marshalling_tests_union_copy,
4117                                            (GBoxedFreeFunc) gi_marshalling_tests_union_free);
4118     }
4119
4120   return type;
4121 }
4122
4123 /**
4124  * gi_marshalling_tests_union_returnv:
4125  *
4126  * Returns: (transfer none):
4127  */
4128 GIMarshallingTestsUnion *
4129 gi_marshalling_tests_union_returnv (void)
4130 {
4131   static GIMarshallingTestsUnion *union_ = NULL;
4132
4133   if (union_ == NULL)
4134     {
4135       union_ = g_new (GIMarshallingTestsUnion, 1);
4136
4137       union_->long_ = 42;
4138     }
4139
4140   return union_;
4141 }
4142
4143 /**
4144  * gi_marshalling_tests_union_inv:
4145  * @union_: (transfer none):
4146  */
4147 void
4148 gi_marshalling_tests_union_inv (GIMarshallingTestsUnion *union_)
4149 {
4150   g_assert_cmpint (union_->long_, ==, 42);
4151 }
4152
4153 void
4154 gi_marshalling_tests_union_method (GIMarshallingTestsUnion *union_)
4155 {
4156   g_assert_cmpint (union_->long_, ==, 42);
4157 }
4158
4159
4160
4161 enum
4162 {
4163   PROP_0,
4164   PROP_INT_
4165 };
4166
4167 static void
4168   gi_marshalling_tests_object_real_method_with_default_implementation (GIMarshallingTestsObject *self, gint8 in);
4169
4170 G_DEFINE_TYPE (GIMarshallingTestsObject, gi_marshalling_tests_object, G_TYPE_OBJECT);
4171
4172 static void
4173 gi_marshalling_tests_object_init (GIMarshallingTestsObject *self G_GNUC_UNUSED)
4174 {
4175 }
4176
4177 static void
4178 gi_marshalling_tests_object_finalize (GObject *object)
4179 {
4180   G_OBJECT_CLASS (gi_marshalling_tests_object_parent_class)->finalize (object);
4181 }
4182
4183 static void
4184 gi_marshalling_tests_object_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
4185 {
4186   g_return_if_fail (GI_MARSHALLING_TESTS_IS_OBJECT (object));
4187
4188   switch (prop_id)
4189     {
4190     case PROP_INT_:
4191       GI_MARSHALLING_TESTS_OBJECT (object)->int_ = g_value_get_int (value);
4192       break;
4193     default:
4194       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
4195       break;
4196     }
4197 }
4198
4199 static void
4200 gi_marshalling_tests_object_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
4201 {
4202   g_return_if_fail (GI_MARSHALLING_TESTS_IS_OBJECT (object));
4203
4204   switch (prop_id)
4205     {
4206     case PROP_INT_:
4207       g_value_set_int (value, GI_MARSHALLING_TESTS_OBJECT (object)->int_);
4208       break;
4209     default:
4210       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
4211       break;
4212     }
4213 }
4214
4215 static void
4216 gi_marshalling_tests_object_class_init (GIMarshallingTestsObjectClass *klass)
4217 {
4218   GObjectClass *object_class = G_OBJECT_CLASS (klass);
4219 #if 0
4220   GObjectClass *parent_class = G_OBJECT_CLASS (klass);
4221 #endif
4222
4223   object_class->finalize = gi_marshalling_tests_object_finalize;
4224   object_class->set_property = gi_marshalling_tests_object_set_property;
4225   object_class->get_property = gi_marshalling_tests_object_get_property;
4226
4227   g_object_class_install_property (object_class, PROP_INT_,
4228                                    g_param_spec_int ("int", "Integer",
4229                                                      "An integer", G_MININT,
4230                                                      G_MAXINT, 0,
4231                                                      G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
4232
4233   klass->method_with_default_implementation = gi_marshalling_tests_object_real_method_with_default_implementation;
4234 }
4235
4236
4237 void
4238 gi_marshalling_tests_object_static_method (void)
4239 {
4240 }
4241
4242 void
4243 gi_marshalling_tests_object_method (GIMarshallingTestsObject *object)
4244 {
4245   g_return_if_fail (GI_MARSHALLING_TESTS_IS_OBJECT (object));
4246   g_assert_cmpint (object->int_, ==, 42);
4247 }
4248
4249 void
4250 gi_marshalling_tests_object_overridden_method (GIMarshallingTestsObject *object)
4251 {
4252   g_return_if_fail (GI_MARSHALLING_TESTS_IS_OBJECT (object));
4253   g_assert_cmpint (object->int_, ==, 0);
4254 }
4255
4256 GIMarshallingTestsObject *
4257 gi_marshalling_tests_object_new (gint int_)
4258 {
4259   return g_object_new (GI_MARSHALLING_TESTS_TYPE_OBJECT, "int", int_, NULL);
4260 }
4261
4262 GIMarshallingTestsObject *
4263 gi_marshalling_tests_object_new_fail (gint     int_ G_GNUC_UNUSED,
4264                                       GError **error)
4265 {
4266   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
4267
4268   g_set_error_literal (error,
4269                        g_quark_from_static_string (GI_MARSHALLING_TESTS_CONSTANT_GERROR_DOMAIN),
4270                        GI_MARSHALLING_TESTS_CONSTANT_GERROR_CODE,
4271                        GI_MARSHALLING_TESTS_CONSTANT_GERROR_MESSAGE);
4272
4273   return NULL;
4274 }
4275
4276 /**
4277  * gi_marshalling_tests_object_method_array_in:
4278  * @ints: (array length=length):
4279  */
4280 void
4281 gi_marshalling_tests_object_method_array_in (GIMarshallingTestsObject *self G_GNUC_UNUSED,
4282                                              const gint               *ints,
4283                                              gint                      length)
4284 {
4285   g_assert_cmpint (length, ==, 4);
4286   g_assert_cmpint (ints[0], ==, -1);
4287   g_assert_cmpint (ints[1], ==, 0);
4288   g_assert_cmpint (ints[2], ==, 1);
4289   g_assert_cmpint (ints[3], ==, 2);
4290 }
4291
4292 /**
4293  * gi_marshalling_tests_object_method_array_out:
4294  * @ints: (out) (array length=length) (transfer none):
4295  */
4296 void
4297 gi_marshalling_tests_object_method_array_out (GIMarshallingTestsObject *self G_GNUC_UNUSED,
4298                                               gint                    **ints,
4299                                               gint                     *length)
4300 {
4301   static gint values[] = { -1, 0, 1, 2 };
4302
4303   *length = 4;
4304   *ints = values;
4305 }
4306
4307 /**
4308  * gi_marshalling_tests_object_method_array_inout:
4309  * @ints: (inout) (array length=length) (transfer none):
4310  * @length: (inout):
4311  */
4312 void
4313 gi_marshalling_tests_object_method_array_inout (GIMarshallingTestsObject *self G_GNUC_UNUSED,
4314                                                 gint                    **ints,
4315                                                 gint                     *length)
4316 {
4317   static gint values[] = { -2, -1, 0, 1, 2 };
4318
4319   g_assert_cmpint (*length, ==, 4);
4320   g_assert_cmpint ((*ints)[0], ==, -1);
4321   g_assert_cmpint ((*ints)[1], ==, 0);
4322   g_assert_cmpint ((*ints)[2], ==, 1);
4323   g_assert_cmpint ((*ints)[3], ==, 2);
4324
4325   *length = 5;
4326   *ints = values;
4327 }
4328
4329 /**
4330  * gi_marshalling_tests_object_method_array_return:
4331  *
4332  * Returns: (array length=length):
4333  */
4334 const gint *
4335 gi_marshalling_tests_object_method_array_return (GIMarshallingTestsObject *self G_GNUC_UNUSED,
4336                                                  gint                     *length)
4337 {
4338   static gint ints[] = { -1, 0, 1, 2 };
4339
4340   *length = 4;
4341   return ints;
4342 }
4343
4344 /**
4345  * gi_marshalling_tests_object_method_int8_in:
4346  * @in: (in):
4347  */
4348 void
4349 gi_marshalling_tests_object_method_int8_in (GIMarshallingTestsObject *self, gint8 in)
4350 {
4351   GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->method_int8_in (self, in);
4352 }
4353
4354 /**
4355  * gi_marshalling_tests_object_method_int8_out:
4356  * @out: (out):
4357  */
4358 void
4359 gi_marshalling_tests_object_method_int8_out (GIMarshallingTestsObject *self, gint8 *out)
4360 {
4361   GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->method_int8_out (self, out);
4362 }
4363
4364 /**
4365  * gi_marshalling_tests_object_method_int8_arg_and_out_caller:
4366  * @out: (out caller-allocates):
4367  */
4368 void
4369   gi_marshalling_tests_object_method_int8_arg_and_out_caller (GIMarshallingTestsObject *self, gint8 arg, gint8 *out)
4370 {
4371   GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->method_int8_arg_and_out_caller (self, arg, out);
4372 }
4373
4374 /**
4375  * gi_marshalling_tests_object_method_int8_arg_and_out_callee:
4376  * @out: (out):
4377  */
4378 void
4379   gi_marshalling_tests_object_method_int8_arg_and_out_callee (GIMarshallingTestsObject *self, gint8 arg, gint8 **out)
4380 {
4381   GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->method_int8_arg_and_out_callee (self, arg, out);
4382 }
4383
4384 /**
4385  * gi_marshalling_tests_object_method_str_arg_out_ret:
4386  * @out: (out caller-allocates):
4387  *
4388  * Returns: (transfer none)
4389  */
4390 const gchar *
4391 gi_marshalling_tests_object_method_str_arg_out_ret (GIMarshallingTestsObject *self, const gchar *arg, guint *out)
4392 {
4393   return GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->method_str_arg_out_ret (self, arg, out);
4394 }
4395
4396 /**
4397  * gi_marshalling_tests_object_method_with_default_implementation:
4398  * @in: (in):
4399  */
4400 void gi_marshalling_tests_object_method_with_default_implementation (GIMarshallingTestsObject *self, gint8 in)
4401 {
4402   GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->method_with_default_implementation (self, in);
4403 }
4404
4405 static void
4406   gi_marshalling_tests_object_real_method_with_default_implementation (GIMarshallingTestsObject *self, gint8 in)
4407 {
4408   GValue val = { 0, };
4409   g_value_init (&val, G_TYPE_INT);
4410   g_value_set_int (&val, in);
4411   g_object_set_property (G_OBJECT (self), "int", &val);
4412 }
4413
4414 /**
4415  * gi_marshalling_tests_object_vfunc_with_callback: (virtual vfunc_with_callback)
4416  * @callback: (scope call) (closure callback_data):
4417  * @callback_data: (allow-none):
4418  */
4419 void
4420 gi_marshalling_tests_object_vfunc_with_callback (GIMarshallingTestsObject        *self G_GNUC_UNUSED,
4421                                                  GIMarshallingTestsCallbackIntInt callback G_GNUC_UNUSED,
4422                                                  void                            *callback_data G_GNUC_UNUSED)
4423 {
4424
4425 }
4426
4427 static int
4428 _callback (int val, void *user_data)
4429 {
4430   g_assert (user_data == (gpointer) 0xdeadbeef);
4431   return val;
4432 }
4433
4434 void
4435 gi_marshalling_tests_object_call_vfunc_with_callback (GIMarshallingTestsObject *object)
4436 {
4437   GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (object)->vfunc_with_callback (object, _callback, (void *) 0xdeadbeef);
4438 }
4439
4440 /**
4441  * gi_marshalling_tests_object_none_return:
4442  *
4443  * Returns: (transfer none):
4444  */
4445 GIMarshallingTestsObject *
4446 gi_marshalling_tests_object_none_return (void)
4447 {
4448   static GIMarshallingTestsObject *object = NULL;
4449
4450   if (object == NULL)
4451     {
4452       object = g_object_new (GI_MARSHALLING_TESTS_TYPE_OBJECT, NULL);
4453     }
4454
4455   return object;
4456 }
4457
4458 /**
4459  * gi_marshalling_tests_object_full_return:
4460  *
4461  * Returns: (transfer full):
4462  */
4463 GIMarshallingTestsObject *
4464 gi_marshalling_tests_object_full_return (void)
4465 {
4466   return g_object_new (GI_MARSHALLING_TESTS_TYPE_OBJECT, NULL);
4467 }
4468
4469 /**
4470  * gi_marshalling_tests_object_none_in:
4471  * @object: (transfer none):
4472  */
4473 void
4474 gi_marshalling_tests_object_none_in (GIMarshallingTestsObject *object)
4475 {
4476   g_assert_cmpint (object->int_, ==, 42);
4477 }
4478
4479 /**
4480  * gi_marshalling_tests_object_none_out:
4481  * @object: (out) (transfer none):
4482  */
4483 void
4484 gi_marshalling_tests_object_none_out (GIMarshallingTestsObject **object)
4485 {
4486   static GIMarshallingTestsObject *new_object = NULL;
4487
4488   if (new_object == NULL)
4489     {
4490       new_object = g_object_new (GI_MARSHALLING_TESTS_TYPE_OBJECT, NULL);
4491     }
4492
4493   *object = new_object;
4494 }
4495
4496 /**
4497  * gi_marshalling_tests_object_full_out:
4498  * @object: (out) (transfer full):
4499  */
4500 void
4501 gi_marshalling_tests_object_full_out (GIMarshallingTestsObject **object)
4502 {
4503   *object = g_object_new (GI_MARSHALLING_TESTS_TYPE_OBJECT, NULL);
4504 }
4505
4506 /**
4507  * gi_marshalling_tests_object_none_inout:
4508  * @object: (inout) (transfer none):
4509  */
4510 void
4511 gi_marshalling_tests_object_none_inout (GIMarshallingTestsObject **object)
4512 {
4513   static GIMarshallingTestsObject *new_object = NULL;
4514
4515   g_assert_cmpint ((*object)->int_, ==, 42);
4516
4517   if (new_object == NULL)
4518     {
4519       new_object = g_object_new (GI_MARSHALLING_TESTS_TYPE_OBJECT, NULL);
4520       new_object->int_ = 0;
4521     }
4522
4523   *object = new_object;
4524 }
4525
4526 /**
4527  * gi_marshalling_tests_object_full_inout:
4528  * @object: (inout) (transfer full):
4529  */
4530 void
4531 gi_marshalling_tests_object_full_inout (GIMarshallingTestsObject **object)
4532 {
4533   g_assert_cmpint ((*object)->int_, ==, 42);
4534
4535   g_object_unref (*object);
4536   *object = g_object_new (GI_MARSHALLING_TESTS_TYPE_OBJECT, NULL);
4537 }
4538
4539 /**
4540  * gi_marshalling_tests_object_int8_in:
4541  * @in: (in):
4542  */
4543 void
4544 gi_marshalling_tests_object_int8_in (GIMarshallingTestsObject *object, gint8 in)
4545 {
4546   gi_marshalling_tests_object_method_int8_in (object, in);
4547 }
4548
4549 /**
4550  * gi_marshalling_tests_object_int8_out:
4551  * @out: (out):
4552  */
4553 void
4554 gi_marshalling_tests_object_int8_out (GIMarshallingTestsObject *object, gint8 *out)
4555 {
4556   gi_marshalling_tests_object_method_int8_out (object, out);
4557 }
4558
4559 /**
4560  * gi_marshalling_tests_object_vfunc_return_value_only:
4561  */
4562 glong
4563 gi_marshalling_tests_object_vfunc_return_value_only (GIMarshallingTestsObject *self)
4564 {
4565   /* make sure that local variables don't get smashed */
4566   glong return_value;
4567   gulong local = 0x12345678;
4568   return_value = GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_return_value_only (self);
4569   g_assert_cmpint (local, ==, 0x12345678);
4570   return return_value;
4571 }
4572
4573 /**
4574  * gi_marshalling_tests_object_vfunc_one_out_parameter:
4575  * @a: (out):
4576  */
4577 void
4578 gi_marshalling_tests_object_vfunc_one_out_parameter (GIMarshallingTestsObject *self, gfloat *a)
4579 {
4580   /* make sure that local variables don't get smashed */
4581   gulong local = 0x12345678;
4582   GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_one_out_parameter (self, a);
4583   g_assert_cmpint (local, ==, 0x12345678);
4584 }
4585
4586 /**
4587  * gi_marshalling_tests_object_vfunc_multiple_out_parameters:
4588  * @a: (out):
4589  * @b: (out):
4590  */
4591 void gi_marshalling_tests_object_vfunc_multiple_out_parameters (GIMarshallingTestsObject *self, gfloat *a, gfloat *b)
4592 {
4593   /* make sure that local variables don't get smashed */
4594   gulong local = 0x12345678;
4595   GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_multiple_out_parameters (self, a, b);
4596   g_assert_cmpint (local, ==, 0x12345678);
4597 }
4598
4599 /**
4600  * gi_marshalling_tests_object_vfunc_caller_allocated_out_parameter:
4601  * @a: (out):
4602  */
4603 void gi_marshalling_tests_object_vfunc_caller_allocated_out_parameter (GIMarshallingTestsObject *self, GValue *a)
4604 {
4605   /* make sure that local variables don't get smashed */
4606   gulong local = 0x12345678;
4607   GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_caller_allocated_out_parameter (self, a);
4608   g_assert_cmpint (local, ==, 0x12345678);
4609 }
4610
4611 /**
4612  * gi_marshalling_tests_object_vfunc_array_out_parameter:
4613  * @a: (out) (array zero-terminated):
4614  */
4615 void gi_marshalling_tests_object_vfunc_array_out_parameter (GIMarshallingTestsObject *self, gfloat **a)
4616 {
4617   /* make sure that local variables don't get smashed */
4618   gulong local = 0x12345678;
4619   GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_array_out_parameter (self, a);
4620   g_assert_cmpint (local, ==, 0x12345678);
4621 }
4622
4623 /**
4624  * gi_marshalling_tests_object_vfunc_return_value_and_one_out_parameter:
4625  * @a: (out):
4626  */
4627 glong gi_marshalling_tests_object_vfunc_return_value_and_one_out_parameter (GIMarshallingTestsObject *self, glong *a)
4628 {
4629   /* make sure that local variables don't get smashed */
4630   gulong return_value;
4631   gulong local = 0x12345678;
4632   return_value = GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_return_value_and_one_out_parameter (self, a);
4633   g_assert_cmpint (local, ==, 0x12345678);
4634   return return_value;
4635 }
4636
4637 /**
4638  * gi_marshalling_tests_object_vfunc_return_value_and_multiple_out_parameters:
4639  * @a: (out):
4640  * @b: (out):
4641  */
4642 glong
4643   gi_marshalling_tests_object_vfunc_return_value_and_multiple_out_parameters
4644   (GIMarshallingTestsObject *self, glong *a, glong *b)
4645 {
4646   gulong return_value;
4647   gulong local = 0x12345678;
4648   return_value =
4649     GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_return_value_and_multiple_out_parameters (self, a, b);
4650   g_assert_cmpint (local, ==, 0x12345678);
4651   return return_value;
4652 }
4653
4654 /**
4655  * gi_marshalling_tests_callback_owned_boxed:
4656  * @callback: (scope call) (closure callback_data):
4657  * @callback_data: (allow-none):
4658  */
4659 glong
4660 gi_marshalling_tests_callback_owned_boxed (GIMarshallingTestsCallbackOwnedBoxed callback,
4661                                            void *callback_data)
4662 {
4663   static GIMarshallingTestsBoxedStruct *box = NULL;
4664   glong ret;
4665
4666   if (!box)
4667     box = gi_marshalling_tests_boxed_struct_new ();
4668   box->long_++;
4669   callback (box, callback_data);
4670   ret = box->long_;
4671   return ret;
4672 }
4673
4674 gboolean
4675 gi_marshalling_tests_object_vfunc_meth_with_error (GIMarshallingTestsObject *self, gint x, GError **error)
4676 {
4677   gulong local = 0x12345678;
4678   gboolean ret = GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_meth_with_err (self,
4679                                                                                     x,
4680                                                                                     error);
4681   g_assert_cmpint (local, ==, 0x12345678);
4682   return ret;
4683 }
4684
4685 /**
4686  * gi_marshalling_tests_object_vfunc_return_enum:
4687  */
4688 GIMarshallingTestsEnum
4689 gi_marshalling_tests_object_vfunc_return_enum (GIMarshallingTestsObject *self)
4690 {
4691   /* make sure that local variables don't get smashed */
4692   GIMarshallingTestsEnum return_value;
4693   glong local = 0x12345678;
4694   return_value = GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_return_enum (self);
4695   g_assert_cmpint (local, ==, 0x12345678);
4696   return return_value;
4697 }
4698
4699 /**
4700  * gi_marshalling_tests_object_vfunc_out_enum:
4701  * @_enum: (out):
4702  */
4703 void
4704 gi_marshalling_tests_object_vfunc_out_enum (GIMarshallingTestsObject *self, GIMarshallingTestsEnum *_enum)
4705 {
4706   /* make sure that local variables don't get smashed */
4707   gulong local = 0x12345678;
4708   GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_out_enum (self, _enum);
4709   g_assert_cmpint (local, ==, 0x12345678);
4710 }
4711
4712
4713 /* NOTE:
4714  *
4715  * The following (get_ref_info_for_*) methods are designed to call vfuncs related
4716  * to object argument marshaling. They do not pass the resulting objects through them
4717  * as regular vfunc wrapper method do, but rather return reference count and floating
4718  * information back to the callers. This is useful because callers can do testing of
4719  * expected reference counts in isolation and from the perspective of C. This is important
4720  * because if there are bugs in the reverse marshaling, they can obfuscate or compound
4721  * bugs in marshaling from the vfuncs.
4722  */
4723
4724 /**
4725  * gi_marshalling_tests_object_get_ref_info_for_vfunc_return_object_transfer_none:
4726  * @ref_count: (out): Ref count of the object returned from the vfunc directly after vfunc call.
4727  * @is_floating: (out): Floating state object returned from the vfunc directly after vfunc call.
4728  */
4729 void
4730   gi_marshalling_tests_object_get_ref_info_for_vfunc_return_object_transfer_none
4731   (GIMarshallingTestsObject *self, guint *ref_count, gboolean *is_floating)
4732 {
4733   GObject *object = GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_return_object_transfer_none (self);
4734   *ref_count = object->ref_count;
4735   *is_floating = g_object_is_floating (object);
4736
4737   /* Attempt to sink and unref the returned object and avoid any potential leaks */
4738   g_object_ref_sink (object);
4739   g_object_unref (object);
4740 }
4741
4742 /**
4743  * gi_marshalling_tests_object_get_ref_info_for_vfunc_return_object_transfer_full:
4744  * @ref_count: (out): Ref count of the object returned from the vfunc directly after vfunc call.
4745  * @is_floating: (out): Floating state object returned from the vfunc directly after vfunc call.
4746  */
4747 void
4748   gi_marshalling_tests_object_get_ref_info_for_vfunc_return_object_transfer_full
4749   (GIMarshallingTestsObject *self, guint *ref_count, gboolean *is_floating)
4750 {
4751   GObject *object = GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_return_object_transfer_full (self);
4752   *ref_count = object->ref_count;
4753   *is_floating = g_object_is_floating (object);
4754   g_object_unref (object);
4755 }
4756
4757 /**
4758  * gi_marshalling_tests_object_get_ref_info_for_vfunc_out_object_transfer_none:
4759  * @ref_count: (out): Ref count of the object returned from the vfunc directly after vfunc call.
4760  * @is_floating: (out): Floating state object returned from the vfunc directly after vfunc call.
4761  */
4762 void
4763   gi_marshalling_tests_object_get_ref_info_for_vfunc_out_object_transfer_none
4764   (GIMarshallingTestsObject *self, guint *ref_count, gboolean *is_floating)
4765 {
4766   GObject *object = NULL;
4767   GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_out_object_transfer_none (self, &object);
4768   *ref_count = object->ref_count;
4769   *is_floating = g_object_is_floating (object);
4770
4771   /* Attempt to sink and unref the returned object and avoid any potential leaks */
4772   g_object_ref_sink (object);
4773   g_object_unref (object);
4774 }
4775
4776 /**
4777  * gi_marshalling_tests_object_get_ref_info_for_vfunc_out_object_transfer_full:
4778  * @ref_count: (out): Ref count of the object returned from the vfunc directly after vfunc call.
4779  * @is_floating: (out): Floating state object returned from the vfunc directly after vfunc call.
4780  */
4781 void
4782   gi_marshalling_tests_object_get_ref_info_for_vfunc_out_object_transfer_full
4783   (GIMarshallingTestsObject *self, guint *ref_count, gboolean *is_floating)
4784 {
4785   GObject *object = NULL;
4786   GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_out_object_transfer_full (self, &object);
4787   *ref_count = object->ref_count;
4788   *is_floating = g_object_is_floating (object);
4789   g_object_unref (object);
4790 }
4791
4792 static void
4793 _vfunc_in_object_destroy_callback (gboolean *destroy_called,
4794                                    GObject  *where_the_object_was G_GNUC_UNUSED)
4795 {
4796   *destroy_called = TRUE;
4797 }
4798
4799 /**
4800  * gi_marshalling_tests_object_get_ref_info_for_vfunc_in_object_transfer_none:
4801  * @type: GType of object to create and pass as in argument to the vfunc
4802  * @ref_count: (out): Ref count of the in object directly after vfunc call.
4803  * @is_floating: (out): Floating state of in object directly after vfunc call.
4804  *
4805  * Calls vfunc_in_object_transfer_none with a new object of the given type.
4806  */
4807 void
4808   gi_marshalling_tests_object_get_ref_info_for_vfunc_in_object_transfer_none
4809   (GIMarshallingTestsObject *self, GType type, guint *ref_count, gboolean *is_floating)
4810 {
4811   static gboolean destroy_called;
4812   GObject *object;
4813   destroy_called = FALSE;
4814
4815   object = g_object_new (type, NULL);
4816   g_object_weak_ref (object, (GWeakNotify) _vfunc_in_object_destroy_callback, &destroy_called);
4817
4818   GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_in_object_transfer_none (self, object);
4819   if (destroy_called)
4820     {
4821       *ref_count = 0;
4822       *is_floating = FALSE;
4823     }
4824   else
4825     {
4826       *ref_count = object->ref_count;
4827       *is_floating = g_object_is_floating (object);
4828       g_object_unref (object);
4829     }
4830 }
4831
4832
4833 /**
4834  * gi_marshalling_tests_object_get_ref_info_for_vfunc_in_object_transfer_full:
4835  * @type: GType of object to create and pass as in argument to the vfunc
4836  * @ref_count: (out): Ref count of the in object directly after vfunc call.
4837  * @is_floating: (out): Floating state of in object directly after vfunc call.
4838  */
4839 void
4840   gi_marshalling_tests_object_get_ref_info_for_vfunc_in_object_transfer_full
4841   (GIMarshallingTestsObject *self, GType type, guint *ref_count, gboolean *is_floating)
4842 {
4843   static gboolean destroy_called;
4844   GObject *object;
4845   destroy_called = FALSE;
4846
4847   object = g_object_new (type, NULL);
4848   g_object_weak_ref (object, (GWeakNotify) _vfunc_in_object_destroy_callback, &destroy_called);
4849
4850   /* Calling the vfunc takes ownership of the object, so we use a weak_ref to determine
4851    * if the object gets destroyed after the call and appropriately return 0 as the ref count.
4852    */
4853   GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_in_object_transfer_full (self, object);
4854   if (destroy_called)
4855     {
4856       *ref_count = 0;
4857       *is_floating = FALSE;
4858     }
4859   else
4860     {
4861       *ref_count = object->ref_count;
4862       *is_floating = g_object_is_floating (object);
4863     }
4864 }
4865
4866
4867 G_DEFINE_TYPE (GIMarshallingTestsSubObject, gi_marshalling_tests_sub_object, GI_MARSHALLING_TESTS_TYPE_OBJECT);
4868
4869 static void
4870 gi_marshalling_tests_sub_object_init (GIMarshallingTestsSubObject *self G_GNUC_UNUSED)
4871 {
4872 }
4873
4874 static void
4875 gi_marshalling_tests_sub_object_finalize (GObject *object)
4876 {
4877   G_OBJECT_CLASS (gi_marshalling_tests_sub_object_parent_class)->finalize (object);
4878 }
4879
4880 static void
4881 method_deep_hierarchy (GIMarshallingTestsObject *self, gint8 in)
4882 {
4883   GValue val = { 0, };
4884   g_value_init (&val, G_TYPE_INT);
4885   g_value_set_int (&val, in);
4886   g_object_set_property (G_OBJECT (self), "int", &val);
4887 }
4888
4889 static void
4890 gi_marshalling_tests_sub_object_class_init (GIMarshallingTestsSubObjectClass *klass)
4891 {
4892   G_OBJECT_CLASS (klass)->finalize = gi_marshalling_tests_sub_object_finalize;
4893   GI_MARSHALLING_TESTS_OBJECT_CLASS (klass)->method_deep_hierarchy = method_deep_hierarchy;
4894 }
4895
4896 void
4897 gi_marshalling_tests_sub_object_sub_method (GIMarshallingTestsSubObject *object)
4898 {
4899   g_assert_cmpint (GI_MARSHALLING_TESTS_OBJECT (object)->int_, ==, 0);
4900 }
4901
4902 void gi_marshalling_tests_sub_object_overwritten_method (GIMarshallingTestsSubObject *object)
4903 {
4904   g_assert_cmpint (GI_MARSHALLING_TESTS_OBJECT (object)->int_, ==, 0);
4905 }
4906
4907 G_DEFINE_TYPE (GIMarshallingTestsSubSubObject,
4908                gi_marshalling_tests_sub_sub_object, GI_MARSHALLING_TESTS_TYPE_SUB_OBJECT);
4909
4910 static void
4911 gi_marshalling_tests_sub_sub_object_init (GIMarshallingTestsSubSubObject *self G_GNUC_UNUSED)
4912 {
4913 }
4914
4915 static void gi_marshalling_tests_sub_sub_object_class_init (GIMarshallingTestsSubSubObjectClass *klass G_GNUC_UNUSED)
4916 {
4917 }
4918
4919 /* Interfaces */
4920
4921 static void
4922 gi_marshalling_tests_interface_class_init (void *g_iface G_GNUC_UNUSED,
4923                                            void *data G_GNUC_UNUSED)
4924 {
4925 }
4926
4927 GType
4928 gi_marshalling_tests_interface_get_type (void)
4929 {
4930   static GType type = 0;
4931   if (type == 0)
4932     {
4933       /* Not adding prerequisite here for test purposes */
4934       type = g_type_register_static_simple (G_TYPE_INTERFACE,
4935                                             "GIMarshallingTestsInterface",
4936                                             sizeof
4937                                             (GIMarshallingTestsInterfaceIface),
4938                                             (GClassInitFunc) gi_marshalling_tests_interface_class_init, 0, NULL, 0);
4939     }
4940
4941   return type;
4942 }
4943
4944 /**
4945  * gi_marshalling_tests_interface_test_int8_in:
4946  * @in: (in):
4947  */
4948 void
4949 gi_marshalling_tests_interface_test_int8_in (GIMarshallingTestsInterface *self, gint8 in)
4950 {
4951   GI_MARSHALLING_TESTS_INTERFACE_GET_IFACE (self)->test_int8_in (self, in);
4952 }
4953
4954 /**
4955  * gi_marshalling_tests_test_interface_test_int8_in:
4956  * @in: (in):
4957  */
4958 void
4959 gi_marshalling_tests_test_interface_test_int8_in (GIMarshallingTestsInterface *test_iface, gint8 in)
4960 {
4961   gi_marshalling_tests_interface_test_int8_in (test_iface, in);
4962 }
4963
4964
4965 static void test_interface_init (GIMarshallingTestsInterfaceIface *iface);
4966
4967 G_DEFINE_TYPE_WITH_CODE (GIMarshallingTestsInterfaceImpl, gi_marshalling_tests_interface_impl, G_TYPE_OBJECT,
4968                          G_IMPLEMENT_INTERFACE(GI_MARSHALLING_TESTS_TYPE_INTERFACE, test_interface_init))
4969
4970 static void
4971 gi_marshalling_tests_interface_impl_test_int8_in (GIMarshallingTestsInterface *self G_GNUC_UNUSED,
4972                                                   gint8                        in G_GNUC_UNUSED)
4973 {
4974 }
4975
4976 static void test_interface_init (GIMarshallingTestsInterfaceIface *iface)
4977 {
4978   iface->test_int8_in = gi_marshalling_tests_interface_impl_test_int8_in;
4979 }
4980
4981 static void
4982 gi_marshalling_tests_interface_impl_init (GIMarshallingTestsInterfaceImpl *self G_GNUC_UNUSED)
4983 {
4984 }
4985
4986 static void
4987 gi_marshalling_tests_interface_impl_class_init (GIMarshallingTestsInterfaceImplClass *klass G_GNUC_UNUSED)
4988 {
4989 }
4990
4991 /**
4992  * gi_marshalling_tests_interface_impl_get_as_interface:
4993  *
4994  * Returns: (transfer none):
4995  */
4996 GIMarshallingTestsInterface *
4997 gi_marshalling_tests_interface_impl_get_as_interface (GIMarshallingTestsInterfaceImpl *self)
4998 {
4999   return (GIMarshallingTestsInterface *) self;
5000 }
5001
5002 static void
5003 gi_marshalling_tests_interface2_class_init (void *g_iface G_GNUC_UNUSED,
5004                                             void *data G_GNUC_UNUSED)
5005 {
5006 }
5007
5008 GType
5009 gi_marshalling_tests_interface2_get_type (void)
5010 {
5011   static GType type = 0;
5012   if (type == 0)
5013     {
5014       type = g_type_register_static_simple (G_TYPE_INTERFACE,
5015                                             "GIMarshallingTestsInterface2",
5016                                             sizeof
5017                                             (GIMarshallingTestsInterface2Iface),
5018                                             (GClassInitFunc) gi_marshalling_tests_interface2_class_init, 0, NULL, 0);
5019     }
5020
5021   return type;
5022 }
5023
5024 static void
5025 gi_marshalling_tests_interface3_class_init (void *g_iface G_GNUC_UNUSED,
5026                                             void *data G_GNUC_UNUSED)
5027 {
5028 }
5029
5030 GType
5031 gi_marshalling_tests_interface3_get_type (void)
5032 {
5033   static GType type = 0;
5034   if (type == 0)
5035     {
5036       type = g_type_register_static_simple (G_TYPE_INTERFACE,
5037                                             "GIMarshallingTestsInterface3",
5038                                             sizeof
5039                                             (GIMarshallingTestsInterface3Iface),
5040                                             (GClassInitFunc) gi_marshalling_tests_interface3_class_init, 0, NULL, 0);
5041     }
5042
5043   return type;
5044 }
5045
5046 /**
5047  * gi_marshalling_tests_interface3_test_variant_array_in:
5048  * @in: (array length=n_in):
5049  * @n_in:
5050  */
5051 void
5052   gi_marshalling_tests_interface3_test_variant_array_in
5053   (GIMarshallingTestsInterface3 *self, GVariant **in, gsize n_in)
5054 {
5055   GI_MARSHALLING_TESTS_INTERFACE3_GET_IFACE (self)->test_variant_array_in (self, in, n_in);
5056 }
5057
5058 /**
5059  * gi_marshalling_tests_int_out_out:
5060  * @int0: (out):
5061  * @int1: (out):
5062  */
5063 void
5064 gi_marshalling_tests_int_out_out (gint *int0, gint *int1)
5065 {
5066   *int0 = 6;
5067   *int1 = 7;
5068 }
5069
5070 /**
5071  * gi_marshalling_tests_int_three_in_three_out:
5072  * @a: (in):
5073  * @b: (in):
5074  * @c: (in):
5075  * @out0: (out):
5076  * @out1: (out):
5077  * @out2: (out):
5078  */
5079 void
5080 gi_marshalling_tests_int_three_in_three_out (gint a, gint b, gint c, gint *out0, gint *out1, gint *out2)
5081 {
5082   *out0 = a;
5083   *out1 = b;
5084   *out2 = c;
5085 }
5086
5087 /**
5088  * gi_marshalling_tests_int_return_out:
5089  * @int_: (out):
5090  */
5091 gint
5092 gi_marshalling_tests_int_return_out (gint *int_)
5093 {
5094   *int_ = 7;
5095   return 6;
5096 }
5097
5098 /**
5099 * gi_marshalling_tests_int_two_in_utf8_two_in_with_allow_none:
5100 * @a: (in): Must be 1
5101 * @b: (in): Must be 2
5102 * @c: (in) (allow-none): Must be "3" or NULL
5103 * @d: (in) (allow-none): Must be "4" or NULL
5104 */
5105 void
5106 gi_marshalling_tests_int_two_in_utf8_two_in_with_allow_none (gint a, gint b, const gchar *c, const gchar *d)
5107 {
5108     g_assert_cmpint (a, ==, 1);
5109     g_assert_cmpint (b, ==, 2);
5110     if (c != NULL)
5111         g_assert_cmpstr (c, ==, "3");
5112     if (d != NULL)
5113         g_assert_cmpstr (d, ==, "4");
5114 }
5115
5116 /**
5117 * gi_marshalling_tests_int_one_in_utf8_two_in_one_allows_none:
5118 * @a: (in): Must be 1
5119 * @b: (in) (allow-none): Must be "2" or NULL
5120 * @c: (in): Must be "3"
5121 */
5122 void
5123 gi_marshalling_tests_int_one_in_utf8_two_in_one_allows_none (gint a, const gchar *b, const gchar *c)
5124 {
5125     g_assert_cmpint (a, ==, 1);
5126     if (b != NULL)
5127         g_assert_cmpstr (b, ==, "2");
5128     g_assert_cmpstr (c, ==, "3");
5129 }
5130
5131 /**
5132  * gi_marshalling_tests_array_in_utf8_two_in:
5133  * @ints: (array length=length):
5134  * @length:
5135  * @a: (in) (allow-none): Must be "1" or NULL
5136  * @b: (in) (allow-none): Must be "2" or NULL
5137  */
5138 void
5139 gi_marshalling_tests_array_in_utf8_two_in (const gint *ints, gint length, const gchar *a, const gchar *b)
5140 {
5141   g_assert_cmpint (length, ==, 4);
5142   g_assert_cmpint (ints[0], ==, -1);
5143   g_assert_cmpint (ints[1], ==, 0);
5144   g_assert_cmpint (ints[2], ==, 1);
5145   g_assert_cmpint (ints[3], ==, 2);
5146
5147   if (a != NULL)
5148       g_assert_cmpstr (a, ==, "1");
5149   if (b != NULL)
5150       g_assert_cmpstr (b, ==, "2");
5151 }
5152
5153 /**
5154  * gi_marshalling_tests_array_in_utf8_two_in_out_of_order:
5155  * @length:
5156  * @a: (in) (allow-none): Must be "1" or NULL
5157  * @ints: (array length=length):
5158  * @b: (in) (allow-none): Must be "2" or NULL
5159  */
5160 void
5161 gi_marshalling_tests_array_in_utf8_two_in_out_of_order (gint length, const gchar *a, const gint *ints, const gchar *b)
5162 {
5163   g_assert_cmpint (length, ==, 4);
5164   g_assert_cmpint (ints[0], ==, -1);
5165   g_assert_cmpint (ints[1], ==, 0);
5166   g_assert_cmpint (ints[2], ==, 1);
5167   g_assert_cmpint (ints[3], ==, 2);
5168
5169   if (a != NULL)
5170       g_assert_cmpstr (a, ==, "1");
5171   if (b != NULL)
5172       g_assert_cmpstr (b, ==, "2");
5173 }
5174
5175 /* GError */
5176
5177 void
5178 gi_marshalling_tests_gerror (GError **error)
5179 {
5180   GQuark quark = g_quark_from_static_string (GI_MARSHALLING_TESTS_CONSTANT_GERROR_DOMAIN);
5181   g_set_error_literal (error, quark,
5182                        GI_MARSHALLING_TESTS_CONSTANT_GERROR_CODE, GI_MARSHALLING_TESTS_CONSTANT_GERROR_MESSAGE);
5183 }
5184
5185 /**
5186  * gi_marshalling_tests_gerror_array_in:
5187  * @in_ints: (array zero-terminated):
5188  */
5189 void
5190 gi_marshalling_tests_gerror_array_in (gint    *in_ints G_GNUC_UNUSED,
5191                                       GError **error)
5192 {
5193   GQuark quark = g_quark_from_static_string (GI_MARSHALLING_TESTS_CONSTANT_GERROR_DOMAIN);
5194   g_set_error_literal (error, quark,
5195                        GI_MARSHALLING_TESTS_CONSTANT_GERROR_CODE, GI_MARSHALLING_TESTS_CONSTANT_GERROR_MESSAGE);
5196 }
5197
5198 /**
5199  * gi_marshalling_tests_gerror_out:
5200  * @error: (out) (allow-none) (transfer full): location for the GError.
5201  * @debug: (out) (allow-none) (transfer full): location for the debug message
5202  *
5203  * Inspired by gst_message_parse_error.
5204  */
5205 void
5206 gi_marshalling_tests_gerror_out (GError **error, gchar **debug)
5207 {
5208   GQuark quark = g_quark_from_static_string (GI_MARSHALLING_TESTS_CONSTANT_GERROR_DOMAIN);
5209   g_set_error_literal (error, quark,
5210                        GI_MARSHALLING_TESTS_CONSTANT_GERROR_CODE, GI_MARSHALLING_TESTS_CONSTANT_GERROR_MESSAGE);
5211
5212   if (debug != NULL)
5213     {
5214       *debug = g_strdup (GI_MARSHALLING_TESTS_CONSTANT_GERROR_DEBUG_MESSAGE);
5215     }
5216 }
5217
5218 /**
5219  * gi_marshalling_tests_gerror_out_transfer_none:
5220  * @err: (out) (allow-none) (transfer none): location for the GError.
5221  * @debug: (out) (allow-none) (transfer none): location for the debug message
5222  *
5223  * A variant of gi_marshalling_tests_gerror_out() which returns data the caller
5224  * must not free.
5225  */
5226 void
5227 gi_marshalling_tests_gerror_out_transfer_none (GError **err, const gchar **debug)
5228 {
5229   static GError error = { 0,
5230     GI_MARSHALLING_TESTS_CONSTANT_GERROR_CODE,
5231     (gchar *) GI_MARSHALLING_TESTS_CONSTANT_GERROR_MESSAGE
5232   };
5233   error.domain = g_quark_from_static_string (GI_MARSHALLING_TESTS_CONSTANT_GERROR_DOMAIN);
5234   *err = &error;
5235   *debug = GI_MARSHALLING_TESTS_CONSTANT_GERROR_DEBUG_MESSAGE;
5236 }
5237
5238 /**
5239  * gi_marshalling_tests_gerror_return:
5240  *
5241  * Yet another variant of gi_marshalling_tests_gerror_out().
5242  *
5243  * Returns: (transfer full): a GError
5244  */
5245 GError *
5246 gi_marshalling_tests_gerror_return (void)
5247 {
5248   GQuark quark = g_quark_from_static_string (GI_MARSHALLING_TESTS_CONSTANT_GERROR_DOMAIN);
5249
5250   return g_error_new_literal (quark, GI_MARSHALLING_TESTS_CONSTANT_GERROR_CODE, GI_MARSHALLING_TESTS_CONSTANT_GERROR_MESSAGE);
5251 }
5252
5253 static GIMarshallingTestsOverridesStruct *
5254 gi_marshalling_tests_overrides_struct_copy (GIMarshallingTestsOverridesStruct *struct_)
5255 {
5256   GIMarshallingTestsOverridesStruct *new_struct;
5257
5258   new_struct = g_slice_new (GIMarshallingTestsOverridesStruct);
5259
5260   *new_struct = *struct_;
5261
5262   return new_struct;
5263 }
5264
5265 static void
5266 gi_marshalling_tests_overrides_struct_free (GIMarshallingTestsOverridesStruct *struct_)
5267 {
5268   g_slice_free (GIMarshallingTestsOverridesStruct, struct_);
5269 }
5270
5271 GType
5272 gi_marshalling_tests_overrides_struct_get_type (void)
5273 {
5274   static GType type = 0;
5275
5276   if (type == 0)
5277     {
5278       type =
5279         g_boxed_type_register_static ("GIMarshallingTestsOverridesStruct",
5280                                       (GBoxedCopyFunc)
5281                                       gi_marshalling_tests_overrides_struct_copy,
5282                                       (GBoxedFreeFunc) gi_marshalling_tests_overrides_struct_free);
5283     }
5284
5285   return type;
5286 }
5287
5288 GIMarshallingTestsOverridesStruct *
5289 gi_marshalling_tests_overrides_struct_new (void)
5290 {
5291   return g_slice_new (GIMarshallingTestsOverridesStruct);
5292 }
5293
5294 glong gi_marshalling_tests_overrides_struct_method (GIMarshallingTestsOverridesStruct *self G_GNUC_UNUSED)
5295 {
5296   return 42;
5297 }
5298
5299
5300 /**
5301  * gi_marshalling_tests_overrides_struct_returnv:
5302  *
5303  * Returns: (transfer full):
5304  */
5305 GIMarshallingTestsOverridesStruct *
5306 gi_marshalling_tests_overrides_struct_returnv (void)
5307 {
5308   return gi_marshalling_tests_overrides_struct_new ();
5309 }
5310
5311
5312 G_DEFINE_TYPE (GIMarshallingTestsOverridesObject, gi_marshalling_tests_overrides_object, G_TYPE_OBJECT);
5313
5314 static void
5315 gi_marshalling_tests_overrides_object_init (GIMarshallingTestsOverridesObject *self G_GNUC_UNUSED)
5316 {
5317 }
5318
5319 static void
5320 gi_marshalling_tests_overrides_object_finalize (GObject *object)
5321 {
5322   G_OBJECT_CLASS (gi_marshalling_tests_overrides_object_parent_class)->finalize (object);
5323 }
5324
5325 static void gi_marshalling_tests_overrides_object_class_init (GIMarshallingTestsOverridesObjectClass *klass)
5326 {
5327   GObjectClass *object_class = G_OBJECT_CLASS (klass);
5328 #if 0
5329   GObjectClass *parent_class = G_OBJECT_CLASS (klass);
5330 #endif
5331
5332   object_class->finalize = gi_marshalling_tests_overrides_object_finalize;
5333 }
5334
5335 GIMarshallingTestsOverridesObject *
5336 gi_marshalling_tests_overrides_object_new (void)
5337 {
5338   return g_object_new (GI_MARSHALLING_TESTS_TYPE_OVERRIDES_OBJECT, NULL);
5339 }
5340
5341 glong gi_marshalling_tests_overrides_object_method (GIMarshallingTestsOverridesObject *self G_GNUC_UNUSED)
5342 {
5343   return 42;
5344 }
5345
5346 /**
5347  * gi_marshalling_tests_overrides_object_returnv:
5348  *
5349  * Returns: (transfer full):
5350  */
5351 GIMarshallingTestsOverridesObject *
5352 gi_marshalling_tests_overrides_object_returnv (void)
5353 {
5354   return g_object_new (GI_MARSHALLING_TESTS_TYPE_OVERRIDES_OBJECT, NULL);
5355 }
5356
5357 /**
5358  * gi_marshalling_tests_filename_list_return:
5359  *
5360  * Returns: (transfer none) (element-type filename): List of filenames
5361  */
5362 GSList *
5363 gi_marshalling_tests_filename_list_return (void)
5364 {
5365   return NULL;
5366 }
5367
5368 /**
5369  * gi_marshalling_tests_param_spec_in_bool:
5370  */
5371 void
5372 gi_marshalling_tests_param_spec_in_bool (const GParamSpec *param)
5373 {
5374   g_assert (G_IS_PARAM_SPEC (param));
5375   g_assert_cmpint (G_PARAM_SPEC_VALUE_TYPE (param), ==, G_TYPE_BOOLEAN);
5376   g_assert_cmpstr (g_param_spec_get_name ((GParamSpec *) param), ==, "mybool");
5377 }
5378
5379 /**
5380  * gi_marshalling_tests_param_spec_return:
5381  *
5382  * Returns: (transfer full): a #GParamSpec
5383  */
5384 GParamSpec *
5385 gi_marshalling_tests_param_spec_return (void)
5386 {
5387   return g_param_spec_string ("test-param", "test", "This is a test", "42", G_PARAM_READABLE);
5388 }
5389
5390 /**
5391  * gi_marshalling_tests_param_spec_out:
5392  * @param: (out):
5393  */
5394 void
5395 gi_marshalling_tests_param_spec_out (GParamSpec **param)
5396 {
5397   *param = g_param_spec_string ("test-param", "test", "This is a test", "42", G_PARAM_READABLE);
5398 }
5399
5400
5401 enum
5402 {
5403   DUMMY_PROPERTY,
5404   SOME_BOOLEAN_PROPERTY,
5405   SOME_CHAR_PROPERTY,
5406   SOME_UCHAR_PROPERTY,
5407   SOME_INT_PROPERTY,
5408   SOME_UINT_PROPERTY,
5409   SOME_LONG_PROPERTY,
5410   SOME_ULONG_PROPERTY,
5411   SOME_INT64_PROPERTY,
5412   SOME_UINT64_PROPERTY,
5413   SOME_FLOAT_PROPERTY,
5414   SOME_DOUBLE_PROPERTY,
5415   SOME_STRV_PROPERTY,
5416   SOME_BOXED_STRUCT_PROPERTY,
5417   SOME_VARIANT_PROPERTY,
5418   SOME_BOXED_GLIST_PROPERTY,
5419   SOME_GVALUE_PROPERTY,
5420   SOME_OBJECT_PROPERTY,
5421   SOME_FLAGS_PROPERTY,
5422   SOME_ENUM_PROPERTY,
5423   SOME_BYTE_ARRAY_PROPERTY,
5424   SOME_READONLY_PROPERTY,
5425 };
5426
5427 G_DEFINE_TYPE (GIMarshallingTestsPropertiesObject, gi_marshalling_tests_properties_object, G_TYPE_OBJECT);
5428
5429 static void gi_marshalling_tests_properties_object_init (GIMarshallingTestsPropertiesObject *self G_GNUC_UNUSED)
5430 {
5431 }
5432
5433 static void
5434 gi_marshalling_tests_properties_object_finalize (GObject *obj)
5435 {
5436   GIMarshallingTestsPropertiesObject *self;
5437   self = GI_MARSHALLING_TESTS_PROPERTIES_OBJECT (obj);
5438
5439   if (self->some_gvalue) {
5440     g_boxed_free (G_TYPE_VALUE, self->some_gvalue);
5441     self->some_gvalue = NULL;
5442   }
5443
5444   g_clear_pointer (&self->some_strv, g_strfreev);
5445   g_clear_pointer (&self->some_boxed_struct, gi_marshalling_tests_boxed_struct_free);
5446   g_clear_pointer (&self->some_variant, g_variant_unref);
5447   g_clear_pointer (&self->some_boxed_glist, g_list_free);
5448   g_clear_object (&self->some_object);
5449
5450   G_OBJECT_CLASS (gi_marshalling_tests_properties_object_parent_class)->finalize (obj);
5451 }
5452
5453 static void
5454 gi_marshalling_tests_properties_object_get_property (GObject *object,
5455                                                      guint property_id, GValue *value, GParamSpec *pspec)
5456 {
5457   GIMarshallingTestsPropertiesObject *self;
5458   self = GI_MARSHALLING_TESTS_PROPERTIES_OBJECT (object);
5459   switch (property_id)
5460     {
5461     case SOME_BOOLEAN_PROPERTY:
5462       g_value_set_boolean (value, self->some_boolean);
5463       break;
5464     case SOME_CHAR_PROPERTY:
5465       g_value_set_schar (value, self->some_char);
5466       break;
5467     case SOME_UCHAR_PROPERTY:
5468       g_value_set_uchar (value, self->some_uchar);
5469       break;
5470     case SOME_INT_PROPERTY:
5471       g_value_set_int (value, self->some_int);
5472       break;
5473     case SOME_UINT_PROPERTY:
5474       g_value_set_uint (value, self->some_uint);
5475       break;
5476     case SOME_LONG_PROPERTY:
5477       g_value_set_long (value, self->some_long);
5478       break;
5479     case SOME_ULONG_PROPERTY:
5480       g_value_set_ulong (value, self->some_ulong);
5481       break;
5482     case SOME_INT64_PROPERTY:
5483       g_value_set_int64 (value, self->some_int64);
5484       break;
5485     case SOME_UINT64_PROPERTY:
5486       g_value_set_uint64 (value, self->some_uint64);
5487       break;
5488     case SOME_FLOAT_PROPERTY:
5489       g_value_set_float (value, self->some_float);
5490       break;
5491     case SOME_DOUBLE_PROPERTY:
5492       g_value_set_double (value, self->some_double);
5493       break;
5494     case SOME_STRV_PROPERTY:
5495       g_value_set_boxed (value, self->some_strv);
5496       break;
5497     case SOME_BOXED_STRUCT_PROPERTY:
5498       g_value_set_boxed (value, self->some_boxed_struct);
5499       break;
5500     case SOME_BOXED_GLIST_PROPERTY:
5501       g_value_set_boxed (value, self->some_boxed_glist);
5502       break;
5503     case SOME_GVALUE_PROPERTY:
5504       g_value_set_boxed (value, self->some_gvalue);
5505       break;
5506     case SOME_VARIANT_PROPERTY:
5507       g_value_set_variant (value, self->some_variant);
5508       break;
5509     case SOME_OBJECT_PROPERTY:
5510       g_value_set_object (value, self->some_object);
5511       break;
5512     case SOME_FLAGS_PROPERTY:
5513       g_value_set_flags (value, self->some_flags);
5514       break;
5515     case SOME_ENUM_PROPERTY:
5516       g_value_set_enum (value, self->some_enum);
5517       break;
5518     case SOME_BYTE_ARRAY_PROPERTY:
5519       g_value_set_boxed (value, self->some_byte_array);
5520       break;
5521     case SOME_READONLY_PROPERTY:
5522       g_value_set_int (value, 42);
5523       break;
5524     default:
5525       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
5526       break;
5527     }
5528 }
5529
5530 static void
5531 gi_marshalling_tests_properties_object_set_property (GObject *object,
5532                                                      guint property_id, const GValue *value, GParamSpec *pspec)
5533 {
5534   GIMarshallingTestsPropertiesObject *self;
5535   self = GI_MARSHALLING_TESTS_PROPERTIES_OBJECT (object);
5536   switch (property_id)
5537     {
5538     case SOME_BOOLEAN_PROPERTY:
5539       self->some_boolean = g_value_get_boolean (value);
5540       break;
5541     case SOME_CHAR_PROPERTY:
5542       self->some_char = g_value_get_schar (value);
5543       break;
5544     case SOME_UCHAR_PROPERTY:
5545       self->some_uchar = g_value_get_uchar (value);
5546       break;
5547     case SOME_INT_PROPERTY:
5548       self->some_int = g_value_get_int (value);
5549       break;
5550     case SOME_UINT_PROPERTY:
5551       self->some_uint = g_value_get_uint (value);
5552       break;
5553     case SOME_LONG_PROPERTY:
5554       self->some_long = g_value_get_long (value);
5555       break;
5556     case SOME_ULONG_PROPERTY:
5557       self->some_ulong = g_value_get_ulong (value);
5558       break;
5559     case SOME_INT64_PROPERTY:
5560       self->some_int64 = g_value_get_int64 (value);
5561       break;
5562     case SOME_UINT64_PROPERTY:
5563       self->some_uint64 = g_value_get_uint64 (value);
5564       break;
5565     case SOME_FLOAT_PROPERTY:
5566       self->some_float = g_value_get_float (value);
5567       break;
5568     case SOME_DOUBLE_PROPERTY:
5569       self->some_double = g_value_get_double (value);
5570       break;
5571     case SOME_STRV_PROPERTY:
5572       g_strfreev (self->some_strv);
5573       self->some_strv = g_strdupv (g_value_get_boxed (value));
5574       break;
5575     case SOME_BOXED_STRUCT_PROPERTY:
5576       gi_marshalling_tests_boxed_struct_free (self->some_boxed_struct);
5577       self->some_boxed_struct = gi_marshalling_tests_boxed_struct_copy (g_value_get_boxed (value));
5578       break;
5579     case SOME_BOXED_GLIST_PROPERTY:
5580       g_list_free (self->some_boxed_glist);
5581       self->some_boxed_glist = g_list_copy (g_value_get_boxed (value));
5582       break;
5583     case SOME_GVALUE_PROPERTY:
5584       if (self->some_gvalue)
5585         g_boxed_free (G_TYPE_VALUE, self->some_gvalue);
5586       self->some_gvalue = g_value_dup_boxed (value);
5587       break;
5588     case SOME_VARIANT_PROPERTY:
5589       if (self->some_variant != NULL)
5590         g_variant_unref (self->some_variant);
5591       self->some_variant = g_value_get_variant (value);
5592       if (self->some_variant != NULL)
5593         g_variant_ref (self->some_variant);
5594       break;
5595     case SOME_OBJECT_PROPERTY:
5596       if (self->some_object != NULL)
5597         g_object_unref (self->some_object);
5598       self->some_object = g_value_dup_object (value);
5599       break;
5600     case SOME_FLAGS_PROPERTY:
5601       self->some_flags = g_value_get_flags (value);
5602       break;
5603     case SOME_ENUM_PROPERTY:
5604       self->some_enum = g_value_get_enum (value);
5605       break;
5606     case SOME_BYTE_ARRAY_PROPERTY:
5607       if (self->some_byte_array != NULL)
5608         g_byte_array_unref (self->some_byte_array);
5609       self->some_byte_array = g_value_dup_boxed (value);
5610       break;
5611     default:
5612       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
5613       break;
5614     }
5615 }
5616
5617 static void gi_marshalling_tests_properties_object_class_init (GIMarshallingTestsPropertiesObjectClass *klass)
5618 {
5619   GObjectClass *object_class = G_OBJECT_CLASS (klass);
5620
5621   object_class->finalize = gi_marshalling_tests_properties_object_finalize;
5622   object_class->get_property = gi_marshalling_tests_properties_object_get_property;
5623   object_class->set_property = gi_marshalling_tests_properties_object_set_property;
5624
5625   g_object_class_install_property (object_class, SOME_BOOLEAN_PROPERTY,
5626                                    g_param_spec_boolean ("some-boolean",
5627                                                          "some-boolean",
5628                                                          "some-boolean",
5629                                                          FALSE,
5630                                                          G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5631
5632   g_object_class_install_property (object_class, SOME_CHAR_PROPERTY,
5633                                    g_param_spec_char ("some-char",
5634                                                       "some-char",
5635                                                       "some-char", G_MININT8,
5636                                                       G_MAXINT8, 0,
5637                                                       G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5638
5639   g_object_class_install_property (object_class, SOME_UCHAR_PROPERTY,
5640                                    g_param_spec_uchar ("some-uchar",
5641                                                        "some-uchar",
5642                                                        "some-uchar", 0,
5643                                                        G_MAXUINT8, 0,
5644                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5645
5646   g_object_class_install_property (object_class, SOME_INT_PROPERTY,
5647                                    g_param_spec_int ("some-int", "some-int",
5648                                                      "some-int", G_MININT,
5649                                                      G_MAXINT, 0,
5650                                                      G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5651
5652   g_object_class_install_property (object_class, SOME_UINT_PROPERTY,
5653                                    g_param_spec_uint ("some-uint",
5654                                                       "some-uint",
5655                                                       "some-uint", 0,
5656                                                       G_MAXUINT, 0,
5657                                                       G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5658
5659   g_object_class_install_property (object_class, SOME_LONG_PROPERTY,
5660                                    g_param_spec_long ("some-long",
5661                                                       "some-long",
5662                                                       "some-long", G_MINLONG,
5663                                                       G_MAXLONG, 0,
5664                                                       G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5665
5666   g_object_class_install_property (object_class, SOME_ULONG_PROPERTY,
5667                                    g_param_spec_ulong ("some-ulong",
5668                                                        "some-ulong",
5669                                                        "some-ulong", 0,
5670                                                        G_MAXULONG, 0,
5671                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5672
5673   g_object_class_install_property (object_class, SOME_INT64_PROPERTY,
5674                                    g_param_spec_int64 ("some-int64",
5675                                                        "some-int64",
5676                                                        "some-int64",
5677                                                        G_MININT64, G_MAXINT64,
5678                                                        0, G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5679
5680   g_object_class_install_property (object_class, SOME_UINT64_PROPERTY,
5681                                    g_param_spec_uint64 ("some-uint64",
5682                                                         "some-uint64",
5683                                                         "some-uint64", 0,
5684                                                         G_MAXUINT64, 0,
5685                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5686
5687   g_object_class_install_property (object_class, SOME_FLOAT_PROPERTY,
5688                                    g_param_spec_float ("some-float",
5689                                                        "some-float",
5690                                                        "some-float",
5691                                                        -1 * G_MAXFLOAT,
5692                                                        G_MAXFLOAT, 0,
5693                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5694
5695   g_object_class_install_property (object_class, SOME_DOUBLE_PROPERTY,
5696                                    g_param_spec_double ("some-double",
5697                                                         "some-double",
5698                                                         "some-double",
5699                                                         -1 * G_MAXDOUBLE,
5700                                                         G_MAXDOUBLE, 0,
5701                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5702
5703   g_object_class_install_property (object_class, SOME_STRV_PROPERTY,
5704                                    g_param_spec_boxed ("some-strv",
5705                                                        "some-strv",
5706                                                        "some-strv",
5707                                                        G_TYPE_STRV,
5708                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5709
5710   g_object_class_install_property (object_class, SOME_BOXED_STRUCT_PROPERTY,
5711                                    g_param_spec_boxed ("some-boxed-struct",
5712                                                        "some-boxed-struct",
5713                                                        "some-boxed-struct",
5714                                                        gi_marshalling_tests_boxed_struct_get_type
5715                                                        (), G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5716
5717     /**
5718      * GIMarshallingTestsPropertiesObject:some-boxed-glist: (type GLib.List(gint)) (transfer none):
5719      */
5720   g_object_class_install_property (object_class, SOME_BOXED_GLIST_PROPERTY,
5721                                    g_param_spec_boxed ("some-boxed-glist",
5722                                                        "some-boxed-glist",
5723                                                        "some-boxed-glist",
5724                                                        gi_marshalling_tests_boxed_glist_get_type
5725                                                        (), G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5726
5727   g_object_class_install_property (object_class, SOME_GVALUE_PROPERTY,
5728                                    g_param_spec_boxed ("some-gvalue",
5729                                                        "some-gvalue",
5730                                                        "some-gvalue",
5731                                                        G_TYPE_VALUE,
5732                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
5733
5734   g_object_class_install_property (object_class, SOME_VARIANT_PROPERTY,
5735                                    g_param_spec_variant ("some-variant",
5736                                                          "some-variant",
5737                                                          "some-variant",
5738                                                          G_VARIANT_TYPE_ANY,
5739                                                          NULL,
5740                                                          G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5741
5742   g_object_class_install_property (object_class, SOME_OBJECT_PROPERTY,
5743                                    g_param_spec_object ("some-object",
5744                                                         "some-object",
5745                                                         "some-object",
5746                                                         G_TYPE_OBJECT,
5747                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5748
5749   g_object_class_install_property (object_class, SOME_FLAGS_PROPERTY,
5750                                    g_param_spec_flags ("some-flags",
5751                                                        "some-flags",
5752                                                        "some-flags",
5753                                                        GI_MARSHALLING_TESTS_TYPE_FLAGS,
5754                                                        GI_MARSHALLING_TESTS_FLAGS_VALUE1,
5755                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5756
5757   g_object_class_install_property (object_class, SOME_ENUM_PROPERTY,
5758                                    g_param_spec_enum ("some-enum",
5759                                                       "some-enum",
5760                                                       "some-enum",
5761                                                       GI_MARSHALLING_TESTS_TYPE_GENUM,
5762                                                       GI_MARSHALLING_TESTS_GENUM_VALUE1,
5763                                                       G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
5764
5765   g_object_class_install_property (object_class, SOME_BYTE_ARRAY_PROPERTY,
5766                                    g_param_spec_boxed ("some-byte-array",
5767                                                        "some-byte-array",
5768                                                        "some-byte-array",
5769                                                        G_TYPE_BYTE_ARRAY,
5770                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
5771
5772   g_object_class_install_property (object_class, SOME_READONLY_PROPERTY,
5773                                    g_param_spec_int ("some-readonly",
5774                                                      "some-readonly",
5775                                                      "some-readonly",
5776                                                      G_MININT, G_MAXINT, 0,
5777                                                      G_PARAM_READABLE));
5778 }
5779
5780 GIMarshallingTestsPropertiesObject *
5781 gi_marshalling_tests_properties_object_new (void)
5782 {
5783   return g_object_new (GI_MARSHALLING_TESTS_TYPE_PROPERTIES_OBJECT, NULL);
5784 }