tstotv.c revision 1.1.1.6 1 #include "config.h"
2
3 #include "ntp_fp.h"
4 #include "timevalops.h"
5
6 #include "unity.h"
7
8 void test_Seconds(void);
9 void test_MicrosecondsExact(void);
10 void test_MicrosecondsRounding(void);
11
12
13 void
14 test_Seconds(void) {
15 const l_fp input = {{50}, 0}; /* 50.0 s */
16 const struct timeval expected = {50, 0};
17 struct timeval actual;
18
19 TSTOTV(&input, &actual);
20
21 TEST_ASSERT_EQUAL(expected.tv_sec, actual.tv_sec);
22 TEST_ASSERT_EQUAL(expected.tv_usec, actual.tv_usec);
23 }
24
25 void
26 test_MicrosecondsExact(void) {
27 const u_long HALF = 2147483648UL;
28 const l_fp input = {{50}, HALF}; /* 50.5 s */
29 const struct timeval expected = {50, 500000};
30 struct timeval actual;
31
32 TSTOTV(&input, &actual);
33
34 TEST_ASSERT_EQUAL(expected.tv_sec, actual.tv_sec);
35 TEST_ASSERT_EQUAL(expected.tv_usec, actual.tv_usec);
36
37 }
38
39 void
40 test_MicrosecondsRounding(void) {
41 const l_fp input = {{50}, 3865471UL}; /* Should round to 50.0009 */
42 const struct timeval expected = {50, 900};
43 struct timeval actual;
44
45 TSTOTV(&input, &actual);
46
47 TEST_ASSERT_EQUAL(expected.tv_sec, actual.tv_sec);
48 TEST_ASSERT_EQUAL(expected.tv_usec, actual.tv_usec);
49 }
50