15 #include <cppunit/BriefTestProgressListener.h> 16 #include <cppunit/CompilerOutputter.h> 17 #include <cppunit/TestResult.h> 18 #include <cppunit/TestResultCollector.h> 19 #include <cppunit/TestRunner.h> 20 #include <cppunit/TextTestProgressListener.h> 21 #include <cppunit/XmlOutputter.h> 22 #include <cppunit/extensions/TestFactoryRegistry.h> 24 #ifdef BUNDLE_TEST_PROFILE 26 #include <boost/filesystem/operations.hpp> 27 #include <boost/filesystem/path.hpp> 29 #include <fwRuntime/operations.hpp> 30 #include <fwRuntime/profile/Profile.hpp> 31 #include <fwRuntime/io/ProfileReader.hpp> 36 MiniLauncher( ::boost::filesystem::path profilePath )
43 if (!::boost::filesystem::exists( profilePath ))
45 profilePath = cwd / profilePath;
48 if (!::boost::filesystem::exists( profilePath ))
50 throw (std::invalid_argument(
"<" + profilePath.string() +
"> not found." ));
54 ::fwRuntime::profile::setCurrentProfile(m_profile);
56 m_profile->setParams(0, NULL);
66 ::fwRuntime::profile::setCurrentProfile(m_profile);
70 ::fwRuntime::profile::Profile::sptr m_profile;
81 std::string xmlReportFile;
82 std::vector< std::string > testsToRun;
84 #ifdef BUNDLE_TEST_PROFILE 92 #ifdef BUNDLE_TEST_PROFILE 94 profile( BUNDLE_TEST_PROFILE )
101 bool parse(
int argc,
char* argv[])
108 std::string programName( *argv != 0 ? *argv :
"test_runner" );
110 char** args = argv + 1;
111 char** argsEnd = argv + argc;
112 while (args < argsEnd)
114 std::string arg(*args);
116 if(arg ==
"--help" || arg ==
"-h")
119 <<
"usage : " << programName <<
" " 120 <<
"[--help|-h] [--verbose|-v] [--xml|-x] [-o FILE] [--list|-l] [test1 ... testN]" 122 <<
" -h,--help Shows this help" << std::endl
123 <<
" -s,--verbose Shows each run test name and it status" << std::endl
124 <<
" -x,--xml Output results to a xml file" << std::endl
125 <<
" -o FILE Specify xml file name" << std::endl
126 <<
" -l,--list Lists test names" << std::endl
127 #ifdef BUNDLE_TEST_PROFILE 128 <<
" -p,--profile Profile to launch for bundle tests" << std::endl
130 <<
" test1 ... testN Test names to run" << std::endl
134 else if( arg ==
"--verbose" || arg ==
"-v")
136 this->verbose =
true;
138 else if( arg ==
"--xml" || arg ==
"-x")
140 this->xmlReport =
true;
142 else if( arg ==
"-o")
147 std::cerr <<
"value for -o is missing" << std::endl;
150 this->xmlReportFile = std::string(*args);
152 else if( arg ==
"--list" || arg ==
"-l")
154 this->listTests =
true;
156 #ifdef BUNDLE_TEST_PROFILE 157 else if( arg ==
"--profile" || arg ==
"-p")
162 std::cerr <<
"value for -p/--profile is missing" << std::endl;
165 this->profile = std::string(*args);
170 this->testsToRun.push_back(arg);
181 class SynchronizationObject;
186 TestLister( SynchronizationObject* syncObject = 0 )
192 virtual void startTest( Test* test )
194 std::cout << test->getName() << std::endl;
199 virtual void runTest( Test* test )
206 virtual bool protect(
const Functor& functor,
208 const std::string& shortDescription = std::string(
"") )
218 int main(
int argc,
char* argv[] )
223 std::string testExecutable = (argc >= 1) ? std::string(argv[0]) :
"unknown";
224 options.xmlReportFile = testExecutable +
"-cppunit-report.xml";
226 if (!options.parse(argc, argv))
231 #ifdef BUNDLE_TEST_PROFILE 232 MiniLauncher miniLaucher( options.profile );
235 CPPUNIT_NS::Test* testSuite = CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
238 CPPUNIT_NS::TestRunner runner;
239 runner.addTest( testSuite );
241 if( options.listTests )
243 CPPUNIT_NS::TestLister lister;
244 runner.run( lister );
249 CPPUNIT_NS::TestResult controller;
252 CPPUNIT_NS::TestResultCollector result;
253 controller.addListener( &result );
256 CPPUNIT_NS::BriefTestProgressListener BriefProgress;
259 CPPUNIT_NS::TextTestProgressListener textProgress;
263 controller.addListener( &BriefProgress );
267 controller.addListener( &textProgress );
270 if(options.testsToRun.empty())
272 options.testsToRun.push_back(
"");
275 std::vector< std::string >::const_iterator iter = options.testsToRun.begin();
277 for(; iter != options.testsToRun.end(); ++iter)
281 runner.run( controller, *iter );
283 catch ( std::exception& e )
285 std::cerr <<
"[" << ((iter->empty()) ?
"All tests" : *iter) <<
"]" <<
"Error: " << e.what() << std::endl;
290 std::cerr <<
"[" << ((iter->empty()) ?
"All tests" : *iter) <<
"]" <<
"Unexpected error. " << std::endl;
296 CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
299 if(options.xmlReport)
301 std::ofstream file( options.xmlReportFile.c_str() );
302 CPPUNIT_NS::XmlOutputter xml( &result, file );
307 if (result.testFailuresTotal())
static FWRUNTIME_API Runtime * getDefault()
Retrieves the default runtime instance.
Defines the runtime class.
static FWRUNTIME_API std::shared_ptr< ::fwRuntime::profile::Profile > createProfile(const boost::filesystem::path &path)
Creates a profile from an xml file located at the given path.
FWRUNTIME_API void addDefaultBundles()
Adds all bundle found at the default location.
FWRUNTIME_API::boost::filesystem::path getWorkingPath() const
Get the path where Bundles and share folder are located.