diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-09-21 09:10:44 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-09-21 09:47:38 +0100 |
commit | ec0581d0421bdd4eb8de682758fe0b481cf0f59f (patch) | |
tree | b6d32df43e17b11bbbeef973930bc82041e09a19 /sal | |
parent | 41ad3fcdbade66eb3e51f7ea58cafbb5a66b8af4 (diff) |
add a simple timer for unit tests
Diffstat (limited to 'sal')
-rw-r--r-- | sal/cppunittester/cppunittester.cxx | 36 |
1 files changed, 35 insertions, 1 deletions
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() { |