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