comparison ext/UnitTest++/src/tests/TestTestMacros.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 "../UnitTest++.h"
2 #include "../TestMacros.h"
3 #include "../TestList.h"
4 #include "../TestResults.h"
5 #include "../TestReporter.h"
6 #include "RecordingReporter.h"
7
8 using namespace UnitTest;
9
10 namespace {
11
12 TestList list1;
13 TEST_EX(DummyTest, list1)
14 {
15 (void)testResults_;
16 }
17
18 TEST (TestsAreAddedToTheListThroughMacro)
19 {
20 CHECK (list1.GetHead() != 0);
21 CHECK (list1.GetHead()->next == 0);
22 }
23
24 struct ThrowingThingie
25 {
26 ThrowingThingie() : dummy(false)
27 {
28 if (!dummy)
29 throw "Oops";
30 }
31 bool dummy;
32 };
33
34 TestList list2;
35 TEST_FIXTURE_EX(ThrowingThingie,DummyTestName,list2)
36 {
37 (void)testResults_;
38 }
39
40 TEST (ExceptionsInFixtureAreReportedAsHappeningInTheFixture)
41 {
42 RecordingReporter reporter;
43 TestResults result(&reporter);
44 list2.GetHead()->Run(result);
45
46 CHECK (strstr(reporter.lastFailedMessage, "xception"));
47 CHECK (strstr(reporter.lastFailedMessage, "fixture"));
48 CHECK (strstr(reporter.lastFailedMessage, "ThrowingThingie"));
49 }
50
51 struct DummyFixture
52 {
53 int x;
54 };
55
56 // We're really testing the macros so we just want them to compile and link
57 SUITE(TestSuite1)
58 {
59
60 TEST(SimilarlyNamedTestsInDifferentSuitesWork)
61 {
62 (void)testResults_;
63 }
64
65 TEST_FIXTURE(DummyFixture,SimilarlyNamedFixtureTestsInDifferentSuitesWork)
66 {
67 (void)testResults_;
68 }
69
70 }
71
72 SUITE(TestSuite2)
73 {
74
75 TEST(SimilarlyNamedTestsInDifferentSuitesWork)
76 {
77 (void)testResults_;
78 }
79
80 TEST_FIXTURE(DummyFixture,SimilarlyNamedFixtureTestsInDifferentSuitesWork)
81 {
82 (void)testResults_;
83 }
84
85 }
86
87 TestList macroTestList1;
88 TEST_EX(MacroTestHelper1,macroTestList1)
89 {
90 (void)testResults_;
91 }
92
93 TEST(TestAddedWithTEST_EXMacroGetsDefaultSuite)
94 {
95 CHECK(macroTestList1.GetHead() != NULL);
96 CHECK_EQUAL ("MacroTestHelper1", macroTestList1.GetHead()->m_details.testName);
97 CHECK_EQUAL ("DefaultSuite", macroTestList1.GetHead()->m_details.suiteName);
98 }
99
100 TestList macroTestList2;
101 TEST_FIXTURE_EX(DummyFixture,MacroTestHelper2,macroTestList2)
102 {
103 (void)testResults_;
104 }
105
106 TEST(TestAddedWithTEST_FIXTURE_EXMacroGetsDefaultSuite)
107 {
108 CHECK(macroTestList2.GetHead() != NULL);
109 CHECK_EQUAL ("MacroTestHelper2", macroTestList2.GetHead()->m_details.testName);
110 CHECK_EQUAL ("DefaultSuite", macroTestList2.GetHead()->m_details.suiteName);
111 }
112
113 struct FixtureCtorThrows
114 {
115 FixtureCtorThrows() { throw "exception"; }
116 };
117
118 TestList throwingFixtureTestList1;
119 TEST_FIXTURE_EX(FixtureCtorThrows, FixtureCtorThrowsTestName, throwingFixtureTestList1)
120 {
121 (void)testResults_;
122 }
123
124 TEST(FixturesWithThrowingCtorsAreFailures)
125 {
126 CHECK(throwingFixtureTestList1.GetHead() != NULL);
127 RecordingReporter reporter;
128 TestResults result(&reporter);
129 throwingFixtureTestList1.GetHead()->Run(result);
130
131 int const failureCount = result.GetFailedTestCount();
132 CHECK_EQUAL(1, failureCount);
133 CHECK(strstr(reporter.lastFailedMessage, "while constructing fixture"));
134 }
135
136 struct FixtureDtorThrows
137 {
138 ~FixtureDtorThrows() { throw "exception"; }
139 };
140
141 TestList throwingFixtureTestList2;
142 TEST_FIXTURE_EX(FixtureDtorThrows, FixtureDtorThrowsTestName, throwingFixtureTestList2)
143 {
144 (void)testResults_;
145 }
146
147 TEST(FixturesWithThrowingDtorsAreFailures)
148 {
149 CHECK(throwingFixtureTestList2.GetHead() != NULL);
150 RecordingReporter reporter;
151 TestResults result(&reporter);
152 throwingFixtureTestList2.GetHead()->Run(result);
153
154 int const failureCount = result.GetFailedTestCount();
155 CHECK_EQUAL(1, failureCount);
156 CHECK(strstr(reporter.lastFailedMessage, "while destroying fixture"));
157 }
158
159 }
160
161 // We're really testing if it's possible to use the same suite in two files
162 // to compile and link successfuly (TestTestSuite.cpp has suite with the same name)
163 // Note: we are outside of the anonymous namespace
164 SUITE(SameTestSuite)
165 {
166 TEST(DummyTest1)
167 {
168 (void)testResults_;
169 }
170 }
171