GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tests/gatecore_test/test_strings.c
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 125 125 100.0%
Functions: 5 5 100.0%
Branches: 79 156 50.6%

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 minibuffer[0] = 0x0a;
91 1 minibuffer[1] = 0x0b;
92 1 minibuffer[2] = 0x0c;
93
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_str_print_int64(minibuffer, 2, 12345) == 2);
94
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(minibuffer[0] == '4');
95
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(minibuffer[1] == '5');
96
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(minibuffer[2] == 0x0c);
97
98 1 GATE_TEST_UNIT_END;
99 }
100
101 1 GATE_TEST_FUNCTION(test_string_buffer)
102 {
103 1 gate_char8_t testdata_small[] = "abcdef";
104 gate_char16_t testdata_small16[7];
105
106 1 gate_size_t testdata_small_len = 6;
107 gate_char8_t testdata[GATE_DEFAULT_LINE_LENGTH + 11];
108
109 1 gate_string_t testdata_small_string = GATE_STRING_INIT_STATIC(testdata_small);
110 1 gate_string_t testdata_string = GATE_STRING_INIT_EMPTY;
111
112 1 gate_size_t testdata_len = sizeof(testdata) - 1;
113 gate_size_t ndx;
114 gate_cstrbuffer8_t b8;
115 gate_cstrbuffer16_t b16;
116
117 1 testdata_small16[0] = testdata_small[0];
118 1 testdata_small16[1] = testdata_small[1];
119 1 testdata_small16[2] = testdata_small[2];
120 1 testdata_small16[3] = testdata_small[3];
121 1 testdata_small16[4] = testdata_small[4];
122 1 testdata_small16[5] = testdata_small[5];
123 1 testdata_small16[6] = 0;
124
125 1 GATE_TEST_UNIT_BEGIN(test_string_buffer);
126
127
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));
128
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(testdata_small == gate_cstrbuffer_get(&b8));
129 1 gate_cstrbuffer_destroy(&b8);
130
131
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));
132
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(testdata_small != gate_cstrbuffer_get(&b8));
133
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);
134 1 gate_cstrbuffer_destroy(&b8);
135
136
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));
137
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(testdata_small != gate_cstrbuffer_get(&b8));
138
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);
139 1 gate_cstrbuffer_destroy(&b8);
140
141
142
2/2
✓ Branch 0 taken 1034 times.
✓ Branch 1 taken 1 times.
1035 for (ndx = 0; ndx != testdata_len; ++ndx)
143 {
144 1034 testdata[ndx] = 'x';
145 }
146 1 testdata[testdata_len] = 0;
147
148
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(&b8 == gate_cstrbuffer_create(&b8, testdata, testdata_len, false));
149
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(testdata == gate_cstrbuffer_get(&b8));
150 1 gate_cstrbuffer_destroy(&b8);
151
152
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(&b8 == gate_cstrbuffer_create(&b8, testdata, testdata_len, true));
153
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(testdata != gate_cstrbuffer_get(&b8));
154
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);
155 1 gate_cstrbuffer_destroy(&b8);
156
157
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));
158
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(testdata != gate_cstrbuffer_get(&b8));
159
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);
160 1 gate_cstrbuffer_destroy(&b8);
161
162
163
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(&b16 == gate_cstrbuffer16_create_string(&b16, &testdata_small_string));
164
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);
165
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(b16.str == &b16.local_buffer[0]);
166 1 gate_cstrbuffer16_destroy(&b16);
167
168 1 gate_string_create_static_len(&testdata_string, testdata, testdata_len);
169
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(&b16 == gate_cstrbuffer16_create_string(&b16, &testdata_string));
170
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(b16.str == b16.heap_buffer);
171 1 gate_cstrbuffer16_destroy(&b16);
172
173
174 1 GATE_TEST_UNIT_END;
175 }
176
177 1 GATE_TEST_FUNCTION(test_string_builder)
178 {
179 gate_strbuilder_t sb;
180 1 GATE_TEST_UNIT_BEGIN(test_string_buffer);
181
182 1 gate_strbuilder_create(&sb, 0);
183
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(11 == gate_strbuilder_append_cstr(&sb, "Hello World"));
184 1 gate_strbuilder_release(&sb);
185
186 1 GATE_TEST_UNIT_END;
187 }
188
189 1 GATE_TEST_FUNCTION(test_strings)
190 {
191 1 gate_bool_t succeeded = true;
192
193 1 succeeded &= test_string_compare();
194 1 succeeded &= test_string_print();
195 1 succeeded &= test_string_buffer();
196 1 succeeded &= test_string_builder();
197
198 1 return succeeded;
199 }
200