]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/g_hextolfp.cpp
Fix a regression with SA-15:24 patch that prevented NIS from
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / g_hextolfp.cpp
1 #include "g_lfptest.h"
2
3 class hextolfpTest : public lfptest {
4 };
5
6 TEST_F(hextolfpTest, PositiveInteger) {
7         const char *str = "00001000.00000000";
8         l_fp actual;
9
10         l_fp expected = {4096, 0}; // 16^3, no fraction part.
11
12         ASSERT_TRUE(hextolfp(str, &actual));
13         EXPECT_TRUE(IsEqual(expected, actual));
14 }
15
16 TEST_F(hextolfpTest, NegativeInteger) {
17         const char *str = "ffffffff.00000000"; // -1 decimal
18         l_fp actual;
19
20         l_fp expected = {-1, 0};
21
22         ASSERT_TRUE(hextolfp(str, &actual));
23         EXPECT_TRUE(IsEqual(expected, actual));
24 }
25
26 TEST_F(hextolfpTest, PositiveFraction) {
27         const char *str = "00002000.80000000"; // 8196.5 decimal
28         l_fp actual;
29
30         l_fp expected = {8192, HALF};
31
32         ASSERT_TRUE(hextolfp(str, &actual));
33         EXPECT_TRUE(IsEqual(expected, actual));
34 }
35
36 TEST_F(hextolfpTest, NegativeFraction) {
37         const char *str = "ffffffff.40000000"; // -1 + 0.25 decimal
38         l_fp actual;
39
40         l_fp expected = {-1, QUARTER}; //-1 + 0.25
41
42         ASSERT_TRUE(hextolfp(str, &actual));
43         EXPECT_TRUE(IsEqual(expected, actual));
44 }
45
46 TEST_F(hextolfpTest, IllegalNumberOfInteger) {
47         const char *str = "1000000.00000000"; // Missing one digit in integral part.
48         l_fp actual;
49
50         ASSERT_FALSE(hextolfp(str, &actual));
51 }
52
53 TEST_F(hextolfpTest, IllegalChar) {
54         const char *str = "10000000.0000h000"; // Illegal character h.
55         l_fp actual;
56
57         ASSERT_FALSE(hextolfp(str, &actual));
58 }