summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-05-28 17:10:10 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-06-03 18:53:40 +0200
commit07ded4912f82008549b69b61a598ec7b0d2b3325 (patch)
treec01e7856e7605152631ed9ea8f8c85a19002e3ea /tests/auto/corelib/kernel
parent5a1680ef131d89190e745131c18b50a4c0871d18 (diff)
Fix and compactify QNotifiedProperty
The static observer can live in a union with the inline observers. We only need to take care of calling the ctors and dtors manually then. In order for any observers to be called in the presence of a static observer, the static observer has to be called after the other observers. Change-Id: I2f56fa64f3fe6fcd7f06cc403929362da7d86f65 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r--tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
index 394438ab88..e606d121ec 100644
--- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
+++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
@@ -782,29 +782,76 @@ struct ClassWithNotifiedProperty
void tst_QProperty::notifiedProperty()
{
ClassWithNotifiedProperty instance;
+ std::array<QProperty<int>, 5> otherProperties = {
+ QProperty<int>([&]() { return instance.property + 1; }),
+ QProperty<int>([&]() { return instance.property + 2; }),
+ QProperty<int>([&]() { return instance.property + 3; }),
+ QProperty<int>([&]() { return instance.property + 4; }),
+ QProperty<int>([&]() { return instance.property + 5; }),
+ };
+
+ auto check = [&] {
+ const int val = instance.property.value();
+ for (int i = 0; i < int(otherProperties.size()); ++i)
+ QCOMPARE(otherProperties[i].value(), val + i + 1);
+ };
+
QVERIFY(instance.recordedValues.isEmpty());
+ check();
instance.property.setValue(&instance, 42);
QCOMPARE(instance.recordedValues.count(), 1);
QCOMPARE(instance.recordedValues.at(0), 42);
instance.recordedValues.clear();
+ check();
instance.property.setValue(&instance, 42);
QVERIFY(instance.recordedValues.isEmpty());
+ check();
+ int subscribedCount = 0;
QProperty<int> injectedValue(100);
instance.property.setBinding(&instance, [&injectedValue]() { return injectedValue.value(); });
+ auto subscriber = [&] { ++subscribedCount; };
+ std::array<QPropertyChangeHandler<decltype (subscriber)>, 10> subscribers = {
+ instance.property.subscribe(subscriber),
+ instance.property.subscribe(subscriber),
+ instance.property.subscribe(subscriber),
+ instance.property.subscribe(subscriber),
+ instance.property.subscribe(subscriber),
+ instance.property.subscribe(subscriber),
+ instance.property.subscribe(subscriber),
+ instance.property.subscribe(subscriber),
+ instance.property.subscribe(subscriber),
+ instance.property.subscribe(subscriber)
+ };
+
+ QCOMPARE(subscribedCount, 10);
+ subscribedCount = 0;
QCOMPARE(instance.property.value(), 100);
QCOMPARE(instance.recordedValues.count(), 1);
QCOMPARE(instance.recordedValues.at(0), 100);
instance.recordedValues.clear();
+ check();
+ QCOMPARE(subscribedCount, 0);
injectedValue = 200;
QCOMPARE(instance.property.value(), 200);
QCOMPARE(instance.recordedValues.count(), 1);
QCOMPARE(instance.recordedValues.at(0), 200);
instance.recordedValues.clear();
+ check();
+ QCOMPARE(subscribedCount, 10);
+ subscribedCount = 0;
+
+ injectedValue = 400;
+ QCOMPARE(instance.property.value(), 400);
+ QCOMPARE(instance.recordedValues.count(), 1);
+ QCOMPARE(instance.recordedValues.at(0), 400);
+ instance.recordedValues.clear();
+ check();
+ QCOMPARE(subscribedCount, 10);
}
QTEST_MAIN(tst_QProperty);