From 94a18cfccc33ee15b8b1b88354ccf635edabb17c Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Sat, 4 May 2019 16:57:55 -0500 Subject: [PATCH] Roll API tests into all_tests --- .travis.yml | 1 - tests/CMakeLists.txt | 5 +--- tests/{api.cpp => api_tests.cpp} | 42 +++++++++++++++----------------- 3 files changed, 20 insertions(+), 28 deletions(-) rename tests/{api.cpp => api_tests.cpp} (77%) diff --git a/.travis.yml b/.travis.yml index 6b1d981..6aca7d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,6 @@ script: - 'which build-wrapper-linux-x86-64 && build-wrapper-linux-x86-64 --out-dir bw-output make -j 2 || make -j 2' - set -o pipefail - tests/run-parallel-tests.sh tests/all_tests - - tests/api 2>&1 | cat - tests/hmac_test 2>&1 | cat - tests/ecc_test README.md 2>&1 | cat - 'find CMakeFiles/fc.dir -type d | while read d; do gcov -o "$d" "${d/CMakeFiles*.dir/./}"/*.cpp; done >/dev/null' diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e968bb3..9e395c3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,3 @@ - -add_executable( api api.cpp ) -target_link_libraries( api fc ) - if( ECC_IMPL STREQUAL secp256k1 ) add_executable( blind all_tests.cpp crypto/blind.cpp ) target_link_libraries( blind fc ) @@ -55,5 +51,6 @@ add_executable( all_tests all_tests.cpp utf8_test.cpp variant_test.cpp logging_tests.cpp + api_tests.cpp ) target_link_libraries( all_tests fc ) diff --git a/tests/api.cpp b/tests/api_tests.cpp similarity index 77% rename from tests/api.cpp rename to tests/api_tests.cpp index 5734758..b334691 100644 --- a/tests/api.cpp +++ b/tests/api_tests.cpp @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -50,23 +52,15 @@ class some_calculator void on_result2( const std::function& cb, int test ){} std::function _cb; }; -class variant_calculator -{ - public: - double add( fc::variant a, fc::variant b ) { return a.as_double()+b.as_double(); } - double sub( fc::variant a, fc::variant b ) { return a.as_double()-b.as_double(); } - void on_result( const std::function& cb ) { wlog("set callback"); _cb = cb; return ; } - void on_result2( const std::function& cb, int test ){} - std::function _cb; -}; using namespace fc::http; using namespace fc::rpc; #define MAX_DEPTH 10 -int main( int argc, char** argv ) -{ +BOOST_AUTO_TEST_SUITE(api_tests) + +BOOST_AUTO_TEST_CASE(login_test) { try { fc::api calc_api( std::make_shared() ); @@ -90,22 +84,24 @@ int main( int argc, char** argv ) auto remote_calc = remote_login_api->get_calc(); bool remote_triggered = false; remote_calc->on_result( [&remote_triggered]( uint32_t r ) { remote_triggered = true; } ); - FC_ASSERT(remote_calc->add( 4, 5 ) == 9); - FC_ASSERT(remote_triggered); + BOOST_CHECK_EQUAL(remote_calc->add( 4, 5 ), 9); + BOOST_CHECK(remote_triggered); client.reset(); fc::usleep(fc::milliseconds(100)); server.reset(); } FC_LOG_AND_RETHROW() } FC_LOG_AND_RETHROW() +} +BOOST_AUTO_TEST_CASE(optionals_test) { try { auto optionals = std::make_shared(); fc::api oapi(optionals); - FC_ASSERT(oapi->foo("a") == "[\"a\",null,null]"); - FC_ASSERT(oapi->foo("a", "b") == "[\"a\",\"b\",null]"); - FC_ASSERT(oapi->foo("a", "b", "c") == "[\"a\",\"b\",\"c\"]"); - FC_ASSERT(oapi->foo("a", {}, "c") == "[\"a\",null,\"c\"]"); + BOOST_CHECK_EQUAL(oapi->foo("a"), "[\"a\",null,null]"); + BOOST_CHECK_EQUAL(oapi->foo("a", "b"), "[\"a\",\"b\",null]"); + BOOST_CHECK_EQUAL(oapi->foo("a", "b", "c"), "[\"a\",\"b\",\"c\"]"); + BOOST_CHECK_EQUAL(oapi->foo("a", {}, "c"), "[\"a\",null,\"c\"]"); auto server = std::make_shared(); server->on_connection([&]( const websocket_connection_ptr& c ){ @@ -123,16 +119,16 @@ int main( int argc, char** argv ) auto apic = std::make_shared(*con, MAX_DEPTH); auto remote_optionals = apic->get_remote_api(); - FC_ASSERT(remote_optionals->foo("a") == "[\"a\",null,null]"); - FC_ASSERT(remote_optionals->foo("a", "b") == "[\"a\",\"b\",null]"); - FC_ASSERT(remote_optionals->foo("a", "b", "c") == "[\"a\",\"b\",\"c\"]"); - FC_ASSERT(remote_optionals->foo("a", {}, "c") == "[\"a\",null,\"c\"]"); + BOOST_CHECK_EQUAL(remote_optionals->foo("a"), "[\"a\",null,null]"); + BOOST_CHECK_EQUAL(remote_optionals->foo("a", "b"), "[\"a\",\"b\",null]"); + BOOST_CHECK_EQUAL(remote_optionals->foo("a", "b", "c"), "[\"a\",\"b\",\"c\"]"); + BOOST_CHECK_EQUAL(remote_optionals->foo("a", {}, "c"), "[\"a\",null,\"c\"]"); client.reset(); fc::usleep(fc::milliseconds(100)); server.reset(); } FC_LOG_AND_RETHROW() } FC_LOG_AND_RETHROW() - - return 0; } + +BOOST_AUTO_TEST_SUITE_END()