aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmltc
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2022-03-30 17:16:11 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2022-04-22 10:38:16 +0200
commitff88fb0c82b9d5e135f1eaae51cab98aa16a15ee (patch)
tree5d5737c0b09cffb761ceed326c359229854dc3d9 /tests/auto/qml/qmltc
parent32b574314ded3c1e770a061523f883d5bca589e9 (diff)
qmlcompiler: Support attached property bindings
Extend group property binding creation with attached properties case As a drive by, add extra attached property tests for QML and qmltc, covering the case where an attaching type exists in both base and derived types Task-number: QTBUG-102082 Change-Id: I6c0d2b941da72d6dab7fc05a4f7b2a7875423ef0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmltc')
-rw-r--r--tests/auto/qml/qmltc/data/AttachedProperty.qml (renamed from tests/auto/qml/qmltc/data/attachedProperty.qml)0
-rw-r--r--tests/auto/qml/qmltc/data/CMakeLists.txt3
-rw-r--r--tests/auto/qml/qmltc/data/attachedPropertyDerived.qml7
-rw-r--r--tests/auto/qml/qmltc/data/cpptypes/testattachedtype.cpp7
-rw-r--r--tests/auto/qml/qmltc/data/cpptypes/testattachedtype.h1
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.cpp28
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.h1
7 files changed, 43 insertions, 4 deletions
diff --git a/tests/auto/qml/qmltc/data/attachedProperty.qml b/tests/auto/qml/qmltc/data/AttachedProperty.qml
index a8ab457980..a8ab457980 100644
--- a/tests/auto/qml/qmltc/data/attachedProperty.qml
+++ b/tests/auto/qml/qmltc/data/AttachedProperty.qml
diff --git a/tests/auto/qml/qmltc/data/CMakeLists.txt b/tests/auto/qml/qmltc/data/CMakeLists.txt
index c58378aa3f..2b83ec6042 100644
--- a/tests/auto/qml/qmltc/data/CMakeLists.txt
+++ b/tests/auto/qml/qmltc/data/CMakeLists.txt
@@ -39,7 +39,8 @@ set(qml_sources
defaultPropertyCorrectSelection.qml
# defaultAlias.qml
propertyReturningFunction.qml
- attachedProperty.qml
+ AttachedProperty.qml
+ attachedPropertyDerived.qml
groupedProperty.qml
groupedProperty_qquicktext.qml
localImport.qml
diff --git a/tests/auto/qml/qmltc/data/attachedPropertyDerived.qml b/tests/auto/qml/qmltc/data/attachedPropertyDerived.qml
new file mode 100644
index 0000000000..532f9fea79
--- /dev/null
+++ b/tests/auto/qml/qmltc/data/attachedPropertyDerived.qml
@@ -0,0 +1,7 @@
+import QmltcTests 1.0
+import QtQml 2.0
+
+AttachedProperty {
+ id: root
+ TestType.attachedCount: -314
+}
diff --git a/tests/auto/qml/qmltc/data/cpptypes/testattachedtype.cpp b/tests/auto/qml/qmltc/data/cpptypes/testattachedtype.cpp
index 04ca79de35..84ffe6333e 100644
--- a/tests/auto/qml/qmltc/data/cpptypes/testattachedtype.cpp
+++ b/tests/auto/qml/qmltc/data/cpptypes/testattachedtype.cpp
@@ -28,7 +28,12 @@
#include "testattachedtype.h"
-TestTypeAttached::TestTypeAttached(QObject *parent) : QObject(parent), m_count(0) { }
+TestTypeAttached::TestTypeAttached(QObject *parent) : QObject(parent), m_count(0)
+{
+ ++creationCount;
+}
+
+int TestTypeAttached::creationCount = 0;
int TestTypeAttached::getAttachedCount() const
{
diff --git a/tests/auto/qml/qmltc/data/cpptypes/testattachedtype.h b/tests/auto/qml/qmltc/data/cpptypes/testattachedtype.h
index 62af6c27c7..f9d890a751 100644
--- a/tests/auto/qml/qmltc/data/cpptypes/testattachedtype.h
+++ b/tests/auto/qml/qmltc/data/cpptypes/testattachedtype.h
@@ -62,6 +62,7 @@ public:
void setAttachedObject(QObject *v);
QBindable<QObject *> bindableAttachedObject();
+ static int creationCount;
signals:
void triggered();
diff --git a/tests/auto/qml/qmltc/tst_qmltc.cpp b/tests/auto/qml/qmltc/tst_qmltc.cpp
index ef92dd5c74..4b0ad9d469 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.cpp
+++ b/tests/auto/qml/qmltc/tst_qmltc.cpp
@@ -60,6 +60,7 @@
#include "defaultproperty.h"
#include "defaultpropertycorrectselection.h"
#include "attachedproperty.h"
+#include "attachedpropertyderived.h"
#include "groupedproperty.h"
#include "groupedproperty_qquicktext.h"
#include "localimport.h"
@@ -154,7 +155,8 @@ void tst_qmltc::initTestCase()
QUrl("qrc:/QmltcTests/listPropertySameName.qml"),
QUrl("qrc:/QmltcTests/defaultProperty.qml"),
QUrl("qrc:/QmltcTests/defaultPropertyCorrectSelection.qml"),
- QUrl("qrc:/QmltcTests/attachedProperty.qml"),
+ QUrl("qrc:/QmltcTests/AttachedProperty.qml"),
+ QUrl("qrc:/QmltcTests/attachedPropertyDerived.qml"),
QUrl("qrc:/QmltcTests/groupedProperty.qml"),
QUrl("qrc:/QmltcTests/groupedProperty_qquicktext.qml"),
QUrl("qrc:/QmltcTests/localImport.qml"),
@@ -1182,8 +1184,13 @@ void tst_qmltc::defaultAlias()
void tst_qmltc::attachedProperty()
{
+ QScopeGuard exitTest([oldCount = TestTypeAttached::creationCount]() {
+ QCOMPARE(TestTypeAttached::creationCount, oldCount + 1);
+ });
+ Q_UNUSED(exitTest);
+
QQmlEngine e;
- PREPEND_NAMESPACE(attachedProperty) created(&e);
+ PREPEND_NAMESPACE(AttachedProperty) created(&e);
TestTypeAttached *attached = qobject_cast<TestTypeAttached *>(
qmlAttachedPropertiesObject<TestType>(&created, false));
@@ -1218,6 +1225,23 @@ void tst_qmltc::attachedProperty()
QCOMPARE(attached->getAttachedFormula(), 42 * 2 * 2 * 2);
}
+void tst_qmltc::attachedPropertyObjectCreatedOnce()
+{
+ QScopeGuard exitTest([oldCount = TestTypeAttached::creationCount]() {
+ QCOMPARE(TestTypeAttached::creationCount, oldCount + 1);
+ });
+ Q_UNUSED(exitTest);
+
+ QQmlEngine e;
+ PREPEND_NAMESPACE(attachedPropertyDerived) created(&e);
+
+ TestTypeAttached *attached = qobject_cast<TestTypeAttached *>(
+ qmlAttachedPropertiesObject<TestType>(&created, false));
+ QVERIFY(attached);
+
+ QCOMPARE(attached->getAttachedCount(), -314);
+}
+
void tst_qmltc::groupedProperty()
{
QQmlEngine e;
diff --git a/tests/auto/qml/qmltc/tst_qmltc.h b/tests/auto/qml/qmltc/tst_qmltc.h
index 597e7c2ee7..09240444dd 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.h
+++ b/tests/auto/qml/qmltc/tst_qmltc.h
@@ -73,6 +73,7 @@ private slots:
void defaultPropertyCorrectSelection();
void defaultAlias();
void attachedProperty();
+ void attachedPropertyObjectCreatedOnce();
void groupedProperty();
void groupedProperty_qquicktext();
void localImport();