1 /* $NetBSD: calyearstart.c,v 1.2 2020/05/25 20:47:36 christos Exp $ */
2
3 #include "config.h"
4
5 #include "ntp_stdlib.h"
6 #include "ntp_calendar.h"
7 #include "unity.h"
8
9 #include "test-libntp.h"
10
11 void setUp(void);
12 void tearDown(void);
13 void test_NoWrapInDateRange(void);
14 void test_NoWrapInDateRangeLeapYear(void);
15 void test_WrapInDateRange(void);
16
setUp(void)17 void setUp(void)
18 {
19 ntpcal_set_timefunc(timefunc);
20 settime(1970, 1, 1, 0, 0, 0);
21 }
22
tearDown(void)23 void tearDown(void)
24 {
25 ntpcal_set_timefunc(NULL);
26 }
27
28
test_NoWrapInDateRange(void)29 void test_NoWrapInDateRange(void) {
30 const u_int32 input = 3486372600UL; // 2010-06-24 12:50:00.
31 const u_int32 expected = 3471292800UL; // 2010-01-01 00:00:00
32
33 TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime));
34 TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL));
35 }
36
test_NoWrapInDateRangeLeapYear(void)37 void test_NoWrapInDateRangeLeapYear(void) {
38 const u_int32 input = 3549528000UL; // 2012-06-24 12:00:00
39 const u_int32 expected = 3534364800UL; // 2012-01-01 00:00:00
40
41 TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime));
42 TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL));
43 }
44
test_WrapInDateRange(void)45 void test_WrapInDateRange(void) {
46 const u_int32 input = 19904UL; // 2036-02-07 12:00:00
47 const u_int32 expected = 4291747200UL; // 2036-01-01 00:00:00
48
49 TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime));
50 TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL));
51 }
52