aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2022-05-09 17:35:35 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2022-05-12 17:36:12 +0200
commit5cd59bff0c2f077ab47c40710a5267c06d3d2aa9 (patch)
treeb3a1f34ce103f1834f20f5921c33f02ad646cff4 /tests
parentc8f9cb050df690696422df2f79f1124340037547 (diff)
Support querying indirect extensions for a given object
Introduce a private version of qmlExtendedObject() that returns an index-based extension (where 0 represents an extension on the leaf type and N represents a (N - 1)th base type's extension) Teach QQmlProxyMetaObject to distinguish different extension proxies. Its custom metaCall can now query up to 128 extensions (should be enough for the user needs) Change-Id: I5520a1e84501f1f9fe6a8e77d8269009a12c255c Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmllanguage/testtypes.h29
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp58
2 files changed, 87 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h
index 8efccbc0fb..ca42ae02bc 100644
--- a/tests/auto/qml/qqmllanguage/testtypes.h
+++ b/tests/auto/qml/qqmllanguage/testtypes.h
@@ -1851,6 +1851,35 @@ public:
ExtendedInParentByIndirect(QObject *parent = nullptr) : ExtendedByIndirect(parent) { }
};
+class MultiExtensionThreeExtensions : public MultiExtension
+{
+ Q_OBJECT
+ QML_ELEMENT
+ QML_EXTENDED(Extension)
+public:
+ MultiExtensionThreeExtensions(QObject *parent = nullptr) : MultiExtension(parent) { }
+};
+
+class MultiExtensionWithoutExtension : public MultiExtension
+{
+ Q_OBJECT
+ QML_ANONYMOUS
+public:
+ MultiExtensionWithoutExtension(QObject *parent = nullptr) : MultiExtension(parent) { }
+};
+
+class MultiExtensionWithExtensionInBaseBase : public MultiExtensionWithoutExtension
+{
+ Q_OBJECT
+ QML_ELEMENT
+ QML_EXTENDED(Extension)
+public:
+ MultiExtensionWithExtensionInBaseBase(QObject *parent = nullptr)
+ : MultiExtensionWithoutExtension(parent)
+ {
+ }
+};
+
class StringSignaler : public QObject
{
Q_OBJECT
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 1e3f06a9e9..bfcd146b10 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -365,6 +365,7 @@ private slots:
void qtbug_86482();
void multiExtension();
+ void multiExtensionExtra();
void multiExtensionIndirect();
void extensionSpecial();
void invalidInlineComponent();
@@ -6395,6 +6396,63 @@ void tst_qqmllanguage::multiExtension()
QCOMPARE(o->property("d").toInt(), 22);
QCOMPARE(o->property("f").toInt(), 31);
QCOMPARE(o->property("g").toInt(), 44); // NB: taken from the type, not from the extension!
+
+ QObject *extension = qmlExtendedObject(o.get());
+ QVERIFY(extension != nullptr);
+ QVERIFY(qobject_cast<ExtensionB *>(extension) != nullptr);
+
+ QCOMPARE(QQmlPrivate::qmlExtendedObject(o.get(), 0), extension);
+ QObject *baseTypeExtension = QQmlPrivate::qmlExtendedObject(o.get(), 1);
+ QVERIFY(baseTypeExtension);
+ QVERIFY(qobject_cast<ExtensionA *>(baseTypeExtension) != nullptr);
+}
+
+void tst_qqmllanguage::multiExtensionExtra()
+{
+ QQmlEngine engine;
+ {
+ QQmlComponent c(&engine);
+ c.setData("import StaticTest\nMultiExtensionThreeExtensions {}", QUrl());
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+
+ QObject *extension = qmlExtendedObject(o.get());
+ QVERIFY(extension != nullptr);
+ QVERIFY(qobject_cast<Extension *>(extension) != nullptr);
+
+ QCOMPARE(QQmlPrivate::qmlExtendedObject(o.get(), 0), extension);
+ QObject *baseTypeExtension = QQmlPrivate::qmlExtendedObject(o.get(), 1);
+ QVERIFY(baseTypeExtension);
+ QVERIFY(qobject_cast<ExtensionB *>(baseTypeExtension) != nullptr);
+ QObject *baseBaseTypeExtension = QQmlPrivate::qmlExtendedObject(o.get(), 2);
+ QVERIFY(baseBaseTypeExtension);
+ QVERIFY(qobject_cast<ExtensionA *>(baseBaseTypeExtension) != nullptr);
+ }
+
+ {
+ QQmlComponent c(&engine);
+ c.setData("import StaticTest\nMultiExtensionWithExtensionInBaseBase {}", QUrl());
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+
+ QObject *extension = qmlExtendedObject(o.get());
+ QVERIFY(extension != nullptr);
+ QVERIFY(qobject_cast<Extension *>(extension) != nullptr);
+
+ QCOMPARE(QQmlPrivate::qmlExtendedObject(o.get(), 0), extension);
+
+ QObject *pseudoExtension = QQmlPrivate::qmlExtendedObject(o.get(), 1);
+ QVERIFY(pseudoExtension);
+ QVERIFY(qobject_cast<ExtensionB *>(pseudoExtension) != nullptr);
+
+ QObject *baseBaseTypeExtension = QQmlPrivate::qmlExtendedObject(o.get(), 2);
+ QVERIFY(baseBaseTypeExtension);
+ QVERIFY(qobject_cast<ExtensionB *>(baseBaseTypeExtension) != nullptr);
+
+ QObject *baseBaseBaseTypeExtension = QQmlPrivate::qmlExtendedObject(o.get(), 3);
+ QVERIFY(baseBaseBaseTypeExtension);
+ QVERIFY(qobject_cast<ExtensionA *>(baseBaseBaseTypeExtension) != nullptr);
+ }
}
void tst_qqmllanguage::multiExtensionIndirect()