Re-enabled + refactored compress test, added zlib test case

This commit is contained in:
Peter Conrad 2015-07-22 22:18:12 +02:00
parent a31f0f503d
commit 39b47c36f0
3 changed files with 87 additions and 21 deletions

View file

@ -351,8 +351,6 @@ target_link_libraries( udt_client fc udt )
add_executable( ecc_test tests/ecc_test.cpp )
target_link_libraries( ecc_test fc )
#add_executable( test_compress tests/compress.cpp )
#target_link_libraries( test_compress fc )
#add_executable( test_aes tests/aes_test.cpp )
#target_link_libraries( test_aes fc ${rt_library} ${pthread_library} )
#add_executable( test_sleep tests/sleep.cpp )
@ -360,6 +358,9 @@ target_link_libraries( ecc_test fc )
#add_executable( test_rate_limiting tests/rate_limiting.cpp )
#target_link_libraries( test_rate_limiting fc )
add_executable( all_tests tests/all_tests.cpp tests/compress.cpp )
target_link_libraries( all_tests fc )
if(WIN32)
# add addtional import library on windows platform
target_link_libraries( fc PUBLIC crypt32.lib)

3
tests/all_tests.cpp Normal file
View file

@ -0,0 +1,3 @@
#define BOOST_TEST_MODULE AllTests
#include <boost/test/unit_test.hpp>

View file

@ -1,27 +1,89 @@
#include <boost/test/unit_test.hpp>
#include <fstream>
#include <iostream>
#include <fc/compress/smaz.hpp>
#include <fc/compress/zlib.hpp>
#include <fc/exception/exception.hpp>
int main( int argc, char** )
BOOST_AUTO_TEST_SUITE(compress)
BOOST_AUTO_TEST_CASE(smaz_test)
{
std::string line;
std::getline( std::cin, line );
while( std::cin && line != "q" )
{
try {
std::string compressed = fc::smaz_compress( line );
std::cout<<"compressed size: "<<compressed.size()<<"\n";
std::string decomp = fc::smaz_decompress( compressed );
std::cout<<"decomp: '"<<decomp<<"'\n";
std::cout<<"line: '"<<line<<"'\n";
FC_ASSERT( decomp == line );
}
catch ( fc::exception& e )
std::ifstream testfile;
testfile.open("README.md");
std::stringstream buffer;
std::string line;
std::getline( testfile, line );
while( testfile.good() )
{
std::cout<<e.to_detail_string()<<"\n";
buffer << line << "\n";
try {
std::string compressed = fc::smaz_compress( line );
std::string decomp = fc::smaz_decompress( compressed );
BOOST_CHECK_EQUAL( decomp, line );
}
catch ( fc::exception& e )
{
std::cout<<e.to_detail_string()<<"\n";
}
std::getline( testfile, line );
}
std::getline( std::cin, line );
}
return 0;
line = buffer.str();
std::string compressed = fc::smaz_compress( line );
std::string decomp = fc::smaz_decompress( compressed );
BOOST_CHECK_EQUAL( decomp, line );
}
extern "C" {
enum
{
TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
TINFL_FLAG_HAS_MORE_INPUT = 2,
TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4,
TINFL_FLAG_COMPUTE_ADLER32 = 8
};
extern char* tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
}
static std::string zlib_decompress( const std::string compressed )
{
size_t decomp_len;
char* decomp = tinfl_decompress_mem_to_heap( compressed.c_str(), compressed.length(), &decomp_len, TINFL_FLAG_PARSE_ZLIB_HEADER );
std::string result( decomp, decomp_len );
free( decomp );
return result;
}
BOOST_AUTO_TEST_CASE(zlib_test)
{
std::ifstream testfile;
testfile.open("README.md");
std::stringstream buffer;
std::string line;
std::getline( testfile, line );
while( testfile.good() )
{
buffer << line << "\n";
std::string compressed = fc::zlib_compress( line );
std::string decomp = zlib_decompress( compressed );
BOOST_CHECK_EQUAL( decomp, line );
std::getline( testfile, line );
}
line = buffer.str();
std::string compressed = fc::zlib_compress( line );
std::string decomp = zlib_decompress( compressed );
BOOST_CHECK_EQUAL( decomp, line );
}
BOOST_AUTO_TEST_SUITE_END()