1290001Sglebius#include "config.h" 2290001Sglebius 3290001Sglebius#include "ntp_stdlib.h" 4290001Sglebius#include "ntp_calendar.h" 5290001Sglebius#include "unity.h" 6290001Sglebius 7290001Sglebius#include "test-libntp.h" 8290001Sglebius 9290001Sglebiusvoid setUp(void); 10290001Sglebiusvoid tearDown(void); 11290001Sglebiusvoid test_NoWrapInDateRange(void); 12290001Sglebiusvoid test_NoWrapInDateRangeLeapYear(void); 13290001Sglebiusvoid test_WrapInDateRange(void); 14290001Sglebius 15290001Sglebiusvoid setUp(void) 16290001Sglebius{ 17290001Sglebius ntpcal_set_timefunc(timefunc); 18290001Sglebius settime(1970, 1, 1, 0, 0, 0); 19290001Sglebius} 20290001Sglebius 21290001Sglebiusvoid tearDown(void) 22290001Sglebius{ 23290001Sglebius ntpcal_set_timefunc(NULL); 24290001Sglebius} 25290001Sglebius 26290001Sglebius 27290001Sglebiusvoid test_NoWrapInDateRange(void) { 28290001Sglebius const u_int32 input = 3486372600UL; // 2010-06-24 12:50:00. 29290001Sglebius const u_int32 expected = 3471292800UL; // 2010-01-01 00:00:00 30290001Sglebius 31290001Sglebius TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime)); 32290001Sglebius TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL)); 33290001Sglebius} 34290001Sglebius 35290001Sglebiusvoid test_NoWrapInDateRangeLeapYear(void) { 36290001Sglebius const u_int32 input = 3549528000UL; // 2012-06-24 12:00:00 37290001Sglebius const u_int32 expected = 3534364800UL; // 2012-01-01 00:00:00 38290001Sglebius 39290001Sglebius TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime)); 40290001Sglebius TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL)); 41290001Sglebius} 42290001Sglebius 43290001Sglebiusvoid test_WrapInDateRange(void) { 44290001Sglebius const u_int32 input = 19904UL; // 2036-02-07 12:00:00 45290001Sglebius const u_int32 expected = 4291747200UL; // 2036-01-01 00:00:00 46290001Sglebius 47290001Sglebius TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime)); 48290001Sglebius TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL)); 49290001Sglebius} 50