diff options
author | Lars Knoll <[email protected]> | 2020-06-28 22:06:50 +0200 |
---|---|---|
committer | Lars Knoll <[email protected]> | 2020-07-06 21:31:09 +0200 |
commit | 3711bf85ae85c9398642ae276cbd90b5bfaa6688 (patch) | |
tree | a4578b5bcccab0675392b987c1b20d954003a324 | |
parent | 215ca735341b9487826023a7983382851ce8bf26 (diff) |
Help qtestlib with int -> qsizetype changes
Make sure we can handle qsizetype as an integer when appending
test data. This is required for backwards compatibility with Qt 5,
so people don't have to rewrite all their test cases.
QCOMPARE can handle mixed types, tthe only method that requires manual
changes now is QTEST(list.size(), "testrow_expecting_int").
Change-Id: I40723b239e0160cefc05745aa35a75de8599ac08
Reviewed-by: MÃ¥rten Nordheim <[email protected]>
Reviewed-by: Edward Welbourne <[email protected]>
Reviewed-by: Thiago Macieira <[email protected]>
Reviewed-by: Qt CI Bot <[email protected]>
-rw-r--r-- | src/testlib/qtestdata.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/testlib/qtestdata.cpp b/src/testlib/qtestdata.cpp index 3a1c6d7e7be..4930954a9e4 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 = ⅆ + 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); |