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