44 #define BOOST_TEST_DYN_LINK 45 #define BOOST_TEST_MODULE uhalTests 48 #define BOOST_TEST_NO_MAIN 51 #include <boost/program_options.hpp> 52 #include <boost/test/unit_test.hpp> 53 #if BOOST_VERSION >= 105900 54 #include <boost/test/tree/traverse.hpp> 55 #include <boost/test/tree/visitor.hpp> 61 #include "uhal/log/log.hpp" 72 maxDepth(aMaxDepth == 0 ?
std::numeric_limits<size_t>::max() : aMaxDepth)
75 void visit( boost::unit_test::test_case
const& test )
77 if ((level+1) <= maxDepth)
78 std::cout << std::string(2 * (level > 2 ? level - 2 : 0),
' ') <<
" └> " << test.p_name << std::endl;
85 if (level <= maxDepth)
86 std::cout << std::string(2 * (level > 2 ? level - 2 : 0),
' ') << (level > 1 ?
"└ " :
"") << suite.p_name << std::endl;
105 int BOOST_TEST_CALL_DECL
108 namespace po = boost::program_options;
110 size_t lListDepth = 0;
112 po::options_description lDesc (
"Allowed options" );
114 ( (
kOptionHelp +
",h").c_str(),
"produce help message" )
115 ( (
kOptionList +
",l").c_str(), po::value<size_t>(&lListDepth)->implicit_value(0),
"List all test suites and test cases (max depth can be specified if wanted; if not, all depths are shown)" )
116 ( (
kOptionConnFile +
",c").c_str(), po::value<std::string>(&AbstractFixture::connectionFileURI),
"Connection file URI" )
120 po::variables_map vm;
123 std::vector<std::string> lOptionsForBoostUTF;
126 po::parsed_options lParsedOptions = po::command_line_parser(argc, argv).options(lDesc).allow_unregistered().run();
127 po::store ( lParsedOptions, vm );
129 lOptionsForBoostUTF = po::collect_unrecognized(lParsedOptions.options, po::include_positional);
131 catch ( std::exception& e )
133 std::cerr <<
"ERROR : " << e.what() << std::endl << std::endl;
134 std::cout <<
"Usage : " << argv[0] <<
" [OPTIONS]" << std::endl;
135 std::cout << lDesc << std::endl;
141 std::cout <<
"Usage: " << argv[0] <<
" [OPTIONS]" << std::endl;
142 std::cout << lDesc << std::endl;
149 boost::unit_test::traverse_test_tree( boost::unit_test::framework::master_test_suite(), lVisitor);
154 std::cerr <<
" ERROR : Option '" <<
kOptionConnFile <<
"' must be specified under normal running mode." << std::endl << std::endl;
155 std::cout <<
"Usage: " << argv[0] <<
" [OPTIONS]" << std::endl;
156 std::cout << lDesc << std::endl;
160 std::cout <<
"Supplied arguments ..." << std::endl;
161 std::cout <<
" connection file = " << AbstractFixture::connectionFileURI << std::endl;
163 std::cout <<
"Log level set to ";
166 std::cout <<
"DEBUG";
170 std::cout <<
"NOTICE";
174 std::cout <<
"FATAL";
176 std::cout << std::endl << std::endl;
179 std::vector<const char*> lArgvForBoostUTF;
180 lArgvForBoostUTF.push_back(argv[0]);
181 if (lOptionsForBoostUTF.empty())
182 std::cout <<
"N.B. Didn't find any arguments/options to pass to boost UTF" << std::endl;
184 std::cout <<
"Passing " << lOptionsForBoostUTF.size() <<
" arguments/options to boost UTF:" << std::endl <<
" ";
185 for (
size_t i=0; i<lOptionsForBoostUTF.size(); i++) {
186 std::cout <<
" " << lOptionsForBoostUTF.at(i);
187 lArgvForBoostUTF.push_back(lOptionsForBoostUTF.at(i).c_str());
190 std::cout << std::endl << std::endl;
192 lArgvForBoostUTF.push_back(0);
193 return ::boost::unit_test::unit_test_main( &init_unit_test, lArgvForBoostUTF.size()-1,
const_cast<char**
>(lArgvForBoostUTF.data()) );
bool test_suite_start(boost::unit_test::test_suite const &suite)
ListWritingVisitor(const size_t aMaxDepth)
const std::string kOptionVerbose
const std::string kOptionConnFile
const std::string kOptionHelp
void visit(boost::unit_test::test_case const &test)
int BOOST_TEST_CALL_DECL main(int argc, char *argv[])
const std::string kOptionVeryVerbose
const std::string kOptionList
void test_suite_finish(boost::unit_test::test_suite const &suite)