root/library/tests/unittest-cpp/TestRunner.cpp @ 1210

Revision 737, 2.0 kB (checked in by mido, 15 years ago)

ASTYLER RUN OVER THE WHOLE LIBRARY, JUPEE

  • Property svn:eol-style set to native
Line 
1#include "TestRunner.h"
2#include "TestResults.h"
3#include "TestReporter.h"
4#include "TestReporterStdout.h"
5#include "TimeHelpers.h"
6#include "MemoryOutStream.h"
7
8
9#include "../bdm/base/bdmbase.h"
10
11#include <cstring>
12
13
14namespace UnitTest {
15
16int RunAllTests() {
17        TestReporterStdout reporter;
18        TestRunner runner ( reporter );
19        return runner.RunTestsIf ( Test::GetTestList(), NULL, True(), 0 );
20}
21
22
23TestRunner::TestRunner ( TestReporter& reporter )
24                : m_reporter ( &reporter )
25                , m_result ( new TestResults ( &reporter ) )
26                , m_timer ( new Timer ) {
27        m_timer->Start();
28}
29
30TestRunner::~TestRunner() {
31        delete m_result;
32        delete m_timer;
33}
34
35int TestRunner::Finish() const {
36        float const secondsElapsed = static_cast<float> ( m_timer->GetTimeInMs() / 1000.0 );
37        m_reporter->ReportSummary ( m_result->GetTotalTestCount(),
38                                    m_result->GetFailedTestCount(),
39                                    m_result->GetFailureCount(),
40                                    secondsElapsed );
41
42        return m_result->GetFailureCount();
43}
44
45bool TestRunner::IsTestInSuite ( const Test* const curTest, char const* suiteName ) const {
46        using namespace std;
47        return ( suiteName == NULL ) || !strcmp ( curTest->m_details.suiteName, suiteName );
48}
49
50void TestRunner::RunTest ( TestResults* const result, Test* const curTest, int const maxTestTimeInMs ) const {
51        CurrentTest::Results() = result;
52
53        Timer testTimer;
54        testTimer.Start();
55
56        result->OnTestStart ( curTest->m_details );
57
58        curTest->Run();
59
60        double const testTimeInMs = testTimer.GetTimeInMs();
61        if ( maxTestTimeInMs > 0 && testTimeInMs > maxTestTimeInMs && !curTest->m_timeConstraintExempt ) {
62                MemoryOutStream stream;
63                stream << "Global time constraint failed. Expected under " << maxTestTimeInMs <<
64                "ms but took " << testTimeInMs << "ms.";
65
66                result->OnTestFailure ( curTest->m_details, stream.GetText() );
67        }
68
69        result->OnTestFinish ( curTest->m_details, static_cast<float> ( testTimeInMs / 1000.0 ) );
70}
71
72void TestRunner::ClearEnvironment() const {
73        bdm::RV::clear_all();
74}
75
76}
Note: See TracBrowser for help on using the browser.