/* Copyright (C) 2004 by Intra2net AG The software in this package is distributed under the GNU General Public License version 2 (with a special exception described below). A copy of GNU General Public License (GPL) is included in this distribution, in the file COPYING.GPL. As a special exception, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other works to produce a work based on this file, this file does not by itself cause the resulting work to be covered by the GNU General Public License. However the source code for this file must still be made available in accordance with section (3) of the GNU General Public License. This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. */ #include #include #include #include #include #include #include #include #include #include #include class VerboseTimingListener : public CppUnit::TestListener { private: double start_time; std::string resultstr; double get_time(void) { struct timeb tb; ftime(&tb); return tb.time+(static_cast(tb.millitm)/1000); } public: void startTest( CppUnit::Test *test ) { resultstr="OK"; std::cout << test->getName() << ": "; start_time=get_time(); } void endTest( CppUnit::Test *test ) { double timediff=get_time()-start_time; // fix clock unpreciseness for small timespans if (timediff < 0) timediff=0; std::cout << resultstr << " (" << std::fixed << std::setprecision(3) << timediff << " sec)" << std::endl; } void addFailure(const CppUnit::TestFailure &failure) { if(failure.isError()) resultstr="ERROR"; else resultstr="FAIL"; } }; int main(int argc, char **argv) { CppUnit::TextTestRunner runner; CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); // set output format that KDevelop can catch errors CppUnit::CompilerOutputter *op=CppUnit::CompilerOutputter::defaultOutputter(&runner.result(),std::cout); op->setLocationFormat("%p:%l: error: "); runner.setOutputter(op); // show every test with timing VerboseTimingListener listener; runner.eventManager().addListener(&listener); runner.addTest(registry.makeTest()); // run all tests in registry (not using the default progress listener) bool wasSucessful = runner.run("",false,true,false); return (wasSucessful ? 0 : 1); }