From ec0581d0421bdd4eb8de682758fe0b481cf0f59f Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 21 Sep 2011 09:10:44 +0100 Subject: add a simple timer for unit tests --- sal/cppunittester/cppunittester.cxx | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'sal') diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx index 49ae0b3e7338..c1904b485974 100644 --- a/sal/cppunittester/cppunittester.cxx +++ b/sal/cppunittester/cppunittester.cxx @@ -86,10 +86,34 @@ std::string convertLazy(rtl::OUString const & s16) { : static_cast< std::string::size_type >(s8.getLength()))); } +//Output how long each test took +class TimingListener + : public CppUnit::TestListener + , private boost::noncopyable +{ +public: + void startTest( CppUnit::Test *) + { + m_nStartTime = osl_getGlobalTimer(); + } + + void endTest( CppUnit::Test *test ) + { + sal_uInt32 nEndTime = osl_getGlobalTimer(); + std::cout << test->getName() << ": " << nEndTime-m_nStartTime + << "ms" << std::endl; + } + +private: + sal_uInt32 m_nStartTime; +}; + //Allow the whole uniting testing framework to be run inside a "Protector" //which knows about uno exceptions, so it can print the content of the //exception before falling over and dying -class CPPUNIT_API ProtectedFixtureFunctor : public CppUnit::Functor, private boost::noncopyable +class CPPUNIT_API ProtectedFixtureFunctor + : public CppUnit::Functor + , private boost::noncopyable { private: const std::string &testlib; @@ -106,11 +130,20 @@ public: { CppUnit::PlugInManager manager; manager.load(testlib, args); + CppUnit::TestRunner runner; runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); + CppUnit::TestResultCollector collector; result.addListener(&collector); + +#ifdef TIMETESTS + TimingListener timer; + result.addListener(&timer); +#endif + runner.run(result); + CppUnit::CompilerOutputter(&collector, CppUnit::stdCErr()).write(); return collector.wasSuccessful(); } @@ -119,6 +152,7 @@ public: return run(); } }; + } SAL_IMPLEMENT_MAIN() { -- cgit