1284990Scy#include "config.h"
2284990Scy
3284990Scy#include "ntp_stdlib.h"
4290000Sglebius#include "vint64ops.h"
5284990Scy
6284990Scy#include "unity.h"
7284990Scy
8284990Scy
9290000Sglebiusint IsEqual(const vint64 expected, const vint64 actual);
10290000Sglebiusvoid test_ParseVUI64_pos(void);
11290000Sglebiusvoid test_ParseVUI64_neg(void);
12290000Sglebiusvoid test_ParseVUI64_case(void);
13290000Sglebius
14290000Sglebius
15290000Sglebius// technically bool
16290000Sglebiusint
17290000SglebiusIsEqual(const vint64 expected, const vint64 actual) {
18284990Scy	if (0 == memcmp(&expected, &actual, sizeof(vint64))) {
19290000Sglebius		printf( "%x.", expected.D_s.hi);
20290000Sglebius		printf("%x", expected.D_s.lo);
21284990Scy		printf(" but was ");
22290000Sglebius		printf("%x.", actual.D_s.hi);
23290000Sglebius		printf("%x\n", actual.D_s.lo);
24284990Scy		return TRUE;
25284990Scy	} else {
26284990Scy		printf("expected: ");
27290000Sglebius		printf( "%d.", expected.D_s.hi);
28290000Sglebius		printf("%d", expected.D_s.lo);
29284990Scy		printf(" but was ");
30290000Sglebius		printf("%d", actual.D_s.lo);
31290000Sglebius		printf("%d", actual.D_s.lo);
32284990Scy		return FALSE;
33284990Scy	}
34284990Scy}
35284990Scy
36284990Scy// ----------------------------------------------------------------------
37284990Scy// test number parser
38290000Sglebiusvoid
39290000Sglebiustest_ParseVUI64_pos(void) {
40284990Scy	vint64 act, exp;
41284990Scy	const char *sp;
42284990Scy	char       *ep;
43284990Scy
44284990Scy	sp         = "1234x";
45284990Scy	exp.D_s.hi = 0;
46284990Scy	exp.D_s.lo = 1234;
47284990Scy	act        = strtouv64(sp, &ep, 0);
48284990Scy
49284990Scy	TEST_ASSERT_TRUE(IsEqual(exp, act));
50284990Scy	TEST_ASSERT_EQUAL(*ep, 'x');
51284990Scy}
52284990Scy
53290000Sglebius
54290000Sglebiusvoid
55290000Sglebiustest_ParseVUI64_neg(void) {
56284990Scy	vint64 act, exp;
57284990Scy	const char *sp;
58284990Scy	char       *ep;
59284990Scy
60284990Scy	sp         = "-1234x";
61284990Scy	exp.D_s.hi = ~0;
62284990Scy	exp.D_s.lo = -1234;
63284990Scy	act        = strtouv64(sp, &ep, 0);
64284990Scy	TEST_ASSERT_TRUE(IsEqual(exp, act));
65284990Scy	TEST_ASSERT_EQUAL(*ep, 'x');
66284990Scy}
67284990Scy
68290000Sglebiusvoid
69290000Sglebiustest_ParseVUI64_case(void) {
70284990Scy	vint64 act, exp;
71284990Scy	const char *sp;
72284990Scy	char       *ep;
73284990Scy
74284990Scy	sp         = "0123456789AbCdEf";
75284990Scy	exp.D_s.hi = 0x01234567;
76284990Scy	exp.D_s.lo = 0x89ABCDEF;
77284990Scy	act        = strtouv64(sp, &ep, 16);
78284990Scy	TEST_ASSERT_TRUE(IsEqual(exp, act));
79284990Scy	TEST_ASSERT_EQUAL(*ep, '\0');
80284990Scy}
81