From 44345ce4c91f4b7d52a929ae4962963482ddc5cd Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 01:48:54 +0000 Subject: [PATCH] Init unit test suite for all unit test apps Move the init_unit_test_suite(...) function to a hpp file and include it in every unit test app: - app_test - chain_test - cli_test - es_test - performance_test --- tests/app/main.cpp | 5 +-- tests/cli/main.cpp | 5 +-- tests/common/init_unit_test_suite.hpp | 42 +++++++++++++++++++++++++ tests/elasticsearch/main.cpp | 3 +- tests/performance/performance_tests.cpp | 8 +---- tests/tests/main.cpp | 20 +----------- 6 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 tests/common/init_unit_test_suite.hpp diff --git a/tests/app/main.cpp b/tests/app/main.cpp index a0d1b9b168..6afc8969a8 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -42,11 +42,12 @@ #include "../../libraries/app/application_impl.hxx" -#define BOOST_TEST_MODULE Test Application -#include +#include "../common/init_unit_test_suite.hpp" #include "../common/genesis_file_util.hpp" +uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP = 1431700000; // needed for compiling, not used + using namespace graphene; namespace bpo = boost::program_options; diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index cdaa707e3b..c0f3396ee5 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -60,8 +60,9 @@ #include -#define BOOST_TEST_MODULE Test Application -#include +#include "../common/init_unit_test_suite.hpp" + +uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP = 1431700000; // needed for compiling, not used /***** * Global Initialization for Windows diff --git a/tests/common/init_unit_test_suite.hpp b/tests/common/init_unit_test_suite.hpp new file mode 100644 index 0000000000..0c3e9f7644 --- /dev/null +++ b/tests/common/init_unit_test_suite.hpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include +#include +#include +#include + +extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; + +boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { + const auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count(); + std::srand( seed ); + std::cout << "Random number generator seeded to " << seed << std::endl; + const char* genesis_timestamp_str = getenv("GRAPHENE_TESTING_GENESIS_TIMESTAMP"); + if( genesis_timestamp_str != nullptr ) + { + GRAPHENE_TESTING_GENESIS_TIMESTAMP = std::stoul( genesis_timestamp_str ); + } + std::cout << "GRAPHENE_TESTING_GENESIS_TIMESTAMP is " << GRAPHENE_TESTING_GENESIS_TIMESTAMP << std::endl; + return nullptr; +} diff --git a/tests/elasticsearch/main.cpp b/tests/elasticsearch/main.cpp index 2935a047d8..2b1836a31b 100644 --- a/tests/elasticsearch/main.cpp +++ b/tests/elasticsearch/main.cpp @@ -31,8 +31,7 @@ #include "../common/database_fixture.hpp" -#define BOOST_TEST_MODULE Elastic Search Database Tests -#include +#include "../common/init_unit_test_suite.hpp" #ifdef NDEBUG #define ES_WAIT_TIME (fc::milliseconds(1000)) diff --git a/tests/performance/performance_tests.cpp b/tests/performance/performance_tests.cpp index 152f672189..35d0a1b7cc 100644 --- a/tests/performance/performance_tests.cpp +++ b/tests/performance/performance_tests.cpp @@ -22,13 +22,7 @@ * THE SOFTWARE. */ -#include - -boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { - std::srand(time(NULL)); - std::cout << "Random number generator seeded to " << time(NULL) << std::endl; - return nullptr; -} +#include "../common/init_unit_test_suite.hpp" #include diff --git a/tests/tests/main.cpp b/tests/tests/main.cpp index 0c3e9f7644..48ba3b7e4b 100644 --- a/tests/tests/main.cpp +++ b/tests/tests/main.cpp @@ -21,22 +21,4 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include -#include -#include -#include - -extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; - -boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { - const auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count(); - std::srand( seed ); - std::cout << "Random number generator seeded to " << seed << std::endl; - const char* genesis_timestamp_str = getenv("GRAPHENE_TESTING_GENESIS_TIMESTAMP"); - if( genesis_timestamp_str != nullptr ) - { - GRAPHENE_TESTING_GENESIS_TIMESTAMP = std::stoul( genesis_timestamp_str ); - } - std::cout << "GRAPHENE_TESTING_GENESIS_TIMESTAMP is " << GRAPHENE_TESTING_GENESIS_TIMESTAMP << std::endl; - return nullptr; -} +#include "../common/init_unit_test_suite.hpp"