diff options
Diffstat (limited to 'tests/auto/qml/qqmlpropertycache')
6 files changed, 203 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlpropertycache/CMakeLists.txt b/tests/auto/qml/qqmlpropertycache/CMakeLists.txt index 8a7ffd2d9d..6dcb042dab 100644 --- a/tests/auto/qml/qqmlpropertycache/CMakeLists.txt +++ b/tests/auto/qml/qqmlpropertycache/CMakeLists.txt @@ -7,6 +7,12 @@ ## tst_qqmlpropertycache Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qqmlpropertycache LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/tests/auto/qml/qqmlpropertycache/data/duplicateIdsAndGeneralizedGroupProperties.qml b/tests/auto/qml/qqmlpropertycache/data/duplicateIdsAndGeneralizedGroupProperties.qml new file mode 100644 index 0000000000..2dd2cd8e21 --- /dev/null +++ b/tests/auto/qml/qqmlpropertycache/data/duplicateIdsAndGeneralizedGroupProperties.qml @@ -0,0 +1,64 @@ +import QtQuick 2.15 + +Item { + component First : Item { + Item { + id: a + } + + states: [ + State { + name: "test1" + + PropertyChanges { + a.enabled: false + } + } + ] + } + + component Second : Item { + QtObject { + id: a + property bool enabled: true + } + + states: [ + State { + name: "test2" + + PropertyChanges { + a.enabled: false + } + } + ] + + property Component cc: Item { + Item { id: a } + + states: [ + State { + name: "test3" + + PropertyChanges { + a.enabled: false + } + } + ] + } + } + + First { id: first } + Second { id: second } + property Item third: second.cc.createObject(); + + Component.onCompleted: { + console.log(1, first.data[0].enabled, second.data[0].enabled, third.data[0].enabled); + first.state = "test1"; + console.log(2, first.data[0].enabled, second.data[0].enabled, third.data[0].enabled); + second.state = "test2"; + console.log(3, first.data[0].enabled, second.data[0].enabled, third.data[0].enabled); + third.state = "test3"; + console.log(4, first.data[0].enabled, second.data[0].enabled, third.data[0].enabled); + } +} diff --git a/tests/auto/qml/qqmlpropertycache/data/overriddenSignal.qml b/tests/auto/qml/qqmlpropertycache/data/overriddenSignal.qml new file mode 100644 index 0000000000..c948d47a1b --- /dev/null +++ b/tests/auto/qml/qqmlpropertycache/data/overriddenSignal.qml @@ -0,0 +1,36 @@ +import QtQml +import Test.PropertyCache + +QtObject { + id: root + + property BaseObject obj: null + property Connections connection: Connections { + target: obj + function onPropertyAChanged() { ++root.a } + } + onObjChanged: { + connection.target = obj // Make sure this takes effect before sending the signal + obj.propertyAChanged() + } + + property BaseObject obj2: null + property Connections connection2: Connections { + target: obj2 + function onSignalA() { ++root.b } + } + onObj2Changed: { + connection2.target = obj2 // Make sure this takes effect before sending the signal + obj2.signalA(); + } + + property BaseObject theObj: BaseObject {} + Component.onCompleted: { + // Make sure the change signals are triggered also initially + obj = theObj; + obj2 = theObj; + } + + property int a: 0 + property int b: 0 +} diff --git a/tests/auto/qml/qqmlpropertycache/data/qmlOverriddenSignal.qml b/tests/auto/qml/qqmlpropertycache/data/qmlOverriddenSignal.qml new file mode 100644 index 0000000000..b8fee08978 --- /dev/null +++ b/tests/auto/qml/qqmlpropertycache/data/qmlOverriddenSignal.qml @@ -0,0 +1,8 @@ +import QtQml +import Test.PropertyCache + +BaseObject { + property int callCount: 0 + function signalA() { ++callCount } + Component.onCompleted: signalA() +} diff --git a/tests/auto/qml/qqmlpropertycache/data/qmlOverriddenSignal2.qml b/tests/auto/qml/qqmlpropertycache/data/qmlOverriddenSignal2.qml new file mode 100644 index 0000000000..cbf1cfe037 --- /dev/null +++ b/tests/auto/qml/qqmlpropertycache/data/qmlOverriddenSignal2.qml @@ -0,0 +1,6 @@ +import QtQml +import Test.PropertyCache + +BaseObject { + signal propertyAChanged +} diff --git a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp index cfea7c0da1..6af2a3e371 100644 --- a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp +++ b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qtest.h> #include <private/qqmlpropertycache_p.h> @@ -8,6 +8,7 @@ #include <QtQml/qqmlcomponent.h> #include <private/qmetaobjectbuilder_p.h> #include <private/qqmlcontextdata_p.h> +#include <private/qqmlpropertycachecreator_p.h> #include <QCryptographicHash> #include <QtQuickTestUtils/private/qmlutils_p.h> @@ -34,6 +35,8 @@ private slots: void derivedGadgetMethod(); void restrictRegistrationVersion(); void rejectOverriddenFinal(); + void overriddenSignals(); + void duplicateIdsAndGeneralizedGroupProperties(); private: QQmlEngine engine; @@ -164,6 +167,19 @@ Q_SIGNALS: void signalB(); }; +class OverriddenSignal : public BaseObject +{ + Q_OBJECT +public: + OverriddenSignal(QObject *parent = nullptr) : BaseObject(parent) {} + + Q_INVOKABLE void propertyAChanged() { ++propertyAChangedCalled; } + int propertyAChangedCalled = 0; + +Q_SIGNALS: + void signalA(); +}; + const QQmlPropertyData *cacheProperty(const QQmlPropertyCache::ConstPtr &cache, const char *name) { return cache->property(QLatin1String(name), nullptr, nullptr); @@ -707,4 +723,70 @@ void tst_qqmlpropertycache::rejectOverriddenFinal() QCOMPARE(o->property("c").toInt(), 0); } +void tst_qqmlpropertycache::overriddenSignals() +{ + qmlRegisterTypesAndRevisions<BaseObject>("Test.PropertyCache", 3); + QQmlEngine engine; + + QQmlComponent c1(&engine, testFileUrl("overriddenSignal.qml")); + QVERIFY2(!c1.isError(), qPrintable(c1.errorString())); + + QScopedPointer<QObject> o(c1.create()); + + // the propertyAChanged _signal_ is sent once (initially). + QCOMPARE(o->property("a").toInt(), 1); + + // signalA() is invoked once as signal, and the other time as method since both are C++. + QCOMPARE(o->property("b").toInt(), 1); + + OverriddenSignal *derived = new OverriddenSignal(o.data()); + + // Does call our overridden method, since that is defined in C++ + QCOMPARE(derived->propertyAChangedCalled, 0); + o->setProperty("obj", QVariant::fromValue(derived)); + QCOMPARE(derived->propertyAChangedCalled, 1); + + o->setProperty("obj2", QVariant::fromValue(derived)); + + // the propertyAChanged _signal_ is sent once (initially). + QCOMPARE(o->property("a").toInt(), 1); + + // We get to receive both signalA() signals since we only match by name. + QCOMPARE(o->property("b").toInt(), 2); + + // We shouldn't be allowed to define such things in QML, though. + + const QUrl c2Url = testFileUrl("qmlOverriddenSignal.qml"); + QTest::ignoreMessage( + QtWarningMsg, + qPrintable(c2Url.toString() + QLatin1String( + ":6:14: Duplicate method name: " + "invalid override of property change signal or superclass signal"))); + QQmlComponent c2(&engine, c2Url); + // Should be an error, but we can't enforce it yet. + + const QUrl c3Url = testFileUrl("qmlOverriddenSignal2.qml"); + QTest::ignoreMessage( + QtWarningMsg, + qPrintable(c3Url.toString() + QLatin1String( + ":5:12: Duplicate signal name: " + "invalid override of property change signal or superclass signal"))); + QQmlComponent c3(&engine, c3Url); + // Should be an error, but we can't enforce it yet. +} + +void tst_qqmlpropertycache::duplicateIdsAndGeneralizedGroupProperties() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("duplicateIdsAndGeneralizedGroupProperties.qml")); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + + QTest::ignoreMessage(QtDebugMsg, "1 true true true"); + QTest::ignoreMessage(QtDebugMsg, "2 false true true"); + QTest::ignoreMessage(QtDebugMsg, "3 false false true"); + QTest::ignoreMessage(QtDebugMsg, "4 false false false"); + + QScopedPointer<QObject> o(c.create()); +} + QTEST_MAIN(tst_qqmlpropertycache) |