1284990Scy#include "config.h" 2284990Scy 3284990Scy#include "ntp_stdlib.h" 4289999Sglebius#include "vint64ops.h" 5284990Scy 6284990Scy#include "unity.h" 7284990Scy 8284990Scy 9289999Sglebiusint IsEqual(const vint64 expected, const vint64 actual); 10289999Sglebiusvoid test_ParseVUI64_pos(void); 11289999Sglebiusvoid test_ParseVUI64_neg(void); 12289999Sglebiusvoid test_ParseVUI64_case(void); 13289999Sglebius 14289999Sglebius 15289999Sglebius// technically bool 16289999Sglebiusint 17289999SglebiusIsEqual(const vint64 expected, const vint64 actual) { 18284990Scy if (0 == memcmp(&expected, &actual, sizeof(vint64))) { 19289999Sglebius printf( "%x.", expected.D_s.hi); 20289999Sglebius printf("%x", expected.D_s.lo); 21284990Scy printf(" but was "); 22289999Sglebius printf("%x.", actual.D_s.hi); 23289999Sglebius printf("%x\n", actual.D_s.lo); 24284990Scy return TRUE; 25284990Scy } else { 26284990Scy printf("expected: "); 27289999Sglebius printf( "%d.", expected.D_s.hi); 28289999Sglebius printf("%d", expected.D_s.lo); 29284990Scy printf(" but was "); 30289999Sglebius printf("%d", actual.D_s.lo); 31289999Sglebius printf("%d", actual.D_s.lo); 32284990Scy return FALSE; 33284990Scy } 34284990Scy} 35284990Scy 36284990Scy// ---------------------------------------------------------------------- 37284990Scy// test number parser 38289999Sglebiusvoid 39289999Sglebiustest_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 53289999Sglebius 54289999Sglebiusvoid 55289999Sglebiustest_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 68289999Sglebiusvoid 69289999Sglebiustest_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