This source file includes following definitions.
- setup
- teardown
- sign
- test_filevercmp
- START_TEST
- START_TEST
- START_TEST
- START_TEST
- START_TEST
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #define TEST_SUITE_NAME "/lib/strutil"
27
28 #include "tests/mctest.h"
29
30 #include "lib/strutil.h"
31 #include "lib/util.h"
32
33
34
35
36 static void
37 setup (void)
38 {
39 }
40
41
42
43
44 static void
45 teardown (void)
46 {
47 }
48
49
50
51 static int
52 sign (int n)
53 {
54 return _GL_CMP (n, 0);
55 }
56
57
58
59
60
61
62
63 static int
64 test_filevercmp (char const *a, char const *b)
65 {
66 int result;
67 char buffer[BUF_1K];
68 size_t alen, blen;
69 size_t i;
70 int nresult;
71
72 result = filevercmp (a, b);
73
74 alen = strlen (a);
75 blen = strlen (b);
76
77 ck_assert_int_le (alen + blen, sizeof (buffer));
78 memcpy (buffer, a, alen);
79 memcpy (buffer + alen, b, blen);
80
81 for (i = 0; i < alen + blen; i++)
82 if (buffer[i] == '\1')
83 buffer[i] = '\0';
84
85 nresult = filenvercmp (buffer, alen, buffer + alen, blen);
86 ck_assert_int_eq (sign (nresult), sign (result));
87
88 return result;
89 }
90
91
92
93
94
95
96 static const struct filevercmp_test_struct
97 {
98 const char *s1;
99 const char *s2;
100 int expected_result;
101 } filevercmp_test_ds1[] =
102 {
103 { "", "", 0 },
104 { "a", "a", 0 },
105 { "a", "b", -1 },
106 { "b", "a", 1 },
107 { "00", "01", -1 },
108 { "01", "010", -1 },
109 { "9", "10", -1 },
110 { "0a", "0", 1 }
111 };
112
113
114
115
116
117 START_TEST (filevercmp_test1)
118
119 {
120
121 int actual_result;
122 const struct filevercmp_test_struct *data = &filevercmp_test_ds1[_i];
123
124
125 actual_result = filevercmp (data->s1, data->s2);
126
127
128 ck_assert_int_eq (sign (actual_result), sign (data->expected_result));
129 }
130
131 END_TEST
132
133
134
135
136
137
138 static const char *filevercmp_test_ds2[] = {
139 "",
140 ".",
141 "..",
142 ".0",
143 ".9",
144 ".A",
145 ".Z",
146 ".a~",
147 ".a",
148 ".b~",
149 ".b",
150 ".z",
151 ".zz~",
152 ".zz",
153 ".zz.~1~",
154 ".zz.0",
155 ".\1",
156 ".\1.txt",
157 ".\1x",
158 ".\1x\1",
159 ".\1.0",
160 "0",
161 "9",
162 "A",
163 "Z",
164 "a~",
165 "a",
166 "a.b~",
167 "a.b",
168 "a.bc~",
169 "a.bc",
170 "a+",
171 "a.",
172 "a..a",
173 "a.+",
174 "b~",
175 "b",
176 "gcc-c++-10.fc9.tar.gz",
177 "gcc-c++-10.fc9.tar.gz.~1~",
178 "gcc-c++-10.fc9.tar.gz.~2~",
179 "gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2",
180 "gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2.~1~",
181 "glibc-2-0.1.beta1.fc10.rpm",
182 "glibc-common-5-0.2.beta2.fc9.ebuild",
183 "glibc-common-5-0.2b.deb",
184 "glibc-common-11b.ebuild",
185 "glibc-common-11-0.6rc2.ebuild",
186 "libstdc++-0.5.8.11-0.7rc2.fc10.tar.gz",
187 "libstdc++-4a.fc8.tar.gz",
188 "libstdc++-4.10.4.20040204svn.rpm",
189 "libstdc++-devel-3.fc8.ebuild",
190 "libstdc++-devel-3a.fc9.tar.gz",
191 "libstdc++-devel-8.fc8.deb",
192 "libstdc++-devel-8.6.2-0.4b.fc8",
193 "nss_ldap-1-0.2b.fc9.tar.bz2",
194 "nss_ldap-1-0.6rc2.fc8.tar.gz",
195 "nss_ldap-1.0-0.1a.tar.gz",
196 "nss_ldap-10beta1.fc8.tar.gz",
197 "nss_ldap-10.11.8.6.20040204cvs.fc10.ebuild",
198 "z",
199 "zz~",
200 "zz",
201 "zz.~1~",
202 "zz.0",
203 "zz.0.txt",
204 "\1",
205 "\1.txt",
206 "\1x",
207 "\1x\1",
208 "\1.0",
209 "#\1.b#",
210 "#.b#"
211 };
212
213 static const size_t filevercmp_test_ds2_len = G_N_ELEMENTS (filevercmp_test_ds2);
214
215
216
217 START_TEST (filevercmp_test2)
218
219 {
220 const char *i = filevercmp_test_ds2[_i];
221 size_t _j;
222
223 for (_j = 0; _j < filevercmp_test_ds2_len; _j++)
224 {
225 const char *j = filevercmp_test_ds2[_j];
226 int result;
227
228 result = test_filevercmp (i, j);
229
230 if (result < 0)
231 ck_assert_int_lt ((size_t) _i, _j);
232 else if (result > 0)
233 ck_assert_int_gt ((size_t) _i, _j);
234 else
235 ck_assert_int_eq ((size_t) _i, _j);
236 }
237 }
238
239 END_TEST
240
241
242
243
244
245 static const char *filevercmp_test_ds3[] = {
246 "application-1.10.tar.gz",
247 "application-1.10.1.tar.gz"
248 };
249
250 static const size_t filevercmp_test_ds3_len = G_N_ELEMENTS (filevercmp_test_ds3);
251
252
253
254 START_TEST (filevercmp_test3)
255
256 {
257 const char *i = filevercmp_test_ds3[_i];
258 size_t _j;
259
260 for (_j = 0; _j < filevercmp_test_ds3_len; _j++)
261 {
262 const char *j = filevercmp_test_ds3[_j];
263 int result;
264
265 result = filevercmp (i, j);
266
267 if (result < 0)
268 ck_assert_int_lt ((size_t) _i, _j);
269 else if (result > 0)
270 ck_assert_int_gt ((size_t) _i, _j);
271 else
272 ck_assert_int_eq ((size_t) _i, _j);
273 }
274 }
275
276 END_TEST
277
278
279
280
281
282 static const char *filevercmp_test_ds4[] = {
283 "firefox-58.0.1+build1.tar.gz",
284 "firefox-59.0~b14+build1.tar.gz",
285 "firefox-59.0.1+build1.tar.gz"
286 };
287
288 static const size_t filevercmp_test_ds4_len = G_N_ELEMENTS (filevercmp_test_ds4);
289
290
291
292 START_TEST (filevercmp_test4)
293
294 {
295 const char *i = filevercmp_test_ds4[_i];
296 size_t _j;
297
298 for (_j = 0; _j < filevercmp_test_ds4_len; _j++)
299 {
300 const char *j = filevercmp_test_ds4[_j];
301 int result;
302
303 result = filevercmp (i, j);
304
305 if (result < 0)
306 ck_assert_int_lt ((size_t) _i, _j);
307 else if (result > 0)
308 ck_assert_int_gt ((size_t) _i, _j);
309 else
310 ck_assert_int_eq ((size_t) _i, _j);
311 }
312 }
313
314 END_TEST
315
316
317
318
319
320 static const char *filevercmp_test_ds5[] = {
321 "a",
322 "a0",
323 "a0000",
324 NULL,
325 "a\1c-27.txt",
326 "a\1c-027.txt",
327 "a\1c-00000000000000000000000000000000000000000000000000000027.txt",
328 NULL,
329 ".a\1c-27.txt",
330 ".a\1c-027.txt",
331 ".a\1c-00000000000000000000000000000000000000000000000000000027.txt",
332 NULL,
333 "a\1c-",
334 "a\1c-0",
335 "a\1c-00",
336 NULL,
337 ".a\1c-",
338 ".a\1c-0",
339 ".a\1c-00",
340 NULL,
341 "a\1c-0.txt",
342 "a\1c-00.txt",
343 NULL,
344 ".a\1c-1\1.txt",
345 ".a\1c-001\1.txt",
346 NULL
347 };
348
349 static const size_t filevercmp_test_ds5_len = G_N_ELEMENTS (filevercmp_test_ds5);
350
351
352
353 START_TEST (filevercmp_test5)
354
355 {
356 size_t ii;
357
358 for (ii = 0; ii < filevercmp_test_ds5_len; ii++)
359 for (; filevercmp_test_ds5[ii] != NULL; ii++)
360 {
361 const char *i = filevercmp_test_ds5[ii];
362 size_t jj;
363
364 for (jj = ii; filevercmp_test_ds5[jj] != NULL; jj++)
365 {
366 const char *j = filevercmp_test_ds5[jj];
367
368 ck_assert_int_eq (test_filevercmp (i, j), 0);
369 ck_assert_int_eq (test_filevercmp (j, i), 0);
370 }
371 }
372 }
373
374 END_TEST
375
376
377
378
379 int
380 main (void)
381 {
382 TCase *tc_core;
383
384 tc_core = tcase_create ("Core");
385
386 tcase_add_checked_fixture (tc_core, setup, teardown);
387
388
389 mctest_add_parameterized_test (tc_core, filevercmp_test1, filevercmp_test_ds1);
390 tcase_add_loop_test (tc_core, filevercmp_test2, 0, filevercmp_test_ds2_len);
391 tcase_add_loop_test (tc_core, filevercmp_test3, 0, filevercmp_test_ds3_len);
392 tcase_add_loop_test (tc_core, filevercmp_test4, 0, filevercmp_test_ds4_len);
393 tcase_add_test (tc_core, filevercmp_test5);
394
395
396 return mctest_run_all (tc_core);
397 }
398
399