diff options
Diffstat (limited to 'tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp')
-rw-r--r-- | tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp | 71 |
1 files changed, 26 insertions, 45 deletions
diff --git a/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp b/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp index 9ee874f355..948dc66e71 100644 --- a/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp +++ b/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** 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 "testtypes.h" #include <QUrl> @@ -38,16 +13,16 @@ #include <QQmlProperty> #include <QQmlComponent> #include <QQmlIncubator> -#include "../../shared/util.h" #include <private/qjsvalue_p.h> #include <private/qqmlincubator_p.h> #include <private/qqmlobjectcreator_p.h> +#include <QtQuickTestUtils/private/qmlutils_p.h> class tst_qqmlincubator : public QQmlDataTest { Q_OBJECT public: - tst_qqmlincubator() {} + tst_qqmlincubator() : QQmlDataTest(QT_QMLTEST_DATADIR) {} private slots: void initTestCase() override; @@ -368,7 +343,7 @@ void tst_qqmlincubator::setInitialState() MyIncubator(QQmlIncubator::IncubationMode mode) : QQmlIncubator(mode) {} - virtual void setInitialState(QObject *o) { + void setInitialState(QObject *o) override { QQmlProperty::write(o, "test2", 19); QQmlProperty::write(o, "testData1", 201); } @@ -442,7 +417,7 @@ void tst_qqmlincubator::objectDeletionAfterInit() MyIncubator(QQmlIncubator::IncubationMode mode) : QQmlIncubator(mode), obj(nullptr) {} - virtual void setInitialState(QObject *o) { + void setInitialState(QObject *o) override { obj = o; } @@ -487,7 +462,7 @@ public: MyIncubator(QQmlIncubator::IncubationMode mode, QObject *s) : QQmlIncubator(mode), switcher(s) {} - virtual void setInitialState(QObject *o) { + void setInitialState(QObject *o) override { if (o->objectName() == "switchMe") connect(o, SIGNAL(switchMe()), switcher, SLOT(switchIt())); } @@ -531,8 +506,8 @@ void tst_qqmlincubator::statusChanged() QList<int> statuses; protected: - virtual void statusChanged(Status s) { statuses << s; } - virtual void setInitialState(QObject *) { statuses << -1; } + void statusChanged(Status s) override { statuses << s; } + void setInitialState(QObject *) override { statuses << -1; } }; { @@ -542,7 +517,7 @@ void tst_qqmlincubator::statusChanged() MyIncubator incubator(QQmlIncubator::Synchronous); component.create(incubator); QVERIFY(incubator.isReady()); - QCOMPARE(incubator.statuses.count(), 3); + QCOMPARE(incubator.statuses.size(), 3); QCOMPARE(incubator.statuses.at(0), int(QQmlIncubator::Loading)); QCOMPARE(incubator.statuses.at(1), -1); QCOMPARE(incubator.statuses.at(2), int(QQmlIncubator::Ready)); @@ -556,7 +531,7 @@ void tst_qqmlincubator::statusChanged() MyIncubator incubator(QQmlIncubator::Asynchronous); component.create(incubator); QVERIFY(incubator.isLoading()); - QCOMPARE(incubator.statuses.count(), 1); + QCOMPARE(incubator.statuses.size(), 1); QCOMPARE(incubator.statuses.at(0), int(QQmlIncubator::Loading)); { @@ -564,7 +539,7 @@ void tst_qqmlincubator::statusChanged() controller.incubateWhile(&b); } - QCOMPARE(incubator.statuses.count(), 3); + QCOMPARE(incubator.statuses.size(), 3); QCOMPARE(incubator.statuses.at(0), int(QQmlIncubator::Loading)); QCOMPARE(incubator.statuses.at(1), -1); QCOMPARE(incubator.statuses.at(2), int(QQmlIncubator::Ready)); @@ -578,7 +553,7 @@ void tst_qqmlincubator::statusChanged() MyIncubator incubator(QQmlIncubator::Asynchronous); component2.create(incubator); QVERIFY(incubator.isLoading()); - QCOMPARE(incubator.statuses.count(), 1); + QCOMPARE(incubator.statuses.size(), 1); QCOMPARE(incubator.statuses.at(0), int(QQmlIncubator::Loading)); { @@ -587,7 +562,7 @@ void tst_qqmlincubator::statusChanged() } QVERIFY(incubator.isReady()); - QCOMPARE(incubator.statuses.count(), 3); + QCOMPARE(incubator.statuses.size(), 3); QCOMPARE(incubator.statuses.at(0), int(QQmlIncubator::Loading)); QCOMPARE(incubator.statuses.at(1), -1); QCOMPARE(incubator.statuses.at(2), int(QQmlIncubator::Ready)); @@ -762,7 +737,7 @@ void tst_qqmlincubator::chainedAsynchronousIfNested() : QQmlIncubator(AsynchronousIfNested), next(next), component(component), ctxt(ctxt) {} protected: - virtual void statusChanged(Status s) { + void statusChanged(Status s) override { if (s == Ready && next) component->create(*next, nullptr, ctxt); } @@ -836,7 +811,7 @@ void tst_qqmlincubator::chainedAsynchronousIfNestedOnCompleted() : QQmlIncubator(AsynchronousIfNested), next(next), component(component), ctxt(ctxt) {} protected: - virtual void statusChanged(Status s) { + void statusChanged(Status s) override { if (s == Ready && next) { component->create(*next, nullptr, ctxt); } @@ -969,7 +944,7 @@ void tst_qqmlincubator::chainedAsynchronousClear() : QQmlIncubator(AsynchronousIfNested), next(next), component(component), ctxt(ctxt) {} protected: - virtual void statusChanged(Status s) { + void statusChanged(Status s) override { if (s == Ready && next) { component->create(*next, nullptr, ctxt); } @@ -1079,7 +1054,7 @@ void tst_qqmlincubator::selfDelete() : QQmlIncubator(mode), done(done), status(status) {} protected: - virtual void statusChanged(Status s) { + void statusChanged(Status s) override { if (s == status) { *done = true; if (s == Ready) delete object(); @@ -1173,7 +1148,7 @@ void tst_qqmlincubator::garbageCollection() QQmlComponent component(&engine, testFileUrl("garbageCollection.qml")); QScopedPointer<QObject> obj(component.create()); - engine.collectGarbage(); + gc(engine); std::atomic<bool> b{true}; controller.incubateWhile(&b); @@ -1191,8 +1166,14 @@ void tst_qqmlincubator::garbageCollection() incubatorVariant.clear(); // verify incubator is correctly collected now that incubation is complete and all references are gone - engine.collectGarbage(); + gc(engine); QVERIFY(weakIncubatorRef.isNullOrUndefined()); + + QQmlComponent component2(&engine, testFileUrl("garbageCollection2.qml")); + QVERIFY2(component2.isReady(), qPrintable(component2.errorString())); + QScopedPointer<QObject> obj2(component2.create()); + QVERIFY(!obj2.isNull()); + QVERIFY(obj2->property("incubated").value<QObject *>() != nullptr); } void tst_qqmlincubator::requiredProperties() |