25 explicit ReporterXml (std::ostream& ostream = std::cout);
28 void Clear ()
override;
36 std::string xml_escape (
const std::string& value);
37 std::string build_failure_message (
const std::string& file,
int line, std::string
const& message);
43 std::string start_time;
48std::string ReporterXml::xml_escape (
const std::string& value)
51 std::string escaped = value;
52 auto replace_char = [&escaped] (
char c,
const char* repl){
53 for (
auto pos = escaped.find(c); pos != std::string::npos; pos = escaped.find(c, pos + 1))
54 escaped.replace(pos, 1, repl);
57 replace_char (
'&',
"&");
58 replace_char (
'<',
"<");
59 replace_char (
'>',
">");
60 replace_char (
'\'',
"'");
61 replace_char (
'\"',
""");
67std::string ReporterXml::build_failure_message (
const std::string& file,
int line, std::string
const& message)
69 std::ostringstream failureMessage;
70 failureMessage << file <<
"(" << line <<
") : " << message;
71 return failureMessage.str();
82 , orig_state (nullptr)
87 const struct tm* t = gmtime (&now);
88 strftime (tmp,
sizeof (tmp),
"%Y-%m-%d %H:%M:%SZ", t);
90 orig_state.copyfmt (os);
91 os <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
102 std::wstring wcmd{ GetCommandLineW () };
103 int nsz = WideCharToMultiByte (CP_UTF8, 0, wcmd.c_str (), -1, 0, 0, 0, 0);
107 WideCharToMultiByte (CP_UTF8, 0, wcmd.c_str (), -1, &cmd[0], nsz, 0, 0);
108 cmd.resize (nsz - 1);
114 const struct tm* t = gmtime (&now);
115 strftime (tmp,
sizeof (tmp),
"%Y-%m-%d %H:%M:%SZ", t);
116 os.copyfmt (orig_state);
118 os <<
"<utpp-results"
122 <<
" duration=\"" << std::fixed << std::setprecision (3) <<
total_time_msec / 1000. <<
'\"'
124 os <<
" <start-time>" << start_time <<
"</start-time>" << std::endl;
126 os <<
" <command-line>" << xml_escape (cmd) <<
"</command-line>" << std::endl;
130 if (i->test_name.empty ())
133 os <<
" </suite>" << std::endl;
134 suite = i->suite_name;
138 os <<
" <suite name=\"" << suite <<
'\"';
139 if ((i + 1) ==
results.cend () || (i + 1)->test_name.empty ())
145 os <<
'>' << std::endl;
151 if (!i->failures.empty ())
158 os <<
" </suite>" << std::endl;
161 <<
"</end-time>" << std::endl;
162 os <<
"</utpp-results>" << std::endl;
172 const struct tm* t = gmtime (&now);
173 strftime (tmp,
sizeof (tmp),
"%Y-%m-%d %H:%M:%SZ", t);
183 <<
" name=\"" << result.
test_name <<
"\""
188void ReporterXml::EndTest (
const ReporterDeferred::TestResult& result)
190 if (result.failures.empty ())
201 os <<
">" << std::endl;
203 for (
auto& fail : result.failures)
205 std::string escapedMessage = xml_escape (fail.message);
206 std::string message = build_failure_message (fail.filename, fail.line_number, escapedMessage);
208 os <<
" <failure" <<
" message=\"" << message <<
"\"" <<
"/>" << std::endl;
void Clear() override
Reset all statistics.
Definition utpp.h:706
std::deque< TestResult > results
Results of all tests.
Definition utpp.h:349
int total_failures_count
total number of failures
Definition utpp.h:317
int total_test_count
total number of tests
Definition utpp.h:315
virtual int Summary()
Generate results report.
Definition utpp.h:304
int total_failed_count
total number of failed tests
Definition utpp.h:316
int total_time_msec
total running time in milliseconds
Definition utpp.h:318
int Summary() override
Generate XML report.
Definition reporter_xml.h:97
void Clear() override
Reset all statistics.
Definition reporter_xml.h:167
ReporterXml(std::ostream &ostream=std::cout)
Definition reporter_xml.h:80
Test results including all failure messages
Definition utpp.h:339
std::string test_name
test name
Definition utpp.h:344
int test_time_ms
test running time in milliseconds
Definition utpp.h:345
#define DEFAULT_SUITE
Name of default suite.
Definition utpp.h:54