]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/calyearstart.c
Upgrade NTP to 4.2.8p4.
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / calyearstart.c
1 #include "config.h"
2
3 #include "ntp_stdlib.h"
4 #include "ntp_calendar.h"
5 #include "unity.h"
6
7 #include "test-libntp.h"
8
9 void setUp(void);
10 void tearDown(void);
11 void test_NoWrapInDateRange(void);
12 void test_NoWrapInDateRangeLeapYear(void);
13 void test_WrapInDateRange(void);
14
15 void setUp(void)
16 {
17     ntpcal_set_timefunc(timefunc);
18     settime(1970, 1, 1, 0, 0, 0);
19 }
20
21 void tearDown(void)
22 {
23     ntpcal_set_timefunc(NULL);
24 }
25
26
27 void test_NoWrapInDateRange(void) {
28         const u_int32 input = 3486372600UL; // 2010-06-24 12:50:00.
29         const u_int32 expected = 3471292800UL; // 2010-01-01 00:00:00
30
31         TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime));
32         TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL));
33 }
34
35 void test_NoWrapInDateRangeLeapYear(void) {
36         const u_int32 input = 3549528000UL; // 2012-06-24 12:00:00
37         const u_int32 expected = 3534364800UL; // 2012-01-01 00:00:00
38
39         TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime));
40         TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL));
41 }
42
43 void test_WrapInDateRange(void) {
44         const u_int32 input = 19904UL; // 2036-02-07 12:00:00
45         const u_int32 expected = 4291747200UL; // 2036-01-01 00:00:00
46
47         TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime));
48         TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL));
49 }