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>
27 static const char *locales[] = { "ja_JP.UTF-8", "lo_LA.UTF-8", "th_TH.UTF-8" };
29 static const char *formats[] = { "%EY", "%_EY", "%-EY" };
44 static char ref[array_length (locales)][array_length (formats)]
45 [array_length (dates)][100];
52 static const int yrj[] = { 63, 64, 1, 2, 9, 10 };
53 static const int yrb[] = { 2531, 2532, 2532, 2533, 2540, 2541 };
55 for (i = 0; i < array_length (locales); i++)
56 for (j = 0; j < array_length (formats); j++)
57 for (k = 0; k < array_length (dates); k++)
61 sprintf (era, "%s", (k < 2) ? "\xe6\x98\xad\xe5\x92\x8c"
62 : "\xe5\xb9\xb3\xe6\x88\x90");
64 sprintf (ref[i][j][k], "%s\xe5\x85\x83\xe5\xb9\xb4", era);
68 sprintf (ref[i][j][k], "%s%02d\xe5\xb9\xb4", era, yrj[k]);
70 sprintf (ref[i][j][k], "%s%2d\xe5\xb9\xb4", era, yrj[k]);
72 sprintf (ref[i][j][k], "%s%d\xe5\xb9\xb4", era, yrj[k]);
77 sprintf (era, "\xe0\xba\x9e\x2e\xe0\xba\xaa\x2e ");
78 sprintf (ref[i][j][k], "%s%d", era, yrb[k]);
82 sprintf (era, "\xe0\xb8\x9e\x2e\xe0\xb8\xa8\x2e ");
83 sprintf (ref[i][j][k], "%s%d", era, yrb[k]);
91 int i, j, k, result = 0;
93 char date[11], buf[100];
97 for (i = 0; i < array_length (locales); i++)
99 if (setlocale (LC_ALL, locales[i]) == NULL)
101 printf ("locale %s does not exist, skipping...\n", locales[i]);
104 printf ("[%s]\n", locales[i]);
105 for (j = 0; j < array_length (formats); j++)
107 for (k = 0; k < array_length (dates); k++)
109 ttm.tm_mday = dates[k].d;
110 ttm.tm_mon = dates[k].m;
111 ttm.tm_year = dates[k].y;
112 strftime (date, sizeof (date), "%F", &ttm);
113 r = strftime (buf, sizeof (buf), formats[j], &ttm);
114 e = strlen (ref[i][j][k]);
115 printf ("%s\t\"%s\"\t\"%s\"", date, formats[j], buf);
116 if (strcmp (buf, ref[i][j][k]) != 0)
118 printf ("\tshould be \"%s\"", ref[i][j][k]);
120 printf ("\tgot: %zu, expected: %zu", r, e);
133 #include <support/test-driver.c>