tst-gettext2.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Test of the gettext functions.
  2. Copyright (C) 2000-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Thorsten Kukuk <kukuk@suse.de> and
  5. Andreas Jaeger <aj@suse.de>, 2000.
  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 <locale.h>
  18. #include <libintl.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #define N_(msgid) msgid
  22. struct data_t
  23. {
  24. const char *selection;
  25. const char *description;
  26. };
  27. int data_cnt = 2;
  28. struct data_t strings[] =
  29. {
  30. { "String1", N_("First string for testing.") },
  31. { "String2", N_("Another string for testing.") }
  32. };
  33. const int lang_cnt = 3;
  34. const char *lang[] = {"lang1", "lang2", "lang3"};
  35. static int
  36. do_test (void)
  37. {
  38. int i;
  39. /* Clean up environment. */
  40. unsetenv ("LANGUAGE");
  41. unsetenv ("LC_ALL");
  42. unsetenv ("LC_MESSAGES");
  43. unsetenv ("LC_CTYPE");
  44. unsetenv ("LANG");
  45. unsetenv ("OUTPUT_CHARSET");
  46. textdomain ("tstlang");
  47. for (i = 0; i < lang_cnt; ++i)
  48. {
  49. int j;
  50. if (setlocale (LC_ALL, lang[i]) == NULL)
  51. setlocale (LC_ALL, "C");
  52. bindtextdomain ("tstlang", OBJPFX "domaindir");
  53. for (j = 0; j < data_cnt; ++j)
  54. printf ("%s - %s\n", strings[j].selection,
  55. gettext (strings[j].description));
  56. }
  57. return 0;
  58. }
  59. #define TEST_FUNCTION do_test ()
  60. #include "../test-skeleton.c"