From patchwork Tue Aug 7 17:36:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [esnacc-dev,RFC,1/4] cxx-examples: hook up the vdatest X-Patchwork-Submitter: Aaron Conole X-Patchwork-Id: 31 X-Patchwork-Delegate: aconole@bytheb.org Message-Id: <20180807173657.7572-2-aconole@bytheb.org> To: dev@lists.esnacc.org Date: Tue, 7 Aug 2018 13:36:54 -0400 From: Aaron Conole List-Id: eSNACC Development discussion Also, fix up the asn-int test. Signed-off-by: Aaron Conole --- cxx-examples/automake.mk | 28 +++-- cxx-examples/src/inttest.cpp | 147 +++++++++++--------------- cxx-examples/src/main.cpp | 116 ++++++++------------ cxx-examples/src/vdatest.cpp | 246 +++++++++++++++++++++---------------------- 4 files changed, 248 insertions(+), 289 deletions(-) diff --git a/cxx-examples/automake.mk b/cxx-examples/automake.mk index 0997e95..051718f 100644 --- a/cxx-examples/automake.mk +++ b/cxx-examples/automake.mk @@ -15,11 +15,11 @@ cxx_examples_main_SOURCES = \ cxx-examples/src/rfc1155-smi.cpp \ cxx-examples/src/rfc1157-snmp.cpp \ cxx-examples/src/snmp.cpp \ - cxx-examples/src/testbuf.cpp + cxx-examples/src/testbuf.cpp \ + cxx-examples/src/vdatest_asn.cpp \ + cxx-examples/src/vdatest_asn2.cpp \ + cxx-examples/src/vdatest.cpp # cxx-examples/src/testsetsorting.cpp -# cxx-examples/src/vdatest_asn.asn1 \ -# cxx-examples/src/vdatest_asn2.asn1 \ -# cxx-examples/src/vdatest.cpp \ # cxx-examples/src/vda_threads.cpp \ # cxx-examples/src/vda_threads.h @@ -32,6 +32,16 @@ cxx_examples_main_LDADD = \ cxx_examples_main_LDFLAGS = +$(top_builddir)/cxx-examples/src/vdatest_asn.cpp: \ + $(top_srcdir)/cxx-examples/src/vdatest_asn.asn1 \ + $(top_builddir)/compiler/esnacc + $(top_builddir)/compiler/esnacc -C -mo `dirname $@` $< + +$(top_builddir)/cxx-examples/src/vdatest_asn2.cpp: \ + $(top_srcdir)/cxx-examples/src/vdatest_asn2.asn1 \ + $(top_builddir)/compiler/esnacc + $(top_builddir)/compiler/esnacc -C -mo `dirname $@` $< + $(top_builddir)/cxx-examples/src/rfc1155-smi.cpp: \ $(top_srcdir)/cxx-examples/src/rfc1155-smi.asn1 \ $(top_builddir)/compiler/esnacc @@ -52,7 +62,9 @@ $(top_builddir)/cxx-examples/src/autotags.cpp: \ EXTRA_DIST+= \ cxx-examples/src/autotags.asn1 \ cxx-examples/src/rfc1155-smi.asn1 \ - cxx-examples/src/rfc1157-snmp.asn1 + cxx-examples/src/rfc1157-snmp.asn1 \ + cxx-examples/src/vdatest_asn.asn1 \ + cxx-examples/src/vdatest_asn2.asn1 CLEANFILES+= \ test.txt \ @@ -61,4 +73,8 @@ CLEANFILES+= \ cxx-examples/src/rfc1157-snmp.cpp \ cxx-examples/src/rfc1157-snmp.h \ cxx-examples/src/rfc1155-smi.cpp \ - cxx-examples/src/rfc1155-smi.h + cxx-examples/src/rfc1155-smi.h \ + cxx-examples/src/vdatest_asn.cpp \ + cxx-examples/src/vdatest_asn.h \ + cxx-examples/src/vdatest_asn2.cpp \ + cxx-examples/src/vdatest_asn2.h diff --git a/cxx-examples/src/inttest.cpp b/cxx-examples/src/inttest.cpp index 4645c0e..2730a59 100644 --- a/cxx-examples/src/inttest.cpp +++ b/cxx-examples/src/inttest.cpp @@ -13,47 +13,47 @@ AsnIntTestTable gIntTestTable[]= // input // result { { - "1234", + "1234", {0x02, 0x02, 0x04, 0xD2}, true }, { - "-3628", + "-3628", {0x02, 0x02, 0xf1, 0xD4}, - true + false }, { - "2047483647", + "2047483647", {0x02, 0x04, 0x7a,0x0a,0x1e,0xff}, true }, { - "-2047483648", - {0x02, 0x04, 0x85,0xf5,0xe1,0x00}, + "-2047483648", + {0x02, 0x05, 0x0, 0x85,0xf5,0xe1,0x00}, true }, { - "0xffffffff", + "0xffffffff", {0x02, 0x01, 0xff}, false }, { - "0xffffffff", + "0xffffffff", {0x02, 0x05, 0x00,0xff,0xff,0xff,0xff}, true }, { - "0x0000ffff", + "0x0000ffff", {0x02, 0x03,0x00,0xff,0xff}, true }, { - "0x0000ffff", + "0x0000ffff", {0x02, 0x03,0x00,0xff,0xff}, true }, { - "0x000fffff", + "0x000fffff", {0x02,0x03,0x0f,0xff,0xff}, false }, @@ -63,28 +63,28 @@ AsnIntTestTable gIntTestTable[]= false }, { - "0x0080", + "0x0080", {0x02, 0x02, 0x00, 0x80}, true }, { - "0x0080", + "0x0080", {0x02, 0x02, 0x00, 0x80}, false }, { - "0xff81", + "0xffffff81", {0x02, 0x01, 0x81}, false }, { - "0xff81", + "0xff81", {0x02,0x03,0x00,0xff,0x81}, true }, { - "5247483647", //bad - {0x02, 0x04, 0x7f,0xff,0xff,0xff}, + "5247483647", + {0x02, 0x04, 0x38, 0xc6, 0x3e, 0xff}, true }, { @@ -99,78 +99,49 @@ int convTests[gCT] = { 0, -1, -5, -256, 256, 16, -10000, 10000, 655335, -655335, void inttests(void) { - FUNC("intTests()"); - try - { - std::cout << "** Conversion tests **\n"; - for (int i=0; i < gCT; i++) - { - AsnInt n(convTests[i]); - int x = n; - if (x == convTests[i]) - { - std::cout.width(10); - std::cout << convTests[i] << " test SUCCESS!\n"; - } - else - { - std::cout.width(10); - std::cout << convTests[i] << " FAILED!\n"; - std::cout << "Input: " << convTests[i] << "\n"; - std::cout << "Result: " << x << "\n"; - } - } - std::cout << "** End Conversion tests **\n\n"; - for (int testIndex = 0; gIntTestTable[testIndex].input != NULL; testIndex++) - { - if (gIntTestTable[testIndex].unsignedFlag) - std::cout << "AsnInt (unsigned) Test " << testIndex << ":"; - else - std::cout << "AsnInt ( signed ) Test " << testIndex << ":"; - - AsnInt asnInt (gIntTestTable[testIndex].input, - gIntTestTable[testIndex].unsignedFlag); - AsnBuf expectedResult((const char *)gIntTestTable[testIndex].result, - DecTagLen(gIntTestTable[testIndex].result + 1) + 2); - AsnBuf result; - - try - { - asnInt.BEnc(result); - - std::cout << "INTEGER encoding matches expected result? "; - if (result == expectedResult) - { - std::cout << "YES!" << std::endl; - } - else - { - std::cout << "NO!" << std::endl; - std::cout << "Input: " << gIntTestTable[testIndex].input << std::endl; - std::cout << "Expected Result: "; - std::cout << std::ios_base::hex << expectedResult; - std::cout << std::endl; - std::cout << "Actual Result: "; - std::cout << std::ios_base::hex << result; - std::cout << std::endl; - } - } - catch (SnaccException &se) - { - std::cout << "AsnInt encode/decode test failed:" << std::endl; - std::cout << "Error: " << se.what() << std::endl; - std::cout << "Stack: \n"; - se.getCallStack(std::cout); - } - } + std::cout << "** Conversion tests **\n"; + for (int i=0; i < gCT; i++) { + AsnInt n(convTests[i]); + int x = n; + if (x == convTests[i]) { + std::cout.width(10); + std::cout << convTests[i] << " test SUCCESS!\n"; + } else { + std::cout.width(10); + std::cout << convTests[i] << " FAILED!\n"; + std::cout << "Input: " << convTests[i] << "\n"; + std::cout << "Result: " << x << "\n"; + } } - catch(SnaccException &e) - { - std::cout << "Int test failed:\n"; - std::cout << "ERROR STRING: "; - std::cout << e.what() << "\n"; - std::cout.flush(); - std::cout << "*** Int Test ***\n"; + std::cout << "** End Conversion tests **\n\n"; + + for (int testIndex = 0; gIntTestTable[testIndex].input != NULL; + testIndex++) { + if (gIntTestTable[testIndex].unsignedFlag) + std::cout << "AsnInt (unsigned) Test " << testIndex << ":" + << gIntTestTable[testIndex].input; + else + std::cout << "AsnInt ( signed ) Test " << testIndex << ":" + << gIntTestTable[testIndex].input; + + AsnInt asnInt (gIntTestTable[testIndex].input, + gIntTestTable[testIndex].unsignedFlag); + AsnBuf expectedResult((const char *)gIntTestTable[testIndex].result, + DecTagLen(gIntTestTable[testIndex].result + 1) + 2); + AsnBuf result; + + asnInt.BEnc(result); + + std::cout << "INTEGER encoding matches expected result? "; + if (result == expectedResult) { + std::cout << "YES!" << std::endl; + } else { + result.hexDump(std::cout); + char msg[512] = {0}; + snprintf(msg, 512, "Failed INTEGER encode/decode test id: %d", + testIndex); + throw SnaccException(__FILE__, __LINE__, __func__, strdup(msg)); + } } } diff --git a/cxx-examples/src/main.cpp b/cxx-examples/src/main.cpp index 0fcc67e..c231f2d 100644 --- a/cxx-examples/src/main.cpp +++ b/cxx-examples/src/main.cpp @@ -7,7 +7,7 @@ void newBufTest(); int automaticTests(); - +void vdatest_main(); using namespace SNACC; void doubleDecodeTest(void) @@ -16,43 +16,34 @@ void doubleDecodeTest(void) AsnBuf asnBuf(buf, 6); AsnLen len; AsnOcts octs; - try { - std::cout << "*** doubleDecodeTest ***\n"; - if (octs.BDecPdu(asnBuf, len)) { - if (octs.c_ustr()[0] == '1') { - std::cout << "First OCTET STRING value: " - << octs.c_ustr()[0] << std::endl; - - if (octs.BDecPdu(asnBuf, len)) { - if (octs.c_ustr()[0] == '2') { - std::cout << "Second OCTET STRING value: " - << octs.c_ustr()[0] << std::endl; - } else { - std::cout - << "Unexpected result for second OCTET STRING: " - << octs.c_ustr()[0] << std::endl; - } + + std::cout << "*** doubleDecodeTest ***\n"; + if (octs.BDecPdu(asnBuf, len)) { + if (octs.c_ustr()[0] == '1') { + std::cout << "First OCTET STRING value: " + << octs.c_ustr()[0] << std::endl; + + if (octs.BDecPdu(asnBuf, len)) { + if (octs.c_ustr()[0] == '2') { + std::cout << "Second OCTET STRING value: " + << octs.c_ustr()[0] << std::endl; } else { - std::cout << "Decode of second OCTET STRING failed!\n"; + throw SnaccException(__FILE__, __LINE__, __func__, + "Bad Value in decode"); } } else { - std::cout - << "ERROR: Unexpected result for first OCTET STRING: " - << octs.c_ustr()[0] << std::endl; + throw SnaccException(__FILE__, __LINE__, __func__, + "Bad decode operation"); } } else { - std::cout << "Decode of double OCTET STRING encoded FAILED!\n"; + throw SnaccException(__FILE__, __LINE__, __func__, + "Bad value for first OCTET."); } - - std::cout << "*** doubleDecodeTest ***\n"; - - } catch(SnaccException &e) { - std::cout << "Double decode test failed:\n"; - std::cout << "ERROR STRING: "; - std::cout << e.what() << "\n"; - std::cout.flush(); - std::cout << "*** doubleDecodeTest ***\n"; + } else { + throw SnaccException(__FILE__, __LINE__, __func__, + "Unable to decode DOUBLE properly."); } + std::cout << "*** doubleDecodeTest ***\n"; } void octsTest(void) @@ -65,32 +56,23 @@ void octsTest(void) AsnLen len = 22; AsnOcts octs; - try { - std::cout << "*** start of AsnOcts tests ***\n"; - if (octs.BDecPdu(asnBuf, len)) { - if (memcmp(octs.c_ustr(), &buf[2], octs.Len()) == 0) { - for (i = 0; i < 20; i++) { - std::cout << "OCTET STRING value: " << octs.c_ustr()[i] << std::endl; - } - } else { - for (i = 0; i < 20; i++) { - std::cout - << "ERROR: Unexpected result for OCTET STRING: " - << octs.c_ustr()[i] << std::endl; - } + std::cout << "*** start of AsnOcts tests ***\n"; + if (octs.BDecPdu(asnBuf, len)) { + if (memcmp(octs.c_ustr(), &buf[2], octs.Len()) == 0) { + for (i = 0; i < 20; i++) { + std::cout << "OCTET STRING value: " << octs.c_ustr()[i] + << std::endl; } } else { - std::cout << "Decode of OCTET STRING encoded FAILED!\n"; + for (i = 0; i < 20; i++) { + std::cout << "ERROR: Unexpected result for OCTET STRING: " + << octs.c_ustr()[i] << std::endl; + } + throw SnaccException(__FILE__, __LINE__, __func__, + "Failed octsTest first"); } - - std::cout << "*** End of AsnOcts tests ***\n"; - } catch(SnaccException &e) { - std::cout << "Octs test failed:\n"; - std::cout << "ERROR STRING: "; - std::cout << e.what() << "\n"; - std::cout.flush(); - std::cout << "*** End of AsnOcts tests ***\n"; } + std::cout << "*** End of AsnOcts tests ***\n"; } void fillTest(void) @@ -125,25 +107,14 @@ void fillTest(void) AsnLen len = sizeof(buf); AsnOcts octs; - try { - std::cout << "*** start of Recursive Fill tests ***\n"; - octs.BDec(asnBuf, len); - - std::cout << std::endl; - - octs.PrintXML(std::cout); - std::cout << std::endl; - std::cout << len; - std::cout << "*** End of Recursive Fill tests ***\n"; - - } catch(SnaccException &e) { - std::cout << "Octs test failed:\n"; - std::cout << "ERROR STRING: "; - std::cout << e.what() << "\n"; - std::cout.flush(); - std::cout << "*** End of Recursive Fill tests ***\n"; - } + std::cout << "*** start of Recursive Fill tests ***\n"; + octs.BDec(asnBuf, len); + std::cout << std::endl; + octs.PrintXML(std::cout); + std::cout << std::endl; + std::cout << len; + std::cout << "*** End of Recursive Fill tests ***\n"; } int main(int argc, char *argv[]) @@ -175,7 +146,7 @@ int main(int argc, char *argv[]) doubleDecodeTest(); inttests(); bittests(); - + vdatest_main(); if (snmpPath != NULL) { run_snmp_tests(snmpPath); } @@ -190,6 +161,7 @@ int main(int argc, char *argv[]) std::cout << "What: " << e.what() << std::endl; std::cout << "Call Stack:\n"; e.getCallStack(std::cout); + return 1; } return 0; } diff --git a/cxx-examples/src/vdatest.cpp b/cxx-examples/src/vdatest.cpp index 9ca74e9..396728f 100644 --- a/cxx-examples/src/vdatest.cpp +++ b/cxx-examples/src/vdatest.cpp @@ -32,50 +32,24 @@ using namespace VDATestModule2Namespace; // // -int vdatest_main(int argc, char *argv[]) +void vdatest_main() { - - /*if (argc > 1) - { - traverseDir(argv[1]); - - exit(0); - }*/ test_IndefiniteLengthEncoding(); -#ifdef BOUNDS_CHECKER_TEST_WITHOUT_THREADS - vdaTestPrintThreadLocks(); - return(0); - vdaTestThreadLocks(); - vdaTestThreads(55); // AVOIDS problems with above; must be performed last. -#endif //ifdef BOUNDS_CHECKER_TEST_WITHOUT_THREADS - - try - { - ANY_DEFINED_BY_test(); - test_AsnOid(); - AsnIntTest(); - ANY_DEFINED_BY_test_2(); - XML_test(); - test_timing(); - test_big_buffer(); - // THE FOLLOWING TEST also tests SET OF ordering. - // ALSO, it must be last since an error condition is trapped. - append_test(); - } - catch ( SnaccException &e ) - { - std::cout << "ERROR: " << e.what() << "\n"; - std::cout << "Call stack:\n"; - e.getCallStack(std::cout); - std::cout << "\n"; - } + ANY_DEFINED_BY_test(); + test_AsnOid(); + AsnIntTest(); + ANY_DEFINED_BY_test_2(); + XML_test(); + test_timing(); + test_big_buffer(); + // THE FOLLOWING TEST also tests SET OF ordering. + // ALSO, it must be last since an error condition is trapped. + append_test(); std::cout << "####### END OF vdatest TESTS #########\n"; std::cout.flush(); - - return 1; } @@ -102,10 +76,10 @@ void ANY_DEFINED_BY_test() A.i2 = 2; A.i3 = 3; A.i4 = 4; - + // Encode TestDefinedByUsage into a buffer // - if (! A.BEnc(buf)) + if (!A.BEnc(buf)) throw SNACC_EXCEPT("Encode of TestDefinedByUsage failed!"); // Decode buffer into a different TestDefinedByUsage to demonstrate the @@ -116,8 +90,7 @@ void ANY_DEFINED_BY_test() // Check the OID to determine if this is the ANY you are looking for. // - if (A2.id == testOID2) - { + if (A2.id == testOID2) { // You must cast the ANY to the type you expect. It's up to the // application to do the proper casting. // @@ -125,9 +98,7 @@ void ANY_DEFINED_BY_test() std::cout << "ANY_DEFINED_BY_test: Good id, == testOID2." << pPrtblStr->c_str() << "\n"; - } - else - { + } else { std::cout << "ANY_DEFINED_BY_test: ***** Bad id, EXPECTED testOID2.\n"; } @@ -135,7 +106,7 @@ void ANY_DEFINED_BY_test() A.id = testOid3_UNKNOWN; //A.anyDefBy.value = new AsnAnyBuffer((char *)data, len); - + buf.ResetMode(); if (! A.BEnc(buf)) throw SNACC_EXCEPT("Encode of TestDefinedByUsage failed!"); @@ -438,18 +409,13 @@ int append_test() testNullBitStringBlob.hexDump(std::cout); std::cout << "\n"; std::cout.flush(); + throw SNACC_EXCEPT("Null bit string 1"); } if (! snaccNullBitString3.BEnc(buf) ) throw SNACC_EXCEPT("Encoding of NULL BIT STRING failed!"); - if (buf == testNullBitStringBlob) - { - std::cout << "NULL BIT STRING 2 TEST PASSED!\n"; - std::cout.flush(); - } - else - { + if (buf == testNullBitStringBlob) { std::cout << "NULL BIT STRING TEST 2 FAILED!\n"; std::cout << "ENCODED VALUE IS:\n"; buf.hexDump(std::cout); @@ -457,6 +423,10 @@ int append_test() testNullBitStringBlob.hexDump(std::cout); std::cout << "\n"; std::cout.flush(); + throw SNACC_EXCEPT("Null bit string 2"); + } else { + std::cout << "NULL BIT STRING 2 TEST PASSED!\n"; + std::cout.flush(); } // Now let's test a bits string that has more than one octet that is null. @@ -654,7 +624,11 @@ int append_test() std::cout << "######### STACK ####\n"; VDATestSequence aa; AsnBuf cBuf("aaa", 3); - aa.BDec(cBuf, bytesDecoded); // expected to fail + try { + aa.BDec(cBuf, bytesDecoded); // expected to fail + } catch (SnaccException &e) { + std::cout << "Correct" << std::endl; + } return 1; } /* append_test */ @@ -1146,6 +1120,7 @@ double test_timingDoTest(long BYTE_COUNT, long iCount, int new_flag, long lTestT // This function demonstrates/tests the new AsnInt BigInteger logic. void AsnIntTest() { + FUNC("AsnIntTest"); AsnInt A,B,H; int /*AsnIntType*/ CInt; AsnBuf b; @@ -1156,19 +1131,23 @@ void AsnIntTest() //######### convert string into Hex ########################## H = AsnInt("0x20FF"); - if (H == 767) - std::cout << "\nAsnIntTest: SUCCESSFUL string to hex conversion, " << H + if (H == 8447) + std::cout << "\nAsnIntTest: SUCCESSFUL string to hex conversion, " << std::hex << H << std::dec << ".\n"; - else - std::cout << "AsnIntTest: UNSUCCESSFUL string to hex conversion, " << H + else { + std::cout << "AsnIntTest[0x20ff]: UNSUCCESSFUL string to hex conversion, " << std::hex << H << std::dec << ".\n"; + throw SNACC_EXCEPT("IntConvTst"); + } H = AsnInt("0xF0"); - if (H == 15) - std::cout << "AsnIntTest: SUCCESSFUL string to hex conversion, " << H + if (H == 240) + std::cout << "AsnIntTest: SUCCESSFUL string to hex conversion, " << std::hex << H << std::dec << ".\n"; - else - std::cout << "AsnIntTest: UNSUCCESSFUL string to hex conversion, " << H + else { + std::cout << "AsnIntTest[0xf0]: UNSUCCESSFUL string to hex conversion, " << std::hex << H << std::dec << ".\n"; + throw SNACC_EXCEPT("IntConvTst"); + } //######### check small integer.############################## A = 20; @@ -1180,9 +1159,11 @@ void AsnIntTest() if (B == 20) std::cout << "AsnIntTest: SUCCESSFUL integer encode/decode, " << B << ".\n"; - else - std::cout << "AsnIntTest: UNSUCCESSFUL integer encode/decode, " << B + else { + std::cout << "AsnIntTest[bytes 20]: UNSUCCESSFUL integer encode/decode, " << B << ".\n"; + throw SNACC_EXCEPT("IntConvTst"); + } } @@ -1209,43 +1190,55 @@ void AsnIntTest() pBuf[2], pBuf[3], pBuf[4], pBuf[5], pBuf[6]); std::cout << buf; } - else + else { std::cout << "AsnIntTest: UNSUCCESSFUL 7 byte integer encode/decode, " << ".\n"; + throw SNACC_EXCEPT("IntConvTst"); + } } - else + else { std::cout << "AsnIntTest: UNSUCCESSFUL length 7 byte integer encode/decode, bytesDecoded=" << bytesDecoded << ".\n"; + throw SNACC_EXCEPT("IntConvTst"); + } //######### check assignment of multi-byte integer to a small int variable. // + bool throwIt = false; try { CInt = B; // Attempt to assign 7 byte integer to 4 byte variable. std::cout << "AsnIntTest: UNSUCCESSFUL ERROR on large integer assign to too small long." << ".\n"; + throwIt = true; } catch (...) { std::cout << "AsnIntTest: SUCCESSFUL ERROR (catch) on large integer assign to too small long." << ".\n"; } + if (throwIt) + throw SNACC_EXCEPT("7 byte test"); //######### check negative small integer.############################## // bytesDecoded = 0; - A = -20; + A = AsnInt(-20); + b = AsnBuf(); A.BEnc(b); B.BDec(b, bytesDecoded); - if (bytesDecoded) - { - if (B == -20) - std::cout << "AsnIntTest: SUCCESSFUL negative integer encode/decode, " << B - << ".\n"; - else - std::cout << "AsnIntTest: UNSUCCESSFUL negative integer encode/decode, " << B - << ".\n"; + if (bytesDecoded) { + if (B == -20) { + std::cout + << "AsnIntTest: SUCCESSFUL negative integer encode/decode, " + << B << ".\n"; + } else { + std::cout + << "AsnIntTest: UNSUCCESSFUL negative integer encode/decode, " + << B << ".\n"; + throw SNACC_EXCEPT("IntConvTst"); + } } //######### check sign-extended negative large integer, with known size.## @@ -1258,49 +1251,51 @@ void AsnIntTest() TmpData2[2] = (char)0xff; TmpData2[3] = (char)0xff; bytesDecoded = 0; - A.Set((unsigned char *)TmpData2, 128); + A.Set((unsigned char *)TmpData2, 128, false); + b = AsnBuf(); A.BEnc(b); // EXPECT 4 less bytes encoded due to sign extension. bytesDecoded = 0; B.BDec(b, bytesDecoded); - if (B.length() == 124/*for Data*/) - { + b.hexDump(std::cout); + if (B.length() == 124) { bFlag = true; // Start out assuming all data is good. const unsigned char *pBuf=B.c_str(); - for (i=0; i < 124; i++) - if (pBuf[i] != (unsigned char)TmpData2[i]) - bFlag = false; - if (bFlag) - { - std::cout << "AsnIntTest: SUCCESSFUL 124 byte negative integer encode/decode, " - << ".\n"; - char buf[200]; - sprintf(buf, "%2.2xx%2.2xx%2.2xx%2.2xx%2.2xx%2.2xx%2.2xx.\n", pBuf[0], pBuf[2], - pBuf[2], pBuf[3], pBuf[4], pBuf[5], pBuf[6]); - std::cout << buf; - unsigned char *pBuf3 = NULL; // RESET for next operation. - size_t length; - B.getPadded(pBuf3, length, size_t(128)); - bFlag = true; // Start out assuming all data is good. - for (int i=0; i < 4; i++) - if (pBuf3[i] != (char)0xff) - bFlag = false; - if (!bFlag || length != 128) - std::cout << "AsnIntTest: UNSUCCESSFUL 128 byte negative integer GetSignedBitExtendedData(...).\n"; - else - std::cout << "AsnIntTest: SUCCESSFUL 128 byte negative integer GetSignedBitExtendedData(...).\n"; - if (pBuf3) - free(pBuf3); + for (i=0; i < 124; i++) { + if (pBuf[i] != (unsigned char)TmpData2[i+4]) { + std::cout + << "AsnIntTest: UNSUCCESSFUL 124 byte negative integer " + " encode/decode, i = " << i << "== [" + << std::hex << (unsigned int)pBuf[i] << ":" + << (unsigned int)TmpData2[i] << std::dec + << "]"<< ".\n"; + throw SNACC_EXCEPT("IntConvTst"); + } } - else - std::cout << "AsnIntTest: UNSUCCESSFUL 124 byte negative integer encode/decode, " - << ".\n"; - } - else + + unsigned char *pBuf3 = NULL; // RESET for next operation. + size_t length; + B.getPadded(pBuf3, length, size_t(128)); + for (int i = 0; i < 4; i++) { + if (pBuf3[i] != (char)0x0 || length != 128) { + std::cout << "AsnIntTest: UNSUCCESSFUL 128 byte negative integer.\n" + << "GetSignedBitExtendedData(len=" + << length << ", pbuff[" << i << "]=" + << std::hex << (int)pBuf3[i] << std::dec + << ").\n"; + throw SNACC_EXCEPT("IntConvTst"); + } + } + + std::cout << "AsnIntTest: SUCCESSFUL 128 byte negative integer GetSignedBitExtendedData(...).\n"; + if (pBuf3) + free(pBuf3); + } else { std::cout << "AsnIntTest: UNSUCCESSFUL length 124 byte integer encode/decode, bytesDecoded=" - << bytesDecoded << ".\n"; + << bytesDecoded << "vs. len == " << B.length() << ".\n"; + throw SNACC_EXCEPT("IntConvTst"); + } - //######### check sign-extended positive large integer, with known size.## // for (i=0; i < 128; i++) @@ -1311,27 +1306,26 @@ void AsnIntTest() TmpData2[3] = (char)0x00; bytesDecoded = 0; A.Set((const unsigned char *)TmpData2, 128); + b = AsnBuf(); A.BEnc(b); // EXPECT 4 less bytes encoded due to sign extension. bytesDecoded = 0; B.BDec(b, bytesDecoded); - if (B.length() == 124/*for Data*/) - { - bFlag = true; // Start out assuming all data is good. - { + if (B.length() == 124/*for Data*/) { const unsigned char *pBuf= B.c_str(); + bFlag = true; // Start out assuming all data is good. for (i=0; i < 124; i++) - if (pBuf[i] != (unsigned char)TmpData2[i]) + if (pBuf[i] != (unsigned char)TmpData2[i+4]) bFlag = false; - } - if (bFlag) - { + + if (bFlag) { unsigned char *pBuf; std::cout << "AsnIntTest: SUCCESSFUL 124 byte integer encode/decode, " << ".\n"; char buf[200]; - sprintf(buf, "%2.2xx%2.2xx%2.2xx%2.2xx%2.2xx%2.2xx%2.2xx.\n", pBuf[0], pBuf[2], - pBuf[2], pBuf[3], pBuf[4], pBuf[5], pBuf[6]); + sprintf(buf, "%2.2xx%2.2xx%2.2xx%2.2xx%2.2xx%2.2xx%2.2xx.\n", + pBuf[0], pBuf[2], pBuf[2], pBuf[3], pBuf[4], pBuf[5], + pBuf[6]); std::cout << buf; pBuf = NULL; // RESET for next operation. size_t length; @@ -1340,16 +1334,22 @@ void AsnIntTest() for (int i=0; i < 4; i++) if (pBuf[i] != (char)0x00) bFlag = false; - if (!bFlag || length != 128) + if (!bFlag || length != 128) { std::cout << "AsnIntTest: UNSUCCESSFUL 128 byte positive integer GetSignedBitExtendedData(...).\n"; + throw SNACC_EXCEPT("IntConvTst"); + } } - else + else { std::cout << "AsnIntTest: UNSUCCESSFUL 124 byte positive integer encode/decode, " << ".\n"; + throw SNACC_EXCEPT("IntConvTst"); + } } - else + else { std::cout << "AsnIntTest: UNSUCCESSFUL length 124 byte positive integer encode/decode, bytesDecoded=" << bytesDecoded << ".\n"; + throw SNACC_EXCEPT("IntConvTst"); + } std::cout.flush(); } @@ -1468,8 +1468,8 @@ long vdaTestPrintThreadLocks() testSequence.testAllPrimatives.boolTestName = true; testSequence.testAllPrimatives.oidName = new AsnOid; *testSequence.testAllPrimatives.oidName = testOID; - char *pData="TES";//(char)0xa5, (char)0xa5, (char)0xa5; - testSequence.testAllPrimatives.bitStringName.Set((const unsigned char*)pData, 24); + const char *pData="TES";//(char)0xa5, (char)0xa5, (char)0xa5; + testSequence.testAllPrimatives.bitStringName.Set((const unsigned char *)pData, 24); testSequence.testAllPrimatives.integerName = 55; testSequence.testAllPrimatives.enumTestName = TestAllAsnPrimativeTypesEnum::aA;