]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/tstotv.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / tstotv.c
1 #include "config.h"
2
3 #include "ntp_fp.h"
4 #include "timevalops.h"
5
6 #include "unity.h"
7
8 void
9 test_Seconds(void) {
10         const l_fp input = {50, 0}; // 50.0 s
11         const struct timeval expected = {50, 0};
12         struct timeval actual;
13
14         TSTOTV(&input, &actual);
15
16         TEST_ASSERT_EQUAL(expected.tv_sec, actual.tv_sec);
17         TEST_ASSERT_EQUAL(expected.tv_usec, actual.tv_usec);
18 }
19
20 void
21 test_MicrosecondsExact(void) {
22         const u_long HALF = 2147483648UL;
23         const l_fp input = {50, HALF}; // 50.5 s
24         const struct timeval expected = {50, 500000};
25         struct timeval actual;
26
27         TSTOTV(&input, &actual);
28
29         TEST_ASSERT_EQUAL(expected.tv_sec, actual.tv_sec);
30         TEST_ASSERT_EQUAL(expected.tv_usec, actual.tv_usec);
31
32 }
33
34 void
35 test_MicrosecondsRounding(void) {
36         const l_fp input = {50, 3865471UL}; // Should round to 50.0009
37         const struct timeval expected = {50, 900};
38         struct timeval actual;
39
40         TSTOTV(&input, &actual);
41
42         TEST_ASSERT_EQUAL(expected.tv_sec, actual.tv_sec);
43         TEST_ASSERT_EQUAL(expected.tv_usec, actual.tv_usec);
44 }