GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tests/gatecore_test/test_strings.c
Date: 2026-12-03 19:36:00
Exec Total Coverage
Lines: 220 220 100.0%
Functions: 8 8 100.0%
Branches: 129 256 50.4%

Line Branch Exec Source
1 #include "gate/tests.h"
2 #include "test_strings.h"
3
4 1 GATE_TEST_FUNCTION(test_string_compare)
5 {
6 1 GATE_TEST_UNIT_BEGIN(test_string_compare);
7
8
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp("abc", "abc") == 0);
9
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp("ab", "abc") == -1);
10
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp("abcd", "abc") == +1);
11
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp("abc", "xyz") == -1);
12
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp("abc", "aaa") == +1);
13
14
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp_ic("abc", "ABC") == 0);
15
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp_ic("ABC", "abc") == 0);
16
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp_ic("ab", "ABC") == -1);
17
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp_ic("AB", "abc") == -1);
18
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp_ic("ABCD", "abc") == +1);
19
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp_ic("abcd", "ABC") == +1);
20
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp_ic("abc", "XYZ") == -1);
21
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp_ic("ABC", "xyz") == -1);
22
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp_ic("ABC", "aaa") == +1);
23
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp_ic("abc", "AAA") == +1);
24
25 1 GATE_TEST_UNIT_END;
26 }
27
28 1 GATE_TEST_FUNCTION(test_string_print)
29 {
30 char buffer[32];
31 char minibuffer[3];
32
33 1 GATE_TEST_UNIT_BEGIN(test_string_print);
34
35
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), 0) == 1);
36
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "0") == 0);
37
38
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), 1) == 1);
39
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "1") == 0);
40
41
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), 22) == 2);
42
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "22") == 0);
43
44
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), 333) == 3);
45
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "333") == 0);
46
47
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), 4444) == 4);
48
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "4444") == 0);
49
50
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), 55555) == 5);
51
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "55555") == 0);
52
53
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), 666666) == 6);
54
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "666666") == 0);
55
56
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), 7777777) == 7);
57
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "7777777") == 0);
58
59
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), 88888888) == 8);
60
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "88888888") == 0);
61
62
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), 999999999) == 9);
63
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "999999999") == 0);
64
65
66
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), -2) == 2);
67
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "-2") == 0);
68
69
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), -33) == 3);
70
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "-33") == 0);
71
72
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), -444) == 4);
73
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "-444") == 0);
74
75
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), -5555) == 5);
76
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "-5555") == 0);
77
78
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), -66666) == 6);
79
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "-66666") == 0);
80
81
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), -777777) == 7);
82
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "-777777") == 0);
83
84
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), -8888888) == 8);
85
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "-8888888") == 0);
86
87
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(buffer, sizeof(buffer), -99999999) == 9);
88
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "-99999999") == 0);
89
90
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_hex_uint64(buffer, sizeof(buffer), 0x1234567890abcdef, false) == 16);
91
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "1234567890abcdef") == 0);
92
93
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_hex_buffer(buffer, sizeof(buffer), "ABC", 3, false) == 6);
94
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_comp(buffer, "414243") == 0);
95
96 1 minibuffer[0] = 0x0a;
97 1 minibuffer[1] = 0x0b;
98 1 minibuffer[2] = 0x0c;
99
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(minibuffer, 2, 12345) == 2);
100
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(minibuffer[0] == '4');
101
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(minibuffer[1] == '5');
102
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(minibuffer[2] == 0x0c);
103
104 1 GATE_TEST_UNIT_END;
105 }
106
107 1 GATE_TEST_FUNCTION(test_string_buffer)
108 {
109 1 gate_char8_t testdata_small[] = "abcdef";
110 gate_char16_t testdata_small16[7];
111
112 1 gate_size_t testdata_small_len = 6;
113 gate_char8_t testdata[GATE_DEFAULT_LINE_LENGTH + 11];
114
115 1 gate_string_t testdata_small_string = GATE_STRING_INIT_STATIC(testdata_small);
116 1 gate_string_t testdata_string = GATE_STRING_INIT_EMPTY;
117
118 1 gate_size_t testdata_len = sizeof(testdata) - 1;
119 gate_size_t ndx;
120 gate_cstrbuffer8_t b8;
121 gate_cstrbuffer16_t b16;
122
123 1 testdata_small16[0] = testdata_small[0];
124 1 testdata_small16[1] = testdata_small[1];
125 1 testdata_small16[2] = testdata_small[2];
126 1 testdata_small16[3] = testdata_small[3];
127 1 testdata_small16[4] = testdata_small[4];
128 1 testdata_small16[5] = testdata_small[5];
129 1 testdata_small16[6] = 0;
130
131 1 GATE_TEST_UNIT_BEGIN(test_string_buffer);
132
133
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(&b8 == gate_cstrbuffer_create(&b8, testdata_small, testdata_small_len, false));
134
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(testdata_small == gate_cstrbuffer_get(&b8));
135 1 gate_cstrbuffer_destroy(&b8);
136
137
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(&b8 == gate_cstrbuffer_create(&b8, testdata_small, testdata_small_len, true));
138
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(testdata_small != gate_cstrbuffer_get(&b8));
139
1/2
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 GATE_TEST_CHECK(gate_str_comp(testdata_small, gate_cstrbuffer_get(&b8)) == 0);
140 1 gate_cstrbuffer_destroy(&b8);
141
142
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(&b8 == gate_cstrbuffer_create(&b8, testdata_small, testdata_small_len - 1, false));
143
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(testdata_small != gate_cstrbuffer_get(&b8));
144
1/2
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
1 GATE_TEST_CHECK(gate_str_compare(testdata_small, testdata_small_len - 1, gate_cstrbuffer_get(&b8), gate_cstrbuffer_length(&b8)) == 0);
145 1 gate_cstrbuffer_destroy(&b8);
146
147
148
2/2
✓ Branch 0 taken 1034 times.
✓ Branch 1 taken 1 times.
1035 for (ndx = 0; ndx != testdata_len; ++ndx)
149 {
150 1034 testdata[ndx] = 'x';
151 }
152 1 testdata[testdata_len] = 0;
153
154
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(&b8 == gate_cstrbuffer_create(&b8, testdata, testdata_len, false));
155
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(testdata == gate_cstrbuffer_get(&b8));
156 1 gate_cstrbuffer_destroy(&b8);
157
158
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(&b8 == gate_cstrbuffer_create(&b8, testdata, testdata_len, true));
159
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(testdata != gate_cstrbuffer_get(&b8));
160
1/2
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
1 GATE_TEST_CHECK(gate_str_compare(testdata, testdata_len, gate_cstrbuffer_get(&b8), gate_cstrbuffer_length(&b8)) == 0);
161 1 gate_cstrbuffer_destroy(&b8);
162
163
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(&b8 == gate_cstrbuffer_create(&b8, testdata, testdata_len - 1, false));
164
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(testdata != gate_cstrbuffer_get(&b8));
165
1/2
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
1 GATE_TEST_CHECK(gate_str_compare(testdata, testdata_len - 1, gate_cstrbuffer_get(&b8), gate_cstrbuffer_length(&b8)) == 0);
166 1 gate_cstrbuffer_destroy(&b8);
167
168
169
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(&b16 == gate_cstrbuffer16_create_string(&b16, &testdata_small_string));
170
1/2
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
1 GATE_TEST_CHECK(gate_str16_compare(testdata_small16, testdata_small_len, gate_cstrbuffer16_get(&b16), gate_cstrbuffer16_length(&b16)) == 0);
171
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(b16.str == &b16.local_buffer[0]);
172 1 gate_cstrbuffer16_destroy(&b16);
173
174 1 gate_string_create_static_len(&testdata_string, testdata, testdata_len);
175
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(&b16 == gate_cstrbuffer16_create_string(&b16, &testdata_string));
176
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(b16.str == b16.heap_buffer);
177 1 gate_cstrbuffer16_destroy(&b16);
178
179
180 1 GATE_TEST_UNIT_END;
181 }
182
183 1 GATE_TEST_FUNCTION(test_string_builder)
184 {
185 1 gate_strbuilder_t sb = GATE_INIT_EMPTY;
186 1 gate_strbuilder_t sb2 = GATE_INIT_EMPTY;
187 1 GATE_TEST_UNIT_BEGIN(test_string_buffer);
188
189 1 gate_strbuilder_create(&sb, 0);
190
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(11 == gate_strbuilder_append_cstr(&sb, "Hello World"));
191
192
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_OK(gate_strbuilder_copy_constructor(&sb2, &sb));
193 1 gate_strbuilder_destructor(&sb2);
194
195 1 gate_strbuilder_release(&sb);
196
197
198 1 GATE_TEST_UNIT_END;
199 }
200
201 1 GATE_TEST_FUNCTION(test_string_change)
202 {
203 char buffer[32];
204 gate_size_t len;
205
206 1 GATE_TEST_UNIT_BEGIN(test_string_change);
207
208 1 len = gate_str_print_text(buffer, sizeof(buffer), "ABC", 3);
209 1 gate_str_replace(buffer, len, 'B', 'b');
210
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(buffer[1], 'b');
211
212
213
214 1 GATE_TEST_UNIT_END;
215 }
216
217
218 1 GATE_TEST_FUNCTION(test_string16)
219 {
220 static gate_char16_t const text[] = { 'A', 'B', 'c', 'd', '1', '2', 0};
221 static gate_size_t const text_len = 6;
222 static gate_char16_t text2[] = { 'A', 'b', 'c', 0};
223 static gate_size_t const text2_len = 3;
224
225 1 GATE_TEST_UNIT_BEGIN(test_string16);
226
227
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_length(text), text_len);
228
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_length_max(text, 7), text_len);
229
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_is_empty(text), false);
230
231
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_char_pos(text, text_len, 'B', 0), 1);
232
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_char_pos(text, text_len, 'B', 2), GATE_STR_NPOS);
233
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_char_pos_last(text, text_len, 'c'), 2);
234
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_pos(text, text_len, &text[2], 3, 0), 2);
235
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_pos_last(text, text_len, &text[2], 3), 2);
236
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str16_comp_range_ic(text, &text[2], 3) < 0);
237
238 1 gate_str16_to_upper(text2, text2_len);
239 1 gate_str16_to_lower(text2, text2_len);
240 1 gate_str16_reverse(text2, text2_len);
241
242
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str16_is_numeric(text, text_len) == 0);
243
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str16_is_numeric(&text[4], 2) > 0);
244
245
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_starts_with(text, text_len, &text[1], 2), false);
246
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_ends_with(text, text_len, &text[4], 2), true);
247
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_comp(text, text), 0);
248
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_comp_ic(text, text), 0);
249
250 {
251 1 gate_char16_t buf[16] = GATE_INIT_EMPTY;
252 1 gate_char16_t const text123[4] = { '1', '2', '3', 0 };
253 1 gate_size_t const text123_len = 3;
254 1 gate_size_t const buf_size = sizeof(buf) / sizeof(buf[0]);
255 1 gate_size_t buf_used = gate_str16_print_text(buf, buf_size, text, text_len);
256
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_compare(buf, buf_used, text, text_len), 0);
257
258 1 buf_used = gate_str16_print_uint16(buf, buf_size, 123);
259
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_compare(buf, buf_used, text123, text123_len), 0);
260
261 1 buf_used = gate_str16_print_int16(buf, buf_size, 123);
262
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_compare(buf, buf_used, text123, text123_len), 0);
263
264 1 buf_used = gate_str16_print_uint32(buf, buf_size, 123);
265
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_compare(buf, buf_used, text123, text123_len), 0);
266
267 1 buf_used = gate_str16_print_int32(buf, buf_size, 123);
268
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_compare(buf, buf_used, text123, text123_len), 0);
269
270 1 buf_used = gate_str16_print_uint64(buf, buf_size, 123);
271
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_compare(buf, buf_used, text123, text123_len), 0);
272
273 1 buf_used = gate_str16_print_int64(buf, buf_size, 123);
274
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str16_compare(buf, buf_used, text123, text123_len), 0);
275 }
276
277 1 GATE_TEST_UNIT_END;
278 }
279
280 1 GATE_TEST_FUNCTION(test_string32)
281 {
282 static gate_char32_t const text[] = { 'A', 'B', 'c', 'd', '1', '2', 0};
283 static gate_size_t const text_len = 6;
284 static gate_char32_t text2[] = { 'A', 'b', 'c', 0};
285 static gate_size_t const text2_len = 3;
286
287 1 GATE_TEST_UNIT_BEGIN(test_string32);
288
289
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_length(text), text_len);
290
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_length_max(text, 7), text_len);
291
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_is_empty(text), false);
292
293
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_char_pos(text, text_len, 'B', 0), 1);
294
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_char_pos(text, text_len, 'B', 2), GATE_STR_NPOS);
295
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_char_pos_last(text, text_len, 'c'), 2);
296
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_pos(text, text_len, &text[2], 3, 0), 2);
297
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_pos_last(text, text_len, &text[2], 3), 2);
298
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str32_comp_range_ic(text, &text[2], 3) < 0);
299
300 1 gate_str32_to_upper(text2, text2_len);
301 1 gate_str32_to_lower(text2, text2_len);
302 1 gate_str32_reverse(text2, text2_len);
303
304
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str32_is_numeric(text, text_len) == 0);
305
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str32_is_numeric(&text[4], 2) > 0);
306
307
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_starts_with(text, text_len, &text[1], 2), false);
308
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_ends_with(text, text_len, &text[4], 2), true);
309
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_comp(text, text), 0);
310
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_comp_ic(text, text), 0);
311
312 {
313 1 gate_char32_t buf[16] = GATE_INIT_EMPTY;
314 1 gate_char32_t const text123[4] = { '1', '2', '3', 0 };
315 1 gate_size_t const text123_len = 3;
316 1 gate_size_t const buf_size = sizeof(buf) / sizeof(buf[0]);
317 1 gate_size_t buf_used = gate_str32_print_text(buf, buf_size, text, text_len);
318
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_compare(buf, buf_used, text, text_len), 0);
319
320 1 buf_used = gate_str32_print_uint16(buf, buf_size, 123);
321
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_compare(buf, buf_used, text123, text123_len), 0);
322
323 1 buf_used = gate_str32_print_int16(buf, buf_size, 123);
324
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_compare(buf, buf_used, text123, text123_len), 0);
325
326 1 buf_used = gate_str32_print_uint32(buf, buf_size, 123);
327
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_compare(buf, buf_used, text123, text123_len), 0);
328
329 1 buf_used = gate_str32_print_int32(buf, buf_size, 123);
330
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_compare(buf, buf_used, text123, text123_len), 0);
331
332 1 buf_used = gate_str32_print_uint64(buf, buf_size, 123);
333
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_compare(buf, buf_used, text123, text123_len), 0);
334
335 1 buf_used = gate_str32_print_int64(buf, buf_size, 123);
336
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_str32_compare(buf, buf_used, text123, text123_len), 0);
337 }
338
339 1 GATE_TEST_UNIT_END;
340 }
341
342
343
344 1 GATE_TEST_FUNCTION(test_strings)
345 {
346 1 gate_bool_t succeeded = true;
347
348 1 succeeded &= test_string_compare();
349 1 succeeded &= test_string_print();
350 1 succeeded &= test_string_buffer();
351 1 succeeded &= test_string_builder();
352 1 succeeded &= test_string_change();
353 1 succeeded &= test_string16();
354 1 succeeded &= test_string32();
355
356 1 return succeeded;
357 }
358