Qt 4.8
Public Functions | Private Functions | Static Private Functions | List of all members
QTestXunitStreamer Class Reference

#include <qtestxunitstreamer.h>

Inheritance diagram for QTestXunitStreamer:
QTestBasicStreamer

Public Functions

void formatAfterAttributes (const QTestElement *element, QTestCharBuffer *formatted) const
 
void formatAttributes (const QTestElement *element, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const
 
void formatEnd (const QTestElement *element, QTestCharBuffer *formatted) const
 
void formatStart (const QTestElement *element, QTestCharBuffer *formatted) const
 
void output (QTestElement *element) const
 
void outputElements (QTestElement *element, bool isChildElement=false) const
 
 QTestXunitStreamer ()
 
 ~QTestXunitStreamer ()
 
- 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 ()
 

Private Functions

void displayXunitXmlHeader () const
 

Static Private Functions

static void indentForElement (const QTestElement *element, char *buf, int size)
 

Additional Inherited Members

- Protected Functions inherited from QTestBasicStreamer
virtual void formatBeforeAttributes (const QTestElement *element, QTestCharBuffer *formatted) const
 
virtual void outputElementAttributes (const QTestElement *element, QTestElementAttribute *attribute) const
 

Detailed Description

Definition at line 55 of file qtestxunitstreamer.h.

Constructors and Destructors

◆ QTestXunitStreamer()

QTestXunitStreamer::QTestXunitStreamer ( )

Definition at line 51 of file qtestxunitstreamer.cpp.

◆ ~QTestXunitStreamer()

QTestXunitStreamer::~QTestXunitStreamer ( )

Definition at line 55 of file qtestxunitstreamer.cpp.

56 {}

Functions

◆ displayXunitXmlHeader()

void QTestXunitStreamer::displayXunitXmlHeader ( ) const
private

◆ formatAfterAttributes()

void QTestXunitStreamer::formatAfterAttributes ( const QTestElement element,
QTestCharBuffer formatted 
) const
virtual

Reimplemented from QTestBasicStreamer.

Definition at line 145 of file qtestxunitstreamer.cpp.

Referenced by outputElements().

146 {
147  if(!element || !formatted )
148  return;
149 
150  // Errors are written as CDATA within system-err, comments elsewhere
151  if (element->elementType() == QTest::LET_Error) {
152  if (element->parentElement()->elementType() == QTest::LET_SystemError) {
153  QTest::qt_asprintf(formatted, "]]>\n");
154  } else {
155  QTest::qt_asprintf(formatted, " -->\n");
156  }
157  return;
158  }
159 
160  if(!element->childElements())
161  QTest::qt_asprintf(formatted, "/>\n");
162  else
163  QTest::qt_asprintf(formatted, ">\n");
164 }
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
const QTestElement * parentElement() const
QTestElement * childElements() const
QTest::LogElementType elementType() const

◆ formatAttributes()

void QTestXunitStreamer::formatAttributes ( const QTestElement element,
const QTestElementAttribute attribute,
QTestCharBuffer formatted 
) const
virtual

Reimplemented from QTestBasicStreamer.

Definition at line 113 of file qtestxunitstreamer.cpp.

114 {
115  if(!attribute || !formatted )
116  return;
117 
118  QTest::AttributeIndex attrindex = attribute->index();
119 
120  // For errors within system-err, we only want to output `message'
121  if (element && element->elementType() == QTest::LET_Error
122  && element->parentElement()->elementType() == QTest::LET_SystemError) {
123 
124  if (attrindex != QTest::AI_Description) return;
125 
126  QXmlTestLogger::xmlCdata(formatted, attribute->value());
127  return;
128  }
129 
130  char const* key = 0;
131  if (attrindex == QTest::AI_Description)
132  key = "message";
133  else if (attrindex != QTest::AI_File && attrindex != QTest::AI_Line)
134  key = attribute->name();
135 
136  if (key) {
138  QXmlTestLogger::xmlQuote(&quotedValue, attribute->value());
139  QTest::qt_asprintf(formatted, " %s=\"%s\"", key, quotedValue.constData());
140  } else {
141  formatted->data()[0] = '\0';
142  }
143 }
const char * value() const
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
static int xmlCdata(QTestCharBuffer *dest, char const *src)
const QTestElement * parentElement() const
const char * constData() const
static QString quotedValue(const QString &data)
Definition: qdom.cpp:3656
static int xmlQuote(QTestCharBuffer *dest, char const *src)
int key
QTest::LogElementType elementType() const
AttributeIndex
This enum numbers the different tests.
QTest::AttributeIndex index() const

◆ formatEnd()

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

Reimplemented from QTestBasicStreamer.

Definition at line 97 of file qtestxunitstreamer.cpp.

Referenced by outputElements().

98 {
99  if (!element || !formatted )
100  return;
101 
102  if (!element->childElements()){
103  formatted->data()[0] = '\0';
104  return;
105  }
106 
107  char indent[20];
108  indentForElement(element, indent, sizeof(indent));
109 
110  QTest::qt_asprintf(formatted, "%s</%s>\n", indent, element->elementName());
111 }
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
QTestElement * childElements() const
const char * elementName() const
static void indentForElement(const QTestElement *element, char *buf, int size)

◆ formatStart()

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

Reimplemented from QTestBasicStreamer.

Definition at line 76 of file qtestxunitstreamer.cpp.

Referenced by outputElements().

77 {
78  if(!element || !formatted )
79  return;
80 
81  char indent[20];
82  indentForElement(element, indent, sizeof(indent));
83 
84  // Errors are written as CDATA within system-err, comments elsewhere
85  if (element->elementType() == QTest::LET_Error) {
86  if (element->parentElement()->elementType() == QTest::LET_SystemError) {
87  QTest::qt_asprintf(formatted, "<![CDATA[");
88  } else {
89  QTest::qt_asprintf(formatted, "%s<!--", indent);
90  }
91  return;
92  }
93 
94  QTest::qt_asprintf(formatted, "%s<%s", indent, element->elementName());
95 }
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
const QTestElement * parentElement() const
const char * elementName() const
static void indentForElement(const QTestElement *element, char *buf, int size)
QTest::LogElementType elementType() const

◆ indentForElement()

void QTestXunitStreamer::indentForElement ( const QTestElement element,
char *  buf,
int  size 
)
staticprivate

Definition at line 58 of file qtestxunitstreamer.cpp.

Referenced by formatEnd(), and formatStart().

59 {
60  if (size == 0) return;
61 
62  buf[0] = 0;
63 
64  if (!element) return;
65 
66  char* endbuf = buf + size;
67  element = element->parentElement();
68  while (element && buf+2 < endbuf) {
69  *(buf++) = ' ';
70  *(buf++) = ' ';
71  *buf = 0;
72  element = element->parentElement();
73  }
74 }
const QTestElement * parentElement() const

◆ output()

void QTestXunitStreamer::output ( QTestElement element) const
virtual

Reimplemented from QTestBasicStreamer.

Definition at line 166 of file qtestxunitstreamer.cpp.

167 {
168  outputString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
170 }
virtual void output(QTestElement *element) const
void outputString(const char *msg) const

◆ outputElements()

void QTestXunitStreamer::outputElements ( QTestElement element,
bool  isChildElement = false 
) const
virtual

Reimplemented from QTestBasicStreamer.

Definition at line 172 of file qtestxunitstreamer.cpp.

173 {
174  QTestCharBuffer buf;
175  bool hasChildren;
176  /*
177  Elements are in reverse order of occurrence, so start from the end and work
178  our way backwards.
179  */
180  while (element && element->nextElement()) {
181  element = element->nextElement();
182  }
183  while (element) {
184  hasChildren = element->childElements();
185 
186  if(element->elementType() != QTest::LET_Benchmark){
187  formatStart(element, &buf);
188  outputString(buf.data());
189 
190  formatBeforeAttributes(element, &buf);
191  outputString(buf.data());
192 
193  outputElementAttributes(element, element->attributes());
194 
195  formatAfterAttributes(element, &buf);
196  outputString(buf.data());
197 
198  if(hasChildren)
199  outputElements(element->childElements(), true);
200 
201  formatEnd(element, &buf);
202  outputString(buf.data());
203  }
204  element = element->previousElement();
205  }
206 }
virtual void outputElementAttributes(const QTestElement *element, QTestElementAttribute *attribute) const
QTestElement * childElements() const
void formatStart(const QTestElement *element, QTestCharBuffer *formatted) const
void formatAfterAttributes(const QTestElement *element, QTestCharBuffer *formatted) const
void outputElements(QTestElement *element, bool isChildElement=false) const
virtual void formatBeforeAttributes(const QTestElement *element, QTestCharBuffer *formatted) const
void formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const
QTestElementAttribute * attributes() const
void outputString(const char *msg) const
T * previousElement()
QTest::LogElementType elementType() const

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