Add test for Huffman codes (Issue 242)

pull/253/head
Jeffrey Walton 2016-08-21 03:18:26 -04:00
parent 5f4b1d4ca9
commit 1e7c837442
2 changed files with 34 additions and 0 deletions

View File

@ -87,6 +87,8 @@ bool ValidateAll(bool thorough)
pass=TestSecBlock() && pass;
// http://github.com/weidai11/cryptopp/issues/64
pass=TestPolynomialMod2() && pass;
// http://github.com/weidai11/cryptopp/pull/242
pass=TestHuffmanCodes() && pass;
#endif
pass=ValidateCRC32() && pass;
@ -806,6 +808,37 @@ bool TestSecBlock()
}
#endif
#if !defined(NDEBUG) && !defined(CRYPTOPP_IMPORTS)
bool TestHuffmanCodes()
{
cout << "\nTesting Huffman codes...\n\n";
static const size_t nCodes = 30;
const unsigned int codeCounts[nCodes] = {
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static const unsigned int maxCodeBits = nCodes >> 1;
unsigned int codeBits[nCodes] = {
~0u, ~0u, ~0u, ~0u, ~0u,
~0u, ~0u, ~0u, ~0u, ~0u,
~0u, ~0u, ~0u, ~0u, ~0u,
};
try
{
HuffmanEncoder::GenerateCodeLengths(codeBits, maxCodeBits, codeCounts, nCodes);
}
catch(const Exception& ex)
{
return false;
}
return true;
}
#endif
bool TestOS_RNG()
{
bool pass = true;

View File

@ -91,6 +91,7 @@ bool ValidateESIGN();
#if !defined(NDEBUG)
bool TestSecBlock();
bool TestPolynomialMod2();
bool TestHuffmanCodes();
#endif
// Coverity finding