comparison ext/UnitTest++/src/tests/TestDeferredTestReporter.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 73a9f7addd33
comparison
equal deleted inserted replaced
36:6f1227f4932b 37:0d325e9d5953
1 #include "../UnitTest++.h"
2 #include "../DeferredTestReporter.h"
3
4 #include <string>
5
6 namespace UnitTest
7 {
8
9 struct MockDeferredTestReporter : public DeferredTestReporter
10 {
11 virtual void ReportSummary(int, int, int, float)
12 {
13 }
14 };
15
16 struct DeferredTestReporterFixture
17 {
18 DeferredTestReporterFixture()
19 : testName("UniqueTestName")
20 , testSuite("UniqueTestSuite")
21 , fileName("filename.h")
22 , lineNumber(12)
23 , details(testName.c_str(), testSuite.c_str(), fileName.c_str(), lineNumber)
24 {
25 }
26
27 MockDeferredTestReporter reporter;
28 std::string const testName;
29 std::string const testSuite;
30 std::string const fileName;
31 int const lineNumber;
32 TestDetails const details;
33 };
34
35 TEST_FIXTURE(DeferredTestReporterFixture, ReportTestStartCreatesANewDeferredTest)
36 {
37 reporter.ReportTestStart(details);
38 CHECK_EQUAL(1, (int)reporter.GetResults().size());
39 }
40
41 TEST_FIXTURE(DeferredTestReporterFixture, ReportTestStartCapturesTestNameAndSuite)
42 {
43 reporter.ReportTestStart(details);
44
45 DeferredTestResult const& result = reporter.GetResults().at(0);
46 CHECK_EQUAL(testName.c_str(), result.testName);
47 CHECK_EQUAL(testSuite.c_str(), result.suiteName);
48 }
49
50 TEST_FIXTURE(DeferredTestReporterFixture, ReportTestEndCapturesTestTime)
51 {
52 float const elapsed = 123.45f;
53 reporter.ReportTestStart(details);
54 reporter.ReportTestFinish(details, elapsed);
55
56 DeferredTestResult const& result = reporter.GetResults().at(0);
57 CHECK_CLOSE(elapsed, result.timeElapsed, 0.0001f);
58 }
59
60 TEST_FIXTURE(DeferredTestReporterFixture, ReportFailureSavesFailureDetails)
61 {
62 char const* failure = "failure";
63
64 reporter.ReportTestStart(details);
65 reporter.ReportFailure(details, failure);
66
67 DeferredTestResult const& result = reporter.GetResults().at(0);
68 CHECK(result.failed == true);
69 CHECK_EQUAL(fileName.c_str(), result.failureFile);
70 }
71
72 TEST_FIXTURE(DeferredTestReporterFixture, ReportFailureSavesFailureDetailsForMultipleFailures)
73 {
74 char const* failure1 = "failure 1";
75 char const* failure2 = "failure 2";
76
77 reporter.ReportTestStart(details);
78 reporter.ReportFailure(details, failure1);
79 reporter.ReportFailure(details, failure2);
80
81 DeferredTestResult const& result = reporter.GetResults().at(0);
82 CHECK_EQUAL(2u, result.failures.size());
83 CHECK_EQUAL(failure1, result.failures[0].second);
84 CHECK_EQUAL(failure2, result.failures[1].second);
85 }
86
87 TEST_FIXTURE(DeferredTestReporterFixture, DeferredTestReporterTakesCopyOfFailureMessage)
88 {
89 reporter.ReportTestStart(details);
90
91 char failureMessage[128];
92 char const* goodStr = "Real failure message";
93 char const* badStr = "Bogus failure message";
94
95 std::strcpy(failureMessage, goodStr);
96 reporter.ReportFailure(details, failureMessage);
97 std::strcpy(failureMessage, badStr);
98
99 DeferredTestResult const& result = reporter.GetResults().at(0);
100 DeferredTestResult::Failure const& failure = result.failures.at(0);
101 CHECK_EQUAL(goodStr, failure.second);
102 }
103
104 }