author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 13 | c0432d11811c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtTest module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qtestxmlstreamer.h" |
|
43 |
#include "qtestelement.h" |
|
44 |
#include "qtestelementattribute.h" |
|
45 |
||
46 |
#include "QtTest/private/qtestlog_p.h" |
|
47 |
#include "QtTest/private/qtestresult_p.h" |
|
48 |
#include "QtTest/private/qxmltestlogger_p.h" |
|
49 |
||
50 |
#include <string.h> |
|
51 |
#include <stdio.h> |
|
52 |
||
53 |
QT_BEGIN_NAMESPACE |
|
54 |
||
55 |
QTestXmlStreamer::QTestXmlStreamer() |
|
56 |
:QTestBasicStreamer() |
|
57 |
{ |
|
58 |
} |
|
59 |
||
60 |
QTestXmlStreamer::~QTestXmlStreamer() |
|
61 |
{} |
|
62 |
||
63 |
void QTestXmlStreamer::formatStart(const QTestElement *element, QTestCharBuffer *formatted) const |
|
64 |
{ |
|
65 |
if(!element || !formatted) |
|
66 |
return; |
|
67 |
||
68 |
switch(element->elementType()){ |
|
69 |
case QTest::LET_TestCase: { |
|
70 |
QTestCharBuffer quotedTf; |
|
71 |
QXmlTestLogger::xmlQuote("edTf, element->attributeValue(QTest::AI_Name)); |
|
72 |
||
73 |
QTest::qt_asprintf(formatted, "<TestFunction name=\"%s\">\n", quotedTf.constData()); |
|
74 |
break; |
|
75 |
} |
|
76 |
case QTest::LET_Failure: { |
|
77 |
QTestCharBuffer cdataDesc; |
|
78 |
QXmlTestLogger::xmlCdata(&cdataDesc, element->attributeValue(QTest::AI_Description)); |
|
79 |
||
80 |
QTestCharBuffer location; |
|
81 |
QTestCharBuffer quotedFile; |
|
82 |
QXmlTestLogger::xmlQuote("edFile, element->attributeValue(QTest::AI_File)); |
|
83 |
||
84 |
QTest::qt_asprintf(&location, "%s=\"%s\" %s=\"%s\"", |
|
85 |
element->attributeName(QTest::AI_File), |
|
86 |
quotedFile.constData(), |
|
87 |
element->attributeName(QTest::AI_Line), |
|
88 |
element->attributeValue(QTest::AI_Line)); |
|
89 |
||
90 |
if (element->attribute(QTest::AI_Tag)) { |
|
91 |
QTestCharBuffer cdataTag; |
|
92 |
QXmlTestLogger::xmlCdata(&cdataTag, element->attributeValue(QTest::AI_Tag)); |
|
93 |
QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s>\n" |
|
94 |
" <DataTag><![CDATA[%s]]></DataTag>\n" |
|
95 |
" <Description><![CDATA[%s]]></Description>\n" |
|
96 |
"</Incident>\n", element->attributeValue(QTest::AI_Result), |
|
97 |
location.constData(), cdataTag.constData(), cdataDesc.constData()); |
|
98 |
} |
|
99 |
else { |
|
100 |
QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s>\n" |
|
101 |
" <Description><![CDATA[%s]]></Description>\n" |
|
102 |
"</Incident>\n", element->attributeValue(QTest::AI_Result), |
|
103 |
location.constData(), cdataDesc.constData()); |
|
104 |
} |
|
105 |
break; |
|
106 |
} |
|
107 |
case QTest::LET_Error: { |
|
108 |
// assuming type and attribute names don't need quoting |
|
109 |
QTestCharBuffer quotedFile; |
|
110 |
QTestCharBuffer cdataDesc; |
|
111 |
QXmlTestLogger::xmlQuote("edFile, element->attributeValue(QTest::AI_File)); |
|
112 |
QXmlTestLogger::xmlCdata(&cdataDesc, element->attributeValue(QTest::AI_Description)); |
|
113 |
||
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
114 |
QTestCharBuffer tagbuf; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
115 |
if (element->attribute(QTest::AI_Tag)) { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
116 |
QTestCharBuffer cdataTag; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
117 |
QXmlTestLogger::xmlCdata(&cdataTag, element->attributeValue(QTest::AI_Tag)); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
118 |
QTest::qt_asprintf(&tagbuf, " <DataTag><![CDATA[%s]]></DataTag>\n", cdataTag.constData()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
119 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
120 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
121 |
QTest::qt_asprintf(formatted, "<Message type=\"%s\" %s=\"%s\" %s=\"%s\">\n%s <Description><![CDATA[%s]]></Description>\n</Message>\n", |
0 | 122 |
element->attributeValue(QTest::AI_Type), |
123 |
element->attributeName(QTest::AI_File), |
|
124 |
quotedFile.constData(), |
|
125 |
element->attributeName(QTest::AI_Line), |
|
126 |
element->attributeValue(QTest::AI_Line), |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
127 |
tagbuf.constData(), |
0 | 128 |
cdataDesc.constData()); |
129 |
break; |
|
130 |
} |
|
131 |
case QTest::LET_Benchmark: { |
|
132 |
// assuming value and iterations don't need quoting |
|
133 |
QTestCharBuffer quotedMetric; |
|
134 |
QTestCharBuffer quotedTag; |
|
135 |
QXmlTestLogger::xmlQuote("edMetric, element->attributeValue(QTest::AI_Metric)); |
|
136 |
QXmlTestLogger::xmlQuote("edTag, element->attributeValue(QTest::AI_Tag)); |
|
137 |
||
138 |
QTest::qt_asprintf(formatted, "<BenchmarkResult %s=\"%s\" %s=\"%s\" %s=\"%s\" %s=\"%s\" />\n", |
|
139 |
element->attributeName(QTest::AI_Metric), |
|
140 |
quotedMetric.constData(), |
|
141 |
element->attributeName(QTest::AI_Tag), |
|
142 |
quotedTag.constData(), |
|
143 |
element->attributeName(QTest::AI_Value), |
|
144 |
element->attributeValue(QTest::AI_Value), |
|
145 |
element->attributeName(QTest::AI_Iterations), |
|
146 |
element->attributeValue(QTest::AI_Iterations) ); |
|
147 |
break; |
|
148 |
} |
|
149 |
default: |
|
150 |
formatted->data()[0] = '\0'; |
|
151 |
} |
|
152 |
} |
|
153 |
||
154 |
void QTestXmlStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const |
|
155 |
{ |
|
156 |
if(!element || !formatted) |
|
157 |
return; |
|
158 |
||
159 |
if (element->elementType() == QTest::LET_TestCase) { |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
160 |
bool failed = false; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
161 |
for (QTestElement* child = element->childElements(); child; child = child->nextElement()) { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
162 |
if ( child->elementType() == QTest::LET_Failure |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
163 |
&& child->attribute(QTest::AI_Result) |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
164 |
&& ( !strcmp(child->attributeValue(QTest::AI_Result), "fail") |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
165 |
|| !strcmp(child->attributeValue(QTest::AI_Result), "xpass")) |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
166 |
) |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
167 |
{ |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
168 |
failed = true; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
169 |
break; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
170 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
171 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
172 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
173 |
// For passing functions, no Incident has been output yet. |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
174 |
// For failing functions, we already output one. |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
175 |
// Please note: we are outputting "pass" even if there was an xfail etc. |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
176 |
// This is by design (arguably bad design, but dangerous to change now!) |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
177 |
if (element->attribute(QTest::AI_Result) && !failed) { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
178 |
QTest::qt_asprintf(formatted, "<Incident type=\"pass\" file=\"\" line=\"0\" />\n</TestFunction>\n"); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
179 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
180 |
else { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
181 |
QTest::qt_asprintf(formatted, "</TestFunction>\n"); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
182 |
} |
0 | 183 |
} else { |
184 |
formatted->data()[0] = '\0'; |
|
185 |
} |
|
186 |
} |
|
187 |
||
188 |
void QTestXmlStreamer::formatBeforeAttributes(const QTestElement *element, QTestCharBuffer *formatted) const |
|
189 |
{ |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
190 |
Q_UNUSED(element); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
191 |
if (!formatted) |
0 | 192 |
return; |
193 |
||
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
194 |
formatted->data()[0] = '\0'; |
0 | 195 |
} |
196 |
||
197 |
void QTestXmlStreamer::output(QTestElement *element) const |
|
198 |
{ |
|
199 |
QTestCharBuffer buf; |
|
200 |
QTestCharBuffer quotedTc; |
|
201 |
QXmlTestLogger::xmlQuote("edTc, QTestResult::currentTestObjectName()); |
|
202 |
||
203 |
QTest::qt_asprintf(&buf, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<TestCase name=\"%s\">\n", |
|
204 |
quotedTc.constData()); |
|
205 |
outputString(buf.constData()); |
|
206 |
||
207 |
QTest::qt_asprintf(&buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n", |
|
208 |
qVersion(), QTEST_VERSION_STR ); |
|
209 |
outputString(buf.constData()); |
|
210 |
||
211 |
QTest::qt_asprintf(&buf, "</Environment>\n"); |
|
212 |
outputString(buf.constData()); |
|
213 |
||
214 |
QTestBasicStreamer::output(element); |
|
215 |
||
216 |
QTest::qt_asprintf(&buf, "</TestCase>\n"); |
|
217 |
outputString(buf.constData()); |
|
218 |
} |
|
219 |
||
220 |
QT_END_NAMESPACE |
|
221 |