intl: Handle translation output codesets with suffixes [BZ #26383]
[platform/upstream/glibc.git] / intl / tst-codeset.c
1 /* Test of bind_textdomain_codeset.
2    Copyright (C) 2001-2020 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Bruno Haible <haible@clisp.cons.org>, 2001.
5
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
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, see
18    <https://www.gnu.org/licenses/>.  */
19
20 #include <libintl.h>
21 #include <locale.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <support/check.h>
26
27 static int
28 do_test (void)
29 {
30   unsetenv ("LANGUAGE");
31   unsetenv ("OUTPUT_CHARSET");
32   setlocale (LC_ALL, "de_DE.ISO-8859-1");
33   textdomain ("codeset");
34   bindtextdomain ("codeset", OBJPFX "domaindir");
35
36   /* Here we expect output in ISO-8859-1.  */
37   TEST_COMPARE_STRING (gettext ("cheese"), "K\344se");
38
39   /* Here we expect output in UTF-8.  */
40   bind_textdomain_codeset ("codeset", "UTF-8");
41   TEST_COMPARE_STRING (gettext ("cheese"), "K\303\244se");
42
43   /* `a with umlaut' is transliterated to `ae'.  */
44   bind_textdomain_codeset ("codeset", "ASCII//TRANSLIT");
45   TEST_COMPARE_STRING (gettext ("cheese"), "Kaese");
46
47   /* Transliteration also works by default even if not set.  */
48   bind_textdomain_codeset ("codeset", "ASCII");
49   TEST_COMPARE_STRING (gettext ("cheese"), "Kaese");
50
51   return 0;
52 }
53
54 #include <support/test-driver.c>