/**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage ** This file contains pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions ** contained in the either Technology Preview License Agreement or the ** Beta Release License Agreement. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain ** additional rights. These rights are described in the Nokia Qt LGPL ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this ** package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please ** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ #include #include #include #include #if defined(Q_OS_WINCE) #include #endif //TESTED_CLASS= //TESTED_FILES= class tst_QChar : public QObject { Q_OBJECT public: tst_QChar(); ~tst_QChar(); public slots: void initTestCase(); void cleanupTestCase(); void init(); void cleanup(); private slots: void toUpper(); void toLower(); void toTitle(); void toCaseFolded(); void isUpper(); void isLower(); void category(); void direction(); void joining(); void combiningClass(); void digitValue(); void decomposition(); // void ligature(); void lineBreakClass(); void normalization(); void normalizationCorrections(); void unicodeVersion(); #if defined(Q_OS_WINCE) private: QCoreApplication* app; #endif }; tst_QChar::tst_QChar() {} tst_QChar::~tst_QChar() { } void tst_QChar::initTestCase() { } void tst_QChar::cleanupTestCase() { } void tst_QChar::init() { #if defined(Q_OS_WINCE) int argc = 0; app = new QCoreApplication(argc, NULL); #endif } void tst_QChar::cleanup() { #if defined(Q_OS_WINCE) delete app; #endif } void tst_QChar::toUpper() { QVERIFY(QChar('a').toUpper() == 'A'); QVERIFY(QChar('A').toUpper() == 'A'); QVERIFY(QChar((ushort)0x1c7).toUpper().unicode() == 0x1c7); QVERIFY(QChar((ushort)0x1c8).toUpper().unicode() == 0x1c7); QVERIFY(QChar((ushort)0x1c9).toUpper().unicode() == 0x1c7); QVERIFY(QChar::toUpper((ushort)'a') == 'A'); QVERIFY(QChar::toUpper((ushort)'A') == 'A'); QVERIFY(QChar::toUpper((ushort)0x1c7) == 0x1c7); QVERIFY(QChar::toUpper((ushort)0x1c8) == 0x1c7); QVERIFY(QChar::toUpper((ushort)0x1c9) == 0x1c7); QVERIFY(QChar::toUpper((uint)'a') == 'A'); QVERIFY(QChar::toUpper((uint)'A') == 'A'); QVERIFY(QChar::toUpper((uint)0x1c7) == 0x1c7); QVERIFY(QChar::toUpper((uint)0x1c8) == 0x1c7); QVERIFY(QChar::toUpper((uint)0x1c9) == 0x1c7); QVERIFY(QChar::toUpper((uint)0x10400) == 0x10400); QVERIFY(QChar::toUpper((uint)0x10428) == 0x10400); } void tst_QChar::toLower() { QVERIFY(QChar('A').toLower() == 'a'); QVERIFY(QChar('a').toLower() == 'a'); QVERIFY(QChar((ushort)0x1c7).toLower().unicode() == 0x1c9); QVERIFY(QChar((ushort)0x1c8).toLower().unicode() == 0x1c9); QVERIFY(QChar((ushort)0x1c9).toLower().unicode() == 0x1c9); QVERIFY(QChar::toLower((ushort)'a') == 'a'); QVERIFY(QChar::toLower((ushort)'A') == 'a'); QVERIFY(QChar::toLower((ushort)0x1c7) == 0x1c9); QVERIFY(QChar::toLower((ushort)0x1c8) == 0x1c9); QVERIFY(QChar::toLower((ushort)0x1c9) == 0x1c9); QVERIFY(QChar::toLower((uint)'a') == 'a'); QVERIFY(QChar::toLower((uint)'A') == 'a'); QVERIFY(QChar::toLower((uint)0x1c7) == 0x1c9); QVERIFY(QChar::toLower((uint)0x1c8) == 0x1c9); QVERIFY(QChar::toLower((uint)0x1c9) == 0x1c9); QVERIFY(QChar::toLower((uint)0x10400) == 0x10428); QVERIFY(QChar::toLower((uint)0x10428) == 0x10428); } void tst_QChar::toTitle() { QVERIFY(QChar('a').toTitleCase() == 'A'); QVERIFY(QChar('A').toTitleCase() == 'A'); QVERIFY(QChar((ushort)0x1c7).toTitleCase().unicode() == 0x1c8); QVERIFY(QChar((ushort)0x1c8).toTitleCase().unicode() == 0x1c8); QVERIFY(QChar((ushort)0x1c9).toTitleCase().unicode() == 0x1c8); QVERIFY(QChar::toTitleCase((ushort)'a') == 'A'); QVERIFY(QChar::toTitleCase((ushort)'A') == 'A'); QVERIFY(QChar::toTitleCase((ushort)0x1c7) == 0x1c8); QVERIFY(QChar::toTitleCase((ushort)0x1c8) == 0x1c8); QVERIFY(QChar::toTitleCase((ushort)0x1c9) == 0x1c8); QVERIFY(QChar::toTitleCase((uint)'a') == 'A'); QVERIFY(QChar::toTitleCase((uint)'A') == 'A'); QVERIFY(QChar::toTitleCase((uint)0x1c7) == 0x1c8); QVERIFY(QChar::toTitleCase((uint)0x1c8) == 0x1c8); QVERIFY(QChar::toTitleCase((uint)0x1c9) == 0x1c8); QVERIFY(QChar::toTitleCase((uint)0x10400) == 0x10400); QVERIFY(QChar::toTitleCase((uint)0x10428) == 0x10400); } void tst_QChar::toCaseFolded() { QVERIFY(QChar('a').toCaseFolded() == 'a'); QVERIFY(QChar('A').toCaseFolded() == 'a'); QVERIFY(QChar((ushort)0x1c7).toCaseFolded().unicode() == 0x1c9); QVERIFY(QChar((ushort)0x1c8).toCaseFolded().unicode() == 0x1c9); QVERIFY(QChar((ushort)0x1c9).toCaseFolded().unicode() == 0x1c9); QVERIFY(QChar::toCaseFolded((ushort)'a') == 'a'); QVERIFY(QChar::toCaseFolded((ushort)'A') == 'a'); QVERIFY(QChar::toCaseFolded((ushort)0x1c7) == 0x1c9); QVERIFY(QChar::toCaseFolded((ushort)0x1c8) == 0x1c9); QVERIFY(QChar::toCaseFolded((ushort)0x1c9) == 0x1c9); QVERIFY(QChar::toCaseFolded((uint)'a') == 'a'); QVERIFY(QChar::toCaseFolded((uint)'A') == 'a'); QVERIFY(QChar::toCaseFolded((uint)0x1c7) == 0x1c9); QVERIFY(QChar::toCaseFolded((uint)0x1c8) == 0x1c9); QVERIFY(QChar::toCaseFolded((uint)0x1c9) == 0x1c9); QVERIFY(QChar::toCaseFolded((uint)0x10400) == 0x10428); QVERIFY(QChar::toCaseFolded((uint)0x10428) == 0x10428); QVERIFY(QChar::toCaseFolded((ushort)0xb5) == 0x3bc); } void tst_QChar::isUpper() { QVERIFY(QChar('A').isUpper()); QVERIFY(QChar('Z').isUpper()); QVERIFY(!QChar('a').isUpper()); QVERIFY(!QChar('z').isUpper()); QVERIFY(!QChar('?').isUpper()); QVERIFY(QChar(0xC2).isUpper()); // A with ^ QVERIFY(!QChar(0xE2).isUpper()); // a with ^ } void tst_QChar::isLower() { QVERIFY(!QChar('A').isLower()); QVERIFY(!QChar('Z').isLower()); QVERIFY(QChar('a').isLower()); QVERIFY(QChar('z').isLower()); QVERIFY(!QChar('?').isLower()); QVERIFY(!QChar(0xC2).isLower()); // A with ^ QVERIFY(QChar(0xE2).isLower()); // a with ^ } void tst_QChar::category() { QVERIFY(QChar('a').category() == QChar::Letter_Lowercase); QVERIFY(QChar('A').category() == QChar::Letter_Uppercase); QVERIFY(QChar::category((ushort)'a') == QChar::Letter_Lowercase); QVERIFY(QChar::category((ushort)'A') == QChar::Letter_Uppercase); QVERIFY(QChar::category((uint)'a') == QChar::Letter_Lowercase); QVERIFY(QChar::category((uint)'A') == QChar::Letter_Uppercase); QVERIFY(QChar::category(0xe0100u) == QChar::Mark_NonSpacing); QVERIFY(QChar::category(0xeffffu) != QChar::Other_PrivateUse); QVERIFY(QChar::category(0xf0000u) == QChar::Other_PrivateUse); QVERIFY(QChar::category(0xf0001u) == QChar::Other_PrivateUse); QVERIFY(QChar::category(0xd900u) == QChar::Other_Surrogate); QVERIFY(QChar::category(0xdc00u) == QChar::Other_Surrogate); QVERIFY(QChar::category(0xdc01u) == QChar::Other_Surrogate); } void tst_QChar::direction() { QVERIFY(QChar('a').direction() == QChar::DirL); QVERIFY(QChar('0').direction() == QChar::DirEN); QVERIFY(QChar((ushort)0x627).direction() == QChar::DirAL); QVERIFY(QChar((ushort)0x5d0).direction() == QChar::DirR); QVERIFY(QChar::direction((ushort)'a') == QChar::DirL); QVERIFY(QChar::direction((ushort)'0') == QChar::DirEN); QVERIFY(QChar::direction((ushort)0x627) == QChar::DirAL); QVERIFY(QChar::direction((ushort)0x5d0) == QChar::DirR); QVERIFY(QChar::direction((uint)'a') == QChar::DirL); QVERIFY(QChar::direction((uint)'0') == QChar::DirEN); QVERIFY(QChar::direction((uint)0x627) == QChar::DirAL); QVERIFY(QChar::direction((uint)0x5d0) == QChar::DirR); QVERIFY(QChar::direction(0xE01DAu) == QChar::DirNSM); QVERIFY(QChar::direction(0xf0000u) == QChar::DirL); QVERIFY(QChar::direction(0xE0030u) == QChar::DirBN); QVERIFY(QChar::direction(0x2FA17u) == QChar::DirL); } void tst_QChar::joining() { QVERIFY(QChar('a').joining() == QChar::OtherJoining); QVERIFY(QChar('0').joining() == QChar::OtherJoining); QVERIFY(QChar((ushort)0x627).joining() == QChar::Right); QVERIFY(QChar((ushort)0x5d0).joining() == QChar::OtherJoining); QVERIFY(QChar::joining((ushort)'a') == QChar::OtherJoining); QVERIFY(QChar::joining((ushort)'0') == QChar::OtherJoining); QVERIFY(QChar::joining((ushort)0x627) == QChar::Right); QVERIFY(QChar::joining((ushort)0x5d0) == QChar::OtherJoining); QVERIFY(QChar::joining((uint)'a') == QChar::OtherJoining); QVERIFY(QChar::joining((uint)'0') == QChar::OtherJoining); QVERIFY(QChar::joining((uint)0x627) == QChar::Right); QVERIFY(QChar::joining((uint)0x5d0) == QChar::OtherJoining); QVERIFY(QChar::joining(0xE01DAu) == QChar::OtherJoining); QVERIFY(QChar::joining(0xf0000u) == QChar::OtherJoining); QVERIFY(QChar::joining(0xE0030u) == QChar::OtherJoining); QVERIFY(QChar::joining(0x2FA17u) == QChar::OtherJoining); } void tst_QChar::combiningClass() { QVERIFY(QChar('a').combiningClass() == 0); QVERIFY(QChar('0').combiningClass() == 0); QVERIFY(QChar((ushort)0x627).combiningClass() == 0); QVERIFY(QChar((ushort)0x5d0).combiningClass() == 0); QVERIFY(QChar::combiningClass((ushort)'a') == 0); QVERIFY(QChar::combiningClass((ushort)'0') == 0); QVERIFY(QChar::combiningClass((ushort)0x627) == 0); QVERIFY(QChar::combiningClass((ushort)0x5d0) == 0); QVERIFY(QChar::combiningClass((uint)'a') == 0); QVERIFY(QChar::combiningClass((uint)'0') == 0); QVERIFY(QChar::combiningClass((uint)0x627) == 0); QVERIFY(QChar::combiningClass((uint)0x5d0) == 0); QVERIFY(QChar::combiningClass(0xE01DAu) == 0); QVERIFY(QChar::combiningClass(0xf0000u) == 0); QVERIFY(QChar::combiningClass(0xE0030u) == 0); QVERIFY(QChar::combiningClass(0x2FA17u) == 0); QVERIFY(QChar::combiningClass((ushort)0x300) == 230); QVERIFY(QChar::combiningClass((uint)0x300) == 230); QVERIFY(QChar::combiningClass((uint)0x1d244) == 230); } void tst_QChar::unicodeVersion() { QVERIFY(QChar('a').unicodeVersion() == QChar::Unicode_1_1); QVERIFY(QChar('0').unicodeVersion() == QChar::Unicode_1_1); QVERIFY(QChar((ushort)0x627).unicodeVersion() == QChar::Unicode_1_1); QVERIFY(QChar((ushort)0x5d0).unicodeVersion() == QChar::Unicode_1_1); QVERIFY(QChar::unicodeVersion((ushort)'a') == QChar::Unicode_1_1); QVERIFY(QChar::unicodeVersion((ushort)'0') == QChar::Unicode_1_1); QVERIFY(QChar::unicodeVersion((ushort)0x627) == QChar::Unicode_1_1); QVERIFY(QChar::unicodeVersion((ushort)0x5d0) == QChar::Unicode_1_1); QVERIFY(QChar::unicodeVersion((uint)'a') == QChar::Unicode_1_1); QVERIFY(QChar::unicodeVersion((uint)'0') == QChar::Unicode_1_1); QVERIFY(QChar::unicodeVersion((uint)0x627) == QChar::Unicode_1_1); QVERIFY(QChar::unicodeVersion((uint)0x5d0) == QChar::Unicode_1_1); QVERIFY(QChar(0x0591).unicodeVersion() == QChar::Unicode_2_0); QVERIFY(QChar::unicodeVersion((ushort)0x0591) == QChar::Unicode_2_0); QVERIFY(QChar::unicodeVersion((uint)0x0591) == QChar::Unicode_2_0); QVERIFY(QChar(0x20AC).unicodeVersion() == QChar::Unicode_2_1_2); QVERIFY(QChar::unicodeVersion((ushort)0x020AC) == QChar::Unicode_2_1_2); QVERIFY(QChar::unicodeVersion((uint)0x20AC) == QChar::Unicode_2_1_2); QVERIFY(QChar(0xfffc).unicodeVersion() == QChar::Unicode_2_1_2); QVERIFY(QChar::unicodeVersion((ushort)0x0fffc) == QChar::Unicode_2_1_2); QVERIFY(QChar::unicodeVersion((uint)0xfffc) == QChar::Unicode_2_1_2); QVERIFY(QChar(0x01f6).unicodeVersion() == QChar::Unicode_3_0); QVERIFY(QChar::unicodeVersion((ushort)0x01f6) == QChar::Unicode_3_0); QVERIFY(QChar::unicodeVersion((uint)0x01f6) == QChar::Unicode_3_0); QVERIFY(QChar(0x03F4).unicodeVersion() == QChar::Unicode_3_1); QVERIFY(QChar::unicodeVersion((ushort)0x03F4) == QChar::Unicode_3_1); QVERIFY(QChar::unicodeVersion((uint)0x03F4) == QChar::Unicode_3_1); QVERIFY(QChar::unicodeVersion((uint)0x10300) == QChar::Unicode_3_1); QVERIFY(QChar(0x0220).unicodeVersion() == QChar::Unicode_3_2); QVERIFY(QChar::unicodeVersion((ushort)0x0220) == QChar::Unicode_3_2); QVERIFY(QChar::unicodeVersion((uint)0x0220) == QChar::Unicode_3_2); QVERIFY(QChar::unicodeVersion((uint)0xFF5F) == QChar::Unicode_3_2); QVERIFY(QChar(0x0221).unicodeVersion() == QChar::Unicode_4_0); QVERIFY(QChar::unicodeVersion((ushort)0x0221) == QChar::Unicode_4_0); QVERIFY(QChar::unicodeVersion((uint)0x0221) == QChar::Unicode_4_0); QVERIFY(QChar::unicodeVersion((uint)0x10000) == QChar::Unicode_4_0); QVERIFY(QChar(0x0237).unicodeVersion() == QChar::Unicode_4_1); QVERIFY(QChar::unicodeVersion((ushort)0x0237) == QChar::Unicode_4_1); QVERIFY(QChar::unicodeVersion((uint)0x0237) == QChar::Unicode_4_1); QVERIFY(QChar::unicodeVersion((uint)0x10140) == QChar::Unicode_4_1); QVERIFY(QChar(0x0242).unicodeVersion() == QChar::Unicode_5_0); QVERIFY(QChar::unicodeVersion((ushort)0x0242) == QChar::Unicode_5_0); QVERIFY(QChar::unicodeVersion((uint)0x0242) == QChar::Unicode_5_0); QVERIFY(QChar::unicodeVersion((uint)0x12000) == QChar::Unicode_5_0); } void tst_QChar::digitValue() { QVERIFY(QChar('9').digitValue() == 9); QVERIFY(QChar('0').digitValue() == 0); QVERIFY(QChar('a').digitValue() == -1); QVERIFY(QChar::digitValue((ushort)'9') == 9); QVERIFY(QChar::digitValue((ushort)'0') == 0); QVERIFY(QChar::digitValue((uint)'9') == 9); QVERIFY(QChar::digitValue((uint)'0') == 0); QVERIFY(QChar::digitValue((ushort)0x1049) == 9); QVERIFY(QChar::digitValue((ushort)0x1040) == 0); QVERIFY(QChar::digitValue((uint)0x1049) == 9); QVERIFY(QChar::digitValue((uint)0x1040) == 0); } void tst_QChar::decomposition() { QVERIFY(QChar((ushort)0xa0).decompositionTag() == QChar::NoBreak); QVERIFY(QChar((ushort)0xa8).decompositionTag() == QChar::Compat); QVERIFY(QChar((ushort)0x41).decompositionTag() == QChar::NoDecomposition); QVERIFY(QChar::decompositionTag(0xa0) == QChar::NoBreak); QVERIFY(QChar::decompositionTag(0xa8) == QChar::Compat); QVERIFY(QChar::decompositionTag(0x41) == QChar::NoDecomposition); QVERIFY(QChar::decomposition(0xa0) == QString(QChar(0x20))); QVERIFY(QChar::decomposition(0xc0) == (QString(QChar(0x41)) + QString(QChar(0x300)))); { QString str; str += QChar( (0x1D157 - 0x10000) / 0x400 + 0xd800 ); str += QChar( ((0x1D157 - 0x10000) % 0x400) + 0xdc00 ); str += QChar( (0x1D165 - 0x10000) / 0x400 + 0xd800 ); str += QChar( ((0x1D165 - 0x10000) % 0x400) + 0xdc00 ); QVERIFY(QChar::decomposition(0x1D15e) == str); } { QString str; str += QChar(0x1100); str += QChar(0x1161); QVERIFY(QChar::decomposition(0xac00) == str); } { QString str; str += QChar(0x110c); str += QChar(0x1165); str += QChar(0x11b7); QVERIFY(QChar::decomposition(0xc810) == str); } } #if 0 void tst_QChar::ligature() { QVERIFY(QChar::ligature(0x0041, 0x00300) == 0xc0); QVERIFY(QChar::ligature(0x0049, 0x00308) == 0xcf); QVERIFY(QChar::ligature(0x0391, 0x00301) == 0x386); QVERIFY(QChar::ligature(0x0627, 0x00653) == 0x622); QVERIFY(QChar::ligature(0x1100, 0x1161) == 0xac00); QVERIFY(QChar::ligature(0xac00, 0x11a8) == 0xac01); } #endif void tst_QChar::lineBreakClass() { QVERIFY(QUnicodeTables::lineBreakClass(0x0041u) == QUnicodeTables::LineBreak_AL); QVERIFY(QUnicodeTables::lineBreakClass(0x0033u) == QUnicodeTables::LineBreak_NU); QVERIFY(QUnicodeTables::lineBreakClass(0xe0164u) == QUnicodeTables::LineBreak_CM); QVERIFY(QUnicodeTables::lineBreakClass(0x2f9a4u) == QUnicodeTables::LineBreak_ID); QVERIFY(QUnicodeTables::lineBreakClass(0x10000u) == QUnicodeTables::LineBreak_AL); QVERIFY(QUnicodeTables::lineBreakClass(0x0fffdu) == QUnicodeTables::LineBreak_AL); } void tst_QChar::normalization() { { QString composed; composed += QChar(0xc0); QString decomposed; decomposed += QChar(0x41); decomposed += QChar(0x300); QVERIFY(composed.normalized(QString::NormalizationForm_D) == decomposed); QVERIFY(composed.normalized(QString::NormalizationForm_C) == composed); QVERIFY(composed.normalized(QString::NormalizationForm_KD) == decomposed); QVERIFY(composed.normalized(QString::NormalizationForm_KC) == composed); } { QString composed; composed += QChar(0xa0); QString decomposed; decomposed += QChar(0x20); QVERIFY(composed.normalized(QString::NormalizationForm_D) == composed); QVERIFY(composed.normalized(QString::NormalizationForm_C) == composed); QVERIFY(composed.normalized(QString::NormalizationForm_KD) == decomposed); QVERIFY(composed.normalized(QString::NormalizationForm_KC) == decomposed); } QFile f("NormalizationTest.txt"); if (!f.exists()) { QFAIL("Couldn't find NormalizationTest.txt"); return; } f.open(QIODevice::ReadOnly); while (!f.atEnd()) { QByteArray line; line.resize(1024); int len = f.readLine(line.data(), 1024); line.resize(len-1); int comment = line.indexOf('#'); if (comment >= 0) line = line.left(comment); if (line.startsWith("@")) continue; if (line.isEmpty()) continue; line = line.trimmed(); if (line.endsWith(';')) line.truncate(line.length()-1); QList l = line.split(';'); Q_ASSERT(l.size() == 5); QString columns[5]; for (int i = 0; i < 5; ++i) { QList c = l.at(i).split(' '); Q_ASSERT(!c.isEmpty()); for (int j = 0; j < c.size(); ++j) { bool ok; uint uc = c.at(j).toInt(&ok, 16); if (uc < 0x10000) columns[i].append(QChar(uc)); else { // convert to utf16 uc -= 0x10000; ushort high = uc/0x400 + 0xd800; ushort low = uc%0x400 + 0xdc00; columns[i].append(QChar(high)); columns[i].append(QChar(low)); } } } // CONFORMANCE: // 1. The following invariants must be true for all conformant implementations // // NFC // c2 == NFC(c1) == NFC(c2) == NFC(c3) // c4 == NFC(c4) == NFC(c5) QVERIFY(columns[1] == columns[0].normalized(QString::NormalizationForm_C)); QVERIFY(columns[1] == columns[1].normalized(QString::NormalizationForm_C)); QVERIFY(columns[1] == columns[2].normalized(QString::NormalizationForm_C)); QVERIFY(columns[3] == columns[3].normalized(QString::NormalizationForm_C)); QVERIFY(columns[3] == columns[4].normalized(QString::NormalizationForm_C)); // NFD // c3 == NFD(c1) == NFD(c2) == NFD(c3) // c5 == NFD(c4) == NFD(c5) QVERIFY(columns[2] == columns[0].normalized(QString::NormalizationForm_D)); QVERIFY(columns[2] == columns[1].normalized(QString::NormalizationForm_D)); QVERIFY(columns[2] == columns[2].normalized(QString::NormalizationForm_D)); QVERIFY(columns[4] == columns[3].normalized(QString::NormalizationForm_D)); QVERIFY(columns[4] == columns[4].normalized(QString::NormalizationForm_D)); // NFKC // c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5) QVERIFY(columns[3] == columns[0].normalized(QString::NormalizationForm_KC)); QVERIFY(columns[3] == columns[1].normalized(QString::NormalizationForm_KC)); QVERIFY(columns[3] == columns[2].normalized(QString::NormalizationForm_KC)); QVERIFY(columns[3] == columns[3].normalized(QString::NormalizationForm_KC)); QVERIFY(columns[3] == columns[4].normalized(QString::NormalizationForm_KC)); // NFKD // c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5) QVERIFY(columns[4] == columns[0].normalized(QString::NormalizationForm_KD)); QVERIFY(columns[4] == columns[1].normalized(QString::NormalizationForm_KD)); QVERIFY(columns[4] == columns[2].normalized(QString::NormalizationForm_KD)); QVERIFY(columns[4] == columns[3].normalized(QString::NormalizationForm_KD)); QVERIFY(columns[4] == columns[4].normalized(QString::NormalizationForm_KD)); // 2. For every code point X assigned in this version of Unicode that is not specifically // listed in Part 1, the following invariants must be true for all conformant // implementations: // // X == NFC(X) == NFD(X) == NFKC(X) == NFKD(X) // ################# } } void tst_QChar::normalizationCorrections() { QString s; s.append(QChar(0xf951)); QString n = s.normalized(QString::NormalizationForm_D); QString res; res.append(QChar(0x964b)); QCOMPARE(n, res); n = s.normalized(QString::NormalizationForm_D, QChar::Unicode_3_1); res.clear(); res.append(QChar(0x96fb)); QCOMPARE(n, res); s.clear(); s += QChar(QChar::highSurrogate(0x2f868)); s += QChar(QChar::lowSurrogate(0x2f868)); n = s.normalized(QString::NormalizationForm_C); res.clear(); res += QChar(0x36fc); QCOMPARE(n, res); n = s.normalized(QString::NormalizationForm_C, QChar::Unicode_3_1); res.clear(); res += QChar(0xd844); res += QChar(0xdf6a); QCOMPARE(n, res); n = s.normalized(QString::NormalizationForm_C, QChar::Unicode_3_2); QCOMPARE(n, res); } QTEST_APPLESS_MAIN(tst_QChar) #include "tst_qchar.moc"