tst-svc2.c 1.3 KB

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