Mercurial > fife-parpg
comparison ext/UnitTest++/src/TestRunner.cpp @ 37:0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
author | jasoka@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 12 Jul 2008 12:00:57 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
36:6f1227f4932b | 37:0d325e9d5953 |
---|---|
1 #include "TestRunner.h" | |
2 #include "TestResults.h" | |
3 #include "Test.h" | |
4 #include "TestList.h" | |
5 #include "TestReporter.h" | |
6 #include "TestReporterStdout.h" | |
7 #include "TimeHelpers.h" | |
8 #include "MemoryOutStream.h" | |
9 #include <cstring> | |
10 | |
11 | |
12 namespace UnitTest { | |
13 | |
14 | |
15 int RunAllTests(TestReporter& reporter, TestList const& list, char const* suiteName, int const maxTestTimeInMs ) | |
16 { | |
17 TestResults result(&reporter); | |
18 | |
19 Timer overallTimer; | |
20 overallTimer.Start(); | |
21 | |
22 Test const* curTest = list.GetHead(); | |
23 while (curTest != 0) | |
24 { | |
25 if (suiteName == 0 || !std::strcmp(curTest->m_details.suiteName, suiteName)) | |
26 { | |
27 Timer testTimer; | |
28 testTimer.Start(); | |
29 result.OnTestStart(curTest->m_details); | |
30 | |
31 curTest->Run(result); | |
32 | |
33 int const testTimeInMs = testTimer.GetTimeInMs(); | |
34 if (maxTestTimeInMs > 0 && testTimeInMs > maxTestTimeInMs && !curTest->m_timeConstraintExempt) | |
35 { | |
36 MemoryOutStream stream; | |
37 stream << "Global time constraint failed. Expected under " << maxTestTimeInMs << | |
38 "ms but took " << testTimeInMs << "ms."; | |
39 result.OnTestFailure(curTest->m_details, stream.GetText()); | |
40 } | |
41 result.OnTestFinish(curTest->m_details, testTimeInMs/1000.0f); | |
42 } | |
43 | |
44 curTest = curTest->next; | |
45 } | |
46 | |
47 float const secondsElapsed = overallTimer.GetTimeInMs() / 1000.0f; | |
48 reporter.ReportSummary(result.GetTotalTestCount(), result.GetFailedTestCount(), result.GetFailureCount(), secondsElapsed); | |
49 | |
50 return result.GetFailureCount(); | |
51 } | |
52 | |
53 | |
54 int RunAllTests() | |
55 { | |
56 TestReporterStdout reporter; | |
57 return RunAllTests(reporter, Test::GetTestList(), 0); | |
58 } | |
59 | |
60 } |