1 /* Verify the behavior of strftime on alternative representation for
4 Copyright (C) 2019-2022 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <https://www.gnu.org/licenses/>. */
21 #include <array_length.h>
23 #include <support/check.h>
30 static const char *locales[] =
32 "ja_JP.UTF-8", "lo_LA.UTF-8", "th_TH.UTF-8",
33 "zh_TW.UTF-8", "cmn_TW.UTF-8", "hak_TW.UTF-8",
34 "nan_TW.UTF-8", "lzh_TW.UTF-8"
37 /* Must match locale index into locales array. */
41 zh_TW, cmn_TW, hak_TW, nan_TW, lzh_TW
44 static const char *formats[] = { "%EY", "%_EY", "%-EY" };
51 static const date_t dates[] =
69 static char ref[array_length (locales)][array_length (formats)]
70 [array_length (dates)][100];
73 is_before (const int i, const int d, const int m, const int y)
77 else if (dates[i].y > y)
79 else if (dates[i].m < m)
81 else if (dates[i].m > m)
84 return dates[i].d < d;
91 const char *era, *sfx;
92 /* Japanese era year to be checked. */
93 static const int yrj[] =
96 63, 64, 1, 2, 9, 10, 22, 23, 31, 1
98 /* Buddhist calendar year to be checked. */
99 static const int yrb[] =
101 2453, 2454, 2455, 2456,
102 2531, 2532, 2532, 2533, 2540, 2541, 2553, 2554, 2562, 2562
104 /* R.O.C. calendar year to be checked. Negative number is prior to
105 Minguo counting up. */
106 static const int yrc[] =
109 77, 78, 78, 79, 86, 87, 99, 100, 108, 108
112 for (i = 0; i < array_length (locales); i++)
113 for (j = 0; j < array_length (formats); j++)
114 for (k = 0; k < array_length (dates); k++)
118 era = (is_before (k, 30, 7, 1912)) ? "\u660e\u6cbb"
119 : (is_before (k, 25, 12, 1926)) ? "\u5927\u6b63"
120 : (is_before (k, 8, 1, 1989)) ? "\u662d\u548c"
121 : (is_before (k, 1, 5, 2019)) ? "\u5e73\u6210"
123 yr = yrj[k], sfx = "\u5e74";
126 era = "\u0e9e.\u0eaa. ", yr = yrb[k], sfx = "";
128 era = "\u0e1e.\u0e28. ", yr = yrb[k], sfx = "";
129 else if (i == zh_TW || i == cmn_TW || i == hak_TW
130 || i == nan_TW || i == lzh_TW)
132 era = (is_before (k, 1, 1, 1912)) ? "\u6c11\u524d"
134 yr = yrc[k], sfx = "\u5e74";
137 FAIL_EXIT1 ("Invalid table index!");
139 sprintf (ref[i][j][k], "%s\u5143%s", era, sfx);
141 sprintf (ref[i][j][k], "%s%02d%s", era, abs (yr), sfx);
143 sprintf (ref[i][j][k], "%s%2d%s", era, abs (yr), sfx);
145 sprintf (ref[i][j][k], "%s%d%s", era, abs (yr), sfx);
147 FAIL_EXIT1 ("Invalid table index!");
154 int i, j, k, result = 0;
156 char date[11], buf[100];
160 for (i = 0; i < array_length (locales); i++)
162 if (setlocale (LC_ALL, locales[i]) == NULL)
164 printf ("locale %s does not exist, skipping...\n", locales[i]);
167 printf ("[%s]\n", locales[i]);
168 for (j = 0; j < array_length (formats); j++)
170 for (k = 0; k < array_length (dates); k++)
172 ttm.tm_mday = dates[k].d;
173 ttm.tm_mon = dates[k].m - 1;
174 ttm.tm_year = dates[k].y - 1900;
175 strftime (date, sizeof (date), "%F", &ttm);
176 r = strftime (buf, sizeof (buf), formats[j], &ttm);
177 e = strlen (ref[i][j][k]);
178 printf ("%s\t\"%s\"\t\"%s\"", date, formats[j], buf);
179 if (strcmp (buf, ref[i][j][k]) != 0)
181 printf ("\tshould be \"%s\"", ref[i][j][k]);
183 printf ("\tgot: %zu, expected: %zu", r, e);
196 #include <support/test-driver.c>