1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtTest module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
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 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
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 |
|
---|
114 | QTest::qt_asprintf(formatted, "<Message type=\"%s\" %s=\"%s\" %s=\"%s\">\n <Description><![CDATA[%s]]></Description>\n</Message>\n",
|
---|
115 | element->attributeValue(QTest::AI_Type),
|
---|
116 | element->attributeName(QTest::AI_File),
|
---|
117 | quotedFile.constData(),
|
---|
118 | element->attributeName(QTest::AI_Line),
|
---|
119 | element->attributeValue(QTest::AI_Line),
|
---|
120 | cdataDesc.constData());
|
---|
121 | break;
|
---|
122 | }
|
---|
123 | case QTest::LET_Benchmark: {
|
---|
124 | // assuming value and iterations don't need quoting
|
---|
125 | QTestCharBuffer quotedMetric;
|
---|
126 | QTestCharBuffer quotedTag;
|
---|
127 | QXmlTestLogger::xmlQuote("edMetric, element->attributeValue(QTest::AI_Metric));
|
---|
128 | QXmlTestLogger::xmlQuote("edTag, element->attributeValue(QTest::AI_Tag));
|
---|
129 |
|
---|
130 | QTest::qt_asprintf(formatted, "<BenchmarkResult %s=\"%s\" %s=\"%s\" %s=\"%s\" %s=\"%s\" />\n",
|
---|
131 | element->attributeName(QTest::AI_Metric),
|
---|
132 | quotedMetric.constData(),
|
---|
133 | element->attributeName(QTest::AI_Tag),
|
---|
134 | quotedTag.constData(),
|
---|
135 | element->attributeName(QTest::AI_Value),
|
---|
136 | element->attributeValue(QTest::AI_Value),
|
---|
137 | element->attributeName(QTest::AI_Iterations),
|
---|
138 | element->attributeValue(QTest::AI_Iterations) );
|
---|
139 | break;
|
---|
140 | }
|
---|
141 | default:
|
---|
142 | formatted->data()[0] = '\0';
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | void QTestXmlStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const
|
---|
147 | {
|
---|
148 | if(!element || !formatted)
|
---|
149 | return;
|
---|
150 |
|
---|
151 | if (element->elementType() == QTest::LET_TestCase) {
|
---|
152 | QTest::qt_asprintf(formatted, "</TestFunction>\n");
|
---|
153 | } else {
|
---|
154 | formatted->data()[0] = '\0';
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | void QTestXmlStreamer::formatBeforeAttributes(const QTestElement *element, QTestCharBuffer *formatted) const
|
---|
159 | {
|
---|
160 | if(!element || !formatted)
|
---|
161 | return;
|
---|
162 |
|
---|
163 | if (element->elementType() == QTest::LET_TestCase && element->attribute(QTest::AI_Result)){
|
---|
164 | QTestCharBuffer buf;
|
---|
165 | QTestCharBuffer quotedFile;
|
---|
166 | QXmlTestLogger::xmlQuote("edFile, element->attributeValue(QTest::AI_File));
|
---|
167 |
|
---|
168 | QTest::qt_asprintf(&buf, "%s=\"%s\" %s=\"%s\"",
|
---|
169 | element->attributeName(QTest::AI_File),
|
---|
170 | quotedFile.constData(),
|
---|
171 | element->attributeName(QTest::AI_Line),
|
---|
172 | element->attributeValue(QTest::AI_Line));
|
---|
173 |
|
---|
174 | if( !element->childElements() ) {
|
---|
175 | QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s/>\n",
|
---|
176 | element->attributeValue(QTest::AI_Result), buf.constData());
|
---|
177 | } else {
|
---|
178 | formatted->data()[0] = '\0';
|
---|
179 | }
|
---|
180 | } else {
|
---|
181 | formatted->data()[0] = '\0';
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 | void QTestXmlStreamer::output(QTestElement *element) const
|
---|
186 | {
|
---|
187 | QTestCharBuffer buf;
|
---|
188 | QTestCharBuffer quotedTc;
|
---|
189 | QXmlTestLogger::xmlQuote("edTc, QTestResult::currentTestObjectName());
|
---|
190 |
|
---|
191 | QTest::qt_asprintf(&buf, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<TestCase name=\"%s\">\n",
|
---|
192 | quotedTc.constData());
|
---|
193 | outputString(buf.constData());
|
---|
194 |
|
---|
195 | QTest::qt_asprintf(&buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n",
|
---|
196 | qVersion(), QTEST_VERSION_STR );
|
---|
197 | outputString(buf.constData());
|
---|
198 |
|
---|
199 | QTest::qt_asprintf(&buf, "</Environment>\n");
|
---|
200 | outputString(buf.constData());
|
---|
201 |
|
---|
202 | QTestBasicStreamer::output(element);
|
---|
203 |
|
---|
204 | QTest::qt_asprintf(&buf, "</TestCase>\n");
|
---|
205 | outputString(buf.constData());
|
---|
206 | }
|
---|
207 |
|
---|
208 | QT_END_NAMESPACE
|
---|
209 |
|
---|