1 #include <TestListener.h>
3 #include <cppunit/Exception.h>
4 #include <cppunit/Test.h>
5 #include <cppunit/TestFailure.h>
15 BTestListener::startTest( CppUnit::Test
*test
) {
17 cout
<< test
->getName() << endl
;
18 startTime
= real_time_clock_usecs();
23 BTestListener::addFailure( const CppUnit::TestFailure
&failure
) {
26 cout
<< (failure
.isError() ? "ERROR" : "FAILURE");
28 cout
<< (failure
.thrownException() != NULL
29 ? failure
.thrownException()->what()
36 BTestListener::endTest( CppUnit::Test
*test
) {
37 bigtime_t length
= real_time_clock_usecs() - startTime
;
39 cout
<< " + PASSED" << endl
;
41 // cout << " - FAILED" << endl;
48 BTestListener::printTime(bigtime_t time
) {
49 // Print out the elapsed time all pretty and stuff:
50 // time >= 1 minute: HH:MM:SS
51 // 1 minute > time: XXX ms
52 const bigtime_t oneMillisecond
= 1000;
53 const bigtime_t oneSecond
= oneMillisecond
*1000;
54 const bigtime_t oneMinute
= oneSecond
*60;
55 const bigtime_t oneHour
= oneMinute
*60;
56 const bigtime_t oneDay
= oneHour
*24;
58 cout
<< " Your test ran for longer than an entire day. Honestly," << endl
;
59 cout
<< " that's 24 hours. That's a long time. Please write shorter" << endl
;
60 cout
<< " tests. Clock time: " << time
<< " microseconds." << endl
;
62 cout
<< " Clock time: ";
63 if (time
>= oneMinute
) {
65 if (begun
|| time
>= oneHour
) {
69 cout
<< time
/ oneHour
<< ":";
72 if (begun
|| time
>= oneMinute
) {
76 cout
<< time
/ oneMinute
<< ":";
79 if (begun
|| time
>= oneSecond
) {
83 cout
<< time
/ oneSecond
;
87 cout
<< time
/ oneMillisecond
<< " ms";