author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 4 | 3b1da2848fc7 |
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 "qtestlightxmlstreamer.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 |
||
52 |
QT_BEGIN_NAMESPACE |
|
53 |
||
54 |
QTestLightXmlStreamer::QTestLightXmlStreamer() |
|
55 |
:QTestBasicStreamer() |
|
56 |
{ |
|
57 |
} |
|
58 |
||
59 |
QTestLightXmlStreamer::~QTestLightXmlStreamer() |
|
60 |
{} |
|
61 |
||
62 |
void QTestLightXmlStreamer::formatStart(const QTestElement *element, QTestCharBuffer *formatted) const |
|
63 |
{ |
|
64 |
if(!element || !formatted) |
|
65 |
return; |
|
66 |
||
67 |
switch(element->elementType()){ |
|
68 |
case QTest::LET_TestCase: { |
|
69 |
QTestCharBuffer quotedTf; |
|
70 |
QXmlTestLogger::xmlQuote("edTf, element->attributeValue(QTest::AI_Name)); |
|
71 |
||
72 |
QTest::qt_asprintf(formatted, "<TestFunction name=\"%s\">\n", quotedTf.constData()); |
|
73 |
break; |
|
74 |
} |
|
75 |
case QTest::LET_Failure: { |
|
76 |
QTestCharBuffer cdataDesc; |
|
77 |
QXmlTestLogger::xmlCdata(&cdataDesc, element->attributeValue(QTest::AI_Description)); |
|
78 |
||
79 |
QTest::qt_asprintf(formatted, " <Description><![CDATA[%s]]></Description>\n", |
|
80 |
cdataDesc.constData()); |
|
81 |
break; |
|
82 |
} |
|
83 |
case QTest::LET_Error: { |
|
84 |
// assuming type and attribute names don't need quoting |
|
85 |
QTestCharBuffer quotedFile; |
|
86 |
QTestCharBuffer cdataDesc; |
|
87 |
QXmlTestLogger::xmlQuote("edFile, element->attributeValue(QTest::AI_File)); |
|
88 |
QXmlTestLogger::xmlCdata(&cdataDesc, element->attributeValue(QTest::AI_Description)); |
|
89 |
||
90 |
QTest::qt_asprintf(formatted, "<Message type=\"%s\" %s=\"%s\" %s=\"%s\">\n <Description><![CDATA[%s]]></Description>\n</Message>\n", |
|
91 |
element->attributeValue(QTest::AI_Type), |
|
92 |
element->attributeName(QTest::AI_File), |
|
93 |
quotedFile.constData(), |
|
94 |
element->attributeName(QTest::AI_Line), |
|
95 |
element->attributeValue(QTest::AI_Line), |
|
96 |
cdataDesc.constData()); |
|
97 |
break; |
|
98 |
} |
|
99 |
case QTest::LET_Benchmark: { |
|
100 |
// assuming value and iterations don't need quoting |
|
101 |
QTestCharBuffer quotedMetric; |
|
102 |
QTestCharBuffer quotedTag; |
|
103 |
QXmlTestLogger::xmlQuote("edMetric, element->attributeValue(QTest::AI_Metric)); |
|
104 |
QXmlTestLogger::xmlQuote("edTag, element->attributeValue(QTest::AI_Tag)); |
|
105 |
||
106 |
QTest::qt_asprintf(formatted, "<BenchmarkResult %s=\"%s\" %s=\"%s\" %s=\"%s\" %s=\"%s\" />\n", |
|
107 |
element->attributeName(QTest::AI_Metric), |
|
108 |
quotedMetric.constData(), |
|
109 |
element->attributeName(QTest::AI_Tag), |
|
110 |
quotedTag.constData(), |
|
111 |
element->attributeName(QTest::AI_Value), |
|
112 |
element->attributeValue(QTest::AI_Value), |
|
113 |
element->attributeName(QTest::AI_Iterations), |
|
114 |
element->attributeValue(QTest::AI_Iterations) ); |
|
115 |
break; |
|
116 |
} |
|
117 |
default: |
|
118 |
formatted->data()[0] = '\0'; |
|
119 |
} |
|
120 |
} |
|
121 |
||
122 |
void QTestLightXmlStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const |
|
123 |
{ |
|
124 |
if(!element || !formatted) |
|
125 |
return; |
|
126 |
||
127 |
if (element->elementType() == QTest::LET_TestCase) { |
|
128 |
if( element->attribute(QTest::AI_Result) && element->childElements()) |
|
129 |
QTest::qt_asprintf(formatted, "</Incident>\n</TestFunction>\n"); |
|
130 |
else |
|
131 |
QTest::qt_asprintf(formatted, "</TestFunction>\n"); |
|
132 |
} else { |
|
133 |
formatted->data()[0] = '\0'; |
|
134 |
} |
|
135 |
} |
|
136 |
||
137 |
void QTestLightXmlStreamer::formatBeforeAttributes(const QTestElement *element, QTestCharBuffer *formatted) const |
|
138 |
{ |
|
139 |
if(!element || !formatted) |
|
140 |
return; |
|
141 |
||
142 |
if (element->elementType() == QTest::LET_TestCase && element->attribute(QTest::AI_Result)) { |
|
143 |
QTestCharBuffer buf; |
|
144 |
QTestCharBuffer quotedFile; |
|
145 |
QXmlTestLogger::xmlQuote("edFile, element->attributeValue(QTest::AI_File)); |
|
146 |
||
147 |
QTest::qt_asprintf(&buf, "%s=\"%s\" %s=\"%s\"", |
|
148 |
element->attributeName(QTest::AI_File), |
|
149 |
quotedFile.constData(), |
|
150 |
element->attributeName(QTest::AI_Line), |
|
151 |
element->attributeValue(QTest::AI_Line)); |
|
152 |
||
153 |
if( !element->childElements() ) |
|
154 |
QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s/>\n", |
|
155 |
element->attributeValue(QTest::AI_Result), buf.constData()); |
|
156 |
else |
|
157 |
QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s>\n", |
|
158 |
element->attributeValue(QTest::AI_Result), buf.constData()); |
|
159 |
} else { |
|
160 |
formatted->data()[0] = '\0'; |
|
161 |
} |
|
162 |
} |
|
163 |
||
164 |
void QTestLightXmlStreamer::output(QTestElement *element) const |
|
165 |
{ |
|
166 |
QTestCharBuffer buf; |
|
167 |
QTest::qt_asprintf(&buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n", |
|
168 |
qVersion(), QTEST_VERSION_STR ); |
|
169 |
outputString(buf.constData()); |
|
170 |
||
171 |
QTest::qt_asprintf(&buf, "</Environment>\n"); |
|
172 |
outputString(buf.constData()); |
|
173 |
||
174 |
QTestBasicStreamer::output(element); |
|
175 |
} |
|
176 |
||
177 |
QT_END_NAMESPACE |
|
178 |