GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tests/gatecore_test/test_values.c
Date: 2025-12-12 23:40:09
Exec Total Coverage
Lines: 97 99 98.0%
Functions: 5 6 83.3%
Branches: 34 66 51.5%

Line Branch Exec Source
1 #include "gate/tests.h"
2 #include "test_values.h"
3 #include "gate/values.h"
4 #include "gate/debugging.h"
5
6 struct value_test_matrix
7 {
8 gate_uint16_t type_id;
9 void const* ptr_value;
10 gate_size_t value_size;
11 };
12
13 static gate_result_t dummy_func(gate_dataptr_t data)
14 {
15 return GATE_RESULT_OK;
16 }
17
18 static gate_bool_t value_bool = true;
19 static gate_int8_t value_i8 = -123;
20 static gate_uint8_t value_ui8 = 234;
21 static gate_int16_t value_i16 = -23456;
22 static gate_uint16_t value_ui16 = 34567;
23 static gate_int32_t value_i32 = -1234567890;
24 static gate_uint32_t value_ui32 = 3456789012;
25 static gate_int64_t value_i64 = -9012345678901234567;
26 static gate_uint64_t value_ui64 = 12345678901234567890ULL;
27 static gate_real32_t value_r32 = -123.456f;
28 static gate_real64_t value_r64 = -12345.6789f;
29 static gate_uintptr_t value_addr = 0;
30 static gate_dataptr_t value_ptr = &value_bool;
31 static gate_funcptr_t value_func = &dummy_func;
32 static gate_cstr_t value_cstr = "1234";
33 static gate_wstr_t value_wstr = L"1234";
34 static gate_guid_t value_guid = GATE_INIT_EMPTY;
35 static gate_date_t value_date = GATE_DATE_INIT_EMPTY;
36 static gate_daytime_t value_daytime = GATE_DAYTIME_INIT_EMPTY;
37 static gate_datetime_t value_datetime = GATE_DATETIME_INIT_EMPTY;
38 static gate_time_t value_time = GATE_TIME_INIT;
39 static gate_string_t value_string = GATE_STRING_INIT_STATIC("1234");
40 static gate_array_t value_array = GATE_ARRAY_INIT_EMPTY;
41 static gate_blob_t value_blob = GATE_BLOB_INIT_EMPTY;
42
43 1 static void init_test_matrix_values()
44 {
45 1 value_addr = (gate_uintptr_t)(void*)&value_bool;
46 1 }
47
48
49 static struct value_test_matrix const test_matrix[] = {
50 { GATE_TYPE_BOOL, &value_bool, sizeof(gate_bool_t) },
51 { GATE_TYPE_I8, &value_i8, sizeof(gate_int8_t) },
52 { GATE_TYPE_UI8, &value_ui8, sizeof(gate_uint8_t) },
53 { GATE_TYPE_I16, &value_i16, sizeof(gate_int16_t) },
54 { GATE_TYPE_UI16, &value_ui16, sizeof(gate_uint16_t) },
55 { GATE_TYPE_I32, &value_i32, sizeof(gate_int32_t) },
56 { GATE_TYPE_UI32, &value_ui32, sizeof(gate_uint32_t) },
57 { GATE_TYPE_I64, &value_i64, sizeof(gate_int64_t) },
58 { GATE_TYPE_UI64, &value_ui64, sizeof(gate_uint64_t) },
59 { GATE_TYPE_R32, &value_r32, sizeof(gate_real32_t) },
60 { GATE_TYPE_R64, &value_r64, sizeof(gate_real64_t) },
61 { GATE_TYPE_ADDRESS, &value_addr, sizeof(gate_uintptr_t) },
62 { GATE_TYPE_DATAPTR, &value_ptr, sizeof(gate_dataptr_t) },
63 { GATE_TYPE_FUNCPTR, &value_func, sizeof(gate_funcptr_t) },
64 { GATE_TYPE_CSTR, &value_cstr, sizeof(gate_cstr_t) },
65 { GATE_TYPE_WSTR, &value_wstr, sizeof(gate_wstr_t) },
66 { GATE_TYPE_GUID, &value_guid, sizeof(gate_guid_t) },
67 { GATE_TYPE_DATE, &value_date, sizeof(gate_date_t) },
68 { GATE_TYPE_DAYTIME, &value_daytime, sizeof(gate_daytime_t) },
69 { GATE_TYPE_DATETIME, &value_datetime,sizeof(gate_datetime_t) },
70 { GATE_TYPE_TIME, &value_time, sizeof(gate_time_t) },
71 { GATE_TYPE_STRING, &value_string, sizeof(gate_string_t) },
72 // { GATE_TYPE_ARRAY, &value_array, sizeof(gate_array_t) },
73 { GATE_TYPE_BLOB, &value_blob, sizeof(gate_blob_t) }
74 };
75 static gate_size_t const test_matrix_size = sizeof(test_matrix) / sizeof(test_matrix[0]);
76
77
78 23 static gate_bool_t check_loaders(gate_value_t const* val)
79 {
80 23 gate_bool_t b_value = false;
81 23 gate_int8_t i8_value = 0;
82 23 gate_int16_t i16_value = 0;
83 23 gate_int32_t i32_value = 0;
84 23 gate_int64_t i64_value = 0;
85 23 gate_uint8_t ui8_value = 0;
86 23 gate_uint16_t ui16_value = 0;
87 23 gate_uint32_t ui32_value = 0;
88 23 gate_uint64_t ui64_value = 0;
89 23 gate_string_t str_value = GATE_STRING_INIT_EMPTY;
90 23 gate_blob_t blob_value = GATE_BLOB_INIT_EMPTY;
91 gate_result_t result;
92 23 gate_type_id_t tid = gate_value_type(val);
93 23 void const* ptr = gate_value_get_ptr(val);
94
95
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_load_bool(tid, ptr, &b_value));
96
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_load_int8(tid, ptr, &i8_value));
97
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_load_int16(tid, ptr, &i16_value));
98
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_load_int32(tid, ptr, &i32_value));
99
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_load_int64(tid, ptr, &i64_value));
100
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_load_uint8(tid, ptr, &ui8_value));
101
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_load_uint16(tid, ptr, &ui16_value));
102
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_load_uint32(tid, ptr, &ui32_value));
103
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_load_uint64(tid, ptr, &ui64_value));
104
105
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_load_string(tid, ptr, &str_value));
106 23 gate_string_release(&str_value);
107
108
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_load_blob(tid, ptr, &blob_value));
109 23 gate_blob_release(&blob_value);
110
111 23 return true;
112 }
113
114 322 static void reset_value(gate_value_t* ptr_val, gate_type_id_t tid)
115 {
116 322 gate_value_release(ptr_val);
117 322 ptr_val->value_type = tid;
118 322 }
119
120 23 static gate_bool_t check_savers(gate_type_id_t tid)
121 {
122 23 gate_value_t val = GATE_INIT_EMPTY;
123 23 gate_string_t str_val = GATE_STRING_INIT_EMPTY;
124 23 gate_blob_t blob_val = GATE_BLOB_INIT_EMPTY;
125 23 void* ptr = &val.content.ptr_value;
126
127 23 reset_value(&val, tid);
128
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_save_bool(true, tid, ptr));
129 23 reset_value(&val, tid);
130
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_save_int8(-123, tid, ptr));
131 23 reset_value(&val, tid);
132
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_save_int16(-123, tid, ptr));
133 23 reset_value(&val, tid);
134
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_save_int32(-123, tid, ptr));
135 23 reset_value(&val, tid);
136
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_save_int64(-123, tid, ptr));
137 23 reset_value(&val, tid);
138
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_save_uint8(123, tid, ptr));
139 23 reset_value(&val, tid);
140
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_save_uint16(123, tid, ptr));
141 23 reset_value(&val, tid);
142
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_save_uint32(123, tid, ptr));
143 23 reset_value(&val, tid);
144
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_save_uint64(123, tid, ptr));
145 23 reset_value(&val, tid);
146
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_save_real32(123.456f, tid, ptr));
147 23 reset_value(&val, tid);
148
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_save_real64(123.456, tid, ptr));
149
150 23 reset_value(&val, tid);
151
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_save_string(&str_val, tid, ptr));
152 23 gate_string_release(&str_val);
153
154 23 reset_value(&val, tid);
155
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_save_blob(&blob_val, tid, ptr));
156 23 gate_blob_release(&blob_val);
157
158 23 reset_value(&val, tid);
159 23 return true;
160 }
161
162 1 GATE_TEST_FUNCTION(test_values)
163 {
164 gate_size_t ndx;
165
166 1 GATE_TEST_UNIT_BEGIN(test_values);
167
168 1 init_test_matrix_values();
169
170
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 1 times.
24 for (ndx = 0; ndx != test_matrix_size; ++ndx)
171 {
172 23 struct value_test_matrix const* const m = &test_matrix[ndx];
173 23 gate_value_t val = GATE_INIT_EMPTY;
174 23 gate_value_t val_copy = GATE_INIT_EMPTY;
175 gate_value_t buffer;
176 char serial_buf[512];
177 gate_size_t serial_buf_used;
178 gate_size_t serial_buf_parsed;
179 23 char const* type_signame = gate_type_signature(m->type_id);
180
181 23 GATE_TEST_TRACE_VALUE(m->type_id);
182
1/2
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
23 GATE_TEST_REQUIRE(type_signame != NULL);
183 23 GATE_TEST_TRACE_MESSAGE(type_signame);
184
185
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK(gate_value_create(m->type_id, m->ptr_value, &val) != NULL);
186
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_EQUAL(gate_value_type(&val), m->type_id);
187
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_NOT_EQUAL(gate_value_get_ptr(&val), NULL);
188
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_OK(gate_value_get(&val, &buffer.content, m->value_size));
189
1/2
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
23 GATE_TEST_CHECK_NOT_EQUAL(gate_value_clone(&val, &val_copy), NULL);
190 23 gate_value_release(&val_copy);
191
192 23 serial_buf_used = gate_value_serialize(&val, serial_buf, sizeof(serial_buf));
193
1/2
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
23 GATE_TEST_CHECK(serial_buf_used > 0);
194 23 gate_mem_clear(&val_copy, sizeof(val_copy));
195 23 serial_buf_parsed = gate_value_deserialize(serial_buf, sizeof(serial_buf), &val_copy);
196
1/2
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
23 GATE_TEST_CHECK_EQUAL(serial_buf_parsed, serial_buf_used);
197 23 gate_value_release(&val_copy);
198
199 23 check_loaders(&val);
200 23 check_savers(m->type_id);
201
202 23 gate_value_release(&val);
203 }
204
205 1 GATE_TEST_UNIT_END;
206 }
207