localedata: Convert oc_FR locale to UTF-8
[glibc.git] / time / tst-gmtime.c
blob2b3061e501bebfc44a70f3ad1d16b49f61061d70
1 /* Basic tests for gmtime.
2 Copyright (C) 2021-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <time.h>
20 #include <stdlib.h>
21 #include <support/check.h>
23 static int
24 do_test (void)
26 /* Check if the epoch time can be converted. */
28 time_t t = 0;
29 struct tm *tmg = gmtime (&t);
30 TEST_COMPARE (tmg->tm_sec, 0);
31 TEST_COMPARE (tmg->tm_min, 0);
32 TEST_COMPARE (tmg->tm_hour, 0);
33 TEST_COMPARE (tmg->tm_mday, 1);
34 TEST_COMPARE (tmg->tm_mon, 0);
35 TEST_COMPARE (tmg->tm_year, 70);
36 TEST_COMPARE (tmg->tm_wday, 4);
37 TEST_COMPARE (tmg->tm_yday, 0);
38 TEST_COMPARE (tmg->tm_isdst, 0);
41 /* Same as before but with gmtime_r. */
42 time_t t = 0;
43 struct tm tms;
44 struct tm *tmg = gmtime_r (&t, &tms);
45 TEST_VERIFY (tmg == &tms);
46 TEST_COMPARE (tmg->tm_sec, 0);
47 TEST_COMPARE (tmg->tm_min, 0);
48 TEST_COMPARE (tmg->tm_hour, 0);
49 TEST_COMPARE (tmg->tm_mday, 1);
50 TEST_COMPARE (tmg->tm_mon, 0);
51 TEST_COMPARE (tmg->tm_year, 70);
52 TEST_COMPARE (tmg->tm_wday, 4);
53 TEST_COMPARE (tmg->tm_yday, 0);
54 TEST_COMPARE (tmg->tm_isdst, 0);
57 /* Check if the max time value for 32 bit time_t can be converted. */
59 time_t t = 0x7fffffff;
60 struct tm *tmg = gmtime (&t);
61 TEST_COMPARE (tmg->tm_sec, 7);
62 TEST_COMPARE (tmg->tm_min, 14);
63 TEST_COMPARE (tmg->tm_hour, 3);
64 TEST_COMPARE (tmg->tm_mday, 19);
65 TEST_COMPARE (tmg->tm_mon, 0);
66 TEST_COMPARE (tmg->tm_year, 138);
67 TEST_COMPARE (tmg->tm_wday, 2);
68 TEST_COMPARE (tmg->tm_yday, 18);
69 TEST_COMPARE (tmg->tm_isdst, 0);
72 /* Same as before but with ctime_r. */
73 time_t t = 0x7fffffff;
74 struct tm tms;
75 struct tm *tmg = gmtime_r (&t, &tms);
76 TEST_VERIFY (tmg == &tms);
77 TEST_COMPARE (tmg->tm_sec, 7);
78 TEST_COMPARE (tmg->tm_min, 14);
79 TEST_COMPARE (tmg->tm_hour, 3);
80 TEST_COMPARE (tmg->tm_mday, 19);
81 TEST_COMPARE (tmg->tm_mon, 0);
82 TEST_COMPARE (tmg->tm_year, 138);
83 TEST_COMPARE (tmg->tm_wday, 2);
84 TEST_COMPARE (tmg->tm_yday, 18);
85 TEST_COMPARE (tmg->tm_isdst, 0);
88 if (sizeof (time_t) < 8)
89 return 0;
92 time_t t = (time_t) 0x80000000ull;
93 struct tm *tmg = gmtime (&t);
94 TEST_COMPARE (tmg->tm_sec, 8);
95 TEST_COMPARE (tmg->tm_min, 14);
96 TEST_COMPARE (tmg->tm_hour, 3);
97 TEST_COMPARE (tmg->tm_mday, 19);
98 TEST_COMPARE (tmg->tm_mon, 0);
99 TEST_COMPARE (tmg->tm_year, 138);
100 TEST_COMPARE (tmg->tm_wday, 2);
101 TEST_COMPARE (tmg->tm_yday, 18);
102 TEST_COMPARE (tmg->tm_isdst, 0);
106 time_t t = (time_t) 0x80000000ull;
107 struct tm tms;
108 struct tm *tmg = gmtime_r (&t, &tms);
109 TEST_VERIFY (tmg == &tms);
110 TEST_COMPARE (tmg->tm_sec, 8);
111 TEST_COMPARE (tmg->tm_min, 14);
112 TEST_COMPARE (tmg->tm_hour, 3);
113 TEST_COMPARE (tmg->tm_mday, 19);
114 TEST_COMPARE (tmg->tm_mon, 0);
115 TEST_COMPARE (tmg->tm_year, 138);
116 TEST_COMPARE (tmg->tm_wday, 2);
117 TEST_COMPARE (tmg->tm_yday, 18);
118 TEST_COMPARE (tmg->tm_isdst, 0);
121 return 0;
124 #include <support/test-driver.c>