From fdf112fd1d023e16cc862d47c789d46a62e56b08 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Tue, 24 Jan 2023 15:22:56 +0200 Subject: [PATCH] QString: unittests: clean-up creating a QChar[] Pick-to: 6.5 Change-Id: I3864d145c05ae4268fe576f84723acc5eba3c2cb Reviewed-by: Thiago Macieira --- tests/auto/corelib/text/qstring/tst_qstring.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index cf61edd174..86521f2dda 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -3185,14 +3185,16 @@ void tst_QString::append_data(DataOptions options) void tst_QString::append_special_cases() { { + static constexpr char16_t utf16[] = u"Hello, World!"; + constexpr int len = std::char_traits::length(utf16); + const auto *unicode = reinterpret_cast(utf16); QString a; - static const QChar unicode[] = { u'H', u'e', u'l', u'l', u'o', u',', u' ', u'W', u'o', u'r', u'l', u'd', u'!' }; - a.append(unicode, sizeof unicode / sizeof *unicode); + a.append(unicode, len); QCOMPARE(a, QLatin1String("Hello, World!")); static const QChar nl(u'\n'); a.append(&nl, 1); QCOMPARE(a, QLatin1String("Hello, World!\n")); - a.append(unicode, sizeof unicode / sizeof *unicode); + a.append(unicode, len); QCOMPARE(a, QLatin1String("Hello, World!\nHello, World!")); a.append(unicode, 0); // no-op QCOMPARE(a, QLatin1String("Hello, World!\nHello, World!"));