bug-strcoll2.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Bug 18589: sort-test.sh fails at random.
  2. Copyright (C) 2015-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <locale.h>
  18. /* An incorrect strcoll optimization resulted in incorrect
  19. results from strcoll for cs_CZ and da_DK. */
  20. int
  21. test_cs_CZ (void)
  22. {
  23. const char t1[] = "config";
  24. const char t2[] = "choose";
  25. if (setlocale (LC_ALL, "cs_CZ.UTF-8") == NULL)
  26. {
  27. perror ("setlocale");
  28. return 1;
  29. }
  30. /* In Czech the digraph ch sorts after c, therefore we expect
  31. config to sort before choose. */
  32. int a = strcoll (t1, t2);
  33. int b = strcoll (t2, t1);
  34. printf ("strcoll (\"%s\", \"%s\") = %d\n", t1, t2, a);
  35. printf ("strcoll (\"%s\", \"%s\") = %d\n", t2, t1, b);
  36. if (a < 0 && b > 0)
  37. {
  38. puts ("PASS: config < choose");
  39. return 0;
  40. }
  41. else
  42. {
  43. puts ("FAIL: Wrong sorting in cs_CZ.UTF-8.");
  44. return 1;
  45. }
  46. }
  47. int
  48. test_da_DK (void)
  49. {
  50. const char t1[] = "AS";
  51. const char t2[] = "AA";
  52. if (setlocale (LC_ALL, "da_DK.ISO-8859-1") == NULL)
  53. {
  54. perror ("setlocale");
  55. return 1;
  56. }
  57. /* AA should be treated as the last letter of the Danish alphabet,
  58. hence sorting after AS. */
  59. int a = strcoll (t1, t2);
  60. int b = strcoll (t2, t1);
  61. printf ("strcoll (\"%s\", \"%s\") = %d\n", t1, t2, a);
  62. printf ("strcoll (\"%s\", \"%s\") = %d\n", t2, t1, b);
  63. if (a < 0 && b > 0)
  64. {
  65. puts ("PASS: AS < AA");
  66. return 0;
  67. }
  68. else
  69. {
  70. puts ("FAIL: Wrong sorting in da_DK.ISO-8859-1");
  71. return 1;
  72. }
  73. }
  74. int
  75. do_test (void)
  76. {
  77. int err = 0;
  78. err |= test_cs_CZ ();
  79. err |= test_da_DK ();
  80. return err;
  81. }
  82. #include <support/test-driver.c>