]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/caltontp.c
Upgrade NTP to 4.2.8p4.
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / caltontp.c
1 #include "config.h"
2 #include "ntp_calendar.h"
3 #include "unity.h"
4
5 void test_DateGivenMonthDay(void);
6 void test_DateGivenYearDay(void);
7 void test_DateLeapYear(void);
8 void test_WraparoundDateIn2036(void);
9
10 void
11 test_DateGivenMonthDay(void) {
12         // 2010-06-24 12:50:00
13         struct calendar input = {2010, 0, 6, 24, 12, 50, 0};
14
15         u_long expected = 3486372600UL; // This is the timestamp above.
16
17         TEST_ASSERT_EQUAL_UINT(expected, caltontp(&input));
18 }
19
20 void
21 test_DateGivenYearDay(void) {
22         // 2010-06-24 12:50:00
23         // This is the 175th day of 2010.
24         struct calendar input = {2010, 175, 0, 0, 12, 50, 0};
25
26         u_long expected = 3486372600UL; // This is the timestamp above.
27
28         TEST_ASSERT_EQUAL_UINT(expected, caltontp(&input));
29 }
30
31 void
32 test_DateLeapYear(void) {
33         // 2012-06-24 12:00:00
34         // This is the 176th day of 2012 (since 2012 is a leap year).
35         struct calendar inputYd = {2012, 176, 0, 0, 12, 00, 00};
36         struct calendar inputMd = {2012, 0, 6, 24, 12, 00, 00};
37
38         u_long expected = 3549528000UL;
39
40         TEST_ASSERT_EQUAL_UINT(expected, caltontp(&inputYd));
41         TEST_ASSERT_EQUAL_UINT(expected, caltontp(&inputMd));
42 }
43
44 void
45 test_WraparoundDateIn2036(void) {
46         // 2036-02-07 06:28:16
47         // This is (one) wrapping boundary where we go from ULONG_MAX to 0.
48         struct calendar input = {2036, 0, 2, 7, 6, 28, 16};
49
50         u_long expected = 0UL;
51
52         TEST_ASSERT_EQUAL_UINT(expected, caltontp(&input));
53 }