]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/g_vi64ops.cpp
Fix a regression with SA-15:24 patch that prevented NIS from
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / g_vi64ops.cpp
1 #include "g_libntptest.h"
2
3 extern "C" {
4 #include "vint64ops.h"
5 }
6
7 class vi64Test : public libntptest {
8 public:
9         ::testing::AssertionResult IsEqual(const vint64 &expected, const vint64 &actual) {
10                 if (0 == memcmp(&expected, &actual, sizeof(vint64))) {
11                         return ::testing::AssertionSuccess();
12                 } else {
13                         return ::testing::AssertionFailure()
14                             << "expected: "
15                             << std::hex << expected.D_s.hi << '.'
16                             << std::hex << expected.D_s.lo
17                             << " but was "
18                             << std::hex << actual.D_s.hi << '.'
19                             << std::hex << actual.D_s.lo;
20                 }
21         }
22 };
23
24 // ----------------------------------------------------------------------
25 // test number parser
26 TEST_F(vi64Test, ParseVUI64_pos) {
27         vint64 act, exp;
28         const char *sp;
29         char       *ep;
30
31         sp         = "1234x";
32         exp.D_s.hi = 0;
33         exp.D_s.lo = 1234;
34         act        = strtouv64(sp, &ep, 0);
35         EXPECT_TRUE(IsEqual(exp, act));
36         EXPECT_EQ(*ep, 'x');
37 }
38
39 TEST_F(vi64Test, ParseVUI64_neg) {
40         vint64 act, exp;
41         const char *sp;
42         char       *ep;
43
44         sp         = "-1234x";
45         exp.D_s.hi = ~0;
46         exp.D_s.lo = -1234;
47         act        = strtouv64(sp, &ep, 0);
48         EXPECT_TRUE(IsEqual(exp, act));
49         EXPECT_EQ(*ep, 'x');
50 }
51
52 TEST_F(vi64Test, ParseVUI64_case) {
53         vint64 act, exp;
54         const char *sp;
55         char       *ep;
56
57         sp         = "0123456789AbCdEf";
58         exp.D_s.hi = 0x01234567;
59         exp.D_s.lo = 0x89ABCDEF;
60         act        = strtouv64(sp, &ep, 16);
61         EXPECT_TRUE(IsEqual(exp, act));
62         EXPECT_EQ(*ep, '\0');
63 }
64