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