2 #ifndef TUT_CPPUNIT_REPORTER
3 #define TUT_CPPUNIT_REPORTER
20 std::vector<tut::test_result> failed_tests_;
21 std::vector<tut::test_result> passed_tests_;
22 const std::string filename_;
23 std::auto_ptr<std::ostream> stream_;
34 stream_(
new std::ofstream(filename_.c_str()))
36 if (!stream_->good()) {
37 throw tut_error(
"Cannot open output file `" + filename_ +
"`");
59 failed_tests_.clear();
60 passed_tests_.clear();
65 assert(tr.result != test_result::dummy );
67 (tr.result == test_result::skipped) )
69 passed_tests_.push_back(tr);
73 failed_tests_.push_back(tr);
81 std::string failure_type;
82 std::string failure_msg;
84 *stream_ <<
"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" << std::endl
85 <<
"<TestRun>" << std::endl;
87 if (failed_tests_.size() > 0)
89 *stream_ <<
" <FailedTests>" << std::endl;
91 for (
unsigned int i=0; i<failed_tests_.size(); i++)
93 switch (failed_tests_[i].result)
96 failure_type =
"Assertion";
101 failure_type =
"Assertion";
102 failure_msg =
"Thrown exception: " + failed_tests_[i].exception_typeid +
'\n';
106 failure_type =
"Assertion";
107 failure_msg =
"Destructor failed\n";
111 failure_type =
"Error";
112 failure_msg =
"Test application terminated abnormally\n";
115 case test_result::ex_ctor:
116 failure_type =
"Error";
117 failure_msg =
"Constructor has thrown an exception: " + failed_tests_[i].exception_typeid +
'\n';
120 case test_result::rethrown:
121 failure_type =
"Assertion";
122 failure_msg =
"Child failed\n";
126 failure_type =
"Error";
127 failure_msg =
"Unknown test status, this should have never happened. "
128 "You may just have found a bug in TUT, please report it immediately.\n";
133 *stream_ <<
" <FailedTest id=\"" << failed_tests_[i].test <<
"\">" << std::endl
134 <<
" <Name>" <<
encode(failed_tests_[i].group) +
"::" +
encode(failed_tests_[i].name) <<
"</Name>" << std::endl
135 <<
" <FailureType>" << failure_type <<
"</FailureType>" << std::endl
136 <<
" <Location>" << std::endl
137 <<
" <File>Unknown</File>" << std::endl
138 <<
" <Line>Unknown</Line>" << std::endl
139 <<
" </Location>" << std::endl
140 <<
" <Message>" <<
encode(failure_msg + failed_tests_[i].message) <<
"</Message>" << std::endl
141 <<
" </FailedTest>" << std::endl;
144 *stream_ <<
" </FailedTests>" << std::endl;
148 if (passed_tests_.size() > 0) {
149 *stream_ <<
" <SuccessfulTests>" << std::endl;
151 for (
unsigned int i=0; i<passed_tests_.size(); i++)
153 *stream_ <<
" <Test id=\"" << passed_tests_[i].test <<
"\">" << std::endl
154 <<
" <Name>" <<
encode(passed_tests_[i].group) +
"::" +
encode(passed_tests_[i].name) <<
"</Name>" << std::endl
155 <<
" </Test>" << std::endl;
158 *stream_ <<
" </SuccessfulTests>" << std::endl;
162 *stream_ <<
" <Statistics>" << std::endl
163 <<
" <Tests>" << (failed_tests_.size() + passed_tests_.size()) <<
"</Tests>" << std::endl
164 <<
" <FailuresTotal>" << failed_tests_.size() <<
"</FailuresTotal>" << std::endl
165 <<
" <Errors>" << errors <<
"</Errors>" << std::endl
166 <<
" <Failures>" << failures <<
"</Failures>" << std::endl
167 <<
" </Statistics>" << std::endl;
170 *stream_ <<
"</TestRun>" << std::endl;
173 virtual bool all_ok()
const
175 return failed_tests_.empty();
184 static std::string
encode(
const std::string & text)
188 for (
unsigned int i=0; i<text.length(); ++i) {
Definition: tut_exception.hpp:13
void run_completed()
Definition: tut_cppunit_reporter.hpp:77
test finished successfully
Definition: tut_result.hpp:91
Definition: tut_cppunit_reporter.hpp:18
test finished successfully, but test destructor throwed
Definition: tut_result.hpp:94
test failed with ensure() or fail() methods
Definition: tut_result.hpp:92
Definition: tut_result.hpp:69
test forced test application to terminate abnormally
Definition: tut_result.hpp:95
test throwed an exceptions
Definition: tut_result.hpp:93
void run_started()
Definition: tut_cppunit_reporter.hpp:57
static std::string encode(const std::string &text)
Encodes text to XML XML-reserved characters (e.g. "<") are encoded according to specification.
Definition: tut_cppunit_reporter.hpp:184
void test_completed(const tut::test_result &tr)
Definition: tut_cppunit_reporter.hpp:63
Definition: tut_runner.hpp:38