From 1e7b737596db7be0a221aa44d1a329d3fdb5d6e3 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 17 Feb 2010 06:08:20 +1000 Subject: Check in sample license headers Reviewed-by: Trust Me --- header.BSD | 40 ++++++++++++++++++++++++++++++++++++++++ header.LGPL | 41 +++++++++++++++++++++++++++++++++++++++++ header.LGPL-ONLY | 22 ++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 header.BSD create mode 100644 header.LGPL create mode 100644 header.LGPL-ONLY diff --git a/header.BSD b/header.BSD new file mode 100644 index 0000000..3c0d604 --- /dev/null +++ b/header.BSD @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the FOO module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + diff --git a/header.LGPL b/header.LGPL new file mode 100644 index 0000000..4fbd874 --- /dev/null +++ b/header.LGPL @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the FOO module 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + diff --git a/header.LGPL-ONLY b/header.LGPL-ONLY new file mode 100644 index 0000000..59b4c04 --- /dev/null +++ b/header.LGPL-ONLY @@ -0,0 +1,22 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the FOO module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL-ONLY$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ -- cgit v0.12 From b7406af04ec83b3e8d712b42a87f6c29121b998d Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 16 Feb 2010 09:47:16 +1000 Subject: Fixed compile of these tests when Qt is configured with -qtnamespace --- tests/auto/modeltest/dynamictreemodel.h | 2 -- tests/auto/qpixmapcache/tst_qpixmapcache.cpp | 2 ++ tests/auto/qtextstream/tst_qtextstream.cpp | 7 ++++++- tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h | 2 ++ tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h | 2 ++ 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/auto/modeltest/dynamictreemodel.h b/tests/auto/modeltest/dynamictreemodel.h index 3f0d90d..9633755 100644 --- a/tests/auto/modeltest/dynamictreemodel.h +++ b/tests/auto/modeltest/dynamictreemodel.h @@ -48,8 +48,6 @@ #include -template class QList; - class DynamicTreeModel : public QAbstractItemModel { Q_OBJECT diff --git a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp index a0f4339..f8951f5 100644 --- a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp +++ b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp @@ -483,7 +483,9 @@ void tst_QPixmapCache::pixmapKey() QVERIFY(!getPrivate(key8)); } +QT_BEGIN_NAMESPACE extern int q_QPixmapCache_keyHashSize(); +QT_END_NAMESPACE void tst_QPixmapCache::noLeak() { diff --git a/tests/auto/qtextstream/tst_qtextstream.cpp b/tests/auto/qtextstream/tst_qtextstream.cpp index 8ff6bee..9146be2 100644 --- a/tests/auto/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/qtextstream/tst_qtextstream.cpp @@ -4308,10 +4308,15 @@ void tst_QTextStream::int_write_with_locale() // ------------------------------------------------------------------------------ // like QTEST_APPLESS_MAIN, but initialising the locale on Unix +#if defined (Q_OS_UNIX) && !defined (Q_OS_SYMBIAN) +QT_BEGIN_NAMESPACE +extern bool qt_locale_initialized; +QT_END_NAMESPACE +#endif + int main(int argc, char *argv[]) { #if defined (Q_OS_UNIX) && !defined (Q_OS_SYMBIAN) - extern bool qt_locale_initialized; ::setlocale(LC_ALL, ""); qt_locale_initialized = true; #endif diff --git a/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h b/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h index 8cfa143..947687a 100644 --- a/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h +++ b/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h @@ -50,6 +50,7 @@ #include "TestCase.h" QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE namespace QPatternistSDK { @@ -153,6 +154,7 @@ namespace QPatternistSDK }; } +QT_END_NAMESPACE QT_END_HEADER #endif diff --git a/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h b/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h index 9179a2d..5493c7d 100644 --- a/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h +++ b/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h @@ -50,6 +50,7 @@ #include "XQTSTestCase.h" QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE namespace QPatternistSDK { @@ -113,6 +114,7 @@ namespace QPatternistSDK }; } +QT_END_NAMESPACE QT_END_HEADER #endif -- cgit v0.12 From 48f4fe4897ba6b98434993179b47d6d9491ae173 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 16 Feb 2010 10:25:03 +1000 Subject: Fixed tests using Q_DECLARE_* when Qt is configured with -qtnamespace --- tests/auto/qlocalsocket/lackey/main.cpp | 2 ++ tests/auto/qpluginloader/theplugin/plugininterface.h | 3 +++ tests/auto/qsharedmemory/lackey/main.cpp | 2 ++ tests/auto/qvariant/tst_qvariant.cpp | 5 +++++ 4 files changed, 12 insertions(+) diff --git a/tests/auto/qlocalsocket/lackey/main.cpp b/tests/auto/qlocalsocket/lackey/main.cpp index 0f1930c..1bba4f8 100644 --- a/tests/auto/qlocalsocket/lackey/main.cpp +++ b/tests/auto/qlocalsocket/lackey/main.cpp @@ -172,8 +172,10 @@ static int _q_ScriptRegisterQObjectMetaType(QScriptEngine *engine, const QScript return qScriptRegisterMetaType(engine, _q_ScriptValueFromQObject, _q_ScriptValueToQObject, prototype); } +QT_BEGIN_NAMESPACE Q_SCRIPT_DECLARE_QMETAOBJECT(QScriptLocalSocket, QObject*); Q_SCRIPT_DECLARE_QMETAOBJECT(QScriptLocalServer, QObject*); +QT_END_NAMESPACE static void interactive(QScriptEngine &eng) { diff --git a/tests/auto/qpluginloader/theplugin/plugininterface.h b/tests/auto/qpluginloader/theplugin/plugininterface.h index 0b093db..9b69429 100644 --- a/tests/auto/qpluginloader/theplugin/plugininterface.h +++ b/tests/auto/qpluginloader/theplugin/plugininterface.h @@ -45,7 +45,10 @@ struct PluginInterface { virtual ~PluginInterface() {} virtual QString pluginName() const = 0; }; + +QT_BEGIN_NAMESPACE Q_DECLARE_INTERFACE(PluginInterface, "com.trolltect.autotests.plugininterface/1.0") +QT_END_NAMESPACE #endif // PLUGININTERFACE_H diff --git a/tests/auto/qsharedmemory/lackey/main.cpp b/tests/auto/qsharedmemory/lackey/main.cpp index 5a5bf5e..fef8d22 100644 --- a/tests/auto/qsharedmemory/lackey/main.cpp +++ b/tests/auto/qsharedmemory/lackey/main.cpp @@ -242,9 +242,11 @@ private: QSharedMemory sm; }; +QT_BEGIN_NAMESPACE Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSharedMemory, QObject*); Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSystemLock, QObject*); Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSystemSemaphore, QObject*); +QT_END_NAMESPACE static void interactive(QScriptEngine &eng) { diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp index 21b2fe3..a316dda 100644 --- a/tests/auto/qvariant/tst_qvariant.cpp +++ b/tests/auto/qvariant/tst_qvariant.cpp @@ -3200,7 +3200,10 @@ struct MyPrimitive return x == o.x && y == o.y; } }; + +QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO(MyPrimitive, Q_PRIMITIVE_TYPE); +QT_END_NAMESPACE struct MyData { @@ -3239,7 +3242,9 @@ struct MyMovable int MyMovable::count = 0; +QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO(MyMovable, Q_MOVABLE_TYPE); +QT_END_NAMESPACE Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(MyPrimitive) -- cgit v0.12 From edb3480202b762860913e5a7b9f5eafe8bda5eff Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 16 Feb 2010 14:10:51 +1000 Subject: Fixed compile of QtHelp tests with vcproj generator. These tests were doing: SUBDIRS+=../../../tools/assistant/lib ... to ensure that part of Qt was built before building the test. That's a cute hack, but it's a bad idea: it breaks the vcproj generator to process the same subdir multiple times, and it also gives the very unintuitive result that doing `make clean' under tests/auto cleans out a part of the Qt build! --- tests/auto/qhelpcontentmodel/qhelpcontentmodel.pro | 26 +++++++++++++++------ .../qhelpcontentmodel/tst_qhelpcontentmodel.pro | 22 ------------------ tests/auto/qhelpenginecore/qhelpenginecore.pro | 27 ++++++++++++++++------ tests/auto/qhelpenginecore/tst_qhelpenginecore.pro | 23 ------------------ tests/auto/qhelpgenerator/qhelpgenerator.pro | 15 ++++++------ tests/auto/qhelpgenerator/tst_qhelpgenerator.pro | 9 -------- tests/auto/qhelpindexmodel/qhelpindexmodel.pro | 15 ++++++------ tests/auto/qhelpindexmodel/tst_qhelpindexmodel.pro | 9 -------- tests/auto/qhelpprojectdata/qhelpprojectdata.pro | 13 +++++------ .../auto/qhelpprojectdata/tst_qhelpprojectdata.pro | 9 -------- 10 files changed, 59 insertions(+), 109 deletions(-) delete mode 100644 tests/auto/qhelpcontentmodel/tst_qhelpcontentmodel.pro delete mode 100644 tests/auto/qhelpenginecore/tst_qhelpenginecore.pro delete mode 100644 tests/auto/qhelpgenerator/tst_qhelpgenerator.pro delete mode 100644 tests/auto/qhelpindexmodel/tst_qhelpindexmodel.pro delete mode 100644 tests/auto/qhelpprojectdata/tst_qhelpprojectdata.pro diff --git a/tests/auto/qhelpcontentmodel/qhelpcontentmodel.pro b/tests/auto/qhelpcontentmodel/qhelpcontentmodel.pro index 79bb44c..889aac9 100644 --- a/tests/auto/qhelpcontentmodel/qhelpcontentmodel.pro +++ b/tests/auto/qhelpcontentmodel/qhelpcontentmodel.pro @@ -1,10 +1,22 @@ -TEMPLATE = subdirs -CONFIG += ordered +load(qttest_p4) +SOURCES += tst_qhelpcontentmodel.cpp -contains(QT_BUILD_PARTS, tools): { - SUBDIRS += ../../../tools/assistant/lib/fulltextsearch \ - ../../../tools/assistant/lib -} +CONFIG += help -SUBDIRS += tst_qhelpcontentmodel.pro +DEFINES += QT_USE_USING_NAMESPACE +!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS +wince*: { + DEFINES += SRCDIR=\\\"./\\\" + QT += network + addFiles.sources = $$PWD/data/*.* + addFiles.path = data + clucene.sources = $$QT_BUILD_TREE/lib/QtCLucene*.dll + + DEPLOYMENT += addFiles + DEPLOYMENT += clucene + + DEPLOYMENT_PLUGIN += qsqlite +} else { + DEFINES += SRCDIR=\\\"$$PWD\\\" +} \ No newline at end of file diff --git a/tests/auto/qhelpcontentmodel/tst_qhelpcontentmodel.pro b/tests/auto/qhelpcontentmodel/tst_qhelpcontentmodel.pro deleted file mode 100644 index 889aac9..0000000 --- a/tests/auto/qhelpcontentmodel/tst_qhelpcontentmodel.pro +++ /dev/null @@ -1,22 +0,0 @@ -load(qttest_p4) -SOURCES += tst_qhelpcontentmodel.cpp - -CONFIG += help - -DEFINES += QT_USE_USING_NAMESPACE -!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS - -wince*: { - DEFINES += SRCDIR=\\\"./\\\" - QT += network - addFiles.sources = $$PWD/data/*.* - addFiles.path = data - clucene.sources = $$QT_BUILD_TREE/lib/QtCLucene*.dll - - DEPLOYMENT += addFiles - DEPLOYMENT += clucene - - DEPLOYMENT_PLUGIN += qsqlite -} else { - DEFINES += SRCDIR=\\\"$$PWD\\\" -} \ No newline at end of file diff --git a/tests/auto/qhelpenginecore/qhelpenginecore.pro b/tests/auto/qhelpenginecore/qhelpenginecore.pro index ee9b0c4..27ebd0f 100644 --- a/tests/auto/qhelpenginecore/qhelpenginecore.pro +++ b/tests/auto/qhelpenginecore/qhelpenginecore.pro @@ -1,10 +1,23 @@ -TEMPLATE = subdirs -CONFIG += ordered +load(qttest_p4) +SOURCES += tst_qhelpenginecore.cpp +CONFIG += help +QT += sql -contains(QT_BUILD_PARTS, tools): { - SUBDIRS += ../../../tools/assistant/lib/fulltextsearch \ - ../../../tools/assistant/lib -} -SUBDIRS += tst_qhelpenginecore.pro +DEFINES += QT_USE_USING_NAMESPACE +!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS + +wince*: { + DEFINES += SRCDIR=\\\"./\\\" + QT += network + addFiles.sources = $$PWD/data/*.* + addFiles.path = data + clucene.sources = $$QT_BUILD_TREE/lib/QtCLucene*.dll + DEPLOYMENT += addFiles + DEPLOYMENT += clucene + + DEPLOYMENT_PLUGIN += qsqlite +} else { + DEFINES += SRCDIR=\\\"$$PWD\\\" +} diff --git a/tests/auto/qhelpenginecore/tst_qhelpenginecore.pro b/tests/auto/qhelpenginecore/tst_qhelpenginecore.pro deleted file mode 100644 index 27ebd0f..0000000 --- a/tests/auto/qhelpenginecore/tst_qhelpenginecore.pro +++ /dev/null @@ -1,23 +0,0 @@ -load(qttest_p4) -SOURCES += tst_qhelpenginecore.cpp -CONFIG += help -QT += sql - - -DEFINES += QT_USE_USING_NAMESPACE -!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS - -wince*: { - DEFINES += SRCDIR=\\\"./\\\" - QT += network - addFiles.sources = $$PWD/data/*.* - addFiles.path = data - clucene.sources = $$QT_BUILD_TREE/lib/QtCLucene*.dll - - DEPLOYMENT += addFiles - DEPLOYMENT += clucene - - DEPLOYMENT_PLUGIN += qsqlite -} else { - DEFINES += SRCDIR=\\\"$$PWD\\\" -} diff --git a/tests/auto/qhelpgenerator/qhelpgenerator.pro b/tests/auto/qhelpgenerator/qhelpgenerator.pro index efa1ef5..b4b07dd 100644 --- a/tests/auto/qhelpgenerator/qhelpgenerator.pro +++ b/tests/auto/qhelpgenerator/qhelpgenerator.pro @@ -1,10 +1,9 @@ -TEMPLATE = subdirs -CONFIG += ordered +load(qttest_p4) -contains(QT_BUILD_PARTS, tools): { - SUBDIRS += ../../../tools/assistant/lib/fulltextsearch \ - ../../../tools/assistant/lib -} - -SUBDIRS += tst_qhelpgenerator.pro +SOURCES += tst_qhelpgenerator.cpp +CONFIG += help +QT += sql +DEFINES += SRCDIR=\\\"$$PWD\\\" +DEFINES += QT_USE_USING_NAMESPACE +!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS diff --git a/tests/auto/qhelpgenerator/tst_qhelpgenerator.pro b/tests/auto/qhelpgenerator/tst_qhelpgenerator.pro deleted file mode 100644 index b4b07dd..0000000 --- a/tests/auto/qhelpgenerator/tst_qhelpgenerator.pro +++ /dev/null @@ -1,9 +0,0 @@ -load(qttest_p4) - -SOURCES += tst_qhelpgenerator.cpp -CONFIG += help -QT += sql - -DEFINES += SRCDIR=\\\"$$PWD\\\" -DEFINES += QT_USE_USING_NAMESPACE -!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS diff --git a/tests/auto/qhelpindexmodel/qhelpindexmodel.pro b/tests/auto/qhelpindexmodel/qhelpindexmodel.pro index 1325e09..927c2e1 100644 --- a/tests/auto/qhelpindexmodel/qhelpindexmodel.pro +++ b/tests/auto/qhelpindexmodel/qhelpindexmodel.pro @@ -1,10 +1,9 @@ -TEMPLATE = subdirs -CONFIG += ordered +load(qttest_p4) -contains(QT_BUILD_PARTS, tools): { - SUBDIRS += ../../../tools/assistant/lib/fulltextsearch \ - ../../../tools/assistant/lib -} - -SUBDIRS += tst_qhelpindexmodel.pro +SOURCES += tst_qhelpindexmodel.cpp +CONFIG += help +QT += sql +DEFINES += SRCDIR=\\\"$$PWD\\\" +DEFINES += QT_USE_USING_NAMESPACE +!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS diff --git a/tests/auto/qhelpindexmodel/tst_qhelpindexmodel.pro b/tests/auto/qhelpindexmodel/tst_qhelpindexmodel.pro deleted file mode 100644 index 927c2e1..0000000 --- a/tests/auto/qhelpindexmodel/tst_qhelpindexmodel.pro +++ /dev/null @@ -1,9 +0,0 @@ -load(qttest_p4) - -SOURCES += tst_qhelpindexmodel.cpp -CONFIG += help -QT += sql - -DEFINES += SRCDIR=\\\"$$PWD\\\" -DEFINES += QT_USE_USING_NAMESPACE -!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS diff --git a/tests/auto/qhelpprojectdata/qhelpprojectdata.pro b/tests/auto/qhelpprojectdata/qhelpprojectdata.pro index 9617416..92dc620 100644 --- a/tests/auto/qhelpprojectdata/qhelpprojectdata.pro +++ b/tests/auto/qhelpprojectdata/qhelpprojectdata.pro @@ -1,10 +1,9 @@ -TEMPLATE = subdirs -CONFIG += ordered +load(qttest_p4) -contains(QT_BUILD_PARTS, tools): { - SUBDIRS += ../../../tools/assistant/lib/fulltextsearch \ - ../../../tools/assistant/lib -} +SOURCES += tst_qhelpprojectdata.cpp +CONFIG += help -SUBDIRS += tst_qhelpprojectdata.pro +DEFINES += SRCDIR=\\\"$$PWD\\\" +DEFINES += QT_USE_USING_NAMESPACE +!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS diff --git a/tests/auto/qhelpprojectdata/tst_qhelpprojectdata.pro b/tests/auto/qhelpprojectdata/tst_qhelpprojectdata.pro deleted file mode 100644 index 92dc620..0000000 --- a/tests/auto/qhelpprojectdata/tst_qhelpprojectdata.pro +++ /dev/null @@ -1,9 +0,0 @@ -load(qttest_p4) - -SOURCES += tst_qhelpprojectdata.cpp -CONFIG += help - -DEFINES += SRCDIR=\\\"$$PWD\\\" -DEFINES += QT_USE_USING_NAMESPACE -!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS - -- cgit v0.12 From 0cdf33e9acb00b8f3654e8268253a3fb7c5db92c Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 16 Feb 2010 14:54:05 +1000 Subject: Fixed compile of shm/sem tests with vcproj generator. SUBDIRS+=../path/to/lackey from two different places means that qmake sees the lackey project twice. This breaks the vcproj generator. Make it so that lackey is only referred to once. --- tests/auto/auto.pro | 3 +- tests/auto/qsharedmemory/.gitignore | 3 - tests/auto/qsharedmemory/lackey/lackey.pro | 20 - tests/auto/qsharedmemory/lackey/main.cpp | 370 ---------- .../auto/qsharedmemory/lackey/scripts/consumer.js | 41 -- .../auto/qsharedmemory/lackey/scripts/producer.js | 44 -- .../lackey/scripts/readonly_segfault.js | 4 - .../lackey/scripts/systemlock_read.js | 11 - .../lackey/scripts/systemlock_readwrite.js | 11 - .../lackey/scripts/systemsemaphore_acquire.js | 18 - .../scripts/systemsemaphore_acquirerelease.js | 11 - .../lackey/scripts/systemsemaphore_release.js | 11 - tests/auto/qsharedmemory/qsharedmemory.pro | 4 - .../auto/qsharedmemory/qsystemlock/qsystemlock.pro | 22 - .../qsharedmemory/qsystemlock/tst_qsystemlock.cpp | 239 ------- tests/auto/qsharedmemory/src/qsystemlock.cpp | 246 ------- tests/auto/qsharedmemory/src/qsystemlock.h | 135 ---- tests/auto/qsharedmemory/src/qsystemlock_p.h | 109 --- tests/auto/qsharedmemory/src/qsystemlock_unix.cpp | 233 ------ tests/auto/qsharedmemory/src/qsystemlock_win.cpp | 182 ----- tests/auto/qsharedmemory/src/src.pri | 10 - tests/auto/qsharedmemory/test/test.pro | 37 - tests/auto/qsharedmemory/tst_qsharedmemory.cpp | 778 --------------------- tests/auto/qsystemsemaphore/.gitignore | 1 - tests/auto/qsystemsemaphore/files.qrc | 7 - tests/auto/qsystemsemaphore/qsystemsemaphore.pro | 4 - tests/auto/qsystemsemaphore/test/test.pro | 40 -- .../auto/qsystemsemaphore/tst_qsystemsemaphore.cpp | 302 -------- tests/auto/qtipc/lackey/lackey.pro | 20 + tests/auto/qtipc/lackey/main.cpp | 370 ++++++++++ tests/auto/qtipc/lackey/scripts/consumer.js | 41 ++ tests/auto/qtipc/lackey/scripts/producer.js | 44 ++ .../auto/qtipc/lackey/scripts/readonly_segfault.js | 4 + tests/auto/qtipc/lackey/scripts/systemlock_read.js | 11 + .../qtipc/lackey/scripts/systemlock_readwrite.js | 11 + .../lackey/scripts/systemsemaphore_acquire.js | 18 + .../scripts/systemsemaphore_acquirerelease.js | 11 + .../lackey/scripts/systemsemaphore_release.js | 11 + tests/auto/qtipc/qsharedmemory/.gitignore | 3 + tests/auto/qtipc/qsharedmemory/qsharedmemory.pro | 4 + .../qsharedmemory/qsystemlock/qsystemlock.pro | 22 + .../qsharedmemory/qsystemlock/tst_qsystemlock.cpp | 239 +++++++ tests/auto/qtipc/qsharedmemory/src/qsystemlock.cpp | 246 +++++++ tests/auto/qtipc/qsharedmemory/src/qsystemlock.h | 135 ++++ tests/auto/qtipc/qsharedmemory/src/qsystemlock_p.h | 109 +++ .../qtipc/qsharedmemory/src/qsystemlock_unix.cpp | 233 ++++++ .../qtipc/qsharedmemory/src/qsystemlock_win.cpp | 182 +++++ tests/auto/qtipc/qsharedmemory/src/src.pri | 10 + tests/auto/qtipc/qsharedmemory/test/test.pro | 37 + .../auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp | 776 ++++++++++++++++++++ tests/auto/qtipc/qsystemsemaphore/.gitignore | 1 + tests/auto/qtipc/qsystemsemaphore/files.qrc | 7 + .../qtipc/qsystemsemaphore/qsystemsemaphore.pro | 36 + .../qsystemsemaphore/tst_qsystemsemaphore.cpp | 302 ++++++++ tests/auto/qtipc/qtipc.pro | 6 + 55 files changed, 2890 insertions(+), 2895 deletions(-) delete mode 100644 tests/auto/qsharedmemory/.gitignore delete mode 100644 tests/auto/qsharedmemory/lackey/lackey.pro delete mode 100644 tests/auto/qsharedmemory/lackey/main.cpp delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/consumer.js delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/producer.js delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/readonly_segfault.js delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/systemlock_read.js delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/systemlock_readwrite.js delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquire.js delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquirerelease.js delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_release.js delete mode 100644 tests/auto/qsharedmemory/qsharedmemory.pro delete mode 100644 tests/auto/qsharedmemory/qsystemlock/qsystemlock.pro delete mode 100644 tests/auto/qsharedmemory/qsystemlock/tst_qsystemlock.cpp delete mode 100644 tests/auto/qsharedmemory/src/qsystemlock.cpp delete mode 100644 tests/auto/qsharedmemory/src/qsystemlock.h delete mode 100644 tests/auto/qsharedmemory/src/qsystemlock_p.h delete mode 100644 tests/auto/qsharedmemory/src/qsystemlock_unix.cpp delete mode 100644 tests/auto/qsharedmemory/src/qsystemlock_win.cpp delete mode 100644 tests/auto/qsharedmemory/src/src.pri delete mode 100644 tests/auto/qsharedmemory/test/test.pro delete mode 100644 tests/auto/qsharedmemory/tst_qsharedmemory.cpp delete mode 100644 tests/auto/qsystemsemaphore/.gitignore delete mode 100644 tests/auto/qsystemsemaphore/files.qrc delete mode 100644 tests/auto/qsystemsemaphore/qsystemsemaphore.pro delete mode 100644 tests/auto/qsystemsemaphore/test/test.pro delete mode 100644 tests/auto/qsystemsemaphore/tst_qsystemsemaphore.cpp create mode 100644 tests/auto/qtipc/lackey/lackey.pro create mode 100644 tests/auto/qtipc/lackey/main.cpp create mode 100644 tests/auto/qtipc/lackey/scripts/consumer.js create mode 100644 tests/auto/qtipc/lackey/scripts/producer.js create mode 100644 tests/auto/qtipc/lackey/scripts/readonly_segfault.js create mode 100644 tests/auto/qtipc/lackey/scripts/systemlock_read.js create mode 100644 tests/auto/qtipc/lackey/scripts/systemlock_readwrite.js create mode 100644 tests/auto/qtipc/lackey/scripts/systemsemaphore_acquire.js create mode 100644 tests/auto/qtipc/lackey/scripts/systemsemaphore_acquirerelease.js create mode 100644 tests/auto/qtipc/lackey/scripts/systemsemaphore_release.js create mode 100644 tests/auto/qtipc/qsharedmemory/.gitignore create mode 100644 tests/auto/qtipc/qsharedmemory/qsharedmemory.pro create mode 100644 tests/auto/qtipc/qsharedmemory/qsystemlock/qsystemlock.pro create mode 100644 tests/auto/qtipc/qsharedmemory/qsystemlock/tst_qsystemlock.cpp create mode 100644 tests/auto/qtipc/qsharedmemory/src/qsystemlock.cpp create mode 100644 tests/auto/qtipc/qsharedmemory/src/qsystemlock.h create mode 100644 tests/auto/qtipc/qsharedmemory/src/qsystemlock_p.h create mode 100644 tests/auto/qtipc/qsharedmemory/src/qsystemlock_unix.cpp create mode 100644 tests/auto/qtipc/qsharedmemory/src/qsystemlock_win.cpp create mode 100644 tests/auto/qtipc/qsharedmemory/src/src.pri create mode 100644 tests/auto/qtipc/qsharedmemory/test/test.pro create mode 100644 tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp create mode 100644 tests/auto/qtipc/qsystemsemaphore/.gitignore create mode 100644 tests/auto/qtipc/qsystemsemaphore/files.qrc create mode 100644 tests/auto/qtipc/qsystemsemaphore/qsystemsemaphore.pro create mode 100644 tests/auto/qtipc/qsystemsemaphore/tst_qsystemsemaphore.cpp create mode 100644 tests/auto/qtipc/qtipc.pro diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 022b19a..9961e25 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -445,17 +445,16 @@ SUBDIRS += \ qplugin \ qpluginloader \ qscrollbar \ - qsharedmemory \ qsidebar \ qsizegrip \ qsqldriver \ - qsystemsemaphore \ qtconcurrentfilter \ qtconcurrentiteratekernel \ qtconcurrentmap \ qtconcurrentrun \ qtconcurrentthreadengine \ qthreadpool \ + qtipc \ qtokenautomaton \ qtouchevent \ qwidget_window \ diff --git a/tests/auto/qsharedmemory/.gitignore b/tests/auto/qsharedmemory/.gitignore deleted file mode 100644 index 03ddcf2..0000000 --- a/tests/auto/qsharedmemory/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -tst_qsharedmemory -lackey/lackey.exe -qsystemlock/tst_qsystemlock.exe diff --git a/tests/auto/qsharedmemory/lackey/lackey.pro b/tests/auto/qsharedmemory/lackey/lackey.pro deleted file mode 100644 index d25a50a..0000000 --- a/tests/auto/qsharedmemory/lackey/lackey.pro +++ /dev/null @@ -1,20 +0,0 @@ -include(../src/src.pri) - -QT = core script - -CONFIG += qtestlib - -DESTDIR = ./ - -win32: CONFIG += console -mac:CONFIG -= app_bundle - -requires(contains(QT_CONFIG,script)) - -DEFINES += QSHAREDMEMORY_DEBUG -DEFINES += QSYSTEMSEMAPHORE_DEBUG - -SOURCES += main.cpp -TARGET = lackey - - diff --git a/tests/auto/qsharedmemory/lackey/main.cpp b/tests/auto/qsharedmemory/lackey/main.cpp deleted file mode 100644 index fef8d22..0000000 --- a/tests/auto/qsharedmemory/lackey/main.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -class ScriptSystemSemaphore : public QObject -{ - Q_OBJECT - -public: - ScriptSystemSemaphore(QObject *parent = 0) : QObject(parent), ss(QString()) - { - } - -public slots: - bool acquire() - { - return ss.acquire(); - }; - - bool release(int n = 1) - { - return ss.release(n); - }; - - void setKey(const QString &key, int n = 0) - { - ss.setKey(key, n); - }; - - QString key() const - { - return ss.key(); - } - -private: - QSystemSemaphore ss; -}; - -class ScriptSystemLock : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString key WRITE setKey READ key) - -public: - ScriptSystemLock(QObject *parent = 0) : QObject(parent), sl(QString()) - { - } - -public slots: - - bool lockReadOnly() - { - return sl.lock(QSystemLock::ReadOnly); - } - - bool lock() - { - return sl.lock(); - }; - - bool unlock() - { - return sl.unlock(); - }; - - void setKey(const QString &key) - { - sl.setKey(key); - }; - - QString key() const - { - return sl.key(); - } - -private: - QSystemLock sl; -}; - -class ScriptSharedMemory : public QObject -{ - Q_OBJECT - Q_PROPERTY(bool attached READ isAttached) - Q_PROPERTY(QString key WRITE setKey READ key) - -public: - enum SharedMemoryError - { - NoError = 0, - PermissionDenied = 1, - InvalidSize = 2, - KeyError = 3, - AlreadyExists = 4, - NotFound = 5, - LockError = 6, - OutOfResources = 7, - UnknownError = 8 - }; - - ScriptSharedMemory(QObject *parent = 0) : QObject(parent) - { - } - -public slots: - void sleep(int x) const - { - QTest::qSleep(x); - } - - bool create(int size) - { - return sm.create(size); - }; - - bool createReadOnly(int size) - { - return sm.create(size, QSharedMemory::ReadOnly); - }; - - int size() const - { - return sm.size(); - }; - - bool attach() - { - return sm.attach(); - }; - - bool attachReadOnly() - { - return sm.attach(QSharedMemory::ReadOnly); - }; - - bool isAttached() const - { - return sm.isAttached(); - }; - - bool detach() - { - return sm.detach(); - }; - - int error() const - { - return (int)sm.error(); - }; - - QString errorString() const - { - return sm.errorString(); - }; - - void set(int i, QChar value) - { - ((char*)sm.data())[i] = value.toLatin1(); - } - - QString get(int i) - { - return QChar::fromLatin1(((char*)sm.data())[i]); - } - - char *data() const - { - return (char*)sm.data(); - }; - - void setKey(const QString &key) - { - sm.setKey(key); - }; - - QString key() const - { - return sm.key(); - } - - bool lock() - { - return sm.lock(); - } - - bool unlock() - { - return sm.unlock(); - } - -private: - QSharedMemory sm; -}; - -QT_BEGIN_NAMESPACE -Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSharedMemory, QObject*); -Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSystemLock, QObject*); -Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSystemSemaphore, QObject*); -QT_END_NAMESPACE - -static void interactive(QScriptEngine &eng) -{ -#ifdef Q_OS_WINCE - fprintf(stderr, "Interactive mode not supported on Windows CE\n"); - return; -#endif - QTextStream qin(stdin, QFile::ReadOnly); - - const char *qscript_prompt = "qs> "; - const char *dot_prompt = ".... "; - const char *prompt = qscript_prompt; - - QString code; - - forever { - QString line; - - printf("%s", prompt); - fflush(stdout); - - line = qin.readLine(); - if (line.isNull()) - break; - - code += line; - code += QLatin1Char('\n'); - - if (line.trimmed().isEmpty()) { - continue; - - } else if (! eng.canEvaluate(code)) { - prompt = dot_prompt; - - } else { - QScriptValue result = eng.evaluate(code); - code.clear(); - prompt = qscript_prompt; - if (!result.isUndefined()) - fprintf(stderr, "%s\n", qPrintable(result.toString())); - } - } -} - -int main(int argc, char *argv[]) -{ - QCoreApplication app(argc, argv); - - QScriptEngine eng; - QScriptValue globalObject = eng.globalObject(); - - QScriptValue sm = qScriptValueFromQMetaObject(&eng); - eng.globalObject().setProperty("ScriptSharedMemory", sm); - - QScriptValue sl = qScriptValueFromQMetaObject(&eng); - eng.globalObject().setProperty("ScriptSystemLock", sl); - - QScriptValue ss = qScriptValueFromQMetaObject(&eng); - eng.globalObject().setProperty("ScriptSystemSemaphore", ss); - - - if (! *++argv) { - interactive(eng); - return EXIT_SUCCESS; - } - - QStringList arguments = app.arguments(); - arguments.takeFirst(); - - while (!arguments.isEmpty()) { - QString fn = arguments.takeFirst(); - - if (fn == QLatin1String("-i")) { - interactive(eng); - break; - } - - QString contents; - - if (fn == QLatin1String("-")) { - QTextStream stream(stdin, QFile::ReadOnly); - contents = stream.readAll(); - } else { - QFile file(fn); - if (!file.exists()) { - fprintf(stderr, "%s doesn't exists\n", qPrintable(fn)); - return EXIT_FAILURE; - } - if (file.open(QFile::ReadOnly)) { - QTextStream stream(&file); - contents = stream.readAll(); - file.close(); - } - } - - if (contents.isEmpty()) - continue; - - if (contents[0] == '#') { - contents.prepend("//"); - QScriptValue args = eng.newArray(); - args.setProperty("0", QScriptValue(&eng, fn)); - int i = 1; - while (!arguments.isEmpty()) - args.setProperty(i++, QScriptValue(&eng, arguments.takeFirst())); - eng.currentContext()->activationObject().setProperty("args", args); - } - QScriptValue r = eng.evaluate(contents); - if (eng.hasUncaughtException()) { - int line = eng.uncaughtExceptionLineNumber(); - fprintf(stderr, "%d: %s\n\t%s\n\n", line, qPrintable(fn), qPrintable(r.toString())); - return EXIT_FAILURE; - } - if (r.isNumber()) - return r.toInt32(); - } - - return EXIT_SUCCESS; -} - -#include "main.moc" diff --git a/tests/auto/qsharedmemory/lackey/scripts/consumer.js b/tests/auto/qsharedmemory/lackey/scripts/consumer.js deleted file mode 100644 index 4d12dca..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/consumer.js +++ /dev/null @@ -1,41 +0,0 @@ -function QVERIFY(x, debugInfo) { - if (!(x)) { - print(debugInfo); - throw(debugInfo); - } -} - -var consumer = new ScriptSharedMemory; -consumer.setKey("market"); - -//print("consumer starting"); -var tries = 0;; -while(!consumer.attach()) { - if (tries == 5000) { - var message = "consumer exiting, waiting too long"; - print(message); - throw(message); - } - ++tries; - consumer.sleep(1); -} -//print("consumer attached"); - - -var i = 0; -while(true) { - QVERIFY(consumer.lock(), "lock"); - if (consumer.get(0) == 'Q') { - consumer.set(0, ++i); - //print ("consumer sets" + i); - } - if (consumer.get(0) == 'E') { - QVERIFY(consumer.unlock(), "unlock"); - break; - } - QVERIFY(consumer.unlock(), "unlock"); - consumer.sleep(10); -} - -//print("consumer detaching"); -QVERIFY(consumer.detach()); diff --git a/tests/auto/qsharedmemory/lackey/scripts/producer.js b/tests/auto/qsharedmemory/lackey/scripts/producer.js deleted file mode 100644 index e02cd8b..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/producer.js +++ /dev/null @@ -1,44 +0,0 @@ -function QVERIFY(x, debugInfo) { - if (!(x)) { - print(debugInfo); - throw(debugInfo); - } -} - -var producer = new ScriptSharedMemory; -producer.setKey("market"); - -var size = 1024; -if (!producer.create(size)) { - QVERIFY(producer.error() == 4, "create"); - QVERIFY(producer.attach()); -} -//print ("producer created and attached"); - -QVERIFY(producer.lock()); -producer.set(0, 'Q'); -QVERIFY(producer.unlock()); - -var i = 0; -while(i < 5) { - QVERIFY(producer.lock(), "lock"); - if (producer.get(0) == 'Q') { - QVERIFY(producer.unlock(), "unlock"); - producer.sleep(1); - continue; - } - //print("producer: " + i); - ++i; - producer.set(0, 'Q'); - QVERIFY(producer.unlock(), "unlock"); - producer.sleep(1); -} -QVERIFY(producer.lock()); -producer.set(0, 'E'); -QVERIFY(producer.unlock()); - -//print ("producer done"); - -// Sleep for a bit to let all consumers start, otherwise they will get stuck in the attach loop, -// because at least in Symbian the shared memory will be destroyed if there are no active handles to it. -producer.sleep(3000); \ No newline at end of file diff --git a/tests/auto/qsharedmemory/lackey/scripts/readonly_segfault.js b/tests/auto/qsharedmemory/lackey/scripts/readonly_segfault.js deleted file mode 100644 index 3eaf789..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/readonly_segfault.js +++ /dev/null @@ -1,4 +0,0 @@ -var sm = new ScriptSharedMemory; -sm.setKey("readonly_segfault"); -sm.createReadOnly(1024); -var data = sm.set(0, "a"); diff --git a/tests/auto/qsharedmemory/lackey/scripts/systemlock_read.js b/tests/auto/qsharedmemory/lackey/scripts/systemlock_read.js deleted file mode 100644 index 1048bc7..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/systemlock_read.js +++ /dev/null @@ -1,11 +0,0 @@ -function QVERIFY(x, debugInfo) { - if (!(x)) { - print(debugInfo); - throw(debugInfo); - } -} - -var lock = new ScriptSystemLock; -lock.setKey("market"); -QVERIFY(lock.lockReadOnly()); -QVERIFY(lock.unlock()); \ No newline at end of file diff --git a/tests/auto/qsharedmemory/lackey/scripts/systemlock_readwrite.js b/tests/auto/qsharedmemory/lackey/scripts/systemlock_readwrite.js deleted file mode 100644 index fc6367f..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/systemlock_readwrite.js +++ /dev/null @@ -1,11 +0,0 @@ -function QVERIFY(x, debugInfo) { - if (!(x)) { - print(debugInfo); - throw(debugInfo); - } -} - -var lock = new ScriptSystemLock; -lock.setKey("market"); -QVERIFY(lock.lock()); -QVERIFY(lock.unlock()); diff --git a/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquire.js b/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquire.js deleted file mode 100644 index 5cff429..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquire.js +++ /dev/null @@ -1,18 +0,0 @@ -#/bin/qscript -function QVERIFY(x, debugInfo) { - if (!(x)) { - print(debugInfo); - throw(debugInfo); - } -} - - -var sem = new ScriptSystemSemaphore; -sem.setKey("store"); - -var count = Number(args[1]); -if (isNaN(count)) - count = 1; -for (var i = 0; i < count; ++i) - QVERIFY(sem.acquire()); -print("done aquiring"); diff --git a/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquirerelease.js b/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquirerelease.js deleted file mode 100644 index cedde3f..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquirerelease.js +++ /dev/null @@ -1,11 +0,0 @@ -function QVERIFY(x, debugInfo) { - if (!(x)) { - print(debugInfo); - throw(debugInfo); - } -} - -var lock = new ScriptSystemSemaphore; -lock.setKey("store"); -QVERIFY(lock.acquire()); -QVERIFY(lock.release()); diff --git a/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_release.js b/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_release.js deleted file mode 100644 index c805e0f..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_release.js +++ /dev/null @@ -1,11 +0,0 @@ -function QVERIFY(x, debugInfo) { - if (!(x)) { - print(debugInfo); - throw(debugInfo); - } -} - -var sem = new ScriptSystemSemaphore; -sem.setKey("store"); -QVERIFY(sem.release()); -print ("done releasing"); diff --git a/tests/auto/qsharedmemory/qsharedmemory.pro b/tests/auto/qsharedmemory/qsharedmemory.pro deleted file mode 100644 index 0aad554..0000000 --- a/tests/auto/qsharedmemory/qsharedmemory.pro +++ /dev/null @@ -1,4 +0,0 @@ -TEMPLATE = subdirs -SUBDIRS = lackey test qsystemlock - - diff --git a/tests/auto/qsharedmemory/qsystemlock/qsystemlock.pro b/tests/auto/qsharedmemory/qsystemlock/qsystemlock.pro deleted file mode 100644 index e232443..0000000 --- a/tests/auto/qsharedmemory/qsystemlock/qsystemlock.pro +++ /dev/null @@ -1,22 +0,0 @@ -CONFIG += qttest_p4 -#QT = core - -include(../src/src.pri) -win32: CONFIG += console -mac:CONFIG -= app_bundle - -wince* { - DEFINES += SRCDIR=\\\"\\\" -} else:!symbian { - DEFINES += SRCDIR=\\\"$$PWD\\\" -} - -DESTDIR = ./ - -DEFINES += QSHAREDMEMORY_DEBUG -DEFINES += QSYSTEMSEMAPHORE_DEBUG - -SOURCES += tst_qsystemlock.cpp -TARGET = tst_qsystemlock - - diff --git a/tests/auto/qsharedmemory/qsystemlock/tst_qsystemlock.cpp b/tests/auto/qsharedmemory/qsystemlock/tst_qsystemlock.cpp deleted file mode 100644 index ea906b7..0000000 --- a/tests/auto/qsharedmemory/qsystemlock/tst_qsystemlock.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include -#include - -//TESTED_CLASS= -//TESTED_FILES= - -#ifdef Q_OS_SYMBIAN -// In Symbian OS test data is located in applications private dir -// And underlying Open C have application private dir in default search path -#define SRCDIR "" -#endif - - -#define EXISTING_SHARE "existing" - -class tst_QSystemLock : public QObject -{ - Q_OBJECT - -public: - tst_QSystemLock(); - virtual ~tst_QSystemLock(); - -public Q_SLOTS: - void init(); - void cleanup(); - -private slots: - void key_data(); - void key(); - - void basicLock(); - void complexLock(); - void lockModes(); - void sucessive(); - void processes_data(); - void processes(); - -private: - QSystemLock *existingLock; - -}; - -tst_QSystemLock::tst_QSystemLock() -{ -} - -tst_QSystemLock::~tst_QSystemLock() -{ -} - -void tst_QSystemLock::init() -{ - existingLock = new QSystemLock(EXISTING_SHARE); -} - -void tst_QSystemLock::cleanup() -{ - delete existingLock; -} - -void tst_QSystemLock::key_data() -{ - QTest::addColumn("constructorKey"); - QTest::addColumn("setKey"); - - QTest::newRow("null, null") << QString() << QString(); - QTest::newRow("null, one") << QString() << QString("one"); - QTest::newRow("one, two") << QString("one") << QString("two"); -} - -/*! - Basic key testing - */ -void tst_QSystemLock::key() -{ - QFETCH(QString, constructorKey); - QFETCH(QString, setKey); - - QSystemLock sl(constructorKey); - QCOMPARE(sl.key(), constructorKey); - sl.setKey(setKey); - QCOMPARE(sl.key(), setKey); -} - -void tst_QSystemLock::basicLock() -{ - QSystemLock lock("foo"); - QVERIFY(lock.lock()); - QVERIFY(lock.unlock()); -} - -void tst_QSystemLock::complexLock() -{ - QSystemLock lock("foo"); - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.unlock()); - - QVERIFY(lock.lock(QSystemLock::ReadWrite)); - QVERIFY(lock.unlock()); - - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.unlock()); - QVERIFY(lock.unlock()); -} - -void tst_QSystemLock::lockModes() -{ - QSystemLock reader1("library"); - QSystemLock reader2("library"); - - QSystemLock librarian("library"); - QVERIFY(reader1.lock(QSystemLock::ReadOnly)); - QVERIFY(reader2.lock(QSystemLock::ReadOnly)); - QVERIFY(reader1.unlock()); - QVERIFY(reader2.unlock()); - QVERIFY(librarian.lock(QSystemLock::ReadWrite)); - QVERIFY(librarian.unlock()); -} - -void tst_QSystemLock::sucessive() -{ - QSystemLock lock("library"); - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.unlock()); - QVERIFY(lock.unlock()); - QVERIFY(lock.unlock()); - QVERIFY(lock.unlock()); - QVERIFY(lock.unlock()); - QVERIFY(!lock.unlock()); -} - -void tst_QSystemLock::processes_data() -{ - QTest::addColumn("readOnly"); - QTest::addColumn("readWrite"); - for (int i = 0; i < 5; ++i) { - QTest::newRow("1/0 process") << 1 << 0; - QTest::newRow("0/1 process") << 0 << 1; - QTest::newRow("0/4 process") << 0 << 4; - QTest::newRow("1/1 process") << 1 << 1; - QTest::newRow("10/1 process") << 10 << 1; - QTest::newRow("1/10 process") << 1 << 10; - QTest::newRow("10/10 processes") << 10 << 10; - } -} - -/*! - Create external processes - */ -void tst_QSystemLock::processes() -{ - QSKIP("This test takes about 15 minutes and needs to be trimmed down before we can re-enable it", SkipAll); - QFETCH(int, readOnly); - QFETCH(int, readWrite); - - QStringList scripts; - for (int i = 0; i < readOnly; ++i) - scripts.append(QFileInfo(SRCDIR "/../lackey/scripts/systemlock_read.js").absoluteFilePath() ); - for (int i = 0; i < readWrite; ++i) - scripts.append(QFileInfo(SRCDIR "/../lackey/scripts/systemlock_readwrite.js").absoluteFilePath()); - - QList consumers; - unsigned int failedProcesses = 0; - for (int i = 0; i < scripts.count(); ++i) { - - QStringList arguments = QStringList() << scripts.at(i); - QProcess *p = new QProcess; - p->setProcessChannelMode(QProcess::ForwardedChannels); - - p->start("../lackey/lackey", arguments); - // test, if the process could be started. - - if (p->waitForStarted(2000)) - consumers.append(p); - else - ++failedProcesses; - } - - while (!consumers.isEmpty()) { - consumers.first()->waitForFinished(3000); - consumers.first()->kill(); - QCOMPARE(consumers.first()->exitStatus(), QProcess::NormalExit); - QCOMPARE(consumers.first()->exitCode(), 0); - delete consumers.takeFirst(); - } - QCOMPARE(failedProcesses, (unsigned int)(0)); -} - -QTEST_MAIN(tst_QSystemLock) -#include "tst_qsystemlock.moc" - diff --git a/tests/auto/qsharedmemory/src/qsystemlock.cpp b/tests/auto/qsharedmemory/src/qsystemlock.cpp deleted file mode 100644 index 4ead748..0000000 --- a/tests/auto/qsharedmemory/src/qsystemlock.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "qsystemlock.h" -#include "qsystemlock_p.h" - -#include - -/*! \class QSystemLocker - - \brief The QSystemLocker class is a convenience class that simplifies - locking and unlocking system locks. - - The purpose of QSystemLocker is to simplify QSystemLock locking and - unlocking. Locking and unlocking a QSystemLock in complex functions and - statements or in exception handling code is error-prone and difficult to - debug. QSystemLocker can be used in such situations to ensure that the - state of the locks is always well-defined. - - QSystemLocker should be created within a function where a QSystemLock needs - to be locked. The system lock is locked when QSystemLocker is created. If - locked, the system lock will be unlocked when the QSystemLocker is - destroyed. QSystemLocker can be unlocked with unlock() and relocked with - relock(). - - \sa QSystemLock - */ - -/*! \fn QSystemLocker::QSystemLocker() - - Constructs a QSystemLocker and locks \a lock. The \a lock will be - unlocked when the QSystemLocker is destroyed. If lock is zero, - QSystemLocker does nothing. - - \sa QSystemLock::lock() - */ - -/*! \fn QSystemLocker::~QSystemLocker() - - Destroys the QSystemLocker and unlocks it if it was - locked in the constructor. - - \sa QSystemLock::unlock() - */ - -/*! \fn QSystemLocker::systemLock() - - Returns a pointer to the lock that was locked in the constructor. - */ - -/*! \fn QSystemLocker::relock() - - Relocks an unlocked locker. - - \sa unlock() - */ - -/*! \fn QSystemLocker::unlock() - - Unlocks this locker. You can use relock() to lock it again. - It does not need to be locked when destroyed. - - \sa relock() - */ - -/*! \class QSystemLock - - \brief The QSystemLock class provides a system wide lock - that can be used between threads or processes. - - The purpose of a QSystemLocker is to protect an object that can be - accessed by multiple threads or processes such as shared memory or a file. - - For example, say there is a method which prints a message to a log file: - - void log(const QString &logText) - { - QSystemLock systemLock(QLatin1String("logfile")); - systemLock.lock(); - QFile file(QDir::temp() + QLatin1String("/log")); - if (file.open(QIODevice::Append)) { - QTextStream out(&file); - out << logText; - } - systemLock.unlock(); - } - - If this is called from two seperate processes the resulting log file is - guaranteed to contain both lines. - - When you call lock(), other threads or processes that try to call lock() - with the same key will block until the thread or process that got the lock - calls unlock(). - - A non-blocking alternative to lock() is tryLock(). - */ - -/*! - Constructs a new system lock with \a key. The lock is created in an - unlocked state. - - \sa lock(), key(). - */ -QSystemLock::QSystemLock(const QString &key) -{ - d = new QSystemLockPrivate; - setKey(key); -} - -/*! - Destroys a system lock. - - warning: This will not unlock the system lock if it has been locked. -*/ -QSystemLock::~QSystemLock() -{ - d->cleanHandle(); - delete d; -} - -/*! - Sets a new key to this system lock. - - \sa key() - */ -void QSystemLock::setKey(const QString &key) -{ - if (key == d->key) - return; - d->cleanHandle(); - d->lockCount = 0; - d->key = key; - // cache the file name so it doesn't have to be generated all the time. - d->fileName = d->makeKeyFileName(); - d->error = QSystemLock::NoError; - d->errorString = QString(); - d->handle(); -} - -/*! - Returns the key assigned to this system lock - - \sa setKey() - */ -QString QSystemLock::key() const -{ - return d->key; -} - -/*! - Locks the system lock. Lock \a mode can either be ReadOnly or ReadWrite. - If a mode is ReadOnly, attempts by other processes to obtain - ReadOnly locks will succeed, and ReadWrite attempts will block until - all of the ReadOnly locks are unlocked. If locked as ReadWrite, all - other attempts to lock will block until the lock is unlocked. A given - QSystemLock can be locked multiple times without blocking, and will - only be unlocked after a corresponding number of unlock() - calls are made. Returns true on success; otherwise returns false. - - \sa unlock(), tryLock() - */ -bool QSystemLock::lock(LockMode mode) -{ - if (d->lockCount > 0 && mode == ReadOnly && d->lockedMode == ReadWrite) { - qWarning() << "QSystemLock::lock readwrite lock on top of readonly lock."; - return false; - } - return d->modifySemaphore(QSystemLockPrivate::Lock, mode); -} - -/*! - Unlocks the system lock. - Returns true on success; otherwise returns false. - - \sa lock() - */ -bool QSystemLock::unlock() -{ - if (d->lockCount == 0) { - qWarning() << "QSystemLock::unlock: unlock with no lock."; - return false; - } - return d->modifySemaphore(QSystemLockPrivate::Unlock, d->lockedMode); -} - -/*! - Returns the type of error that occurred last or NoError. - - \sa errorString() - */ -QSystemLock::SystemLockError QSystemLock::error() const -{ - return d->error; -} - -/*! - Returns the human-readable message appropriate to the current error - reported by error(). If no suitable string is available, an empty - string is returned. - - \sa error() - */ -QString QSystemLock::errorString() const -{ - return d->errorString; -} - diff --git a/tests/auto/qsharedmemory/src/qsystemlock.h b/tests/auto/qsharedmemory/src/qsystemlock.h deleted file mode 100644 index 7cd6b89..0000000 --- a/tests/auto/qsharedmemory/src/qsystemlock.h +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QSYSTEMLOCK_H -#define QSYSTEMLOCK_H - -#include - -QT_BEGIN_HEADER - -#ifndef QT_NO_SYSTEMLOCK - -QT_FORWARD_DECLARE_CLASS(QSystemLockPrivate) - -class QSystemLock -{ - -public: - enum SystemLockError - { - NoError, - UnknownError - }; - - QSystemLock(const QString &key); - ~QSystemLock(); - - void setKey(const QString &key); - QString key() const; - - enum LockMode - { - ReadOnly, - ReadWrite - }; - - bool lock(LockMode mode = ReadWrite); - bool unlock(); - - SystemLockError error() const; - QString errorString() const; - -private: - Q_DISABLE_COPY(QSystemLock) - - QSystemLockPrivate *d; -}; - -class QSystemLocker -{ - -public: - inline QSystemLocker(QSystemLock *systemLock, - QSystemLock::LockMode mode = QSystemLock::ReadWrite) : q_lock(systemLock) - { - autoUnLocked = relock(mode); - } - - inline ~QSystemLocker() - { - if (autoUnLocked) - unlock(); - } - - inline QSystemLock *systemLock() const - { - return q_lock; - } - - inline bool relock(QSystemLock::LockMode mode = QSystemLock::ReadWrite) - { - return (q_lock && q_lock->lock(mode)); - } - - inline bool unlock() - { - if (q_lock && q_lock->unlock()) { - autoUnLocked = false; - return true; - } - return false; - } - -private: - Q_DISABLE_COPY(QSystemLocker) - - bool autoUnLocked; - QSystemLock *q_lock; -}; - -#endif // QT_NO_SYSTEMLOCK - -QT_END_HEADER - -#endif // QSYSTEMLOCK_H - diff --git a/tests/auto/qsharedmemory/src/qsystemlock_p.h b/tests/auto/qsharedmemory/src/qsystemlock_p.h deleted file mode 100644 index 7995a91..0000000 --- a/tests/auto/qsharedmemory/src/qsystemlock_p.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QSYSTEMLOCK_P_H -#define QSYSTEMLOCK_P_H - -#ifndef QT_NO_SYSTEMLOCK - -#include "qsystemlock.h" -#include "private/qsharedmemory_p.h" -#ifndef Q_OS_WINCE -#include -#endif - -#define MAX_LOCKS 64 - -class QSystemLockPrivate -{ - -public: - QSystemLockPrivate(); - - QString makeKeyFileName() - { - return QSharedMemoryPrivate::makePlatformSafeKey(key, QLatin1String("qipc_systemlock_")); - } - - void setErrorString(const QString &function); - -#ifdef Q_OS_WIN - HANDLE handle(); - bool lock(HANDLE, int count); - bool unlock(HANDLE, int count); -#else - key_t handle(); -#endif - void cleanHandle(); - - enum Operation { - Lock, - Unlock - }; - bool modifySemaphore(Operation op, QSystemLock::LockMode mode = QSystemLock::ReadOnly); - - QString key; - QString fileName; -#ifdef Q_OS_WIN - HANDLE semaphore; - HANDLE semaphoreLock; -#else - int semaphore; -#endif - int lockCount; - QSystemLock::LockMode lockedMode; - - QSystemLock::SystemLockError error; - QString errorString; - -private: -#ifndef Q_OS_WIN - key_t unix_key; - bool createdFile; - bool createdSemaphore; -#endif -}; - -#endif // QT_NO_SYSTEMLOCK - -#endif // QSYSTEMLOCK_P_H - diff --git a/tests/auto/qsharedmemory/src/qsystemlock_unix.cpp b/tests/auto/qsharedmemory/src/qsystemlock_unix.cpp deleted file mode 100644 index 525aa78..0000000 --- a/tests/auto/qsharedmemory/src/qsystemlock_unix.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "qsystemlock.h" -#include "qsystemlock_p.h" - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -// We have to define this as on some sem.h will have it -union qt_semun { - int val; /* value for SETVAL */ - struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ - unsigned short *array; /* array for GETALL, SETALL */ -}; - -#define tr(x) QT_TRANSLATE_NOOP(QLatin1String("QSystemLock"), (x)) - -#if defined(Q_OS_SYMBIAN) -int createUnixKeyFile(const QString &fileName) -{ - if (QFile::exists(fileName)) - return 0; - - int fd = open(QFile::encodeName(fileName).constData(), - O_EXCL | O_CREAT | O_RDWR, 0640); - if (-1 == fd) { - if (errno == EEXIST) - return 0; - return -1; - } else { - close(fd); - } - return 1; -} -#endif - -QSystemLockPrivate::QSystemLockPrivate() : - semaphore(-1), lockCount(0), - error(QSystemLock::NoError), unix_key(-1), createdFile(false), createdSemaphore(false) -{ -} - -void QSystemLockPrivate::setErrorString(const QString &function) -{ - switch (errno) { - case EIDRM: - errorString = function + QLatin1String(": ") + tr("The semaphore set was removed"); - error = QSystemLock::UnknownError; - break; - default: - errorString = function + QLatin1String(": ") + tr("unknown error"); - error = QSystemLock::UnknownError; - qWarning() << errorString << "key" << key << "errno" << errno << ERANGE << ENOMEM << EINVAL << EINTR << EFBIG << EFAULT << EAGAIN << EACCES << E2BIG; - } -} - -/*! - \internal - - Setup unix_key - */ -key_t QSystemLockPrivate::handle() -{ - if (key.isEmpty()) - return -1; - - // ftok requires that an actual file exists somewhere - // If we have already made at some point in the past, - // double check that it is still there. - if (-1 != unix_key) { - int aNewunix_key = ftok(QFile::encodeName(fileName).constData(), 'Q'); - if (aNewunix_key != unix_key) { - cleanHandle(); - } else { - return unix_key; - } - } - - // Create the file needed for ftok -#if defined(Q_OS_SYMBIAN) - int built = createUnixKeyFile(fileName); -#else - int built = QSharedMemoryPrivate::createUnixKeyFile(fileName); -#endif - if (-1 == built) - return -1; - createdFile = (1 == built); - - // Get the unix key for the created file - unix_key = ftok(QFile::encodeName(fileName).constData(), 'Q'); - if (-1 == unix_key) { - setErrorString(QLatin1String("QSystemLock::handle ftok")); - return -1; - } - - // Get semaphore - semaphore = semget(unix_key, 1, 0666 | IPC_CREAT | IPC_EXCL); - if (-1 == semaphore) { - if (errno == EEXIST) - semaphore = semget(unix_key, 1, 0666 | IPC_CREAT); - if (-1 == semaphore) { - setErrorString(QLatin1String("QSystemLock::handle semget")); - cleanHandle(); - return -1; - } - } else { - // Created semaphore, initialize value. - createdSemaphore = true; - qt_semun init_op; - init_op.val = MAX_LOCKS; - if (-1 == semctl(semaphore, 0, SETVAL, init_op)) { - setErrorString(QLatin1String("QSystemLock::handle semctl")); - cleanHandle(); - return -1; - } - } - - return unix_key; -} - -/*! - \internal - - Cleanup the unix_key - */ -void QSystemLockPrivate::cleanHandle() -{ - unix_key = -1; - - // remove the file if we made it - if (createdFile) { - if (!QFile::remove(fileName)) - setErrorString(QLatin1String("QSystemLock::cleanHandle QFile::remove")); - createdFile = false; - } - - if (createdSemaphore) { - if (-1 != semaphore) { - if (-1 == semctl(semaphore, 0, IPC_RMID)) { - setErrorString(QLatin1String("QSystemLock::cleanHandle semctl")); - } - semaphore = -1; - } - createdSemaphore = false; - } -} - -/*! - \internal - - modifySemaphore generates operation.sem_op and handles recursive behavior. - */ -bool QSystemLockPrivate::modifySemaphore(QSystemLockPrivate::Operation op, - QSystemLock::LockMode mode) -{ - if (-1 == handle()) - return false; - - if ((lockCount == 0 && op == Lock) || (lockCount > 0 && op == Unlock)) { - if (op == Unlock) { - --lockCount; - Q_ASSERT(lockCount >= 0); - if (lockCount > 0) - return true; - } - - struct sembuf operation; - operation.sem_num = 0; - operation.sem_op = (mode == QSystemLock::ReadWrite) ? MAX_LOCKS : 1; - if (op == Lock) - operation.sem_op *= -1; - operation.sem_flg = SEM_UNDO; - - if (-1 == semop(semaphore, &operation, 1)) { - setErrorString(QLatin1String("QSystemLock::modify")); - return false; - } - lockedMode = mode; - } - if (op == Lock) - lockCount++; - - return true; -} - diff --git a/tests/auto/qsharedmemory/src/qsystemlock_win.cpp b/tests/auto/qsharedmemory/src/qsystemlock_win.cpp deleted file mode 100644 index ac97100..0000000 --- a/tests/auto/qsharedmemory/src/qsystemlock_win.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "qsystemlock.h" -#include "qsystemlock_p.h" -#include -#include -QSystemLockPrivate::QSystemLockPrivate() : - semaphore(0), semaphoreLock(0), - lockCount(0), error(QSystemLock::NoError) -{ -} - -void QSystemLockPrivate::setErrorString(const QString &function) -{ - BOOL windowsError = GetLastError(); - if (windowsError == 0) - return; - errorString = function + QLatin1String(": ") - + QLatin1String("Unknown error"); - error = QSystemLock::UnknownError; - qWarning() << errorString << "key" << key << (int)windowsError << semaphore << semaphoreLock; -} - -/*! - \internal - - Setup the semaphore - */ -HANDLE QSystemLockPrivate::handle() -{ - // don't allow making handles on empty keys - if (key.isEmpty()) - return 0; - - // Create it if it doesn't already exists. - if (semaphore == 0) { - QString safeName = makeKeyFileName(); - semaphore = CreateSemaphore(0, MAX_LOCKS, MAX_LOCKS, (wchar_t*)safeName.utf16()); - - if (semaphore == 0) { - setErrorString(QLatin1String("QSystemLockPrivate::handle")); - return 0; - } - } - - if (semaphoreLock == 0) { - QString safeLockName = QSharedMemoryPrivate::makePlatformSafeKey(key + QLatin1String("lock"), QLatin1String("qipc_systemlock_")); - semaphoreLock = CreateSemaphore(0, 1, 1, (wchar_t*)safeLockName.utf16()); - - if (semaphoreLock == 0) { - setErrorString(QLatin1String("QSystemLockPrivate::handle")); - return 0; - } - } - - return semaphore; -} - -/*! - \internal - - Cleanup the semaphore - */ -void QSystemLockPrivate::cleanHandle() -{ - if (semaphore && !CloseHandle(semaphore)) - setErrorString(QLatin1String("QSystemLockPrivate::cleanHandle:")); - if (semaphoreLock && !CloseHandle(semaphoreLock)) - setErrorString(QLatin1String("QSystemLockPrivate::cleanHandle:")); - semaphore = 0; - semaphoreLock = 0; -} - -bool QSystemLockPrivate::lock(HANDLE handle, int count) -{ - if (count == 1) { - WaitForSingleObject(handle, INFINITE); - return true; - } - - int i = count; - while (i > 0) { - if (WAIT_OBJECT_0 == WaitForSingleObject(handle, 0)) { - --i; - } else { - // undo what we have done, sleep and then try again later - ReleaseSemaphore(handle, (count - i), 0); - i = count; - ReleaseSemaphore(semaphoreLock, 1, 0); - Sleep(1); - WaitForSingleObject(semaphoreLock, INFINITE); - } - } - return true; -} - -bool QSystemLockPrivate::unlock(HANDLE handle, int count) -{ - if (0 == ReleaseSemaphore(handle, count, 0)) { - setErrorString(QLatin1String("QSystemLockPrivate::unlock")); - return false; - } - return true; -} - -/*! - \internal - - modifySemaphore handles recursive behavior and modifies the semaphore. - */ -bool QSystemLockPrivate::modifySemaphore(QSystemLockPrivate::Operation op, - QSystemLock::LockMode mode) -{ - if (0 == handle()) - return false; - - if ((lockCount == 0 && op == Lock) || (lockCount > 0 && op == Unlock)) { - if (op == Unlock) { - --lockCount; - Q_ASSERT(lockCount >= 0); - if (lockCount > 0) - return true; - } - - int count = (mode == QSystemLock::ReadWrite) ? MAX_LOCKS : 1; - if (op == Lock) { - lock(semaphoreLock, 1); - lock(semaphore, count); - if (count != MAX_LOCKS) unlock(semaphoreLock, 1); - lockedMode = mode; - } else { - if (count == MAX_LOCKS) unlock(semaphoreLock, 1); - unlock(semaphore, count); - } - - } - if (op == Lock) - lockCount++; - - return true; -} - diff --git a/tests/auto/qsharedmemory/src/src.pri b/tests/auto/qsharedmemory/src/src.pri deleted file mode 100644 index 5bc9de6..0000000 --- a/tests/auto/qsharedmemory/src/src.pri +++ /dev/null @@ -1,10 +0,0 @@ -INCLUDEPATH += $$PWD -DEPENDPATH += $$PWD - -SOURCES += $$PWD/qsystemlock.cpp - -HEADERS += $$PWD/qsystemlock.h \ - $$PWD/qsystemlock_p.h - -unix:SOURCES += $$PWD/qsystemlock_unix.cpp -win32:SOURCES += $$PWD/qsystemlock_win.cpp diff --git a/tests/auto/qsharedmemory/test/test.pro b/tests/auto/qsharedmemory/test/test.pro deleted file mode 100644 index c9f4fec..0000000 --- a/tests/auto/qsharedmemory/test/test.pro +++ /dev/null @@ -1,37 +0,0 @@ -load(qttest_p4) - -include(../src/src.pri) -QT -= gui - -DEFINES += QSHAREDMEMORY_DEBUG -DEFINES += QSYSTEMSEMAPHORE_DEBUG - -SOURCES += ../tst_qsharedmemory.cpp -TARGET = ../tst_qsharedmemory - -!wince*:win32 { - CONFIG(debug, debug|release) { - TARGET = ../../debug/tst_qsharedmemory -} else { - TARGET = ../../release/tst_qsharedmemory - } -} - -wince*:{ -requires(contains(QT_CONFIG,script)) -QT += gui script -addFiles.sources = ../lackey/lackey.exe ../lackey/scripts -addFiles.path = lackey -DEPLOYMENT += addFiles -DEFINES += SRCDIR=\\\"\\\" -}else:symbian*{ -requires(contains(QT_CONFIG,script)) -QT += gui script -addFiles.sources = ../lackey/scripts -addFiles.path = /data/qsharedmemorytemp/lackey -addBin.sources = lackey.exe -addBin.path = /sys/bin -DEPLOYMENT += addFiles addBin -} else { -DEFINES += SRCDIR=\\\"$$PWD/../\\\" -} diff --git a/tests/auto/qsharedmemory/tst_qsharedmemory.cpp b/tests/auto/qsharedmemory/tst_qsharedmemory.cpp deleted file mode 100644 index cea75bf..0000000 --- a/tests/auto/qsharedmemory/tst_qsharedmemory.cpp +++ /dev/null @@ -1,778 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include -#include - -//TESTED_CLASS= -//TESTED_FILES= - -#define EXISTING_SHARE "existing" -#define EXISTING_SIZE 1024 - -#ifdef Q_OS_SYMBIAN -#define SRCDIR "c:/data/qsharedmemorytemp/" -#endif -Q_DECLARE_METATYPE(QSharedMemory::SharedMemoryError) -Q_DECLARE_METATYPE(QSharedMemory::AccessMode) - -class tst_QSharedMemory : public QObject -{ - Q_OBJECT - -public: - tst_QSharedMemory(); - virtual ~tst_QSharedMemory(); - -public Q_SLOTS: - void init(); - void cleanup(); - -private slots: - // basics - void constructor(); - void key_data(); - void key(); - void create_data(); - void create(); - void attach_data(); - void attach(); - void lock(); - - // custom edge cases - void removeWhileAttached(); - void emptyMemory(); - void readOnly(); - - // basics all together - void simpleProducerConsumer_data(); - void simpleProducerConsumer(); - void simpleDoubleProducerConsumer(); - - // with threads - void simpleThreadedProducerConsumer_data(); - void simpleThreadedProducerConsumer(); - - // with processes - void simpleProcessProducerConsumer_data(); - void simpleProcessProducerConsumer(); - - // extreme cases - void useTooMuchMemory(); - void attachTooMuch(); - -protected: - int remove(const QString &key); - - QString rememberKey(const QString &key) - { - if (key == EXISTING_SHARE) - return key; - if (!keys.contains(key)) { - keys.append(key); - remove(key); - } - return key; - } - - QStringList keys; - QList jail; - QSharedMemory *existingSharedMemory; -}; - -tst_QSharedMemory::tst_QSharedMemory() : existingSharedMemory(0) -{ -} - -tst_QSharedMemory::~tst_QSharedMemory() -{ -} - -void tst_QSharedMemory::init() -{ - existingSharedMemory = new QSharedMemory(EXISTING_SHARE); - if (!existingSharedMemory->create(EXISTING_SIZE)) { - QVERIFY(existingSharedMemory->error() == QSharedMemory::AlreadyExists); - } -} - -void tst_QSharedMemory::cleanup() -{ - delete existingSharedMemory; - qDeleteAll(jail.begin(), jail.end()); - jail.clear(); - - keys.append(EXISTING_SHARE); - for (int i = 0; i < keys.count(); ++i) { - QSharedMemory sm(keys.at(i)); - if (!sm.create(1024)) { - //if(sm.error() != QSharedMemory::KeyError) - // qWarning() << "test cleanup: remove failed:" << keys.at(i) << sm.error() << sm.errorString(); - sm.attach(); - sm.detach(); - remove(keys.at(i)); - } - } -} - -#ifndef Q_OS_WIN -#include "private/qsharedmemory_p.h" -#include -#include -#include -#endif - -int tst_QSharedMemory::remove(const QString &key) -{ -#ifndef Q_OS_WIN - // On unix the shared memory might exists from a previously failed test - // or segfault, remove it it does - if (key.isEmpty()) - return -1; - - // ftok requires that an actual file exists somewhere - QString fileName = QSharedMemoryPrivate::makePlatformSafeKey(key); - if (!QFile::exists(fileName)) { - //qDebug() << "exits failed"; - return -2; - } - - int unix_key = ftok(fileName.toLatin1().constData(), 'Q'); - if (-1 == unix_key) { - qDebug() << "ftok failed"; - return -3; - } - - int id = shmget(unix_key, 0, 0660); - if (-1 == id) { - qDebug() << "shmget failed"; - return -4; - } - - struct shmid_ds shmid_ds; - if (-1 == shmctl(id, IPC_RMID, &shmid_ds)) { - qDebug() << "shmctl failed"; - return -5; - } - return QFile::remove(fileName); -#else - Q_UNUSED(key); - return 0; -#endif -} - -/*! - Tests the default values - */ -void tst_QSharedMemory::constructor() -{ - QSharedMemory sm; - QCOMPARE(sm.key(), QString()); - QVERIFY(!sm.isAttached()); - QVERIFY(sm.data() == 0); - QCOMPARE(sm.size(), 0); - QCOMPARE(sm.error(), QSharedMemory::NoError); - QVERIFY(sm.errorString() == QString()); -} - -void tst_QSharedMemory::key_data() -{ - QTest::addColumn("constructorKey"); - QTest::addColumn("setKey"); - - QTest::newRow("null, null") << QString() << QString(); - QTest::newRow("null, one") << QString() << QString("one"); - QTest::newRow("one, two") << QString("one") << QString("two"); - QTest::newRow("invalid") << QString("o/e") << QString("t/o"); -} - -/*! - Basic key testing - */ -void tst_QSharedMemory::key() -{ - QFETCH(QString, constructorKey); - QFETCH(QString, setKey); - - QSharedMemory sm(constructorKey); - QCOMPARE(sm.key(), constructorKey); - sm.setKey(setKey); - QCOMPARE(sm.key(), setKey); - QCOMPARE(sm.isAttached(), false); - - QCOMPARE(sm.error(), QSharedMemory::NoError); - QVERIFY(sm.errorString() == QString()); - QVERIFY(sm.data() == 0); - QCOMPARE(sm.size(), 0); - - QCOMPARE(sm.detach(), false); -} - -void tst_QSharedMemory::create_data() -{ - QTest::addColumn("key"); - QTest::addColumn("size"); - QTest::addColumn("canCreate"); - QTest::addColumn("error"); - - QTest::newRow("null key") << QString() << 1024 - << false << QSharedMemory::LockError; - QTest::newRow("-1 size") << QString("negsize") << -1 - << false << QSharedMemory::InvalidSize; - QTest::newRow("nor size") << QString("norsize") << 1024 - << true << QSharedMemory::NoError; - QTest::newRow("already exists") << QString(EXISTING_SHARE) << EXISTING_SIZE - << false << QSharedMemory::AlreadyExists; -} - -/*! - Basic create testing - */ -void tst_QSharedMemory::create() -{ - QFETCH(QString, key); - QFETCH(int, size); - QFETCH(bool, canCreate); - QFETCH(QSharedMemory::SharedMemoryError, error); - - QSharedMemory sm(rememberKey(key)); - QCOMPARE(sm.create(size), canCreate); - if(sm.error() != error) - qDebug() << sm.errorString(); - QCOMPARE(sm.key(), key); - if (canCreate) { - QVERIFY(sm.errorString() == QString()); - QVERIFY(sm.data() != 0); - QVERIFY(sm.size() != 0); - } else { - QVERIFY(sm.data() == 0); - QVERIFY(sm.errorString() != QString()); - } -} - -void tst_QSharedMemory::attach_data() -{ - QTest::addColumn("key"); - QTest::addColumn("exists"); - QTest::addColumn("error"); - - QTest::newRow("null key") << QString() << false << QSharedMemory::LockError; - QTest::newRow("doesn't exists") << QString("doesntexists") << false << QSharedMemory::NotFound; - QTest::newRow("already exists") << QString(EXISTING_SHARE) << true << QSharedMemory::NoError; -} - -/*! - Basic attach/detach testing - */ -void tst_QSharedMemory::attach() -{ - QFETCH(QString, key); - QFETCH(bool, exists); - QFETCH(QSharedMemory::SharedMemoryError, error); -#ifdef Q_OS_HPUX - if (QLatin1String(QTest::currentDataTag()) == QLatin1String("already exists")) { - QSKIP("HPUX doesn't allow for multiple attaches per process", SkipSingle); - } -#endif - QSharedMemory sm(key); - QCOMPARE(sm.attach(), exists); - QCOMPARE(sm.isAttached(), exists); - QCOMPARE(sm.error(), error); - QCOMPARE(sm.key(), key); - if (exists) { - QVERIFY(sm.data() != 0); - QVERIFY(sm.size() != 0); - QCOMPARE(sm.errorString(), QString()); - QVERIFY(sm.detach()); - // Make sure detach doesn't screw up something and we can't re-attach. - QVERIFY(sm.attach()); - QVERIFY(sm.detach()); - QCOMPARE(sm.size(), 0); - QVERIFY(sm.data() == 0); - } else { - QVERIFY(sm.data() == 0); - QVERIFY(sm.size() == 0); - QVERIFY(sm.errorString() != QString()); - QVERIFY(!sm.detach()); - } -} - -void tst_QSharedMemory::lock() -{ - QSharedMemory shm; - QVERIFY(!shm.lock()); - QCOMPARE(shm.error(), QSharedMemory::LockError); - - shm.setKey(QLatin1String("qsharedmemory")); - - QVERIFY(!shm.lock()); - QCOMPARE(shm.error(), QSharedMemory::LockError); - - QVERIFY(shm.create(100)); - QVERIFY(shm.lock()); - QTest::ignoreMessage(QtWarningMsg, "QSharedMemory::lock: already locked"); - QVERIFY(shm.lock()); - // don't lock forever -} - -/*! - Other shared memory are allowed to be attached after we remove, - but new shared memory are not allowed to attach after a remove. - */ -void tst_QSharedMemory::removeWhileAttached() -{ -#ifdef Q_OS_HPUX - QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); -#endif - rememberKey("one"); - - // attach 1 - QSharedMemory *smOne = new QSharedMemory(QLatin1String("one")); - QVERIFY(smOne->create(1024)); - QVERIFY(smOne->isAttached()); - - // attach 2 - QSharedMemory *smTwo = new QSharedMemory(QLatin1String("one")); - QVERIFY(smTwo->attach()); - QVERIFY(smTwo->isAttached()); - - // detach 1 and remove, remove one first to catch another error. - delete smOne; - delete smTwo; - - // three shouldn't be able to attach - QSharedMemory smThree(QLatin1String("one")); - QVERIFY(!smThree.attach()); - QCOMPARE(smThree.error(), QSharedMemory::NotFound); -} - -/*! - The memory should be set to 0 after created. - */ -void tst_QSharedMemory::emptyMemory() -{ - QSharedMemory sm(rememberKey(QLatin1String("voidland"))); - int size = 1024; - QVERIFY(sm.create(size, QSharedMemory::ReadOnly)); - char *get = (char*)sm.data(); - char null = 0; - for (int i = 0; i < size; ++i) - QCOMPARE(get[i], null); -} - -/*! - Verify that attach with ReadOnly is actually read only - by writing to data and causing a segfault. -*/ -void tst_QSharedMemory::readOnly() -{ -#ifdef Q_OS_WIN - QSKIP("This test opens a crash dialog on Windows", SkipSingle); -#endif -#if defined (Q_OS_SYMBIAN) - QSKIP("Readonly shared memory is not supported in symbian", SkipAll); -#endif - QString program = "./lackey/lackey"; - QStringList arguments; - rememberKey("readonly_segfault"); - arguments << SRCDIR "lackey/scripts/readonly_segfault.js"; - - // ### on windows disable the popup somehow - QProcess p; - p.start(program, arguments); - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.waitForFinished(); - QCOMPARE(p.error(), QProcess::Crashed); -} - -/*! - Keep making shared memory until the kernel stops us. - */ -void tst_QSharedMemory::useTooMuchMemory() -{ -#ifdef Q_OS_LINUX - bool success = true; - int count = 0; - while (success) { - QString key = QString("maxmemorytest_%1").arg(count++); - QSharedMemory *sm = new QSharedMemory(rememberKey(key)); - QVERIFY(sm); - jail.append(sm); - int size = 32768 * 1024; - success = sm->create(size); - if (!success && sm->error() == QSharedMemory::AlreadyExists) { - // left over from a crash, clean it up - sm->attach(); - sm->detach(); - success = sm->create(size); - } - - if (!success) { - QVERIFY(!sm->isAttached()); - QCOMPARE(sm->key(), key); - QCOMPARE(sm->size(), 0); - QVERIFY(sm->data() == 0); - if (sm->error() != QSharedMemory::OutOfResources) - qDebug() << sm->error() << sm->errorString(); - // ### Linux wont return OutOfResources if there are not enough semaphores to use. - QVERIFY(sm->error() == QSharedMemory::OutOfResources - || sm->error() == QSharedMemory::LockError); - QVERIFY(sm->errorString() != QString()); - QVERIFY(!sm->attach()); - QVERIFY(!sm->detach()); - } else { - QVERIFY(sm->isAttached()); - } - } -#endif -} - -/*! - Create one shared memory (government) and see how many other shared memories (wars) we can - attach before the system runs out of resources. - */ -void tst_QSharedMemory::attachTooMuch() -{ - QSKIP("disabled", SkipAll); -#ifdef Q_OS_HPUX - QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); -#endif -#ifdef Q_OS_WINCE - QSKIP("This nearly kills the system itself, so skip for Qt/WinCE", SkipAll); -#endif - QSharedMemory government(rememberKey("government")); - QVERIFY(government.create(1024)); - while (true) { - QSharedMemory *war = new QSharedMemory(government.key()); - QVERIFY(war); - jail.append(war); - if (!war->attach()) { - QVERIFY(!war->isAttached()); - QCOMPARE(war->key(), government.key()); - QCOMPARE(war->size(), 0); - QVERIFY(war->data() == 0); - QCOMPARE(war->error(), QSharedMemory::OutOfResources); - QVERIFY(war->errorString() != QString()); - QVERIFY(!war->detach()); - break; - } else { - QVERIFY(war->isAttached()); - } - } -} - -void tst_QSharedMemory::simpleProducerConsumer_data() -{ - QTest::addColumn("mode"); - - QTest::newRow("readonly") << QSharedMemory::ReadOnly; - QTest::newRow("readwrite") << QSharedMemory::ReadWrite; -} - -/*! - The basic consumer producer that rounds out the basic testing. - If this fails then any muli-threading/process might fail (but be - harder to debug) - - This doesn't require nor test any locking system. - */ -void tst_QSharedMemory::simpleProducerConsumer() -{ -#ifdef Q_OS_HPUX - QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); -#endif - QFETCH(QSharedMemory::AccessMode, mode); - - rememberKey(QLatin1String("market")); - QSharedMemory producer(QLatin1String("market")); - QSharedMemory consumer(QLatin1String("market")); - int size = 512; - QVERIFY(producer.create(size)); - QVERIFY(consumer.attach(mode)); - - char *put = (char*)producer.data(); - char *get = (char*)consumer.data(); - // On Windows CE you always have ReadWrite access. Thus - // ViewMapOfFile returns the same pointer - // On Symbian, the address will always be same, as - // write protection of chunks is not currently supported by Symbian -#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) - QVERIFY(put != get); -#endif - for (int i = 0; i < size; ++i) { - put[i] = 'Q'; - QCOMPARE(get[i], 'Q'); - } - QVERIFY(consumer.detach()); -} - -void tst_QSharedMemory::simpleDoubleProducerConsumer() -{ -#ifdef Q_OS_HPUX - QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); -#endif - rememberKey(QLatin1String("market")); - QSharedMemory producer(QLatin1String("market")); - int size = 512; - QVERIFY(producer.create(size)); - QVERIFY(producer.detach()); - QVERIFY(producer.create(size)); - - { - QSharedMemory consumer(QLatin1String("market")); - QVERIFY(consumer.attach()); - } -} - -class Consumer : public QThread -{ - -public: - void run() - { - QSharedMemory consumer(QLatin1String("market")); - while (!consumer.attach()) { - if (consumer.error() != QSharedMemory::NotFound) - qDebug() << "consumer: failed to connect" << consumer.error() << consumer.errorString(); - QVERIFY(consumer.error() == QSharedMemory::NotFound || consumer.error() == QSharedMemory::KeyError); - QTest::qWait(1); - } - - char *memory = (char*)consumer.data(); - - int i = 0; - while (true) { - if(!consumer.lock()) - break; - if (memory[0] == 'Q') - memory[0] = ++i; - if (memory[0] == 'E') { - memory[1]++; - QVERIFY(consumer.unlock()); - break; - } - QVERIFY(consumer.unlock()); - QTest::qWait(1); - } - - QVERIFY(consumer.detach()); - } -}; - -class Producer : public QThread -{ - -public: - void run() - { - QSharedMemory producer(QLatin1String("market")); - int size = 1024; - if (!producer.create(size)) { - // left over from a crash... - if (producer.error() == QSharedMemory::AlreadyExists) { - producer.attach(); - producer.detach(); - QVERIFY(producer.create(size)); - } - } - QVERIFY(producer.isAttached()); - char *memory = (char*)producer.data(); - memory[1] = '0'; - QTime timer; - timer.start(); - int i = 0; - while (i < 5 && timer.elapsed() < 5000) { - QVERIFY(producer.lock()); - if (memory[0] == 'Q') { - QVERIFY(producer.unlock()); - QTest::qWait(1); - continue; - } - ++i; - memory[0] = 'Q'; - QVERIFY(producer.unlock()); - QTest::qWait(1); - } - - // tell everyone to quit - QVERIFY(producer.lock()); - memory[0] = 'E'; - QVERIFY(producer.unlock()); - -#if defined(Q_OS_SYMBIAN) - // Sleep a while to ensure that consumers start properly - QTest::qSleep(1000); -#endif - } -private: - -}; - -void tst_QSharedMemory::simpleThreadedProducerConsumer_data() -{ - QTest::addColumn("producerIsThread"); - QTest::addColumn("threads"); - for (int i = 0; i < 5; ++i) { - QTest::newRow("1 consumer, producer is thread") << true << 1; - QTest::newRow("1 consumer, producer is this") << false << 1; - QTest::newRow("5 consumers, producer is thread") << true << 5; - QTest::newRow("5 consumers, producer is this") << false << 5; - } -} - -/*! - The basic producer/consumer, but this time using threads. - */ -void tst_QSharedMemory::simpleThreadedProducerConsumer() -{ - QFETCH(bool, producerIsThread); - QFETCH(int, threads); - rememberKey(QLatin1String("market")); - -#if defined Q_OS_HPUX && defined __ia64 - QSKIP("This test locks up on gravlaks.troll.no", SkipSingle); -#endif - - Producer p; -#if defined(Q_OS_SYMBIAN) - enum - { - /** - * The maximum stack size. - */ - SymbianStackSize = 0x14000 - }; - p.setStackSize(SymbianStackSize); -#endif - if (producerIsThread) - p.start(); - - QList consumers; - for (int i = 0; i < threads; ++i) { - consumers.append(new Consumer()); -#if defined(Q_OS_SYMBIAN) - consumers.last()->setStackSize(SymbianStackSize); -#endif - consumers.last()->start(); - } - - if (!producerIsThread) - p.run(); - - p.wait(5000); - while (!consumers.isEmpty()) { - QVERIFY(consumers.first()->wait(5000)); - delete consumers.takeFirst(); - } -} - -void tst_QSharedMemory::simpleProcessProducerConsumer_data() -{ - QTest::addColumn("processes"); - int tries = 5; - for (int i = 0; i < tries; ++i) { - QTest::newRow("1 process") << 1; - QTest::newRow("5 processes") << 5; - } -} - -/*! - Create external processes that produce and consume. - */ -void tst_QSharedMemory::simpleProcessProducerConsumer() -{ -#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) - QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); -#endif - QFETCH(int, processes); - - rememberKey("market"); - -#ifndef Q_OS_WINCE - QStringList arguments = QStringList() << SRCDIR "lackey/scripts/producer.js"; -#else - QStringList arguments = QStringList() << QFileInfo(SRCDIR "lackey/scripts/producer.js").absoluteFilePath(); -#endif - QProcess producer; - producer.setProcessChannelMode(QProcess::ForwardedChannels); - producer.start( "./lackey/lackey", arguments); - producer.waitForStarted(); - QVERIFY(producer.error() != QProcess::FailedToStart); - - QList consumers; - unsigned int failedProcesses = 0; - for (int i = 0; i < processes; ++i) { -#ifndef Q_OS_WINCE - QStringList arguments = QStringList() << SRCDIR "lackey/scripts/consumer.js"; -#else - QStringList arguments = QStringList() << QFileInfo(SRCDIR "lackey/scripts/consumer.js").absoluteFilePath(); -#endif - QProcess *p = new QProcess; - p->setProcessChannelMode(QProcess::ForwardedChannels); - p->start("./lackey/lackey", arguments); - - if (p->waitForStarted(2000)) - consumers.append(p); - else - ++failedProcesses; - } - - QVERIFY(producer.waitForFinished(5000)); - - bool consumerFailed = false; - - while (!consumers.isEmpty()) { - QVERIFY(consumers.first()->waitForFinished(3000)); - if (consumers.first()->state() == QProcess::Running || - consumers.first()->exitStatus() != QProcess::NormalExit || - consumers.first()->exitCode() != 0) { - consumerFailed = true; - } - delete consumers.takeFirst(); - } - QCOMPARE(consumerFailed, false); - QCOMPARE(failedProcesses, (unsigned int)(0)); -} - -QTEST_MAIN(tst_QSharedMemory) -#include "tst_qsharedmemory.moc" - diff --git a/tests/auto/qsystemsemaphore/.gitignore b/tests/auto/qsystemsemaphore/.gitignore deleted file mode 100644 index 2b60bfb..0000000 --- a/tests/auto/qsystemsemaphore/.gitignore +++ /dev/null @@ -1 +0,0 @@ -tst_qsystemsemaphore diff --git a/tests/auto/qsystemsemaphore/files.qrc b/tests/auto/qsystemsemaphore/files.qrc deleted file mode 100644 index 7b344ba..0000000 --- a/tests/auto/qsystemsemaphore/files.qrc +++ /dev/null @@ -1,7 +0,0 @@ - - - ../qsharedmemory/lackey/scripts/systemsemaphore_acquire.js - ../qsharedmemory/lackey/scripts/systemsemaphore_release.js - ../qsharedmemory/lackey/scripts/systemsemaphore_acquirerelease.js - - diff --git a/tests/auto/qsystemsemaphore/qsystemsemaphore.pro b/tests/auto/qsystemsemaphore/qsystemsemaphore.pro deleted file mode 100644 index a3f4a34..0000000 --- a/tests/auto/qsystemsemaphore/qsystemsemaphore.pro +++ /dev/null @@ -1,4 +0,0 @@ -TEMPLATE = subdirs -SUBDIRS = ../qsharedmemory/lackey test - - diff --git a/tests/auto/qsystemsemaphore/test/test.pro b/tests/auto/qsystemsemaphore/test/test.pro deleted file mode 100644 index ed7898c..0000000 --- a/tests/auto/qsystemsemaphore/test/test.pro +++ /dev/null @@ -1,40 +0,0 @@ -CONFIG += qttest_p4 -#QT = core - -include(../../qsharedmemory/src/src.pri) -win32: CONFIG += console - -DEFINES += QSHAREDMEMORY_DEBUG -DEFINES += QSYSTEMSEMAPHORE_DEBUG - -SOURCES += ../tst_qsystemsemaphore.cpp -TARGET = tst_qsystemsemaphore -DESTDIR = ../ -win32 { - CONFIG(debug, debug|release): DESTDIR = ../debug - else: DESTDIR = ../release -} - -RESOURCES += ../files.qrc - -wince*: { -requires(contains(QT_CONFIG,script)) -# this test calls lackey, which then again depends on QtScript. -# let's add it here so that it gets deployed easily -QT += script -lackey.sources = ../../qsharedmemory/lackey/lackey.exe -lackey.path = ../qsharedmemory/lackey - -DEPLOYMENT += lackey -} - -symbian: { -requires(contains(QT_CONFIG,script)) -# this test calls lackey, which then again depends on QtScript. -# let's add it here so that it gets deployed easily -QT += script - -lackey.sources = ../../qsharedmemory/lackey/lackey.exe -lackey.path = /sys/bin -DEPLOYMENT += lackey -} diff --git a/tests/auto/qsystemsemaphore/tst_qsystemsemaphore.cpp b/tests/auto/qsystemsemaphore/tst_qsystemsemaphore.cpp deleted file mode 100644 index bf4efdc..0000000 --- a/tests/auto/qsystemsemaphore/tst_qsystemsemaphore.cpp +++ /dev/null @@ -1,302 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include -#include -//TESTED_CLASS= -//TESTED_FILES= - -#define EXISTING_SHARE "existing" -#define LACKYLOC "../qsharedmemory/lackey" -#define LACKYWAITTIME 10000 - -class tst_QSystemSemaphore : public QObject -{ - Q_OBJECT - -public: - tst_QSystemSemaphore(); - virtual ~tst_QSystemSemaphore(); - -public Q_SLOTS: - void init(); - void cleanup(); - -private slots: - void key_data(); - void key(); - - void basicacquire(); - void complexacquire(); - - void basicProcesses(); - - void processes_data(); - void processes(); - - void undo(); - void initialValue(); - -private: - QSystemSemaphore *existingLock; - - QString makeFile(const QString &resource) - { - QFile memory(resource); - if (!memory.open(QIODevice::ReadOnly)) { - qDebug() << "error reading resource" << resource; - return QString(); - } - QTemporaryFile *file = new QTemporaryFile; - file->open(); - file->write(memory.readAll()); - tempFiles.append(file); - file->flush(); -#ifdef Q_OS_WINCE - // flush does not flush to disk on Windows CE. It flushes it into its application - // cache. Thus we need to close the file to be able that other processes(lackey) can read it - QString fileName = file->fileName(); - file->close(); - return fileName; -#endif - return file->fileName(); - } - - QString acquire_js() { return makeFile(":/systemsemaphore_acquire.js"); } - QString release_js() { return makeFile(":/systemsemaphore_release.js"); } - QString acquirerelease_js() { return makeFile(":/systemsemaphore_acquirerelease.js"); } - QList tempFiles; -}; - -tst_QSystemSemaphore::tst_QSystemSemaphore() -{ - if (!QFile::exists(LACKYLOC "/lackey")) - qWarning() << "lackey executable doesn't exists!"; -} - -tst_QSystemSemaphore::~tst_QSystemSemaphore() -{ - qDeleteAll(tempFiles); -} - -void tst_QSystemSemaphore::init() -{ - existingLock = new QSystemSemaphore(EXISTING_SHARE, 1, QSystemSemaphore::Create); -} - -void tst_QSystemSemaphore::cleanup() -{ - delete existingLock; -} - -void tst_QSystemSemaphore::key_data() -{ - QTest::addColumn("constructorKey"); - QTest::addColumn("setKey"); - - QTest::newRow("null, null") << QString() << QString(); - QTest::newRow("null, one") << QString() << QString("one"); - QTest::newRow("one, two") << QString("one") << QString("two"); -} - -/*! - Basic key testing - */ -void tst_QSystemSemaphore::key() -{ - QFETCH(QString, constructorKey); - QFETCH(QString, setKey); - - QSystemSemaphore sem(constructorKey); - QCOMPARE(sem.key(), constructorKey); - QCOMPARE(sem.error(), QSystemSemaphore::NoError); - QCOMPARE(sem.errorString(), QString()); - - sem.setKey(setKey); - QCOMPARE(sem.key(), setKey); - QCOMPARE(sem.error(), QSystemSemaphore::NoError); - QCOMPARE(sem.errorString(), QString()); -} - -void tst_QSystemSemaphore::basicacquire() -{ - QSystemSemaphore sem("QSystemSemaphore_basicacquire", 1, QSystemSemaphore::Create); - QVERIFY(sem.acquire()); - QCOMPARE(sem.error(), QSystemSemaphore::NoError); - QVERIFY(sem.release()); - QCOMPARE(sem.error(), QSystemSemaphore::NoError); - QCOMPARE(sem.errorString(), QString()); -} - -void tst_QSystemSemaphore::complexacquire() -{ - QSystemSemaphore sem("QSystemSemaphore_complexacquire", 2, QSystemSemaphore::Create); - QVERIFY(sem.acquire()); - QVERIFY(sem.release()); - QVERIFY(sem.acquire()); - QVERIFY(sem.release()); - QVERIFY(sem.acquire()); - QVERIFY(sem.acquire()); - QVERIFY(sem.release()); - QVERIFY(sem.release()); - QCOMPARE(sem.error(), QSystemSemaphore::NoError); - QCOMPARE(sem.errorString(), QString()); -} - -void tst_QSystemSemaphore::basicProcesses() -{ -#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) - QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); -#endif - QSystemSemaphore sem("store", 0, QSystemSemaphore::Create); - - QStringList acquireArguments = QStringList() << acquire_js(); - QStringList releaseArguments = QStringList() << release_js(); - QProcess acquire; - acquire.setProcessChannelMode(QProcess::ForwardedChannels); - - QProcess release; - release.setProcessChannelMode(QProcess::ForwardedChannels); - - acquire.start(LACKYLOC "/lackey", acquireArguments); - acquire.waitForFinished(LACKYWAITTIME); - QVERIFY(acquire.state() == QProcess::Running); - acquire.kill(); - release.start(LACKYLOC "/lackey", releaseArguments); - acquire.waitForFinished(LACKYWAITTIME); - release.waitForFinished(LACKYWAITTIME); - QVERIFY(acquire.state() == QProcess::NotRunning); -} - -void tst_QSystemSemaphore::processes_data() -{ - QTest::addColumn("processes"); - for (int i = 0; i < 5; ++i) { - QTest::newRow("1 process") << 1; - QTest::newRow("3 process") << 3; - QTest::newRow("10 process") << 10; - } -} - -void tst_QSystemSemaphore::processes() -{ -#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) - QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); -#endif - QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); - - QFETCH(int, processes); - QStringList scripts; - for (int i = 0; i < processes; ++i) - scripts.append(acquirerelease_js()); - - QList consumers; - for (int i = 0; i < scripts.count(); ++i) { - QStringList arguments = QStringList() << scripts.at(i); - QProcess *p = new QProcess; - p->setProcessChannelMode(QProcess::ForwardedChannels); - consumers.append(p); - p->start(LACKYLOC "/lackey", arguments); - } - - while (!consumers.isEmpty()) { - consumers.first()->waitForFinished(); - QCOMPARE(consumers.first()->exitStatus(), QProcess::NormalExit); - QCOMPARE(consumers.first()->exitCode(), 0); - delete consumers.takeFirst(); - } -} - -void tst_QSystemSemaphore::undo() -{ -#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) - QSKIP("This test only checks a unix behavior", SkipSingle); -#endif - - QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); - - QStringList acquireArguments = QStringList() << acquire_js(); - QProcess acquire; - acquire.setProcessChannelMode(QProcess::ForwardedChannels); - acquire.start(LACKYLOC "/lackey", acquireArguments); - acquire.waitForFinished(LACKYWAITTIME); - QVERIFY(acquire.state()== QProcess::NotRunning); - - // At process exit the kernel should auto undo - - acquire.start(LACKYLOC "/lackey", acquireArguments); - acquire.waitForFinished(LACKYWAITTIME); - QVERIFY(acquire.state()== QProcess::NotRunning); -} - -void tst_QSystemSemaphore::initialValue() -{ -#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) - QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); -#endif - QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); - - QStringList acquireArguments = QStringList() << acquire_js(); - QStringList releaseArguments = QStringList() << release_js(); - QProcess acquire; - acquire.setProcessChannelMode(QProcess::ForwardedChannels); - - QProcess release; - release.setProcessChannelMode(QProcess::ForwardedChannels); - - acquire.start(LACKYLOC "/lackey", acquireArguments); - acquire.waitForFinished(LACKYWAITTIME); - QVERIFY(acquire.state()== QProcess::NotRunning); - - acquire.start(LACKYLOC "/lackey", acquireArguments << "2"); - acquire.waitForFinished(LACKYWAITTIME); - QVERIFY(acquire.state()== QProcess::Running); - acquire.kill(); - - release.start(LACKYLOC "/lackey", releaseArguments); - acquire.waitForFinished(LACKYWAITTIME); - release.waitForFinished(LACKYWAITTIME); - QVERIFY(acquire.state()== QProcess::NotRunning); -} -QTEST_MAIN(tst_QSystemSemaphore) -#include "tst_qsystemsemaphore.moc" - diff --git a/tests/auto/qtipc/lackey/lackey.pro b/tests/auto/qtipc/lackey/lackey.pro new file mode 100644 index 0000000..3912312 --- /dev/null +++ b/tests/auto/qtipc/lackey/lackey.pro @@ -0,0 +1,20 @@ +include(../qsharedmemory/src/src.pri) + +QT = core script + +CONFIG += qtestlib + +DESTDIR = ./ + +win32: CONFIG += console +mac:CONFIG -= app_bundle + +requires(contains(QT_CONFIG,script)) + +DEFINES += QSHAREDMEMORY_DEBUG +DEFINES += QSYSTEMSEMAPHORE_DEBUG + +SOURCES += main.cpp +TARGET = lackey + + diff --git a/tests/auto/qtipc/lackey/main.cpp b/tests/auto/qtipc/lackey/main.cpp new file mode 100644 index 0000000..fef8d22 --- /dev/null +++ b/tests/auto/qtipc/lackey/main.cpp @@ -0,0 +1,370 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +class ScriptSystemSemaphore : public QObject +{ + Q_OBJECT + +public: + ScriptSystemSemaphore(QObject *parent = 0) : QObject(parent), ss(QString()) + { + } + +public slots: + bool acquire() + { + return ss.acquire(); + }; + + bool release(int n = 1) + { + return ss.release(n); + }; + + void setKey(const QString &key, int n = 0) + { + ss.setKey(key, n); + }; + + QString key() const + { + return ss.key(); + } + +private: + QSystemSemaphore ss; +}; + +class ScriptSystemLock : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString key WRITE setKey READ key) + +public: + ScriptSystemLock(QObject *parent = 0) : QObject(parent), sl(QString()) + { + } + +public slots: + + bool lockReadOnly() + { + return sl.lock(QSystemLock::ReadOnly); + } + + bool lock() + { + return sl.lock(); + }; + + bool unlock() + { + return sl.unlock(); + }; + + void setKey(const QString &key) + { + sl.setKey(key); + }; + + QString key() const + { + return sl.key(); + } + +private: + QSystemLock sl; +}; + +class ScriptSharedMemory : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool attached READ isAttached) + Q_PROPERTY(QString key WRITE setKey READ key) + +public: + enum SharedMemoryError + { + NoError = 0, + PermissionDenied = 1, + InvalidSize = 2, + KeyError = 3, + AlreadyExists = 4, + NotFound = 5, + LockError = 6, + OutOfResources = 7, + UnknownError = 8 + }; + + ScriptSharedMemory(QObject *parent = 0) : QObject(parent) + { + } + +public slots: + void sleep(int x) const + { + QTest::qSleep(x); + } + + bool create(int size) + { + return sm.create(size); + }; + + bool createReadOnly(int size) + { + return sm.create(size, QSharedMemory::ReadOnly); + }; + + int size() const + { + return sm.size(); + }; + + bool attach() + { + return sm.attach(); + }; + + bool attachReadOnly() + { + return sm.attach(QSharedMemory::ReadOnly); + }; + + bool isAttached() const + { + return sm.isAttached(); + }; + + bool detach() + { + return sm.detach(); + }; + + int error() const + { + return (int)sm.error(); + }; + + QString errorString() const + { + return sm.errorString(); + }; + + void set(int i, QChar value) + { + ((char*)sm.data())[i] = value.toLatin1(); + } + + QString get(int i) + { + return QChar::fromLatin1(((char*)sm.data())[i]); + } + + char *data() const + { + return (char*)sm.data(); + }; + + void setKey(const QString &key) + { + sm.setKey(key); + }; + + QString key() const + { + return sm.key(); + } + + bool lock() + { + return sm.lock(); + } + + bool unlock() + { + return sm.unlock(); + } + +private: + QSharedMemory sm; +}; + +QT_BEGIN_NAMESPACE +Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSharedMemory, QObject*); +Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSystemLock, QObject*); +Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSystemSemaphore, QObject*); +QT_END_NAMESPACE + +static void interactive(QScriptEngine &eng) +{ +#ifdef Q_OS_WINCE + fprintf(stderr, "Interactive mode not supported on Windows CE\n"); + return; +#endif + QTextStream qin(stdin, QFile::ReadOnly); + + const char *qscript_prompt = "qs> "; + const char *dot_prompt = ".... "; + const char *prompt = qscript_prompt; + + QString code; + + forever { + QString line; + + printf("%s", prompt); + fflush(stdout); + + line = qin.readLine(); + if (line.isNull()) + break; + + code += line; + code += QLatin1Char('\n'); + + if (line.trimmed().isEmpty()) { + continue; + + } else if (! eng.canEvaluate(code)) { + prompt = dot_prompt; + + } else { + QScriptValue result = eng.evaluate(code); + code.clear(); + prompt = qscript_prompt; + if (!result.isUndefined()) + fprintf(stderr, "%s\n", qPrintable(result.toString())); + } + } +} + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + + QScriptEngine eng; + QScriptValue globalObject = eng.globalObject(); + + QScriptValue sm = qScriptValueFromQMetaObject(&eng); + eng.globalObject().setProperty("ScriptSharedMemory", sm); + + QScriptValue sl = qScriptValueFromQMetaObject(&eng); + eng.globalObject().setProperty("ScriptSystemLock", sl); + + QScriptValue ss = qScriptValueFromQMetaObject(&eng); + eng.globalObject().setProperty("ScriptSystemSemaphore", ss); + + + if (! *++argv) { + interactive(eng); + return EXIT_SUCCESS; + } + + QStringList arguments = app.arguments(); + arguments.takeFirst(); + + while (!arguments.isEmpty()) { + QString fn = arguments.takeFirst(); + + if (fn == QLatin1String("-i")) { + interactive(eng); + break; + } + + QString contents; + + if (fn == QLatin1String("-")) { + QTextStream stream(stdin, QFile::ReadOnly); + contents = stream.readAll(); + } else { + QFile file(fn); + if (!file.exists()) { + fprintf(stderr, "%s doesn't exists\n", qPrintable(fn)); + return EXIT_FAILURE; + } + if (file.open(QFile::ReadOnly)) { + QTextStream stream(&file); + contents = stream.readAll(); + file.close(); + } + } + + if (contents.isEmpty()) + continue; + + if (contents[0] == '#') { + contents.prepend("//"); + QScriptValue args = eng.newArray(); + args.setProperty("0", QScriptValue(&eng, fn)); + int i = 1; + while (!arguments.isEmpty()) + args.setProperty(i++, QScriptValue(&eng, arguments.takeFirst())); + eng.currentContext()->activationObject().setProperty("args", args); + } + QScriptValue r = eng.evaluate(contents); + if (eng.hasUncaughtException()) { + int line = eng.uncaughtExceptionLineNumber(); + fprintf(stderr, "%d: %s\n\t%s\n\n", line, qPrintable(fn), qPrintable(r.toString())); + return EXIT_FAILURE; + } + if (r.isNumber()) + return r.toInt32(); + } + + return EXIT_SUCCESS; +} + +#include "main.moc" diff --git a/tests/auto/qtipc/lackey/scripts/consumer.js b/tests/auto/qtipc/lackey/scripts/consumer.js new file mode 100644 index 0000000..4d12dca --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/consumer.js @@ -0,0 +1,41 @@ +function QVERIFY(x, debugInfo) { + if (!(x)) { + print(debugInfo); + throw(debugInfo); + } +} + +var consumer = new ScriptSharedMemory; +consumer.setKey("market"); + +//print("consumer starting"); +var tries = 0;; +while(!consumer.attach()) { + if (tries == 5000) { + var message = "consumer exiting, waiting too long"; + print(message); + throw(message); + } + ++tries; + consumer.sleep(1); +} +//print("consumer attached"); + + +var i = 0; +while(true) { + QVERIFY(consumer.lock(), "lock"); + if (consumer.get(0) == 'Q') { + consumer.set(0, ++i); + //print ("consumer sets" + i); + } + if (consumer.get(0) == 'E') { + QVERIFY(consumer.unlock(), "unlock"); + break; + } + QVERIFY(consumer.unlock(), "unlock"); + consumer.sleep(10); +} + +//print("consumer detaching"); +QVERIFY(consumer.detach()); diff --git a/tests/auto/qtipc/lackey/scripts/producer.js b/tests/auto/qtipc/lackey/scripts/producer.js new file mode 100644 index 0000000..e02cd8b --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/producer.js @@ -0,0 +1,44 @@ +function QVERIFY(x, debugInfo) { + if (!(x)) { + print(debugInfo); + throw(debugInfo); + } +} + +var producer = new ScriptSharedMemory; +producer.setKey("market"); + +var size = 1024; +if (!producer.create(size)) { + QVERIFY(producer.error() == 4, "create"); + QVERIFY(producer.attach()); +} +//print ("producer created and attached"); + +QVERIFY(producer.lock()); +producer.set(0, 'Q'); +QVERIFY(producer.unlock()); + +var i = 0; +while(i < 5) { + QVERIFY(producer.lock(), "lock"); + if (producer.get(0) == 'Q') { + QVERIFY(producer.unlock(), "unlock"); + producer.sleep(1); + continue; + } + //print("producer: " + i); + ++i; + producer.set(0, 'Q'); + QVERIFY(producer.unlock(), "unlock"); + producer.sleep(1); +} +QVERIFY(producer.lock()); +producer.set(0, 'E'); +QVERIFY(producer.unlock()); + +//print ("producer done"); + +// Sleep for a bit to let all consumers start, otherwise they will get stuck in the attach loop, +// because at least in Symbian the shared memory will be destroyed if there are no active handles to it. +producer.sleep(3000); \ No newline at end of file diff --git a/tests/auto/qtipc/lackey/scripts/readonly_segfault.js b/tests/auto/qtipc/lackey/scripts/readonly_segfault.js new file mode 100644 index 0000000..3eaf789 --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/readonly_segfault.js @@ -0,0 +1,4 @@ +var sm = new ScriptSharedMemory; +sm.setKey("readonly_segfault"); +sm.createReadOnly(1024); +var data = sm.set(0, "a"); diff --git a/tests/auto/qtipc/lackey/scripts/systemlock_read.js b/tests/auto/qtipc/lackey/scripts/systemlock_read.js new file mode 100644 index 0000000..1048bc7 --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/systemlock_read.js @@ -0,0 +1,11 @@ +function QVERIFY(x, debugInfo) { + if (!(x)) { + print(debugInfo); + throw(debugInfo); + } +} + +var lock = new ScriptSystemLock; +lock.setKey("market"); +QVERIFY(lock.lockReadOnly()); +QVERIFY(lock.unlock()); \ No newline at end of file diff --git a/tests/auto/qtipc/lackey/scripts/systemlock_readwrite.js b/tests/auto/qtipc/lackey/scripts/systemlock_readwrite.js new file mode 100644 index 0000000..fc6367f --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/systemlock_readwrite.js @@ -0,0 +1,11 @@ +function QVERIFY(x, debugInfo) { + if (!(x)) { + print(debugInfo); + throw(debugInfo); + } +} + +var lock = new ScriptSystemLock; +lock.setKey("market"); +QVERIFY(lock.lock()); +QVERIFY(lock.unlock()); diff --git a/tests/auto/qtipc/lackey/scripts/systemsemaphore_acquire.js b/tests/auto/qtipc/lackey/scripts/systemsemaphore_acquire.js new file mode 100644 index 0000000..5cff429 --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/systemsemaphore_acquire.js @@ -0,0 +1,18 @@ +#/bin/qscript +function QVERIFY(x, debugInfo) { + if (!(x)) { + print(debugInfo); + throw(debugInfo); + } +} + + +var sem = new ScriptSystemSemaphore; +sem.setKey("store"); + +var count = Number(args[1]); +if (isNaN(count)) + count = 1; +for (var i = 0; i < count; ++i) + QVERIFY(sem.acquire()); +print("done aquiring"); diff --git a/tests/auto/qtipc/lackey/scripts/systemsemaphore_acquirerelease.js b/tests/auto/qtipc/lackey/scripts/systemsemaphore_acquirerelease.js new file mode 100644 index 0000000..cedde3f --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/systemsemaphore_acquirerelease.js @@ -0,0 +1,11 @@ +function QVERIFY(x, debugInfo) { + if (!(x)) { + print(debugInfo); + throw(debugInfo); + } +} + +var lock = new ScriptSystemSemaphore; +lock.setKey("store"); +QVERIFY(lock.acquire()); +QVERIFY(lock.release()); diff --git a/tests/auto/qtipc/lackey/scripts/systemsemaphore_release.js b/tests/auto/qtipc/lackey/scripts/systemsemaphore_release.js new file mode 100644 index 0000000..c805e0f --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/systemsemaphore_release.js @@ -0,0 +1,11 @@ +function QVERIFY(x, debugInfo) { + if (!(x)) { + print(debugInfo); + throw(debugInfo); + } +} + +var sem = new ScriptSystemSemaphore; +sem.setKey("store"); +QVERIFY(sem.release()); +print ("done releasing"); diff --git a/tests/auto/qtipc/qsharedmemory/.gitignore b/tests/auto/qtipc/qsharedmemory/.gitignore new file mode 100644 index 0000000..03ddcf2 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/.gitignore @@ -0,0 +1,3 @@ +tst_qsharedmemory +lackey/lackey.exe +qsystemlock/tst_qsystemlock.exe diff --git a/tests/auto/qtipc/qsharedmemory/qsharedmemory.pro b/tests/auto/qtipc/qsharedmemory/qsharedmemory.pro new file mode 100644 index 0000000..9fef8e4 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/qsharedmemory.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS = test qsystemlock + + diff --git a/tests/auto/qtipc/qsharedmemory/qsystemlock/qsystemlock.pro b/tests/auto/qtipc/qsharedmemory/qsystemlock/qsystemlock.pro new file mode 100644 index 0000000..e232443 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/qsystemlock/qsystemlock.pro @@ -0,0 +1,22 @@ +CONFIG += qttest_p4 +#QT = core + +include(../src/src.pri) +win32: CONFIG += console +mac:CONFIG -= app_bundle + +wince* { + DEFINES += SRCDIR=\\\"\\\" +} else:!symbian { + DEFINES += SRCDIR=\\\"$$PWD\\\" +} + +DESTDIR = ./ + +DEFINES += QSHAREDMEMORY_DEBUG +DEFINES += QSYSTEMSEMAPHORE_DEBUG + +SOURCES += tst_qsystemlock.cpp +TARGET = tst_qsystemlock + + diff --git a/tests/auto/qtipc/qsharedmemory/qsystemlock/tst_qsystemlock.cpp b/tests/auto/qtipc/qsharedmemory/qsystemlock/tst_qsystemlock.cpp new file mode 100644 index 0000000..ea906b7 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/qsystemlock/tst_qsystemlock.cpp @@ -0,0 +1,239 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include + +//TESTED_CLASS= +//TESTED_FILES= + +#ifdef Q_OS_SYMBIAN +// In Symbian OS test data is located in applications private dir +// And underlying Open C have application private dir in default search path +#define SRCDIR "" +#endif + + +#define EXISTING_SHARE "existing" + +class tst_QSystemLock : public QObject +{ + Q_OBJECT + +public: + tst_QSystemLock(); + virtual ~tst_QSystemLock(); + +public Q_SLOTS: + void init(); + void cleanup(); + +private slots: + void key_data(); + void key(); + + void basicLock(); + void complexLock(); + void lockModes(); + void sucessive(); + void processes_data(); + void processes(); + +private: + QSystemLock *existingLock; + +}; + +tst_QSystemLock::tst_QSystemLock() +{ +} + +tst_QSystemLock::~tst_QSystemLock() +{ +} + +void tst_QSystemLock::init() +{ + existingLock = new QSystemLock(EXISTING_SHARE); +} + +void tst_QSystemLock::cleanup() +{ + delete existingLock; +} + +void tst_QSystemLock::key_data() +{ + QTest::addColumn("constructorKey"); + QTest::addColumn("setKey"); + + QTest::newRow("null, null") << QString() << QString(); + QTest::newRow("null, one") << QString() << QString("one"); + QTest::newRow("one, two") << QString("one") << QString("two"); +} + +/*! + Basic key testing + */ +void tst_QSystemLock::key() +{ + QFETCH(QString, constructorKey); + QFETCH(QString, setKey); + + QSystemLock sl(constructorKey); + QCOMPARE(sl.key(), constructorKey); + sl.setKey(setKey); + QCOMPARE(sl.key(), setKey); +} + +void tst_QSystemLock::basicLock() +{ + QSystemLock lock("foo"); + QVERIFY(lock.lock()); + QVERIFY(lock.unlock()); +} + +void tst_QSystemLock::complexLock() +{ + QSystemLock lock("foo"); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.unlock()); + + QVERIFY(lock.lock(QSystemLock::ReadWrite)); + QVERIFY(lock.unlock()); + + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.unlock()); + QVERIFY(lock.unlock()); +} + +void tst_QSystemLock::lockModes() +{ + QSystemLock reader1("library"); + QSystemLock reader2("library"); + + QSystemLock librarian("library"); + QVERIFY(reader1.lock(QSystemLock::ReadOnly)); + QVERIFY(reader2.lock(QSystemLock::ReadOnly)); + QVERIFY(reader1.unlock()); + QVERIFY(reader2.unlock()); + QVERIFY(librarian.lock(QSystemLock::ReadWrite)); + QVERIFY(librarian.unlock()); +} + +void tst_QSystemLock::sucessive() +{ + QSystemLock lock("library"); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.unlock()); + QVERIFY(lock.unlock()); + QVERIFY(lock.unlock()); + QVERIFY(lock.unlock()); + QVERIFY(lock.unlock()); + QVERIFY(!lock.unlock()); +} + +void tst_QSystemLock::processes_data() +{ + QTest::addColumn("readOnly"); + QTest::addColumn("readWrite"); + for (int i = 0; i < 5; ++i) { + QTest::newRow("1/0 process") << 1 << 0; + QTest::newRow("0/1 process") << 0 << 1; + QTest::newRow("0/4 process") << 0 << 4; + QTest::newRow("1/1 process") << 1 << 1; + QTest::newRow("10/1 process") << 10 << 1; + QTest::newRow("1/10 process") << 1 << 10; + QTest::newRow("10/10 processes") << 10 << 10; + } +} + +/*! + Create external processes + */ +void tst_QSystemLock::processes() +{ + QSKIP("This test takes about 15 minutes and needs to be trimmed down before we can re-enable it", SkipAll); + QFETCH(int, readOnly); + QFETCH(int, readWrite); + + QStringList scripts; + for (int i = 0; i < readOnly; ++i) + scripts.append(QFileInfo(SRCDIR "/../lackey/scripts/systemlock_read.js").absoluteFilePath() ); + for (int i = 0; i < readWrite; ++i) + scripts.append(QFileInfo(SRCDIR "/../lackey/scripts/systemlock_readwrite.js").absoluteFilePath()); + + QList consumers; + unsigned int failedProcesses = 0; + for (int i = 0; i < scripts.count(); ++i) { + + QStringList arguments = QStringList() << scripts.at(i); + QProcess *p = new QProcess; + p->setProcessChannelMode(QProcess::ForwardedChannels); + + p->start("../lackey/lackey", arguments); + // test, if the process could be started. + + if (p->waitForStarted(2000)) + consumers.append(p); + else + ++failedProcesses; + } + + while (!consumers.isEmpty()) { + consumers.first()->waitForFinished(3000); + consumers.first()->kill(); + QCOMPARE(consumers.first()->exitStatus(), QProcess::NormalExit); + QCOMPARE(consumers.first()->exitCode(), 0); + delete consumers.takeFirst(); + } + QCOMPARE(failedProcesses, (unsigned int)(0)); +} + +QTEST_MAIN(tst_QSystemLock) +#include "tst_qsystemlock.moc" + diff --git a/tests/auto/qtipc/qsharedmemory/src/qsystemlock.cpp b/tests/auto/qtipc/qsharedmemory/src/qsystemlock.cpp new file mode 100644 index 0000000..4ead748 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/src/qsystemlock.cpp @@ -0,0 +1,246 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include "qsystemlock.h" +#include "qsystemlock_p.h" + +#include + +/*! \class QSystemLocker + + \brief The QSystemLocker class is a convenience class that simplifies + locking and unlocking system locks. + + The purpose of QSystemLocker is to simplify QSystemLock locking and + unlocking. Locking and unlocking a QSystemLock in complex functions and + statements or in exception handling code is error-prone and difficult to + debug. QSystemLocker can be used in such situations to ensure that the + state of the locks is always well-defined. + + QSystemLocker should be created within a function where a QSystemLock needs + to be locked. The system lock is locked when QSystemLocker is created. If + locked, the system lock will be unlocked when the QSystemLocker is + destroyed. QSystemLocker can be unlocked with unlock() and relocked with + relock(). + + \sa QSystemLock + */ + +/*! \fn QSystemLocker::QSystemLocker() + + Constructs a QSystemLocker and locks \a lock. The \a lock will be + unlocked when the QSystemLocker is destroyed. If lock is zero, + QSystemLocker does nothing. + + \sa QSystemLock::lock() + */ + +/*! \fn QSystemLocker::~QSystemLocker() + + Destroys the QSystemLocker and unlocks it if it was + locked in the constructor. + + \sa QSystemLock::unlock() + */ + +/*! \fn QSystemLocker::systemLock() + + Returns a pointer to the lock that was locked in the constructor. + */ + +/*! \fn QSystemLocker::relock() + + Relocks an unlocked locker. + + \sa unlock() + */ + +/*! \fn QSystemLocker::unlock() + + Unlocks this locker. You can use relock() to lock it again. + It does not need to be locked when destroyed. + + \sa relock() + */ + +/*! \class QSystemLock + + \brief The QSystemLock class provides a system wide lock + that can be used between threads or processes. + + The purpose of a QSystemLocker is to protect an object that can be + accessed by multiple threads or processes such as shared memory or a file. + + For example, say there is a method which prints a message to a log file: + + void log(const QString &logText) + { + QSystemLock systemLock(QLatin1String("logfile")); + systemLock.lock(); + QFile file(QDir::temp() + QLatin1String("/log")); + if (file.open(QIODevice::Append)) { + QTextStream out(&file); + out << logText; + } + systemLock.unlock(); + } + + If this is called from two seperate processes the resulting log file is + guaranteed to contain both lines. + + When you call lock(), other threads or processes that try to call lock() + with the same key will block until the thread or process that got the lock + calls unlock(). + + A non-blocking alternative to lock() is tryLock(). + */ + +/*! + Constructs a new system lock with \a key. The lock is created in an + unlocked state. + + \sa lock(), key(). + */ +QSystemLock::QSystemLock(const QString &key) +{ + d = new QSystemLockPrivate; + setKey(key); +} + +/*! + Destroys a system lock. + + warning: This will not unlock the system lock if it has been locked. +*/ +QSystemLock::~QSystemLock() +{ + d->cleanHandle(); + delete d; +} + +/*! + Sets a new key to this system lock. + + \sa key() + */ +void QSystemLock::setKey(const QString &key) +{ + if (key == d->key) + return; + d->cleanHandle(); + d->lockCount = 0; + d->key = key; + // cache the file name so it doesn't have to be generated all the time. + d->fileName = d->makeKeyFileName(); + d->error = QSystemLock::NoError; + d->errorString = QString(); + d->handle(); +} + +/*! + Returns the key assigned to this system lock + + \sa setKey() + */ +QString QSystemLock::key() const +{ + return d->key; +} + +/*! + Locks the system lock. Lock \a mode can either be ReadOnly or ReadWrite. + If a mode is ReadOnly, attempts by other processes to obtain + ReadOnly locks will succeed, and ReadWrite attempts will block until + all of the ReadOnly locks are unlocked. If locked as ReadWrite, all + other attempts to lock will block until the lock is unlocked. A given + QSystemLock can be locked multiple times without blocking, and will + only be unlocked after a corresponding number of unlock() + calls are made. Returns true on success; otherwise returns false. + + \sa unlock(), tryLock() + */ +bool QSystemLock::lock(LockMode mode) +{ + if (d->lockCount > 0 && mode == ReadOnly && d->lockedMode == ReadWrite) { + qWarning() << "QSystemLock::lock readwrite lock on top of readonly lock."; + return false; + } + return d->modifySemaphore(QSystemLockPrivate::Lock, mode); +} + +/*! + Unlocks the system lock. + Returns true on success; otherwise returns false. + + \sa lock() + */ +bool QSystemLock::unlock() +{ + if (d->lockCount == 0) { + qWarning() << "QSystemLock::unlock: unlock with no lock."; + return false; + } + return d->modifySemaphore(QSystemLockPrivate::Unlock, d->lockedMode); +} + +/*! + Returns the type of error that occurred last or NoError. + + \sa errorString() + */ +QSystemLock::SystemLockError QSystemLock::error() const +{ + return d->error; +} + +/*! + Returns the human-readable message appropriate to the current error + reported by error(). If no suitable string is available, an empty + string is returned. + + \sa error() + */ +QString QSystemLock::errorString() const +{ + return d->errorString; +} + diff --git a/tests/auto/qtipc/qsharedmemory/src/qsystemlock.h b/tests/auto/qtipc/qsharedmemory/src/qsystemlock.h new file mode 100644 index 0000000..7cd6b89 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/src/qsystemlock.h @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef QSYSTEMLOCK_H +#define QSYSTEMLOCK_H + +#include + +QT_BEGIN_HEADER + +#ifndef QT_NO_SYSTEMLOCK + +QT_FORWARD_DECLARE_CLASS(QSystemLockPrivate) + +class QSystemLock +{ + +public: + enum SystemLockError + { + NoError, + UnknownError + }; + + QSystemLock(const QString &key); + ~QSystemLock(); + + void setKey(const QString &key); + QString key() const; + + enum LockMode + { + ReadOnly, + ReadWrite + }; + + bool lock(LockMode mode = ReadWrite); + bool unlock(); + + SystemLockError error() const; + QString errorString() const; + +private: + Q_DISABLE_COPY(QSystemLock) + + QSystemLockPrivate *d; +}; + +class QSystemLocker +{ + +public: + inline QSystemLocker(QSystemLock *systemLock, + QSystemLock::LockMode mode = QSystemLock::ReadWrite) : q_lock(systemLock) + { + autoUnLocked = relock(mode); + } + + inline ~QSystemLocker() + { + if (autoUnLocked) + unlock(); + } + + inline QSystemLock *systemLock() const + { + return q_lock; + } + + inline bool relock(QSystemLock::LockMode mode = QSystemLock::ReadWrite) + { + return (q_lock && q_lock->lock(mode)); + } + + inline bool unlock() + { + if (q_lock && q_lock->unlock()) { + autoUnLocked = false; + return true; + } + return false; + } + +private: + Q_DISABLE_COPY(QSystemLocker) + + bool autoUnLocked; + QSystemLock *q_lock; +}; + +#endif // QT_NO_SYSTEMLOCK + +QT_END_HEADER + +#endif // QSYSTEMLOCK_H + diff --git a/tests/auto/qtipc/qsharedmemory/src/qsystemlock_p.h b/tests/auto/qtipc/qsharedmemory/src/qsystemlock_p.h new file mode 100644 index 0000000..7995a91 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/src/qsystemlock_p.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef QSYSTEMLOCK_P_H +#define QSYSTEMLOCK_P_H + +#ifndef QT_NO_SYSTEMLOCK + +#include "qsystemlock.h" +#include "private/qsharedmemory_p.h" +#ifndef Q_OS_WINCE +#include +#endif + +#define MAX_LOCKS 64 + +class QSystemLockPrivate +{ + +public: + QSystemLockPrivate(); + + QString makeKeyFileName() + { + return QSharedMemoryPrivate::makePlatformSafeKey(key, QLatin1String("qipc_systemlock_")); + } + + void setErrorString(const QString &function); + +#ifdef Q_OS_WIN + HANDLE handle(); + bool lock(HANDLE, int count); + bool unlock(HANDLE, int count); +#else + key_t handle(); +#endif + void cleanHandle(); + + enum Operation { + Lock, + Unlock + }; + bool modifySemaphore(Operation op, QSystemLock::LockMode mode = QSystemLock::ReadOnly); + + QString key; + QString fileName; +#ifdef Q_OS_WIN + HANDLE semaphore; + HANDLE semaphoreLock; +#else + int semaphore; +#endif + int lockCount; + QSystemLock::LockMode lockedMode; + + QSystemLock::SystemLockError error; + QString errorString; + +private: +#ifndef Q_OS_WIN + key_t unix_key; + bool createdFile; + bool createdSemaphore; +#endif +}; + +#endif // QT_NO_SYSTEMLOCK + +#endif // QSYSTEMLOCK_P_H + diff --git a/tests/auto/qtipc/qsharedmemory/src/qsystemlock_unix.cpp b/tests/auto/qtipc/qsharedmemory/src/qsystemlock_unix.cpp new file mode 100644 index 0000000..525aa78 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/src/qsystemlock_unix.cpp @@ -0,0 +1,233 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include "qsystemlock.h" +#include "qsystemlock_p.h" + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +// We have to define this as on some sem.h will have it +union qt_semun { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ + unsigned short *array; /* array for GETALL, SETALL */ +}; + +#define tr(x) QT_TRANSLATE_NOOP(QLatin1String("QSystemLock"), (x)) + +#if defined(Q_OS_SYMBIAN) +int createUnixKeyFile(const QString &fileName) +{ + if (QFile::exists(fileName)) + return 0; + + int fd = open(QFile::encodeName(fileName).constData(), + O_EXCL | O_CREAT | O_RDWR, 0640); + if (-1 == fd) { + if (errno == EEXIST) + return 0; + return -1; + } else { + close(fd); + } + return 1; +} +#endif + +QSystemLockPrivate::QSystemLockPrivate() : + semaphore(-1), lockCount(0), + error(QSystemLock::NoError), unix_key(-1), createdFile(false), createdSemaphore(false) +{ +} + +void QSystemLockPrivate::setErrorString(const QString &function) +{ + switch (errno) { + case EIDRM: + errorString = function + QLatin1String(": ") + tr("The semaphore set was removed"); + error = QSystemLock::UnknownError; + break; + default: + errorString = function + QLatin1String(": ") + tr("unknown error"); + error = QSystemLock::UnknownError; + qWarning() << errorString << "key" << key << "errno" << errno << ERANGE << ENOMEM << EINVAL << EINTR << EFBIG << EFAULT << EAGAIN << EACCES << E2BIG; + } +} + +/*! + \internal + + Setup unix_key + */ +key_t QSystemLockPrivate::handle() +{ + if (key.isEmpty()) + return -1; + + // ftok requires that an actual file exists somewhere + // If we have already made at some point in the past, + // double check that it is still there. + if (-1 != unix_key) { + int aNewunix_key = ftok(QFile::encodeName(fileName).constData(), 'Q'); + if (aNewunix_key != unix_key) { + cleanHandle(); + } else { + return unix_key; + } + } + + // Create the file needed for ftok +#if defined(Q_OS_SYMBIAN) + int built = createUnixKeyFile(fileName); +#else + int built = QSharedMemoryPrivate::createUnixKeyFile(fileName); +#endif + if (-1 == built) + return -1; + createdFile = (1 == built); + + // Get the unix key for the created file + unix_key = ftok(QFile::encodeName(fileName).constData(), 'Q'); + if (-1 == unix_key) { + setErrorString(QLatin1String("QSystemLock::handle ftok")); + return -1; + } + + // Get semaphore + semaphore = semget(unix_key, 1, 0666 | IPC_CREAT | IPC_EXCL); + if (-1 == semaphore) { + if (errno == EEXIST) + semaphore = semget(unix_key, 1, 0666 | IPC_CREAT); + if (-1 == semaphore) { + setErrorString(QLatin1String("QSystemLock::handle semget")); + cleanHandle(); + return -1; + } + } else { + // Created semaphore, initialize value. + createdSemaphore = true; + qt_semun init_op; + init_op.val = MAX_LOCKS; + if (-1 == semctl(semaphore, 0, SETVAL, init_op)) { + setErrorString(QLatin1String("QSystemLock::handle semctl")); + cleanHandle(); + return -1; + } + } + + return unix_key; +} + +/*! + \internal + + Cleanup the unix_key + */ +void QSystemLockPrivate::cleanHandle() +{ + unix_key = -1; + + // remove the file if we made it + if (createdFile) { + if (!QFile::remove(fileName)) + setErrorString(QLatin1String("QSystemLock::cleanHandle QFile::remove")); + createdFile = false; + } + + if (createdSemaphore) { + if (-1 != semaphore) { + if (-1 == semctl(semaphore, 0, IPC_RMID)) { + setErrorString(QLatin1String("QSystemLock::cleanHandle semctl")); + } + semaphore = -1; + } + createdSemaphore = false; + } +} + +/*! + \internal + + modifySemaphore generates operation.sem_op and handles recursive behavior. + */ +bool QSystemLockPrivate::modifySemaphore(QSystemLockPrivate::Operation op, + QSystemLock::LockMode mode) +{ + if (-1 == handle()) + return false; + + if ((lockCount == 0 && op == Lock) || (lockCount > 0 && op == Unlock)) { + if (op == Unlock) { + --lockCount; + Q_ASSERT(lockCount >= 0); + if (lockCount > 0) + return true; + } + + struct sembuf operation; + operation.sem_num = 0; + operation.sem_op = (mode == QSystemLock::ReadWrite) ? MAX_LOCKS : 1; + if (op == Lock) + operation.sem_op *= -1; + operation.sem_flg = SEM_UNDO; + + if (-1 == semop(semaphore, &operation, 1)) { + setErrorString(QLatin1String("QSystemLock::modify")); + return false; + } + lockedMode = mode; + } + if (op == Lock) + lockCount++; + + return true; +} + diff --git a/tests/auto/qtipc/qsharedmemory/src/qsystemlock_win.cpp b/tests/auto/qtipc/qsharedmemory/src/qsystemlock_win.cpp new file mode 100644 index 0000000..ac97100 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/src/qsystemlock_win.cpp @@ -0,0 +1,182 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include "qsystemlock.h" +#include "qsystemlock_p.h" +#include +#include +QSystemLockPrivate::QSystemLockPrivate() : + semaphore(0), semaphoreLock(0), + lockCount(0), error(QSystemLock::NoError) +{ +} + +void QSystemLockPrivate::setErrorString(const QString &function) +{ + BOOL windowsError = GetLastError(); + if (windowsError == 0) + return; + errorString = function + QLatin1String(": ") + + QLatin1String("Unknown error"); + error = QSystemLock::UnknownError; + qWarning() << errorString << "key" << key << (int)windowsError << semaphore << semaphoreLock; +} + +/*! + \internal + + Setup the semaphore + */ +HANDLE QSystemLockPrivate::handle() +{ + // don't allow making handles on empty keys + if (key.isEmpty()) + return 0; + + // Create it if it doesn't already exists. + if (semaphore == 0) { + QString safeName = makeKeyFileName(); + semaphore = CreateSemaphore(0, MAX_LOCKS, MAX_LOCKS, (wchar_t*)safeName.utf16()); + + if (semaphore == 0) { + setErrorString(QLatin1String("QSystemLockPrivate::handle")); + return 0; + } + } + + if (semaphoreLock == 0) { + QString safeLockName = QSharedMemoryPrivate::makePlatformSafeKey(key + QLatin1String("lock"), QLatin1String("qipc_systemlock_")); + semaphoreLock = CreateSemaphore(0, 1, 1, (wchar_t*)safeLockName.utf16()); + + if (semaphoreLock == 0) { + setErrorString(QLatin1String("QSystemLockPrivate::handle")); + return 0; + } + } + + return semaphore; +} + +/*! + \internal + + Cleanup the semaphore + */ +void QSystemLockPrivate::cleanHandle() +{ + if (semaphore && !CloseHandle(semaphore)) + setErrorString(QLatin1String("QSystemLockPrivate::cleanHandle:")); + if (semaphoreLock && !CloseHandle(semaphoreLock)) + setErrorString(QLatin1String("QSystemLockPrivate::cleanHandle:")); + semaphore = 0; + semaphoreLock = 0; +} + +bool QSystemLockPrivate::lock(HANDLE handle, int count) +{ + if (count == 1) { + WaitForSingleObject(handle, INFINITE); + return true; + } + + int i = count; + while (i > 0) { + if (WAIT_OBJECT_0 == WaitForSingleObject(handle, 0)) { + --i; + } else { + // undo what we have done, sleep and then try again later + ReleaseSemaphore(handle, (count - i), 0); + i = count; + ReleaseSemaphore(semaphoreLock, 1, 0); + Sleep(1); + WaitForSingleObject(semaphoreLock, INFINITE); + } + } + return true; +} + +bool QSystemLockPrivate::unlock(HANDLE handle, int count) +{ + if (0 == ReleaseSemaphore(handle, count, 0)) { + setErrorString(QLatin1String("QSystemLockPrivate::unlock")); + return false; + } + return true; +} + +/*! + \internal + + modifySemaphore handles recursive behavior and modifies the semaphore. + */ +bool QSystemLockPrivate::modifySemaphore(QSystemLockPrivate::Operation op, + QSystemLock::LockMode mode) +{ + if (0 == handle()) + return false; + + if ((lockCount == 0 && op == Lock) || (lockCount > 0 && op == Unlock)) { + if (op == Unlock) { + --lockCount; + Q_ASSERT(lockCount >= 0); + if (lockCount > 0) + return true; + } + + int count = (mode == QSystemLock::ReadWrite) ? MAX_LOCKS : 1; + if (op == Lock) { + lock(semaphoreLock, 1); + lock(semaphore, count); + if (count != MAX_LOCKS) unlock(semaphoreLock, 1); + lockedMode = mode; + } else { + if (count == MAX_LOCKS) unlock(semaphoreLock, 1); + unlock(semaphore, count); + } + + } + if (op == Lock) + lockCount++; + + return true; +} + diff --git a/tests/auto/qtipc/qsharedmemory/src/src.pri b/tests/auto/qtipc/qsharedmemory/src/src.pri new file mode 100644 index 0000000..5bc9de6 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/src/src.pri @@ -0,0 +1,10 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +SOURCES += $$PWD/qsystemlock.cpp + +HEADERS += $$PWD/qsystemlock.h \ + $$PWD/qsystemlock_p.h + +unix:SOURCES += $$PWD/qsystemlock_unix.cpp +win32:SOURCES += $$PWD/qsystemlock_win.cpp diff --git a/tests/auto/qtipc/qsharedmemory/test/test.pro b/tests/auto/qtipc/qsharedmemory/test/test.pro new file mode 100644 index 0000000..40ba8b9 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/test/test.pro @@ -0,0 +1,37 @@ +load(qttest_p4) + +include(../src/src.pri) +QT -= gui + +DEFINES += QSHAREDMEMORY_DEBUG +DEFINES += QSYSTEMSEMAPHORE_DEBUG + +SOURCES += ../tst_qsharedmemory.cpp +TARGET = ../tst_qsharedmemory + +!wince*:win32 { + CONFIG(debug, debug|release) { + TARGET = ../../debug/tst_qsharedmemory +} else { + TARGET = ../../release/tst_qsharedmemory + } +} + +wince*:{ +requires(contains(QT_CONFIG,script)) +QT += gui script +addFiles.sources = ../../lackey/lackey.exe ../../lackey/scripts +addFiles.path = lackey +DEPLOYMENT += addFiles +DEFINES += SRCDIR=\\\"\\\" +}else:symbian*{ +requires(contains(QT_CONFIG,script)) +QT += gui script +addFiles.sources = ../../lackey/scripts +addFiles.path = /data/qsharedmemorytemp/lackey +addBin.sources = lackey.exe +addBin.path = /sys/bin +DEPLOYMENT += addFiles addBin +} else { +DEFINES += SRCDIR=\\\"$$PWD/../\\\" +} diff --git a/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp b/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp new file mode 100644 index 0000000..83f65b0 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp @@ -0,0 +1,776 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include + +//TESTED_CLASS= +//TESTED_FILES= + +#define EXISTING_SHARE "existing" +#define EXISTING_SIZE 1024 + +#ifdef Q_OS_SYMBIAN +#define SRCDIR "c:/data/qsharedmemorytemp/" +#define LACKEYDIR SRCDIR "lackey" +#elif Q_OS_WINCE +#define LACKEYDIR SRCDIR "lackey" +#else +#define LACKEYDIR SRCDIR "../lackey" +#endif + +Q_DECLARE_METATYPE(QSharedMemory::SharedMemoryError) +Q_DECLARE_METATYPE(QSharedMemory::AccessMode) + +class tst_QSharedMemory : public QObject +{ + Q_OBJECT + +public: + tst_QSharedMemory(); + virtual ~tst_QSharedMemory(); + +public Q_SLOTS: + void init(); + void cleanup(); + +private slots: + // basics + void constructor(); + void key_data(); + void key(); + void create_data(); + void create(); + void attach_data(); + void attach(); + void lock(); + + // custom edge cases + void removeWhileAttached(); + void emptyMemory(); + void readOnly(); + + // basics all together + void simpleProducerConsumer_data(); + void simpleProducerConsumer(); + void simpleDoubleProducerConsumer(); + + // with threads + void simpleThreadedProducerConsumer_data(); + void simpleThreadedProducerConsumer(); + + // with processes + void simpleProcessProducerConsumer_data(); + void simpleProcessProducerConsumer(); + + // extreme cases + void useTooMuchMemory(); + void attachTooMuch(); + +protected: + int remove(const QString &key); + + QString rememberKey(const QString &key) + { + if (key == EXISTING_SHARE) + return key; + if (!keys.contains(key)) { + keys.append(key); + remove(key); + } + return key; + } + + QStringList keys; + QList jail; + QSharedMemory *existingSharedMemory; +}; + +tst_QSharedMemory::tst_QSharedMemory() : existingSharedMemory(0) +{ +} + +tst_QSharedMemory::~tst_QSharedMemory() +{ +} + +void tst_QSharedMemory::init() +{ + existingSharedMemory = new QSharedMemory(EXISTING_SHARE); + if (!existingSharedMemory->create(EXISTING_SIZE)) { + QVERIFY(existingSharedMemory->error() == QSharedMemory::AlreadyExists); + } +} + +void tst_QSharedMemory::cleanup() +{ + delete existingSharedMemory; + qDeleteAll(jail.begin(), jail.end()); + jail.clear(); + + keys.append(EXISTING_SHARE); + for (int i = 0; i < keys.count(); ++i) { + QSharedMemory sm(keys.at(i)); + if (!sm.create(1024)) { + //if(sm.error() != QSharedMemory::KeyError) + // qWarning() << "test cleanup: remove failed:" << keys.at(i) << sm.error() << sm.errorString(); + sm.attach(); + sm.detach(); + remove(keys.at(i)); + } + } +} + +#ifndef Q_OS_WIN +#include "private/qsharedmemory_p.h" +#include +#include +#include +#endif + +int tst_QSharedMemory::remove(const QString &key) +{ +#ifndef Q_OS_WIN + // On unix the shared memory might exists from a previously failed test + // or segfault, remove it it does + if (key.isEmpty()) + return -1; + + // ftok requires that an actual file exists somewhere + QString fileName = QSharedMemoryPrivate::makePlatformSafeKey(key); + if (!QFile::exists(fileName)) { + //qDebug() << "exits failed"; + return -2; + } + + int unix_key = ftok(fileName.toLatin1().constData(), 'Q'); + if (-1 == unix_key) { + qDebug() << "ftok failed"; + return -3; + } + + int id = shmget(unix_key, 0, 0660); + if (-1 == id) { + qDebug() << "shmget failed"; + return -4; + } + + struct shmid_ds shmid_ds; + if (-1 == shmctl(id, IPC_RMID, &shmid_ds)) { + qDebug() << "shmctl failed"; + return -5; + } + return QFile::remove(fileName); +#else + Q_UNUSED(key); + return 0; +#endif +} + +/*! + Tests the default values + */ +void tst_QSharedMemory::constructor() +{ + QSharedMemory sm; + QCOMPARE(sm.key(), QString()); + QVERIFY(!sm.isAttached()); + QVERIFY(sm.data() == 0); + QCOMPARE(sm.size(), 0); + QCOMPARE(sm.error(), QSharedMemory::NoError); + QVERIFY(sm.errorString() == QString()); +} + +void tst_QSharedMemory::key_data() +{ + QTest::addColumn("constructorKey"); + QTest::addColumn("setKey"); + + QTest::newRow("null, null") << QString() << QString(); + QTest::newRow("null, one") << QString() << QString("one"); + QTest::newRow("one, two") << QString("one") << QString("two"); + QTest::newRow("invalid") << QString("o/e") << QString("t/o"); +} + +/*! + Basic key testing + */ +void tst_QSharedMemory::key() +{ + QFETCH(QString, constructorKey); + QFETCH(QString, setKey); + + QSharedMemory sm(constructorKey); + QCOMPARE(sm.key(), constructorKey); + sm.setKey(setKey); + QCOMPARE(sm.key(), setKey); + QCOMPARE(sm.isAttached(), false); + + QCOMPARE(sm.error(), QSharedMemory::NoError); + QVERIFY(sm.errorString() == QString()); + QVERIFY(sm.data() == 0); + QCOMPARE(sm.size(), 0); + + QCOMPARE(sm.detach(), false); +} + +void tst_QSharedMemory::create_data() +{ + QTest::addColumn("key"); + QTest::addColumn("size"); + QTest::addColumn("canCreate"); + QTest::addColumn("error"); + + QTest::newRow("null key") << QString() << 1024 + << false << QSharedMemory::LockError; + QTest::newRow("-1 size") << QString("negsize") << -1 + << false << QSharedMemory::InvalidSize; + QTest::newRow("nor size") << QString("norsize") << 1024 + << true << QSharedMemory::NoError; + QTest::newRow("already exists") << QString(EXISTING_SHARE) << EXISTING_SIZE + << false << QSharedMemory::AlreadyExists; +} + +/*! + Basic create testing + */ +void tst_QSharedMemory::create() +{ + QFETCH(QString, key); + QFETCH(int, size); + QFETCH(bool, canCreate); + QFETCH(QSharedMemory::SharedMemoryError, error); + + QSharedMemory sm(rememberKey(key)); + QCOMPARE(sm.create(size), canCreate); + if(sm.error() != error) + qDebug() << sm.errorString(); + QCOMPARE(sm.key(), key); + if (canCreate) { + QVERIFY(sm.errorString() == QString()); + QVERIFY(sm.data() != 0); + QVERIFY(sm.size() != 0); + } else { + QVERIFY(sm.data() == 0); + QVERIFY(sm.errorString() != QString()); + } +} + +void tst_QSharedMemory::attach_data() +{ + QTest::addColumn("key"); + QTest::addColumn("exists"); + QTest::addColumn("error"); + + QTest::newRow("null key") << QString() << false << QSharedMemory::LockError; + QTest::newRow("doesn't exists") << QString("doesntexists") << false << QSharedMemory::NotFound; + QTest::newRow("already exists") << QString(EXISTING_SHARE) << true << QSharedMemory::NoError; +} + +/*! + Basic attach/detach testing + */ +void tst_QSharedMemory::attach() +{ + QFETCH(QString, key); + QFETCH(bool, exists); + QFETCH(QSharedMemory::SharedMemoryError, error); +#ifdef Q_OS_HPUX + if (QLatin1String(QTest::currentDataTag()) == QLatin1String("already exists")) { + QSKIP("HPUX doesn't allow for multiple attaches per process", SkipSingle); + } +#endif + QSharedMemory sm(key); + QCOMPARE(sm.attach(), exists); + QCOMPARE(sm.isAttached(), exists); + QCOMPARE(sm.error(), error); + QCOMPARE(sm.key(), key); + if (exists) { + QVERIFY(sm.data() != 0); + QVERIFY(sm.size() != 0); + QCOMPARE(sm.errorString(), QString()); + QVERIFY(sm.detach()); + // Make sure detach doesn't screw up something and we can't re-attach. + QVERIFY(sm.attach()); + QVERIFY(sm.detach()); + QCOMPARE(sm.size(), 0); + QVERIFY(sm.data() == 0); + } else { + QVERIFY(sm.data() == 0); + QVERIFY(sm.size() == 0); + QVERIFY(sm.errorString() != QString()); + QVERIFY(!sm.detach()); + } +} + +void tst_QSharedMemory::lock() +{ + QSharedMemory shm; + QVERIFY(!shm.lock()); + QCOMPARE(shm.error(), QSharedMemory::LockError); + + shm.setKey(QLatin1String("qsharedmemory")); + + QVERIFY(!shm.lock()); + QCOMPARE(shm.error(), QSharedMemory::LockError); + + QVERIFY(shm.create(100)); + QVERIFY(shm.lock()); + QTest::ignoreMessage(QtWarningMsg, "QSharedMemory::lock: already locked"); + QVERIFY(shm.lock()); + // don't lock forever +} + +/*! + Other shared memory are allowed to be attached after we remove, + but new shared memory are not allowed to attach after a remove. + */ +void tst_QSharedMemory::removeWhileAttached() +{ +#ifdef Q_OS_HPUX + QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); +#endif + rememberKey("one"); + + // attach 1 + QSharedMemory *smOne = new QSharedMemory(QLatin1String("one")); + QVERIFY(smOne->create(1024)); + QVERIFY(smOne->isAttached()); + + // attach 2 + QSharedMemory *smTwo = new QSharedMemory(QLatin1String("one")); + QVERIFY(smTwo->attach()); + QVERIFY(smTwo->isAttached()); + + // detach 1 and remove, remove one first to catch another error. + delete smOne; + delete smTwo; + + // three shouldn't be able to attach + QSharedMemory smThree(QLatin1String("one")); + QVERIFY(!smThree.attach()); + QCOMPARE(smThree.error(), QSharedMemory::NotFound); +} + +/*! + The memory should be set to 0 after created. + */ +void tst_QSharedMemory::emptyMemory() +{ + QSharedMemory sm(rememberKey(QLatin1String("voidland"))); + int size = 1024; + QVERIFY(sm.create(size, QSharedMemory::ReadOnly)); + char *get = (char*)sm.data(); + char null = 0; + for (int i = 0; i < size; ++i) + QCOMPARE(get[i], null); +} + +/*! + Verify that attach with ReadOnly is actually read only + by writing to data and causing a segfault. +*/ +void tst_QSharedMemory::readOnly() +{ +#ifdef Q_OS_WIN + QSKIP("This test opens a crash dialog on Windows", SkipSingle); +#endif +#if defined (Q_OS_SYMBIAN) + QSKIP("Readonly shared memory is not supported in symbian", SkipAll); +#endif + QString program = LACKEYDIR "/lackey"; + QStringList arguments; + rememberKey("readonly_segfault"); + arguments << LACKEYDIR "/scripts/readonly_segfault.js"; + + // ### on windows disable the popup somehow + QProcess p; + p.start(program, arguments); + p.setProcessChannelMode(QProcess::ForwardedChannels); + p.waitForFinished(); + QCOMPARE(p.error(), QProcess::Crashed); +} + +/*! + Keep making shared memory until the kernel stops us. + */ +void tst_QSharedMemory::useTooMuchMemory() +{ +#ifdef Q_OS_LINUX + bool success = true; + int count = 0; + while (success) { + QString key = QString("maxmemorytest_%1").arg(count++); + QSharedMemory *sm = new QSharedMemory(rememberKey(key)); + QVERIFY(sm); + jail.append(sm); + int size = 32768 * 1024; + success = sm->create(size); + if (!success && sm->error() == QSharedMemory::AlreadyExists) { + // left over from a crash, clean it up + sm->attach(); + sm->detach(); + success = sm->create(size); + } + + if (!success) { + QVERIFY(!sm->isAttached()); + QCOMPARE(sm->key(), key); + QCOMPARE(sm->size(), 0); + QVERIFY(sm->data() == 0); + if (sm->error() != QSharedMemory::OutOfResources) + qDebug() << sm->error() << sm->errorString(); + // ### Linux wont return OutOfResources if there are not enough semaphores to use. + QVERIFY(sm->error() == QSharedMemory::OutOfResources + || sm->error() == QSharedMemory::LockError); + QVERIFY(sm->errorString() != QString()); + QVERIFY(!sm->attach()); + QVERIFY(!sm->detach()); + } else { + QVERIFY(sm->isAttached()); + } + } +#endif +} + +/*! + Create one shared memory (government) and see how many other shared memories (wars) we can + attach before the system runs out of resources. + */ +void tst_QSharedMemory::attachTooMuch() +{ + QSKIP("disabled", SkipAll); +#ifdef Q_OS_HPUX + QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); +#endif +#ifdef Q_OS_WINCE + QSKIP("This nearly kills the system itself, so skip for Qt/WinCE", SkipAll); +#endif + QSharedMemory government(rememberKey("government")); + QVERIFY(government.create(1024)); + while (true) { + QSharedMemory *war = new QSharedMemory(government.key()); + QVERIFY(war); + jail.append(war); + if (!war->attach()) { + QVERIFY(!war->isAttached()); + QCOMPARE(war->key(), government.key()); + QCOMPARE(war->size(), 0); + QVERIFY(war->data() == 0); + QCOMPARE(war->error(), QSharedMemory::OutOfResources); + QVERIFY(war->errorString() != QString()); + QVERIFY(!war->detach()); + break; + } else { + QVERIFY(war->isAttached()); + } + } +} + +void tst_QSharedMemory::simpleProducerConsumer_data() +{ + QTest::addColumn("mode"); + + QTest::newRow("readonly") << QSharedMemory::ReadOnly; + QTest::newRow("readwrite") << QSharedMemory::ReadWrite; +} + +/*! + The basic consumer producer that rounds out the basic testing. + If this fails then any muli-threading/process might fail (but be + harder to debug) + + This doesn't require nor test any locking system. + */ +void tst_QSharedMemory::simpleProducerConsumer() +{ +#ifdef Q_OS_HPUX + QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); +#endif + QFETCH(QSharedMemory::AccessMode, mode); + + rememberKey(QLatin1String("market")); + QSharedMemory producer(QLatin1String("market")); + QSharedMemory consumer(QLatin1String("market")); + int size = 512; + QVERIFY(producer.create(size)); + QVERIFY(consumer.attach(mode)); + + char *put = (char*)producer.data(); + char *get = (char*)consumer.data(); + // On Windows CE you always have ReadWrite access. Thus + // ViewMapOfFile returns the same pointer + // On Symbian, the address will always be same, as + // write protection of chunks is not currently supported by Symbian +#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) + QVERIFY(put != get); +#endif + for (int i = 0; i < size; ++i) { + put[i] = 'Q'; + QCOMPARE(get[i], 'Q'); + } + QVERIFY(consumer.detach()); +} + +void tst_QSharedMemory::simpleDoubleProducerConsumer() +{ +#ifdef Q_OS_HPUX + QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); +#endif + rememberKey(QLatin1String("market")); + QSharedMemory producer(QLatin1String("market")); + int size = 512; + QVERIFY(producer.create(size)); + QVERIFY(producer.detach()); + QVERIFY(producer.create(size)); + + { + QSharedMemory consumer(QLatin1String("market")); + QVERIFY(consumer.attach()); + } +} + +class Consumer : public QThread +{ + +public: + void run() + { + QSharedMemory consumer(QLatin1String("market")); + while (!consumer.attach()) { + if (consumer.error() != QSharedMemory::NotFound) + qDebug() << "consumer: failed to connect" << consumer.error() << consumer.errorString(); + QVERIFY(consumer.error() == QSharedMemory::NotFound || consumer.error() == QSharedMemory::KeyError); + QTest::qWait(1); + } + + char *memory = (char*)consumer.data(); + + int i = 0; + while (true) { + if(!consumer.lock()) + break; + if (memory[0] == 'Q') + memory[0] = ++i; + if (memory[0] == 'E') { + memory[1]++; + QVERIFY(consumer.unlock()); + break; + } + QVERIFY(consumer.unlock()); + QTest::qWait(1); + } + + QVERIFY(consumer.detach()); + } +}; + +class Producer : public QThread +{ + +public: + void run() + { + QSharedMemory producer(QLatin1String("market")); + int size = 1024; + if (!producer.create(size)) { + // left over from a crash... + if (producer.error() == QSharedMemory::AlreadyExists) { + producer.attach(); + producer.detach(); + QVERIFY(producer.create(size)); + } + } + QVERIFY(producer.isAttached()); + char *memory = (char*)producer.data(); + memory[1] = '0'; + QTime timer; + timer.start(); + int i = 0; + while (i < 5 && timer.elapsed() < 5000) { + QVERIFY(producer.lock()); + if (memory[0] == 'Q') { + QVERIFY(producer.unlock()); + QTest::qWait(1); + continue; + } + ++i; + memory[0] = 'Q'; + QVERIFY(producer.unlock()); + QTest::qWait(1); + } + + // tell everyone to quit + QVERIFY(producer.lock()); + memory[0] = 'E'; + QVERIFY(producer.unlock()); + +#if defined(Q_OS_SYMBIAN) + // Sleep a while to ensure that consumers start properly + QTest::qSleep(1000); +#endif + } +private: + +}; + +void tst_QSharedMemory::simpleThreadedProducerConsumer_data() +{ + QTest::addColumn("producerIsThread"); + QTest::addColumn("threads"); + for (int i = 0; i < 5; ++i) { + QTest::newRow("1 consumer, producer is thread") << true << 1; + QTest::newRow("1 consumer, producer is this") << false << 1; + QTest::newRow("5 consumers, producer is thread") << true << 5; + QTest::newRow("5 consumers, producer is this") << false << 5; + } +} + +/*! + The basic producer/consumer, but this time using threads. + */ +void tst_QSharedMemory::simpleThreadedProducerConsumer() +{ + QFETCH(bool, producerIsThread); + QFETCH(int, threads); + rememberKey(QLatin1String("market")); + +#if defined Q_OS_HPUX && defined __ia64 + QSKIP("This test locks up on gravlaks.troll.no", SkipSingle); +#endif + + Producer p; +#if defined(Q_OS_SYMBIAN) + enum + { + /** + * The maximum stack size. + */ + SymbianStackSize = 0x14000 + }; + p.setStackSize(SymbianStackSize); +#endif + if (producerIsThread) + p.start(); + + QList consumers; + for (int i = 0; i < threads; ++i) { + consumers.append(new Consumer()); +#if defined(Q_OS_SYMBIAN) + consumers.last()->setStackSize(SymbianStackSize); +#endif + consumers.last()->start(); + } + + if (!producerIsThread) + p.run(); + + p.wait(5000); + while (!consumers.isEmpty()) { + QVERIFY(consumers.first()->wait(5000)); + delete consumers.takeFirst(); + } +} + +void tst_QSharedMemory::simpleProcessProducerConsumer_data() +{ + QTest::addColumn("processes"); + int tries = 5; + for (int i = 0; i < tries; ++i) { + QTest::newRow("1 process") << 1; + QTest::newRow("5 processes") << 5; + } +} + +/*! + Create external processes that produce and consume. + */ +void tst_QSharedMemory::simpleProcessProducerConsumer() +{ +#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) + QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); +#endif + QFETCH(int, processes); + + rememberKey("market"); + + QStringList arguments = QStringList() << LACKEYDIR "/scripts/producer.js"; + QProcess producer; + producer.setProcessChannelMode(QProcess::ForwardedChannels); + producer.start( LACKEYDIR "/lackey", arguments); + producer.waitForStarted(); + QVERIFY(producer.error() != QProcess::FailedToStart); + + QList consumers; + unsigned int failedProcesses = 0; + for (int i = 0; i < processes; ++i) { + QStringList arguments = QStringList() << LACKEYDIR "/scripts/consumer.js"; + QProcess *p = new QProcess; + p->setProcessChannelMode(QProcess::ForwardedChannels); + p->start(LACKEYDIR "/lackey", arguments); + + if (p->waitForStarted(2000)) + consumers.append(p); + else + ++failedProcesses; + } + + QVERIFY(producer.waitForFinished(5000)); + + bool consumerFailed = false; + + while (!consumers.isEmpty()) { + QVERIFY(consumers.first()->waitForFinished(3000)); + if (consumers.first()->state() == QProcess::Running || + consumers.first()->exitStatus() != QProcess::NormalExit || + consumers.first()->exitCode() != 0) { + consumerFailed = true; + } + delete consumers.takeFirst(); + } + QCOMPARE(consumerFailed, false); + QCOMPARE(failedProcesses, (unsigned int)(0)); +} + +QTEST_MAIN(tst_QSharedMemory) +#include "tst_qsharedmemory.moc" + diff --git a/tests/auto/qtipc/qsystemsemaphore/.gitignore b/tests/auto/qtipc/qsystemsemaphore/.gitignore new file mode 100644 index 0000000..2b60bfb --- /dev/null +++ b/tests/auto/qtipc/qsystemsemaphore/.gitignore @@ -0,0 +1 @@ +tst_qsystemsemaphore diff --git a/tests/auto/qtipc/qsystemsemaphore/files.qrc b/tests/auto/qtipc/qsystemsemaphore/files.qrc new file mode 100644 index 0000000..6296690 --- /dev/null +++ b/tests/auto/qtipc/qsystemsemaphore/files.qrc @@ -0,0 +1,7 @@ + + + ../lackey/scripts/systemsemaphore_acquire.js + ../lackey/scripts/systemsemaphore_release.js + ../lackey/scripts/systemsemaphore_acquirerelease.js + + diff --git a/tests/auto/qtipc/qsystemsemaphore/qsystemsemaphore.pro b/tests/auto/qtipc/qsystemsemaphore/qsystemsemaphore.pro new file mode 100644 index 0000000..1f9205e --- /dev/null +++ b/tests/auto/qtipc/qsystemsemaphore/qsystemsemaphore.pro @@ -0,0 +1,36 @@ +CONFIG += qttest_p4 +#QT = core + +include(../qsharedmemory/src/src.pri) +win32: CONFIG += console + +DEFINES += QSHAREDMEMORY_DEBUG +DEFINES += QSYSTEMSEMAPHORE_DEBUG + +SOURCES += tst_qsystemsemaphore.cpp +TARGET = tst_qsystemsemaphore + +RESOURCES += files.qrc + +wince*: { +requires(contains(QT_CONFIG,script)) +# this test calls lackey, which then again depends on QtScript. +# let's add it here so that it gets deployed easily +QT += script +lackey.sources = ../lackey/lackey.exe +lackey.path = ../lackey + +DEPLOYMENT += lackey +} + +symbian: { +requires(contains(QT_CONFIG,script)) +# this test calls lackey, which then again depends on QtScript. +# let's add it here so that it gets deployed easily +QT += script + +lackey.sources = ../lackey/lackey.exe +lackey.path = /sys/bin +DEPLOYMENT += lackey +} + diff --git a/tests/auto/qtipc/qsystemsemaphore/tst_qsystemsemaphore.cpp b/tests/auto/qtipc/qsystemsemaphore/tst_qsystemsemaphore.cpp new file mode 100644 index 0000000..eb82fd4 --- /dev/null +++ b/tests/auto/qtipc/qsystemsemaphore/tst_qsystemsemaphore.cpp @@ -0,0 +1,302 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include +//TESTED_CLASS= +//TESTED_FILES= + +#define EXISTING_SHARE "existing" +#define LACKYLOC "../lackey" +#define LACKYWAITTIME 10000 + +class tst_QSystemSemaphore : public QObject +{ + Q_OBJECT + +public: + tst_QSystemSemaphore(); + virtual ~tst_QSystemSemaphore(); + +public Q_SLOTS: + void init(); + void cleanup(); + +private slots: + void key_data(); + void key(); + + void basicacquire(); + void complexacquire(); + + void basicProcesses(); + + void processes_data(); + void processes(); + + void undo(); + void initialValue(); + +private: + QSystemSemaphore *existingLock; + + QString makeFile(const QString &resource) + { + QFile memory(resource); + if (!memory.open(QIODevice::ReadOnly)) { + qDebug() << "error reading resource" << resource; + return QString(); + } + QTemporaryFile *file = new QTemporaryFile; + file->open(); + file->write(memory.readAll()); + tempFiles.append(file); + file->flush(); +#ifdef Q_OS_WINCE + // flush does not flush to disk on Windows CE. It flushes it into its application + // cache. Thus we need to close the file to be able that other processes(lackey) can read it + QString fileName = file->fileName(); + file->close(); + return fileName; +#endif + return file->fileName(); + } + + QString acquire_js() { return makeFile(":/systemsemaphore_acquire.js"); } + QString release_js() { return makeFile(":/systemsemaphore_release.js"); } + QString acquirerelease_js() { return makeFile(":/systemsemaphore_acquirerelease.js"); } + QList tempFiles; +}; + +tst_QSystemSemaphore::tst_QSystemSemaphore() +{ + if (!QFile::exists(LACKYLOC "/lackey")) + qWarning() << "lackey executable doesn't exists!"; +} + +tst_QSystemSemaphore::~tst_QSystemSemaphore() +{ + qDeleteAll(tempFiles); +} + +void tst_QSystemSemaphore::init() +{ + existingLock = new QSystemSemaphore(EXISTING_SHARE, 1, QSystemSemaphore::Create); +} + +void tst_QSystemSemaphore::cleanup() +{ + delete existingLock; +} + +void tst_QSystemSemaphore::key_data() +{ + QTest::addColumn("constructorKey"); + QTest::addColumn("setKey"); + + QTest::newRow("null, null") << QString() << QString(); + QTest::newRow("null, one") << QString() << QString("one"); + QTest::newRow("one, two") << QString("one") << QString("two"); +} + +/*! + Basic key testing + */ +void tst_QSystemSemaphore::key() +{ + QFETCH(QString, constructorKey); + QFETCH(QString, setKey); + + QSystemSemaphore sem(constructorKey); + QCOMPARE(sem.key(), constructorKey); + QCOMPARE(sem.error(), QSystemSemaphore::NoError); + QCOMPARE(sem.errorString(), QString()); + + sem.setKey(setKey); + QCOMPARE(sem.key(), setKey); + QCOMPARE(sem.error(), QSystemSemaphore::NoError); + QCOMPARE(sem.errorString(), QString()); +} + +void tst_QSystemSemaphore::basicacquire() +{ + QSystemSemaphore sem("QSystemSemaphore_basicacquire", 1, QSystemSemaphore::Create); + QVERIFY(sem.acquire()); + QCOMPARE(sem.error(), QSystemSemaphore::NoError); + QVERIFY(sem.release()); + QCOMPARE(sem.error(), QSystemSemaphore::NoError); + QCOMPARE(sem.errorString(), QString()); +} + +void tst_QSystemSemaphore::complexacquire() +{ + QSystemSemaphore sem("QSystemSemaphore_complexacquire", 2, QSystemSemaphore::Create); + QVERIFY(sem.acquire()); + QVERIFY(sem.release()); + QVERIFY(sem.acquire()); + QVERIFY(sem.release()); + QVERIFY(sem.acquire()); + QVERIFY(sem.acquire()); + QVERIFY(sem.release()); + QVERIFY(sem.release()); + QCOMPARE(sem.error(), QSystemSemaphore::NoError); + QCOMPARE(sem.errorString(), QString()); +} + +void tst_QSystemSemaphore::basicProcesses() +{ +#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) + QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); +#endif + QSystemSemaphore sem("store", 0, QSystemSemaphore::Create); + + QStringList acquireArguments = QStringList() << acquire_js(); + QStringList releaseArguments = QStringList() << release_js(); + QProcess acquire; + acquire.setProcessChannelMode(QProcess::ForwardedChannels); + + QProcess release; + release.setProcessChannelMode(QProcess::ForwardedChannels); + + acquire.start(LACKYLOC "/lackey", acquireArguments); + acquire.waitForFinished(LACKYWAITTIME); + QVERIFY(acquire.state() == QProcess::Running); + acquire.kill(); + release.start(LACKYLOC "/lackey", releaseArguments); + acquire.waitForFinished(LACKYWAITTIME); + release.waitForFinished(LACKYWAITTIME); + QVERIFY(acquire.state() == QProcess::NotRunning); +} + +void tst_QSystemSemaphore::processes_data() +{ + QTest::addColumn("processes"); + for (int i = 0; i < 5; ++i) { + QTest::newRow("1 process") << 1; + QTest::newRow("3 process") << 3; + QTest::newRow("10 process") << 10; + } +} + +void tst_QSystemSemaphore::processes() +{ +#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) + QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); +#endif + QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); + + QFETCH(int, processes); + QStringList scripts; + for (int i = 0; i < processes; ++i) + scripts.append(acquirerelease_js()); + + QList consumers; + for (int i = 0; i < scripts.count(); ++i) { + QStringList arguments = QStringList() << scripts.at(i); + QProcess *p = new QProcess; + p->setProcessChannelMode(QProcess::ForwardedChannels); + consumers.append(p); + p->start(LACKYLOC "/lackey", arguments); + } + + while (!consumers.isEmpty()) { + consumers.first()->waitForFinished(); + QCOMPARE(consumers.first()->exitStatus(), QProcess::NormalExit); + QCOMPARE(consumers.first()->exitCode(), 0); + delete consumers.takeFirst(); + } +} + +void tst_QSystemSemaphore::undo() +{ +#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) + QSKIP("This test only checks a unix behavior", SkipSingle); +#endif + + QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); + + QStringList acquireArguments = QStringList() << acquire_js(); + QProcess acquire; + acquire.setProcessChannelMode(QProcess::ForwardedChannels); + acquire.start(LACKYLOC "/lackey", acquireArguments); + acquire.waitForFinished(LACKYWAITTIME); + QVERIFY(acquire.state()== QProcess::NotRunning); + + // At process exit the kernel should auto undo + + acquire.start(LACKYLOC "/lackey", acquireArguments); + acquire.waitForFinished(LACKYWAITTIME); + QVERIFY(acquire.state()== QProcess::NotRunning); +} + +void tst_QSystemSemaphore::initialValue() +{ +#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) + QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); +#endif + QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); + + QStringList acquireArguments = QStringList() << acquire_js(); + QStringList releaseArguments = QStringList() << release_js(); + QProcess acquire; + acquire.setProcessChannelMode(QProcess::ForwardedChannels); + + QProcess release; + release.setProcessChannelMode(QProcess::ForwardedChannels); + + acquire.start(LACKYLOC "/lackey", acquireArguments); + acquire.waitForFinished(LACKYWAITTIME); + QVERIFY(acquire.state()== QProcess::NotRunning); + + acquire.start(LACKYLOC "/lackey", acquireArguments << "2"); + acquire.waitForFinished(LACKYWAITTIME); + QVERIFY(acquire.state()== QProcess::Running); + acquire.kill(); + + release.start(LACKYLOC "/lackey", releaseArguments); + acquire.waitForFinished(LACKYWAITTIME); + release.waitForFinished(LACKYWAITTIME); + QVERIFY(acquire.state()== QProcess::NotRunning); +} +QTEST_MAIN(tst_QSystemSemaphore) +#include "tst_qsystemsemaphore.moc" + diff --git a/tests/auto/qtipc/qtipc.pro b/tests/auto/qtipc/qtipc.pro new file mode 100644 index 0000000..60037d2 --- /dev/null +++ b/tests/auto/qtipc/qtipc.pro @@ -0,0 +1,6 @@ +TEMPLATE=subdirs +SUBDIRS=\ + lackey \ + qsharedmemory \ + qsystemsemaphore \ + -- cgit v0.12 From 2d67f6efc47986e8f6d69943f0986d18ae2ced96 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 16 Feb 2010 15:34:50 +1000 Subject: Fixed compile of xmlpatterns tests with vcproj generator. These tests were adding the same SUBDIR multiple times from different projects. Don't do that. --- tests/auto/auto.pro | 9 +- tests/auto/xmlpatternsdiagnosticsts/test/test.pro | 32 - .../test/tst_xmlpatternsdiagnosticsts.cpp | 80 -- .../tst_xmlpatternsdiagnosticsts.cpp | 80 ++ .../xmlpatternsdiagnosticsts.pro | 30 +- .../xmlpatternsschemats/xmlpatternsschemats.pro | 14 +- tests/auto/xmlpatternssdk/ASTItem.cpp | 161 ++++ tests/auto/xmlpatternssdk/ASTItem.h | 115 +++ .../auto/xmlpatternssdk/DebugExpressionFactory.cpp | 264 ++++++ tests/auto/xmlpatternssdk/DebugExpressionFactory.h | 128 +++ tests/auto/xmlpatternssdk/ErrorHandler.cpp | 166 ++++ tests/auto/xmlpatternssdk/ErrorHandler.h | 149 ++++ tests/auto/xmlpatternssdk/ErrorItem.cpp | 142 ++++ tests/auto/xmlpatternssdk/ErrorItem.h | 94 +++ tests/auto/xmlpatternssdk/ExitCode.h | 105 +++ tests/auto/xmlpatternssdk/ExpressionInfo.cpp | 54 ++ tests/auto/xmlpatternssdk/ExpressionInfo.h | 80 ++ tests/auto/xmlpatternssdk/ExpressionNamer.cpp | 316 +++++++ tests/auto/xmlpatternssdk/ExpressionNamer.h | 281 +++++++ tests/auto/xmlpatternssdk/ExternalSourceLoader.cpp | 140 ++++ tests/auto/xmlpatternssdk/ExternalSourceLoader.h | 137 ++++ tests/auto/xmlpatternssdk/Global.cpp | 83 ++ tests/auto/xmlpatternssdk/Global.h | 128 +++ tests/auto/xmlpatternssdk/ResultThreader.cpp | 76 ++ tests/auto/xmlpatternssdk/ResultThreader.h | 110 +++ tests/auto/xmlpatternssdk/TestBaseLine.cpp | 511 ++++++++++++ tests/auto/xmlpatternssdk/TestBaseLine.h | 212 +++++ tests/auto/xmlpatternssdk/TestCase.cpp | 439 ++++++++++ tests/auto/xmlpatternssdk/TestCase.h | 256 ++++++ tests/auto/xmlpatternssdk/TestContainer.cpp | 151 ++++ tests/auto/xmlpatternssdk/TestContainer.h | 123 +++ tests/auto/xmlpatternssdk/TestGroup.cpp | 143 ++++ tests/auto/xmlpatternssdk/TestGroup.h | 93 +++ tests/auto/xmlpatternssdk/TestItem.h | 133 +++ tests/auto/xmlpatternssdk/TestResult.cpp | 158 ++++ tests/auto/xmlpatternssdk/TestResult.h | 179 ++++ tests/auto/xmlpatternssdk/TestResultHandler.cpp | 98 +++ tests/auto/xmlpatternssdk/TestResultHandler.h | 115 +++ tests/auto/xmlpatternssdk/TestSuite.cpp | 269 ++++++ tests/auto/xmlpatternssdk/TestSuite.h | 160 ++++ tests/auto/xmlpatternssdk/TestSuiteHandler.cpp | 312 +++++++ tests/auto/xmlpatternssdk/TestSuiteHandler.h | 169 ++++ tests/auto/xmlpatternssdk/TestSuiteResult.cpp | 173 ++++ tests/auto/xmlpatternssdk/TestSuiteResult.h | 93 +++ tests/auto/xmlpatternssdk/TreeItem.cpp | 62 ++ tests/auto/xmlpatternssdk/TreeItem.h | 114 +++ tests/auto/xmlpatternssdk/TreeModel.cpp | 184 +++++ tests/auto/xmlpatternssdk/TreeModel.h | 110 +++ tests/auto/xmlpatternssdk/Worker.cpp | 258 ++++++ tests/auto/xmlpatternssdk/Worker.h | 100 +++ tests/auto/xmlpatternssdk/XMLWriter.cpp | 669 +++++++++++++++ tests/auto/xmlpatternssdk/XMLWriter.h | 403 +++++++++ tests/auto/xmlpatternssdk/XQTSTestCase.cpp | 286 +++++++ tests/auto/xmlpatternssdk/XQTSTestCase.h | 149 ++++ tests/auto/xmlpatternssdk/XSDTSTestCase.cpp | 375 +++++++++ tests/auto/xmlpatternssdk/XSDTSTestCase.h | 161 ++++ tests/auto/xmlpatternssdk/XSDTestSuiteHandler.cpp | 910 +++++++++++++++++++++ tests/auto/xmlpatternssdk/XSDTestSuiteHandler.h | 121 +++ tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp | 234 ++++++ tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.h | 158 ++++ .../xmlpatternssdk/docs/XMLIndenterExample.cpp | 63 ++ .../docs/XMLIndenterExampleResult.xml | 3 + .../auto/xmlpatternssdk/docs/XMLWriterExample.cpp | 63 ++ .../xmlpatternssdk/docs/XMLWriterExampleResult.xml | 3 + tests/auto/xmlpatternssdk/tests/XMLWriterTest.cpp | 186 +++++ tests/auto/xmlpatternssdk/tests/XMLWriterTest.h | 77 ++ tests/auto/xmlpatternssdk/xmlpatternssdk.pro | 88 ++ tests/auto/xmlpatternsview/test/test.pro | 17 - .../xmlpatternsview/test/tst_xmlpatternsview.cpp | 74 -- tests/auto/xmlpatternsview/tst_xmlpatternsview.cpp | 74 ++ tests/auto/xmlpatternsview/xmlpatternsview.pro | 15 +- tests/auto/xmlpatternsxqts/lib/ASTItem.cpp | 161 ---- tests/auto/xmlpatternsxqts/lib/ASTItem.h | 115 --- .../xmlpatternsxqts/lib/DebugExpressionFactory.cpp | 264 ------ .../xmlpatternsxqts/lib/DebugExpressionFactory.h | 128 --- tests/auto/xmlpatternsxqts/lib/ErrorHandler.cpp | 166 ---- tests/auto/xmlpatternsxqts/lib/ErrorHandler.h | 149 ---- tests/auto/xmlpatternsxqts/lib/ErrorItem.cpp | 142 ---- tests/auto/xmlpatternsxqts/lib/ErrorItem.h | 94 --- tests/auto/xmlpatternsxqts/lib/ExitCode.h | 105 --- tests/auto/xmlpatternsxqts/lib/ExpressionInfo.cpp | 54 -- tests/auto/xmlpatternsxqts/lib/ExpressionInfo.h | 80 -- tests/auto/xmlpatternsxqts/lib/ExpressionNamer.cpp | 316 ------- tests/auto/xmlpatternsxqts/lib/ExpressionNamer.h | 281 ------- .../xmlpatternsxqts/lib/ExternalSourceLoader.cpp | 140 ---- .../xmlpatternsxqts/lib/ExternalSourceLoader.h | 137 ---- tests/auto/xmlpatternsxqts/lib/Global.cpp | 83 -- tests/auto/xmlpatternsxqts/lib/Global.h | 128 --- tests/auto/xmlpatternsxqts/lib/ResultThreader.cpp | 76 -- tests/auto/xmlpatternsxqts/lib/ResultThreader.h | 110 --- tests/auto/xmlpatternsxqts/lib/TestBaseLine.cpp | 511 ------------ tests/auto/xmlpatternsxqts/lib/TestBaseLine.h | 212 ----- tests/auto/xmlpatternsxqts/lib/TestCase.cpp | 439 ---------- tests/auto/xmlpatternsxqts/lib/TestCase.h | 256 ------ tests/auto/xmlpatternsxqts/lib/TestContainer.cpp | 151 ---- tests/auto/xmlpatternsxqts/lib/TestContainer.h | 123 --- tests/auto/xmlpatternsxqts/lib/TestGroup.cpp | 143 ---- tests/auto/xmlpatternsxqts/lib/TestGroup.h | 93 --- tests/auto/xmlpatternsxqts/lib/TestItem.h | 133 --- tests/auto/xmlpatternsxqts/lib/TestResult.cpp | 158 ---- tests/auto/xmlpatternsxqts/lib/TestResult.h | 179 ---- .../auto/xmlpatternsxqts/lib/TestResultHandler.cpp | 98 --- tests/auto/xmlpatternsxqts/lib/TestResultHandler.h | 115 --- tests/auto/xmlpatternsxqts/lib/TestSuite.cpp | 269 ------ tests/auto/xmlpatternsxqts/lib/TestSuite.h | 160 ---- .../auto/xmlpatternsxqts/lib/TestSuiteHandler.cpp | 312 ------- tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.h | 169 ---- tests/auto/xmlpatternsxqts/lib/TestSuiteResult.cpp | 173 ---- tests/auto/xmlpatternsxqts/lib/TestSuiteResult.h | 93 --- tests/auto/xmlpatternsxqts/lib/TreeItem.cpp | 62 -- tests/auto/xmlpatternsxqts/lib/TreeItem.h | 114 --- tests/auto/xmlpatternsxqts/lib/TreeModel.cpp | 184 ----- tests/auto/xmlpatternsxqts/lib/TreeModel.h | 110 --- tests/auto/xmlpatternsxqts/lib/Worker.cpp | 258 ------ tests/auto/xmlpatternsxqts/lib/Worker.h | 100 --- tests/auto/xmlpatternsxqts/lib/XMLWriter.cpp | 669 --------------- tests/auto/xmlpatternsxqts/lib/XMLWriter.h | 403 --------- tests/auto/xmlpatternsxqts/lib/XQTSTestCase.cpp | 286 ------- tests/auto/xmlpatternsxqts/lib/XQTSTestCase.h | 149 ---- tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.cpp | 375 --------- tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h | 161 ---- .../xmlpatternsxqts/lib/XSDTestSuiteHandler.cpp | 910 --------------------- .../auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h | 121 --- .../xmlpatternsxqts/lib/XSLTTestSuiteHandler.cpp | 234 ------ .../xmlpatternsxqts/lib/XSLTTestSuiteHandler.h | 158 ---- .../lib/docs/XMLIndenterExample.cpp | 63 -- .../lib/docs/XMLIndenterExampleResult.xml | 3 - .../xmlpatternsxqts/lib/docs/XMLWriterExample.cpp | 63 -- .../lib/docs/XMLWriterExampleResult.xml | 3 - tests/auto/xmlpatternsxqts/lib/lib.pro | 88 -- .../xmlpatternsxqts/lib/tests/XMLWriterTest.cpp | 186 ----- .../auto/xmlpatternsxqts/lib/tests/XMLWriterTest.h | 77 -- tests/auto/xmlpatternsxqts/test/test.pro | 26 - tests/auto/xmlpatternsxqts/test/tst_suitetest.cpp | 175 ---- tests/auto/xmlpatternsxqts/test/tst_suitetest.h | 107 --- .../xmlpatternsxqts/test/tst_xmlpatternsxqts.cpp | 106 --- tests/auto/xmlpatternsxqts/tst_suitetest.cpp | 175 ++++ tests/auto/xmlpatternsxqts/tst_suitetest.h | 107 +++ tests/auto/xmlpatternsxqts/tst_xmlpatternsxqts.cpp | 106 +++ tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro | 26 +- tests/auto/xmlpatternsxslts/xmlpatternsxslts.pro | 14 +- 141 files changed, 11906 insertions(+), 11947 deletions(-) delete mode 100644 tests/auto/xmlpatternsdiagnosticsts/test/test.pro delete mode 100644 tests/auto/xmlpatternsdiagnosticsts/test/tst_xmlpatternsdiagnosticsts.cpp create mode 100644 tests/auto/xmlpatternsdiagnosticsts/tst_xmlpatternsdiagnosticsts.cpp create mode 100644 tests/auto/xmlpatternssdk/ASTItem.cpp create mode 100644 tests/auto/xmlpatternssdk/ASTItem.h create mode 100644 tests/auto/xmlpatternssdk/DebugExpressionFactory.cpp create mode 100644 tests/auto/xmlpatternssdk/DebugExpressionFactory.h create mode 100644 tests/auto/xmlpatternssdk/ErrorHandler.cpp create mode 100644 tests/auto/xmlpatternssdk/ErrorHandler.h create mode 100644 tests/auto/xmlpatternssdk/ErrorItem.cpp create mode 100644 tests/auto/xmlpatternssdk/ErrorItem.h create mode 100644 tests/auto/xmlpatternssdk/ExitCode.h create mode 100644 tests/auto/xmlpatternssdk/ExpressionInfo.cpp create mode 100644 tests/auto/xmlpatternssdk/ExpressionInfo.h create mode 100644 tests/auto/xmlpatternssdk/ExpressionNamer.cpp create mode 100644 tests/auto/xmlpatternssdk/ExpressionNamer.h create mode 100644 tests/auto/xmlpatternssdk/ExternalSourceLoader.cpp create mode 100644 tests/auto/xmlpatternssdk/ExternalSourceLoader.h create mode 100644 tests/auto/xmlpatternssdk/Global.cpp create mode 100644 tests/auto/xmlpatternssdk/Global.h create mode 100644 tests/auto/xmlpatternssdk/ResultThreader.cpp create mode 100644 tests/auto/xmlpatternssdk/ResultThreader.h create mode 100644 tests/auto/xmlpatternssdk/TestBaseLine.cpp create mode 100644 tests/auto/xmlpatternssdk/TestBaseLine.h create mode 100644 tests/auto/xmlpatternssdk/TestCase.cpp create mode 100644 tests/auto/xmlpatternssdk/TestCase.h create mode 100644 tests/auto/xmlpatternssdk/TestContainer.cpp create mode 100644 tests/auto/xmlpatternssdk/TestContainer.h create mode 100644 tests/auto/xmlpatternssdk/TestGroup.cpp create mode 100644 tests/auto/xmlpatternssdk/TestGroup.h create mode 100644 tests/auto/xmlpatternssdk/TestItem.h create mode 100644 tests/auto/xmlpatternssdk/TestResult.cpp create mode 100644 tests/auto/xmlpatternssdk/TestResult.h create mode 100644 tests/auto/xmlpatternssdk/TestResultHandler.cpp create mode 100644 tests/auto/xmlpatternssdk/TestResultHandler.h create mode 100644 tests/auto/xmlpatternssdk/TestSuite.cpp create mode 100644 tests/auto/xmlpatternssdk/TestSuite.h create mode 100644 tests/auto/xmlpatternssdk/TestSuiteHandler.cpp create mode 100644 tests/auto/xmlpatternssdk/TestSuiteHandler.h create mode 100644 tests/auto/xmlpatternssdk/TestSuiteResult.cpp create mode 100644 tests/auto/xmlpatternssdk/TestSuiteResult.h create mode 100644 tests/auto/xmlpatternssdk/TreeItem.cpp create mode 100644 tests/auto/xmlpatternssdk/TreeItem.h create mode 100644 tests/auto/xmlpatternssdk/TreeModel.cpp create mode 100644 tests/auto/xmlpatternssdk/TreeModel.h create mode 100644 tests/auto/xmlpatternssdk/Worker.cpp create mode 100644 tests/auto/xmlpatternssdk/Worker.h create mode 100644 tests/auto/xmlpatternssdk/XMLWriter.cpp create mode 100644 tests/auto/xmlpatternssdk/XMLWriter.h create mode 100644 tests/auto/xmlpatternssdk/XQTSTestCase.cpp create mode 100644 tests/auto/xmlpatternssdk/XQTSTestCase.h create mode 100644 tests/auto/xmlpatternssdk/XSDTSTestCase.cpp create mode 100644 tests/auto/xmlpatternssdk/XSDTSTestCase.h create mode 100644 tests/auto/xmlpatternssdk/XSDTestSuiteHandler.cpp create mode 100644 tests/auto/xmlpatternssdk/XSDTestSuiteHandler.h create mode 100644 tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp create mode 100644 tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.h create mode 100644 tests/auto/xmlpatternssdk/docs/XMLIndenterExample.cpp create mode 100644 tests/auto/xmlpatternssdk/docs/XMLIndenterExampleResult.xml create mode 100644 tests/auto/xmlpatternssdk/docs/XMLWriterExample.cpp create mode 100644 tests/auto/xmlpatternssdk/docs/XMLWriterExampleResult.xml create mode 100644 tests/auto/xmlpatternssdk/tests/XMLWriterTest.cpp create mode 100644 tests/auto/xmlpatternssdk/tests/XMLWriterTest.h create mode 100644 tests/auto/xmlpatternssdk/xmlpatternssdk.pro delete mode 100644 tests/auto/xmlpatternsview/test/test.pro delete mode 100644 tests/auto/xmlpatternsview/test/tst_xmlpatternsview.cpp create mode 100644 tests/auto/xmlpatternsview/tst_xmlpatternsview.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ASTItem.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ASTItem.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/ErrorHandler.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ErrorHandler.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/ErrorItem.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ErrorItem.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/ExitCode.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/ExpressionInfo.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ExpressionInfo.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/ExpressionNamer.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ExpressionNamer.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/Global.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/Global.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/ResultThreader.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ResultThreader.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestBaseLine.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestBaseLine.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestCase.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestCase.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestContainer.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestContainer.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestGroup.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestGroup.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestItem.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestResult.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestResult.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestResultHandler.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestResultHandler.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestSuite.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestSuite.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestSuiteResult.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestSuiteResult.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TreeItem.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TreeItem.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TreeModel.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TreeModel.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/Worker.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/Worker.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/XMLWriter.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/XMLWriter.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/XQTSTestCase.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/XQTSTestCase.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExample.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExampleResult.xml delete mode 100644 tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExample.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExampleResult.xml delete mode 100644 tests/auto/xmlpatternsxqts/lib/lib.pro delete mode 100644 tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.h delete mode 100644 tests/auto/xmlpatternsxqts/test/test.pro delete mode 100644 tests/auto/xmlpatternsxqts/test/tst_suitetest.cpp delete mode 100644 tests/auto/xmlpatternsxqts/test/tst_suitetest.h delete mode 100644 tests/auto/xmlpatternsxqts/test/tst_xmlpatternsxqts.cpp create mode 100644 tests/auto/xmlpatternsxqts/tst_suitetest.cpp create mode 100644 tests/auto/xmlpatternsxqts/tst_suitetest.h create mode 100644 tests/auto/xmlpatternsxqts/tst_xmlpatternsxqts.cpp diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 9961e25..af9832c 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -518,15 +518,16 @@ SUBDIRS += checkxmlfiles \ xmlpatternsdiagnosticsts \ xmlpatternsschema \ xmlpatternsschemats \ + xmlpatternssdk \ xmlpatternsvalidator \ xmlpatternsview \ xmlpatternsxqts \ xmlpatternsxslts -xmlpatternsdiagnosticsts.depends = xmlpatternsxqts -xmlpatternsview.depends = xmlpatternsxqts -xmlpatternsxslts.depends = xmlpatternsxqts -xmlpatternsschemats.depends = xmlpatternsxqts +xmlpatternsdiagnosticsts.depends = xmlpatternssdk +xmlpatternsview.depends = xmlpatternssdk +xmlpatternsxslts.depends = xmlpatternssdk +xmlpatternsschemats.depends = xmlpatternssdk } unix:!embedded:contains(QT_CONFIG, dbus):SUBDIRS += \ diff --git a/tests/auto/xmlpatternsdiagnosticsts/test/test.pro b/tests/auto/xmlpatternsdiagnosticsts/test/test.pro deleted file mode 100644 index acd71e4..0000000 --- a/tests/auto/xmlpatternsdiagnosticsts/test/test.pro +++ /dev/null @@ -1,32 +0,0 @@ -load(qttest_p4) -SOURCES += tst_xmlpatternsdiagnosticsts.cpp \ - ../../qxmlquery/TestFundament.cpp - -include (../../xmlpatterns.pri) - -TARGET = tst_xmlpatternsdiagnosticsts -DESTDIR = .. -win32 { - CONFIG(debug, debug|release): DESTDIR = ../debug - else: DESTDIR = ../release -} - -contains(QT_CONFIG, xmlpatterns) { -HEADERS += ../../xmlpatternsxqts/test/tst_suitetest.h -SOURCES += ../../xmlpatternsxqts/test/tst_suitetest.cpp -LIBS += -l$$XMLPATTERNS_SDK -} - -QT += xml - -INCLUDEPATH += $$(QTSRCDIR)/tests/auto/xmlpatternsxqts/lib/ \ - $$(QTDIR)/include/QtXmlPatterns/private \ - $$(QTSRCDIR)/tests/auto/xmlpatternsxqts/test \ - ../../xmlpatternsxqts/test \ - ../../xmlpatternsxqts/lib - -wince*|symbian { - catalog.sources = ../TestSuite ../Baseline.xml - catalog.path = . - DEPLOYMENT += catalog -} diff --git a/tests/auto/xmlpatternsdiagnosticsts/test/tst_xmlpatternsdiagnosticsts.cpp b/tests/auto/xmlpatternsdiagnosticsts/test/tst_xmlpatternsdiagnosticsts.cpp deleted file mode 100644 index 4a11404..0000000 --- a/tests/auto/xmlpatternsdiagnosticsts/test/tst_xmlpatternsdiagnosticsts.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include - -#ifdef QTEST_XMLPATTERNS - -#include "tst_suitetest.h" - -/*! - \class tst_XmlPatternsDiagnosticsTS - \internal - \since 4.5 - \brief Test QtXmlPatterns test suite driver in tests/auto/xmlpatternsxqts/lib/. - */ -class tst_XmlPatternsXSLTS : public tst_SuiteTest -{ - Q_OBJECT -public: - tst_XmlPatternsXSLTS(); -protected: - virtual void catalogPath(QString &write) const; -}; - -tst_XmlPatternsXSLTS::tst_XmlPatternsXSLTS() : tst_SuiteTest(tst_SuiteTest::XQuerySuite, true) -{ -} - -void tst_XmlPatternsXSLTS::catalogPath(QString &write) const -{ - write = QLatin1String("TestSuite/DiagnosticsCatalog.xml"); -} - -QTEST_MAIN(tst_XmlPatternsXSLTS) - -#include "tst_xmlpatternsdiagnosticsts.moc" -#else -QTEST_NOOP_MAIN -#endif - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsdiagnosticsts/tst_xmlpatternsdiagnosticsts.cpp b/tests/auto/xmlpatternsdiagnosticsts/tst_xmlpatternsdiagnosticsts.cpp new file mode 100644 index 0000000..4a11404 --- /dev/null +++ b/tests/auto/xmlpatternsdiagnosticsts/tst_xmlpatternsdiagnosticsts.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include + +#ifdef QTEST_XMLPATTERNS + +#include "tst_suitetest.h" + +/*! + \class tst_XmlPatternsDiagnosticsTS + \internal + \since 4.5 + \brief Test QtXmlPatterns test suite driver in tests/auto/xmlpatternsxqts/lib/. + */ +class tst_XmlPatternsXSLTS : public tst_SuiteTest +{ + Q_OBJECT +public: + tst_XmlPatternsXSLTS(); +protected: + virtual void catalogPath(QString &write) const; +}; + +tst_XmlPatternsXSLTS::tst_XmlPatternsXSLTS() : tst_SuiteTest(tst_SuiteTest::XQuerySuite, true) +{ +} + +void tst_XmlPatternsXSLTS::catalogPath(QString &write) const +{ + write = QLatin1String("TestSuite/DiagnosticsCatalog.xml"); +} + +QTEST_MAIN(tst_XmlPatternsXSLTS) + +#include "tst_xmlpatternsdiagnosticsts.moc" +#else +QTEST_NOOP_MAIN +#endif + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsdiagnosticsts/xmlpatternsdiagnosticsts.pro b/tests/auto/xmlpatternsdiagnosticsts/xmlpatternsdiagnosticsts.pro index 3d82eaf..981adab 100644 --- a/tests/auto/xmlpatternsdiagnosticsts/xmlpatternsdiagnosticsts.pro +++ b/tests/auto/xmlpatternsdiagnosticsts/xmlpatternsdiagnosticsts.pro @@ -1,5 +1,27 @@ -TEMPLATE = subdirs -CONFIG += ordered +load(qttest_p4) +SOURCES += tst_xmlpatternsdiagnosticsts.cpp \ + ../qxmlquery/TestFundament.cpp -SUBDIRS = ../xmlpatternsxqts test -requires(contains(QT_CONFIG,private_tests)) +include (../xmlpatterns.pri) + +TARGET = tst_xmlpatternsdiagnosticsts + +contains(QT_CONFIG, xmlpatterns) { +HEADERS += ../xmlpatternsxqts/tst_suitetest.h +SOURCES += ../xmlpatternsxqts/tst_suitetest.cpp +LIBS += -l$$XMLPATTERNS_SDK +} + +QT += xml + +INCLUDEPATH += $$(QTSRCDIR)/tests/auto/xmlpatternssdk \ + $$(QTDIR)/include/QtXmlPatterns/private \ + $$(QTSRCDIR)/tests/auto/xmlpatternsxqts \ + ../xmlpatternsxqts \ + ../xmlpatternssdk + +wince*|symbian { + catalog.sources = TestSuite Baseline.xml + catalog.path = . + DEPLOYMENT += catalog +} diff --git a/tests/auto/xmlpatternsschemats/xmlpatternsschemats.pro b/tests/auto/xmlpatternsschemats/xmlpatternsschemats.pro index 0f55078..f36211e 100644 --- a/tests/auto/xmlpatternsschemats/xmlpatternsschemats.pro +++ b/tests/auto/xmlpatternsschemats/xmlpatternsschemats.pro @@ -5,8 +5,8 @@ SOURCES += tst_xmlpatternsschemats.cpp \ include (../xmlpatterns.pri) contains(QT_CONFIG,xmlpatterns) { -HEADERS += ../xmlpatternsxqts/test/tst_suitetest.h -SOURCES += ../xmlpatternsxqts/test/tst_suitetest.cpp +HEADERS += ../xmlpatternsxqts/tst_suitetest.h +SOURCES += ../xmlpatternsxqts/tst_suitetest.cpp } PATTERNIST_SDK = QtXmlPatternsSDK @@ -20,8 +20,8 @@ LIBS += -l$$PATTERNIST_SDK QT += xml -INCLUDEPATH += $$QT_SOURCE_TREE/tests/auto/xmlpatternsxqts/lib/ \ - $$QT_BUILD_TREE/include/QtXmlPatterns/private \ - $$QT_SOURCE_TREE/tests/auto/xmlpatternsxqts/test \ - ../xmlpatternsxqts/test \ - ../xmlpatternsxqts/lib +INCLUDEPATH += $$QT_SOURCE_TREE/tests/auto/xmlpatternssdk/ \ + $$QT_BUILD_TREE/include/QtXmlPatterns/private \ + $$QT_SOURCE_TREE/tests/auto/xmlpatternsxqts \ + ../xmlpatternsxqts \ + ../xmlpatternssdk diff --git a/tests/auto/xmlpatternssdk/ASTItem.cpp b/tests/auto/xmlpatternssdk/ASTItem.cpp new file mode 100644 index 0000000..3b4fbdc --- /dev/null +++ b/tests/auto/xmlpatternssdk/ASTItem.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +#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(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(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/xmlpatternssdk/ASTItem.h b/tests/auto/xmlpatternssdk/ASTItem.h new file mode 100644 index 0000000..ca3ac8f --- /dev/null +++ b/tests/auto/xmlpatternssdk/ASTItem.h @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_ASTItem_H +#define PatternistSDK_ASTItem_H + +#include +#include + +#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 + */ + 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 1 eq number() 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/xmlpatternssdk/DebugExpressionFactory.cpp b/tests/auto/xmlpatternssdk/DebugExpressionFactory.cpp new file mode 100644 index 0000000..1b5121e --- /dev/null +++ b/tests/auto/xmlpatternssdk/DebugExpressionFactory.cpp @@ -0,0 +1,264 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +#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(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/xmlpatternssdk/DebugExpressionFactory.h b/tests/auto/xmlpatternssdk/DebugExpressionFactory.h new file mode 100644 index 0000000..d5e676d --- /dev/null +++ b/tests/auto/xmlpatternssdk/DebugExpressionFactory.h @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@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 + */ + class Q_PATTERNISTSDK_EXPORT DebugExpressionFactory : public QPatternist::ExpressionFactory + { + public: + DebugExpressionFactory() : m_ast(0) + { + } + + typedef QExplicitlySharedDataPointer 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/xmlpatternssdk/ErrorHandler.cpp b/tests/auto/xmlpatternssdk/ErrorHandler.cpp new file mode 100644 index 0000000..3f07737 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ErrorHandler.cpp @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#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("

") + QPatternist::escape(QLatin1String(description)) + QLatin1String("

")); +} + +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/xmlpatternssdk/ErrorHandler.h b/tests/auto/xmlpatternssdk/ErrorHandler.h new file mode 100644 index 0000000..25447a9 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ErrorHandler.h @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@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 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 + */ + class Q_PATTERNISTSDK_EXPORT ErrorHandler : public QAbstractMessageHandler + { + public: + class Message + { + public: + typedef QList 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/xmlpatternssdk/ErrorItem.cpp b/tests/auto/xmlpatternssdk/ErrorItem.cpp new file mode 100644 index 0000000..57edc1f --- /dev/null +++ b/tests/auto/xmlpatternssdk/ErrorItem.cpp @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +#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/xmlpatternssdk/ErrorItem.h b/tests/auto/xmlpatternssdk/ErrorItem.h new file mode 100644 index 0000000..1d05872 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ErrorItem.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_ErrorItem_H +#define PatternistSDK_ErrorItem_H + +#include + +#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 + */ + 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/xmlpatternssdk/ExitCode.h b/tests/auto/xmlpatternssdk/ExitCode.h new file mode 100644 index 0000000..e1810b1 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ExitCode.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@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 + */ + 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/xmlpatternssdk/ExpressionInfo.cpp b/tests/auto/xmlpatternssdk/ExpressionInfo.cpp new file mode 100644 index 0000000..abbc8b3 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ExpressionInfo.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "ExpressionInfo.h" + +using namespace QPatternistSDK; + +ExpressionInfo::ExpressionInfo(const QString &name, + const QString &details) : QPair(name, details) +{ +} + +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/ExpressionInfo.h b/tests/auto/xmlpatternssdk/ExpressionInfo.h new file mode 100644 index 0000000..2d9d398 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ExpressionInfo.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_ExpressionInfo_H +#define PatternistSDK_ExpressionInfo_H + +#include "Global.h" +#include "qexpressiondispatch_p.h" + +#include +#include + +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 + */ + class Q_PATTERNISTSDK_EXPORT ExpressionInfo : public QPatternist::ExpressionVisitorResult + , public QPair + { + 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/xmlpatternssdk/ExpressionNamer.cpp b/tests/auto/xmlpatternssdk/ExpressionNamer.cpp new file mode 100644 index 0000000..605c754 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ExpressionNamer.cpp @@ -0,0 +1,316 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#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 *i) const +{ + return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("EvaluationCache"), + QLatin1String("Slot: ") + QString::number(i->slot()))); + +} + +QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::EvaluationCache *i) const +{ + return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("EvaluationCache"), + 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/xmlpatternssdk/ExpressionNamer.h b/tests/auto/xmlpatternssdk/ExpressionNamer.h new file mode 100644 index 0000000..129d8d7 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ExpressionNamer.h @@ -0,0 +1,281 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@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 + */ + 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 *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::EvaluationCache *) 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/xmlpatternssdk/ExternalSourceLoader.cpp b/tests/auto/xmlpatternssdk/ExternalSourceLoader.cpp new file mode 100644 index 0000000..a83a100 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ExternalSourceLoader.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +#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/xmlpatternssdk/ExternalSourceLoader.h b/tests/auto/xmlpatternssdk/ExternalSourceLoader.h new file mode 100644 index 0000000..2d88222 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ExternalSourceLoader.h @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_ExternalSourceLoader_H +#define PatternistSDK_ExternalSourceLoader_H + +#include +#include +#include + +#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 $input-context, + * by loading appropriate XML source files. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + 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 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 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 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/xmlpatternssdk/Global.cpp b/tests/auto/xmlpatternssdk/Global.cpp new file mode 100644 index 0000000..f78e421 --- /dev/null +++ b/tests/auto/xmlpatternssdk/Global.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#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/xmlpatternssdk/Global.h b/tests/auto/xmlpatternssdk/Global.h new file mode 100644 index 0000000..53c32cb --- /dev/null +++ b/tests/auto/xmlpatternssdk/Global.h @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_Global_H +#define PatternistSDK_Global_H + +#include + +#include "private/qitem_p.h" +#include "private/qnamepool_p.h" + +#if defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN) +# 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 XML Query Test Suite + * @author Frans Englich + */ +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + /** + * @short Contains global constants. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT Global + { + public: + + /** + * The namespace which the XQTS test case catalog(specified by Catalog.xsd) + * is in. The namespace is: http://www.w3.org/2005/02/query-test-XQTSCatalog + */ + static const QString xqtsCatalogNS; + + /** + * The namespace which the XQTS test results collection(specified by XQTSResult.xsd) + * is in. The namespace is: http://www.w3.org/2005/02/query-test-XQTSResult + */ + 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/xmlpatternssdk/ResultThreader.cpp b/tests/auto/xmlpatternssdk/ResultThreader.cpp new file mode 100644 index 0000000..3296854 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ResultThreader.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#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/xmlpatternssdk/ResultThreader.h b/tests/auto/xmlpatternssdk/ResultThreader.h new file mode 100644 index 0000000..19749f0 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ResultThreader.h @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_ResultThreader_H +#define PatternistSDK_ResultThreader_H + +#include +#include +#include + +#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 + * @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/xmlpatternssdk/TestBaseLine.cpp b/tests/auto/xmlpatternssdk/TestBaseLine.cpp new file mode 100644 index 0000000..6a46bcc --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestBaseLine.cpp @@ -0,0 +1,511 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#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 SchemaIsValid: /* 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(n1).data() == + static_cast(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 SchemaIsValid: + /* Fall through. */ + 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("") + + serializedInput + + QLatin1String("")).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("") + + details() + + QLatin1String("")).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"); + case SchemaIsValid: + return QLatin1String("SchemaIsValid"); + } + + 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_type == SchemaIsValid) /* We're a schema validation information . */ + 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/xmlpatternssdk/TestBaseLine.h b/tests/auto/xmlpatternssdk/TestBaseLine.h new file mode 100644 index 0000000..e297128 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestBaseLine.h @@ -0,0 +1,212 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestBaseLine_H +#define PatternistSDK_TestBaseLine_H + +#include + +#include "Global.h" +#include "TestResult.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QDomNamedNodeMap; +class QDomNode; +class QDomNodeList; +template 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 + */ + class Q_PATTERNISTSDK_EXPORT TestBaseLine + { + public: + typedef QList List; + + /** + * Identifies what kind of comparator to use. The documentation + * for each enumerator is copied from + * Guidelines + * for Running the XML Query Test Suite + */ + 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, + + /** + * A special comparison for the schema validation tests. The details + * can only be 'true' or 'false' depending on whether it is a valid + * schema or not. + */ + SchemaIsValid + }; + + /** + * 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/xmlpatternssdk/TestCase.cpp b/tests/auto/xmlpatternssdk/TestCase.cpp new file mode 100644 index 0000000..7b424d2 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestCase.cpp @@ -0,0 +1,439 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#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(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 +{ + /* */ + 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); + + /* */ + receiver.startElement(QLatin1String("description"), test_caseAtts); + receiver.characters(description()); + + /* */ + receiver.endElement(QLatin1String("description")); + + /* */ + 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); + + /* */ + 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); + + /* */ + 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/xmlpatternssdk/TestCase.h b/tests/auto/xmlpatternssdk/TestCase.h new file mode 100644 index 0000000..28df5f1 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestCase.h @@ -0,0 +1,256 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestCase_H +#define PatternistSDK_TestCase_H + +#include + +#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 + */ + 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 m_result; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestContainer.cpp b/tests/auto/xmlpatternssdk/TestContainer.cpp new file mode 100644 index 0000000..ec6196c --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestContainer.cpp @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#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(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(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/xmlpatternssdk/TestContainer.h b/tests/auto/xmlpatternssdk/TestContainer.h new file mode 100644 index 0000000..5b93491 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestContainer.h @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@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 + */ + 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/xmlpatternssdk/TestGroup.cpp b/tests/auto/xmlpatternssdk/TestGroup.cpp new file mode 100644 index 0000000..f2cd2bd --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestGroup.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +#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 && role != Qt::ToolTipRole) + 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(); + } + } + case Qt::ToolTipRole: + { + return description(); + } + 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/xmlpatternssdk/TestGroup.h b/tests/auto/xmlpatternssdk/TestGroup.h new file mode 100644 index 0000000..5f4798f --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestGroup.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestGroup_H +#define PatternistSDK_TestGroup_H + +#include + +#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 + */ + 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 ¬e); + + 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/xmlpatternssdk/TestItem.h b/tests/auto/xmlpatternssdk/TestItem.h new file mode 100644 index 0000000..0b3c606 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestItem.h @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@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 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 + */ + 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 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/xmlpatternssdk/TestResult.cpp b/tests/auto/xmlpatternssdk/TestResult.cpp new file mode 100644 index 0000000..2374bc0 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestResult.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#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/xmlpatternssdk/TestResult.h b/tests/auto/xmlpatternssdk/TestResult.h new file mode 100644 index 0000000..6951f90 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestResult.h @@ -0,0 +1,179 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestResult_H +#define PatternistSDK_TestResult_H + +#include +#include +#include +#include + +#include +#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 + */ + 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 > 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 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/xmlpatternssdk/TestResultHandler.cpp b/tests/auto/xmlpatternssdk/TestResultHandler.cpp new file mode 100644 index 0000000..b87d481 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestResultHandler.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#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/xmlpatternssdk/TestResultHandler.h b/tests/auto/xmlpatternssdk/TestResultHandler.h new file mode 100644 index 0000000..a786ac4 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestResultHandler.h @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestResultHandler_H +#define PatternistSDK_TestResultHandler_H + +#include +#include +#include + +#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 + * @ingroup PatternistSDK + */ + class Q_PATTERNISTSDK_EXPORT TestResultHandler : public QXmlDefaultHandler + { + public: + /** + * A hash where the key is the class's name, that is test-case/@@name, + * and the value the test's result status. + */ + typedef QHash Hash; + + /** + * A hash mapping test-case names to their' comments. + */ + typedef QHash CommentHash; + + /** + * Creates a TestResultHandler that will read @p file when run() is called. + */ + TestResultHandler(); + + /** + * Performs finalization. + */ + virtual bool endDocument(); + + /** + * Reads the test-case 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/xmlpatternssdk/TestSuite.cpp b/tests/auto/xmlpatternssdk/TestSuite.cpp new file mode 100644 index 0000000..2c3e49c --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestSuite.cpp @@ -0,0 +1,269 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +#include "Global.h" +#include "TestSuiteHandler.h" +#include "TestSuiteResult.h" +#include "XMLWriter.h" +#include "XSLTTestSuiteHandler.h" +#include "XSDTestSuiteHandler.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, + SuiteType suiteType) +{ + 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, suiteType); +} + +TestSuite *TestSuite::openCatalog(QIODevice *input, + QString &errorMsg, + const QUrl &fileName, + const bool useExclusionList, + SuiteType suiteType) +{ + Q_ASSERT(input); + + QXmlSimpleReader reader; + typedef QPatternist::AutoPtr HandlerPtr; + + HandlerPtr loader; + + switch (suiteType) { + case XQuerySuite: loader = HandlerPtr(new TestSuiteHandler(fileName, useExclusionList)); break; + case XsltSuite: loader = HandlerPtr(new XSLTTestSuiteHandler(fileName)); break; + case XsdSuite: loader = HandlerPtr(new XSDTestSuiteHandler(fileName)); break; + default: Q_ASSERT(false); break; + } + + reader.setContentHandler(loader.data()); + + QXmlInputSource source(input); + + if(!reader.parse(source)) + { + errorMsg = QString::fromLatin1("Couldn't parse %1").arg(fileName.toString()); + return 0; + } + + TestSuite *suite = 0; + switch (suiteType) { + case XQuerySuite: suite = static_cast(loader.data())->testSuite(); break; + case XsltSuite: suite = static_cast(loader.data())->testSuite(); break; + case XsdSuite: suite = static_cast(loader.data())->testSuite(); break; + default: Q_ASSERT(false); break; + } + + 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(); + /* */ + 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()); + + /* */ + QXmlAttributes test_groupAtts; + test_groupAtts.append(QLatin1String("GeneratedGroupByPatternistSDKRunSuite"), QString(), + QLatin1String("GeneratedGroupByPatternistSDKRunSuite"), QString()); + receiver.startElement(QLatin1String("test-group"), test_groupAtts); + + /* */ + receiver.startElement(QLatin1String("GroupInfo"), test_groupAtts); + + /* */ + receiver.startElement(QLatin1String("title"), test_groupAtts); + receiver.characters(QLatin1String("Contains the test case generated by PatternistSDKRunSuite.")); + + /* */ + receiver.endElement(QLatin1String("title")); + + /* */ + receiver.startElement(QLatin1String("description"), test_groupAtts); + /* */ + receiver.endElement(QLatin1String("description")); + + /* */ + receiver.endElement(QLatin1String("GroupInfo")); + + /* */ + tc->toXML(receiver); + /* */ + + /* */ + receiver.endElement(QLatin1String("test-group")); + + /* */ + 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/xmlpatternssdk/TestSuite.h b/tests/auto/xmlpatternssdk/TestSuite.h new file mode 100644 index 0000000..d14dc62 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestSuite.h @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestSuite_H +#define PatternistSDK_TestSuite_H + +#include +#include + +#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 + */ + class Q_PATTERNISTSDK_EXPORT TestSuite : public TestContainer + { + public: + /** + * Describes the type of test suite. + */ + enum SuiteType + { + XQuerySuite, ///< The test suite for XQuery + XsltSuite, ///< The test suite for XSLT + XsdSuite ///< The test suite for XML Schema + }; + + 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, + SuiteType type); + + 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, + SuiteType type); + 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/xmlpatternssdk/TestSuiteHandler.cpp b/tests/auto/xmlpatternssdk/TestSuiteHandler.cpp new file mode 100644 index 0000000..7c687f3 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestSuiteHandler.cpp @@ -0,0 +1,312 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#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 , so the 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(m_container->parent()); + Q_ASSERT(m_container); + } + else if(localName == QLatin1String("test-suite")) + { + Q_ASSERT(m_container); + m_container = static_cast(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/xmlpatternssdk/TestSuiteHandler.h b/tests/auto/xmlpatternssdk/TestSuiteHandler.h new file mode 100644 index 0000000..76156c0 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestSuiteHandler.h @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestSuiteHandler_H +#define PatternistSDK_TestSuiteHandler_H + +#include +#include +#include + +#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 + */ + 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 input-file/\@variable/. + */ + 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 m_testGroupName; + + /** + * Holds the content of the current input-URI 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/xmlpatternssdk/TestSuiteResult.cpp b/tests/auto/xmlpatternssdk/TestSuiteResult.cpp new file mode 100644 index 0000000..4e81859 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestSuiteResult.cpp @@ -0,0 +1,173 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#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("frans.englich@nokia.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: + * - + * - + * - + */ + + receiver.startDocument(); + /* */ + receiver.startPrefixMapping(QString(), Global::xqtsResultNS); + receiver.startElement(QLatin1String("test-suite-result")); + receiver.endPrefixMapping(QString()); + + /* */ + QXmlAttributes implementationAtts; + implementationAtts.append(QLatin1String("name"), QString(), + QLatin1String("name"), implementationName); + implementationAtts.append(QLatin1String("version"), QString(), + QLatin1String("version"), implementationVersion); + receiver.startElement(QLatin1String("implementation"), implementationAtts); + + /* */ + QXmlAttributes organizationAtts; + organizationAtts.append(QLatin1String("name"), QString(), + QLatin1String("name"), organizationName); + organizationAtts.append(QLatin1String("website"), QString(), + QLatin1String("website"), organizationWebsite); + receiver.startElement(QLatin1String("organization"), organizationAtts); + + /* */ + receiver.endElement(QLatin1String("organization")); + + /* */ + QXmlAttributes submittorAtts; + submittorAtts.append(QLatin1String("name"), QString(), QLatin1String("name"), submittorName); + submittorAtts.append(QLatin1String("email"), QString(), QLatin1String("email"), submittorEmail); + receiver.startElement(QLatin1String("submittor"), submittorAtts); + + /* */ + receiver.endElement(QLatin1String("submittor")); + + /* */ + receiver.startElement(QLatin1String("description")); + + /*

*/ + receiver.startElement(QLatin1String("p")); + receiver.characters(implementationDescription); + + /*

*/ + receiver.endElement(QLatin1String("p")); + /*
*/ + receiver.endElement(QLatin1String("description")); + + /*
*/ + receiver.endElement(QLatin1String("implementation")); + + /* */ + receiver.startElement(QLatin1String("syntax")); + receiver.characters(QLatin1String(QLatin1String("XQuery"))); + + /* */ + receiver.endElement(QLatin1String("syntax")); + + /* */ + 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); + + /* */ + QXmlAttributes test_suiteAtts; + test_suiteAtts.append(QLatin1String("version"), QString(), QLatin1String("version"), m_testSuiteVersion); + receiver.startElement(QLatin1String("test-suite"), test_suiteAtts); + + /* */ + receiver.endElement(QLatin1String("test-suite")); + + /* */ + 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); + + /*
*/ + receiver.endElement(QLatin1String("test-suite-result")); + receiver.endDocument(); +} + +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/TestSuiteResult.h b/tests/auto/xmlpatternssdk/TestSuiteResult.h new file mode 100644 index 0000000..491c2b2 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestSuiteResult.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestSuiteResult_H +#define PatternistSDK_TestSuiteResult_H + +#include +#include + +#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 + */ + 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/xmlpatternssdk/TreeItem.cpp b/tests/auto/xmlpatternssdk/TreeItem.cpp new file mode 100644 index 0000000..b34262d --- /dev/null +++ b/tests/auto/xmlpatternssdk/TreeItem.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@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(this)); + } + else + return -1; +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TreeItem.h b/tests/auto/xmlpatternssdk/TreeItem.h new file mode 100644 index 0000000..f5e051f --- /dev/null +++ b/tests/auto/xmlpatternssdk/TreeItem.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TreeItem_H +#define PatternistSDK_TreeItem_H + +#include + +#include "Global.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QVariant; +template class QList; +template 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 + * @see TreeModel + * @ingroup PatternistSDK + */ + class Q_PATTERNISTSDK_EXPORT TreeItem : public QObject + { + Q_OBJECT + public: + typedef QList > 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/xmlpatternssdk/TreeModel.cpp b/tests/auto/xmlpatternssdk/TreeModel.cpp new file mode 100644 index 0000000..e27f8e0 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TreeModel.cpp @@ -0,0 +1,184 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#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(idx.internalPointer()); + Q_ASSERT(item); + + return item->data(static_cast(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 *item) +{ + if (item) { + const QModelIndex index = createIndex(item->row(), 0, item); + dataChanged(index, index); + } else { + 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(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(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(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(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/xmlpatternssdk/TreeModel.h b/tests/auto/xmlpatternssdk/TreeModel.h new file mode 100644 index 0000000..1d8ea72 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TreeModel.h @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TreeModel_H +#define PatternistSDK_TreeModel_H + +#include +#include +#include +#include + +#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 + */ + 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 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/xmlpatternssdk/Worker.cpp b/tests/auto/xmlpatternssdk/Worker.cpp new file mode 100644 index 0000000..0121099 --- /dev/null +++ b/tests/auto/xmlpatternssdk/Worker.cpp @@ -0,0 +1,258 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +#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(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 Info; + typedef QList 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(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/xmlpatternssdk/Worker.h b/tests/auto/xmlpatternssdk/Worker.h new file mode 100644 index 0000000..b3d7ae2 --- /dev/null +++ b/tests/auto/xmlpatternssdk/Worker.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_Worker_H +#define PatternistSDK_Worker_H + +#include +#include +#include +#include + +#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 + * @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/xmlpatternssdk/XMLWriter.cpp b/tests/auto/xmlpatternssdk/XMLWriter.cpp new file mode 100644 index 0000000..60a5344 --- /dev/null +++ b/tests/auto/xmlpatternssdk/XMLWriter.cpp @@ -0,0 +1,669 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#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 NSBinding; +typedef QList 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::const_iterator end(namespaceTracker.constEnd()); + QStack::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("&"); + else if(c == QLatin1Char(QLatin1Char('<'))) + retval += QLatin1String("<"); + 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("&"); + else if(c == QLatin1Char('<')) + retval += QLatin1String("<"); + else if(c == QLatin1Char('"')) + retval += QLatin1String("""); + 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(">"); + 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 hasContentStack; + QString errorString; + DEBUG_CODE(QStack tags;) + DEBUG_CODE(QStack 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 do {} while (false) + +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("\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("'); + } + 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("")); + 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 "")); + + 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("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("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/xmlpatternssdk/XMLWriter.h b/tests/auto/xmlpatternssdk/XMLWriter.h new file mode 100644 index 0000000..2b629bb --- /dev/null +++ b/tests/auto/xmlpatternssdk/XMLWriter.h @@ -0,0 +1,403 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_XMLWriter_H +#define PatternistSDK_XMLWriter_H + +#include "Global.h" + +#include +#include + +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 xmlns:* to startElement(). + * + * @see HOWTO Avoid Being + * Called a Bozo When Producing XML + * @see Extensible Markup + * Language (XML) 1.0 (Third Edition) + * @see Namespaces in XML + * @todo Replace this class with QXmlStreamWriter + * @author Frans Englich + * @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 xmlns:* 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 + +@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 "" 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/xmlpatternssdk/XQTSTestCase.cpp b/tests/auto/xmlpatternssdk/XQTSTestCase.cpp new file mode 100644 index 0000000..6a8645b --- /dev/null +++ b/tests/auto/xmlpatternssdk/XQTSTestCase.cpp @@ -0,0 +1,286 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +#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/xmlpatternssdk/XQTSTestCase.h b/tests/auto/xmlpatternssdk/XQTSTestCase.h new file mode 100644 index 0000000..8872b32 --- /dev/null +++ b/tests/auto/xmlpatternssdk/XQTSTestCase.h @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_XQTSTestCase_H +#define PatternistSDK_XQTSTestCase_H + +#include +#include +#include + +#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 + */ + 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/xmlpatternssdk/XSDTSTestCase.cpp b/tests/auto/xmlpatternssdk/XSDTSTestCase.cpp new file mode 100644 index 0000000..3cbb681 --- /dev/null +++ b/tests/auto/xmlpatternssdk/XSDTSTestCase.cpp @@ -0,0 +1,375 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the autotests 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +#include "XSDTSTestCase.h" + +#include "qxmlschema.h" +#include "qxmlschemavalidator.h" + +using namespace QPatternistSDK; +using namespace QPatternist; + +XSDTSTestCase::XSDTSTestCase(const Scenario scen, TreeItem *p, TestType testType) + : m_scenario(scen) + , m_parent(p) + , m_testType(testType) +{ +} + +XSDTSTestCase::~XSDTSTestCase() +{ + qDeleteAll(m_baseLines); +} + +TestResult::List XSDTSTestCase::execute(const ExecutionStage, TestSuite*) +{ + ErrorHandler errHandler; + ErrorHandler::installQtMessageHandler(&errHandler); + + TestResult::List retval; + TestResult::Status resultStatus = TestResult::Unknown; + QString serialized; + + if (m_testType == SchemaTest) { + executeSchemaTest(resultStatus, serialized, &errHandler); + } else { + executeInstanceTest(resultStatus, serialized, &errHandler); + } + + resultStatus = TestBaseLine::scan(serialized, baseLines()); + Q_ASSERT(resultStatus != TestResult::Unknown); + + m_result = new TestResult(name(), resultStatus, 0, errHandler.messages(), + QPatternist::Item::List(), serialized); + retval.append(m_result); + ErrorHandler::installQtMessageHandler(0); + changed(this); + return retval; +} + +void XSDTSTestCase::executeSchemaTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler) +{ + QFile file(m_schemaUri.path()); + if (!file.open(QIODevice::ReadOnly)) { + resultStatus = TestResult::Fail; + serialized = QString(); + return; + } + + QXmlSchema schema; + schema.setMessageHandler(handler); + schema.load(&file, m_schemaUri); + + if (schema.isValid()) { + resultStatus = TestResult::Pass; + serialized = QString::fromLatin1("true"); + } else { + resultStatus = TestResult::Pass; + serialized = QString::fromLatin1("false"); + } +} + +void XSDTSTestCase::executeInstanceTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler) +{ + QFile instanceFile(m_instanceUri.path()); + if (!instanceFile.open(QIODevice::ReadOnly)) { + resultStatus = TestResult::Fail; + serialized = QString(); + return; + } + + QXmlSchema schema; + if (m_schemaUri.isValid()) { + QFile file(m_schemaUri.path()); + if (!file.open(QIODevice::ReadOnly)) { + resultStatus = TestResult::Fail; + serialized = QString(); + return; + } + + schema.setMessageHandler(handler); + schema.load(&file, m_schemaUri); + + if (!schema.isValid()) { + resultStatus = TestResult::Pass; + serialized = QString::fromLatin1("false"); + return; + } + } + + QXmlSchemaValidator validator(schema); + validator.setMessageHandler(handler); + + qDebug("check %s", qPrintable(m_instanceUri.path())); + if (validator.validate(&instanceFile, m_instanceUri)) { + resultStatus = TestResult::Pass; + serialized = QString::fromLatin1("true"); + } else { + resultStatus = TestResult::Pass; + serialized = QString::fromLatin1("false"); + } +} + +QVariant XSDTSTestCase::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 XSDTSTestCase::sourceCode(bool &ok) const +{ + QFile file((m_testType == SchemaTest ? m_schemaUri : m_instanceUri).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 XSDTSTestCase::columnCount() const +{ + return 2; +} + +void XSDTSTestCase::addBaseLine(TestBaseLine *line) +{ + m_baseLines.append(line); +} + +QString XSDTSTestCase::name() const +{ + return m_name; +} + +QString XSDTSTestCase::creator() const +{ + return m_creator; +} + +QString XSDTSTestCase::description() const +{ + return m_description; +} + +QDate XSDTSTestCase::lastModified() const +{ + return m_lastModified; +} + +bool XSDTSTestCase::isXPath() const +{ + return false; +} + +TestCase::Scenario XSDTSTestCase::scenario() const +{ + return m_scenario; +} + +void XSDTSTestCase::setName(const QString &n) +{ + m_name = n; +} + +void XSDTSTestCase::setCreator(const QString &ctor) +{ + m_creator = ctor; +} + +void XSDTSTestCase::setDescription(const QString &descriptionP) +{ + m_description = descriptionP; +} + +void XSDTSTestCase::setLastModified(const QDate &date) +{ + m_lastModified = date; +} + +void XSDTSTestCase::setSchemaUri(const QUrl &uri) +{ + m_schemaUri = uri; +} + +void XSDTSTestCase::setInstanceUri(const QUrl &uri) +{ + m_instanceUri = uri; +} + +TreeItem *XSDTSTestCase::parent() const +{ + return m_parent; +} + +QString XSDTSTestCase::title() const +{ + return m_name; +} + +TestBaseLine::List XSDTSTestCase::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 XSDTSTestCase::schemaUri() const +{ + return m_schemaUri; +} + +QUrl XSDTSTestCase::instanceUri() const +{ + return m_instanceUri; +} + +void XSDTSTestCase::setContextItemSource(const QUrl &uri) +{ + m_contextItemSource = uri; +} + +QUrl XSDTSTestCase::contextItemSource() const +{ + return m_contextItemSource; +} + +void XSDTSTestCase::setParent(TreeItem *const p) +{ + m_parent = p; +} + +QPatternist::ExternalVariableLoader::Ptr XSDTSTestCase::externalVariableLoader() const +{ + return QPatternist::ExternalVariableLoader::Ptr(); +} + +TestResult *XSDTSTestCase::testResult() const +{ + return m_result; +} + +TestItem::ResultSummary XSDTSTestCase::resultSummary() const +{ + if(m_result) + return ResultSummary(m_result->status() == TestResult::Pass ? 1 : 0, + 1); + + return ResultSummary(0, 1); +} + +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/XSDTSTestCase.h b/tests/auto/xmlpatternssdk/XSDTSTestCase.h new file mode 100644 index 0000000..947687a --- /dev/null +++ b/tests/auto/xmlpatternssdk/XSDTSTestCase.h @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the autotests 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_XSDTSTestCase_H +#define PatternistSDK_XSDTSTestCase_H + +#include +#include +#include + +#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 + */ + class Q_PATTERNISTSDK_EXPORT XSDTSTestCase : public TestCase + { + public: + enum TestType + { + SchemaTest, + InstanceTest + }; + + XSDTSTestCase(const Scenario scen, TreeItem *parent, TestType testType); + virtual ~XSDTSTestCase(); + + /** + * 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); + /** + * 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 schemaUri() const; + virtual QUrl instanceUri() const; + virtual QUrl testCasePath() const {return QUrl();} + 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 setName(const QString &name); + void setSchemaUri(const QUrl &uri); + void setInstanceUri(const QUrl &uri); + void setTestCasePath(const QUrl & /* uri */) {} + void setContextItemSource(const QUrl &uri); + void addBaseLine(TestBaseLine *lines); + + 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; + + virtual QUrl contextItemSource() const; + void setParent(TreeItem *const parent); + virtual QPatternist::ExternalVariableLoader::Ptr externalVariableLoader() const; + virtual TestResult *testResult() const; + virtual ResultSummary resultSummary() const; + + private: + void executeSchemaTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler); + void executeInstanceTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler); + + QString m_name; + QString m_creator; + QString m_description; + QUrl m_schemaUri; + QUrl m_instanceUri; + QDate m_lastModified; + const Scenario m_scenario; + TreeItem * m_parent; + TestBaseLine::List m_baseLines; + QUrl m_contextItemSource; + TestType m_testType; + QPointer m_result; + }; +} + +QT_END_NAMESPACE +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.cpp b/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.cpp new file mode 100644 index 0000000..a868d19 --- /dev/null +++ b/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.cpp @@ -0,0 +1,910 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the autotests 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "qacceltreeresourceloader_p.h" +#include "qnetworkaccessdelegator_p.h" + +#include "Global.h" +#include "TestBaseLine.h" +#include "TestGroup.h" + +#include "XSDTestSuiteHandler.h" +#include "XSDTSTestCase.h" + +using namespace QPatternistSDK; + +extern QNetworkAccessManager s_networkManager; + +XSDTestSuiteHandler::XSDTestSuiteHandler(const QUrl &catalogFile) : m_ts(0) + , m_catalogFile(catalogFile) + , m_inSchemaTest(false) + , m_inInstanceTest(false) + , m_inTestGroup(false) + , m_inDescription(false) + , m_schemaBlacklisted(false) + , m_counter(0) +{ + Q_ASSERT(!m_catalogFile.isRelative()); + m_ts = new TestSuite(); + m_topLevelGroup = new TestGroup(m_ts); + m_topLevelGroup->setTitle("XML Schema Test Suite"); + m_ts->appendChild(m_topLevelGroup); + + // exclude these test cases, as they break our current state machine + m_blackList << QLatin1String("addB099") + << QLatin1String("addB118") + << QLatin1String("elemJ003") + << QLatin1String("elemJ011") + << QLatin1String("elemZ004") + << QLatin1String("elemZ020") + << QLatin1String("groupH021v") + << QLatin1String("groupJ009v") + << QLatin1String("name00101m2") + << QLatin1String("schL5") + << QLatin1String("ste110") + << QLatin1String("stZ007") + << QLatin1String("stZ047") + << QLatin1String("stZ055") + << QLatin1String("addB049") + << QLatin1String("addB068") + << QLatin1String("addB078") + << QLatin1String("addB078A") + << QLatin1String("addB078B") + << QLatin1String("addB167") + << QLatin1String("addB191") + << QLatin1String("isDefault060_2") + << QLatin1String("isDefault069") + << QLatin1String("annotB025") + << QLatin1String("base64Binary_enumeration003_1321") + << QLatin1String("anyURI_a001_1336") + << QLatin1String("anyURI_a001_1336") + << QLatin1String("anyURI_a003_1338") + << QLatin1String("anyURI_a004_1339") + << QLatin1String("anyURI_b004_1354") + << QLatin1String("anyURI_b004_1354") + << QLatin1String("anyURI_b006_1356") + << QLatin1String("QName_length001_1357") + << QLatin1String("QName_length003_1359") + << QLatin1String("QName_minLength003_1362") + << QLatin1String("QName_maxLength001_1364") + << QLatin1String("NOTATION_length001_1372") + << QLatin1String("NOTATION_length003_1374") + << QLatin1String("NOTATION_minLength003_1377") + << QLatin1String("NOTATION_maxLength001_1379") + << QLatin1String("hexBinary003_2069") + << QLatin1String("QName009_2092") + << QLatin1String("dtZ107447_a_2245") + << QLatin1String("elemE001") + << QLatin1String("elemE002") + << QLatin1String("elemE003") + << QLatin1String("elemE004") + << QLatin1String("elemE005") + << QLatin1String("elemT026") + << QLatin1String("elemT027") + << QLatin1String("elemT028") + << QLatin1String("elemT029") + << QLatin1String("elemT054") + << QLatin1String("elemT055") + << QLatin1String("elemT056") + << QLatin1String("elemT057") + << QLatin1String("elemZ006") + << QLatin1String("elemZ007") + << QLatin1String("elemZ026") + << QLatin1String("elemZ027_c") + << QLatin1String("elemZ028c") + << QLatin1String("elemZ028d") + << QLatin1String("elemZ028f1") + << QLatin1String("elemZ028f1") + << QLatin1String("elemZ028f2") + << QLatin1String("elemZ028f2") + << QLatin1String("elemZ028f3") + << QLatin1String("elemZ028f3") + << QLatin1String("elemZ031") + << QLatin1String("errF001") + << QLatin1String("idC019") + << QLatin1String("idL100") + << QLatin1String("idZ011") + << QLatin1String("idZ015") + << QLatin1String("mgO013") + << QLatin1String("particlesA012") + << QLatin1String("particlesA013") + << QLatin1String("particlesA014") + << QLatin1String("particlesA015") + << QLatin1String("particlesHa161") + << QLatin1String("particlesHb008") + << QLatin1String("particlesHb011") + << QLatin1String("particlesIe003") + << QLatin1String("particlesIg003") + << QLatin1String("particlesIg004") + << QLatin1String("particlesJb003") + << QLatin1String("particlesJd003") + << QLatin1String("particlesJf003") + << QLatin1String("particlesJk003") + << QLatin1String("particlesOb001") + << QLatin1String("particlesOb002") + << QLatin1String("particlesOb004") + << QLatin1String("particlesOb008") + << QLatin1String("particlesOb009") + << QLatin1String("particlesOb013") + << QLatin1String("particlesOb018") + << QLatin1String("particlesQ005") + << QLatin1String("particlesS002") + << QLatin1String("particlesT002") + << QLatin1String("particlesT009") + << QLatin1String("particlesT014") + << QLatin1String("particlesV001") + << QLatin1String("particlesV002") + << QLatin1String("particlesV020") + << QLatin1String("particlesZ001") + << QLatin1String("particlesZ005") + << QLatin1String("particlesZ007") + << QLatin1String("particlesZ023") + << QLatin1String("particlesZ024") + << QLatin1String("particlesZ026") + << QLatin1String("particlesZ028") + << QLatin1String("particlesZ033_c") + << QLatin1String("particlesZ033_d") + << QLatin1String("particlesZ033_e") + << QLatin1String("particlesZ033_f") + << QLatin1String("particlesZ033_g") + << QLatin1String("particlesZ034_a1") + << QLatin1String("particlesZ034_a2") + << QLatin1String("particlesZ034_a3") + << QLatin1String("particlesZ034_b") + << QLatin1String("particlesZ035_a") + << QLatin1String("particlesZ035_b") + << QLatin1String("particlesZ036_a") + << QLatin1String("particlesZ036_b1") + << QLatin1String("particlesZ036_b2") + << QLatin1String("particlesZ036_c") +/* + << QLatin1String("reC65") + << QLatin1String("reC66") + << QLatin1String("reC67") + << QLatin1String("reC68") + << QLatin1String("reF58") + << QLatin1String("reG50") + << QLatin1String("reJ11") + << QLatin1String("reJ13") + << QLatin1String("reJ19") + << QLatin1String("reJ21") + << QLatin1String("reJ23") + << QLatin1String("reJ25") + << QLatin1String("reJ29") + << QLatin1String("reJ31") + << QLatin1String("reJ33") + << QLatin1String("reJ35") + << QLatin1String("reJ61") + << QLatin1String("reJ69") + << QLatin1String("reJ75") + << QLatin1String("reJ77") + << QLatin1String("reL98") + << QLatin1String("reL99") + << QLatin1String("reM98") + << QLatin1String("reN99") + << QLatin1String("reS21") + << QLatin1String("reS42") + << QLatin1String("reT63") + << QLatin1String("reT84") + << QLatin1String("reDG2") + << QLatin1String("RegexTest_9") + << QLatin1String("RegexTest_11") + << QLatin1String("RegexTest_14") + << QLatin1String("RegexTest_15") + << QLatin1String("RegexTest_16") + << QLatin1String("RegexTest_17") + << QLatin1String("RegexTest_23") + << QLatin1String("RegexTest_24") + << QLatin1String("RegexTest_25") + << QLatin1String("RegexTest_26") + << QLatin1String("RegexTest_27") + << QLatin1String("RegexTest_28") + << QLatin1String("RegexTest_30") + << QLatin1String("RegexTest_30") + << QLatin1String("RegexTest_33") + << QLatin1String("RegexTest_34") + << QLatin1String("RegexTest_34") + << QLatin1String("RegexTest_43") + << QLatin1String("RegexTest_44") + << QLatin1String("RegexTest_45") + << QLatin1String("RegexTest_46") + << QLatin1String("RegexTest_47") + << QLatin1String("RegexTest_48") + << QLatin1String("RegexTest_49") + << QLatin1String("RegexTest_50") + << QLatin1String("RegexTest_51") + << QLatin1String("RegexTest_52") + << QLatin1String("RegexTest_53") + << QLatin1String("RegexTest_54") + << QLatin1String("RegexTest_55") + << QLatin1String("RegexTest_56") + << QLatin1String("RegexTest_57") + << QLatin1String("RegexTest_57") + << QLatin1String("RegexTest_58") + << QLatin1String("RegexTest_58") + << QLatin1String("RegexTest_65") + << QLatin1String("RegexTest_113") + << QLatin1String("RegexTest_116") + << QLatin1String("RegexTest_119") + << QLatin1String("RegexTest_120") + << QLatin1String("RegexTest_121") + << QLatin1String("RegexTest_141") + << QLatin1String("RegexTest_142") + << QLatin1String("RegexTest_143") + << QLatin1String("RegexTest_145") + << QLatin1String("RegexTest_146") + << QLatin1String("RegexTest_147") + << QLatin1String("RegexTest_148") + << QLatin1String("RegexTest_149") + << QLatin1String("RegexTest_150") + << QLatin1String("RegexTest_151") + << QLatin1String("RegexTest_152") + << QLatin1String("RegexTest_154") + << QLatin1String("RegexTest_155") + << QLatin1String("RegexTest_156") + << QLatin1String("RegexTest_157") + << QLatin1String("RegexTest_158") + << QLatin1String("RegexTest_163") + << QLatin1String("RegexTest_164") + << QLatin1String("RegexTest_165") + << QLatin1String("RegexTest_166") + << QLatin1String("RegexTest_167") + << QLatin1String("RegexTest_168") + << QLatin1String("RegexTest_169") + << QLatin1String("RegexTest_170") + << QLatin1String("RegexTest_171") + << QLatin1String("RegexTest_172") + << QLatin1String("RegexTest_173") + << QLatin1String("RegexTest_174") + << QLatin1String("RegexTest_178") + << QLatin1String("RegexTest_194") + << QLatin1String("RegexTest_194") + << QLatin1String("RegexTest_195") + << QLatin1String("RegexTest_195") + << QLatin1String("RegexTest_196") + << QLatin1String("RegexTest_196") + << QLatin1String("RegexTest_197") + << QLatin1String("RegexTest_198") + << QLatin1String("RegexTest_199") + << QLatin1String("RegexTest_200") + << QLatin1String("RegexTest_200") + << QLatin1String("RegexTest_201") + << QLatin1String("RegexTest_201") + << QLatin1String("RegexTest_202") + << QLatin1String("RegexTest_202") + << QLatin1String("RegexTest_203") + << QLatin1String("RegexTest_204") + << QLatin1String("RegexTest_205") + << QLatin1String("RegexTest_206") + << QLatin1String("RegexTest_207") + << QLatin1String("RegexTest_208") + << QLatin1String("RegexTest_209") + << QLatin1String("RegexTest_209") + << QLatin1String("RegexTest_210") + << QLatin1String("RegexTest_210") + << QLatin1String("RegexTest_211") + << QLatin1String("RegexTest_211") + << QLatin1String("RegexTest_212") + << QLatin1String("RegexTest_213") + << QLatin1String("RegexTest_214") + << QLatin1String("RegexTest_215") + << QLatin1String("RegexTest_216") + << QLatin1String("RegexTest_217") + << QLatin1String("RegexTest_218") + << QLatin1String("RegexTest_220") + << QLatin1String("RegexTest_221") + << QLatin1String("RegexTest_222") + << QLatin1String("RegexTest_226") + << QLatin1String("RegexTest_230") + << QLatin1String("RegexTest_232") + << QLatin1String("RegexTest_233") + << QLatin1String("RegexTest_294") + << QLatin1String("RegexTest_294") + << QLatin1String("RegexTest_295") + << QLatin1String("RegexTest_295") + << QLatin1String("RegexTest_299") + << QLatin1String("RegexTest_300") + << QLatin1String("RegexTest_301") + << QLatin1String("RegexTest_302") + << QLatin1String("RegexTest_303") + << QLatin1String("RegexTest_304") + << QLatin1String("RegexTest_305") + << QLatin1String("RegexTest_306") + << QLatin1String("RegexTest_307") + << QLatin1String("RegexTest_308") + << QLatin1String("RegexTest_309") + << QLatin1String("RegexTest_310") + << QLatin1String("RegexTest_311") + << QLatin1String("RegexTest_312") + << QLatin1String("RegexTest_313") + << QLatin1String("RegexTest_314") + << QLatin1String("RegexTest_315") + << QLatin1String("RegexTest_315") + << QLatin1String("RegexTest_316") + << QLatin1String("RegexTest_316") + << QLatin1String("RegexTest_317") + << QLatin1String("RegexTest_317") + << QLatin1String("RegexTest_440") + << QLatin1String("RegexTest_441") + << QLatin1String("RegexTest_442") + << QLatin1String("RegexTest_443") + << QLatin1String("RegexTest_448") + << QLatin1String("RegexTest_449") + << QLatin1String("RegexTest_450") + << QLatin1String("RegexTest_451") + << QLatin1String("RegexTest_458") + << QLatin1String("RegexTest_464") + << QLatin1String("RegexTest_464") + << QLatin1String("RegexTest_465") + << QLatin1String("RegexTest_469") + << QLatin1String("RegexTest_470") + << QLatin1String("RegexTest_471") + << QLatin1String("RegexTest_472") + << QLatin1String("RegexTest_473") + << QLatin1String("RegexTest_477") + << QLatin1String("RegexTest_478") + << QLatin1String("RegexTest_478") + << QLatin1String("RegexTest_479") + << QLatin1String("RegexTest_480") + << QLatin1String("RegexTest_481") + << QLatin1String("RegexTest_482") + << QLatin1String("RegexTest_482") + << QLatin1String("RegexTest_483") + << QLatin1String("RegexTest_483") + << QLatin1String("RegexTest_484") + << QLatin1String("RegexTest_487") + << QLatin1String("RegexTest_516") + << QLatin1String("RegexTest_516") + << QLatin1String("RegexTest_517") + << QLatin1String("RegexTest_517") + << QLatin1String("RegexTest_518") + << QLatin1String("RegexTest_518") + << QLatin1String("RegexTest_519") + << QLatin1String("RegexTest_519") + << QLatin1String("RegexTest_521") + << QLatin1String("RegexTest_523") + << QLatin1String("RegexTest_524") + << QLatin1String("RegexTest_524") + << QLatin1String("RegexTest_586") + << QLatin1String("RegexTest_587") + << QLatin1String("RegexTest_592") + << QLatin1String("RegexTest_593") + << QLatin1String("RegexTest_594") + << QLatin1String("RegexTest_595") + << QLatin1String("RegexTest_596") + << QLatin1String("RegexTest_597") + << QLatin1String("RegexTest_598") + << QLatin1String("RegexTest_599") + << QLatin1String("RegexTest_600") + << QLatin1String("RegexTest_601") + << QLatin1String("RegexTest_602") + << QLatin1String("RegexTest_603") + << QLatin1String("RegexTest_604") + << QLatin1String("RegexTest_605") + << QLatin1String("RegexTest_648") + << QLatin1String("RegexTest_655") + << QLatin1String("RegexTest_688") + << QLatin1String("RegexTest_696") + << QLatin1String("RegexTest_697") + << QLatin1String("RegexTest_698") + << QLatin1String("RegexTest_700") + << QLatin1String("RegexTest_701") + << QLatin1String("RegexTest_702") + << QLatin1String("RegexTest_703") + << QLatin1String("RegexTest_704") + << QLatin1String("RegexTest_705") + << QLatin1String("RegexTest_706") + << QLatin1String("RegexTest_707") + << QLatin1String("RegexTest_717") + << QLatin1String("RegexTest_718") + << QLatin1String("RegexTest_719") + << QLatin1String("RegexTest_724") + << QLatin1String("RegexTest_725") + << QLatin1String("RegexTest_726") + << QLatin1String("RegexTest_727") + << QLatin1String("RegexTest_728") + << QLatin1String("RegexTest_729") + << QLatin1String("RegexTest_730") + << QLatin1String("RegexTest_731") + << QLatin1String("RegexTest_732") + << QLatin1String("RegexTest_733") + << QLatin1String("RegexTest_743") + << QLatin1String("RegexTest_755") + << QLatin1String("RegexTest_756") + << QLatin1String("RegexTest_761") + << QLatin1String("RegexTest_762") + << QLatin1String("RegexTest_781") + << QLatin1String("RegexTest_782") + << QLatin1String("RegexTest_783") + << QLatin1String("RegexTest_790") + << QLatin1String("RegexTest_791") + << QLatin1String("RegexTest_824") + << QLatin1String("RegexTest_826") + << QLatin1String("RegexTest_827") + << QLatin1String("RegexTest_836") + << QLatin1String("RegexTest_837") + << QLatin1String("RegexTest_841") + << QLatin1String("RegexTest_842") + << QLatin1String("RegexTest_843") + << QLatin1String("RegexTest_844") + << QLatin1String("RegexTest_845") + << QLatin1String("RegexTest_846") + << QLatin1String("RegexTest_847") + << QLatin1String("RegexTest_848") + << QLatin1String("RegexTest_851") + << QLatin1String("RegexTest_852") + << QLatin1String("RegexTest_853") + << QLatin1String("RegexTest_854") + << QLatin1String("RegexTest_855") + << QLatin1String("RegexTest_856") + << QLatin1String("RegexTest_857") + << QLatin1String("RegexTest_861") + << QLatin1String("RegexTest_862") + << QLatin1String("RegexTest_863") + << QLatin1String("RegexTest_864") + << QLatin1String("RegexTest_865") + << QLatin1String("RegexTest_866") + << QLatin1String("RegexTest_870") + << QLatin1String("RegexTest_879") + << QLatin1String("RegexTest_880") + << QLatin1String("RegexTest_888") + << QLatin1String("RegexTest_889") + << QLatin1String("RegexTest_890") + << QLatin1String("RegexTest_891") + << QLatin1String("RegexTest_892") + << QLatin1String("RegexTest_893") + << QLatin1String("RegexTest_894") + << QLatin1String("RegexTest_895") + << QLatin1String("RegexTest_896") + << QLatin1String("RegexTest_897") + << QLatin1String("RegexTest_898") + << QLatin1String("RegexTest_899") + << QLatin1String("RegexTest_900") + << QLatin1String("RegexTest_901") + << QLatin1String("RegexTest_902") + << QLatin1String("RegexTest_903") + << QLatin1String("RegexTest_904") + << QLatin1String("RegexTest_905") + << QLatin1String("RegexTest_906") + << QLatin1String("RegexTest_907") + << QLatin1String("RegexTest_908") + << QLatin1String("RegexTest_909") + << QLatin1String("RegexTest_910") + << QLatin1String("RegexTest_911") + << QLatin1String("RegexTest_912") + << QLatin1String("RegexTest_913") + << QLatin1String("RegexTest_914") + << QLatin1String("RegexTest_915") + << QLatin1String("RegexTest_916") + << QLatin1String("RegexTest_917") + << QLatin1String("RegexTest_918") + << QLatin1String("RegexTest_919") + << QLatin1String("RegexTest_920") + << QLatin1String("RegexTest_921") + << QLatin1String("RegexTest_922") + << QLatin1String("RegexTest_923") + << QLatin1String("RegexTest_924") + << QLatin1String("RegexTest_925") + << QLatin1String("RegexTest_926") + << QLatin1String("RegexTest_928") + << QLatin1String("RegexTest_929") + << QLatin1String("RegexTest_930") + << QLatin1String("RegexTest_936") + << QLatin1String("RegexTest_937") + << QLatin1String("RegexTest_938") + << QLatin1String("RegexTest_939") + << QLatin1String("RegexTest_940") + << QLatin1String("RegexTest_941") + << QLatin1String("RegexTest_942") + << QLatin1String("RegexTest_943") + << QLatin1String("RegexTest_944") + << QLatin1String("RegexTest_945") + << QLatin1String("RegexTest_946") + << QLatin1String("RegexTest_949") + << QLatin1String("RegexTest_950") + << QLatin1String("RegexTest_951") + << QLatin1String("RegexTest_952") + << QLatin1String("RegexTest_953") + << QLatin1String("RegexTest_954") + << QLatin1String("RegexTest_955") + << QLatin1String("RegexTest_956") + << QLatin1String("RegexTest_957") + << QLatin1String("RegexTest_958") + << QLatin1String("RegexTest_959") + << QLatin1String("RegexTest_960") + << QLatin1String("RegexTest_961") + << QLatin1String("RegexTest_962") + << QLatin1String("RegexTest_963") + << QLatin1String("RegexTest_964") + << QLatin1String("RegexTest_976") + << QLatin1String("RegexTest_977") + << QLatin1String("RegexTest_988") + << QLatin1String("RegexTest_989") + << QLatin1String("RegexTest_990") + << QLatin1String("RegexTest_991") + << QLatin1String("RegexTest_994") + << QLatin1String("RegexTest_995") + << QLatin1String("RegexTest_996") + << QLatin1String("RegexTest_997") + << QLatin1String("RegexTest_1000") + << QLatin1String("RegexTest_1001") + << QLatin1String("RegexTest_1002") + << QLatin1String("RegexTest_1003") + << QLatin1String("RegexTest_1004") + << QLatin1String("RegexTest_1007") + << QLatin1String("RegexTest_1008") + << QLatin1String("RegexTest_1009") + << QLatin1String("RegexTest_1010") + << QLatin1String("RegexTest_1011") + << QLatin1String("RegexTest_1012") + << QLatin1String("RegexTest_1013") + << QLatin1String("RegexTest_1014") + << QLatin1String("RegexTest_1015") + << QLatin1String("RegexTest_1016") + << QLatin1String("RegexTest_1017") + << QLatin1String("RegexTest_1018") + << QLatin1String("RegexTest_1019") + << QLatin1String("RegexTest_1070") + << QLatin1String("RegexTest_1071") + << QLatin1String("RegexTest_1076") + << QLatin1String("RegexTest_1077") + << QLatin1String("RegexTest_1078") + << QLatin1String("RegexTest_1079") + << QLatin1String("RegexTest_1080") + << QLatin1String("RegexTest_1081") + << QLatin1String("RegexTest_1082") + << QLatin1String("RegexTest_1083") + << QLatin1String("RegexTest_1084") + << QLatin1String("RegexTest_1085") + << QLatin1String("RegexTest_1086") + << QLatin1String("RegexTest_1087") + << QLatin1String("RegexTest_1088") + << QLatin1String("RegexTest_1089") + << QLatin1String("RegexTest_1132") + << QLatin1String("RegexTest_1139") + << QLatin1String("RegexTest_1172") + << QLatin1String("RegexTest_1180") + << QLatin1String("RegexTest_1181") + << QLatin1String("RegexTest_1182") + << QLatin1String("RegexTest_1184") + << QLatin1String("RegexTest_1185") + << QLatin1String("RegexTest_1186") + << QLatin1String("RegexTest_1187") + << QLatin1String("RegexTest_1188") + << QLatin1String("RegexTest_1189") + << QLatin1String("RegexTest_1190") + << QLatin1String("RegexTest_1191") + << QLatin1String("RegexTest_1201") + << QLatin1String("RegexTest_1202") + << QLatin1String("RegexTest_1203") + << QLatin1String("RegexTest_1208") + << QLatin1String("RegexTest_1209") + << QLatin1String("RegexTest_1210") + << QLatin1String("RegexTest_1211") + << QLatin1String("RegexTest_1212") + << QLatin1String("RegexTest_1213") + << QLatin1String("RegexTest_1214") + << QLatin1String("RegexTest_1215") + << QLatin1String("RegexTest_1216") + << QLatin1String("RegexTest_1217") + << QLatin1String("RegexTest_1227") + << QLatin1String("RegexTest_1239") + << QLatin1String("RegexTest_1240") + << QLatin1String("RegexTest_1245") + << QLatin1String("RegexTest_1246") + << QLatin1String("RegexTest_1265") + << QLatin1String("RegexTest_1266") + << QLatin1String("RegexTest_1267") + << QLatin1String("RegexTest_1274") + << QLatin1String("RegexTest_1275") + << QLatin1String("RegexTest_1308") + << QLatin1String("RegexTest_1310") + << QLatin1String("RegexTest_1311") + << QLatin1String("RegexTest_1320") + << QLatin1String("RegexTest_1321") + << QLatin1String("RegexTest_1322") + << QLatin1String("RegexTest_1323") + << QLatin1String("RegexTest_1324") + << QLatin1String("RegexTest_1325") + << QLatin1String("RegexTest_1326") + << QLatin1String("RegexTest_1327") + << QLatin1String("RegexTest_1328") + << QLatin1String("RegexTest_1329") + << QLatin1String("RegexTest_1330") + << QLatin1String("RegexTest_1331") + << QLatin1String("RegexTest_1332") + << QLatin1String("RegexTest_1335") + << QLatin1String("RegexTest_1336") + << QLatin1String("RegexTest_1337") + << QLatin1String("RegexTest_1338") + << QLatin1String("RegexTest_1339") + << QLatin1String("RegexTest_1340") + << QLatin1String("RegexTest_1341") + << QLatin1String("RegexTest_1345") + << QLatin1String("RegexTest_1346") + << QLatin1String("RegexTest_1347") + << QLatin1String("RegexTest_1348") + << QLatin1String("RegexTest_1349") + << QLatin1String("RegexTest_1350") + << QLatin1String("RegexTest_1354") + << QLatin1String("RegexTest_1363") + << QLatin1String("RegexTest_1364") + << QLatin1String("RegexTest_1365") + << QLatin1String("RegexTest_1372") + << QLatin1String("RegexTest_1373") + << QLatin1String("RegexTest_1374") + << QLatin1String("RegexTest_1375") + << QLatin1String("RegexTest_1376") + << QLatin1String("RegexTest_1377") + << QLatin1String("RegexTest_1378") + << QLatin1String("RegexTest_1379") + << QLatin1String("RegexTest_1380") + << QLatin1String("RegexTest_1381") + << QLatin1String("RegexTest_1382") + << QLatin1String("RegexTest_1383") + << QLatin1String("RegexTest_1384") + << QLatin1String("RegexTest_1385") + << QLatin1String("RegexTest_1386") + << QLatin1String("RegexTest_1387") + << QLatin1String("RegexTest_1388") + << QLatin1String("RegexTest_1389") + << QLatin1String("RegexTest_1390") + << QLatin1String("RegexTest_1391") + << QLatin1String("RegexTest_1392") + << QLatin1String("RegexTest_1393") + << QLatin1String("RegexTest_1394") + << QLatin1String("RegexTest_1395") + << QLatin1String("RegexTest_1396") + << QLatin1String("RegexTest_1397") + << QLatin1String("RegexTest_1398") + << QLatin1String("RegexTest_1399") + << QLatin1String("RegexTest_1400") + << QLatin1String("RegexTest_1401") + << QLatin1String("RegexTest_1402") + << QLatin1String("RegexTest_1403") + << QLatin1String("RegexTest_1404") + << QLatin1String("RegexTest_1405") + << QLatin1String("RegexTest_1406") + << QLatin1String("RegexTest_1407") + << QLatin1String("RegexTest_1408") + << QLatin1String("RegexTest_1409") + << QLatin1String("RegexTest_1410") + << QLatin1String("RegexTest_1412") + << QLatin1String("RegexTest_1413") + << QLatin1String("RegexTest_1414") + << QLatin1String("RegexTest_1420") + << QLatin1String("RegexTest_1421") + << QLatin1String("RegexTest_1422") + << QLatin1String("RegexTest_1423") + << QLatin1String("RegexTest_1424") + << QLatin1String("RegexTest_1425") + << QLatin1String("RegexTest_1426") + << QLatin1String("RegexTest_1427") + << QLatin1String("RegexTest_1428") + << QLatin1String("RegexTest_1429") + << QLatin1String("RegexTest_1430") + << QLatin1String("RegexTest_1433") + << QLatin1String("RegexTest_1434") + << QLatin1String("RegexTest_1435") + << QLatin1String("RegexTest_1436") + << QLatin1String("RegexTest_1437") + << QLatin1String("RegexTest_1438") + << QLatin1String("RegexTest_1439") + << QLatin1String("RegexTest_1440") + << QLatin1String("RegexTest_1441") + << QLatin1String("RegexTest_1442") + << QLatin1String("RegexTest_1443") + << QLatin1String("RegexTest_1444") + << QLatin1String("RegexTest_1445") + << QLatin1String("RegexTest_1446") + << QLatin1String("RegexTest_1447") + << QLatin1String("RegexTest_1448") + << QLatin1String("RegexTest_1451") + << QLatin1String("RegexTest_1452") + << QLatin1String("RegexTest_1453") + << QLatin1String("RegexTest_1454") + << QLatin1String("RegexTest_1455") + << QLatin1String("RegexTest_1456") + << QLatin1String("RegexTest_1472") + << QLatin1String("RegexTest_1473") + << QLatin1String("RegexTest_1474") + << QLatin1String("RegexTest_1475") + << QLatin1String("RegexTest_1478") + << QLatin1String("RegexTest_1479") + << QLatin1String("RegexTest_1480") + << QLatin1String("RegexTest_1481") + << QLatin1String("RegexTest_1484") + << QLatin1String("RegexTest_1485") + << QLatin1String("RegexTest_1486") + << QLatin1String("RegexTest_1487") + << QLatin1String("RegexTest_1488") + << QLatin1String("RegexTest_1491") + << QLatin1String("RegexTest_1492") + << QLatin1String("RegexTest_1493") + << QLatin1String("RegexTest_1494") + << QLatin1String("RegexTest_1495") + << QLatin1String("RegexTest_1496") + << QLatin1String("RegexTest_1497") + << QLatin1String("RegexTest_1498") + << QLatin1String("RegexTest_1499") + << QLatin1String("RegexTest_1500") + << QLatin1String("RegexTest_1501") + << QLatin1String("RegexTest_1502") + << QLatin1String("RegexTest_1503") + << QLatin1String("RegexTest_1543") + << QLatin1String("RegexTest_1544") + << QLatin1String("reZ001") +*/ + << QLatin1String("schA2") + << QLatin1String("schA5") + << QLatin1String("schA7") + << QLatin1String("schD8") + << QLatin1String("schG3") + << QLatin1String("schG6") + << QLatin1String("schG9") + << QLatin1String("schG11") + << QLatin1String("schG12") + << QLatin1String("schU1") + << QLatin1String("schU3") + << QLatin1String("schU4") + << QLatin1String("schU5") + << QLatin1String("schZ004") + << QLatin1String("schZ005") + << QLatin1String("schZ012_a") + << QLatin1String("stZ041") + << QLatin1String("wildZ010"); +} + +bool XSDTestSuiteHandler::startElement(const QString &namespaceURI, + const QString &localName, + const QString &/*qName*/, + const QXmlAttributes &atts) +{ + if(namespaceURI != QString::fromLatin1("http://www.w3.org/XML/2004/xml-schema-test-suite/")) + return true; + + if (localName == QLatin1String("testSet")) { + m_currentTestSet = new TestGroup(m_topLevelGroup); + Q_ASSERT(m_currentTestSet); + m_currentTestSet->setTitle(atts.value("name")); + m_topLevelGroup->appendChild(m_currentTestSet); + } else if (localName == QLatin1String("testGroup")) { + m_currentTestGroup = new TestGroup(m_currentTestSet); + Q_ASSERT(m_currentTestGroup); + m_currentTestGroup->setTitle(atts.value("name")); + m_currentTestSet->appendChild(m_currentTestGroup); + m_inTestGroup = true; + } else if (localName == QLatin1String("schemaTest")) { + if (m_blackList.contains(atts.value("name"))) { + m_currentTestCase = 0; + m_schemaBlacklisted = true; + return true; + } + m_schemaBlacklisted = false; + + m_currentTestCase = new XSDTSTestCase(TestCase::Standard, m_currentTestGroup, XSDTSTestCase::SchemaTest); + Q_ASSERT(m_currentTestCase); + m_counter++; + m_currentTestCase->setName(QString::number(m_counter) + atts.value("name")); + m_currentTestGroup->appendChild(m_currentTestCase); + m_currentTestCase->setParent(m_currentTestGroup); + + m_inSchemaTest = true; + } else if (localName == QLatin1String("instanceTest")) { + if (m_schemaBlacklisted) { + m_currentTestCase = 0; + return true; + } + + m_currentTestCase = new XSDTSTestCase(TestCase::Standard, m_currentTestGroup, XSDTSTestCase::InstanceTest); + Q_ASSERT(m_currentTestCase); + m_counter++; + m_currentTestCase->setName(QString::number(m_counter) + atts.value("name")); + m_currentTestGroup->appendChild(m_currentTestCase); + + m_inInstanceTest = true; + } else if (localName == QLatin1String("schemaDocument") || localName == QLatin1String("instanceDocument")) { + if (m_inSchemaTest) { + m_currentTestCase->setSchemaUri(QUrl(atts.value("xlink:href"))); + if (m_currentSchemaLink.isEmpty()) // we only use the first schema document for validation + m_currentSchemaLink = atts.value("xlink:href"); + } + if (m_inInstanceTest) { + m_currentTestCase->setInstanceUri(QUrl(atts.value("xlink:href"))); + m_currentTestCase->setSchemaUri(QUrl(m_currentSchemaLink)); + } + } else if (localName == QLatin1String("expected") && (m_inSchemaTest || m_inInstanceTest)) { + TestBaseLine *baseLine = new TestBaseLine(TestBaseLine::SchemaIsValid); + if (atts.value("validity") == QLatin1String("valid")) { + baseLine->setDetails(QLatin1String("true")); + m_currentTestCase->setName(m_currentTestCase->name() + QLatin1String(" tokoe:valid")); + } else { + baseLine->setDetails(QLatin1String("false")); + m_currentTestCase->setName(m_currentTestCase->name() + QLatin1String(" tokoe:invalid")); + } + + m_currentTestCase->addBaseLine(baseLine); + } else if (localName == QLatin1String("documentation") && m_inTestGroup) { + m_inDescription = true; + } + + return true; +} + +bool XSDTestSuiteHandler::endElement(const QString &/*namespaceURI*/, + const QString &localName, + const QString &/*qName*/) +{ + if (localName == QLatin1String("testGroup")) { + m_inTestGroup = false; + m_currentTestGroup->setDescription(m_documentation); + m_documentation.clear(); + m_currentSchemaLink.clear(); + + if (m_currentTestGroup->childCount() == 0) + m_currentTestSet->removeLast(); + } else if (localName == QLatin1String("schemaTest")) + m_inSchemaTest = false; + else if (localName == QLatin1String("instanceTest")) + m_inInstanceTest = false; + else if (localName == QLatin1String("documentation")) + m_inDescription = false; + + return true; +} + +bool XSDTestSuiteHandler::characters(const QString &ch) +{ + if (m_inDescription) + m_documentation += ch; + + return true; +} + +TestSuite *XSDTestSuiteHandler::testSuite() const +{ + return m_ts; +} + +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.h b/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.h new file mode 100644 index 0000000..5493c7d --- /dev/null +++ b/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.h @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the autotests 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_XSDTestSuiteHandler_H +#define PatternistSDK_XSDTestSuiteHandler_H + +#include +#include + +#include "ExternalSourceLoader.h" +#include "TestSuite.h" +#include "XQTSTestCase.h" + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + class TestBaseLine; + class TestGroup; + class XSDTSTestCase; + + /** + * @short Creates a TestSuite from the XSD Test Suite. + * + * The created TestSuite can be retrieved via testSuite(). + * + * @note XSDTestSuiteHandler 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. + * + * @ingroup PatternistSDK + * @author Tobias Koenig + */ + class Q_PATTERNISTSDK_EXPORT XSDTestSuiteHandler : 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 + */ + XSDTestSuiteHandler(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: + TestSuite* m_ts; + const QUrl m_catalogFile; + + TestGroup* m_topLevelGroup; + TestGroup* m_currentTestSet; + TestGroup* m_currentTestGroup; + XSDTSTestCase* m_currentTestCase; + bool m_inSchemaTest; + bool m_inInstanceTest; + bool m_inTestGroup; + bool m_inDescription; + bool m_schemaBlacklisted; + QString m_documentation; + QString m_currentSchemaLink; + int m_counter; + QSet m_blackList; + }; +} + +QT_END_NAMESPACE +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp b/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp new file mode 100644 index 0000000..cfc3b2b --- /dev/null +++ b/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp @@ -0,0 +1,234 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#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 , so the 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/xmlpatternssdk/XSLTTestSuiteHandler.h b/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.h new file mode 100644 index 0000000..8614789 --- /dev/null +++ b/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.h @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_XSLTTestSuiteHandler_H +#define PatternistSDK_XSLTTestSuiteHandler_H + +#include +#include +#include + +#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 + */ + 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 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 input-file/\@variable. + */ + QString m_currentInputVariable; + + /** + * The names of the test groups. + */ + QStack m_testGroupName; + + /** + * Holds the content of the current input-URI 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/xmlpatternssdk/docs/XMLIndenterExample.cpp b/tests/auto/xmlpatternssdk/docs/XMLIndenterExample.cpp new file mode 100644 index 0000000..24ee158 --- /dev/null +++ b/tests/auto/xmlpatternssdk/docs/XMLIndenterExample.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@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/xmlpatternssdk/docs/XMLIndenterExampleResult.xml b/tests/auto/xmlpatternssdk/docs/XMLIndenterExampleResult.xml new file mode 100644 index 0000000..c5e7312 --- /dev/null +++ b/tests/auto/xmlpatternssdk/docs/XMLIndenterExampleResult.xml @@ -0,0 +1,3 @@ + + +

Hello World!

diff --git a/tests/auto/xmlpatternssdk/docs/XMLWriterExample.cpp b/tests/auto/xmlpatternssdk/docs/XMLWriterExample.cpp new file mode 100644 index 0000000..24ee158 --- /dev/null +++ b/tests/auto/xmlpatternssdk/docs/XMLWriterExample.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@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/xmlpatternssdk/docs/XMLWriterExampleResult.xml b/tests/auto/xmlpatternssdk/docs/XMLWriterExampleResult.xml new file mode 100644 index 0000000..c5e7312 --- /dev/null +++ b/tests/auto/xmlpatternssdk/docs/XMLWriterExampleResult.xml @@ -0,0 +1,3 @@ + + +

Hello World!

diff --git a/tests/auto/xmlpatternssdk/tests/XMLWriterTest.cpp b/tests/auto/xmlpatternssdk/tests/XMLWriterTest.cpp new file mode 100644 index 0000000..a10c01a --- /dev/null +++ b/tests/auto/xmlpatternssdk/tests/XMLWriterTest.cpp @@ -0,0 +1,186 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#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("input"); + QTest::addColumn("expectedResult"); + + /* ------------------- Elements ------------------- */ + QTest::newRow("Only an document element") + << "" + << "\n"; + + QTest::newRow("Document element containing a short closed element") + << "" + << "\n"; + QTest::newRow("Complex nested elements") + << "" + << "\n"; + /* ------------------------------------------------- */ + + /* ---------------- Element Content ---------------- */ + QTest::newRow("Element content with simple content") + << "content" + << "\ncontent"; + + QTest::newRow("Element content with tricky to escape content") + << ">>&'\"''/>" + << "\n>>&'\"''/>"; + /* ------------------------------------------------- */ + + /* ----------- Processing Instructions ------------- */ + QTest::newRow("Simple processing instruction.") + << "" + << "\n"; + /* ------------------------------------------------- */ + + /* --------------- 'xml' attributes ---------------- */ + QTest::newRow("Simple xml:space attribute.") + << "content" + << "\ncontent"; + + QTest::newRow("Many 'xml' attributes.") + << "content" + << "\n" + "content"; + /* ------------------------------------------------- */ + + /* ------------ namespace declarations ------------- */ + QTest::newRow("One simple namespace declaration.") + << "" + << "\n" + ""; + + QTest::newRow("Two simple namespace declarations.") + << "" + << "\n" + ""; + + QTest::newRow("A simple default namespace.") + << "" + << "\n" + ""; + /* ------------------------------------------------- */ + + /* -------- namespace declarations in use ---------- */ + QTest::newRow("Simple use of a namespace declaration.") + << "" + << "\n" + ""; + /* ------------------------------------------------- */ +} + +void XMLWriterTest::cdata() +{ + /* + QTest::newRow("Simple CDATA") + << "" + << "\n"; + + QTest::newRow("Complex CDATA") + << ">&'\";&987;]]>" + << "\n>&'\";&123;]]>"; + */ +} + +void XMLWriterTest::comments() +{ + /* + QTest::newRow("Simple comment") + << "" + << "\n"; + QTest::newRow("Comment") + << "" + << "\n"; + */ +} + +void XMLWriterTest::doxygenExample() +{ +#include "../docs/XMLWriterExample.cpp" + + /* When changing, remember to update the Doxygen in XMLWriter.h */ + const QByteArray expectedResult( + "\n" + "\n" + "

Hello World!

" + ); + + QCOMPARE(QString::fromLatin1(result), QString::fromLatin1(expectedResult)); +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/tests/XMLWriterTest.h b/tests/auto/xmlpatternssdk/tests/XMLWriterTest.h new file mode 100644 index 0000000..f90aea2 --- /dev/null +++ b/tests/auto/xmlpatternssdk/tests/XMLWriterTest.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PatternistSDK_XMLWriterTest_H +#define PatternistSDK_XMLWriterTest_H + +#include + +QT_BEGIN_HEADER + +namespace QPatternistSDK +{ + /** + * @short QTestLib test for XMLWriter. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + 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 diff --git a/tests/auto/xmlpatternssdk/xmlpatternssdk.pro b/tests/auto/xmlpatternssdk/xmlpatternssdk.pro new file mode 100644 index 0000000..6204f01 --- /dev/null +++ b/tests/auto/xmlpatternssdk/xmlpatternssdk.pro @@ -0,0 +1,88 @@ +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 +} + +symbian { + TARGET.EPOCALLOWDLLDATA=1 + TARGET.CAPABILITY = All -Tcb + MMP_RULES += EXPORTUNFROZEN +} + +# 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 \ + XSDTestSuiteHandler.h \ + XSDTSTestCase.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 \ + XSDTestSuiteHandler.cpp \ + XSDTSTestCase.cpp \ + XSLTTestSuiteHandler.cpp diff --git a/tests/auto/xmlpatternsview/test/test.pro b/tests/auto/xmlpatternsview/test/test.pro deleted file mode 100644 index 6adff4d..0000000 --- a/tests/auto/xmlpatternsview/test/test.pro +++ /dev/null @@ -1,17 +0,0 @@ -load(qttest_p4) -SOURCES += tst_xmlpatternsview.cpp - -include (../../xmlpatterns.pri) - -DESTDIR = .. -win32 { - CONFIG(debug, debug|release): DESTDIR = ../debug - else: DESTDIR = ../release -} -TARGET = tst_xmlpatternsview - -wince*: { - viewexe.sources = $$QT_BUILD_TREE/xmlpatternsview.exe - viewexe.path = . - DEPLOYMENT += viewexe -} diff --git a/tests/auto/xmlpatternsview/test/tst_xmlpatternsview.cpp b/tests/auto/xmlpatternsview/test/tst_xmlpatternsview.cpp deleted file mode 100644 index 91dee63..0000000 --- a/tests/auto/xmlpatternsview/test/tst_xmlpatternsview.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include - -#ifdef QTEST_XMLPATTERNS - -/*! - \class tst_XmlPatternsView - \internal - \since 4.5 - \brief This test tests nothing, it only exists in order to have a place - for the xmlpatternsview utility. - - tests/auto/xmlpatternsview doesn't test anything, it only exists to house the - xmlpatternsview debugging utility inside the Qt directory. - */ -class tst_XmlPatternsView : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - void run() const; -}; - -void tst_XmlPatternsView::run() const -{ -} - -QTEST_MAIN(tst_XmlPatternsView) - -#include "tst_xmlpatternsview.moc" -#else //QTEST_XMLPATTERNS -QTEST_NOOP_MAIN -#endif diff --git a/tests/auto/xmlpatternsview/tst_xmlpatternsview.cpp b/tests/auto/xmlpatternsview/tst_xmlpatternsview.cpp new file mode 100644 index 0000000..91dee63 --- /dev/null +++ b/tests/auto/xmlpatternsview/tst_xmlpatternsview.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include + +#ifdef QTEST_XMLPATTERNS + +/*! + \class tst_XmlPatternsView + \internal + \since 4.5 + \brief This test tests nothing, it only exists in order to have a place + for the xmlpatternsview utility. + + tests/auto/xmlpatternsview doesn't test anything, it only exists to house the + xmlpatternsview debugging utility inside the Qt directory. + */ +class tst_XmlPatternsView : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void run() const; +}; + +void tst_XmlPatternsView::run() const +{ +} + +QTEST_MAIN(tst_XmlPatternsView) + +#include "tst_xmlpatternsview.moc" +#else //QTEST_XMLPATTERNS +QTEST_NOOP_MAIN +#endif diff --git a/tests/auto/xmlpatternsview/xmlpatternsview.pro b/tests/auto/xmlpatternsview/xmlpatternsview.pro index 04ee4d0..d93cba3 100644 --- a/tests/auto/xmlpatternsview/xmlpatternsview.pro +++ b/tests/auto/xmlpatternsview/xmlpatternsview.pro @@ -1,9 +1,12 @@ -TEMPLATE = subdirs -CONFIG += ordered +load(qttest_p4) +SOURCES += tst_xmlpatternsview.cpp -SUBDIRS = ../xmlpatternsxqts test +include (../xmlpatterns.pri) -contains(QT_CONFIG,xmlpatterns) { - SUBDIRS += view +TARGET = tst_xmlpatternsview + +wince*: { + viewexe.sources = $$QT_BUILD_TREE/xmlpatternsview.exe + viewexe.path = . + DEPLOYMENT += viewexe } -requires(contains(QT_CONFIG,private_tests)) diff --git a/tests/auto/xmlpatternsxqts/lib/ASTItem.cpp b/tests/auto/xmlpatternsxqts/lib/ASTItem.cpp deleted file mode 100644 index 3b4fbdc..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ASTItem.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include - -#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(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(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 deleted file mode 100644 index ca3ac8f..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ASTItem.h +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_ASTItem_H -#define PatternistSDK_ASTItem_H - -#include -#include - -#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 - */ - 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 1 eq number() 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 deleted file mode 100644 index 1b5121e..0000000 --- a/tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include - -#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(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 deleted file mode 100644 index d5e676d..0000000 --- a/tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.h +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@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 - */ - class Q_PATTERNISTSDK_EXPORT DebugExpressionFactory : public QPatternist::ExpressionFactory - { - public: - DebugExpressionFactory() : m_ast(0) - { - } - - typedef QExplicitlySharedDataPointer 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 deleted file mode 100644 index 3f07737..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ErrorHandler.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include - -#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("

") + QPatternist::escape(QLatin1String(description)) + QLatin1String("

")); -} - -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 deleted file mode 100644 index 25447a9..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ErrorHandler.h +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@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 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 - */ - class Q_PATTERNISTSDK_EXPORT ErrorHandler : public QAbstractMessageHandler - { - public: - class Message - { - public: - typedef QList 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 deleted file mode 100644 index 57edc1f..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ErrorItem.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include - -#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 deleted file mode 100644 index 1d05872..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ErrorItem.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_ErrorItem_H -#define PatternistSDK_ErrorItem_H - -#include - -#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 - */ - 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 deleted file mode 100644 index e1810b1..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ExitCode.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@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 - */ - 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 deleted file mode 100644 index abbc8b3..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ExpressionInfo.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include "ExpressionInfo.h" - -using namespace QPatternistSDK; - -ExpressionInfo::ExpressionInfo(const QString &name, - const QString &details) : QPair(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 deleted file mode 100644 index 2d9d398..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ExpressionInfo.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_ExpressionInfo_H -#define PatternistSDK_ExpressionInfo_H - -#include "Global.h" -#include "qexpressiondispatch_p.h" - -#include -#include - -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 - */ - class Q_PATTERNISTSDK_EXPORT ExpressionInfo : public QPatternist::ExpressionVisitorResult - , public QPair - { - 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 deleted file mode 100644 index 605c754..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ExpressionNamer.cpp +++ /dev/null @@ -1,316 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#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 *i) const -{ - return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("EvaluationCache"), - QLatin1String("Slot: ") + QString::number(i->slot()))); - -} - -QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::EvaluationCache *i) const -{ - return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("EvaluationCache"), - 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 deleted file mode 100644 index 129d8d7..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ExpressionNamer.h +++ /dev/null @@ -1,281 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@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 - */ - 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 *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::EvaluationCache *) 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 deleted file mode 100644 index a83a100..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include - -#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 deleted file mode 100644 index 2d88222..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.h +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_ExternalSourceLoader_H -#define PatternistSDK_ExternalSourceLoader_H - -#include -#include -#include - -#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 $input-context, - * by loading appropriate XML source files. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - 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 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 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 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 deleted file mode 100644 index f78e421..0000000 --- a/tests/auto/xmlpatternsxqts/lib/Global.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#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 deleted file mode 100644 index 53c32cb..0000000 --- a/tests/auto/xmlpatternsxqts/lib/Global.h +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_Global_H -#define PatternistSDK_Global_H - -#include - -#include "private/qitem_p.h" -#include "private/qnamepool_p.h" - -#if defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN) -# 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
XML Query Test Suite - * @author Frans Englich - */ -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - /** - * @short Contains global constants. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT Global - { - public: - - /** - * The namespace which the XQTS test case catalog(specified by Catalog.xsd) - * is in. The namespace is: http://www.w3.org/2005/02/query-test-XQTSCatalog - */ - static const QString xqtsCatalogNS; - - /** - * The namespace which the XQTS test results collection(specified by XQTSResult.xsd) - * is in. The namespace is: http://www.w3.org/2005/02/query-test-XQTSResult - */ - 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 deleted file mode 100644 index 3296854..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ResultThreader.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#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 deleted file mode 100644 index 19749f0..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ResultThreader.h +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_ResultThreader_H -#define PatternistSDK_ResultThreader_H - -#include -#include -#include - -#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 - * @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 deleted file mode 100644 index 6a46bcc..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestBaseLine.cpp +++ /dev/null @@ -1,511 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#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 SchemaIsValid: /* 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(n1).data() == - static_cast(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 SchemaIsValid: - /* Fall through. */ - 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("") + - serializedInput + - QLatin1String("")).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("") + - details() + - QLatin1String("")).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"); - case SchemaIsValid: - return QLatin1String("SchemaIsValid"); - } - - 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_type == SchemaIsValid) /* We're a schema validation information . */ - 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 deleted file mode 100644 index e297128..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestBaseLine.h +++ /dev/null @@ -1,212 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestBaseLine_H -#define PatternistSDK_TestBaseLine_H - -#include - -#include "Global.h" -#include "TestResult.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QDomNamedNodeMap; -class QDomNode; -class QDomNodeList; -template 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 - */ - class Q_PATTERNISTSDK_EXPORT TestBaseLine - { - public: - typedef QList List; - - /** - * Identifies what kind of comparator to use. The documentation - * for each enumerator is copied from - * Guidelines - * for Running the XML Query Test Suite - */ - 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, - - /** - * A special comparison for the schema validation tests. The details - * can only be 'true' or 'false' depending on whether it is a valid - * schema or not. - */ - SchemaIsValid - }; - - /** - * 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 deleted file mode 100644 index 7b424d2..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestCase.cpp +++ /dev/null @@ -1,439 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -#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(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 -{ - /* */ - 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); - - /* */ - receiver.startElement(QLatin1String("description"), test_caseAtts); - receiver.characters(description()); - - /* */ - receiver.endElement(QLatin1String("description")); - - /* */ - 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); - - /* */ - 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); - - /* */ - 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 deleted file mode 100644 index 28df5f1..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestCase.h +++ /dev/null @@ -1,256 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestCase_H -#define PatternistSDK_TestCase_H - -#include - -#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 - */ - 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 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 deleted file mode 100644 index ec6196c..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestContainer.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -#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(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(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 deleted file mode 100644 index 5b93491..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestContainer.h +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@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 - */ - 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 deleted file mode 100644 index f2cd2bd..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestGroup.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include - -#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 && role != Qt::ToolTipRole) - 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(); - } - } - case Qt::ToolTipRole: - { - return description(); - } - 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 deleted file mode 100644 index 5f4798f..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestGroup.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestGroup_H -#define PatternistSDK_TestGroup_H - -#include - -#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 - */ - 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 ¬e); - - 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 deleted file mode 100644 index 0b3c606..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestItem.h +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@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 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 - */ - 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 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 deleted file mode 100644 index 2374bc0..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestResult.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -#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 deleted file mode 100644 index 6951f90..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestResult.h +++ /dev/null @@ -1,179 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestResult_H -#define PatternistSDK_TestResult_H - -#include -#include -#include -#include - -#include -#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 - */ - 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 > 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 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 deleted file mode 100644 index b87d481..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestResultHandler.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#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 deleted file mode 100644 index a786ac4..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestResultHandler.h +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestResultHandler_H -#define PatternistSDK_TestResultHandler_H - -#include -#include -#include - -#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 - * @ingroup PatternistSDK - */ - class Q_PATTERNISTSDK_EXPORT TestResultHandler : public QXmlDefaultHandler - { - public: - /** - * A hash where the key is the class's name, that is test-case/@@name, - * and the value the test's result status. - */ - typedef QHash Hash; - - /** - * A hash mapping test-case names to their' comments. - */ - typedef QHash CommentHash; - - /** - * Creates a TestResultHandler that will read @p file when run() is called. - */ - TestResultHandler(); - - /** - * Performs finalization. - */ - virtual bool endDocument(); - - /** - * Reads the test-case 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 deleted file mode 100644 index 2c3e49c..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestSuite.cpp +++ /dev/null @@ -1,269 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include - -#include "Global.h" -#include "TestSuiteHandler.h" -#include "TestSuiteResult.h" -#include "XMLWriter.h" -#include "XSLTTestSuiteHandler.h" -#include "XSDTestSuiteHandler.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, - SuiteType suiteType) -{ - 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, suiteType); -} - -TestSuite *TestSuite::openCatalog(QIODevice *input, - QString &errorMsg, - const QUrl &fileName, - const bool useExclusionList, - SuiteType suiteType) -{ - Q_ASSERT(input); - - QXmlSimpleReader reader; - typedef QPatternist::AutoPtr HandlerPtr; - - HandlerPtr loader; - - switch (suiteType) { - case XQuerySuite: loader = HandlerPtr(new TestSuiteHandler(fileName, useExclusionList)); break; - case XsltSuite: loader = HandlerPtr(new XSLTTestSuiteHandler(fileName)); break; - case XsdSuite: loader = HandlerPtr(new XSDTestSuiteHandler(fileName)); break; - default: Q_ASSERT(false); break; - } - - reader.setContentHandler(loader.data()); - - QXmlInputSource source(input); - - if(!reader.parse(source)) - { - errorMsg = QString::fromLatin1("Couldn't parse %1").arg(fileName.toString()); - return 0; - } - - TestSuite *suite = 0; - switch (suiteType) { - case XQuerySuite: suite = static_cast(loader.data())->testSuite(); break; - case XsltSuite: suite = static_cast(loader.data())->testSuite(); break; - case XsdSuite: suite = static_cast(loader.data())->testSuite(); break; - default: Q_ASSERT(false); break; - } - - 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(); - /* */ - 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()); - - /* */ - QXmlAttributes test_groupAtts; - test_groupAtts.append(QLatin1String("GeneratedGroupByPatternistSDKRunSuite"), QString(), - QLatin1String("GeneratedGroupByPatternistSDKRunSuite"), QString()); - receiver.startElement(QLatin1String("test-group"), test_groupAtts); - - /* */ - receiver.startElement(QLatin1String("GroupInfo"), test_groupAtts); - - /* */ - receiver.startElement(QLatin1String("title"), test_groupAtts); - receiver.characters(QLatin1String("Contains the test case generated by PatternistSDKRunSuite.")); - - /* */ - receiver.endElement(QLatin1String("title")); - - /* */ - receiver.startElement(QLatin1String("description"), test_groupAtts); - /* */ - receiver.endElement(QLatin1String("description")); - - /* */ - receiver.endElement(QLatin1String("GroupInfo")); - - /* */ - tc->toXML(receiver); - /* */ - - /* */ - receiver.endElement(QLatin1String("test-group")); - - /* */ - 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 deleted file mode 100644 index d14dc62..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestSuite.h +++ /dev/null @@ -1,160 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestSuite_H -#define PatternistSDK_TestSuite_H - -#include -#include - -#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 - */ - class Q_PATTERNISTSDK_EXPORT TestSuite : public TestContainer - { - public: - /** - * Describes the type of test suite. - */ - enum SuiteType - { - XQuerySuite, ///< The test suite for XQuery - XsltSuite, ///< The test suite for XSLT - XsdSuite ///< The test suite for XML Schema - }; - - 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, - SuiteType type); - - 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, - SuiteType type); - 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 deleted file mode 100644 index 7c687f3..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.cpp +++ /dev/null @@ -1,312 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#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 , so the 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(m_container->parent()); - Q_ASSERT(m_container); - } - else if(localName == QLatin1String("test-suite")) - { - Q_ASSERT(m_container); - m_container = static_cast(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 deleted file mode 100644 index 76156c0..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.h +++ /dev/null @@ -1,169 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestSuiteHandler_H -#define PatternistSDK_TestSuiteHandler_H - -#include -#include -#include - -#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 - */ - 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 input-file/\@variable/. - */ - 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 m_testGroupName; - - /** - * Holds the content of the current input-URI 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 deleted file mode 100644 index 4e81859..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestSuiteResult.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#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("frans.englich@nokia.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: - * - - * - - * - - */ - - receiver.startDocument(); - /* */ - receiver.startPrefixMapping(QString(), Global::xqtsResultNS); - receiver.startElement(QLatin1String("test-suite-result")); - receiver.endPrefixMapping(QString()); - - /* */ - QXmlAttributes implementationAtts; - implementationAtts.append(QLatin1String("name"), QString(), - QLatin1String("name"), implementationName); - implementationAtts.append(QLatin1String("version"), QString(), - QLatin1String("version"), implementationVersion); - receiver.startElement(QLatin1String("implementation"), implementationAtts); - - /* */ - QXmlAttributes organizationAtts; - organizationAtts.append(QLatin1String("name"), QString(), - QLatin1String("name"), organizationName); - organizationAtts.append(QLatin1String("website"), QString(), - QLatin1String("website"), organizationWebsite); - receiver.startElement(QLatin1String("organization"), organizationAtts); - - /* */ - receiver.endElement(QLatin1String("organization")); - - /* */ - QXmlAttributes submittorAtts; - submittorAtts.append(QLatin1String("name"), QString(), QLatin1String("name"), submittorName); - submittorAtts.append(QLatin1String("email"), QString(), QLatin1String("email"), submittorEmail); - receiver.startElement(QLatin1String("submittor"), submittorAtts); - - /* */ - receiver.endElement(QLatin1String("submittor")); - - /* */ - receiver.startElement(QLatin1String("description")); - - /*

*/ - receiver.startElement(QLatin1String("p")); - receiver.characters(implementationDescription); - - /*

*/ - receiver.endElement(QLatin1String("p")); - /*
*/ - receiver.endElement(QLatin1String("description")); - - /*
*/ - receiver.endElement(QLatin1String("implementation")); - - /* */ - receiver.startElement(QLatin1String("syntax")); - receiver.characters(QLatin1String(QLatin1String("XQuery"))); - - /* */ - receiver.endElement(QLatin1String("syntax")); - - /* */ - 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); - - /* */ - QXmlAttributes test_suiteAtts; - test_suiteAtts.append(QLatin1String("version"), QString(), QLatin1String("version"), m_testSuiteVersion); - receiver.startElement(QLatin1String("test-suite"), test_suiteAtts); - - /* */ - receiver.endElement(QLatin1String("test-suite")); - - /* */ - 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); - - /*
*/ - 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 deleted file mode 100644 index 491c2b2..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestSuiteResult.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestSuiteResult_H -#define PatternistSDK_TestSuiteResult_H - -#include -#include - -#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 - */ - 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 deleted file mode 100644 index b34262d..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TreeItem.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@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(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 deleted file mode 100644 index f5e051f..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TreeItem.h +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TreeItem_H -#define PatternistSDK_TreeItem_H - -#include - -#include "Global.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QVariant; -template class QList; -template 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 - * @see TreeModel - * @ingroup PatternistSDK - */ - class Q_PATTERNISTSDK_EXPORT TreeItem : public QObject - { - Q_OBJECT - public: - typedef QList > 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 deleted file mode 100644 index e27f8e0..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TreeModel.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#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(idx.internalPointer()); - Q_ASSERT(item); - - return item->data(static_cast(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 *item) -{ - if (item) { - const QModelIndex index = createIndex(item->row(), 0, item); - dataChanged(index, index); - } else { - 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(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(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(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(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 deleted file mode 100644 index 1d8ea72..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TreeModel.h +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TreeModel_H -#define PatternistSDK_TreeModel_H - -#include -#include -#include -#include - -#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 - */ - 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 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 deleted file mode 100644 index 0121099..0000000 --- a/tests/auto/xmlpatternsxqts/lib/Worker.cpp +++ /dev/null @@ -1,258 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include - -#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(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 Info; - typedef QList 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(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 deleted file mode 100644 index b3d7ae2..0000000 --- a/tests/auto/xmlpatternsxqts/lib/Worker.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_Worker_H -#define PatternistSDK_Worker_H - -#include -#include -#include -#include - -#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 - * @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 deleted file mode 100644 index 60a5344..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XMLWriter.cpp +++ /dev/null @@ -1,669 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -#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 NSBinding; -typedef QList 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::const_iterator end(namespaceTracker.constEnd()); - QStack::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("&"); - else if(c == QLatin1Char(QLatin1Char('<'))) - retval += QLatin1String("<"); - 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("&"); - else if(c == QLatin1Char('<')) - retval += QLatin1String("<"); - else if(c == QLatin1Char('"')) - retval += QLatin1String("""); - 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(">"); - 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 hasContentStack; - QString errorString; - DEBUG_CODE(QStack tags;) - DEBUG_CODE(QStack 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 do {} while (false) - -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("\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("'); - } - 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("")); - 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 "")); - - 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("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("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 deleted file mode 100644 index 2b629bb..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XMLWriter.h +++ /dev/null @@ -1,403 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_XMLWriter_H -#define PatternistSDK_XMLWriter_H - -#include "Global.h" - -#include -#include - -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 xmlns:* to startElement(). - * - * @see HOWTO Avoid Being - * Called a Bozo When Producing XML - * @see Extensible Markup - * Language (XML) 1.0 (Third Edition) - * @see Namespaces in XML - * @todo Replace this class with QXmlStreamWriter - * @author Frans Englich - * @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 xmlns:* 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 - -@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 "" 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 deleted file mode 100644 index 6a8645b..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XQTSTestCase.cpp +++ /dev/null @@ -1,286 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include - -#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 deleted file mode 100644 index 8872b32..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XQTSTestCase.h +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_XQTSTestCase_H -#define PatternistSDK_XQTSTestCase_H - -#include -#include -#include - -#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 - */ - 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/XSDTSTestCase.cpp b/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.cpp deleted file mode 100644 index 3cbb681..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.cpp +++ /dev/null @@ -1,375 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the autotests 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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include - -#include "XSDTSTestCase.h" - -#include "qxmlschema.h" -#include "qxmlschemavalidator.h" - -using namespace QPatternistSDK; -using namespace QPatternist; - -XSDTSTestCase::XSDTSTestCase(const Scenario scen, TreeItem *p, TestType testType) - : m_scenario(scen) - , m_parent(p) - , m_testType(testType) -{ -} - -XSDTSTestCase::~XSDTSTestCase() -{ - qDeleteAll(m_baseLines); -} - -TestResult::List XSDTSTestCase::execute(const ExecutionStage, TestSuite*) -{ - ErrorHandler errHandler; - ErrorHandler::installQtMessageHandler(&errHandler); - - TestResult::List retval; - TestResult::Status resultStatus = TestResult::Unknown; - QString serialized; - - if (m_testType == SchemaTest) { - executeSchemaTest(resultStatus, serialized, &errHandler); - } else { - executeInstanceTest(resultStatus, serialized, &errHandler); - } - - resultStatus = TestBaseLine::scan(serialized, baseLines()); - Q_ASSERT(resultStatus != TestResult::Unknown); - - m_result = new TestResult(name(), resultStatus, 0, errHandler.messages(), - QPatternist::Item::List(), serialized); - retval.append(m_result); - ErrorHandler::installQtMessageHandler(0); - changed(this); - return retval; -} - -void XSDTSTestCase::executeSchemaTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler) -{ - QFile file(m_schemaUri.path()); - if (!file.open(QIODevice::ReadOnly)) { - resultStatus = TestResult::Fail; - serialized = QString(); - return; - } - - QXmlSchema schema; - schema.setMessageHandler(handler); - schema.load(&file, m_schemaUri); - - if (schema.isValid()) { - resultStatus = TestResult::Pass; - serialized = QString::fromLatin1("true"); - } else { - resultStatus = TestResult::Pass; - serialized = QString::fromLatin1("false"); - } -} - -void XSDTSTestCase::executeInstanceTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler) -{ - QFile instanceFile(m_instanceUri.path()); - if (!instanceFile.open(QIODevice::ReadOnly)) { - resultStatus = TestResult::Fail; - serialized = QString(); - return; - } - - QXmlSchema schema; - if (m_schemaUri.isValid()) { - QFile file(m_schemaUri.path()); - if (!file.open(QIODevice::ReadOnly)) { - resultStatus = TestResult::Fail; - serialized = QString(); - return; - } - - schema.setMessageHandler(handler); - schema.load(&file, m_schemaUri); - - if (!schema.isValid()) { - resultStatus = TestResult::Pass; - serialized = QString::fromLatin1("false"); - return; - } - } - - QXmlSchemaValidator validator(schema); - validator.setMessageHandler(handler); - - qDebug("check %s", qPrintable(m_instanceUri.path())); - if (validator.validate(&instanceFile, m_instanceUri)) { - resultStatus = TestResult::Pass; - serialized = QString::fromLatin1("true"); - } else { - resultStatus = TestResult::Pass; - serialized = QString::fromLatin1("false"); - } -} - -QVariant XSDTSTestCase::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 XSDTSTestCase::sourceCode(bool &ok) const -{ - QFile file((m_testType == SchemaTest ? m_schemaUri : m_instanceUri).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 XSDTSTestCase::columnCount() const -{ - return 2; -} - -void XSDTSTestCase::addBaseLine(TestBaseLine *line) -{ - m_baseLines.append(line); -} - -QString XSDTSTestCase::name() const -{ - return m_name; -} - -QString XSDTSTestCase::creator() const -{ - return m_creator; -} - -QString XSDTSTestCase::description() const -{ - return m_description; -} - -QDate XSDTSTestCase::lastModified() const -{ - return m_lastModified; -} - -bool XSDTSTestCase::isXPath() const -{ - return false; -} - -TestCase::Scenario XSDTSTestCase::scenario() const -{ - return m_scenario; -} - -void XSDTSTestCase::setName(const QString &n) -{ - m_name = n; -} - -void XSDTSTestCase::setCreator(const QString &ctor) -{ - m_creator = ctor; -} - -void XSDTSTestCase::setDescription(const QString &descriptionP) -{ - m_description = descriptionP; -} - -void XSDTSTestCase::setLastModified(const QDate &date) -{ - m_lastModified = date; -} - -void XSDTSTestCase::setSchemaUri(const QUrl &uri) -{ - m_schemaUri = uri; -} - -void XSDTSTestCase::setInstanceUri(const QUrl &uri) -{ - m_instanceUri = uri; -} - -TreeItem *XSDTSTestCase::parent() const -{ - return m_parent; -} - -QString XSDTSTestCase::title() const -{ - return m_name; -} - -TestBaseLine::List XSDTSTestCase::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 XSDTSTestCase::schemaUri() const -{ - return m_schemaUri; -} - -QUrl XSDTSTestCase::instanceUri() const -{ - return m_instanceUri; -} - -void XSDTSTestCase::setContextItemSource(const QUrl &uri) -{ - m_contextItemSource = uri; -} - -QUrl XSDTSTestCase::contextItemSource() const -{ - return m_contextItemSource; -} - -void XSDTSTestCase::setParent(TreeItem *const p) -{ - m_parent = p; -} - -QPatternist::ExternalVariableLoader::Ptr XSDTSTestCase::externalVariableLoader() const -{ - return QPatternist::ExternalVariableLoader::Ptr(); -} - -TestResult *XSDTSTestCase::testResult() const -{ - return m_result; -} - -TestItem::ResultSummary XSDTSTestCase::resultSummary() const -{ - if(m_result) - return ResultSummary(m_result->status() == TestResult::Pass ? 1 : 0, - 1); - - return ResultSummary(0, 1); -} - -// vim: et:ts=4:sw=4:sts=4 - diff --git a/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h b/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h deleted file mode 100644 index 947687a..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the autotests 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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_XSDTSTestCase_H -#define PatternistSDK_XSDTSTestCase_H - -#include -#include -#include - -#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 - */ - class Q_PATTERNISTSDK_EXPORT XSDTSTestCase : public TestCase - { - public: - enum TestType - { - SchemaTest, - InstanceTest - }; - - XSDTSTestCase(const Scenario scen, TreeItem *parent, TestType testType); - virtual ~XSDTSTestCase(); - - /** - * 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); - /** - * 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 schemaUri() const; - virtual QUrl instanceUri() const; - virtual QUrl testCasePath() const {return QUrl();} - 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 setName(const QString &name); - void setSchemaUri(const QUrl &uri); - void setInstanceUri(const QUrl &uri); - void setTestCasePath(const QUrl & /* uri */) {} - void setContextItemSource(const QUrl &uri); - void addBaseLine(TestBaseLine *lines); - - 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; - - virtual QUrl contextItemSource() const; - void setParent(TreeItem *const parent); - virtual QPatternist::ExternalVariableLoader::Ptr externalVariableLoader() const; - virtual TestResult *testResult() const; - virtual ResultSummary resultSummary() const; - - private: - void executeSchemaTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler); - void executeInstanceTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler); - - QString m_name; - QString m_creator; - QString m_description; - QUrl m_schemaUri; - QUrl m_instanceUri; - QDate m_lastModified; - const Scenario m_scenario; - TreeItem * m_parent; - TestBaseLine::List m_baseLines; - QUrl m_contextItemSource; - TestType m_testType; - QPointer m_result; - }; -} - -QT_END_NAMESPACE -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.cpp b/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.cpp deleted file mode 100644 index a868d19..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.cpp +++ /dev/null @@ -1,910 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the autotests 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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include "qacceltreeresourceloader_p.h" -#include "qnetworkaccessdelegator_p.h" - -#include "Global.h" -#include "TestBaseLine.h" -#include "TestGroup.h" - -#include "XSDTestSuiteHandler.h" -#include "XSDTSTestCase.h" - -using namespace QPatternistSDK; - -extern QNetworkAccessManager s_networkManager; - -XSDTestSuiteHandler::XSDTestSuiteHandler(const QUrl &catalogFile) : m_ts(0) - , m_catalogFile(catalogFile) - , m_inSchemaTest(false) - , m_inInstanceTest(false) - , m_inTestGroup(false) - , m_inDescription(false) - , m_schemaBlacklisted(false) - , m_counter(0) -{ - Q_ASSERT(!m_catalogFile.isRelative()); - m_ts = new TestSuite(); - m_topLevelGroup = new TestGroup(m_ts); - m_topLevelGroup->setTitle("XML Schema Test Suite"); - m_ts->appendChild(m_topLevelGroup); - - // exclude these test cases, as they break our current state machine - m_blackList << QLatin1String("addB099") - << QLatin1String("addB118") - << QLatin1String("elemJ003") - << QLatin1String("elemJ011") - << QLatin1String("elemZ004") - << QLatin1String("elemZ020") - << QLatin1String("groupH021v") - << QLatin1String("groupJ009v") - << QLatin1String("name00101m2") - << QLatin1String("schL5") - << QLatin1String("ste110") - << QLatin1String("stZ007") - << QLatin1String("stZ047") - << QLatin1String("stZ055") - << QLatin1String("addB049") - << QLatin1String("addB068") - << QLatin1String("addB078") - << QLatin1String("addB078A") - << QLatin1String("addB078B") - << QLatin1String("addB167") - << QLatin1String("addB191") - << QLatin1String("isDefault060_2") - << QLatin1String("isDefault069") - << QLatin1String("annotB025") - << QLatin1String("base64Binary_enumeration003_1321") - << QLatin1String("anyURI_a001_1336") - << QLatin1String("anyURI_a001_1336") - << QLatin1String("anyURI_a003_1338") - << QLatin1String("anyURI_a004_1339") - << QLatin1String("anyURI_b004_1354") - << QLatin1String("anyURI_b004_1354") - << QLatin1String("anyURI_b006_1356") - << QLatin1String("QName_length001_1357") - << QLatin1String("QName_length003_1359") - << QLatin1String("QName_minLength003_1362") - << QLatin1String("QName_maxLength001_1364") - << QLatin1String("NOTATION_length001_1372") - << QLatin1String("NOTATION_length003_1374") - << QLatin1String("NOTATION_minLength003_1377") - << QLatin1String("NOTATION_maxLength001_1379") - << QLatin1String("hexBinary003_2069") - << QLatin1String("QName009_2092") - << QLatin1String("dtZ107447_a_2245") - << QLatin1String("elemE001") - << QLatin1String("elemE002") - << QLatin1String("elemE003") - << QLatin1String("elemE004") - << QLatin1String("elemE005") - << QLatin1String("elemT026") - << QLatin1String("elemT027") - << QLatin1String("elemT028") - << QLatin1String("elemT029") - << QLatin1String("elemT054") - << QLatin1String("elemT055") - << QLatin1String("elemT056") - << QLatin1String("elemT057") - << QLatin1String("elemZ006") - << QLatin1String("elemZ007") - << QLatin1String("elemZ026") - << QLatin1String("elemZ027_c") - << QLatin1String("elemZ028c") - << QLatin1String("elemZ028d") - << QLatin1String("elemZ028f1") - << QLatin1String("elemZ028f1") - << QLatin1String("elemZ028f2") - << QLatin1String("elemZ028f2") - << QLatin1String("elemZ028f3") - << QLatin1String("elemZ028f3") - << QLatin1String("elemZ031") - << QLatin1String("errF001") - << QLatin1String("idC019") - << QLatin1String("idL100") - << QLatin1String("idZ011") - << QLatin1String("idZ015") - << QLatin1String("mgO013") - << QLatin1String("particlesA012") - << QLatin1String("particlesA013") - << QLatin1String("particlesA014") - << QLatin1String("particlesA015") - << QLatin1String("particlesHa161") - << QLatin1String("particlesHb008") - << QLatin1String("particlesHb011") - << QLatin1String("particlesIe003") - << QLatin1String("particlesIg003") - << QLatin1String("particlesIg004") - << QLatin1String("particlesJb003") - << QLatin1String("particlesJd003") - << QLatin1String("particlesJf003") - << QLatin1String("particlesJk003") - << QLatin1String("particlesOb001") - << QLatin1String("particlesOb002") - << QLatin1String("particlesOb004") - << QLatin1String("particlesOb008") - << QLatin1String("particlesOb009") - << QLatin1String("particlesOb013") - << QLatin1String("particlesOb018") - << QLatin1String("particlesQ005") - << QLatin1String("particlesS002") - << QLatin1String("particlesT002") - << QLatin1String("particlesT009") - << QLatin1String("particlesT014") - << QLatin1String("particlesV001") - << QLatin1String("particlesV002") - << QLatin1String("particlesV020") - << QLatin1String("particlesZ001") - << QLatin1String("particlesZ005") - << QLatin1String("particlesZ007") - << QLatin1String("particlesZ023") - << QLatin1String("particlesZ024") - << QLatin1String("particlesZ026") - << QLatin1String("particlesZ028") - << QLatin1String("particlesZ033_c") - << QLatin1String("particlesZ033_d") - << QLatin1String("particlesZ033_e") - << QLatin1String("particlesZ033_f") - << QLatin1String("particlesZ033_g") - << QLatin1String("particlesZ034_a1") - << QLatin1String("particlesZ034_a2") - << QLatin1String("particlesZ034_a3") - << QLatin1String("particlesZ034_b") - << QLatin1String("particlesZ035_a") - << QLatin1String("particlesZ035_b") - << QLatin1String("particlesZ036_a") - << QLatin1String("particlesZ036_b1") - << QLatin1String("particlesZ036_b2") - << QLatin1String("particlesZ036_c") -/* - << QLatin1String("reC65") - << QLatin1String("reC66") - << QLatin1String("reC67") - << QLatin1String("reC68") - << QLatin1String("reF58") - << QLatin1String("reG50") - << QLatin1String("reJ11") - << QLatin1String("reJ13") - << QLatin1String("reJ19") - << QLatin1String("reJ21") - << QLatin1String("reJ23") - << QLatin1String("reJ25") - << QLatin1String("reJ29") - << QLatin1String("reJ31") - << QLatin1String("reJ33") - << QLatin1String("reJ35") - << QLatin1String("reJ61") - << QLatin1String("reJ69") - << QLatin1String("reJ75") - << QLatin1String("reJ77") - << QLatin1String("reL98") - << QLatin1String("reL99") - << QLatin1String("reM98") - << QLatin1String("reN99") - << QLatin1String("reS21") - << QLatin1String("reS42") - << QLatin1String("reT63") - << QLatin1String("reT84") - << QLatin1String("reDG2") - << QLatin1String("RegexTest_9") - << QLatin1String("RegexTest_11") - << QLatin1String("RegexTest_14") - << QLatin1String("RegexTest_15") - << QLatin1String("RegexTest_16") - << QLatin1String("RegexTest_17") - << QLatin1String("RegexTest_23") - << QLatin1String("RegexTest_24") - << QLatin1String("RegexTest_25") - << QLatin1String("RegexTest_26") - << QLatin1String("RegexTest_27") - << QLatin1String("RegexTest_28") - << QLatin1String("RegexTest_30") - << QLatin1String("RegexTest_30") - << QLatin1String("RegexTest_33") - << QLatin1String("RegexTest_34") - << QLatin1String("RegexTest_34") - << QLatin1String("RegexTest_43") - << QLatin1String("RegexTest_44") - << QLatin1String("RegexTest_45") - << QLatin1String("RegexTest_46") - << QLatin1String("RegexTest_47") - << QLatin1String("RegexTest_48") - << QLatin1String("RegexTest_49") - << QLatin1String("RegexTest_50") - << QLatin1String("RegexTest_51") - << QLatin1String("RegexTest_52") - << QLatin1String("RegexTest_53") - << QLatin1String("RegexTest_54") - << QLatin1String("RegexTest_55") - << QLatin1String("RegexTest_56") - << QLatin1String("RegexTest_57") - << QLatin1String("RegexTest_57") - << QLatin1String("RegexTest_58") - << QLatin1String("RegexTest_58") - << QLatin1String("RegexTest_65") - << QLatin1String("RegexTest_113") - << QLatin1String("RegexTest_116") - << QLatin1String("RegexTest_119") - << QLatin1String("RegexTest_120") - << QLatin1String("RegexTest_121") - << QLatin1String("RegexTest_141") - << QLatin1String("RegexTest_142") - << QLatin1String("RegexTest_143") - << QLatin1String("RegexTest_145") - << QLatin1String("RegexTest_146") - << QLatin1String("RegexTest_147") - << QLatin1String("RegexTest_148") - << QLatin1String("RegexTest_149") - << QLatin1String("RegexTest_150") - << QLatin1String("RegexTest_151") - << QLatin1String("RegexTest_152") - << QLatin1String("RegexTest_154") - << QLatin1String("RegexTest_155") - << QLatin1String("RegexTest_156") - << QLatin1String("RegexTest_157") - << QLatin1String("RegexTest_158") - << QLatin1String("RegexTest_163") - << QLatin1String("RegexTest_164") - << QLatin1String("RegexTest_165") - << QLatin1String("RegexTest_166") - << QLatin1String("RegexTest_167") - << QLatin1String("RegexTest_168") - << QLatin1String("RegexTest_169") - << QLatin1String("RegexTest_170") - << QLatin1String("RegexTest_171") - << QLatin1String("RegexTest_172") - << QLatin1String("RegexTest_173") - << QLatin1String("RegexTest_174") - << QLatin1String("RegexTest_178") - << QLatin1String("RegexTest_194") - << QLatin1String("RegexTest_194") - << QLatin1String("RegexTest_195") - << QLatin1String("RegexTest_195") - << QLatin1String("RegexTest_196") - << QLatin1String("RegexTest_196") - << QLatin1String("RegexTest_197") - << QLatin1String("RegexTest_198") - << QLatin1String("RegexTest_199") - << QLatin1String("RegexTest_200") - << QLatin1String("RegexTest_200") - << QLatin1String("RegexTest_201") - << QLatin1String("RegexTest_201") - << QLatin1String("RegexTest_202") - << QLatin1String("RegexTest_202") - << QLatin1String("RegexTest_203") - << QLatin1String("RegexTest_204") - << QLatin1String("RegexTest_205") - << QLatin1String("RegexTest_206") - << QLatin1String("RegexTest_207") - << QLatin1String("RegexTest_208") - << QLatin1String("RegexTest_209") - << QLatin1String("RegexTest_209") - << QLatin1String("RegexTest_210") - << QLatin1String("RegexTest_210") - << QLatin1String("RegexTest_211") - << QLatin1String("RegexTest_211") - << QLatin1String("RegexTest_212") - << QLatin1String("RegexTest_213") - << QLatin1String("RegexTest_214") - << QLatin1String("RegexTest_215") - << QLatin1String("RegexTest_216") - << QLatin1String("RegexTest_217") - << QLatin1String("RegexTest_218") - << QLatin1String("RegexTest_220") - << QLatin1String("RegexTest_221") - << QLatin1String("RegexTest_222") - << QLatin1String("RegexTest_226") - << QLatin1String("RegexTest_230") - << QLatin1String("RegexTest_232") - << QLatin1String("RegexTest_233") - << QLatin1String("RegexTest_294") - << QLatin1String("RegexTest_294") - << QLatin1String("RegexTest_295") - << QLatin1String("RegexTest_295") - << QLatin1String("RegexTest_299") - << QLatin1String("RegexTest_300") - << QLatin1String("RegexTest_301") - << QLatin1String("RegexTest_302") - << QLatin1String("RegexTest_303") - << QLatin1String("RegexTest_304") - << QLatin1String("RegexTest_305") - << QLatin1String("RegexTest_306") - << QLatin1String("RegexTest_307") - << QLatin1String("RegexTest_308") - << QLatin1String("RegexTest_309") - << QLatin1String("RegexTest_310") - << QLatin1String("RegexTest_311") - << QLatin1String("RegexTest_312") - << QLatin1String("RegexTest_313") - << QLatin1String("RegexTest_314") - << QLatin1String("RegexTest_315") - << QLatin1String("RegexTest_315") - << QLatin1String("RegexTest_316") - << QLatin1String("RegexTest_316") - << QLatin1String("RegexTest_317") - << QLatin1String("RegexTest_317") - << QLatin1String("RegexTest_440") - << QLatin1String("RegexTest_441") - << QLatin1String("RegexTest_442") - << QLatin1String("RegexTest_443") - << QLatin1String("RegexTest_448") - << QLatin1String("RegexTest_449") - << QLatin1String("RegexTest_450") - << QLatin1String("RegexTest_451") - << QLatin1String("RegexTest_458") - << QLatin1String("RegexTest_464") - << QLatin1String("RegexTest_464") - << QLatin1String("RegexTest_465") - << QLatin1String("RegexTest_469") - << QLatin1String("RegexTest_470") - << QLatin1String("RegexTest_471") - << QLatin1String("RegexTest_472") - << QLatin1String("RegexTest_473") - << QLatin1String("RegexTest_477") - << QLatin1String("RegexTest_478") - << QLatin1String("RegexTest_478") - << QLatin1String("RegexTest_479") - << QLatin1String("RegexTest_480") - << QLatin1String("RegexTest_481") - << QLatin1String("RegexTest_482") - << QLatin1String("RegexTest_482") - << QLatin1String("RegexTest_483") - << QLatin1String("RegexTest_483") - << QLatin1String("RegexTest_484") - << QLatin1String("RegexTest_487") - << QLatin1String("RegexTest_516") - << QLatin1String("RegexTest_516") - << QLatin1String("RegexTest_517") - << QLatin1String("RegexTest_517") - << QLatin1String("RegexTest_518") - << QLatin1String("RegexTest_518") - << QLatin1String("RegexTest_519") - << QLatin1String("RegexTest_519") - << QLatin1String("RegexTest_521") - << QLatin1String("RegexTest_523") - << QLatin1String("RegexTest_524") - << QLatin1String("RegexTest_524") - << QLatin1String("RegexTest_586") - << QLatin1String("RegexTest_587") - << QLatin1String("RegexTest_592") - << QLatin1String("RegexTest_593") - << QLatin1String("RegexTest_594") - << QLatin1String("RegexTest_595") - << QLatin1String("RegexTest_596") - << QLatin1String("RegexTest_597") - << QLatin1String("RegexTest_598") - << QLatin1String("RegexTest_599") - << QLatin1String("RegexTest_600") - << QLatin1String("RegexTest_601") - << QLatin1String("RegexTest_602") - << QLatin1String("RegexTest_603") - << QLatin1String("RegexTest_604") - << QLatin1String("RegexTest_605") - << QLatin1String("RegexTest_648") - << QLatin1String("RegexTest_655") - << QLatin1String("RegexTest_688") - << QLatin1String("RegexTest_696") - << QLatin1String("RegexTest_697") - << QLatin1String("RegexTest_698") - << QLatin1String("RegexTest_700") - << QLatin1String("RegexTest_701") - << QLatin1String("RegexTest_702") - << QLatin1String("RegexTest_703") - << QLatin1String("RegexTest_704") - << QLatin1String("RegexTest_705") - << QLatin1String("RegexTest_706") - << QLatin1String("RegexTest_707") - << QLatin1String("RegexTest_717") - << QLatin1String("RegexTest_718") - << QLatin1String("RegexTest_719") - << QLatin1String("RegexTest_724") - << QLatin1String("RegexTest_725") - << QLatin1String("RegexTest_726") - << QLatin1String("RegexTest_727") - << QLatin1String("RegexTest_728") - << QLatin1String("RegexTest_729") - << QLatin1String("RegexTest_730") - << QLatin1String("RegexTest_731") - << QLatin1String("RegexTest_732") - << QLatin1String("RegexTest_733") - << QLatin1String("RegexTest_743") - << QLatin1String("RegexTest_755") - << QLatin1String("RegexTest_756") - << QLatin1String("RegexTest_761") - << QLatin1String("RegexTest_762") - << QLatin1String("RegexTest_781") - << QLatin1String("RegexTest_782") - << QLatin1String("RegexTest_783") - << QLatin1String("RegexTest_790") - << QLatin1String("RegexTest_791") - << QLatin1String("RegexTest_824") - << QLatin1String("RegexTest_826") - << QLatin1String("RegexTest_827") - << QLatin1String("RegexTest_836") - << QLatin1String("RegexTest_837") - << QLatin1String("RegexTest_841") - << QLatin1String("RegexTest_842") - << QLatin1String("RegexTest_843") - << QLatin1String("RegexTest_844") - << QLatin1String("RegexTest_845") - << QLatin1String("RegexTest_846") - << QLatin1String("RegexTest_847") - << QLatin1String("RegexTest_848") - << QLatin1String("RegexTest_851") - << QLatin1String("RegexTest_852") - << QLatin1String("RegexTest_853") - << QLatin1String("RegexTest_854") - << QLatin1String("RegexTest_855") - << QLatin1String("RegexTest_856") - << QLatin1String("RegexTest_857") - << QLatin1String("RegexTest_861") - << QLatin1String("RegexTest_862") - << QLatin1String("RegexTest_863") - << QLatin1String("RegexTest_864") - << QLatin1String("RegexTest_865") - << QLatin1String("RegexTest_866") - << QLatin1String("RegexTest_870") - << QLatin1String("RegexTest_879") - << QLatin1String("RegexTest_880") - << QLatin1String("RegexTest_888") - << QLatin1String("RegexTest_889") - << QLatin1String("RegexTest_890") - << QLatin1String("RegexTest_891") - << QLatin1String("RegexTest_892") - << QLatin1String("RegexTest_893") - << QLatin1String("RegexTest_894") - << QLatin1String("RegexTest_895") - << QLatin1String("RegexTest_896") - << QLatin1String("RegexTest_897") - << QLatin1String("RegexTest_898") - << QLatin1String("RegexTest_899") - << QLatin1String("RegexTest_900") - << QLatin1String("RegexTest_901") - << QLatin1String("RegexTest_902") - << QLatin1String("RegexTest_903") - << QLatin1String("RegexTest_904") - << QLatin1String("RegexTest_905") - << QLatin1String("RegexTest_906") - << QLatin1String("RegexTest_907") - << QLatin1String("RegexTest_908") - << QLatin1String("RegexTest_909") - << QLatin1String("RegexTest_910") - << QLatin1String("RegexTest_911") - << QLatin1String("RegexTest_912") - << QLatin1String("RegexTest_913") - << QLatin1String("RegexTest_914") - << QLatin1String("RegexTest_915") - << QLatin1String("RegexTest_916") - << QLatin1String("RegexTest_917") - << QLatin1String("RegexTest_918") - << QLatin1String("RegexTest_919") - << QLatin1String("RegexTest_920") - << QLatin1String("RegexTest_921") - << QLatin1String("RegexTest_922") - << QLatin1String("RegexTest_923") - << QLatin1String("RegexTest_924") - << QLatin1String("RegexTest_925") - << QLatin1String("RegexTest_926") - << QLatin1String("RegexTest_928") - << QLatin1String("RegexTest_929") - << QLatin1String("RegexTest_930") - << QLatin1String("RegexTest_936") - << QLatin1String("RegexTest_937") - << QLatin1String("RegexTest_938") - << QLatin1String("RegexTest_939") - << QLatin1String("RegexTest_940") - << QLatin1String("RegexTest_941") - << QLatin1String("RegexTest_942") - << QLatin1String("RegexTest_943") - << QLatin1String("RegexTest_944") - << QLatin1String("RegexTest_945") - << QLatin1String("RegexTest_946") - << QLatin1String("RegexTest_949") - << QLatin1String("RegexTest_950") - << QLatin1String("RegexTest_951") - << QLatin1String("RegexTest_952") - << QLatin1String("RegexTest_953") - << QLatin1String("RegexTest_954") - << QLatin1String("RegexTest_955") - << QLatin1String("RegexTest_956") - << QLatin1String("RegexTest_957") - << QLatin1String("RegexTest_958") - << QLatin1String("RegexTest_959") - << QLatin1String("RegexTest_960") - << QLatin1String("RegexTest_961") - << QLatin1String("RegexTest_962") - << QLatin1String("RegexTest_963") - << QLatin1String("RegexTest_964") - << QLatin1String("RegexTest_976") - << QLatin1String("RegexTest_977") - << QLatin1String("RegexTest_988") - << QLatin1String("RegexTest_989") - << QLatin1String("RegexTest_990") - << QLatin1String("RegexTest_991") - << QLatin1String("RegexTest_994") - << QLatin1String("RegexTest_995") - << QLatin1String("RegexTest_996") - << QLatin1String("RegexTest_997") - << QLatin1String("RegexTest_1000") - << QLatin1String("RegexTest_1001") - << QLatin1String("RegexTest_1002") - << QLatin1String("RegexTest_1003") - << QLatin1String("RegexTest_1004") - << QLatin1String("RegexTest_1007") - << QLatin1String("RegexTest_1008") - << QLatin1String("RegexTest_1009") - << QLatin1String("RegexTest_1010") - << QLatin1String("RegexTest_1011") - << QLatin1String("RegexTest_1012") - << QLatin1String("RegexTest_1013") - << QLatin1String("RegexTest_1014") - << QLatin1String("RegexTest_1015") - << QLatin1String("RegexTest_1016") - << QLatin1String("RegexTest_1017") - << QLatin1String("RegexTest_1018") - << QLatin1String("RegexTest_1019") - << QLatin1String("RegexTest_1070") - << QLatin1String("RegexTest_1071") - << QLatin1String("RegexTest_1076") - << QLatin1String("RegexTest_1077") - << QLatin1String("RegexTest_1078") - << QLatin1String("RegexTest_1079") - << QLatin1String("RegexTest_1080") - << QLatin1String("RegexTest_1081") - << QLatin1String("RegexTest_1082") - << QLatin1String("RegexTest_1083") - << QLatin1String("RegexTest_1084") - << QLatin1String("RegexTest_1085") - << QLatin1String("RegexTest_1086") - << QLatin1String("RegexTest_1087") - << QLatin1String("RegexTest_1088") - << QLatin1String("RegexTest_1089") - << QLatin1String("RegexTest_1132") - << QLatin1String("RegexTest_1139") - << QLatin1String("RegexTest_1172") - << QLatin1String("RegexTest_1180") - << QLatin1String("RegexTest_1181") - << QLatin1String("RegexTest_1182") - << QLatin1String("RegexTest_1184") - << QLatin1String("RegexTest_1185") - << QLatin1String("RegexTest_1186") - << QLatin1String("RegexTest_1187") - << QLatin1String("RegexTest_1188") - << QLatin1String("RegexTest_1189") - << QLatin1String("RegexTest_1190") - << QLatin1String("RegexTest_1191") - << QLatin1String("RegexTest_1201") - << QLatin1String("RegexTest_1202") - << QLatin1String("RegexTest_1203") - << QLatin1String("RegexTest_1208") - << QLatin1String("RegexTest_1209") - << QLatin1String("RegexTest_1210") - << QLatin1String("RegexTest_1211") - << QLatin1String("RegexTest_1212") - << QLatin1String("RegexTest_1213") - << QLatin1String("RegexTest_1214") - << QLatin1String("RegexTest_1215") - << QLatin1String("RegexTest_1216") - << QLatin1String("RegexTest_1217") - << QLatin1String("RegexTest_1227") - << QLatin1String("RegexTest_1239") - << QLatin1String("RegexTest_1240") - << QLatin1String("RegexTest_1245") - << QLatin1String("RegexTest_1246") - << QLatin1String("RegexTest_1265") - << QLatin1String("RegexTest_1266") - << QLatin1String("RegexTest_1267") - << QLatin1String("RegexTest_1274") - << QLatin1String("RegexTest_1275") - << QLatin1String("RegexTest_1308") - << QLatin1String("RegexTest_1310") - << QLatin1String("RegexTest_1311") - << QLatin1String("RegexTest_1320") - << QLatin1String("RegexTest_1321") - << QLatin1String("RegexTest_1322") - << QLatin1String("RegexTest_1323") - << QLatin1String("RegexTest_1324") - << QLatin1String("RegexTest_1325") - << QLatin1String("RegexTest_1326") - << QLatin1String("RegexTest_1327") - << QLatin1String("RegexTest_1328") - << QLatin1String("RegexTest_1329") - << QLatin1String("RegexTest_1330") - << QLatin1String("RegexTest_1331") - << QLatin1String("RegexTest_1332") - << QLatin1String("RegexTest_1335") - << QLatin1String("RegexTest_1336") - << QLatin1String("RegexTest_1337") - << QLatin1String("RegexTest_1338") - << QLatin1String("RegexTest_1339") - << QLatin1String("RegexTest_1340") - << QLatin1String("RegexTest_1341") - << QLatin1String("RegexTest_1345") - << QLatin1String("RegexTest_1346") - << QLatin1String("RegexTest_1347") - << QLatin1String("RegexTest_1348") - << QLatin1String("RegexTest_1349") - << QLatin1String("RegexTest_1350") - << QLatin1String("RegexTest_1354") - << QLatin1String("RegexTest_1363") - << QLatin1String("RegexTest_1364") - << QLatin1String("RegexTest_1365") - << QLatin1String("RegexTest_1372") - << QLatin1String("RegexTest_1373") - << QLatin1String("RegexTest_1374") - << QLatin1String("RegexTest_1375") - << QLatin1String("RegexTest_1376") - << QLatin1String("RegexTest_1377") - << QLatin1String("RegexTest_1378") - << QLatin1String("RegexTest_1379") - << QLatin1String("RegexTest_1380") - << QLatin1String("RegexTest_1381") - << QLatin1String("RegexTest_1382") - << QLatin1String("RegexTest_1383") - << QLatin1String("RegexTest_1384") - << QLatin1String("RegexTest_1385") - << QLatin1String("RegexTest_1386") - << QLatin1String("RegexTest_1387") - << QLatin1String("RegexTest_1388") - << QLatin1String("RegexTest_1389") - << QLatin1String("RegexTest_1390") - << QLatin1String("RegexTest_1391") - << QLatin1String("RegexTest_1392") - << QLatin1String("RegexTest_1393") - << QLatin1String("RegexTest_1394") - << QLatin1String("RegexTest_1395") - << QLatin1String("RegexTest_1396") - << QLatin1String("RegexTest_1397") - << QLatin1String("RegexTest_1398") - << QLatin1String("RegexTest_1399") - << QLatin1String("RegexTest_1400") - << QLatin1String("RegexTest_1401") - << QLatin1String("RegexTest_1402") - << QLatin1String("RegexTest_1403") - << QLatin1String("RegexTest_1404") - << QLatin1String("RegexTest_1405") - << QLatin1String("RegexTest_1406") - << QLatin1String("RegexTest_1407") - << QLatin1String("RegexTest_1408") - << QLatin1String("RegexTest_1409") - << QLatin1String("RegexTest_1410") - << QLatin1String("RegexTest_1412") - << QLatin1String("RegexTest_1413") - << QLatin1String("RegexTest_1414") - << QLatin1String("RegexTest_1420") - << QLatin1String("RegexTest_1421") - << QLatin1String("RegexTest_1422") - << QLatin1String("RegexTest_1423") - << QLatin1String("RegexTest_1424") - << QLatin1String("RegexTest_1425") - << QLatin1String("RegexTest_1426") - << QLatin1String("RegexTest_1427") - << QLatin1String("RegexTest_1428") - << QLatin1String("RegexTest_1429") - << QLatin1String("RegexTest_1430") - << QLatin1String("RegexTest_1433") - << QLatin1String("RegexTest_1434") - << QLatin1String("RegexTest_1435") - << QLatin1String("RegexTest_1436") - << QLatin1String("RegexTest_1437") - << QLatin1String("RegexTest_1438") - << QLatin1String("RegexTest_1439") - << QLatin1String("RegexTest_1440") - << QLatin1String("RegexTest_1441") - << QLatin1String("RegexTest_1442") - << QLatin1String("RegexTest_1443") - << QLatin1String("RegexTest_1444") - << QLatin1String("RegexTest_1445") - << QLatin1String("RegexTest_1446") - << QLatin1String("RegexTest_1447") - << QLatin1String("RegexTest_1448") - << QLatin1String("RegexTest_1451") - << QLatin1String("RegexTest_1452") - << QLatin1String("RegexTest_1453") - << QLatin1String("RegexTest_1454") - << QLatin1String("RegexTest_1455") - << QLatin1String("RegexTest_1456") - << QLatin1String("RegexTest_1472") - << QLatin1String("RegexTest_1473") - << QLatin1String("RegexTest_1474") - << QLatin1String("RegexTest_1475") - << QLatin1String("RegexTest_1478") - << QLatin1String("RegexTest_1479") - << QLatin1String("RegexTest_1480") - << QLatin1String("RegexTest_1481") - << QLatin1String("RegexTest_1484") - << QLatin1String("RegexTest_1485") - << QLatin1String("RegexTest_1486") - << QLatin1String("RegexTest_1487") - << QLatin1String("RegexTest_1488") - << QLatin1String("RegexTest_1491") - << QLatin1String("RegexTest_1492") - << QLatin1String("RegexTest_1493") - << QLatin1String("RegexTest_1494") - << QLatin1String("RegexTest_1495") - << QLatin1String("RegexTest_1496") - << QLatin1String("RegexTest_1497") - << QLatin1String("RegexTest_1498") - << QLatin1String("RegexTest_1499") - << QLatin1String("RegexTest_1500") - << QLatin1String("RegexTest_1501") - << QLatin1String("RegexTest_1502") - << QLatin1String("RegexTest_1503") - << QLatin1String("RegexTest_1543") - << QLatin1String("RegexTest_1544") - << QLatin1String("reZ001") -*/ - << QLatin1String("schA2") - << QLatin1String("schA5") - << QLatin1String("schA7") - << QLatin1String("schD8") - << QLatin1String("schG3") - << QLatin1String("schG6") - << QLatin1String("schG9") - << QLatin1String("schG11") - << QLatin1String("schG12") - << QLatin1String("schU1") - << QLatin1String("schU3") - << QLatin1String("schU4") - << QLatin1String("schU5") - << QLatin1String("schZ004") - << QLatin1String("schZ005") - << QLatin1String("schZ012_a") - << QLatin1String("stZ041") - << QLatin1String("wildZ010"); -} - -bool XSDTestSuiteHandler::startElement(const QString &namespaceURI, - const QString &localName, - const QString &/*qName*/, - const QXmlAttributes &atts) -{ - if(namespaceURI != QString::fromLatin1("http://www.w3.org/XML/2004/xml-schema-test-suite/")) - return true; - - if (localName == QLatin1String("testSet")) { - m_currentTestSet = new TestGroup(m_topLevelGroup); - Q_ASSERT(m_currentTestSet); - m_currentTestSet->setTitle(atts.value("name")); - m_topLevelGroup->appendChild(m_currentTestSet); - } else if (localName == QLatin1String("testGroup")) { - m_currentTestGroup = new TestGroup(m_currentTestSet); - Q_ASSERT(m_currentTestGroup); - m_currentTestGroup->setTitle(atts.value("name")); - m_currentTestSet->appendChild(m_currentTestGroup); - m_inTestGroup = true; - } else if (localName == QLatin1String("schemaTest")) { - if (m_blackList.contains(atts.value("name"))) { - m_currentTestCase = 0; - m_schemaBlacklisted = true; - return true; - } - m_schemaBlacklisted = false; - - m_currentTestCase = new XSDTSTestCase(TestCase::Standard, m_currentTestGroup, XSDTSTestCase::SchemaTest); - Q_ASSERT(m_currentTestCase); - m_counter++; - m_currentTestCase->setName(QString::number(m_counter) + atts.value("name")); - m_currentTestGroup->appendChild(m_currentTestCase); - m_currentTestCase->setParent(m_currentTestGroup); - - m_inSchemaTest = true; - } else if (localName == QLatin1String("instanceTest")) { - if (m_schemaBlacklisted) { - m_currentTestCase = 0; - return true; - } - - m_currentTestCase = new XSDTSTestCase(TestCase::Standard, m_currentTestGroup, XSDTSTestCase::InstanceTest); - Q_ASSERT(m_currentTestCase); - m_counter++; - m_currentTestCase->setName(QString::number(m_counter) + atts.value("name")); - m_currentTestGroup->appendChild(m_currentTestCase); - - m_inInstanceTest = true; - } else if (localName == QLatin1String("schemaDocument") || localName == QLatin1String("instanceDocument")) { - if (m_inSchemaTest) { - m_currentTestCase->setSchemaUri(QUrl(atts.value("xlink:href"))); - if (m_currentSchemaLink.isEmpty()) // we only use the first schema document for validation - m_currentSchemaLink = atts.value("xlink:href"); - } - if (m_inInstanceTest) { - m_currentTestCase->setInstanceUri(QUrl(atts.value("xlink:href"))); - m_currentTestCase->setSchemaUri(QUrl(m_currentSchemaLink)); - } - } else if (localName == QLatin1String("expected") && (m_inSchemaTest || m_inInstanceTest)) { - TestBaseLine *baseLine = new TestBaseLine(TestBaseLine::SchemaIsValid); - if (atts.value("validity") == QLatin1String("valid")) { - baseLine->setDetails(QLatin1String("true")); - m_currentTestCase->setName(m_currentTestCase->name() + QLatin1String(" tokoe:valid")); - } else { - baseLine->setDetails(QLatin1String("false")); - m_currentTestCase->setName(m_currentTestCase->name() + QLatin1String(" tokoe:invalid")); - } - - m_currentTestCase->addBaseLine(baseLine); - } else if (localName == QLatin1String("documentation") && m_inTestGroup) { - m_inDescription = true; - } - - return true; -} - -bool XSDTestSuiteHandler::endElement(const QString &/*namespaceURI*/, - const QString &localName, - const QString &/*qName*/) -{ - if (localName == QLatin1String("testGroup")) { - m_inTestGroup = false; - m_currentTestGroup->setDescription(m_documentation); - m_documentation.clear(); - m_currentSchemaLink.clear(); - - if (m_currentTestGroup->childCount() == 0) - m_currentTestSet->removeLast(); - } else if (localName == QLatin1String("schemaTest")) - m_inSchemaTest = false; - else if (localName == QLatin1String("instanceTest")) - m_inInstanceTest = false; - else if (localName == QLatin1String("documentation")) - m_inDescription = false; - - return true; -} - -bool XSDTestSuiteHandler::characters(const QString &ch) -{ - if (m_inDescription) - m_documentation += ch; - - return true; -} - -TestSuite *XSDTestSuiteHandler::testSuite() const -{ - return m_ts; -} - -// vim: et:ts=4:sw=4:sts=4 - diff --git a/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h b/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h deleted file mode 100644 index 5493c7d..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the autotests 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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_XSDTestSuiteHandler_H -#define PatternistSDK_XSDTestSuiteHandler_H - -#include -#include - -#include "ExternalSourceLoader.h" -#include "TestSuite.h" -#include "XQTSTestCase.h" - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - class TestBaseLine; - class TestGroup; - class XSDTSTestCase; - - /** - * @short Creates a TestSuite from the XSD Test Suite. - * - * The created TestSuite can be retrieved via testSuite(). - * - * @note XSDTestSuiteHandler 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. - * - * @ingroup PatternistSDK - * @author Tobias Koenig - */ - class Q_PATTERNISTSDK_EXPORT XSDTestSuiteHandler : 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 - */ - XSDTestSuiteHandler(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: - TestSuite* m_ts; - const QUrl m_catalogFile; - - TestGroup* m_topLevelGroup; - TestGroup* m_currentTestSet; - TestGroup* m_currentTestGroup; - XSDTSTestCase* m_currentTestCase; - bool m_inSchemaTest; - bool m_inInstanceTest; - bool m_inTestGroup; - bool m_inDescription; - bool m_schemaBlacklisted; - QString m_documentation; - QString m_currentSchemaLink; - int m_counter; - QSet m_blackList; - }; -} - -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 deleted file mode 100644 index cfc3b2b..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#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 , so the 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 deleted file mode 100644 index 8614789..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.h +++ /dev/null @@ -1,158 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_XSLTTestSuiteHandler_H -#define PatternistSDK_XSLTTestSuiteHandler_H - -#include -#include -#include - -#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 - */ - 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 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 input-file/\@variable. - */ - QString m_currentInputVariable; - - /** - * The names of the test groups. - */ - QStack m_testGroupName; - - /** - * Holds the content of the current input-URI 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 deleted file mode 100644 index 24ee158..0000000 --- a/tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExample.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@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 deleted file mode 100644 index c5e7312..0000000 --- a/tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExampleResult.xml +++ /dev/null @@ -1,3 +0,0 @@ - - -

Hello World!

diff --git a/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExample.cpp b/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExample.cpp deleted file mode 100644 index 24ee158..0000000 --- a/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExample.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@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 deleted file mode 100644 index c5e7312..0000000 --- a/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExampleResult.xml +++ /dev/null @@ -1,3 +0,0 @@ - - -

Hello World!

diff --git a/tests/auto/xmlpatternsxqts/lib/lib.pro b/tests/auto/xmlpatternsxqts/lib/lib.pro deleted file mode 100644 index f5b0a06..0000000 --- a/tests/auto/xmlpatternsxqts/lib/lib.pro +++ /dev/null @@ -1,88 +0,0 @@ -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 -} - -symbian { - TARGET.EPOCALLOWDLLDATA=1 - TARGET.CAPABILITY = All -Tcb - MMP_RULES += EXPORTUNFROZEN -} - -# 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 \ - XSDTestSuiteHandler.h \ - XSDTSTestCase.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 \ - XSDTestSuiteHandler.cpp \ - XSDTSTestCase.cpp \ - XSLTTestSuiteHandler.cpp diff --git a/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.cpp b/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.cpp deleted file mode 100644 index a10c01a..0000000 --- a/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#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("input"); - QTest::addColumn("expectedResult"); - - /* ------------------- Elements ------------------- */ - QTest::newRow("Only an document element") - << "" - << "\n"; - - QTest::newRow("Document element containing a short closed element") - << "" - << "\n"; - QTest::newRow("Complex nested elements") - << "" - << "\n"; - /* ------------------------------------------------- */ - - /* ---------------- Element Content ---------------- */ - QTest::newRow("Element content with simple content") - << "content" - << "\ncontent"; - - QTest::newRow("Element content with tricky to escape content") - << ">>&'\"''/>" - << "\n>>&'\"''/>"; - /* ------------------------------------------------- */ - - /* ----------- Processing Instructions ------------- */ - QTest::newRow("Simple processing instruction.") - << "" - << "\n"; - /* ------------------------------------------------- */ - - /* --------------- 'xml' attributes ---------------- */ - QTest::newRow("Simple xml:space attribute.") - << "content" - << "\ncontent"; - - QTest::newRow("Many 'xml' attributes.") - << "content" - << "\n" - "content"; - /* ------------------------------------------------- */ - - /* ------------ namespace declarations ------------- */ - QTest::newRow("One simple namespace declaration.") - << "" - << "\n" - ""; - - QTest::newRow("Two simple namespace declarations.") - << "" - << "\n" - ""; - - QTest::newRow("A simple default namespace.") - << "" - << "\n" - ""; - /* ------------------------------------------------- */ - - /* -------- namespace declarations in use ---------- */ - QTest::newRow("Simple use of a namespace declaration.") - << "" - << "\n" - ""; - /* ------------------------------------------------- */ -} - -void XMLWriterTest::cdata() -{ - /* - QTest::newRow("Simple CDATA") - << "" - << "\n"; - - QTest::newRow("Complex CDATA") - << ">&'\";&987;]]>" - << "\n>&'\";&123;]]>"; - */ -} - -void XMLWriterTest::comments() -{ - /* - QTest::newRow("Simple comment") - << "" - << "\n"; - QTest::newRow("Comment") - << "" - << "\n"; - */ -} - -void XMLWriterTest::doxygenExample() -{ -#include "../docs/XMLWriterExample.cpp" - - /* When changing, remember to update the Doxygen in XMLWriter.h */ - const QByteArray expectedResult( - "\n" - "\n" - "

Hello World!

" - ); - - 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 deleted file mode 100644 index f90aea2..0000000 --- a/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PatternistSDK_XMLWriterTest_H -#define PatternistSDK_XMLWriterTest_H - -#include - -QT_BEGIN_HEADER - -namespace QPatternistSDK -{ - /** - * @short QTestLib test for XMLWriter. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - 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 diff --git a/tests/auto/xmlpatternsxqts/test/test.pro b/tests/auto/xmlpatternsxqts/test/test.pro deleted file mode 100644 index a69838a..0000000 --- a/tests/auto/xmlpatternsxqts/test/test.pro +++ /dev/null @@ -1,26 +0,0 @@ -load(qttest_p4) -SOURCES += tst_xmlpatternsxqts.cpp ../../qxmlquery/TestFundament.cpp tst_suitetest.cpp - -include(../../xmlpatterns.pri) - -contains(QT_CONFIG,xmlpatterns) { - HEADERS += tst_suitetest.h - LIBS += -l$$XMLPATTERNS_SDK -} - -# syncqt doesn't copy headers in tools/ so let's manually ensure -# it works with shadow builds and source builds. -INCLUDEPATH += $$(QTDIR)/include/QtXmlPatterns/private \ - $$(QTSRCDIR)/include/QtXmlPatterns/private \ - $$(QTSRCDIR)/tools/xmlpatterns \ - $$(QTDIR)/tools/xmlpatterns \ - ../lib/ - -CONFIG += testlib -QT += xml -DESTDIR = .. -win32 { - CONFIG(debug, debug|release): DESTDIR = ../debug - else: DESTDIR = ../release -} -TARGET = tst_xmlpatternsxqts diff --git a/tests/auto/xmlpatternsxqts/test/tst_suitetest.cpp b/tests/auto/xmlpatternsxqts/test/tst_suitetest.cpp deleted file mode 100644 index 64120c7..0000000 --- a/tests/auto/xmlpatternsxqts/test/tst_suitetest.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include - -#ifdef QTEST_XMLPATTERNS - -#include -#include "TestSuite.h" -#include "TestSuiteResult.h" -#include "XMLWriter.h" -#include "ExitCode.h" -#include "Worker.h" -#include "private/qautoptr_p.h" -#include "tst_suitetest.h" - -using namespace QPatternistSDK; - -tst_SuiteTest::tst_SuiteTest(const SuiteType suiteType, - const bool alwaysRun) : m_existingBaseline(inputFile(QLatin1String("Baseline.xml"))) - , m_candidateBaseline(inputFile(QLatin1String("CandidateBaseline.xml"))) - , m_abortRun(!alwaysRun && !QFile::exists(QLatin1String("runTests"))) - , m_suiteType(suiteType) -{ -} - -/*! - Returns an absolute path to the XQTS catalog, or flags a failure using - QTestLib's mechanisms. - - Finding the location of the catalog is done with `p4 where` such that we don't have - to care about where it is checked out. - */ -void tst_SuiteTest::initTestCase() -{ - catalogPath(m_catalogPath); -} - -/*! - Just runs the test suite and writes the result to m_candidateBaseline. - */ -void tst_SuiteTest::runTestSuite() const -{ - if(m_abortRun) - QSKIP("The test suite is not available, no tests are run.", SkipAll); - - QString errMsg; - const QFileInfo fi(m_catalogPath); - const QUrl catalogPath(QUrl::fromLocalFile(fi.absoluteFilePath())); - - TestSuite::SuiteType suiteType; - switch (m_suiteType) { - case XQuerySuite: suiteType = TestSuite::XQuerySuite; - case XsltSuite: suiteType = TestSuite::XsltSuite; - case XsdSuite: suiteType = TestSuite::XsdSuite; - default: break; - } - - TestSuite *const ts = TestSuite::openCatalog(catalogPath, errMsg, true, suiteType); - - QVERIFY2(ts, qPrintable(QString::fromLatin1("Failed to open the catalog, maybe it doesn't exist or is broken: %1").arg(errMsg))); - - /* Run the tests, and serialize the result(as according to XQTSResult.xsd) to standard out. */ - TestSuiteResult *const result = ts->runSuite(); - Q_ASSERT(result); - - QFile out(m_candidateBaseline); - QVERIFY(out.open(QIODevice::WriteOnly)); - - XMLWriter serializer(&out); - result->toXML(serializer); - - delete result; - delete ts; -} - -void tst_SuiteTest::checkTestSuiteResult() const -{ - if(m_abortRun) - QSKIP("This test takes too long time to run on the majority of platforms.", SkipAll); - - typedef QList QFileInfoList; - - const QFileInfo baseline(m_existingBaseline); - const QFileInfo result(m_candidateBaseline); - QFileInfoList list; - list.append(baseline); - list.append(result); - - const QFileInfoList::const_iterator end(list.constEnd()); - - QEventLoop eventLoop; - const QPatternist::AutoPtr worker(new Worker(eventLoop, m_existingBaseline, result)); - - /* Passed to ResultThreader so it knows what kind of file it is handling. */ - ResultThreader::Type type = ResultThreader::Baseline; - - QProcess::execute(QLatin1String("p4 edit ") + m_existingBaseline); - - for(QFileInfoList::const_iterator it(list.constBegin()); it != end; ++it) - { - QFileInfo i(*it); - i.makeAbsolute(); - - QVERIFY2(i.exists(), qPrintable(QString::fromLatin1("File %1 does not exist.") - .arg(i.fileName()))); - - QFile *const file = new QFile(i.absoluteFilePath(), worker.data()); - - QVERIFY2(file->open(QIODevice::ReadOnly), qPrintable(QString::fromLatin1("Could not open file %1 for reading.") - .arg(i.fileName()))); - - ResultThreader *handler = new ResultThreader(eventLoop, file, type, worker.data()); - - QObject::connect(handler, SIGNAL(finished()), worker.data(), SLOT(threadFinished())); - - handler->start(); /* Start the thread. It now parses the file - and emits threadFinished() when done. */ - type = ResultThreader::Result; - } - - const int exitCode = eventLoop.exec(); - - QProcess::execute(QLatin1String("p4 revert -a ") + m_existingBaseline); - - QCOMPARE(exitCode, 0); -} - -bool tst_SuiteTest::dontRun() const -{ - return m_abortRun; -} -#endif - - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/test/tst_suitetest.h b/tests/auto/xmlpatternsxqts/test/tst_suitetest.h deleted file mode 100644 index 22e384a..0000000 --- a/tests/auto/xmlpatternsxqts/test/tst_suitetest.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef Q_tst_SuiteTest -#define Q_tst_SuiteTest - -#include -#include "../../qxmlquery/TestFundament.h" - -/*! - \class tst_SuiteTest - \internal - \since 4.5 - \brief Base class for tst_XmlPatternsXQTS, tst_XmlPatternsXSLTS and tst_XmlPatternsXSDTS. - */ -class tst_SuiteTest : public QObject - , private TestFundament -{ - Q_OBJECT - -public: - enum SuiteType - { - XQuerySuite, - XsltSuite, - XsdSuite - }; - -protected: - /** - * @p isXSLT is @c true if the catalog opened is an - * XSL-T test suite. - * - * @p alwaysRun is @c true if the test should always be run, - * regardless of if the file runTests exists. - */ - tst_SuiteTest(SuiteType type, - const bool alwaysRun = false); - - /** - * The reason why we pass in a mutable reference and have void as return - * value instead of simply returning the string, is that we in some - * implementations use QTestLib's macros such as QVERIFY, which contains - * return statements. Yay for QTestLib. - */ - virtual void catalogPath(QString &write) const = 0; - - bool dontRun() const; - -private Q_SLOTS: - void initTestCase(); - void runTestSuite() const; - void checkTestSuiteResult() const; - -private: - /** - * An absolute path to the catalog. - */ - QString m_catalogPath; - const QString m_existingBaseline; - const QString m_candidateBaseline; - const bool m_abortRun; - const SuiteType m_suiteType; -}; - -#endif - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/test/tst_xmlpatternsxqts.cpp b/tests/auto/xmlpatternsxqts/test/tst_xmlpatternsxqts.cpp deleted file mode 100644 index 890234e..0000000 --- a/tests/auto/xmlpatternsxqts/test/tst_xmlpatternsxqts.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include - -#ifdef QTEST_XMLPATTERNS - -#include "tst_suitetest.h" - -/*! - \class tst_XmlPatternsXQTS - \internal - \since 4.4 - \brief Tests the actual engine by running W3C's conformance test suite. - */ -class tst_XmlPatternsXQTS : public tst_SuiteTest -{ - Q_OBJECT -public: - tst_XmlPatternsXQTS(); -public: - virtual void catalogPath(QString &write) const; -}; - -tst_XmlPatternsXQTS::tst_XmlPatternsXQTS() : tst_SuiteTest(tst_SuiteTest::XQuerySuite) -{ -} - -void tst_XmlPatternsXQTS::catalogPath(QString &write) const -{ - if(dontRun()) - QSKIP("This test takes too long time to run on the majority of platforms.", SkipAll); - - QProcess p4; - - QStringList arguments; - arguments << QLatin1String("where") - << QLatin1String("//depot/autotests/4.4/tests/auto/xmlpatternsxqts/XQTS/XQTSCatalog.xml"); - p4.start(QLatin1String("p4"), arguments); - QVERIFY(p4.waitForFinished()); - QCOMPARE(p4.exitCode(), 0); - QCOMPARE(p4.exitStatus(), QProcess::NormalExit); - - /* `p4 where' prints for instance: - * - * //depot/qt/4.4/tests/auto/xmlpatternsxqts/... //fenglich-englich/qt-4.4/tests/auto/xmlpatternsxqts/... /home/fenglich/dev/autotests/4.4/tests/auto/xmlpatternsxqts/XQTS/XQTSCatalog.xml - * - * so we want the last string. - */ - write = QString::fromLocal8Bit(p4.readAllStandardOutput()).split(QLatin1Char(' ')).last().trimmed(); - - if(write.isEmpty() || !QFile::exists(write)) - { - QEXPECT_FAIL("", "//depot/autotests/4.4/tests/auto/xmlpatternsxqts/XQTS/ must be part of the perforce client spec, " - "checked out at an arbitrary location, for this test to run. The test suite will now be skipped.", Abort); - QVERIFY(false); - } -} - -QTEST_MAIN(tst_XmlPatternsXQTS) - -#include "tst_xmlpatternsxqts.moc" -#else -QTEST_NOOP_MAIN -#endif - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/tst_suitetest.cpp b/tests/auto/xmlpatternsxqts/tst_suitetest.cpp new file mode 100644 index 0000000..64120c7 --- /dev/null +++ b/tests/auto/xmlpatternsxqts/tst_suitetest.cpp @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include + +#ifdef QTEST_XMLPATTERNS + +#include +#include "TestSuite.h" +#include "TestSuiteResult.h" +#include "XMLWriter.h" +#include "ExitCode.h" +#include "Worker.h" +#include "private/qautoptr_p.h" +#include "tst_suitetest.h" + +using namespace QPatternistSDK; + +tst_SuiteTest::tst_SuiteTest(const SuiteType suiteType, + const bool alwaysRun) : m_existingBaseline(inputFile(QLatin1String("Baseline.xml"))) + , m_candidateBaseline(inputFile(QLatin1String("CandidateBaseline.xml"))) + , m_abortRun(!alwaysRun && !QFile::exists(QLatin1String("runTests"))) + , m_suiteType(suiteType) +{ +} + +/*! + Returns an absolute path to the XQTS catalog, or flags a failure using + QTestLib's mechanisms. + + Finding the location of the catalog is done with `p4 where` such that we don't have + to care about where it is checked out. + */ +void tst_SuiteTest::initTestCase() +{ + catalogPath(m_catalogPath); +} + +/*! + Just runs the test suite and writes the result to m_candidateBaseline. + */ +void tst_SuiteTest::runTestSuite() const +{ + if(m_abortRun) + QSKIP("The test suite is not available, no tests are run.", SkipAll); + + QString errMsg; + const QFileInfo fi(m_catalogPath); + const QUrl catalogPath(QUrl::fromLocalFile(fi.absoluteFilePath())); + + TestSuite::SuiteType suiteType; + switch (m_suiteType) { + case XQuerySuite: suiteType = TestSuite::XQuerySuite; + case XsltSuite: suiteType = TestSuite::XsltSuite; + case XsdSuite: suiteType = TestSuite::XsdSuite; + default: break; + } + + TestSuite *const ts = TestSuite::openCatalog(catalogPath, errMsg, true, suiteType); + + QVERIFY2(ts, qPrintable(QString::fromLatin1("Failed to open the catalog, maybe it doesn't exist or is broken: %1").arg(errMsg))); + + /* Run the tests, and serialize the result(as according to XQTSResult.xsd) to standard out. */ + TestSuiteResult *const result = ts->runSuite(); + Q_ASSERT(result); + + QFile out(m_candidateBaseline); + QVERIFY(out.open(QIODevice::WriteOnly)); + + XMLWriter serializer(&out); + result->toXML(serializer); + + delete result; + delete ts; +} + +void tst_SuiteTest::checkTestSuiteResult() const +{ + if(m_abortRun) + QSKIP("This test takes too long time to run on the majority of platforms.", SkipAll); + + typedef QList QFileInfoList; + + const QFileInfo baseline(m_existingBaseline); + const QFileInfo result(m_candidateBaseline); + QFileInfoList list; + list.append(baseline); + list.append(result); + + const QFileInfoList::const_iterator end(list.constEnd()); + + QEventLoop eventLoop; + const QPatternist::AutoPtr worker(new Worker(eventLoop, m_existingBaseline, result)); + + /* Passed to ResultThreader so it knows what kind of file it is handling. */ + ResultThreader::Type type = ResultThreader::Baseline; + + QProcess::execute(QLatin1String("p4 edit ") + m_existingBaseline); + + for(QFileInfoList::const_iterator it(list.constBegin()); it != end; ++it) + { + QFileInfo i(*it); + i.makeAbsolute(); + + QVERIFY2(i.exists(), qPrintable(QString::fromLatin1("File %1 does not exist.") + .arg(i.fileName()))); + + QFile *const file = new QFile(i.absoluteFilePath(), worker.data()); + + QVERIFY2(file->open(QIODevice::ReadOnly), qPrintable(QString::fromLatin1("Could not open file %1 for reading.") + .arg(i.fileName()))); + + ResultThreader *handler = new ResultThreader(eventLoop, file, type, worker.data()); + + QObject::connect(handler, SIGNAL(finished()), worker.data(), SLOT(threadFinished())); + + handler->start(); /* Start the thread. It now parses the file + and emits threadFinished() when done. */ + type = ResultThreader::Result; + } + + const int exitCode = eventLoop.exec(); + + QProcess::execute(QLatin1String("p4 revert -a ") + m_existingBaseline); + + QCOMPARE(exitCode, 0); +} + +bool tst_SuiteTest::dontRun() const +{ + return m_abortRun; +} +#endif + + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/tst_suitetest.h b/tests/auto/xmlpatternsxqts/tst_suitetest.h new file mode 100644 index 0000000..70e56af --- /dev/null +++ b/tests/auto/xmlpatternsxqts/tst_suitetest.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef Q_tst_SuiteTest +#define Q_tst_SuiteTest + +#include +#include "../qxmlquery/TestFundament.h" + +/*! + \class tst_SuiteTest + \internal + \since 4.5 + \brief Base class for tst_XmlPatternsXQTS, tst_XmlPatternsXSLTS and tst_XmlPatternsXSDTS. + */ +class tst_SuiteTest : public QObject + , private TestFundament +{ + Q_OBJECT + +public: + enum SuiteType + { + XQuerySuite, + XsltSuite, + XsdSuite + }; + +protected: + /** + * @p isXSLT is @c true if the catalog opened is an + * XSL-T test suite. + * + * @p alwaysRun is @c true if the test should always be run, + * regardless of if the file runTests exists. + */ + tst_SuiteTest(SuiteType type, + const bool alwaysRun = false); + + /** + * The reason why we pass in a mutable reference and have void as return + * value instead of simply returning the string, is that we in some + * implementations use QTestLib's macros such as QVERIFY, which contains + * return statements. Yay for QTestLib. + */ + virtual void catalogPath(QString &write) const = 0; + + bool dontRun() const; + +private Q_SLOTS: + void initTestCase(); + void runTestSuite() const; + void checkTestSuiteResult() const; + +private: + /** + * An absolute path to the catalog. + */ + QString m_catalogPath; + const QString m_existingBaseline; + const QString m_candidateBaseline; + const bool m_abortRun; + const SuiteType m_suiteType; +}; + +#endif + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/tst_xmlpatternsxqts.cpp b/tests/auto/xmlpatternsxqts/tst_xmlpatternsxqts.cpp new file mode 100644 index 0000000..890234e --- /dev/null +++ b/tests/auto/xmlpatternsxqts/tst_xmlpatternsxqts.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include + +#ifdef QTEST_XMLPATTERNS + +#include "tst_suitetest.h" + +/*! + \class tst_XmlPatternsXQTS + \internal + \since 4.4 + \brief Tests the actual engine by running W3C's conformance test suite. + */ +class tst_XmlPatternsXQTS : public tst_SuiteTest +{ + Q_OBJECT +public: + tst_XmlPatternsXQTS(); +public: + virtual void catalogPath(QString &write) const; +}; + +tst_XmlPatternsXQTS::tst_XmlPatternsXQTS() : tst_SuiteTest(tst_SuiteTest::XQuerySuite) +{ +} + +void tst_XmlPatternsXQTS::catalogPath(QString &write) const +{ + if(dontRun()) + QSKIP("This test takes too long time to run on the majority of platforms.", SkipAll); + + QProcess p4; + + QStringList arguments; + arguments << QLatin1String("where") + << QLatin1String("//depot/autotests/4.4/tests/auto/xmlpatternsxqts/XQTS/XQTSCatalog.xml"); + p4.start(QLatin1String("p4"), arguments); + QVERIFY(p4.waitForFinished()); + QCOMPARE(p4.exitCode(), 0); + QCOMPARE(p4.exitStatus(), QProcess::NormalExit); + + /* `p4 where' prints for instance: + * + * //depot/qt/4.4/tests/auto/xmlpatternsxqts/... //fenglich-englich/qt-4.4/tests/auto/xmlpatternsxqts/... /home/fenglich/dev/autotests/4.4/tests/auto/xmlpatternsxqts/XQTS/XQTSCatalog.xml + * + * so we want the last string. + */ + write = QString::fromLocal8Bit(p4.readAllStandardOutput()).split(QLatin1Char(' ')).last().trimmed(); + + if(write.isEmpty() || !QFile::exists(write)) + { + QEXPECT_FAIL("", "//depot/autotests/4.4/tests/auto/xmlpatternsxqts/XQTS/ must be part of the perforce client spec, " + "checked out at an arbitrary location, for this test to run. The test suite will now be skipped.", Abort); + QVERIFY(false); + } +} + +QTEST_MAIN(tst_XmlPatternsXQTS) + +#include "tst_xmlpatternsxqts.moc" +#else +QTEST_NOOP_MAIN +#endif + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro b/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro index 3f49ccc..e81888a 100644 --- a/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro +++ b/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro @@ -1,13 +1,21 @@ -TEMPLATE = subdirs +load(qttest_p4) +SOURCES += tst_xmlpatternsxqts.cpp ../qxmlquery/TestFundament.cpp tst_suitetest.cpp + +include(../xmlpatterns.pri) + contains(QT_CONFIG,xmlpatterns) { - SUBDIRS += lib - test.depends = lib + HEADERS += tst_suitetest.h + LIBS += -l$$XMLPATTERNS_SDK } -SUBDIRS += test - -# Needed on the win32-g++ setup and on the test machine arsia. -INCLUDEPATH += $$QT_BUILD_TREE/include/QtXmlPatterns/private \ - ../../../include/QtXmlPatterns/private -requires(contains(QT_CONFIG,private_tests)) +# syncqt doesn't copy headers in tools/ so let's manually ensure +# it works with shadow builds and source builds. +INCLUDEPATH += $$(QTDIR)/include/QtXmlPatterns/private \ + $$(QTSRCDIR)/include/QtXmlPatterns/private \ + $$(QTSRCDIR)/tools/xmlpatterns \ + $$(QTDIR)/tools/xmlpatterns \ + ../xmlpatternssdk/ +CONFIG += testlib +QT += xml +TARGET = tst_xmlpatternsxqts diff --git a/tests/auto/xmlpatternsxslts/xmlpatternsxslts.pro b/tests/auto/xmlpatternsxslts/xmlpatternsxslts.pro index 9b63a52..940cc31 100644 --- a/tests/auto/xmlpatternsxslts/xmlpatternsxslts.pro +++ b/tests/auto/xmlpatternsxslts/xmlpatternsxslts.pro @@ -5,17 +5,17 @@ SOURCES += tst_xmlpatternsxslts.cpp \ include (../xmlpatterns.pri) contains(QT_CONFIG,xmlpatterns) { -HEADERS += ../xmlpatternsxqts/test/tst_suitetest.h -SOURCES += ../xmlpatternsxqts/test/tst_suitetest.cpp +HEADERS += ../xmlpatternsxqts/tst_suitetest.h +SOURCES += ../xmlpatternsxqts/tst_suitetest.cpp LIBS += -l$$XMLPATTERNS_SDK } QT += xml -INCLUDEPATH += $$(QTSRCDIR)/tests/auto/xmlpatternsxqts/lib/ \ - $$(QTDIR)/include/QtXmlPatterns/private \ - $$(QTSRCDIR)/tests/auto/xmlpatternsxqts/test \ - ../xmlpatternsxqts/test \ - ../xmlpatternsxqts/lib +INCLUDEPATH += $$(QTSRCDIR)/tests/auto/xmlpatternssdk \ + $$(QTDIR)/include/QtXmlPatterns/private \ + $$(QTSRCDIR)/tests/auto/xmlpatternsxqts \ + ../xmlpatternsxqts \ + ../xmlpatternssdk wince*: { testdata.sources = XSLTS Baseline.xml -- cgit v0.12 From cc583fef7b9839be7173e039a1162541449e18c2 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 16 Feb 2010 16:57:27 +1000 Subject: Fixed compile of qlibrary test with vcproj generator. COPY and DESTDIR_TARGET are defined by qmake when generating makefiles, but not when generating vcproj files. We need to do something different for the vcproj generator. --- tests/auto/qlibrary/lib2/lib2.pro | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/auto/qlibrary/lib2/lib2.pro b/tests/auto/qlibrary/lib2/lib2.pro index da30a2d..4654f4d 100644 --- a/tests/auto/qlibrary/lib2/lib2.pro +++ b/tests/auto/qlibrary/lib2/lib2.pro @@ -16,14 +16,19 @@ win32-borland: DEFINES += WIN32_BORLAND !symbian { win32 { - src = $(DESTDIR_TARGET) + # vcproj and Makefile generators refer to target differently + contains(TEMPLATE,vc.*) { + src = $(TargetPath) + } else { + src = $(DESTDIR_TARGET) + } files = mylib.dl2 system.trolltech.test.mylib.dll } else { src = $(DESTDIR)$(TARGET) files = libmylib.so2 system.trolltech.test.mylib.so } for(file, files) { - QMAKE_POST_LINK += $(COPY) $$src ..$$QMAKE_DIR_SEP$$file && + QMAKE_POST_LINK += $$QMAKE_COPY $$src ..$$QMAKE_DIR_SEP$$file && CLEAN_FILES += ../$$file } QMAKE_POST_LINK = $$member(QMAKE_POST_LINK, 0, -2) -- cgit v0.12 From 87613a0fb5149b934642c455cf8cae6a373598e3 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 16 Feb 2010 17:02:37 +1000 Subject: Fixed compile of compilerwarnings test with vcproj generator. Rename the test C++ file from `test.cpp' to `test_cpp.txt'. When named `test.cpp', the build system will attempt to build it, which we don't want. --- tests/auto/compilerwarnings/compilerwarnings.qrc | 2 +- tests/auto/compilerwarnings/test.cpp | 67 ---------------------- tests/auto/compilerwarnings/test_cpp.txt | 67 ++++++++++++++++++++++ .../auto/compilerwarnings/tst_compilerwarnings.cpp | 4 +- 4 files changed, 70 insertions(+), 70 deletions(-) delete mode 100644 tests/auto/compilerwarnings/test.cpp create mode 100644 tests/auto/compilerwarnings/test_cpp.txt diff --git a/tests/auto/compilerwarnings/compilerwarnings.qrc b/tests/auto/compilerwarnings/compilerwarnings.qrc index 40fa8f1..3fa313c 100644 --- a/tests/auto/compilerwarnings/compilerwarnings.qrc +++ b/tests/auto/compilerwarnings/compilerwarnings.qrc @@ -1,5 +1,5 @@ - test.cpp + test_cpp.txt diff --git a/tests/auto/compilerwarnings/test.cpp b/tests/auto/compilerwarnings/test.cpp deleted file mode 100644 index 62b35eb..0000000 --- a/tests/auto/compilerwarnings/test.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include -#include -#include -#include -#include - -#ifndef QT_NO_OPENGL -#include -#endif - -#include - -#include - -#if !defined(QT_NO_DBUS) && defined(Q_OS_UNIX) -#include -#endif - -#ifndef Q_OS_MAC -int main(int, char **) -{ - return 0; -} -#endif - diff --git a/tests/auto/compilerwarnings/test_cpp.txt b/tests/auto/compilerwarnings/test_cpp.txt new file mode 100644 index 0000000..62b35eb --- /dev/null +++ b/tests/auto/compilerwarnings/test_cpp.txt @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include +#include +#include +#include + +#ifndef QT_NO_OPENGL +#include +#endif + +#include + +#include + +#if !defined(QT_NO_DBUS) && defined(Q_OS_UNIX) +#include +#endif + +#ifndef Q_OS_MAC +int main(int, char **) +{ + return 0; +} +#endif + diff --git a/tests/auto/compilerwarnings/tst_compilerwarnings.cpp b/tests/auto/compilerwarnings/tst_compilerwarnings.cpp index 27624e9..f910a18 100644 --- a/tests/auto/compilerwarnings/tst_compilerwarnings.cpp +++ b/tests/auto/compilerwarnings/tst_compilerwarnings.cpp @@ -148,7 +148,7 @@ void tst_CompilerWarnings::warnings() if (tmpSourceFile.isEmpty()) { tmpQSourceFile.open(QIODevice::ReadWrite | QIODevice::Truncate); tmpSourceFile = tmpQSourceFile.fileName(); - QFile cppSource(":/test.cpp"); + QFile cppSource(":/test_cpp.txt"); bool openResult = cppSource.open(QIODevice::ReadOnly); if (openResult) { @@ -158,7 +158,7 @@ void tst_CompilerWarnings::warnings() } } tmpQSourceFile.close(); - QVERIFY2(openResult, "Need resource temporary \"test.cpp\""); + QVERIFY2(openResult, "Need resource temporary \"test_cpp.txt\""); QStringList args; QString compilerName; -- cgit v0.12 From 4a1bca54c48087dd7f0f6d0a88c87b9b41283fcf Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Wed, 17 Feb 2010 11:26:09 +1000 Subject: Fixed failure of maketestselftest with vcproj generator. --- tests/auto/maketestselftest/tst_maketestselftest.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/auto/maketestselftest/tst_maketestselftest.cpp b/tests/auto/maketestselftest/tst_maketestselftest.cpp index ef92c56..1dde44b 100644 --- a/tests/auto/maketestselftest/tst_maketestselftest.cpp +++ b/tests/auto/maketestselftest/tst_maketestselftest.cpp @@ -92,7 +92,9 @@ void tst_MakeTestSelfTest::auto_dot_pro_data() QStringList subdirs = dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot); foreach (const QString& subdir, subdirs) { - if (subdir == QString::fromLatin1("tmp")) { + if (subdir == QString::fromLatin1("tmp") + || subdir.startsWith(".")) + { continue; } QTest::newRow(qPrintable(subdir)) << subdir; -- cgit v0.12 From dd745238e17dbdc52417e11a70e74cf6f8e15d04 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Wed, 17 Feb 2010 11:41:03 +0100 Subject: HTTP backend: remove comment the date header always needs to be updated in the cache. Task-number: QTBUG-7466 --- src/network/access/qnetworkaccesshttpbackend.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp index 61a95fe..af971a7 100644 --- a/src/network/access/qnetworkaccesshttpbackend.cpp +++ b/src/network/access/qnetworkaccesshttpbackend.cpp @@ -976,7 +976,7 @@ QNetworkCacheMetaData QNetworkAccessHttpBackend::fetchCacheMetaData(const QNetwo // of writes to disk when using a QNetworkDiskCache (i.e. don't // write to disk when only the date changes). // However, without the date we cannot calculate the age of the page - // anymore. Consider a proper fix of that problem for 4.6.1. + // anymore. //if (header == "date") //continue; -- cgit v0.12 From 729d67cb35830a812c8c41a02a7b16a077dc14fb Mon Sep 17 00:00:00 2001 From: Janne Anttila Date: Wed, 17 Feb 2010 13:04:07 +0200 Subject: Support for dynamic localization in Symbian softkeys. This commit adds support for dynamic i.e. runtime localization of S60 softkeys. Note that translations are not provided yet with qt.sis (QTBUG-4919), meaning that localization does not actually happen unless application developer provides its own translation (including translation for softkeys). Task-number: QTBUG-6785 Reviewed-by: Jason Barron --- src/gui/itemviews/qabstractitemview.cpp | 5 +++++ src/gui/kernel/qsoftkeymanager.cpp | 17 ++++++++--------- src/gui/kernel/qsoftkeymanager_p.h | 2 +- src/gui/widgets/qcombobox.cpp | 4 ++++ src/gui/widgets/qmainwindow.cpp | 5 +++++ src/gui/widgets/qmenu.cpp | 20 +++++++++++++++++--- 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index cbd9a8a..adf3ce3 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -1540,6 +1540,11 @@ bool QAbstractItemView::event(QEvent *event) case QEvent::FontChange: d->doDelayedItemsLayout(); // the size of the items will change break; +#ifdef QT_SOFTKEYS_ENABLED + case QEvent::LanguageChange: + d->doneSoftKey->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::DoneSoftKey)); + break; +#endif default: break; } diff --git a/src/gui/kernel/qsoftkeymanager.cpp b/src/gui/kernel/qsoftkeymanager.cpp index 6d108b0..7412b06 100644 --- a/src/gui/kernel/qsoftkeymanager.cpp +++ b/src/gui/kernel/qsoftkeymanager.cpp @@ -55,24 +55,24 @@ QT_BEGIN_NAMESPACE QSoftKeyManager *QSoftKeyManagerPrivate::self = 0; -const char *QSoftKeyManager::standardSoftKeyText(StandardSoftKey standardKey) +QString QSoftKeyManager::standardSoftKeyText(StandardSoftKey standardKey) { - const char *softKeyText = 0; + QString softKeyText; switch (standardKey) { case OkSoftKey: - softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Ok"); + softKeyText = QSoftKeyManager::tr("Ok"); break; case SelectSoftKey: - softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Select"); + softKeyText = QSoftKeyManager::tr("Select"); break; case DoneSoftKey: - softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Done"); + softKeyText = QSoftKeyManager::tr("Done"); break; case MenuSoftKey: - softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Options"); + softKeyText = QSoftKeyManager::tr("Options"); break; case CancelSoftKey: - softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Cancel"); + softKeyText = QSoftKeyManager::tr("Cancel"); break; default: break; @@ -100,8 +100,7 @@ QSoftKeyManager::QSoftKeyManager() : QAction *QSoftKeyManager::createAction(StandardSoftKey standardKey, QWidget *actionWidget) { - const char* text = standardSoftKeyText(standardKey); - QAction *action = new QAction(QSoftKeyManager::tr(text), actionWidget); + QAction *action = new QAction(standardSoftKeyText(standardKey), actionWidget); QAction::SoftKeyRole softKeyRole = QAction::NoSoftKey; switch (standardKey) { case MenuSoftKey: // FALL-THROUGH diff --git a/src/gui/kernel/qsoftkeymanager_p.h b/src/gui/kernel/qsoftkeymanager_p.h index ce902fe..a6fe17e 100644 --- a/src/gui/kernel/qsoftkeymanager_p.h +++ b/src/gui/kernel/qsoftkeymanager_p.h @@ -87,6 +87,7 @@ public: static QAction *createAction(StandardSoftKey standardKey, QWidget *actionWidget); static QAction *createKeyedAction(StandardSoftKey standardKey, Qt::Key key, QWidget *actionWidget); + static QString standardSoftKeyText(StandardSoftKey standardKey); protected: bool event(QEvent *e); @@ -94,7 +95,6 @@ protected: private: QSoftKeyManager(); static QSoftKeyManager *instance(); - static const char *standardSoftKeyText(StandardSoftKey standardKey); bool appendSoftkeys(const QWidget &source, int level); QWidget *softkeySource(QWidget *previousSource, bool& recursiveMerging); bool handleUpdateSoftKeys(); diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index 72f32dc..c4340e2 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -607,7 +607,11 @@ void QComboBoxPrivateContainer::changeEvent(QEvent *e) view->setMouseTracking(combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) || combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)); setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo)); + } else if (e->type() == QEvent::LanguageChange) { + selectAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::SelectSoftKey)); + cancelAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::CancelSoftKey)); } + QWidget::changeEvent(e); } diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index 269cd12..e7c4f45 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -1426,6 +1426,11 @@ bool QMainWindow::event(QEvent *event) } break; #endif +#ifdef QT_SOFTKEYS_ENABLED + case QEvent::LanguageChange: + d->menuBarAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::MenuSoftKey)); + break; +#endif default: break; } diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index 8ce7cc0..42b7406 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -117,7 +117,7 @@ public: if (parentWidget->parentWidget()) parentWidget = parentWidget->parentWidget(); setParent(parentWidget, Qt::Window | Qt::Tool); - setAttribute(Qt::WA_DeleteOnClose, true); + setAttribute(Qt::WA_DeleteOnClose, true); setAttribute(Qt::WA_X11NetWmWindowTypeMenu, true); setWindowTitle(p->windowTitle()); setEnabled(p->isEnabled()); @@ -1226,7 +1226,7 @@ void QMenu::initStyleOption(QStyleOptionMenuItem *option, const QAction *action) else if (action->isSeparator()) option->menuItemType = QStyleOptionMenuItem::Separator; else if (d->defaultAction == action) - option->menuItemType = QStyleOptionMenuItem::DefaultItem; + option->menuItemType = QStyleOptionMenuItem::DefaultItem; else option->menuItemType = QStyleOptionMenuItem::Normal; if (action->isIconVisibleInMenu()) @@ -1719,7 +1719,14 @@ bool QMenu::isEmpty() const void QMenu::clear() { QList acts = actions(); + for(int i = 0; i < acts.size(); i++) { +#ifdef QT_SOFTKEYS_ENABLED + Q_D(QMenu); + // Lets not touch to our internal softkey actions + if(acts[i] == d->selectAction || acts[i] == d->cancelAction) + continue; +#endif removeAction(acts[i]); if (acts[i]->parent() == this && acts[i]->d_func()->widgets.isEmpty()) delete acts[i]; @@ -2408,6 +2415,13 @@ QMenu::event(QEvent *e) } return true; #endif +#ifdef QT_SOFTKEYS_ENABLED + case QEvent::LanguageChange: { + d->selectAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::SelectSoftKey)); + d->cancelAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::CancelSoftKey)); + } + break; +#endif default: break; } @@ -2919,7 +2933,7 @@ void QMenu::actionEvent(QActionEvent *e) #endif if (isVisible()) { d->updateActionRects(); - resize(sizeHint()); + resize(sizeHint()); update(); } } -- cgit v0.12 From 095496e02610c66d34cf3ee0fc329abed2be47e3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 16 Feb 2010 17:28:40 +0100 Subject: Change all ptrdiff_t to qptrdiff. Reviewed-By: Bradley T. Hughes --- src/corelib/concurrent/qfuture.h | 2 +- src/corelib/tools/qcontiguouscache.h | 2 +- src/corelib/tools/qhash.h | 6 +++--- src/corelib/tools/qlinkedlist.h | 6 +++--- src/corelib/tools/qlist.h | 6 +++--- src/corelib/tools/qmap.h | 6 +++--- src/corelib/tools/qset.h | 7 +++---- src/corelib/tools/qsharedpointer_impl.h | 4 ++-- src/corelib/tools/qvector.h | 6 +++--- 9 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/corelib/concurrent/qfuture.h b/src/corelib/concurrent/qfuture.h index e402335..02ae40a 100644 --- a/src/corelib/concurrent/qfuture.h +++ b/src/corelib/concurrent/qfuture.h @@ -111,7 +111,7 @@ public: { public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h index aa5603d..f767962 100644 --- a/src/corelib/tools/qcontiguouscache.h +++ b/src/corelib/tools/qcontiguouscache.h @@ -97,7 +97,7 @@ public: typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef int size_type; explicit QContiguousCache(int capacity = 0); diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 5e93523..05eae42 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -329,7 +329,7 @@ public: public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef T *pointer; typedef T &reference; @@ -394,7 +394,7 @@ public: public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; @@ -478,7 +478,7 @@ public: // STL compatibility typedef T mapped_type; typedef Key key_type; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef int size_type; inline bool empty() const { return isEmpty(); } diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h index f6de966..bfcf24f 100644 --- a/src/corelib/tools/qlinkedlist.h +++ b/src/corelib/tools/qlinkedlist.h @@ -113,7 +113,7 @@ public: { public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef T *pointer; typedef T &reference; @@ -146,7 +146,7 @@ public: { public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; @@ -212,7 +212,7 @@ public: typedef const value_type *const_pointer; typedef value_type &reference; typedef const value_type &const_reference; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; #ifndef QT_NO_STL static inline QLinkedList fromStdList(const std::list &list) diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 120442d..1ad7528 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -163,7 +163,7 @@ public: public: Node *i; typedef std::random_access_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef T *pointer; typedef T &reference; @@ -210,7 +210,7 @@ public: public: Node *i; typedef std::random_access_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; @@ -289,7 +289,7 @@ public: typedef const value_type *const_pointer; typedef value_type &reference; typedef const value_type &const_reference; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; #ifdef QT3_SUPPORT inline QT3_SUPPORT iterator remove(iterator pos) { return erase(pos); } diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index e71064c..4679812 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -213,7 +213,7 @@ public: public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef T *pointer; typedef T &reference; @@ -281,7 +281,7 @@ public: public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; @@ -384,7 +384,7 @@ public: // STL compatibility typedef Key key_type; typedef T mapped_type; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef int size_type; inline bool empty() const { return isEmpty(); } diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index 6525880..b266deb 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -97,7 +97,7 @@ public: public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; @@ -132,7 +132,7 @@ public: public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; @@ -188,11 +188,10 @@ public: typedef const value_type *const_pointer; typedef value_type &reference; typedef const value_type &const_reference; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef int size_type; inline bool empty() const { return isEmpty(); } - // comfort inline QSet &operator<<(const T &value) { insert(value); return *this; } inline QSet &operator|=(const QSet &other) { unite(other); return *this; } diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 8fbfcda..964b279 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -132,7 +132,7 @@ namespace QtSharedPointer { typedef const value_type *const_pointer; typedef value_type &reference; typedef const value_type &const_reference; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; inline T *data() const { return value; } inline bool isNull() const { return !data(); } @@ -541,7 +541,7 @@ public: typedef const value_type *const_pointer; typedef value_type &reference; typedef const value_type &const_reference; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; inline bool isNull() const { return d == 0 || d->strongref == 0 || value == 0; } #ifndef Q_CC_NOKIAX86 diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 90b7442..ac7c795 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -163,7 +163,7 @@ public: public: T *i; typedef std::random_access_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef T *pointer; typedef T &reference; @@ -196,7 +196,7 @@ public: public: T *i; typedef std::random_access_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; @@ -260,7 +260,7 @@ public: typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef iterator Iterator; typedef const_iterator ConstIterator; typedef int size_type; -- cgit v0.12 From fc1f21b62243bc377889bf142da3b6ecad05aff0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 17 Feb 2010 10:04:19 +0100 Subject: Fix handling of Evaluation licenses on the Windows configure.exe Reviewed-By: Marius Storm-Olsen --- configure.exe | Bin 1180160 -> 1179136 bytes tools/configure/tools.cpp | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) mode change 100644 => 100755 configure.exe diff --git a/configure.exe b/configure.exe old mode 100644 new mode 100755 index 8913de1..09f4ef2 Binary files a/configure.exe and b/configure.exe differ diff --git a/tools/configure/tools.cpp b/tools/configure/tools.cpp index aea2713..c4625af 100644 --- a/tools/configure/tools.cpp +++ b/tools/configure/tools.cpp @@ -146,6 +146,7 @@ void Tools::checkLicense(QMap &dictionary, QMap &dictionary, QMap Date: Wed, 17 Feb 2010 15:11:50 +0100 Subject: Added note to make QList destructor virtual in version 5 Reviewed-by: TrustMe --- src/corelib/tools/qlist.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 1ad7528..a549f2f 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -112,7 +112,7 @@ class QList public: inline QList() : d(&QListData::shared_null) { d->ref.ref(); } inline QList(const QList &l) : d(l.d) { d->ref.ref(); if (!d->sharable) detach_helper(); } - ~QList(); + ~QList(); // ### Qt5: make this destructor virtual QList &operator=(const QList &l); bool operator==(const QList &l) const; inline bool operator!=(const QList &l) const { return !(*this == l); } -- cgit v0.12 From ac523359aa630c05df21d4c09970cb0b89a5b05f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 17 Feb 2010 15:21:46 +0100 Subject: Stabilize QGraphicsItem benchmarks. The benchmark must report stable numbers in order to be useful. E.g. we can not accept instability of +-20% between each run (with the same configuration in the same environment). --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index ac51072..d452593 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -55,6 +55,7 @@ public: virtual ~tst_QGraphicsItem(); public slots: + void initTestCase(); void init(); void cleanup(); @@ -82,8 +83,23 @@ tst_QGraphicsItem::~tst_QGraphicsItem() { } +static inline void processEvents() +{ + QApplication::flush(); + QApplication::processEvents(); + QApplication::processEvents(); +} + +void tst_QGraphicsItem::initTestCase() +{ + QApplication::flush(); + QTest::qWait(1500); + processEvents(); +} + void tst_QGraphicsItem::init() { + processEvents(); } void tst_QGraphicsItem::cleanup() @@ -152,10 +168,10 @@ void tst_QGraphicsItem::setPos() QGraphicsScene scene; QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 100, 100)); + processEvents(); QBENCHMARK { rect->setPos(10, 10); - rect->transform(); // prevent lazy optimizing } } @@ -177,10 +193,10 @@ void tst_QGraphicsItem::setTransform() QGraphicsScene scene; QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + processEvents(); QBENCHMARK { item->setTransform(transform); - item->transform(); // prevent lazy optimizing } } @@ -188,10 +204,10 @@ void tst_QGraphicsItem::rotate() { QGraphicsScene scene; QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + processEvents(); QBENCHMARK { item->rotate(45); - item->transform(); // prevent lazy optimizing } } @@ -199,10 +215,10 @@ void tst_QGraphicsItem::scale() { QGraphicsScene scene; QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + processEvents(); QBENCHMARK { item->scale(2, 2); - item->transform(); // prevent lazy optimizing } } @@ -210,10 +226,10 @@ void tst_QGraphicsItem::shear() { QGraphicsScene scene; QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + processEvents(); QBENCHMARK { item->shear(1.5, 1.5); - item->transform(); // prevent lazy optimizing } } @@ -221,10 +237,10 @@ void tst_QGraphicsItem::translate() { QGraphicsScene scene; QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + processEvents(); QBENCHMARK { item->translate(100, 100); - item->transform(); // prevent lazy optimizing } } @@ -232,10 +248,10 @@ void tst_QGraphicsItem::setRotation() { QGraphicsScene scene; QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + processEvents(); QBENCHMARK { item->setRotation(45); - item->transform(); // prevent lazy optimizing } } -- cgit v0.12 From 2c53e6c50e7f47fa60b6cf8293651f8eaf05ebf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 17 Feb 2010 15:35:36 +0100 Subject: Remove unstable test case from QGraphicsItem::setTransform benchmark. The item's transform is identity by default, so trying to set an indentiy transform again does too little in order to measure it with stable results. --- tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index d452593..ec77eb0 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -179,7 +179,6 @@ void tst_QGraphicsItem::setTransform_data() { QTest::addColumn("transform"); - QTest::newRow("id") << QTransform(); QTest::newRow("rotate 45z") << QTransform().rotate(45); QTest::newRow("scale 2x2") << QTransform().scale(2, 2); QTest::newRow("translate 100, 100") << QTransform().translate(100, 100); -- cgit v0.12 From 9531f924478d78f0a679305cd2e5f1b4c4dd849e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 17 Feb 2010 15:50:44 +0100 Subject: Remove unusable test case from QGraphicsItem benchmark. setRotation() is already covered by the rotate() test case. --- .../gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index ec77eb0..e17cf1c 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -72,7 +72,6 @@ private slots: void scale(); void shear(); void translate(); - void setRotation(); }; tst_QGraphicsItem::tst_QGraphicsItem() @@ -243,16 +242,5 @@ void tst_QGraphicsItem::translate() } } -void tst_QGraphicsItem::setRotation() -{ - QGraphicsScene scene; - QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); - processEvents(); - - QBENCHMARK { - item->setRotation(45); - } -} - QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" -- cgit v0.12 From 59b646dfde1923bbd1f24d7cbb1920d56af7a0b1 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 17 Feb 2010 15:51:44 +0100 Subject: Doc fix, ensure that the \obsolete tag is placed correctly If its not placed in the right place then it will cause the doc to lose the line that \obsolete is on Reviewed-by: TrustMe --- src/gui/graphicsview/qgraphicsview.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 96b9373..06b7438 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -3609,6 +3609,8 @@ void QGraphicsView::drawForeground(QPainter *painter, const QRectF &rect) } /*! + \obsolete + Draws the items \a items in the scene using \a painter, after the background and before the foreground are drawn. \a numItems is the number of items in \a items and options in \a options. \a options is a list of @@ -3617,7 +3619,7 @@ void QGraphicsView::drawForeground(QPainter *painter, const QRectF &rect) The default implementation calls the scene's drawItems() function. - \obsolete Since Qt 4.6, this function is not called anymore unless + Since Qt 4.6, this function is not called anymore unless the QGraphicsView::IndirectPainting flag is given as an Optimization flag. -- cgit v0.12 From cafcb49b3f46915fef5106cfaa14a01079e537bc Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 17 Feb 2010 19:26:37 +0100 Subject: Fix compilation on Mac 32-bit. Reviewed-By: Trust Me --- src/corelib/codecs/qtextcodec.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/codecs/qtextcodec.h b/src/corelib/codecs/qtextcodec.h index 23c91c7..169fe82 100644 --- a/src/corelib/codecs/qtextcodec.h +++ b/src/corelib/codecs/qtextcodec.h @@ -170,7 +170,7 @@ private: friend class QXmlStreamWriter; friend class QXmlStreamWriterPrivate; -#if defined Q_XMLSTREAM_RENAME_SYMBOLS +#if defined(Q_OS_MAC32) || defined(Q_OS_AIX) friend class QCoreXmlStreamWriter; friend class QCoreXmlStreamWriterPrivate; #endif -- cgit v0.12 From ce2f1065693e6944df40d2e04e20e83d59544a15 Mon Sep 17 00:00:00 2001 From: Iain Date: Wed, 17 Feb 2010 18:46:51 +0000 Subject: Use correct (forward slash) separators in qmake-generated bld.inf We should always use forward slash as a directory separator in include paths - it's not OS dependant. Task-number: QTBUG-8308 Reviewed-by: Alessandro Portale --- qmake/generators/symbian/symmake.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qmake/generators/symbian/symmake.cpp b/qmake/generators/symbian/symmake.cpp index 61988d3..2055f81 100644 --- a/qmake/generators/symbian/symmake.cpp +++ b/qmake/generators/symbian/symmake.cpp @@ -1348,7 +1348,7 @@ void SymbianMakefileGenerator::writeBldInfContent(QTextStream &t, bool addDeploy removeSpecialCharacters(bldinfDefine); t << "#ifndef " << bldinfDefine << endl; - t << "\t#include \"" << QDir::toNativeSeparators(bldinfFilename) << "\"" << endl; + t << "\t#include \"" << bldinfFilename << "\"" << endl; t << "#endif // " << bldinfDefine << endl; } -- cgit v0.12 From 48d25e6c9fcb5644ff6d9fdbe876c0a49413c583 Mon Sep 17 00:00:00 2001 From: Janne Anttila Date: Thu, 18 Feb 2010 09:52:54 +0200 Subject: Fixed softkey localizaton to comile also on platforms without softkeys. Task-number: QTBUG-6785 Reviewed-by: TrustMe --- src/gui/widgets/qcombobox.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index c4340e2..585db70 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -607,9 +607,11 @@ void QComboBoxPrivateContainer::changeEvent(QEvent *e) view->setMouseTracking(combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) || combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)); setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo)); +#ifdef QT_SOFTKEYS_ENABLED } else if (e->type() == QEvent::LanguageChange) { selectAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::SelectSoftKey)); cancelAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::CancelSoftKey)); +#endif } QWidget::changeEvent(e); -- cgit v0.12 From 342b916ab4fb1a9c6f3a2608e7c5a43d6a763981 Mon Sep 17 00:00:00 2001 From: Iain Date: Thu, 18 Feb 2010 09:03:49 +0000 Subject: Use correct include path for qglobal.h Reviewed-by: Shane Kearns --- src/corelib/arch/qatomic_symbian.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/arch/qatomic_symbian.h b/src/corelib/arch/qatomic_symbian.h index f1d332f..fa4e4a9 100644 --- a/src/corelib/arch/qatomic_symbian.h +++ b/src/corelib/arch/qatomic_symbian.h @@ -42,7 +42,7 @@ #ifndef QATOMIC_SYMBIAN_H #define QATOMIC_SYMBIAN_H -#include +#include #include QT_BEGIN_HEADER -- cgit v0.12 From a359db8f939ccbe8ce49c2ef71ff4585ab69c15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Wed, 17 Feb 2010 17:12:57 +0100 Subject: Fixed autotest failure in tst_QPainter::drawEllipse on Maemo. The previous fix (baa7c3bdecc) attempted to fall back to path drawing in QPainter::drawEllipse, however we have some specific filling rules for aliased ellipse drawing in the raster paint engine. We should use the (now free of fixed point math) drawEllipse_midpoint_i function on all platforms. Reviewed-by: Gunnar Sletta --- src/gui/painting/qpaintengine_raster.cpp | 8 -------- tests/auto/qpainter/tst_qpainter.cpp | 2 -- 2 files changed, 10 deletions(-) diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 4a4792a..3c2cc8c 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -100,10 +100,6 @@ #endif #include -#if defined(QT_NO_FPU) || (_MSC_VER >= 1300 && _MSC_VER < 1400) -# define FLOATING_POINT_BUGGY_OR_NO_FPU -#endif - QT_BEGIN_NAMESPACE extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp @@ -1827,7 +1823,6 @@ void QRasterPaintEngine::fill(const QVectorPath &path, const QBrush &brush) } } -#ifndef FLOATING_POINT_BUGGY_OR_NO_FPU if (path.shape() == QVectorPath::EllipseHint) { if (!s->flags.antialiased && s->matrix.type() <= QTransform::TxScale) { const qreal *p = path.points(); @@ -1847,7 +1842,6 @@ void QRasterPaintEngine::fill(const QVectorPath &path, const QBrush &brush) } } } -#endif // ### Optimize for non transformed ellipses and rectangles... QRectF cpRect = path.controlPointRect(); @@ -3674,7 +3668,6 @@ void QRasterPaintEngine::drawLines(const QLineF *lines, int lineCount) */ void QRasterPaintEngine::drawEllipse(const QRectF &rect) { -#ifndef FLOATING_POINT_BUGGY_OR_NO_FPU Q_D(QRasterPaintEngine); QRasterPaintEngineState *s = state(); @@ -3697,7 +3690,6 @@ void QRasterPaintEngine::drawEllipse(const QRectF &rect) return; } } -#endif QPaintEngineEx::drawEllipse(rect); } diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index 104728d..beb83a1 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -1580,10 +1580,8 @@ void tst_QPainter::drawClippedEllipse_data() void tst_QPainter::drawClippedEllipse() { QFETCH(QRect, rect); -#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) if (sizeof(qreal) != sizeof(double)) QSKIP("Test only works for qreal==double", SkipAll); -#endif QImage image(rect.width() + 1, rect.height() + 1, QImage::Format_ARGB32_Premultiplied); QRect expected = QRect(rect.x(), rect.y(), rect.width()+1, rect.height()+1) -- cgit v0.12 From 08a40e6d4ef085c13d95c300c4df6b19caf7c483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 18 Feb 2010 10:10:39 +0100 Subject: Documented behavior of blur effect radius and drop shadow offset. Our graphics effects are always done in device coordinates (unless they can be done in logical coordinates with the same result as an optimization, e.g. opacity effects). Reviewed-by: Andy Shaw --- src/gui/effects/qgraphicseffect.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gui/effects/qgraphicseffect.cpp b/src/gui/effects/qgraphicseffect.cpp index 7d1d03d..ce4ce6a 100644 --- a/src/gui/effects/qgraphicseffect.cpp +++ b/src/gui/effects/qgraphicseffect.cpp @@ -726,7 +726,8 @@ void QGraphicsColorizeEffect::draw(QPainter *painter) elements. The level of detail can be modified using the setBlurRadius() function. Use setBlurHints() to choose the blur hints. - By default, the blur radius is 5 pixels. + By default, the blur radius is 5 pixels. The blur radius is specified in + device coordinates. \img graphicseffect-blur.png @@ -781,6 +782,9 @@ QGraphicsBlurEffect::~QGraphicsBlurEffect() radius results in a more blurred appearance. By default, the blur radius is 5 pixels. + + The radius is given in device coordinates, meaning it is + unaffected by scale. */ qreal QGraphicsBlurEffect::blurRadius() const { @@ -884,7 +888,8 @@ void QGraphicsBlurEffect::draw(QPainter *painter) By default, the drop shadow is a semi-transparent dark gray (QColor(63, 63, 63, 180)) shadow, blurred with a radius of 1 at an offset - of 8 pixels towards the lower right. + of 8 pixels towards the lower right. The drop shadow offset is specified + in device coordinates. \img graphicseffect-drop-shadow.png @@ -913,6 +918,9 @@ QGraphicsDropShadowEffect::~QGraphicsDropShadowEffect() By default, the offset is 8 pixels towards the lower right. + The offset is given in device coordinates, which means it is + unaffected by scale. + \sa xOffset(), yOffset(), blurRadius(), color() */ QPointF QGraphicsDropShadowEffect::offset() const -- cgit v0.12 From a6eac63470ad8dd3f1687fcd4039a5312c44a5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 17 Feb 2010 15:59:49 +0100 Subject: Compiler warning, unusable variable in tst_QGraphicsScene benchmark. --- tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index 5bd07f9..9531619 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -209,7 +209,6 @@ void tst_QGraphicsScene::itemAt() if (!sceneRect.isNull()) scene.setSceneRect(sceneRect); - QGraphicsItem *item = 0; for (int y = 0; y < numItems_Y; ++y) { for (int x = 0; x < numItems_X; ++x) { QGraphicsRectItem *item = new QGraphicsRectItem(itemRect); -- cgit v0.12 From 5c4363a0fa3cd654413ff2637cb70aeec7a590ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 17 Feb 2010 16:12:09 +0100 Subject: Stabilize QGraphicsScene benchmarks. --- .../gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index 9531619..10d73d5 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -75,8 +75,16 @@ tst_QGraphicsScene::~tst_QGraphicsScene() { } +static inline void processEvents() +{ + QApplication::flush(); + QApplication::processEvents(); + QApplication::processEvents(); +} + void tst_QGraphicsScene::init() { + processEvents(); } void tst_QGraphicsScene::cleanup() @@ -148,6 +156,8 @@ void tst_QGraphicsScene::addItem() if (!sceneRect.isNull()) scene.setSceneRect(sceneRect); + processEvents(); + QBENCHMARK { QGraphicsItem *item = 0; for (int y = 0; y < numItems_Y; ++y) { @@ -218,9 +228,11 @@ void tst_QGraphicsScene::itemAt() } scene.itemAt(0, 0); // triggers indexing + processEvents(); + QGraphicsItem *item = 0; QBENCHMARK { - scene.itemAt(0, 0); + item = scene.itemAt(0, 0); } //let QGraphicsScene::_q_polishItems be called so ~QGraphicsItem doesn't spend all his time cleaning the unpolished list -- cgit v0.12 From b77624c18896e149f338cb512369215b11bba685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 17 Feb 2010 16:30:52 +0100 Subject: Compiler warnings in QGraphicsView benchmark. --- .../gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 10e00a6..267fecc 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -560,7 +560,7 @@ void tst_QGraphicsView::imageRiver() #else for (int i = 0; i < 100; ++i) { #endif - AnimatedPixmapItem *item; + AnimatedPixmapItem *item = 0; if (direction == 0) item = new AnimatedPixmapItem((i % 4) + 1, 0, rotation, scale); if (direction == 1) item = new AnimatedPixmapItem(0, (i % 4) + 1, rotation, scale); if (direction == 2) item = new AnimatedPixmapItem((i % 4) + 1, (i % 4) + 1, rotation, scale); @@ -682,7 +682,7 @@ void tst_QGraphicsView::textRiver() #else for (int i = 0; i < 100; ++i) { #endif - AnimatedTextItem *item; + AnimatedTextItem *item = 0; if (direction == 0) item = new AnimatedTextItem((i % 4) + 1, 0, rotation, scale); if (direction == 1) item = new AnimatedTextItem(0, (i % 4) + 1, rotation, scale); if (direction == 2) item = new AnimatedTextItem((i % 4) + 1, (i % 4) + 1, rotation, scale); @@ -792,7 +792,7 @@ void tst_QGraphicsView::moveItemCache() #else for (int i = 0; i < 50; ++i) { #endif - AnimatedPixmapCacheItem *item; + AnimatedPixmapCacheItem *item = 0; if (direction == 0) item = new AnimatedPixmapCacheItem((i % 4) + 1, 0); if (direction == 1) item = new AnimatedPixmapCacheItem(0, (i % 4) + 1); if (direction == 2) item = new AnimatedPixmapCacheItem((i % 4) + 1, (i % 4) + 1); @@ -843,6 +843,7 @@ public: protected: void advance(int i) { + Q_UNUSED(i); if (partial) update(QRectF(boundingRect().center().x(), boundingRect().center().x(), 30, 30)); else -- cgit v0.12 From f9a790fcac5222c89797e896ed14cd5b4ccd1fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 17 Feb 2010 16:43:04 +0100 Subject: Remove platform dependent code from QGraphicsView benchmark. First, it doesn't make much sense to have platform specific code like this in a benchmark. Second, the Q_OS_SYMBIAN specific values makes more sense anyways, so we can use them on all platforms. --- .../qgraphicsview/tst_qgraphicsview.cpp | 34 +--------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 267fecc..235afef 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -170,11 +170,7 @@ void tst_QGraphicsView::paintSingleItem() } } -#ifdef Q_OS_SYMBIAN -# define DEEP_STACKING_COUNT 85 -#else -# define DEEP_STACKING_COUNT 1000 -#endif +#define DEEP_STACKING_COUNT 85 void tst_QGraphicsView::paintDeepStackingItems() { @@ -555,11 +551,7 @@ void tst_QGraphicsView::imageRiver() QFile file(":/random.data"); QVERIFY(file.open(QIODevice::ReadOnly)); QDataStream str(&file); -#if defined(Q_OS_SYMBIAN) for (int i = 0; i < 50; ++i) { -#else - for (int i = 0; i < 100; ++i) { -#endif AnimatedPixmapItem *item = 0; if (direction == 0) item = new AnimatedPixmapItem((i % 4) + 1, 0, rotation, scale); if (direction == 1) item = new AnimatedPixmapItem(0, (i % 4) + 1, rotation, scale); @@ -578,11 +570,7 @@ void tst_QGraphicsView::imageRiver() #ifdef CALLGRIND_DEBUG CALLGRIND_START_INSTRUMENTATION #endif -#if defined(Q_OS_SYMBIAN) for (int i = 0; i < 50; ++i) { -#else - for (int i = 0; i < 100; ++i) { -#endif scene.advance(); while (view.count < (i+1)) qApp->processEvents(); @@ -677,11 +665,7 @@ void tst_QGraphicsView::textRiver() QFile file(":/random.data"); QVERIFY(file.open(QIODevice::ReadOnly)); QDataStream str(&file); -#if defined(Q_OS_SYMBIAN) for (int i = 0; i < 50; ++i) { -#else - for (int i = 0; i < 100; ++i) { -#endif AnimatedTextItem *item = 0; if (direction == 0) item = new AnimatedTextItem((i % 4) + 1, 0, rotation, scale); if (direction == 1) item = new AnimatedTextItem(0, (i % 4) + 1, rotation, scale); @@ -699,11 +683,7 @@ void tst_QGraphicsView::textRiver() #ifdef CALLGRIND_DEBUG CALLGRIND_START_INSTRUMENTATION #endif -#if defined(Q_OS_SYMBIAN) for (int i = 0; i < 50; ++i) { -#else - for (int i = 0; i < 100; ++i) { -#endif scene.advance(); while (view.count < (i+1)) qApp->processEvents(); @@ -787,11 +767,7 @@ void tst_QGraphicsView::moveItemCache() QFile file(":/random.data"); QVERIFY(file.open(QIODevice::ReadOnly)); QDataStream str(&file); -#if defined(Q_OS_SYMBIAN) for (int i = 0; i < 5; ++i) { -#else - for (int i = 0; i < 50; ++i) { -#endif AnimatedPixmapCacheItem *item = 0; if (direction == 0) item = new AnimatedPixmapCacheItem((i % 4) + 1, 0); if (direction == 1) item = new AnimatedPixmapCacheItem(0, (i % 4) + 1); @@ -813,11 +789,7 @@ void tst_QGraphicsView::moveItemCache() #ifdef CALLGRIND_DEBUG CALLGRIND_START_INSTRUMENTATION #endif -#if defined(Q_OS_SYMBIAN) for (int i = 0; i < 50; ++i) { -#else - for (int i = 0; i < 100; ++i) { -#endif scene.advance(); while (view.count < (i+1)) qApp->processEvents(); @@ -918,11 +890,7 @@ void tst_QGraphicsView::paintItemCache() #ifdef CALLGRIND_DEBUG CALLGRIND_START_INSTRUMENTATION #endif -#if defined(Q_OS_SYMBIAN) for (int i = 0; i < 5; ++i) { -#else - for (int i = 0; i < 50; ++i) { -#endif scene.advance(); while (view.count < (i+1)) qApp->processEvents(); -- cgit v0.12 From b37def83cb97dec7167f99a53dfada1b48dee59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Thu, 18 Feb 2010 16:13:14 +0100 Subject: Stabilize QGraphicsView benchmarks. --- .../qgraphicsview/tst_qgraphicsview.cpp | 259 +++++++++++---------- 1 file changed, 134 insertions(+), 125 deletions(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 235afef..3c0ae71 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -45,11 +45,7 @@ #include #include #include -#ifdef Q_WS_X11 -QT_BEGIN_NAMESPACE -extern void qt_x11_wait_for_window_manager(QWidget *); -QT_END_NAMESPACE -#endif + #include "chiptester/chiptester.h" //#define CALLGRIND_DEBUG #ifdef CALLGRIND_DEBUG @@ -58,34 +54,65 @@ QT_END_NAMESPACE //TESTED_FILES= -class QEventWaiter : public QEventLoop +static inline void processEvents() { + QPixmapCache::clear(); + QApplication::flush(); + QApplication::processEvents(); + QApplication::processEvents(); +} + +class TestView : public QGraphicsView +{ + Q_OBJECT public: - QEventWaiter(QObject *receiver, QEvent::Type type) - : waiting(false), t(type) - { - receiver->installEventFilter(this); - } + TestView() : QGraphicsView(), waiting(false), timerId(-1) + {} - void wait() + void waitForPaintEvent(int timeout = 4000) { + if (waiting) + return; waiting = true; - exec(); + timerId = startTimer(timeout); + eventLoop.exec(); + killTimer(timerId); + timerId = -1; + waiting = false; } - bool eventFilter(QObject *receiver, QEvent *event) + void tryResize(int width, int height) { - Q_UNUSED(receiver); - if (waiting && event->type() == t) { - waiting = false; - exit(); + QDesktopWidget *desktop = QApplication::desktop(); + if (desktop->width() < width) + width = desktop->width(); + if (desktop->height() < height) + height = desktop->height(); + if (size() != QSize(width, height)) { + resize(width, height); + QTest::qWait(250); + processEvents(); } - return false; + } + +protected: + void paintEvent(QPaintEvent *event) + { + QGraphicsView::paintEvent(event); + if (waiting) + eventLoop.exit(); + } + + void timerEvent(QTimerEvent *event) + { + if (event->timerId() == timerId) + eventLoop.exit(); } private: + QEventLoop eventLoop; bool waiting; - QEvent::Type t; + int timerId; }; class tst_QGraphicsView : public QObject @@ -97,6 +124,7 @@ public: virtual ~tst_QGraphicsView(); public slots: + void initTestCase(); void init(); void cleanup(); @@ -126,6 +154,9 @@ private slots: void moveItemCache(); void paintItemCache_data(); void paintItemCache(); + +private: + TestView mView; }; tst_QGraphicsView::tst_QGraphicsView() @@ -136,8 +167,25 @@ tst_QGraphicsView::~tst_QGraphicsView() { } +void tst_QGraphicsView::initTestCase() +{ + mView.setFrameStyle(0); + mView.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + mView.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + mView.tryResize(100, 100); + mView.show(); + QTest::qWaitForWindowShown(&mView); + QTest::qWait(300); + processEvents(); +} + void tst_QGraphicsView::init() { + mView.setRenderHints(QPainter::RenderHints(0)); + mView.viewport()->setMouseTracking(false); + mView.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); + for (int i = 0; i < 3; ++i) + processEvents(); } void tst_QGraphicsView::cleanup() @@ -156,17 +204,14 @@ void tst_QGraphicsView::paintSingleItem() QGraphicsScene scene(0, 0, 100, 100); scene.addRect(0, 0, 10, 10); - QGraphicsView view(&scene); - view.show(); - view.resize(100, 100); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(&view); -#endif + mView.setScene(&scene); + mView.tryResize(100, 100); + processEvents(); QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); QPainter painter(&image); QBENCHMARK { - view.viewport()->render(&painter); + mView.viewport()->render(&painter); } } @@ -184,17 +229,14 @@ void tst_QGraphicsView::paintDeepStackingItems() lastRect = rect; } - QGraphicsView view(&scene); - view.show(); - view.resize(100, 100); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(&view); -#endif + mView.setScene(&scene); + mView.tryResize(100, 100); + processEvents(); QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); QPainter painter(&image); QBENCHMARK { - view.viewport()->render(&painter); + mView.viewport()->render(&painter); } } @@ -211,17 +253,14 @@ void tst_QGraphicsView::paintDeepStackingItems_clipped() lastRect = rect; } - QGraphicsView view(&scene); - view.show(); - view.resize(100, 100); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(&view); -#endif + mView.setScene(&scene); + mView.tryResize(100, 100); + processEvents(); QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); QPainter painter(&image); QBENCHMARK { - view.viewport()->render(&painter); + mView.viewport()->render(&painter); } } @@ -230,18 +269,14 @@ void tst_QGraphicsView::moveSingleItem() QGraphicsScene scene(0, 0, 100, 100); QGraphicsRectItem *item = scene.addRect(0, 0, 10, 10); - QGraphicsView view(&scene); - view.show(); - view.resize(100, 100); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(&view); -#endif + mView.setScene(&scene); + mView.tryResize(100, 100); + processEvents(); - QEventWaiter waiter(view.viewport(), QEvent::Paint); int n = 1; QBENCHMARK { item->setPos(25 * n, 25 * n); - waiter.wait(); + mView.waitForPaintEvent(); n = n ? 0 : 1; } } @@ -267,6 +302,8 @@ void tst_QGraphicsView::mapPointToScene() QGraphicsView view; view.setTransform(transform); + processEvents(); + QBENCHMARK { view.mapToScene(point); } @@ -293,6 +330,8 @@ void tst_QGraphicsView::mapPointFromScene() QGraphicsView view; view.setTransform(transform); + processEvents(); + QBENCHMARK { view.mapFromScene(point); } @@ -319,6 +358,8 @@ void tst_QGraphicsView::mapRectToScene() QGraphicsView view; view.setTransform(transform); + processEvents(); + QBENCHMARK { view.mapToScene(rect); } @@ -345,6 +386,8 @@ void tst_QGraphicsView::mapRectFromScene() QGraphicsView view; view.setTransform(transform); + processEvents(); + QBENCHMARK { view.mapFromScene(rect); } @@ -376,13 +419,14 @@ void tst_QGraphicsView::chipTester() QFETCH(int, operation); ChipTester tester; - tester.show(); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(&tester); -#endif tester.setAntialias(antialias); tester.setOpenGL(opengl); tester.setOperation(ChipTester::Operation(operation)); + tester.show(); + QTest::qWaitForWindowShown(&tester); + QTest::qWait(250); + processEvents(); + QBENCHMARK { tester.runBenchmark(); } @@ -432,20 +476,20 @@ void tst_QGraphicsView::deepNesting() } scene.setItemIndexMethod(bsp ? QGraphicsScene::BspTreeIndex : QGraphicsScene::NoIndex); scene.setSortCacheEnabled(sortCache); + scene.setSceneRect(scene.sceneRect()); - QGraphicsView view(&scene); - view.setRenderHint(QPainter::Antialiasing); - view.show(); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(&view); -#endif - QTest::qWait(250); + mView.setRenderHint(QPainter::Antialiasing); + mView.setScene(&scene); + mView.tryResize(600, 600); + (void)scene.itemAt(0, 0); + processEvents(); QBENCHMARK { #ifdef CALLGRIND_DEBUG CALLGRIND_START_INSTRUMENTATION #endif - view.viewport()->repaint(); + mView.viewport()->update(); + mView.waitForPaintEvent(); #ifdef CALLGRIND_DEBUG CALLGRIND_STOP_INSTRUMENTATION #endif @@ -499,23 +543,6 @@ private: bool scale; }; -class CountPaintEventView : public QGraphicsView -{ -public: - CountPaintEventView(QGraphicsScene *scene = 0) - : QGraphicsView(scene), count(0) - { } - - int count; - -protected: - void paintEvent(QPaintEvent *event) - { - ++count; - QGraphicsView::paintEvent(event); - }; -}; - void tst_QGraphicsView::imageRiver_data() { QTest::addColumn("direction"); @@ -537,13 +564,6 @@ void tst_QGraphicsView::imageRiver() QGraphicsScene scene(0, 0, 300, 300); - CountPaintEventView view(&scene); - view.resize(300, 300); - view.setFrameStyle(0); - view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.show(); - QPixmap pix(":/images/designer.png"); QVERIFY(!pix.isNull()); @@ -559,12 +579,15 @@ void tst_QGraphicsView::imageRiver() item->setPixmap(pix); int rnd1, rnd2; str >> rnd1 >> rnd2; - item->setPos(-pix.width() + rnd1 % (view.width() + pix.width()), - -pix.height() + rnd2 % (view.height() + pix.height())); + item->setPos(-pix.width() + rnd1 % (300 + pix.width()), + -pix.height() + rnd2 % (300 + pix.height())); scene.addItem(item); } + scene.setSceneRect(0, 0, 300, 300); - view.count = 0; + mView.setScene(&scene); + mView.tryResize(300, 300); + processEvents(); QBENCHMARK { #ifdef CALLGRIND_DEBUG @@ -572,8 +595,7 @@ void tst_QGraphicsView::imageRiver() #endif for (int i = 0; i < 50; ++i) { scene.advance(); - while (view.count < (i+1)) - qApp->processEvents(); + mView.waitForPaintEvent(); } #ifdef CALLGRIND_DEBUG CALLGRIND_STOP_INSTRUMENTATION @@ -651,13 +673,6 @@ void tst_QGraphicsView::textRiver() QGraphicsScene scene(0, 0, 300, 300); - CountPaintEventView view(&scene); - view.resize(300, 300); - view.setFrameStyle(0); - view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.show(); - QPixmap pix(":/images/designer.png"); QVERIFY(!pix.isNull()); @@ -672,12 +687,17 @@ void tst_QGraphicsView::textRiver() if (direction == 2) item = new AnimatedTextItem((i % 4) + 1, (i % 4) + 1, rotation, scale); int rnd1, rnd2; str >> rnd1 >> rnd2; - item->setPos(-pix.width() + rnd1 % (view.width() + pix.width()), - -pix.height() + rnd2 % (view.height() + pix.height())); + item->setPos(-pix.width() + rnd1 % (300 + pix.width()), + -pix.height() + rnd2 % (300 + pix.height())); + item->setAcceptDrops(false); + item->setAcceptHoverEvents(false); scene.addItem(item); } + scene.setSceneRect(0, 0, 300, 300); - view.count = 0; + mView.setScene(&scene); + mView.tryResize(300, 300); + processEvents(); QBENCHMARK { #ifdef CALLGRIND_DEBUG @@ -685,8 +705,7 @@ void tst_QGraphicsView::textRiver() #endif for (int i = 0; i < 50; ++i) { scene.advance(); - while (view.count < (i+1)) - qApp->processEvents(); + mView.waitForPaintEvent(); } #ifdef CALLGRIND_DEBUG CALLGRIND_STOP_INSTRUMENTATION @@ -753,13 +772,6 @@ void tst_QGraphicsView::moveItemCache() QGraphicsScene scene(0, 0, 300, 300); - CountPaintEventView view(&scene); - view.resize(600, 600); - view.setFrameStyle(0); - view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.show(); - QPixmap pix(":/images/wine.jpeg"); QVERIFY(!pix.isNull()); @@ -778,21 +790,23 @@ void tst_QGraphicsView::moveItemCache() item->setTransform(QTransform().rotate(45)); int rnd1, rnd2; str >> rnd1 >> rnd2; - item->setPos(-pix.width() + rnd1 % (view.width() + pix.width()), - -pix.height() + rnd2 % (view.height() + pix.height())); + item->setPos(-pix.width() + rnd1 % (400 + pix.width()), + -pix.height() + rnd2 % (400 + pix.height())); scene.addItem(item); } + scene.setSceneRect(0, 0, 400, 400); - view.count = 0; + mView.setScene(&scene); + mView.tryResize(400, 400); + processEvents(); QBENCHMARK { #ifdef CALLGRIND_DEBUG CALLGRIND_START_INSTRUMENTATION #endif - for (int i = 0; i < 50; ++i) { + for (int i = 0; i < 5; ++i) { scene.advance(); - while (view.count < (i+1)) - qApp->processEvents(); + mView.waitForPaintEvent(); } #ifdef CALLGRIND_DEBUG CALLGRIND_STOP_INSTRUMENTATION @@ -853,13 +867,6 @@ void tst_QGraphicsView::paintItemCache() QGraphicsScene scene(0, 0, 300, 300); - CountPaintEventView view(&scene); - view.resize(600, 600); - view.setFrameStyle(0); - view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.show(); - QPixmap pix(":/images/wine.jpeg"); QVERIFY(!pix.isNull()); @@ -883,8 +890,11 @@ void tst_QGraphicsView::paintItemCache() item->setTransform(QTransform().rotate(45)); item->setPos(0, 0); scene.addItem(item); + scene.setSceneRect(-100, -100, 600, 600); - view.count = 0; + mView.tryResize(600, 600); + mView.setScene(&scene); + processEvents(); QBENCHMARK { #ifdef CALLGRIND_DEBUG @@ -892,8 +902,7 @@ void tst_QGraphicsView::paintItemCache() #endif for (int i = 0; i < 5; ++i) { scene.advance(); - while (view.count < (i+1)) - qApp->processEvents(); + mView.waitForPaintEvent(); } #ifdef CALLGRIND_DEBUG CALLGRIND_STOP_INSTRUMENTATION -- cgit v0.12 From 059be19781a22d2e41f22072152589857d0fabf9 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Thu, 18 Feb 2010 16:21:42 +0100 Subject: Fixed a regression in dockwidgets that would jump when toplevel resized This was reproducible when the main window doesn't contain a central widget. Task-number: QTBUG-8107 Reviewed-by: ogoffart --- src/gui/widgets/qdockarealayout.cpp | 2 +- src/gui/widgets/qmainwindowlayout.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qdockarealayout.cpp b/src/gui/widgets/qdockarealayout.cpp index d754800..0c39f42 100644 --- a/src/gui/widgets/qdockarealayout.cpp +++ b/src/gui/widgets/qdockarealayout.cpp @@ -2635,7 +2635,7 @@ void QDockAreaLayout::getGrid(QVector *_ver_struct_list, QSize bottom_max = docks[QInternal::BottomDock].maximumSize(); bottom_hint = bottom_hint.boundedTo(bottom_max).expandedTo(bottom_min); - fallbackToSizeHints = !have_central; + fallbackToSizeHints = false; if (_ver_struct_list != 0) { QVector &ver_struct_list = *_ver_struct_list; diff --git a/src/gui/widgets/qmainwindowlayout.cpp b/src/gui/widgets/qmainwindowlayout.cpp index fc75c92..593e391 100644 --- a/src/gui/widgets/qmainwindowlayout.cpp +++ b/src/gui/widgets/qmainwindowlayout.cpp @@ -1772,6 +1772,7 @@ void QMainWindowLayout::setCentralWidget(QWidget *widget) if (savedState.isValid()) { #ifndef QT_NO_DOCKWIDGET savedState.dockAreaLayout.centralWidgetItem = layoutState.dockAreaLayout.centralWidgetItem; + savedState.dockAreaLayout.fallbackToSizeHints = true; #else savedState.centralWidgetItem = layoutState.centralWidgetItem; #endif -- cgit v0.12 From 3a1ad930266b7b10c04ee0481e6fa6b0b6bed739 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Thu, 18 Feb 2010 17:08:29 +0100 Subject: Always use display() in QEglContext, so initialization can occur Reviewed-By: Trustme --- src/gui/egl/qegl.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/gui/egl/qegl.cpp b/src/gui/egl/qegl.cpp index 4d447cb..0ed95ea 100644 --- a/src/gui/egl/qegl.cpp +++ b/src/gui/egl/qegl.cpp @@ -101,7 +101,7 @@ bool QEglContext::chooseConfig // If we want the best pixel format, then return the first // matching configuration. if (match == QEgl::BestPixelFormat) { - eglChooseConfig(dpy, props.properties(), &cfg, 1, &matching); + eglChooseConfig(display(), props.properties(), &cfg, 1, &matching); if (matching < 1) continue; return true; @@ -111,13 +111,13 @@ bool QEglContext::chooseConfig // first that matches the pixel format we wanted. EGLint size = matching; EGLConfig *configs = new EGLConfig [size]; - eglChooseConfig(dpy, props.properties(), configs, size, &matching); + eglChooseConfig(display(), props.properties(), configs, size, &matching); for (EGLint index = 0; index < size; ++index) { EGLint red, green, blue, alpha; - eglGetConfigAttrib(dpy, configs[index], EGL_RED_SIZE, &red); - eglGetConfigAttrib(dpy, configs[index], EGL_GREEN_SIZE, &green); - eglGetConfigAttrib(dpy, configs[index], EGL_BLUE_SIZE, &blue); - eglGetConfigAttrib(dpy, configs[index], EGL_ALPHA_SIZE, &alpha); + eglGetConfigAttrib(display(), configs[index], EGL_RED_SIZE, &red); + eglGetConfigAttrib(display(), configs[index], EGL_GREEN_SIZE, &green); + eglGetConfigAttrib(display(), configs[index], EGL_BLUE_SIZE, &blue); + eglGetConfigAttrib(display(), configs[index], EGL_ALPHA_SIZE, &alpha); if (red == props.value(EGL_RED_SIZE) && green == props.value(EGL_GREEN_SIZE) && blue == props.value(EGL_BLUE_SIZE) && @@ -181,7 +181,7 @@ bool QEglContext::createContext(QEglContext *shareContext, const QEglProperties } } if (ctx == EGL_NO_CONTEXT) { - ctx = eglCreateContext(dpy, cfg, 0, contextProps.properties()); + ctx = eglCreateContext(display(), cfg, 0, contextProps.properties()); if (ctx == EGL_NO_CONTEXT) { qWarning() << "QEglContext::createContext(): Unable to create EGL context:" << errorString(eglGetError()); return false; @@ -197,7 +197,7 @@ void QEglContext::destroySurface(EGLSurface surface) if (surface != EGL_NO_SURFACE) { if (surface == currentSurface) doneCurrent(); - eglDestroySurface(dpy, surface); + eglDestroySurface(display(), surface); } } @@ -205,8 +205,7 @@ void QEglContext::destroySurface(EGLSurface surface) void QEglContext::destroyContext() { if (ctx != EGL_NO_CONTEXT && ownsContext) - eglDestroyContext(dpy, ctx); - dpy = EGL_NO_DISPLAY; + eglDestroyContext(display(), ctx); ctx = EGL_NO_CONTEXT; cfg = 0; } @@ -343,7 +342,7 @@ QEglProperties QEglContext::configProperties(EGLConfig cfg) const QEglProperties props; for (int name = 0x3020; name <= 0x304F; ++name) { EGLint value; - if (name != EGL_NONE && eglGetConfigAttrib(dpy, cfg, name, &value)) + if (name != EGL_NONE && eglGetConfigAttrib(display(), cfg, name, &value)) props.setValue(name, value); } eglGetError(); // Clear the error state. @@ -417,7 +416,7 @@ void QEglContext::dumpAllConfigs() if (!eglGetConfigs(display(), 0, 0, &count) || count < 1) return; EGLConfig *configs = new EGLConfig [count]; - eglGetConfigs(dpy, configs, count, &count); + eglGetConfigs(display(), configs, count, &count); for (EGLint index = 0; index < count; ++index) { props = configProperties(configs[index]); qWarning() << props.toString(); -- cgit v0.12