Branch data Line data Source code
1 : : /*
2 : : SPDX-License-Identifier: LGPL-2.1-or-later
3 : : SPDX-FileCopyrightText: 2018 PyGObject contributors
4 : : */
5 : :
6 : : #include <string.h>
7 : :
8 : : #ifndef GI_TEST_DISABLE_CAIRO
9 : : #include <cairo.h>
10 : : #endif /* GI_TEST_DISABLE_CAIRO */
11 : : #include <glib-object.h>
12 : :
13 : : #include "regress.h"
14 : : #include "regressextra.h"
15 : :
16 : : struct _RegressTestBoxedCWrapper
17 : : {
18 : : RegressTestBoxedC *cptr;
19 : : };
20 : :
21 : : RegressTestBoxedCWrapper *
22 : 1 : regress_test_boxed_c_wrapper_new (void)
23 : : {
24 : : RegressTestBoxedCWrapper *boxed;
25 : 1 : boxed = g_slice_new (RegressTestBoxedCWrapper);
26 : 1 : boxed->cptr = regress_test_boxed_c_new ();
27 : 1 : return boxed;
28 : : }
29 : :
30 : : RegressTestBoxedCWrapper *
31 : 2 : regress_test_boxed_c_wrapper_copy (RegressTestBoxedCWrapper *self)
32 : : {
33 : : RegressTestBoxedCWrapper *ret_boxed;
34 : 2 : ret_boxed = g_slice_new (RegressTestBoxedCWrapper);
35 : 2 : ret_boxed->cptr = g_boxed_copy (regress_test_boxed_c_get_type (), self->cptr);
36 : 2 : return ret_boxed;
37 : : }
38 : :
39 : : static void
40 : 3 : regress_test_boxed_c_wrapper_free (RegressTestBoxedCWrapper *boxed)
41 : : {
42 : 3 : g_boxed_free (regress_test_boxed_c_get_type (), boxed->cptr);
43 : 3 : g_slice_free (RegressTestBoxedCWrapper, boxed);
44 : 3 : }
45 : :
46 [ + + + - : 14 : G_DEFINE_BOXED_TYPE (RegressTestBoxedCWrapper,
+ + ]
47 : : regress_test_boxed_c_wrapper,
48 : : regress_test_boxed_c_wrapper_copy,
49 : : regress_test_boxed_c_wrapper_free);
50 : :
51 : : /**
52 : : * regress_test_boxed_c_wrapper_get
53 : : * @self: a #RegressTestBoxedCWrapper objects
54 : : *
55 : : * Returns: (transfer none): associated #RegressTestBoxedC
56 : : **/
57 : : RegressTestBoxedC *
58 : 2 : regress_test_boxed_c_wrapper_get (RegressTestBoxedCWrapper *self)
59 : : {
60 : 2 : return self->cptr;
61 : : }
62 : :
63 : : /**
64 : : * regress_test_array_of_non_utf8_strings
65 : : * Returns: (transfer full) (allow-none) (array zero-terminated=1): Array of strings
66 : : */
67 : : gchar **
68 : 1 : regress_test_array_of_non_utf8_strings (void)
69 : : {
70 : 1 : char **ret = g_new (char *, 2);
71 : 1 : ret[0] = g_strdup ("Andr\351 Lur\347at");
72 : 1 : ret[1] = NULL;
73 : 1 : return ret;
74 : : }
75 : :
76 : : /**
77 : : * regress_test_array_fixed_boxed_none_out
78 : : * @objs: (out) (array fixed-size=2) (transfer none): An array of #RegressTestBoxedC
79 : : **/
80 : : void
81 : 1 : regress_test_array_fixed_boxed_none_out (RegressTestBoxedC ***objs)
82 : : {
83 : : static RegressTestBoxedC **arr;
84 : :
85 [ + - ]: 1 : if (arr == NULL)
86 : : {
87 : 1 : arr = g_new0 (RegressTestBoxedC *, 3);
88 : 1 : arr[0] = regress_test_boxed_c_new ();
89 : 1 : arr[1] = regress_test_boxed_c_new ();
90 : : }
91 : :
92 : 1 : *objs = arr;
93 : 1 : }
94 : :
95 : : /**
96 : : * regress_test_gvalue_out_boxed:
97 : : * @value: (out) (transfer full): the output gvalue
98 : : * @init: (in): the initialisation value
99 : : **/
100 : : void
101 : 1 : regress_test_gvalue_out_boxed (GValue *value, int init)
102 : : {
103 : : RegressTestBoxed rtb;
104 : 1 : GValue v = G_VALUE_INIT;
105 : :
106 : 1 : memset (&rtb, 0, sizeof (rtb));
107 : 1 : rtb.some_int8 = init;
108 : 1 : g_value_init (&v, REGRESS_TEST_TYPE_BOXED);
109 : 1 : g_value_set_boxed (&v, &rtb);
110 : 1 : *value = v;
111 : 1 : }
112 : :
113 : : /**
114 : : * regress_test_glist_boxed_none_return
115 : : * Return value: (element-type RegressTestBoxedC) (transfer none):
116 : : **/
117 : : GList *
118 : 1 : regress_test_glist_boxed_none_return (guint count)
119 : : {
120 : : static GList *list = NULL;
121 [ + - ]: 1 : if (!list)
122 : : {
123 [ + + ]: 3 : while (count > 0)
124 : : {
125 : 2 : list = g_list_prepend (list, regress_test_boxed_c_new ());
126 : 2 : count--;
127 : : }
128 : : }
129 : :
130 : 1 : return list;
131 : : }
132 : :
133 : : /**
134 : : * regress_test_glist_boxed_full_return
135 : : * Return value: (element-type RegressTestBoxedC) (transfer full):
136 : : **/
137 : : GList *
138 : 1 : regress_test_glist_boxed_full_return (guint count)
139 : : {
140 : 1 : GList *list = NULL;
141 [ + + ]: 3 : while (count > 0)
142 : : {
143 : 2 : list = g_list_prepend (list, regress_test_boxed_c_new ());
144 : 2 : count--;
145 : : }
146 : 1 : return list;
147 : : }
148 : :
149 : : /**
150 : : * regress_test_array_of_fundamental_objects_in
151 : : * @list: (array length=len) (element-type RegressTestFundamentalObject): An array of #RegressTestFundamentalObject
152 : : * @len: length of the list
153 : : **/
154 : : gboolean
155 : 1 : regress_test_array_of_fundamental_objects_in (RegressTestFundamentalObject **list, gsize len)
156 : : {
157 : : gsize i;
158 : :
159 [ + + ]: 3 : for (i = 0; i < len; i++)
160 : : {
161 [ - + + - : 2 : if (!REGRESS_TEST_IS_FUNDAMENTAL_OBJECT (list[i]))
- + - + ]
162 : : {
163 : 0 : return FALSE;
164 : : }
165 : : }
166 : 1 : return TRUE;
167 : : }
168 : :
169 : : /**
170 : : * regress_test_array_of_fundamental_objects_out
171 : : * @len: (out): length of the list
172 : : * Returns: (array length=len) (transfer full): An array of #RegressTestFundamentalObject
173 : : **/
174 : : RegressTestFundamentalObject **
175 : 1 : regress_test_array_of_fundamental_objects_out (gsize *len)
176 : : {
177 : : RegressTestFundamentalObject **objs;
178 : : int i;
179 : :
180 : 1 : objs = g_new (RegressTestFundamentalObject *, 2);
181 : :
182 [ + + ]: 3 : for (i = 0; i < 2; i++)
183 : : {
184 : 2 : objs[i] = (RegressTestFundamentalObject *) regress_test_fundamental_sub_object_new ("foo");
185 : : }
186 : 1 : *len = 2;
187 : 1 : return objs;
188 : : }
189 : :
190 : : /**
191 : : * regress_test_fundamental_argument_in
192 : : * @obj: (transfer full): A #RegressTestFundamentalObject
193 : : **/
194 : : gboolean
195 : 1 : regress_test_fundamental_argument_in (RegressTestFundamentalObject *obj)
196 : : {
197 [ - + + - : 1 : gboolean retval = REGRESS_TEST_IS_FUNDAMENTAL_OBJECT (obj);
- + ]
198 : 1 : regress_test_fundamental_object_unref(obj);
199 : 1 : return retval;
200 : : }
201 : :
202 : : /**
203 : : * regress_test_fundamental_argument_out
204 : : * @obj: (transfer none): A #RegressTestFundamentalObject
205 : : * Returns: (transfer none): Same #RegressTestFundamentalObject
206 : : **/
207 : : RegressTestFundamentalObject *
208 : 1 : regress_test_fundamental_argument_out (RegressTestFundamentalObject *obj)
209 : : {
210 : 1 : return obj;
211 : : }
212 : :
213 : : #ifndef GI_TEST_DISABLE_CAIRO
214 : :
215 : : /**
216 : : * regress_test_cairo_context_none_return:
217 : : *
218 : : * Returns: (transfer none):
219 : : */
220 : : cairo_t *
221 : 2 : regress_test_cairo_context_none_return (void)
222 : : {
223 : : static cairo_t *cr;
224 : :
225 [ + + ]: 2 : if (cr == NULL)
226 : : {
227 : : cairo_surface_t *surface;
228 : 1 : surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 10, 10);
229 : 1 : cr = cairo_create (surface);
230 : 1 : cairo_surface_destroy (surface);
231 : : }
232 : :
233 : 2 : return cr;
234 : : }
235 : :
236 : : /**
237 : : * regress_test_cairo_context_full_in:
238 : : * @context: (transfer full):
239 : : */
240 : : void
241 : 1 : regress_test_cairo_context_full_in (cairo_t *context)
242 : : {
243 : 1 : cairo_destroy (context);
244 : 1 : }
245 : :
246 : : /**
247 : : * regress_test_cairo_path_full_return:
248 : : *
249 : : * Returns: (transfer full):
250 : : */
251 : : cairo_path_t *
252 : 1 : regress_test_cairo_path_full_return (void)
253 : : {
254 : 1 : cairo_t *cr = regress_test_cairo_context_none_return ();
255 : :
256 : 1 : return cairo_copy_path (cr);
257 : : }
258 : :
259 : : /**
260 : : * regress_test_cairo_path_none_in:
261 : : * @path: (transfer none):
262 : : */
263 : : void
264 : 1 : regress_test_cairo_path_none_in (cairo_path_t *path)
265 : : {
266 : 1 : cairo_t *cr = regress_test_cairo_context_full_return ();
267 : 1 : cairo_append_path (cr, path);
268 : 1 : g_assert (cairo_status (cr) == CAIRO_STATUS_SUCCESS);
269 : 1 : cairo_destroy (cr);
270 : 1 : }
271 : :
272 : : /**
273 : : * regress_test_cairo_path_full_in_full_return:
274 : : * @path: (transfer full):
275 : : *
276 : : * Returns: (transfer full):
277 : : */
278 : : cairo_path_t *
279 : 1 : regress_test_cairo_path_full_in_full_return (cairo_path_t *path)
280 : : {
281 : 1 : return path;
282 : : }
283 : :
284 : : /**
285 : : * regress_test_cairo_pattern_full_in:
286 : : * @pattern: (transfer full):
287 : : */
288 : : void
289 : 1 : regress_test_cairo_pattern_full_in (cairo_pattern_t *pattern)
290 : : {
291 : 1 : cairo_pattern_destroy (pattern);
292 : 1 : }
293 : :
294 : : /**
295 : : * regress_test_cairo_pattern_none_in:
296 : : * @pattern: (transfer none):
297 : : */
298 : : void
299 : 1 : regress_test_cairo_pattern_none_in (cairo_pattern_t *pattern)
300 : : {
301 : 1 : cairo_t *cr = regress_test_cairo_context_full_return ();
302 : 1 : cairo_set_source (cr, pattern);
303 : 1 : g_assert (cairo_status (cr) == CAIRO_STATUS_SUCCESS);
304 : 1 : cairo_destroy (cr);
305 : 1 : }
306 : :
307 : : /**
308 : : * regress_test_cairo_pattern_none_return:
309 : : *
310 : : * Returns: (transfer none):
311 : : */
312 : : cairo_pattern_t *
313 : 1 : regress_test_cairo_pattern_none_return (void)
314 : : {
315 : : static cairo_pattern_t *pattern;
316 : :
317 [ + - ]: 1 : if (pattern == NULL)
318 : : {
319 : 1 : pattern = cairo_pattern_create_rgb (0.1, 0.2, 0.3);
320 : : }
321 : :
322 : 1 : return pattern;
323 : : }
324 : :
325 : : /**
326 : : * regress_test_cairo_pattern_full_return:
327 : : *
328 : : * Returns: (transfer full):
329 : : */
330 : : cairo_pattern_t *
331 : 1 : regress_test_cairo_pattern_full_return (void)
332 : : {
333 : 1 : cairo_pattern_t *pattern = cairo_pattern_create_rgb (0.5, 0.6, 0.7);
334 : 1 : return pattern;
335 : : }
336 : :
337 : : /**
338 : : * regress_test_cairo_region_full_in:
339 : : * @region: (transfer full):
340 : : */
341 : : void
342 : 1 : regress_test_cairo_region_full_in (cairo_region_t *region)
343 : : {
344 : 1 : cairo_region_destroy (region);
345 : 1 : }
346 : :
347 : : /**
348 : : * regress_test_cairo_surface_full_in:
349 : : * @surface: (transfer full):
350 : : */
351 : : void
352 : 1 : regress_test_cairo_surface_full_in (cairo_surface_t *surface)
353 : : {
354 : 1 : g_assert (cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32);
355 : 1 : g_assert (cairo_image_surface_get_width (surface) == 10);
356 : 1 : g_assert (cairo_image_surface_get_height (surface) == 10);
357 : 1 : cairo_surface_destroy (surface);
358 : 1 : }
359 : :
360 : : /**
361 : : * regress_test_cairo_font_options_full_return:
362 : : *
363 : : * Returns: (transfer full):
364 : : */
365 : : cairo_font_options_t *
366 : 0 : regress_test_cairo_font_options_full_return (void)
367 : : {
368 : 0 : return cairo_font_options_create ();
369 : : }
370 : :
371 : : /**
372 : : * regress_test_cairo_font_options_none_return:
373 : : *
374 : : * Returns: (transfer none):
375 : : */
376 : : cairo_font_options_t *
377 : 0 : regress_test_cairo_font_options_none_return (void)
378 : : {
379 : : static cairo_font_options_t *options;
380 : :
381 [ # # ]: 0 : if (options == NULL)
382 : 0 : options = cairo_font_options_create ();
383 : :
384 : 0 : return options;
385 : : }
386 : :
387 : : /**
388 : : * regress_test_cairo_font_options_full_in:
389 : : * @options: (transfer full):
390 : : */
391 : : void
392 : 0 : regress_test_cairo_font_options_full_in (cairo_font_options_t *options)
393 : : {
394 : 0 : cairo_font_options_destroy (options);
395 : 0 : }
396 : :
397 : : /**
398 : : * regress_test_cairo_font_options_none_in:
399 : : * @options: (transfer none):
400 : : */
401 : : void
402 : 0 : regress_test_cairo_font_options_none_in (cairo_font_options_t *options G_GNUC_UNUSED)
403 : : {
404 : 0 : }
405 : :
406 : : /**
407 : : * regress_test_cairo_font_face_full_return:
408 : : * @cairo: (transfer none):
409 : : *
410 : : * Returns: (transfer full):
411 : : */
412 : : cairo_font_face_t *
413 : 0 : regress_test_cairo_font_face_full_return (cairo_t *cairo)
414 : : {
415 : 0 : cairo_font_face_t *font_face = cairo_get_font_face (cairo);
416 : :
417 : 0 : return cairo_font_face_reference (font_face);
418 : : }
419 : :
420 : : /**
421 : : * regress_test_cairo_scaled_font_full_return:
422 : : * @cairo: (transfer none):
423 : : *
424 : : * Returns: (transfer full):
425 : : */
426 : : cairo_scaled_font_t *
427 : 0 : regress_test_cairo_scaled_font_full_return (cairo_t *cairo)
428 : : {
429 : 0 : cairo_scaled_font_t *scaled_font = cairo_get_scaled_font (cairo);
430 : :
431 : 0 : return cairo_scaled_font_reference (scaled_font);
432 : : }
433 : :
434 : : /**
435 : : * regress_test_cairo_matrix_none_in:
436 : : * @matrix: (transfer none):
437 : : */
438 : : void
439 : 0 : regress_test_cairo_matrix_none_in (const cairo_matrix_t *matrix)
440 : : {
441 : 0 : cairo_matrix_t m = *matrix;
442 : 0 : g_assert (m.x0 == 0);
443 : 0 : g_assert (m.y0 == 0);
444 : 0 : g_assert (m.xx == 1);
445 : 0 : g_assert (m.xy == 0);
446 : 0 : g_assert (m.yy == 1);
447 : 0 : g_assert (m.yx == 0);
448 : 0 : }
449 : :
450 : : /**
451 : : * regress_test_cairo_matrix_none_return:
452 : : * Returns: (transfer none):
453 : : */
454 : : cairo_matrix_t *
455 : 0 : regress_test_cairo_matrix_none_return (void)
456 : : {
457 : : static cairo_matrix_t matrix;
458 : 0 : cairo_matrix_init_identity (&matrix);
459 : 0 : return &matrix;
460 : : }
461 : :
462 : : /**
463 : : * regress_test_cairo_matrix_out_caller_allocates:
464 : : * @matrix: (out):
465 : : */
466 : : void
467 : 0 : regress_test_cairo_matrix_out_caller_allocates (cairo_matrix_t *matrix)
468 : : {
469 : : cairo_matrix_t m;
470 : 0 : cairo_matrix_init_identity (&m);
471 : 0 : *matrix = m;
472 : 0 : }
473 : :
474 : : #endif
475 : :
476 [ + + + - : 10 : G_DEFINE_TYPE (RegressTestAction, regress_test_action, G_TYPE_INITIALLY_UNOWNED)
+ + ]
477 : :
478 : : enum
479 : : {
480 : : SIGNAL_0,
481 : : ACTION_SIGNAL,
482 : : ACTION2_SIGNAL,
483 : : LAST_SIGNAL
484 : : };
485 : :
486 : : static guint regress_test_action_signals[LAST_SIGNAL] = { 0 };
487 : :
488 : : static RegressTestAction *
489 : 0 : regress_test_action_do_action (RegressTestAction *self G_GNUC_UNUSED)
490 : : {
491 : 0 : RegressTestAction *ret = g_object_new (regress_test_action_get_type (), NULL);
492 : :
493 : 0 : return ret;
494 : : }
495 : :
496 : : static RegressTestAction *
497 : 1 : regress_test_action_do_action2 (RegressTestAction *self G_GNUC_UNUSED)
498 : : {
499 : 1 : return NULL;
500 : : }
501 : :
502 : : static void
503 : 1 : regress_test_action_init (RegressTestAction *self G_GNUC_UNUSED)
504 : : {
505 : 1 : }
506 : :
507 : : static void
508 : 2 : regress_test_action_class_init (RegressTestActionClass *klass)
509 : : {
510 : : /**
511 : : * RegressTestAction::action:
512 : : *
513 : : * An action signal.
514 : : *
515 : : * Returns: (transfer full): another #RegressTestAction
516 : : */
517 : 2 : regress_test_action_signals[ACTION_SIGNAL] =
518 : 2 : g_signal_new_class_handler ("action",
519 : : G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
520 : : G_CALLBACK (regress_test_action_do_action), NULL, NULL,
521 : : NULL, regress_test_action_get_type (), 0);
522 : :
523 : : /**
524 : : * RegressTestAction::action2:
525 : : *
526 : : * Another action signal.
527 : : *
528 : : * Returns: (transfer full): another #RegressTestAction
529 : : */
530 : 2 : regress_test_action_signals[ACTION2_SIGNAL] =
531 : 2 : g_signal_new_class_handler ("action2",
532 : : G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
533 : : G_CALLBACK (regress_test_action_do_action2), NULL, NULL,
534 : : NULL, regress_test_action_get_type (), 0);
535 : 2 : }
536 : :
537 : : /*
538 : : * RegressBitmask
539 : : *
540 : : * Mimic a primitive, fundamental type.
541 : : */
542 : :
543 : : static void
544 : 0 : regress_value_init_bitmask (GValue *value)
545 : : {
546 : 0 : value->data[0].v_uint64 = 0;
547 : 0 : }
548 : :
549 : : static void
550 : 0 : regress_value_copy_bitmask (const GValue *src_value, GValue *dest_value)
551 : : {
552 : 0 : dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
553 : 0 : }
554 : :
555 : : static void
556 : 0 : _value_transform_uint64_bitmask (const GValue *src_value, GValue *dest_value)
557 : : {
558 : 0 : dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
559 : 0 : }
560 : :
561 : : static void
562 : 0 : _value_transform_bitmask_uint64 (const GValue *src_value, GValue *dest_value)
563 : : {
564 : 0 : dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
565 : 0 : }
566 : :
567 : : static const GTypeValueTable _regress_bitmask_value_table = {
568 : : regress_value_init_bitmask,
569 : : NULL,
570 : : regress_value_copy_bitmask,
571 : : NULL,
572 : : (char *) NULL,
573 : : NULL,
574 : : (char *) NULL,
575 : : NULL
576 : : };
577 : :
578 : : GType
579 : 3 : regress_bitmask_get_type (void)
580 : : {
581 : : static GType regress_bitmask_type = 0;
582 : :
583 [ + + + - : 3 : if (g_once_init_enter (®ress_bitmask_type))
+ + ]
584 : : {
585 : 1 : GTypeInfo _info = { 0, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, &_regress_bitmask_value_table };
586 : 1 : GTypeFundamentalInfo _finfo = { 0 };
587 : 1 : GType _type = g_type_register_fundamental (
588 : : g_type_fundamental_next (),
589 : : "RegressBitmask", &_info, &_finfo, 0);
590 : :
591 : 1 : g_once_init_leave (®ress_bitmask_type, _type);
592 : :
593 : 1 : g_value_register_transform_func (
594 : : REGRESS_TYPE_BITMASK, G_TYPE_UINT64,
595 : : _value_transform_bitmask_uint64);
596 : 1 : g_value_register_transform_func (
597 : : G_TYPE_UINT64, REGRESS_TYPE_BITMASK,
598 : : _value_transform_uint64_bitmask);
599 : : }
600 : :
601 : 3 : return regress_bitmask_type;
602 : : }
|