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