summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-12-08 16:03:36 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-12-09 14:39:44 +0000
commit0292acf06df4444086586b951dd1567506e07fa0 (patch)
tree870aa71f12ac27624188e8af1689800ec26a5938 /tests/auto/corelib
parent2f60a68ca411d79b9a43a0a82dc25a88aabc6bff (diff)
QProperty: Handle eager binding calling setBinding
When an eager binding triggers a setBinding call, we end up with a special kind of binding loop: setBinding() -> evaluate -> notifyObserver ^ | | / ---------------------------- We now catch set condition, and set the binding status to BindingLoop (with a distinct description). Task-number: QTBUG-87153 Task-number: QTBUG-87733 Change-Id: I9f9915797d82eab820fc279baceaf89d7e5a3f4a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit ddc585b7c773786045f3658d7da5425ed2f2f786) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
index 5ae92e8981..ca2de478cf 100644
--- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
+++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
@@ -462,6 +462,7 @@ class BindingLoopTester : public QObject
eagerData2.setBinding(Qt::makePropertyBinding([&](){ return eagerData.value() + 1; } ) );
i->setValue(42);
}
+ BindingLoopTester() {}
int eagerProp() {return eagerData.value();}
void setEagerProp(int i) { eagerData = i; }
@@ -495,11 +496,21 @@ void tst_QProperty::bindingLoop()
QCOMPARE(secondProp.binding().error().type(), QPropertyBindingError::BindingLoop);
- QProperty<int> i;
- BindingLoopTester tester(&i);
- QCOMPARE(tester.bindableEagerProp().binding().error().type(), QPropertyBindingError::BindingLoop);
- QEXPECT_FAIL("", "Only the first property in a dependency cycle is set to the error state", Continue);
- QCOMPARE(tester.bindableEagerProp2().binding().error().type(), QPropertyBindingError::BindingLoop);
+ {
+ QProperty<int> i;
+ BindingLoopTester tester(&i);
+ QCOMPARE(tester.bindableEagerProp().binding().error().type(), QPropertyBindingError::BindingLoop);
+ QCOMPARE(tester.bindableEagerProp2().binding().error().type(), QPropertyBindingError::BindingLoop);
+ }
+ {
+ BindingLoopTester tester;
+ auto handler = tester.bindableEagerProp().onValueChanged([&]() {
+ tester.bindableEagerProp().setBinding([](){return 42;});
+ });
+ tester.bindableEagerProp().setBinding([]() {return 42;});
+ QCOMPARE(tester.bindableEagerProp().binding().error().type(), QPropertyBindingError::BindingLoop);
+ QCOMPARE(tester.bindableEagerProp().binding().error().description(), "Binding set during binding evaluation!");
+ }
}
class ReallocTester : public QObject