]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/g_calyearstart.cpp
Fix a regression with SA-15:24 patch that prevented NIS from
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / g_calyearstart.cpp
1 #include "g_libntptest.h"
2
3 class calyearstartTest : public libntptest {
4 protected:
5         virtual void SetUp();
6         virtual void TearDown();
7 };
8
9 void calyearstartTest::SetUp()
10 {
11     ntpcal_set_timefunc(timefunc);
12     settime(1970, 1, 1, 0, 0, 0);
13 }
14
15 void calyearstartTest::TearDown()
16 {
17     ntpcal_set_timefunc(NULL);
18 }
19
20
21 TEST_F(calyearstartTest, NoWrapInDateRange) {
22         const u_int32 input = 3486372600UL; // 2010-06-24 12:50:00.
23         const u_int32 expected = 3471292800UL; // 2010-01-01 00:00:00
24
25         EXPECT_EQ(expected, calyearstart(input, &nowtime));
26         EXPECT_EQ(expected, calyearstart(input, NULL));
27 }
28
29 TEST_F(calyearstartTest, NoWrapInDateRangeLeapYear) {
30         const u_int32 input = 3549528000UL; // 2012-06-24 12:00:00
31         const u_int32 expected = 3534364800UL; // 2012-01-01 00:00:00
32
33         EXPECT_EQ(expected, calyearstart(input, &nowtime));
34         EXPECT_EQ(expected, calyearstart(input, NULL));
35 }
36
37 TEST_F(calyearstartTest, WrapInDateRange) {
38         const u_int32 input = 19904UL; // 2036-02-07 12:00:00
39         const u_int32 expected = 4291747200UL; // 2036-01-01 00:00:00
40
41         EXPECT_EQ(expected, calyearstart(input, &nowtime));
42         EXPECT_EQ(expected, calyearstart(input, NULL));
43 }