openat: don’t close (-1)
[gnulib.git] / tests / test-quotearg.c
blob0283f1ca1c246c358a4a7038947fa64ad1be4f4d
1 /* Test of quotearg family of functions.
2 Copyright (C) 2008-2024 Free Software Foundation, Inc.
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Eric Blake <ebb9@byu.net>, 2008. */
19 #include <config.h>
21 #include "quotearg.h"
23 #include <locale.h>
24 #include <stdint.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #include "gettext.h"
29 #include "macros.h"
31 #if ENABLE_NLS
33 # include "test-quotearg.h"
35 static struct result_groups locale_results[] = {
36 /* locale_quoting_style */
37 { { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ, LQ "\\t'\\t" RQ,
38 LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
39 LQ "a' b" RQ, LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ },
40 { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ, LQ "\\t'\\t" RQ,
41 LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
42 LQ "a' b" RQ, LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ},
43 { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ, LQ "\\t'\\t" RQ,
44 LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ, LQ "a\\\\b" RQ,
45 LQ "a' b" RQ, LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ } },
47 /* clocale_quoting_style */
48 { { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ, LQ "\\t'\\t" RQ,
49 LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
50 LQ "a' b" RQ, LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ },
51 { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ, LQ "\\t'\\t" RQ,
52 LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
53 LQ "a' b" RQ, LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ },
54 { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ, LQ "\\t'\\t" RQ,
55 LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ, LQ "a\\\\b" RQ,
56 LQ "a' b" RQ, LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ } }
59 #endif /* ENABLE_NLS */
61 int
62 main (_GL_UNUSED int argc, char *argv[])
64 #if ENABLE_NLS
65 /* Clean up environment. */
66 unsetenv ("LANGUAGE");
67 unsetenv ("LC_ALL");
68 unsetenv ("LC_MESSAGES");
69 unsetenv ("LC_CTYPE");
70 unsetenv ("LANG");
71 unsetenv ("OUTPUT_CHARSET");
73 /* This program part runs in a French UTF-8 locale. It uses
74 the test-quotearg.mo message catalog. */
76 const char *locale_name = getenv ("LOCALE");
78 if (!(locale_name != NULL && strcmp (locale_name, "none") != 0
79 && setenv ("LC_ALL", locale_name, 1) == 0
80 && setlocale (LC_ALL, "") != NULL))
82 fputs ("Skipping test: no french Unicode locale is installed\n", stderr);
83 return 77;
85 textdomain ("test-quotearg");
86 bindtextdomain ("test-quotearg", getenv ("LOCALEDIR"));
88 set_quoting_style (NULL, locale_quoting_style);
89 compare_strings (use_quotearg_buffer, &locale_results[0].group1, false);
90 compare_strings (use_quotearg, &locale_results[0].group2, false);
91 compare_strings (use_quotearg_colon, &locale_results[0].group3, false);
93 set_quoting_style (NULL, clocale_quoting_style);
94 compare_strings (use_quotearg_buffer, &locale_results[1].group1, false);
95 compare_strings (use_quotearg, &locale_results[1].group2, false);
96 compare_strings (use_quotearg_colon, &locale_results[1].group3, false);
98 quotearg_free ();
99 return test_exit_status;
102 #else
103 fputs ("Skipping test: internationalization is disabled\n", stderr);
104 return 77;
105 #endif /* ENABLE_NLS */