1/* $NetBSD: calyearstart.c,v 1.2 2020/05/25 20:47:36 christos Exp $ */ 2 3#include "config.h" 4 5#include "ntp_stdlib.h" 6#include "ntp_calendar.h" 7#include "unity.h" 8 9#include "test-libntp.h" 10 11void setUp(void); 12void tearDown(void); 13void test_NoWrapInDateRange(void); 14void test_NoWrapInDateRangeLeapYear(void); 15void test_WrapInDateRange(void); 16 17void setUp(void) 18{ 19 ntpcal_set_timefunc(timefunc); 20 settime(1970, 1, 1, 0, 0, 0); 21} 22 23void tearDown(void) 24{ 25 ntpcal_set_timefunc(NULL); 26} 27 28 29void test_NoWrapInDateRange(void) { 30 const u_int32 input = 3486372600UL; // 2010-06-24 12:50:00. 31 const u_int32 expected = 3471292800UL; // 2010-01-01 00:00:00 32 33 TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime)); 34 TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL)); 35} 36 37void test_NoWrapInDateRangeLeapYear(void) { 38 const u_int32 input = 3549528000UL; // 2012-06-24 12:00:00 39 const u_int32 expected = 3534364800UL; // 2012-01-01 00:00:00 40 41 TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime)); 42 TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL)); 43} 44 45void test_WrapInDateRange(void) { 46 const u_int32 input = 19904UL; // 2036-02-07 12:00:00 47 const u_int32 expected = 4291747200UL; // 2036-01-01 00:00:00 48 49 TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime)); 50 TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL)); 51} 52