Simplify qtestlib logging code, part 3

Collapse the QTestBasicStreamer class into QTestXunitStreamer.

Change-Id: I349b8db432fd45f9352084f60b36b460f3b61f6a
Reviewed-on: http://codereview.qt.nokia.com/3925
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
bb10
Jason McDonald 2011-08-31 18:53:46 +10:00 committed by Qt by Nokia
parent d88b335d08
commit 964793718f
7 changed files with 37 additions and 266 deletions

View File

@ -1,165 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtTest module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qtestbasicstreamer.h"
#include "qxunittestlogger_p.h"
#include "qtestelement.h"
#include "qtestelementattribute.h"
#include "qtestassert.h"
#include <stdio.h>
#include <stdlib.h>
#ifndef Q_OS_WIN
#include <unistd.h>
#endif
QT_BEGIN_NAMESPACE
QTestBasicStreamer::QTestBasicStreamer(QXunitTestLogger *logger)
:testLogger(logger)
{
QTEST_ASSERT(testLogger);
}
QTestBasicStreamer::~QTestBasicStreamer()
{}
void QTestBasicStreamer::formatStart(const QTestElement *element, QTestCharBuffer *formatted) const
{
if(!element || !formatted )
return;
formatted->data()[0] = '\0';
}
void QTestBasicStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const
{
if(!element || !formatted )
return;
formatted->data()[0] = '\0';
}
void QTestBasicStreamer::formatBeforeAttributes(const QTestElement *element, QTestCharBuffer *formatted) const
{
if(!element || !formatted )
return;
formatted->data()[0] = '\0';
}
void QTestBasicStreamer::formatAfterAttributes(const QTestElement *element, QTestCharBuffer *formatted) const
{
if(!element || !formatted )
return;
formatted->data()[0] = '\0';
}
void QTestBasicStreamer::formatAttributes(const QTestElement *, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const
{
if(!attribute || !formatted )
return;
formatted->data()[0] = '\0';
}
void QTestBasicStreamer::output(QTestElement *element) const
{
if(!element)
return;
outputElements(element);
}
void QTestBasicStreamer::outputElements(QTestElement *element, bool) const
{
QTestCharBuffer buf;
bool hasChildren;
/*
Elements are in reverse order of occurrence, so start from the end and work
our way backwards.
*/
while (element && element->nextElement()) {
element = element->nextElement();
}
while (element) {
hasChildren = element->childElements();
formatStart(element, &buf);
outputString(buf.data());
formatBeforeAttributes(element, &buf);
outputString(buf.data());
outputElementAttributes(element, element->attributes());
formatAfterAttributes(element, &buf);
outputString(buf.data());
if(hasChildren)
outputElements(element->childElements(), true);
formatEnd(element, &buf);
outputString(buf.data());
element = element->previousElement();
}
}
void QTestBasicStreamer::outputElementAttributes(const QTestElement* element, QTestElementAttribute *attribute) const
{
QTestCharBuffer buf;
while(attribute){
formatAttributes(element, attribute, &buf);
outputString(buf.data());
attribute = attribute->nextElement();
}
}
void QTestBasicStreamer::outputString(const char *msg) const
{
testLogger->outputString(msg);
}
QXunitTestLogger *QTestBasicStreamer::logger() const
{
return testLogger;
}
QT_END_NAMESPACE

View File

@ -1,87 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtTest module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QTESTBASICSTREAMER_H
#define QTESTBASICSTREAMER_H
#include <QtCore/qglobal.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Test)
class QTestElement;
class QTestElementAttribute;
class QXunitTestLogger;
struct QTestCharBuffer;
class QTestBasicStreamer
{
public:
QTestBasicStreamer(QXunitTestLogger *logger);
virtual ~QTestBasicStreamer();
virtual void output(QTestElement *element) const;
void outputString(const char *msg) const;
QXunitTestLogger *logger() const;
protected:
virtual void formatStart(const QTestElement *element, QTestCharBuffer *formatted) const;
virtual void formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const;
virtual void formatBeforeAttributes(const QTestElement *element, QTestCharBuffer *formatted) const;
virtual void formatAfterAttributes(const QTestElement *element, QTestCharBuffer *formatted) const;
virtual void formatAttributes(const QTestElement *element, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const;
virtual void outputElements(QTestElement *element, bool isChildElement = false) const;
virtual void outputElementAttributes(const QTestElement *element, QTestElementAttribute *attribute) const;
private:
QXunitTestLogger *testLogger;
};
QT_END_NAMESPACE
QT_END_HEADER
#endif

View File

@ -40,7 +40,10 @@
****************************************************************************/
#include "qtestxunitstreamer.h"
#include "qxunittestlogger_p.h"
#include "qtestelement.h"
#include "qtestelementattribute.h"
#include "qtestassert.h"
#include "QtTest/private/qtestlog_p.h"
#include "QtTest/private/qtestresult_p.h"
@ -49,8 +52,10 @@
QT_BEGIN_NAMESPACE
QTestXunitStreamer::QTestXunitStreamer(QXunitTestLogger *logger)
: QTestBasicStreamer(logger)
{}
: testLogger(logger)
{
QTEST_ASSERT(testLogger);
}
QTestXunitStreamer::~QTestXunitStreamer()
{}
@ -165,8 +170,10 @@ void QTestXunitStreamer::formatAfterAttributes(const QTestElement *element, QTes
void QTestXunitStreamer::output(QTestElement *element) const
{
QTEST_ASSERT(element);
outputString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
QTestBasicStreamer::output(element);
outputElements(element);
}
void QTestXunitStreamer::outputElements(QTestElement *element, bool) const
@ -187,9 +194,6 @@ void QTestXunitStreamer::outputElements(QTestElement *element, bool) const
formatStart(element, &buf);
outputString(buf.data());
formatBeforeAttributes(element, &buf);
outputString(buf.data());
outputElementAttributes(element, element->attributes());
formatAfterAttributes(element, &buf);
@ -205,5 +209,19 @@ void QTestXunitStreamer::outputElements(QTestElement *element, bool) const
}
}
QT_END_NAMESPACE
void QTestXunitStreamer::outputElementAttributes(const QTestElement* element, QTestElementAttribute *attribute) const
{
QTestCharBuffer buf;
while(attribute){
formatAttributes(element, attribute, &buf);
outputString(buf.data());
attribute = attribute->nextElement();
}
}
void QTestXunitStreamer::outputString(const char *msg) const
{
testLogger->outputString(msg);
}
QT_END_NAMESPACE

View File

@ -42,7 +42,7 @@
#ifndef QTESTXUNITSTREAMER_H
#define QTESTXUNITSTREAMER_H
#include <QtTest/qtestbasicstreamer.h>
#include <QtCore/qglobal.h>
QT_BEGIN_HEADER
@ -50,9 +50,12 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Test)
class QTestElement;
class QTestElementAttribute;
class QXunitTestLogger;
struct QTestCharBuffer;
class QTestXunitStreamer: public QTestBasicStreamer
class QTestXunitStreamer
{
public:
QTestXunitStreamer(QXunitTestLogger *logger);
@ -64,10 +67,15 @@ class QTestXunitStreamer: public QTestBasicStreamer
void formatAttributes(const QTestElement *element, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const;
void output(QTestElement *element) const;
void outputElements(QTestElement *element, bool isChildElement = false) const;
void outputElementAttributes(const QTestElement *element, QTestElementAttribute *attribute) const;
void outputString(const char *msg) const;
private:
void displayXunitXmlHeader() const;
static void indentForElement(const QTestElement* element, char* buf, int size);
QXunitTestLogger *testLogger;
};
QT_END_NAMESPACE

View File

@ -57,7 +57,7 @@
QT_BEGIN_NAMESPACE
class QTestBasicStreamer;
class QTestXunitStreamer;
class QTestElement;
class QXunitTestLogger : public QAbstractTestLogger
@ -84,7 +84,7 @@ class QXunitTestLogger : public QAbstractTestLogger
QTestElement *listOfTestcases;
QTestElement *currentLogElement;
QTestElement *errorLogElement;
QTestBasicStreamer *logFormatter;
QTestXunitStreamer *logFormatter;
int testCounter;
int failureCounter;

View File

@ -18,7 +18,6 @@ HEADERS = qbenchmark.h \
qsignalspy.h \
qtestaccessible.h \
qtestassert.h \
qtestbasicstreamer.h \
qtestcase.h \
qtestcoreelement.h \
qtestcorelist.h \
@ -53,7 +52,6 @@ SOURCES = qtestcase.cpp \
qbenchmarkmetric.cpp \
qtestelement.cpp \
qtestelementattribute.cpp \
qtestbasicstreamer.cpp \
qtestxunitstreamer.cpp \
qxunittestlogger.cpp
DEFINES *= QT_NO_CAST_TO_ASCII \

View File

@ -514,7 +514,6 @@ QT_CLASS_LIB(QTest, QtTest, qtest.h)
QT_CLASS_LIB(QtTestGui, QtTest, qtest_gui.h)
QT_CLASS_LIB(QTestAccessibilityEvent, QtTest, qtestaccessible.h)
QT_CLASS_LIB(QTestAccessibility, QtTest, qtestaccessible.h)
QT_CLASS_LIB(QTestBasicStreamer, QtTest, qtestbasicstreamer.h)
QT_CLASS_LIB(QTestCoreElement, QtTest, qtestcoreelement.h)
QT_CLASS_LIB(QTestCoreList, QtTest, qtestcorelist.h)
QT_CLASS_LIB(QTestData, QtTest, qtestdata.h)