summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp')
-rw-r--r--tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp98
1 files changed, 11 insertions, 87 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
index 848226713c..12fd124b18 100644
--- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
+++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
@@ -95,7 +95,6 @@ private slots:
void noFakeDependencies();
void bindablePropertyWithInitialization();
- void markDirty();
};
void tst_QProperty::functorBinding()
@@ -129,8 +128,8 @@ void tst_QProperty::multipleDependencies()
QProperty<int> sum;
sum.setBinding([&]() { return firstDependency + secondDependency; });
- QCOMPARE(QPropertyBindingDataPointer::get(firstDependency).observerCount(), 0);
- QCOMPARE(QPropertyBindingDataPointer::get(secondDependency).observerCount(), 0);
+ QCOMPARE(QPropertyBindingDataPointer::get(firstDependency).observerCount(), 1);
+ QCOMPARE(QPropertyBindingDataPointer::get(secondDependency).observerCount(), 1);
QCOMPARE(sum.value(), int(3));
QCOMPARE(QPropertyBindingDataPointer::get(firstDependency).observerCount(), 1);
@@ -484,23 +483,22 @@ class BindingLoopTester : public QObject
void tst_QProperty::bindingLoop()
{
- QScopedPointer<QProperty<int>> firstProp;
+ QProperty<int> firstProp;
QProperty<int> secondProp([&]() -> int {
- return firstProp ? firstProp->value() : 0;
+ return firstProp.value();
});
QProperty<int> thirdProp([&]() -> int {
return secondProp.value();
});
- firstProp.reset(new QProperty<int>());
- firstProp->setBinding([&]() -> int {
- return secondProp.value();
+ firstProp.setBinding([&]() -> int {
+ return secondProp.value() + thirdProp.value();
});
- QCOMPARE(thirdProp.value(), 0);
- QCOMPARE(secondProp.binding().error().type(), QPropertyBindingError::BindingLoop);
+ thirdProp.setValue(10);
+ QCOMPARE(firstProp.binding().error().type(), QPropertyBindingError::BindingLoop);
{
@@ -1200,7 +1198,9 @@ void tst_QProperty::qobjectObservers()
MyQObject object;
int onValueChangedCalled = 0;
{
- auto handler = object.bindableFoo().onValueChanged([&onValueChangedCalled]() { ++onValueChangedCalled;});
+ auto handler = object.bindableFoo().onValueChanged([&onValueChangedCalled]() {
+ ++onValueChangedCalled;
+ });
QCOMPARE(onValueChangedCalled, 0);
object.setFoo(10);
@@ -1606,82 +1606,6 @@ void tst_QProperty::bindablePropertyWithInitialization()
QCOMPARE(tester.prop3().anotherValue, 20);
}
-class MarkDirtyTester : public QObject
-{
- Q_OBJECT
-public:
- Q_PROPERTY(int value1 READ value1 WRITE setValue1 BINDABLE bindableValue1)
- Q_PROPERTY(int value2 READ value2 WRITE setValue1 BINDABLE bindableValue2)
- Q_PROPERTY(int computed READ computed BINDABLE bindableComputed)
-
- inline static int staticValue = 0;
-
- int value1() const {return m_value1;}
- void setValue1(int val) {m_value1 = val;}
- QBindable<int> bindableValue1() {return { &m_value1 };}
-
- int value2() const {return m_value2;}
- void setValue2(int val) { m_value2.setValue(val); }
- QBindable<int> bindableValue2() {return { &m_value2 };}
-
- int computed() const { return staticValue + m_value1; }
- QBindable<int> bindableComputed() {return {&m_computed};}
-
- void incrementStaticValue() {
- ++staticValue;
- m_computed.markDirty();
- }
-
- void markValue1Dirty() {
- m_value1.markDirty();
- }
-
- void markValue2Dirty() {
- m_value2.markDirty();
- }
-private:
- Q_OBJECT_BINDABLE_PROPERTY(MarkDirtyTester, int, m_value1, nullptr)
- Q_OBJECT_COMPAT_PROPERTY(MarkDirtyTester, int, m_value2, &MarkDirtyTester::setValue2)
- Q_OBJECT_COMPUTED_PROPERTY(MarkDirtyTester, int, m_computed, &MarkDirtyTester::computed)
-};
-
-void tst_QProperty::markDirty()
-{
- {
- QProperty<int> testProperty;
- int changeCounter = 0;
- auto handler = testProperty.onValueChanged([&](){++changeCounter;});
- testProperty.markDirty();
- QCOMPARE(changeCounter, 1);
- }
- {
- MarkDirtyTester dirtyTester;
- int computedChangeCounter = 0;
- int value1ChangeCounter = 0;
- auto handler = dirtyTester.bindableComputed().onValueChanged([&](){
- computedChangeCounter++;
- });
- auto handler2 = dirtyTester.bindableValue1().onValueChanged([&](){
- value1ChangeCounter++;
- });
- dirtyTester.incrementStaticValue();
- QCOMPARE(computedChangeCounter, 1);
- QCOMPARE(dirtyTester.computed(), 1);
- dirtyTester.markValue1Dirty();
- QCOMPARE(value1ChangeCounter, 1);
- QCOMPARE(computedChangeCounter, 1);
- }
- {
- MarkDirtyTester dirtyTester;
- int changeCounter = 0;
- auto handler = dirtyTester.bindableValue2().onValueChanged([&](){
- changeCounter++;
- });
- dirtyTester.markValue2Dirty();
- QCOMPARE(changeCounter, 1);
- }
-}
-
QTEST_MAIN(tst_QProperty);
#include "tst_qproperty.moc"