]> git.ipfire.org Git - thirdparty/glibc.git/blame - time/tst-strftime2.c
iconv, localedef: avoid floating point rounding differences [BZ #24372]
[thirdparty/glibc.git] / time / tst-strftime2.c
CommitLineData
32f600a2
TS
1/* Verify the behavior of strftime on alternative representation for
2 year.
3
4 Copyright (C) 2019 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
6
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.
11
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.
16
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/>. */
20
21#include <array_length.h>
22#include <locale.h>
23#include <time.h>
24#include <stdio.h>
25#include <string.h>
26
27static const char *locales[] = { "ja_JP.UTF-8", "lo_LA.UTF-8", "th_TH.UTF-8" };
28
29static const char *formats[] = { "%EY", "%_EY", "%-EY" };
30
31static const struct
32{
33 const int d, m, y;
34} dates[] =
35 {
36 { 1, 3, 88 },
37 { 7, 0, 89 },
38 { 8, 0, 89 },
39 { 1, 3, 90 },
40 { 1, 3, 97 },
41 { 1, 3, 98 }
42 };
43
144a794e
TS
44static char ref[array_length (locales)][array_length (formats)]
45 [array_length (dates)][100];
32f600a2
TS
46
47static void
48mkreftable (void)
49{
50 int i, j, k;
51 char era[10];
52 static const int yrj[] = { 63, 64, 1, 2, 9, 10 };
53 static const int yrb[] = { 2531, 2532, 2532, 2533, 2540, 2541 };
54
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++)
58 {
59 if (i == 0)
60 {
61 sprintf (era, "%s", (k < 2) ? "\xe6\x98\xad\xe5\x92\x8c"
62 : "\xe5\xb9\xb3\xe6\x88\x90");
63 if (yrj[k] == 1)
64 sprintf (ref[i][j][k], "%s\xe5\x85\x83\xe5\xb9\xb4", era);
65 else
66 {
67 if (j == 0)
68 sprintf (ref[i][j][k], "%s%02d\xe5\xb9\xb4", era, yrj[k]);
69 else if (j == 1)
70 sprintf (ref[i][j][k], "%s%2d\xe5\xb9\xb4", era, yrj[k]);
71 else
72 sprintf (ref[i][j][k], "%s%d\xe5\xb9\xb4", era, yrj[k]);
73 }
74 }
75 else if (i == 1)
76 {
77 sprintf (era, "\xe0\xba\x9e\x2e\xe0\xba\xaa\x2e ");
78 sprintf (ref[i][j][k], "%s%d", era, yrb[k]);
79 }
80 else
81 {
82 sprintf (era, "\xe0\xb8\x9e\x2e\xe0\xb8\xa8\x2e ");
83 sprintf (ref[i][j][k], "%s%d", era, yrb[k]);
84 }
85 }
86}
87
88static int
89do_test (void)
90{
91 int i, j, k, result = 0;
92 struct tm ttm;
93 char date[11], buf[100];
94 size_t r, e;
95
96 mkreftable ();
97 for (i = 0; i < array_length (locales); i++)
98 {
99 if (setlocale (LC_ALL, locales[i]) == NULL)
100 {
101 printf ("locale %s does not exist, skipping...\n", locales[i]);
102 continue;
103 }
104 printf ("[%s]\n", locales[i]);
105 for (j = 0; j < array_length (formats); j++)
106 {
107 for (k = 0; k < array_length (dates); k++)
108 {
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)
117 {
118 printf ("\tshould be \"%s\"", ref[i][j][k]);
119 if (r != e)
120 printf ("\tgot: %zu, expected: %zu", r, e);
121 result = 1;
122 }
123 else
124 printf ("\tOK");
125 putchar ('\n');
126 }
127 putchar ('\n');
128 }
129 }
130 return result;
131}
132
133#include <support/test-driver.c>