Skip to content

Commit f5b58e9

Browse files
committed
tests: implement more time related tests
1 parent ed69d69 commit f5b58e9

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/00-time.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <assert.h>
2020
#include <unistd.h>
21+
#include <stdlib.h>
2122
#include "../src/time.h"
2223

2324
/* XXX: keep it synchronized with time.c */
@@ -138,11 +139,60 @@ static void test_03(void)
138139
/* TODO: check DST wrap */
139140
}
140141

142+
static void test_04(void)
143+
{
144+
struct tm tm = {
145+
.tm_sec = 59,
146+
.tm_min = 58,
147+
.tm_hour = 3,
148+
149+
.tm_mday = 31,
150+
.tm_mon = 11,
151+
.tm_year = 2023 - 1900,
152+
153+
.tm_isdst = -1,
154+
};
155+
156+
time_t now = mktime(&tm);
157+
158+
assert(time_max_lt(now, -1) == 0);
159+
assert(time_max_lt(now, 500) == 1 * 3600 + 1 * 60 + 1 + EXTRA_DAILY_TM);
160+
assert(time_max_lt(now, 100) == 25 * 3600 + EXTRA_DAILY_TM - (3 * 3600 + 58 * 60 + 59));
161+
}
162+
163+
static void test_05(void)
164+
{
165+
/* CEST -> CET DST change */
166+
167+
/* Sat Mar 25 12:00:00 CET 2023 */
168+
assert(time_max_lt(1679742000, 500) == 1679799600 - 1679742000 + EXTRA_DAILY_TM);
169+
170+
/* Sun Mar 26 01:00:00 CET 2023 */
171+
assert(time_max_lt(1679788800, 500) == 1679799600 - 1679788800 + EXTRA_DAILY_TM);
172+
173+
/* Sun Mar 26 12:00:00 CEST 2023 */
174+
assert(time_max_lt(1679824800, 500) == 1679886000 - 1679824800 + EXTRA_DAILY_TM);
175+
176+
177+
/* Sat Oct 28 12:00:00 CEST 2023 */
178+
assert(time_max_lt(1698487200, 500) == 1698552000 - 1698487200 + EXTRA_DAILY_TM);
179+
180+
/* Sun Oct 29 01:00:00 CEST 2023 */
181+
assert(time_max_lt(1698534000, 500) == 1698552000 - 1698534000 + EXTRA_DAILY_TM);
182+
183+
/* Sun Oct 29 12:00:00 CET 2023 */
184+
assert(time_max_lt(1698577200, 500) == 1698638400 - 1698577200 + EXTRA_DAILY_TM);
185+
}
186+
141187
#undef main
142188
int main(void)
143189
{
190+
setenv("TZ", "Europe/Berlin", 1);
191+
144192
test_00();
145193
test_01();
146194
test_02();
147195
test_03();
196+
test_04();
197+
test_05();
148198
}

0 commit comments

Comments
 (0)