2015-07-01 03:12:13 +00:00
|
|
|
#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)
|
2015-07-01 03:12:13 +00:00
|
|
|
{
|
|
|
|
time_t sample = 1276601278;
|
|
|
|
char expected[15];
|
2015-10-21 19:16:13 +00:00
|
|
|
struct tm* tm;
|
2015-07-01 03:12:13 +00:00
|
|
|
|
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-07-01 03:12:13 +00:00
|
|
|
|
2015-10-21 19:16:13 +00:00
|
|
|
snprintf(expected, 15, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
|
2015-07-01 03:12:13 +00:00
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL_STRING(expected, humantime(sample));
|
2016-01-08 08:06:14 +00:00
|
|
|
|
|
|
|
return;
|
2015-07-01 03:12:13 +00:00
|
|
|
}
|
|
|
|
|
2015-10-21 19:16:13 +00:00
|
|
|
void
|
|
|
|
test_CurrentTime(void)
|
2015-07-01 03:12:13 +00:00
|
|
|
{
|
|
|
|
time_t sample;
|
|
|
|
char expected[15];
|
2015-10-21 19:16:13 +00:00
|
|
|
struct tm* tm;
|
2015-07-01 03:12:13 +00:00
|
|
|
|
|
|
|
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-07-01 03:12:13 +00:00
|
|
|
|
2015-10-21 19:16:13 +00:00
|
|
|
snprintf(expected, 15, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
|
2015-07-01 03:12:13 +00:00
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL_STRING(expected, humantime(sample));
|
2016-01-08 08:06:14 +00:00
|
|
|
|
|
|
|
return;
|
2015-07-01 03:12:13 +00:00
|
|
|
}
|