round: Update regarding AIX.
[gnulib.git] / tests / test-quotearg.c
1 /* Test of quotearg family of functions.
2    Copyright (C) 2008-2010 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3, or (at your option)
7    any later version.
8
9    This program 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
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
18 /* Written by Eric Blake <ebb9@byu.net>, 2008.  */
19
20 #include <config.h>
21
22 #include "quotearg.h"
23
24 #include <locale.h>
25 #include <stdbool.h>
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include "progname.h"
31 #include "gettext.h"
32 #include "macros.h"
33
34 #include "test-quotearg.h"
35
36 #if ENABLE_NLS
37
38 static struct result_groups locale_results[] = {
39   /* locale_quoting_style */
40   { { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
41       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
42       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ },
43     { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
44       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
45       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ},
46     { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
47       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ, LQ "a\\\\b" RQ,
48       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ } },
49
50   /* clocale_quoting_style */
51   { { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
52       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
53       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ },
54     { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
55       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
56       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ },
57     { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
58       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ, LQ "a\\\\b" RQ,
59       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ } }
60 };
61
62 #endif /* ENABLE_NLS */
63
64 int
65 main (int argc _GL_UNUSED, char *argv[])
66 {
67   set_program_name (argv[0]);
68
69 #if ENABLE_NLS
70   /* Clean up environment.  */
71   unsetenv ("LANGUAGE");
72   unsetenv ("LC_ALL");
73   unsetenv ("LC_MESSAGES");
74   unsetenv ("LC_CTYPE");
75   unsetenv ("LANG");
76   unsetenv ("OUTPUT_CHARSET");
77
78   /* This program part runs in a French UTF-8 locale.  It uses
79      the test-quotearg.mo message catalog.  */
80   {
81     const char *locale_name = getenv ("LOCALE");
82
83     if (locale_name != NULL && strcmp (locale_name, "none") != 0
84         && setenv ("LC_ALL", locale_name, 1) == 0
85         && setlocale (LC_ALL, "") != NULL)
86       {
87         textdomain ("test-quotearg");
88         bindtextdomain ("test-quotearg", getenv ("LOCALEDIR"));
89
90         set_quoting_style (NULL, locale_quoting_style);
91         compare_strings (use_quotearg_buffer, &locale_results[0].group1, false);
92         compare_strings (use_quotearg, &locale_results[0].group2, false);
93         compare_strings (use_quotearg_colon, &locale_results[0].group3, false);
94
95         set_quoting_style (NULL, clocale_quoting_style);
96         compare_strings (use_quotearg_buffer, &locale_results[1].group1, false);
97         compare_strings (use_quotearg, &locale_results[1].group2, false);
98         compare_strings (use_quotearg_colon, &locale_results[1].group3, false);
99
100         quotearg_free ();
101         return 0;
102       }
103   }
104
105   fputs ("Skipping test: no french Unicode locale is installed\n", stderr);
106   return 77;
107 #else
108   fputs ("Skipping test: internationalization is disabled\n", stderr);
109   return 77;
110 #endif /* ENABLE_NLS */
111 }