gnulib-common: prefer _GL_UNUSED over _UNUSED_PARAMETER_
[gnulib.git] / tests / test-quotearg.c
1 /* Test of quotearg family of functions.
2    Copyright (C) 2008-2009 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 <ctype.h>
25 #include <locale.h>
26 #include <stdbool.h>
27 #include <stdint.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31
32 #include "progname.h"
33 #include "gettext.h"
34
35 #define ASSERT(expr) \
36   do                                                                         \
37     {                                                                        \
38       if (!(expr))                                                           \
39         {                                                                    \
40           fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
41           fflush (stderr);                                                   \
42           abort ();                                                          \
43         }                                                                    \
44     }                                                                        \
45   while (0)
46
47 struct result_strings {
48   char const *str1; /* Translation of "".  */
49   char const *str2; /* Translation of "\0""1\0".  */
50   size_t len2; /* Length of str2.  */
51   char const *str3; /* Translation of "simple".  */
52   char const *str4; /* Translation of " \t\n'\"\033?""?/\\".  */
53   char const *str5; /* Translation of "a:b".  */
54   char const *str6; /* Translation of "a\\b".  */
55   char const *str7a; /* Translation of LQ RQ, in ASCII charset.  */
56   char const *str7b; /* Translation of LQ RQ, in Latin1 or UTF-8 charset.  */
57 };
58
59 struct result_groups {
60   struct result_strings group1; /* Via quotearg_buffer.  */
61   struct result_strings group2; /* Via quotearg{,_mem}.  */
62   struct result_strings group3; /* Via quotearg_colon{,_mem}.  */
63 };
64
65 /* These quotes are borrowed from a pt_PT.utf8 translation.  */
66 # define LQ "\302\253"
67 # define RQ "\302\273"
68 # define LQ_ENC "\\302\\253"
69 # define RQ_ENC "\\302\\273"
70 # define RQ_ESC "\\\302\273"
71
72 static struct result_strings inputs = {
73   "", "\0001\0", 3, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b",
74   LQ RQ, NULL
75 };
76
77 static struct result_groups results_g[] = {
78   /* literal_quoting_style */
79   { { "", "\0""1\0", 3, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b",
80       LQ RQ, LQ RQ },
81     { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b",
82       LQ RQ, LQ RQ },
83     { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b",
84       LQ RQ, LQ RQ } },
85
86   /* shell_quoting_style */
87   { { "''", "\0""1\0", 3, "simple", "' \t\n'\\''\"\033?""?/\\'", "a:b",
88       "'a\\b'", LQ RQ, LQ RQ },
89     { "''", "1", 1, "simple", "' \t\n'\\''\"\033?""?/\\'", "a:b",
90       "'a\\b'", LQ RQ, LQ RQ },
91     { "''", "1", 1, "simple", "' \t\n'\\''\"\033?""?/\\'", "'a:b'",
92       "'a\\b'", LQ RQ, LQ RQ } },
93
94   /* shell_always_quoting_style */
95   { { "''", "'\0""1\0'", 5, "'simple'", "' \t\n'\\''\"\033?""?/\\'", "'a:b'",
96       "'a\\b'", "'" LQ RQ "'", "'" LQ RQ "'" },
97     { "''", "'1'", 3, "'simple'", "' \t\n'\\''\"\033?""?/\\'", "'a:b'",
98       "'a\\b'", "'" LQ RQ "'", "'" LQ RQ "'" },
99     { "''", "'1'", 3, "'simple'", "' \t\n'\\''\"\033?""?/\\'", "'a:b'",
100       "'a\\b'", "'" LQ RQ "'", "'" LQ RQ "'" } },
101
102   /* c_quoting_style */
103   { { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
104       "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
105       "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
106     { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
107       "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
108       "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
109     { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
110       "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"",
111       "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" } },
112
113   /* c_maybe_quoting_style */
114   { { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
115       "a:b", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
116     { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
117       "a:b", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
118     { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
119       "\"a:b\"", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ } },
120
121   /* escape_quoting_style */
122   { { "", "\\0001\\0", 7, "simple", " \\t\\n'\"\\033?""?/\\\\", "a:b",
123       "a\\\\b", LQ_ENC RQ_ENC, LQ RQ },
124     { "", "\\0001\\0", 7, "simple", " \\t\\n'\"\\033?""?/\\\\", "a:b",
125       "a\\\\b", LQ_ENC RQ_ENC, LQ RQ },
126     { "", "\\0001\\0", 7, "simple", " \\t\\n'\"\\033?""?/\\\\", "a\\:b",
127       "a\\\\b", LQ_ENC RQ_ENC, LQ RQ } },
128
129   /* locale_quoting_style */
130   { { "`'", "`\\0001\\0'", 9, "`simple'", "` \\t\\n\\'\"\\033?""?/\\\\'",
131       "`a:b'", "`a\\\\b'", "`" LQ_ENC RQ_ENC "'", "`" LQ RQ "'" },
132     { "`'", "`\\0001\\0'", 9, "`simple'", "` \\t\\n\\'\"\\033?""?/\\\\'",
133       "`a:b'", "`a\\\\b'", "`" LQ_ENC RQ_ENC "'", "`" LQ RQ "'" },
134     { "`'", "`\\0001\\0'", 9, "`simple'", "` \\t\\n\\'\"\\033?""?/\\\\'",
135       "`a\\:b'", "`a\\\\b'", "`" LQ_ENC RQ_ENC "'", "`" LQ RQ "'" } },
136
137   /* clocale_quoting_style */
138   { { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
139       "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
140       "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
141     { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
142       "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
143       "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
144     { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
145       "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"",
146       "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" } }
147 };
148
149 static struct result_groups flag_results[] = {
150   /* literal_quoting_style and QA_ELIDE_NULL_BYTES */
151   { { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", LQ RQ,
152       LQ RQ },
153     { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", LQ RQ,
154       LQ RQ },
155     { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", LQ RQ,
156       LQ RQ } },
157
158   /* c_quoting_style and QA_ELIDE_OUTER_QUOTES */
159   { { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
160       "a:b", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
161     { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
162       "a:b", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
163     { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
164       "\"a:b\"", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ } },
165
166   /* c_quoting_style and QA_SPLIT_TRIGRAPHS */
167   { { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
168       "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
169       "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
170     { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
171       "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
172       "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
173     { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
174       "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"",
175       "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" } }
176 };
177
178 #if ENABLE_NLS
179
180 static struct result_groups locale_results[] = {
181   /* locale_quoting_style */
182   { { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
183       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
184       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ },
185     { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
186       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
187       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ},
188     { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
189       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ, LQ "a\\\\b" RQ,
190       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ } },
191
192   /* clocale_quoting_style */
193   { { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
194       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
195       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ },
196     { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
197       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
198       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ },
199     { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
200       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ, LQ "a\\\\b" RQ,
201       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ } }
202 };
203
204 #endif /* ENABLE_NLS */
205
206 static char const *custom_quotes[][2] = {
207   { "", ""  },
208   { "'", "'"  },
209   { "(", ")"  },
210   { ":", " "  },
211   { " ", ":"  },
212   { "# ", "\n" },
213   { "\"'", "'\"" }
214 };
215
216 static struct result_groups custom_results[] = {
217   /* left_quote = right_quote = "" */
218   { { "", "\\0001\\0", 7, "simple",
219       " \\t\\n'\"\\033?""?/\\\\", "a:b", "a\\\\b",
220       LQ_ENC RQ_ENC, LQ RQ },
221     { "", "\\0001\\0", 7, "simple",
222       " \\t\\n'\"\\033?""?/\\\\", "a:b", "a\\\\b",
223       LQ_ENC RQ_ENC, LQ RQ },
224     { "", "\\0001\\0", 7, "simple",
225       " \\t\\n'\"\\033?""?/\\\\", "a\\:b", "a\\\\b",
226       LQ_ENC RQ_ENC, LQ RQ } },
227
228   /* left_quote = right_quote = "'" */
229   { { "''", "'\\0001\\0'", 9, "'simple'",
230       "' \\t\\n\\'\"\\033?""?/\\\\'", "'a:b'", "'a\\\\b'",
231       "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
232     { "''", "'\\0001\\0'", 9, "'simple'",
233       "' \\t\\n\\'\"\\033?""?/\\\\'", "'a:b'", "'a\\\\b'",
234       "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
235     { "''", "'\\0001\\0'", 9, "'simple'",
236       "' \\t\\n\\'\"\\033?""?/\\\\'", "'a\\:b'", "'a\\\\b'",
237       "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" } },
238
239   /* left_quote = "(" and right_quote = ")" */
240   { { "()", "(\\0001\\0)", 9, "(simple)",
241       "( \\t\\n'\"\\033?""?/\\\\)", "(a:b)", "(a\\\\b)",
242       "(" LQ_ENC RQ_ENC ")", "(" LQ RQ ")" },
243     { "()", "(\\0001\\0)", 9, "(simple)",
244       "( \\t\\n'\"\\033?""?/\\\\)", "(a:b)", "(a\\\\b)",
245       "(" LQ_ENC RQ_ENC ")", "(" LQ RQ ")" },
246     { "()", "(\\0001\\0)", 9, "(simple)",
247       "( \\t\\n'\"\\033?""?/\\\\)", "(a\\:b)", "(a\\\\b)",
248       "(" LQ_ENC RQ_ENC ")", "(" LQ RQ ")" } },
249
250   /* left_quote = ":" and right_quote = " " */
251   { { ": ", ":\\0001\\0 ", 9, ":simple ",
252       ":\\ \\t\\n'\"\\033?""?/\\\\ ", ":a:b ", ":a\\\\b ",
253       ":" LQ_ENC RQ_ENC " ", ":" LQ RQ " " },
254     { ": ", ":\\0001\\0 ", 9, ":simple ",
255       ":\\ \\t\\n'\"\\033?""?/\\\\ ", ":a:b ", ":a\\\\b ",
256       ":" LQ_ENC RQ_ENC " ", ":" LQ RQ " " },
257     { ": ", ":\\0001\\0 ", 9, ":simple ",
258       ":\\ \\t\\n'\"\\033?""?/\\\\ ", ":a\\:b ", ":a\\\\b ",
259       ":" LQ_ENC RQ_ENC " ", ":" LQ RQ " " } },
260
261   /* left_quote = " " and right_quote = ":" */
262   { { " :", " \\0001\\0:", 9, " simple:",
263       "  \\t\\n'\"\\033?""?/\\\\:", " a\\:b:", " a\\\\b:",
264       " " LQ_ENC RQ_ENC ":", " " LQ RQ ":" },
265     { " :", " \\0001\\0:", 9, " simple:",
266       "  \\t\\n'\"\\033?""?/\\\\:", " a\\:b:", " a\\\\b:",
267       " " LQ_ENC RQ_ENC ":", " " LQ RQ ":" },
268     { " :", " \\0001\\0:", 9, " simple:",
269       "  \\t\\n'\"\\033?""?/\\\\:", " a\\:b:", " a\\\\b:",
270       " " LQ_ENC RQ_ENC ":", " " LQ RQ ":" } },
271
272   /* left_quote = "# " and right_quote = "\n" */
273   { { "# \n", "# \\0001\\0\n", 10, "# simple\n",
274       "#  \\t\\n'\"\\033?""?/\\\\\n", "# a:b\n", "# a\\\\b\n",
275       "# " LQ_ENC RQ_ENC "\n", "# " LQ RQ "\n" },
276     { "# \n", "# \\0001\\0\n", 10, "# simple\n",
277       "#  \\t\\n'\"\\033?""?/\\\\\n", "# a:b\n", "# a\\\\b\n",
278       "# " LQ_ENC RQ_ENC "\n", "# " LQ RQ "\n" },
279     { "# \n", "# \\0001\\0\n", 10, "# simple\n",
280       "#  \\t\\n'\"\\033?""?/\\\\\n", "# a\\:b\n", "# a\\\\b\n",
281       "# " LQ_ENC RQ_ENC "\n", "# " LQ RQ "\n" } },
282
283   /* left_quote = "\"'" and right_quote = "'\"" */
284   { { "\"''\"", "\"'\\0001\\0'\"", 11, "\"'simple'\"",
285       "\"' \\t\\n\\'\"\\033?""?/\\\\'\"", "\"'a:b'\"", "\"'a\\\\b'\"",
286       "\"'" LQ_ENC RQ_ENC "'\"", "\"'" LQ RQ "'\"" },
287     { "\"''\"", "\"'\\0001\\0'\"", 11, "\"'simple'\"",
288       "\"' \\t\\n\\'\"\\033?""?/\\\\'\"", "\"'a:b'\"", "\"'a\\\\b'\"",
289       "\"'" LQ_ENC RQ_ENC "'\"", "\"'" LQ RQ "'\"" },
290     { "\"''\"", "\"'\\0001\\0'\"", 11, "\"'simple'\"",
291       "\"' \\t\\n\\'\"\\033?""?/\\\\'\"", "\"'a\\:b'\"", "\"'a\\\\b'\"",
292       "\"'" LQ_ENC RQ_ENC "'\"", "\"'" LQ RQ "'\"" } }
293 };
294
295 static void
296 compare (char const *a, size_t la, char const *b, size_t lb)
297 {
298   ASSERT (la == lb);
299   ASSERT (memcmp (a, b, la) == 0);
300   ASSERT (b[lb] == '\0');
301 }
302
303 static void
304 compare_strings (char *(func) (char const *, size_t *),
305                  struct result_strings *results, bool ascii_only)
306 {
307   size_t len;
308   char *p;
309
310   len = 0;
311   p = func (inputs.str1, &len);
312   compare (results->str1, strlen (results->str1), p, len);
313
314   len = inputs.len2;
315   p = func (inputs.str2, &len);
316   compare (results->str2, results->len2, p, len);
317
318   len = SIZE_MAX;
319   p = func (inputs.str3, &len);
320   compare (results->str3, strlen (results->str3), p, len);
321
322   len = strlen (inputs.str4);
323   p = func (inputs.str4, &len);
324   compare (results->str4, strlen (results->str4), p, len);
325
326   len = SIZE_MAX;
327   p = func (inputs.str5, &len);
328   compare (results->str5, strlen (results->str5), p, len);
329
330   len = strlen (inputs.str6);
331   p = func (inputs.str6, &len);
332   compare (results->str6, strlen (results->str6), p, len);
333
334   len = strlen (inputs.str7a);
335   p = func (inputs.str7a, &len);
336   if (ascii_only)
337     compare (results->str7a, strlen (results->str7a), p, len);
338   else
339     compare (results->str7b, strlen (results->str7b), p, len);
340 }
341
342 static char *
343 use_quotearg_buffer (const char *str, size_t *len)
344 {
345   static char buf[100];
346   size_t size;
347   memset (buf, 0xa5, 100);
348   size = quotearg_buffer (buf, 100, str, *len, NULL);
349   *len = size;
350   ASSERT ((unsigned char) buf[size + 1] == 0xa5);
351   return buf;
352 }
353
354 static char *
355 use_quotearg (const char *str, size_t *len)
356 {
357   char *p = *len == SIZE_MAX ? quotearg (str) : quotearg_mem (str, *len);
358   *len = strlen (p);
359   return p;
360 }
361
362 static char *
363 use_quote_double_quotes (const char *str, size_t *len)
364 {
365   char *p = *len == SIZE_MAX ? quotearg_char (str, '"')
366                                : quotearg_char_mem (str, *len, '"');
367   *len = strlen (p);
368   return p;
369 }
370
371 static char *
372 use_quotearg_colon (const char *str, size_t *len)
373 {
374   char *p = (*len == SIZE_MAX ? quotearg_colon (str)
375              : quotearg_colon_mem (str, *len));
376   *len = strlen (p);
377   return p;
378 }
379
380 int
381 main (int argc _GL_UNUSED, char *argv[])
382 {
383   int i;
384   bool ascii_only = MB_CUR_MAX == 1 && !isprint ((unsigned char) LQ[0]);
385
386   set_program_name (argv[0]);
387
388   /* This part of the program is hard-wired to the C locale since it
389      does not call setlocale.  However, according to POSIX, the use of
390      8-bit bytes in a character context in the C locale gives
391      unspecified results (that is, the C locale charset is allowed to
392      be unibyte with 8-bit bytes rejected [ASCII], unibyte with 8-bit
393      bytes being characters [often ISO-8859-1], or multibyte [often
394      UTF-8]).  We assume that the latter two cases will be
395      indistinguishable in this test - that is, the LQ and RQ sequences
396      will pass through unchanged in either type of charset.  So when
397      testing for quoting of str7, use the ascii_only flag to decide
398      what to expect for the 8-bit data being quoted.  */
399   ASSERT (!isprint ('\033'));
400   for (i = literal_quoting_style; i <= clocale_quoting_style; i++)
401     {
402       set_quoting_style (NULL, i);
403       compare_strings (use_quotearg_buffer, &results_g[i].group1, ascii_only);
404       compare_strings (use_quotearg, &results_g[i].group2, ascii_only);
405       if (i == c_quoting_style)
406         compare_strings (use_quote_double_quotes, &results_g[i].group2,
407                          ascii_only);
408       compare_strings (use_quotearg_colon, &results_g[i].group3, ascii_only);
409     }
410
411   set_quoting_style (NULL, literal_quoting_style);
412   ASSERT (set_quoting_flags (NULL, QA_ELIDE_NULL_BYTES) == 0);
413   compare_strings (use_quotearg_buffer, &flag_results[0].group1, ascii_only);
414   compare_strings (use_quotearg, &flag_results[0].group2, ascii_only);
415   compare_strings (use_quotearg_colon, &flag_results[0].group3, ascii_only);
416
417   set_quoting_style (NULL, c_quoting_style);
418   ASSERT (set_quoting_flags (NULL, QA_ELIDE_OUTER_QUOTES)
419           == QA_ELIDE_NULL_BYTES);
420   compare_strings (use_quotearg_buffer, &flag_results[1].group1, ascii_only);
421   compare_strings (use_quotearg, &flag_results[1].group2, ascii_only);
422   compare_strings (use_quote_double_quotes, &flag_results[1].group2,
423                    ascii_only);
424   compare_strings (use_quotearg_colon, &flag_results[1].group3, ascii_only);
425
426   ASSERT (set_quoting_flags (NULL, QA_SPLIT_TRIGRAPHS)
427           == QA_ELIDE_OUTER_QUOTES);
428   compare_strings (use_quotearg_buffer, &flag_results[2].group1, ascii_only);
429   compare_strings (use_quotearg, &flag_results[2].group2, ascii_only);
430   compare_strings (use_quote_double_quotes, &flag_results[2].group2,
431                    ascii_only);
432   compare_strings (use_quotearg_colon, &flag_results[2].group3, ascii_only);
433
434   ASSERT (set_quoting_flags (NULL, 0) == QA_SPLIT_TRIGRAPHS);
435
436   for (i = 0; i < sizeof custom_quotes / sizeof *custom_quotes; ++i)
437     {
438       set_custom_quoting (NULL,
439                           custom_quotes[i][0], custom_quotes[i][1]);
440       compare_strings (use_quotearg_buffer, &custom_results[i].group1,
441                        ascii_only);
442       compare_strings (use_quotearg, &custom_results[i].group2, ascii_only);
443       compare_strings (use_quotearg_colon, &custom_results[i].group3,
444                        ascii_only);
445     }
446
447 #if ENABLE_NLS
448   /* Clean up environment.  */
449   unsetenv ("LANGUAGE");
450   unsetenv ("LC_ALL");
451   unsetenv ("LC_MESSAGES");
452   unsetenv ("LC_CTYPE");
453   unsetenv ("LANG");
454   unsetenv ("OUTPUT_CHARSET");
455
456   /* This program part runs in a French UTF-8 locale.  It uses
457      the test-quotearg.mo message catalog.  */
458   {
459     const char *locale_name = getenv ("LOCALE");
460
461     if (locale_name != NULL && strcmp (locale_name, "none") != 0
462         && setenv ("LC_ALL", locale_name, 1) == 0
463         && setlocale (LC_ALL, "") != NULL)
464       {
465         textdomain ("test-quotearg");
466         bindtextdomain ("test-quotearg", getenv ("LOCALEDIR"));
467
468         set_quoting_style (NULL, locale_quoting_style);
469         compare_strings (use_quotearg_buffer, &locale_results[0].group1, false);
470         compare_strings (use_quotearg, &locale_results[0].group2, false);
471         compare_strings (use_quotearg_colon, &locale_results[0].group3, false);
472
473         set_quoting_style (NULL, clocale_quoting_style);
474         compare_strings (use_quotearg_buffer, &locale_results[1].group1, false);
475         compare_strings (use_quotearg, &locale_results[1].group2, false);
476         compare_strings (use_quotearg_colon, &locale_results[1].group3, false);
477       }
478   }
479 #endif /* ENABLE_NLS */
480
481   quotearg_free ();
482   return 0;
483 }