From e8dae6ea35538a5c9020498d2b0604efb40de856 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Tue, 18 Aug 2015 13:33:29 +0300 Subject: [PATCH] Style --- test/TestHelper.h | 2 +- test/boostTest.cpp | 15 ++++++--------- test/fuzzTesting/createRandomTest.cpp | 23 ++++++++++++----------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/test/TestHelper.h b/test/TestHelper.h index a35325b65..3e38bf99a 100644 --- a/test/TestHelper.h +++ b/test/TestHelper.h @@ -178,7 +178,7 @@ json_spirit::mObject fillJsonWithState(eth::State _state); json_spirit::mObject fillJsonWithTransaction(eth::Transaction _txn); //Fill Test Functions -int createRandomTest(int argc, char *argv[]); +int createRandomTest(std::vector const& args); void doTransactionTests(json_spirit::mValue& _v, bool _fillin); void doStateTests(json_spirit::mValue& v, bool _fillin); void doVMTests(json_spirit::mValue& v, bool _fillin); diff --git a/test/boostTest.cpp b/test/boostTest.cpp index db31e0d1e..8cae101f9 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -32,8 +32,7 @@ using namespace boost::unit_test; -char** originalArgv; -int originalArgc; +std::vector originalArgs; static std::ostringstream strCout; std::streambuf* oldCoutStreamBuf; @@ -46,17 +45,17 @@ test_suite* init_func( int argc, char* argv[] ) //restore output for creating test std::cout.rdbuf(oldCoutStreamBuf); std::cerr.rdbuf(oldCoutStreamBuf); - const dev::test::Options& opt = dev::test::Options::get(); + const auto& opt = dev::test::Options::get(); if (opt.createRandomTest) { //For no reason BOOST tend to remove valuable arg -t "TestSuiteName", so using original parametrs instead - if (dev::test::createRandomTest(originalArgc, originalArgv)) + if (dev::test::createRandomTest(originalArgs)) throw framework::internal_error("Create Random Test Error!"); else { //disable post output so the test json would be clean - std::cout.rdbuf( strCout.rdbuf() ); - std::cerr.rdbuf( strCout.rdbuf() ); + std::cout.rdbuf(strCout.rdbuf()); + std::cerr.rdbuf(strCout.rdbuf()); throw framework::nothing_to_test(); } } @@ -66,10 +65,8 @@ test_suite* init_func( int argc, char* argv[] ) //Custom Boost Unit Test Main int main( int argc, char* argv[] ) { - originalArgc = argc; - originalArgv = new char*[argc]; for (int i = 0; i < argc; i++) - originalArgv[i] = argv[i]; + originalArgs.push_back(argv[i]); //disable initial output oldCoutStreamBuf = std::cout.rdbuf(); diff --git a/test/fuzzTesting/createRandomTest.cpp b/test/fuzzTesting/createRandomTest.cpp index ea63ada79..373df595f 100644 --- a/test/fuzzTesting/createRandomTest.cpp +++ b/test/fuzzTesting/createRandomTest.cpp @@ -43,7 +43,7 @@ std::vector getTypes(); void parseTestWithTypes(std::string& test); namespace dev { namespace test { -int createRandomTest(int argc, char *argv[]) +int createRandomTest(std::vector const& args) { std::string testSuite; std::string testFillString; @@ -52,29 +52,30 @@ int createRandomTest(int argc, char *argv[]) bool filldebug = false; bool debug = false; bool filltest = false; - for (auto i = 0; i < argc; ++i) + + for (unsigned i = 0; i < args.size(); ++i) { - auto arg = std::string{argv[i]}; + auto arg = std::string{args.at(i)}; dev::test::Options& options = const_cast(dev::test::Options::get()); if (arg == "--fulloutput") options.fulloutput = true; else - if (arg == "-t" && i + 1 < argc) + if (arg == "-t" && i + 1 < args.size()) { - testSuite = argv[i + 1]; + testSuite = args.at(i+1); if (testSuite != "BlockChainTests" && testSuite != "TransactionTests" && testSuite != "StateTests" && testSuite != "VMTests" && testSuite != "RLPTests") testSuite = ""; } else - if ((arg == "-checktest" || arg == "-filltest") && i + 1 < argc) + if ((arg == "-checktest" || arg == "-filltest") && i + 1 < args.size()) { std::string s; - for (int j = i+1; j < argc; ++j) - s += argv[j]; + for (unsigned j = i+1; j < args.size(); ++j) + s += args.at(j); if (asserts(s.length() > 0)) { - std::cout << "Error! Content of argument is empty! (Usage -checktest textstream)" << std::endl; + std::cerr << "Error! Content of argument is empty! (Usage -checktest textstream)" << std::endl; return 1; } if (arg == "-filltest") @@ -98,7 +99,7 @@ int createRandomTest(int argc, char *argv[]) if (testSuite == "") { - std::cout << "Error! Test suite not supported! (Usage -t TestSuite)" << std::endl; + std::cerr << "Error! Test suite not supported! (Usage -t TestSuite)" << std::endl; return 1; } else @@ -152,7 +153,7 @@ int createRandomTest(int argc, char *argv[]) return 0; } -}} //namesapces +}} //namespaces int checkRandomTest(std::function _doTests, json_spirit::mValue& _value, bool _debug) {