summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-06-28 22:06:50 +0200
committerLars Knoll <lars.knoll@qt.io>2020-07-06 21:31:09 +0200
commit3711bf85ae85c9398642ae276cbd90b5bfaa6688 (patch)
treea4578b5bcccab0675392b987c1b20d954003a324 /src/testlib
parent215ca735341b9487826023a7983382851ce8bf26 (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 <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/testlib')
-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);