summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/testlib/qtestdata.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/testlib/qtestdata.cpp b/src/testlib/qtestdata.cpp
index 3a1c6d7e7b..4930954a9e 100644
--- a/src/testlib/qtestdata.cpp
+++ b/src/testlib/qtestdata.cpp
@@ -82,9 +82,24 @@ QTestData::~QTestData()
void QTestData::append(int type, const void *data)
{
QTEST_ASSERT(d->dataCount < d->parent->elementCount());
- if (d->parent->elementTypeId(d->dataCount) != type) {
+ int expectedType = d->parent->elementTypeId(d->dataCount);
+ int dd = 0;
+ if constexpr (sizeof(qsizetype) == 8) {
+ // Compatibility with Qt 5. Passing a qsizetype to a test function expecting
+ // an int will work. This is required, as methods returning a qsizetype in Qt 6
+ // used to return an int in Qt 5.
+ if (type == QMetaType::LongLong && expectedType == QMetaType::Int) {
+ qlonglong d = *static_cast<const qlonglong *>(data);
+ if (d >= std::numeric_limits<int>::min() && d <= std::numeric_limits<int>::max()) {
+ dd = d;
+ data = &dd;
+ type = QMetaType::Int;
+ }
+ }
+ }
+ if (expectedType != type) {
qDebug("expected data of type '%s', got '%s' for element %d of data with tag '%s'",
- QMetaType::typeName(d->parent->elementTypeId(d->dataCount)),
+ QMetaType::typeName(expectedType),
QMetaType::typeName(type),
d->dataCount, d->tag);
QTEST_ASSERT(false);