summaryrefslogtreecommitdiffstats
path: root/tests/auto/xmlpatternsxqts/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/xmlpatternsxqts/lib')
-rw-r--r--tests/auto/xmlpatternsxqts/lib/ASTItem.cpp202
-rw-r--r--tests/auto/xmlpatternsxqts/lib/ASTItem.h156
-rw-r--r--tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.cpp305
-rw-r--r--tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.h169
-rw-r--r--tests/auto/xmlpatternsxqts/lib/ErrorHandler.cpp207
-rw-r--r--tests/auto/xmlpatternsxqts/lib/ErrorHandler.h190
-rw-r--r--tests/auto/xmlpatternsxqts/lib/ErrorItem.cpp183
-rw-r--r--tests/auto/xmlpatternsxqts/lib/ErrorItem.h135
-rw-r--r--tests/auto/xmlpatternsxqts/lib/ExitCode.h146
-rw-r--r--tests/auto/xmlpatternsxqts/lib/ExpressionInfo.cpp95
-rw-r--r--tests/auto/xmlpatternsxqts/lib/ExpressionInfo.h121
-rw-r--r--tests/auto/xmlpatternsxqts/lib/ExpressionNamer.cpp357
-rw-r--r--tests/auto/xmlpatternsxqts/lib/ExpressionNamer.h322
-rw-r--r--tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.cpp181
-rw-r--r--tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.h178
-rw-r--r--tests/auto/xmlpatternsxqts/lib/Global.cpp124
-rw-r--r--tests/auto/xmlpatternsxqts/lib/Global.h169
-rw-r--r--tests/auto/xmlpatternsxqts/lib/ResultThreader.cpp117
-rw-r--r--tests/auto/xmlpatternsxqts/lib/ResultThreader.h151
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestBaseLine.cpp545
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestBaseLine.h246
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestCase.cpp480
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestCase.h297
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestContainer.cpp192
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestContainer.h164
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestGroup.cpp180
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestGroup.h134
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestItem.h174
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestResult.cpp199
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestResult.h220
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestResultHandler.cpp139
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestResultHandler.h156
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestSuite.cpp302
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestSuite.h191
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.cpp353
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.h210
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestSuiteResult.cpp214
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TestSuiteResult.h134
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TreeItem.cpp103
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TreeItem.h155
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TreeModel.cpp220
-rw-r--r--tests/auto/xmlpatternsxqts/lib/TreeModel.h151
-rw-r--r--tests/auto/xmlpatternsxqts/lib/Worker.cpp299
-rw-r--r--tests/auto/xmlpatternsxqts/lib/Worker.h141
-rw-r--r--tests/auto/xmlpatternsxqts/lib/XMLWriter.cpp710
-rw-r--r--tests/auto/xmlpatternsxqts/lib/XMLWriter.h444
-rw-r--r--tests/auto/xmlpatternsxqts/lib/XQTSTestCase.cpp327
-rw-r--r--tests/auto/xmlpatternsxqts/lib/XQTSTestCase.h190
-rw-r--r--tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.cpp275
-rw-r--r--tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.h199
-rw-r--r--tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExample.cpp63
-rw-r--r--tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExampleResult.xml3
-rw-r--r--tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExample.cpp63
-rw-r--r--tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExampleResult.xml3
-rw-r--r--tests/auto/xmlpatternsxqts/lib/lib.pro78
-rw-r--r--tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.cpp227
-rw-r--r--tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.h118
57 files changed, 11807 insertions, 0 deletions
diff --git a/tests/auto/xmlpatternsxqts/lib/ASTItem.cpp b/tests/auto/xmlpatternsxqts/lib/ASTItem.cpp
new file mode 100644
index 0000000..a9aeb39
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/ASTItem.cpp
@@ -0,0 +1,202 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QList>
+#include <QPointer>
+#include <QVariant>
+
+#include "ASTItem.h"
+
+using namespace QPatternistSDK;
+
+/**
+ * This is what the AST rendering is indented with.
+ */
+static const QLatin1String astIndent(" ");
+// STATIC DATA
+
+ASTItem::ASTItem(ASTItem *p,
+ const QString &name,
+ const QString &details,
+ const QString &staticType,
+ const QString &reqType) : m_name(name),
+ m_details(details),
+ m_reqType(reqType),
+ m_staticType(staticType),
+ m_parent(p)
+{
+}
+
+ASTItem::~ASTItem()
+{
+ qDeleteAll(m_children);
+}
+
+QString ASTItem::toString() const
+{
+ /* The first ASTItem* is a virtual root node, so skip "this". */
+ Q_ASSERT(m_children.count() == 1);
+ TreeItem *treeChild = m_children.first();
+ Q_ASSERT(treeChild);
+
+ ASTItem *astChild = static_cast<ASTItem *>(treeChild);
+
+ return astChild->toString(QString());
+}
+
+QString ASTItem::toString(const QString &indent) const
+{
+ QString retval;
+
+ retval += indent;
+ retval += m_name;
+ retval += QLatin1Char('(');
+ retval += m_details;
+ retval += QLatin1String(")\n");
+
+ const TreeItem::List::const_iterator end(m_children.constEnd());
+
+ for(TreeItem::List::const_iterator it(m_children.constBegin()); it != end; ++it)
+ {
+ TreeItem *treeChild = *it; /* Cast away the QPointer with its casting operator. */
+ ASTItem *astChild = static_cast<ASTItem *>(treeChild);
+
+ retval += astChild->toString(indent + astIndent);
+ }
+
+ return retval;
+}
+
+QVariant ASTItem::data(const Qt::ItemDataRole role, int column) const
+{
+ if(role != Qt::DisplayRole)
+ return QVariant();
+
+ switch(column)
+ {
+ case 0:
+ return m_name;
+ case 1:
+ return m_details;
+ case 2:
+ return m_staticType;
+ case 3:
+ return m_reqType;
+ default:
+ {
+ Q_ASSERT(false);
+ return QVariant();
+ }
+ }
+}
+
+int ASTItem::columnCount() const
+{
+ return 4;
+}
+
+TreeItem::List ASTItem::children() const
+{
+ return m_children;
+}
+
+void ASTItem::appendChild(TreeItem *item)
+{
+ m_children.append(item);
+}
+
+TreeItem *ASTItem::child(const unsigned int rowP) const
+{
+ return m_children.value(rowP);
+}
+
+unsigned int ASTItem::childCount() const
+{
+ return m_children.count();
+}
+
+TreeItem *ASTItem::parent() const
+{
+ return m_parent;
+}
+
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/ASTItem.h b/tests/auto/xmlpatternsxqts/lib/ASTItem.h
new file mode 100644
index 0000000..7d72db7
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/ASTItem.h
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_ASTItem_H
+#define PatternistSDK_ASTItem_H
+
+#include <QList>
+#include <QString>
+
+#include "TreeItem.h"
+#include "Global.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ /**
+ * @short Is a node in a ASTItem tree; each ASTItem contains
+ * debug information about an QPatternist::Expression.
+ *
+ * ASTItem, by implementing TreeItem, leverages debug data about QPatternist::Expression
+ * instances into Qt's model/view framework.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT ASTItem : public TreeItem
+ {
+ public:
+ virtual ~ASTItem();
+ ASTItem(ASTItem *parent,
+ const QString &name,
+ const QString &details = QString(),
+ const QString &staticType = QString(),
+ const QString &reqType = QString());
+
+ virtual void appendChild(TreeItem *item);
+ virtual TreeItem *child(const unsigned int row) const;
+ virtual unsigned int childCount() const;
+ virtual QVariant data(const Qt::ItemDataRole role, int column) const;
+ virtual TreeItem::List children() const;
+ virtual TreeItem *parent() const;
+ int columnCount() const;
+
+ /**
+ * Returns a string representation of this AST node, recursively including
+ * children. For example, the query <tt>1 eq number()</tt> would result in the string:
+ *
+@verbatim
+ValueComparison(eq)
+ xs:integer(0)
+ FunctionCall(fn:number)
+ ContextItem
+@endverbatim
+ */
+ QString toString() const;
+
+ private:
+ QString toString(const QString &indent) const;
+
+ const QString m_name;
+ const QString m_details;
+ const QString m_reqType;
+ const QString m_staticType;
+ TreeItem::List m_children;
+ TreeItem *m_parent;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.cpp b/tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.cpp
new file mode 100644
index 0000000..888c14f
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.cpp
@@ -0,0 +1,305 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QStringList>
+#include <QVariant>
+#include <QtDebug>
+#include <QXmlNamePool>
+
+#include "qfunctionfactorycollection_p.h"
+
+#include "ASTItem.h"
+#include "ExpressionInfo.h"
+#include "ExpressionNamer.h"
+#include "Global.h"
+
+#include "DebugExpressionFactory.h"
+
+using namespace QPatternistSDK;
+using namespace QPatternist;
+
+static const QPatternist::ExpressionVisitor::Ptr namer(new ExpressionNamer());
+
+QStringList DebugExpressionFactory::availableFunctionSignatures()
+{
+ const QPatternist::FunctionFactory::Ptr factory(QPatternist::FunctionFactoryCollection::xpath20Factory(Global::namePool()));
+ const QPatternist::FunctionSignature::Hash signs(factory->functionSignatures());
+ const QPatternist::FunctionSignature::Hash::const_iterator end(signs.constEnd());
+ QPatternist::FunctionSignature::Hash::const_iterator it(signs.constBegin());
+ QStringList retval;
+
+ while(it != end)
+ {
+ retval << it.value()->displayName(Global::namePool());
+ ++it;
+ }
+
+ return retval;
+}
+
+ASTItem *DebugExpressionFactory::buildASTTree(const QPatternist::Expression::Ptr &expr,
+ ASTItem *parent,
+ const QPatternist::SequenceType::Ptr &reqType)
+{
+ Q_ASSERT(expr);
+ const QPatternist::ExpressionVisitorResult::Ptr exprInfo(expr->accept(namer));
+ Q_ASSERT(exprInfo);
+ const ExpressionInfo *const constExprInfo = static_cast<const ExpressionInfo *>(exprInfo.data());
+ const QString name(constExprInfo->first);
+ const QString details(constExprInfo->second);
+ const QString rType(reqType ? reqType->displayName(Global::namePool()) : QLatin1String("Not specified"));
+
+ /* ---------- Handle its staticType() -------- */
+ const QPatternist::SequenceType::Ptr type(expr->staticType());
+ QString seqType;
+
+ if(type)
+ seqType = type->displayName(Global::namePool());
+ else
+ seqType = QLatin1String("no type, null pointer returned");
+ /* ------------------------------------------- */
+
+ ASTItem *const node = new ASTItem(parent, name, details, seqType, rType);
+
+ /* ------------ Handle child nodes ----------- */
+ const QPatternist::Expression::List children(expr->operands());
+ QPatternist::Expression::List::const_iterator it(children.constBegin());
+ const QPatternist::Expression::List::const_iterator end(children.constEnd());
+
+ const QPatternist::SequenceType::List reqTypes(expr->expectedOperandTypes());
+ const QPatternist::SequenceType::List::const_iterator typeEnd(reqTypes.constEnd());
+ QPatternist::SequenceType::List::const_iterator typeIt(reqTypes.constBegin());
+ QPatternist::SequenceType::Ptr t;
+
+ for(; it != end; ++it)
+ {
+ if(typeIt != typeEnd)
+ {
+ t = *typeIt;
+ ++typeIt;
+ }
+
+ node->appendChild(buildASTTree(*it, node, t));
+ }
+ /* ------------------------------------------- */
+
+ return node;
+}
+
+QPatternist::Expression::Ptr
+DebugExpressionFactory::createExpression(QIODevice *const expr,
+ const QPatternist::StaticContext::Ptr &context,
+ const QXmlQuery::QueryLanguage lang,
+ const QPatternist::SequenceType::Ptr &requiredType,
+ const QUrl &baseURI,
+ const QXmlName &initialTemplateName)
+{
+ /* Create the root node. */
+ m_ast = new ASTItem(0, QString());
+
+ return ExpressionFactory::createExpression(expr, context, lang, requiredType, baseURI, initialTemplateName);
+}
+
+void DebugExpressionFactory::processTreePass(const QPatternist::Expression::Ptr &expr,
+ const CompilationStage stage)
+{
+ ASTItem *newChild = 0;
+
+ switch(stage)
+ {
+ case QueryBodyInitial:
+ {
+ newChild = new ASTItem(m_ast, QLatin1String("Initial Build"));
+ break;
+ }
+ case QueryBodyTypeCheck:
+ {
+ newChild = new ASTItem(m_ast, QLatin1String("Type Check"));
+ break;
+ }
+ case QueryBodyCompression:
+ {
+ newChild = new ASTItem(m_ast, QLatin1String("Compression"));
+ break;
+ }
+ case UserFunctionTypeCheck:
+ {
+ newChild = new ASTItem(m_ast, QLatin1String("User Function Type Check"));
+ break;
+ }
+ case UserFunctionCompression:
+ {
+ newChild = new ASTItem(m_ast, QLatin1String("User Function Compression"));
+ break;
+ }
+ case GlobalVariableTypeCheck:
+ {
+ newChild = new ASTItem(m_ast, QLatin1String("Global Variable Type Check"));
+ break;
+ }
+ }
+
+ Q_ASSERT(newChild);
+ m_ast->appendChild(newChild);
+ newChild->appendChild(buildASTTree(expr, newChild, QPatternist::SequenceType::Ptr()));
+}
+
+void DebugExpressionFactory::processTemplateRule(const Expression::Ptr &body,
+ const TemplatePattern::Ptr &pattern,
+ const QXmlName &mode,
+ const TemplateCompilationStage stage)
+{
+ const char * title;
+
+ switch(stage)
+ {
+ case TemplateInitial:
+ {
+ title = "Initial Build";
+ break;
+ }
+ case TemplateTypeCheck:
+ {
+ title = "Type Check";
+ break;
+ }
+ case TemplateCompress:
+ {
+ title = "Compression";
+ break;
+ }
+ }
+
+ const QString modeName(Global::namePool()->displayName(mode));
+ Q_ASSERT(title);
+ ASTItem *const newChild = new ASTItem(m_ast, QLatin1String("T-Rule ")
+ + QLatin1String(title)
+ + QLatin1String(" mode: ")
+ + modeName
+ + QLatin1String(" priority: ")
+ + QString::number(pattern->priority()));
+ m_ast->appendChild(newChild);
+
+ newChild->appendChild(buildASTTree(pattern->matchPattern(), newChild, QPatternist::SequenceType::Ptr()));
+ newChild->appendChild(buildASTTree(body, newChild, QPatternist::SequenceType::Ptr()));
+}
+
+void DebugExpressionFactory::processNamedTemplate(const QXmlName &name,
+ const Expression::Ptr &body,
+ const TemplateCompilationStage stage)
+{
+ const char * title;
+
+ switch(stage)
+ {
+ case TemplateInitial:
+ {
+ title = "Named Template Initial Build";
+ break;
+ }
+ case TemplateTypeCheck:
+ {
+ title = "Named Template Type Check";
+ break;
+ }
+ case TemplateCompress:
+ {
+ title = "Named Template Compression";
+ break;
+ }
+ }
+
+ Q_ASSERT(title);
+ ASTItem *const newChild = new ASTItem(m_ast, QLatin1String(title)
+ + QLatin1String(": ")
+ + Global::namePool()->displayName(name));
+
+ m_ast->appendChild(newChild);
+ newChild->appendChild(buildASTTree(body, newChild, QPatternist::SequenceType::Ptr()));
+}
+
+ASTItem *DebugExpressionFactory::astTree() const
+{
+ return m_ast;
+}
+
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.h b/tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.h
new file mode 100644
index 0000000..235e936
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.h
@@ -0,0 +1,169 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_DebugExpressionFactory_H
+#define PatternistSDK_DebugExpressionFactory_H
+
+#include "Global.h"
+#include "qexpressionfactory_p.h"
+#include "qfunctionfactory_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ class ASTItem;
+
+ /**
+ * @short Is a QPatternist::ExpressionFactory, with the
+ * difference that it provides the hooks for building from a tree of
+ * debug data from the compiled expression.
+ *
+ * This tree can be retrieved via astTree(). The astTree() function
+ * returns the AST built the last time createExpression() was called.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT DebugExpressionFactory : public QPatternist::ExpressionFactory
+ {
+ public:
+ DebugExpressionFactory() : m_ast(0)
+ {
+ }
+
+ typedef QExplicitlySharedDataPointer<DebugExpressionFactory> Ptr;
+ /**
+ * Identical to ExpressionFactory::createExpression() with the difference
+ * that it builds an ASTItem tree which can be accessed via astTree().
+ */
+ virtual QPatternist::Expression::Ptr createExpression(QIODevice *const expr,
+ const QPatternist::StaticContext::Ptr &context,
+ const QXmlQuery::QueryLanguage lang,
+ const QPatternist::SequenceType::Ptr &requiredType,
+ const QUrl &queryURI,
+ const QXmlName &initialTemplateName);
+
+ /**
+ * @returns an ASTItem tree built for the last created expression,
+ * via createExpression().
+ */
+ virtual ASTItem *astTree() const;
+
+ /**
+ * @returns a list containing string representations of all available
+ * functions in Patternist. Each QString in the returned QStringList
+ * is a function synopsis for human consumption.
+ */
+ static QStringList availableFunctionSignatures();
+
+ protected:
+ /**
+ * Performs the ASTItem tree building.
+ */
+ virtual void processTreePass(const QPatternist::Expression::Ptr &tree,
+ const CompilationStage stage);
+
+ void processTemplateRule(const QPatternist::Expression::Ptr &body,
+ const QPatternist::TemplatePattern::Ptr &pattern,
+ const QXmlName &mode,
+ const TemplateCompilationStage stage);
+
+ void processNamedTemplate(const QXmlName &name,
+ const QPatternist::Expression::Ptr &body,
+ const TemplateCompilationStage stage);
+ private:
+ static ASTItem *buildASTTree(const QPatternist::Expression::Ptr &expr,
+ ASTItem *const parent,
+ const QPatternist::SequenceType::Ptr &reqType);
+ ASTItem *m_ast;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/ErrorHandler.cpp b/tests/auto/xmlpatternsxqts/lib/ErrorHandler.cpp
new file mode 100644
index 0000000..35d7b74
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/ErrorHandler.cpp
@@ -0,0 +1,207 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <cstdio>
+
+#include <QBuffer>
+#include <QStringList>
+#include <QtDebug>
+#include <QtTest>
+#include <QtGlobal>
+#include <QXmlQuery>
+#include <QXmlResultItems>
+
+#include "ErrorHandler.h"
+
+using namespace QPatternistSDK;
+
+ErrorHandler *ErrorHandler::handler = 0;
+
+void qMessageHandler(QtMsgType type, const char *description)
+{
+ if(type == QtDebugMsg)
+ {
+ std::fprintf(stderr, "%s\n", description);
+ return;
+ }
+
+ QtMsgType t;
+
+ switch(type)
+ {
+ case QtWarningMsg:
+ {
+ t = QtWarningMsg;
+ break;
+ }
+ case QtCriticalMsg:
+ {
+ t = QtFatalMsg;
+ break;
+ }
+ case QtFatalMsg:
+ {
+ /* We can't swallow Q_ASSERTs, we need to fail the hard way here.
+ * But maybe not: when run from "patternistrunsingle" it could be an idea
+ * to actually try to record it(but nevertheless fail somehow) such
+ * that it gets reported. */
+ std::fprintf(stderr, "Fatal error: %s\n", description);
+ t = QtFatalMsg; /* Dummy, to silence a bogus compiler warning. */
+ return;
+ }
+ case QtDebugMsg: /* This enum is handled above in the if-clause. */
+ /* Fallthrough. */
+ default:
+ {
+ Q_ASSERT(false);
+ return;
+ }
+ }
+
+ Q_ASSERT(ErrorHandler::handler);
+ /* This message is hacky. Ideally, we should do it the same way
+ * ReportContext::error() constructs messages, but this is just testing
+ * code. */
+ ErrorHandler::handler->message(t, QLatin1String("<p>") + QPatternist::escape(QLatin1String(description)) + QLatin1String("</p>"));
+}
+
+void ErrorHandler::installQtMessageHandler(ErrorHandler *const h)
+{
+ handler = h;
+
+ if(h)
+ qInstallMsgHandler(qMessageHandler);
+ else
+ qInstallMsgHandler(0);
+}
+
+void ErrorHandler::handleMessage(QtMsgType type,
+ const QString &description,
+ const QUrl &identifier,
+ const QSourceLocation &)
+{
+ /* Don't use pDebug() in this function, it results in infinite
+ * recursion. Talking from experience.. */
+
+ Message msg;
+ msg.setType(type);
+ msg.setIdentifier(identifier);
+
+ /* Let's remove all the XHTML markup. */
+ QBuffer buffer;
+ buffer.setData(description.toLatin1());
+ buffer.open(QIODevice::ReadOnly);
+
+ QXmlQuery query;
+ query.bindVariable(QLatin1String("desc"), &buffer);
+ query.setQuery(QLatin1String("string(doc($desc))"));
+
+ QStringList result;
+ const bool success = query.evaluateTo(&result);
+
+ if(!description.startsWith(QLatin1String("\"Test-suite harness error:")))
+ {
+ const QString msg(QString::fromLatin1("Invalid description: %1").arg(description));
+ QVERIFY2(success, qPrintable(msg));
+
+ if(!success)
+ QTextStream(stderr) << msg;
+ }
+
+
+ if(!result.isEmpty())
+ msg.setDescription(result.first());
+
+ m_messages.append(msg);
+}
+
+ErrorHandler::Message::List ErrorHandler::messages() const
+{
+ return m_messages;
+}
+
+void ErrorHandler::reset()
+{
+ m_messages.clear();
+}
+
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/ErrorHandler.h b/tests/auto/xmlpatternsxqts/lib/ErrorHandler.h
new file mode 100644
index 0000000..150a522
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/ErrorHandler.h
@@ -0,0 +1,190 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_ErrorHandler_H
+#define PatternistSDK_ErrorHandler_H
+
+#include "Global.h"
+#include "qabstractmessagehandler.h"
+
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+template<typename T> class QList;
+
+namespace QPatternistSDK
+{
+ /**
+ * @short A MessageHandler which
+ * accumulates all its received ErrorHandler::Message instances
+ * in a list, retrievable via messages().
+ *
+ * Thus, ErrorHandler does not report errors, but collects them
+ * and allows easy access to them.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT ErrorHandler : public QAbstractMessageHandler
+ {
+ public:
+ class Message
+ {
+ public:
+ typedef QList<Message> List;
+
+ QString description() const
+ {
+ return m_description;
+ }
+
+ void setDescription(const QString &desc)
+ {
+ m_description = desc;
+ }
+
+ void setIdentifier(const QUrl &newId)
+ {
+ m_identifier = newId;
+ }
+
+ QUrl identifier() const
+ {
+ return m_identifier;
+ }
+
+ QtMsgType type() const
+ {
+ return m_type;
+ }
+
+ void setType(const QtMsgType t)
+ {
+ m_type = t;
+ }
+
+ private:
+ QUrl m_identifier;
+ QtMsgType m_type;
+ QString m_description;
+ };
+
+ /**
+ * Clears all accumulated errors.
+ */
+ void reset();
+
+ Message::List messages() const;
+
+ /**
+ * Calling this function causes all Qt's internal debug messages to be
+ * sent to @p handler. If @p handler is @c null, Qt's default message
+ * handler is re-installed. In other words, via an internal proxy function,
+ * it installs @p handler as Qt's message handler.
+ *
+ * If @p handler is heap allocated, it will be leaked.
+ *
+ * @see qInstallMsgHandler()
+ */
+ static void installQtMessageHandler(ErrorHandler *const handler);
+
+ static ErrorHandler *handler;
+
+ protected:
+ virtual void handleMessage(QtMsgType type,
+ const QString &description,
+ const QUrl &identifier = QUrl(),
+ const QSourceLocation &sourceLocation = QSourceLocation());
+
+ private:
+ ErrorHandler::Message::List m_messages;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/ErrorItem.cpp b/tests/auto/xmlpatternsxqts/lib/ErrorItem.cpp
new file mode 100644
index 0000000..955e261
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/ErrorItem.cpp
@@ -0,0 +1,183 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QList>
+#include <QPointer>
+#include <QVariant>
+
+#include "qreportcontext_p.h"
+#include "qcommonnamespaces_p.h"
+
+#include "ErrorItem.h"
+
+using namespace QPatternistSDK;
+
+QString ErrorItem::toString(const QtMsgType type)
+{
+ switch(type)
+ {
+ case QtWarningMsg:
+ return QLatin1String("Warning");
+ case QtFatalMsg:
+ return QLatin1String("Error");
+ default:
+ {
+ Q_ASSERT(false);
+ return QString();
+ }
+ }
+}
+
+ErrorItem::ErrorItem(const ErrorHandler::Message &error,
+ ErrorItem *p) : m_message(error),
+ m_parent(p)
+{
+}
+
+ErrorItem::~ErrorItem()
+{
+ qDeleteAll(m_children);
+}
+
+int ErrorItem::columnCount() const
+{
+ return 3;
+}
+
+QVariant ErrorItem::data(const Qt::ItemDataRole role, int column) const
+{
+ if(role != Qt::DisplayRole)
+ return QVariant();
+
+ switch(column)
+ {
+ case 0:
+ return toString(m_message.type());
+ case 1:
+ {
+ if(!m_message.type()) /* It's a warning, likely. */
+ return QString();
+
+ QString ns;
+ const QString code(QPatternist::ReportContext::codeFromURI(m_message.identifier().toString(), ns));
+
+ if(ns == QPatternist::CommonNamespaces::XPERR)
+ return code;
+ else /* Do the full version. */
+ return m_message.type();
+ }
+ case 2:
+ return m_message.description();
+ default:
+ {
+ Q_ASSERT(false);
+ return QVariant();
+ }
+ }
+}
+
+TreeItem::List ErrorItem::children() const
+{
+ return m_children;
+}
+
+void ErrorItem::appendChild(TreeItem *item)
+{
+ m_children.append(item);
+}
+
+TreeItem *ErrorItem::child(const unsigned int rowP) const
+{
+ return m_children.value(rowP);
+}
+
+unsigned int ErrorItem::childCount() const
+{
+ return m_children.count();
+}
+
+TreeItem *ErrorItem::parent() const
+{
+ return m_parent;
+}
+
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/ErrorItem.h b/tests/auto/xmlpatternsxqts/lib/ErrorItem.h
new file mode 100644
index 0000000..fe0602d
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/ErrorItem.h
@@ -0,0 +1,135 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_ErrorItem_H
+#define PatternistSDK_ErrorItem_H
+
+#include <QList>
+
+#include "ErrorHandler.h"
+#include "Global.h"
+#include "TreeItem.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ /**
+ * @short Delegates a ErrorHandler::Message through the interface
+ * exposed by TreeItem, such that errors from DOM related code
+ * can be displayed/used in Qt's model/view framework.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT ErrorItem : public TreeItem
+ {
+ public:
+ ErrorItem(const ErrorHandler::Message &error, ErrorItem *parent);
+ virtual ~ErrorItem();
+
+ virtual QVariant data(const Qt::ItemDataRole role, int column) const;
+
+ virtual void appendChild(TreeItem *item);
+ virtual TreeItem *child(const unsigned int row) const;
+ virtual unsigned int childCount() const;
+ virtual TreeItem::List children() const;
+ virtual TreeItem *parent() const;
+ int columnCount() const;
+
+ private:
+ static QString toString(const QtMsgType sev);
+
+ const ErrorHandler::Message m_message;
+ ErrorItem * m_parent;
+ TreeItem::List m_children;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/ExitCode.h b/tests/auto/xmlpatternsxqts/lib/ExitCode.h
new file mode 100644
index 0000000..a419796
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/ExitCode.h
@@ -0,0 +1,146 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_ExitCode_H
+#define PatternistSDK_ExitCode_H
+
+#include "Global.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ /**
+ * @short Houses program exit codes for PatternistSDK utilities.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT ExitCode
+ {
+ public:
+ /**
+ * Exit codes for programs part of PatternistSDK. The values for the enums are specified
+ * to make it easily understandable what number a symbol corresponds to.
+ */
+ enum Code
+ {
+ Success = 0,
+ InvalidArgCount = 1,
+ InvalidArgs = 2,
+
+ /**
+ * Used in @c patternistrunsuite
+ */
+ InvalidCatalogFile = 3,
+ FileNotExists = 4,
+ OpenError = 5,
+ WriteError = 6,
+
+ /**
+ * Used in the test program used for comparing files on the byte level.
+ */
+ NotEqual = 7,
+ UnevenTestCount = 8,
+ InternalError = 9,
+ Regression = 10
+ };
+
+ private:
+ /**
+ * This constructor is private and has no implementation, because this
+ * class is not supposed to be instantiated.
+ */
+ inline ExitCode();
+
+ Q_DISABLE_COPY(ExitCode)
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/ExpressionInfo.cpp b/tests/auto/xmlpatternsxqts/lib/ExpressionInfo.cpp
new file mode 100644
index 0000000..a9137ba
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/ExpressionInfo.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QtDebug>
+
+#include "ExpressionInfo.h"
+
+using namespace QPatternistSDK;
+
+ExpressionInfo::ExpressionInfo(const QString &name,
+ const QString &details) : QPair<QString, QString>(name, details)
+{
+}
+
+// vim: et:ts=4:sw=4:sts=4
+
diff --git a/tests/auto/xmlpatternsxqts/lib/ExpressionInfo.h b/tests/auto/xmlpatternsxqts/lib/ExpressionInfo.h
new file mode 100644
index 0000000..a48cfbe
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/ExpressionInfo.h
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_ExpressionInfo_H
+#define PatternistSDK_ExpressionInfo_H
+
+#include "Global.h"
+#include "qexpressiondispatch_p.h"
+
+#include <QPair>
+#include <QString>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ /**
+ * @short Houses debug information about an QPatternist::Expression instance.
+ *
+ * An Expression's name, typically its class name, can be retrieved
+ * via the member variable first, and additional data, for example its string
+ * value or operator, can be retrieved via the member variable second.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT ExpressionInfo : public QPatternist::ExpressionVisitorResult
+ , public QPair<QString, QString>
+ {
+ public:
+ ExpressionInfo(const QString &name, const QString &details);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/ExpressionNamer.cpp b/tests/auto/xmlpatternsxqts/lib/ExpressionNamer.cpp
new file mode 100644
index 0000000..0286366
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/ExpressionNamer.cpp
@@ -0,0 +1,357 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QtDebug>
+
+#include "qabstractfloat_p.h"
+#include "qandexpression_p.h"
+#include "qanyuri_p.h"
+#include "qapplytemplate_p.h"
+#include "qargumentreference_p.h"
+#include "qarithmeticexpression_p.h"
+#include "qatomicstring_p.h"
+#include "qatomizer_p.h"
+#include "qattributeconstructor_p.h"
+#include "qattributenamevalidator_p.h"
+#include "qaxisstep_p.h"
+#include "qbase64binary_p.h"
+#include "qboolean_p.h"
+#include "qcardinalityverifier_p.h"
+#include "qcastableas_p.h"
+#include "qcastas_p.h"
+#include "qcombinenodes_p.h"
+#include "qcontextitem_p.h"
+#include "qdate_p.h"
+#include "qdecimal_p.h"
+#include "qdynamiccontextstore_p.h"
+#include "qelementconstructor_p.h"
+#include "qemptysequence_p.h"
+#include "qevaluationcache_p.h"
+#include "qexpressionsequence_p.h"
+#include "qexpressionvariablereference_p.h"
+#include "qfirstitempredicate_p.h"
+#include "qforclause_p.h"
+#include "qfunctioncall_p.h"
+#include "qgday_p.h"
+#include "qgeneralcomparison_p.h"
+#include "qgenericpredicate_p.h"
+#include "qgmonthday_p.h"
+#include "qgmonth_p.h"
+#include "qgyearmonth_p.h"
+#include "qgyear_p.h"
+#include "qhexbinary_p.h"
+#include "qifthenclause_p.h"
+#include "qinstanceof_p.h"
+#include "qinteger_p.h"
+#include "qitem_p.h"
+#include "qitemverifier_p.h"
+#include "qliteral_p.h"
+#include "qnamespaceconstructor_p.h"
+#include "qncnameconstructor_p.h"
+#include "qnodecomparison_p.h"
+#include "qorexpression_p.h"
+#include "qpath_p.h"
+#include "qpositionalvariablereference_p.h"
+#include "qqnameconstructor_p.h"
+#include "qqnamevalue_p.h"
+#include "qquantifiedexpression_p.h"
+#include "qrangeexpression_p.h"
+#include "qrangevariablereference_p.h"
+#include "qschemadatetime_p.h"
+#include "qschematime_p.h"
+#include "qsimplecontentconstructor_p.h"
+#include "qtreatas_p.h"
+#include "qtruthpredicate_p.h"
+#include "quntypedatomicconverter_p.h"
+#include "quntypedatomic_p.h"
+#include "quserfunctioncallsite_p.h"
+#include "qvalidationerror_p.h"
+#include "qvaluecomparison_p.h"
+
+#include "ExpressionInfo.h"
+#include "Global.h"
+
+#include "ExpressionNamer.h"
+
+using namespace QPatternistSDK;
+
+/* Simple ones, they have no additional data. */
+#define implClass(cls) \
+QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *) const \
+{ \
+ return QPatternist::ExpressionVisitorResult::Ptr \
+ (new ExpressionInfo(QLatin1String(#cls), QString())); \
+}
+
+implClass(AndExpression)
+implClass(ArgumentConverter)
+implClass(Atomizer)
+implClass(AttributeConstructor)
+implClass(AttributeNameValidator)
+implClass(CallTemplate)
+implClass(CardinalityVerifier)
+implClass(CollationChecker)
+implClass(CommentConstructor)
+implClass(ComputedNamespaceConstructor)
+implClass(ContextItem)
+implClass(CopyOf)
+implClass(CurrentItemStore)
+implClass(DocumentConstructor)
+implClass(DynamicContextStore)
+implClass(EBVExtractor)
+implClass(ElementConstructor)
+implClass(EmptySequence)
+implClass(ExpressionSequence)
+implClass(ExternalVariableReference)
+implClass(FirstItemPredicate)
+implClass(ForClause)
+implClass(GenericPredicate)
+implClass(IfThenClause)
+implClass(ItemVerifier)
+implClass(LetClause)
+implClass(LiteralSequence)
+implClass(NCNameConstructor)
+implClass(NodeSortExpression)
+implClass(OrderBy)
+implClass(OrExpression)
+implClass(ParentNodeAxis)
+implClass(ProcessingInstructionConstructor)
+implClass(QNameConstructor)
+implClass(RangeExpression)
+implClass(ReturnOrderBy)
+implClass(SimpleContentConstructor)
+implClass(StaticBaseURIStore)
+implClass(StaticCompatibilityStore)
+implClass(TemplateParameterReference)
+implClass(TextNodeConstructor)
+implClass(TreatAs)
+implClass(TruthPredicate)
+implClass(UnresolvedVariableReference)
+implClass(UntypedAtomicConverter)
+implClass(UserFunctionCallsite)
+implClass(ValidationError)
+#undef implClass
+
+/** Variable references. */
+#define implVarRef(name) \
+QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::name *i) const \
+{ \
+ return QPatternist::ExpressionVisitorResult::Ptr \
+ (new ExpressionInfo(QLatin1String(#name), \
+ QString(QLatin1String("Slot: %1")).arg(i->slot()))); \
+}
+implVarRef(RangeVariableReference)
+implVarRef(ArgumentReference)
+implVarRef(ExpressionVariableReference)
+implVarRef(PositionalVariableReference)
+#undef implVarRef
+
+/* Type related classes which have a targetType() function. */
+#define implTypeClass(cls) \
+QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *i) const \
+{ \
+ return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String(#cls), \
+ i->targetType()->displayName(Global::namePool()))); \
+}
+
+implTypeClass(InstanceOf)
+implTypeClass(CastableAs)
+#undef implTypeClass
+
+/* Type related classes which have a targetType() function. */
+QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::CastAs *i) const
+{
+ return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("CastAs"),
+ i->targetSequenceType()->displayName(Global::namePool())));
+}
+
+/* Classes which represent operators. */
+#define implOPClass(cls, compClass) \
+QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *i) const \
+{ \
+ return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String(#cls), \
+ QPatternist::compClass::displayName(i->operatorID()))); \
+}
+
+implOPClass(ArithmeticExpression, AtomicMathematician)
+implOPClass(NodeComparison, NodeComparison)
+implOPClass(QuantifiedExpression, QuantifiedExpression)
+implOPClass(CombineNodes, CombineNodes)
+#undef implOPClass
+
+/* Classes which represent operators. */
+#define implCompClass(cls, type) \
+QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *i) const \
+{ \
+ return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String(#cls), \
+ QPatternist::AtomicComparator::displayName(i->operatorID(), \
+ QPatternist::AtomicComparator::type))); \
+}
+
+implCompClass(GeneralComparison, AsGeneralComparison)
+implCompClass(ValueComparison, AsValueComparison)
+#undef implCompClass
+
+QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::FunctionCall *i) const
+{
+ return QPatternist::ExpressionVisitorResult::Ptr
+ (new ExpressionInfo(QLatin1String("FunctionCall"),
+ Global::namePool()->displayName(i->signature()->name())));
+}
+
+QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::Literal *i) const
+{
+ return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(
+ i->item().type()->displayName(Global::namePool()),
+ i->item().stringValue()));
+}
+
+QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::AxisStep *i) const
+{
+ return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("AxisStep"),
+ QPatternist::AxisStep::axisName(i->axis()) +
+ QLatin1String("::") +
+ i->nodeTest()->displayName(Global::namePool())));
+
+}
+
+
+QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::EvaluationCache<true> *i) const
+{
+ return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("EvaluationCache<IsForGlobal=true>"),
+ QLatin1String("Slot: ") + QString::number(i->slot())));
+
+}
+
+QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::EvaluationCache<false> *i) const
+{
+ return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("EvaluationCache<IsForGlobal=false>"),
+ QLatin1String("Slot: ") + QString::number(i->slot())));
+
+}
+
+QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::NamespaceConstructor *i) const
+{
+ return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("NamespaceConstructor"),
+ Global::namePool()->stringForPrefix(i->namespaceBinding().prefix()) +
+ QLatin1Char('=') +
+ Global::namePool()->stringForNamespace(i->namespaceBinding().namespaceURI())));
+
+}
+
+QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::Path *path) const
+{
+
+ QPatternist::Path::Kind k = path->kind();
+ QString type;
+
+ switch(k)
+ {
+ case QPatternist::Path::XSLTForEach:
+ {
+ type = QLatin1String("XSLTForEach");
+ break;
+ }
+ case QPatternist::Path::RegularPath:
+ {
+ type = QLatin1String("RegularPath");
+ break;
+ }
+ case QPatternist::Path::ForApplyTemplate:
+ {
+ type = QLatin1String("ForApplyTemplate");
+ break;
+ }
+ }
+
+ return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("Path"), type));
+}
+
+QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::ApplyTemplate *path) const
+{
+ const QPatternist::TemplateMode::Ptr mode(path->mode());
+ return QPatternist::ExpressionVisitorResult::Ptr
+ (new ExpressionInfo(QLatin1String("ApplyTemplate"), mode ? Global::namePool()->displayName(mode->name()) : QString::fromLatin1("#current")));
+}
+
+// vim: et:ts=4:sw=4:sts=4
+
diff --git a/tests/auto/xmlpatternsxqts/lib/ExpressionNamer.h b/tests/auto/xmlpatternsxqts/lib/ExpressionNamer.h
new file mode 100644
index 0000000..1fb44d3
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/ExpressionNamer.h
@@ -0,0 +1,322 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_ExpressionNamer_H
+#define PatternistSDK_ExpressionNamer_H
+
+#include "Global.h"
+#include "qexpressiondispatch_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ /**
+ * @short Extracts debug information from a QPatternist::Expression tree.
+ *
+ * This data is the name of the AST node(typically the class name),
+ * and additional data such as the value, type of operator, and so forth. The result
+ * is returned(from visit()), is an ExpressionInfo instance.
+ *
+ * @see ExpressionInfo
+ * @see ASTItem
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT ExpressionNamer : public QPatternist::ExpressionVisitor
+ {
+ public:
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::AndExpression *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ApplyTemplate *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ArgumentReference *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ArithmeticExpression *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::Atomizer *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::AttributeConstructor *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::AttributeNameValidator *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::CallTemplate *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::CardinalityVerifier *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::CastAs *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::CastableAs *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::CollationChecker *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::CombineNodes *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ComputedNamespaceConstructor *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::CommentConstructor *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ContextItem *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::CopyOf *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::CurrentItemStore *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::DocumentConstructor *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::DynamicContextStore *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::EBVExtractor *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ElementConstructor *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::EmptySequence *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ExpressionSequence *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ExpressionVariableReference *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ExternalVariableReference *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::EvaluationCache<true> *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::EvaluationCache<false> *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::FirstItemPredicate *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ForClause *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::FunctionCall *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::GeneralComparison *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::GenericPredicate *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::IfThenClause *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::InstanceOf *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ItemVerifier *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::LetClause *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::Literal *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::LiteralSequence *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::NCNameConstructor *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::NodeComparison *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::NodeSortExpression *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::OrderBy *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::OrExpression *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ParentNodeAxis *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::Path *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::PositionalVariableReference *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ProcessingInstructionConstructor *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::QNameConstructor *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::QuantifiedExpression *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::RangeExpression *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::RangeVariableReference *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ReturnOrderBy *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::SimpleContentConstructor *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::StaticBaseURIStore *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::StaticCompatibilityStore *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::AxisStep *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::TemplateParameterReference *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::TextNodeConstructor *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::TreatAs *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::TruthPredicate *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::UntypedAtomicConverter *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::UnresolvedVariableReference *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ArgumentConverter *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::UserFunctionCallsite *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ValidationError *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::ValueComparison *) const;
+
+ virtual QPatternist::ExpressionVisitorResult::Ptr
+ visit(const QPatternist::NamespaceConstructor *) const;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.cpp b/tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.cpp
new file mode 100644
index 0000000..5d62889
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.cpp
@@ -0,0 +1,181 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QCoreApplication>
+#include <QFile>
+#include <QtDebug>
+#include <QXmlResultItems>
+#include <QXmlNamePool>
+
+#include "Global.h"
+
+#include "qcommonsequencetypes_p.h"
+#include "qdebug_p.h"
+#include "qatomicstring_p.h"
+
+#include "ExternalSourceLoader.h"
+
+using namespace QPatternistSDK;
+using namespace QPatternist;
+
+ExternalSourceLoader::ExternalSourceLoader(const VariableMap &varMap,
+ const QPatternist::ResourceLoader::Ptr &r) : m_variableMap(varMap)
+ , m_resourceLoader(r)
+ , m_query(Global::namePoolAsPublic())
+{
+ Q_ASSERT(m_resourceLoader);
+}
+
+QPatternist::SequenceType::Ptr
+ExternalSourceLoader::announceExternalVariable(const QXmlName name,
+ const QPatternist::SequenceType::Ptr &declaredType)
+{
+ pDebug() << "ExternalSourceLoader::announceExternalVariable()";
+ Q_ASSERT(!name.isNull());
+ Q_ASSERT(declaredType);
+ Q_UNUSED(declaredType); /* Needed when bulding in release mode. */
+
+ if(name.namespaceURI() == QPatternist::StandardNamespaces::empty)
+ {
+ const VariableValue variable(m_variableMap.value(Global::namePool()->stringForLocalName(name.localName())));
+
+ if(variable.first.isEmpty())
+ return QPatternist::SequenceType::Ptr();
+ else
+ {
+ /* If announceDocument() can't load a document for uriForVar, it will return
+ * null, which we will too, which is fine, since we can't supply a value for
+ * this variable then. */
+ if(variable.second == Document)
+ return m_resourceLoader->announceDocument(variable.first, QPatternist::ResourceLoader::WillUse);
+ else if(variable.second == URI)
+ {
+ return QPatternist::CommonSequenceTypes::ExactlyOneString;
+ }
+ else
+ {
+ /* The type is Query, and we don't pre-load
+ * them. No particular reason, just not worth it. */
+ return QPatternist::CommonSequenceTypes::ZeroOrMoreItems;
+ }
+ }
+ }
+ else
+ return QPatternist::SequenceType::Ptr();
+}
+
+QPatternist::Item
+ExternalSourceLoader::evaluateSingleton(const QXmlName name,
+ const QPatternist::DynamicContext::Ptr &context)
+{
+ Q_ASSERT(!name.isNull());
+ const VariableValue variable(m_variableMap.value(Global::namePool()->stringForLocalName(name.localName())));
+
+ if(variable.second == Document)
+ {
+ Q_ASSERT_X(QFile::exists(variable.first.toLocalFile()), Q_FUNC_INFO,
+ qPrintable(QString::fromLatin1("The file %1 doesn't exist").arg(variable.first.toLocalFile())));
+ Q_ASSERT_X(m_resourceLoader->openDocument(variable.first, context), Q_FUNC_INFO,
+ "We're supposed to have the value. If not, an error should have been issued at query compile time.");
+
+ return m_resourceLoader->openDocument(variable.first, context);
+ }
+ else if(variable.second == Query)
+ {
+ /* Well, here we open the file and execute it. */
+ m_query.setQuery(QUrl::fromLocalFile(variable.first.toLocalFile()));
+ Q_ASSERT(m_query.isValid());
+
+ QXmlResultItems result;
+ m_query.evaluateTo(&result);
+
+ return QPatternist::Item::fromPublic(result.next());
+ }
+ else
+ {
+ Q_ASSERT(variable.second == URI);
+ return QPatternist::AtomicString::fromValue(variable.first.toString());
+ }
+}
+
+// vim: et:ts=4:sw=4:sts=4
+
diff --git a/tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.h b/tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.h
new file mode 100644
index 0000000..802f5b4
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.h
@@ -0,0 +1,178 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_ExternalSourceLoader_H
+#define PatternistSDK_ExternalSourceLoader_H
+
+#include <QHash>
+#include <QUrl>
+#include <QXmlQuery>
+
+#include "qdynamiccontext_p.h"
+#include "qresourceloader_p.h"
+#include "qexternalvariableloader_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ /**
+ * @short Handles external variables in XQTS queries, such as <tt>$input-context</tt>,
+ * by loading appropriate XML source files.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT ExternalSourceLoader : public QPatternist::ExternalVariableLoader
+ {
+ public:
+ enum TargetOfURI
+ {
+ /**
+ * Identifies @c input-file.
+ */
+ Document,
+
+ /**
+ * Identifies @c input-URI.
+ */
+ URI,
+
+ /**
+ * Identifies @c input-query.
+ */
+ Query
+ };
+
+ /**
+ * The first is the complete, absolute, final URI to the file to be loaded,
+ * and the second is the type of source found at that URI.
+ */
+ typedef QPair<QUrl, TargetOfURI> VariableValue;
+
+ /**
+ * In the XQTSCatalog.xml each source file in each test is referred to
+ * by a key, which can be fully looked up in the @c sources element. This QHash
+ * maps the keys to absolute URIs pointing to the source file.
+ */
+ typedef QHash<QString, QUrl> SourceMap;
+
+ /**
+ * The first value is the variable name, and the second is the URI identifying
+ * the XML source file that's supposed to be loaded as a document.
+ *
+ * This is one for every test case, except for @c rdb-queries-results-q5,
+ * @c rdb-queries-results-q17 and @c rdb-queries-results-q18(at least in XQTS 1.0).
+ */
+ typedef QHash<QString, VariableValue> VariableMap;
+
+ ExternalSourceLoader(const VariableMap &varMap,
+ const QPatternist::ResourceLoader::Ptr &resourceLoader);
+
+ virtual QPatternist::SequenceType::Ptr
+ announceExternalVariable(const QXmlName name,
+ const QPatternist::SequenceType::Ptr &declaredType);
+
+ virtual QPatternist::Item
+ evaluateSingleton(const QXmlName name,
+ const QPatternist::DynamicContext::Ptr &context);
+
+ VariableMap variableMap() const
+ {
+ return m_variableMap;
+ }
+
+ private:
+ const VariableMap m_variableMap;
+ const QPatternist::ResourceLoader::Ptr m_resourceLoader;
+ QXmlQuery m_query;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/Global.cpp b/tests/auto/xmlpatternsxqts/lib/Global.cpp
new file mode 100644
index 0000000..b5aa189
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/Global.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QXmlNamePool>
+
+#include "Global.h"
+
+using namespace QPatternistSDK;
+
+const QString Global::xqtsCatalogNS (QLatin1String("http://www.w3.org/2005/02/query-test-XQTSCatalog"));
+const QString Global::xqtsResultNS (QLatin1String("http://www.w3.org/2005/02/query-test-XQTSResult"));
+const QString Global::xsltsCatalogNS (QLatin1String("http://www.w3.org/2005/05/xslt20-test-catalog"));
+const QString Global::organizationName (QLatin1String("Patternist Team"));
+const qint16 Global::versionNumber (0x01);
+
+static QXmlNamePool s_namePool;
+
+QPatternist::NamePool::Ptr Global::namePool()
+{
+ return s_namePool.d;
+}
+
+QXmlNamePool Global::namePoolAsPublic()
+{
+ return s_namePool;
+}
+
+bool Global::readBoolean(const QString &value)
+{
+ const QString normd(value.simplified());
+
+ if(normd == QLatin1String("true") ||
+ normd == QLatin1String("1"))
+ return true;
+ else if(normd.isEmpty() ||
+ normd == QLatin1String("false") ||
+ normd == QLatin1String("0"))
+ return false;
+
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "The lexical representation of xs:boolean was invalid");
+ return false;
+}
+
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/Global.h b/tests/auto/xmlpatternsxqts/lib/Global.h
new file mode 100644
index 0000000..640ca32
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/Global.h
@@ -0,0 +1,169 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_Global_H
+#define PatternistSDK_Global_H
+
+#include <QString>
+
+#include "private/qitem_p.h"
+#include "private/qnamepool_p.h"
+
+#ifdef Q_WS_WIN
+# ifdef Q_PATTERNISTSDK_BUILDING
+ #define Q_PATTERNISTSDK_EXPORT __declspec(dllexport)
+ #else
+ #define Q_PATTERNISTSDK_EXPORT __declspec(dllimport)
+ #endif
+#else
+ #define Q_PATTERNISTSDK_EXPORT
+#endif
+
+/**
+ * @short Contains testing utilities for Patternist, interfacing W3C's XQuery Test Suite.
+ *
+ * @see <a href="http://www.w3.org/XML/Query/test-suite/">XML Query Test Suite</a>
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ /**
+ * @short Contains global constants.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT Global
+ {
+ public:
+
+ /**
+ * The namespace which the XQTS test case catalog(specified by Catalog.xsd)
+ * is in. The namespace is: <tt>http://www.w3.org/2005/02/query-test-XQTSCatalog</tt>
+ */
+ static const QString xqtsCatalogNS;
+
+ /**
+ * The namespace which the XQTS test results collection(specified by XQTSResult.xsd)
+ * is in. The namespace is: <tt>http://www.w3.org/2005/02/query-test-XQTSResult</tt>
+ */
+ static const QString xqtsResultNS;
+
+ /**
+ * The organization which created PatternistSDK. It say something
+ * in the direction of "Patternist Team", and is used for QSettings and the like.
+ */
+ static const QString organizationName;
+
+ /**
+ * The namespace which W3C's XSL-T test suite resides in.
+ */
+ static const QString xsltsCatalogNS;
+
+ /**
+ * The version of PatternistSDK. The value has currently no other
+ * meaning than that larger means older. This version information is supplied to
+ * QMainWindow::restoreState() and QMainWindow::saveState().
+ */
+ static const qint16 versionNumber;
+
+ /**
+ * Parses the lexical space of @c xs:boolean,
+ * with the exception that the empty string is considered @c false.
+ */
+ static bool readBoolean(const QString &lexicalSpace);
+
+ static QPatternist::NamePool::Ptr namePool();
+ static QXmlNamePool namePoolAsPublic();
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/ResultThreader.cpp b/tests/auto/xmlpatternsxqts/lib/ResultThreader.cpp
new file mode 100644
index 0000000..44dc8a2
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/ResultThreader.cpp
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QEventLoop>
+
+#include "ResultThreader.h"
+
+using namespace QPatternistSDK;
+
+ResultThreader::ResultThreader(QEventLoop &ev,
+ QFile *file,
+ const Type t,
+ QObject *p) : QThread(p)
+ , m_file(file)
+ , m_type(t)
+ , m_eventLoop(ev)
+{
+ Q_ASSERT_X(p, Q_FUNC_INFO, "Should have a parent");
+ Q_ASSERT_X(file, Q_FUNC_INFO, "Should have a valid file");
+ Q_ASSERT(m_type == Baseline || m_type == Result);
+}
+
+void ResultThreader::run()
+{
+ QXmlSimpleReader reader;
+ reader.setContentHandler(this);
+
+ QXmlInputSource source(m_file);
+ reader.parse(source);
+ m_file->close();
+}
+
+ResultThreader::Type ResultThreader::type() const
+{
+ return m_type;
+}
+
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/ResultThreader.h b/tests/auto/xmlpatternsxqts/lib/ResultThreader.h
new file mode 100644
index 0000000..8c511a8
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/ResultThreader.h
@@ -0,0 +1,151 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_ResultThreader_H
+#define PatternistSDK_ResultThreader_H
+
+#include <QFile>
+#include <QFileInfo>
+#include <QThread>
+
+#include "TestResultHandler.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QEventLoop;
+
+namespace QPatternistSDK
+{
+ /**
+ * @short Reads XML in the @c XQTSResult.xsd format, as a thread, allowing
+ * multiple parses to be done simultaneously.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup PatternistSDK
+ */
+ class Q_PATTERNISTSDK_EXPORT ResultThreader : public QThread
+ , public TestResultHandler
+ {
+ public:
+ enum Type
+ {
+ Baseline = 1,
+ Result
+ };
+
+ /**
+ * Creates a ResultThreader that will read @p file when run() is called.
+ */
+ ResultThreader(QEventLoop &ev,
+ QFile *file,
+ const Type type,
+ QObject *parent);
+
+ /**
+ * Parses the file passed in this class's constructor with this ResultHandlerTH::Item::LisT
+ * as the QXmlContentHandler, and returns.
+ */
+ virtual void run();
+
+ /**
+ * @note Do not reimplement this function.
+ * @returns whether this ResultThreader handles the baseline or the result.
+ */
+ Type type() const;
+
+ private:
+ Q_DISABLE_COPY(ResultThreader)
+
+ QFile *const m_file;
+ const Type m_type;
+ QEventLoop & m_eventLoop;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TestBaseLine.cpp b/tests/auto/xmlpatternsxqts/lib/TestBaseLine.cpp
new file mode 100644
index 0000000..b699ead
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestBaseLine.cpp
@@ -0,0 +1,545 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QDomDocument>
+#include <QFile>
+#include <QFileInfo>
+#include <QRegExp>
+#include <QtDebug>
+#include <QUrl>
+#include <QXmlAttributes>
+#include <QXmlSimpleReader>
+
+#include "qdebug_p.h"
+#include "XMLWriter.h"
+
+#include "TestBaseLine.h"
+
+using namespace QPatternistSDK;
+using namespace QPatternist;
+
+Q_GLOBAL_STATIC_WITH_ARGS(QRegExp, errorRegExp, (QLatin1String("[A-Z]{4}[0-9]{4}")))
+
+TestBaseLine::TestBaseLine(const Type t) : m_type(t)
+{
+ Q_ASSERT(errorRegExp()->isValid());
+}
+
+TestResult::Status TestBaseLine::scan(const QString &serialized,
+ const TestBaseLine::List &lines)
+{
+ Q_ASSERT_X(lines.count() >= 1, Q_FUNC_INFO,
+ "At least one base line must be passed, otherwise there's nothing "
+ "to compare to.");
+
+ const TestBaseLine::List::const_iterator end(lines.constEnd());
+ TestBaseLine::List::const_iterator it(lines.constBegin());
+ for(; it != end; ++it)
+ {
+ const TestResult::Status retval((*it)->verify(serialized));
+
+ if(retval == TestResult::Pass || retval == TestResult::NotTested)
+ return retval;
+ }
+
+ return TestResult::Fail;
+}
+
+TestResult::Status TestBaseLine::scanErrors(const ErrorHandler::Message::List &errors,
+ const TestBaseLine::List &lines)
+{
+ pDebug() << "TestBaseLine::scanErrors()";
+
+ /* 1. Find the first error in @p errors that's a Patternist
+ * error(not warning and not from Qt) and extract the error code. */
+ QString errorCode;
+
+ const ErrorHandler::Message::List::const_iterator end(errors.constEnd());
+ ErrorHandler::Message::List::const_iterator it(errors.constBegin());
+ for(; it != end; ++it)
+ {
+ if((*it).type() != QtFatalMsg)
+ continue;
+
+ errorCode = QUrl((*it).identifier()).fragment();
+
+ pDebug() << "ERR:" << (*it).description();
+ /* This is hackish. We have no way of determining whether a Message
+ * is actually issued from Patternist, so we try to narrow it down like this. */
+ if(errorRegExp()->exactMatch(errorCode))
+ break; /* It's an error code. */
+ else
+ errorCode.clear();
+ }
+
+ pDebug() << "Got error code: " << errorCode;
+ /* 2. Loop through @p lines, and for the first base line
+ * which is of type ExpectedError and which matches @p errorCode
+ * return Pass, otherwise Fail. */
+ const TestBaseLine::List::const_iterator blend(lines.constEnd());
+ TestBaseLine::List::const_iterator blit(lines.constBegin());
+ for(; blit != blend; ++blit)
+ {
+ const Type t = (*blit)->type();
+
+ if(t == TestBaseLine::ExpectedError)
+ {
+ const QString d((*blit)->details());
+ if(d == errorCode || d == QChar::fromLatin1('*'))
+ return TestResult::Pass;
+ }
+ }
+
+ return TestResult::Fail;
+}
+
+void TestBaseLine::toXML(XMLWriter &receiver) const
+{
+ switch(m_type)
+ {
+ case XML: /* Fallthrough. */
+ case Fragment: /* Fallthrough. */
+ case Text:
+ {
+ QXmlAttributes inspectAtts;
+ inspectAtts.append(QLatin1String("role"), QString(),
+ QLatin1String("role"), QLatin1String("principal"));
+ inspectAtts.append(QLatin1String("compare"), QString(),
+ QLatin1String("compare"), displayName(m_type));
+ receiver.startElement(QLatin1String("output-file"), inspectAtts);
+ receiver.characters(m_details);
+ receiver.endElement(QLatin1String("output-file"));
+ return;
+ }
+ case Ignore:
+ {
+ Q_ASSERT_X(false, Q_FUNC_INFO, "Serializing 'Ignore' is not implemented.");
+ return;
+ }
+ case Inspect:
+ {
+ QXmlAttributes inspectAtts;
+ inspectAtts.append(QLatin1String("role"), QString(),
+ QLatin1String("role"), QLatin1String("principal"));
+ inspectAtts.append(QLatin1String("compare"), QString(),
+ QLatin1String("compare"), QLatin1String("Inspect"));
+ receiver.startElement(QLatin1String("output-file"), inspectAtts);
+ receiver.characters(m_details);
+ receiver.endElement(QLatin1String("output-file"));
+ return;
+ }
+ case ExpectedError:
+ {
+ receiver.startElement(QLatin1String("expected-error"));
+ receiver.characters(m_details);
+ receiver.endElement(QLatin1String("expected-error"));
+ return;
+ }
+ }
+}
+
+bool TestBaseLine::isChildrenDeepEqual(const QDomNodeList &cl1, const QDomNodeList &cl2)
+{
+ const unsigned int len = cl1.length();
+
+ if(len == cl2.length())
+ {
+ for(unsigned int i = 0; i < len; ++i)
+ {
+ if(!isDeepEqual(cl1.at(i), cl2.at(i)))
+ return false;
+ }
+
+ return true;
+ }
+ else
+ return false;
+}
+
+bool TestBaseLine::isAttributesEqual(const QDomNamedNodeMap &cl1, const QDomNamedNodeMap &cl2)
+{
+ const unsigned int len = cl1.length();
+ pDebug() << "LEN:" << len;
+
+ if(len == cl2.length())
+ {
+ for(unsigned int i1 = 0; i1 < len; ++i1)
+ {
+ const QDomNode attr1(cl1.item(i1));
+ Q_ASSERT(!attr1.isNull());
+
+ /* This is set if attr1 cannot be found at all in cl2. */
+ bool earlyExit = false;
+
+ for(unsigned int i2 = 0; i2 < len; ++i2)
+ {
+ const QDomNode attr2(cl2.item(i2));
+ Q_ASSERT(!attr2.isNull());
+ pDebug() << "ATTR1:" << attr1.localName() << attr1.namespaceURI() << attr1.prefix() << attr1.nodeName();
+ pDebug() << "ATTR2:" << attr2.localName() << attr2.namespaceURI() << attr2.prefix() << attr2.nodeName();
+
+ if(attr1.localName() == attr2.localName() &&
+ attr1.namespaceURI() == attr2.namespaceURI() &&
+ attr1.prefix() == attr2.prefix() &&
+ attr1.nodeName() == attr2.nodeName() && /* Yes, needed in addition to all the other. */
+ attr1.nodeValue() == attr2.nodeValue())
+ {
+ earlyExit = true;
+ break;
+ }
+ }
+
+ if(!earlyExit)
+ {
+ /* An attribute was found that doesn't exist in the other list so exit. */
+ return false;
+ }
+ }
+
+ return true;
+ }
+ else
+ return false;
+}
+
+bool TestBaseLine::isDeepEqual(const QDomNode &n1, const QDomNode &n2)
+{
+ if(n1.nodeType() != n2.nodeType())
+ return false;
+
+ switch(n1.nodeType())
+ {
+ case QDomNode::CommentNode:
+ /* Fallthrough. */
+ case QDomNode::TextNode:
+ {
+ return static_cast<const QDomCharacterData &>(n1).data() ==
+ static_cast<const QDomCharacterData &>(n2).data();
+ }
+ case QDomNode::ProcessingInstructionNode:
+ {
+ return n1.nodeName() == n2.nodeName() &&
+ n1.nodeValue() == n2.nodeValue();
+ }
+ case QDomNode::DocumentNode:
+ return isChildrenDeepEqual(n1.childNodes(), n2.childNodes());
+ case QDomNode::ElementNode:
+ {
+ return n1.localName() == n2.localName() &&
+ n1.namespaceURI() == n2.namespaceURI() &&
+ n1.nodeName() == n2.nodeName() && /* Yes, this one is needed in addition to localName(). */
+ isAttributesEqual(n1.attributes(), n2.attributes()) &&
+ isChildrenDeepEqual(n1.childNodes(), n2.childNodes());
+ }
+ /* Fallthrough all these. */
+ case QDomNode::EntityReferenceNode:
+ case QDomNode::CDATASectionNode:
+ case QDomNode::EntityNode:
+ case QDomNode::DocumentTypeNode:
+ case QDomNode::DocumentFragmentNode:
+ case QDomNode::NotationNode:
+ case QDomNode::BaseNode:
+ case QDomNode::CharacterDataNode:
+ {
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "An unsupported node type was encountered.");
+ return false;
+ }
+ case QDomNode::AttributeNode:
+ {
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ "This should never happen. QDom doesn't allow us to compare DOM attributes "
+ "properly.");
+ return false;
+ }
+ default:
+ {
+ Q_ASSERT_X(false, Q_FUNC_INFO, "Unhandled QDom::NodeType value.");
+ return false;
+ }
+ }
+}
+
+TestResult::Status TestBaseLine::verify(const QString &serializedInput) const
+{
+ switch(m_type)
+ {
+ case Text:
+ {
+ if(serializedInput == details())
+ return TestResult::Pass;
+ else
+ return TestResult::Fail;
+ }
+ case Fragment:
+ /* Fall through. */
+ case XML:
+ {
+ /* Read the baseline and the serialized input into two QDomDocuments, and compare
+ * them deeply. We wrap fragments in a root node such that it is well-formed XML.
+ */
+
+ QDomDocument output;
+ {
+ /* The reason we put things into a QByteArray and then parse it through QXmlSimpleReader, is that
+ * QDomDocument does whitespace stripping when calling setContent(QString). In other words,
+ * this workarounds a bug. */
+
+ QXmlInputSource source;
+ source.setData((m_type == XML ? serializedInput : QLatin1String("<r>") +
+ serializedInput +
+ QLatin1String("</r>")).toUtf8());
+
+ QString outputReadingError;
+
+ QXmlSimpleReader reader;
+ reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true);
+
+ const bool success = output.setContent(&source,
+ &reader,
+ &outputReadingError);
+
+ if(!success)
+ return TestResult::Fail;
+
+ Q_ASSERT(success);
+ }
+
+ QDomDocument baseline;
+ {
+ QXmlInputSource source;
+ source.setData((m_type == XML ? details() : QLatin1String("<r>") +
+ details() +
+ QLatin1String("</r>")).toUtf8());
+ QString baselineReadingError;
+
+ QXmlSimpleReader reader;
+ reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true);
+
+ const bool success = baseline.setContent(&source,
+ &reader,
+ &baselineReadingError);
+
+ if(!success)
+ return TestResult::Fail;
+
+ /* This piece of code workaround a bug in QDom, which treats XML prologs as processing
+ * instructions and make them available in the tree as so. */
+ if(m_type == XML)
+ {
+ /* $doc/r/node() */
+ const QDomNodeList children(baseline.childNodes());
+ const int len = children.length();
+
+ for(int i = 0; i < len; ++i)
+ {
+ const QDomNode &child = children.at(i);
+ if(child.isProcessingInstruction() && child.nodeName() == QLatin1String("xml"))
+ {
+ baseline.removeChild(child);
+ break;
+ }
+ }
+ }
+
+ Q_ASSERT_X(baselineReadingError.isNull(), Q_FUNC_INFO,
+ qPrintable((QLatin1String("Reading the baseline failed: ") + baselineReadingError)));
+ }
+
+ if(isDeepEqual(output, baseline))
+ return TestResult::Pass;
+ else
+ {
+ pDebug() << "FAILURE:" << output.toString() << "is NOT IDENTICAL to(baseline):" << baseline.toString();
+ return TestResult::Fail;
+ }
+ }
+ case Ignore:
+ return TestResult::Pass;
+ case Inspect:
+ return TestResult::NotTested;
+ case ExpectedError:
+ {
+ /* This function is only called for Text/XML/Fragment tests. */
+ return TestResult::Fail;
+ }
+ }
+ Q_ASSERT(false);
+ return TestResult::Fail;
+}
+
+TestBaseLine::Type TestBaseLine::identifierFromString(const QString &string)
+{
+ /* "html-output: Using an ad hoc tool, it must assert that the document obeys the HTML
+ * Output Method as defined in the Serialization specification and section
+ * 20 of the XSLT 2.0 specification." We treat it as XML for now, same with
+ * xhtml-output. */
+ if(string.compare(QLatin1String("XML"), Qt::CaseInsensitive) == 0 ||
+ string == QLatin1String("html-output") ||
+ string == QLatin1String("xml-output") ||
+ string == QLatin1String("xhtml-output"))
+ return XML;
+ else if(string == QLatin1String("Fragment") || string == QLatin1String("xml-frag"))
+ return Fragment;
+ else if(string.compare(QLatin1String("Text"), Qt::CaseInsensitive) == 0)
+ return Text;
+ else if(string == QLatin1String("Ignore"))
+ return Ignore;
+ else if(string.compare(QLatin1String("Inspect"), Qt::CaseInsensitive) == 0)
+ return Inspect;
+ else
+ {
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ qPrintable(QString::fromLatin1("Invalid string representation for a comparation type: %1").arg(string)));
+
+ return Ignore; /* Silence GCC. */
+ }
+}
+
+QString TestBaseLine::displayName(const Type id)
+{
+ switch(id)
+ {
+ case XML:
+ return QLatin1String("XML");
+ case Fragment:
+ return QLatin1String("Fragment");
+ case Text:
+ return QLatin1String("Text");
+ case Ignore:
+ return QLatin1String("Ignore");
+ case Inspect:
+ return QLatin1String("Inspect");
+ case ExpectedError:
+ return QLatin1String("ExpectedError");
+ }
+
+ Q_ASSERT(false);
+ return QString();
+}
+
+QString TestBaseLine::details() const
+{
+ if(m_type == Ignore) /* We're an error code. */
+ return QString();
+ if(m_type == ExpectedError) /* We're an error code. */
+ return m_details;
+
+ if(m_details.isEmpty())
+ return m_details;
+
+ /* m_details is a file name, we open it and return the result. */
+ QFile file(QUrl(m_details).toLocalFile());
+
+ QString retval;
+ if(!file.exists())
+ retval = QString::fromLatin1("%1 does not exist.").arg(file.fileName());
+ else if(!QFileInfo(file.fileName()).isFile())
+ retval = QString::fromLatin1("%1 is not a file, cannot display it.").arg(file.fileName());
+ else if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ retval = QString::fromLatin1("Could not open %1. Likely a permission error.").arg(file.fileName());
+
+ if(retval.isNull())
+ {
+ /* Scary, we assume the query/baseline is in UTF-8. */
+ return QString::fromUtf8(file.readAll());
+ }
+ else
+ {
+ /* We had a file error. */
+ retval.prepend(QLatin1String("Test-suite harness error: "));
+ qCritical() << retval;
+ return retval;
+ }
+}
+
+TestBaseLine::Type TestBaseLine::type() const
+{
+ return m_type;
+}
+
+void TestBaseLine::setDetails(const QString &detailsP)
+{
+ m_details = detailsP;
+}
+
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TestBaseLine.h b/tests/auto/xmlpatternsxqts/lib/TestBaseLine.h
new file mode 100644
index 0000000..577c4b1
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestBaseLine.h
@@ -0,0 +1,246 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_TestBaseLine_H
+#define PatternistSDK_TestBaseLine_H
+
+#include <QString>
+
+#include "Global.h"
+#include "TestResult.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QDomNamedNodeMap;
+class QDomNode;
+class QDomNodeList;
+template<typename T> class QList;
+
+namespace QPatternistSDK
+{
+ /**
+ * @short Represents an expected test result for a test case.
+ *
+ * TestBaseLine represents a valid outcome for a test case,
+ * the "base line". A XQTS test case can have many different valid
+ * base lines, and one TestBaseLine instance represents on of them.
+ *
+ * Of highest interest, TestBaseLine have the function scan() and
+ * scanErrors(), which allows serialized output to be
+ * compared to the base line.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT TestBaseLine
+ {
+ public:
+ typedef QList<TestBaseLine *> List;
+
+ /**
+ * Identifies what kind of comparator to use. The documentation
+ * for each enumerator is copied from
+ * <a href="http://www.w3.org/XML/Query/test-suite/Guidelines
+ * for Running the XML Query Test Suite.html">Guidelines
+ * for Running the XML Query Test Suite</a>
+ */
+ enum Type
+ {
+ /**
+ * The test harness must canonicalize both, the actual result
+ * and the expected result according to the "Canonical XML" recommendation [2],
+ * which refers to a number of open-source implementations. Byte-comparison can
+ * then be applied to the resulting XML documents. If the test harness does
+ * this process in a different manner, it must be documented.
+ */
+ XML,
+
+ /**
+ * For XML fragments, the same root node must be created for both,
+ * implementation result and test suite result. The resulting XML
+ * can be compared using XML comparison.
+ */
+ Fragment,
+
+ /**
+ * Text (that has been produced by XML serialization) is compared
+ * using byte-comparison.
+ */
+ Text,
+
+ /**
+ * No comparison needs to be applied; the result is always @c true if
+ * the implementation successfully executes the test case.
+ */
+ Ignore,
+
+ /**
+ * A human is required to make the call about correctness of the result
+ * according to the description in the test case.
+ */
+ Inspect,
+
+ /**
+ * The expected result of the test case is an error, identified as an
+ * eight-character error code (e.g., XPST0003). The result of a test is
+ * @c true, if the implementation raises an error. However, raising an error
+ * because an implementation does not support the feature is not
+ * considered a correct result.
+ */
+ ExpectedError
+ };
+
+ /**
+ * Takes a string identifying a comparator either in the XSL-T or the
+ * XQuery test suite, and returns an enum value for it.
+ *
+ * If the value is unknown, the code asserts.
+ */
+ static Type identifierFromString(const QString &string);
+
+ /**
+ * @returns a display name for @p id. For example, if Inspect was passed, "Inspect"
+ * would be returned.
+ */
+ static QString displayName(const Type id);
+
+ /**
+ * Compares @p items(typically the result of an evaluation) against
+ * the base lines @p lines.
+ *
+ * @returns the status of the first base line which passes,
+ * otherwise TestResult::Fail.
+ */
+ static TestResult::Status scan(const QString &serialized,
+ const TestBaseLine::List &lines);
+
+ static TestResult::Status scanErrors(const ErrorHandler::Message::List &errors,
+ const TestBaseLine::List &lines);
+
+ /**
+ * Constructs a TestBaseLine of type @p type.
+ */
+ TestBaseLine(const Type type);
+
+ /**
+ * What @p details contains depends on the type(). If the type() is ExpectedError,
+ * @p details contains the relevant error code. If the type() is one which compares
+ * result against a base line, it is a filename locating the baseline.
+ */
+ void setDetails(const QString &details);
+
+ Type type() const;
+
+ QString details() const;
+
+ void toXML(XMLWriter &receiver) const;
+
+ protected:
+ TestResult::Status verify(const QString &serializedInput) const;
+
+ private:
+ static bool isDeepEqual(const QDomNode &n1, const QDomNode &n2);
+
+ /**
+ * @returns @c true if the nodes in @p cl1 are equal to @p cl2, by calling isDeepEqual()
+ * for each pair.
+ */
+ static bool isChildrenDeepEqual(const QDomNodeList &cl1, const QDomNodeList &cl2);
+
+ /**
+ * Considers @p cl1 and @p cl2 to be lists containing attributes. The list are equal
+ * if they contain attributes by same value and name, but regardless of order.
+ */
+ static bool isAttributesEqual(const QDomNamedNodeMap &cl1, const QDomNamedNodeMap &cl2);
+ const Type m_type;
+ QString m_details;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TestCase.cpp b/tests/auto/xmlpatternsxqts/lib/TestCase.cpp
new file mode 100644
index 0000000..0dc23dd
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestCase.cpp
@@ -0,0 +1,480 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QBuffer>
+#include <QUrl>
+#include <QXmlAttributes>
+#include <QXmlQuery>
+#include <QXmlResultItems>
+#include <QXmlSerializer>
+#include <qxmlquery_p.h>
+
+#include "DebugExpressionFactory.h"
+#include "ExternalSourceLoader.h"
+#include "Global.h"
+#include "TestSuite.h"
+#include "XMLWriter.h"
+
+#include "TestCase.h"
+
+using namespace QPatternistSDK;
+using namespace QPatternist;
+
+// STATIC DATA
+static const DebugExpressionFactory::Ptr s_exprFact(new DebugExpressionFactory());
+
+TestCase::TestCase() : m_result(0)
+{
+}
+
+TestCase::~TestCase()
+{
+ delete m_result;
+}
+
+TestResult::List TestCase::execute(const ExecutionStage stage,
+ TestSuite *)
+{
+ if(name() == QLatin1String("Constr-cont-document-3"))
+ {
+ TestResult::List result;
+ result.append(createTestResult(TestResult::Fail, QLatin1String("Skipped this test, because we loop infinitely on it.")));
+ return result;
+ }
+ else if(name() == QLatin1String("Axes089"))
+ {
+ TestResult::List result;
+ result.append(createTestResult(TestResult::Fail, QLatin1String("Skipped this test, we crash on it.")));
+ return result;
+ }
+
+ qDebug() << "Running test case: " << name();
+
+ return execute(stage);
+
+ Q_ASSERT(false);
+ return TestResult::List();
+}
+
+TestResult *TestCase::createTestResult(const TestResult::Status status,
+ const QString &comment) const
+{
+ TestResult *const result = new TestResult(name(),
+ status,
+ 0 /* We don't have an AST. */,
+ ErrorHandler::Message::List(),
+ QPatternist::Item::List(),
+ QString());
+ result->setComment(comment);
+ return result;
+}
+
+TestResult::List TestCase::execute(const ExecutionStage stage)
+{
+ ErrorHandler errHandler;
+ ErrorHandler::installQtMessageHandler(&errHandler);
+
+ pDebug() << "TestCase::execute()";
+ delete m_result;
+
+ QXmlQuery query(language(), Global::namePoolAsPublic());
+
+ query.d->setExpressionFactory(s_exprFact);
+ query.setInitialTemplateName(initialTemplateName());
+
+ QXmlQuery openDoc(query.namePool());
+
+ if(contextItemSource().isValid())
+ {
+ openDoc.setQuery(QString::fromLatin1("doc('") + contextItemSource().toString() + QLatin1String("')"));
+ Q_ASSERT(openDoc.isValid());
+ QXmlResultItems result;
+
+ openDoc.evaluateTo(&result);
+ const QXmlItem item(result.next());
+ Q_ASSERT(!item.isNull());
+ query.setFocus(item);
+ }
+
+ TestResult::List retval;
+
+ const Scenario scen(scenario());
+ TestResult::Status resultStatus = TestResult::Unknown;
+
+ bool ok = false;
+ const QString queryString(sourceCode(ok));
+
+ if(!ok)
+ {
+ /* Loading the query file failed, or similar. */
+ resultStatus = TestResult::Fail;
+
+ m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(),
+ errHandler.messages(), QPatternist::Item::List(), QString());
+ retval.append(m_result);
+ ErrorHandler::installQtMessageHandler(0);
+ changed(this);
+ return retval;
+ }
+
+ query.setMessageHandler(&errHandler);
+ QXmlNamePool namePool(query.namePool());
+
+ /* Bind variables. */
+ QPatternist::ExternalVariableLoader::Ptr loader(externalVariableLoader());
+ if(loader)
+ {
+ Q_ASSERT(loader);
+ const ExternalSourceLoader::VariableMap vMap(static_cast<const ExternalSourceLoader *>(loader.data())->variableMap());
+ const QStringList variables(vMap.keys());
+
+ for(int i = 0; i < variables.count(); ++i)
+ {
+ const QXmlName name(namePool, variables.at(i));
+ const QXmlItem val(QPatternist::Item::toPublic(loader->evaluateSingleton(name, QPatternist::DynamicContext::Ptr())));
+ query.bindVariable(name, val);
+ }
+ }
+
+ /* We pass in the testCasePath(), such that the base URI is correct fort
+ * XSL-T stylesheets. */
+ query.setQuery(queryString, testCasePath());
+
+ if(!query.isValid())
+ {
+ pDebug() << "Got compilation exception.";
+ resultStatus = TestBaseLine::scanErrors(errHandler.messages(), baseLines());
+
+ Q_ASSERT(resultStatus != TestResult::Unknown);
+ m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(),
+ errHandler.messages(), QPatternist::Item::List(), QString());
+ retval.append(m_result);
+ ErrorHandler::installQtMessageHandler(0);
+ changed(this);
+ return retval;
+ }
+
+ if(stage == CompileOnly)
+ {
+ m_result = new TestResult(name(), TestResult::Fail, s_exprFact->astTree(),
+ errHandler.messages(), QPatternist::Item::List(), QString());
+ retval.append(m_result);
+ return retval;
+ }
+
+ Q_ASSERT(stage == CompileAndRun);
+
+ if(scen == ParseError) /* We're supposed to have received an error
+ at this point. */
+ {
+ m_result = new TestResult(name(), TestResult::Fail, s_exprFact->astTree(),
+ errHandler.messages(), QPatternist::Item::List(), QString());
+ ErrorHandler::installQtMessageHandler(0);
+ retval.append(m_result);
+ changed(this);
+ return retval;
+ }
+
+ QPatternist::Item::List itemList;
+
+ QByteArray output;
+ QBuffer buffer(&output);
+ buffer.open(QIODevice::WriteOnly);
+
+ QXmlSerializer serializer(query, &buffer);
+
+ pDebug() << "-------------------------- evaluateToPushCallback() ---------------------------- ";
+ const bool success = query.evaluateTo(&serializer);
+ pDebug() << "------------------------------------------------------------------------------------ ";
+
+ buffer.close();
+
+ const QString serialized(QString::fromUtf8(output.constData(), output.size()));
+
+ if(!success)
+ {
+ resultStatus = TestBaseLine::scanErrors(errHandler.messages(), baseLines());
+
+ Q_ASSERT(resultStatus != TestResult::Unknown);
+ m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(),
+ errHandler.messages(), QPatternist::Item::List(), serialized);
+ retval.append(m_result);
+ ErrorHandler::installQtMessageHandler(0);
+ changed(this);
+ return retval;
+ }
+
+ /* It's a regular test. */
+ Q_ASSERT(scen == Standard || scen == RuntimeError);
+
+ resultStatus = TestBaseLine::scan(serialized, baseLines());
+ Q_ASSERT(resultStatus != TestResult::Unknown);
+
+ /* Check that errHandler()->messages() at most only contains
+ * warnings, since it shouldn't have errors at this point. */
+ const ErrorHandler::Message::List errors (errHandler.messages());
+ const ErrorHandler::Message::List::const_iterator end(errors.constEnd());
+ ErrorHandler::Message::List::const_iterator it(errors.constBegin());
+
+ for(; it != end; ++it)
+ {
+ const QtMsgType type = (*it).type();
+ if(type == QtFatalMsg)
+ {
+ m_result = new TestResult(name(), TestResult::Fail, s_exprFact->astTree(),
+ errHandler.messages(), itemList, serialized);
+ retval.append(m_result);
+ ErrorHandler::installQtMessageHandler(0);
+ changed(this);
+ return retval;
+ }
+ }
+
+ m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(),
+ errHandler.messages(), itemList, serialized);
+ retval.append(m_result);
+ ErrorHandler::installQtMessageHandler(0);
+ changed(this);
+ return retval;
+}
+
+TestCase::Scenario TestCase::scenarioFromString(const QString &string)
+{
+ if(string == QLatin1String("standard"))
+ return Standard;
+ else if(string == QLatin1String("parse-error"))
+ return ParseError;
+ else if(string == QLatin1String("runtime-error"))
+ return RuntimeError;
+ else if(string == QLatin1String("trivial"))
+ return Trivial;
+ else
+ {
+ Q_ASSERT_X(false, Q_FUNC_INFO,
+ qPrintable(QString::fromLatin1("Invalid string representation for the scenario-enum: %1").arg(string)));
+ return ParseError; /* Silence GCC. */
+ }
+}
+
+void TestCase::toXML(XMLWriter &receiver) const
+{
+ /* <test-case> */
+ QXmlAttributes test_caseAtts;
+ test_caseAtts.append(QLatin1String("is-XPath2"), QString(),
+ QLatin1String("is-XPath2"), isXPath() ? QLatin1String("true")
+ : QLatin1String("false"));
+ test_caseAtts.append(QLatin1String("name"), QString(), QLatin1String("name"), name());
+ test_caseAtts.append(QLatin1String("creator"), QString(), QLatin1String("creator"), creator());
+ QString scen;
+ switch(scenario())
+ {
+ case Standard:
+ {
+ scen = QLatin1String("standard");
+ break;
+ }
+ case ParseError:
+ {
+ scen = QLatin1String("parse-error");
+ break;
+ }
+ case RuntimeError:
+ {
+ scen = QLatin1String("runtime-error");
+ break;
+ }
+ case Trivial:
+ {
+ scen = QLatin1String("trivial");
+ break;
+ }
+ default: /* includes 'AnyError' */
+ Q_ASSERT(false);
+ }
+ test_caseAtts.append(QLatin1String("scenario"), QString(), QLatin1String("scenario"), scen);
+ test_caseAtts.append(QLatin1String(QLatin1String("FilePath")), QString(),
+ QLatin1String("FilePath"), QString());
+ receiver.startElement(QLatin1String("test-case"), test_caseAtts);
+
+ /* <description> */
+ receiver.startElement(QLatin1String("description"), test_caseAtts);
+ receiver.characters(description());
+
+ /* </description> */
+ receiver.endElement(QLatin1String("description"));
+
+ /* <query> */
+ QXmlAttributes queryAtts;
+ queryAtts.append(QLatin1String("date"), QString(), QLatin1String("date"), /* This date is a dummy. */
+ QDate::currentDate().toString(Qt::ISODate));
+ queryAtts.append(QLatin1String("name"), QString(), QLatin1String("name"), testCasePath().toString());
+ receiver.startElement(QLatin1String("query"), queryAtts);
+
+ /* </query> */
+ receiver.endElement(QLatin1String("query"));
+
+ /* Note: this is invalid, we don't add spec-citation. */
+ TestBaseLine::List bls(baseLines());
+ const TestBaseLine::List::const_iterator end(bls.constEnd());
+ TestBaseLine::List::const_iterator it(bls.constBegin());
+
+ for(; it != end; ++it)
+ (*it)->toXML(receiver);
+
+ /* </test-case> */
+ receiver.endElement(QLatin1String("test-case"));
+}
+
+QString TestCase::displayName(const Scenario scen)
+{
+ switch(scen)
+ {
+ case Standard:
+ return QLatin1String("Standard");
+ case ParseError:
+ return QLatin1String("Parse Error");
+ case RuntimeError:
+ return QLatin1String("Runtime Error");
+ case Trivial:
+ return QLatin1String("Trivial");
+ case AnyError:
+ {
+ Q_ASSERT(false);
+ return QString();
+ }
+ }
+
+ Q_ASSERT(false);
+ return QString();
+}
+
+TestItem::ResultSummary TestCase::resultSummary() const
+{
+ if(m_result)
+ return ResultSummary(m_result->status() == TestResult::Pass ? 1 : 0,
+ 1);
+
+ return ResultSummary(0, 1);
+}
+
+void TestCase::appendChild(TreeItem *)
+{
+ Q_ASSERT_X(false, Q_FUNC_INFO, "Makes no sense to call appendChild() for TestCase.");
+}
+
+TreeItem *TestCase::child(const unsigned int) const
+{
+ return 0; /* Silence GCC */
+}
+
+TreeItem::List TestCase::children() const
+{
+ return TreeItem::List();
+}
+
+unsigned int TestCase::childCount() const
+{
+ return 0;
+}
+
+TestResult *TestCase::testResult() const
+{
+ return m_result;
+}
+
+bool TestCase::isFinalNode() const
+{
+ return true;
+}
+
+QXmlQuery::QueryLanguage TestCase::language() const
+{
+ return QXmlQuery::XQuery10;
+}
+
+QXmlName TestCase::initialTemplateName() const
+{
+ return QXmlName();
+}
+
+// vim: et:ts=4:sw=4:sts=4
+
diff --git a/tests/auto/xmlpatternsxqts/lib/TestCase.h b/tests/auto/xmlpatternsxqts/lib/TestCase.h
new file mode 100644
index 0000000..14d4a48
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestCase.h
@@ -0,0 +1,297 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_TestCase_H
+#define PatternistSDK_TestCase_H
+
+#include <QtXmlPatterns/QXmlQuery>
+
+#include "qexternalvariableloader_p.h"
+
+#include "ErrorHandler.h"
+#include "TestBaseLine.h"
+#include "Global.h"
+
+#include "TestItem.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QDate;
+class QString;
+class QUrl;
+
+namespace QPatternistSDK
+{
+ class XMLWriter;
+
+ /**
+ * @short A generic abstract base class for test cases.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT TestCase : public TestItem
+ {
+ public:
+ /**
+ * Corresponds to the simpleType test:scenarios-enum
+ */
+ enum Scenario
+ {
+ /**
+ * The test case should evaluate normally and that the output
+ * should match the supplied base line.
+ */
+ Standard = 1,
+
+ /**
+ * The test case should result in a static error, a parser error.
+ */
+ ParseError = 2,
+
+ /**
+ * The test case should result in a dynamic error, a runtime error.
+ */
+ RuntimeError = 4,
+
+ Trivial = 8,
+
+ /**
+ * ParseError and RuntimeError OR'd.
+ */
+ AnyError = RuntimeError | ParseError
+
+ };
+
+ TestCase();
+ virtual ~TestCase();
+
+ /**
+ * Executes the test, and returns the result. The returned list
+ * will always contain exactly one TestResult.
+ *
+ * @p stage is ignored when running out-of-process.
+ */
+ virtual TestResult::List execute(const ExecutionStage stage,
+ TestSuite *ts);
+
+ /**
+ * Determines the corresponding Scenario enumerator from the string
+ * representation @p string.
+ *
+ * The following mappings are in effect:
+ * @arg @c Standard "standard"
+ * @arg @c ParseError "parse-error"
+ * @arg @c RuntimeError "runtime-error"
+ */
+ static Scenario scenarioFromString(const QString &string);
+
+ /**
+ * @return always @c true
+ */
+ virtual bool isFinalNode() const;
+
+ /**
+ * Calling this function makes no sense, so it always
+ * performs an Q_ASSERT check.
+ */
+ virtual void appendChild(TreeItem *);
+
+ /**
+ * Calling this function makes no sense, so it always
+ * performs an Q_ASSERT check.
+ */
+ virtual TreeItem *child(const unsigned int) const;
+
+ /**
+ * @return always zero
+ */
+ virtual unsigned int childCount() const;
+
+ /**
+ * @return always an empty list.
+ */
+ virtual TreeItem::List children() const;
+
+ /**
+ * A description of the test case for human consumption.
+ */
+ virtual QString description() const = 0;
+
+ /**
+ * The title of the test. This can be the identifier of the test, for example.
+ */
+ virtual QString title() const = 0;
+
+ /**
+ * Whether this test case only make use of XPath features.
+ *
+ * @returns @c false if the test case exercises any XQuery feature
+ * which is not available in XPath 2.0.
+ */
+ virtual bool isXPath() const = 0;
+
+ /**
+ * The full name of the creator of the test case. For example, "Frans Englich".
+ */
+ virtual QString creator() const = 0;
+
+ /**
+ * The date of when the test case was created or last modified.
+ */
+ virtual QDate lastModified() const = 0;
+
+ /**
+ * The test's source code. That is, the XPath/XQuery code for the test.
+ *
+ * @param ok the function sets this value to @c false if loading the query
+ * failed, and returns a description of the error for human consumption. If
+ * everything went ok, @p ok is set to @c true, and the query is returned.
+ */
+ virtual QString sourceCode(bool &ok) const = 0;
+
+ /**
+ * The path to the file containing the code of the test case.
+ */
+ virtual QUrl testCasePath() const = 0;
+
+ /**
+ * The test case's identifier. For example, "Literals001".
+ */
+ virtual QString name() const = 0;
+
+ /**
+ * What kind of test this is. For example, whether the test case
+ * should result in a parser error or should evaluate without errors.
+ *
+ * The vast common case is that one Scenario is returned; the bit signifiance
+ * is for the TestCase sub-class UserTestCase.
+ */
+ virtual Scenario scenario() const = 0;
+
+ static QString displayName(const Scenario scen);
+
+ /**
+ * @returns the valid test baselines for this test case. If only
+ * one outcome is valid, the returned list only contains
+ * that baseline.
+ */
+ virtual TestBaseLine::List baseLines() const = 0;
+
+ virtual TestResult *testResult() const;
+
+ virtual ResultSummary resultSummary() const;
+
+ void toXML(XMLWriter &receiver) const;
+
+ virtual QPatternist::ExternalVariableLoader::Ptr externalVariableLoader() const = 0;
+
+ /**
+ * @short The XML document that should be used as focus. If none should
+ * be used, and hence the focus be undefined, a default constructed
+ * QUrl is returned.
+ */
+ virtual QUrl contextItemSource() const = 0;
+
+ /**
+ * Returns by default QXmlQuery::XQuery10.
+ */
+ virtual QXmlQuery::QueryLanguage language() const;
+
+ virtual QXmlName initialTemplateName() const;
+ private:
+ TestResult::List execute(const ExecutionStage stage);
+ TestResult *createTestResult(const TestResult::Status status,
+ const QString &comment) const;
+
+ QPointer<TestResult> m_result;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TestContainer.cpp b/tests/auto/xmlpatternsxqts/lib/TestContainer.cpp
new file mode 100644
index 0000000..b0a7c36
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestContainer.cpp
@@ -0,0 +1,192 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QPair>
+#include <QtDebug>
+
+#include "TestContainer.h"
+
+using namespace QPatternistSDK;
+
+TestContainer::TestContainer() : m_deleteChildren(true)
+{
+}
+
+TestContainer::~TestContainer()
+{
+ if(m_deleteChildren)
+ qDeleteAll(m_children);
+}
+
+TestResult::List TestContainer::execute(const ExecutionStage stage,
+ TestSuite *ts)
+{
+ Q_ASSERT(ts);
+ const unsigned int c = m_children.count();
+ TestResult::List result;
+
+ for(unsigned int i = 0; i != c; ++i)
+ result += static_cast<TestItem *>(child(i))->execute(stage, ts);
+
+ return result;
+}
+
+TestItem::ResultSummary TestContainer::resultSummary() const
+{
+ const int c = childCount();
+ int total = 0;
+ int pass = 0;
+
+ for(int i = 0; i != c; ++i)
+ {
+ TestItem *t = static_cast<TestItem *>(child(i));
+ const ResultSummary sum(t->resultSummary());
+ pass += sum.first;
+ total += sum.second;
+ }
+
+ return ResultSummary(pass, total);
+}
+
+TreeItem::List TestContainer::children() const
+{
+ return m_children;
+}
+
+void TestContainer::appendChild(TreeItem *item)
+{
+ /* When one of our children changes, we changes. */
+ connect(item, SIGNAL(changed(TreeItem *)), SIGNAL(changed(TreeItem *)));
+ m_children.append(item);
+}
+
+TreeItem *TestContainer::child(const unsigned int rowP) const
+{
+ return m_children.value(rowP);
+}
+
+unsigned int TestContainer::childCount() const
+{
+ return m_children.count();
+}
+
+void TestContainer::setTitle(const QString &titleP)
+{
+ m_title = titleP;
+}
+
+QString TestContainer::title() const
+{
+ return m_title;
+}
+
+bool TestContainer::isFinalNode() const
+{
+ return false;
+}
+
+int TestContainer::columnCount() const
+{
+ return 4;
+}
+
+QString TestContainer::description() const
+{
+ return m_description;
+}
+
+void TestContainer::setDescription(const QString &desc)
+{
+ m_description = desc;
+}
+
+void TestContainer::setDeleteChildren(const bool val)
+{
+ m_deleteChildren = val;
+}
+
+void TestContainer::removeLast()
+{
+ m_children.removeLast();
+}
+
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TestContainer.h b/tests/auto/xmlpatternsxqts/lib/TestContainer.h
new file mode 100644
index 0000000..5cea0ba
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestContainer.h
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_TestContainer_H
+#define PatternistSDK_TestContainer_H
+
+#include "Global.h"
+#include "TestItem.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ /**
+ * @short an abstract base class, containing
+ * an appropriate implementation of TestItem for sub-classes
+ * which can contain other TestItem instances.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT TestContainer : public TestItem
+ {
+ public:
+ virtual ~TestContainer();
+ virtual void appendChild(TreeItem *item);
+ virtual TreeItem *child(const unsigned int row) const;
+ virtual unsigned int childCount() const;
+
+ /**
+ * @returns the TestResults of this TestContainer's children.
+ */
+ virtual TestResult::List execute(const ExecutionStage stage,
+ TestSuite *ts);
+
+ QString title() const;
+ void setTitle(const QString &title);
+
+ virtual TreeItem::List children() const;
+
+ /**
+ * @return always 2
+ */
+ virtual int columnCount() const;
+
+ virtual bool isFinalNode() const;
+
+ virtual ResultSummary resultSummary() const;
+ virtual QString description() const;
+ virtual void setDescription(const QString &desc);
+
+ /**
+ * Determines whether TestContainer will delete its children upon
+ * destruction. By default, it will.
+ */
+ void setDeleteChildren(const bool val);
+
+ /**
+ * Removes the last appended child.
+ */
+ void removeLast();
+
+ protected:
+ /**
+ * Constructor, protected. TestContainer is an abstract class,
+ * and is not ment to be instantiated, but sub classed.
+ */
+ TestContainer();
+
+ private:
+ TreeItem::List m_children;
+ QString m_title;
+ QString m_description;
+ bool m_deleteChildren;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TestGroup.cpp b/tests/auto/xmlpatternsxqts/lib/TestGroup.cpp
new file mode 100644
index 0000000..060f993
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestGroup.cpp
@@ -0,0 +1,180 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QColor>
+#include <QPair>
+#include <QVariant>
+
+#include "TestGroup.h"
+
+using namespace QPatternistSDK;
+
+TestGroup::TestGroup(TreeItem *p) : m_parent(p)
+{
+}
+
+QVariant TestGroup::data(const Qt::ItemDataRole role, int column) const
+{
+ if(role != Qt::DisplayRole && role != Qt::BackgroundRole)
+ return QVariant();
+
+ /* In ResultSummary, the first is the amount of passes and the second is the total. */
+ const ResultSummary sum(resultSummary());
+ const int failures = sum.second - sum.first;
+
+ switch(role)
+ {
+ case Qt::DisplayRole:
+ {
+
+ switch(column)
+ {
+ case 0:
+ return title();
+ case 1:
+ /* Passes. */
+ return QString::number(sum.first);
+ case 2:
+ /* Failures. */
+ return QString::number(failures);
+ case 3:
+ /* Total. */
+ return QString::number(sum.second);
+ default:
+ {
+ Q_ASSERT(false);
+ return QString();
+ }
+ }
+ }
+ case Qt::BackgroundRole:
+ {
+ switch(column)
+ {
+ case 1:
+ {
+ if(sum.first)
+ {
+ /* Pass. */
+ return Qt::green;
+ }
+ else
+ return QVariant();
+ }
+ case 2:
+ {
+ if(failures)
+ {
+ /* Failure. */
+ return Qt::red;
+ }
+ else
+ return QVariant();
+ }
+ default:
+ return QVariant();
+ }
+ }
+ default:
+ {
+ Q_ASSERT_X(false, Q_FUNC_INFO, "This shouldn't be reached");
+ return QVariant();
+ }
+ }
+}
+
+void TestGroup::setNote(const QString &n)
+{
+ m_note = n;
+}
+
+QString TestGroup::note() const
+{
+ return m_note;
+}
+
+TreeItem *TestGroup::parent() const
+{
+ return m_parent;
+}
+
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TestGroup.h b/tests/auto/xmlpatternsxqts/lib/TestGroup.h
new file mode 100644
index 0000000..bfa9468
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestGroup.h
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_TestGroup_H
+#define PatternistSDK_TestGroup_H
+
+#include <QString>
+
+#include "TestContainer.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ /**
+ * @short Groups test groups and test cases into a group.
+ *
+ * TestGroup corresponds to the @c test-group element in XQTSCatalog.xsd.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT TestGroup : public TestContainer
+ {
+ public:
+ TestGroup(TreeItem *parent);
+
+ /**
+ * @returns the parent of this group. Is either another group, or
+ * the TestSuite instance governing this tree.
+ */
+ virtual TreeItem *parent() const;
+
+ virtual QVariant data(const Qt::ItemDataRole role, int column) const;
+
+ QString note() const;
+
+ void setName(const QString &name);
+ void setNote(const QString &note);
+
+ private:
+ QString m_name;
+ QString m_note;
+ TreeItem *m_parent;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TestItem.h b/tests/auto/xmlpatternsxqts/lib/TestItem.h
new file mode 100644
index 0000000..ec373ab
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestItem.h
@@ -0,0 +1,174 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_TestItem_H
+#define PatternistSDK_TestItem_H
+
+#include "TestResult.h"
+#include "TreeItem.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+template<typename A, typename B> struct QPair;
+
+namespace QPatternistSDK
+{
+ class XMLWriter;
+ class TestSuite;
+
+ /**
+ * @short base class for all classes which
+ * represent an element in an XQuery Test Suite catalog.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT TestItem : public TreeItem
+ {
+ public:
+
+ /**
+ * Determines how far an test case execution should go.
+ */
+ enum ExecutionStage
+ {
+ /**
+ * The query will not be run. It will only go through the (whole) compilation stage.
+ */
+ CompileOnly = 1,
+
+ /**
+ * The query will be compiled and run, as ordinary.
+ */
+ CompileAndRun
+ };
+
+ /**
+ * Represents a summary of test results for a collection
+ * of tests. QPair::first contains the amount of
+ * passed tests; QPair::second contains the count of
+ * all tests. For example TestCase::summary() returns
+ * ResultSummary(0, 1) or ResultSummary(1, 1) depending
+ * on whether the TestCase have succeeded or not.
+ */
+ typedef QPair<int, int> ResultSummary;
+
+ /**
+ * Executes the test case(s) this TestItem represents,
+ * and return the TestResult. For example, the TestGroup
+ * returns the result of its children concatenated, while
+ * TestCase always returns a list containing one
+ * TestResult(what it evaluated to).
+ */
+ virtual TestResult::List execute(const ExecutionStage stage,
+ TestSuite *ts) = 0;
+
+ /**
+ * @todo Rename this function. Perhaps create a type() hierarchy
+ * instead.
+ */
+ virtual bool isFinalNode() const = 0;
+
+ /**
+ * @returns a ResultSummary for this TestItem.
+ */
+ virtual ResultSummary resultSummary() const = 0;
+
+ /**
+ * Serializes into the corresponding elements attributes
+ * specified in XQTSCatalog.xsd.
+ *
+ * @note Sub-classes must assume the XQTSCatalog namespace
+ * is the default namespace, and not add any namespace declarations.
+ */
+ //virtual void toXML(XMLWriter &receiver) const = 0;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TestResult.cpp b/tests/auto/xmlpatternsxqts/lib/TestResult.cpp
new file mode 100644
index 0000000..ae4fd07
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestResult.cpp
@@ -0,0 +1,199 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QXmlAttributes>
+#include <QtDebug>
+
+#include "qdebug_p.h"
+#include "Global.h"
+#include "XMLWriter.h"
+
+#include "TestResult.h"
+
+using namespace QPatternistSDK;
+using namespace QPatternist;
+
+QString TestResult::displayName(const TestResult::Status stat)
+{
+ switch(stat)
+ {
+ case Pass:
+ return QLatin1String("pass");
+ case Fail:
+ return QLatin1String("fail");
+ case NotTested:
+ return QLatin1String("not tested");
+ case Unknown:
+ Q_ASSERT(false);
+ }
+
+ Q_ASSERT(false);
+ return QString();
+}
+
+TestResult::Status TestResult::statusFromString(const QString &string)
+{
+ if(string == QLatin1String("pass"))
+ return Pass;
+ else if(string == QLatin1String("fail"))
+ return Fail;
+ else if(string == QLatin1String("not tested"))
+ return NotTested;
+ else
+ {
+ Q_ASSERT(false);
+ return Fail;
+ }
+}
+
+TestResult::TestResult(const QString &n,
+ const Status s,
+ ASTItem *tree,
+ const ErrorHandler::Message::List &ers,
+ const QPatternist::Item::List &itemsP,
+ const QString &serialized) : m_status(s),
+ m_messages(ers),
+ m_astTree(tree),
+ m_testName(n),
+ m_items(itemsP),
+ m_asSerialized(serialized)
+{
+ Q_ASSERT(!n.isEmpty());
+ Q_ASSERT(s != 0);
+}
+
+TestResult::~TestResult()
+{
+ delete m_astTree;
+}
+
+void TestResult::toXML(XMLWriter &receiver) const
+{
+ QXmlAttributes atts;
+ atts.append(QLatin1String("name"), QString(), QLatin1String("name"), m_testName);
+ atts.append(QLatin1String("result"), QString(), QLatin1String("result"), displayName(m_status));
+
+ if(!m_comment.isEmpty())
+ atts.append(QLatin1String("comment"), QString(), QLatin1String("comment"), m_comment);
+
+ receiver.startElement(QLatin1String("test-case"), atts);
+ receiver.endElement(QLatin1String("test-case"));
+}
+
+void TestResult::setComment(const QString &comm)
+{
+ m_comment = comm;
+}
+
+TestResult::Status TestResult::status() const
+{
+ return m_status;
+}
+
+QString TestResult::comment() const
+{
+ return m_comment;
+}
+
+ASTItem *TestResult::astTree() const
+{
+ return m_astTree;
+}
+
+ErrorHandler::Message::List TestResult::messages() const
+{
+ return m_messages;
+}
+
+QPatternist::Item::List TestResult::items() const
+{
+ return m_items;
+}
+
+QString TestResult::asSerialized() const
+{
+ pDebug() << "asSerialized: " << m_asSerialized;
+ return m_asSerialized;
+}
+
+// vim: et:ts=4:sw=4:sts=4
+
diff --git a/tests/auto/xmlpatternsxqts/lib/TestResult.h b/tests/auto/xmlpatternsxqts/lib/TestResult.h
new file mode 100644
index 0000000..078f495
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestResult.h
@@ -0,0 +1,220 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_TestResult_H
+#define PatternistSDK_TestResult_H
+
+#include <QList>
+#include <QObject>
+#include <QPointer>
+#include <QString>
+
+#include <QtXmlPatterns/private/qitem_p.h>
+#include "ErrorHandler.h"
+
+#include "ASTItem.h"
+
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ class ASTItem;
+ class XMLWriter;
+
+ /**
+ * @short represents the result produced by running a test case.
+ *
+ * This information TestResult houses is:
+ *
+ * - The result status() of the run. Whether the test case succeeded or not, for example.
+ * - The astTree() which reflects the compiled test case
+ * - The messages issued when compiling and running the test case, retrievable via messages()
+ * - The data -- XPath Data Model items() -- the test case evaluated to, if any.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT TestResult : public QObject
+ {
+ Q_OBJECT
+
+ public:
+ enum Status
+ {
+ /**
+ * Used when the status is unknown.
+ */
+ Unknown = 0,
+
+ /**
+ * The test case passed.
+ */
+ Pass,
+
+ /**
+ * The test case failed.
+ */
+ Fail,
+
+ /**
+ * The test was not run. Similar to "SKIP".
+ */
+ NotTested
+ };
+
+ /**
+ * A list of TestResult instances.
+ */
+ typedef QList<QPointer<TestResult> > List;
+
+ /**
+ * Constructs a TestResult.
+ *
+ * @param testName the name of the test. For example, @c Literal-001.
+ * @param astTree may be @c null, signalling no AST being available, or point to one.
+ * @param status the result status of running the test-case. Whether the test-case
+ * passed or failed, and so forth.
+ * @param errors the errors and warnings that were reported while running the test-case
+ * @param items the XDM items that were outputted, if any
+ * @param serialized the output when serialized
+ */
+ TestResult(const QString &testName,
+ const Status status,
+ ASTItem *astTree,
+ const ErrorHandler::Message::List &errors,
+ const QPatternist::Item::List &items,
+ const QString &serialized);
+
+ virtual ~TestResult();
+
+ Status status() const;
+
+ QString comment() const;
+ void setComment(const QString &comment);
+
+ QPatternist::Item::List items() const;
+
+ ErrorHandler::Message::List messages() const;
+
+ /**
+ * Serializes itself to @p receiver, into a test-case element,
+ * as per @c XQTSResult.xsd.
+ */
+ void toXML(XMLWriter &receiver) const;
+
+ ASTItem *astTree() const;
+
+ /**
+ * @returns a string representation for @p status, as per the anonymous
+ * type inside the type test-case, in @c XQTSResult.xsd. For example, if @p status
+ * is NotTested, is "not tested" returned.
+ */
+ static QString displayName(const TestResult::Status status);
+
+ static Status statusFromString(const QString &string);
+
+ /**
+ * @returns the output of this test result(if any) as when
+ * being serialized.
+ */
+ QString asSerialized() const;
+
+ private:
+ const Status m_status;
+ QString m_comment;
+ const ErrorHandler::Message::List m_messages;
+ QPointer<ASTItem> m_astTree;
+ QString m_testName;
+ const QPatternist::Item::List m_items;
+ const QString m_asSerialized;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TestResultHandler.cpp b/tests/auto/xmlpatternsxqts/lib/TestResultHandler.cpp
new file mode 100644
index 0000000..1816dd8
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestResultHandler.cpp
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QtDebug>
+
+#include "Global.h"
+
+#include "TestResultHandler.h"
+
+using namespace QPatternistSDK;
+
+TestResultHandler::TestResultHandler()
+{
+ /* Fifteen thousand. When finished, we squeeze them. */
+ m_result.reserve(15000);
+ m_comments.reserve(1000); /* Comments are only used for stuff that crash, more or less. */
+}
+
+bool TestResultHandler::startElement(const QString &namespaceURI,
+ const QString &localName,
+ const QString &,
+ const QXmlAttributes &atts)
+{
+ /* We only care about 'test-case', ignore everything else. */
+ if(localName != QLatin1String("test-case") ||
+ namespaceURI != Global::xqtsResultNS)
+ return true;
+
+ /* The 'comments' attribute is optional. */
+ Q_ASSERT_X(atts.count() == 2 || atts.count() == 3, Q_FUNC_INFO,
+ "The input appears to not conform to XQTSResult.xsd");
+
+ Q_ASSERT_X(!m_result.contains(atts.value(QLatin1String("name"))),
+ Q_FUNC_INFO,
+ qPrintable(QString::fromLatin1("A test result for test case %1 has "
+ "already been read(duplicate entry it seems).").arg(atts.value(QLatin1String("name")))));
+
+ m_result.insert(atts.value(0), TestResult::statusFromString(atts.value(QLatin1String("result"))));
+
+ return true;
+}
+
+bool TestResultHandler::endDocument()
+{
+ m_result.squeeze();
+ m_comments.squeeze();
+ return true;
+}
+
+TestResultHandler::Hash TestResultHandler::result() const
+{
+ return m_result;
+}
+
+TestResultHandler::CommentHash TestResultHandler::comments() const
+{
+ return m_comments;
+}
+
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TestResultHandler.h b/tests/auto/xmlpatternsxqts/lib/TestResultHandler.h
new file mode 100644
index 0000000..d738c4c
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestResultHandler.h
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_TestResultHandler_H
+#define PatternistSDK_TestResultHandler_H
+
+#include <QHash>
+#include <QString>
+#include <QtXml/QXmlDefaultHandler>
+
+#include "TestResult.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ /**
+ * @short Reads XML in the @c XQTSResult.xsd format, and provides access to
+ * the reported results.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup PatternistSDK
+ */
+ class Q_PATTERNISTSDK_EXPORT TestResultHandler : public QXmlDefaultHandler
+ {
+ public:
+ /**
+ * A hash where the key is the class's name, that is <tt>test-case/@@name</tt>,
+ * and the value the test's result status.
+ */
+ typedef QHash<QString, TestResult::Status> Hash;
+
+ /**
+ * A hash mapping test-case names to their' comments.
+ */
+ typedef QHash<QString, QString> CommentHash;
+
+ /**
+ * Creates a TestResultHandler that will read @p file when run() is called.
+ */
+ TestResultHandler();
+
+ /**
+ * Performs finalization.
+ */
+ virtual bool endDocument();
+
+ /**
+ * Reads the <tt>test-case</tt> element and its attributes, everything else is ignored.
+ */
+ virtual bool startElement(const QString &namespaceURI,
+ const QString &localName,
+ const QString &qName,
+ const QXmlAttributes &atts);
+ /**
+ * @note Do not reimplement this function.
+ * @returns the result obtained from reading the XML file.
+ */
+ Hash result() const;
+
+ CommentHash comments() const;
+
+ private:
+ Q_DISABLE_COPY(TestResultHandler)
+ Hash m_result;
+ CommentHash m_comments;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TestSuite.cpp b/tests/auto/xmlpatternsxqts/lib/TestSuite.cpp
new file mode 100644
index 0000000..3bca281
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestSuite.cpp
@@ -0,0 +1,302 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QFileInfo>
+#include <QVariant>
+#include <QXmlInputSource>
+#include <QXmlSimpleReader>
+#include <QtDebug>
+
+#include "Global.h"
+#include "TestSuiteHandler.h"
+#include "TestSuiteResult.h"
+#include "XMLWriter.h"
+#include "XSLTTestSuiteHandler.h"
+#include "qdebug_p.h"
+
+#include "TestSuite.h"
+
+using namespace QPatternistSDK;
+using namespace QPatternist;
+
+TestSuite::TestSuite()
+{
+}
+
+QVariant TestSuite::data(const Qt::ItemDataRole role, int column) const
+{
+ if(role != Qt::DisplayRole)
+ return QVariant();
+
+ switch(column)
+ {
+ case 0:
+ return title();
+ case 1:
+ return QString();
+ default:
+ {
+ Q_ASSERT(false);
+ return QString();
+ }
+ }
+}
+
+TestSuiteResult *TestSuite::runSuite()
+{
+ const QDate date(QDate::currentDate());
+ TestResult::List result(execute(CompileAndRun, this));
+
+ return new TestSuiteResult(version(), date, result);
+}
+
+TestSuite *TestSuite::openCatalog(const QUrl &catalogURI,
+ QString &errorMsg,
+ const bool useExclusionList,
+ const bool isXSLTCatalog)
+{
+ pDebug() << "Opening catalog:" << catalogURI.toString();
+ QFile ts(catalogURI.toLocalFile());
+ Q_ASSERT(catalogURI.isValid());
+
+ if(!ts.exists())
+ {
+ errorMsg = QString::fromLatin1("The test suite catalog \"%1\" could not be found.\n")
+ .arg(ts.fileName());
+ return 0;
+ }
+
+ const QFileInfo info(ts);
+
+ if(!info.isReadable())
+ {
+ errorMsg = QString::fromLatin1("Cannot read the test suite catalog.\n");
+ return 0;
+ }
+ else if(!info.isFile())
+ {
+ errorMsg = QString::fromLatin1("The specified test suite catalog \"%1\" is not a file. "
+ "The test suite catalog must be a file, it cannot be "
+ "a directory, for example.\n")
+ .arg(ts.fileName());
+ return 0;
+ }
+ else if(!ts.open(QIODevice::ReadOnly | QIODevice::Text))
+ {
+ errorMsg = QString::fromLatin1("Failed to open the test suite catalog, \"%1\".\n")
+ .arg(ts.fileName());
+ return 0;
+ }
+
+ return openCatalog(&ts, errorMsg, catalogURI, useExclusionList, isXSLTCatalog);
+}
+
+TestSuite *TestSuite::openCatalog(QIODevice *input,
+ QString &errorMsg,
+ const QUrl &fileName,
+ const bool useExclusionList,
+ const bool isXSLTCatalog)
+{
+ Q_ASSERT(input);
+
+ QXmlSimpleReader reader;
+ typedef QPatternist::AutoPtr<QXmlDefaultHandler> HandlerPtr;
+
+ HandlerPtr loader;
+
+ if(isXSLTCatalog)
+ loader = HandlerPtr(new XSLTTestSuiteHandler(fileName));
+ else
+ loader = HandlerPtr(new TestSuiteHandler(fileName, useExclusionList));
+
+ reader.setContentHandler(loader.data());
+
+ QXmlInputSource source(input);
+
+ if(!reader.parse(source))
+ {
+ errorMsg = QString::fromLatin1("Couldn't parse %1").arg(fileName.toString());
+ return 0;
+ }
+
+ TestSuite *const suite = isXSLTCatalog ? static_cast<XSLTTestSuiteHandler *>(loader.data())->testSuite()
+ : static_cast<TestSuiteHandler *>(loader.data())->testSuite();
+
+ if(suite)
+ return suite;
+
+ errorMsg = QString::fromLatin1("Failed to load \"%1\". "
+ "It appears to have no test-suite element.\n").arg(fileName.toString());
+ return 0;
+}
+
+void TestSuite::toXML(XMLWriter &receiver, TestCase *const tc) const
+{
+ // TODO startElement() endElement() calls can be simplified.
+
+ Q_ASSERT(tc);
+
+ receiver.startDocument();
+ /* <test-suite> */
+ QXmlAttributes test_suiteAtts;
+ test_suiteAtts.append(QLatin1String("CatalogDesignDate"), QString(),
+ QLatin1String("CatalogDesignDate"), m_designDate.toString(Qt::ISODate));
+ test_suiteAtts.append(QLatin1String("version"), QString(),
+ QLatin1String("version"), m_version);
+ test_suiteAtts.append(QLatin1String("SourceOffsetPath"), QString(),
+ QLatin1String("SourceOffsetPath"), QString());
+ test_suiteAtts.append(QLatin1String("ResultOffsetPath"), QString(),
+ QLatin1String("ResultOffsetPath"), QString());
+ test_suiteAtts.append(QLatin1String("XQueryQueryOffsetPath"), QString(),
+ QLatin1String("XQueryQueryOffsetPath"), QString());
+ test_suiteAtts.append(QLatin1String("QueryXQueryOffsetPath"), QString(),
+ QLatin1String("QueryXQueryOffsetPath"), QString());
+ test_suiteAtts.append(QLatin1String("XQueryFileExtension"), QString(),
+ QLatin1String("XQueryFileExtension"), QString());
+ test_suiteAtts.append(QLatin1String("XQueryXFileExtension"), QString(),
+ QLatin1String("XQueryXFileExtension"), QString());
+
+ receiver.startPrefixMapping(QString(), Global::xqtsCatalogNS);
+ receiver.startElement(QLatin1String("test-suite"), test_suiteAtts);
+ receiver.endPrefixMapping(QString());
+
+ /* <test-group> */
+ QXmlAttributes test_groupAtts;
+ test_groupAtts.append(QLatin1String("GeneratedGroupByPatternistSDKRunSuite"), QString(),
+ QLatin1String("GeneratedGroupByPatternistSDKRunSuite"), QString());
+ receiver.startElement(QLatin1String("test-group"), test_groupAtts);
+
+ /* <GroupInfo> */
+ receiver.startElement(QLatin1String("GroupInfo"), test_groupAtts);
+
+ /* <title> */
+ receiver.startElement(QLatin1String("title"), test_groupAtts);
+ receiver.characters(QLatin1String("Contains the test case generated by PatternistSDKRunSuite."));
+
+ /* </title> */
+ receiver.endElement(QLatin1String("title"));
+
+ /* <description> */
+ receiver.startElement(QLatin1String("description"), test_groupAtts);
+ /* </description> */
+ receiver.endElement(QLatin1String("description"));
+
+ /* </GroupInfo> */
+ receiver.endElement(QLatin1String("GroupInfo"));
+
+ /* <test-case> */
+ tc->toXML(receiver);
+ /* </test-case> */
+
+ /* </test-group> */
+ receiver.endElement(QLatin1String("test-group"));
+
+ /* </test-suite> */
+ receiver.endElement(QLatin1String("test-suite"));
+}
+
+QString TestSuite::version() const
+{
+ return m_version;
+}
+
+QDate TestSuite::designDate() const
+{
+ return m_designDate;
+}
+
+void TestSuite::setVersion(const QString &ver)
+{
+ m_version = ver;
+}
+
+void TestSuite::setDesignDate(const QDate &date)
+{
+ m_designDate = date;
+}
+
+TestContainer *TestSuite::parent() const
+{
+ return 0;
+}
+
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TestSuite.h b/tests/auto/xmlpatternsxqts/lib/TestSuite.h
new file mode 100644
index 0000000..cdd511f
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestSuite.h
@@ -0,0 +1,191 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_TestSuite_H
+#define PatternistSDK_TestSuite_H
+
+#include <QDate>
+#include <QString>
+
+#include "TestContainer.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QIODevice;
+class QUrl;
+class QVariant;
+
+namespace QPatternistSDK
+{
+ class TestCase;
+ class TestSuiteResult;
+
+ /**
+ * @short Represents a test suite in the W3C XML Query Test Suite format.
+ *
+ * TestSuite contains the test suite's test cases and meta data.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT TestSuite : public TestContainer
+ {
+ public:
+ TestSuite();
+
+ virtual QVariant data(const Qt::ItemDataRole role, int column) const;
+
+ /**
+ * The version of the catalog test suite. For example, "0.8.0".
+ */
+ QString version() const;
+
+ /**
+ * When the catalog was designed, last modified.
+ */
+ QDate designDate() const;
+
+ void setVersion(const QString &version);
+ void setDesignDate(const QDate &version);
+
+ /**
+ * @return always @c null
+ */
+ virtual TestContainer *parent() const;
+
+ /**
+ * Creates and returns a pointer to a TestSuite instance, which
+ * was instantiated from the XQuery Test Suite catalog file @p catalogFile.
+ *
+ * If loading went wrong, @c null is returned and @p errorMsg is set with a
+ * human readable message string. However, @p catalogFile is not validated;
+ * if the XML file is not valid against the XQTS task force's W3C XML Schema, the
+ * behavior and result for this function is undefined.
+ *
+ * This function blocks. Currently is only local files supported.
+ */
+ static TestSuite *openCatalog(const QUrl &catalogFile,
+ QString &errorMsg,
+ const bool useExclusionList,
+ const bool isXSLTCatalog = false);
+
+ void toXML(XMLWriter &receiver, TestCase *const tc) const;
+
+ /**
+ * Evaluates all the test cases in this TestSuite, and returns
+ * it all in a TestSuiteResult.
+ */
+ TestSuiteResult *runSuite();
+
+ private:
+ /**
+ * Essentially similar to open(const QUrl &, QString &errorMsg),
+ * with the difference that it takes directly a QIODevice as input,
+ * as opposed to a file name locating the catalog file to read.
+ *
+ * @param input the test suite catalog
+ * @param fileName this URI is used for resolving relative paths inside
+ * the catalog file into absolute.
+ * @param errorMsg if an error occurs, this QString is set to contain the message.
+ * Whether an error occurred can therefore be determined by checking if this variable
+ * still is @c null after the call
+ * @param useExclusionList whether the excludeTestGroups.txt file should be used
+ * to exclude test groups for this catalog
+ */
+ static TestSuite *openCatalog(QIODevice *input,
+ QString &errorMsg,
+ const QUrl &fileName,
+ const bool useExclusionList,
+ const bool isXSLTCatalog);
+ QString m_version;
+ QDate m_designDate;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.cpp b/tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.cpp
new file mode 100644
index 0000000..a87eeaa
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.cpp
@@ -0,0 +1,353 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QtDebug>
+
+#include "qacceltreeresourceloader_p.h"
+#include "qnetworkaccessdelegator_p.h"
+
+#include "Global.h"
+#include "TestBaseLine.h"
+#include "TestGroup.h"
+
+#include "TestSuiteHandler.h"
+
+using namespace QPatternistSDK;
+
+QNetworkAccessManager s_networkManager;
+
+TestSuiteHandler::TestSuiteHandler(const QUrl &catalogFile,
+ const bool useEList) : m_ts(0)
+ , m_container(0)
+ , m_tc(0)
+ , m_baseLine(0)
+ , m_catalogFile(catalogFile)
+ , m_exclusionList(readExclusionList(useEList))
+ , m_isExcluding(false)
+{
+ Q_ASSERT(!m_catalogFile.isRelative());
+}
+
+QStringList TestSuiteHandler::readExclusionList(const bool useExclusionList) const
+{
+ if(!useExclusionList)
+ return QStringList();
+
+ QStringList avoid;
+
+ /* These test groups are for features we don't support.
+ *
+ * Originally these were stored in a text file pulled in with Qt resources, but
+ * it was not possible to get it to link on some HP-UX and Intel-icc platforms. */
+
+ avoid << "SchemaImport"; // The schema import feature
+ avoid << "SchemaValidation"; // The validate expression(requires schema import)
+ avoid << "StaticTyping"; // Pessimistic static typing checking
+ avoid << "TrivialEmbedding"; // XQueryX inside XQuery
+ avoid << "XMark"; // We're currently too buggy for running these tests.
+
+ return avoid;
+}
+
+bool TestSuiteHandler::startElement(const QString &namespaceURI,
+ const QString &localName,
+ const QString &/*qName*/,
+ const QXmlAttributes &atts)
+{
+ if(namespaceURI != Global::xqtsCatalogNS)
+ return true;
+ else if(m_isExcluding)
+ {
+ if(localName == QLatin1String("test-group"))
+ {
+ m_testGroupName.push(atts.value(QLatin1String("name")));
+ return true;
+ }
+ else
+ return true;
+ }
+
+ /* The elements are handled roughly in the order of highest occurrence in the catalog file. */
+ if(localName == QLatin1String("test-case"))
+ {
+ XQTSTestCase *const c = new XQTSTestCase(
+ TestCase::scenarioFromString(atts.value(QLatin1String("scenario"))), m_container);
+
+ c->setName(atts.value(QLatin1String("name")));
+ c->setCreator(atts.value(QLatin1String("Creator")));
+ c->setIsXPath(Global::readBoolean(atts.value(QLatin1String("is-XPath2"))));
+ c->setLastModified(QDate::fromString(atts.value(QLatin1String("version-drop")), Qt::ISODate));
+ Q_ASSERT(c->lastModified().isNull() || c->lastModified().isValid());
+
+ m_currentQueryPath = m_queryOffset.resolved(QUrl(atts.value(QLatin1String("FilePath"))));
+ m_currentBaselinePath = m_baselineOffset.resolved(QUrl(atts.value(QLatin1String("FilePath"))));
+
+ m_container->appendChild(c);
+ m_tc = c;
+ }
+ else if(localName == QLatin1String("query"))
+ {
+ m_tc->setQueryPath(m_currentQueryPath.resolved(atts.value(QLatin1String("name")) +
+ m_xqueryFileExtension));
+ }
+ else if(localName == QLatin1String("input-file") ||
+ localName == QLatin1String("input-URI"))
+ {
+ m_currentInputVariable = atts.value(QLatin1String("variable"));
+ }
+ else if(localName == QLatin1String("output-file"))
+ {
+ m_baseLine = new TestBaseLine(TestBaseLine::identifierFromString(atts.value(QLatin1String("compare"))));
+ }
+ else if(localName == QLatin1String("expected-error"))
+ {
+ m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError);
+ }
+ else if(localName == QLatin1String("test-group"))
+ {
+ m_testGroupName.push(atts.value(QLatin1String("name")));
+
+ if(m_exclusionList.contains(m_testGroupName.top()))
+ {
+ /* Ok, this group is supposed to be excluded, we don't
+ * insert it into the tree. */
+ m_isExcluding = true;
+ return true;
+ }
+ else
+ {
+ Q_ASSERT(m_container);
+ TestGroup *const newGroup = new TestGroup(m_container);
+ m_container->appendChild(newGroup);
+ m_container = newGroup;
+ }
+ }
+ else if(localName == QLatin1String("source"))
+ {
+ m_sourceMap.insert(atts.value(QLatin1String("ID")),
+ m_sourceOffset.resolved(QUrl(atts.value(QLatin1String("FileName")))));
+ }
+ else if(localName == QLatin1String("test-suite"))
+ {
+ m_ts = new TestSuite();
+ m_ts->setVersion(atts.value(QLatin1String("version")));
+ m_ts->setDesignDate(QDate::fromString(atts.value(QLatin1String("CatalogDesignDate")), Qt::ISODate));
+ Q_ASSERT(m_ts->designDate().isValid());
+ m_container = m_ts;
+
+ m_xqueryFileExtension = atts.value(QLatin1String("XQueryFileExtension"));
+ m_queryOffset = m_catalogFile.resolved(atts.value(QLatin1String("XQueryQueryOffsetPath")));
+ m_baselineOffset = m_catalogFile.resolved(atts.value(QLatin1String("ResultOffsetPath")));
+ m_sourceOffset = m_catalogFile.resolved(atts.value(QLatin1String("SourceOffsetPath")));
+ }
+ else if(localName == QLatin1String("input-query"))
+ {
+ m_tcSourceInputs.insert(atts.value(QLatin1String("variable")),
+ ExternalSourceLoader::VariableValue(m_currentQueryPath.resolved(atts.value(QLatin1String("name")) + m_xqueryFileExtension),
+ ExternalSourceLoader::Query));
+ }
+
+ return true;
+}
+
+bool TestSuiteHandler::endElement(const QString &namespaceURI,
+ const QString &localName,
+ const QString &/*qName*/)
+{
+ if(namespaceURI != Global::xqtsCatalogNS)
+ return true;
+
+ if(m_isExcluding)
+ {
+ if(localName == QLatin1String("test-group"))
+ {
+ const QString myName(m_testGroupName.pop());
+
+ if(m_exclusionList.contains(myName))
+ {
+ /* This test-group is being excluded and now we're exiting from it. */
+ m_isExcluding = false;
+ }
+ }
+
+ return true;
+ }
+
+ /* The elements are handled roughly in the order of highest occurrence in the catalog file. */
+ if(localName == QLatin1String("description"))
+ {
+ if(m_tc)
+ {
+ /* We're inside a <test-case>, so the <description> belongs
+ * to the test-case. */
+ m_tc->setDescription(m_ch.simplified());
+ }
+ else
+ m_container->setDescription(m_ch.simplified());
+ }
+ else if(localName == QLatin1String("test-case"))
+ {
+ Q_ASSERT(m_tc->baseLines().count() >= 1);
+ Q_ASSERT(m_resourceLoader);
+ m_tc->setExternalVariableLoader(QPatternist::ExternalVariableLoader::Ptr
+ (new ExternalSourceLoader(m_tcSourceInputs,
+ m_resourceLoader)));
+ m_tcSourceInputs.clear();
+
+ if(!m_contextItemSource.isEmpty())
+ {
+ m_tc->setContextItemSource(QUrl(m_sourceMap.value(m_contextItemSource)));
+ m_contextItemSource.clear();
+ }
+
+ m_tc = 0;
+ }
+ else if(localName == QLatin1String("output-file"))
+ {
+ m_baseLine->setDetails(m_currentBaselinePath.resolved(m_ch).toString());
+ m_tc->addBaseLine(m_baseLine);
+ }
+ else if(localName == QLatin1String("input-file"))
+ {
+ m_tcSourceInputs.insert(m_currentInputVariable, ExternalSourceLoader::VariableValue(m_sourceMap.value(m_ch),
+ ExternalSourceLoader::Document));
+ }
+ else if(localName == QLatin1String("expected-error"))
+ {
+ m_baseLine->setDetails(m_ch);
+ m_tc->addBaseLine(m_baseLine);
+ }
+ else if(localName == QLatin1String("title"))
+ {
+ /* A bit dangerous, the only element with name title in the vocabulary
+ * is the the child of GroupInfo */
+ m_container->setTitle(m_ch.simplified());
+ }
+ else if(localName == QLatin1String("test-group"))
+ {
+ m_testGroupName.pop();
+ Q_ASSERT(m_container);
+ m_container = static_cast<TestContainer *>(m_container->parent());
+ Q_ASSERT(m_container);
+ }
+ else if(localName == QLatin1String("test-suite"))
+ {
+ Q_ASSERT(m_container);
+ m_container = static_cast<TestContainer *>(m_container->parent());
+ }
+ else if(localName == QLatin1String("sources"))
+ {
+ const QPatternist::NetworkAccessDelegator::Ptr networkDelegator(new QPatternist::NetworkAccessDelegator(&s_networkManager, &s_networkManager));
+
+ m_resourceLoader = QPatternist::ResourceLoader::Ptr(new QPatternist::AccelTreeResourceLoader(Global::namePool(),
+ networkDelegator));
+
+ const ExternalSourceLoader::SourceMap::const_iterator end(m_sourceMap.constEnd());
+ ExternalSourceLoader::SourceMap::const_iterator it(m_sourceMap.constBegin());
+
+ for(; it != end; ++it)
+ m_resourceLoader->announceDocument(it.value(), QPatternist::ResourceLoader::WillUse);
+ }
+ else if(localName == QLatin1String("input-URI"))
+ {
+ m_tcSourceInputs.insert(m_currentInputVariable, ExternalSourceLoader::VariableValue(m_sourceMap.value(m_ch),
+ ExternalSourceLoader::URI));
+ }
+ else if(localName == QLatin1String("contextItem"))
+ m_contextItemSource = m_ch;
+
+ return true;
+}
+
+bool TestSuiteHandler::characters(const QString &ch)
+{
+ m_ch = ch;
+ return true;
+}
+
+TestSuite *TestSuiteHandler::testSuite() const
+{
+ return m_ts;
+}
+
+// vim: et:ts=4:sw=4:sts=4
+
diff --git a/tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.h b/tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.h
new file mode 100644
index 0000000..dff56e5
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.h
@@ -0,0 +1,210 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_TestSuiteHandler_H
+#define PatternistSDK_TestSuiteHandler_H
+
+#include <QStack>
+#include <QUrl>
+#include <QXmlDefaultHandler>
+
+#include "ExternalSourceLoader.h"
+#include "TestSuite.h"
+#include "XQTSTestCase.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ class TestBaseLine;
+
+ /**
+ * @short Creates a TestSuite from the XQuery Test Suite catalog,
+ * represented as a SAX stream.
+ *
+ * The created TestSuite can be retrieved via testSuite().
+ *
+ * @note TestSuiteHandler assumes the XML is valid by having been validated
+ * against the W3C XML Schema. It have no safety checks for that the XML format
+ * is correct but is hard coded for it. Thus, the behavior is undefined if
+ * the XML is invalid.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT TestSuiteHandler : public QXmlDefaultHandler
+ {
+ public:
+ /**
+ * @param catalogFile the URI for the catalog file being parsed. This
+ * URI is used for creating absolute URIs for files mentioned in
+ * the catalog with relative URIs.
+ * @param useExclusionList whether excludeTestGroups.txt should be used to ignore
+ * test groups when loading
+ */
+ TestSuiteHandler(const QUrl &catalogFile,
+ const bool useExclusionList);
+ virtual bool characters(const QString &ch);
+
+ virtual bool endElement(const QString &namespaceURI,
+ const QString &localName,
+ const QString &qName);
+ virtual bool startElement(const QString &namespaceURI,
+ const QString &localName,
+ const QString &qName,
+ const QXmlAttributes &atts);
+
+ virtual TestSuite *testSuite() const;
+
+ private:
+ QStringList readExclusionList(const bool useExclusionList) const;
+
+ TestSuite * m_ts;
+ TestContainer * m_container;
+ XQTSTestCase * m_tc;
+ TestBaseLine * m_baseLine;
+ QString m_ch;
+ const QUrl m_catalogFile;
+
+ /**
+ * The extension of XQuery files. For example, ".xq"
+ */
+ QString m_xqueryFileExtension;
+
+ /**
+ * The base URI for where the XQuery query files are found.
+ * It is absolute, resolved against catalogFile.
+ */
+ QUrl m_queryOffset;
+
+ QUrl m_baselineOffset;
+ QUrl m_sourceOffset;
+ QUrl m_currentQueryPath;
+ QUrl m_currentBaselinePath;
+
+ /**
+ * In the XQTSCatalog.xml, each source file in each test is referred to
+ * by a key, which can be fully looked up in the @c sources element. This QHash
+ * maps the keys to absolute URIs pointing to the source files.
+ */
+ ExternalSourceLoader::SourceMap m_sourceMap;
+
+ ExternalSourceLoader::VariableMap m_tcSourceInputs;
+
+ QPatternist::ResourceLoader::Ptr m_resourceLoader;
+
+ /**
+ * The current value of <tt>input-file/\@variable/</tt>.
+ */
+ QString m_currentInputVariable;
+
+ /**
+ * The names of the test groups we're excluding.
+ */
+ const QStringList m_exclusionList;
+
+ /**
+ * This is set when we're inside a test-group that we're excluding.
+ */
+ bool m_isExcluding;
+
+ /**
+ * The names of the test groups.
+ */
+ QStack<QString> m_testGroupName;
+
+ /**
+ * Holds the content of the current <tt>input-URI</tt> element.
+ */
+ QString m_inputURI;
+ QString m_contextItemSource;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TestSuiteResult.cpp b/tests/auto/xmlpatternsxqts/lib/TestSuiteResult.cpp
new file mode 100644
index 0000000..c88af5c
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestSuiteResult.cpp
@@ -0,0 +1,214 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QXmlContentHandler>
+
+#include "Global.h"
+#include "XMLWriter.h"
+
+#include "TestSuiteResult.h"
+
+using namespace QPatternistSDK;
+
+TestSuiteResult::TestSuiteResult(const QString &testSuiteVersion,
+ const QDate &runDate,
+ const TestResult::List &results) : m_testSuiteVersion(testSuiteVersion),
+ m_runDate(runDate),
+ m_results(results)
+{
+}
+
+TestSuiteResult::~TestSuiteResult()
+{
+ qDeleteAll(m_results);
+}
+
+void TestSuiteResult::toXML(XMLWriter &receiver) const
+{
+ /* If this data needs to be configurable in someway(say, another
+ * XML format is supported), then break out the info into getters(alternatively, combined
+ * with setters, or that the class is subclassed), and access the getters instead.
+ */
+ const QString organizationName (QLatin1String("K Desktop Environment(KDE)"));
+ const QString organizationWebsite (QLatin1String("http://www.kde.org/"));
+ const QString submittorName (QLatin1String("Frans Englich"));
+ const QString submittorEmail (QLatin1String("fenglich@trolltech.com"));
+ const QString implementationVersion (QLatin1String("0.1"));
+ const QString implementationName (QLatin1String("Patternist"));
+ const QString implementationDescription (QLatin1String(
+ "Patternist is an implementation written in C++ "
+ "and with the Qt/KDE libraries. "
+ "It is licensed under GNU LGPL and part of KDE, "
+ "the K Desktop Environment."));
+
+ /* Not currently serialized:
+ * - <implementation-defined-items>
+ * - <features>
+ * - <context-properties>
+ */
+
+ receiver.startDocument();
+ /* <test-suite-result> */
+ receiver.startPrefixMapping(QString(), Global::xqtsResultNS);
+ receiver.startElement(QLatin1String("test-suite-result"));
+ receiver.endPrefixMapping(QString());
+
+ /* <implementation> */
+ QXmlAttributes implementationAtts;
+ implementationAtts.append(QLatin1String("name"), QString(),
+ QLatin1String("name"), implementationName);
+ implementationAtts.append(QLatin1String("version"), QString(),
+ QLatin1String("version"), implementationVersion);
+ receiver.startElement(QLatin1String("implementation"), implementationAtts);
+
+ /* <organization> */
+ QXmlAttributes organizationAtts;
+ organizationAtts.append(QLatin1String("name"), QString(),
+ QLatin1String("name"), organizationName);
+ organizationAtts.append(QLatin1String("website"), QString(),
+ QLatin1String("website"), organizationWebsite);
+ receiver.startElement(QLatin1String("organization"), organizationAtts);
+
+ /* </organization> */
+ receiver.endElement(QLatin1String("organization"));
+
+ /* <submittor> */
+ QXmlAttributes submittorAtts;
+ submittorAtts.append(QLatin1String("name"), QString(), QLatin1String("name"), submittorName);
+ submittorAtts.append(QLatin1String("email"), QString(), QLatin1String("email"), submittorEmail);
+ receiver.startElement(QLatin1String("submittor"), submittorAtts);
+
+ /* </submittor> */
+ receiver.endElement(QLatin1String("submittor"));
+
+ /* <description> */
+ receiver.startElement(QLatin1String("description"));
+
+ /* <p> */
+ receiver.startElement(QLatin1String("p"));
+ receiver.characters(implementationDescription);
+
+ /* </p> */
+ receiver.endElement(QLatin1String("p"));
+ /* </description> */
+ receiver.endElement(QLatin1String("description"));
+
+ /* </implementation> */
+ receiver.endElement(QLatin1String("implementation"));
+
+ /* <syntax> */
+ receiver.startElement(QLatin1String("syntax"));
+ receiver.characters(QLatin1String(QLatin1String("XQuery")));
+
+ /* </syntax> */
+ receiver.endElement(QLatin1String("syntax"));
+
+ /* <test-run> */
+ QXmlAttributes test_runAtts;
+ test_runAtts.append(QLatin1String("dateRun"), QString(), QLatin1String("dateRun"), m_runDate.toString(QLatin1String("yyyy-MM-dd")));
+ receiver.startElement(QLatin1String("test-run"), test_runAtts);
+
+ /* <test-suite> */
+ QXmlAttributes test_suiteAtts;
+ test_suiteAtts.append(QLatin1String("version"), QString(), QLatin1String("version"), m_testSuiteVersion);
+ receiver.startElement(QLatin1String("test-suite"), test_suiteAtts);
+
+ /* </test-suite> */
+ receiver.endElement(QLatin1String("test-suite"));
+
+ /* </test-run> */
+ receiver.endElement(QLatin1String("test-run"));
+
+ /* Serialize the TestResults: tons of test-case elements. */
+ const TestResult::List::const_iterator end(m_results.constEnd());
+ TestResult::List::const_iterator it(m_results.constBegin());
+
+ for(; it != end; ++it)
+ (*it)->toXML(receiver);
+
+ /* </test-suite-result> */
+ receiver.endElement(QLatin1String("test-suite-result"));
+ receiver.endDocument();
+}
+
+// vim: et:ts=4:sw=4:sts=4
+
diff --git a/tests/auto/xmlpatternsxqts/lib/TestSuiteResult.h b/tests/auto/xmlpatternsxqts/lib/TestSuiteResult.h
new file mode 100644
index 0000000..f859bfd
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TestSuiteResult.h
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_TestSuiteResult_H
+#define PatternistSDK_TestSuiteResult_H
+
+#include <QDate>
+#include <QString>
+
+#include "TestResult.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ /**
+ * @short A collection of TestResult instances.
+ *
+ * A TestSuiteResult gathers all TestResult instances, and provides
+ * the toXML() function which serializes it all into a XQuery Test Suite
+ * result file, conforming to XQTSResult.xsd.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT TestSuiteResult
+ {
+ public:
+ ~TestSuiteResult();
+
+ TestSuiteResult(const QString &testSuiteVersion,
+ const QDate &runDate,
+ const TestResult::List &results);
+
+ /**
+ * Serializes the test results this TestSuiteResult represents,
+ * into XQTS test-suite-result document, conformant to XQTSCatalog.xsd.
+ */
+ void toXML(XMLWriter &receiver) const;
+
+ private:
+ const QString m_testSuiteVersion;
+ const QDate m_runDate;
+ const TestResult::List m_results;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TreeItem.cpp b/tests/auto/xmlpatternsxqts/lib/TreeItem.cpp
new file mode 100644
index 0000000..2c5c82f
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TreeItem.cpp
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include "TestContainer.h"
+
+#include "TreeItem.h"
+
+using namespace QPatternistSDK;
+
+int TreeItem::row() const
+{
+ const TreeItem *const p = parent();
+
+ if(p)
+ {
+ /* The const_cast makes it possible for QPointer's constructor
+ * to implicitly kick in. */
+ return p->children().indexOf(const_cast<TreeItem *>(this));
+ }
+ else
+ return -1;
+}
+
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TreeItem.h b/tests/auto/xmlpatternsxqts/lib/TreeItem.h
new file mode 100644
index 0000000..318c123
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TreeItem.h
@@ -0,0 +1,155 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_TreeItem_H
+#define PatternistSDK_TreeItem_H
+
+#include <QObject>
+
+#include "Global.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QVariant;
+template<typename T> class QList;
+template<typename T> class QPointer;
+
+namespace QPatternistSDK
+{
+ /**
+ * @short TreeItem is a node in a hierachial structure and is used together
+ * with TreeModel.
+ *
+ * TreeItem is abstract base class. Instances of sub-classes of TreeItem
+ * can be used with TreeModel in order to use hierarchial data in Qt's
+ * model/view framework.
+ *
+ * TreeItem is a QObject in order to be able to be used with QPointer.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @see TreeModel
+ * @ingroup PatternistSDK
+ */
+ class Q_PATTERNISTSDK_EXPORT TreeItem : public QObject
+ {
+ Q_OBJECT
+ public:
+ typedef QList<QPointer<TreeItem> > List;
+
+ virtual ~TreeItem() {}
+ virtual void appendChild(TreeItem *item) = 0;
+ virtual TreeItem *child(const unsigned int row) const = 0;
+ virtual unsigned int childCount() const = 0;
+ virtual TreeItem *parent() const = 0;
+
+ virtual TreeItem::List children() const = 0;
+ virtual int columnCount() const = 0;
+
+ /**
+ * Determines the position among the children of
+ * this TreeItem's parent. This is done by introspecting the result
+ * of children().
+ */
+ int row() const;
+
+ virtual QVariant data(const Qt::ItemDataRole role, int column) const = 0;
+
+ Q_SIGNALS:
+ /**
+ * Emitted whenever this item changed. This is used for keeping
+ * views in synchronization with the item model which houses
+ * this item.
+ *
+ * @param item the item which changed. That is, this TreeItem.
+ */
+ void changed(TreeItem *item);
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TreeModel.cpp b/tests/auto/xmlpatternsxqts/lib/TreeModel.cpp
new file mode 100644
index 0000000..d9ba200
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TreeModel.cpp
@@ -0,0 +1,220 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QtDebug>
+
+#include "TestContainer.h"
+
+#include "TreeModel.h"
+
+using namespace QPatternistSDK;
+
+TreeModel::TreeModel(const QStringList columnData,
+ QObject *p) : QAbstractItemModel(p),
+ m_root(0),
+ m_columnData(columnData)
+{
+}
+
+TreeModel::~TreeModel()
+{
+}
+
+QVariant TreeModel::data(const QModelIndex &idx, int role) const
+{
+ if(!idx.isValid())
+ return QVariant();
+
+ TreeItem *item = static_cast<TreeItem *>(idx.internalPointer());
+ Q_ASSERT(item);
+
+ return item->data(static_cast<Qt::ItemDataRole>(role), idx.column());
+}
+
+QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if(orientation == Qt::Horizontal && role == Qt::DisplayRole)
+ return m_columnData.value(section);
+
+ return QVariant();
+}
+
+void TreeModel::childChanged(TreeItem *)
+{
+ layoutChanged();
+}
+
+QModelIndex TreeModel::index(int row, int column, const QModelIndex &p) const
+{
+ const int c = columnCount(p);
+
+ if(row < 0 || column < 0 || column >= c)
+ return QModelIndex();
+
+ TreeItem *parentItem;
+
+ if(p.isValid())
+ parentItem = static_cast<TreeItem *>(p.internalPointer());
+ else
+ parentItem = m_root;
+
+ if(!parentItem)
+ return QModelIndex();
+
+ TreeItem *childItem = parentItem->child(row);
+
+ if(childItem)
+ return createIndex(row, column, childItem);
+ else
+ return QModelIndex();
+}
+
+QModelIndex TreeModel::parent(const QModelIndex &idx) const
+{
+ if(!idx.isValid())
+ return QModelIndex();
+
+ TreeItem *childItem = static_cast<TreeItem *>(idx.internalPointer());
+ Q_ASSERT(childItem);
+ TreeItem *parentItem = childItem->parent();
+
+ if(!parentItem || parentItem == m_root)
+ return QModelIndex();
+
+ Q_ASSERT(parentItem);
+ return createIndex(parentItem->row(), 0, parentItem);
+}
+
+Qt::ItemFlags TreeModel::flags(const QModelIndex &idx) const
+{
+ /* Not sure about this code. */
+ if(!idx.isValid())
+ return Qt::ItemFlags();
+
+ return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+}
+
+int TreeModel::rowCount(const QModelIndex &p) const
+{
+ if(p.column() > 0)
+ return 0;
+
+ const TreeItem *parentItem;
+
+ if(p.isValid())
+ parentItem = static_cast<TreeItem *>(p.internalPointer());
+ else
+ {
+ if(m_root)
+ parentItem = m_root;
+ else
+ return 0;
+ }
+
+ return parentItem->childCount();
+}
+
+int TreeModel::columnCount(const QModelIndex &p) const
+{
+ if(p.isValid())
+ return static_cast<TreeItem *>(p.internalPointer())->columnCount();
+ else
+ return m_columnData.count();
+}
+
+TreeItem *TreeModel::root() const
+{
+ return m_root;
+}
+
+void TreeModel::setRoot(TreeItem *r)
+{
+ TreeItem *const oldRoot = m_root;
+ m_root = r;
+
+ if(m_root)
+ connect(r, SIGNAL(changed(TreeItem *)), SLOT(childChanged(TreeItem *)));
+ reset(); /* Notify views that we have radically changed. */
+ delete oldRoot;
+}
+
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/TreeModel.h b/tests/auto/xmlpatternsxqts/lib/TreeModel.h
new file mode 100644
index 0000000..a85b06b
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/TreeModel.h
@@ -0,0 +1,151 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_TreeModel_H
+#define PatternistSDK_TreeModel_H
+
+#include <QAbstractItemModel>
+#include <QObject>
+#include <QPointer>
+#include <QStringList>
+
+#include "Global.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ class TreeItem;
+
+ /**
+ * @short TreeItem is a generic QAbstractItemModel tailored for
+ * representing hierarchial data.
+ *
+ * TreeModel is an item model in Qt's model/view framework. Its
+ * data consists of TreeItem instances.
+ *
+ * @see TreeItem
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT TreeModel : public QAbstractItemModel
+ {
+ Q_OBJECT
+ public:
+ TreeModel(const QStringList columnData, QObject *parent);
+ virtual ~TreeModel();
+
+ virtual QVariant data(const QModelIndex &index, int role) const;
+ virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+ virtual QVariant headerData(int section,
+ Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const;
+ virtual QModelIndex index(int row,
+ int column,
+ const QModelIndex &parent = QModelIndex()) const;
+ virtual QModelIndex parent(const QModelIndex &index) const;
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
+
+ TreeItem *root() const;
+ /**
+ * Sets @p root to the new root, and deletes the old.
+ */
+ void setRoot(TreeItem *root);
+
+ protected Q_SLOTS:
+ void childChanged(TreeItem *child);
+
+ private:
+ QPointer<TreeItem> m_root;
+ const QStringList m_columnData;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/Worker.cpp b/tests/auto/xmlpatternsxqts/lib/Worker.cpp
new file mode 100644
index 0000000..9fd7b1d
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/Worker.cpp
@@ -0,0 +1,299 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QDir>
+#include <QEventLoop>
+#include <QPair>
+#include <QtDebug>
+
+#include "ExitCode.h"
+
+#include "Worker.h"
+
+using namespace QPatternistSDK;
+
+const char *const Worker::m_indent = " ";
+
+Worker::Worker(QEventLoop &ev,
+ const QFileInfo &baseline,
+ const QFileInfo &result) : m_finishedCount(0)
+ , m_baselineFile(baseline)
+ , m_resultFile(result)
+ , m_eventLoop(ev)
+{
+}
+
+void Worker::list(QTextStream &out, const QString &msg, QStringList &list)
+{
+ Q_ASSERT(!msg.isEmpty());
+
+ if(list.isEmpty())
+ return;
+
+ list.sort(); /* Make it pretty, and easy to read. */
+
+ out << msg << ":\n";
+
+ const QStringList::const_iterator end(list.constEnd());
+ QStringList::const_iterator it(list.constBegin());
+
+ for(; it != end; ++it)
+ out << m_indent << qPrintable(*it) << '\n';
+}
+
+static inline int count(const ResultThreader::Hash &list, const TestResult::Status stat)
+{
+ const ResultThreader::Hash::const_iterator end(list.constEnd());
+ ResultThreader::Hash::const_iterator it(list.constBegin());
+ int result = 0;
+
+ for(; it != end; ++it)
+ {
+ if(it.value() == stat)
+ ++result;
+ }
+
+ return result;
+}
+
+void Worker::threadFinished()
+{
+ ++m_finishedCount;
+ Q_ASSERT(m_finishedCount == 1 || m_finishedCount == 2);
+
+ const ResultThreader *const handler = static_cast<ResultThreader *>(sender());
+ Q_ASSERT(handler);
+
+ switch(handler->type())
+ {
+ case ResultThreader::Baseline:
+ {
+ m_baseline = handler->result();
+ break;
+ }
+ case ResultThreader::Result:
+ m_result = handler->result();
+ }
+
+ if(m_finishedCount == 1) /* One thread's missing. */
+ return;
+
+ /* Ok, both threads have now finished, and we got their results in m_result and m_baseline. */
+
+ /* No matter how this function exits, we want to delete this Worker. */
+ deleteLater();
+
+ ResultThreader::Hash::const_iterator itA(m_result.constBegin());
+ ResultThreader::Hash::const_iterator itB(m_baseline.constBegin());
+ const ResultThreader::Hash::const_iterator endA(m_result.constEnd());
+ const ResultThreader::Hash::const_iterator endB(m_baseline.constEnd());
+ const int baselineCount = m_baseline.count();
+ const int resultCount = m_result.count();
+
+ /* If you want useful output, change the QTextStream to use stderr. */
+ //QTextStream err(stderr);
+ QByteArray out;
+ QTextStream err(&out);
+
+ if(resultCount < baselineCount)
+ {
+ err << qPrintable(QString(QLatin1String("WARNING: Test result contains %1 reports, "
+ "but the baseline contains %2, a DECREASE "
+ "of %3 tests.\n"))
+ .arg(resultCount)
+ .arg(baselineCount)
+ .arg(resultCount - baselineCount));
+ }
+ else if(resultCount > baselineCount)
+ {
+ err << qPrintable(QString(QLatin1String("NOTE: The number of tests run is more than what "
+ "the baseline specifies. Run was %1 test cases, the "
+ "baseline specifies %2; an increase of %3 tests.\n"))
+ .arg(resultCount)
+ .arg(baselineCount)
+ .arg(resultCount - baselineCount));
+ }
+
+ for(; itA != endA; ++itA)
+ {
+ const TestResult::Status result = itA.value();
+ const TestResult::Status baseline = m_baseline.value(itA.key());
+
+ if(result == baseline) /* We have no change. */
+ {
+ if(result == TestResult::NotTested)
+ m_notTested.append(itA.key());
+ else
+ continue;
+ }
+ else if(baseline == TestResult::Pass && result == TestResult::Fail)
+ m_unexpectedFailures.append(itA.key());
+ else if(baseline == TestResult::Fail && result == TestResult::Pass)
+ m_unexpectedPasses.append(itA.key());
+ }
+
+ list(err, QLatin1String("Not tested"), m_notTested);
+ list(err, QLatin1String("Unexpected failures"), m_unexpectedFailures);
+ list(err, QLatin1String("Unexpected passes"), m_unexpectedPasses);
+
+ err << "SUMMARY:\n";
+ typedef QPair<QString, int> Info;
+ typedef QList<Info> InfoList;
+ InfoList info;
+
+ const int totFail = count(m_result, TestResult::Fail);
+ const int totPass = count(m_result, TestResult::Pass);
+ const int total = resultCount;
+ const int notTested = m_notTested.count();
+ const int percentage = int((static_cast<double>(totPass) / total) * 100);
+
+ Q_ASSERT_X(percentage >= 0 && percentage <= 100, Q_FUNC_INFO,
+ qPrintable(QString(QLatin1String("Percentage was: %1")).arg(percentage)));
+
+ info.append(Info(QLatin1String("Total"), total));
+ info.append(Info(QLatin1String("Failures"), totFail));
+ info.append(Info(QLatin1String("Passes"), totPass));
+ info.append(Info(QLatin1String("Not tested"), notTested));
+ info.append(Info(QLatin1String("Pass percentage(%)"), percentage));
+ info.append(Info(QLatin1String("Unexpected failures"), m_unexpectedFailures.count()));
+ info.append(Info(QLatin1String("Unexpected passes"), m_unexpectedPasses.count()));
+
+ const InfoList::const_iterator end(info.constEnd());
+ InfoList::const_iterator it(info.constBegin());
+
+ /* List the statistics nicely in a row with padded columns. */
+ for(; it != end; ++it)
+ {
+ const QString result((((*it).first) + QLatin1Char(':')).leftJustified(22, QLatin1Char(' ')));
+ err << m_indent << qPrintable(result) << (*it).second << '\n';
+ }
+
+ if(!m_unexpectedFailures.isEmpty())
+ {
+ err << "FAILURE: Regressions discovered, baseline was not updated.\n";
+ err.flush();
+ QTextStream(stderr) << out;
+ m_eventLoop.exit(ExitCode::Regression);
+ return;
+ }
+ else if(m_unexpectedPasses.isEmpty() && baselineCount == resultCount)
+ {
+ err << "Result was identical to the baseline, baseline was not updated.\n";
+ m_eventLoop.exit(ExitCode::Success);
+ return;
+ }
+
+ /* Ok, we got unexpected successes and no regressions: let's update the baseline. */
+
+ QFile resultFile(m_resultFile.absoluteFilePath());
+
+ /* Remove the old file, otherwise QFile::copy() will fail. */
+ QDir baselineDir(m_baselineFile.absolutePath());
+ baselineDir.remove(m_baselineFile.fileName());
+
+ if(resultFile.copy(m_baselineFile.absoluteFilePath()))
+ {
+ /* Give a detailed message of what's going on. */
+ if(resultCount > baselineCount)
+ err << "More tests was run than specified in the baseline, updating the baseline.\n";
+ else
+ err << "Improvement, the baseline was updated.\n";
+
+ /* We actually flag this as an error, because the new baseline must be submitted. */
+ err.flush();
+ QTextStream(stderr) << out;
+ m_eventLoop.exit(ExitCode::Regression);
+ return;
+ }
+ else
+ {
+ err << qPrintable(QString(QLatin1String("Encountered error when updating "
+ "the baseline: %1\n"))
+ .arg(resultFile.errorString()));
+ err.flush();
+ QTextStream(stderr) << out;
+ m_eventLoop.exit(ExitCode::WriteError);
+ return;
+ }
+}
+
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/Worker.h b/tests/auto/xmlpatternsxqts/lib/Worker.h
new file mode 100644
index 0000000..df59892
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/Worker.h
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_Worker_H
+#define PatternistSDK_Worker_H
+
+#include <QFileInfo>
+#include <QList>
+#include <QObject>
+#include <QStringList>
+
+#include "ResultThreader.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QEventLoop;
+
+namespace QPatternistSDK
+{
+ /**
+ * @short Gets notified when the ResultThreader threads are
+ * finished, and output summaries and adjusts a baseline.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup PatternistSDK
+ */
+ class Q_PATTERNISTSDK_EXPORT Worker : public QObject
+ {
+ Q_OBJECT
+ public:
+ Worker(QEventLoop &e,
+ const QFileInfo &baseline,
+ const QFileInfo &result);
+
+ public Q_SLOTS:
+ void threadFinished();
+
+ private:
+ static inline void list(QTextStream &out, const QString &msg, QStringList &list);
+
+ qint8 m_finishedCount;
+ const QFileInfo m_baselineFile;
+ const QFileInfo m_resultFile;
+ ResultThreader::Hash m_result;
+ ResultThreader::Hash m_baseline;
+ ResultThreader::Hash m_summary;
+ QStringList m_unexpectedPasses;
+ QStringList m_unexpectedFailures;
+ QStringList m_notTested;
+ QEventLoop & m_eventLoop;
+ static const char *const m_indent;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/XMLWriter.cpp b/tests/auto/xmlpatternsxqts/lib/XMLWriter.cpp
new file mode 100644
index 0000000..9911d40
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/XMLWriter.cpp
@@ -0,0 +1,710 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QCoreApplication>
+#include <QDateTime>
+#include <QIODevice>
+#include <QList>
+#include <QPair>
+#include <QStack>
+#include <QtDebug>
+
+#include "XMLWriter.h"
+
+/* Issues:
+ * - Switch to Qt's d-pointer semantics, if in Qt.
+ * - Remove namespace(PatternistSDK), and change name, if in Qt.
+ * - Is it really necessary to pass the tag name to endElement()?
+ * - Could it be of interest to let the user control the encoding? Are those cases common
+ * enough to justify support in Qt? Using anything but UTF-8 or UTF-16
+ * means asking for trouble, from an interoperability perspective.
+ */
+
+/* Design rationalis, comments:
+ *
+ * - The class is called XMLWriter to harvest familarity by being consistent with
+ * Java's XMLWriter class. If XMLWriter is moved to Qt, the name QXmlWriter is perhaps suitable.
+ * - The class does not handle indentation because the "do one thing well"-principle is
+ * in use. XMLWriter should be fast and not assume a certain idea of indentation. Indentation
+ * should be implemented in a standalone QXmlContentHandler that performs the indentation and
+ * "has a" QXmlContentHandler which it in addition calls, and by that proxying/piping another
+ * QXmlContentHandler(which most likely is an XMLWriter). Thus, achieving a modularized,
+ * flexibly approach to indentation. A reason is also that indentation is very subjective.
+ * The indenter class should probably be called XMLIndenter/QXmlIndenter.
+ * - It could be of interest to implement QXmlDTDHandler such that it would be possible to serialize
+ * DTDs. Must be done before BC becomes significant.
+ * - I think the most valuable of this class is its Q_ASSERT tests. Many programmers have severe problems
+ * producing XML, and the tests helps them catching their mistakes. They therefore promote
+ * interoperability. Do not remove them. If any are wrong, fix them instead.
+ */
+
+using namespace QPatternistSDK;
+
+/**
+ * A namespace binding, prefix/namespace URI.
+ */
+typedef QPair<QString, QString> NSBinding;
+typedef QList<NSBinding> NSBindingList;
+
+#ifdef QT_NO_DEBUG
+# define DEBUG_CODE(code)
+#else
+# define DEBUG_CODE(code) code
+#endif
+
+class XMLWriter::Private
+{
+public:
+ inline Private(QIODevice *devP) : insideCDATA(false),
+ addModificationNote(false),
+ dev(devP)
+ {
+ hasContentStack.push(true);
+ }
+
+#ifdef QT_NO_DEBUG
+ inline void validateQName(const QString &) const
+ {
+ }
+
+ inline void verifyNS(const QString &) const
+ {
+ }
+#else
+ /**
+ * Simple test of that @p name is an acceptable QName.
+ */
+ inline void validateQName(const QString &name)
+ {
+ Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO,
+ "An XML name cannot be empty.");
+ Q_ASSERT_X(!name.endsWith(QLatin1Char(':')), Q_FUNC_INFO,
+ "An XML name cannot end with a colon(QLatin1Char(':')).");
+ Q_ASSERT_X(!name.contains(QRegExp(QLatin1String("[ \t\n]"))), Q_FUNC_INFO,
+ "An XML name cannot contain whitespace.");
+ }
+
+ /**
+ * Ensures that the prefix of @p qName is declared.
+ */
+ inline void verifyNS(const QString &qName) const
+ {
+ const QString prefix(qName.left(qName.indexOf(QLatin1Char(':'))));
+
+ if(qName.contains(QLatin1Char(':')) && prefix != QLatin1String("xml"))
+ {
+ bool foundPrefix = false;
+ const QStack<NSBindingList>::const_iterator end(namespaceTracker.constEnd());
+ QStack<NSBindingList>::const_iterator it(namespaceTracker.constBegin());
+
+ for(; it != end; ++it)
+ {
+ const NSBindingList::const_iterator lend((*it).constEnd());
+ NSBindingList::const_iterator lit((*it).constBegin());
+
+ for(; lit != lend; ++it)
+ {
+ if((*lit).first == prefix)
+ {
+ foundPrefix = true;
+ break;
+ }
+ }
+ if(foundPrefix)
+ break;
+ }
+
+ Q_ASSERT_X(foundPrefix, "XMLWriter::startElement()",
+ qPrintable(QString::fromLatin1("The prefix %1 is not declared. All prefixes "
+ "except 'xml' must be declared.").arg(prefix)));
+ }
+ }
+#endif
+
+ inline QString escapeElementContent(const QString &ch)
+ {
+ const int l = ch.length();
+ QString retval;
+
+ for(int i = 0; i != l; ++i)
+ {
+ const QChar c(ch.at(i));
+
+ if(c == QLatin1Char(QLatin1Char('&')))
+ retval += QLatin1String("&amp;");
+ else if(c == QLatin1Char(QLatin1Char('<')))
+ retval += QLatin1String("&lt;");
+ else
+ retval += c;
+ }
+
+ return retval;
+ }
+
+ inline QString escapeAttributeContent(const QString &ch)
+ {
+ const int l = ch.length();
+ QString retval;
+
+ for(int i = 0; i != l; ++i)
+ {
+ const QChar c(ch.at(i));
+
+ /* We don't have to escape '\'' because we use '\"' as attribute delimiter. */
+ if(c == QLatin1Char('&'))
+ retval += QLatin1String("&amp;");
+ else if(c == QLatin1Char('<'))
+ retval += QLatin1String("&lt;");
+ else if(c == QLatin1Char('"'))
+ retval += QLatin1String("&quot;");
+ else
+ retval += c;
+ }
+
+ return retval;
+ }
+
+ inline QString escapeCDATAContent(const QString &ch)
+ {
+ const int l = ch.length();
+ QString retval;
+ qint8 atEnd = 0;
+
+ for(int i = 0; i != l; ++i)
+ {
+ const QChar c(ch.at(i));
+
+ /* Escape '>' if in "]]>" */
+ if(c == QLatin1Char(']'))
+ {
+ if(atEnd == 0 || atEnd == 1)
+ ++atEnd;
+ else
+ atEnd = 0;
+
+ retval += QLatin1Char(']');
+ }
+ else if(c == QLatin1Char('>'))
+ {
+ if(atEnd == 2)
+ retval += QLatin1String("&gt;");
+ else
+ {
+ atEnd = 0;
+ retval += QLatin1Char('>');
+ }
+ }
+ else
+ retval += c;
+ }
+
+ return retval;
+ }
+
+ /**
+ * We wrap dev in this function such that we can deploy the Q_ASSERT_X
+ * macro in each place it's used.
+ */
+ inline QIODevice *device() const
+ {
+ Q_ASSERT_X(dev, Q_FUNC_INFO,
+ "No device specified for XMLWriter; one must be specified with "
+ "setDevice() or via the constructor before XMLWriter can be used.");
+ return dev;
+ }
+
+ /**
+ * @returns true on success, otherwise false
+ */
+ inline bool serialize(const QString &data)
+ {
+ const QByteArray utf8(data.toUtf8());
+
+ return device()->write(utf8) == utf8.size();
+ }
+
+ /**
+ * @returns true on success, otherwise false
+ */
+ inline bool serialize(const char data)
+ {
+ return device()->putChar(data);
+ }
+
+ /**
+ * @returns true on success, otherwise false
+ */
+ inline bool serialize(const char *data)
+ {
+ return device()->write(data) == qstrlen(data);
+ }
+
+ inline bool hasElementContent() const
+ {
+ return hasContentStack.top();
+ }
+
+ inline void handleElement()
+ {
+ if(!hasElementContent())
+ serialize('>');
+
+ /* This element is content for the parent. */
+ hasContentStack.top() = true;
+ }
+
+ NSBindingList namespaces;
+ bool insideCDATA;
+ bool addModificationNote;
+ QString msg;
+ QIODevice *dev;
+ QStack<bool> hasContentStack;
+ QString errorString;
+ DEBUG_CODE(QStack<QString> tags;)
+ DEBUG_CODE(QStack<NSBindingList> namespaceTracker;)
+};
+
+/**
+ * Reduces complexity. The empty else clause is for avoiding mess when macro
+ * is used in the 'then' branch of an if clause, which is followed by an else clause.
+ */
+#define serialize(string) if(!d->serialize(string)) \
+ { \
+ d->errorString = d->device()->errorString(); \
+ return false; \
+ } \
+ else
+
+XMLWriter::XMLWriter(QIODevice *outStream) : d(new Private(outStream))
+{
+}
+
+XMLWriter::~XMLWriter()
+{
+ delete d;
+}
+
+bool XMLWriter::startDocument()
+{
+ if(!device()->isOpen() && !device()->open(QIODevice::WriteOnly))
+ return false;
+
+ if(d->addModificationNote)
+ {
+ if(d->msg.isNull())
+ {
+ d->msg = QString::fromLatin1("NOTE: This file was automatically generated "
+ "by %1 at %2. All changes to this file will be lost.")
+ .arg(QCoreApplication::instance()->applicationName(),
+ QDateTime::currentDateTime().toString());
+ }
+ if(!comment(d->msg))
+ return false;
+
+ serialize('\n');
+ }
+
+ serialize(QLatin1String("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"));
+
+ return true;
+}
+
+bool XMLWriter::startElement(const QString &/*namespaceURI*/,
+ const QString &/*localName*/,
+ const QString &qName,
+ const QXmlAttributes &atts)
+{
+ return startElement(qName, atts);
+}
+
+bool XMLWriter::startElement(const QString &qName,
+ const QXmlAttributes &atts)
+{
+ Q_ASSERT_X(!d->insideCDATA, Q_FUNC_INFO,
+ "Only characters() can be received when inside CDATA.");
+ Q_ASSERT_X(!qName.startsWith(QLatin1String("xmlns")), Q_FUNC_INFO,
+ "startElement should not be used for declaring prefixes, "
+ "use startPrefixMapping() for that.");
+
+ d->validateQName(qName);
+ d->verifyNS(qName);
+
+ d->handleElement();
+
+ serialize('<');
+ serialize(qName);
+
+ DEBUG_CODE(d->tags.push(qName));
+ DEBUG_CODE(d->namespaceTracker.push(d->namespaces));
+
+ /* Add namespace declarations. */
+ const NSBindingList::const_iterator end(d->namespaces.constEnd());
+ NSBindingList::const_iterator it(d->namespaces.constBegin());
+
+ for(; it != end; ++it)
+ {
+ if((*it).first.isEmpty())
+ serialize(" xmlns=");
+ else
+ {
+ serialize(" xmlns:");
+ serialize((*it).first);
+ serialize('=');
+ }
+
+ serialize('"');
+ serialize(d->escapeElementContent((*it).second));
+ serialize('"');
+ }
+ d->namespaces.clear();
+
+ const int c = atts.count();
+
+ /* Serialize attributes. */
+ for(int i = 0; i != c; ++i)
+ {
+ d->validateQName(atts.qName(i));
+ d->verifyNS(atts.qName(i));
+
+ serialize(' ');
+ serialize(atts.qName(i));
+ serialize("=\"");
+ serialize(d->escapeAttributeContent(atts.value(i)));
+ serialize('"');
+ }
+
+ d->hasContentStack.push(false);
+ return true;
+}
+
+bool XMLWriter::endElement(const QString &/*namespaceURI*/,
+ const QString &/*localName*/,
+ const QString &qName)
+{
+ return endElement(qName);
+}
+
+bool XMLWriter::endElement(const QString &qName)
+{
+ Q_ASSERT_X(!d->insideCDATA, Q_FUNC_INFO,
+ "Only characters() can be received when inside CDATA.");
+ Q_ASSERT_X(d->tags.pop() == qName, Q_FUNC_INFO,
+ "The element tags are not balanced, the produced XML is invalid.");
+
+ DEBUG_CODE(d->namespaceTracker.pop());
+
+ /* "this" element is content for our parent, so ensure hasElementContent is true. */
+
+ if(d->hasElementContent())
+ {
+ serialize(QLatin1String("</"));
+ serialize(qName);
+ serialize('>');
+ }
+ else
+ serialize(QLatin1String("/>"));
+
+ d->hasContentStack.pop();
+
+ return true;
+}
+
+bool XMLWriter::startPrefixMapping(const QString &prefix, const QString &uri)
+{
+ Q_ASSERT_X(!d->insideCDATA, Q_FUNC_INFO,
+ "Only characters() can be received when inside CDATA.");
+ Q_ASSERT_X(prefix.toLower() != QLatin1String("xml") ||
+ (prefix.toLower() == QLatin1String("xml") &&
+ (uri == QLatin1String("http://www.w3.org/TR/REC-xml-names/") ||
+ uri.isEmpty())),
+ Q_FUNC_INFO,
+ "The prefix 'xml' can only be bound to the namespace "
+ "\"http://www.w3.org/TR/REC-xml-names/\".");
+ Q_ASSERT_X(prefix.toLower() != QLatin1String("xml") &&
+ uri != QLatin1String("http://www.w3.org/TR/REC-xml-names/"),
+ Q_FUNC_INFO,
+ "The namespace \"http://www.w3.org/TR/REC-xml-names/\" can only be bound to the "
+ "\"xml\" prefix.");
+
+ d->namespaces.append(qMakePair(prefix, uri));
+ return true;
+}
+
+bool XMLWriter::processingInstruction(const QString &target,
+ const QString &data)
+{
+ Q_ASSERT_X(target.toLower() != QLatin1String("xml"), Q_FUNC_INFO,
+ "A processing instruction cannot have the name xml in any "
+ "capitalization, because it is reserved.");
+ Q_ASSERT_X(!data.contains(QLatin1String("?>")), Q_FUNC_INFO,
+ "The content of a processing instruction cannot contain the string \"?>\".");
+ Q_ASSERT_X(!d->insideCDATA, "XMLWriter::processingInstruction()",
+ "Only characters() can be received when inside CDATA.");
+
+ d->handleElement();
+
+ serialize(QLatin1String("<?"));
+ serialize(target);
+ serialize(' ');
+ serialize(data);
+ serialize(QLatin1String("?>"));
+ return true;
+}
+
+bool XMLWriter::characters(const QString &ch)
+{
+ Q_ASSERT_X(d->tags.count() >= 1, Q_FUNC_INFO,
+ "Text nodes can only appear inside elements(no elements sent).");
+ d->handleElement();
+
+ if(d->insideCDATA)
+ serialize(d->escapeCDATAContent(ch));
+ else
+ serialize(d->escapeElementContent(ch));
+
+ return true;
+}
+
+bool XMLWriter::comment(const QString &ch)
+{
+ Q_ASSERT_X(!d->insideCDATA, Q_FUNC_INFO,
+ "Only characters() can be received when inside CDATA.");
+ Q_ASSERT_X(!ch.contains(QLatin1String("--")), Q_FUNC_INFO,
+ "XML comments may not contain double-hyphens(\"--\").");
+ Q_ASSERT_X(!ch.endsWith(QLatin1Char('-')), Q_FUNC_INFO,
+ "XML comments cannot end with a hyphen, \"-\"(add a space, for example).");
+ /* A comment starting with "<!---" is ok. */
+
+ d->handleElement();
+
+ serialize(QLatin1String("<!--"));
+ serialize(ch);
+ serialize(QLatin1String("-->"));
+
+ return true;
+}
+
+bool XMLWriter::startCDATA()
+{
+ Q_ASSERT_X(d->insideCDATA, Q_FUNC_INFO,
+ "startCDATA() has already been called.");
+ Q_ASSERT_X(d->tags.count() >= 1, Q_FUNC_INFO,
+ "CDATA sections can only appear inside elements(no elements sent).");
+ d->insideCDATA = true;
+ serialize(QLatin1String("<![CDATA["));
+ return true;
+}
+
+bool XMLWriter::endCDATA()
+{
+ d->insideCDATA = false;
+ serialize("]]>");
+ return true;
+}
+
+bool XMLWriter::startDTD(const QString &name,
+ const QString &publicId,
+ const QString &systemId)
+{
+ Q_ASSERT_X(!d->insideCDATA, Q_FUNC_INFO,
+ "Only characters() can be received when inside CDATA.");
+ Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO,
+ "The DOCTYPE name cannot be empty.");
+ Q_ASSERT_X(d->tags.isEmpty() && d->namespaces.isEmpty(), Q_FUNC_INFO,
+ "No content such as namespace declarations or elements can be serialized "
+ "before the DOCTYPE declaration, the XML is invalid.");
+ Q_ASSERT_X(!publicId.contains(QLatin1Char('"')), Q_FUNC_INFO,
+ "The PUBLIC ID cannot contain quotes('\"').");
+ Q_ASSERT_X(!systemId.contains(QLatin1Char('"')), Q_FUNC_INFO,
+ "The SYSTEM ID cannot contain quotes('\"').");
+
+ serialize(QLatin1String("<!DOCTYPE "));
+ serialize(name);
+
+ if(!publicId.isEmpty())
+ {
+ Q_ASSERT_X(!systemId.isEmpty(), Q_FUNC_INFO,
+ "When a public identifier is specified, a system identifier "
+ "must also be specified in order to produce valid XML.");
+ serialize(" PUBLIC \"");
+ serialize(publicId);
+ serialize('"');
+ }
+
+ if(!systemId.isEmpty())
+ {
+ if(publicId.isEmpty())
+ serialize(" SYSTEM");
+
+ serialize(" \"");
+ serialize(systemId);
+ serialize('"');
+ }
+
+ return true;
+}
+
+bool XMLWriter::endDTD()
+{
+ Q_ASSERT_X(d->tags.isEmpty() && d->namespaces.isEmpty(), Q_FUNC_INFO,
+ "Content such as namespace declarations or elements cannot occur inside "
+ "the DOCTYPE declaration, the XML is invalid.");
+ serialize(QLatin1String(">\n"));
+ return true;
+}
+
+bool XMLWriter::startEntity(const QString &)
+{
+ return true;
+}
+
+bool XMLWriter::endEntity(const QString &)
+{
+ return true;
+}
+
+void XMLWriter::setMessage(const QString &msg)
+{
+ d->msg = msg;
+}
+
+QString XMLWriter::modificationMessage() const
+{
+ return d->msg;
+}
+
+bool XMLWriter::endDocument()
+{
+ Q_ASSERT_X(d->tags.isEmpty(), Q_FUNC_INFO,
+ "endDocument() called before all elements were closed with endElement().");
+ d->device()->close();
+ return true;
+}
+
+QString XMLWriter::errorString() const
+{
+ return d->errorString;
+}
+
+bool XMLWriter::ignorableWhitespace(const QString &ch)
+{
+ return characters(ch);
+}
+
+bool XMLWriter::endPrefixMapping(const QString &)
+{
+ /* Again, should we do something with this? */
+ return true;
+}
+
+bool XMLWriter::skippedEntity(const QString &)
+{
+ return true;
+}
+
+void XMLWriter::setDocumentLocator(QXmlLocator *)
+{
+}
+
+QIODevice *XMLWriter::device() const
+{
+ return d->dev;
+}
+
+void XMLWriter::setDevice(QIODevice *dev)
+{
+ d->dev = dev;
+}
+
+void XMLWriter::setAddMessage(const bool toggle)
+{
+ d->addModificationNote = toggle;
+}
+
+bool XMLWriter::addModificationMessage() const
+{
+ return d->addModificationNote;
+}
+
+#undef serialize
+// vim: et:ts=4:sw=4:sts=4
+
diff --git a/tests/auto/xmlpatternsxqts/lib/XMLWriter.h b/tests/auto/xmlpatternsxqts/lib/XMLWriter.h
new file mode 100644
index 0000000..e8f100e
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/XMLWriter.h
@@ -0,0 +1,444 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_XMLWriter_H
+#define PatternistSDK_XMLWriter_H
+
+#include "Global.h"
+
+#include <QtXml/QXmlContentHandler>
+#include <QtXml/QXmlLexicalHandler>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QIODevice;
+
+namespace QPatternistSDK
+{
+ /**
+ * @short Serializes a stream of SAX events into XML, sent to a QIODevice.
+ *
+ * XMLWriter is a fast and simple XML serializer which takes care of
+ * all the low level details of well-formedness and character escaping, allowing
+ * the user to focus on higher level issues and increasing the chances of producing
+ * valid, interoperable XML.
+ *
+ * The content XMLWriter produces is sent to a QIODevice, which is either
+ * specified in XMLWriter's constructor or via setDevice(). If writing to
+ * the device fails, the content functions such as startElement() returns @c false.
+ *
+ * XMLWriter sub-classes QXmlContentHandler meaning it can serialize content
+ * from any code that produces SAX events. The class can also be used manually,
+ * by calling startElement(), endCDATA(), and so forth.
+ *
+ * XMLWriter cannot be used to serialize multiple documents. One instance per
+ * document must be used.
+ *
+ * XMLWriter takes care of escaping content into character references as necessary. Thus,
+ * it should not be done manually. In fact, it would most likely
+ * result in invalid XML or an unintended result. XMLWriter always serializes into UTF-8.
+ *
+ * When compiled in debug mode, XMLWriter contains several tests that helps
+ * ensuring that XMLWriter produces valid XML. Some of these tests ensures that:
+ *
+ * - The @c xmlns and @c xml prefixes are used properly
+ * - Content of comments and processing instructions is valid
+ * - Element, attribute and DOCTYPE names are sensible
+ * - Elements are properly nested and balanced
+ * - To some extent that things occur in the proper order. For example, that
+ * the document type definition isn't added inside an element
+ * - That namespaces prefixes are declared
+ *
+ * Not triggering XMLWriter's tests does not guarantee valid XML is produced,
+ * but they do help catching common mistakes and some of the corner cases in the
+ * specifications. When XMLWriter is compiled in release mode, these tests are not enabled
+ * and the error handling in effect is concerning writing to the QIODevice.
+ *
+ * Often it is of interest to add a note at the beginning of the file communicating
+ * it is auto-generated. setMessage() and setAddMessage() provides
+ * a convenient way of doing that.
+ *
+ * Namespace declarations are added with startPrefixMapping(), not by sending attributes
+ * with name <tt>xmlns:*</tt> to startElement().
+ *
+ * @see <a href="http://hsivonen.iki.fi/producing-xml/">HOWTO Avoid Being
+ * Called a Bozo When Producing XML</a>
+ * @see <a href="http://www.w3.org/TR/REC-xml/">Extensible Markup
+ * Language (XML) 1.0 (Third Edition)</a>
+ * @see <a href="http://www.w3.org/TR/REC-xml-names/">Namespaces in XML</a>
+ * @todo Replace this class with QXmlStreamWriter
+ * @author Frans Englich <fenglich@trolltech.com>
+ * @ingroup PatternistSDK
+ */
+ class Q_PATTERNISTSDK_EXPORT XMLWriter : public QXmlContentHandler
+ , public QXmlLexicalHandler
+ {
+ public:
+ /**
+ * Creates a XMLWriter which serializes its received events
+ * to @p outStream.
+ *
+ * @note XMLWriter does not claim ownership of @p outStream. Thus,
+ * @p outStream may not be destroyed as long as
+ * this XMLWriter instance uses it.
+ */
+ XMLWriter(QIODevice *outStream = 0);
+
+ virtual ~XMLWriter();
+
+ /**
+ * @returns @c true if opening the output device succeeds, otherwise @c false
+ */
+ virtual bool startDocument();
+
+ /**
+ * @returns @c false if failure occurs in writing to the QIODevice, otherwise
+ * @c true
+ */
+ virtual bool characters(const QString &ch);
+
+ /**
+ * Starts an element with name @p qName and attributes @p atts. The prefix
+ * in @p qName must first be declared with startPrefixMapping(), if it has one.
+ *
+ * A call to startElement() must always at some point be balanced with a call
+ * to endElement().
+ *
+ * To declare namespaces, don't put attributes with name <tt>xmlns:*</tt> in @p atts,
+ * but use startPrefixMapping().
+ */
+ virtual bool startElement(const QString &qName, const QXmlAttributes &atts = QXmlAttributes());
+
+ /**
+ *
+ * Behaves essentially as startElement(const QString &qName, const QXmlAttributes &atts). This
+ * function is used in conjunction with other SAX classes.
+ *
+ * The call:
+ *
+ * @code
+ * startElement(QString(), QString(), qName, atts);
+ * @endcode
+ *
+ * is equivalent to:
+ *
+ * @code
+ * startElement(qName, atts);
+ * @endcode
+ *
+ * @p namespaceURI and @p localName are not used. This function is
+ * used in conjunction with other SAX classes.
+ *
+ * @returns @c false if failure occurs in writing to the QIODevice, otherwise
+ * @c true
+ */
+ virtual bool startElement(const QString &namespaceURI,
+ const QString &localName,
+ const QString &qName,
+ const QXmlAttributes &atts);
+
+ /**
+ * Signals the end of an element with name @p qName. @p qName must
+ * be supplied.
+ *
+ * Calls to startElement() and endElement() must always be balanced.
+ *
+ * @returns @c false if failure occurs in writing to the QIODevice, otherwise
+ * @c true
+ */
+ virtual bool endElement(const QString &qName);
+
+ /**
+ * Behaves essentially as endElement(const QString &qName). This function
+ * is used when XMLWriter is used in SAX code.
+ *
+ * @p namespaceURI and @p localName are not used.
+ *
+ * The call:
+ *
+ * @code
+ * endElement(QString(), QString(), qName);
+ * @endcode
+ *
+ * is equivalent to:
+ *
+ * @code
+ * endElement(qName);
+ * @endcode
+ *
+ * @returns @c false if failure occurs in writing to the QIODevice, otherwise
+ * @c true
+ */
+ virtual bool endElement(const QString &namespaceURI,
+ const QString &localName,
+ const QString &qName);
+
+ /**
+ * A description of an error if it occurred. This is typically
+ * QIODevice::errorString(). If no error has occurred, an empty
+ * string is returned.
+ */
+ virtual QString errorString() const;
+
+ /**
+ * Starts a CDATA section. Content sent with characters() will not be escaped
+ * except for ">" if occurring in "]]>".
+ *
+ * @returns @c false if failure occurs in writing to the QIODevice, otherwise
+ * @c true
+ */
+ virtual bool startCDATA();
+
+ /**
+ * @returns @c false if failure occurs in writing to the QIODevice, otherwise
+ * @c true
+ */
+ virtual bool endCDATA();
+
+ /**
+ * Creates a document type definition.
+ *
+ * For example, the code snippet:
+ *
+ * @code
+ * writer.startDTD("html", "-//W3C//DTD XHTML 1.0 Strict//EN",
+ * "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
+ * writer.endDTD();
+ * @endcode
+ *
+ * would create:
+ * @verbatim
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+@endverbatim
+ *
+ * @note A system identifier must always be specified, but a public identifier may
+ * be left out.
+ *
+ * A call to startDTD() must be followed by a call to endDTD().
+ */
+ virtual bool startDTD(const QString &name,
+ const QString &publicId,
+ const QString &systemId);
+
+ /**
+ * Apart from closing the DTD, an new line is also added at end.
+ */
+ virtual bool endDTD();
+
+ /**
+ * Creates a processing instruction by name @p target, and content
+ * @p data.
+ *
+ * @returns @c false if failure occurs in writing to the QIODevice, otherwise
+ * @c true
+ */
+ virtual bool processingInstruction(const QString &target,
+ const QString &data);
+
+ /**
+ * Declares a namespace which maps @p prefix to @p namespaceURI. For example, the call:
+ *
+ * @code
+ * startPrefixMapping("xhtml", "http://www.w3.org/1999/xhtml");
+ * @endcode
+ *
+ * would result in:
+ *
+ * @code
+ * xmlns="http://www.w3.org/1999/xhtml"
+ * @endcode
+ */
+ virtual bool startPrefixMapping(const QString &prefix,
+ const QString &namespaceURI);
+
+ /**
+ * Creates a comment with content @p ch. @p ch is escaped, there's
+ * no need to do it manually. For example, calling comment() with @p ch
+ * set to "my comment", results in "<!--my comment-->" in the output.
+ *
+ * @note if @p ch contains double hyphen("--"), the produced XML will
+ * not be well formed.
+ *
+ * @returns @c false if failure occurs in writing to the QIODevice, otherwise
+ * @c true
+ */
+ virtual bool comment(const QString &ch);
+
+ virtual bool startEntity(const QString &name);
+ virtual bool endEntity(const QString &name);
+
+ /**
+ * Sets the message which is added as a comment if addModificationMessage()
+ * is set to @c true. If no message is specified and addModificationMessage()
+ * is set to @c true, a default message is used.
+ *
+ * @see modificationMessage(), setAddMessage()
+ */
+ virtual void setMessage(const QString &msg);
+
+ /**
+ * The message that is added at the beginning of the XML events
+ * in a comment node. If no modificationMessage is set via modificationMessage(),
+ * and addModificationMessage is set to @c true, this message will be used:
+ * "NOTE: This file was automatically generated by [the application name] at
+ * [the current date time]. All changes to this file will be lost."
+ *
+ * @see setMessage()
+ */
+ virtual QString modificationMessage() const;
+
+ /**
+ * Closes the QIODevice XMLWriter writes to.
+ */
+ virtual bool endDocument();
+
+ /**
+ * Serializes @p ch as if it was sent to characters().
+ *
+ * @returns @c false if failure occurs in writing to the QIODevice, otherwise
+ * @c true
+ */
+ virtual bool ignorableWhitespace(const QString &ch);
+
+ /**
+ * This function is not used by XMLWriter, but is implemented
+ * in order to satisfy QXmlContentHandler's interface.
+ */
+ virtual bool endPrefixMapping(const QString &prefix);
+
+ /**
+ * This function is not used by XMLWriter, but is implemented
+ * in order to satisfy QXmlContentHandler's interface.
+ */
+ virtual bool skippedEntity(const QString &name);
+
+ /**
+ * This function is not used by XMLWriter, but is implemented
+ * in order to satisfy QXmlContentHandler's interface.
+ */
+ virtual void setDocumentLocator(QXmlLocator *);
+
+ /**
+ * @returns the device XMLWriter writes its output to.
+ * XMLWriter does not own the device.
+ */
+ virtual QIODevice *device() const;
+
+ /**
+ * Sets the QIODevice XMLWriter writes to, to @p device. A device must be specified
+ * either via this function or in the constructor before XMLWriter is used.
+ *
+ * XMLWriter does not claim ownership of @p device.
+ */
+ virtual void setDevice(QIODevice *device);
+
+ /**
+ * Determines whether the modification message should be inserted as a comment
+ * before the document element. The message returned by modificationMessage() is used.
+ *
+ * If @p toggle is @c true, the message will be added, otherwise not.
+ */
+ virtual void setAddMessage(const bool toggle);
+
+ /**
+ * Tells whether a modification message will be added.
+ *
+ * @see setAddMessage(), modificationMessage()
+ */
+ virtual bool addModificationMessage() const;
+
+ private:
+ Q_DISABLE_COPY(XMLWriter)
+
+ class Private;
+ Private *d;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/XQTSTestCase.cpp b/tests/auto/xmlpatternsxqts/lib/XQTSTestCase.cpp
new file mode 100644
index 0000000..ecd8dd6
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/XQTSTestCase.cpp
@@ -0,0 +1,327 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QColor>
+#include <QFile>
+#include <QFileInfo>
+#include <QVariant>
+#include <QtDebug>
+
+#include "XQTSTestCase.h"
+
+using namespace QPatternistSDK;
+using namespace QPatternist;
+
+XQTSTestCase::XQTSTestCase(const Scenario scen,
+ TreeItem *p,
+ const QXmlQuery::QueryLanguage lang) : m_isXPath(false)
+ , m_scenario(scen)
+ , m_parent(p)
+ , m_lang(lang)
+{
+}
+
+XQTSTestCase::~XQTSTestCase()
+{
+ qDeleteAll(m_baseLines);
+}
+
+QVariant XQTSTestCase::data(const Qt::ItemDataRole role, int column) const
+{
+ if(role == Qt::DisplayRole)
+ {
+ if(column == 0)
+ return title();
+
+ const TestResult *const tr = testResult();
+ if(!tr)
+ {
+ if(column == 1)
+ return TestResult::displayName(TestResult::NotTested);
+ else
+ return QString();
+ }
+ const TestResult::Status status = tr->status();
+
+ switch(column)
+ {
+ case 1:
+ return status == TestResult::Pass ? QString(QChar::fromLatin1('1'))
+ : QString(QChar::fromLatin1('0'));
+ case 2:
+ return status == TestResult::Fail ? QString(QChar::fromLatin1('1'))
+ : QString(QChar::fromLatin1('0'));
+ default:
+ return QString();
+ }
+ }
+
+ if(role != Qt::BackgroundRole)
+ return QVariant();
+
+ const TestResult *const tr = testResult();
+
+ if(!tr)
+ {
+ if(column == 0)
+ return Qt::yellow;
+ else
+ return QVariant();
+ }
+
+ const TestResult::Status status = tr->status();
+
+ if(status == TestResult::NotTested || status == TestResult::Unknown)
+ return Qt::yellow;
+
+ switch(column)
+ {
+ case 1:
+ return status == TestResult::Pass ? Qt::green : QVariant();
+ case 2:
+ return status == TestResult::Fail ? Qt::red : QVariant();
+ default:
+ return QVariant();
+ }
+}
+
+QString XQTSTestCase::sourceCode(bool &ok) const
+{
+ QFile file(m_queryPath.toLocalFile());
+
+ QString err;
+
+ if(!file.exists())
+ err = QString::fromLatin1("Error: %1 does not exist.").arg(file.fileName());
+ else if(!QFileInfo(file.fileName()).isFile())
+ err = QString::fromLatin1("Error: %1 is not a file, cannot display it.").arg(file.fileName());
+ else if(!file.open(QIODevice::ReadOnly))
+ err = QString::fromLatin1("Error: Could not open %1. Likely a permission error.")
+ .arg(file.fileName());
+
+ if(err.isNull()) /* No errors. */
+ {
+ ok = true;
+ /* Scary, we assume the query is stored in UTF-8. */
+ return QString::fromUtf8(file.readAll());
+ }
+ else
+ {
+ ok = false;
+ return err;
+ }
+}
+
+int XQTSTestCase::columnCount() const
+{
+ return 2;
+}
+
+void XQTSTestCase::addBaseLine(TestBaseLine *line)
+{
+ m_baseLines.append(line);
+}
+
+QString XQTSTestCase::name() const
+{
+ return m_name;
+}
+
+QString XQTSTestCase::creator() const
+{
+ return m_creator;
+}
+
+QString XQTSTestCase::description() const
+{
+ return m_description;
+}
+
+QDate XQTSTestCase::lastModified() const
+{
+ return m_lastModified;
+}
+
+bool XQTSTestCase::isXPath() const
+{
+ return m_isXPath;
+}
+
+TestCase::Scenario XQTSTestCase::scenario() const
+{
+ return m_scenario;
+}
+
+void XQTSTestCase::setName(const QString &n)
+{
+ m_name = n;
+}
+
+void XQTSTestCase::setCreator(const QString &ctor)
+{
+ m_creator = ctor;
+}
+
+void XQTSTestCase::setDescription(const QString &descriptionP)
+{
+ m_description = descriptionP;
+}
+
+void XQTSTestCase::setLastModified(const QDate &date)
+{
+ m_lastModified = date;
+}
+
+void XQTSTestCase::setIsXPath(const bool isXPathP)
+{
+ m_isXPath = isXPathP;
+}
+
+void XQTSTestCase::setQueryPath(const QUrl &uri)
+{
+ m_queryPath = uri;
+}
+
+TreeItem *XQTSTestCase::parent() const
+{
+ return m_parent;
+}
+
+QString XQTSTestCase::title() const
+{
+ return m_name;
+}
+
+TestBaseLine::List XQTSTestCase::baseLines() const
+{
+ Q_ASSERT_X(!m_baseLines.isEmpty(), Q_FUNC_INFO,
+ qPrintable(QString::fromLatin1("The test %1 has no base lines, it should have at least one.").arg(name())));
+ return m_baseLines;
+}
+
+QUrl XQTSTestCase::testCasePath() const
+{
+ return m_queryPath;
+}
+
+void XQTSTestCase::setExternalVariableLoader(const QPatternist::ExternalVariableLoader::Ptr &loader)
+{
+ m_externalVariableLoader = loader;
+}
+
+QPatternist::ExternalVariableLoader::Ptr XQTSTestCase::externalVariableLoader() const
+{
+ return m_externalVariableLoader;
+}
+
+void XQTSTestCase::setContextItemSource(const QUrl &uri)
+{
+ m_contextItemSource = uri;
+}
+
+QUrl XQTSTestCase::contextItemSource() const
+{
+ return m_contextItemSource;
+}
+
+QXmlQuery::QueryLanguage XQTSTestCase::language() const
+{
+ return m_lang;
+}
+
+void XQTSTestCase::setParent(TreeItem *const p)
+{
+ m_parent = p;
+}
+
+void XQTSTestCase::setInitialTemplateName(const QXmlName &name)
+{
+ m_initialTemplateName = name;
+}
+
+QXmlName XQTSTestCase::initialTemplateName() const
+{
+ return m_initialTemplateName;
+}
+
+// vim: et:ts=4:sw=4:sts=4
+
diff --git a/tests/auto/xmlpatternsxqts/lib/XQTSTestCase.h b/tests/auto/xmlpatternsxqts/lib/XQTSTestCase.h
new file mode 100644
index 0000000..80ab20d
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/XQTSTestCase.h
@@ -0,0 +1,190 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_XQTSTestCase_H
+#define PatternistSDK_XQTSTestCase_H
+
+#include <QDate>
+#include <QString>
+#include <QUrl>
+
+#include "qexternalvariableloader_p.h"
+
+#include "TestBaseLine.h"
+#include "TestCase.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ /**
+ * @short Represents a test case in a test suite in the XML Query Test Suite.
+ *
+ * TestCase is a memory representation of a test case, and maps
+ * to the @c test-case element in the XQuery Test Suite test
+ * case catalog.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT XQTSTestCase : public TestCase
+ {
+ public:
+ XQTSTestCase(const Scenario scen, TreeItem *parent,
+ const QXmlQuery::QueryLanguage lang = QXmlQuery::XQuery10);
+ virtual ~XQTSTestCase();
+
+ /**
+ * The identifier, the name of the test. For example, "Literals034".
+ * The name of a test case must be unique.
+ */
+ virtual QString name() const;
+ virtual QString creator() const;
+ virtual QString description() const;
+ /**
+ * @returns the query inside the file, specified by testCasePath(). Loading
+ * of the file is not cached in order to avoid complications.
+ * @param ok is set to @c false if loading the query file fails
+ */
+ virtual QString sourceCode(bool &ok) const;
+ virtual QUrl testCasePath() const;
+ virtual QDate lastModified() const;
+
+ bool isXPath() const;
+
+ /**
+ * What kind of test case this is, what kind of scenario it takes part
+ * of. For example, whether the test case should evaluate normally or fail.
+ */
+ Scenario scenario() const;
+
+ void setCreator(const QString &creator);
+ void setLastModified(const QDate &date);
+ void setDescription(const QString &description);
+ void setIsXPath(const bool isXPath);
+ void setName(const QString &name);
+ void setQueryPath(const QUrl &uri);
+ void setContextItemSource(const QUrl &uri);
+ void addBaseLine(TestBaseLine *lines);
+ void setInitialTemplateName(const QXmlName &name);
+
+ virtual TreeItem *parent() const;
+
+ virtual QVariant data(const Qt::ItemDataRole role, int column) const;
+
+ virtual QString title() const;
+ virtual TestBaseLine::List baseLines() const;
+
+ virtual int columnCount() const;
+
+ void setExternalVariableLoader(const QPatternist::ExternalVariableLoader::Ptr &loader);
+ virtual QPatternist::ExternalVariableLoader::Ptr externalVariableLoader() const;
+ virtual QUrl contextItemSource() const;
+ virtual QXmlQuery::QueryLanguage language() const;
+ void setParent(TreeItem *const parent);
+ virtual QXmlName initialTemplateName() const;
+
+ private:
+ QString m_name;
+ QString m_creator;
+ QString m_description;
+ QUrl m_queryPath;
+ bool m_isXPath;
+ QDate m_lastModified;
+ const Scenario m_scenario;
+ TreeItem * m_parent;
+ TestBaseLine::List m_baseLines;
+ QPatternist::ExternalVariableLoader::Ptr m_externalVariableLoader;
+ QUrl m_contextItemSource;
+ QXmlQuery::QueryLanguage m_lang;
+ QXmlName m_initialTemplateName;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.cpp b/tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.cpp
new file mode 100644
index 0000000..ef5833e4
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.cpp
@@ -0,0 +1,275 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#include <QtDebug>
+
+#include "qacceltreeresourceloader_p.h"
+#include "qnetworkaccessdelegator_p.h"
+
+#include "Global.h"
+#include "TestBaseLine.h"
+#include "TestGroup.h"
+
+#include "XSLTTestSuiteHandler.h"
+
+using namespace QPatternistSDK;
+
+extern QNetworkAccessManager s_networkManager;
+
+XSLTTestSuiteHandler::XSLTTestSuiteHandler(const QUrl &catalogFile) : m_ts(0)
+ , m_tc(0)
+ , m_baseLine(0)
+ , m_catalogFile(catalogFile)
+ , m_removeTestcase(false)
+{
+ const QPatternist::NetworkAccessDelegator::Ptr networkDelegator(new QPatternist::NetworkAccessDelegator(&s_networkManager, &s_networkManager));
+
+ m_resourceLoader = QPatternist::ResourceLoader::Ptr(new QPatternist::AccelTreeResourceLoader(Global::namePool(),
+ networkDelegator));
+ Q_ASSERT(!m_catalogFile.isRelative());
+}
+
+bool XSLTTestSuiteHandler::startElement(const QString &namespaceURI,
+ const QString &localName,
+ const QString &/*qName*/,
+ const QXmlAttributes &atts)
+ {
+ if(namespaceURI != Global::xsltsCatalogNS)
+ return true;
+
+ /* The elements are handled roughly in the order of highest occurrence in the catalog file. */
+ if(localName == QLatin1String("testcase"))
+ {
+ /* We pass m_ts temporarily, and change it later. */
+ m_tc = new XQTSTestCase(TestCase::Standard, 0, QXmlQuery::XSLT20);
+
+ m_currentQueryPath = m_queryOffset.resolved(QUrl(atts.value(QLatin1String("FilePath"))));
+ m_currentBaselinePath = m_baselineOffset.resolved(QUrl(atts.value(QLatin1String("FilePath"))));
+ }
+ else if(localName == QLatin1String("stylesheet"))
+ m_tc->setQueryPath(m_currentQueryPath.resolved(atts.value(QLatin1String("file"))));
+ else if(localName == QLatin1String("error"))
+ {
+ m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError);
+ m_baseLine->setDetails(atts.value(QLatin1String("error-id")));
+ m_tc->addBaseLine(m_baseLine);
+ }
+ else if(localName == QLatin1String("testcases"))
+ {
+ m_ts = new TestSuite();
+ m_ts->setVersion(atts.value(QLatin1String("testSuiteVersion")));
+
+ m_queryOffset = m_catalogFile.resolved(atts.value(QLatin1String("InputOffsetPath")));
+ m_baselineOffset = m_catalogFile.resolved(atts.value(QLatin1String("ResultOffsetPath")));
+ m_sourceOffset = m_catalogFile.resolved(atts.value(QLatin1String("InputOffsetPath")));
+ }
+ else if(localName == QLatin1String("source-document"))
+ {
+ if(atts.value(QLatin1String("role")) == QLatin1String("principal"))
+ m_tc->setContextItemSource(m_sourceOffset.resolved(QUrl(atts.value(QLatin1String("file")))));
+ }
+ else if(localName == QLatin1String("result-document"))
+ {
+ m_baseLine = new TestBaseLine(TestBaseLine::identifierFromString(atts.value(QLatin1String("type"))));
+ m_baseLine->setDetails(m_currentBaselinePath.resolved(atts.value(QLatin1String("file"))).toString());
+ m_tc->addBaseLine(m_baseLine);
+ }
+ else if(localName == QLatin1String("discretionary-feature"))
+ {
+ const QString feature(atts.value(QLatin1String("name")));
+
+ m_removeTestcase = feature == QLatin1String("schema_aware") ||
+ feature == QLatin1String("namespace_axis") ||
+ feature == QLatin1String("disabling_output_escaping") ||
+ feature == QLatin1String("XML_1.1");
+ }
+ else if(localName == QLatin1String("discretionary-choice"))
+ {
+ m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError);
+ m_baseLine->setDetails(atts.value(QLatin1String("name")));
+ m_tc->addBaseLine(m_baseLine);
+ const QString feature(atts.value(QLatin1String("name")));
+
+ m_removeTestcase = feature == QLatin1String("schema_aware") ||
+ feature == QLatin1String("namespace_axis") ||
+ feature == QLatin1String("disabling_output_escaping") ||
+ feature == QLatin1String("XML_1.1");
+ }
+ else if(localName == QLatin1String("entry-named-template"))
+ {
+ const QString name(atts.value(QLatin1String("qname")));
+
+ if(!name.contains(QLatin1Char(':')))
+ {
+ // TODO do namespace processing
+ const QXmlName complete(Global::namePool()->allocateQName(QString(), name));
+
+ m_tc->setInitialTemplateName(complete);
+ }
+ }
+
+ return true;
+}
+
+TestGroup *XSLTTestSuiteHandler::containerFor(const QString &name)
+{
+ TestGroup *& c = m_containers[name];
+
+ if(!c)
+ {
+ c = new TestGroup(m_ts);
+ c->setTitle(name);
+ Q_ASSERT(c);
+ m_ts->appendChild(c);
+ }
+
+ return c;
+}
+
+bool XSLTTestSuiteHandler::endElement(const QString &namespaceURI,
+ const QString &localName,
+ const QString &/*qName*/)
+{
+ if(namespaceURI != Global::xsltsCatalogNS)
+ return true;
+
+ /* The elements are handled roughly in the order of highest occurrence in the catalog file. */
+ if(localName == QLatin1String("description"))
+ {
+ if(m_tc)
+ {
+ /* We're inside a <testcase>, so the <description> belongs
+ * to the testcase. */
+ m_tc->setDescription(m_ch.simplified());
+ }
+ }
+ else if(localName == QLatin1String("testcase"))
+ {
+ Q_ASSERT(m_tc->baseLines().count() >= 1);
+ Q_ASSERT(m_resourceLoader);
+ // TODO can this be removed?
+ m_tc->setExternalVariableLoader(QPatternist::ExternalVariableLoader::Ptr
+ (new ExternalSourceLoader(m_tcSourceInputs,
+ m_resourceLoader)));
+ m_tcSourceInputs.clear();
+
+ if(!m_removeTestcase)
+ {
+ /*
+ TestContainer *const container = containerFor(m_currentCategory);
+ delete m_tc;
+ container->removeLast();
+ */
+ TestContainer *const container = containerFor(m_currentCategory);
+ m_tc->setParent(container);
+ Q_ASSERT(m_tc);
+ container->appendChild(m_tc);
+ }
+
+ m_tc = 0;
+ m_removeTestcase = false;
+ }
+ else if(localName == QLatin1String("name"))
+ m_tc->setName(m_ch);
+ else if(localName == QLatin1String("creator"))
+ m_tc->setCreator(m_ch);
+ else if(localName == QLatin1String("contextItem"))
+ m_contextItemSource = m_ch;
+ else if(localName == QLatin1String("category"))
+ m_currentCategory = m_ch;
+
+ return true;
+}
+
+bool XSLTTestSuiteHandler::characters(const QString &ch)
+{
+ m_ch = ch;
+ return true;
+}
+
+TestSuite *XSLTTestSuiteHandler::testSuite() const
+{
+ return m_ts;
+}
+
+// vim: et:ts=4:sw=4:sts=4
+
diff --git a/tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.h b/tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.h
new file mode 100644
index 0000000..fce64e2
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.h
@@ -0,0 +1,199 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+*/
+
+#ifndef PatternistSDK_XSLTTestSuiteHandler_H
+#define PatternistSDK_XSLTTestSuiteHandler_H
+
+#include <QStack>
+#include <QUrl>
+#include <QXmlDefaultHandler>
+
+#include "ExternalSourceLoader.h"
+#include "TestSuite.h"
+#include "XQTSTestCase.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+namespace QPatternistSDK
+{
+ class TestBaseLine;
+ class TestGroup;
+
+ /**
+ * @short Creates a TestSuite from the XQuery Test Suite catalog.
+ *
+ * The created TestSuite can be retrieved via testSuite().
+ *
+ * @note XSLTTestSuiteHandler assumes the XML is valid by having been validated
+ * against the W3C XML Schema. It has no safety checks for that the XML format
+ * is correct but is hard coded for it. Thus, the behavior is undefined if
+ * the XML is invalid.
+ *
+ * @see http://www.w3.org/XML/Group/xslt20-test/TestSuiteStagingArea/catalog.html
+ * @see http://www.w3.org/XML/Group/xslt20-test/Documentation/XSLT2Test.htm
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class Q_PATTERNISTSDK_EXPORT XSLTTestSuiteHandler : public QXmlDefaultHandler
+ {
+ public:
+ /**
+ * @param catalogFile the URI for the catalog file being parsed. This
+ * URI is used for creating absolute URIs for files mentioned in
+ * the catalog with relative URIs.
+ * @param useExclusionList whether excludeTestGroups.txt should be used to ignore
+ * test groups when loading
+ */
+ XSLTTestSuiteHandler(const QUrl &catalogFile);
+ virtual bool characters(const QString &ch);
+
+ virtual bool endElement(const QString &namespaceURI,
+ const QString &localName,
+ const QString &qName);
+ virtual bool startElement(const QString &namespaceURI,
+ const QString &localName,
+ const QString &qName,
+ const QXmlAttributes &atts);
+
+ virtual TestSuite *testSuite() const;
+
+ private:
+ TestGroup *containerFor(const QString &name);
+
+ QHash<QString, TestGroup *> m_containers;
+
+ TestSuite * m_ts;
+ XQTSTestCase * m_tc;
+ TestBaseLine * m_baseLine;
+ QString m_ch;
+ const QUrl m_catalogFile;
+
+ /**
+ * The base URI for where the XQuery query files are found.
+ * It is absolute, resolved against catalogFile.
+ */
+ QUrl m_queryOffset;
+
+ QUrl m_baselineOffset;
+ QUrl m_sourceOffset;
+ QUrl m_currentQueryPath;
+ QUrl m_currentBaselinePath;
+
+ /**
+ * In the XQTSCatalog.xml, each source file in each test is referred to
+ * by a key, which can be fully looked up in the @c sources element. This QHash
+ * maps the keys to absolute URIs pointing to the source files.
+ */
+ ExternalSourceLoader::SourceMap m_sourceMap;
+
+ ExternalSourceLoader::VariableMap m_tcSourceInputs;
+
+ QPatternist::ResourceLoader::Ptr m_resourceLoader;
+
+ /**
+ * The current value of <tt>input-file/\@variable</tt>.
+ */
+ QString m_currentInputVariable;
+
+ /**
+ * The names of the test groups.
+ */
+ QStack<QString> m_testGroupName;
+
+ /**
+ * Holds the content of the current <tt>input-URI</tt> element.
+ */
+ QString m_inputURI;
+ QString m_contextItemSource;
+ QString m_currentCategory;
+ bool m_removeTestcase;
+ };
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExample.cpp b/tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExample.cpp
new file mode 100644
index 0000000..935143a
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExample.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+QByteArray result;
+QBuffer returnBuffer(&result);
+XMLWriter writer(&returnBuffer);
+
+writer.startDocument();
+
+writer.startDTD(QLatin1String("html"), QLatin1String("-//W3C//DTD XHTML 1.0 Strict//EN"),
+ QLatin1String("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"));
+writer.endDTD();
+
+writer.startPrefixMapping(QString(), QLatin1String("http://www.w3.org/1999/xhtml"));
+
+writer.startElement(QLatin1String("html"), QXmlAttributes());
+writer.startElement(QLatin1String("body"), QXmlAttributes());
+writer.startElement(QLatin1String("p"), QXmlAttributes());
+
+writer.characters(QLatin1String("Hello World!"));
+
+writer.endElement(QLatin1String("p"));
+writer.endElement(QLatin1String("body"));
+writer.endElement(QLatin1String("html"));
+
+writer.endDocument();
diff --git a/tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExampleResult.xml b/tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExampleResult.xml
new file mode 100644
index 0000000..c5e7312
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExampleResult.xml
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><body><p>Hello World!</p></body></html>
diff --git a/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExample.cpp b/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExample.cpp
new file mode 100644
index 0000000..935143a
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExample.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+QByteArray result;
+QBuffer returnBuffer(&result);
+XMLWriter writer(&returnBuffer);
+
+writer.startDocument();
+
+writer.startDTD(QLatin1String("html"), QLatin1String("-//W3C//DTD XHTML 1.0 Strict//EN"),
+ QLatin1String("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"));
+writer.endDTD();
+
+writer.startPrefixMapping(QString(), QLatin1String("http://www.w3.org/1999/xhtml"));
+
+writer.startElement(QLatin1String("html"), QXmlAttributes());
+writer.startElement(QLatin1String("body"), QXmlAttributes());
+writer.startElement(QLatin1String("p"), QXmlAttributes());
+
+writer.characters(QLatin1String("Hello World!"));
+
+writer.endElement(QLatin1String("p"));
+writer.endElement(QLatin1String("body"));
+writer.endElement(QLatin1String("html"));
+
+writer.endDocument();
diff --git a/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExampleResult.xml b/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExampleResult.xml
new file mode 100644
index 0000000..c5e7312
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExampleResult.xml
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><body><p>Hello World!</p></body></html>
diff --git a/tests/auto/xmlpatternsxqts/lib/lib.pro b/tests/auto/xmlpatternsxqts/lib/lib.pro
new file mode 100644
index 0000000..5b12d63
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/lib.pro
@@ -0,0 +1,78 @@
+include (../../xmlpatterns.pri)
+
+TARGET = $$XMLPATTERNS_SDK
+TEMPLATE = lib
+DEFINES += Q_PATTERNISTSDK_BUILDING
+
+# lib_bundle ensures we get a framework on OS X, a library bundle.
+CONFIG += resources
+
+mac {
+ CONFIG += absolute_library_soname
+ target.path=$$[QT_INSTALL_LIBS]
+ INSTALLS += target
+}
+
+# We add gui, because xmlpatterns.pri pull it out.
+QT += xmlpatterns xml network testlib gui
+
+DESTDIR = $$QT_BUILD_TREE/lib
+!wince*:DLLDESTDIR = $$QT_BUILD_TREE/bin
+
+# syncqt doesn't copy headers in tools/ so let's manually ensure
+# it works with shadow builds and source builds.
+INCLUDEPATH += $$QT_BUILD_TREE/include/QtXmlPatterns/private \
+ $$QT_SOURCE_TREE/include/QtXmlPatterns/private \
+ $$QT_SOURCE_TREE/tools/xmlpatterns
+
+HEADERS = ASTItem.h \
+ DebugExpressionFactory.h \
+ ErrorHandler.h \
+ ErrorItem.h \
+ ExitCode.h \
+ ExpressionInfo.h \
+ ExpressionNamer.h \
+ ExternalSourceLoader.h \
+ Global.h \
+ ResultThreader.h \
+ TestBaseLine.h \
+ TestCase.h \
+ TestContainer.h \
+ TestGroup.h \
+ TestItem.h \
+ TestResult.h \
+ TestResultHandler.h \
+ TestSuite.h \
+ TestSuiteHandler.h \
+ TestSuiteResult.h \
+ TreeItem.h \
+ TreeModel.h \
+ Worker.h \
+ XMLWriter.h \
+ XQTSTestCase.h \
+ XSLTTestSuiteHandler.h
+
+SOURCES = ASTItem.cpp \
+ DebugExpressionFactory.cpp \
+ ErrorHandler.cpp \
+ ErrorItem.cpp \
+ ExpressionInfo.cpp \
+ ExpressionNamer.cpp \
+ ExternalSourceLoader.cpp \
+ Global.cpp \
+ ResultThreader.cpp \
+ TestBaseLine.cpp \
+ TestCase.cpp \
+ TestContainer.cpp \
+ TestGroup.cpp \
+ TestResult.cpp \
+ TestResultHandler.cpp \
+ TestSuite.cpp \
+ TestSuiteHandler.cpp \
+ TestSuiteResult.cpp \
+ TreeItem.cpp \
+ TreeModel.cpp \
+ Worker.cpp \
+ XMLWriter.cpp \
+ XQTSTestCase.cpp \
+ XSLTTestSuiteHandler.cpp
diff --git a/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.cpp b/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.cpp
new file mode 100644
index 0000000..738fae1
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.cpp
@@ -0,0 +1,227 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+ */
+
+#include <QtTest/QtTest>
+
+#include "XMLWriter.h"
+
+#include "XMLWriterTest.h"
+#include "XMLWriterTest.moc"
+
+using namespace QPatternistSDK;
+
+QTEST_MAIN(XMLWriterTest)
+
+void XMLWriterTest::serialize()
+{
+ QFETCH(QString, input);
+ QFETCH(QString, expectedResult);
+
+ QByteArray result;
+ QBuffer returnBuffer(&result);
+
+ XMLWriter writer(&returnBuffer);
+
+ QXmlInputSource inputSource;
+ inputSource.setData(input);
+
+ QXmlSimpleReader reader;
+ reader.setContentHandler(&writer);
+
+ const bool parseSuccess = reader.parse(inputSource);
+ Q_ASSERT_X(parseSuccess, Q_FUNC_INFO,
+ "XMLWriter reported an error while serializing the input.");
+
+ QCOMPARE(QString::fromLatin1(result), expectedResult);
+}
+
+void XMLWriterTest::serialize_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<QString>("expectedResult");
+
+ /* ------------------- Elements ------------------- */
+ QTest::newRow("Only an document element")
+ << "<doc></doc>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<doc/>";
+
+ QTest::newRow("Document element containing a short closed element")
+ << "<doc><f/></doc>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<doc><f/></doc>";
+ QTest::newRow("Complex nested elements")
+ << "<doc><a/><b/><c><d/><e><f><x/></f></e></c></doc>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<doc><a/><b/><c><d/><e><f><x/></f></e></c></doc>";
+ /* ------------------------------------------------- */
+
+ /* ---------------- Element Content ---------------- */
+ QTest::newRow("Element content with simple content")
+ << "<doc>content</doc>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<doc>content</doc>";
+
+ QTest::newRow("Element content with tricky to escape content")
+ << "<doc>>>&amp;'\"''/></doc>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<doc>>>&amp;'\"''/></doc>";
+ /* ------------------------------------------------- */
+
+ /* ----------- Processing Instructions ------------- */
+ QTest::newRow("Simple processing instruction.")
+ << "<doc><?php content?></doc>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<doc><?php content?></doc>";
+ /* ------------------------------------------------- */
+
+ /* --------------- 'xml' attributes ---------------- */
+ QTest::newRow("Simple xml:space attribute.")
+ << "<doc xml:space='preserve'>content</doc>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<doc xml:space=\"preserve\">content</doc>";
+
+ QTest::newRow("Many 'xml' attributes.")
+ << "<doc xml:space='preserve' xml:foo='3' xml:s2='3'>content</doc>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<doc xml:space=\"preserve\" xml:foo=\"3\" xml:s2=\"3\">content</doc>";
+ /* ------------------------------------------------- */
+
+ /* ------------ namespace declarations ------------- */
+ QTest::newRow("One simple namespace declaration.")
+ << "<doc xmlns:f='example.org/'/>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<doc xmlns:f=\"example.org/\"/>";
+
+ QTest::newRow("Two simple namespace declarations.")
+ << "<doc xmlns:f='example.org/' xmlns:e='example.org/'/>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<doc xmlns:f=\"example.org/\" xmlns:e=\"example.org/\"/>";
+
+ QTest::newRow("A simple default namespace.")
+ << "<doc xmlns='example.org/'/>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<doc xmlns=\"example.org/\"/>";
+ /* ------------------------------------------------- */
+
+ /* -------- namespace declarations in use ---------- */
+ QTest::newRow("Simple use of a namespace declaration.")
+ << "<doc xmlns:f='example.org/' f:attr='chars'><n/><f:name f:attr='chars'/></doc>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<doc xmlns:f=\"example.org/\" f:attr=\"chars\"><n/><f:name f:attr=\"chars\"/></doc>";
+ /* ------------------------------------------------- */
+}
+
+void XMLWriterTest::cdata()
+{
+ /*
+ QTest::newRow("Simple CDATA")
+ << "<doc><![CDATA[content]]></doc>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<doc><![CDATA[content]]></doc>";
+
+ QTest::newRow("Complex CDATA")
+ << "<doc><![CDATA[<<>>&'\";&987;]]></doc>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<doc><![CDATA[<<>>&'\";&123;]]></doc>";
+ */
+}
+
+void XMLWriterTest::comments()
+{
+ /*
+ QTest::newRow("Simple comment")
+ << "<doc><!-- comment --></doc>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<doc><!-- comment --></doc>";
+ QTest::newRow("Comment")
+ << "<doc><!--- comment --></doc>"
+ << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<doc><!--- comment --></doc>";
+ */
+}
+
+void XMLWriterTest::doxygenExample()
+{
+#include "../docs/XMLWriterExample.cpp"
+
+ /* When changing, remember to update the Doxygen in XMLWriter.h */
+ const QByteArray expectedResult(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
+ "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\"><body><p>Hello World!</p></body></html>"
+ );
+
+ QCOMPARE(QString::fromLatin1(result), QString::fromLatin1(expectedResult));
+}
+
+// vim: et:ts=4:sw=4:sts=4
diff --git a/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.h b/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.h
new file mode 100644
index 0000000..bba6557
--- /dev/null
+++ b/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.h
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Patternist project on Trolltech Labs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+***************************************************************************
+ */
+
+#ifndef PatternistSDK_XMLWriterTest_H
+#define PatternistSDK_XMLWriterTest_H
+
+#include <QObject>
+
+QT_BEGIN_HEADER
+
+namespace QPatternistSDK
+{
+ /**
+ * @short QTestLib test for XMLWriter.
+ *
+ * @ingroup PatternistSDK
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+ class XMLWriterTest : public QObject
+ {
+ Q_OBJECT
+ private Q_SLOTS:
+ void serialize();
+ void serialize_data();
+ void comments();
+ void cdata();
+
+ /**
+ * Ensure the example compiles, and that it does
+ * what it claims to.
+ */
+ void doxygenExample();
+ };
+}
+
+QT_END_HEADER
+
+#endif
+// vim: et:ts=4:sw=4:sts=4