|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 |
|
43 #include <QtTest/QtTest> |
|
44 #include <qchar.h> |
|
45 #include <qfile.h> |
|
46 #include <private/qunicodetables_p.h> |
|
47 #if defined(Q_OS_WINCE) |
|
48 #include <qcoreapplication.h> |
|
49 #endif |
|
50 |
|
51 |
|
52 |
|
53 //TESTED_CLASS= |
|
54 //TESTED_FILES= |
|
55 |
|
56 class tst_QChar : public QObject |
|
57 { |
|
58 Q_OBJECT |
|
59 |
|
60 public: |
|
61 tst_QChar(); |
|
62 ~tst_QChar(); |
|
63 |
|
64 |
|
65 public slots: |
|
66 void initTestCase(); |
|
67 void cleanupTestCase(); |
|
68 void init(); |
|
69 void cleanup(); |
|
70 private slots: |
|
71 void toUpper(); |
|
72 void toLower(); |
|
73 void toTitle(); |
|
74 void toCaseFolded(); |
|
75 void isUpper(); |
|
76 void isLower(); |
|
77 void category(); |
|
78 void direction(); |
|
79 void joining(); |
|
80 void combiningClass(); |
|
81 void digitValue(); |
|
82 void decomposition(); |
|
83 // void ligature(); |
|
84 void lineBreakClass(); |
|
85 void normalization(); |
|
86 void normalizationCorrections(); |
|
87 void unicodeVersion(); |
|
88 #if defined(Q_OS_WINCE) |
|
89 private: |
|
90 QCoreApplication* app; |
|
91 #endif |
|
92 }; |
|
93 |
|
94 tst_QChar::tst_QChar() |
|
95 {} |
|
96 |
|
97 tst_QChar::~tst_QChar() |
|
98 { } |
|
99 |
|
100 void tst_QChar::initTestCase() |
|
101 { } |
|
102 |
|
103 void tst_QChar::cleanupTestCase() |
|
104 { } |
|
105 |
|
106 void tst_QChar::init() |
|
107 { |
|
108 #if defined(Q_OS_WINCE) |
|
109 int argc = 0; |
|
110 app = new QCoreApplication(argc, NULL); |
|
111 #endif |
|
112 } |
|
113 |
|
114 void tst_QChar::cleanup() |
|
115 { |
|
116 #if defined(Q_OS_WINCE) |
|
117 delete app; |
|
118 #endif |
|
119 } |
|
120 |
|
121 void tst_QChar::toUpper() |
|
122 { |
|
123 QVERIFY(QChar('a').toUpper() == 'A'); |
|
124 QVERIFY(QChar('A').toUpper() == 'A'); |
|
125 QVERIFY(QChar((ushort)0x1c7).toUpper().unicode() == 0x1c7); |
|
126 QVERIFY(QChar((ushort)0x1c8).toUpper().unicode() == 0x1c7); |
|
127 QVERIFY(QChar((ushort)0x1c9).toUpper().unicode() == 0x1c7); |
|
128 |
|
129 QVERIFY(QChar::toUpper((ushort)'a') == 'A'); |
|
130 QVERIFY(QChar::toUpper((ushort)'A') == 'A'); |
|
131 QVERIFY(QChar::toUpper((ushort)0x1c7) == 0x1c7); |
|
132 QVERIFY(QChar::toUpper((ushort)0x1c8) == 0x1c7); |
|
133 QVERIFY(QChar::toUpper((ushort)0x1c9) == 0x1c7); |
|
134 |
|
135 QVERIFY(QChar::toUpper((uint)'a') == 'A'); |
|
136 QVERIFY(QChar::toUpper((uint)'A') == 'A'); |
|
137 QVERIFY(QChar::toUpper((uint)0x1c7) == 0x1c7); |
|
138 QVERIFY(QChar::toUpper((uint)0x1c8) == 0x1c7); |
|
139 QVERIFY(QChar::toUpper((uint)0x1c9) == 0x1c7); |
|
140 |
|
141 QVERIFY(QChar::toUpper((uint)0x10400) == 0x10400); |
|
142 QVERIFY(QChar::toUpper((uint)0x10428) == 0x10400); |
|
143 |
|
144 } |
|
145 |
|
146 void tst_QChar::toLower() |
|
147 { |
|
148 QVERIFY(QChar('A').toLower() == 'a'); |
|
149 QVERIFY(QChar('a').toLower() == 'a'); |
|
150 QVERIFY(QChar((ushort)0x1c7).toLower().unicode() == 0x1c9); |
|
151 QVERIFY(QChar((ushort)0x1c8).toLower().unicode() == 0x1c9); |
|
152 QVERIFY(QChar((ushort)0x1c9).toLower().unicode() == 0x1c9); |
|
153 |
|
154 QVERIFY(QChar::toLower((ushort)'a') == 'a'); |
|
155 QVERIFY(QChar::toLower((ushort)'A') == 'a'); |
|
156 QVERIFY(QChar::toLower((ushort)0x1c7) == 0x1c9); |
|
157 QVERIFY(QChar::toLower((ushort)0x1c8) == 0x1c9); |
|
158 QVERIFY(QChar::toLower((ushort)0x1c9) == 0x1c9); |
|
159 |
|
160 QVERIFY(QChar::toLower((uint)'a') == 'a'); |
|
161 QVERIFY(QChar::toLower((uint)'A') == 'a'); |
|
162 QVERIFY(QChar::toLower((uint)0x1c7) == 0x1c9); |
|
163 QVERIFY(QChar::toLower((uint)0x1c8) == 0x1c9); |
|
164 QVERIFY(QChar::toLower((uint)0x1c9) == 0x1c9); |
|
165 |
|
166 QVERIFY(QChar::toLower((uint)0x10400) == 0x10428); |
|
167 QVERIFY(QChar::toLower((uint)0x10428) == 0x10428); |
|
168 } |
|
169 |
|
170 void tst_QChar::toTitle() |
|
171 { |
|
172 QVERIFY(QChar('a').toTitleCase() == 'A'); |
|
173 QVERIFY(QChar('A').toTitleCase() == 'A'); |
|
174 QVERIFY(QChar((ushort)0x1c7).toTitleCase().unicode() == 0x1c8); |
|
175 QVERIFY(QChar((ushort)0x1c8).toTitleCase().unicode() == 0x1c8); |
|
176 QVERIFY(QChar((ushort)0x1c9).toTitleCase().unicode() == 0x1c8); |
|
177 |
|
178 QVERIFY(QChar::toTitleCase((ushort)'a') == 'A'); |
|
179 QVERIFY(QChar::toTitleCase((ushort)'A') == 'A'); |
|
180 QVERIFY(QChar::toTitleCase((ushort)0x1c7) == 0x1c8); |
|
181 QVERIFY(QChar::toTitleCase((ushort)0x1c8) == 0x1c8); |
|
182 QVERIFY(QChar::toTitleCase((ushort)0x1c9) == 0x1c8); |
|
183 |
|
184 QVERIFY(QChar::toTitleCase((uint)'a') == 'A'); |
|
185 QVERIFY(QChar::toTitleCase((uint)'A') == 'A'); |
|
186 QVERIFY(QChar::toTitleCase((uint)0x1c7) == 0x1c8); |
|
187 QVERIFY(QChar::toTitleCase((uint)0x1c8) == 0x1c8); |
|
188 QVERIFY(QChar::toTitleCase((uint)0x1c9) == 0x1c8); |
|
189 |
|
190 QVERIFY(QChar::toTitleCase((uint)0x10400) == 0x10400); |
|
191 QVERIFY(QChar::toTitleCase((uint)0x10428) == 0x10400); |
|
192 |
|
193 } |
|
194 |
|
195 void tst_QChar::toCaseFolded() |
|
196 { |
|
197 QVERIFY(QChar('a').toCaseFolded() == 'a'); |
|
198 QVERIFY(QChar('A').toCaseFolded() == 'a'); |
|
199 QVERIFY(QChar((ushort)0x1c7).toCaseFolded().unicode() == 0x1c9); |
|
200 QVERIFY(QChar((ushort)0x1c8).toCaseFolded().unicode() == 0x1c9); |
|
201 QVERIFY(QChar((ushort)0x1c9).toCaseFolded().unicode() == 0x1c9); |
|
202 |
|
203 QVERIFY(QChar::toCaseFolded((ushort)'a') == 'a'); |
|
204 QVERIFY(QChar::toCaseFolded((ushort)'A') == 'a'); |
|
205 QVERIFY(QChar::toCaseFolded((ushort)0x1c7) == 0x1c9); |
|
206 QVERIFY(QChar::toCaseFolded((ushort)0x1c8) == 0x1c9); |
|
207 QVERIFY(QChar::toCaseFolded((ushort)0x1c9) == 0x1c9); |
|
208 |
|
209 QVERIFY(QChar::toCaseFolded((uint)'a') == 'a'); |
|
210 QVERIFY(QChar::toCaseFolded((uint)'A') == 'a'); |
|
211 QVERIFY(QChar::toCaseFolded((uint)0x1c7) == 0x1c9); |
|
212 QVERIFY(QChar::toCaseFolded((uint)0x1c8) == 0x1c9); |
|
213 QVERIFY(QChar::toCaseFolded((uint)0x1c9) == 0x1c9); |
|
214 |
|
215 QVERIFY(QChar::toCaseFolded((uint)0x10400) == 0x10428); |
|
216 QVERIFY(QChar::toCaseFolded((uint)0x10428) == 0x10428); |
|
217 |
|
218 QVERIFY(QChar::toCaseFolded((ushort)0xb5) == 0x3bc); |
|
219 } |
|
220 |
|
221 void tst_QChar::isUpper() |
|
222 { |
|
223 QVERIFY(QChar('A').isUpper()); |
|
224 QVERIFY(QChar('Z').isUpper()); |
|
225 QVERIFY(!QChar('a').isUpper()); |
|
226 QVERIFY(!QChar('z').isUpper()); |
|
227 QVERIFY(!QChar('?').isUpper()); |
|
228 QVERIFY(QChar(0xC2).isUpper()); // A with ^ |
|
229 QVERIFY(!QChar(0xE2).isUpper()); // a with ^ |
|
230 } |
|
231 |
|
232 void tst_QChar::isLower() |
|
233 { |
|
234 QVERIFY(!QChar('A').isLower()); |
|
235 QVERIFY(!QChar('Z').isLower()); |
|
236 QVERIFY(QChar('a').isLower()); |
|
237 QVERIFY(QChar('z').isLower()); |
|
238 QVERIFY(!QChar('?').isLower()); |
|
239 QVERIFY(!QChar(0xC2).isLower()); // A with ^ |
|
240 QVERIFY(QChar(0xE2).isLower()); // a with ^ |
|
241 } |
|
242 |
|
243 void tst_QChar::category() |
|
244 { |
|
245 QVERIFY(QChar('a').category() == QChar::Letter_Lowercase); |
|
246 QVERIFY(QChar('A').category() == QChar::Letter_Uppercase); |
|
247 |
|
248 QVERIFY(QChar::category((ushort)'a') == QChar::Letter_Lowercase); |
|
249 QVERIFY(QChar::category((ushort)'A') == QChar::Letter_Uppercase); |
|
250 |
|
251 QVERIFY(QChar::category((uint)'a') == QChar::Letter_Lowercase); |
|
252 QVERIFY(QChar::category((uint)'A') == QChar::Letter_Uppercase); |
|
253 |
|
254 QVERIFY(QChar::category(0xe0100u) == QChar::Mark_NonSpacing); |
|
255 QVERIFY(QChar::category(0xeffffu) != QChar::Other_PrivateUse); |
|
256 QVERIFY(QChar::category(0xf0000u) == QChar::Other_PrivateUse); |
|
257 QVERIFY(QChar::category(0xf0001u) == QChar::Other_PrivateUse); |
|
258 |
|
259 QVERIFY(QChar::category(0xd900u) == QChar::Other_Surrogate); |
|
260 QVERIFY(QChar::category(0xdc00u) == QChar::Other_Surrogate); |
|
261 QVERIFY(QChar::category(0xdc01u) == QChar::Other_Surrogate); |
|
262 } |
|
263 |
|
264 void tst_QChar::direction() |
|
265 { |
|
266 QVERIFY(QChar('a').direction() == QChar::DirL); |
|
267 QVERIFY(QChar('0').direction() == QChar::DirEN); |
|
268 QVERIFY(QChar((ushort)0x627).direction() == QChar::DirAL); |
|
269 QVERIFY(QChar((ushort)0x5d0).direction() == QChar::DirR); |
|
270 |
|
271 QVERIFY(QChar::direction((ushort)'a') == QChar::DirL); |
|
272 QVERIFY(QChar::direction((ushort)'0') == QChar::DirEN); |
|
273 QVERIFY(QChar::direction((ushort)0x627) == QChar::DirAL); |
|
274 QVERIFY(QChar::direction((ushort)0x5d0) == QChar::DirR); |
|
275 |
|
276 QVERIFY(QChar::direction((uint)'a') == QChar::DirL); |
|
277 QVERIFY(QChar::direction((uint)'0') == QChar::DirEN); |
|
278 QVERIFY(QChar::direction((uint)0x627) == QChar::DirAL); |
|
279 QVERIFY(QChar::direction((uint)0x5d0) == QChar::DirR); |
|
280 |
|
281 QVERIFY(QChar::direction(0xE01DAu) == QChar::DirNSM); |
|
282 QVERIFY(QChar::direction(0xf0000u) == QChar::DirL); |
|
283 QVERIFY(QChar::direction(0xE0030u) == QChar::DirBN); |
|
284 QVERIFY(QChar::direction(0x2FA17u) == QChar::DirL); |
|
285 } |
|
286 |
|
287 void tst_QChar::joining() |
|
288 { |
|
289 QVERIFY(QChar('a').joining() == QChar::OtherJoining); |
|
290 QVERIFY(QChar('0').joining() == QChar::OtherJoining); |
|
291 QVERIFY(QChar((ushort)0x627).joining() == QChar::Right); |
|
292 QVERIFY(QChar((ushort)0x5d0).joining() == QChar::OtherJoining); |
|
293 |
|
294 QVERIFY(QChar::joining((ushort)'a') == QChar::OtherJoining); |
|
295 QVERIFY(QChar::joining((ushort)'0') == QChar::OtherJoining); |
|
296 QVERIFY(QChar::joining((ushort)0x627) == QChar::Right); |
|
297 QVERIFY(QChar::joining((ushort)0x5d0) == QChar::OtherJoining); |
|
298 |
|
299 QVERIFY(QChar::joining((uint)'a') == QChar::OtherJoining); |
|
300 QVERIFY(QChar::joining((uint)'0') == QChar::OtherJoining); |
|
301 QVERIFY(QChar::joining((uint)0x627) == QChar::Right); |
|
302 QVERIFY(QChar::joining((uint)0x5d0) == QChar::OtherJoining); |
|
303 |
|
304 QVERIFY(QChar::joining(0xE01DAu) == QChar::OtherJoining); |
|
305 QVERIFY(QChar::joining(0xf0000u) == QChar::OtherJoining); |
|
306 QVERIFY(QChar::joining(0xE0030u) == QChar::OtherJoining); |
|
307 QVERIFY(QChar::joining(0x2FA17u) == QChar::OtherJoining); |
|
308 } |
|
309 |
|
310 void tst_QChar::combiningClass() |
|
311 { |
|
312 QVERIFY(QChar('a').combiningClass() == 0); |
|
313 QVERIFY(QChar('0').combiningClass() == 0); |
|
314 QVERIFY(QChar((ushort)0x627).combiningClass() == 0); |
|
315 QVERIFY(QChar((ushort)0x5d0).combiningClass() == 0); |
|
316 |
|
317 QVERIFY(QChar::combiningClass((ushort)'a') == 0); |
|
318 QVERIFY(QChar::combiningClass((ushort)'0') == 0); |
|
319 QVERIFY(QChar::combiningClass((ushort)0x627) == 0); |
|
320 QVERIFY(QChar::combiningClass((ushort)0x5d0) == 0); |
|
321 |
|
322 QVERIFY(QChar::combiningClass((uint)'a') == 0); |
|
323 QVERIFY(QChar::combiningClass((uint)'0') == 0); |
|
324 QVERIFY(QChar::combiningClass((uint)0x627) == 0); |
|
325 QVERIFY(QChar::combiningClass((uint)0x5d0) == 0); |
|
326 |
|
327 QVERIFY(QChar::combiningClass(0xE01DAu) == 0); |
|
328 QVERIFY(QChar::combiningClass(0xf0000u) == 0); |
|
329 QVERIFY(QChar::combiningClass(0xE0030u) == 0); |
|
330 QVERIFY(QChar::combiningClass(0x2FA17u) == 0); |
|
331 |
|
332 QVERIFY(QChar::combiningClass((ushort)0x300) == 230); |
|
333 QVERIFY(QChar::combiningClass((uint)0x300) == 230); |
|
334 |
|
335 QVERIFY(QChar::combiningClass((uint)0x1d244) == 230); |
|
336 |
|
337 } |
|
338 |
|
339 void tst_QChar::unicodeVersion() |
|
340 { |
|
341 QVERIFY(QChar('a').unicodeVersion() == QChar::Unicode_1_1); |
|
342 QVERIFY(QChar('0').unicodeVersion() == QChar::Unicode_1_1); |
|
343 QVERIFY(QChar((ushort)0x627).unicodeVersion() == QChar::Unicode_1_1); |
|
344 QVERIFY(QChar((ushort)0x5d0).unicodeVersion() == QChar::Unicode_1_1); |
|
345 |
|
346 QVERIFY(QChar::unicodeVersion((ushort)'a') == QChar::Unicode_1_1); |
|
347 QVERIFY(QChar::unicodeVersion((ushort)'0') == QChar::Unicode_1_1); |
|
348 QVERIFY(QChar::unicodeVersion((ushort)0x627) == QChar::Unicode_1_1); |
|
349 QVERIFY(QChar::unicodeVersion((ushort)0x5d0) == QChar::Unicode_1_1); |
|
350 |
|
351 QVERIFY(QChar::unicodeVersion((uint)'a') == QChar::Unicode_1_1); |
|
352 QVERIFY(QChar::unicodeVersion((uint)'0') == QChar::Unicode_1_1); |
|
353 QVERIFY(QChar::unicodeVersion((uint)0x627) == QChar::Unicode_1_1); |
|
354 QVERIFY(QChar::unicodeVersion((uint)0x5d0) == QChar::Unicode_1_1); |
|
355 |
|
356 QVERIFY(QChar(0x0591).unicodeVersion() == QChar::Unicode_2_0); |
|
357 QVERIFY(QChar::unicodeVersion((ushort)0x0591) == QChar::Unicode_2_0); |
|
358 QVERIFY(QChar::unicodeVersion((uint)0x0591) == QChar::Unicode_2_0); |
|
359 |
|
360 QVERIFY(QChar(0x20AC).unicodeVersion() == QChar::Unicode_2_1_2); |
|
361 QVERIFY(QChar::unicodeVersion((ushort)0x020AC) == QChar::Unicode_2_1_2); |
|
362 QVERIFY(QChar::unicodeVersion((uint)0x20AC) == QChar::Unicode_2_1_2); |
|
363 QVERIFY(QChar(0xfffc).unicodeVersion() == QChar::Unicode_2_1_2); |
|
364 QVERIFY(QChar::unicodeVersion((ushort)0x0fffc) == QChar::Unicode_2_1_2); |
|
365 QVERIFY(QChar::unicodeVersion((uint)0xfffc) == QChar::Unicode_2_1_2); |
|
366 |
|
367 QVERIFY(QChar(0x01f6).unicodeVersion() == QChar::Unicode_3_0); |
|
368 QVERIFY(QChar::unicodeVersion((ushort)0x01f6) == QChar::Unicode_3_0); |
|
369 QVERIFY(QChar::unicodeVersion((uint)0x01f6) == QChar::Unicode_3_0); |
|
370 |
|
371 QVERIFY(QChar(0x03F4).unicodeVersion() == QChar::Unicode_3_1); |
|
372 QVERIFY(QChar::unicodeVersion((ushort)0x03F4) == QChar::Unicode_3_1); |
|
373 QVERIFY(QChar::unicodeVersion((uint)0x03F4) == QChar::Unicode_3_1); |
|
374 QVERIFY(QChar::unicodeVersion((uint)0x10300) == QChar::Unicode_3_1); |
|
375 |
|
376 QVERIFY(QChar(0x0220).unicodeVersion() == QChar::Unicode_3_2); |
|
377 QVERIFY(QChar::unicodeVersion((ushort)0x0220) == QChar::Unicode_3_2); |
|
378 QVERIFY(QChar::unicodeVersion((uint)0x0220) == QChar::Unicode_3_2); |
|
379 QVERIFY(QChar::unicodeVersion((uint)0xFF5F) == QChar::Unicode_3_2); |
|
380 |
|
381 QVERIFY(QChar(0x0221).unicodeVersion() == QChar::Unicode_4_0); |
|
382 QVERIFY(QChar::unicodeVersion((ushort)0x0221) == QChar::Unicode_4_0); |
|
383 QVERIFY(QChar::unicodeVersion((uint)0x0221) == QChar::Unicode_4_0); |
|
384 QVERIFY(QChar::unicodeVersion((uint)0x10000) == QChar::Unicode_4_0); |
|
385 |
|
386 QVERIFY(QChar(0x0237).unicodeVersion() == QChar::Unicode_4_1); |
|
387 QVERIFY(QChar::unicodeVersion((ushort)0x0237) == QChar::Unicode_4_1); |
|
388 QVERIFY(QChar::unicodeVersion((uint)0x0237) == QChar::Unicode_4_1); |
|
389 QVERIFY(QChar::unicodeVersion((uint)0x10140) == QChar::Unicode_4_1); |
|
390 |
|
391 QVERIFY(QChar(0x0242).unicodeVersion() == QChar::Unicode_5_0); |
|
392 QVERIFY(QChar::unicodeVersion((ushort)0x0242) == QChar::Unicode_5_0); |
|
393 QVERIFY(QChar::unicodeVersion((uint)0x0242) == QChar::Unicode_5_0); |
|
394 QVERIFY(QChar::unicodeVersion((uint)0x12000) == QChar::Unicode_5_0); |
|
395 |
|
396 } |
|
397 |
|
398 |
|
399 void tst_QChar::digitValue() |
|
400 { |
|
401 QVERIFY(QChar('9').digitValue() == 9); |
|
402 QVERIFY(QChar('0').digitValue() == 0); |
|
403 QVERIFY(QChar('a').digitValue() == -1); |
|
404 |
|
405 QVERIFY(QChar::digitValue((ushort)'9') == 9); |
|
406 QVERIFY(QChar::digitValue((ushort)'0') == 0); |
|
407 QVERIFY(QChar::digitValue((uint)'9') == 9); |
|
408 QVERIFY(QChar::digitValue((uint)'0') == 0); |
|
409 |
|
410 QVERIFY(QChar::digitValue((ushort)0x1049) == 9); |
|
411 QVERIFY(QChar::digitValue((ushort)0x1040) == 0); |
|
412 QVERIFY(QChar::digitValue((uint)0x1049) == 9); |
|
413 QVERIFY(QChar::digitValue((uint)0x1040) == 0); |
|
414 } |
|
415 |
|
416 void tst_QChar::decomposition() |
|
417 { |
|
418 QVERIFY(QChar((ushort)0xa0).decompositionTag() == QChar::NoBreak); |
|
419 QVERIFY(QChar((ushort)0xa8).decompositionTag() == QChar::Compat); |
|
420 QVERIFY(QChar((ushort)0x41).decompositionTag() == QChar::NoDecomposition); |
|
421 |
|
422 QVERIFY(QChar::decompositionTag(0xa0) == QChar::NoBreak); |
|
423 QVERIFY(QChar::decompositionTag(0xa8) == QChar::Compat); |
|
424 QVERIFY(QChar::decompositionTag(0x41) == QChar::NoDecomposition); |
|
425 |
|
426 QVERIFY(QChar::decomposition(0xa0) == QString(QChar(0x20))); |
|
427 QVERIFY(QChar::decomposition(0xc0) == (QString(QChar(0x41)) + QString(QChar(0x300)))); |
|
428 |
|
429 { |
|
430 QString str; |
|
431 str += QChar( (0x1D157 - 0x10000) / 0x400 + 0xd800 ); |
|
432 str += QChar( ((0x1D157 - 0x10000) % 0x400) + 0xdc00 ); |
|
433 str += QChar( (0x1D165 - 0x10000) / 0x400 + 0xd800 ); |
|
434 str += QChar( ((0x1D165 - 0x10000) % 0x400) + 0xdc00 ); |
|
435 QVERIFY(QChar::decomposition(0x1D15e) == str); |
|
436 } |
|
437 |
|
438 { |
|
439 QString str; |
|
440 str += QChar(0x1100); |
|
441 str += QChar(0x1161); |
|
442 QVERIFY(QChar::decomposition(0xac00) == str); |
|
443 } |
|
444 { |
|
445 QString str; |
|
446 str += QChar(0x110c); |
|
447 str += QChar(0x1165); |
|
448 str += QChar(0x11b7); |
|
449 QVERIFY(QChar::decomposition(0xc810) == str); |
|
450 } |
|
451 } |
|
452 |
|
453 #if 0 |
|
454 void tst_QChar::ligature() |
|
455 { |
|
456 QVERIFY(QChar::ligature(0x0041, 0x00300) == 0xc0); |
|
457 QVERIFY(QChar::ligature(0x0049, 0x00308) == 0xcf); |
|
458 QVERIFY(QChar::ligature(0x0391, 0x00301) == 0x386); |
|
459 QVERIFY(QChar::ligature(0x0627, 0x00653) == 0x622); |
|
460 |
|
461 QVERIFY(QChar::ligature(0x1100, 0x1161) == 0xac00); |
|
462 QVERIFY(QChar::ligature(0xac00, 0x11a8) == 0xac01); |
|
463 } |
|
464 #endif |
|
465 |
|
466 void tst_QChar::lineBreakClass() |
|
467 { |
|
468 QVERIFY(QUnicodeTables::lineBreakClass(0x0041u) == QUnicodeTables::LineBreak_AL); |
|
469 QVERIFY(QUnicodeTables::lineBreakClass(0x0033u) == QUnicodeTables::LineBreak_NU); |
|
470 QVERIFY(QUnicodeTables::lineBreakClass(0xe0164u) == QUnicodeTables::LineBreak_CM); |
|
471 QVERIFY(QUnicodeTables::lineBreakClass(0x2f9a4u) == QUnicodeTables::LineBreak_ID); |
|
472 QVERIFY(QUnicodeTables::lineBreakClass(0x10000u) == QUnicodeTables::LineBreak_AL); |
|
473 QVERIFY(QUnicodeTables::lineBreakClass(0x0fffdu) == QUnicodeTables::LineBreak_AL); |
|
474 } |
|
475 |
|
476 void tst_QChar::normalization() |
|
477 { |
|
478 { |
|
479 QString composed; |
|
480 composed += QChar(0xc0); |
|
481 QString decomposed; |
|
482 decomposed += QChar(0x41); |
|
483 decomposed += QChar(0x300); |
|
484 |
|
485 QVERIFY(composed.normalized(QString::NormalizationForm_D) == decomposed); |
|
486 QVERIFY(composed.normalized(QString::NormalizationForm_C) == composed); |
|
487 QVERIFY(composed.normalized(QString::NormalizationForm_KD) == decomposed); |
|
488 QVERIFY(composed.normalized(QString::NormalizationForm_KC) == composed); |
|
489 } |
|
490 { |
|
491 QString composed; |
|
492 composed += QChar(0xa0); |
|
493 QString decomposed; |
|
494 decomposed += QChar(0x20); |
|
495 |
|
496 QVERIFY(composed.normalized(QString::NormalizationForm_D) == composed); |
|
497 QVERIFY(composed.normalized(QString::NormalizationForm_C) == composed); |
|
498 QVERIFY(composed.normalized(QString::NormalizationForm_KD) == decomposed); |
|
499 QVERIFY(composed.normalized(QString::NormalizationForm_KC) == decomposed); |
|
500 } |
|
501 |
|
502 QFile f("NormalizationTest.txt"); |
|
503 // Windows - current directory is the debug/release subdirectory where the executable is located |
|
504 if (!f.exists()) |
|
505 f.setFileName("../NormalizationTest.txt");; |
|
506 if (!f.exists()) { |
|
507 QFAIL("Couldn't find NormalizationTest.txt"); |
|
508 return; |
|
509 } |
|
510 |
|
511 f.open(QIODevice::ReadOnly); |
|
512 |
|
513 while (!f.atEnd()) { |
|
514 QByteArray line; |
|
515 line.resize(1024); |
|
516 int len = f.readLine(line.data(), 1024); |
|
517 line.resize(len-1); |
|
518 |
|
519 int comment = line.indexOf('#'); |
|
520 if (comment >= 0) |
|
521 line = line.left(comment); |
|
522 |
|
523 if (line.startsWith("@")) |
|
524 continue; |
|
525 |
|
526 if (line.isEmpty()) |
|
527 continue; |
|
528 |
|
529 line = line.trimmed(); |
|
530 if (line.endsWith(';')) |
|
531 line.truncate(line.length()-1); |
|
532 |
|
533 QList<QByteArray> l = line.split(';'); |
|
534 |
|
535 Q_ASSERT(l.size() == 5); |
|
536 |
|
537 QString columns[5]; |
|
538 for (int i = 0; i < 5; ++i) { |
|
539 QList<QByteArray> c = l.at(i).split(' '); |
|
540 Q_ASSERT(!c.isEmpty()); |
|
541 |
|
542 for (int j = 0; j < c.size(); ++j) { |
|
543 bool ok; |
|
544 uint uc = c.at(j).toInt(&ok, 16); |
|
545 if (uc < 0x10000) |
|
546 columns[i].append(QChar(uc)); |
|
547 else { |
|
548 // convert to utf16 |
|
549 uc -= 0x10000; |
|
550 ushort high = uc/0x400 + 0xd800; |
|
551 ushort low = uc%0x400 + 0xdc00; |
|
552 columns[i].append(QChar(high)); |
|
553 columns[i].append(QChar(low)); |
|
554 } |
|
555 } |
|
556 } |
|
557 |
|
558 // CONFORMANCE: |
|
559 // 1. The following invariants must be true for all conformant implementations |
|
560 // |
|
561 // NFC |
|
562 // c2 == NFC(c1) == NFC(c2) == NFC(c3) |
|
563 // c4 == NFC(c4) == NFC(c5) |
|
564 |
|
565 QVERIFY(columns[1] == columns[0].normalized(QString::NormalizationForm_C)); |
|
566 QVERIFY(columns[1] == columns[1].normalized(QString::NormalizationForm_C)); |
|
567 QVERIFY(columns[1] == columns[2].normalized(QString::NormalizationForm_C)); |
|
568 QVERIFY(columns[3] == columns[3].normalized(QString::NormalizationForm_C)); |
|
569 QVERIFY(columns[3] == columns[4].normalized(QString::NormalizationForm_C)); |
|
570 |
|
571 // NFD |
|
572 // c3 == NFD(c1) == NFD(c2) == NFD(c3) |
|
573 // c5 == NFD(c4) == NFD(c5) |
|
574 |
|
575 QVERIFY(columns[2] == columns[0].normalized(QString::NormalizationForm_D)); |
|
576 QVERIFY(columns[2] == columns[1].normalized(QString::NormalizationForm_D)); |
|
577 QVERIFY(columns[2] == columns[2].normalized(QString::NormalizationForm_D)); |
|
578 QVERIFY(columns[4] == columns[3].normalized(QString::NormalizationForm_D)); |
|
579 QVERIFY(columns[4] == columns[4].normalized(QString::NormalizationForm_D)); |
|
580 |
|
581 // NFKC |
|
582 // c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5) |
|
583 |
|
584 QVERIFY(columns[3] == columns[0].normalized(QString::NormalizationForm_KC)); |
|
585 QVERIFY(columns[3] == columns[1].normalized(QString::NormalizationForm_KC)); |
|
586 QVERIFY(columns[3] == columns[2].normalized(QString::NormalizationForm_KC)); |
|
587 QVERIFY(columns[3] == columns[3].normalized(QString::NormalizationForm_KC)); |
|
588 QVERIFY(columns[3] == columns[4].normalized(QString::NormalizationForm_KC)); |
|
589 |
|
590 // NFKD |
|
591 // c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5) |
|
592 |
|
593 QVERIFY(columns[4] == columns[0].normalized(QString::NormalizationForm_KD)); |
|
594 QVERIFY(columns[4] == columns[1].normalized(QString::NormalizationForm_KD)); |
|
595 QVERIFY(columns[4] == columns[2].normalized(QString::NormalizationForm_KD)); |
|
596 QVERIFY(columns[4] == columns[3].normalized(QString::NormalizationForm_KD)); |
|
597 QVERIFY(columns[4] == columns[4].normalized(QString::NormalizationForm_KD)); |
|
598 |
|
599 // 2. For every code point X assigned in this version of Unicode that is not specifically |
|
600 // listed in Part 1, the following invariants must be true for all conformant |
|
601 // implementations: |
|
602 // |
|
603 // X == NFC(X) == NFD(X) == NFKC(X) == NFKD(X) |
|
604 |
|
605 // ################# |
|
606 |
|
607 } |
|
608 } |
|
609 |
|
610 void tst_QChar::normalizationCorrections() |
|
611 { |
|
612 QString s; |
|
613 s.append(QChar(0xf951)); |
|
614 |
|
615 QString n = s.normalized(QString::NormalizationForm_D); |
|
616 QString res; |
|
617 res.append(QChar(0x964b)); |
|
618 QCOMPARE(n, res); |
|
619 |
|
620 n = s.normalized(QString::NormalizationForm_D, QChar::Unicode_3_1); |
|
621 res.clear(); |
|
622 res.append(QChar(0x96fb)); |
|
623 QCOMPARE(n, res); |
|
624 |
|
625 s.clear(); |
|
626 s += QChar(QChar::highSurrogate(0x2f868)); |
|
627 s += QChar(QChar::lowSurrogate(0x2f868)); |
|
628 |
|
629 n = s.normalized(QString::NormalizationForm_C); |
|
630 res.clear(); |
|
631 res += QChar(0x36fc); |
|
632 QCOMPARE(n, res); |
|
633 |
|
634 n = s.normalized(QString::NormalizationForm_C, QChar::Unicode_3_1); |
|
635 res.clear(); |
|
636 res += QChar(0xd844); |
|
637 res += QChar(0xdf6a); |
|
638 QCOMPARE(n, res); |
|
639 |
|
640 n = s.normalized(QString::NormalizationForm_C, QChar::Unicode_3_2); |
|
641 QCOMPARE(n, res); |
|
642 } |
|
643 |
|
644 |
|
645 QTEST_APPLESS_MAIN(tst_QChar) |
|
646 #include "tst_qchar.moc" |