diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-10-05 20:14:43 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-10-08 08:06:42 +0000 |
commit | 4d79f2a1bb4cf5a43662b536547635c83b452994 (patch) | |
tree | d85e5518874e657d26b85414c2ecc699bb1a5529 /tests | |
parent | 46c1ca0f323d8578c7550b12cd361a8334c16a4c (diff) |
Add a basic round-trip test for QStringConverter
For now it only has a trivial test (empty) and an all-surrogate test
(Chakma digits) - but at least now all conversions to and from UTF-16
are tested. In particular, there were previously no UTF-32 tests.
Change-Id: I9317928a88b9990530126db80e4756b880a364df
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit f644a122125feb799a02f4a3fb0f0fa51b8a14ad)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp b/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp index 38714ef580..23d8fd429c 100644 --- a/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp +++ b/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Copyright (C) 2016 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -42,6 +42,8 @@ private slots: void constructByName(); void convertUtf8(); + void roundtrip_data(); + void roundtrip(); void nonFlaggedCodepointFFFF() const; void flagF7808080() const; @@ -148,6 +150,59 @@ void tst_QStringConverter::convertUtf8() } } +void tst_QStringConverter::roundtrip_data() +{ + QTest::addColumn<QString>("utf16"); + QTest::addColumn<QStringConverter::Encoding>("code"); + + const struct { + QStringConverter::Encoding code; + const char *name; + } codes[] = { + { QStringConverter::Utf8, "UTF-8" }, + { QStringConverter::Utf16, "UTF-16" }, + { QStringConverter::Utf16LE, "UTF-16-le" }, + { QStringConverter::Utf16BE, "UTF-16-be" }, + { QStringConverter::Utf32, "UTF-32" }, + { QStringConverter::Utf32LE, "UTF-32-le" }, + { QStringConverter::Utf32BE, "UTF-32-be" }, + // Latin1, System: not guaranteed to be able to represent arbitrary Unicode. + }; + // TODO: include flag variations, too. + + for (const auto code : codes) { + QTest::addRow("empty-%s", code.name) << u""_qs << code.code; + { + const char32_t zeroVal = 0x11136; // Unicode's representation of Chakma zero + const QChar data[] = { + QChar::highSurrogate(zeroVal), QChar::lowSurrogate(zeroVal), + QChar::highSurrogate(zeroVal + 1), QChar::lowSurrogate(zeroVal + 1), + QChar::highSurrogate(zeroVal + 2), QChar::lowSurrogate(zeroVal + 2), + QChar::highSurrogate(zeroVal + 3), QChar::lowSurrogate(zeroVal + 3), + QChar::highSurrogate(zeroVal + 4), QChar::lowSurrogate(zeroVal + 4), + QChar::highSurrogate(zeroVal + 5), QChar::lowSurrogate(zeroVal + 5), + QChar::highSurrogate(zeroVal + 6), QChar::lowSurrogate(zeroVal + 6), + QChar::highSurrogate(zeroVal + 7), QChar::lowSurrogate(zeroVal + 7), + QChar::highSurrogate(zeroVal + 8), QChar::lowSurrogate(zeroVal + 8), + QChar::highSurrogate(zeroVal + 9), QChar::lowSurrogate(zeroVal + 9) + }; + QTest::addRow("Chakma-digits-%s", code.name) + << QString(data, std::size(data)) << code.code; + } + } +} + +void tst_QStringConverter::roundtrip() +{ + QFETCH(QString, utf16); + QFETCH(QStringConverter::Encoding, code); + QStringEncoder out(code); + const QByteArray encoded = out.encode(utf16); + QStringDecoder back(code); + const QString decoded = back.decode(encoded); + QCOMPARE(decoded, utf16); +} + void tst_QStringConverter::nonFlaggedCodepointFFFF() const { //Check that the code point 0xFFFF (=non-character code 0xEFBFBF) is not flagged |