summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qchar
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/text/qchar')
-rw-r--r--tests/auto/corelib/text/qchar/CMakeLists.txt23
-rw-r--r--tests/auto/corelib/text/qchar/qchar.pro11
-rw-r--r--tests/auto/corelib/text/qchar/testdata.qrc5
-rw-r--r--tests/auto/corelib/text/qchar/tst_qchar.cpp166
4 files changed, 119 insertions, 86 deletions
diff --git a/tests/auto/corelib/text/qchar/CMakeLists.txt b/tests/auto/corelib/text/qchar/CMakeLists.txt
new file mode 100644
index 0000000000..03b99356ea
--- /dev/null
+++ b/tests/auto/corelib/text/qchar/CMakeLists.txt
@@ -0,0 +1,23 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## tst_qchar Test:
+#####################################################################
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qchar LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+# Collect test data
+list(APPEND test_data "data/NormalizationTest.txt")
+
+qt_internal_add_test(tst_qchar
+ SOURCES
+ tst_qchar.cpp
+ LIBRARIES
+ Qt::CorePrivate
+ TESTDATA ${test_data}
+)
diff --git a/tests/auto/corelib/text/qchar/qchar.pro b/tests/auto/corelib/text/qchar/qchar.pro
deleted file mode 100644
index 70c1222988..0000000000
--- a/tests/auto/corelib/text/qchar/qchar.pro
+++ /dev/null
@@ -1,11 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qchar
-QT = core-private testlib
-SOURCES = tst_qchar.cpp
-
-TESTDATA += data/NormalizationTest.txt
-
-android:!android-embedded {
- RESOURCES += \
- testdata.qrc
-}
diff --git a/tests/auto/corelib/text/qchar/testdata.qrc b/tests/auto/corelib/text/qchar/testdata.qrc
deleted file mode 100644
index 7b3fb2461c..0000000000
--- a/tests/auto/corelib/text/qchar/testdata.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>data/NormalizationTest.txt</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/corelib/text/qchar/tst_qchar.cpp b/tests/auto/corelib/text/qchar/tst_qchar.cpp
index cf4f6d21e2..fae507f4c6 100644
--- a/tests/auto/corelib/text/qchar/tst_qchar.cpp
+++ b/tests/auto/corelib/text/qchar/tst_qchar.cpp
@@ -1,46 +1,24 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
#include <qchar.h>
#include <qfile.h>
#include <qstringlist.h>
-#include <private/qunicodetables_p.h>
class tst_QChar : public QObject
{
Q_OBJECT
private slots:
void fromChar16_t();
+ void fromUcs4_data();
+ void fromUcs4();
void fromWchar_t();
void operator_eqeq_null();
void operators_data();
void operators();
+ void qchar_qlatin1char_operators_symmetry_data();
+ void qchar_qlatin1char_operators_symmetry();
void toUpper();
void toLower();
void toTitle();
@@ -65,36 +43,58 @@ private slots:
void digitValue();
void mirroredChar();
void decomposition();
- void lineBreakClass();
void script();
+#if !defined(Q_OS_WASM)
void normalization_data();
void normalization();
+#endif // !defined(Q_OS_WASM)
void normalization_manual();
void normalizationCorrections();
void unicodeVersion();
};
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_DEPRECATED
-
void tst_QChar::fromChar16_t()
{
-#if defined(Q_COMPILER_UNICODE_STRINGS)
QChar aUmlaut = u'\u00E4'; // German small letter a-umlaut
QCOMPARE(aUmlaut, QChar(0xE4));
QChar replacementCharacter = u'\uFFFD';
QCOMPARE(replacementCharacter, QChar(QChar::ReplacementCharacter));
-#else
- QSKIP("This test requires C++11 char16_t support enabled in the compiler.");
-#endif
+}
+
+void tst_QChar::fromUcs4_data()
+{
+ QTest::addColumn<uint>("ucs4");
+ auto row = [](uint ucs4) {
+ QTest::addRow("0x%08X", ucs4) << ucs4;
+ };
+
+ row(0x2f868); // a CJK Compatibility Ideograph
+ row(0x11139); // Chakma digit 3
+ row(0x1D157); // Musical Symbol Void Notehead
+}
+
+void tst_QChar::fromUcs4()
+{
+ QFETCH(const uint, ucs4);
+
+ const auto result = QChar::fromUcs4(ucs4);
+ if (QChar::requiresSurrogates(ucs4)) {
+ QCOMPARE(result.chars[0], QChar::highSurrogate(ucs4));
+ QCOMPARE(result.chars[1], QChar::lowSurrogate(ucs4));
+ QCOMPARE(QStringView{result}.size(), 2);
+ } else {
+ QCOMPARE(result.chars[0], ucs4);
+ QCOMPARE(result.chars[1], 0u);
+ QCOMPARE(QStringView{result}.size(), 1);
+ }
}
void tst_QChar::fromWchar_t()
{
#if defined(Q_OS_WIN)
- QChar aUmlaut = L'\u00E4'; // German small letter a-umlaut
+ QChar aUmlaut(L'\u00E4'); // German small letter a-umlaut
QCOMPARE(aUmlaut, QChar(0xE4));
- QChar replacementCharacter = L'\uFFFD';
+ QChar replacementCharacter(L'\uFFFD');
QCOMPARE(replacementCharacter, QChar(QChar::ReplacementCharacter));
#else
QSKIP("This is a Windows-only test.");
@@ -176,6 +176,36 @@ void tst_QChar::operators()
#undef CHECK
}
+void tst_QChar::qchar_qlatin1char_operators_symmetry_data()
+{
+ QTest::addColumn<char>("lhs");
+ QTest::addColumn<char>("rhs");
+
+ const uchar values[] = {0x00, 0x3a, 0x7f, 0x80, 0xab, 0xff};
+
+ for (uchar i : values) {
+ for (uchar j : values)
+ QTest::addRow("'\\x%02x'_op_'\\x%02x'", i, j) << char(i) << char(j);
+ }
+}
+
+void tst_QChar::qchar_qlatin1char_operators_symmetry()
+{
+ QFETCH(char, lhs);
+ QFETCH(char, rhs);
+
+ const QLatin1Char l1lhs(lhs);
+ const QLatin1Char l1rhs(rhs);
+#define CHECK(op) QCOMPARE((l1lhs op l1rhs), (QChar(l1lhs) op QChar(l1rhs)))
+ CHECK(==);
+ CHECK(!=);
+ CHECK(< );
+ CHECK(> );
+ CHECK(<=);
+ CHECK(>=);
+#undef CHECK
+}
+
void tst_QChar::toUpper()
{
QVERIFY(QChar('a').toUpper() == 'A');
@@ -725,24 +755,6 @@ void tst_QChar::decomposition()
}
}
-void tst_QChar::lineBreakClass()
-{
- QVERIFY(QUnicodeTables::lineBreakClass(0x0029) == QUnicodeTables::LineBreak_CP);
- QVERIFY(QUnicodeTables::lineBreakClass(0x0041) == QUnicodeTables::LineBreak_AL);
- QVERIFY(QUnicodeTables::lineBreakClass(0x0033) == QUnicodeTables::LineBreak_NU);
- QVERIFY(QUnicodeTables::lineBreakClass(0x00ad) == QUnicodeTables::LineBreak_BA);
- QVERIFY(QUnicodeTables::lineBreakClass(0x05d0) == QUnicodeTables::LineBreak_HL);
- QVERIFY(QUnicodeTables::lineBreakClass(0xfffc) == QUnicodeTables::LineBreak_CB);
- QVERIFY(QUnicodeTables::lineBreakClass(0xe0164) == QUnicodeTables::LineBreak_CM);
- QVERIFY(QUnicodeTables::lineBreakClass(0x2f9a4) == QUnicodeTables::LineBreak_ID);
- QVERIFY(QUnicodeTables::lineBreakClass(0x10000) == QUnicodeTables::LineBreak_AL);
- QVERIFY(QUnicodeTables::lineBreakClass(0x1f1e6) == QUnicodeTables::LineBreak_RI);
-
- // mapped to AL:
- QVERIFY(QUnicodeTables::lineBreakClass(0xfffd) == QUnicodeTables::LineBreak_AL); // AI -> AL
- QVERIFY(QUnicodeTables::lineBreakClass(0x100000) == QUnicodeTables::LineBreak_AL); // XX -> AL
-}
-
void tst_QChar::script()
{
QVERIFY(QChar::script(0x0020) == QChar::Script_Common);
@@ -781,6 +793,8 @@ void tst_QChar::script()
QVERIFY(QChar::script(0xe0100) == QChar::Script_Inherited);
}
+// wasm is limited in reading filesystems, so omit this test for now
+#if !defined(Q_OS_WASM)
void tst_QChar::normalization_data()
{
QTest::addColumn<QStringList>("columns");
@@ -792,9 +806,7 @@ void tst_QChar::normalization_data()
QString testFile = QFINDTESTDATA("data/NormalizationTest.txt");
QVERIFY2(!testFile.isEmpty(), "data/NormalizationTest.txt not found!");
QFile f(testFile);
- QVERIFY(f.exists());
-
- f.open(QIODevice::ReadOnly);
+ QVERIFY(f.open(QIODevice::ReadOnly));
while (!f.atEnd()) {
linenum++;
@@ -819,7 +831,7 @@ void tst_QChar::normalization_data()
line = line.trimmed();
if (line.endsWith(';'))
- line.truncate(line.length()-1);
+ line.truncate(line.size()-1);
QList<QByteArray> l = line.split(';');
@@ -835,13 +847,7 @@ void tst_QChar::normalization_data()
for (int j = 0; j < c.size(); ++j) {
bool ok;
uint uc = c.at(j).toInt(&ok, 16);
- if (!QChar::requiresSurrogates(uc)) {
- columns[i].append(QChar(uc));
- } else {
- // convert to utf16
- columns[i].append(QChar(QChar::highSurrogate(uc)));
- columns[i].append(QChar(QChar::lowSurrogate(uc)));
- }
+ columns[i].append(QChar::fromUcs4(uc));
}
}
@@ -857,7 +863,7 @@ void tst_QChar::normalization()
QFETCH(QStringList, columns);
QFETCH(int, part);
- Q_UNUSED(part)
+ Q_UNUSED(part);
// CONFORMANCE:
// 1. The following invariants must be true for all conformant implementations
@@ -909,6 +915,7 @@ void tst_QChar::normalization()
// #################
}
+#endif // !defined(Q_OS_WASM)
void tst_QChar::normalization_manual()
{
@@ -980,6 +987,25 @@ void tst_QChar::normalization_manual()
QVERIFY(decomposed.normalized(QString::NormalizationForm_KD) == decomposed);
QVERIFY(decomposed.normalized(QString::NormalizationForm_KC) == composed);
}
+ // QTBUG-71894 - erratum fixed in Unicode 4.1.0; SCount bounds are < not <=
+ {
+ // Hangul compose, test 0x11a7:
+ const QChar c[] = { QChar(0xae30), QChar(0x11a7), {} };
+ const QChar d[] = { QChar(0x1100), QChar(0x1175), QChar(0x11a7), {} };
+ const QString composed(c, 2);
+ const QString decomposed(d, 3);
+
+ QCOMPARE(decomposed.normalized(QString::NormalizationForm_C), composed);
+ }
+ {
+ // Hangul compose, test 0x11c3:
+ const QChar c[] = { QChar(0xae30), QChar(0x11c3), {} };
+ const QChar d[] = { QChar(0x1100), QChar(0x1175), QChar(0x11c3), {} };
+ const QString composed(c, 2);
+ const QString decomposed(d, 3);
+
+ QCOMPARE(decomposed.normalized(QString::NormalizationForm_C), composed);
+ }
}
void tst_QChar::normalizationCorrections()