From 3c45877e2aecb7e73392540fdbf82de0bd35156e Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Mon, 10 Nov 2014 17:37:55 +0100 Subject: added generic userDefinedTest function --- TestHelper.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index f5d40f00..306fc956 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -305,6 +305,45 @@ std::string getTestPath() return testPath; } +void userDefinedTest(string testTypeFlag, std::function doTests) +{ + for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) + { + string arg = boost::unit_test::framework::master_test_suite().argv[i]; + if (arg == testTypeFlag) + { + if (i + 1 >= boost::unit_test::framework::master_test_suite().argc) + { + cnote << "Missing filename\nUsage: testeth " << testTypeFlag << " \n"; + return; + } + string filename = boost::unit_test::framework::master_test_suite().argv[i + 1]; + int currentVerbosity = g_logVerbosity; + g_logVerbosity = 12; + try + { + cnote << "Testing user defined test: " << filename; + json_spirit::mValue v; + string s = asString(contents(filename)); + BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. "); + json_spirit::read_string(s, v); + doTests(v, false); + } + catch (Exception const& _e) + { + BOOST_ERROR("Failed Test with Exception: " << diagnostic_information(_e)); + } + catch (std::exception const& _e) + { + BOOST_ERROR("Failed Test with Exception: " << _e.what()); + } + g_logVerbosity = currentVerbosity; + } + else + continue; + } +} + void executeTests(const string& _name, const string& _testPathAppendix, std::function doTests) { string testPath = getTestPath(); -- cgit