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