Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | QXunitTestLogger::QXunitTestLogger(const char *filename) | - |
7 | : QAbstractTestLogger(filename) | - |
8 | , listOfTestcases(0) | - |
9 | , currentLogElement(0) | - |
10 | , errorLogElement(0) | - |
11 | , logFormatter(0) | - |
12 | , testCounter(0) | - |
13 | , failureCounter(0) | - |
14 | , errorCounter(0) | - |
15 | { | - |
16 | } | 0 |
17 | | - |
18 | QXunitTestLogger::~QXunitTestLogger() | - |
19 | { | - |
20 | delete currentLogElement; | - |
21 | delete logFormatter; | - |
22 | } | 0 |
23 | | - |
24 | void QXunitTestLogger::startLogging() | - |
25 | { | - |
26 | QAbstractTestLogger::startLogging(); | - |
27 | | - |
28 | logFormatter = new QTestXunitStreamer(this); | - |
29 | delete errorLogElement; | - |
30 | errorLogElement = new QTestElement(QTest::LET_SystemError); | - |
31 | } | 0 |
32 | | - |
33 | void QXunitTestLogger::stopLogging() | - |
34 | { | - |
35 | QTestElement *iterator = listOfTestcases; | - |
36 | | - |
37 | char buf[10]; | - |
38 | | - |
39 | currentLogElement = new QTestElement(QTest::LET_TestSuite); | - |
40 | currentLogElement->addAttribute(QTest::AI_Name, QTestResult::currentTestObjectName()); | - |
41 | | - |
42 | qsnprintf(buf, sizeof(buf), "%i", testCounter); | - |
43 | currentLogElement->addAttribute(QTest::AI_Tests, buf); | - |
44 | | - |
45 | qsnprintf(buf, sizeof(buf), "%i", failureCounter); | - |
46 | currentLogElement->addAttribute(QTest::AI_Failures, buf); | - |
47 | | - |
48 | qsnprintf(buf, sizeof(buf), "%i", errorCounter); | - |
49 | currentLogElement->addAttribute(QTest::AI_Errors, buf); | - |
50 | | - |
51 | QTestElement *property; | - |
52 | QTestElement *properties = new QTestElement(QTest::LET_Properties); | - |
53 | | - |
54 | property = new QTestElement(QTest::LET_Property); | - |
55 | property->addAttribute(QTest::AI_Name, "QTestVersion"); | - |
56 | property->addAttribute(QTest::AI_PropertyValue, "5.0.2"); | - |
57 | properties->addLogElement(property); | - |
58 | | - |
59 | property = new QTestElement(QTest::LET_Property); | - |
60 | property->addAttribute(QTest::AI_Name, "QtVersion"); | - |
61 | property->addAttribute(QTest::AI_PropertyValue, qVersion()); | - |
62 | properties->addLogElement(property); | - |
63 | | - |
64 | currentLogElement->addLogElement(properties); | - |
65 | | - |
66 | currentLogElement->addLogElement(iterator); | - |
67 | | - |
68 | | - |
69 | QTestElement* testcase = iterator; | - |
70 | while (testcase) { never evaluated: testcase | 0 |
71 | testcase->setParent(currentLogElement); | - |
72 | testcase = testcase->nextElement(); | - |
73 | } | 0 |
74 | | - |
75 | currentLogElement->addLogElement(errorLogElement); | - |
76 | | - |
77 | QTestElement *it = currentLogElement; | - |
78 | logFormatter->output(it); | - |
79 | | - |
80 | QAbstractTestLogger::stopLogging(); | - |
81 | } | 0 |
82 | | - |
83 | void QXunitTestLogger::enterTestFunction(const char *function) | - |
84 | { | - |
85 | currentLogElement = new QTestElement(QTest::LET_TestCase); | - |
86 | currentLogElement->addAttribute(QTest::AI_Name, function); | - |
87 | currentLogElement->addToList(&listOfTestcases); | - |
88 | | - |
89 | ++testCounter; | - |
90 | } | 0 |
91 | | - |
92 | void QXunitTestLogger::leaveTestFunction() | - |
93 | { | - |
94 | } | - |
95 | | - |
96 | void QXunitTestLogger::addIncident(IncidentTypes type, const char *description, | - |
97 | const char *file, int line) | - |
98 | { | - |
99 | const char *typeBuf = 0; | - |
100 | char buf[100]; | - |
101 | | - |
102 | switch (type) { | - |
103 | case QAbstractTestLogger::XPass: | - |
104 | ++failureCounter; | - |
105 | typeBuf = "xpass"; | - |
106 | break; | 0 |
107 | case QAbstractTestLogger::Pass: | - |
108 | typeBuf = "pass"; | - |
109 | break; | 0 |
110 | case QAbstractTestLogger::XFail: | - |
111 | typeBuf = "xfail"; | - |
112 | break; | 0 |
113 | case QAbstractTestLogger::Fail: | - |
114 | ++failureCounter; | - |
115 | typeBuf = "fail"; | - |
116 | break; | 0 |
117 | default: | - |
118 | typeBuf = "??????"; | - |
119 | break; | 0 |
120 | } | - |
121 | | - |
122 | if (type == QAbstractTestLogger::Fail || type == QAbstractTestLogger::XPass) { never evaluated: type == QAbstractTestLogger::Fail never evaluated: type == QAbstractTestLogger::XPass | 0 |
123 | QTestElement *failureElement = new QTestElement(QTest::LET_Failure); | - |
124 | failureElement->addAttribute(QTest::AI_Result, typeBuf); | - |
125 | if (file) | 0 |
126 | failureElement->addAttribute(QTest::AI_File, file); never executed: failureElement->addAttribute(QTest::AI_File, file); | 0 |
127 | else | - |
128 | failureElement->addAttribute(QTest::AI_File, ""); never executed: failureElement->addAttribute(QTest::AI_File, ""); | 0 |
129 | qsnprintf(buf, sizeof(buf), "%i", line); | - |
130 | failureElement->addAttribute(QTest::AI_Line, buf); | - |
131 | failureElement->addAttribute(QTest::AI_Description, description); | - |
132 | addTag(failureElement); | - |
133 | currentLogElement->addLogElement(failureElement); | - |
134 | } | 0 |
135 | | - |
136 | | - |
137 | | - |
138 | | - |
139 | | - |
140 | | - |
141 | QTestElementAttribute* resultAttr = | - |
142 | const_cast<QTestElementAttribute*>(currentLogElement->attribute(QTest::AI_Result)); | - |
143 | if (resultAttr) { never evaluated: resultAttr | 0 |
144 | const char* oldResult = resultAttr->value(); | - |
145 | bool overwrite = false; | - |
146 | if (!strcmp(oldResult, "pass")) { never evaluated: !strcmp(oldResult, "pass") | 0 |
147 | overwrite = true; | - |
148 | } | 0 |
149 | else if (!strcmp(oldResult, "xfail")) { never evaluated: !strcmp(oldResult, "xfail") | 0 |
150 | overwrite = (type == QAbstractTestLogger::XPass || type == QAbstractTestLogger::Fail); never evaluated: type == QAbstractTestLogger::XPass never evaluated: type == QAbstractTestLogger::Fail | 0 |
151 | } | 0 |
152 | else if (!strcmp(oldResult, "xpass")) { never evaluated: !strcmp(oldResult, "xpass") | 0 |
153 | overwrite = (type == QAbstractTestLogger::Fail); | - |
154 | } | 0 |
155 | if (overwrite) { never evaluated: overwrite | 0 |
156 | resultAttr->setPair(QTest::AI_Result, typeBuf); | - |
157 | } | 0 |
158 | } | 0 |
159 | else { | - |
160 | currentLogElement->addAttribute(QTest::AI_Result, typeBuf); | - |
161 | } | 0 |
162 | | - |
163 | if (file) | 0 |
164 | currentLogElement->addAttribute(QTest::AI_File, file); never executed: currentLogElement->addAttribute(QTest::AI_File, file); | 0 |
165 | else | - |
166 | currentLogElement->addAttribute(QTest::AI_File, ""); never executed: currentLogElement->addAttribute(QTest::AI_File, ""); | 0 |
167 | | - |
168 | qsnprintf(buf, sizeof(buf), "%i", line); | - |
169 | currentLogElement->addAttribute(QTest::AI_Line, buf); | - |
170 | | - |
171 | | - |
172 | | - |
173 | | - |
174 | | - |
175 | if (type == QAbstractTestLogger::XFail) { never evaluated: type == QAbstractTestLogger::XFail | 0 |
176 | QXunitTestLogger::addMessage(QAbstractTestLogger::Info, description, file, line); | - |
177 | } | 0 |
178 | } | 0 |
179 | | - |
180 | void QXunitTestLogger::addBenchmarkResult(const QBenchmarkResult &result) | - |
181 | { | - |
182 | QTestElement *benchmarkElement = new QTestElement(QTest::LET_Benchmark); | - |
183 | | - |
184 | benchmarkElement->addAttribute( | - |
185 | QTest::AI_Metric, | - |
186 | QTest::benchmarkMetricName(QBenchmarkTestMethodData::current->result.metric)); | - |
187 | benchmarkElement->addAttribute(QTest::AI_Tag, result.context.tag.toUtf8().data()); | - |
188 | benchmarkElement->addAttribute(QTest::AI_Value, QByteArray::number(result.value).constData()); | - |
189 | | - |
190 | char buf[100]; | - |
191 | qsnprintf(buf, sizeof(buf), "%i", result.iterations); | - |
192 | benchmarkElement->addAttribute(QTest::AI_Iterations, buf); | - |
193 | currentLogElement->addLogElement(benchmarkElement); | - |
194 | } | 0 |
195 | | - |
196 | void QXunitTestLogger::addTag(QTestElement* element) | - |
197 | { | - |
198 | const char *tag = QTestResult::currentDataTag(); | - |
199 | const char *gtag = QTestResult::currentGlobalDataTag(); | - |
200 | const char *filler = (tag && gtag) ? ":" : ""; | 0 |
201 | if ((!tag || !tag[0]) && (!gtag || !gtag[0])) { never evaluated: !gtag[0] | 0 |
202 | return; | 0 |
203 | } | - |
204 | | - |
205 | if (!tag) { | 0 |
206 | tag = ""; | - |
207 | } | 0 |
208 | if (!gtag) { | 0 |
209 | gtag = ""; | - |
210 | } | 0 |
211 | | - |
212 | QTestCharBuffer buf; | - |
213 | QTest::qt_asprintf(&buf, "%s%s%s", gtag, filler, tag); | - |
214 | element->addAttribute(QTest::AI_Tag, buf.constData()); | - |
215 | } | 0 |
216 | | - |
217 | void QXunitTestLogger::addMessage(MessageTypes type, const char *message, const char *file, int line) | - |
218 | { | - |
219 | QTestElement *errorElement = new QTestElement(QTest::LET_Error); | - |
220 | const char *typeBuf = 0; | - |
221 | | - |
222 | switch (type) { | - |
223 | case QAbstractTestLogger::Warn: | - |
224 | typeBuf = "warn"; | - |
225 | break; | 0 |
226 | case QAbstractTestLogger::QSystem: | - |
227 | typeBuf = "system"; | - |
228 | break; | 0 |
229 | case QAbstractTestLogger::QDebug: | - |
230 | typeBuf = "qdebug"; | - |
231 | break; | 0 |
232 | case QAbstractTestLogger::QWarning: | - |
233 | typeBuf = "qwarn"; | - |
234 | break; | 0 |
235 | case QAbstractTestLogger::QFatal: | - |
236 | typeBuf = "qfatal"; | - |
237 | break; | 0 |
238 | case QAbstractTestLogger::Skip: | - |
239 | typeBuf = "skip"; | - |
240 | break; | 0 |
241 | case QAbstractTestLogger::Info: | - |
242 | typeBuf = "info"; | - |
243 | break; | 0 |
244 | default: | - |
245 | typeBuf = "??????"; | - |
246 | break; | 0 |
247 | } | - |
248 | | - |
249 | errorElement->addAttribute(QTest::AI_Type, typeBuf); | - |
250 | errorElement->addAttribute(QTest::AI_Description, message); | - |
251 | addTag(errorElement); | - |
252 | | - |
253 | if (file) | 0 |
254 | errorElement->addAttribute(QTest::AI_File, file); never executed: errorElement->addAttribute(QTest::AI_File, file); | 0 |
255 | else | - |
256 | errorElement->addAttribute(QTest::AI_File, ""); never executed: errorElement->addAttribute(QTest::AI_File, ""); | 0 |
257 | | - |
258 | char buf[100]; | - |
259 | qsnprintf(buf, sizeof(buf), "%i", line); | - |
260 | errorElement->addAttribute(QTest::AI_Line, buf); | - |
261 | | - |
262 | currentLogElement->addLogElement(errorElement); | - |
263 | ++errorCounter; | - |
264 | | - |
265 | | - |
266 | if (errorLogElement) { never evaluated: errorLogElement | 0 |
267 | QTestElement *systemErrorElement = new QTestElement(QTest::LET_Error); | - |
268 | systemErrorElement->addAttribute(QTest::AI_Description, message); | - |
269 | errorLogElement->addLogElement(systemErrorElement); | - |
270 | } | 0 |
271 | } | 0 |
272 | | - |
273 | | - |
274 | | - |
| | |