tst-gettext3.c 1.7 KB

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