Qt 4.8
qtestlightxmlstreamer.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtTest module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qtestlightxmlstreamer.h"
43 #include "qtestelement.h"
44 #include "qtestelementattribute.h"
45 #include "qtestlogger_p.h"
46 
47 #include "QtTest/private/qtestlog_p.h"
48 #include "QtTest/private/qtestresult_p.h"
49 #include "QtTest/private/qxmltestlogger_p.h"
50 
51 #include <string.h>
52 
54 
57 {
58 }
59 
61 {}
62 
63 void QTestLightXmlStreamer::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;
72 
73  QTest::qt_asprintf(formatted, "<TestFunction name=\"%s\">\n", quotedTf.constData());
74  break;
75  }
76  case QTest::LET_Failure: {
77  QTestCharBuffer cdataDesc;
79 
80  QTest::qt_asprintf(formatted, " <Description><![CDATA[%s]]></Description>\n",
81  cdataDesc.constData());
82  break;
83  }
84  case QTest::LET_Error: {
85  // assuming type and attribute names don't need quoting
86  QTestCharBuffer quotedFile;
87  QTestCharBuffer cdataDesc;
90 
91  QTest::qt_asprintf(formatted, "<Message type=\"%s\" %s=\"%s\" %s=\"%s\">\n <Description><![CDATA[%s]]></Description>\n</Message>\n",
93  element->attributeName(QTest::AI_File),
94  quotedFile.constData(),
95  element->attributeName(QTest::AI_Line),
97  cdataDesc.constData());
98  break;
99  }
100  case QTest::LET_Benchmark: {
101  // assuming value and iterations don't need quoting
102  QTestCharBuffer quotedMetric;
103  QTestCharBuffer quotedTag;
104  QXmlTestLogger::xmlQuote(&quotedMetric, element->attributeValue(QTest::AI_Metric));
106 
107  QTest::qt_asprintf(formatted, "<BenchmarkResult %s=\"%s\" %s=\"%s\" %s=\"%s\" %s=\"%s\" />\n",
109  quotedMetric.constData(),
110  element->attributeName(QTest::AI_Tag),
111  quotedTag.constData(),
112  element->attributeName(QTest::AI_Value),
116  break;
117  }
118  default:
119  formatted->data()[0] = '\0';
120  }
121 }
122 
123 void QTestLightXmlStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const
124 {
125  if(!element || !formatted)
126  return;
127 
128  if (element->elementType() == QTest::LET_TestCase) {
129  if( element->attribute(QTest::AI_Result) && element->childElements())
130  QTest::qt_asprintf(formatted, "</Incident>\n</TestFunction>\n");
131  else
132  QTest::qt_asprintf(formatted, "</TestFunction>\n");
133  } else {
134  formatted->data()[0] = '\0';
135  }
136 }
137 
139 {
140  if(!element || !formatted)
141  return;
142 
143  if (element->elementType() == QTest::LET_TestCase && element->attribute(QTest::AI_Result)) {
144  QTestCharBuffer buf;
145  QTestCharBuffer quotedFile;
147 
148  QTest::qt_asprintf(&buf, "%s=\"%s\" %s=\"%s\"",
149  element->attributeName(QTest::AI_File),
150  quotedFile.constData(),
151  element->attributeName(QTest::AI_Line),
152  element->attributeValue(QTest::AI_Line));
153 
154  if( !element->childElements() )
155  QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s/>\n",
156  element->attributeValue(QTest::AI_Result), buf.constData());
157  else
158  QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s>\n",
159  element->attributeValue(QTest::AI_Result), buf.constData());
160  } else {
161  formatted->data()[0] = '\0';
162  }
163 }
164 
166 {
167  QTestCharBuffer buf;
168  if (logger()->hasRandomSeed()) {
169  QTest::qt_asprintf(&buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n <RandomSeed>%d</RandomSeed>\n",
170  qVersion(), QTEST_VERSION_STR, logger()->randomSeed() );
171  } else {
172  QTest::qt_asprintf(&buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n",
174  }
175  outputString(buf.constData());
176 
177  QTest::qt_asprintf(&buf, "</Environment>\n");
178  outputString(buf.constData());
179 
181 }
182 
184 
void formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
const char * attributeName(QTest::AttributeIndex index) const
static int xmlCdata(QTestCharBuffer *dest, char const *src)
virtual void output(QTestElement *element) const
QTestElement * childElements() const
Q_CORE_EXPORT const char * qVersion()
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void formatStart(const QTestElement *element, QTestCharBuffer *formatted) const
const char * constData() const
const QTestLogger * logger() const
const char * attributeValue(QTest::AttributeIndex index) const
void output(QTestElement *element) const
#define QTEST_VERSION_STR
Definition: qtest_global.h:78
static int xmlQuote(QTestCharBuffer *dest, char const *src)
const QTestElementAttribute * attribute(QTest::AttributeIndex index) const
void outputString(const char *msg) const
void formatBeforeAttributes(const QTestElement *element, QTestCharBuffer *formatted) const
QTest::LogElementType elementType() const