tst_QString: refactor one test
By using a lambda and QTest::ThrowOnFailEnabler; this required changing the custom QCOMPARE in those tests. Drive-by, use the UTF16 character instead of the hexdecimal representation, one of them is easier to read. Change-Id: Ic319cc2afdda6a73e293ebf16eb4f8df469b6d72 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
68f970d285
commit
d3d395ab3d
@ -5936,22 +5936,30 @@ void tst_QString::setRawData()
|
||||
|
||||
void tst_QString::setUnicode()
|
||||
{
|
||||
const QChar ptr[] = { QChar(0x1234), QChar(0x0000) };
|
||||
const QChar ptr[] = { u'ሴ', QChar(0x0000) };
|
||||
|
||||
QString str;
|
||||
QVERIFY(!str.isDetached());
|
||||
str.setUnicode(ptr, 1);
|
||||
// make sure that the data is copied
|
||||
QVERIFY(str.constData() != ptr);
|
||||
QVERIFY(str.isDetached());
|
||||
QCOMPARE(str, QString(ptr, 1));
|
||||
QTest::ThrowOnFailEnabler throwOnFail;
|
||||
|
||||
// make sure that the string is resized, even if the data is nullptr
|
||||
str = u"test"_s;
|
||||
QCOMPARE(str.size(), 4);
|
||||
str.setUnicode(nullptr, 1);
|
||||
QCOMPARE(str.size(), 1);
|
||||
QCOMPARE(str, u"t");
|
||||
auto doTest = [](const auto ptr, QString &str) mutable {
|
||||
// make sure that the data is copied
|
||||
QVERIFY(str.constData() != ptr);
|
||||
QVERIFY(str.isDetached());
|
||||
QCOMPARE(str, QString(ptr, 1));
|
||||
|
||||
// make sure that the string is resized, even if the data is nullptr
|
||||
str = u"test"_s;
|
||||
QCOMPARE(str.size(), 4);
|
||||
str.setUnicode(nullptr, 1);
|
||||
QCOMPARE(str.size(), 1);
|
||||
QCOMPARE(str, u"t");
|
||||
};
|
||||
|
||||
{
|
||||
QString str;
|
||||
QVERIFY(!str.isDetached());
|
||||
str.setUnicode(ptr, 1);
|
||||
doTest(ptr, str);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QString::fromStdString()
|
||||
|
Loading…
x
Reference in New Issue
Block a user