diff --git a/CMakeLists.txt b/CMakeLists.txt index eac631a..e254c99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -338,7 +338,7 @@ target_link_libraries( task_cancel_test fc ) add_executable( bloom_test tests/bloom_test.cpp ) target_link_libraries( bloom_test fc ) -add_executable( real128_test tests/real128_test.cpp ) +add_executable( real128_test tests/all_tests.cpp tests/real128_test.cpp ) target_link_libraries( real128_test fc ) @@ -358,7 +358,7 @@ 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 ) +add_executable( all_tests tests/all_tests.cpp tests/compress.cpp tests/real128_test.cpp ) target_link_libraries( all_tests fc ) if(WIN32) diff --git a/tests/aes_test.cpp b/tests/aes_test.cpp index 4b85134..4635258 100644 --- a/tests/aes_test.cpp +++ b/tests/aes_test.cpp @@ -1,46 +1,70 @@ +#include + +#include #include #include #include #include #include -int main( int argc, char** ) + +BOOST_AUTO_TEST_SUITE(fc_crypto) + +BOOST_AUTO_TEST_CASE(aes_test) { - std::string line; - std::getline( std::cin, line ); - auto key = fc::sha512::hash( "hello", 5 ); - while( std::cin && line != "q" ) - { - try { - std::vector data( line.c_str(),line.c_str()+line.size()+1 ); - std::vector crypt = fc::aes_encrypt( key, data ); - std::vector dcrypt = fc::aes_decrypt( key, crypt ); + std::ifstream testfile; + testfile.open("README.md"); - std::cout<<"line.size: '"< data( line.c_str(),line.c_str()+line.size()+1 ); + std::vector crypt = fc::aes_encrypt( key, data ); + std::vector dcrypt = fc::aes_decrypt( key, crypt ); + BOOST_CHECK( data == dcrypt ); + +// memset( crypt.data(), 0, crypt.size() ); +// fc::aes_encoder enc; +// enc.init( fc::sha256::hash((char*)&key,sizeof(key) ), fc::city_hash_crc_128( (char*)&key, sizeof(key) ) ); +// auto len = enc.encode( dcrypt.data(), dcrypt.size(), crypt.data() ); +// BOOST_CHECK_EQUAL( dcrypt.size(), len ); +// +// fc::aes_decoder dec; +// dec.init( fc::sha256::hash((char*)&key,sizeof(key) ), fc::city_hash_crc_128( (char*)&key, sizeof(key) ) ); +// len = dec.decode( crypt.data(), len, dcrypt.data() ); +// BOOST_CHECK_EQUAL( dcrypt.size(), len ); +// BOOST_CHECK( !memcmp( dcrypt.data(), data.data(), len) ); + } + catch ( fc::exception& e ) + { + std::cout< data( line.c_str(),line.c_str()+line.size()+1 ); + std::vector crypt = fc::aes_encrypt( key, data ); + std::vector dcrypt = fc::aes_decrypt( key, crypt ); + BOOST_CHECK( data == dcrypt ); + +// memset( crypt.data(), 0, crypt.size() ); +// fc::aes_encoder enc; +// enc.init( fc::sha256::hash((char*)&key,sizeof(key) ), fc::city_hash_crc_128( (char*)&key, sizeof(key) ) ); +// auto len = enc.encode( dcrypt.data(), dcrypt.size(), crypt.data() ); +// BOOST_CHECK_EQUAL( dcrypt.size(), len ); +// +// fc::aes_decoder dec; +// dec.init( fc::sha256::hash((char*)&key,sizeof(key) ), fc::city_hash_crc_128( (char*)&key, sizeof(key) ) ); +// len = dec.decode( crypt.data(), len, dcrypt.data() ); +// BOOST_CHECK_EQUAL( dcrypt.size(), len ); +// BOOST_CHECK( !memcmp( dcrypt.data(), data.data(), len) ); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/real128_test.cpp b/tests/real128_test.cpp index 76164fc..beae9b7 100644 --- a/tests/real128_test.cpp +++ b/tests/real128_test.cpp @@ -1,8 +1,9 @@ #include -#define BOOST_TEST_MODULE Real128Test #include #include +BOOST_AUTO_TEST_SUITE(fc) + using fc::real128; using std::string; @@ -50,3 +51,5 @@ BOOST_AUTO_TEST_CASE(real128_test) wdump((real128("12345.6789")) ); wdump( (ten/3*3) ); } + +BOOST_AUTO_TEST_SUITE_END()