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