]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/vi64ops.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / vi64ops.c
1 #include "config.h"
2
3 #include "ntp_stdlib.h"
4
5 #include "unity.h"
6
7 #include "vint64ops.h"
8
9 //technically bool
10 //int IsEqual(const vint64 &expected, const vint64 &actual) {
11 int IsEqual(const vint64 expected, const vint64 actual) {
12         if (0 == memcmp(&expected, &actual, sizeof(vint64))) {
13                 printf( "%x.", expected.D_s.hi); //<< std::hex << expected.D_s.hi << '.'
14                 printf("%x",expected.D_s.lo);//<< std::hex << expected.D_s.lo
15                 printf(" but was ");
16                 printf("%x.",actual.D_s.hi); //<< std::hex << actual.D_s.hi << '.'
17                 printf("%x\n",actual.D_s.lo); //<< std::hex << actual.D_s.lo;
18                 return TRUE;
19         } else {
20                 
21                 printf("expected: ");
22                 printf( "%d.", expected.D_s.hi); //<< std::hex << expected.D_s.hi << '.'
23                 printf("%d",expected.D_s.lo);//<< std::hex << expected.D_s.lo
24                 printf(" but was ");
25                 printf("%d",actual.D_s.lo); //<< std::hex << actual.D_s.hi << '.'
26                 printf("%d",actual.D_s.lo); //<< std::hex << actual.D_s.lo;
27                 return FALSE;
28         }
29 }
30
31 // ----------------------------------------------------------------------
32 // test number parser
33 void test_ParseVUI64_pos() {
34         vint64 act, exp;
35         const char *sp;
36         char       *ep;
37
38         sp         = "1234x";
39         exp.D_s.hi = 0;
40         exp.D_s.lo = 1234;
41         act        = strtouv64(sp, &ep, 0);
42
43         TEST_ASSERT_TRUE(IsEqual(exp, act));
44         TEST_ASSERT_EQUAL(*ep, 'x');
45 }
46
47 void test_ParseVUI64_neg() {
48         vint64 act, exp;
49         const char *sp;
50         char       *ep;
51
52         sp         = "-1234x";
53         exp.D_s.hi = ~0;
54         exp.D_s.lo = -1234;
55         act        = strtouv64(sp, &ep, 0);
56         TEST_ASSERT_TRUE(IsEqual(exp, act));
57         TEST_ASSERT_EQUAL(*ep, 'x');
58 }
59
60 void test_ParseVUI64_case() {
61         vint64 act, exp;
62         const char *sp;
63         char       *ep;
64
65         sp         = "0123456789AbCdEf";
66         exp.D_s.hi = 0x01234567;
67         exp.D_s.lo = 0x89ABCDEF;
68         act        = strtouv64(sp, &ep, 16);
69         TEST_ASSERT_TRUE(IsEqual(exp, act));
70         TEST_ASSERT_EQUAL(*ep, '\0');
71 }
72