summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-06-29 22:16:34 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-07-01 10:38:00 +0200
commit47c86cbb55a03df0f9d95dc2311b0be6d7852a5b (patch)
tree6cc56042980eae95994dcaf2c3f50b52a7cf6dbe
parentce43c8f6270518d801d91124ea1f32309c8e119d (diff)
downloadqtxmlpatterns-47c86cbb55a03df0f9d95dc2311b0be6d7852a5b.tar.gz
Actually test XmlListModel
Due to a typo in 'SUBDIRS', the test was never added to the build. Adding tests/shared/util.* from (current) qtdeclarative, adjusting paths and eradicating Q_FOREACHs, as the module defines QT_NO_FOREACH. Amends 8c6e24329ecd65f364654b1ca2b6a273f0826a8b. Change-Id: Ifacec982e8628c1317b1d7cc5c454c0a2cfafba1 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--tests/auto/auto.pro2
-rw-r--r--tests/auto/qquickxmllistmodel/qquickxmllistmodel.pro6
-rw-r--r--tests/auto/qquickxmllistmodel/tst_qquickxmllistmodel.cpp19
-rw-r--r--tests/shared/util.cpp103
-rw-r--r--tests/shared/util.h95
-rw-r--r--tests/shared/util.pri10
6 files changed, 223 insertions, 12 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 40f4c5c..81669e3 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -53,7 +53,7 @@ xmlpatternsxqts.depends = xmlpatternssdk
xmlpatternsxqts \
xmlpatternsxslts \
-qtHaveModule(quick): SUBIDIRS += qquickxmllistmodel
+qtHaveModule(quick):SUBDIRS += qquickxmllistmodel
!cross_compile: SUBDIRS += host.pro
diff --git a/tests/auto/qquickxmllistmodel/qquickxmllistmodel.pro b/tests/auto/qquickxmllistmodel/qquickxmllistmodel.pro
index e2d873c..2c7eacc 100644
--- a/tests/auto/qquickxmllistmodel/qquickxmllistmodel.pro
+++ b/tests/auto/qquickxmllistmodel/qquickxmllistmodel.pro
@@ -3,8 +3,10 @@ TARGET = tst_qquickxmllistmodel
macos:CONFIG -= app_bundle
SOURCES += tst_qquickxmllistmodel.cpp \
- ../../../../src/imports/xmllistmodel/qqmlxmllistmodel.cpp
-HEADERS += ../../../../src/imports/xmllistmodel/qqmlxmllistmodel_p.h
+ $$PWD/../../../src/imports/xmllistmodel/qqmlxmllistmodel.cpp
+HEADERS += $$PWD/../../../src/imports/xmllistmodel/qqmlxmllistmodel_p.h
+
+INCLUDEPATH *= $$PWD/../../../src/imports/xmllistmodel
include (../../shared/util.pri)
diff --git a/tests/auto/qquickxmllistmodel/tst_qquickxmllistmodel.cpp b/tests/auto/qquickxmllistmodel/tst_qquickxmllistmodel.cpp
index b2e5703..8059afc 100644
--- a/tests/auto/qquickxmllistmodel/tst_qquickxmllistmodel.cpp
+++ b/tests/auto/qquickxmllistmodel/tst_qquickxmllistmodel.cpp
@@ -44,7 +44,7 @@
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>
-#include "../../../../src/imports/xmllistmodel/qqmlxmllistmodel_p.h"
+#include "../../../src/imports/xmllistmodel/qqmlxmllistmodel_p.h"
#include <algorithm>
@@ -110,14 +110,14 @@ private:
QString xml;
if (!data.isEmpty()) {
- QStringList items = data.split(QLatin1Char(';'));
- foreach (const QString &item, items) {
+ const QStringList items = data.split(QLatin1Char(';'));
+ for (const QString &item : items) {
if (item.isEmpty())
continue;
QVariantList variants;
xml += QLatin1String("<item>");
- QStringList fields = item.split(QLatin1Char(','));
- foreach (const QString &field, fields) {
+ const QStringList fields = item.split(QLatin1Char(','));
+ for (const QString &field : fields) {
QStringList values = field.split(QLatin1Char('='));
if (values.count() != 2) {
qWarning() << "makeItemXmlAndData: invalid field:" << field;
@@ -168,7 +168,8 @@ protected:
{
if (m_factory) {
QVariantMap map;
- foreach (const QString &header, req.rawHeaderList())
+ const auto rawHeaderList = req.rawHeaderList();
+ for (const QString &header : rawHeaderList)
map[header] = req.rawHeader(header.toUtf8());
m_factory->lastSentHeaders = map;
}
@@ -421,9 +422,9 @@ void tst_qquickxmllistmodel::headers()
expectedHeaders["Accept"] = "application/xml,*/*";
QCOMPARE(factory.lastSentHeaders.count(), expectedHeaders.count());
- foreach (const QString &header, expectedHeaders.keys()) {
- QVERIFY(factory.lastSentHeaders.contains(header));
- QCOMPARE(factory.lastSentHeaders[header].toString(), expectedHeaders[header].toString());
+ for (auto it = expectedHeaders.cbegin(), end = expectedHeaders.cend(); it != end; ++it) {
+ QVERIFY(factory.lastSentHeaders.contains(it.key()));
+ QCOMPARE(factory.lastSentHeaders[it.key()].toString(), it.value().toString());
}
delete model;
diff --git a/tests/shared/util.cpp b/tests/shared/util.cpp
new file mode 100644
index 0000000..9687642
--- /dev/null
+++ b/tests/shared/util.cpp
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "util.h"
+
+#include <QtCore/QDebug>
+#include <QtCore/QMutexLocker>
+
+QQmlDataTest *QQmlDataTest::m_instance = 0;
+
+QQmlDataTest::QQmlDataTest() :
+#ifdef QT_TESTCASE_BUILDDIR
+ m_dataDirectory(QTest::qFindTestData("data", QT_QMLTEST_DATADIR, 0, QT_TESTCASE_BUILDDIR)),
+#else
+ m_dataDirectory(QTest::qFindTestData("data", QT_QMLTEST_DATADIR, 0)),
+#endif
+
+ m_dataDirectoryUrl(m_dataDirectory.startsWith(QLatin1Char(':'))
+ ? QUrl(QLatin1String("qrc") + m_dataDirectory)
+ : QUrl::fromLocalFile(m_dataDirectory + QLatin1Char('/')))
+{
+ m_instance = this;
+}
+
+QQmlDataTest::~QQmlDataTest()
+{
+ m_instance = 0;
+}
+
+void QQmlDataTest::initTestCase()
+{
+ QVERIFY2(!m_dataDirectory.isEmpty(), "'data' directory not found");
+ m_directory = QFileInfo(m_dataDirectory).absolutePath();
+ if (m_dataDirectoryUrl.scheme() != QLatin1String("qrc"))
+ QVERIFY2(QDir::setCurrent(m_directory), qPrintable(QLatin1String("Could not chdir to ") + m_directory));
+}
+
+QString QQmlDataTest::testFile(const QString &fileName) const
+{
+ if (m_directory.isEmpty())
+ qFatal("QQmlDataTest::initTestCase() not called.");
+ QString result = m_dataDirectory;
+ result += QLatin1Char('/');
+ result += fileName;
+ return result;
+}
+
+Q_GLOBAL_STATIC(QMutex, qQmlTestMessageHandlerMutex)
+
+QQmlTestMessageHandler *QQmlTestMessageHandler::m_instance = 0;
+
+void QQmlTestMessageHandler::messageHandler(QtMsgType, const QMessageLogContext &context, const QString &message)
+{
+ QMutexLocker locker(qQmlTestMessageHandlerMutex());
+ if (QQmlTestMessageHandler::m_instance) {
+ if (QQmlTestMessageHandler::m_instance->m_includeCategories)
+ QQmlTestMessageHandler::m_instance->m_messages.push_back(QString("%1: %2").arg(context.category, message));
+ else
+ QQmlTestMessageHandler::m_instance->m_messages.push_back(message);
+ }
+}
+
+QQmlTestMessageHandler::QQmlTestMessageHandler()
+{
+ QMutexLocker locker(qQmlTestMessageHandlerMutex());
+ Q_ASSERT(!QQmlTestMessageHandler::m_instance);
+ QQmlTestMessageHandler::m_instance = this;
+ m_oldHandler = qInstallMessageHandler(messageHandler);
+ m_includeCategories = false;
+}
+
+QQmlTestMessageHandler::~QQmlTestMessageHandler()
+{
+ QMutexLocker locker(qQmlTestMessageHandlerMutex());
+ Q_ASSERT(QQmlTestMessageHandler::m_instance);
+ qInstallMessageHandler(m_oldHandler);
+ QQmlTestMessageHandler::m_instance = 0;
+}
diff --git a/tests/shared/util.h b/tests/shared/util.h
new file mode 100644
index 0000000..6f3f0a0
--- /dev/null
+++ b/tests/shared/util.h
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQMLTESTUTILS_H
+#define QQMLTESTUTILS_H
+
+#include <QtCore/QDir>
+#include <QtCore/QUrl>
+#include <QtCore/QCoreApplication>
+#include <QtCore/QStringList>
+#include <QtTest/QTest>
+
+/* Base class for tests with data that are located in a "data" subfolder. */
+
+class QQmlDataTest : public QObject
+{
+ Q_OBJECT
+public:
+ QQmlDataTest();
+ virtual ~QQmlDataTest();
+
+ QString testFile(const QString &fileName) const;
+ inline QString testFile(const char *fileName) const
+ { return testFile(QLatin1String(fileName)); }
+ inline QUrl testFileUrl(const QString &fileName) const
+ { return QUrl::fromLocalFile(testFile(fileName)); }
+ inline QUrl testFileUrl(const char *fileName) const
+ { return testFileUrl(QLatin1String(fileName)); }
+
+ inline QString dataDirectory() const { return m_dataDirectory; }
+ inline QUrl dataDirectoryUrl() const { return m_dataDirectoryUrl; }
+ inline QString directory() const { return m_directory; }
+
+ static inline QQmlDataTest *instance() { return m_instance; }
+
+public slots:
+ virtual void initTestCase();
+
+private:
+ static QQmlDataTest *m_instance;
+
+ const QString m_dataDirectory;
+ const QUrl m_dataDirectoryUrl;
+ QString m_directory;
+};
+
+class QQmlTestMessageHandler
+{
+ Q_DISABLE_COPY(QQmlTestMessageHandler)
+public:
+ QQmlTestMessageHandler();
+ ~QQmlTestMessageHandler();
+
+ const QStringList &messages() const { return m_messages; }
+ const QString messageString() const { return m_messages.join(QLatin1Char('\n')); }
+
+ void clear() { m_messages.clear(); }
+
+ void setIncludeCategoriesEnabled(bool enabled) { m_includeCategories = enabled; }
+
+private:
+ static void messageHandler(QtMsgType, const QMessageLogContext &context, const QString &message);
+
+ static QQmlTestMessageHandler *m_instance;
+ QStringList m_messages;
+ QtMessageHandler m_oldHandler;
+ bool m_includeCategories;
+};
+
+#endif // QQMLTESTUTILS_H
diff --git a/tests/shared/util.pri b/tests/shared/util.pri
new file mode 100644
index 0000000..b54897a
--- /dev/null
+++ b/tests/shared/util.pri
@@ -0,0 +1,10 @@
+
+INCLUDEPATH += $$PWD
+HEADERS += $$PWD/util.h
+SOURCES += $$PWD/util.cpp
+
+android|ios {
+ DEFINES += QT_QMLTEST_DATADIR=\\\":/data\\\"
+} else {
+ DEFINES += QT_QMLTEST_DATADIR=\\\"$${_PRO_FILE_PWD_}/data\\\"
+}