1 /* Verify the behavior of strftime on alternative representation for
4 Copyright (C) 2019 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 <http://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"
35 /* Must match locale index into locales array. */
41 static const char *formats[] = { "%EY", "%_EY", "%-EY" };
48 static const date_t dates[] =
58 static char ref[array_length (locales)][array_length (formats)]
59 [array_length (dates)][100];
62 is_before (const int i, const int d, const int m, const int y)
66 else if (dates[i].y > y)
68 else if (dates[i].m < m)
70 else if (dates[i].m > m)
73 return dates[i].d < d;
80 const char *era, *sfx;
81 /* Japanese era year to be checked. */
82 static const int yrj[] =
86 /* Buddhist calendar year to be checked. */
87 static const int yrb[] =
89 2531, 2532, 2532, 2533, 2540, 2541
92 for (i = 0; i < array_length (locales); i++)
93 for (j = 0; j < array_length (formats); j++)
94 for (k = 0; k < array_length (dates); k++)
98 era = (is_before (k, 8, 1, 1989)) ? "\u662d\u548c"
100 yr = yrj[k], sfx = "\u5e74";
103 era = "\u0e9e.\u0eaa. ", yr = yrb[k], sfx = "";
105 era = "\u0e1e.\u0e28. ", yr = yrb[k], sfx = "";
107 FAIL_EXIT1 ("Invalid table index!");
109 sprintf (ref[i][j][k], "%s\u5143%s", era, sfx);
111 sprintf (ref[i][j][k], "%s%02d%s", era, abs (yr), sfx);
113 sprintf (ref[i][j][k], "%s%2d%s", era, abs (yr), sfx);
115 sprintf (ref[i][j][k], "%s%d%s", era, abs (yr), sfx);
117 FAIL_EXIT1 ("Invalid table index!");
124 int i, j, k, result = 0;
126 char date[11], buf[100];
130 for (i = 0; i < array_length (locales); i++)
132 if (setlocale (LC_ALL, locales[i]) == NULL)
134 printf ("locale %s does not exist, skipping...\n", locales[i]);
137 printf ("[%s]\n", locales[i]);
138 for (j = 0; j < array_length (formats); j++)
140 for (k = 0; k < array_length (dates); k++)
142 ttm.tm_mday = dates[k].d;
143 ttm.tm_mon = dates[k].m - 1;
144 ttm.tm_year = dates[k].y - 1900;
145 strftime (date, sizeof (date), "%F", &ttm);
146 r = strftime (buf, sizeof (buf), formats[j], &ttm);
147 e = strlen (ref[i][j][k]);
148 printf ("%s\t\"%s\"\t\"%s\"", date, formats[j], buf);
149 if (strcmp (buf, ref[i][j][k]) != 0)
151 printf ("\tshould be \"%s\"", ref[i][j][k]);
153 printf ("\tgot: %zu, expected: %zu", r, e);
166 #include <support/test-driver.c>