1 | #include <stdio.h> |
2 | #include <stdlib.h> |
3 | #include <string.h> |
4 | |
5 | |
6 | static struct |
7 | { |
8 | const char *str1; |
9 | const char *str2; |
10 | } tests[] = |
11 | { |
12 | { "B0075022800016.gbp.corp.com" , "B007502280067.gbp.corp.com" }, |
13 | { "B0075022800016.gbp.corp.com" , "B007502357019.GBP.CORP.COM" }, |
14 | { "B007502280067.gbp.corp.com" , "B007502357019.GBP.CORP.COM" } |
15 | }; |
16 | #define ntests (sizeof (tests) / sizeof (tests[0])) |
17 | |
18 | |
19 | int |
20 | compare (const char *str1, const char *str2, int exp) |
21 | { |
22 | int c = strverscmp (s1: str1, s2: str2); |
23 | if (c != 0) |
24 | c /= abs (x: c); |
25 | return c != exp; |
26 | } |
27 | |
28 | |
29 | int |
30 | do_test (void) |
31 | { |
32 | int res = 0; |
33 | for (int i = 0; i < ntests; ++i) |
34 | { |
35 | if (compare (str1: tests[i].str1, str2: tests[i].str2, exp: -1)) |
36 | { |
37 | printf (format: "FAIL: \"%s\" > \"%s\"\n" , tests[i].str1, tests[i].str2); |
38 | res = 1; |
39 | } |
40 | if (compare (str1: tests[i].str2, str2: tests[i].str1, exp: +1)) |
41 | { |
42 | printf (format: "FAIL: \"%s\" > \"%s\"\n" , tests[i].str2, tests[i].str1); |
43 | res = 1; |
44 | } |
45 | char *copy1 = strdupa (tests[i].str1); |
46 | if (compare (str1: tests[i].str1, str2: copy1, exp: 0)) |
47 | { |
48 | printf (format: "FAIL: \"%s\" != \"%s\"\n" , tests[i].str1, copy1); |
49 | res = 1; |
50 | } |
51 | char *copy2 = strdupa (tests[i].str2); |
52 | if (compare (str1: tests[i].str2, str2: copy2, exp: 0)) |
53 | { |
54 | printf (format: "FAIL: \"%s\" != \"%s\"\n" , tests[i].str2, copy2); |
55 | res = 1; |
56 | } |
57 | } |
58 | return res; |
59 | } |
60 | |
61 | #include <support/test-driver.c> |
62 | |