Add additional tests

Whitespace check-in
pull/416/head
Jeffrey Walton 2017-05-05 20:34:43 -04:00
parent 9225ca09cb
commit ac930b084d
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 213 additions and 145 deletions

View File

@ -54,11 +54,35 @@ bool TestGzip()
fail = true;
}
// Unzip random data. See if we can induce a crash
for (unsigned int i=0; i<128; i++)
{
std::string src, dest;
unsigned int len = GlobalRNG().GenerateWord32() & 0xffff;
src.resize(len);
GlobalRNG().GenerateBlock(reinterpret_cast<byte*>(&src[0]), src.size());
src[0] = 0x1f; src[1] = 0x8b; // magic Header
src[2] = 0x00; // extra flags
src[3] = src[3] & (2|4|8|16|32); // flags
// Don't allow ENCRYPTED|CONTINUED to over-run tests
if (src[3] & (2|32)) {
if (i%3 == 0) {src[3] &= ~2;}
if (i%3 == 1) {src[3] &= ~32;}
}
// The remainder are extra headers and the payload
try {
StringSource(src, true, new Gunzip(new StringSink(dest)));
} catch(const Exception&) { }
}
if (!fail)
std::cout << "passed:";
else
std::cout << "FAILED:";
std::cout << "128 zip and unzip" << std::endl;
std::cout << " 256 zips and unzips" << std::endl;
return !fail;
}
@ -81,7 +105,7 @@ bool TestZinflate()
StringSource(src, true, new Deflator(new StringSink(dest)));
StringSource(dest, true, new Inflator(new StringSink(rec)));
if (src != rec)
throw Exception(Exception::OTHER_ERROR, "Inflate failed a self test");
throw Exception(Exception::OTHER_ERROR, "Deflate failed a self test");
}
}
catch(const Exception&)
@ -89,12 +113,51 @@ bool TestZinflate()
fail = true;
}
for (unsigned int i=0; i<128; i++)
{
// See if we can induce a crash
std::string src, dest;
unsigned int len = GlobalRNG().GenerateWord32() & 0xffff;
src.resize(len);
GlobalRNG().GenerateBlock(reinterpret_cast<byte*>(&src[0]), src.size());
try {
StringSource(src, true, new Inflator(new StringSink(dest)));
} catch(const Exception&) { }
}
// Unzip random data. See if we can induce a crash
for (unsigned int i=0; i<128; i++)
{
std::string src, dest;
unsigned int len = GlobalRNG().GenerateWord32() & 0xffff;
src.resize(len);
GlobalRNG().GenerateBlock(reinterpret_cast<byte*>(&src[0]), src.size());
src[0] = 0x1f; src[1] = 0x8b; // magic Header
src[2] = 0x00; // extra flags
src[3] = src[3] & (2|4|8|16|32); // flags
// Don't allow ENCRYPTED|CONTINUED to over-run tests
if (src[3] & (2|32)) {
if (i%3 == 0) {src[3] &= ~2;}
if (i%3 == 1) {src[3] &= ~32;}
}
// The remainder are extra headers and the payload
try {
StringSource(src, true, new Inflator(new StringSink(dest)));
} catch(const Exception&) { }
}
if (!fail)
std::cout << "passed:";
else
std::cout << "FAILED:";
std::cout << "128 deflate and inflate" << std::endl;
std::cout << " 256 deflates and inflates\n";
std::cout.flush();
return !fail;
}
@ -695,6 +758,7 @@ bool TestRounding()
std::cout << (fail ? "FAILED:" : "passed:") << " RoundUpToMultipleOf, word128, overflow\n";
#endif
std::cout.flush();
return pass;
}
#endif
@ -773,6 +837,7 @@ bool RunASN1TestSet(const ASN1_TestTuple asnTuples[], size_t count)
pass = !fail && pass;
}
std::cout.flush();
return pass;
}
@ -946,6 +1011,7 @@ bool TestASN1Parse()
pass = RunASN1TestSet(integerValues, COUNTOF(integerValues)) && pass;
std::cout.flush();
return pass;
}
#endif
@ -984,7 +1050,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Zeroized byte array" << std::endl;
std::cout << " Zeroized byte array\n";
SecBlock<word32> z2(NULLPTR, 256);
temp = true;
@ -997,7 +1063,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Zeroized word32 array" << std::endl;
std::cout << " Zeroized word32 array\n";
SecBlock<word64> z3(NULLPTR, 256);
temp = true;
@ -1010,7 +1076,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Zeroized word64 array" << std::endl;
std::cout << " Zeroized word64 array\n";
#if defined(CRYPTOPP_WORD128_AVAILABLE)
SecBlock<word128> z4(NULLPTR, 256);
@ -1024,7 +1090,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Zeroized word128 array" << std::endl;
std::cout << " Zeroized word128 array\n";
#endif
}
@ -1079,7 +1145,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Assign byte" << std::endl;
std::cout << " Assign byte\n";
try
{
@ -1114,7 +1180,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Assign word32" << std::endl;
std::cout << " Assign word32\n";
try
{
@ -1149,7 +1215,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Assign word64" << std::endl;
std::cout << " Assign word64\n";
#if defined(CRYPTOPP_WORD128_AVAILABLE)
try
@ -1185,7 +1251,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Assign word128" << std::endl;
std::cout << " Assign word128\n";
#endif
//********** Append **********//
@ -1231,7 +1297,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Append byte" << std::endl;
std::cout << " Append byte\n";
try
{
@ -1276,7 +1342,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Append word32" << std::endl;
std::cout << " Append word32\n";
try
{
@ -1321,7 +1387,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Append word64" << std::endl;
std::cout << " Append word64\n";
#if defined(CRYPTOPP_WORD128_AVAILABLE)
try
@ -1367,7 +1433,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Append word128" << std::endl;
std::cout << " Append word128\n";
#endif
//********** Concatenate **********//
@ -1406,7 +1472,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Concatenate byte" << std::endl;
std::cout << " Concatenate byte\n";
// word32
try
@ -1444,7 +1510,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Concatenate word32" << std::endl;
std::cout << " Concatenate word32\n";
// word64
try
@ -1482,7 +1548,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Concatenate word64" << std::endl;
std::cout << " Concatenate word64\n";
#if defined(CRYPTOPP_WORD128_AVAILABLE)
try
@ -1520,7 +1586,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Concatenate word128" << std::endl;
std::cout << " Concatenate word128\n";
#endif
//********** Equality **********//
@ -1561,7 +1627,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Equality byte" << std::endl;
std::cout << " Equality byte\n";
// word32
try
@ -1599,7 +1665,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Equality word32" << std::endl;
std::cout << " Equality word32\n";
// word64
try
@ -1637,7 +1703,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Equality word64" << std::endl;
std::cout << " Equality word64\n";
#if defined(CRYPTOPP_WORD128_AVAILABLE)
// word128
@ -1676,7 +1742,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Equality word128" << std::endl;
std::cout << " Equality word128\n";
#endif
//********** Allocator Size/Overflow **********//
@ -1703,7 +1769,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Overflow word32" << std::endl;
std::cout << " Overflow word32\n";
try
{
@ -1727,7 +1793,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Overflow word64" << std::endl;
std::cout << " Overflow word64\n";
#if defined(CRYPTOPP_WORD128_AVAILABLE)
try
@ -1752,7 +1818,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "Overflow word128" << std::endl;
std::cout << " Overflow word128\n";
#endif
//********** FixedSizeAllocatorWithCleanup and Grow **********//
@ -1792,7 +1858,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "FixedSizeAllocator Grow with byte" << std::endl;
std::cout << " FixedSizeAllocator Grow with byte\n";
// word32
try
@ -1830,7 +1896,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "FixedSizeAllocator Grow with word32" << std::endl;
std::cout << " FixedSizeAllocator Grow with word32\n";
// word64
try
@ -1868,7 +1934,7 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "FixedSizeAllocator Grow with word64" << std::endl;
std::cout << " FixedSizeAllocator Grow with word64\n";
#if defined(CRYPTOPP_WORD128_AVAILABLE)
// word128
@ -1907,9 +1973,10 @@ bool TestSecBlock()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << "FixedSizeAllocator Grow with word128" << std::endl;
std::cout << " FixedSizeAllocator Grow with word128\n";
#endif
std::cout.flush();
return pass1 && pass2 && pass3 && pass4 && pass5 && pass6 && pass7;
}
#endif
@ -2535,7 +2602,7 @@ bool TestIntegerBitops()
std::cout << "passed:";
else
std::cout << "FAILED:";
std::cout << "Bitwise AND over 32-bits to 1024-bits" << std::endl;
std::cout << " Bitwise AND over 32-bits to 1024-bits\n";
//////////////////// OR ////////////////////
@ -2561,7 +2628,7 @@ bool TestIntegerBitops()
std::cout << "passed:";
else
std::cout << "FAILED:";
std::cout << "Bitwise OR over 32-bits to 1024-bits" << std::endl;
std::cout << " Bitwise OR over 32-bits to 1024-bits\n";
//////////////////// XOR ////////////////////
@ -2587,8 +2654,9 @@ bool TestIntegerBitops()
std::cout << "passed:";
else
std::cout << "FAILED:";
std::cout << "Bitwise XOR over 32-bits to 1024-bits" << std::endl;
std::cout << " Bitwise XOR over 32-bits to 1024-bits\n";
std::cout.flush();
return opa && opo && opx;
}
#endif