diff options
Diffstat (limited to 'contrib/ntp/tests/libntp/caljulian.c')
-rw-r--r-- | contrib/ntp/tests/libntp/caljulian.c | 86 |
1 files changed, 49 insertions, 37 deletions
diff --git a/contrib/ntp/tests/libntp/caljulian.c b/contrib/ntp/tests/libntp/caljulian.c index 907f25d..ecf5d9255 100644 --- a/contrib/ntp/tests/libntp/caljulian.c +++ b/contrib/ntp/tests/libntp/caljulian.c @@ -2,46 +2,53 @@ #include "ntp_calendar.h" #include "ntp_stdlib.h" -#include "unity.h" +#include "unity.h" #include "test-libntp.h" - #include <string.h> -//#include <stdlib.h> -//added struct to calendar! -char * CalendarToString(const struct calendar cal) { - char * ss = malloc (sizeof (char) * 100); +char * CalendarToString(const struct calendar cal); +int IsEqual(const struct calendar expected, const struct calendar actual); +void setUp(void); +void tearDown(void); +void test_RegularTime(void); +void test_LeapYear(void); +void test_uLongBoundary(void); +void test_uLongWrapped(void); + + +char * +CalendarToString(const struct calendar cal) { + char * str = emalloc (sizeof (char) * 100); char buffer[100] =""; - sprintf(buffer, "%u", cal.year); - strcat(ss,buffer); - strcat(ss,"-"); - sprintf(buffer, "%u", (u_int)cal.month); - strcat(ss,buffer); - strcat(ss,"-"); - sprintf(buffer, "%u", (u_int)cal.monthday); - strcat(ss,buffer); - strcat(ss," ("); - sprintf(buffer, "%u", (u_int) cal.yearday); - strcat(ss,buffer); - strcat(ss,") "); - sprintf(buffer, "%u", (u_int)cal.hour); - strcat(ss,buffer); - strcat(ss,":"); - sprintf(buffer, "%u", (u_int)cal.minute); - strcat(ss,buffer); - strcat(ss,":"); - sprintf(buffer, "%u", (u_int)cal.second); - strcat(ss,buffer); - //ss << cal.year << "-" << (u_int)cal.month << "-" << (u_int)cal.monthday << " (" << cal.yearday << ") " << (u_int)cal.hour << ":" << (u_int)cal.minute << ":" << (u_int)cal.second; - return ss; + snprintf(buffer, 100, "%u", cal.year); + strcat(str, buffer); + strcat(str, "-"); + snprintf(buffer, 100, "%u", (u_int)cal.month); + strcat(str, buffer); + strcat(str, "-"); + snprintf(buffer, 100, "%u", (u_int)cal.monthday); + strcat(str, buffer); + strcat(str, " ("); + snprintf(buffer, 100, "%u", (u_int) cal.yearday); + strcat(str, buffer); + strcat(str, ") "); + snprintf(buffer, 100, "%u", (u_int)cal.hour); + strcat(str, buffer); + strcat(str, ":"); + snprintf(buffer, 100, "%u", (u_int)cal.minute); + strcat(str, buffer); + strcat(str, ":"); + snprintf(buffer, 100, "%u", (u_int)cal.second); + strcat(str, buffer); + return str; } -//tehnically boolean -int IsEqual(const struct calendar expected, const struct calendar actual) { +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 && @@ -58,20 +65,22 @@ int IsEqual(const struct calendar expected, const struct calendar actual) { } -void setUp() +void +setUp() { - ntpcal_set_timefunc(timefunc); settime(1970, 1, 1, 0, 0, 0); } -void tearDown() +void +tearDown() { ntpcal_set_timefunc(NULL); } -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}; @@ -82,7 +91,8 @@ void test_RegularTime() { TEST_ASSERT_TRUE(IsEqual(expected, actual)); } -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}; @@ -93,7 +103,8 @@ void test_LeapYear() { TEST_ASSERT_TRUE(IsEqual(expected, actual)); } -void test_uLongBoundary() { +void +test_uLongBoundary(void) { u_long time = 4294967295UL; // 2036-02-07 6:28:15 struct calendar expected = {2036,0,2,7,6,28,15}; @@ -104,7 +115,8 @@ void test_uLongBoundary() { TEST_ASSERT_TRUE(IsEqual(expected, actual)); } -void test_uLongWrapped() { +void +test_uLongWrapped(void) { u_long time = 0; struct calendar expected = {2036,0,2,7,6,28,16}; |