void bittests(void) { std::cout << "*** Start of AsnBits tests ***\n"; for (int index=0; gBitTestTable[index].input != NULL; index++) { AsnBits asnBits(gBitTestTable[index].input); asnBits.UseNamedBitListRules(gBitTestTable[index].nblFlag); AsnBuf expectedResult(&gBitTestTable[index].result[0], DecTagLen((unsigned char *)gBitTestTable[index].result+1) + 2); AsnBuf result; AsnLen bytesEncoded; std::cout << "AsnBits test " << index << " matches expected result? "; try { asnBits.BEnc(result); if (!(result == expectedResult)) { std::string str; int i; int ch; std::cout << "NO!\n"; std::cout << "FAILED!\n"; std::cout << "Expected Result: "; expectedResult.hexDump(std::cout); std::cout << "\n"; std::cout << "\nActual Result: "; result.hexDump(std::cout); std::cout << "\n"; } else { std::cout << "YES!\n"; } } catch (SnaccException &e) { std::cout << "Encode FAILED: \n"; std::cout << "Error: " << e.what() << std::endl; std::cout << "Stack:\n"; e.getCallStack(std::cout); } } std::cout << "*** End of AsnBits tests ***\n"; }
void TestSetSorting(void) { int i = 0; while (gSetSortingTable[i].input != NULL) { AsnLen bytesDecoded=0, bytesEncoded; //TestSetSorting1 testSetSorting1; int ch; std::string input, result; hex2str(gSetSortingTable[i].input, input); hex2str(gSetSortingTable[i].derSorted, result); std::stringstream ssInput(input); std::stringstream ssResult(result); AsnBuf inputBuf(ssInput); AsnBuf expectedResultBuf(ssResult); AsnBuf outputBuf; inputBuf.ResetMode(); expectedResultBuf.ResetMode(); gSetSortingTable[i].asnType->BDec(inputBuf, bytesDecoded); bytesEncoded = gSetSortingTable[i].asnType->BEnc(outputBuf); if (bytesEncoded != bytesDecoded) { std::cout << "Encoded / Decode byte length mismatch!!!\n"; } if (outputBuf == expectedResultBuf) { std::cout << "SET sorting SUCCESS!\n"; } else { std::cout << "SET sorting FAILURE!\n"; std::string str; std::cout << "Expected result: "; expectedResultBuf.hexDump(std::cout); std::cout << std::endl; std::cout << "Actual result : "; outputBuf.ResetMode(); outputBuf.hexDump(std::cout); std::cout << std::endl; } i++; } multiCardSetTest(); }