]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/hextolfp.c
Upgrade NTP to 4.2.8p4.
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / hextolfp.c
1 #include "config.h"
2
3 #include "ntp_stdlib.h"
4 #include "ntp_calendar.h"
5
6 #include "unity.h"
7 #include "lfptest.h"
8
9 void test_PositiveInteger(void);
10 void test_NegativeInteger(void);
11 void test_PositiveFraction(void);
12 void test_NegativeFraction(void);
13 void test_IllegalNumberOfInteger(void);
14 void test_IllegalChar(void);
15
16
17 void
18 test_PositiveInteger(void) {
19         const char *str = "00001000.00000000";
20         l_fp actual;
21
22         l_fp expected = {{4096}, 0}; /* 16^3, no fraction part. */
23
24         TEST_ASSERT_TRUE(hextolfp(str, &actual));
25         TEST_ASSERT_TRUE(IsEqual(expected, actual));
26 }
27
28 void
29 test_NegativeInteger(void) {
30         const char *str = "ffffffff.00000000"; /* -1 decimal */
31         l_fp actual;
32
33         l_fp expected = {{-1}, 0};
34
35         TEST_ASSERT_TRUE(hextolfp(str, &actual));
36         TEST_ASSERT_TRUE(IsEqual(expected, actual));
37 }
38
39 void
40 test_PositiveFraction(void) {
41         const char *str = "00002000.80000000"; /* 8196.5 decimal */
42         l_fp actual;
43
44         l_fp expected = {{8192}, HALF};
45
46         TEST_ASSERT_TRUE(hextolfp(str, &actual));
47         TEST_ASSERT_TRUE(IsEqual(expected, actual));
48 }
49
50 void
51 test_NegativeFraction(void) {
52         const char *str = "ffffffff.40000000"; /* -1 + 0.25 decimal */
53         l_fp actual;
54
55         l_fp expected = {{-1}, QUARTER}; /* -1 + 0.25 */
56
57         TEST_ASSERT_TRUE(hextolfp(str, &actual));
58         TEST_ASSERT_TRUE(IsEqual(expected, actual));
59 }
60
61 void
62 test_IllegalNumberOfInteger(void) {
63         const char *str = "1000000.00000000"; /* Missing one digit in integral part. */
64         l_fp actual;
65
66         TEST_ASSERT_FALSE(hextolfp(str, &actual));
67 }
68
69 void
70 test_IllegalChar(void) {
71         const char *str = "10000000.0000h000"; /* Illegal character h. */
72         l_fp actual;
73
74         TEST_ASSERT_FALSE(hextolfp(str, &actual));
75 }