diff options
Diffstat (limited to 'contrib/ntp/tests/libntp/caljulian.c')
-rw-r--r-- | contrib/ntp/tests/libntp/caljulian.c | 65 |
1 files changed, 45 insertions, 20 deletions
diff --git a/contrib/ntp/tests/libntp/caljulian.c b/contrib/ntp/tests/libntp/caljulian.c index ecf5d9255..b25f8ac 100644 --- a/contrib/ntp/tests/libntp/caljulian.c +++ b/contrib/ntp/tests/libntp/caljulian.c @@ -20,10 +20,12 @@ void test_uLongWrapped(void); char * -CalendarToString(const struct calendar cal) { +CalendarToString(const struct calendar cal) +{ char * str = emalloc (sizeof (char) * 100); - char buffer[100] =""; + + *str = '\0'; snprintf(buffer, 100, "%u", cal.year); strcat(str, buffer); strcat(str, "-"); @@ -48,19 +50,25 @@ CalendarToString(const struct calendar cal) { } int // technically boolean -IsEqual(const struct calendar expected, const struct calendar actual) { - if (expected.year == actual.year && - (expected.yearday == actual.yearday || - (expected.month == actual.month && - expected.monthday == actual.monthday)) && - expected.hour == actual.hour && - expected.minute == actual.minute && - expected.second == actual.second) { +IsEqual(const struct calendar expected, const struct calendar actual) +{ + if ( expected.year == actual.year + && ( expected.yearday == actual.yearday + || ( expected.month == actual.month + && expected.monthday == actual.monthday)) + && expected.hour == actual.hour + && expected.minute == actual.minute + && expected.second == actual.second) { return TRUE; } else { - printf("expected: %s but was %s", CalendarToString(expected) ,CalendarToString(actual)); + char *p_exp, *p_act; + + p_exp = CalendarToString(expected); + p_act = CalendarToString(actual); + printf("expected: %s but was %s", p_exp, p_act); + free(p_exp); + free(p_act); return FALSE; - } } @@ -70,17 +78,23 @@ setUp() { ntpcal_set_timefunc(timefunc); settime(1970, 1, 1, 0, 0, 0); + init_lib(); + + return; } void tearDown() { ntpcal_set_timefunc(NULL); + + return; } void -test_RegularTime(void) { +test_RegularTime(void) +{ u_long testDate = 3485080800UL; // 2010-06-09 14:00:00 struct calendar expected = {2010,160,6,9,14,0,0}; @@ -89,10 +103,13 @@ test_RegularTime(void) { caljulian(testDate, &actual); TEST_ASSERT_TRUE(IsEqual(expected, actual)); + + return; } void -test_LeapYear(void) { +test_LeapYear(void) +{ u_long input = 3549902400UL; // 2012-06-28 20:00:00Z struct calendar expected = {2012, 179, 6, 28, 20, 0, 0}; @@ -101,28 +118,36 @@ test_LeapYear(void) { caljulian(input, &actual); TEST_ASSERT_TRUE(IsEqual(expected, actual)); + + return; } void -test_uLongBoundary(void) { - u_long time = 4294967295UL; // 2036-02-07 6:28:15 +test_uLongBoundary(void) +{ + u_long enc_time = 4294967295UL; // 2036-02-07 6:28:15 struct calendar expected = {2036,0,2,7,6,28,15}; struct calendar actual; - caljulian(time, &actual); + caljulian(enc_time, &actual); TEST_ASSERT_TRUE(IsEqual(expected, actual)); + + return; } void -test_uLongWrapped(void) { - u_long time = 0; +test_uLongWrapped(void) +{ + u_long enc_time = 0; struct calendar expected = {2036,0,2,7,6,28,16}; struct calendar actual; - caljulian(time, &actual); + caljulian(enc_time, &actual); TEST_ASSERT_TRUE(IsEqual(expected, actual)); + + return; } |