Add test for Huffman codes (Issue 242)
parent
5f4b1d4ca9
commit
1e7c837442
33
validat1.cpp
33
validat1.cpp
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ bool ValidateESIGN();
|
|||
#if !defined(NDEBUG)
|
||||
bool TestSecBlock();
|
||||
bool TestPolynomialMod2();
|
||||
bool TestHuffmanCodes();
|
||||
#endif
|
||||
|
||||
// Coverity finding
|
||||
|
|
|
|||
Loading…
Reference in New Issue