maint: update copyright
[gnulib.git] / tests / test-quotearg.c
1 /* Test of quotearg family of functions.
2    Copyright (C) 2008-2014 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, see <http://www.gnu.org/licenses/>.  */
16
17 /* Written by Eric Blake <ebb9@byu.net>, 2008.  */
18
19 #include <config.h>
20
21 #include "quotearg.h"
22
23 #include <locale.h>
24 #include <stdbool.h>
25 #include <stdint.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "progname.h"
30 #include "gettext.h"
31 #include "macros.h"
32
33 #include "test-quotearg.h"
34
35 #if ENABLE_NLS
36
37 static struct result_groups locale_results[] = {
38   /* locale_quoting_style */
39   { { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
40       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
41       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ },
42     { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
43       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
44       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ},
45     { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
46       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ, LQ "a\\\\b" RQ,
47       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ } },
48
49   /* clocale_quoting_style */
50   { { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
51       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
52       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ },
53     { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
54       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a:b" RQ, LQ "a\\\\b" RQ,
55       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ },
56     { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ,
57       LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ, LQ "a\\\\b" RQ,
58       LQ LQ RQ_ESC RQ, LQ LQ RQ_ESC RQ } }
59 };
60
61 #endif /* ENABLE_NLS */
62
63 int
64 main (int argc _GL_UNUSED, char *argv[])
65 {
66   set_program_name (argv[0]);
67
68 #if ENABLE_NLS
69   /* Clean up environment.  */
70   unsetenv ("LANGUAGE");
71   unsetenv ("LC_ALL");
72   unsetenv ("LC_MESSAGES");
73   unsetenv ("LC_CTYPE");
74   unsetenv ("LANG");
75   unsetenv ("OUTPUT_CHARSET");
76
77   /* This program part runs in a French UTF-8 locale.  It uses
78      the test-quotearg.mo message catalog.  */
79   {
80     const char *locale_name = getenv ("LOCALE");
81
82     if (locale_name != NULL && strcmp (locale_name, "none") != 0
83         && setenv ("LC_ALL", locale_name, 1) == 0
84         && setlocale (LC_ALL, "") != NULL)
85       {
86         textdomain ("test-quotearg");
87         bindtextdomain ("test-quotearg", getenv ("LOCALEDIR"));
88
89         set_quoting_style (NULL, locale_quoting_style);
90         compare_strings (use_quotearg_buffer, &locale_results[0].group1, false);
91         compare_strings (use_quotearg, &locale_results[0].group2, false);
92         compare_strings (use_quotearg_colon, &locale_results[0].group3, false);
93
94         set_quoting_style (NULL, clocale_quoting_style);
95         compare_strings (use_quotearg_buffer, &locale_results[1].group1, false);
96         compare_strings (use_quotearg, &locale_results[1].group2, false);
97         compare_strings (use_quotearg_colon, &locale_results[1].group3, false);
98
99         quotearg_free ();
100         return 0;
101       }
102   }
103
104   fputs ("Skipping test: no french Unicode locale is installed\n", stderr);
105   return 77;
106 #else
107   fputs ("Skipping test: internationalization is disabled\n", stderr);
108   return 77;
109 #endif /* ENABLE_NLS */
110 }