Browse Source

Style

cl-refactor
Dimitry 9 years ago
parent
commit
e8dae6ea35
  1. 2
      test/TestHelper.h
  2. 15
      test/boostTest.cpp
  3. 23
      test/fuzzTesting/createRandomTest.cpp

2
test/TestHelper.h

@ -178,7 +178,7 @@ json_spirit::mObject fillJsonWithState(eth::State _state);
json_spirit::mObject fillJsonWithTransaction(eth::Transaction _txn); json_spirit::mObject fillJsonWithTransaction(eth::Transaction _txn);
//Fill Test Functions //Fill Test Functions
int createRandomTest(int argc, char *argv[]); int createRandomTest(std::vector<char*> const& args);
void doTransactionTests(json_spirit::mValue& _v, bool _fillin); void doTransactionTests(json_spirit::mValue& _v, bool _fillin);
void doStateTests(json_spirit::mValue& v, bool _fillin); void doStateTests(json_spirit::mValue& v, bool _fillin);
void doVMTests(json_spirit::mValue& v, bool _fillin); void doVMTests(json_spirit::mValue& v, bool _fillin);

15
test/boostTest.cpp

@ -32,8 +32,7 @@
using namespace boost::unit_test; using namespace boost::unit_test;
char** originalArgv; std::vector<char*> originalArgs;
int originalArgc;
static std::ostringstream strCout; static std::ostringstream strCout;
std::streambuf* oldCoutStreamBuf; std::streambuf* oldCoutStreamBuf;
@ -46,17 +45,17 @@ test_suite* init_func( int argc, char* argv[] )
//restore output for creating test //restore output for creating test
std::cout.rdbuf(oldCoutStreamBuf); std::cout.rdbuf(oldCoutStreamBuf);
std::cerr.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) if (opt.createRandomTest)
{ {
//For no reason BOOST tend to remove valuable arg -t "TestSuiteName", so using original parametrs instead //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!"); throw framework::internal_error("Create Random Test Error!");
else else
{ {
//disable post output so the test json would be clean //disable post output so the test json would be clean
std::cout.rdbuf( strCout.rdbuf() ); std::cout.rdbuf(strCout.rdbuf());
std::cerr.rdbuf( strCout.rdbuf() ); std::cerr.rdbuf(strCout.rdbuf());
throw framework::nothing_to_test(); throw framework::nothing_to_test();
} }
} }
@ -66,10 +65,8 @@ test_suite* init_func( int argc, char* argv[] )
//Custom Boost Unit Test Main //Custom Boost Unit Test Main
int main( int argc, char* argv[] ) int main( int argc, char* argv[] )
{ {
originalArgc = argc;
originalArgv = new char*[argc];
for (int i = 0; i < argc; i++) for (int i = 0; i < argc; i++)
originalArgv[i] = argv[i]; originalArgs.push_back(argv[i]);
//disable initial output //disable initial output
oldCoutStreamBuf = std::cout.rdbuf(); oldCoutStreamBuf = std::cout.rdbuf();

23
test/fuzzTesting/createRandomTest.cpp

@ -43,7 +43,7 @@ std::vector<std::string> getTypes();
void parseTestWithTypes(std::string& test); void parseTestWithTypes(std::string& test);
namespace dev { namespace test { namespace dev { namespace test {
int createRandomTest(int argc, char *argv[]) int createRandomTest(std::vector<char*> const& args)
{ {
std::string testSuite; std::string testSuite;
std::string testFillString; std::string testFillString;
@ -52,29 +52,30 @@ int createRandomTest(int argc, char *argv[])
bool filldebug = false; bool filldebug = false;
bool debug = false; bool debug = false;
bool filltest = 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&>(dev::test::Options::get()); dev::test::Options& options = const_cast<dev::test::Options&>(dev::test::Options::get());
if (arg == "--fulloutput") if (arg == "--fulloutput")
options.fulloutput = true; options.fulloutput = true;
else 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" if (testSuite != "BlockChainTests" && testSuite != "TransactionTests" && testSuite != "StateTests"
&& testSuite != "VMTests" && testSuite != "RLPTests") && testSuite != "VMTests" && testSuite != "RLPTests")
testSuite = ""; testSuite = "";
} }
else else
if ((arg == "-checktest" || arg == "-filltest") && i + 1 < argc) if ((arg == "-checktest" || arg == "-filltest") && i + 1 < args.size())
{ {
std::string s; std::string s;
for (int j = i+1; j < argc; ++j) for (unsigned j = i+1; j < args.size(); ++j)
s += argv[j]; s += args.at(j);
if (asserts(s.length() > 0)) 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; return 1;
} }
if (arg == "-filltest") if (arg == "-filltest")
@ -98,7 +99,7 @@ int createRandomTest(int argc, char *argv[])
if (testSuite == "") 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; return 1;
} }
else else
@ -152,7 +153,7 @@ int createRandomTest(int argc, char *argv[])
return 0; return 0;
} }
}} //namesapces }} //namespaces
int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> _doTests, json_spirit::mValue& _value, bool _debug) int checkRandomTest(std::function<void(json_spirit::mValue&, bool)> _doTests, json_spirit::mValue& _value, bool _debug)
{ {

Loading…
Cancel
Save