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