1*2f083884Ss.makeev_local #include "UnitTest++/Config.h"
2*2f083884Ss.makeev_local #ifndef UNITTEST_NO_EXCEPTIONS
3*2f083884Ss.makeev_local
4*2f083884Ss.makeev_local #include "UnitTest++/UnitTestPP.h"
5*2f083884Ss.makeev_local #include "UnitTest++/CurrentTest.h"
6*2f083884Ss.makeev_local #include "RecordingReporter.h"
7*2f083884Ss.makeev_local #include "ScopedCurrentTest.h"
8*2f083884Ss.makeev_local
9*2f083884Ss.makeev_local #include <stdexcept>
10*2f083884Ss.makeev_local
11*2f083884Ss.makeev_local using namespace std;
12*2f083884Ss.makeev_local
13*2f083884Ss.makeev_local namespace {
14*2f083884Ss.makeev_local
ThrowingFunction()15*2f083884Ss.makeev_local int ThrowingFunction()
16*2f083884Ss.makeev_local {
17*2f083884Ss.makeev_local throw "Doh";
18*2f083884Ss.makeev_local }
19*2f083884Ss.makeev_local
ThrowingStdExceptionFunction()20*2f083884Ss.makeev_local int ThrowingStdExceptionFunction()
21*2f083884Ss.makeev_local {
22*2f083884Ss.makeev_local throw std::logic_error("Doh");
23*2f083884Ss.makeev_local }
24*2f083884Ss.makeev_local
SUITE(CheckExceptionTests)25*2f083884Ss.makeev_local SUITE(CheckExceptionTests)
26*2f083884Ss.makeev_local {
27*2f083884Ss.makeev_local struct CheckFixture
28*2f083884Ss.makeev_local {
29*2f083884Ss.makeev_local CheckFixture()
30*2f083884Ss.makeev_local : reporter()
31*2f083884Ss.makeev_local , testResults(&reporter)
32*2f083884Ss.makeev_local {
33*2f083884Ss.makeev_local }
34*2f083884Ss.makeev_local
35*2f083884Ss.makeev_local void PerformCheckWithNonStdThrow()
36*2f083884Ss.makeev_local {
37*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(testResults);
38*2f083884Ss.makeev_local CHECK(ThrowingFunction() == 1);
39*2f083884Ss.makeev_local }
40*2f083884Ss.makeev_local
41*2f083884Ss.makeev_local void PerformCheckWithStdThrow()
42*2f083884Ss.makeev_local {
43*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(testResults);
44*2f083884Ss.makeev_local CHECK(ThrowingStdExceptionFunction() == 1);
45*2f083884Ss.makeev_local }
46*2f083884Ss.makeev_local
47*2f083884Ss.makeev_local RecordingReporter reporter;
48*2f083884Ss.makeev_local UnitTest::TestResults testResults;
49*2f083884Ss.makeev_local };
50*2f083884Ss.makeev_local
51*2f083884Ss.makeev_local TEST_FIXTURE(CheckFixture, CheckFailsOnException)
52*2f083884Ss.makeev_local {
53*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
54*2f083884Ss.makeev_local CHECK(testResults.GetFailureCount() > 0);
55*2f083884Ss.makeev_local }
56*2f083884Ss.makeev_local
57*2f083884Ss.makeev_local TEST_FIXTURE(CheckFixture, CheckFailsOnStdException)
58*2f083884Ss.makeev_local {
59*2f083884Ss.makeev_local PerformCheckWithStdThrow();
60*2f083884Ss.makeev_local CHECK(testResults.GetFailureCount() > 0);
61*2f083884Ss.makeev_local }
62*2f083884Ss.makeev_local
63*2f083884Ss.makeev_local TEST_FIXTURE(CheckFixture, CheckFailureBecauseOfExceptionIncludesCheckContents)
64*2f083884Ss.makeev_local {
65*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
66*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "ThrowingFunction() == 1"));
67*2f083884Ss.makeev_local }
68*2f083884Ss.makeev_local
69*2f083884Ss.makeev_local TEST_FIXTURE(CheckFixture, CheckFailureBecauseOfStdExceptionIncludesCheckContents)
70*2f083884Ss.makeev_local {
71*2f083884Ss.makeev_local PerformCheckWithStdThrow();
72*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "ThrowingStdExceptionFunction() == 1"));
73*2f083884Ss.makeev_local }
74*2f083884Ss.makeev_local
75*2f083884Ss.makeev_local TEST_FIXTURE(CheckFixture, CheckFailureBecauseOfStandardExceptionIncludesWhat)
76*2f083884Ss.makeev_local {
77*2f083884Ss.makeev_local PerformCheckWithStdThrow();
78*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "exception (Doh)"));
79*2f083884Ss.makeev_local }
80*2f083884Ss.makeev_local }
81*2f083884Ss.makeev_local
SUITE(CheckEqualExceptionTests)82*2f083884Ss.makeev_local SUITE(CheckEqualExceptionTests)
83*2f083884Ss.makeev_local {
84*2f083884Ss.makeev_local struct CheckEqualFixture
85*2f083884Ss.makeev_local {
86*2f083884Ss.makeev_local CheckEqualFixture()
87*2f083884Ss.makeev_local : reporter()
88*2f083884Ss.makeev_local , testResults(&reporter)
89*2f083884Ss.makeev_local , line(-1)
90*2f083884Ss.makeev_local {
91*2f083884Ss.makeev_local }
92*2f083884Ss.makeev_local
93*2f083884Ss.makeev_local void PerformCheckWithNonStdThrow()
94*2f083884Ss.makeev_local {
95*2f083884Ss.makeev_local UnitTest::TestDetails const testDetails("testName", "suiteName", "filename", -1);
96*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(testResults, &testDetails);
97*2f083884Ss.makeev_local CHECK_EQUAL(ThrowingFunction(), 123); line = __LINE__;
98*2f083884Ss.makeev_local }
99*2f083884Ss.makeev_local
100*2f083884Ss.makeev_local void PerformCheckWithStdThrow()
101*2f083884Ss.makeev_local {
102*2f083884Ss.makeev_local UnitTest::TestDetails const testDetails("testName", "suiteName", "filename", -1);
103*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(testResults, &testDetails);
104*2f083884Ss.makeev_local CHECK_EQUAL(ThrowingStdExceptionFunction(), 123); line = __LINE__;
105*2f083884Ss.makeev_local }
106*2f083884Ss.makeev_local
107*2f083884Ss.makeev_local RecordingReporter reporter;
108*2f083884Ss.makeev_local UnitTest::TestResults testResults;
109*2f083884Ss.makeev_local int line;
110*2f083884Ss.makeev_local };
111*2f083884Ss.makeev_local
112*2f083884Ss.makeev_local TEST_FIXTURE(CheckEqualFixture, CheckEqualFailsOnException)
113*2f083884Ss.makeev_local {
114*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
115*2f083884Ss.makeev_local CHECK(testResults.GetFailureCount() > 0);
116*2f083884Ss.makeev_local }
117*2f083884Ss.makeev_local
118*2f083884Ss.makeev_local TEST_FIXTURE(CheckEqualFixture, CheckEqualFailsOnStdException)
119*2f083884Ss.makeev_local {
120*2f083884Ss.makeev_local PerformCheckWithStdThrow();
121*2f083884Ss.makeev_local CHECK(testResults.GetFailureCount() > 0);
122*2f083884Ss.makeev_local }
123*2f083884Ss.makeev_local
124*2f083884Ss.makeev_local TEST_FIXTURE(CheckEqualFixture, CheckEqualFailureBecauseOfExceptionContainsCorrectDetails)
125*2f083884Ss.makeev_local {
126*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
127*2f083884Ss.makeev_local
128*2f083884Ss.makeev_local CHECK_EQUAL("testName", reporter.lastFailedTest);
129*2f083884Ss.makeev_local CHECK_EQUAL("suiteName", reporter.lastFailedSuite);
130*2f083884Ss.makeev_local CHECK_EQUAL("filename", reporter.lastFailedFile);
131*2f083884Ss.makeev_local CHECK_EQUAL(line, reporter.lastFailedLine);
132*2f083884Ss.makeev_local }
133*2f083884Ss.makeev_local
134*2f083884Ss.makeev_local TEST_FIXTURE(CheckEqualFixture, CheckEqualFailureBecauseOfStdExceptionContainsCorrectDetails)
135*2f083884Ss.makeev_local {
136*2f083884Ss.makeev_local PerformCheckWithStdThrow();
137*2f083884Ss.makeev_local
138*2f083884Ss.makeev_local CHECK_EQUAL("testName", reporter.lastFailedTest);
139*2f083884Ss.makeev_local CHECK_EQUAL("suiteName", reporter.lastFailedSuite);
140*2f083884Ss.makeev_local CHECK_EQUAL("filename", reporter.lastFailedFile);
141*2f083884Ss.makeev_local CHECK_EQUAL(line, reporter.lastFailedLine);
142*2f083884Ss.makeev_local }
143*2f083884Ss.makeev_local
144*2f083884Ss.makeev_local TEST_FIXTURE(CheckEqualFixture, CheckEqualFailureBecauseOfExceptionIncludesCheckContents)
145*2f083884Ss.makeev_local {
146*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
147*2f083884Ss.makeev_local
148*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "ThrowingFunction()"));
149*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "123"));
150*2f083884Ss.makeev_local }
151*2f083884Ss.makeev_local
152*2f083884Ss.makeev_local TEST_FIXTURE(CheckEqualFixture, CheckEqualFailureBecauseOfStdExceptionIncludesCheckContents)
153*2f083884Ss.makeev_local {
154*2f083884Ss.makeev_local PerformCheckWithStdThrow();
155*2f083884Ss.makeev_local
156*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "ThrowingStdExceptionFunction()"));
157*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "123"));
158*2f083884Ss.makeev_local }
159*2f083884Ss.makeev_local
160*2f083884Ss.makeev_local TEST_FIXTURE(CheckEqualFixture, CheckEqualFailureBecauseOfStandardExceptionIncludesWhat)
161*2f083884Ss.makeev_local {
162*2f083884Ss.makeev_local PerformCheckWithStdThrow();
163*2f083884Ss.makeev_local
164*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "exception (Doh)"));
165*2f083884Ss.makeev_local }
166*2f083884Ss.makeev_local }
167*2f083884Ss.makeev_local
SUITE(CheckCloseExceptionTests)168*2f083884Ss.makeev_local SUITE(CheckCloseExceptionTests)
169*2f083884Ss.makeev_local {
170*2f083884Ss.makeev_local struct CheckCloseFixture
171*2f083884Ss.makeev_local {
172*2f083884Ss.makeev_local CheckCloseFixture()
173*2f083884Ss.makeev_local : reporter()
174*2f083884Ss.makeev_local , testResults(&reporter)
175*2f083884Ss.makeev_local , line(-1)
176*2f083884Ss.makeev_local {
177*2f083884Ss.makeev_local }
178*2f083884Ss.makeev_local
179*2f083884Ss.makeev_local void PerformCheckWithNonStdThrow()
180*2f083884Ss.makeev_local {
181*2f083884Ss.makeev_local UnitTest::TestDetails const testDetails("closeTest", "closeSuite", "filename", -1);
182*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(testResults, &testDetails);
183*2f083884Ss.makeev_local CHECK_CLOSE(static_cast<float>(ThrowingFunction()), 1.0001f, 0.1f); line = __LINE__;
184*2f083884Ss.makeev_local }
185*2f083884Ss.makeev_local
186*2f083884Ss.makeev_local void PerformCheckWithStdThrow()
187*2f083884Ss.makeev_local {
188*2f083884Ss.makeev_local UnitTest::TestDetails const testDetails("closeTest", "closeSuite", "filename", -1);
189*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(testResults, &testDetails);
190*2f083884Ss.makeev_local CHECK_CLOSE(static_cast<float>(ThrowingStdExceptionFunction()), 1.0001f, 0.1f); line = __LINE__;
191*2f083884Ss.makeev_local }
192*2f083884Ss.makeev_local
193*2f083884Ss.makeev_local RecordingReporter reporter;
194*2f083884Ss.makeev_local UnitTest::TestResults testResults;
195*2f083884Ss.makeev_local int line;
196*2f083884Ss.makeev_local };
197*2f083884Ss.makeev_local
198*2f083884Ss.makeev_local TEST_FIXTURE(CheckCloseFixture, CheckCloseFailsOnException)
199*2f083884Ss.makeev_local {
200*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
201*2f083884Ss.makeev_local
202*2f083884Ss.makeev_local CHECK(testResults.GetFailureCount() > 0);
203*2f083884Ss.makeev_local }
204*2f083884Ss.makeev_local
205*2f083884Ss.makeev_local TEST_FIXTURE(CheckCloseFixture, CheckCloseFailsOnStdException)
206*2f083884Ss.makeev_local {
207*2f083884Ss.makeev_local PerformCheckWithStdThrow();
208*2f083884Ss.makeev_local
209*2f083884Ss.makeev_local CHECK(testResults.GetFailureCount() > 0);
210*2f083884Ss.makeev_local }
211*2f083884Ss.makeev_local
212*2f083884Ss.makeev_local TEST_FIXTURE(CheckCloseFixture, CheckCloseFailureBecauseOfExceptionContainsCorrectDetails)
213*2f083884Ss.makeev_local {
214*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
215*2f083884Ss.makeev_local
216*2f083884Ss.makeev_local CHECK_EQUAL("closeTest", reporter.lastFailedTest);
217*2f083884Ss.makeev_local CHECK_EQUAL("closeSuite", reporter.lastFailedSuite);
218*2f083884Ss.makeev_local CHECK_EQUAL("filename", reporter.lastFailedFile);
219*2f083884Ss.makeev_local CHECK_EQUAL(line, reporter.lastFailedLine);
220*2f083884Ss.makeev_local }
221*2f083884Ss.makeev_local
222*2f083884Ss.makeev_local TEST_FIXTURE(CheckCloseFixture, CheckCloseFailureBecauseOfStdExceptionContainsCorrectDetails)
223*2f083884Ss.makeev_local {
224*2f083884Ss.makeev_local PerformCheckWithStdThrow();
225*2f083884Ss.makeev_local
226*2f083884Ss.makeev_local CHECK_EQUAL("closeTest", reporter.lastFailedTest);
227*2f083884Ss.makeev_local CHECK_EQUAL("closeSuite", reporter.lastFailedSuite);
228*2f083884Ss.makeev_local CHECK_EQUAL("filename", reporter.lastFailedFile);
229*2f083884Ss.makeev_local CHECK_EQUAL(line, reporter.lastFailedLine);
230*2f083884Ss.makeev_local }
231*2f083884Ss.makeev_local
232*2f083884Ss.makeev_local TEST_FIXTURE(CheckCloseFixture, CheckCloseFailureBecauseOfExceptionIncludesCheckContents)
233*2f083884Ss.makeev_local {
234*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
235*2f083884Ss.makeev_local
236*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "static_cast<float>(ThrowingFunction())"));
237*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "1.0001f"));
238*2f083884Ss.makeev_local }
239*2f083884Ss.makeev_local
240*2f083884Ss.makeev_local TEST_FIXTURE(CheckCloseFixture, CheckCloseFailureBecauseOfStdExceptionIncludesCheckContents)
241*2f083884Ss.makeev_local {
242*2f083884Ss.makeev_local PerformCheckWithStdThrow();
243*2f083884Ss.makeev_local
244*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "static_cast<float>(ThrowingStdExceptionFunction())"));
245*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "1.0001f"));
246*2f083884Ss.makeev_local }
247*2f083884Ss.makeev_local
248*2f083884Ss.makeev_local TEST_FIXTURE(CheckCloseFixture, CheckCloseFailureBecauseOfStandardExceptionIncludesWhat)
249*2f083884Ss.makeev_local {
250*2f083884Ss.makeev_local PerformCheckWithStdThrow();
251*2f083884Ss.makeev_local
252*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "exception (Doh)"));
253*2f083884Ss.makeev_local }
254*2f083884Ss.makeev_local }
255*2f083884Ss.makeev_local
256*2f083884Ss.makeev_local class ThrowingObject
257*2f083884Ss.makeev_local {
258*2f083884Ss.makeev_local public:
operator [](int) const259*2f083884Ss.makeev_local float operator[](int) const
260*2f083884Ss.makeev_local {
261*2f083884Ss.makeev_local throw "Test throw";
262*2f083884Ss.makeev_local }
263*2f083884Ss.makeev_local };
264*2f083884Ss.makeev_local
265*2f083884Ss.makeev_local class StdThrowingObject
266*2f083884Ss.makeev_local {
267*2f083884Ss.makeev_local public:
operator [](int) const268*2f083884Ss.makeev_local float operator[](int) const
269*2f083884Ss.makeev_local {
270*2f083884Ss.makeev_local throw std::runtime_error("Test throw");
271*2f083884Ss.makeev_local }
272*2f083884Ss.makeev_local };
273*2f083884Ss.makeev_local
SUITE(CheckArrayCloseExceptionTests)274*2f083884Ss.makeev_local SUITE(CheckArrayCloseExceptionTests)
275*2f083884Ss.makeev_local {
276*2f083884Ss.makeev_local struct CheckArrayCloseFixture
277*2f083884Ss.makeev_local {
278*2f083884Ss.makeev_local CheckArrayCloseFixture()
279*2f083884Ss.makeev_local : reporter()
280*2f083884Ss.makeev_local , testResults(&reporter)
281*2f083884Ss.makeev_local , line(-1)
282*2f083884Ss.makeev_local {
283*2f083884Ss.makeev_local }
284*2f083884Ss.makeev_local
285*2f083884Ss.makeev_local void PerformCheckWithNonStdThrow()
286*2f083884Ss.makeev_local {
287*2f083884Ss.makeev_local UnitTest::TestDetails const testDetails("arrayCloseTest", "arrayCloseSuite", "filename", -1);
288*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(testResults, &testDetails);
289*2f083884Ss.makeev_local int const data[4] = { 0, 1, 2, 3 };
290*2f083884Ss.makeev_local CHECK_ARRAY_CLOSE(data, ThrowingObject(), 4, 0.01f); line = __LINE__;
291*2f083884Ss.makeev_local }
292*2f083884Ss.makeev_local
293*2f083884Ss.makeev_local void PerformCheckWithStdThrow()
294*2f083884Ss.makeev_local {
295*2f083884Ss.makeev_local UnitTest::TestDetails const testDetails("arrayCloseTest", "arrayCloseSuite", "filename", -1);
296*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(testResults, &testDetails);
297*2f083884Ss.makeev_local int const data[4] = { 0, 1, 2, 3 };
298*2f083884Ss.makeev_local CHECK_ARRAY_CLOSE(data, StdThrowingObject(), 4, 0.01f); line = __LINE__;
299*2f083884Ss.makeev_local }
300*2f083884Ss.makeev_local
301*2f083884Ss.makeev_local RecordingReporter reporter;
302*2f083884Ss.makeev_local UnitTest::TestResults testResults;
303*2f083884Ss.makeev_local int line;
304*2f083884Ss.makeev_local };
305*2f083884Ss.makeev_local
306*2f083884Ss.makeev_local TEST_FIXTURE(CheckArrayCloseFixture, CheckFailureBecauseOfExceptionContainsCorrectDetails)
307*2f083884Ss.makeev_local {
308*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
309*2f083884Ss.makeev_local
310*2f083884Ss.makeev_local CHECK_EQUAL("arrayCloseTest", reporter.lastFailedTest);
311*2f083884Ss.makeev_local CHECK_EQUAL("arrayCloseSuite", reporter.lastFailedSuite);
312*2f083884Ss.makeev_local CHECK_EQUAL("filename", reporter.lastFailedFile);
313*2f083884Ss.makeev_local CHECK_EQUAL(line, reporter.lastFailedLine);
314*2f083884Ss.makeev_local }
315*2f083884Ss.makeev_local
316*2f083884Ss.makeev_local TEST_FIXTURE(CheckArrayCloseFixture, CheckFailureBecauseOfStdExceptionContainsCorrectDetails)
317*2f083884Ss.makeev_local {
318*2f083884Ss.makeev_local PerformCheckWithStdThrow();
319*2f083884Ss.makeev_local
320*2f083884Ss.makeev_local CHECK_EQUAL("arrayCloseTest", reporter.lastFailedTest);
321*2f083884Ss.makeev_local CHECK_EQUAL("arrayCloseSuite", reporter.lastFailedSuite);
322*2f083884Ss.makeev_local CHECK_EQUAL("filename", reporter.lastFailedFile);
323*2f083884Ss.makeev_local CHECK_EQUAL(line, reporter.lastFailedLine);
324*2f083884Ss.makeev_local }
325*2f083884Ss.makeev_local
326*2f083884Ss.makeev_local TEST_FIXTURE(CheckArrayCloseFixture, CheckFailsOnException)
327*2f083884Ss.makeev_local {
328*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
329*2f083884Ss.makeev_local
330*2f083884Ss.makeev_local CHECK(testResults.GetFailureCount() > 0);
331*2f083884Ss.makeev_local }
332*2f083884Ss.makeev_local
333*2f083884Ss.makeev_local TEST_FIXTURE(CheckArrayCloseFixture, CheckFailsOnStdException)
334*2f083884Ss.makeev_local {
335*2f083884Ss.makeev_local PerformCheckWithStdThrow();
336*2f083884Ss.makeev_local
337*2f083884Ss.makeev_local CHECK(testResults.GetFailureCount() > 0);
338*2f083884Ss.makeev_local }
339*2f083884Ss.makeev_local
340*2f083884Ss.makeev_local TEST_FIXTURE(CheckArrayCloseFixture, CheckFailureOnExceptionIncludesCheckContents)
341*2f083884Ss.makeev_local {
342*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
343*2f083884Ss.makeev_local
344*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "data"));
345*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "ThrowingObject()"));
346*2f083884Ss.makeev_local }
347*2f083884Ss.makeev_local
348*2f083884Ss.makeev_local TEST_FIXTURE(CheckArrayCloseFixture, CheckFailureOnStdExceptionIncludesCheckContents)
349*2f083884Ss.makeev_local {
350*2f083884Ss.makeev_local PerformCheckWithStdThrow();
351*2f083884Ss.makeev_local
352*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "data"));
353*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "StdThrowingObject()"));
354*2f083884Ss.makeev_local }
355*2f083884Ss.makeev_local
356*2f083884Ss.makeev_local TEST_FIXTURE(CheckArrayCloseFixture, CheckFailureOnStdExceptionIncludesWhat)
357*2f083884Ss.makeev_local {
358*2f083884Ss.makeev_local PerformCheckWithStdThrow();
359*2f083884Ss.makeev_local
360*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "exception (Test throw)"));
361*2f083884Ss.makeev_local }
362*2f083884Ss.makeev_local }
363*2f083884Ss.makeev_local
SUITE(CheckArrayEqualExceptionTests)364*2f083884Ss.makeev_local SUITE(CheckArrayEqualExceptionTests)
365*2f083884Ss.makeev_local {
366*2f083884Ss.makeev_local struct CheckArrayEqualFixture
367*2f083884Ss.makeev_local {
368*2f083884Ss.makeev_local CheckArrayEqualFixture()
369*2f083884Ss.makeev_local : reporter()
370*2f083884Ss.makeev_local , testResults(&reporter)
371*2f083884Ss.makeev_local , line(-1)
372*2f083884Ss.makeev_local {
373*2f083884Ss.makeev_local }
374*2f083884Ss.makeev_local
375*2f083884Ss.makeev_local void PerformCheckWithNonStdThrow()
376*2f083884Ss.makeev_local {
377*2f083884Ss.makeev_local UnitTest::TestDetails const testDetails("arrayEqualTest", "arrayEqualSuite", "filename", -1);
378*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(testResults, &testDetails);
379*2f083884Ss.makeev_local int const data[4] = { 0, 1, 2, 3 };
380*2f083884Ss.makeev_local CHECK_ARRAY_EQUAL(data, ThrowingObject(), 4); line = __LINE__;
381*2f083884Ss.makeev_local }
382*2f083884Ss.makeev_local
383*2f083884Ss.makeev_local void PerformCheckWithStdThrow()
384*2f083884Ss.makeev_local {
385*2f083884Ss.makeev_local UnitTest::TestDetails const testDetails("arrayEqualTest", "arrayEqualSuite", "filename", -1);
386*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(testResults, &testDetails);
387*2f083884Ss.makeev_local int const data[4] = { 0, 1, 2, 3 };
388*2f083884Ss.makeev_local CHECK_ARRAY_EQUAL(data, StdThrowingObject(), 4); line = __LINE__;
389*2f083884Ss.makeev_local }
390*2f083884Ss.makeev_local
391*2f083884Ss.makeev_local RecordingReporter reporter;
392*2f083884Ss.makeev_local UnitTest::TestResults testResults;
393*2f083884Ss.makeev_local int line;
394*2f083884Ss.makeev_local };
395*2f083884Ss.makeev_local
396*2f083884Ss.makeev_local TEST_FIXTURE(CheckArrayEqualFixture, CheckFailureBecauseOfExceptionContainsCorrectDetails)
397*2f083884Ss.makeev_local {
398*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
399*2f083884Ss.makeev_local
400*2f083884Ss.makeev_local CHECK_EQUAL("arrayEqualTest", reporter.lastFailedTest);
401*2f083884Ss.makeev_local CHECK_EQUAL("arrayEqualSuite", reporter.lastFailedSuite);
402*2f083884Ss.makeev_local CHECK_EQUAL("filename", reporter.lastFailedFile);
403*2f083884Ss.makeev_local CHECK_EQUAL(line, reporter.lastFailedLine);
404*2f083884Ss.makeev_local }
405*2f083884Ss.makeev_local
406*2f083884Ss.makeev_local TEST_FIXTURE(CheckArrayEqualFixture, CheckFailureBecauseOfStdExceptionContainsCorrectDetails)
407*2f083884Ss.makeev_local {
408*2f083884Ss.makeev_local PerformCheckWithStdThrow();
409*2f083884Ss.makeev_local
410*2f083884Ss.makeev_local CHECK_EQUAL("arrayEqualTest", reporter.lastFailedTest);
411*2f083884Ss.makeev_local CHECK_EQUAL("arrayEqualSuite", reporter.lastFailedSuite);
412*2f083884Ss.makeev_local CHECK_EQUAL("filename", reporter.lastFailedFile);
413*2f083884Ss.makeev_local CHECK_EQUAL(line, reporter.lastFailedLine);
414*2f083884Ss.makeev_local }
415*2f083884Ss.makeev_local
416*2f083884Ss.makeev_local TEST_FIXTURE(CheckArrayEqualFixture, CheckFailsOnException)
417*2f083884Ss.makeev_local {
418*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
419*2f083884Ss.makeev_local
420*2f083884Ss.makeev_local CHECK(testResults.GetFailureCount() > 0);
421*2f083884Ss.makeev_local }
422*2f083884Ss.makeev_local
423*2f083884Ss.makeev_local TEST_FIXTURE(CheckArrayEqualFixture, CheckFailsOnStdException)
424*2f083884Ss.makeev_local {
425*2f083884Ss.makeev_local PerformCheckWithStdThrow();
426*2f083884Ss.makeev_local
427*2f083884Ss.makeev_local CHECK(testResults.GetFailureCount() > 0);
428*2f083884Ss.makeev_local }
429*2f083884Ss.makeev_local
430*2f083884Ss.makeev_local TEST_FIXTURE(CheckArrayEqualFixture, CheckFailureOnExceptionIncludesCheckContents)
431*2f083884Ss.makeev_local {
432*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
433*2f083884Ss.makeev_local
434*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "data"));
435*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "ThrowingObject()"));
436*2f083884Ss.makeev_local }
437*2f083884Ss.makeev_local
438*2f083884Ss.makeev_local TEST_FIXTURE(CheckArrayEqualFixture, CheckFailureOnStdExceptionIncludesCheckContents)
439*2f083884Ss.makeev_local {
440*2f083884Ss.makeev_local PerformCheckWithStdThrow();
441*2f083884Ss.makeev_local
442*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "data"));
443*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "StdThrowingObject()"));
444*2f083884Ss.makeev_local }
445*2f083884Ss.makeev_local
446*2f083884Ss.makeev_local TEST_FIXTURE(CheckArrayEqualFixture, CheckFailureOnStdExceptionIncludesWhat)
447*2f083884Ss.makeev_local {
448*2f083884Ss.makeev_local PerformCheckWithStdThrow();
449*2f083884Ss.makeev_local
450*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "exception (Test throw)"));
451*2f083884Ss.makeev_local }
452*2f083884Ss.makeev_local }
453*2f083884Ss.makeev_local
SUITE(CheckArray2DExceptionTests)454*2f083884Ss.makeev_local SUITE(CheckArray2DExceptionTests)
455*2f083884Ss.makeev_local {
456*2f083884Ss.makeev_local class ThrowingObject2D
457*2f083884Ss.makeev_local {
458*2f083884Ss.makeev_local public:
459*2f083884Ss.makeev_local float* operator[](int) const
460*2f083884Ss.makeev_local {
461*2f083884Ss.makeev_local throw "Test throw";
462*2f083884Ss.makeev_local }
463*2f083884Ss.makeev_local };
464*2f083884Ss.makeev_local
465*2f083884Ss.makeev_local class StdThrowingObject2D
466*2f083884Ss.makeev_local {
467*2f083884Ss.makeev_local public:
468*2f083884Ss.makeev_local float* operator[](int) const
469*2f083884Ss.makeev_local {
470*2f083884Ss.makeev_local throw std::runtime_error("Test throw");
471*2f083884Ss.makeev_local }
472*2f083884Ss.makeev_local };
473*2f083884Ss.makeev_local
474*2f083884Ss.makeev_local struct CheckArray2DCloseFixture
475*2f083884Ss.makeev_local {
476*2f083884Ss.makeev_local CheckArray2DCloseFixture()
477*2f083884Ss.makeev_local : reporter()
478*2f083884Ss.makeev_local , testResults(&reporter)
479*2f083884Ss.makeev_local , line(-1)
480*2f083884Ss.makeev_local {
481*2f083884Ss.makeev_local }
482*2f083884Ss.makeev_local
483*2f083884Ss.makeev_local void PerformCheckWithNonStdThrow()
484*2f083884Ss.makeev_local {
485*2f083884Ss.makeev_local UnitTest::TestDetails const testDetails("array2DCloseTest", "array2DCloseSuite", "filename", -1);
486*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(testResults, &testDetails);
487*2f083884Ss.makeev_local const float data[2][2] = { {0, 1}, {2, 3} };
488*2f083884Ss.makeev_local CHECK_ARRAY2D_CLOSE(data, ThrowingObject2D(), 2, 2, 0.01f); line = __LINE__;
489*2f083884Ss.makeev_local }
490*2f083884Ss.makeev_local
491*2f083884Ss.makeev_local void PerformCheckWithStdThrow()
492*2f083884Ss.makeev_local {
493*2f083884Ss.makeev_local UnitTest::TestDetails const testDetails("array2DCloseTest", "array2DCloseSuite", "filename", -1);
494*2f083884Ss.makeev_local ScopedCurrentTest scopedResults(testResults, &testDetails);
495*2f083884Ss.makeev_local const float data[2][2] = { {0, 1}, {2, 3} };
496*2f083884Ss.makeev_local CHECK_ARRAY2D_CLOSE(data, StdThrowingObject2D(), 2, 2, 0.01f); line = __LINE__;
497*2f083884Ss.makeev_local }
498*2f083884Ss.makeev_local
499*2f083884Ss.makeev_local RecordingReporter reporter;
500*2f083884Ss.makeev_local UnitTest::TestResults testResults;
501*2f083884Ss.makeev_local int line;
502*2f083884Ss.makeev_local };
503*2f083884Ss.makeev_local
504*2f083884Ss.makeev_local TEST_FIXTURE(CheckArray2DCloseFixture, CheckFailureBecauseOfExceptionContainsCorrectDetails)
505*2f083884Ss.makeev_local {
506*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
507*2f083884Ss.makeev_local
508*2f083884Ss.makeev_local CHECK_EQUAL("array2DCloseTest", reporter.lastFailedTest);
509*2f083884Ss.makeev_local CHECK_EQUAL("array2DCloseSuite", reporter.lastFailedSuite);
510*2f083884Ss.makeev_local CHECK_EQUAL("filename", reporter.lastFailedFile);
511*2f083884Ss.makeev_local CHECK_EQUAL(line, reporter.lastFailedLine);
512*2f083884Ss.makeev_local }
513*2f083884Ss.makeev_local
514*2f083884Ss.makeev_local TEST_FIXTURE(CheckArray2DCloseFixture, CheckFailureBecauseOfStdExceptionContainsCorrectDetails)
515*2f083884Ss.makeev_local {
516*2f083884Ss.makeev_local PerformCheckWithStdThrow();
517*2f083884Ss.makeev_local
518*2f083884Ss.makeev_local CHECK_EQUAL("array2DCloseTest", reporter.lastFailedTest);
519*2f083884Ss.makeev_local CHECK_EQUAL("array2DCloseSuite", reporter.lastFailedSuite);
520*2f083884Ss.makeev_local CHECK_EQUAL("filename", reporter.lastFailedFile);
521*2f083884Ss.makeev_local CHECK_EQUAL(line, reporter.lastFailedLine);
522*2f083884Ss.makeev_local }
523*2f083884Ss.makeev_local
524*2f083884Ss.makeev_local TEST_FIXTURE(CheckArray2DCloseFixture, CheckFailsOnException)
525*2f083884Ss.makeev_local {
526*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
527*2f083884Ss.makeev_local
528*2f083884Ss.makeev_local CHECK(testResults.GetFailureCount() > 0);
529*2f083884Ss.makeev_local }
530*2f083884Ss.makeev_local
531*2f083884Ss.makeev_local TEST_FIXTURE(CheckArray2DCloseFixture, CheckFailsOnStdException)
532*2f083884Ss.makeev_local {
533*2f083884Ss.makeev_local PerformCheckWithStdThrow();
534*2f083884Ss.makeev_local
535*2f083884Ss.makeev_local CHECK(testResults.GetFailureCount() > 0);
536*2f083884Ss.makeev_local }
537*2f083884Ss.makeev_local
538*2f083884Ss.makeev_local TEST_FIXTURE(CheckArray2DCloseFixture, CheckFailureOnExceptionIncludesCheckContents)
539*2f083884Ss.makeev_local {
540*2f083884Ss.makeev_local PerformCheckWithNonStdThrow();
541*2f083884Ss.makeev_local
542*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "data"));
543*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "ThrowingObject2D()"));
544*2f083884Ss.makeev_local }
545*2f083884Ss.makeev_local
546*2f083884Ss.makeev_local TEST_FIXTURE(CheckArray2DCloseFixture, CheckFailureOnStdExceptionIncludesCheckContents)
547*2f083884Ss.makeev_local {
548*2f083884Ss.makeev_local PerformCheckWithStdThrow();
549*2f083884Ss.makeev_local
550*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "data"));
551*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "StdThrowingObject2D()"));
552*2f083884Ss.makeev_local }
553*2f083884Ss.makeev_local
554*2f083884Ss.makeev_local TEST_FIXTURE(CheckArray2DCloseFixture, CheckFailureOnStdExceptionIncludesWhat)
555*2f083884Ss.makeev_local {
556*2f083884Ss.makeev_local PerformCheckWithStdThrow();
557*2f083884Ss.makeev_local
558*2f083884Ss.makeev_local CHECK(strstr(reporter.lastFailedMessage, "exception (Test throw)"));
559*2f083884Ss.makeev_local }
560*2f083884Ss.makeev_local }
561*2f083884Ss.makeev_local }
562*2f083884Ss.makeev_local
563*2f083884Ss.makeev_local #endif
564