tst-gettext2.c 1.8 KB

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