xref: /netbsd-src/external/bsd/ntp/dist/tests/libntp/humandate.c (revision cdfa2a7ef92791ba9db70a584a1d904730e6fb46)
1 /*	$NetBSD: humandate.c,v 1.2 2020/05/25 20:47:36 christos Exp $	*/
2 
3 #include "config.h"
4 
5 #include "ntp_calendar.h"
6 #include "ntp_stdlib.h"
7 
8 #include "unity.h"
9 
10 void setUp(void);
11 void test_RegularTime(void);
12 void test_CurrentTime(void);
13 
14 
15 void
setUp(void)16 setUp(void)
17 {
18 	init_lib();
19 
20 	return;
21 }
22 
23 
24 void
test_RegularTime(void)25 test_RegularTime(void)
26 {
27 	time_t sample = 1276601278;
28 	char expected[15];
29 	struct tm* tm;
30 
31 	tm = localtime(&sample);
32 	TEST_ASSERT_TRUE(tm != NULL);
33 
34 	snprintf(expected, 15, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
35 
36 	TEST_ASSERT_EQUAL_STRING(expected, humantime(sample));
37 
38 	return;
39 }
40 
41 void
test_CurrentTime(void)42 test_CurrentTime(void)
43 {
44 	time_t sample;
45 	char expected[15];
46 	struct tm* tm;
47 
48 	time(&sample);
49 
50 	tm = localtime(&sample);
51 	TEST_ASSERT_TRUE(tm != NULL);
52 
53 	snprintf(expected, 15, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
54 
55 	TEST_ASSERT_EQUAL_STRING(expected, humantime(sample));
56 
57 	return;
58 }
59