aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ode-0.9/tests/CppTestHarness/HTMLTestReporter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ode-0.9/tests/CppTestHarness/HTMLTestReporter.cpp')
-rw-r--r--libraries/ode-0.9/tests/CppTestHarness/HTMLTestReporter.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/libraries/ode-0.9/tests/CppTestHarness/HTMLTestReporter.cpp b/libraries/ode-0.9/tests/CppTestHarness/HTMLTestReporter.cpp
new file mode 100644
index 0000000..fd4acb1
--- /dev/null
+++ b/libraries/ode-0.9/tests/CppTestHarness/HTMLTestReporter.cpp
@@ -0,0 +1,87 @@
1#include "HTMLTestReporter.h"
2
3#ifdef _MSC_VER
4# pragma warning(disable:4996) // shut the secure crt stuff up, ctime is used correctly here.
5#endif
6
7#include <iostream>
8#include <ctime>
9#include <sstream>
10
11namespace CppTestHarness
12{
13
14void HTMLTestReporter::ReportFailure(char const* file, int const line, std::string const failure)
15{
16 std::stringstream msg;
17 msg << file << "(" << line << ") : " << failure;
18
19 m_failureMessages.push_back(msg.str());
20}
21
22void HTMLTestReporter::ReportSingleResult(const std::string& testName, bool failed)
23{
24 ResultRecord r;
25 r.testName = testName;
26 r.failed = failed;
27
28 //get reported failures and clear temp list
29 r.failureMessages = m_failureMessages;
30 m_failureMessages.clear();
31
32 m_results.push_back(r);
33}
34
35void HTMLTestReporter::ReportSummary(int const testCount, int const failureCount)
36{
37 std::ostream& os = std::cout;
38
39 //TODO: make all strings html safe
40 os << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
41 os << "<html>\n";
42 os << "<head>\n";
43 os << " <title>Test Report</title>\n";
44 os << "</head>\n";
45 os << "<body text=\"black\" bgcolor=\"white\">\n";
46
47 std::time_t currtime;
48 std::time(&currtime);
49
50 os << "<h1>Test Report: " << std::ctime(&currtime) << "</h1>\n";
51 os << "<p><em>";
52 os << testCount << " tests run.<br />\n";
53 os << failureCount << " failed.<br />\n";
54 os << "</em></p>";
55
56 os << "<table border=1 bgcolor=\"#dddddd\">";
57
58 //for each single test
59 for (ResultList::iterator i = m_results.begin(); i != m_results.end(); ++i)
60 {
61 os << "<tr>";
62 os << "<td><strong>" << i->testName << "</strong></td>";
63
64 if (i->failed)
65 os << "<td bgcolor=\"#ff0000\"><strong>FAILED</strong></td>";
66 else
67 os << "<td bgcolor=\"#00ee00\"><strong>PASSED</strong></td>";
68
69 os << "</tr><tr><td>";
70 if (i->failed) os << "<ul>";
71
72 for (MessageList::iterator j = i->failureMessages.begin(); j != i->failureMessages.end(); ++j)
73 {
74 os << "<li><code>"<< *j << "</code></li>\n";
75 }
76
77 if (i->failed) os << "</ul>";
78 os << "</td></tr>";
79 }
80
81 os << "</table>";
82 os << "</body>";
83 os << "</html>";
84}
85
86}
87