WindowContainer: Add auto test for basic functionality
Now that we have a preliminary implementation, that we will
continue improving and extending, we need to make sure it
doesn't regress.
Change-Id: I53da32316e3d8a30257e5c93d542e3e87dc02aea
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
(cherry picked from commit a21d8e10a6
)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
2ad42e1f27
commit
00bb4ecac9
|
@ -43,6 +43,7 @@ if(QT_FEATURE_private_tests)
|
|||
add_subdirectory(qquickdynamicpropertyanimation)
|
||||
add_subdirectory(qquickborderimage)
|
||||
add_subdirectory(qquickwindow)
|
||||
add_subdirectory(qquickwindowcontainer)
|
||||
add_subdirectory(qquickdeliveryagent)
|
||||
add_subdirectory(qquickdrag)
|
||||
add_subdirectory(qquickdragattached)
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
# Copyright (C) 2023 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(tst_qquickwindowcontainer LANGUAGES CXX)
|
||||
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE test_data_glob
|
||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
data/*)
|
||||
list(APPEND test_data ${test_data_glob})
|
||||
|
||||
qt_internal_add_test(tst_qquickwindowcontainer
|
||||
SOURCES
|
||||
tst_qquickwindowcontainer.cpp
|
||||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::Gui
|
||||
Qt::GuiPrivate
|
||||
Qt::QmlPrivate
|
||||
Qt::QuickPrivate
|
||||
Qt::QuickTestUtilsPrivate
|
||||
TESTDATA ${test_data}
|
||||
)
|
||||
|
||||
if(ANDROID OR IOS)
|
||||
set(TESTDATA_DIR ":/data")
|
||||
else()
|
||||
set(TESTDATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/data")
|
||||
endif()
|
||||
|
||||
qt_internal_extend_target(tst_qquickwindowcontainer
|
||||
DEFINES
|
||||
QT_QMLTEST_DATADIR="${TESTDATA_DIR}"
|
||||
)
|
|
@ -0,0 +1,15 @@
|
|||
import QtQuick
|
||||
|
||||
Window {
|
||||
id: topLevel
|
||||
Item {
|
||||
id: childItem
|
||||
x: 100; y: 100
|
||||
|
||||
WindowContainer {
|
||||
window: Window {
|
||||
objectName: "childWindow"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
import QtQuick
|
||||
|
||||
Window {
|
||||
id: topLevel
|
||||
Item {
|
||||
id: childItem
|
||||
x: 100; y: 100
|
||||
|
||||
Window {
|
||||
parent: childItem
|
||||
objectName: "childWindow"
|
||||
x: 100; y: 100
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
import QtQuick
|
||||
|
||||
Window {
|
||||
id: topLevel
|
||||
Window {
|
||||
parent: topLevel
|
||||
objectName: "childWindow"
|
||||
x: 100; y: 100
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QtTest/qtest.h>
|
||||
|
||||
#include <QtQuickTest/QtQuickTest>
|
||||
|
||||
#include <QtQuickTestUtils/private/qmlutils_p.h>
|
||||
|
||||
#include <QtQml/qqmlengine.h>
|
||||
#include <QtQml/qqmlfile.h>
|
||||
#include <QtQml/qqmlcomponent.h>
|
||||
#include <QtQml/qqmlapplicationengine.h>
|
||||
|
||||
#include <QtQuick/qquickwindow.h>
|
||||
|
||||
class tst_QQuickWindowContainer : public QQmlDataTest
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
tst_QQuickWindowContainer()
|
||||
: QQmlDataTest(QT_QMLTEST_DATADIR)
|
||||
{
|
||||
}
|
||||
|
||||
private slots:
|
||||
void init() override;
|
||||
void cleanup();
|
||||
|
||||
void basicFunctionality_data();
|
||||
void basicFunctionality();
|
||||
|
||||
private:
|
||||
std::unique_ptr<QQmlApplicationEngine> m_engine;
|
||||
};
|
||||
|
||||
void tst_QQuickWindowContainer::init()
|
||||
{
|
||||
QQmlDataTest::init();
|
||||
|
||||
QString testFile = QTest::currentTestFunction();
|
||||
if (auto *dataTag = QTest::currentDataTag())
|
||||
testFile += QChar('_') % dataTag;
|
||||
testFile += ".qml";
|
||||
|
||||
const auto testUrl = testFileUrl(testFile);
|
||||
if (QFileInfo::exists(QQmlFile::urlToLocalFileOrQrc(testUrl))) {
|
||||
m_engine.reset(new QQmlApplicationEngine(testUrl));
|
||||
QVERIFY(m_engine->rootObjects().size() > 0);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QQuickWindowContainer::cleanup()
|
||||
{
|
||||
m_engine.reset(nullptr);
|
||||
}
|
||||
|
||||
void tst_QQuickWindowContainer::basicFunctionality_data()
|
||||
{
|
||||
QTest::addColumn<QPoint>("position");
|
||||
|
||||
QTest::newRow("window") << QPoint(100, 100);
|
||||
QTest::newRow("item") << QPoint(200, 200);
|
||||
QTest::newRow("container") << QPoint(100, 100);
|
||||
}
|
||||
|
||||
void tst_QQuickWindowContainer::basicFunctionality()
|
||||
{
|
||||
QFETCH(QPoint, position);
|
||||
|
||||
auto *topLevelWindow = qobject_cast<QQuickWindow*>(m_engine->rootObjects().first());
|
||||
auto *childWindow = topLevelWindow->findChild<QWindow*>("childWindow");
|
||||
QVERIFY(childWindow);
|
||||
|
||||
// The top level isn't visible yet, so there hasn't been any
|
||||
// polish, which we rely on for the actual reparenting.
|
||||
QCOMPARE(childWindow->parent(), nullptr);
|
||||
|
||||
topLevelWindow->setVisible(true);
|
||||
QVERIFY(QQuickTest::qWaitForPolish(topLevelWindow));
|
||||
QCOMPARE(childWindow->parent(), topLevelWindow);
|
||||
|
||||
QCOMPARE(childWindow->position(), position);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QQuickWindowContainer)
|
||||
|
||||
#include "tst_qquickwindowcontainer.moc"
|
Loading…
Reference in New Issue