Changeset 477 for library/tests/unittest-cpp/TestRunner.cpp
- Timestamp:
- 08/05/09 14:40:03 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/tests/unittest-cpp/TestRunner.cpp
r418 r477 11 11 namespace UnitTest { 12 12 13 int RunAllTests() 14 { 13 int RunAllTests() { 15 14 TestReporterStdout reporter; 16 TestRunner runner (reporter);17 return runner.RunTestsIf (Test::GetTestList(), NULL, True(), 0);15 TestRunner runner ( reporter ); 16 return runner.RunTestsIf ( Test::GetTestList(), NULL, True(), 0 ); 18 17 } 19 18 20 19 21 TestRunner::TestRunner(TestReporter& reporter) 22 : m_reporter(&reporter) 23 , m_result(new TestResults(&reporter)) 24 , m_timer(new Timer) 25 { 20 TestRunner::TestRunner ( TestReporter& reporter ) 21 : m_reporter ( &reporter ) 22 , m_result ( new TestResults ( &reporter ) ) 23 , m_timer ( new Timer ) { 26 24 m_timer->Start(); 27 25 } 28 26 29 TestRunner::~TestRunner() 30 { 27 TestRunner::~TestRunner() { 31 28 delete m_result; 32 29 delete m_timer; 33 30 } 34 31 35 int TestRunner::Finish() const 36 { 37 float const secondsElapsed = static_cast<float>(m_timer->GetTimeInMs() / 1000.0); 38 m_reporter->ReportSummary(m_result->GetTotalTestCount(), 39 m_result->GetFailedTestCount(), 40 m_result->GetFailureCount(), 41 secondsElapsed); 42 32 int TestRunner::Finish() const { 33 float const secondsElapsed = static_cast<float> ( m_timer->GetTimeInMs() / 1000.0 ); 34 m_reporter->ReportSummary ( m_result->GetTotalTestCount(), 35 m_result->GetFailedTestCount(), 36 m_result->GetFailureCount(), 37 secondsElapsed ); 38 43 39 return m_result->GetFailureCount(); 44 40 } 45 41 46 bool TestRunner::IsTestInSuite(const Test* const curTest, char const* suiteName) const 47 { 42 bool TestRunner::IsTestInSuite ( const Test* const curTest, char const* suiteName ) const { 48 43 using namespace std; 49 return ( suiteName == NULL) || !strcmp(curTest->m_details.suiteName, suiteName);44 return ( suiteName == NULL ) || !strcmp ( curTest->m_details.suiteName, suiteName ); 50 45 } 51 46 52 void TestRunner::RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const 53 { 47 void TestRunner::RunTest ( TestResults* const result, Test* const curTest, int const maxTestTimeInMs ) const { 54 48 CurrentTest::Results() = result; 55 49 … … 57 51 testTimer.Start(); 58 52 59 result->OnTestStart (curTest->m_details);53 result->OnTestStart ( curTest->m_details ); 60 54 61 55 curTest->Run(); 62 56 63 57 double const testTimeInMs = testTimer.GetTimeInMs(); 64 if (maxTestTimeInMs > 0 && testTimeInMs > maxTestTimeInMs && !curTest->m_timeConstraintExempt) 65 { 66 MemoryOutStream stream; 67 stream << "Global time constraint failed. Expected under " << maxTestTimeInMs << 68 "ms but took " << testTimeInMs << "ms."; 58 if ( maxTestTimeInMs > 0 && testTimeInMs > maxTestTimeInMs && !curTest->m_timeConstraintExempt ) { 59 MemoryOutStream stream; 60 stream << "Global time constraint failed. Expected under " << maxTestTimeInMs << 61 "ms but took " << testTimeInMs << "ms."; 69 62 70 result->OnTestFailure(curTest->m_details, stream.GetText());63 result->OnTestFailure ( curTest->m_details, stream.GetText() ); 71 64 } 72 65 73 result->OnTestFinish (curTest->m_details, static_cast<float>(testTimeInMs/1000.0));66 result->OnTestFinish ( curTest->m_details, static_cast<float> ( testTimeInMs / 1000.0 ) ); 74 67 } 75 68