Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
188 lines (146 loc) · 5.84 KB

File metadata and controls

188 lines (146 loc) · 5.84 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include "../../config.h"
#ifndef UNITTEST_NO_DEFERRED_REPORTER
#include "../../unittestpp.h"
#include "../XmlTestReporter.h"
#include <sstream>
using namespace UnitTest;
using std::ostringstream;
namespace
{
#ifndef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM
// Overload to let MemoryOutStream accept std::string
MemoryOutStream& operator<<(MemoryOutStream& s, const std::string& value)
{
s << value.c_str();
return s;
}
#endif
struct XmlTestReporterFixture
{
XmlTestReporterFixture()
: reporter(output)
{
}
ostringstream output;
XmlTestReporter reporter;
};
TEST_FIXTURE(XmlTestReporterFixture, MultipleCharactersAreEscaped)
{
TestDetails const details("TestName", "suite", "filename.h", 4321);
reporter.ReportTestStart(details);
reporter.ReportFailure(details, "\"\"\'\'&&<<>>");
reporter.ReportTestFinish(details, 0.1f);
reporter.ReportSummary(1, 2, 3, 0.1f);
char const* expected =
"<?xml version=\"1.0\"?>"
"<unittest-results tests=\"1\" failedtests=\"2\" failures=\"3\" time=\"0.1\">"
"<test suite=\"suite\" name=\"TestName\" time=\"0.1\">"
"<failure message=\"filename.h(4321) : "
"&quot;&quot;&apos;&apos;&amp;&amp;&lt;&lt;&gt;&gt;\"/>"
"</test>"
"</unittest-results>";
CHECK_EQUAL(expected, output.str());
}
TEST_FIXTURE(XmlTestReporterFixture, OutputIsCachedUntilReportSummaryIsCalled)
{
TestDetails const details("", "", "", 0);
reporter.ReportTestStart(details);
reporter.ReportFailure(details, "message");
reporter.ReportTestFinish(details, 1.0F);
CHECK(output.str().empty());
reporter.ReportSummary(1, 1, 1, 1.0f);
CHECK(!output.str().empty());
}
TEST_FIXTURE(XmlTestReporterFixture, EmptyReportSummaryFormat)
{
reporter.ReportSummary(0, 0, 0, 0.1f);
const char *expected =
"<?xml version=\"1.0\"?>"
"<unittest-results tests=\"0\" failedtests=\"0\" failures=\"0\" time=\"0.1\">"
"</unittest-results>";
CHECK_EQUAL(expected, output.str());
}
TEST_FIXTURE(XmlTestReporterFixture, SingleSuccessfulTestReportSummaryFormat)
{
TestDetails const details("TestName", "DefaultSuite", "", 0);
reporter.ReportTestStart(details);
reporter.ReportSummary(1, 0, 0, 0.1f);
const char *expected =
"<?xml version=\"1.0\"?>"
"<unittest-results tests=\"1\" failedtests=\"0\" failures=\"0\" time=\"0.1\">"
"<test suite=\"DefaultSuite\" name=\"TestName\" time=\"0\"/>"
"</unittest-results>";
CHECK_EQUAL(expected, output.str());
}
TEST_FIXTURE(XmlTestReporterFixture, SingleFailedTestReportSummaryFormat)
{
TestDetails const details("A Test", "suite", "A File", 4321);
reporter.ReportTestStart(details);
reporter.ReportFailure(details, "A Failure");
reporter.ReportSummary(1, 1, 1, 0.1f);
const char *expected =
"<?xml version=\"1.0\"?>"
"<unittest-results tests=\"1\" failedtests=\"1\" failures=\"1\" time=\"0.1\">"
"<test suite=\"suite\" name=\"A Test\" time=\"0\">"
"<failure message=\"A File(4321) : A Failure\"/>"
"</test>"
"</unittest-results>";
CHECK_EQUAL(expected, output.str());
}
TEST_FIXTURE(XmlTestReporterFixture, FailureMessageIsXMLEscaped)
{
TestDetails const details("TestName", "suite", "filename.h", 4321);
reporter.ReportTestStart(details);
reporter.ReportFailure(details, "\"\'&<>");
reporter.ReportTestFinish(details, 0.1f);
reporter.ReportSummary(1, 1, 1, 0.1f);
char const* expected =
"<?xml version=\"1.0\"?>"
"<unittest-results tests=\"1\" failedtests=\"1\" failures=\"1\" time=\"0.1\">"
"<test suite=\"suite\" name=\"TestName\" time=\"0.1\">"
"<failure message=\"filename.h(4321) : &quot;&apos;&amp;&lt;&gt;\"/>"
"</test>"
"</unittest-results>";
CHECK_EQUAL(expected, output.str());
}
TEST_FIXTURE(XmlTestReporterFixture, OneFailureAndOneSuccess)
{
TestDetails const failedDetails("FailedTest", "suite", "fail.h", 1);
reporter.ReportTestStart(failedDetails);
reporter.ReportFailure(failedDetails, "expected 1 but was 2");
reporter.ReportTestFinish(failedDetails, 0.1f);
TestDetails const succeededDetails("SucceededTest", "suite", "", 0);
reporter.ReportTestStart(succeededDetails);
reporter.ReportTestFinish(succeededDetails, 1.0f);
reporter.ReportSummary(2, 1, 1, 1.1f);
char const* expected =
"<?xml version=\"1.0\"?>"
"<unittest-results tests=\"2\" failedtests=\"1\" failures=\"1\" time=\"1.1\">"
"<test suite=\"suite\" name=\"FailedTest\" time=\"0.1\">"
"<failure message=\"fail.h(1) : expected 1 but was 2\"/>"
"</test>"
"<test suite=\"suite\" name=\"SucceededTest\" time=\"1\"/>"
"</unittest-results>";
CHECK_EQUAL(expected, output.str());
}
TEST_FIXTURE(XmlTestReporterFixture, MultipleFailures)
{
TestDetails const failedDetails1("FailedTest", "suite", "fail.h", 1);
TestDetails const failedDetails2("FailedTest", "suite", "fail.h", 31);
reporter.ReportTestStart(failedDetails1);
reporter.ReportFailure(failedDetails1, "expected 1 but was 2");
reporter.ReportFailure(failedDetails2, "expected one but was two");
reporter.ReportTestFinish(failedDetails1, 0.1f);
reporter.ReportSummary(1, 1, 2, 1.1f);
char const* expected =
"<?xml version=\"1.0\"?>"
"<unittest-results tests=\"1\" failedtests=\"1\" failures=\"2\" time=\"1.1\">"
"<test suite=\"suite\" name=\"FailedTest\" time=\"0.1\">"
"<failure message=\"fail.h(1) : expected 1 but was 2\"/>"
"<failure message=\"fail.h(31) : expected one but was two\"/>"
"</test>"
"</unittest-results>";
CHECK_EQUAL(expected, output.str());
}
}
#endif
Morty Proxy This is a proxified and sanitized view of the page, visit original site.