diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index d54f40f114d..8e93d2153e6 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -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()