#include <cppunit/Test.h>
#include <iostream>
+#ifdef WIN32
+ #include <windows.h>
+#endif
+
+#ifdef WIN32
+/**
+ Convert the given time structure to milliseconds number
+ @param theTime the time structure to convert
+ @return the calculated number of milliseconds
+*/
+INT64 GetMilliseconds( const FILETIME& theTime )
+{
+ SYSTEMTIME aTime;
+ FileTimeToSystemTime( &theTime, &aTime );
+ INT64 aRes = 0;
+ aRes += aTime.wHour * ( 3600 * 1000 );
+ aRes += aTime.wMinute * ( 60 * 1000 );
+ aRes += aTime.wSecond * ( 1000 );
+ aRes += aTime.wMilliseconds;
+ return aRes;
+}
+#endif
+
+/**
+ Calculate the complete execution time for the current thread
+ @return the calculated time as the number of milliseconds
+*/
+INT64 GetTimeForCurrentThreadInMs()
+{
+#ifdef WIN32
+ FILETIME aCreationTime, anExitTime, aKernelTime, aUserTime;
+ GetThreadTimes( GetCurrentThread(), &aCreationTime, &anExitTime, &aKernelTime, &aUserTime );
+ INT64 aKernelMs = GetMilliseconds( aKernelTime );
+ INT64 aUserMs = GetMilliseconds( aUserTime );
+ return aKernelMs + aUserMs;
+#else
+ struct timespec aTime;
+ clock_gettime( CLOCK_MONOTONIC, &aTime );
+ INT64 aSec = aTime.tv_sec;
+ aSec *= 1000;
+ aSec += aTime.tv_nsec / 1000000;
+ return aSec;
+#endif
+}
+
/**
\brief Constructor
*/
TestLib_Listener::TestLib_Listener()
+: myStart( 0 ), myComplete( 0 )
{
}
*/
void TestLib_Listener::Clear()
{
+ myStart = 0;
+ myComplete = 0;
+}
+
+/**
+ Get complete time of all tests execution in milliseconds
+ @return complete time in milliseconds
+*/
+INT64 TestLib_Listener::GetCompleteTimeInMS() const
+{
+ return myComplete;
}
/**
aName = theTest->getName();
std::cout << aName << "...";
+ myStart = GetTimeForCurrentThreadInMs();
}
/**
*/
void TestLib_Listener::endTest( CppUnit::Test* theTest )
{
- std::cout << std::endl;
+ INT64 aCurTime = GetTimeForCurrentThreadInMs();
+ INT64 anExecTimeMS = aCurTime - myStart;
+ myComplete += anExecTimeMS;
+ std::cout << " " << anExecTimeMS << " ms" << std::endl;
}
/**
#include <cppunit/TestListener.h>
+typedef long long INT64; ///< the cross-platform type definition for 64-bits integer
+
/**
\class TestLib_Listener
\brief Implementation of the custom listener printing the time of test execution
virtual ~TestLib_Listener();
void Clear();
-
+ INT64 GetCompleteTimeInMS() const;
+
virtual void startTest( CppUnit::Test* );
virtual void endTest( CppUnit::Test* );
virtual void endSuite( CppUnit::Test* );
virtual void addFailure( const CppUnit::TestFailure& );
+
+private:
+ INT64 myStart; ///< start time in milliseconds
+ INT64 myComplete; ///< complete time of all tests execution in milliseconds
};