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;
|
pass=TestSecBlock() && pass;
|
||||||
// http://github.com/weidai11/cryptopp/issues/64
|
// http://github.com/weidai11/cryptopp/issues/64
|
||||||
pass=TestPolynomialMod2() && pass;
|
pass=TestPolynomialMod2() && pass;
|
||||||
|
// http://github.com/weidai11/cryptopp/pull/242
|
||||||
|
pass=TestHuffmanCodes() && pass;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pass=ValidateCRC32() && pass;
|
pass=ValidateCRC32() && pass;
|
||||||
|
|
@ -806,6 +808,37 @@ bool TestSecBlock()
|
||||||
}
|
}
|
||||||
#endif
|
#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 TestOS_RNG()
|
||||||
{
|
{
|
||||||
bool pass = true;
|
bool pass = true;
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,7 @@ bool ValidateESIGN();
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
bool TestSecBlock();
|
bool TestSecBlock();
|
||||||
bool TestPolynomialMod2();
|
bool TestPolynomialMod2();
|
||||||
|
bool TestHuffmanCodes();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Coverity finding
|
// Coverity finding
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue