diff options
author | dan miller | 2007-10-19 05:15:33 +0000 |
---|---|---|
committer | dan miller | 2007-10-19 05:15:33 +0000 |
commit | 79eca25c945a535a7a0325999034bae17da92412 (patch) | |
tree | 40ff433d94859d629aac933d5ec73b382f62ba1a /libraries/ode-0.9/tests/CppTestHarness/HTMLTestReporter.cpp | |
parent | adding ode source to /libraries (diff) | |
download | opensim-SC-79eca25c945a535a7a0325999034bae17da92412.zip opensim-SC-79eca25c945a535a7a0325999034bae17da92412.tar.gz opensim-SC-79eca25c945a535a7a0325999034bae17da92412.tar.bz2 opensim-SC-79eca25c945a535a7a0325999034bae17da92412.tar.xz |
resubmitting ode
Diffstat (limited to 'libraries/ode-0.9/tests/CppTestHarness/HTMLTestReporter.cpp')
-rw-r--r-- | libraries/ode-0.9/tests/CppTestHarness/HTMLTestReporter.cpp | 87 |
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 | |||
11 | namespace CppTestHarness | ||
12 | { | ||
13 | |||
14 | void 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 | |||
22 | void 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 | |||
35 | void 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 | |||