Qt 4.8
Public Functions | List of all members
QTestXmlStreamer Class Reference

#include <qtestxmlstreamer.h>

Inheritance diagram for QTestXmlStreamer:
QTestBasicStreamer

Public Functions

void formatBeforeAttributes (const QTestElement *element, QTestCharBuffer *formatted) const
 
void formatEnd (const QTestElement *element, QTestCharBuffer *formatted) const
 
void formatStart (const QTestElement *element, QTestCharBuffer *formatted) const
 
void output (QTestElement *element) const
 
 QTestXmlStreamer ()
 
 ~QTestXmlStreamer ()
 
- Public Functions inherited from QTestBasicStreamer
bool isTtyOutput ()
 
const QTestLoggerlogger () const
 
void outputString (const char *msg) const
 
 QTestBasicStreamer ()
 
void setLogger (const QTestLogger *tstLogger)
 
void startStreaming ()
 
void stopStreaming ()
 
virtual ~QTestBasicStreamer ()
 

Additional Inherited Members

- Protected Functions inherited from QTestBasicStreamer
virtual void formatAfterAttributes (const QTestElement *element, QTestCharBuffer *formatted) const
 
virtual void formatAttributes (const QTestElement *element, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const
 
virtual void outputElementAttributes (const QTestElement *element, QTestElementAttribute *attribute) const
 
virtual void outputElements (QTestElement *element, bool isChildElement=false) const
 

Detailed Description

Definition at line 56 of file qtestxmlstreamer.h.

Constructors and Destructors

◆ QTestXmlStreamer()

QTestXmlStreamer::QTestXmlStreamer ( )

Definition at line 56 of file qtestxmlstreamer.cpp.

58 {
59 }

◆ ~QTestXmlStreamer()

QTestXmlStreamer::~QTestXmlStreamer ( )

Definition at line 61 of file qtestxmlstreamer.cpp.

62 {}

Functions

◆ formatBeforeAttributes()

void QTestXmlStreamer::formatBeforeAttributes ( const QTestElement element,
QTestCharBuffer formatted 
) const
virtual

Reimplemented from QTestBasicStreamer.

Definition at line 189 of file qtestxmlstreamer.cpp.

190 {
191  Q_UNUSED(element);
192  if (!formatted)
193  return;
194 
195  formatted->data()[0] = '\0';
196 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ formatEnd()

void QTestXmlStreamer::formatEnd ( const QTestElement element,
QTestCharBuffer formatted 
) const
virtual

Reimplemented from QTestBasicStreamer.

Definition at line 155 of file qtestxmlstreamer.cpp.

156 {
157  if(!element || !formatted)
158  return;
159 
160  if (element->elementType() == QTest::LET_TestCase) {
161  bool failed = false;
162  for (QTestElement* child = element->childElements(); child; child = child->nextElement()) {
163  if ( child->elementType() == QTest::LET_Failure
164  && child->attribute(QTest::AI_Result)
165  && ( !strcmp(child->attributeValue(QTest::AI_Result), "fail")
166  || !strcmp(child->attributeValue(QTest::AI_Result), "xpass"))
167  )
168  {
169  failed = true;
170  break;
171  }
172  }
173 
174  // For passing functions, no Incident has been output yet.
175  // For failing functions, we already output one.
176  // Please note: we are outputting "pass" even if there was an xfail etc.
177  // This is by design (arguably bad design, but dangerous to change now!)
178  if (element->attribute(QTest::AI_Result) && !failed) {
179  QTest::qt_asprintf(formatted, "<Incident type=\"pass\" file=\"\" line=\"0\" />\n</TestFunction>\n");
180  }
181  else {
182  QTest::qt_asprintf(formatted, "</TestFunction>\n");
183  }
184  } else {
185  formatted->data()[0] = '\0';
186  }
187 }
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
QTestElement * childElements() const
static bool failed
Definition: qtestresult.cpp:60
const QTestElementAttribute * attribute(QTest::AttributeIndex index) const
QTest::LogElementType elementType() const

◆ formatStart()

void QTestXmlStreamer::formatStart ( const QTestElement element,
QTestCharBuffer formatted 
) const
virtual

Reimplemented from QTestBasicStreamer.

Definition at line 64 of file qtestxmlstreamer.cpp.

65 {
66  if(!element || !formatted)
67  return;
68 
69  switch(element->elementType()){
70  case QTest::LET_TestCase: {
71  QTestCharBuffer quotedTf;
73 
74  QTest::qt_asprintf(formatted, "<TestFunction name=\"%s\">\n", quotedTf.constData());
75  break;
76  }
77  case QTest::LET_Failure: {
78  QTestCharBuffer cdataDesc;
80 
82  QTestCharBuffer quotedFile;
84 
85  QTest::qt_asprintf(&location, "%s=\"%s\" %s=\"%s\"",
86  element->attributeName(QTest::AI_File),
87  quotedFile.constData(),
88  element->attributeName(QTest::AI_Line),
89  element->attributeValue(QTest::AI_Line));
90 
91  if (element->attribute(QTest::AI_Tag)) {
92  QTestCharBuffer cdataTag;
94  QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s>\n"
95  " <DataTag><![CDATA[%s]]></DataTag>\n"
96  " <Description><![CDATA[%s]]></Description>\n"
97  "</Incident>\n", element->attributeValue(QTest::AI_Result),
98  location.constData(), cdataTag.constData(), cdataDesc.constData());
99  }
100  else {
101  QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s>\n"
102  " <Description><![CDATA[%s]]></Description>\n"
103  "</Incident>\n", element->attributeValue(QTest::AI_Result),
104  location.constData(), cdataDesc.constData());
105  }
106  break;
107  }
108  case QTest::LET_Error: {
109  // assuming type and attribute names don't need quoting
110  QTestCharBuffer quotedFile;
111  QTestCharBuffer cdataDesc;
114 
115  QTestCharBuffer tagbuf;
116  if (element->attribute(QTest::AI_Tag)) {
117  QTestCharBuffer cdataTag;
119  QTest::qt_asprintf(&tagbuf, " <DataTag><![CDATA[%s]]></DataTag>\n", cdataTag.constData());
120  }
121 
122  QTest::qt_asprintf(formatted, "<Message type=\"%s\" %s=\"%s\" %s=\"%s\">\n%s <Description><![CDATA[%s]]></Description>\n</Message>\n",
123  element->attributeValue(QTest::AI_Type),
124  element->attributeName(QTest::AI_File),
125  quotedFile.constData(),
126  element->attributeName(QTest::AI_Line),
127  element->attributeValue(QTest::AI_Line),
128  tagbuf.constData(),
129  cdataDesc.constData());
130  break;
131  }
132  case QTest::LET_Benchmark: {
133  // assuming value and iterations don't need quoting
134  QTestCharBuffer quotedMetric;
135  QTestCharBuffer quotedTag;
136  QXmlTestLogger::xmlQuote(&quotedMetric, element->attributeValue(QTest::AI_Metric));
138 
139  QTest::qt_asprintf(formatted, "<BenchmarkResult %s=\"%s\" %s=\"%s\" %s=\"%s\" %s=\"%s\" />\n",
141  quotedMetric.constData(),
142  element->attributeName(QTest::AI_Tag),
143  quotedTag.constData(),
144  element->attributeName(QTest::AI_Value),
148  break;
149  }
150  default:
151  formatted->data()[0] = '\0';
152  }
153 }
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
const char * attributeName(QTest::AttributeIndex index) const
static int xmlCdata(QTestCharBuffer *dest, char const *src)
const char * constData() const
const char * attributeValue(QTest::AttributeIndex index) const
static int xmlQuote(QTestCharBuffer *dest, char const *src)
const QTestElementAttribute * attribute(QTest::AttributeIndex index) const
static QTestResult::TestLocation location
Definition: qtestresult.cpp:63
QTest::LogElementType elementType() const

◆ output()

void QTestXmlStreamer::output ( QTestElement element) const
virtual

Reimplemented from QTestBasicStreamer.

Definition at line 198 of file qtestxmlstreamer.cpp.

199 {
200  QTestCharBuffer buf;
201  QTestCharBuffer quotedTc;
203 
204  QTest::qt_asprintf(&buf, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<TestCase name=\"%s\">\n",
205  quotedTc.constData());
206  outputString(buf.constData());
207 
208  if (logger()->hasRandomSeed()) {
209  QTest::qt_asprintf(&buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n <RandomSeed>%d</RandomSeed>\n",
210  qVersion(), QTEST_VERSION_STR, logger()->randomSeed() );
211  } else {
212  QTest::qt_asprintf(&buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n",
214  }
215  outputString(buf.constData());
216 
217  QTest::qt_asprintf(&buf, "</Environment>\n");
218  outputString(buf.constData());
219 
221 
222  QTest::qt_asprintf(&buf, "</TestCase>\n");
223  outputString(buf.constData());
224 }
bool hasRandomSeed() const
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
virtual void output(QTestElement *element) const
Q_CORE_EXPORT const char * qVersion()
static const char * currentTestObjectName()
const char * constData() const
const QTestLogger * logger() const
#define QTEST_VERSION_STR
Definition: qtest_global.h:78
static int xmlQuote(QTestCharBuffer *dest, char const *src)
void outputString(const char *msg) const

The documentation for this class was generated from the following files: