caltontp.c revision 290001
1#include "config.h"
2#include "ntp_calendar.h"
3#include "unity.h"
4
5void test_DateGivenMonthDay(void);
6void test_DateGivenYearDay(void);
7void test_DateLeapYear(void);
8void test_WraparoundDateIn2036(void);
9
10void
11test_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
20void
21test_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
31void
32test_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
44void
45test_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}
54