]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/g_caltontp.cpp
Fix a regression with SA-15:24 patch that prevented NIS from
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / g_caltontp.cpp
1 #include "g_libntptest.h"
2
3 extern "C" {
4 #include "ntp_calendar.h"
5 }
6
7 class caltontpTest : public libntptest {
8 };
9
10 TEST_F(caltontpTest, DateGivenMonthDay) {
11         // 2010-06-24 12:50:00
12         calendar input = {2010, 0, 6, 24, 12, 50, 0};
13
14         u_long expected = 3486372600UL; // This is the timestamp above.
15
16         EXPECT_EQ(expected, caltontp(&input));
17 }
18
19 TEST_F(caltontpTest, DateGivenYearDay) {
20         // 2010-06-24 12:50:00
21         // This is the 175th day of 2010.
22         calendar input = {2010, 175, 0, 0, 12, 50, 0};
23
24         u_long expected = 3486372600UL; // This is the timestamp above.
25
26         EXPECT_EQ(expected, caltontp(&input));
27 }
28
29 TEST_F(caltontpTest, DateLeapYear) {
30         // 2012-06-24 12:00:00
31         // This is the 176th day of 2012 (since 2012 is a leap year).
32         calendar inputYd = {2012, 176, 0, 0, 12, 00, 00};
33         calendar inputMd = {2012, 0, 6, 24, 12, 00, 00};
34
35         u_long expected = 3549528000UL;
36
37         EXPECT_EQ(expected, caltontp(&inputYd));
38         EXPECT_EQ(expected, caltontp(&inputMd));
39 }
40
41 TEST_F(caltontpTest, WraparoundDateIn2036) {
42         // 2036-02-07 06:28:16
43         // This is (one) wrapping boundary where we go from ULONG_MAX to 0.
44         calendar input = {2036, 0, 2, 7, 6, 28, 16};
45
46         u_long expected = 0UL;
47
48         EXPECT_EQ(expected, caltontp(&input));
49 }