aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickview
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quick/qquickview')
-rw-r--r--tests/auto/quick/qquickview/CMakeLists.txt34
-rw-r--r--tests/auto/quick/qquickview/data/TestQml.qml3
-rw-r--r--tests/auto/quick/qquickview/data/overlay.qml17
-rw-r--r--tests/auto/quick/qquickview/tst_qquickview.cpp123
4 files changed, 134 insertions, 43 deletions
diff --git a/tests/auto/quick/qquickview/CMakeLists.txt b/tests/auto/quick/qquickview/CMakeLists.txt
index 16babb106a..658d957de5 100644
--- a/tests/auto/quick/qquickview/CMakeLists.txt
+++ b/tests/auto/quick/qquickview/CMakeLists.txt
@@ -1,9 +1,20 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
# Generated from qquickview.pro.
#####################################################################
## tst_qquickview Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qquickview LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_policy(SET QTP0001 NEW)
+
# Collect test data
file(GLOB_RECURSE test_data_glob
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
@@ -12,33 +23,34 @@ list(APPEND test_data ${test_data_glob})
qt_internal_add_test(tst_qquickview
SOURCES
- ../../shared/util.cpp ../../shared/util.h
- ../shared/geometrytestutil.cpp ../shared/geometrytestutil.h
- ../shared/viewtestutil.cpp ../shared/viewtestutil.h
- ../shared/visualtestutil.cpp ../shared/visualtestutil.h
tst_qquickview.cpp
- DEFINES
- QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\"
- INCLUDE_DIRECTORIES
- ../../shared
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
Qt::QmlPrivate
Qt::QuickPrivate
+ Qt::QuickTestUtilsPrivate
TESTDATA ${test_data}
)
+
+qt_add_qml_module(
+ tst_qquickview
+ URI test
+ QML_FILES
+ "data/TestQml.qml"
+)
+
## Scopes:
#####################################################################
qt_internal_extend_target(tst_qquickview CONDITION ANDROID OR IOS
DEFINES
- QT_QMLTEST_DATADIR=\\\":/data\\\"
+ QT_QMLTEST_DATADIR=":/data"
)
qt_internal_extend_target(tst_qquickview CONDITION NOT ANDROID AND NOT IOS
DEFINES
- QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\"
+ QT_QMLTEST_DATADIR="${CMAKE_CURRENT_SOURCE_DIR}/data"
)
diff --git a/tests/auto/quick/qquickview/data/TestQml.qml b/tests/auto/quick/qquickview/data/TestQml.qml
new file mode 100644
index 0000000000..3052615aef
--- /dev/null
+++ b/tests/auto/quick/qquickview/data/TestQml.qml
@@ -0,0 +1,3 @@
+import QtQuick
+
+Item {}
diff --git a/tests/auto/quick/qquickview/data/overlay.qml b/tests/auto/quick/qquickview/data/overlay.qml
new file mode 100644
index 0000000000..cefaaed8bd
--- /dev/null
+++ b/tests/auto/quick/qquickview/data/overlay.qml
@@ -0,0 +1,17 @@
+// RootItem.qml
+import QtQuick
+import QtQuick.Controls.Basic
+
+Item {
+ id: root
+ width: 640
+ height: 480
+
+ property double scaleFactor: 2.0
+ Scale {
+ id: scale
+ xScale: root.scaleFactor
+ yScale: root.scaleFactor
+ }
+ Overlay.overlay.transform: scale
+}
diff --git a/tests/auto/quick/qquickview/tst_qquickview.cpp b/tests/auto/quick/qquickview/tst_qquickview.cpp
index 7e47e0ca59..91a45077fb 100644
--- a/tests/auto/quick/qquickview/tst_qquickview.cpp
+++ b/tests/auto/quick/qquickview/tst_qquickview.cpp
@@ -1,42 +1,21 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qtest.h>
#include <QtTest/QSignalSpy>
#include <QtQml/qqmlcomponent.h>
#include <QtQml/qqmlcontext.h>
#include <QtQuick/qquickview.h>
#include <QtQuick/qquickitem.h>
-#include "../../shared/util.h"
+#include <QtQuickTestUtils/private/qmlutils_p.h>
#include <QtGui/QWindow>
#include <QtCore/QDebug>
#include <QtQml/qqmlengine.h>
+#include <private/qv4engine_p.h>
+#include <private/qv4mm_p.h>
-#include "../shared/geometrytestutil.h"
+#include <QtQuickTestUtils/private/geometrytestutils_p.h>
+
+using namespace Qt::StringLiterals;
class tst_QQuickView : public QQmlDataTest
{
@@ -45,16 +24,52 @@ public:
tst_QQuickView();
private slots:
+ void gc();
void resizemodeitem();
void errors();
void engine();
void findChild();
void setInitialProperties();
+ void fromModuleCtor();
+ void loadFromModule_data();
+ void loadFromModule();
+ void overlay();
};
tst_QQuickView::tst_QQuickView()
+ : QQmlDataTest(QT_QMLTEST_DATADIR)
+{
+}
+
+void tst_QQuickView::gc()
{
+ QQuickView view;
+ QQmlEngine *engine = view.engine();
+ QV4::ExecutionEngine *v4 = engine->handle();
+
+ v4->memoryManager->gcStateMachine->deadline = QDeadlineTimer(QDeadlineTimer::Forever);
+ auto sm = v4->memoryManager->gcStateMachine.get();
+ sm->reset();
+ while (sm->state != QV4::GCState::CallDestroyObjects) {
+ QV4::GCStateInfo& stateInfo = sm->stateInfoMap[int(sm->state)];
+ sm->state = stateInfo.execute(sm, sm->stateData);
+ }
+ view.loadFromModule("test", "TestQml");
+ auto root = view.rootObject();
+ QVERIFY(root);
+ auto ddata = QQmlData::get(root, false);
+ while (sm->state != QV4::GCState::DoSweep) {
+ if (sm->state > QV4::GCState::InitCallDestroyObjects) {
+ sm->mm->collectFromJSStack(sm->mm->markStack());
+ sm->mm->m_markStack->drain();
+ }
+ QV4::GCStateInfo& stateInfo = sm->stateInfoMap[int(sm->state)];
+ sm->state = stateInfo.execute(sm, sm->stateData);
+ }
+ QVERIFY(ddata);
+ QVERIFY(ddata->jsWrapper.asManaged());
+ QVERIFY(ddata->jsWrapper.asManaged()->markBit());
}
void tst_QQuickView::resizemodeitem()
@@ -147,7 +162,7 @@ void tst_QQuickView::resizemodeitem()
view->resize(QSize(200,300));
QTRY_COMPARE(item->width(), 200.0);
- for (int i = 0; i < sizeListener.count(); ++i) {
+ for (int i = 0; i < sizeListener.size(); ++i) {
// Check that we have the correct geometry on all signals
QCOMPARE(sizeListener.at(i), view->size());
}
@@ -195,7 +210,7 @@ void tst_QQuickView::errors()
QQmlTestMessageHandler messageHandler;
view.setSource(testFileUrl("error1.qml"));
QCOMPARE(view.status(), QQuickView::Error);
- QCOMPARE(view.errors().count(), 1);
+ QCOMPARE(view.errors().size(), 1);
}
{
@@ -203,7 +218,7 @@ void tst_QQuickView::errors()
QQmlTestMessageHandler messageHandler;
view.setSource(testFileUrl("error2.qml"));
QCOMPARE(view.status(), QQuickView::Error);
- QCOMPARE(view.errors().count(), 1);
+ QCOMPARE(view.errors().size(), 1);
view.show();
}
}
@@ -294,6 +309,50 @@ void tst_QQuickView::setInitialProperties()
QCOMPARE(rootObject->property("width").toInt(), 100);
}
+void tst_QQuickView::fromModuleCtor()
+{
+ QQuickView view("QtQuick", "Rectangle");
+ // creation is always synchronous for C++ defined types, so we don't need _TRY
+ QObject *rootObject = view.rootObject();
+ QVERIFY(rootObject);
+ QCOMPARE(rootObject->metaObject()->className(), "QQuickRectangle");
+}
+
+void tst_QQuickView::loadFromModule_data()
+{
+ QTest::addColumn<QString>("module");
+ QTest::addColumn<QString>("typeName");
+ QTest::addColumn<QUrl>("url");
+ QTest::addColumn<QQuickView::Status>("status");
+
+ QTest::addRow("Item") << u"QtQuick"_s << u"Item"_s << QUrl() << QQuickView::Ready;
+ QTest::addRow("composite") << u"test"_s << u"TestQml"_s << QUrl("qrc:/qt/qml/test/data/TestQml.qml") << QQuickView::Ready;
+ QTest::addRow("nonexistent") << u"missing"_s << u"Type"_s << QUrl() << QQuickView::Error;
+}
+
+void tst_QQuickView::loadFromModule()
+{
+ QFETCH(QString, module);
+ QFETCH(QString, typeName);
+ QFETCH(QUrl, url);
+ QFETCH(QQuickView::Status, status);
+
+ QQuickView view;
+ view.loadFromModule(module, typeName);
+ QTRY_COMPARE(view.status(), status);
+ QCOMPARE(view.source(), url);
+}
+
+void tst_QQuickView::overlay()
+{
+ QTest::ignoreMessage(QtWarningMsg,
+ QRegularExpression(".*: Cannot set properties on overlay as it is null"));
+ QQuickView view;
+ view.setSource(testFileUrl("overlay.qml"));
+ QObject *rootObject = view.rootObject();
+ QVERIFY(!rootObject);
+}
+
QTEST_MAIN(tst_QQuickView)
#include "tst_qquickview.moc"