aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-06-21 14:30:47 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-24 12:53:07 +0000
commitef265596e9d6b610a6f6e180c75075b392593161 (patch)
tree9bc381e9e511e837dad7b6d7f2e4ebd3e0815d96
parent3de6051d2b082e46f811e4307ec9c2a6834e434d (diff)
Add basic QML application to test CMake API for QML modules
An application with two modules which allows us to check that all the files end up in the right places. Change-Id: I58557d453e644e13f2eb646ec3195bba2654f569 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 5e78dc847d64cf99548d2b26cd957fb550c90cf2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tests/auto/qml/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmlbasicapp/CMakeLists.txt17
-rw-r--r--tests/auto/qml/qmlbasicapp/TimeExample/CMakeLists.txt18
-rw-r--r--tests/auto/qml/qmlbasicapp/TimeExample/Clock.qml6
-rw-r--r--tests/auto/qml/qmlbasicapp/TimeExample/center.pngbin0 -> 765 bytes
-rw-r--r--tests/auto/qml/qmlbasicapp/TimeExample/clock.pngbin0 -> 20653 bytes
-rw-r--r--tests/auto/qml/qmlbasicapp/TimeExample/hour.pngbin0 -> 518 bytes
-rw-r--r--tests/auto/qml/qmlbasicapp/TimeExample/minute.pngbin0 -> 528 bytes
-rw-r--r--tests/auto/qml/qmlbasicapp/TimeExample/timemodel.cpp74
-rw-r--r--tests/auto/qml/qmlbasicapp/TimeExample/timemodel.h84
-rw-r--r--tests/auto/qml/qmlbasicapp/main.qml58
-rw-r--r--tests/auto/qml/qmlbasicapp/tst_qmlbasicapp.cpp86
12 files changed, 344 insertions, 0 deletions
diff --git a/tests/auto/qml/CMakeLists.txt b/tests/auto/qml/CMakeLists.txt
index 685d4fba02..9a674cd24a 100644
--- a/tests/auto/qml/CMakeLists.txt
+++ b/tests/auto/qml/CMakeLists.txt
@@ -33,6 +33,7 @@ add_subdirectory(qqmlsettings)
add_subdirectory(qmldiskcache)
add_subdirectory(qqmlmetatype)
add_subdirectory(qmlcompiler_manual)
+add_subdirectory(qmlbasicapp)
if(TARGET Qt::Widgets)
add_subdirectory(qjsengine)
add_subdirectory(qjsvalue)
diff --git a/tests/auto/qml/qmlbasicapp/CMakeLists.txt b/tests/auto/qml/qmlbasicapp/CMakeLists.txt
new file mode 100644
index 0000000000..c121c089ee
--- /dev/null
+++ b/tests/auto/qml/qmlbasicapp/CMakeLists.txt
@@ -0,0 +1,17 @@
+qt_internal_add_test(tst_qmlbasicapp
+ SOURCES
+ tst_qmlbasicapp.cpp
+ LIBRARIES
+ Qt::Core
+ Qt::Qml
+)
+
+qt6_add_qml_module(tst_qmlbasicapp
+ VERSION 1.0
+ URI "BasicApp"
+ NO_CREATE_PLUGIN_TARGET
+ QML_FILES
+ main.qml
+)
+
+add_subdirectory(TimeExample)
diff --git a/tests/auto/qml/qmlbasicapp/TimeExample/CMakeLists.txt b/tests/auto/qml/qmlbasicapp/TimeExample/CMakeLists.txt
new file mode 100644
index 0000000000..2e55d6c47c
--- /dev/null
+++ b/tests/auto/qml/qmlbasicapp/TimeExample/CMakeLists.txt
@@ -0,0 +1,18 @@
+add_library(qmlqtimeexample STATIC)
+qt_autogen_tools_initial_setup(qmlqtimeexample)
+qt6_add_qml_module(qmlqtimeexample
+ VERSION 1.0
+ URI "TimeExample"
+ SOURCES
+ timemodel.cpp timemodel.h
+ QML_FILES
+ Clock.qml
+ RESOURCES
+ center.png
+ clock.png
+ hour.png
+ minute.png
+ DEPENDENCIES
+ QtQml
+)
+qt_autogen_tools_initial_setup(qmlqtimeexampleplugin)
diff --git a/tests/auto/qml/qmlbasicapp/TimeExample/Clock.qml b/tests/auto/qml/qmlbasicapp/TimeExample/Clock.qml
new file mode 100644
index 0000000000..3ee53b9c0b
--- /dev/null
+++ b/tests/auto/qml/qmlbasicapp/TimeExample/Clock.qml
@@ -0,0 +1,6 @@
+import QtQml
+
+QtObject {
+ property int hours: -1
+ property int minutes: -1
+}
diff --git a/tests/auto/qml/qmlbasicapp/TimeExample/center.png b/tests/auto/qml/qmlbasicapp/TimeExample/center.png
new file mode 100644
index 0000000000..7fbd802a44
--- /dev/null
+++ b/tests/auto/qml/qmlbasicapp/TimeExample/center.png
Binary files differ
diff --git a/tests/auto/qml/qmlbasicapp/TimeExample/clock.png b/tests/auto/qml/qmlbasicapp/TimeExample/clock.png
new file mode 100644
index 0000000000..462edacc0e
--- /dev/null
+++ b/tests/auto/qml/qmlbasicapp/TimeExample/clock.png
Binary files differ
diff --git a/tests/auto/qml/qmlbasicapp/TimeExample/hour.png b/tests/auto/qml/qmlbasicapp/TimeExample/hour.png
new file mode 100644
index 0000000000..9f33fc5d48
--- /dev/null
+++ b/tests/auto/qml/qmlbasicapp/TimeExample/hour.png
Binary files differ
diff --git a/tests/auto/qml/qmlbasicapp/TimeExample/minute.png b/tests/auto/qml/qmlbasicapp/TimeExample/minute.png
new file mode 100644
index 0000000000..e2f216c897
--- /dev/null
+++ b/tests/auto/qml/qmlbasicapp/TimeExample/minute.png
Binary files differ
diff --git a/tests/auto/qml/qmlbasicapp/TimeExample/timemodel.cpp b/tests/auto/qml/qmlbasicapp/TimeExample/timemodel.cpp
new file mode 100644
index 0000000000..e157d9ddd5
--- /dev/null
+++ b/tests/auto/qml/qmlbasicapp/TimeExample/timemodel.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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$
+**
+****************************************************************************/
+
+#include "timemodel.h"
+
+void TimeModel::timerEvent(QTimerEvent *)
+{
+ const QTime now = QTime::currentTime();
+ if (now.second() == 59
+ && now.minute() == m_time.value().minute()
+ && now.hour() == m_time.value().hour()) {
+ // just missed time tick over, force it, wait extra 0.5 seconds
+ timer.start(60500, this);
+ } else {
+ timer.start(60000 - m_time.value().second() * 1000, this);
+ }
+ m_time = now;
+}
+
+TimeModel::TimeModel(QObject *parent)
+ : QObject(parent)
+ , m_time(QTime::currentTime())
+{
+ m_minute.setBinding([this]() { return m_time.value().minute(); });
+ m_hour.setBinding([this]() { return m_time.value().hour(); });
+ timer.start(60000 - m_time.value().second() * 1000, this);
+}
diff --git a/tests/auto/qml/qmlbasicapp/TimeExample/timemodel.h b/tests/auto/qml/qmlbasicapp/TimeExample/timemodel.h
new file mode 100644
index 0000000000..62827dac5e
--- /dev/null
+++ b/tests/auto/qml/qmlbasicapp/TimeExample/timemodel.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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$
+**
+****************************************************************************/
+
+#ifndef TIMEMODEL_H
+#define TIMEMODEL_H
+
+#include <QtQml/qqml.h>
+#include <QtCore/qdatetime.h>
+#include <QtCore/qbasictimer.h>
+#include <QtCore/qcoreapplication.h>
+
+class TimeModel : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int hour READ hour BINDABLE hourBindable FINAL)
+ Q_PROPERTY(int minute READ minute BINDABLE minuteBindable FINAL)
+ QML_NAMED_ELEMENT(Time)
+
+public:
+ TimeModel(QObject *parent=nullptr);
+
+ int minute() const { return m_minute.value(); }
+ int hour() const { return m_hour.value(); }
+
+ QBindable<int> hourBindable() { return QBindable<int>(&m_hour); }
+ QBindable<int> minuteBindable() { return QBindable<int>(&m_minute); }
+
+private:
+ void timerEvent(QTimerEvent *) override;
+
+ QProperty<int> m_minute;
+ QProperty<int> m_hour;
+ QProperty<QTime> m_time;
+ QBasicTimer timer;
+};
+
+#endif // TIMEMODEL_H
diff --git a/tests/auto/qml/qmlbasicapp/main.qml b/tests/auto/qml/qmlbasicapp/main.qml
new file mode 100644
index 0000000000..45b989d48a
--- /dev/null
+++ b/tests/auto/qml/qmlbasicapp/main.qml
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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$
+**
+****************************************************************************/
+
+import TimeExample // import types from the plugin
+
+Clock { // this class is defined in QML (Clock.qml)
+ property Time time: Time {} // this class is defined in C++ (plugin.cpp)
+
+ hours: time.hour
+ minutes: time.minute
+}
diff --git a/tests/auto/qml/qmlbasicapp/tst_qmlbasicapp.cpp b/tests/auto/qml/qmlbasicapp/tst_qmlbasicapp.cpp
new file mode 100644
index 0000000000..bd3584ba37
--- /dev/null
+++ b/tests/auto/qml/qmlbasicapp/tst_qmlbasicapp.cpp
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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 <QQmlEngine>
+#include <QQmlComponent>
+#include <QObject>
+#include <qtest.h>
+
+class tst_basicapp : public QObject
+{
+ Q_OBJECT
+private slots:
+ void loadComponent();
+ void resourceFiles();
+ void fileSystemFiles();
+};
+
+void tst_basicapp::loadComponent()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, QStringLiteral("qrc:/BasicApp/main.qml"));
+ QEXPECT_FAIL(nullptr, "Tries to load plugin from qrc", Abort);
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer o(c.create());
+ QVERIFY(!o.isNull());
+
+ const QTime time = QTime::currentTime();
+ const int hour = o->property("hours").toInt();
+ QVERIFY(hour >= time.hour() - 1);
+ QVERIFY(hour <= time.hour() + 1);
+
+ const int minute = o->property("minutes").toInt();
+ QVERIFY(minute >= time.minute() - 1);
+ QVERIFY(minute <= time.minute() + 1);
+}
+
+void tst_basicapp::resourceFiles()
+{
+ QVERIFY(QFile::exists(QStringLiteral(":/BasicApp/main.qml")));
+ QVERIFY(QFile::exists(QStringLiteral(":/TimeExample/Clock.qml")));
+ QVERIFY(QFile::exists(QStringLiteral(":/TimeExample/center.png")));
+ QVERIFY(QFile::exists(QStringLiteral(":/TimeExample/clock.png")));
+ QVERIFY(QFile::exists(QStringLiteral(":/TimeExample/hour.png")));
+ QVERIFY(QFile::exists(QStringLiteral(":/TimeExample/minute.png")));
+}
+
+void tst_basicapp::fileSystemFiles()
+{
+ const QString basedir = QCoreApplication::applicationDirPath();
+ QVERIFY(QFile::exists(basedir + QStringLiteral("/main.qml")));
+ QVERIFY(QFile::exists(basedir + QStringLiteral("/TimeExample/Clock.qml")));
+
+ QEXPECT_FAIL(nullptr, "Does not install RESOURCES in qrc", Abort);
+ QVERIFY(QFile::exists(basedir + QStringLiteral("/TimeExample/center.png")));
+ QVERIFY(QFile::exists(basedir + QStringLiteral("/TimeExample/clock.png")));
+ QVERIFY(QFile::exists(basedir + QStringLiteral("/TimeExample/hour.png")));
+ QVERIFY(QFile::exists(basedir + QStringLiteral("/TimeExample/minute.png")));
+}
+
+QTEST_MAIN(tst_basicapp)
+#include "tst_qmlbasicapp.moc"