Mercurial > fife-parpg
comparison ext/UnitTest++/src/TestMacros.h @ 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 #ifndef UNITTEST_TESTMACROS_H | |
2 #define UNITTEST_TESTMACROS_H | |
3 | |
4 #include "Config.h" | |
5 | |
6 #ifndef UNITTEST_POSIX | |
7 #define UNITTEST_THROW_SIGNALS | |
8 #else | |
9 #include "Posix/SignalTranslator.h" | |
10 #endif | |
11 | |
12 #ifdef TEST | |
13 #error UnitTest++ redefines TEST | |
14 #endif | |
15 | |
16 #define SUITE(Name) \ | |
17 namespace Name { \ | |
18 namespace UnitTestSuite { \ | |
19 inline char const* GetSuiteName () { \ | |
20 return #Name ; \ | |
21 } \ | |
22 } \ | |
23 } \ | |
24 namespace Name | |
25 | |
26 #define TEST_EX(Name, List) \ | |
27 class Test##Name : public UnitTest::Test \ | |
28 { \ | |
29 public: \ | |
30 Test##Name() : Test(#Name, UnitTestSuite::GetSuiteName(), __FILE__, __LINE__) {} \ | |
31 private: \ | |
32 virtual void RunImpl(UnitTest::TestResults& testResults_) const; \ | |
33 } test##Name##Instance; \ | |
34 \ | |
35 UnitTest::ListAdder adder##Name (List, &test##Name##Instance); \ | |
36 \ | |
37 void Test##Name::RunImpl(UnitTest::TestResults& testResults_) const | |
38 | |
39 | |
40 #define TEST(Name) TEST_EX(Name, UnitTest::Test::GetTestList()) | |
41 | |
42 | |
43 #define TEST_FIXTURE_EX(Fixture, Name, List) \ | |
44 class Fixture##Name##Helper : public Fixture \ | |
45 { \ | |
46 public: \ | |
47 Fixture##Name##Helper(UnitTest::TestDetails const& details) : m_details(details) {} \ | |
48 void RunTest(UnitTest::TestResults& testResults_); \ | |
49 UnitTest::TestDetails const& m_details; \ | |
50 private: \ | |
51 Fixture##Name##Helper(Fixture##Name##Helper const&); \ | |
52 Fixture##Name##Helper& operator =(Fixture##Name##Helper const&); \ | |
53 }; \ | |
54 \ | |
55 class Test##Fixture##Name : public UnitTest::Test \ | |
56 { \ | |
57 public: \ | |
58 Test##Fixture##Name() : Test(#Name, UnitTestSuite::GetSuiteName(), __FILE__, __LINE__) {} \ | |
59 private: \ | |
60 virtual void RunImpl(UnitTest::TestResults& testResults_) const; \ | |
61 } test##Fixture##Name##Instance; \ | |
62 \ | |
63 UnitTest::ListAdder adder##Fixture##Name (List, &test##Fixture##Name##Instance); \ | |
64 \ | |
65 void Test##Fixture##Name::RunImpl(UnitTest::TestResults& testResults_) const \ | |
66 { \ | |
67 bool ctorOk = false; \ | |
68 try { \ | |
69 Fixture##Name##Helper fixtureHelper(m_details); \ | |
70 ctorOk = true; \ | |
71 try { \ | |
72 UNITTEST_THROW_SIGNALS; \ | |
73 fixtureHelper.RunTest(testResults_); \ | |
74 } catch (UnitTest::AssertException const& e) { \ | |
75 testResults_.OnTestFailure(UnitTest::TestDetails(m_details.testName, m_details.suiteName, e.Filename(), e.LineNumber()), e.what()); \ | |
76 } catch (std::exception const& e) { \ | |
77 UnitTest::MemoryOutStream stream; \ | |
78 stream << "Unhandled exception: " << e.what(); \ | |
79 testResults_.OnTestFailure(m_details, stream.GetText()); \ | |
80 } catch (...) { testResults_.OnTestFailure(m_details, "Unhandled exception: Crash!"); } \ | |
81 } \ | |
82 catch (...) { \ | |
83 if (ctorOk) \ | |
84 { \ | |
85 testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \ | |
86 "Unhandled exception while destroying fixture " #Fixture); \ | |
87 } \ | |
88 else \ | |
89 { \ | |
90 testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \ | |
91 "Unhandled exception while constructing fixture " #Fixture); \ | |
92 } \ | |
93 } \ | |
94 } \ | |
95 void Fixture##Name##Helper::RunTest(UnitTest::TestResults& testResults_) | |
96 | |
97 #define TEST_FIXTURE(Fixture,Name) TEST_FIXTURE_EX(Fixture, Name, UnitTest::Test::GetTestList()) | |
98 | |
99 #endif |