tst-strxfrm2.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <locale.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. int
  5. do_test (void)
  6. {
  7. static const char test_locale[] = "de_DE.UTF-8";
  8. int res = 0;
  9. char buf[20];
  10. size_t l1 = strxfrm (NULL, "ab", 0);
  11. size_t l2 = strxfrm (buf, "ab", 1);
  12. size_t l3 = strxfrm (buf, "ab", sizeof (buf));
  13. if (l3 < sizeof (buf) && strlen (buf) != l3)
  14. {
  15. puts ("C locale l3 test failed");
  16. res = 1;
  17. }
  18. size_t l4 = strxfrm (buf, "ab", l1 + 1);
  19. if (l4 < l1 + 1 && strlen (buf) != l4)
  20. {
  21. puts ("C locale l4 test failed");
  22. res = 1;
  23. }
  24. buf[l1] = 'Z';
  25. size_t l5 = strxfrm (buf, "ab", l1);
  26. if (buf[l1] != 'Z')
  27. {
  28. puts ("C locale l5 test failed");
  29. res = 1;
  30. }
  31. if (l1 != l2 || l1 != l3 || l1 != l4 || l1 != l5)
  32. {
  33. puts ("C locale retval test failed");
  34. res = 1;
  35. }
  36. if (setlocale (LC_ALL, test_locale) == NULL)
  37. {
  38. printf ("cannot set locale \"%s\"\n", test_locale);
  39. res = 1;
  40. }
  41. else
  42. {
  43. l1 = strxfrm (NULL, "ab", 0);
  44. l2 = strxfrm (buf, "ab", 1);
  45. l3 = strxfrm (buf, "ab", sizeof (buf));
  46. if (l3 < sizeof (buf) && strlen (buf) != l3)
  47. {
  48. puts ("UTF-8 locale l3 test failed");
  49. res = 1;
  50. }
  51. l4 = strxfrm (buf, "ab", l1 + 1);
  52. if (l4 < l1 + 1 && strlen (buf) != l4)
  53. {
  54. puts ("UTF-8 locale l4 test failed");
  55. res = 1;
  56. }
  57. buf[l1] = 'Z';
  58. l5 = strxfrm (buf, "ab", l1);
  59. if (buf[l1] != 'Z')
  60. {
  61. puts ("UTF-8 locale l5 test failed");
  62. res = 1;
  63. }
  64. if (l1 != l2 || l1 != l3 || l1 != l4 || l1 != l5)
  65. {
  66. puts ("UTF-8 locale retval test failed");
  67. res = 1;
  68. }
  69. }
  70. return res;
  71. }
  72. #include <support/test-driver.c>