annotate ext/UnitTest++/src/tests/TestDeferredTestReporter.cpp @ 357:2cdce58c1109

Fixes the scroll areas in the pychan demo. fixes[t:363]
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 25 Sep 2009 19:48:07 +0000
parents fa33cda75471
children
rev   line source
89
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 #include "../UnitTest++.h"
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2 #include "../DeferredTestReporter.h"
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 #include <string>
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 #include <cstring>
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 namespace UnitTest
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 {
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 struct MockDeferredTestReporter : public DeferredTestReporter
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 {
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 virtual void ReportSummary(int, int, int, float)
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 {
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 }
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 };
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 struct DeferredTestReporterFixture
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 {
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 DeferredTestReporterFixture()
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 : testName("UniqueTestName")
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 , testSuite("UniqueTestSuite")
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 , fileName("filename.h")
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23 , lineNumber(12)
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 , details(testName.c_str(), testSuite.c_str(), fileName.c_str(), lineNumber)
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 {
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26 }
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 MockDeferredTestReporter reporter;
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 std::string const testName;
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 std::string const testSuite;
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 std::string const fileName;
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 int const lineNumber;
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 TestDetails const details;
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 };
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 TEST_FIXTURE(DeferredTestReporterFixture, ReportTestStartCreatesANewDeferredTest)
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37 {
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38 reporter.ReportTestStart(details);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 CHECK_EQUAL(1, (int)reporter.GetResults().size());
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 }
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42 TEST_FIXTURE(DeferredTestReporterFixture, ReportTestStartCapturesTestNameAndSuite)
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 {
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 reporter.ReportTestStart(details);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 DeferredTestResult const& result = reporter.GetResults().at(0);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47 CHECK_EQUAL(testName.c_str(), result.testName);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 CHECK_EQUAL(testSuite.c_str(), result.suiteName);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 }
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51 TEST_FIXTURE(DeferredTestReporterFixture, ReportTestEndCapturesTestTime)
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52 {
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 float const elapsed = 123.45f;
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 reporter.ReportTestStart(details);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 reporter.ReportTestFinish(details, elapsed);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 DeferredTestResult const& result = reporter.GetResults().at(0);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 CHECK_CLOSE(elapsed, result.timeElapsed, 0.0001f);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59 }
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61 TEST_FIXTURE(DeferredTestReporterFixture, ReportFailureSavesFailureDetails)
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
62 {
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
63 char const* failure = "failure";
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
64
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
65 reporter.ReportTestStart(details);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66 reporter.ReportFailure(details, failure);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
68 DeferredTestResult const& result = reporter.GetResults().at(0);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69 CHECK(result.failed == true);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 CHECK_EQUAL(fileName.c_str(), result.failureFile);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71 }
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73 TEST_FIXTURE(DeferredTestReporterFixture, ReportFailureSavesFailureDetailsForMultipleFailures)
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74 {
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75 char const* failure1 = "failure 1";
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 char const* failure2 = "failure 2";
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78 reporter.ReportTestStart(details);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 reporter.ReportFailure(details, failure1);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80 reporter.ReportFailure(details, failure2);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 DeferredTestResult const& result = reporter.GetResults().at(0);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83 CHECK_EQUAL(2u, result.failures.size());
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84 CHECK_EQUAL(failure1, result.failures[0].second);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85 CHECK_EQUAL(failure2, result.failures[1].second);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86 }
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
88 TEST_FIXTURE(DeferredTestReporterFixture, DeferredTestReporterTakesCopyOfFailureMessage)
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89 {
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90 reporter.ReportTestStart(details);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 char failureMessage[128];
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93 char const* goodStr = "Real failure message";
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94 char const* badStr = "Bogus failure message";
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96 std::strcpy(failureMessage, goodStr);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97 reporter.ReportFailure(details, failureMessage);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 std::strcpy(failureMessage, badStr);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
100 DeferredTestResult const& result = reporter.GetResults().at(0);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101 DeferredTestResult::Failure const& failure = result.failures.at(0);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
102 CHECK_EQUAL(goodStr, failure.second);
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
103 }
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
104
fa33cda75471 * Reverting back to 2543 as requested by sleek
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
105 }