tst_qstring: port away from deprecated APIs

* QVariant::Type -> QMetaType::Type.
* Guard the test for deprecated fromUtf16(const ushort *) overload with
  QT_DEPRECATED_SINCE check.
* Use fromUtf16(const char16_t *) overload in other places.

As a drive-by: fix formatting in the affected lines.

Task-number: QTBUG-104858
Change-Id: I9fa3a935bca36e97f934f673e2fc07b451c72872
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ivan Solovev 2022-08-25 15:29:21 +02:00
parent f35e5a44b0
commit aafd2c3fba
2 changed files with 29 additions and 14 deletions

View File

@ -10,8 +10,6 @@
qt_internal_add_test(tst_qstring
SOURCES
tst_qstring.cpp
DEFINES
QT_DISABLE_DEPRECATED_UP_TO=0
LIBRARIES
Qt::CorePrivate
)

View File

@ -540,7 +540,9 @@ private slots:
void regularexpression_lifetime();
#endif
void fromUtf16_data();
#if QT_DEPRECATED_SINCE(6, 0)
void fromUtf16();
#endif
void fromUtf16_char16_data() { fromUtf16_data(); }
void fromUtf16_char16();
@ -6296,14 +6298,15 @@ void tst_QString::fromUtf16_data()
QTest::newRow("str0-len") << QString("abcdefgh") << QString("abc") << 3;
}
#if QT_DEPRECATED_SINCE(6, 0)
void tst_QString::fromUtf16()
{
QFETCH(QString, ucs2);
QFETCH(QString, res);
QFETCH(int, len);
QCOMPARE(QString::fromUtf16(ucs2.utf16(), len), res);
QT_IGNORE_DEPRECATIONS(QCOMPARE(QString::fromUtf16(ucs2.utf16(), len), res);)
}
#endif // QT_DEPRECATED_SINCE(6, 0)
void tst_QString::fromUtf16_char16()
{
@ -6534,14 +6537,28 @@ void tst_QString::arg_fillChar()
const QVariant &var = replaceValues.at(i);
const int width = widths.at(i);
const QChar fillChar = fillChars.at(i);
switch (var.type()) {
case QVariant::String: actual = actual.arg(var.toString(), width, fillChar); break;
case QVariant::Int: actual = actual.arg(var.toInt(), width, base, fillChar); break;
case QVariant::UInt: actual = actual.arg(var.toUInt(), width, base, fillChar); break;
case QVariant::Double: actual = actual.arg(var.toDouble(), width, fmt, prec, fillChar); break;
case QVariant::LongLong: actual = actual.arg(var.toLongLong(), width, base, fillChar); break;
case QVariant::ULongLong: actual = actual.arg(var.toULongLong(), width, base, fillChar); break;
default: QVERIFY(0); break;
switch (var.typeId()) {
case QMetaType::QString:
actual = actual.arg(var.toString(), width, fillChar);
break;
case QMetaType::Int:
actual = actual.arg(var.toInt(), width, base, fillChar);
break;
case QMetaType::UInt:
actual = actual.arg(var.toUInt(), width, base, fillChar);
break;
case QMetaType::Double:
actual = actual.arg(var.toDouble(), width, fmt, prec, fillChar);
break;
case QMetaType::LongLong:
actual = actual.arg(var.toLongLong(), width, base, fillChar);
break;
case QMetaType::ULongLong:
actual = actual.arg(var.toULongLong(), width, base, fillChar);
break;
default:
QVERIFY(0);
break;
}
}
@ -7559,7 +7576,7 @@ void tst_QString::rawData()
const QChar *dataConstPtr = s.constData();
QVERIFY(dataConstPtr != constPtr);
const ushort *utf16Ptr = s.utf16();
const char16_t *char16Ptr = reinterpret_cast<const char16_t *>(s.utf16());
QString s1 = s;
QCOMPARE(s1.constData(), dataConstPtr);
@ -7573,7 +7590,7 @@ void tst_QString::rawData()
QCOMPARE(s1, "dbc");
// utf pointer is valid while the string is not changed
QCOMPARE(QString::fromUtf16(utf16Ptr), s);
QCOMPARE(QString::fromUtf16(char16Ptr), s);
}
void tst_QString::clear()