GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tests/gatecore_test/test_wrappers.c
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 28 28 100.0%
Functions: 3 3 100.0%
Branches: 11 18 61.1%

Line Branch Exec Source
1 #include "gate/tests.h"
2 #include "test_wrappers.h"
3
4 #include "gate/wrappers.h"
5 #include "gate/typeids.h"
6 #include "gate/debugging.h"
7
8 static gate_bool_t bv = true;
9 static gate_int8_t i8v = 123;
10 static gate_int16_t i16v = 123;
11 static gate_int32_t i32v = 123;
12 static gate_int64_t i64v = 123;
13 static gate_uint8_t ui8v = 123;
14 static gate_uint16_t ui16v = 123;
15 static gate_uint32_t ui32v = 123;
16 static gate_uint64_t ui64v = 123;
17 static gate_real32_t r32v = 123.456f;
18 static gate_real64_t r64v = 123.456;
19 static gate_string_t strv = GATE_STRING_INIT_EMPTY;
20
21 struct test_item
22 {
23 void* ptr;
24 gate_type_id_t tid;
25 };
26
27 static struct test_item test_items[] = {
28 { &bv, GATE_TYPE_BOOL },
29 { &i8v, GATE_TYPE_I8 },
30 { &i16v, GATE_TYPE_I16 },
31 { &i32v, GATE_TYPE_I32 },
32 { &i64v, GATE_TYPE_I64 },
33 { &ui8v, GATE_TYPE_UI8 },
34 { &ui16v, GATE_TYPE_UI16 },
35 { &ui32v, GATE_TYPE_UI32 },
36 { &ui64v, GATE_TYPE_UI64 },
37 { &r32v, GATE_TYPE_R32 },
38 { &r64v, GATE_TYPE_R64 },
39 { &strv, GATE_TYPE_STRING }
40 };
41 static gate_size_t test_items_count = sizeof(test_items) / sizeof(test_items[0]);
42
43 static gate_wrapper_type_info_t infos[sizeof(test_items) / sizeof(test_items[0])];
44
45 1 static gate_bool_t init_wrapper_types()
46 {
47 gate_size_t ndx;
48
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1 times.
13 for (ndx = 0; ndx != test_items_count; ++ndx)
49 {
50 12 gate_wrapper_type_info_init(&infos[ndx], test_items[ndx].tid);
51 }
52 1 return true;
53 }
54
55 1 static gate_bool_t check_variant_contents(gate_variant_t* v)
56 {
57 gate_size_t ndx;
58
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1 times.
13 for (ndx = 0; ndx != test_items_count; ++ndx)
59 {
60 12 void* ptr_orig = test_items[ndx].ptr;
61 12 gate_type_id_t tid = test_items[ndx].tid;
62 12 gate_size_t length = gate_type_length(tid);
63 12 void const* signature = gate_type_signature(tid);
64
65 12 void* ptr_var = NULL;
66
67
1/2
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
12 GATE_TEST_CHECK_OK(gate_variant_set_content(v, ptr_orig, length, signature));
68
69 12 ptr_var = gate_variant_get_content(v);
70
1/2
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 GATE_TEST_CHECK(ptr_var != NULL);
71
1/2
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
12 GATE_TEST_CHECK_EQUAL(gate_variant_get_size(v), length);
72
1/2
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
12 GATE_TEST_CHECK_EQUAL(gate_variant_get_type(v), signature);
73 }
74 1 return true;
75 }
76
77 1 GATE_TEST_FUNCTION(test_wrappers)
78 {
79 1 GATE_TEST_UNIT_BEGIN(test_wrappers);
80
81 {
82 1 gate_variant_t* v = NULL;
83
84
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(init_wrapper_types());
85
86 1 v = gate_variant_create(infos, sizeof(infos) / sizeof(infos[0]));
87
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE(v != NULL);
88
89 1 gate_object_retain(v);
90 1 gate_object_release(v);
91
92
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(check_variant_contents(v));
93
94 1 gate_object_release(v);
95 }
96
97 1 GATE_TEST_UNIT_END;
98 }
99