Qt 4.8
Public Types | Public Functions | Static Public Functions | Properties | List of all members
QXmlTestLogger Class Reference

#include <qxmltestlogger_p.h>

Inheritance diagram for QXmlTestLogger:
QAbstractTestLogger

Public Types

enum  XmlMode { Complete = 0, Light }
 
- Public Types inherited from QAbstractTestLogger
enum  IncidentTypes { Pass, XFail, Fail, XPass }
 
enum  MessageTypes {
  Warn, QWarning, QDebug, QSystem,
  QFatal, Skip, Info
}
 

Public Functions

void addBenchmarkResult (const QBenchmarkResult &result)
 
void addIncident (IncidentTypes type, const char *description, const char *file=0, int line=0)
 
void addMessage (MessageTypes type, const char *message, const char *file=0, int line=0)
 
void enterTestFunction (const char *function)
 
void leaveTestFunction ()
 
 QXmlTestLogger (XmlMode mode=Complete)
 
void registerRandomSeed (unsigned int seed)
 
void startLogging ()
 
void stopLogging ()
 
 ~QXmlTestLogger ()
 
- Public Functions inherited from QAbstractTestLogger
 QAbstractTestLogger ()
 
virtual ~QAbstractTestLogger ()
 

Static Public Functions

static int xmlCdata (QTestCharBuffer *dest, char const *src)
 
static int xmlCdata (QTestCharBuffer *dest, char const *src, size_t n)
 
static int xmlQuote (QTestCharBuffer *dest, char const *src)
 
static int xmlQuote (QTestCharBuffer *dest, char const *src, size_t n)
 
- Static Public Functions inherited from QAbstractTestLogger
static bool isTtyOutput ()
 
static void outputString (const char *msg)
 

Properties

bool hasRandomSeed
 
unsigned int randomSeed
 
XmlMode xmlmode
 

Detailed Description

Definition at line 61 of file qxmltestlogger_p.h.

Enumerations

◆ XmlMode

Enumerator
Complete 
Light 

Definition at line 64 of file qxmltestlogger_p.h.

Constructors and Destructors

◆ QXmlTestLogger()

QXmlTestLogger::QXmlTestLogger ( XmlMode  mode = Complete)

Definition at line 95 of file qxmltestlogger.cpp.

96  :xmlmode(mode), randomSeed(0), hasRandomSeed(false)
97 {
98 
99 }
unsigned int randomSeed

◆ ~QXmlTestLogger()

QXmlTestLogger::~QXmlTestLogger ( )

Definition at line 101 of file qxmltestlogger.cpp.

102 {
103 }

Functions

◆ addBenchmarkResult()

void QXmlTestLogger::addBenchmarkResult ( const QBenchmarkResult result)
virtual

Implements QAbstractTestLogger.

Definition at line 249 of file qxmltestlogger.cpp.

250 {
251  QTestCharBuffer buf;
252  QTestCharBuffer quotedMetric;
253  QTestCharBuffer quotedTag;
254 
255  xmlQuote(&quotedMetric,
256  benchmarkMetricName(result.metric));
257  xmlQuote(&quotedTag, result.context.tag.toAscii().constData());
258 
260  &buf,
262  quotedMetric.constData(),
263  quotedTag.constData(),
264  QByteArray::number(result.value).constData(), //no 64-bit qt_snprintf support
265  result.iterations);
266  outputString(buf.constData());
267 }
QTest::QBenchmarkMetric metric
Definition: qbenchmark_p.h:100
static void outputString(const char *msg)
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
const char * constData() const
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static const char * benchmarkResultFormatString()
const char * benchmarkMetricName(QBenchmarkMetric metric)
static int xmlQuote(QTestCharBuffer *dest, char const *src)
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4014
QBenchmarkContext context
Definition: qbenchmark_p.h:97
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...

◆ addIncident()

void QXmlTestLogger::addIncident ( IncidentTypes  type,
const char *  description,
const char *  file = 0,
int  line = 0 
)
virtual

Implements QAbstractTestLogger.

Definition at line 218 of file qxmltestlogger.cpp.

220 {
221  QTestCharBuffer buf;
222  const char *tag = QTestResult::currentDataTag();
223  const char *gtag = QTestResult::currentGlobalDataTag();
224  const char *filler = (tag && gtag) ? ":" : "";
225  const bool notag = QTest::isEmpty(tag) && QTest::isEmpty(gtag);
226 
227  QTestCharBuffer quotedFile;
228  QTestCharBuffer cdataGtag;
229  QTestCharBuffer cdataTag;
230  QTestCharBuffer cdataDescription;
231 
232  xmlQuote(&quotedFile, file);
233  xmlCdata(&cdataGtag, gtag);
234  xmlCdata(&cdataTag, tag);
235  xmlCdata(&cdataDescription, description);
236 
237  QTest::qt_asprintf(&buf,
238  QTest::incidentFormatString(QTest::isEmpty(description), notag),
240  quotedFile.constData(), line,
241  cdataGtag.constData(),
242  filler,
243  cdataTag.constData(),
244  cdataDescription.constData());
245 
246  outputString(buf.constData());
247 }
static const char * xmlIncidentType2String(QAbstractTestLogger::IncidentTypes type)
int type
Definition: qmetatype.cpp:239
static void outputString(const char *msg)
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
static int xmlCdata(QTestCharBuffer *dest, char const *src)
static const char * incidentFormatString(bool noDescription, bool noTag)
static bool isEmpty(const char *str)
const char * constData() const
static const char * currentGlobalDataTag()
static int xmlQuote(QTestCharBuffer *dest, char const *src)
static const char * currentDataTag()

◆ addMessage()

void QXmlTestLogger::addMessage ( MessageTypes  type,
const char *  message,
const char *  file = 0,
int  line = 0 
)
virtual

Implements QAbstractTestLogger.

Definition at line 269 of file qxmltestlogger.cpp.

271 {
272  QTestCharBuffer buf;
273  const char *tag = QTestResult::currentDataTag();
274  const char *gtag = QTestResult::currentGlobalDataTag();
275  const char *filler = (tag && gtag) ? ":" : "";
276  const bool notag = QTest::isEmpty(tag) && QTest::isEmpty(gtag);
277 
278  QTestCharBuffer quotedFile;
279  QTestCharBuffer cdataGtag;
280  QTestCharBuffer cdataTag;
281  QTestCharBuffer cdataDescription;
282 
283  xmlQuote(&quotedFile, file);
284  xmlCdata(&cdataGtag, gtag);
285  xmlCdata(&cdataTag, tag);
286  xmlCdata(&cdataDescription, message);
287 
288  QTest::qt_asprintf(&buf,
291  quotedFile.constData(), line,
292  cdataGtag.constData(),
293  filler,
294  cdataTag.constData(),
295  cdataDescription.constData());
296 
297  outputString(buf.constData());
298 }
int type
Definition: qmetatype.cpp:239
static void outputString(const char *msg)
static const char * xmlMessageType2String(QAbstractTestLogger::MessageTypes type)
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
static int xmlCdata(QTestCharBuffer *dest, char const *src)
static bool isEmpty(const char *str)
const char * constData() const
static const char * currentGlobalDataTag()
static const char * messageFormatString(bool noDescription, bool noTag)
static int xmlQuote(QTestCharBuffer *dest, char const *src)
static const char * currentDataTag()

◆ enterTestFunction()

void QXmlTestLogger::enterTestFunction ( const char *  function)
virtual

Implements QAbstractTestLogger.

Definition at line 145 of file qxmltestlogger.cpp.

146 {
147  QTestCharBuffer buf;
148  QTestCharBuffer quotedFunction;
149  xmlQuote(&quotedFunction, function);
150  QTest::qt_asprintf(&buf, "<TestFunction name=\"%s\">\n", quotedFunction.constData());
151  outputString(buf.constData());
152 }
static void outputString(const char *msg)
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
const char * constData() const
static int xmlQuote(QTestCharBuffer *dest, char const *src)

◆ leaveTestFunction()

void QXmlTestLogger::leaveTestFunction ( )
virtual

Implements QAbstractTestLogger.

Definition at line 154 of file qxmltestlogger.cpp.

155 {
156  outputString("</TestFunction>\n");
157 }
static void outputString(const char *msg)

◆ registerRandomSeed()

void QXmlTestLogger::registerRandomSeed ( unsigned int  seed)
virtual

Implements QAbstractTestLogger.

Definition at line 453 of file qxmltestlogger.cpp.

454 {
455  randomSeed = seed;
456  hasRandomSeed = true;
457 }
static unsigned int seed
Definition: qtestcase.cpp:943
unsigned int randomSeed

◆ startLogging()

void QXmlTestLogger::startLogging ( )
virtual

Reimplemented from QAbstractTestLogger.

Definition at line 105 of file qxmltestlogger.cpp.

106 {
108  QTestCharBuffer buf;
109 
111  QTestCharBuffer quotedTc;
113  QTest::qt_asprintf(&buf,
114  "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
115  "<TestCase name=\"%s\">\n", quotedTc.constData());
116  outputString(buf.constData());
117  }
118 
119  if (hasRandomSeed) {
120  QTest::qt_asprintf(&buf,
121  "<Environment>\n"
122  " <QtVersion>%s</QtVersion>\n"
123  " <QTestVersion>" QTEST_VERSION_STR "</QTestVersion>\n"
124  " <RandomSeed>%d</RandomSeed>\n"
125  "</Environment>\n", qVersion(), randomSeed);
126  } else {
127  QTest::qt_asprintf(&buf,
128  "<Environment>\n"
129  " <QtVersion>%s</QtVersion>\n"
130  " <QTestVersion>" QTEST_VERSION_STR "</QTestVersion>\n"
131  "</Environment>\n", qVersion());
132  }
133  outputString(buf.constData());
134 }
static void outputString(const char *msg)
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
Q_CORE_EXPORT const char * qVersion()
static const char * currentTestObjectName()
const char * constData() const
#define QTEST_VERSION_STR
Definition: qtest_global.h:78
static int xmlQuote(QTestCharBuffer *dest, char const *src)
unsigned int randomSeed

◆ stopLogging()

void QXmlTestLogger::stopLogging ( )
virtual

Reimplemented from QAbstractTestLogger.

Definition at line 136 of file qxmltestlogger.cpp.

137 {
139  outputString("</TestCase>\n");
140  }
141 
143 }
static void outputString(const char *msg)

◆ xmlCdata() [1/2]

int QXmlTestLogger::xmlCdata ( QTestCharBuffer dest,
char const *  src 
)
static

Definition at line 448 of file qxmltestlogger.cpp.

Referenced by addIncident(), addMessage(), QTestXunitStreamer::formatAttributes(), QTestLightXmlStreamer::formatStart(), and QTestXmlStreamer::formatStart().

449 {
450  return allocateStringFn(str, src, QXmlTestLogger::xmlCdata);
451 }
static int xmlCdata(QTestCharBuffer *dest, char const *src)
int allocateStringFn(QTestCharBuffer *str, char const *src, StringFormatFunction func)

◆ xmlCdata() [2/2]

int QXmlTestLogger::xmlCdata ( QTestCharBuffer dest,
char const *  src,
size_t  n 
)
static

Definition at line 365 of file qxmltestlogger.cpp.

366 {
367  if (!n) return 0;
368 
369  char *dest = destBuf->data();
370 
371  if (!src || n == 1) {
372  *dest = 0;
373  return 0;
374  }
375 
376  static char const CDATA_END[] = "]]>";
377  static char const CDATA_END_ESCAPED[] = "]]]><![CDATA[]>";
378 
379  char* begin = dest;
380  char* end = dest + n;
381  while (dest < end) {
382  if (!*src) {
383  *dest = 0;
384  return (dest-begin);
385  }
386 
387  if (!strncmp(src, CDATA_END, sizeof(CDATA_END)-1)) {
388  if (dest + sizeof(CDATA_END_ESCAPED) < end) {
389  strcpy(dest, CDATA_END_ESCAPED);
390  src += sizeof(CDATA_END)-1;
391  dest += sizeof(CDATA_END_ESCAPED) - 1;
392  }
393  else {
394  *dest = 0;
395  return (dest+sizeof(CDATA_END_ESCAPED)-begin);
396  }
397  continue;
398  }
399 
400  *dest = *src;
401  ++src;
402  ++dest;
403  }
404 
405  // If we get here, dest was completely filled (dest == end)
406  *(dest-1) = 0;
407  return (dest-begin);
408 }
static const KeyPair *const end

◆ xmlQuote() [1/2]

int QXmlTestLogger::xmlQuote ( QTestCharBuffer dest,
char const *  src 
)
static

Definition at line 443 of file qxmltestlogger.cpp.

Referenced by addBenchmarkResult(), addIncident(), addMessage(), enterTestFunction(), QTestXunitStreamer::formatAttributes(), QTestLightXmlStreamer::formatBeforeAttributes(), QTestLightXmlStreamer::formatStart(), QTestXmlStreamer::formatStart(), QTestXmlStreamer::output(), and startLogging().

444 {
445  return allocateStringFn(str, src, QXmlTestLogger::xmlQuote);
446 }
int allocateStringFn(QTestCharBuffer *str, char const *src, StringFormatFunction func)
static int xmlQuote(QTestCharBuffer *dest, char const *src)

◆ xmlQuote() [2/2]

int QXmlTestLogger::xmlQuote ( QTestCharBuffer dest,
char const *  src,
size_t  n 
)
static

Definition at line 305 of file qxmltestlogger.cpp.

306 {
307  if (n == 0) return 0;
308 
309  char *dest = destBuf->data();
310  *dest = 0;
311  if (!src) return 0;
312 
313  char* begin = dest;
314  char* end = dest + n;
315 
316  while (dest < end) {
317  switch (*src) {
318 
319 #define MAP_ENTITY(chr, ent) \
320  case chr: \
321  if (dest + sizeof(ent) < end) { \
322  strcpy(dest, ent); \
323  dest += sizeof(ent) - 1; \
324  } \
325  else { \
326  *dest = 0; \
327  return (dest+sizeof(ent)-begin); \
328  } \
329  ++src; \
330  break;
331 
332  MAP_ENTITY('>', "&gt;");
333  MAP_ENTITY('<', "&lt;");
334  MAP_ENTITY('\'', "&apos;");
335  MAP_ENTITY('"', "&quot;");
336  MAP_ENTITY('&', "&amp;");
337 
338  // not strictly necessary, but allows handling of comments without
339  // having to explicitly look for `--'
340  MAP_ENTITY('-', "&#x002D;");
341 
342 #undef MAP_ENTITY
343 
344  case 0:
345  *dest = 0;
346  return (dest-begin);
347 
348  default:
349  *dest = *src;
350  ++dest;
351  ++src;
352  break;
353  }
354  }
355 
356  // If we get here, dest was completely filled (dest == end)
357  *(dest-1) = 0;
358  return (dest-begin);
359 }
#define MAP_ENTITY(chr, ent)
static const KeyPair *const end

Properties

◆ hasRandomSeed

bool QXmlTestLogger::hasRandomSeed
private

Definition at line 92 of file qxmltestlogger_p.h.

Referenced by registerRandomSeed(), and startLogging().

◆ randomSeed

unsigned int QXmlTestLogger::randomSeed
private

Definition at line 91 of file qxmltestlogger_p.h.

Referenced by registerRandomSeed(), and startLogging().

◆ xmlmode

XmlMode QXmlTestLogger::xmlmode
private

Definition at line 90 of file qxmltestlogger_p.h.

Referenced by startLogging(), and stopLogging().


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