diff options
Diffstat (limited to 'tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp')
-rw-r--r-- | tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp index 7a214acbc4..4195459af5 100644 --- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -107,6 +107,7 @@ private slots: void noDoubleNotification(); void groupedNotifications(); void groupedNotificationConsistency(); + void uninstalledBindingDoesNotEvaluate(); }; void tst_QProperty::functorBinding() @@ -1747,6 +1748,32 @@ void tst_QProperty::groupedNotificationConsistency() QVERIFY(areEqual); // value changed runs after everything has been evaluated } +void tst_QProperty::uninstalledBindingDoesNotEvaluate() +{ + QProperty<int> i; + QProperty<int> j; + int bindingEvaluationCounter = 0; + i.setBinding([&](){ + bindingEvaluationCounter++; + return j.value(); + }); + QCOMPARE(bindingEvaluationCounter, 1); + // Sanity check: if we force a binding reevaluation, + j = 42; + // the binding function will be called again. + QCOMPARE(bindingEvaluationCounter, 2); + // If we keep referencing the binding + auto keptBinding = i.binding(); + // but have it not installed on a property + i = 10; + QVERIFY(!i.hasBinding()); + QVERIFY(!keptBinding.isNull()); + // then changing a dependency + j = 12; + // does not lead to the binding being reevaluated. + QCOMPARE(bindingEvaluationCounter, 2); +} + QTEST_MAIN(tst_QProperty); #undef QT_SOURCE_LOCATION_NAMESPACE |