summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-07-15 14:17:35 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-07-15 16:16:53 +0200
commit124590850b7017233e25366688715ef642c5cdc3 (patch)
tree0d8e3b2f0a32ad65c415bb70c0c83e7bb7cb5482 /tests/auto
parent5f3f23462e7990800b7d93daecd4ab8e895ef036 (diff)
Don't test for equality if types can't be compared
For types that don't have an operator==(), always trigger the binding and the changed notification. Task-number: QTBUG-85578 Change-Id: I41374f6d13c88106f4de83864e82172f3a248150 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
index 5f17bcb2b7..41cf60b55f 100644
--- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
+++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
@@ -72,6 +72,7 @@ private slots:
void notifiedProperty();
void notifiedPropertyWithOldValueCallback();
void notifiedPropertyWithGuard();
+ void typeNoOperatorEqual();
};
void tst_QProperty::functorBinding()
@@ -985,6 +986,77 @@ void tst_QProperty::notifiedPropertyWithGuard()
}
}
+void tst_QProperty::typeNoOperatorEqual()
+{
+ struct Uncomparable
+ {
+ int data = -1;
+ bool changedCalled = false;
+
+ Uncomparable(int value = 0)
+ : data(value)
+ {}
+ Uncomparable(const Uncomparable &other)
+ {
+ data = other.data;
+ changedCalled = false;
+ }
+ Uncomparable(Uncomparable &&other)
+ {
+ data = other.data;
+ changedCalled = false;
+ other.data = -1;
+ other.changedCalled = false;
+ }
+ Uncomparable &operator=(const Uncomparable &other)
+ {
+ data = other.data;
+ return *this;
+ }
+ Uncomparable &operator=(Uncomparable &&other)
+ {
+ data = other.data;
+ changedCalled = false;
+ other.data = -1;
+ other.changedCalled = false;
+ return *this;
+ }
+ bool operator==(const Uncomparable&) = delete;
+ bool operator!=(const Uncomparable&) = delete;
+
+ void changed()
+ {
+ changedCalled = true;
+ }
+ };
+
+ Uncomparable u1 = { 13 };
+ Uncomparable u2 = { 27 };
+
+ QProperty<Uncomparable> p1;
+ QProperty<Uncomparable> p2 = Qt::makePropertyBinding(p1);
+
+ QCOMPARE(p1.value().data, p2.value().data);
+ p1.setValue(u1);
+ QCOMPARE(p1.value().data, u1.data);
+ QCOMPARE(p1.value().data, p2.value().data);
+ p2.setValue(u2);
+ QCOMPARE(p1.value().data, u1.data);
+ QCOMPARE(p2.value().data, u2.data);
+
+ QProperty<Uncomparable> p3 = Qt::makePropertyBinding(p1);
+ p1.setValue(u1);
+ QCOMPARE(p1.value().data, p3.value().data);
+
+ QNotifiedProperty<Uncomparable, &Uncomparable::changed> np;
+ QVERIFY(np.value().data != u1.data);
+ np.setValue(&u1, u1);
+ QVERIFY(u1.changedCalled);
+ u1.changedCalled = false;
+ QCOMPARE(np.value().data, u1.data);
+ np.setValue(&u1, u1);
+ QVERIFY(u1.changedCalled);
+}
QTEST_MAIN(tst_QProperty);