aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlcomponent
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2021-12-20 15:44:59 +0100
committerAndrei Golubev <andrei.golubev@qt.io>2021-12-23 15:56:16 +0100
commit7b25a46fc7310db4c06a29f21bb3534c9d484cb2 (patch)
treebd845ace00d565e1b526fae523a70c90f15ed4b8 /tests/auto/qml/qqmlcomponent
parent71084db1df9453aa9c657b91f2dab6766a56903b (diff)
qqmlcomponent: Test interesting Component-based types
1) we do not allow "empty" Component objects 2) explicit components leak ids when used in implicit component setting (unlike non-components) As of now, just "document" this behavior by adding an extra test Change-Id: I42346217c2d6aed661c2e58d4c01a580c89a1fae Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlcomponent')
-rw-r--r--tests/auto/qml/qqmlcomponent/data/ComponentType.qml4
-rw-r--r--tests/auto/qml/qqmlcomponent/data/componentTypes.qml25
-rw-r--r--tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp42
3 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlcomponent/data/ComponentType.qml b/tests/auto/qml/qqmlcomponent/data/ComponentType.qml
new file mode 100644
index 0000000000..1e6fa88216
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/ComponentType.qml
@@ -0,0 +1,4 @@
+import QtQml
+Component {
+ QtObject {} // this is required
+}
diff --git a/tests/auto/qml/qqmlcomponent/data/componentTypes.qml b/tests/auto/qml/qqmlcomponent/data/componentTypes.qml
new file mode 100644
index 0000000000..48b68e9112
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/componentTypes.qml
@@ -0,0 +1,25 @@
+import QtQuick
+Item {
+ ComponentType { // normal type here
+ id: normal
+ property string text: "indirect component"
+ }
+
+ Component {
+ id: accessibleNormal
+ ComponentType {
+ id: inaccessibleNormal
+ }
+ }
+
+ property Component p2: ComponentType { id: accessible; property string text: "foo" }
+ property Component p3: Rectangle { id: inaccessible; property string text: "bar" }
+
+ TableView {
+ delegate: Rectangle { id: inaccessibleDelegate }
+ }
+
+ TableView {
+ delegate: ComponentType { id: accessibleDelegate }
+ }
+}
diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
index 2c11d63167..4f52661767 100644
--- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
+++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
@@ -157,6 +157,7 @@ private slots:
void qmlErrorIsReported();
void initJSValueProp();
void qmlPropertySignalExists();
+ void componentTypes();
private:
QQmlEngine engine;
@@ -1119,6 +1120,47 @@ void tst_qqmlcomponent::qmlPropertySignalExists()
QCOMPARE(o->property("p").toInt(), 42);
}
+void tst_qqmlcomponent::componentTypes()
+{
+ {
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ // not allowed: "Cannot create empty component specification"
+ component.setData("import QtQml; Component { }", QUrl());
+ QVERIFY(!component.isReady());
+ }
+
+ {
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.loadUrl(testFileUrl("ComponentType.qml"));
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(!o.isNull(), qPrintable(component.errorString()));
+ }
+
+ {
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.loadUrl(testFileUrl("componentTypes.qml"));
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(!o.isNull(), qPrintable(component.errorString()));
+
+ QQmlContext *ctx = engine.contextForObject(o.get());
+
+ QObject *normal = ctx->objectForName(u"normal"_qs);
+ QVERIFY(normal);
+ QCOMPARE(normal->property("text").toString(), u"indirect component"_qs);
+
+ // check (and thus "document" in code) various ways of how ids work
+ QVERIFY(ctx->objectForName(u"accessibleNormal"_qs));
+ QVERIFY(!ctx->objectForName(u"inaccessibleNormal"_qs));
+ QVERIFY(ctx->objectForName(u"accessible"_qs));
+ QVERIFY(!ctx->objectForName(u"inaccessible"_qs));
+ QVERIFY(ctx->objectForName(u"accessibleDelegate"_qs));
+ QVERIFY(!ctx->objectForName(u"inaccessibleDelegate"_qs));
+ }
+}
+
QTEST_MAIN(tst_qqmlcomponent)
#include "tst_qqmlcomponent.moc"