QString: change test data to compile with QT_NO_CAST_FROM_ASCII [10/13]
Drive-by changes: - Cleanup creating a QChar[], by creating a char16_t[] and reinterpret_cast'ing it - Use human-readable Unicode characters where possible Pick-to: 6.5 Change-Id: Ice2c36ff3ea4b6a5562cf907a7809166a51abd28 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
f325bdacb6
commit
9d05fd9fa2
|
|
@ -1233,7 +1233,10 @@ void tst_QString::isEmpty()
|
|||
QVERIFY(a.isEmpty());
|
||||
QVERIFY(!a.isDetached());
|
||||
|
||||
QString c("Not empty");
|
||||
QString b = QString::fromLatin1("Not empty");
|
||||
QVERIFY(!b.isEmpty());
|
||||
|
||||
QString c = u"Not empty"_s;
|
||||
QVERIFY(!c.isEmpty());
|
||||
}
|
||||
|
||||
|
|
@ -3364,13 +3367,11 @@ void tst_QString::append_bytearray_special_cases()
|
|||
|
||||
void tst_QString::operator_pluseq_special_cases()
|
||||
{
|
||||
{
|
||||
QString a;
|
||||
a += QChar::CarriageReturn;
|
||||
a += '\r';
|
||||
a += u'\x1111';
|
||||
QCOMPARE(a, QStringView(u"\r\r\x1111"));
|
||||
}
|
||||
QString a;
|
||||
a += QChar::CarriageReturn;
|
||||
a += u'\r';
|
||||
a += u'\x1111';
|
||||
QCOMPARE(a, u"\r\r\x1111");
|
||||
}
|
||||
|
||||
void tst_QString::operator_pluseq_data(DataOptions options)
|
||||
|
|
@ -3818,7 +3819,7 @@ void tst_QString::replace_string_extra()
|
|||
void tst_QString::replace_regexp()
|
||||
{
|
||||
static const QRegularExpression ignoreMessagePattern(
|
||||
"^QString::replace\\(\\): called on an invalid QRegularExpression object"
|
||||
u"^QString::replace\\(\\): called on an invalid QRegularExpression object"_s
|
||||
);
|
||||
|
||||
QFETCH( QString, string );
|
||||
|
|
@ -5081,25 +5082,25 @@ void tst_QString::endsWith()
|
|||
{
|
||||
QString a;
|
||||
|
||||
QVERIFY(!a.endsWith('A'));
|
||||
QVERIFY(!a.endsWith("AB"));
|
||||
QVERIFY(!a.endsWith(u'A'));
|
||||
QVERIFY(!a.endsWith(u"AB"_s));
|
||||
{
|
||||
CREATE_VIEW("AB");
|
||||
CREATE_VIEW(u"AB"_s);
|
||||
QVERIFY(!a.endsWith(view));
|
||||
}
|
||||
QVERIFY(!a.isDetached());
|
||||
|
||||
a = "AB";
|
||||
QVERIFY( a.endsWith("B") );
|
||||
QVERIFY( a.endsWith("AB") );
|
||||
QVERIFY( !a.endsWith("C") );
|
||||
QVERIFY( !a.endsWith("ABCDEF") );
|
||||
QVERIFY( a.endsWith("") );
|
||||
a = u"AB"_s;
|
||||
QVERIFY( a.endsWith(u"B"_s) );
|
||||
QVERIFY( a.endsWith(u"AB"_s) );
|
||||
QVERIFY( !a.endsWith(u"C"_s) );
|
||||
QVERIFY( !a.endsWith(u"ABCDEF"_s) );
|
||||
QVERIFY( a.endsWith(u""_s) );
|
||||
QVERIFY( a.endsWith(QString()) );
|
||||
QVERIFY( a.endsWith('B') );
|
||||
QVERIFY( a.endsWith(u'B') );
|
||||
QVERIFY( a.endsWith(QLatin1Char('B')) );
|
||||
QVERIFY( a.endsWith(QChar('B')) );
|
||||
QVERIFY( !a.endsWith('C') );
|
||||
QVERIFY( a.endsWith(QChar(u'B')) );
|
||||
QVERIFY( !a.endsWith(u'C') );
|
||||
QVERIFY( !a.endsWith(QChar()) );
|
||||
QVERIFY( !a.endsWith(QLatin1Char(0)) );
|
||||
|
||||
|
|
@ -5110,24 +5111,24 @@ void tst_QString::endsWith()
|
|||
QVERIFY( a.endsWith(QLatin1String("")) );
|
||||
QVERIFY( a.endsWith(QLatin1String(nullptr)) );
|
||||
|
||||
QVERIFY( a.endsWith("B", Qt::CaseSensitive) );
|
||||
QVERIFY( a.endsWith("B", Qt::CaseInsensitive) );
|
||||
QVERIFY( !a.endsWith("b", Qt::CaseSensitive) );
|
||||
QVERIFY( a.endsWith("b", Qt::CaseInsensitive) );
|
||||
QVERIFY( !a.endsWith("aB", Qt::CaseSensitive) );
|
||||
QVERIFY( a.endsWith("aB", Qt::CaseInsensitive) );
|
||||
QVERIFY( !a.endsWith("C", Qt::CaseSensitive) );
|
||||
QVERIFY( !a.endsWith("C", Qt::CaseInsensitive) );
|
||||
QVERIFY( !a.endsWith("c", Qt::CaseSensitive) );
|
||||
QVERIFY( !a.endsWith("c", Qt::CaseInsensitive) );
|
||||
QVERIFY( !a.endsWith("abcdef", Qt::CaseInsensitive) );
|
||||
QVERIFY( a.endsWith("", Qt::CaseInsensitive) );
|
||||
QVERIFY( a.endsWith(u"B"_s, Qt::CaseSensitive) );
|
||||
QVERIFY( a.endsWith(u"B", Qt::CaseInsensitive) );
|
||||
QVERIFY( !a.endsWith(u"b", Qt::CaseSensitive) );
|
||||
QVERIFY( a.endsWith(u"b"_s, Qt::CaseInsensitive) );
|
||||
QVERIFY( !a.endsWith(u"aB"_s, Qt::CaseSensitive) );
|
||||
QVERIFY( a.endsWith(u"aB"_s, Qt::CaseInsensitive) );
|
||||
QVERIFY( !a.endsWith(u"C"_s, Qt::CaseSensitive) );
|
||||
QVERIFY( !a.endsWith(u"C"_s, Qt::CaseInsensitive) );
|
||||
QVERIFY( !a.endsWith(u"c"_s, Qt::CaseSensitive) );
|
||||
QVERIFY( !a.endsWith(u"c"_s, Qt::CaseInsensitive) );
|
||||
QVERIFY( !a.endsWith(u"abcdef"_s, Qt::CaseInsensitive) );
|
||||
QVERIFY( a.endsWith(u""_s, Qt::CaseInsensitive) );
|
||||
QVERIFY( a.endsWith(QString(), Qt::CaseInsensitive) );
|
||||
QVERIFY( a.endsWith('b', Qt::CaseInsensitive) );
|
||||
QVERIFY( a.endsWith('B', Qt::CaseInsensitive) );
|
||||
QVERIFY( a.endsWith(u'b', Qt::CaseInsensitive) );
|
||||
QVERIFY( a.endsWith(u'B', Qt::CaseInsensitive) );
|
||||
QVERIFY( a.endsWith(QLatin1Char('b'), Qt::CaseInsensitive) );
|
||||
QVERIFY( a.endsWith(QChar('b'), Qt::CaseInsensitive) );
|
||||
QVERIFY( !a.endsWith('c', Qt::CaseInsensitive) );
|
||||
QVERIFY( a.endsWith(QChar(u'b'), Qt::CaseInsensitive) );
|
||||
QVERIFY( !a.endsWith(u'c', Qt::CaseInsensitive) );
|
||||
QVERIFY( !a.endsWith(QChar(), Qt::CaseInsensitive) );
|
||||
QVERIFY( !a.endsWith(QLatin1Char(0), Qt::CaseInsensitive) );
|
||||
|
||||
|
|
@ -5144,10 +5145,10 @@ void tst_QString::endsWith()
|
|||
QVERIFY( !a.endsWith(QLatin1String("abcdef"), Qt::CaseInsensitive) );
|
||||
QVERIFY( a.endsWith(QLatin1String(""), Qt::CaseInsensitive) );
|
||||
QVERIFY( a.endsWith(QLatin1String(nullptr), Qt::CaseInsensitive) );
|
||||
QVERIFY( a.endsWith('B', Qt::CaseSensitive) );
|
||||
QVERIFY( a.endsWith(u'B', Qt::CaseSensitive) );
|
||||
QVERIFY( a.endsWith(QLatin1Char('B'), Qt::CaseSensitive) );
|
||||
QVERIFY( a.endsWith(QChar('B'), Qt::CaseSensitive) );
|
||||
QVERIFY( !a.endsWith('b', Qt::CaseSensitive) );
|
||||
QVERIFY( a.endsWith(QChar(u'B'), Qt::CaseSensitive) );
|
||||
QVERIFY( !a.endsWith(u'b', Qt::CaseSensitive) );
|
||||
QVERIFY( !a.endsWith(QChar(), Qt::CaseSensitive) );
|
||||
QVERIFY( !a.endsWith(QLatin1Char(0), Qt::CaseSensitive) );
|
||||
|
||||
|
|
@ -5160,10 +5161,10 @@ void tst_QString::endsWith()
|
|||
TEST_VIEW_ENDS_WITH(QLatin1String(nullptr), true);
|
||||
#undef TEST_VIEW_ENDS_WITH
|
||||
|
||||
a = "";
|
||||
QVERIFY( a.endsWith("") );
|
||||
a = u""_s;
|
||||
QVERIFY( a.endsWith(u""_s) );
|
||||
QVERIFY( a.endsWith(QString()) );
|
||||
QVERIFY( !a.endsWith("ABC") );
|
||||
QVERIFY( !a.endsWith(u"ABC"_s) );
|
||||
QVERIFY( !a.endsWith(QLatin1Char(0)) );
|
||||
QVERIFY( !a.endsWith(QLatin1Char('x')) );
|
||||
QVERIFY( !a.endsWith(QChar()) );
|
||||
|
|
@ -5173,9 +5174,9 @@ void tst_QString::endsWith()
|
|||
QVERIFY( !a.endsWith(QLatin1String("ABC")) );
|
||||
|
||||
a = QString();
|
||||
QVERIFY( !a.endsWith("") );
|
||||
QVERIFY( !a.endsWith(u""_s) );
|
||||
QVERIFY( a.endsWith(QString()) );
|
||||
QVERIFY( !a.endsWith("ABC") );
|
||||
QVERIFY( !a.endsWith(u"ABC"_s) );
|
||||
|
||||
QVERIFY( !a.endsWith(QLatin1String("")) );
|
||||
QVERIFY( a.endsWith(QLatin1String(nullptr)) );
|
||||
|
|
@ -5186,12 +5187,12 @@ void tst_QString::endsWith()
|
|||
QVERIFY( !a.endsWith(QChar()) );
|
||||
|
||||
// this test is independent of encoding
|
||||
a = "\xc3\xa9";
|
||||
QVERIFY( a.endsWith("\xc3\xa9") );
|
||||
QVERIFY( !a.endsWith("\xc3\xa1") );
|
||||
a = u'é';
|
||||
QVERIFY(a.endsWith(u"é"_s));
|
||||
QVERIFY(!a.endsWith(u"á"_s));
|
||||
|
||||
// this one is dependent of encoding
|
||||
QVERIFY( a.endsWith("\xc3\x89", Qt::CaseInsensitive) );
|
||||
QVERIFY(a.endsWith(u"É"_s, Qt::CaseInsensitive));
|
||||
}
|
||||
|
||||
void tst_QString::check_QDataStream()
|
||||
|
|
@ -5200,7 +5201,7 @@ void tst_QString::check_QDataStream()
|
|||
QByteArray ar;
|
||||
{
|
||||
QDataStream out(&ar,QIODevice::WriteOnly);
|
||||
out << QString("COMPARE Text");
|
||||
out << u"COMPARE Text"_s;
|
||||
}
|
||||
{
|
||||
QDataStream in(&ar,QIODevice::ReadOnly);
|
||||
|
|
@ -5215,7 +5216,7 @@ void tst_QString::check_QTextStream()
|
|||
QByteArray ar;
|
||||
{
|
||||
QTextStream out(&ar,QIODevice::WriteOnly);
|
||||
out << QString("This is COMPARE Text");
|
||||
out << u"This is COMPARE Text"_s;
|
||||
}
|
||||
{
|
||||
QTextStream in(&ar,QIODevice::ReadOnly);
|
||||
|
|
@ -5228,21 +5229,21 @@ void tst_QString::check_QTextIOStream()
|
|||
{
|
||||
QString a;
|
||||
{
|
||||
a="";
|
||||
a = u""_s;
|
||||
QTextStream ts(&a);
|
||||
// invalid Utf8
|
||||
ts << "pi \261= " << 3.125;
|
||||
QCOMPARE(a, QString::fromUtf16(u"pi \xfffd= 3.125"));
|
||||
}
|
||||
{
|
||||
a="";
|
||||
a = u""_s;
|
||||
QTextStream ts(&a);
|
||||
// valid Utf8
|
||||
ts << "pi ø= " << 3.125;
|
||||
QCOMPARE(a, QString::fromUtf16(u"pi ø= 3.125"));
|
||||
}
|
||||
{
|
||||
a="123 456";
|
||||
a = u"123 456"_s;
|
||||
int x,y;
|
||||
QTextStream(&a) >> x >> y;
|
||||
QCOMPARE(x,123);
|
||||
|
|
@ -5291,7 +5292,7 @@ void tst_QString::setRawData()
|
|||
QVERIFY(cstr.data_ptr() == csd);
|
||||
|
||||
// This tests the discarding of the shared data object
|
||||
cstr = "foo";
|
||||
cstr = QString::fromUtf8("foo");
|
||||
QVERIFY(cstr.isDetached());
|
||||
QVERIFY(cstr.constData() != ptr2);
|
||||
|
||||
|
|
@ -5318,7 +5319,7 @@ void tst_QString::setUnicode()
|
|||
QCOMPARE(str, QString(ptr, 1));
|
||||
|
||||
// make sure that the string is resized, even if the data is nullptr
|
||||
str = "test";
|
||||
str = u"test"_s;
|
||||
QCOMPARE(str.size(), 4);
|
||||
str.setUnicode(nullptr, 1);
|
||||
QCOMPARE(str.size(), 1);
|
||||
|
|
@ -5330,7 +5331,7 @@ void tst_QString::fromStdString()
|
|||
QVERIFY(QString::fromStdString(std::string()).isEmpty());
|
||||
std::string stroustrup = "foo";
|
||||
QString eng = QString::fromStdString( stroustrup );
|
||||
QCOMPARE( eng, QString("foo") );
|
||||
QCOMPARE( eng, u"foo"_s );
|
||||
const char cnull[] = "Embedded\0null\0character!";
|
||||
std::string stdnull( cnull, sizeof(cnull)-1 );
|
||||
QString qtnull = QString::fromStdString( stdnull );
|
||||
|
|
@ -5343,23 +5344,25 @@ void tst_QString::toStdString()
|
|||
QVERIFY(nullStr.toStdString().empty());
|
||||
QVERIFY(!nullStr.isDetached());
|
||||
|
||||
QString emptyStr("");
|
||||
QString emptyStr(u""_s);
|
||||
QVERIFY(emptyStr.toStdString().empty());
|
||||
QVERIFY(!emptyStr.isDetached());
|
||||
|
||||
QString nord = "foo";
|
||||
QString nord = u"foo"_s;
|
||||
std::string stroustrup1 = nord.toStdString();
|
||||
QVERIFY( qstrcmp(stroustrup1.c_str(), "foo") == 0 );
|
||||
|
||||
// For now, most QString constructors are also broken with respect
|
||||
// to embedded null characters, had to find one that works...
|
||||
const QChar qcnull[] = {
|
||||
'E', 'm', 'b', 'e', 'd', 'd', 'e', 'd', '\0',
|
||||
'n', 'u', 'l', 'l', '\0',
|
||||
'c', 'h', 'a', 'r', 'a', 'c', 't', 'e', 'r', '!'
|
||||
};
|
||||
QString qtnull( qcnull, sizeof(qcnull)/sizeof(QChar) );
|
||||
const char16_t utf16[] = u"Embedded\0null\0character!";
|
||||
const int size = std::size(utf16) - 1; // - 1, null terminator of the string literal
|
||||
QString qtnull(reinterpret_cast<const QChar *>(utf16), size);
|
||||
|
||||
std::string stdnull = qtnull.toStdString();
|
||||
QCOMPARE( int(stdnull.size()), qtnull.size() );
|
||||
QCOMPARE(int(stdnull.size()), qtnull.size());
|
||||
|
||||
std::u16string stdu16null = qtnull.toStdU16String();
|
||||
QCOMPARE(int(stdu16null.size()), qtnull.size());
|
||||
}
|
||||
|
||||
void tst_QString::utf8()
|
||||
|
|
@ -5509,7 +5512,7 @@ void tst_QString::fromLocal8Bit_data()
|
|||
|
||||
for (int l=0;l<111;l++) {
|
||||
longQByteArray = longQByteArray + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
||||
longQString += "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
||||
longQString += u"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"_s;
|
||||
}
|
||||
|
||||
//QTest::newRow("longString") << longQByteArray << -1 << longQString;
|
||||
|
|
@ -5778,7 +5781,7 @@ void tst_QString::toLatin1Roundtrip()
|
|||
QCOMPARE(std::move(s).toLatin1(), latin1);
|
||||
|
||||
// and verify that the moved-from object can still be used
|
||||
s = "foo";
|
||||
s = u"foo"_s;
|
||||
s.clear();
|
||||
}
|
||||
|
||||
|
|
@ -5841,13 +5844,13 @@ void tst_QString::fromUcs4()
|
|||
|
||||
static const char32_t str1[] = U"Hello Unicode World";
|
||||
s = QString::fromUcs4(str1, sizeof(str1) / sizeof(str1[0]) - 1);
|
||||
QCOMPARE(s, QString("Hello Unicode World"));
|
||||
QCOMPARE(s, u"Hello Unicode World");
|
||||
|
||||
s = QString::fromUcs4(str1);
|
||||
QCOMPARE(s, QString("Hello Unicode World"));
|
||||
QCOMPARE(s, u"Hello Unicode World");
|
||||
|
||||
s = QString::fromUcs4(str1, 5);
|
||||
QCOMPARE(s, QString("Hello"));
|
||||
QCOMPARE(s, u"Hello");
|
||||
|
||||
s = QString::fromUcs4(U"\u221212\U000020AC\U00010000");
|
||||
QCOMPARE(s, QString::fromUtf8("\342\210\222" "12" "\342\202\254" "\360\220\200\200"));
|
||||
|
|
@ -6255,7 +6258,7 @@ void tst_QString::doubleOut()
|
|||
const QString expect(QStringLiteral("1e-06"));
|
||||
const double micro = 1e-6;
|
||||
QCOMPARE(QString::number(micro), expect);
|
||||
QCOMPARE(QString("%1").arg(micro), expect);
|
||||
QCOMPARE(u"%1"_s.arg(micro), expect);
|
||||
{
|
||||
QCOMPARE(QString::asprintf("%g", micro), expect);
|
||||
}
|
||||
|
|
@ -6480,31 +6483,31 @@ void tst_QString::operator_eqeq_nullstring()
|
|||
/* Some of these might not be all that logical but it's the behaviour we've had since 3.0.0
|
||||
so we should probably stick with it. */
|
||||
|
||||
QVERIFY( QString() == "" );
|
||||
QVERIFY( "" == QString() );
|
||||
QVERIFY( QString() == u""_s );
|
||||
QVERIFY( u""_s == QString() );
|
||||
|
||||
QVERIFY( QString("") == "" );
|
||||
QVERIFY( "" == QString("") );
|
||||
QVERIFY( QString(u""_s) == u""_s );
|
||||
QVERIFY( u""_s == QString(u""_s) );
|
||||
|
||||
QVERIFY(QString() == nullptr);
|
||||
QVERIFY(nullptr == QString());
|
||||
|
||||
QVERIFY(QString("") == nullptr);
|
||||
QVERIFY(nullptr == QString(""));
|
||||
QVERIFY(QString(u""_s) == nullptr);
|
||||
QVERIFY(nullptr == QString(u""_s));
|
||||
|
||||
QVERIFY( QString().size() == 0 );
|
||||
|
||||
QVERIFY( QString("").size() == 0 );
|
||||
QVERIFY(u""_s.size() == 0);
|
||||
|
||||
QVERIFY( QString() == QString("") );
|
||||
QVERIFY( QString("") == QString() );
|
||||
QVERIFY(QString() == u""_s);
|
||||
QVERIFY( QString(u""_s) == QString() );
|
||||
}
|
||||
|
||||
void tst_QString::operator_smaller()
|
||||
{
|
||||
QString null;
|
||||
QString empty("");
|
||||
QString foo("foo");
|
||||
QString empty(u""_s);
|
||||
QString foo(u"foo"_s);
|
||||
[[maybe_unused]]
|
||||
const char *nullC = nullptr;
|
||||
[[maybe_unused]]
|
||||
|
|
@ -6513,8 +6516,8 @@ void tst_QString::operator_smaller()
|
|||
QVERIFY( !(null < QString()) );
|
||||
QVERIFY( !(null > QString()) );
|
||||
|
||||
QVERIFY( !(empty < QString("")) );
|
||||
QVERIFY( !(empty > QString("")) );
|
||||
QVERIFY(!(empty < u""_s));
|
||||
QVERIFY(!(empty > u""_s));
|
||||
|
||||
QVERIFY( !(null < empty) );
|
||||
QVERIFY( !(null > empty) );
|
||||
|
|
@ -6858,7 +6861,7 @@ void tst_QString::iterators()
|
|||
QVERIFY(!emptyStr.isDetached());
|
||||
QCOMPARE(emptyStr.begin(), emptyStr.end());
|
||||
|
||||
QString s = "0123456789";
|
||||
QString s = u"0123456789"_s;
|
||||
|
||||
auto it = s.begin();
|
||||
auto constIt = s.cbegin();
|
||||
|
|
@ -6899,7 +6902,7 @@ void tst_QString::reverseIterators()
|
|||
QVERIFY(!emptyStr.isDetached());
|
||||
QCOMPARE(emptyStr.rbegin(), emptyStr.rend());
|
||||
|
||||
QString s = "1234";
|
||||
QString s(u"1234"_s);
|
||||
QString sr = s;
|
||||
std::reverse(sr.begin(), sr.end());
|
||||
const QString &csr = sr;
|
||||
|
|
@ -7000,7 +7003,7 @@ QT_WARNING_DISABLE_DEPRECATED
|
|||
QVERIFY(list == result);
|
||||
}
|
||||
|
||||
result.removeAll("");
|
||||
result.removeAll(u""_s);
|
||||
list = str.split(sep, Qt::SkipEmptyParts);
|
||||
QVERIFY(list == result);
|
||||
#if QT_CONFIG(regularexpression)
|
||||
|
|
@ -7076,13 +7079,13 @@ void tst_QString::regularexpression_lifetime()
|
|||
return QString(QLatin1String("the quick brown fox jumps over the lazy dog"));
|
||||
};
|
||||
|
||||
QRegularExpression re("\\w{5}");
|
||||
QRegularExpression re(u"\\w{5}"_s);
|
||||
|
||||
{
|
||||
QString s = getString();
|
||||
QRegularExpressionMatch match;
|
||||
const bool contains = std::move(s).contains(re, &match);
|
||||
s.fill('X'); // NOLINT(bugprone-use-after-move)
|
||||
s.fill(u'X'); // NOLINT(bugprone-use-after-move)
|
||||
QVERIFY(contains);
|
||||
QCOMPARE(match.capturedView(), u"quick");
|
||||
}
|
||||
|
|
@ -7091,7 +7094,7 @@ void tst_QString::regularexpression_lifetime()
|
|||
QString s = getString();
|
||||
QRegularExpressionMatch match;
|
||||
const auto index = std::move(s).indexOf(re, 0, &match);
|
||||
s.fill('X'); // NOLINT(bugprone-use-after-move)
|
||||
s.fill(u'X'); // NOLINT(bugprone-use-after-move)
|
||||
QCOMPARE(index, 4);
|
||||
QCOMPARE(match.capturedView(), u"quick");
|
||||
}
|
||||
|
|
@ -7100,7 +7103,7 @@ void tst_QString::regularexpression_lifetime()
|
|||
QString s = getString();
|
||||
QRegularExpressionMatch match;
|
||||
const auto lastIndex = std::move(s).lastIndexOf(re, &match);
|
||||
s.fill('X'); // NOLINT(bugprone-use-after-move)
|
||||
s.fill(u'X'); // NOLINT(bugprone-use-after-move)
|
||||
QCOMPARE(lastIndex, 20);
|
||||
QCOMPARE(match.capturedView(), u"jumps");
|
||||
}
|
||||
|
|
@ -7143,7 +7146,7 @@ void tst_QString::unicodeStrings()
|
|||
QVERIFY(nullStr.toStdU32String().empty());
|
||||
QVERIFY(!nullStr.isDetached());
|
||||
|
||||
QString emptyStr("");
|
||||
QString emptyStr(u""_s);
|
||||
QVERIFY(emptyStr.toStdU16String().empty());
|
||||
QVERIFY(emptyStr.toStdU32String().empty());
|
||||
QVERIFY(!emptyStr.isDetached());
|
||||
|
|
@ -7153,7 +7156,7 @@ void tst_QString::unicodeStrings()
|
|||
static const std::u32string u32str1(U"Hello Unicode World");
|
||||
s1 = QString::fromStdU16String(u16str1);
|
||||
s2 = QString::fromStdU32String(u32str1);
|
||||
QCOMPARE(s1, QString("Hello Unicode World"));
|
||||
QCOMPARE(s1, u"Hello Unicode World");
|
||||
QCOMPARE(s1, s2);
|
||||
|
||||
QCOMPARE(s2.toStdU16String(), u16str1);
|
||||
|
|
@ -7165,7 +7168,7 @@ void tst_QString::unicodeStrings()
|
|||
|
||||
void tst_QString::latin1String()
|
||||
{
|
||||
QString s("Hello");
|
||||
QString s(u"Hello"_s);
|
||||
|
||||
QVERIFY(s == QLatin1String("Hello"));
|
||||
QVERIFY(s != QLatin1String("Hello World"));
|
||||
|
|
@ -7255,20 +7258,20 @@ void tst_QString::nanAndInf()
|
|||
bool ok;
|
||||
double d;
|
||||
|
||||
d = QString("-INF").toDouble(&ok);
|
||||
d = u"-INF"_s.toDouble(&ok);
|
||||
QVERIFY(ok);
|
||||
QVERIFY(d == -qInf());
|
||||
|
||||
QString("INF").toLong(&ok);
|
||||
u"INF"_s.toLong(&ok);
|
||||
QVERIFY(!ok);
|
||||
|
||||
QString("INF").toLong(&ok, 36);
|
||||
u"INF"_s.toLong(&ok, 36);
|
||||
QVERIFY(ok);
|
||||
|
||||
QString("INF0").toLong(&ok, 36);
|
||||
u"INF0"_s.toLong(&ok, 36);
|
||||
QVERIFY(ok);
|
||||
|
||||
QString("0INF0").toLong(&ok, 36);
|
||||
u"0INF0"_s.toLong(&ok, 36);
|
||||
QVERIFY(ok);
|
||||
|
||||
// Check that inf (float) => "inf" (QString) => inf (float).
|
||||
|
|
@ -7288,36 +7291,36 @@ void tst_QString::nanAndInf()
|
|||
|
||||
// Check that .arg(inf-or-nan, wide, fmt, 3, '0') padds with zeros
|
||||
QString form = QStringLiteral("%1");
|
||||
QCOMPARE(form.arg(qInf(), 5, 'f', 3, '0'), u"00inf");
|
||||
QCOMPARE(form.arg(qInf(), -5, 'f', 3, '0'), u"inf00");
|
||||
QCOMPARE(form.arg(-qInf(), 6, 'f', 3, '0'), u"00-inf");
|
||||
QCOMPARE(form.arg(-qInf(), -6, 'f', 3, '0'), u"-inf00");
|
||||
QCOMPARE(form.arg(qQNaN(), -5, 'f', 3, '0'), u"nan00");
|
||||
QCOMPARE(form.arg(qInf(), 5, 'F', 3, '0'), u"00INF");
|
||||
QCOMPARE(form.arg(qInf(), -5, 'F', 3, '0'), u"INF00");
|
||||
QCOMPARE(form.arg(-qInf(), 6, 'F', 3, '0'), u"00-INF");
|
||||
QCOMPARE(form.arg(-qInf(), -6, 'F', 3, '0'), u"-INF00");
|
||||
QCOMPARE(form.arg(qQNaN(), -5, 'F', 3, '0'), u"NAN00");
|
||||
QCOMPARE(form.arg(qInf(), 5, 'e', 3, '0'), u"00inf");
|
||||
QCOMPARE(form.arg(qInf(), -5, 'e', 3, '0'), u"inf00");
|
||||
QCOMPARE(form.arg(-qInf(), 6, 'e', 3, '0'), u"00-inf");
|
||||
QCOMPARE(form.arg(-qInf(), -6, 'e', 3, '0'), u"-inf00");
|
||||
QCOMPARE(form.arg(qQNaN(), -5, 'e', 3, '0'), u"nan00");
|
||||
QCOMPARE(form.arg(qInf(), 5, 'E', 3, '0'), u"00INF");
|
||||
QCOMPARE(form.arg(qInf(), -5, 'E', 3, '0'), u"INF00");
|
||||
QCOMPARE(form.arg(-qInf(), 6, 'E', 3, '0'), u"00-INF");
|
||||
QCOMPARE(form.arg(-qInf(), -6, 'E', 3, '0'), u"-INF00");
|
||||
QCOMPARE(form.arg(qQNaN(), -5, 'E', 3, '0'), u"NAN00");
|
||||
QCOMPARE(form.arg(qInf(), 5, 'g', 3, '0'), u"00inf");
|
||||
QCOMPARE(form.arg(qInf(), -5, 'g', 3, '0'), u"inf00");
|
||||
QCOMPARE(form.arg(-qInf(), 6, 'g', 3, '0'), u"00-inf");
|
||||
QCOMPARE(form.arg(-qInf(), -6, 'g', 3, '0'), u"-inf00");
|
||||
QCOMPARE(form.arg(qQNaN(), -5, 'g', 3, '0'), u"nan00");
|
||||
QCOMPARE(form.arg(qInf(), 5, 'G', 3, '0'), u"00INF");
|
||||
QCOMPARE(form.arg(qInf(), -5, 'G', 3, '0'), u"INF00");
|
||||
QCOMPARE(form.arg(-qInf(), 6, 'G', 3, '0'), u"00-INF");
|
||||
QCOMPARE(form.arg(-qInf(), -6, 'G', 3, '0'), u"-INF00");
|
||||
QCOMPARE(form.arg(qQNaN(), -5, 'G', 3, '0'), u"NAN00");
|
||||
QCOMPARE(form.arg(qInf(), 5, 'f', 3, u'0'), u"00inf");
|
||||
QCOMPARE(form.arg(qInf(), -5, 'f', 3, u'0'), u"inf00");
|
||||
QCOMPARE(form.arg(-qInf(), 6, 'f', 3, u'0'), u"00-inf");
|
||||
QCOMPARE(form.arg(-qInf(), -6, 'f', 3, u'0'), u"-inf00");
|
||||
QCOMPARE(form.arg(qQNaN(), -5, 'f', 3, u'0'), u"nan00");
|
||||
QCOMPARE(form.arg(qInf(), 5, 'F', 3, u'0'), u"00INF");
|
||||
QCOMPARE(form.arg(qInf(), -5, 'F', 3, u'0'), u"INF00");
|
||||
QCOMPARE(form.arg(-qInf(), 6, 'F', 3, u'0'), u"00-INF");
|
||||
QCOMPARE(form.arg(-qInf(), -6, 'F', 3, u'0'), u"-INF00");
|
||||
QCOMPARE(form.arg(qQNaN(), -5, 'F', 3, u'0'), u"NAN00");
|
||||
QCOMPARE(form.arg(qInf(), 5, 'e', 3, u'0'), u"00inf");
|
||||
QCOMPARE(form.arg(qInf(), -5, 'e', 3, u'0'), u"inf00");
|
||||
QCOMPARE(form.arg(-qInf(), 6, 'e', 3, u'0'), u"00-inf");
|
||||
QCOMPARE(form.arg(-qInf(), -6, 'e', 3, u'0'), u"-inf00");
|
||||
QCOMPARE(form.arg(qQNaN(), -5, 'e', 3, u'0'), u"nan00");
|
||||
QCOMPARE(form.arg(qInf(), 5, 'E', 3, u'0'), u"00INF");
|
||||
QCOMPARE(form.arg(qInf(), -5, 'E', 3, u'0'), u"INF00");
|
||||
QCOMPARE(form.arg(-qInf(), 6, 'E', 3, u'0'), u"00-INF");
|
||||
QCOMPARE(form.arg(-qInf(), -6, 'E', 3, u'0'), u"-INF00");
|
||||
QCOMPARE(form.arg(qQNaN(), -5, 'E', 3, u'0'), u"NAN00");
|
||||
QCOMPARE(form.arg(qInf(), 5, 'g', 3, u'0'), u"00inf");
|
||||
QCOMPARE(form.arg(qInf(), -5, 'g', 3, u'0'), u"inf00");
|
||||
QCOMPARE(form.arg(-qInf(), 6, 'g', 3, u'0'), u"00-inf");
|
||||
QCOMPARE(form.arg(-qInf(), -6, 'g', 3, u'0'), u"-inf00");
|
||||
QCOMPARE(form.arg(qQNaN(), -5, 'g', 3, u'0'), u"nan00");
|
||||
QCOMPARE(form.arg(qInf(), 5, 'G', 3, u'0'), u"00INF");
|
||||
QCOMPARE(form.arg(qInf(), -5, 'G', 3, u'0'), u"INF00");
|
||||
QCOMPARE(form.arg(-qInf(), 6, 'G', 3, u'0'), u"00-INF");
|
||||
QCOMPARE(form.arg(-qInf(), -6, 'G', 3, u'0'), u"-INF00");
|
||||
QCOMPARE(form.arg(qQNaN(), -5, 'G', 3, u'0'), u"NAN00");
|
||||
}
|
||||
|
||||
void tst_QString::arg_fillChar_data()
|
||||
|
|
@ -7602,7 +7605,7 @@ void tst_QString::compare()
|
|||
void tst_QString::resize()
|
||||
{
|
||||
QString s;
|
||||
s.resize(11, ' ');
|
||||
s.resize(11, u' ');
|
||||
QCOMPARE(s.size(), 11);
|
||||
QCOMPARE(s, QLatin1String(" "));
|
||||
|
||||
|
|
@ -7622,7 +7625,7 @@ void tst_QString::resize()
|
|||
|
||||
void tst_QString::resizeAfterFromRawData()
|
||||
{
|
||||
QString buffer("hello world");
|
||||
QString buffer(u"hello world"_s);
|
||||
|
||||
QString array = QString::fromRawData(buffer.constData(), buffer.size());
|
||||
QVERIFY(array.constData() == buffer.constData());
|
||||
|
|
@ -7638,7 +7641,7 @@ void tst_QString::resizeAfterReserve()
|
|||
QString s;
|
||||
s.reserve(100);
|
||||
|
||||
s += "hello world";
|
||||
s += u"hello world"_s;
|
||||
|
||||
// resize should not affect capacity
|
||||
s.resize(s.size());
|
||||
|
|
@ -7654,12 +7657,12 @@ void tst_QString::resizeAfterReserve()
|
|||
|
||||
// test resize(0) border case
|
||||
s.reserve(100);
|
||||
s += "hello world";
|
||||
s += u"hello world"_s;
|
||||
s.resize(0);
|
||||
QVERIFY(s.capacity() == 100);
|
||||
|
||||
// reserve() can't be used to truncate data
|
||||
s.fill('x', 100);
|
||||
s.fill(u'x', 100);
|
||||
s.reserve(50);
|
||||
QVERIFY(s.capacity() == 100);
|
||||
QVERIFY(s.size() == 100);
|
||||
|
|
@ -8274,7 +8277,7 @@ void tst_QString::assignQChar()
|
|||
QCOMPARE(s.capacity(), 1);
|
||||
|
||||
// assign to empty QString:
|
||||
s = QString("");
|
||||
s = QString(u""_s);
|
||||
s.detach();
|
||||
QCOMPARE(s.capacity(), 0);
|
||||
s = sp;
|
||||
|
|
@ -8419,7 +8422,7 @@ void tst_QString::rawData()
|
|||
QCOMPARE(s.utf16(), reinterpret_cast<const ushort *>(constPtr));
|
||||
QVERIFY(!s.isDetached());
|
||||
|
||||
s = "abc"; // detached
|
||||
s = QString::fromUtf8("abc"); // detached
|
||||
const QChar *dataConstPtr = s.constData();
|
||||
QVERIFY(dataConstPtr != constPtr);
|
||||
|
||||
|
|
@ -8433,8 +8436,8 @@ void tst_QString::rawData()
|
|||
QVERIFY(s1Ptr != dataConstPtr);
|
||||
QVERIFY(s1.unicode() != s.unicode());
|
||||
|
||||
*s1Ptr = 'd';
|
||||
QCOMPARE(s1, "dbc");
|
||||
*s1Ptr = u'd';
|
||||
QCOMPARE(s1, u"dbc");
|
||||
|
||||
// utf pointer is valid while the string is not changed
|
||||
QCOMPARE(QString::fromUtf16(char16Ptr), s);
|
||||
|
|
@ -8447,7 +8450,7 @@ void tst_QString::clear()
|
|||
QVERIFY(s.isEmpty());
|
||||
QVERIFY(!s.isDetached());
|
||||
|
||||
s = "some tests string";
|
||||
s = u"some tests string"_s;
|
||||
QVERIFY(!s.isEmpty());
|
||||
|
||||
s.clear();
|
||||
|
|
@ -8462,7 +8465,7 @@ void tst_QString::sliced()
|
|||
QVERIFY(a.sliced(0, 0).isEmpty());
|
||||
QVERIFY(!a.isDetached());
|
||||
|
||||
a = "ABCDEFGHIEfGEFG"; // 15 chars
|
||||
a = u"ABCDEFGHIEfGEFG"_s; // 15 chars
|
||||
|
||||
QCOMPARE(a.sliced(5), u"FGHIEfGEFG");
|
||||
QCOMPARE(a.sliced(5, 3), u"FGH");
|
||||
|
|
@ -8475,14 +8478,13 @@ void tst_QString::chopped()
|
|||
QVERIFY(a.chopped(0).isEmpty());
|
||||
QVERIFY(!a.isDetached());
|
||||
|
||||
a = "ABCDEFGHIEfGEFG"; // 15 chars
|
||||
a = u"ABCDEFGHIEfGEFG"_s; // 15 chars
|
||||
|
||||
QCOMPARE(a.chopped(10), u"ABCDE");
|
||||
}
|
||||
|
||||
void tst_QString::removeIf()
|
||||
{
|
||||
const char str[] = "aABbcCDd";
|
||||
QString a;
|
||||
|
||||
auto pred = [](const QChar &c) { return c.isLower(); };
|
||||
|
|
@ -8491,27 +8493,27 @@ void tst_QString::removeIf()
|
|||
QVERIFY(!a.isDetached());
|
||||
|
||||
// Test when the string is not shared
|
||||
a = str;
|
||||
a = "aABbcCDd"_L1;
|
||||
QVERIFY(!a.data_ptr()->needsDetach());
|
||||
a.removeIf(pred);
|
||||
QCOMPARE(a, u"ABCD");
|
||||
|
||||
// Test when the string is shared
|
||||
a = str;
|
||||
a = "aABbcCDd"_L1;
|
||||
QString b = a;
|
||||
QVERIFY(a.data_ptr()->needsDetach());
|
||||
a.removeIf(pred);
|
||||
QCOMPARE(a, u"ABCD");
|
||||
QCOMPARE(b, str);
|
||||
QCOMPARE(b, "aABbcCDd"_L1);
|
||||
|
||||
auto removeA = [](const char c) { return c == 'a' || c == 'A'; };
|
||||
|
||||
a = "aBcAbCa"; // Not shared
|
||||
QCOMPARE(a.removeIf(removeA), QString("BcbC"));
|
||||
a = "aBcAbCa"_L1; // Not shared
|
||||
QCOMPARE(a.removeIf(removeA), u"BcbC");
|
||||
|
||||
a = "aBcAbCa";
|
||||
a = "aBcAbCa"_L1;
|
||||
b = a; // Shared
|
||||
QCOMPARE(a.removeIf(removeA), QString("BcbC"));
|
||||
QCOMPARE(a.removeIf(removeA), u"BcbC");
|
||||
}
|
||||
|
||||
// QString's collation order is only supported during the lifetime as QCoreApplication
|
||||
|
|
|
|||
|
|
@ -9,17 +9,20 @@
|
|||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
void tst_QString_macTypes()
|
||||
{
|
||||
const QLatin1StringView testString("test string");
|
||||
// QString <-> CFString
|
||||
{
|
||||
QString qtString("test string");
|
||||
QString qtString = testString;
|
||||
const CFStringRef cfString = qtString.toCFString();
|
||||
QCOMPARE(QString::fromCFString(cfString), qtString);
|
||||
CFRelease(cfString);
|
||||
}
|
||||
{
|
||||
QString qtString("test string");
|
||||
QString qtString = testString;
|
||||
const CFStringRef cfString = qtString.toCFString();
|
||||
QString qtStringCopy(qtString);
|
||||
qtString = qtString.toUpper(); // modify
|
||||
|
|
@ -29,14 +32,14 @@ void tst_QString_macTypes()
|
|||
{
|
||||
QMacAutoReleasePool pool;
|
||||
|
||||
QString qtString("test string");
|
||||
QString qtString = testString;
|
||||
const NSString *nsString = qtString.toNSString();
|
||||
QCOMPARE(QString::fromNSString(nsString), qtString);
|
||||
}
|
||||
{
|
||||
QMacAutoReleasePool pool;
|
||||
|
||||
QString qtString("test string");
|
||||
QString qtString = testString;
|
||||
const NSString *nsString = qtString.toNSString();
|
||||
QString qtStringCopy(qtString);
|
||||
qtString = qtString.toUpper(); // modify
|
||||
|
|
|
|||
Loading…
Reference in New Issue