X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-quotearg.c;h=c9636a1ccff228e07012e54ebd177d4dfbb6aa7e;hb=4b95adc9f2ec340f80d4b9ee81938d1070de0c67;hp=04de223cd802201b7d70665ce4ffaa9ac8c01110;hpb=e220635fc952c63b533873f2af39ec76aed4b4e3;p=gnulib.git diff --git a/tests/test-quotearg.c b/tests/test-quotearg.c index 04de223cd..c9636a1cc 100644 --- a/tests/test-quotearg.c +++ b/tests/test-quotearg.c @@ -1,5 +1,5 @@ /* Test of quotearg family of functions. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,36 +22,26 @@ #include "quotearg.h" #include +#include #include #include #include #include #include -#if ENABLE_NLS -/* On Linux, gettext is optionally defined as a forwarding macro, - which would cause syntax errors in our definition below. But on - platforms that require -lintl, we cannot #undef gettext, since we - want to provide the entry point libintl_gettext. So we disable - optimizations to avoid the Linux macros. */ -# undef __OPTIMIZE__ -# include - -/* These quotes are borrowed from a pt_PT.utf8 translation. */ -# define LQ "\302\253" -# define RQ "\302\273" -#endif +#include "progname.h" +#include "gettext.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) struct result_strings { @@ -62,6 +52,8 @@ struct result_strings { char const *str4; /* Translation of " \t\n'\"\033?""?/\\". */ char const *str5; /* Translation of "a:b". */ char const *str6; /* Translation of "a\\b". */ + char const *str7a; /* Translation of LQ RQ, in ASCII charset. */ + char const *str7b; /* Translation of LQ RQ, in Latin1 or UTF-8 charset. */ }; struct result_groups { @@ -70,116 +62,236 @@ struct result_groups { struct result_strings group3; /* Via quotearg_colon{,_mem}. */ }; +/* These quotes are borrowed from a pt_PT.utf8 translation. */ +# define LQ "\302\253" +# define RQ "\302\273" +# define LQ_ENC "\\302\\253" +# define RQ_ENC "\\302\\273" +# define RQ_ESC "\\\302\273" + static struct result_strings inputs = { - "", "\0001\0", 3, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b" + "", "\0001\0", 3, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", + LQ RQ, NULL }; static struct result_groups results_g[] = { /* literal_quoting_style */ - { { "", "\0""1\0", 3, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b" }, - { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b" }, - { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b" } }, + { { "", "\0""1\0", 3, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", + LQ RQ, LQ RQ }, + { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", + LQ RQ, LQ RQ }, + { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", + LQ RQ, LQ RQ } }, /* shell_quoting_style */ { { "''", "\0""1\0", 3, "simple", "' \t\n'\\''\"\033?""?/\\'", "a:b", - "'a\\b'" }, + "'a\\b'", LQ RQ, LQ RQ }, { "''", "1", 1, "simple", "' \t\n'\\''\"\033?""?/\\'", "a:b", - "'a\\b'" }, + "'a\\b'", LQ RQ, LQ RQ }, { "''", "1", 1, "simple", "' \t\n'\\''\"\033?""?/\\'", "'a:b'", - "'a\\b'" } }, + "'a\\b'", LQ RQ, LQ RQ } }, /* shell_always_quoting_style */ { { "''", "'\0""1\0'", 5, "'simple'", "' \t\n'\\''\"\033?""?/\\'", "'a:b'", - "'a\\b'" }, + "'a\\b'", "'" LQ RQ "'", "'" LQ RQ "'" }, { "''", "'1'", 3, "'simple'", "' \t\n'\\''\"\033?""?/\\'", "'a:b'", - "'a\\b'" }, + "'a\\b'", "'" LQ RQ "'", "'" LQ RQ "'" }, { "''", "'1'", 3, "'simple'", "' \t\n'\\''\"\033?""?/\\'", "'a:b'", - "'a\\b'" } }, + "'a\\b'", "'" LQ RQ "'", "'" LQ RQ "'" } }, /* c_quoting_style */ { { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", - "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"" }, + "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"", + "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" }, { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", - "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"" }, + "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"", + "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" }, { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", - "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"" } }, + "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"", + "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" } }, /* c_maybe_quoting_style */ { { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"", - "a:b", "a\\b" }, + "a:b", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ }, { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"", - "a:b", "a\\b" }, + "a:b", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ }, { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"", - "\"a:b\"", "a\\b" } }, + "\"a:b\"", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ } }, /* escape_quoting_style */ { { "", "\\0001\\0", 7, "simple", " \\t\\n'\"\\033?""?/\\\\", "a:b", - "a\\\\b" }, + "a\\\\b", LQ_ENC RQ_ENC, LQ RQ }, { "", "\\0001\\0", 7, "simple", " \\t\\n'\"\\033?""?/\\\\", "a:b", - "a\\\\b" }, + "a\\\\b", LQ_ENC RQ_ENC, LQ RQ }, { "", "\\0001\\0", 7, "simple", " \\t\\n'\"\\033?""?/\\\\", "a\\:b", - "a\\\\b" } }, + "a\\\\b", LQ_ENC RQ_ENC, LQ RQ } }, /* locale_quoting_style */ { { "`'", "`\\0001\\0'", 9, "`simple'", "` \\t\\n\\'\"\\033?""?/\\\\'", - "`a:b'", "`a\\\\b'" }, + "`a:b'", "`a\\\\b'", "`" LQ_ENC RQ_ENC "'", "`" LQ RQ "'" }, { "`'", "`\\0001\\0'", 9, "`simple'", "` \\t\\n\\'\"\\033?""?/\\\\'", - "`a:b'", "`a\\\\b'" }, + "`a:b'", "`a\\\\b'", "`" LQ_ENC RQ_ENC "'", "`" LQ RQ "'" }, { "`'", "`\\0001\\0'", 9, "`simple'", "` \\t\\n\\'\"\\033?""?/\\\\'", - "`a\\:b'", "`a\\\\b'" } }, + "`a\\:b'", "`a\\\\b'", "`" LQ_ENC RQ_ENC "'", "`" LQ RQ "'" } }, /* clocale_quoting_style */ { { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", - "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"" }, + "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"", + "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" }, { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", - "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"" }, + "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"", + "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" }, { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", - "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"" } } + "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"", + "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" } } }; static struct result_groups flag_results[] = { /* literal_quoting_style and QA_ELIDE_NULL_BYTES */ - { { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b" }, - { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b" }, - { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b" } }, + { { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", LQ RQ, + LQ RQ }, + { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", LQ RQ, + LQ RQ }, + { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", LQ RQ, + LQ RQ } }, /* c_quoting_style and QA_ELIDE_OUTER_QUOTES */ { { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"", - "a:b", "a\\b" }, + "a:b", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ }, { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"", - "a:b", "a\\b" }, + "a:b", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ }, { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"", - "\"a:b\"", "a\\b" } }, + "\"a:b\"", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ } }, /* c_quoting_style and QA_SPLIT_TRIGRAPHS */ { { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", - "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a:b\"", "\"a\\\\b\"" }, + "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a:b\"", "\"a\\\\b\"", + "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" }, { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", - "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a:b\"", "\"a\\\\b\"" }, + "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a:b\"", "\"a\\\\b\"", + "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" }, { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", - "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"" } } + "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"", + "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" } } }; #if ENABLE_NLS + static struct result_groups locale_results[] = { /* locale_quoting_style */ { { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ, - LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ }, + LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ, + LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ }, { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ, - LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ }, + LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ, + LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ}, { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ, - LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ, LQ "a\\\\b" RQ } }, + LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ, LQ "a\\\\b" RQ, + LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ } }, /* clocale_quoting_style */ { { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ, - LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ }, + LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ, + LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ }, { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ, - LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ }, + LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ, + LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ }, { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ, - LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ, LQ "a\\\\b" RQ } } + LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ, LQ "a\\\\b" RQ, + LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ } } }; + #endif /* ENABLE_NLS */ +static char const *custom_quotes[][2] = { + { "", "" }, + { "'", "'" }, + { "(", ")" }, + { ":", " " }, + { " ", ":" }, + { "# ", "\n" }, + { "\"'", "'\"" } +}; + +static struct result_groups custom_results[] = { + /* left_quote = right_quote = "" */ + { { "", "\\0001\\0", 7, "simple", + " \\t\\n'\"\\033?""?/\\\\", "a:b", "a\\\\b", + LQ_ENC RQ_ENC, LQ RQ }, + { "", "\\0001\\0", 7, "simple", + " \\t\\n'\"\\033?""?/\\\\", "a:b", "a\\\\b", + LQ_ENC RQ_ENC, LQ RQ }, + { "", "\\0001\\0", 7, "simple", + " \\t\\n'\"\\033?""?/\\\\", "a\\:b", "a\\\\b", + LQ_ENC RQ_ENC, LQ RQ } }, + + /* left_quote = right_quote = "'" */ + { { "''", "'\\0001\\0'", 9, "'simple'", + "' \\t\\n\\'\"\\033?""?/\\\\'", "'a:b'", "'a\\\\b'", + "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" }, + { "''", "'\\0001\\0'", 9, "'simple'", + "' \\t\\n\\'\"\\033?""?/\\\\'", "'a:b'", "'a\\\\b'", + "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" }, + { "''", "'\\0001\\0'", 9, "'simple'", + "' \\t\\n\\'\"\\033?""?/\\\\'", "'a\\:b'", "'a\\\\b'", + "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" } }, + + /* left_quote = "(" and right_quote = ")" */ + { { "()", "(\\0001\\0)", 9, "(simple)", + "( \\t\\n'\"\\033?""?/\\\\)", "(a:b)", "(a\\\\b)", + "(" LQ_ENC RQ_ENC ")", "(" LQ RQ ")" }, + { "()", "(\\0001\\0)", 9, "(simple)", + "( \\t\\n'\"\\033?""?/\\\\)", "(a:b)", "(a\\\\b)", + "(" LQ_ENC RQ_ENC ")", "(" LQ RQ ")" }, + { "()", "(\\0001\\0)", 9, "(simple)", + "( \\t\\n'\"\\033?""?/\\\\)", "(a\\:b)", "(a\\\\b)", + "(" LQ_ENC RQ_ENC ")", "(" LQ RQ ")" } }, + + /* left_quote = ":" and right_quote = " " */ + { { ": ", ":\\0001\\0 ", 9, ":simple ", + ":\\ \\t\\n'\"\\033?""?/\\\\ ", ":a:b ", ":a\\\\b ", + ":" LQ_ENC RQ_ENC " ", ":" LQ RQ " " }, + { ": ", ":\\0001\\0 ", 9, ":simple ", + ":\\ \\t\\n'\"\\033?""?/\\\\ ", ":a:b ", ":a\\\\b ", + ":" LQ_ENC RQ_ENC " ", ":" LQ RQ " " }, + { ": ", ":\\0001\\0 ", 9, ":simple ", + ":\\ \\t\\n'\"\\033?""?/\\\\ ", ":a\\:b ", ":a\\\\b ", + ":" LQ_ENC RQ_ENC " ", ":" LQ RQ " " } }, + + /* left_quote = " " and right_quote = ":" */ + { { " :", " \\0001\\0:", 9, " simple:", + " \\t\\n'\"\\033?""?/\\\\:", " a\\:b:", " a\\\\b:", + " " LQ_ENC RQ_ENC ":", " " LQ RQ ":" }, + { " :", " \\0001\\0:", 9, " simple:", + " \\t\\n'\"\\033?""?/\\\\:", " a\\:b:", " a\\\\b:", + " " LQ_ENC RQ_ENC ":", " " LQ RQ ":" }, + { " :", " \\0001\\0:", 9, " simple:", + " \\t\\n'\"\\033?""?/\\\\:", " a\\:b:", " a\\\\b:", + " " LQ_ENC RQ_ENC ":", " " LQ RQ ":" } }, + + /* left_quote = "# " and right_quote = "\n" */ + { { "# \n", "# \\0001\\0\n", 10, "# simple\n", + "# \\t\\n'\"\\033?""?/\\\\\n", "# a:b\n", "# a\\\\b\n", + "# " LQ_ENC RQ_ENC "\n", "# " LQ RQ "\n" }, + { "# \n", "# \\0001\\0\n", 10, "# simple\n", + "# \\t\\n'\"\\033?""?/\\\\\n", "# a:b\n", "# a\\\\b\n", + "# " LQ_ENC RQ_ENC "\n", "# " LQ RQ "\n" }, + { "# \n", "# \\0001\\0\n", 10, "# simple\n", + "# \\t\\n'\"\\033?""?/\\\\\n", "# a\\:b\n", "# a\\\\b\n", + "# " LQ_ENC RQ_ENC "\n", "# " LQ RQ "\n" } }, + + /* left_quote = "\"'" and right_quote = "'\"" */ + { { "\"''\"", "\"'\\0001\\0'\"", 11, "\"'simple'\"", + "\"' \\t\\n\\'\"\\033?""?/\\\\'\"", "\"'a:b'\"", "\"'a\\\\b'\"", + "\"'" LQ_ENC RQ_ENC "'\"", "\"'" LQ RQ "'\"" }, + { "\"''\"", "\"'\\0001\\0'\"", 11, "\"'simple'\"", + "\"' \\t\\n\\'\"\\033?""?/\\\\'\"", "\"'a:b'\"", "\"'a\\\\b'\"", + "\"'" LQ_ENC RQ_ENC "'\"", "\"'" LQ RQ "'\"" }, + { "\"''\"", "\"'\\0001\\0'\"", 11, "\"'simple'\"", + "\"' \\t\\n\\'\"\\033?""?/\\\\'\"", "\"'a\\:b'\"", "\"'a\\\\b'\"", + "\"'" LQ_ENC RQ_ENC "'\"", "\"'" LQ RQ "'\"" } } +}; + static void compare (char const *a, size_t la, char const *b, size_t lb) { @@ -190,7 +302,7 @@ compare (char const *a, size_t la, char const *b, size_t lb) static void compare_strings (char *(func) (char const *, size_t *), - struct result_strings *results) + struct result_strings *results, bool ascii_only) { size_t len; char *p; @@ -218,6 +330,13 @@ compare_strings (char *(func) (char const *, size_t *), len = strlen (inputs.str6); p = func (inputs.str6, &len); compare (results->str6, strlen (results->str6), p, len); + + len = strlen (inputs.str7a); + p = func (inputs.str7a, &len); + if (ascii_only) + compare (results->str7a, strlen (results->str7a), p, len); + else + compare (results->str7b, strlen (results->str7b), p, len); } static char * @@ -241,101 +360,122 @@ use_quotearg (const char *str, size_t *len) } static char * -use_quotearg_colon (const char *str, size_t *len) +use_quote_double_quotes (const char *str, size_t *len) { - char *p = (*len == SIZE_MAX ? quotearg_colon (str) - : quotearg_colon_mem (str, *len)); + char *p = *len == SIZE_MAX ? quotearg_char (str, '"') + : quotearg_char_mem (str, *len, '"'); *len = strlen (p); return p; } -#if ENABLE_NLS -/* True if the locale should be faked. */ -static bool fake_locale; - -/* A replacement gettext that allows testing of locale quotes without - requiring a locale. */ -char * -gettext (char const *str) -{ - if (fake_locale) - { - static char lq[] = LQ; - static char rq[] = RQ; - if (strcmp (str, "`") == 0) - return lq; - if (strcmp (str, "'") == 0) - return rq; - } - return (char *) str; -} - -char * -dgettext (char const *d, char const *str) -{ - return gettext (str); -} - -char * -dcgettext (char const *d, char const *str, int c) +static char * +use_quotearg_colon (const char *str, size_t *len) { - return gettext (str); + char *p = (*len == SIZE_MAX ? quotearg_colon (str) + : quotearg_colon_mem (str, *len)); + *len = strlen (p); + return p; } -#endif /* ENABLE_NLS */ int -main () +main (int argc _UNUSED_PARAMETER_, char *argv[]) { int i; - - /* This program is hard-wired to the C locale since it does not call - setlocale. */ + bool ascii_only = MB_CUR_MAX == 1 && !isprint ((unsigned char) LQ[0]); + + set_program_name (argv[0]); + + /* This part of the program is hard-wired to the C locale since it + does not call setlocale. However, according to POSIX, the use of + 8-bit bytes in a character context in the C locale gives + unspecified results (that is, the C locale charset is allowed to + be unibyte with 8-bit bytes rejected [ASCII], unibyte with 8-bit + bytes being characters [often ISO-8859-1], or multibyte [often + UTF-8]). We assume that the latter two cases will be + indistinguishable in this test - that is, the LQ and RQ sequences + will pass through unchanged in either type of charset. So when + testing for quoting of str7, use the ascii_only flag to decide + what to expect for the 8-bit data being quoted. */ ASSERT (!isprint ('\033')); for (i = literal_quoting_style; i <= clocale_quoting_style; i++) { set_quoting_style (NULL, i); - compare_strings (use_quotearg_buffer, &results_g[i].group1); - compare_strings (use_quotearg, &results_g[i].group2); - compare_strings (use_quotearg_colon, &results_g[i].group3); + compare_strings (use_quotearg_buffer, &results_g[i].group1, ascii_only); + compare_strings (use_quotearg, &results_g[i].group2, ascii_only); + if (i == c_quoting_style) + compare_strings (use_quote_double_quotes, &results_g[i].group2, + ascii_only); + compare_strings (use_quotearg_colon, &results_g[i].group3, ascii_only); } set_quoting_style (NULL, literal_quoting_style); ASSERT (set_quoting_flags (NULL, QA_ELIDE_NULL_BYTES) == 0); - compare_strings (use_quotearg_buffer, &flag_results[0].group1); - compare_strings (use_quotearg, &flag_results[0].group2); - compare_strings (use_quotearg_colon, &flag_results[0].group3); + compare_strings (use_quotearg_buffer, &flag_results[0].group1, ascii_only); + compare_strings (use_quotearg, &flag_results[0].group2, ascii_only); + compare_strings (use_quotearg_colon, &flag_results[0].group3, ascii_only); set_quoting_style (NULL, c_quoting_style); ASSERT (set_quoting_flags (NULL, QA_ELIDE_OUTER_QUOTES) - == QA_ELIDE_NULL_BYTES); - compare_strings (use_quotearg_buffer, &flag_results[1].group1); - compare_strings (use_quotearg, &flag_results[1].group2); - compare_strings (use_quotearg_colon, &flag_results[1].group3); + == QA_ELIDE_NULL_BYTES); + compare_strings (use_quotearg_buffer, &flag_results[1].group1, ascii_only); + compare_strings (use_quotearg, &flag_results[1].group2, ascii_only); + compare_strings (use_quote_double_quotes, &flag_results[1].group2, + ascii_only); + compare_strings (use_quotearg_colon, &flag_results[1].group3, ascii_only); ASSERT (set_quoting_flags (NULL, QA_SPLIT_TRIGRAPHS) - == QA_ELIDE_OUTER_QUOTES); - compare_strings (use_quotearg_buffer, &flag_results[2].group1); - compare_strings (use_quotearg, &flag_results[2].group2); - compare_strings (use_quotearg_colon, &flag_results[2].group3); + == QA_ELIDE_OUTER_QUOTES); + compare_strings (use_quotearg_buffer, &flag_results[2].group1, ascii_only); + compare_strings (use_quotearg, &flag_results[2].group2, ascii_only); + compare_strings (use_quote_double_quotes, &flag_results[2].group2, + ascii_only); + compare_strings (use_quotearg_colon, &flag_results[2].group3, ascii_only); ASSERT (set_quoting_flags (NULL, 0) == QA_SPLIT_TRIGRAPHS); + for (i = 0; i < sizeof custom_quotes / sizeof *custom_quotes; ++i) + { + set_custom_quoting (NULL, + custom_quotes[i][0], custom_quotes[i][1]); + compare_strings (use_quotearg_buffer, &custom_results[i].group1, + ascii_only); + compare_strings (use_quotearg, &custom_results[i].group2, ascii_only); + compare_strings (use_quotearg_colon, &custom_results[i].group3, + ascii_only); + } + #if ENABLE_NLS - /* Rather than change locales, and require a .gmo file with - translations for "`" and "'" that match our expectations, we - merely override the gettext function to satisfy the link - dependencies of quotearg.c. */ - fake_locale = true; - - set_quoting_style (NULL, locale_quoting_style); - compare_strings (use_quotearg_buffer, &locale_results[0].group1); - compare_strings (use_quotearg, &locale_results[0].group2); - compare_strings (use_quotearg_colon, &locale_results[0].group3); - - set_quoting_style (NULL, clocale_quoting_style); - compare_strings (use_quotearg_buffer, &locale_results[1].group1); - compare_strings (use_quotearg, &locale_results[1].group2); - compare_strings (use_quotearg_colon, &locale_results[1].group3); + /* Clean up environment. */ + unsetenv ("LANGUAGE"); + unsetenv ("LC_ALL"); + unsetenv ("LC_MESSAGES"); + unsetenv ("LC_CTYPE"); + unsetenv ("LANG"); + unsetenv ("OUTPUT_CHARSET"); + + /* This program part runs in a French UTF-8 locale. It uses + the test-quotearg.mo message catalog. */ + { + const char *locale_name = getenv ("LOCALE"); + + if (locale_name != NULL && strcmp (locale_name, "none") != 0 + && setenv ("LC_ALL", locale_name, 1) == 0 + && setlocale (LC_ALL, "") != NULL) + { + textdomain ("test-quotearg"); + bindtextdomain ("test-quotearg", getenv ("LOCALEDIR")); + + set_quoting_style (NULL, locale_quoting_style); + compare_strings (use_quotearg_buffer, &locale_results[0].group1, false); + compare_strings (use_quotearg, &locale_results[0].group2, false); + compare_strings (use_quotearg_colon, &locale_results[0].group3, false); + + set_quoting_style (NULL, clocale_quoting_style); + compare_strings (use_quotearg_buffer, &locale_results[1].group1, false); + compare_strings (use_quotearg, &locale_results[1].group2, false); + compare_strings (use_quotearg_colon, &locale_results[1].group3, false); + } + } #endif /* ENABLE_NLS */ quotearg_free ();