1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include <QtTest/QtTest>
45 #include <qstringlist.h>
46 #include <private/qunicodetables_p.h>
47 #if defined(Q_OS_WINCE)
48 #include <qcoreapplication.h>
51 class tst_QChar : public QObject
66 void isLetterOrNumber_data();
67 void isLetterOrNumber();
73 void isSpaceSpecial();
78 void combiningClass();
81 void lineBreakClass();
82 void normalization_data();
84 void normalization_manual();
85 void normalizationCorrections();
86 void unicodeVersion();
87 #if defined(Q_OS_WINCE)
89 QCoreApplication* app;
93 void tst_QChar::init()
95 #if defined(Q_OS_WINCE)
97 app = new QCoreApplication(argc, NULL);
101 void tst_QChar::cleanup()
103 #if defined(Q_OS_WINCE)
108 void tst_QChar::toUpper()
110 QVERIFY(QChar('a').toUpper() == 'A');
111 QVERIFY(QChar('A').toUpper() == 'A');
112 QVERIFY(QChar((ushort)0x1c7).toUpper().unicode() == 0x1c7);
113 QVERIFY(QChar((ushort)0x1c8).toUpper().unicode() == 0x1c7);
114 QVERIFY(QChar((ushort)0x1c9).toUpper().unicode() == 0x1c7);
116 QVERIFY(QChar::toUpper((ushort)'a') == 'A');
117 QVERIFY(QChar::toUpper((ushort)'A') == 'A');
118 QVERIFY(QChar::toUpper((ushort)0x1c7) == 0x1c7);
119 QVERIFY(QChar::toUpper((ushort)0x1c8) == 0x1c7);
120 QVERIFY(QChar::toUpper((ushort)0x1c9) == 0x1c7);
122 QVERIFY(QChar::toUpper((uint)'a') == 'A');
123 QVERIFY(QChar::toUpper((uint)'A') == 'A');
124 QVERIFY(QChar::toUpper((uint)0x1c7) == 0x1c7);
125 QVERIFY(QChar::toUpper((uint)0x1c8) == 0x1c7);
126 QVERIFY(QChar::toUpper((uint)0x1c9) == 0x1c7);
128 QVERIFY(QChar::toUpper((uint)0x10400) == 0x10400);
129 QVERIFY(QChar::toUpper((uint)0x10428) == 0x10400);
133 void tst_QChar::toLower()
135 QVERIFY(QChar('A').toLower() == 'a');
136 QVERIFY(QChar('a').toLower() == 'a');
137 QVERIFY(QChar((ushort)0x1c7).toLower().unicode() == 0x1c9);
138 QVERIFY(QChar((ushort)0x1c8).toLower().unicode() == 0x1c9);
139 QVERIFY(QChar((ushort)0x1c9).toLower().unicode() == 0x1c9);
141 QVERIFY(QChar::toLower((ushort)'a') == 'a');
142 QVERIFY(QChar::toLower((ushort)'A') == 'a');
143 QVERIFY(QChar::toLower((ushort)0x1c7) == 0x1c9);
144 QVERIFY(QChar::toLower((ushort)0x1c8) == 0x1c9);
145 QVERIFY(QChar::toLower((ushort)0x1c9) == 0x1c9);
147 QVERIFY(QChar::toLower((uint)'a') == 'a');
148 QVERIFY(QChar::toLower((uint)'A') == 'a');
149 QVERIFY(QChar::toLower((uint)0x1c7) == 0x1c9);
150 QVERIFY(QChar::toLower((uint)0x1c8) == 0x1c9);
151 QVERIFY(QChar::toLower((uint)0x1c9) == 0x1c9);
153 QVERIFY(QChar::toLower((uint)0x10400) == 0x10428);
154 QVERIFY(QChar::toLower((uint)0x10428) == 0x10428);
157 void tst_QChar::toTitle()
159 QVERIFY(QChar('a').toTitleCase() == 'A');
160 QVERIFY(QChar('A').toTitleCase() == 'A');
161 QVERIFY(QChar((ushort)0x1c7).toTitleCase().unicode() == 0x1c8);
162 QVERIFY(QChar((ushort)0x1c8).toTitleCase().unicode() == 0x1c8);
163 QVERIFY(QChar((ushort)0x1c9).toTitleCase().unicode() == 0x1c8);
165 QVERIFY(QChar::toTitleCase((ushort)'a') == 'A');
166 QVERIFY(QChar::toTitleCase((ushort)'A') == 'A');
167 QVERIFY(QChar::toTitleCase((ushort)0x1c7) == 0x1c8);
168 QVERIFY(QChar::toTitleCase((ushort)0x1c8) == 0x1c8);
169 QVERIFY(QChar::toTitleCase((ushort)0x1c9) == 0x1c8);
171 QVERIFY(QChar::toTitleCase((uint)'a') == 'A');
172 QVERIFY(QChar::toTitleCase((uint)'A') == 'A');
173 QVERIFY(QChar::toTitleCase((uint)0x1c7) == 0x1c8);
174 QVERIFY(QChar::toTitleCase((uint)0x1c8) == 0x1c8);
175 QVERIFY(QChar::toTitleCase((uint)0x1c9) == 0x1c8);
177 QVERIFY(QChar::toTitleCase((uint)0x10400) == 0x10400);
178 QVERIFY(QChar::toTitleCase((uint)0x10428) == 0x10400);
182 void tst_QChar::toCaseFolded()
184 QVERIFY(QChar('a').toCaseFolded() == 'a');
185 QVERIFY(QChar('A').toCaseFolded() == 'a');
186 QVERIFY(QChar((ushort)0x1c7).toCaseFolded().unicode() == 0x1c9);
187 QVERIFY(QChar((ushort)0x1c8).toCaseFolded().unicode() == 0x1c9);
188 QVERIFY(QChar((ushort)0x1c9).toCaseFolded().unicode() == 0x1c9);
190 QVERIFY(QChar::toCaseFolded((ushort)'a') == 'a');
191 QVERIFY(QChar::toCaseFolded((ushort)'A') == 'a');
192 QVERIFY(QChar::toCaseFolded((ushort)0x1c7) == 0x1c9);
193 QVERIFY(QChar::toCaseFolded((ushort)0x1c8) == 0x1c9);
194 QVERIFY(QChar::toCaseFolded((ushort)0x1c9) == 0x1c9);
196 QVERIFY(QChar::toCaseFolded((uint)'a') == 'a');
197 QVERIFY(QChar::toCaseFolded((uint)'A') == 'a');
198 QVERIFY(QChar::toCaseFolded((uint)0x1c7) == 0x1c9);
199 QVERIFY(QChar::toCaseFolded((uint)0x1c8) == 0x1c9);
200 QVERIFY(QChar::toCaseFolded((uint)0x1c9) == 0x1c9);
202 QVERIFY(QChar::toCaseFolded((uint)0x10400) == 0x10428);
203 QVERIFY(QChar::toCaseFolded((uint)0x10428) == 0x10428);
205 QVERIFY(QChar::toCaseFolded((ushort)0xb5) == 0x3bc);
208 void tst_QChar::isDigit_data()
210 QTest::addColumn<ushort>("ucs");
211 QTest::addColumn<bool>("expected");
213 for (ushort ucs = 0; ucs < 256; ++ucs) {
214 bool isDigit = (ucs <= '9' && ucs >= '0');
215 QString tag = QString::fromLatin1("0x%0").arg(QString::number(ucs, 16));
216 QTest::newRow(tag.toLatin1()) << ucs << isDigit;
220 void tst_QChar::isDigit()
223 QFETCH(bool, expected);
224 QCOMPARE(QChar(ucs).isDigit(), expected);
227 static bool isExpectedLetter(ushort ucs)
229 return (ucs >= 'a' && ucs <= 'z') || (ucs >= 'A' && ucs <= 'Z')
230 || ucs == 0xAA || ucs == 0xB5 || ucs == 0xBA
231 || (ucs >= 0xC0 && ucs <= 0xD6)
232 || (ucs >= 0xD8 && ucs <= 0xF6)
233 || (ucs >= 0xF8 && ucs <= 0xFF);
236 void tst_QChar::isLetter_data()
238 QTest::addColumn<ushort>("ucs");
239 QTest::addColumn<bool>("expected");
241 for (ushort ucs = 0; ucs < 256; ++ucs) {
242 QString tag = QString::fromLatin1("0x%0").arg(QString::number(ucs, 16));
243 QTest::newRow(tag.toLatin1()) << ucs << isExpectedLetter(ucs);
247 void tst_QChar::isLetter()
250 QFETCH(bool, expected);
251 QCOMPARE(QChar(ucs).isLetter(), expected);
254 void tst_QChar::isLetterOrNumber_data()
256 QTest::addColumn<ushort>("ucs");
257 QTest::addColumn<bool>("expected");
259 for (ushort ucs = 0; ucs < 256; ++ucs) {
260 bool isLetterOrNumber = isExpectedLetter(ucs)
261 || (ucs >= '0' && ucs <= '9')
262 || ucs == 0xB2 || ucs == 0xB3 || ucs == 0xB9
263 || (ucs >= 0xBC && ucs <= 0xBE);
264 QString tag = QString::fromLatin1("0x%0").arg(QString::number(ucs, 16));
265 QTest::newRow(tag.toLatin1()) << ucs << isLetterOrNumber;
269 void tst_QChar::isLetterOrNumber()
272 QFETCH(bool, expected);
273 QCOMPARE(QChar(ucs).isLetterOrNumber(), expected);
276 void tst_QChar::isPrint()
278 QVERIFY(QChar('A').isPrint());
279 QVERIFY(!QChar(0x1aff).isPrint()); // General_Gategory =Cn
282 void tst_QChar::isUpper()
284 QVERIFY(QChar('A').isUpper());
285 QVERIFY(QChar('Z').isUpper());
286 QVERIFY(!QChar('a').isUpper());
287 QVERIFY(!QChar('z').isUpper());
288 QVERIFY(!QChar('?').isUpper());
289 QVERIFY(QChar(0xC2).isUpper()); // A with ^
290 QVERIFY(!QChar(0xE2).isUpper()); // a with ^
292 for (uint codepoint = 0; codepoint <= UNICODE_LAST_CODEPOINT; ++codepoint) {
293 if (QChar::category(codepoint) == QChar::Letter_Uppercase)
294 QVERIFY(codepoint == QChar::toUpper(codepoint));
298 void tst_QChar::isLower()
300 QVERIFY(!QChar('A').isLower());
301 QVERIFY(!QChar('Z').isLower());
302 QVERIFY(QChar('a').isLower());
303 QVERIFY(QChar('z').isLower());
304 QVERIFY(!QChar('?').isLower());
305 QVERIFY(!QChar(0xC2).isLower()); // A with ^
306 QVERIFY(QChar(0xE2).isLower()); // a with ^
308 for (uint codepoint = 0; codepoint <= UNICODE_LAST_CODEPOINT; ++codepoint) {
309 if (QChar::category(codepoint) == QChar::Letter_Lowercase)
310 QVERIFY(codepoint == QChar::toLower(codepoint));
314 void tst_QChar::isSpace_data()
316 QTest::addColumn<ushort>("ucs");
317 QTest::addColumn<bool>("expected");
319 for (ushort ucs = 0; ucs < 256; ++ucs) {
320 bool isSpace = (ucs <= 0x0D && ucs >= 0x09) || ucs == 0x20 || ucs == 0xA0 || ucs == 0x85;
321 QString tag = QString::fromLatin1("0x%0").arg(QString::number(ucs, 16));
322 QTest::newRow(tag.toLatin1()) << ucs << isSpace;
326 void tst_QChar::isSpace()
329 QFETCH(bool, expected);
330 QCOMPARE(QChar(ucs).isSpace(), expected);
333 void tst_QChar::isSpaceSpecial()
335 QVERIFY(!QChar(QChar::Null).isSpace());
336 QVERIFY(QChar(QChar::Nbsp).isSpace());
337 QVERIFY(QChar(QChar::ParagraphSeparator).isSpace());
338 QVERIFY(QChar(QChar::LineSeparator).isSpace());
339 QVERIFY(QChar(0x1680).isSpace());
342 void tst_QChar::isTitle()
344 for (uint codepoint = 0; codepoint <= UNICODE_LAST_CODEPOINT; ++codepoint) {
345 if (QChar::category(codepoint) == QChar::Letter_Titlecase)
346 QVERIFY(codepoint == QChar::toTitleCase(codepoint));
350 void tst_QChar::category()
352 QVERIFY(QChar('a').category() == QChar::Letter_Lowercase);
353 QVERIFY(QChar('A').category() == QChar::Letter_Uppercase);
355 QVERIFY(QChar::category((ushort)'a') == QChar::Letter_Lowercase);
356 QVERIFY(QChar::category((ushort)'A') == QChar::Letter_Uppercase);
358 QVERIFY(QChar::category((uint)'a') == QChar::Letter_Lowercase);
359 QVERIFY(QChar::category((uint)'A') == QChar::Letter_Uppercase);
361 QVERIFY(QChar::category(0xe0100u) == QChar::Mark_NonSpacing);
362 QVERIFY(QChar::category(0xeffffu) != QChar::Other_PrivateUse);
363 QVERIFY(QChar::category(0xf0000u) == QChar::Other_PrivateUse);
364 QVERIFY(QChar::category(0xf0001u) == QChar::Other_PrivateUse);
366 QVERIFY(QChar::category(0xd900u) == QChar::Other_Surrogate);
367 QVERIFY(QChar::category(0xdc00u) == QChar::Other_Surrogate);
368 QVERIFY(QChar::category(0xdc01u) == QChar::Other_Surrogate);
370 QVERIFY(QChar::category((uint)0x1aff) == QChar::Other_NotAssigned);
371 QVERIFY(QChar::category((uint)0x10fffdu) == QChar::Other_PrivateUse);
372 QVERIFY(QChar::category((uint)0x10ffffu) == QChar::Other_NotAssigned);
373 QVERIFY(QChar::category((uint)0x110000u) == QChar::Other_NotAssigned);
376 void tst_QChar::direction()
378 QVERIFY(QChar('a').direction() == QChar::DirL);
379 QVERIFY(QChar('0').direction() == QChar::DirEN);
380 QVERIFY(QChar((ushort)0x627).direction() == QChar::DirAL);
381 QVERIFY(QChar((ushort)0x5d0).direction() == QChar::DirR);
383 QVERIFY(QChar::direction((ushort)'a') == QChar::DirL);
384 QVERIFY(QChar::direction((ushort)'0') == QChar::DirEN);
385 QVERIFY(QChar::direction((ushort)0x627) == QChar::DirAL);
386 QVERIFY(QChar::direction((ushort)0x5d0) == QChar::DirR);
388 QVERIFY(QChar::direction((uint)'a') == QChar::DirL);
389 QVERIFY(QChar::direction((uint)'0') == QChar::DirEN);
390 QVERIFY(QChar::direction((uint)0x627) == QChar::DirAL);
391 QVERIFY(QChar::direction((uint)0x5d0) == QChar::DirR);
393 QVERIFY(QChar::direction(0xE01DAu) == QChar::DirNSM);
394 QVERIFY(QChar::direction(0xf0000u) == QChar::DirL);
395 QVERIFY(QChar::direction(0xE0030u) == QChar::DirBN);
396 QVERIFY(QChar::direction(0x2FA17u) == QChar::DirL);
399 void tst_QChar::joining()
401 QVERIFY(QChar('a').joining() == QChar::OtherJoining);
402 QVERIFY(QChar('0').joining() == QChar::OtherJoining);
403 QVERIFY(QChar((ushort)0x627).joining() == QChar::Right);
404 QVERIFY(QChar((ushort)0x5d0).joining() == QChar::OtherJoining);
406 QVERIFY(QChar::joining((ushort)'a') == QChar::OtherJoining);
407 QVERIFY(QChar::joining((ushort)'0') == QChar::OtherJoining);
408 QVERIFY(QChar::joining((ushort)0x627) == QChar::Right);
409 QVERIFY(QChar::joining((ushort)0x5d0) == QChar::OtherJoining);
411 QVERIFY(QChar::joining((uint)'a') == QChar::OtherJoining);
412 QVERIFY(QChar::joining((uint)'0') == QChar::OtherJoining);
413 QVERIFY(QChar::joining((uint)0x627) == QChar::Right);
414 QVERIFY(QChar::joining((uint)0x5d0) == QChar::OtherJoining);
416 QVERIFY(QChar::joining(0xE01DAu) == QChar::OtherJoining);
417 QVERIFY(QChar::joining(0xf0000u) == QChar::OtherJoining);
418 QVERIFY(QChar::joining(0xE0030u) == QChar::OtherJoining);
419 QVERIFY(QChar::joining(0x2FA17u) == QChar::OtherJoining);
422 void tst_QChar::combiningClass()
424 QVERIFY(QChar('a').combiningClass() == 0);
425 QVERIFY(QChar('0').combiningClass() == 0);
426 QVERIFY(QChar((ushort)0x627).combiningClass() == 0);
427 QVERIFY(QChar((ushort)0x5d0).combiningClass() == 0);
429 QVERIFY(QChar::combiningClass((ushort)'a') == 0);
430 QVERIFY(QChar::combiningClass((ushort)'0') == 0);
431 QVERIFY(QChar::combiningClass((ushort)0x627) == 0);
432 QVERIFY(QChar::combiningClass((ushort)0x5d0) == 0);
434 QVERIFY(QChar::combiningClass((uint)'a') == 0);
435 QVERIFY(QChar::combiningClass((uint)'0') == 0);
436 QVERIFY(QChar::combiningClass((uint)0x627) == 0);
437 QVERIFY(QChar::combiningClass((uint)0x5d0) == 0);
439 QVERIFY(QChar::combiningClass(0xE01DAu) == 0);
440 QVERIFY(QChar::combiningClass(0xf0000u) == 0);
441 QVERIFY(QChar::combiningClass(0xE0030u) == 0);
442 QVERIFY(QChar::combiningClass(0x2FA17u) == 0);
444 QVERIFY(QChar::combiningClass((ushort)0x300) == 230);
445 QVERIFY(QChar::combiningClass((uint)0x300) == 230);
447 QVERIFY(QChar::combiningClass((uint)0x1d244) == 230);
451 void tst_QChar::unicodeVersion()
453 QVERIFY(QChar('a').unicodeVersion() == QChar::Unicode_1_1);
454 QVERIFY(QChar('0').unicodeVersion() == QChar::Unicode_1_1);
455 QVERIFY(QChar((ushort)0x627).unicodeVersion() == QChar::Unicode_1_1);
456 QVERIFY(QChar((ushort)0x5d0).unicodeVersion() == QChar::Unicode_1_1);
458 QVERIFY(QChar::unicodeVersion((ushort)'a') == QChar::Unicode_1_1);
459 QVERIFY(QChar::unicodeVersion((ushort)'0') == QChar::Unicode_1_1);
460 QVERIFY(QChar::unicodeVersion((ushort)0x627) == QChar::Unicode_1_1);
461 QVERIFY(QChar::unicodeVersion((ushort)0x5d0) == QChar::Unicode_1_1);
463 QVERIFY(QChar::unicodeVersion((uint)'a') == QChar::Unicode_1_1);
464 QVERIFY(QChar::unicodeVersion((uint)'0') == QChar::Unicode_1_1);
465 QVERIFY(QChar::unicodeVersion((uint)0x627) == QChar::Unicode_1_1);
466 QVERIFY(QChar::unicodeVersion((uint)0x5d0) == QChar::Unicode_1_1);
468 QVERIFY(QChar(0x0591).unicodeVersion() == QChar::Unicode_2_0);
469 QVERIFY(QChar::unicodeVersion((ushort)0x0591) == QChar::Unicode_2_0);
470 QVERIFY(QChar::unicodeVersion((uint)0x0591) == QChar::Unicode_2_0);
472 QVERIFY(QChar(0x20AC).unicodeVersion() == QChar::Unicode_2_1_2);
473 QVERIFY(QChar::unicodeVersion((ushort)0x020AC) == QChar::Unicode_2_1_2);
474 QVERIFY(QChar::unicodeVersion((uint)0x20AC) == QChar::Unicode_2_1_2);
475 QVERIFY(QChar(0xfffc).unicodeVersion() == QChar::Unicode_2_1_2);
476 QVERIFY(QChar::unicodeVersion((ushort)0x0fffc) == QChar::Unicode_2_1_2);
477 QVERIFY(QChar::unicodeVersion((uint)0xfffc) == QChar::Unicode_2_1_2);
479 QVERIFY(QChar(0x01f6).unicodeVersion() == QChar::Unicode_3_0);
480 QVERIFY(QChar::unicodeVersion((ushort)0x01f6) == QChar::Unicode_3_0);
481 QVERIFY(QChar::unicodeVersion((uint)0x01f6) == QChar::Unicode_3_0);
483 QVERIFY(QChar(0x03F4).unicodeVersion() == QChar::Unicode_3_1);
484 QVERIFY(QChar::unicodeVersion((ushort)0x03F4) == QChar::Unicode_3_1);
485 QVERIFY(QChar::unicodeVersion((uint)0x03F4) == QChar::Unicode_3_1);
486 QVERIFY(QChar::unicodeVersion((uint)0x10300) == QChar::Unicode_3_1);
488 QVERIFY(QChar(0x0220).unicodeVersion() == QChar::Unicode_3_2);
489 QVERIFY(QChar::unicodeVersion((ushort)0x0220) == QChar::Unicode_3_2);
490 QVERIFY(QChar::unicodeVersion((uint)0x0220) == QChar::Unicode_3_2);
491 QVERIFY(QChar::unicodeVersion((uint)0xFF5F) == QChar::Unicode_3_2);
493 QVERIFY(QChar(0x0221).unicodeVersion() == QChar::Unicode_4_0);
494 QVERIFY(QChar::unicodeVersion((ushort)0x0221) == QChar::Unicode_4_0);
495 QVERIFY(QChar::unicodeVersion((uint)0x0221) == QChar::Unicode_4_0);
496 QVERIFY(QChar::unicodeVersion((uint)0x10000) == QChar::Unicode_4_0);
498 QVERIFY(QChar(0x0237).unicodeVersion() == QChar::Unicode_4_1);
499 QVERIFY(QChar::unicodeVersion((ushort)0x0237) == QChar::Unicode_4_1);
500 QVERIFY(QChar::unicodeVersion((uint)0x0237) == QChar::Unicode_4_1);
501 QVERIFY(QChar::unicodeVersion((uint)0x10140) == QChar::Unicode_4_1);
503 QVERIFY(QChar(0x0242).unicodeVersion() == QChar::Unicode_5_0);
504 QVERIFY(QChar::unicodeVersion((ushort)0x0242) == QChar::Unicode_5_0);
505 QVERIFY(QChar::unicodeVersion((uint)0x0242) == QChar::Unicode_5_0);
506 QVERIFY(QChar::unicodeVersion((uint)0x12000) == QChar::Unicode_5_0);
511 void tst_QChar::digitValue()
513 QVERIFY(QChar('9').digitValue() == 9);
514 QVERIFY(QChar('0').digitValue() == 0);
515 QVERIFY(QChar('a').digitValue() == -1);
517 QVERIFY(QChar::digitValue((ushort)'9') == 9);
518 QVERIFY(QChar::digitValue((ushort)'0') == 0);
519 QVERIFY(QChar::digitValue((uint)'9') == 9);
520 QVERIFY(QChar::digitValue((uint)'0') == 0);
522 QVERIFY(QChar::digitValue((ushort)0x1049) == 9);
523 QVERIFY(QChar::digitValue((ushort)0x1040) == 0);
524 QVERIFY(QChar::digitValue((uint)0x1049) == 9);
525 QVERIFY(QChar::digitValue((uint)0x1040) == 0);
527 QVERIFY(QChar::digitValue((ushort)0xd800) == -1);
528 QVERIFY(QChar::digitValue((uint)UNICODE_LAST_CODEPOINT + 1) == -1);
531 void tst_QChar::decomposition()
533 QVERIFY(QChar((ushort)0xa0).decompositionTag() == QChar::NoBreak);
534 QVERIFY(QChar((ushort)0xa8).decompositionTag() == QChar::Compat);
535 QVERIFY(QChar((ushort)0x41).decompositionTag() == QChar::NoDecomposition);
537 QVERIFY(QChar::decompositionTag(0xa0) == QChar::NoBreak);
538 QVERIFY(QChar::decompositionTag(0xa8) == QChar::Compat);
539 QVERIFY(QChar::decompositionTag(0x41) == QChar::NoDecomposition);
541 QVERIFY(QChar::decomposition(0xa0) == QString(QChar(0x20)));
542 QVERIFY(QChar::decomposition(0xc0) == (QString(QChar(0x41)) + QString(QChar(0x300))));
546 str += QChar( (0x1D157 - 0x10000) / 0x400 + 0xd800 );
547 str += QChar( ((0x1D157 - 0x10000) % 0x400) + 0xdc00 );
548 str += QChar( (0x1D165 - 0x10000) / 0x400 + 0xd800 );
549 str += QChar( ((0x1D165 - 0x10000) % 0x400) + 0xdc00 );
550 QVERIFY(QChar::decomposition(0x1D15e) == str);
555 str += QChar(0x1100);
556 str += QChar(0x1161);
557 QVERIFY(QChar::decomposition(0xac00) == str);
561 str += QChar(0x110c);
562 str += QChar(0x1165);
563 str += QChar(0x11b7);
564 QVERIFY(QChar::decomposition(0xc810) == str);
568 void tst_QChar::lineBreakClass()
570 QVERIFY(QUnicodeTables::lineBreakClass(0x0041u) == QUnicodeTables::LineBreak_AL);
571 QVERIFY(QUnicodeTables::lineBreakClass(0x0033u) == QUnicodeTables::LineBreak_NU);
572 QVERIFY(QUnicodeTables::lineBreakClass(0xe0164u) == QUnicodeTables::LineBreak_CM);
573 QVERIFY(QUnicodeTables::lineBreakClass(0x2f9a4u) == QUnicodeTables::LineBreak_ID);
574 QVERIFY(QUnicodeTables::lineBreakClass(0x10000u) == QUnicodeTables::LineBreak_AL);
575 QVERIFY(QUnicodeTables::lineBreakClass(0x0fffdu) == QUnicodeTables::LineBreak_AL);
578 void tst_QChar::normalization_data()
580 QTest::addColumn<QStringList>("columns");
581 QTest::addColumn<int>("part");
586 QString testFile = QFINDTESTDATA("NormalizationTest.txt");
587 QVERIFY2(!testFile.isEmpty(), "NormalizationTest.txt not found!");
591 f.open(QIODevice::ReadOnly);
598 int len = f.readLine(line.data(), 1024);
601 int comment = line.indexOf('#');
603 line = line.left(comment);
605 if (line.startsWith("@")) {
606 if (line.startsWith("@Part") && line.size() > 5 && QChar(line.at(5)).isDigit())
607 part = QChar(line.at(5)).digitValue();
614 line = line.trimmed();
615 if (line.endsWith(';'))
616 line.truncate(line.length()-1);
618 QList<QByteArray> l = line.split(';');
620 QCOMPARE(l.size(), 5);
623 for (int i = 0; i < 5; ++i) {
624 columns.append(QString());
626 QList<QByteArray> c = l.at(i).split(' ');
627 QVERIFY(!c.isEmpty());
629 for (int j = 0; j < c.size(); ++j) {
631 uint uc = c.at(j).toInt(&ok, 16);
633 columns[i].append(QChar(uc));
636 ushort high = QChar::highSurrogate(uc);
637 ushort low = QChar::lowSurrogate(uc);
638 columns[i].append(QChar(high));
639 columns[i].append(QChar(low));
644 QString nm = QString("line #%1:").arg(linenum);
645 QTest::newRow(nm.toLatin1()) << columns << part;
649 void tst_QChar::normalization()
651 QFETCH(QStringList, columns);
657 // 1. The following invariants must be true for all conformant implementations
660 // c2 == NFC(c1) == NFC(c2) == NFC(c3)
661 // c4 == NFC(c4) == NFC(c5)
663 QVERIFY(columns[1] == columns[0].normalized(QString::NormalizationForm_C));
664 QVERIFY(columns[1] == columns[1].normalized(QString::NormalizationForm_C));
665 QVERIFY(columns[1] == columns[2].normalized(QString::NormalizationForm_C));
666 QVERIFY(columns[3] == columns[3].normalized(QString::NormalizationForm_C));
667 QVERIFY(columns[3] == columns[4].normalized(QString::NormalizationForm_C));
670 // c3 == NFD(c1) == NFD(c2) == NFD(c3)
671 // c5 == NFD(c4) == NFD(c5)
673 QVERIFY(columns[2] == columns[0].normalized(QString::NormalizationForm_D));
674 QVERIFY(columns[2] == columns[1].normalized(QString::NormalizationForm_D));
675 QVERIFY(columns[2] == columns[2].normalized(QString::NormalizationForm_D));
676 QVERIFY(columns[4] == columns[3].normalized(QString::NormalizationForm_D));
677 QVERIFY(columns[4] == columns[4].normalized(QString::NormalizationForm_D));
680 // c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5)
682 QVERIFY(columns[3] == columns[0].normalized(QString::NormalizationForm_KC));
683 QVERIFY(columns[3] == columns[1].normalized(QString::NormalizationForm_KC));
684 QVERIFY(columns[3] == columns[2].normalized(QString::NormalizationForm_KC));
685 QVERIFY(columns[3] == columns[3].normalized(QString::NormalizationForm_KC));
686 QVERIFY(columns[3] == columns[4].normalized(QString::NormalizationForm_KC));
689 // c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5)
691 QVERIFY(columns[4] == columns[0].normalized(QString::NormalizationForm_KD));
692 QVERIFY(columns[4] == columns[1].normalized(QString::NormalizationForm_KD));
693 QVERIFY(columns[4] == columns[2].normalized(QString::NormalizationForm_KD));
694 QVERIFY(columns[4] == columns[3].normalized(QString::NormalizationForm_KD));
695 QVERIFY(columns[4] == columns[4].normalized(QString::NormalizationForm_KD));
697 // 2. For every code point X assigned in this version of Unicode that is not specifically
698 // listed in Part 1, the following invariants must be true for all conformant
701 // X == NFC(X) == NFD(X) == NFKC(X) == NFKD(X)
707 void tst_QChar::normalization_manual()
711 composed += QChar(0xc0);
713 decomposed += QChar(0x41);
714 decomposed += QChar(0x300);
716 QVERIFY(composed.normalized(QString::NormalizationForm_D) == decomposed);
717 QVERIFY(composed.normalized(QString::NormalizationForm_C) == composed);
718 QVERIFY(composed.normalized(QString::NormalizationForm_KD) == decomposed);
719 QVERIFY(composed.normalized(QString::NormalizationForm_KC) == composed);
723 composed += QChar(0xa0);
725 decomposed += QChar(0x20);
727 QVERIFY(composed.normalized(QString::NormalizationForm_D) == composed);
728 QVERIFY(composed.normalized(QString::NormalizationForm_C) == composed);
729 QVERIFY(composed.normalized(QString::NormalizationForm_KD) == decomposed);
730 QVERIFY(composed.normalized(QString::NormalizationForm_KC) == decomposed);
734 void tst_QChar::normalizationCorrections()
737 s.append(QChar(0xf951));
739 QString n = s.normalized(QString::NormalizationForm_D);
741 res.append(QChar(0x964b));
744 n = s.normalized(QString::NormalizationForm_D, QChar::Unicode_3_1);
746 res.append(QChar(0x96fb));
750 s += QChar(QChar::highSurrogate(0x2f868));
751 s += QChar(QChar::lowSurrogate(0x2f868));
753 n = s.normalized(QString::NormalizationForm_C);
755 res += QChar(0x36fc);
758 n = s.normalized(QString::NormalizationForm_C, QChar::Unicode_3_1);
760 res += QChar(0xd844);
761 res += QChar(0xdf6a);
764 n = s.normalized(QString::NormalizationForm_C, QChar::Unicode_3_2);
769 QTEST_APPLESS_MAIN(tst_QChar)
770 #include "tst_qchar.moc"