52 #define TOHOSTTEST(TYPE,STR,EXP,FN) \
54 testFramework.changeSourceMethod(#FN); \
56 gnsstk::BinUtils::FN(STR,val); \
57 TUASSERTE(TYPE,EXP,val); \
59 #define TOHOSTTESTPOS(TYPE,STR,EXP,FN,POS) \
61 testFramework.changeSourceMethod(#FN); \
63 gnsstk::BinUtils::FN(STR,val,POS); \
64 TUASSERTE(TYPE,EXP,val); \
66 #define TOHOSTTESTF(TYPE,STR,EXP,FN) \
68 testFramework.changeSourceMethod(#FN); \
70 gnsstk::BinUtils::FN(STR,val); \
71 TUASSERTFE(EXP,val); \
73 #define TOHOSTTESTFPOS(TYPE,STR,EXP,FN,POS) \
75 testFramework.changeSourceMethod(#FN); \
77 gnsstk::BinUtils::FN(STR,val,POS); \
78 TUASSERTFE(EXP,val); \
81 #define HOSTTOTEST(TYPE,STR,VAL,FN) \
82 testFramework.changeSourceMethod(#FN); \
83 gnsstk::BinUtils::FN(buffer,VAL); \
84 TUASSERTE(int,0,memcmp(buffer,STR,sizeof(TYPE)));
85 #define HOSTTOTESTPOS(TYPE,STR,VAL,FN,POS) \
86 testFramework.changeSourceMethod(#FN); \
87 gnsstk::BinUtils::FN(buffer,VAL,POS); \
88 TUASSERTE(int,0,memcmp(&buffer[POS],STR,sizeof(TYPE)));
96 TUDEF(
"BinUtils",
"buitoh*");
114 uint32_t fbits = 0x0100807f;
115 float *fptr = (
float*)&fbits;
118 uint64_t dbits = 0x3d859d6aa891f37f;
119 double *dptr = (
double*)&dbits;
135 return testFramework.countFails();
141 TUDEF(
"BinUtils",
"buntoh*");
159 uint32_t fbits = 0x0100807f;
160 float *fptr = (
float*)&fbits;
163 uint64_t dbits = 0x3d859d6aa891f37f;
164 double *dptr = (
double*)&dbits;
180 return testFramework.countFails();
186 TUDEF(
"BinUtils",
"buhtoi*");
197 uint32_t fbits = 0x0100807f;
198 float *fptr = (
float*)&fbits;
200 uint64_t dbits = 0x3d859d6aa891f37f;
201 double *dptr = (
double*)&dbits;
217 return testFramework.countFails();
223 TUDEF(
"BinUtils",
"buhton*");
234 uint32_t fbits = 0x0100807f;
235 float *fptr = (
float*)&fbits;
237 uint64_t dbits = 0x3d859d6aa891f37f;
238 double *dptr = (
double*)&dbits;
254 return testFramework.countFails();
267 TUDEF(
"BinUtils",
"decodeVar");
271 std::string stringTest =
"Random";
273 gnsstk::BinUtils::decodeVar<char>(stringTest);
274 TUASSERTE(std::string,
"andom",stringTest);
276 std::string stringTest0 =
"Random";
277 char out0 = gnsstk::BinUtils::decodeVar<char>(stringTest0, 0);
282 uint64_t dbits = 0x3d859d6aa891f37f;
283 double *dptr = (
double*)&dbits;
284 static const unsigned char test4Arr[] = { 0x3d, 0x85, 0x9d, 0x6a,
285 0xa8, 0x91, 0xf3, 0x7f };
286 std::string encBE((
char*)test4Arr,
sizeof(test4Arr));
287 TUASSERTFE(*dptr,gnsstk::BinUtils::decodeVar<double>(encBE));
300 std::string stringTest1 =
"I am 5000.";
301 uint32_t out1 = gnsstk::BinUtils::decodeVar<uint32_t>(stringTest1, 5);
304 std::string stringTest2 =
"The word 'this' should be read";
305 float out2 = gnsstk::BinUtils::decodeVar<float>(stringTest2, 10);
306 uint32_t bytes = 0x74686973;
307 float fexpected = *(
float*)&bytes;
310 return testFramework.countFails();
316 TUDEF(
"BinUtils",
"decodeVarLE");
320 std::string stringTest =
"Random";
322 gnsstk::BinUtils::decodeVarLE<char>(stringTest);
323 TUASSERTE(std::string,
"andom",stringTest);
325 std::string stringTest0 =
"Random";
326 char out0 = gnsstk::BinUtils::decodeVarLE<char>(stringTest0, 0);
331 uint64_t dbits = 0x3d859d6aa891f37f;
332 double *dptr = (
double*)&dbits;
333 static const unsigned char test4Arr[] = { 0x7f, 0xf3, 0x91, 0xa8,
334 0x6a, 0x9d, 0x85, 0x3d };
335 std::string encLE((
char*)test4Arr,
sizeof(test4Arr));
336 TUASSERTFE(*dptr,gnsstk::BinUtils::decodeVarLE<double>(encLE));
349 std::string stringTest1 =
"I am 5012.";
350 uint32_t out1 = gnsstk::BinUtils::decodeVarLE<uint32_t>(stringTest1, 5);
353 std::string stringTest2 =
"The word 'this' should be read";
354 float out2 = gnsstk::BinUtils::decodeVarLE<float>(stringTest2, 10);
355 uint32_t bytes = 0x73696874;
356 float fexpected = *(
float*)&bytes;
359 return testFramework.countFails();
372 TUDEF(
"BinUtils",
"encodeVar");
375 std::string stringTest1 = gnsstk::BinUtils::encodeVar<char>(test1);
378 uint32_t test2 = 0x41424344;
379 std::string stringTest2 = gnsstk::BinUtils::encodeVar<uint32_t>(test2);
380 TUASSERTE(std::string,
"ABCD",stringTest2);
384 float test3 = 0x4D336C316F;
385 std::string stringTest3 = gnsstk::BinUtils::encodeVar<float>(test3);
386 TUASSERTE(std::string,
"\x52\x9A\x66\xD8",stringTest3);
389 static const double test4 = 2.4573306210644260e-12;
392 static const unsigned char test4Arr[] = { 0x3d, 0x85, 0x9d, 0x6a,
393 0xa8, 0x91, 0xf3, 0x7f };
394 static const std::string test4Str((
char*)test4Arr,
sizeof(test4Arr));
395 std::string encBE(gnsstk::BinUtils::encodeVar<double>(test4));
398 return testFramework.countFails();
404 TUDEF(
"BinUtils",
"encodeVarLE");
407 std::string stringTest1 = gnsstk::BinUtils::encodeVarLE<char>(test1);
410 uint32_t test2 = 0x41424344;
411 std::string stringTest2 = gnsstk::BinUtils::encodeVarLE<uint32_t>(test2);
412 TUASSERTE(std::string,
"DCBA",stringTest2);
416 float test3 = 0x4D336C316F;
417 std::string stringTest3 = gnsstk::BinUtils::encodeVarLE<float>(test3);
418 TUASSERTE(std::string,
"\xD8\x66\x9A\x52",stringTest3);
421 static const double test4 = 2.4573306210644260e-12;
424 static const unsigned char test4Arr[] = { 0x7f, 0xf3, 0x91, 0xa8,
425 0x6a, 0x9d, 0x85, 0x3d };
426 static const std::string test4Str((
char*)test4Arr,
sizeof(test4Arr));
427 std::string encLE(gnsstk::BinUtils::encodeVarLE<double>(test4));
430 return testFramework.countFails();
449 TUDEF(
"BinUtils",
"computeCRC");
454 unsigned char data1[] =
"This is a Test!@#$^...";
456 unsigned long len1 =
sizeof(data1)-1;
468 TUASSERTE(
unsigned long, 0xeaa96e4d, crc);
483 CRCParam nonDirect(24, 0x823ba9, 0xffffff, 0xffffff,
false,
false,
false);
488 CRCParam parity(1, 1, 0, 0,
true,
false,
false);
493 unsigned char data2[] = { 0x72 };
494 unsigned long len2 = 1;
496 TUASSERTE(
unsigned long, 0x6c09ff9d, crc);
502 return testFramework.countFails();
515 TUDEF(
"BinUtils",
"xorChecksum");
520 TUFAIL(
"xorChecksum should have failed on uneven input string");
522 catch(gnsstk::InvalidParameter e)
528 TUFAIL(
"xorChecksum threw the wrong exception type");
534 TUASSERTE(std::string,std::string(
"7"),cksum);
537 TUASSERTE(std::string,std::string(
"!"),cksum);
540 TUASSERTE(std::string,std::string(
"."),cksum);
543 TUASSERTE(std::string,std::string(
"mn"),cksum);
546 TUASSERTE(std::string,std::string(
"bc"),cksum);
549 TUASSERTE(std::string,std::string(
"z~"),cksum);
552 TUASSERTE(std::string,std::string(
"97Bg"),cksum);
555 TUASSERTE(std::string,std::string(
"`aga"),cksum);
558 TUASSERTE(std::string,std::string(
"zq3V"),cksum);
560 return testFramework.countFails();
573 TUDEF(
"BinUtils",
"countBits");
574 std::string failMesg;
589 return testFramework.countFails();
612 cout <<
"Total Failures for " << __FILE__ <<
": " << errorTotal << endl;