summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-11-30 10:40:00 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-12-01 18:43:20 +0000
commite50cd75a77e678d409c72ab8fdd503b5b9e8ded8 (patch)
treeaaf3aeb4c79fe83b1e740a34988ea2b1816bf3ac /tests
parentb874ff67d0fc406c19c94eab7384c4e97fdab6b2 (diff)
QProperty: add test case for spurious dependency issue
Task-number: QTBUG-88999 Change-Id: Ifcbf23fedfb795771550762dfed8fc38bce65794 Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit cea8b5832c56e92aba2b028afc965ddcf384d37b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
index 31807bf1a7..d824d39941 100644
--- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
+++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
@@ -87,6 +87,8 @@ private slots:
void modifyObserverListWhileIterating();
void compatPropertyNoDobuleNotification();
+
+ void noFakeDependencies();
};
void tst_QProperty::functorBinding()
@@ -1353,6 +1355,56 @@ void tst_QProperty::compatPropertyNoDobuleNotification()
QCOMPARE(counter, 1);
}
+class FakeDependencyCreator : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(int prop1 READ prop1 WRITE setProp1 NOTIFY prop1Changed BINDABLE bindableProp1)
+ Q_PROPERTY(int prop2 READ prop2 WRITE setProp2 NOTIFY prop2Changed BINDABLE bindableProp2)
+ Q_PROPERTY(int prop3 READ prop3 WRITE setProp3 NOTIFY prop3Changed BINDABLE bindableProp3)
+
+signals:
+ void prop1Changed();
+ void prop2Changed();
+ void prop3Changed();
+
+public:
+ void setProp1(int val) { prop1Data = val; emit prop1Changed();}
+ void setProp2(int val) { prop2Data = val; emit prop2Changed();}
+ void setProp3(int val) { prop3Data = val; emit prop3Changed();}
+
+ int prop1() { return prop1Data; }
+ int prop2() { return prop2Data; }
+ int prop3() { return prop3Data; }
+
+ QBindable<int> bindableProp1() { return QBindable<int>(&prop1Data); }
+ QBindable<int> bindableProp2() { return QBindable<int>(&prop2Data); }
+ QBindable<int> bindableProp3() { return QBindable<int>(&prop3Data); }
+
+private:
+ Q_OBJECT_COMPAT_PROPERTY(FakeDependencyCreator, int, prop1Data, &FakeDependencyCreator::setProp1);
+ Q_OBJECT_COMPAT_PROPERTY(FakeDependencyCreator, int, prop2Data, &FakeDependencyCreator::setProp2);
+ Q_OBJECT_COMPAT_PROPERTY(FakeDependencyCreator, int, prop3Data, &FakeDependencyCreator::setProp3);
+};
+
+void tst_QProperty::noFakeDependencies()
+{
+ FakeDependencyCreator fdc;
+ int bindingFunctionCalled = 0;
+ fdc.bindableProp1().setBinding([&]() -> int {++bindingFunctionCalled; return fdc.prop2();});
+ fdc.setProp2(42);
+ QCOMPARE(fdc.prop1(), 42); // basic binding works
+
+ int slotCounter = 0;
+ QObject::connect(&fdc, &FakeDependencyCreator::prop1Changed, &fdc, [&](){ (void) fdc.prop3(); ++slotCounter;});
+ fdc.setProp2(13);
+ QCOMPARE(slotCounter, 1); // sanity check
+ int old = bindingFunctionCalled;
+ fdc.setProp3(100);
+ QEXPECT_FAIL("", "Known to create a spurious dependency", Continue);
+ QCOMPARE(old, bindingFunctionCalled);
+}
+
QTEST_MAIN(tst_QProperty);
#include "tst_qproperty.moc"