44 #define BOOST_TEST_MODULE uhalTests
47 #define BOOST_TEST_NO_MAIN
50 #include <boost/program_options.hpp>
51 #include <boost/test/unit_test.hpp>
52 #if BOOST_VERSION >= 105900
53 #include <boost/test/tree/traverse.hpp>
54 #include <boost/test/tree/visitor.hpp>
63 #ifdef BOOST_TEST_DYN_LINK
66 struct ListWritingVisitor : boost::unit_test::test_tree_visitor
71 ListWritingVisitor(
const size_t aMaxDepth) :
73 maxDepth(aMaxDepth == 0 ? std::numeric_limits<size_t>::max() : aMaxDepth)
76 void visit( boost::unit_test::test_case
const& test )
78 if ((level+1) <= maxDepth)
79 std::cout << std::string(2 * (level > 2 ? level - 2 : 0),
' ') <<
" └> " << test.p_name << std::endl;
82 bool test_suite_start( boost::unit_test::test_suite
const& suite )
86 if (level <= maxDepth)
87 std::cout << std::string(2 * (level > 2 ? level - 2 : 0),
' ') << (level > 1 ?
"└ " :
"") << suite.p_name << std::endl;
91 void test_suite_finish( boost::unit_test::test_suite
const& suite )
100 const std::string kOptionHelp =
"help";
101 const std::string kOptionList =
"list";
102 const std::string kOptionConnFile =
"connection-file";
103 const std::string kOptionHwTimeout =
"timeout";
104 const std::string kOptionQuickTest =
"quick";
105 const std::string kOptionVerbose =
"verbose";
106 const std::string kOptionVeryVerbose =
"very-verbose";
108 int BOOST_TEST_CALL_DECL
109 main(
int argc,
char* argv[] )
111 namespace po = boost::program_options;
113 size_t lListDepth = 0;
115 po::options_description lDesc (
"Allowed options" );
117 ( (kOptionHelp +
",h").c_str(),
"produce help message" )
118 ( (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)" )
120 ( (kOptionHwTimeout +
",t").c_str(), po::value<size_t>(&
AbstractFixture::timeout)->default_value(1000),
"Timeout for Client/HwInterface (unit: ms)" )
121 ( kOptionQuickTest.c_str(),
"Run brief tests (fewer iterations)" )
122 ( (kOptionVerbose +
",v").c_str(),
"Verbose output" )
123 ( (kOptionVeryVerbose +
",V").c_str(),
"Very verbose output" )
125 po::variables_map vm;
128 std::vector<std::string> lOptionsForBoostUTF;
131 po::parsed_options lParsedOptions = po::command_line_parser(argc, argv).options(lDesc).allow_unregistered().run();
132 po::store ( lParsedOptions, vm );
134 lOptionsForBoostUTF = po::collect_unrecognized(lParsedOptions.options, po::include_positional);
136 catch ( std::exception& e )
138 std::cerr <<
"ERROR : " << e.what() << std::endl << std::endl;
139 std::cout <<
"Usage : " << argv[0] <<
" [OPTIONS]" << std::endl;
140 std::cout << lDesc << std::endl;
144 if ( vm.count ( kOptionHelp ) )
146 std::cout <<
"Usage: " << argv[0] <<
" [OPTIONS]" << std::endl;
147 std::cout << lDesc << std::endl;
151 if ( vm.count ( kOptionList ) )
153 ListWritingVisitor lVisitor(lListDepth);
154 boost::unit_test::traverse_test_tree( boost::unit_test::framework::master_test_suite(), lVisitor);
158 if ( vm.count (kOptionConnFile) == 0)
160 std::cerr <<
" ERROR : Option '" << kOptionConnFile <<
"' must be specified under normal running mode." << std::endl << std::endl;
161 std::cout <<
"Usage: " << argv[0] <<
" [OPTIONS]" << std::endl;
162 std::cout << lDesc << std::endl;
170 std::cout <<
"Supplied arguments ..." << std::endl;
175 std::cout <<
"Log level set to ";
176 if ( vm.count ( kOptionVeryVerbose ) ) {
178 std::cout <<
"DEBUG";
180 else if ( vm.count ( kOptionVerbose ) ) {
182 std::cout <<
"NOTICE";
186 std::cout <<
"FATAL";
188 std::cout << std::endl << std::endl;
191 std::vector<const char*> lArgvForBoostUTF;
192 lArgvForBoostUTF.push_back(argv[0]);
193 if (lOptionsForBoostUTF.empty())
194 std::cout <<
"N.B. Didn't find any arguments/options to pass to boost UTF" << std::endl;
196 std::cout <<
"Passing " << lOptionsForBoostUTF.size() <<
" arguments/options to boost UTF:" << std::endl <<
" ";
197 for (
size_t i=0; i<lOptionsForBoostUTF.size(); i++) {
198 std::cout <<
" " << lOptionsForBoostUTF.at(i);
199 lArgvForBoostUTF.push_back(lOptionsForBoostUTF.at(i).c_str());
202 std::cout << std::endl << std::endl;
204 lArgvForBoostUTF.push_back(0);
205 return ::boost::unit_test::unit_test_main( &init_unit_test, lArgvForBoostUTF.size()-1,
const_cast<char**
>(lArgvForBoostUTF.data()) );