1*2f083884Ss.makeev_local #include "UnitTest++/UnitTestPP.h"
2*2f083884Ss.makeev_local #include "UnitTest++/TestMacros.h"
3*2f083884Ss.makeev_local #include "UnitTest++/TestList.h"
4*2f083884Ss.makeev_local #include "UnitTest++/TestResults.h"
5*2f083884Ss.makeev_local #include "UnitTest++/TestReporter.h"
6*2f083884Ss.makeev_local #include "UnitTest++/ReportAssert.h"
7*2f083884Ss.makeev_local #include "RecordingReporter.h"
8*2f083884Ss.makeev_local #include "ScopedCurrentTest.h"
9*2f083884Ss.makeev_local
10*2f083884Ss.makeev_local using namespace UnitTest;
11*2f083884Ss.makeev_local using namespace std;
12*2f083884Ss.makeev_local
13*2f083884Ss.makeev_local namespace {
14*2f083884Ss.makeev_local
15*2f083884Ss.makeev_local TestList list1;
TEST_EX(DummyTest,list1)16*2f083884Ss.makeev_local TEST_EX(DummyTest, list1)
17*2f083884Ss.makeev_local {
18*2f083884Ss.makeev_local }
19*2f083884Ss.makeev_local
TEST(TestsAreAddedToTheListThroughMacro)20*2f083884Ss.makeev_local TEST (TestsAreAddedToTheListThroughMacro)
21*2f083884Ss.makeev_local {
22*2f083884Ss.makeev_local CHECK(list1.GetHead() != 0);
23*2f083884Ss.makeev_local CHECK(list1.GetHead()->m_nextTest == 0);
24*2f083884Ss.makeev_local }
25*2f083884Ss.makeev_local
26*2f083884Ss.makeev_local #ifndef UNITTEST_NO_EXCEPTIONS
27*2f083884Ss.makeev_local
28*2f083884Ss.makeev_local struct ThrowingThingie
29*2f083884Ss.makeev_local {
ThrowingThingie__anon00d823b30111::ThrowingThingie30*2f083884Ss.makeev_local ThrowingThingie() : dummy(false)
31*2f083884Ss.makeev_local {
32*2f083884Ss.makeev_local if (!dummy)
33*2f083884Ss.makeev_local throw "Oops";
34*2f083884Ss.makeev_local }
35*2f083884Ss.makeev_local
36*2f083884Ss.makeev_local bool dummy;
37*2f083884Ss.makeev_local };
38*2f083884Ss.makeev_local
39*2f083884Ss.makeev_local TestList list2;
TEST_FIXTURE_EX(ThrowingThingie,DummyTestName,list2)40*2f083884Ss.makeev_local TEST_FIXTURE_EX(ThrowingThingie, DummyTestName, list2)
41*2f083884Ss.makeev_local {
42*2f083884Ss.makeev_local }
43*2f083884Ss.makeev_local
TEST(ExceptionsInFixtureAreReportedAsHappeningInTheFixture)44*2f083884Ss.makeev_local TEST (ExceptionsInFixtureAreReportedAsHappeningInTheFixture)
45*2f083884Ss.makeev_local {
46*2f083884Ss.makeev_local RecordingReporter reporter;
47*2f083884Ss.makeev_local TestResults result(&reporter);
48*2f083884Ss.makeev_local {
49*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(result);
50*2f083884Ss.makeev_local list2.GetHead()->Run();
51*2f083884Ss.makeev_local }
52*2f083884Ss.makeev_local
53*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "xception"));
54*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "fixture"));
55*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "ThrowingThingie"));
56*2f083884Ss.makeev_local }
57*2f083884Ss.makeev_local
58*2f083884Ss.makeev_local #endif
59*2f083884Ss.makeev_local
60*2f083884Ss.makeev_local struct DummyFixture
61*2f083884Ss.makeev_local {
62*2f083884Ss.makeev_local int x;
63*2f083884Ss.makeev_local };
64*2f083884Ss.makeev_local
65*2f083884Ss.makeev_local // We're really testing the macros so we just want them to compile and link
SUITE(TestSuite1)66*2f083884Ss.makeev_local SUITE(TestSuite1)
67*2f083884Ss.makeev_local {
68*2f083884Ss.makeev_local TEST(SimilarlyNamedTestsInDifferentSuitesWork)
69*2f083884Ss.makeev_local {
70*2f083884Ss.makeev_local }
71*2f083884Ss.makeev_local
72*2f083884Ss.makeev_local TEST_FIXTURE(DummyFixture, SimilarlyNamedFixtureTestsInDifferentSuitesWork)
73*2f083884Ss.makeev_local {
74*2f083884Ss.makeev_local }
75*2f083884Ss.makeev_local }
76*2f083884Ss.makeev_local
SUITE(TestSuite2)77*2f083884Ss.makeev_local SUITE(TestSuite2)
78*2f083884Ss.makeev_local {
79*2f083884Ss.makeev_local TEST(SimilarlyNamedTestsInDifferentSuitesWork)
80*2f083884Ss.makeev_local {
81*2f083884Ss.makeev_local }
82*2f083884Ss.makeev_local
83*2f083884Ss.makeev_local TEST_FIXTURE(DummyFixture,SimilarlyNamedFixtureTestsInDifferentSuitesWork)
84*2f083884Ss.makeev_local {
85*2f083884Ss.makeev_local }
86*2f083884Ss.makeev_local }
87*2f083884Ss.makeev_local
88*2f083884Ss.makeev_local TestList macroTestList1;
TEST_EX(MacroTestHelper1,macroTestList1)89*2f083884Ss.makeev_local TEST_EX(MacroTestHelper1, macroTestList1)
90*2f083884Ss.makeev_local {
91*2f083884Ss.makeev_local }
92*2f083884Ss.makeev_local
TEST(TestAddedWithTEST_EXMacroGetsDefaultSuite)93*2f083884Ss.makeev_local TEST(TestAddedWithTEST_EXMacroGetsDefaultSuite)
94*2f083884Ss.makeev_local {
95*2f083884Ss.makeev_local CHECK(macroTestList1.GetHead() != NULL);
96*2f083884Ss.makeev_local CHECK_EQUAL ("MacroTestHelper1", macroTestList1.GetHead()->m_details.testName);
97*2f083884Ss.makeev_local CHECK_EQUAL ("DefaultSuite", macroTestList1.GetHead()->m_details.suiteName);
98*2f083884Ss.makeev_local }
99*2f083884Ss.makeev_local
100*2f083884Ss.makeev_local TestList macroTestList2;
TEST_FIXTURE_EX(DummyFixture,MacroTestHelper2,macroTestList2)101*2f083884Ss.makeev_local TEST_FIXTURE_EX(DummyFixture, MacroTestHelper2, macroTestList2)
102*2f083884Ss.makeev_local {
103*2f083884Ss.makeev_local }
104*2f083884Ss.makeev_local
TEST(TestAddedWithTEST_FIXTURE_EXMacroGetsDefaultSuite)105*2f083884Ss.makeev_local TEST(TestAddedWithTEST_FIXTURE_EXMacroGetsDefaultSuite)
106*2f083884Ss.makeev_local {
107*2f083884Ss.makeev_local CHECK(macroTestList2.GetHead() != NULL);
108*2f083884Ss.makeev_local CHECK_EQUAL ("MacroTestHelper2", macroTestList2.GetHead()->m_details.testName);
109*2f083884Ss.makeev_local CHECK_EQUAL ("DefaultSuite", macroTestList2.GetHead()->m_details.suiteName);
110*2f083884Ss.makeev_local }
111*2f083884Ss.makeev_local
112*2f083884Ss.makeev_local #ifndef UNITTEST_NO_EXCEPTIONS
113*2f083884Ss.makeev_local
114*2f083884Ss.makeev_local struct FixtureCtorThrows
115*2f083884Ss.makeev_local {
FixtureCtorThrows__anon00d823b30111::FixtureCtorThrows116*2f083884Ss.makeev_local FixtureCtorThrows() { throw "exception"; }
117*2f083884Ss.makeev_local };
118*2f083884Ss.makeev_local
119*2f083884Ss.makeev_local TestList throwingFixtureTestList1;
TEST_FIXTURE_EX(FixtureCtorThrows,FixtureCtorThrowsTestName,throwingFixtureTestList1)120*2f083884Ss.makeev_local TEST_FIXTURE_EX(FixtureCtorThrows, FixtureCtorThrowsTestName, throwingFixtureTestList1)
121*2f083884Ss.makeev_local {
122*2f083884Ss.makeev_local }
123*2f083884Ss.makeev_local
TEST(FixturesWithThrowingCtorsAreFailures)124*2f083884Ss.makeev_local TEST(FixturesWithThrowingCtorsAreFailures)
125*2f083884Ss.makeev_local {
126*2f083884Ss.makeev_local CHECK(throwingFixtureTestList1.GetHead() != NULL);
127*2f083884Ss.makeev_local RecordingReporter reporter;
128*2f083884Ss.makeev_local TestResults result(&reporter);
129*2f083884Ss.makeev_local {
130*2f083884Ss.makeev_local ScopedCurrentTest scopedResult(result);
131*2f083884Ss.makeev_local throwingFixtureTestList1.GetHead()->Run();
132*2f083884Ss.makeev_local }
133*2f083884Ss.makeev_local
134*2f083884Ss.makeev_local int const failureCount = result.GetFailedTestCount();
135*2f083884Ss.makeev_local CHECK_EQUAL(1, failureCount);
136*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "while constructing fixture"));
137*2f083884Ss.makeev_local }
138*2f083884Ss.makeev_local
139*2f083884Ss.makeev_local struct FixtureDtorThrows
140*2f083884Ss.makeev_local {
~FixtureDtorThrows__anon00d823b30111::FixtureDtorThrows141*2f083884Ss.makeev_local ~FixtureDtorThrows() { throw "exception"; }
142*2f083884Ss.makeev_local };
143*2f083884Ss.makeev_local
144*2f083884Ss.makeev_local TestList throwingFixtureTestList2;
TEST_FIXTURE_EX(FixtureDtorThrows,FixtureDtorThrowsTestName,throwingFixtureTestList2)145*2f083884Ss.makeev_local TEST_FIXTURE_EX(FixtureDtorThrows, FixtureDtorThrowsTestName, throwingFixtureTestList2)
146*2f083884Ss.makeev_local {
147*2f083884Ss.makeev_local }
148*2f083884Ss.makeev_local
TEST(FixturesWithThrowingDtorsAreFailures)149*2f083884Ss.makeev_local TEST(FixturesWithThrowingDtorsAreFailures)
150*2f083884Ss.makeev_local {
151*2f083884Ss.makeev_local CHECK(throwingFixtureTestList2.GetHead() != NULL);
152*2f083884Ss.makeev_local
153*2f083884Ss.makeev_local RecordingReporter reporter;
154*2f083884Ss.makeev_local TestResults result(&reporter);
155*2f083884Ss.makeev_local {
156*2f083884Ss.makeev_local ScopedCurrentTest scopedResult(result);
157*2f083884Ss.makeev_local throwingFixtureTestList2.GetHead()->Run();
158*2f083884Ss.makeev_local }
159*2f083884Ss.makeev_local
160*2f083884Ss.makeev_local int const failureCount = result.GetFailedTestCount();
161*2f083884Ss.makeev_local CHECK_EQUAL(1, failureCount);
162*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "while destroying fixture"));
163*2f083884Ss.makeev_local }
164*2f083884Ss.makeev_local
165*2f083884Ss.makeev_local const int FailingLine = 123;
166*2f083884Ss.makeev_local
167*2f083884Ss.makeev_local struct FixtureCtorAsserts
168*2f083884Ss.makeev_local {
FixtureCtorAsserts__anon00d823b30111::FixtureCtorAsserts169*2f083884Ss.makeev_local FixtureCtorAsserts()
170*2f083884Ss.makeev_local {
171*2f083884Ss.makeev_local UnitTest::ReportAssert("assert failure", "file", FailingLine);
172*2f083884Ss.makeev_local }
173*2f083884Ss.makeev_local };
174*2f083884Ss.makeev_local
175*2f083884Ss.makeev_local TestList ctorAssertFixtureTestList;
TEST_FIXTURE_EX(FixtureCtorAsserts,CorrectlyReportsAssertFailureInCtor,ctorAssertFixtureTestList)176*2f083884Ss.makeev_local TEST_FIXTURE_EX(FixtureCtorAsserts, CorrectlyReportsAssertFailureInCtor, ctorAssertFixtureTestList)
177*2f083884Ss.makeev_local {
178*2f083884Ss.makeev_local }
179*2f083884Ss.makeev_local
TEST(CorrectlyReportsFixturesWithCtorsThatAssert)180*2f083884Ss.makeev_local TEST(CorrectlyReportsFixturesWithCtorsThatAssert)
181*2f083884Ss.makeev_local {
182*2f083884Ss.makeev_local RecordingReporter reporter;
183*2f083884Ss.makeev_local TestResults result(&reporter);
184*2f083884Ss.makeev_local {
185*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(result);
186*2f083884Ss.makeev_local ctorAssertFixtureTestList.GetHead()->Run();
187*2f083884Ss.makeev_local }
188*2f083884Ss.makeev_local
189*2f083884Ss.makeev_local const int failureCount = result.GetFailedTestCount();
190*2f083884Ss.makeev_local CHECK_EQUAL(1, failureCount);
191*2f083884Ss.makeev_local CHECK_EQUAL(FailingLine, reporter.lastFailedLine);
192*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "assert failure"));
193*2f083884Ss.makeev_local }
194*2f083884Ss.makeev_local
195*2f083884Ss.makeev_local #endif
196*2f083884Ss.makeev_local
197*2f083884Ss.makeev_local }
198*2f083884Ss.makeev_local
199*2f083884Ss.makeev_local // We're really testing if it's possible to use the same suite in two files
200*2f083884Ss.makeev_local // to compile and link successfuly (TestTestSuite.cpp has suite with the same name)
201*2f083884Ss.makeev_local // Note: we are outside of the anonymous namespace
SUITE(SameTestSuite)202*2f083884Ss.makeev_local SUITE(SameTestSuite)
203*2f083884Ss.makeev_local {
204*2f083884Ss.makeev_local TEST(DummyTest1)
205*2f083884Ss.makeev_local {
206*2f083884Ss.makeev_local }
207*2f083884Ss.makeev_local }
208*2f083884Ss.makeev_local
209*2f083884Ss.makeev_local #define CUR_TEST_NAME CurrentTestDetailsContainCurrentTestInfo
210*2f083884Ss.makeev_local #define INNER_STRINGIFY(X) #X
211*2f083884Ss.makeev_local #define STRINGIFY(X) INNER_STRINGIFY(X)
212*2f083884Ss.makeev_local
TEST(CUR_TEST_NAME)213*2f083884Ss.makeev_local TEST(CUR_TEST_NAME)
214*2f083884Ss.makeev_local {
215*2f083884Ss.makeev_local const UnitTest::TestDetails* details = CurrentTest::Details();
216*2f083884Ss.makeev_local CHECK_EQUAL(STRINGIFY(CUR_TEST_NAME), details->testName);
217*2f083884Ss.makeev_local }
218*2f083884Ss.makeev_local
219*2f083884Ss.makeev_local #undef CUR_TEST_NAME
220*2f083884Ss.makeev_local #undef INNER_STRINGIFY
221*2f083884Ss.makeev_local #undef STRINGIFY
222