From 6b4e0c5803b4b8b4396791ba436d9692195993d6 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Fri, 25 Sep 2020 15:45:28 +0200 Subject: QProperty: fix QBindingStoragePrivate::reallocate related code In the internal hash map implementation, we have to ensure that the index is in the interval [0, size - 1]. Moreover, in setBinding we have to refetch the binding storage in case a reallocation happened. Change-Id: I11c6264f16537699c8908b647e2355a39ce87648 Reviewed-by: Lars Knoll --- .../corelib/kernel/qproperty/tst_qproperty.cpp | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp index 0394e9ccf7..d71053ff04 100644 --- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -60,6 +60,7 @@ private slots: void bindingSourceLocation(); void bindingError(); void bindingLoop(); + void realloc(); void changePropertyFromWithinChangeHandler(); void changePropertyFromWithinChangeHandlerThroughDependency(); void changePropertyFromWithinChangeHandler2(); @@ -567,6 +568,41 @@ void tst_QProperty::bindingLoop() QCOMPARE(tester.bindableEagerProp2().binding().error().type(), QPropertyBindingError::BindingLoop); } +class ReallocTester : public QObject +{ + Q_OBJECT + Q_PROPERTY(int prop1 READ prop1 WRITE setProp1 BINDABLE bindableProp1) + Q_PROPERTY(int prop2 READ prop2 WRITE setProp2 BINDABLE bindableProp2) + Q_PROPERTY(int prop3 READ prop3 WRITE setProp3 BINDABLE bindableProp3) + Q_PROPERTY(int prop4 READ prop4 WRITE setProp4 BINDABLE bindableProp4) + Q_PROPERTY(int prop5 READ prop5 WRITE setProp5 BINDABLE bindableProp5) +public: + ReallocTester(QObject *parent = nullptr) : QObject(parent) {} + + +#define GEN(N) \ + int prop##N() {return propData##N.value();} \ + void setProp##N(int i) { propData##N = i; } \ + QBindable bindableProp##N() {return QBindable(&propData##N);} \ + Q_OBJECT_COMPAT_PROPERTY(ReallocTester, int, propData##N, &ReallocTester::setProp##N) + GEN(1) + GEN(2) + GEN(3) + GEN(4) + GEN(5) +#undef GEN +}; + +void tst_QProperty::realloc() +{ + ReallocTester tester; + tester.bindableProp1().setBinding([&](){return tester.prop5();}); + tester.bindableProp2().setBinding([&](){return tester.prop5();}); + tester.bindableProp3().setBinding([&](){return tester.prop5();}); + tester.bindableProp4().setBinding([&](){return tester.prop5();}); + tester.bindableProp5().setBinding([&]() -> int{return 42;}); +}; + void tst_QProperty::changePropertyFromWithinChangeHandler() { QProperty property(100); -- cgit v1.2.3