aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/shared
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/shared')
-rw-r--r--tests/auto/shared/qtest_quickcontrols.h90
-rw-r--r--tests/auto/shared/util.cpp144
-rw-r--r--tests/auto/shared/util.h108
-rw-r--r--tests/auto/shared/util.pri14
-rw-r--r--tests/auto/shared/visualtestutil.cpp169
-rw-r--r--tests/auto/shared/visualtestutil.h219
6 files changed, 0 insertions, 744 deletions
diff --git a/tests/auto/shared/qtest_quickcontrols.h b/tests/auto/shared/qtest_quickcontrols.h
deleted file mode 100644
index 8eadd979..00000000
--- a/tests/auto/shared/qtest_quickcontrols.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QTEST_QUICKCONTROLS_H
-#define QTEST_QUICKCONTROLS_H
-
-#include <QtTest/qtest.h>
-#include <QtTest/private/qtestresult_p.h>
-#include <QtGui/qguiapplication.h>
-#include <QtQml/qqml.h>
-#include <QtQuickControls2/qquickstyle.h>
-#include <QtQuickControls2/private/qquickstyle_p.h>
-
-static QStringList testStyles()
-{
- // It's not enough to check if the name is empty, because since Qt 6
- // we set an appropriate style for the platform if no style was specified.
- // Also, we need the name check to come first, as isUsingDefaultStyle() does not do any resolving,
- // and so its return value wouldn't be correct otherwise.
- if (QQuickStyle::name().isEmpty() || QQuickStylePrivate::isUsingDefaultStyle())
- return QQuickStylePrivate::builtInStyles();
- return QStringList(QQuickStyle::name());
-}
-
-static int runTests(QObject *testObject, int argc, char *argv[])
-{
- int res = 0;
- QTest::qInit(testObject, argc, argv);
- const QByteArray testObjectName = QTestResult::currentTestObjectName();
- // setCurrentTestObject() takes a C string, which means we must ensure
- // that the string we pass in lives long enough (i.e until the next call
- // to setCurrentTestObject()), so store the name outside of the loop.
- QByteArray testName;
- const QStringList styles = testStyles();
- for (const QString &style : styles) {
- qmlClearTypeRegistrations();
- QQuickStyle::setStyle(style);
- testName = testObjectName + "::" + style.toLocal8Bit();
- QTestResult::setCurrentTestObject(testName);
- res += QTest::qRun();
- }
- QTestResult::setCurrentTestObject(testObjectName);
- QTest::qCleanup();
- return res;
-}
-
-#define QTEST_QUICKCONTROLS_MAIN(TestCase) \
-int main(int argc, char *argv[]) \
-{ \
- qputenv("QML_NO_TOUCH_COMPRESSION", "1"); \
- QGuiApplication app(argc, argv); \
- TestCase tc; \
- QTEST_SET_MAIN_SOURCE_PATH \
- return runTests(&tc, argc, argv); \
-}
-
-#endif // QTEST_QUICKCONTROLS_H
diff --git a/tests/auto/shared/util.cpp b/tests/auto/shared/util.cpp
deleted file mode 100644
index 31647d69..00000000
--- a/tests/auto/shared/util.cpp
+++ /dev/null
@@ -1,144 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "util.h"
-
-#include <QtQml/QQmlComponent>
-#include <QtQml/QQmlError>
-#include <QtQml/QQmlContext>
-#include <QtQml/QQmlEngine>
-#include <QtCore/QTextStream>
-#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;
-}
-
-QByteArray QQmlDataTest::msgComponentError(const QQmlComponent &c,
- const QQmlEngine *engine /* = 0 */)
-{
- QString result;
- const QList<QQmlError> errors = c.errors();
- QTextStream str(&result);
- str << "Component '" << c.url().toString() << "' has " << errors.size()
- << " errors: '";
- for (int i = 0; i < errors.size(); ++i) {
- if (i)
- str << ", '";
- str << errors.at(i).toString() << '\'';
-
- }
- if (!engine)
- if (QQmlContext *context = c.creationContext())
- engine = context->engine();
- if (engine) {
- str << " Import paths: (" << engine->importPathList().join(QStringLiteral(", "))
- << ") Plugin paths: (" << engine->pluginPathList().join(QStringLiteral(", "))
- << ')';
- }
- return result.toLocal8Bit();
-}
-
-bool QQmlDataTest::canImportModule(const QString &importTestQmlSource) const
-{
- QQmlEngine engine;
- QQmlComponent component(&engine);
- component.setData(importTestQmlSource.toLatin1(), QUrl());
- return !component.isError();
-}
-
-Q_GLOBAL_STATIC(QMutex, qQmlTestMessageHandlerMutex)
-
-QQmlTestMessageHandler *QQmlTestMessageHandler::m_instance = 0;
-
-void QQmlTestMessageHandler::messageHandler(QtMsgType, const QMessageLogContext &, const QString &message)
-{
- QMutexLocker locker(qQmlTestMessageHandlerMutex());
- if (QQmlTestMessageHandler::m_instance)
- 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);
-}
-
-QQmlTestMessageHandler::~QQmlTestMessageHandler()
-{
- QMutexLocker locker(qQmlTestMessageHandlerMutex());
- Q_ASSERT(QQmlTestMessageHandler::m_instance);
- qInstallMessageHandler(m_oldHandler);
- QQmlTestMessageHandler::m_instance = 0;
-}
diff --git a/tests/auto/shared/util.h b/tests/auto/shared/util.h
deleted file mode 100644
index 50d161e0..00000000
--- a/tests/auto/shared/util.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.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>
-
-QT_FORWARD_DECLARE_CLASS(QQmlComponent)
-QT_FORWARD_DECLARE_CLASS(QQmlEngine)
-
-/* 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; }
-
- static QByteArray msgComponentError(const QQmlComponent &,
- const QQmlEngine *engine = 0);
-
- bool canImportModule(const QString &importTestQmlSource) const;
-
-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(); }
-
-private:
- static void messageHandler(QtMsgType, const QMessageLogContext &, const QString &message);
-
- static QQmlTestMessageHandler *m_instance;
- QStringList m_messages;
- QtMessageHandler m_oldHandler;
-};
-
-#endif // QQMLTESTUTILS_H
diff --git a/tests/auto/shared/util.pri b/tests/auto/shared/util.pri
deleted file mode 100644
index c2eb9f0a..00000000
--- a/tests/auto/shared/util.pri
+++ /dev/null
@@ -1,14 +0,0 @@
-QT += testlib-private core-private gui-private qml-private quick-private quicktemplates2-private quickcontrols2 quickcontrols2-private
-
-HEADERS += $$PWD/visualtestutil.h \
- $$PWD/util.h \
- $$PWD/qtest_quickcontrols.h
-SOURCES += $$PWD/visualtestutil.cpp \
- $$PWD/util.cpp
-
-android|ios {
- DEFINES += QT_QMLTEST_DATADIR=\\\":/data\\\"
-} else {
- DEFINES += QT_QMLTEST_DATADIR=\\\"$${_PRO_FILE_PWD_}/data\\\"
-}
-DEFINES += QQC2_IMPORT_PATH=\\\"$$QQC2_SOURCE_TREE/src/imports\\\"
diff --git a/tests/auto/shared/visualtestutil.cpp b/tests/auto/shared/visualtestutil.cpp
deleted file mode 100644
index 4e33c6f1..00000000
--- a/tests/auto/shared/visualtestutil.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "visualtestutil.h"
-
-#include <QtQuick/QQuickItem>
-#include <QtCore/QDebug>
-#include <QtGui/QCursor>
-#include <QtCore/QCoreApplication>
-#include <QtQml/QQmlFile>
-#include <QtTest/QTest>
-
-bool QQuickVisualTestUtil::delegateVisible(QQuickItem *item)
-{
- return item->isVisible() && !QQuickItemPrivate::get(item)->culled;
-}
-
-QQuickItem *QQuickVisualTestUtil::findVisibleChild(QQuickItem *parent, const QString &objectName)
-{
- QQuickItem *item = 0;
- QList<QQuickItem*> items = parent->findChildren<QQuickItem*>(objectName);
- for (int i = 0; i < items.count(); ++i) {
- if (items.at(i)->isVisible() && !QQuickItemPrivate::get(items.at(i))->culled) {
- item = items.at(i);
- break;
- }
- }
- return item;
-}
-
-void QQuickVisualTestUtil::dumpTree(QQuickItem *parent, int depth)
-{
- static QString padding(" ");
- for (int i = 0; i < parent->childItems().count(); ++i) {
- QQuickItem *item = qobject_cast<QQuickItem*>(parent->childItems().at(i));
- if (!item)
- continue;
- qDebug() << padding.left(depth*2) << item;
- dumpTree(item, depth+1);
- }
-}
-
-void QQuickVisualTestUtil::moveMouseAway(QQuickWindow *window)
-{
-#if QT_CONFIG(cursor) // Get the cursor out of the way.
- // Using "bottomRight() + QPoint(100, 100)" was causing issues on Ubuntu,
- // where the window was positioned at the bottom right corner of the window
- // (even after centering the window on the screen), so we use another position.
- QCursor::setPos(window->geometry().bottomLeft() + QPoint(0, 10));
-#endif
-
- // make sure hover events from QQuickWindowPrivate::flushFrameSynchronousEvents()
- // do not interfere with the tests
- QEvent leave(QEvent::Leave);
- QCoreApplication::sendEvent(window, &leave);
-}
-
-void QQuickVisualTestUtil::centerOnScreen(QQuickWindow *window)
-{
- const QRect screenGeometry = window->screen()->availableGeometry();
- const QPoint offset = QPoint(window->width() / 2, window->height() / 2);
- window->setFramePosition(screenGeometry.center() - offset);
-}
-
-void QQuickVisualTestUtil::forEachControl(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skipList, QQuickVisualTestUtil::ForEachCallback callback)
-{
- // We cannot use QQmlComponent to load QML files directly from the source tree.
- // For styles that use internal QML types (eg. material/Ripple.qml), the source
- // dir would be added as an "implicit" import path overriding the actual import
- // path (qtbase/qml/QtQuick/Controls.2/Material). => The QML engine fails to load
- // the style C++ plugin from the implicit import path (the source dir).
- //
- // Therefore we only use the source tree for finding out the set of QML files that
- // a particular style implements, and then we locate the respective QML files in
- // the engine's import path. This way we can use QQmlComponent to load each QML file
- // for benchmarking.
-
- const QFileInfoList entries = QDir(QQC2_IMPORT_PATH "/" + sourcePath).entryInfoList(QStringList("*.qml"), QDir::Files);
- for (const QFileInfo &entry : entries) {
- QString name = entry.baseName();
- if (!skipList.contains(name)) {
- const auto importPathList = engine->importPathList();
- for (const QString &importPath : importPathList) {
- QString name = entry.dir().dirName() + "/" + entry.fileName();
- QString filePath = importPath + "/" + targetPath + "/" + entry.fileName();
- if (filePath.startsWith(":"))
- filePath.prepend("qrc");
- if (QFile::exists(filePath)) {
- callback(name, QUrl::fromLocalFile(filePath));
- break;
- } else {
- QUrl url(filePath);
- filePath = QQmlFile::urlToLocalFileOrQrc(filePath);
- if (!filePath.isEmpty() && QFile::exists(filePath)) {
- callback(name, url);
- break;
- }
- }
- }
- }
- }
-}
-
-void QQuickVisualTestUtil::addTestRowForEachControl(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skipList)
-{
- forEachControl(engine, sourcePath, targetPath, skipList, [&](const QString &relativePath, const QUrl &absoluteUrl) {
- QTest::newRow(qPrintable(relativePath)) << absoluteUrl;
- });
-}
-
-QQuickVisualTestUtil::MnemonicKeySimulator::MnemonicKeySimulator(QWindow *window)
- : m_window(window), m_modifiers(Qt::NoModifier)
-{
-}
-
-void QQuickVisualTestUtil::MnemonicKeySimulator::press(Qt::Key key)
-{
- // QTest::keyPress() but not generating the press event for the modifier key.
- if (key == Qt::Key_Alt)
- m_modifiers |= Qt::AltModifier;
- QTest::simulateEvent(m_window, true, key, m_modifiers, QString(), false);
-}
-
-void QQuickVisualTestUtil::MnemonicKeySimulator::release(Qt::Key key)
-{
- // QTest::keyRelease() but not generating the release event for the modifier key.
- if (key == Qt::Key_Alt)
- m_modifiers &= ~Qt::AltModifier;
- QTest::simulateEvent(m_window, false, key, m_modifiers, QString(), false);
-}
-
-void QQuickVisualTestUtil::MnemonicKeySimulator::click(Qt::Key key)
-{
- press(key);
- release(key);
-}
diff --git a/tests/auto/shared/visualtestutil.h b/tests/auto/shared/visualtestutil.h
deleted file mode 100644
index 78c625ea..00000000
--- a/tests/auto/shared/visualtestutil.h
+++ /dev/null
@@ -1,219 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QQUICKVISUALTESTUTIL_H
-#define QQUICKVISUALTESTUTIL_H
-
-#include <functional>
-
-#include <QtCore/QPointer>
-#include <QtQuick/QQuickItem>
-#include <QtQml/QQmlExpression>
-#include <QtQuick/private/qquickitem_p.h>
-#include <QtQuickControls2/qquickstyle.h>
-#include <QtQuickTemplates2/private/qquickapplicationwindow_p.h>
-
-#include "util.h"
-
-namespace QQuickVisualTestUtil
-{
- QQuickItem *findVisibleChild(QQuickItem *parent, const QString &objectName);
-
- void dumpTree(QQuickItem *parent, int depth = 0);
-
- bool delegateVisible(QQuickItem *item);
-
- void centerOnScreen(QQuickWindow *window);
-
- void moveMouseAway(QQuickWindow *window);
-
- /*
- Find an item with the specified objectName. If index is supplied then the
- item must also evaluate the {index} expression equal to index
- */
- template<typename T>
- T *findItem(QQuickItem *parent, const QString &objectName, int index = -1)
- {
- const QMetaObject &mo = T::staticMetaObject;
- for (int i = 0; i < parent->childItems().count(); ++i) {
- QQuickItem *item = qobject_cast<QQuickItem*>(parent->childItems().at(i));
- if (!item)
- continue;
- if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) {
- if (index != -1) {
- QQmlExpression e(qmlContext(item), item, "index");
- if (e.evaluate().toInt() == index)
- return static_cast<T*>(item);
- } else {
- return static_cast<T*>(item);
- }
- }
- item = findItem<T>(item, objectName, index);
- if (item)
- return static_cast<T*>(item);
- }
-
- return 0;
- }
-
- template<typename T>
- QList<T*> findItems(QQuickItem *parent, const QString &objectName, bool visibleOnly = true)
- {
- QList<T*> items;
- const QMetaObject &mo = T::staticMetaObject;
- for (int i = 0; i < parent->childItems().count(); ++i) {
- QQuickItem *item = qobject_cast<QQuickItem*>(parent->childItems().at(i));
- if (!item || (visibleOnly && (!item->isVisible() || QQuickItemPrivate::get(item)->culled)))
- continue;
- if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName))
- items.append(static_cast<T*>(item));
- items += findItems<T>(item, objectName);
- }
-
- return items;
- }
-
- template<typename T>
- QList<T*> findItems(QQuickItem *parent, const QString &objectName, const QList<int> &indexes)
- {
- QList<T*> items;
- for (int i=0; i<indexes.count(); i++)
- items << qobject_cast<QQuickItem*>(findItem<T>(parent, objectName, indexes[i]));
- return items;
- }
-
- class QQuickApplicationHelper
- {
- public:
- QQuickApplicationHelper(QQmlDataTest *testCase, const QString &testFilePath,
- const QStringList &qmlImportPaths = QStringList())
- {
- for (const auto &path : qmlImportPaths)
- engine.addImportPath(path);
-
- QQmlComponent component(&engine);
-
- component.loadUrl(testCase->testFileUrl(testFilePath));
- QObject *rootObject = component.create();
- cleanup.reset(rootObject);
- if (!rootObject) {
- errorMessage = QString::fromUtf8("Failed to create window: %1").arg(component.errorString()).toUtf8();
- return;
- }
-
- window = qobject_cast<QQuickWindow*>(rootObject);
- appWindow = qobject_cast<QQuickApplicationWindow*>(rootObject);
- if (!window) {
- errorMessage = QString::fromUtf8("Root object %1 must be a QQuickWindow subclass").arg(QDebug::toString(window)).toUtf8();
- return;
- }
-
- if (window->isVisible()) {
- errorMessage = QString::fromUtf8("Expected window not to be visible, but it is").toUtf8();
- return;
- }
-
- ready = true;
- }
-
- // Return a C-style string instead of QString because that's what QTest uses for error messages,
- // so it saves code at the calling site.
- inline const char *failureMessage() const
- {
- return errorMessage.constData();
- }
-
- QQmlEngine engine;
- QScopedPointer<QObject> cleanup;
- QQuickApplicationWindow *appWindow = nullptr;
- QQuickWindow *window = nullptr;
-
- bool ready = false;
- // Store as a byte array so that we can return its raw data safely;
- // using qPrintable() in failureMessage() will construct a throwaway QByteArray
- // that is destroyed before the function returns.
- QByteArray errorMessage;
- };
-
- struct QQuickStyleHelper
- {
- bool updateStyle(const QString &style)
- {
- // If it's not the first time a style has been set and the new style is not different, do nothing.
- if (!currentStyle.isEmpty() && style == currentStyle)
- return false;
-
- engine.reset(new QQmlEngine);
- currentStyle = style;
- qmlClearTypeRegistrations();
- QQuickStyle::setStyle(style);
-
- QQmlComponent component(engine.data());
- component.setData(QString("import QtQuick\nimport QtQuick.Controls\n Control { }").toUtf8(), QUrl());
-
- return true;
- }
-
- QString currentStyle;
- QScopedPointer<QQmlEngine> engine;
- };
-
- typedef std::function<void(const QString &/*relativePath*/, const QUrl &/*absoluteUrl*/)> ForEachCallback;
-
- void forEachControl(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skipList, ForEachCallback callback);
- void addTestRowForEachControl(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skipList = QStringList());
-
- // Helper to simulate Alt itself and Alt+<key> events.
- class MnemonicKeySimulator
- {
- Q_DISABLE_COPY(MnemonicKeySimulator)
- public:
- explicit MnemonicKeySimulator(QWindow *window);
-
- void press(Qt::Key key);
- void release(Qt::Key key);
- void click(Qt::Key key);
-
- private:
- QPointer<QWindow> m_window;
- Qt::KeyboardModifiers m_modifiers;
- };
-}
-
-#define QQUICK_VERIFY_POLISH(item) \
- QTRY_COMPARE(QQuickItemPrivate::get(item)->polishScheduled, false)
-
-#endif // QQUICKVISUALTESTUTIL_H