freebsd-dev/contrib/ntp/tests/libntp/humandate.c

57 lines
827 B
C
Raw Normal View History

#include "config.h"
#include "ntp_calendar.h"
#include "ntp_stdlib.h"
#include "unity.h"
2016-01-08 08:06:14 +00:00
void setUp(void);
2015-10-21 19:16:13 +00:00
void test_RegularTime(void);
void test_CurrentTime(void);
2016-01-08 08:06:14 +00:00
void
setUp(void)
{
init_lib();
return;
}
2015-10-21 19:16:13 +00:00
void
test_RegularTime(void)
{
time_t sample = 1276601278;
char expected[15];
2015-10-21 19:16:13 +00:00
struct tm* tm;
2015-10-21 19:16:13 +00:00
tm = localtime(&sample);
2016-01-08 08:06:14 +00:00
TEST_ASSERT_TRUE(tm != NULL);
2015-10-21 19:16:13 +00:00
snprintf(expected, 15, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
TEST_ASSERT_EQUAL_STRING(expected, humantime(sample));
2016-01-08 08:06:14 +00:00
return;
}
2015-10-21 19:16:13 +00:00
void
test_CurrentTime(void)
{
time_t sample;
char expected[15];
2015-10-21 19:16:13 +00:00
struct tm* tm;
time(&sample);
2015-10-21 19:16:13 +00:00
tm = localtime(&sample);
2016-01-08 08:06:14 +00:00
TEST_ASSERT_TRUE(tm != NULL);
2015-10-21 19:16:13 +00:00
snprintf(expected, 15, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
TEST_ASSERT_EQUAL_STRING(expected, humantime(sample));
2016-01-08 08:06:14 +00:00
return;
}