159078Smdodd#include "config.h" 259078Smdodd#include "ntp_calendar.h" 359078Smdodd#include "unity.h" 432801Sjulian 559078Smdoddvoid test_DateGivenMonthDay(void); 659078Smdoddvoid test_DateGivenYearDay(void); 759078Smdoddvoid test_DateLeapYear(void); 832801Sjulianvoid test_WraparoundDateIn2036(void); 932801Sjulian 1032801Sjulianvoid 1132801Sjuliantest_DateGivenMonthDay(void) { 1259078Smdodd // 2010-06-24 12:50:00 1332801Sjulian struct calendar input = {2010, 0, 6, 24, 12, 50, 0}; 1432801Sjulian 1532801Sjulian u_long expected = 3486372600UL; // This is the timestamp above. 1632801Sjulian 1732801Sjulian TEST_ASSERT_EQUAL_UINT(expected, caltontp(&input)); 1832801Sjulian} 1932801Sjulian 2059078Smdoddvoid 2159078Smdoddtest_DateGivenYearDay(void) { 2232801Sjulian // 2010-06-24 12:50:00 2332801Sjulian // This is the 175th day of 2010. 2432801Sjulian struct calendar input = {2010, 175, 0, 0, 12, 50, 0}; 2532801Sjulian 2632801Sjulian u_long expected = 3486372600UL; // This is the timestamp above. 2732801Sjulian 2832801Sjulian TEST_ASSERT_EQUAL_UINT(expected, caltontp(&input)); 2932801Sjulian} 30119418Sobrien 31119418Sobrienvoid 32119418Sobrientest_DateLeapYear(void) { 3332801Sjulian // 2012-06-24 12:00:00 3432801Sjulian // This is the 176th day of 2012 (since 2012 is a leap year). 3532801Sjulian struct calendar inputYd = {2012, 176, 0, 0, 12, 00, 00}; 3659078Smdodd struct calendar inputMd = {2012, 0, 6, 24, 12, 00, 00}; 37117126Sscottl 38117126Sscottl u_long expected = 3549528000UL; 3959078Smdodd 4032801Sjulian TEST_ASSERT_EQUAL_UINT(expected, caltontp(&inputYd)); 4139234Sgibbs TEST_ASSERT_EQUAL_UINT(expected, caltontp(&inputMd)); 4239234Sgibbs} 4339234Sgibbs 4459078Smdoddvoid 4559078Smdoddtest_WraparoundDateIn2036(void) { 4639234Sgibbs // 2036-02-07 06:28:16 47119277Simp // This is (one) wrapping boundary where we go from ULONG_MAX to 0. 48119277Simp struct calendar input = {2036, 0, 2, 7, 6, 28, 16}; 4959078Smdodd 5039234Sgibbs u_long expected = 0UL; 5139234Sgibbs 5239234Sgibbs TEST_ASSERT_EQUAL_UINT(expected, caltontp(&input)); 5332801Sjulian} 5459078Smdodd