tst-ngettext.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Test of the ngettext functions.
  2. Copyright (C) 2000-2026 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. <https://www.gnu.org/licenses/>. */
  15. #include <langinfo.h>
  16. #include <libintl.h>
  17. #include <locale.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. static int
  22. do_test (void)
  23. {
  24. const char *strs[2] = { "singular", "plural" };
  25. unsigned long int i;
  26. int res = 0;
  27. /* We don't want any translation here. */
  28. setenv ("LANGUAGE", "C", 1);
  29. unsetenv ("OUTPUT_CHARSET");
  30. for (i = 0; i < 30; ++i)
  31. {
  32. char *tr;
  33. tr = ngettext (strs[0], strs[1], i);
  34. #define TEST \
  35. do \
  36. if (tr != strs[i != 1]) \
  37. { \
  38. if (strcmp (tr, strs[i != 1]) == 0) \
  39. printf ("%lu: correct string, wrong pointer (%s)\n", i, tr); \
  40. else \
  41. printf ("%lu: wrong result (%s)\n", i, tr); \
  42. res = 1; \
  43. } \
  44. while (0)
  45. TEST;
  46. tr = dngettext ("messages", strs[0], strs[1], i);
  47. TEST;
  48. tr = dcngettext ("messages", strs[0], strs[1], i, LC_MESSAGES);
  49. TEST;
  50. }
  51. return res;
  52. }
  53. #define TEST_FUNCTION do_test ()
  54. #include "../test-skeleton.c"