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
compare(const char * str1,const char * str2,int exp)20 compare (const char *str1, const char *str2, int exp)
21 {
22   int c = strverscmp (str1, str2);
23   if (c != 0)
24     c /= abs (c);
25   return c != exp;
26 }
27 
28 
29 int
do_test(void)30 do_test (void)
31 {
32   int res = 0;
33   for (int i = 0; i < ntests; ++i)
34     {
35       if (compare (tests[i].str1, tests[i].str2, -1))
36 	{
37 	  printf ("FAIL: \"%s\" > \"%s\"\n", tests[i].str1, tests[i].str2);
38 	  res = 1;
39 	}
40       if (compare (tests[i].str2, tests[i].str1, +1))
41 	{
42 	  printf ("FAIL: \"%s\" > \"%s\"\n", tests[i].str2, tests[i].str1);
43 	  res = 1;
44 	}
45       char *copy1 = strdupa (tests[i].str1);
46       if (compare (tests[i].str1, copy1, 0))
47 	{
48 	  printf ("FAIL: \"%s\" != \"%s\"\n", tests[i].str1, copy1);
49 	  res = 1;
50 	}
51       char *copy2 = strdupa (tests[i].str2);
52       if (compare (tests[i].str2, copy2, 0))
53 	{
54 	  printf ("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