summaryrefslogtreecommitdiffstats
path: root/src/testlib/qpropertytesthelper_p.h
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-04-22 11:59:30 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2021-04-22 16:48:46 +0200
commit948261d70c1719dc7d4dfed7ecfd94ca9b9ade9e (patch)
tree8ecb8a83fbd5bd331cf30d2a2c1afc18a134b360 /src/testlib/qpropertytesthelper_p.h
parentbf65abc4ab49bb8511533886842c698631132eb0 (diff)
qpropertytesthelper: Check that the types match
If you have a property myprop of type float, testReadWritePropertyBasics would happily accept testReadWritePropertyBasics(myObject, 1, 2, "myProp") The test would then fail when setting bindings, as we would try to install a binding of type int on a float property, which gets rejected at runtime. To prevent unexpected failures, verify that the types match before doing any further checks. Change-Id: I3893563fce0e11f9e20afa7c6a1e1fe0385382ab Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/testlib/qpropertytesthelper_p.h')
-rw-r--r--src/testlib/qpropertytesthelper_p.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/testlib/qpropertytesthelper_p.h b/src/testlib/qpropertytesthelper_p.h
index 1a769bc3f0..7b22e15784 100644
--- a/src/testlib/qpropertytesthelper_p.h
+++ b/src/testlib/qpropertytesthelper_p.h
@@ -139,6 +139,11 @@ void testReadWritePropertyBasics(
// get the property
const QMetaObject *metaObject = instance.metaObject();
QMetaProperty metaProperty = metaObject->property(metaObject->indexOfProperty(propertyName));
+ QVERIFY2(metaProperty.metaType() == QMetaType::fromType<PropertyType>(),
+ QByteArray("Preconditions not met for") + propertyName + '\n' +
+ "The type of initial and changed value does not match the type of the property."
+ "Please ensure that the types match exactly (convertability is not enough)."
+ "You can provide the template types to the function explicitly to force a certain type");
// in case the TestedClass has setProperty()/property() methods.
QObject &testedObj = static_cast<QObject &>(instance);
@@ -268,6 +273,12 @@ void testReadOnlyPropertyBasics(
// in case the TestedClass has setProperty()/property() methods.
QObject &testedObj = static_cast<QObject &>(instance);
+ QVERIFY2(metaProperty.metaType() == QMetaType::fromType<PropertyType>(),
+ QByteArray("Preconditions not met for") + propertyName + '\n' +
+ "The type of initial and changed value does not match the type of the property."
+ "Please ensure that the types match exactly (convertability is not enough)."
+ "You can provide the template types to the function explicitly to force a certain type");
+
QVERIFY2(metaProperty.isBindable(), "Preconditions not met for " + QByteArray(propertyName));
QUntypedBindable bindable = metaProperty.bindable(&instance);