tst-gettext3.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Test that the gettext() results come out in the correct encoding for
  2. locales that differ only in their encoding.
  3. Copyright (C) 2001-2026 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <https://www.gnu.org/licenses/>. */
  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. char *s;
  25. int result = 0;
  26. unsetenv ("LANGUAGE");
  27. unsetenv ("OUTPUT_CHARSET");
  28. textdomain ("codeset");
  29. bindtextdomain ("codeset", OBJPFX "domaindir");
  30. setlocale (LC_ALL, "de_DE.ISO-8859-1");
  31. /* Here we expect output in ISO-8859-1. */
  32. s = gettext ("cheese");
  33. if (strcmp (s, "K\344se"))
  34. {
  35. printf ("call 1 returned: %s\n", s);
  36. result = 1;
  37. }
  38. setlocale (LC_ALL, "de_DE.UTF-8");
  39. /* Here we expect output in UTF-8. */
  40. s = gettext ("cheese");
  41. if (strcmp (s, "K\303\244se"))
  42. {
  43. printf ("call 2 returned: %s\n", s);
  44. result = 1;
  45. }
  46. return result;
  47. }
  48. #define TEST_FUNCTION do_test ()
  49. #include "../test-skeleton.c"