Mercurial > fife-parpg
annotate ext/UnitTest++/src/Test.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 |
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 #include "Config.h" |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 #include "Test.h" |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 #include "TestList.h" |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 #include "TestResults.h" |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 #include "AssertException.h" |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 #include "MemoryOutStream.h" |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 #ifdef UNITTEST_POSIX |
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 namespace UnitTest { |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 TestList& Test::GetTestList() |
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 static TestList s_list; |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 return s_list; |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 } |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 Test::Test(char const* testName, char const* suiteName, char const* filename, int const lineNumber) |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 : m_details(testName, suiteName, filename, lineNumber) |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 , next(0) |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 , m_timeConstraintExempt(false) |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 { |
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 |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 Test::~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 } |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 void Test::Run(TestResults& testResults) const |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 { |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 try |
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 #ifdef UNITTEST_POSIX |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 UNITTEST_THROW_SIGNALS |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 #endif |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 RunImpl(testResults); |
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 catch (AssertException const& e) |
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 testResults.OnTestFailure( 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
|
43 } |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 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
|
45 { |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 MemoryOutStream stream; |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 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
|
48 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
|
49 } |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 catch (...) |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 { |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 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
|
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 |
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 void Test::RunImpl(TestResults&) const |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 { |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 } |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 |
0d325e9d5953
added unittest++ files into ext. Not hooked into build scripts yet
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 } |