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>bb10
parent
215ca73534
commit
3711bf85ae
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue