author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
child 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
||
45 |
#include <qtextcodec.h> |
|
46 |
#include <qfile.h> |
|
47 |
#include <qtextdocument.h> |
|
48 |
#include <time.h> |
|
49 |
#include <qprocess.h> |
|
50 |
||
51 |
#ifdef Q_OS_SYMBIAN |
|
52 |
#define SRCDIR "" |
|
53 |
#endif |
|
54 |
||
55 |
||
56 |
class tst_QTextCodec : public QObject |
|
57 |
{ |
|
58 |
Q_OBJECT |
|
59 |
||
60 |
private slots: |
|
61 |
void toUnicode_data(); |
|
62 |
void toUnicode(); |
|
63 |
void codecForName_data(); |
|
64 |
void codecForName(); |
|
65 |
void fromUnicode_data(); |
|
66 |
void fromUnicode(); |
|
67 |
void toUnicode_codecForHtml(); |
|
68 |
void toUnicode_incremental(); |
|
69 |
void codecForLocale(); |
|
70 |
||
71 |
void asciiToIscii() const; |
|
72 |
void flagCodepointFFFF() const; |
|
73 |
void flagF7808080() const; |
|
74 |
void flagEFBFBF() const; |
|
75 |
void decode0D() const; |
|
76 |
void codecForIndex() const; |
|
77 |
void aliasForUTF16() const; |
|
78 |
void mibForTSCII() const; |
|
79 |
||
80 |
void utf8Codec_data(); |
|
81 |
void utf8Codec(); |
|
82 |
||
83 |
void utf8bom_data(); |
|
84 |
void utf8bom(); |
|
85 |
||
86 |
void utfHeaders_data(); |
|
87 |
void utfHeaders(); |
|
88 |
||
89 |
void codecForHtml(); |
|
90 |
||
91 |
void codecForUtfText_data(); |
|
92 |
void codecForUtfText(); |
|
93 |
||
94 |
#ifdef Q_OS_UNIX |
|
95 |
void toLocal8Bit(); |
|
96 |
#endif |
|
97 |
}; |
|
98 |
||
99 |
void tst_QTextCodec::toUnicode_data() |
|
100 |
{ |
|
101 |
QTest::addColumn<QString>("fileName"); |
|
102 |
QTest::addColumn<QString>("codecName"); |
|
103 |
||
104 |
QTest::newRow( "korean-eucKR" ) << SRCDIR "korean.txt" << "eucKR"; |
|
105 |
QTest::newRow( "UTF-8" ) << SRCDIR "utf8.txt" << "UTF-8"; |
|
106 |
} |
|
107 |
||
108 |
void tst_QTextCodec::toUnicode() |
|
109 |
{ |
|
110 |
QFETCH( QString, fileName ); |
|
111 |
QFETCH( QString, codecName ); |
|
112 |
||
113 |
QFile file( fileName ); |
|
114 |
||
115 |
if ( file.open( QIODevice::ReadOnly ) ) { |
|
116 |
QByteArray ba = file.readAll(); |
|
117 |
QTextCodec *c = QTextCodec::codecForName( codecName.toLatin1() ); |
|
118 |
QVERIFY(c != 0); |
|
119 |
QString uniString = c->toUnicode( ba ); |
|
120 |
if (codecName == QLatin1String("UTF-8")) { |
|
121 |
QCOMPARE(uniString, QString::fromUtf8(ba)); |
|
122 |
QCOMPARE(ba, uniString.toUtf8()); |
|
123 |
} |
|
124 |
QCOMPARE( ba, c->fromUnicode( uniString ) ); |
|
125 |
||
126 |
if (codecName == QLatin1String("eucKR")) { |
|
127 |
char ch = '\0'; |
|
128 |
QVERIFY(c->toUnicode(&ch, 1).isEmpty()); |
|
129 |
QVERIFY(c->toUnicode(&ch, 1).isNull()); |
|
130 |
} |
|
131 |
} else { |
|
132 |
QFAIL(qPrintable("File could not be opened: " + file.errorString())); |
|
133 |
} |
|
134 |
} |
|
135 |
||
136 |
void tst_QTextCodec::codecForName_data() |
|
137 |
{ |
|
138 |
QTest::addColumn<QString>("hint"); |
|
139 |
QTest::addColumn<QString>("actualCodecName"); |
|
140 |
||
141 |
QTest::newRow("data1") << "iso88591" << "ISO-8859-1"; |
|
142 |
QTest::newRow("data2") << "iso88592" << "ISO-8859-2"; |
|
143 |
QTest::newRow("data3") << " IsO(8)8/5*9-2 " << "ISO-8859-2"; |
|
144 |
QTest::newRow("data4") << " IsO(8)8/5*2-9 " << ""; |
|
145 |
QTest::newRow("data5") << "latin2" << "ISO-8859-2"; |
|
146 |
} |
|
147 |
||
148 |
void tst_QTextCodec::codecForName() |
|
149 |
{ |
|
150 |
QFETCH(QString, hint); |
|
151 |
QFETCH(QString, actualCodecName); |
|
152 |
||
153 |
QTextCodec *codec = QTextCodec::codecForName(hint.toLatin1()); |
|
154 |
if (actualCodecName.isEmpty()) { |
|
155 |
QVERIFY(codec == 0); |
|
156 |
} else { |
|
157 |
QVERIFY(codec != 0); |
|
158 |
QCOMPARE(QString(codec->name()), actualCodecName); |
|
159 |
} |
|
160 |
} |
|
161 |
||
162 |
void tst_QTextCodec::fromUnicode_data() |
|
163 |
{ |
|
164 |
QTest::addColumn<QString>("codecName"); |
|
165 |
QTest::addColumn<bool>("eightBit"); |
|
166 |
||
167 |
QTest::newRow("data1") << "ISO-8859-1" << true; |
|
168 |
QTest::newRow("data2") << "ISO-8859-2" << true; |
|
169 |
QTest::newRow("data3") << "ISO-8859-3" << true; |
|
170 |
QTest::newRow("data4") << "ISO-8859-4" << true; |
|
171 |
QTest::newRow("data5") << "ISO-8859-5" << true; |
|
172 |
QTest::newRow("data6") << "ISO-8859-6" << true; |
|
173 |
QTest::newRow("data7") << "ISO-8859-7" << true; |
|
174 |
QTest::newRow("data8") << "ISO-8859-8" << true; |
|
175 |
QTest::newRow("data9") << "ISO-8859-9" << true; |
|
176 |
QTest::newRow("data10") << "ISO-8859-10" << true; |
|
177 |
QTest::newRow("data13") << "ISO-8859-13" << true; |
|
178 |
QTest::newRow("data14") << "ISO-8859-14" << true; |
|
179 |
QTest::newRow("data15") << "ISO-8859-15" << true; |
|
180 |
QTest::newRow("data16") << "ISO-8859-16" << true; |
|
181 |
||
182 |
QTest::newRow("data18") << "IBM850" << true; |
|
183 |
QTest::newRow("data19") << "IBM874" << true; |
|
184 |
QTest::newRow("data20") << "IBM866" << true; |
|
185 |
||
186 |
QTest::newRow("data21") << "windows-1250" << true; |
|
187 |
QTest::newRow("data22") << "windows-1251" << true; |
|
188 |
QTest::newRow("data23") << "windows-1252" << true; |
|
189 |
QTest::newRow("data24") << "windows-1253" << true; |
|
190 |
QTest::newRow("data25") << "windows-1254" << true; |
|
191 |
QTest::newRow("data26") << "windows-1255" << true; |
|
192 |
QTest::newRow("data27") << "windows-1256" << true; |
|
193 |
QTest::newRow("data28") << "windows-1257" << true; |
|
194 |
QTest::newRow("data28") << "windows-1258" << true; |
|
195 |
||
196 |
QTest::newRow("data29") << "Apple Roman" << true; |
|
197 |
QTest::newRow("data29") << "WINSAMI2" << true; |
|
198 |
QTest::newRow("data30") << "TIS-620" << true; |
|
199 |
QTest::newRow("data31") << "roman8" << true; |
|
200 |
||
201 |
QTest::newRow("data32") << "SJIS" << false; |
|
202 |
QTest::newRow("data33") << "EUC-KR" << false; |
|
203 |
} |
|
204 |
||
205 |
void tst_QTextCodec::fromUnicode() |
|
206 |
{ |
|
207 |
QFETCH(QString, codecName); |
|
208 |
QFETCH(bool, eightBit); |
|
209 |
||
210 |
QTextCodec *codec = QTextCodec::codecForName(codecName.toLatin1()); |
|
211 |
QVERIFY(codec != 0); |
|
212 |
||
213 |
// Check if the reverse lookup is what we expect |
|
214 |
if (eightBit) { |
|
215 |
char chars[128]; |
|
216 |
for (int i = 0; i < 128; ++i) |
|
217 |
chars[i] = i + 128; |
|
218 |
QString s = codec->toUnicode(chars, 128); |
|
219 |
QByteArray c = codec->fromUnicode(s); |
|
220 |
||
221 |
int numberOfQuestionMarks = 0; |
|
222 |
for (int i = 0; i < 128; ++i) { |
|
223 |
if (c.at(i) == '?') |
|
224 |
++numberOfQuestionMarks; |
|
225 |
else |
|
226 |
QCOMPARE(c.at(i), char(i + 128)); |
|
227 |
} |
|
228 |
QVERIFY(numberOfQuestionMarks != 128); |
|
229 |
} |
|
230 |
||
231 |
/* |
|
232 |
If the encoding is a superset of ASCII, test that the byte |
|
233 |
array is correct (no off by one, no trailing '\0'). |
|
234 |
*/ |
|
235 |
QByteArray result = codec->fromUnicode(QString("abc")); |
|
236 |
if (result.startsWith("a")) { |
|
237 |
QCOMPARE(result.size(), 3); |
|
238 |
QCOMPARE(result, QByteArray("abc")); |
|
239 |
} else { |
|
240 |
QVERIFY(true); |
|
241 |
} |
|
242 |
} |
|
243 |
||
244 |
void tst_QTextCodec::toUnicode_codecForHtml() |
|
245 |
{ |
|
246 |
QFile file(QString(SRCDIR "QT4-crashtest.txt")); |
|
247 |
QVERIFY(file.open(QFile::ReadOnly)); |
|
248 |
||
249 |
QByteArray data = file.readAll(); |
|
250 |
QTextCodec *codec = Qt::codecForHtml(data); |
|
251 |
codec->toUnicode(data); // this line crashes |
|
252 |
} |
|
253 |
||
254 |
||
255 |
void tst_QTextCodec::toUnicode_incremental() |
|
256 |
{ |
|
257 |
QByteArray ba; |
|
258 |
ba += char(0xf0); |
|
259 |
ba += char(0x90); |
|
260 |
ba += char(0x80); |
|
261 |
ba += char(0x80); |
|
262 |
ba += char(0xf4); |
|
263 |
ba += char(0x8f); |
|
264 |
ba += char(0xbf); |
|
265 |
ba += char(0xbd); |
|
266 |
||
267 |
QString expected = QString::fromUtf8(ba); |
|
268 |
||
269 |
QString incremental; |
|
270 |
QTextDecoder *utf8Decoder = QTextCodec::codecForMib(106)->makeDecoder(); |
|
271 |
||
272 |
QString actual; |
|
273 |
for (int i = 0; i < ba.size(); ++i) |
|
274 |
utf8Decoder->toUnicode(&actual, ba.constData() + i, 1); |
|
275 |
||
276 |
QCOMPARE(actual, expected); |
|
277 |
||
278 |
||
279 |
delete utf8Decoder; |
|
280 |
} |
|
281 |
||
282 |
void tst_QTextCodec::codecForLocale() |
|
283 |
{ |
|
284 |
QTextCodec *codec = QTextCodec::codecForLocale(); |
|
285 |
QVERIFY(codec != 0); |
|
286 |
||
287 |
#if defined(Q_OS_UNIX) |
|
288 |
// get a time string that is locale-encoded |
|
289 |
QByteArray originalLocaleEncodedTimeString; |
|
290 |
originalLocaleEncodedTimeString.resize(1024); |
|
291 |
time_t t; |
|
292 |
time(&t); |
|
293 |
int r = strftime(originalLocaleEncodedTimeString.data(), |
|
294 |
originalLocaleEncodedTimeString.size(), |
|
295 |
"%A%a%B%b%Z", |
|
296 |
localtime(&t)); |
|
297 |
if (r == 0) |
|
298 |
QSKIP("strftime() failed", SkipAll); |
|
299 |
originalLocaleEncodedTimeString.resize(r); |
|
300 |
||
301 |
QString unicodeTimeString = codec->toUnicode(originalLocaleEncodedTimeString); |
|
302 |
QByteArray localeEncodedTimeString = codec->fromUnicode(unicodeTimeString); |
|
303 |
QCOMPARE(localeEncodedTimeString, originalLocaleEncodedTimeString); |
|
304 |
#else |
|
305 |
QSKIP("This test is not implemented on Windows", SkipAll); |
|
306 |
#endif |
|
307 |
||
308 |
// find a codec that is not the codecForLocale() |
|
309 |
QTextCodec *codec2 = 0; |
|
310 |
foreach (int mib, QTextCodec::availableMibs()) { |
|
311 |
if (mib != codec->mibEnum()) { |
|
312 |
codec2 = QTextCodec::codecForMib(mib); |
|
313 |
if (codec2) |
|
314 |
break; |
|
315 |
} |
|
316 |
} |
|
317 |
if (!codec2) { |
|
318 |
QSKIP("Could not find a codec that is not already the codecForLocale()", SkipAll); |
|
319 |
} |
|
320 |
||
321 |
// set it, codecForLocale() should return it now |
|
322 |
QTextCodec::setCodecForLocale(codec2); |
|
323 |
QCOMPARE(QTextCodec::codecForLocale(), codec2); |
|
324 |
||
325 |
// reset back to the default |
|
326 |
QTextCodec::setCodecForLocale(0); |
|
327 |
QCOMPARE(QTextCodec::codecForLocale(), codec); |
|
328 |
} |
|
329 |
||
330 |
void tst_QTextCodec::asciiToIscii() const |
|
331 |
{ |
|
332 |
/* Add all low, 7-bit ASCII characters. */ |
|
333 |
QString ascii; |
|
334 |
const int len = 0xA0 - 1; |
|
335 |
ascii.resize(len); |
|
336 |
||
337 |
for(int i = 0; i < len; ++i) |
|
338 |
ascii[i] = QChar(i + 1); |
|
339 |
||
340 |
static const char *const isciiCodecs[] = |
|
341 |
{ |
|
342 |
"Iscii-Mlm", |
|
343 |
"Iscii-Knd", |
|
344 |
"Iscii-Tlg", |
|
345 |
"Iscii-Tml", |
|
346 |
"Iscii-Ori", |
|
347 |
"Iscii-Gjr", |
|
348 |
"Iscii-Pnj", |
|
349 |
"Iscii-Bng", |
|
350 |
"Iscii-Dev" |
|
351 |
}; |
|
352 |
const int isciiCodecsLen = sizeof(isciiCodecs) / sizeof(const char *); |
|
353 |
||
354 |
for(int i = 0; i < isciiCodecsLen; ++i) { |
|
355 |
/* For each codec. */ |
|
356 |
||
357 |
const QTextCodec *const textCodec = QTextCodec::codecForName(isciiCodecs[i]); |
|
358 |
Q_ASSERT(textCodec); |
|
359 |
||
360 |
for(int i2 = 0; i2 < len; ++i2) { |
|
361 |
/* For each character in ascii. */ |
|
362 |
const QChar c(ascii[i2]); |
|
363 |
QVERIFY2(textCodec->canEncode(c), qPrintable(QString::fromLatin1("Failed to encode %1 with encoding %2") |
|
364 |
.arg(QString::number(c.unicode()), QString::fromLatin1(textCodec->name().constData())))); |
|
365 |
} |
|
366 |
||
367 |
QVERIFY2(textCodec->canEncode(ascii), qPrintable(QString::fromLatin1("Failed for full string with encoding %1") |
|
368 |
.arg(QString::fromLatin1(textCodec->name().constData())))); |
|
369 |
} |
|
370 |
} |
|
371 |
||
372 |
void tst_QTextCodec::flagCodepointFFFF() const |
|
373 |
{ |
|
374 |
// This is an invalid Unicode codepoint. |
|
375 |
const QChar ch(0xFFFF); |
|
376 |
QString input(ch); |
|
377 |
||
378 |
QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8 |
|
379 |
Q_ASSERT(codec); |
|
380 |
||
381 |
const QByteArray asDecoded(codec->fromUnicode(input)); |
|
382 |
QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull); |
|
383 |
QVERIFY(codec->toUnicode(asDecoded.constData(), asDecoded.length(), &state) == QChar(0)); |
|
384 |
QVERIFY(codec->toUnicode(asDecoded) == QChar(0xfffd)); |
|
385 |
} |
|
386 |
||
387 |
void tst_QTextCodec::flagF7808080() const |
|
388 |
{ |
|
389 |
/* This test case stems from test not-wf-sa-170, tests/qxmlstream/XML-Test-Suite/xmlconf/xmltest/not-wf/sa/166.xml, |
|
390 |
* whose description reads: |
|
391 |
* |
|
392 |
* "Four byte UTF-8 encodings can encode UCS-4 characters |
|
393 |
* which are beyond the range of legal XML characters |
|
394 |
* (and can't be expressed in Unicode surrogate pairs). |
|
395 |
* This document holds such a character." |
|
396 |
* |
|
397 |
* In binary, this is: |
|
398 |
* 11110111100000001000000010000000 |
|
399 |
* * * * * |
|
400 |
* 11110www10xxxxxx10yyyyyy10zzzzzz |
|
401 |
* |
|
402 |
* With multibyte logic removed it is the codepoint 0x1C0000. |
|
403 |
*/ |
|
404 |
QByteArray input; |
|
405 |
input.resize(4); |
|
406 |
input[0] = char(0xF7); |
|
407 |
input[1] = char(0x80); |
|
408 |
input[2] = char(0x80); |
|
409 |
input[3] = char(0x80); |
|
410 |
||
411 |
||
412 |
QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8 |
|
413 |
Q_ASSERT(codec); |
|
414 |
||
415 |
//QVERIFY(!codec->canEncode(QChar(0x1C0000))); |
|
416 |
||
417 |
QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull); |
|
418 |
QVERIFY(codec->toUnicode(input.constData(), input.length(), &state) == QChar(0)); |
|
419 |
} |
|
420 |
||
421 |
void tst_QTextCodec::flagEFBFBF() const |
|
422 |
{ |
|
423 |
QByteArray invalidInput; |
|
424 |
invalidInput.resize(3); |
|
425 |
invalidInput[0] = char(0xEF); |
|
426 |
invalidInput[1] = char(0xBF); |
|
427 |
invalidInput[2] = char(0xBF); |
|
428 |
||
429 |
const QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8 |
|
430 |
Q_ASSERT(codec); |
|
431 |
||
432 |
{ |
|
433 |
//QVERIFY(!codec->canEncode(QChar(0xFFFF))); |
|
434 |
QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull); |
|
435 |
QVERIFY(codec->toUnicode(invalidInput.constData(), invalidInput.length(), &state) == QChar(0)); |
|
436 |
||
437 |
QByteArray start("<?pi "); |
|
438 |
start.append(invalidInput); |
|
439 |
start.append("?>"); |
|
440 |
} |
|
441 |
||
442 |
/* When 0xEFBFBF is preceeded by what seems to be an arbitrary character, |
|
443 |
* QTextCodec fails to flag it. */ |
|
444 |
{ |
|
445 |
QEXPECT_FAIL("", "This is a bug and needs to be fixed.", Continue); |
|
446 |
QByteArray start("B"); |
|
447 |
start.append(invalidInput); |
|
448 |
||
449 |
QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull); |
|
450 |
QVERIFY(codec->toUnicode(start.constData(), start.length(), &state) == QChar(0)); |
|
451 |
} |
|
452 |
} |
|
453 |
||
454 |
void tst_QTextCodec::decode0D() const |
|
455 |
{ |
|
456 |
QByteArray input; |
|
457 |
input.resize(3); |
|
458 |
input[0] = 'A'; |
|
459 |
input[1] = '\r'; |
|
460 |
input[2] = 'B'; |
|
461 |
||
462 |
QCOMPARE(QString::fromUtf8(input.constData()).toUtf8(), input); |
|
463 |
} |
|
464 |
||
465 |
void tst_QTextCodec::codecForIndex() const |
|
466 |
{ |
|
467 |
} |
|
468 |
||
469 |
void tst_QTextCodec::aliasForUTF16() const |
|
470 |
{ |
|
471 |
QVERIFY(QTextCodec::codecForName("UTF-16")->aliases().isEmpty()); |
|
472 |
} |
|
473 |
||
474 |
void tst_QTextCodec::mibForTSCII() const |
|
475 |
{ |
|
476 |
QCOMPARE(QTextCodec::codecForName("TSCII")->mibEnum(), 2107); |
|
477 |
} |
|
478 |
||
479 |
static QString fromInvalidUtf8Sequence(const QByteArray &ba) |
|
480 |
{ |
|
481 |
return QString().fill(QChar::ReplacementCharacter, ba.size()); |
|
482 |
} |
|
483 |
||
484 |
// copied from tst_QString::fromUtf8_data() |
|
485 |
void tst_QTextCodec::utf8Codec_data() |
|
486 |
{ |
|
487 |
QTest::addColumn<QByteArray>("utf8"); |
|
488 |
QTest::addColumn<QString>("res"); |
|
489 |
QTest::addColumn<int>("len"); |
|
490 |
QString str; |
|
491 |
||
492 |
QTest::newRow("str0") << QByteArray("abcdefgh") << QString("abcdefgh") << -1; |
|
493 |
QTest::newRow("str0-len") << QByteArray("abcdefgh") << QString("abc") << 3; |
|
494 |
QTest::newRow("str1") << QByteArray("\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205") << QString("\366\344\374\326\304\334\370\346\345\330\306\305") << -1; |
|
495 |
QTest::newRow("str1-len") << QByteArray("\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205") << QString("\366\344\374\326\304") << 10; |
|
496 |
||
497 |
str += QChar(0x05e9); |
|
498 |
str += QChar(0x05d3); |
|
499 |
str += QChar(0x05d2); |
|
500 |
QTest::newRow("str2") << QByteArray("\327\251\327\223\327\222") << str << -1; |
|
501 |
||
502 |
str = QChar(0x05e9); |
|
503 |
QTest::newRow("str2-len") << QByteArray("\327\251\327\223\327\222") << str << 2; |
|
504 |
||
505 |
str = QChar(0x20ac); |
|
506 |
str += " some text"; |
|
507 |
QTest::newRow("str3") << QByteArray("\342\202\254 some text") << str << -1; |
|
508 |
||
509 |
str = QChar(0x20ac); |
|
510 |
str += " some "; |
|
511 |
QTest::newRow("str3-len") << QByteArray("\342\202\254 some text") << str << 9; |
|
512 |
||
513 |
str = "hello"; |
|
514 |
str += QChar::ReplacementCharacter; |
|
515 |
str += QChar(0x68); |
|
516 |
str += QChar::ReplacementCharacter; |
|
517 |
str += QChar::ReplacementCharacter; |
|
518 |
str += QChar::ReplacementCharacter; |
|
519 |
str += QChar::ReplacementCharacter; |
|
520 |
str += QChar(0x61); |
|
521 |
str += QChar::ReplacementCharacter; |
|
522 |
QTest::newRow("invalid utf8") << QByteArray("hello\344h\344\344\366\344a\304") << str << -1; |
|
523 |
QTest::newRow("invalid utf8-len") << QByteArray("hello\344h\344\344\366\344a\304") << QString("hello") << 5; |
|
524 |
||
525 |
str = "Prohl"; |
|
526 |
str += QChar::ReplacementCharacter; |
|
527 |
str += QChar::ReplacementCharacter; |
|
528 |
str += "e"; |
|
529 |
str += QChar::ReplacementCharacter; |
|
530 |
str += " plugin"; |
|
531 |
str += QChar::ReplacementCharacter; |
|
532 |
str += " Netscape"; |
|
533 |
||
534 |
QTest::newRow("task28417") << QByteArray("Prohl\355\276e\350 plugin\371 Netscape") << str << -1; |
|
535 |
QTest::newRow("task28417-len") << QByteArray("Prohl\355\276e\350 plugin\371 Netscape") << QString("") << 0; |
|
536 |
||
537 |
QTest::newRow("null-1") << QByteArray() << QString() << -1; |
|
538 |
QTest::newRow("null0") << QByteArray() << QString() << 0; |
|
539 |
// QTest::newRow("null5") << QByteArray() << QString() << 5; |
|
540 |
QTest::newRow("empty-1") << QByteArray("\0abcd", 5) << QString() << -1; |
|
541 |
QTest::newRow("empty0") << QByteArray() << QString() << 0; |
|
542 |
QTest::newRow("empty5") << QByteArray("\0abcd", 5) << QString::fromAscii("\0abcd", 5) << 5; |
|
543 |
QTest::newRow("other-1") << QByteArray("ab\0cd", 5) << QString::fromAscii("ab") << -1; |
|
544 |
QTest::newRow("other5") << QByteArray("ab\0cd", 5) << QString::fromAscii("ab\0cd", 5) << 5; |
|
545 |
||
546 |
str = "Old Italic: "; |
|
547 |
str += QChar(0xd800); |
|
548 |
str += QChar(0xdf00); |
|
549 |
str += QChar(0xd800); |
|
550 |
str += QChar(0xdf01); |
|
551 |
str += QChar(0xd800); |
|
552 |
str += QChar(0xdf02); |
|
553 |
str += QChar(0xd800); |
|
554 |
str += QChar(0xdf03); |
|
555 |
str += QChar(0xd800); |
|
556 |
str += QChar(0xdf04); |
|
557 |
QTest::newRow("surrogate") << QByteArray("Old Italic: \360\220\214\200\360\220\214\201\360\220\214\202\360\220\214\203\360\220\214\204") << str << -1; |
|
558 |
||
559 |
QTest::newRow("surrogate-len") << QByteArray("Old Italic: \360\220\214\200\360\220\214\201\360\220\214\202\360\220\214\203\360\220\214\204") << str.left(16) << 20; |
|
560 |
||
561 |
// from http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html |
|
562 |
||
563 |
// 2.1.1 U+00000000 |
|
564 |
QByteArray utf8; |
|
565 |
utf8 += char(0x00); |
|
566 |
str = QChar(QChar::Null); |
|
567 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.1") << utf8 << str << 1; |
|
568 |
||
569 |
// 2.1.2 U+00000080 |
|
570 |
utf8.clear(); |
|
571 |
utf8 += char(0xc2); |
|
572 |
utf8 += char(0x80); |
|
573 |
str = QChar(0x80); |
|
574 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.2") << utf8 << str << -1; |
|
575 |
||
576 |
// 2.1.3 U+00000800 |
|
577 |
utf8.clear(); |
|
578 |
utf8 += char(0xe0); |
|
579 |
utf8 += char(0xa0); |
|
580 |
utf8 += char(0x80); |
|
581 |
str = QChar(0x800); |
|
582 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.3") << utf8 << str << -1; |
|
583 |
||
584 |
// 2.1.4 U+00010000 |
|
585 |
utf8.clear(); |
|
586 |
utf8 += char(0xf0); |
|
587 |
utf8 += char(0x90); |
|
588 |
utf8 += char(0x80); |
|
589 |
utf8 += char(0x80); |
|
590 |
str.clear(); |
|
591 |
str += QChar(0xd800); |
|
592 |
str += QChar(0xdc00); |
|
593 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.4") << utf8 << str << -1; |
|
594 |
||
595 |
// 2.1.5 U+00200000 (not a valid Unicode character) |
|
596 |
utf8.clear(); |
|
597 |
utf8 += char(0xf8); |
|
598 |
utf8 += char(0x88); |
|
599 |
utf8 += char(0x80); |
|
600 |
utf8 += char(0x80); |
|
601 |
utf8 += char(0x80); |
|
602 |
str = fromInvalidUtf8Sequence(utf8); |
|
603 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.5") << utf8 << str << -1; |
|
604 |
||
605 |
// 2.1.6 U+04000000 (not a valid Unicode character) |
|
606 |
utf8.clear(); |
|
607 |
utf8 += char(0xfc); |
|
608 |
utf8 += char(0x84); |
|
609 |
utf8 += char(0x80); |
|
610 |
utf8 += char(0x80); |
|
611 |
utf8 += char(0x80); |
|
612 |
utf8 += char(0x80); |
|
613 |
str = fromInvalidUtf8Sequence(utf8); |
|
614 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.6") << utf8 << str << -1; |
|
615 |
||
616 |
// 2.2.1 U+0000007F |
|
617 |
utf8.clear(); |
|
618 |
utf8 += char(0x7f); |
|
619 |
str = QChar(0x7f); |
|
620 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.1") << utf8 << str << -1; |
|
621 |
||
622 |
// 2.2.2 U+000007FF |
|
623 |
utf8.clear(); |
|
624 |
utf8 += char(0xdf); |
|
625 |
utf8 += char(0xbf); |
|
626 |
str = QChar(0x7ff); |
|
627 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.2") << utf8 << str << -1; |
|
628 |
||
629 |
// 2.2.3 U+000FFFF |
|
630 |
utf8.clear(); |
|
631 |
utf8 += char(0xef); |
|
632 |
utf8 += char(0xbf); |
|
633 |
utf8 += char(0xbf); |
|
634 |
str.clear(); |
|
635 |
str += QChar::ReplacementCharacter; |
|
636 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.3") << utf8 << str << -1; |
|
637 |
||
638 |
// 2.2.4 U+001FFFFF |
|
639 |
utf8.clear(); |
|
640 |
utf8 += char(0xf7); |
|
641 |
utf8 += char(0xbf); |
|
642 |
utf8 += char(0xbf); |
|
643 |
utf8 += char(0xbf); |
|
644 |
str.clear(); |
|
645 |
str += QChar(QChar::ReplacementCharacter); |
|
646 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.4") << utf8 << str << -1; |
|
647 |
||
648 |
// 2.2.5 U+03FFFFFF (not a valid Unicode character) |
|
649 |
utf8.clear(); |
|
650 |
utf8 += char(0xfb); |
|
651 |
utf8 += char(0xbf); |
|
652 |
utf8 += char(0xbf); |
|
653 |
utf8 += char(0xbf); |
|
654 |
utf8 += char(0xbf); |
|
655 |
str = fromInvalidUtf8Sequence(utf8); |
|
656 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.5") << utf8 << str << -1; |
|
657 |
||
658 |
// 2.2.6 U+7FFFFFFF |
|
659 |
utf8.clear(); |
|
660 |
utf8 += char(0xfd); |
|
661 |
utf8 += char(0xbf); |
|
662 |
utf8 += char(0xbf); |
|
663 |
utf8 += char(0xbf); |
|
664 |
utf8 += char(0xbf); |
|
665 |
utf8 += char(0xbf); |
|
666 |
str = fromInvalidUtf8Sequence(utf8); |
|
667 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.6") << utf8 << str << -1; |
|
668 |
||
669 |
// 2.3.1 U+0000D7FF |
|
670 |
utf8.clear(); |
|
671 |
utf8 += char(0xed); |
|
672 |
utf8 += char(0x9f); |
|
673 |
utf8 += char(0xbf); |
|
674 |
str = QChar(0xd7ff); |
|
675 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.1") << utf8 << str << -1; |
|
676 |
||
677 |
// 2.3.2 U+0000E000 |
|
678 |
utf8.clear(); |
|
679 |
utf8 += char(0xee); |
|
680 |
utf8 += char(0x80); |
|
681 |
utf8 += char(0x80); |
|
682 |
str = QChar(0xe000); |
|
683 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.2") << utf8 << str << -1; |
|
684 |
||
685 |
// 2.3.3 U+0000FFFD |
|
686 |
utf8.clear(); |
|
687 |
utf8 += char(0xef); |
|
688 |
utf8 += char(0xbf); |
|
689 |
utf8 += char(0xbd); |
|
690 |
str = QChar(QChar::ReplacementCharacter); |
|
691 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.3") << utf8 << str << -1; |
|
692 |
||
693 |
// 2.3.4 U+0010FFFF |
|
694 |
utf8.clear(); |
|
695 |
utf8 += char(0xf4); |
|
696 |
utf8 += char(0x8f); |
|
697 |
utf8 += char(0xbf); |
|
698 |
utf8 += char(0xbf); |
|
699 |
str.clear(); |
|
700 |
str += QChar(0xdbff); |
|
701 |
str += QChar(0xdfff); |
|
702 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.4") << utf8 << str << -1; |
|
703 |
||
704 |
// 2.3.5 U+00110000 |
|
705 |
utf8.clear(); |
|
706 |
utf8 += char(0xf4); |
|
707 |
utf8 += char(0x90); |
|
708 |
utf8 += char(0x80); |
|
709 |
utf8 += char(0x80); |
|
710 |
str.clear(); |
|
711 |
str += QChar(QChar::ReplacementCharacter); |
|
712 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.5") << utf8 << str << -1; |
|
713 |
||
714 |
// 3.1.1 |
|
715 |
utf8.clear(); |
|
716 |
utf8 += char(0x80); |
|
717 |
str = fromInvalidUtf8Sequence(utf8); |
|
718 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.1") << utf8 << str << -1; |
|
719 |
||
720 |
// 3.1.2 |
|
721 |
utf8.clear(); |
|
722 |
utf8 += char(0xbf); |
|
723 |
str = fromInvalidUtf8Sequence(utf8); |
|
724 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.2") << utf8 << str << -1; |
|
725 |
||
726 |
// 3.1.3 |
|
727 |
utf8.clear(); |
|
728 |
utf8 += char(0x80); |
|
729 |
utf8 += char(0xbf); |
|
730 |
str = fromInvalidUtf8Sequence(utf8); |
|
731 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.3") << utf8 << str << -1; |
|
732 |
||
733 |
// 3.1.4 |
|
734 |
utf8.clear(); |
|
735 |
utf8 += char(0x80); |
|
736 |
utf8 += char(0xbf); |
|
737 |
utf8 += char(0x80); |
|
738 |
str = fromInvalidUtf8Sequence(utf8); |
|
739 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.4") << utf8 << str << -1; |
|
740 |
||
741 |
// 3.1.5 |
|
742 |
utf8.clear(); |
|
743 |
utf8 += char(0x80); |
|
744 |
utf8 += char(0xbf); |
|
745 |
utf8 += char(0x80); |
|
746 |
utf8 += char(0xbf); |
|
747 |
str = fromInvalidUtf8Sequence(utf8); |
|
748 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.5") << utf8 << str << -1; |
|
749 |
||
750 |
// 3.1.6 |
|
751 |
utf8.clear(); |
|
752 |
utf8 += char(0x80); |
|
753 |
utf8 += char(0xbf); |
|
754 |
utf8 += char(0x80); |
|
755 |
utf8 += char(0xbf); |
|
756 |
utf8 += char(0x80); |
|
757 |
str = fromInvalidUtf8Sequence(utf8); |
|
758 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.6") << utf8 << str << -1; |
|
759 |
||
760 |
// 3.1.7 |
|
761 |
utf8.clear(); |
|
762 |
utf8 += char(0x80); |
|
763 |
utf8 += char(0xbf); |
|
764 |
utf8 += char(0x80); |
|
765 |
utf8 += char(0xbf); |
|
766 |
utf8 += char(0x80); |
|
767 |
utf8 += char(0xbf); |
|
768 |
str = fromInvalidUtf8Sequence(utf8); |
|
769 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.7") << utf8 << str << -1; |
|
770 |
||
771 |
// 3.1.8 |
|
772 |
utf8.clear(); |
|
773 |
utf8 += char(0x80); |
|
774 |
utf8 += char(0xbf); |
|
775 |
utf8 += char(0x80); |
|
776 |
utf8 += char(0xbf); |
|
777 |
utf8 += char(0x80); |
|
778 |
utf8 += char(0xbf); |
|
779 |
utf8 += char(0x80); |
|
780 |
str = fromInvalidUtf8Sequence(utf8); |
|
781 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.8") << utf8 << str << -1; |
|
782 |
||
783 |
// 3.1.9 |
|
784 |
utf8.clear(); |
|
785 |
for (uint i = 0x80; i<= 0xbf; ++i) |
|
786 |
utf8 += i; |
|
787 |
str = fromInvalidUtf8Sequence(utf8); |
|
788 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.9") << utf8 << str << -1; |
|
789 |
||
790 |
// 3.2.1 |
|
791 |
utf8.clear(); |
|
792 |
str.clear(); |
|
793 |
for (uint i = 0xc8; i <= 0xdf; ++i) { |
|
794 |
utf8 += i; |
|
795 |
utf8 += char(0x20); |
|
796 |
||
797 |
str += QChar::ReplacementCharacter; |
|
798 |
str += QChar(0x0020); |
|
799 |
} |
|
800 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.2.1") << utf8 << str << -1; |
|
801 |
||
802 |
// 3.2.2 |
|
803 |
utf8.clear(); |
|
804 |
str.clear(); |
|
805 |
for (uint i = 0xe0; i <= 0xef; ++i) { |
|
806 |
utf8 += i; |
|
807 |
utf8 += char(0x20); |
|
808 |
||
809 |
str += QChar::ReplacementCharacter; |
|
810 |
str += QChar(0x0020); |
|
811 |
} |
|
812 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.2.2") << utf8 << str << -1; |
|
813 |
||
814 |
// 3.2.3 |
|
815 |
utf8.clear(); |
|
816 |
str.clear(); |
|
817 |
for (uint i = 0xf0; i <= 0xf7; ++i) { |
|
818 |
utf8 += i; |
|
819 |
utf8 += 0x20; |
|
820 |
||
821 |
str += QChar::ReplacementCharacter; |
|
822 |
str += QChar(0x0020); |
|
823 |
} |
|
824 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.2.3") << utf8 << str << -1; |
|
825 |
||
826 |
// 3.2.4 |
|
827 |
utf8.clear(); |
|
828 |
str.clear(); |
|
829 |
for (uint i = 0xf8; i <= 0xfb; ++i) { |
|
830 |
utf8 += i; |
|
831 |
utf8 += 0x20; |
|
832 |
||
833 |
str += QChar::ReplacementCharacter; |
|
834 |
str += QChar(0x0020); |
|
835 |
} |
|
836 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.2.4") << utf8 << str << -1; |
|
837 |
||
838 |
// 3.2.5 |
|
839 |
utf8.clear(); |
|
840 |
str.clear(); |
|
841 |
for (uint i = 0xfc; i <= 0xfd; ++i) { |
|
842 |
utf8 += i; |
|
843 |
utf8 += 0x20; |
|
844 |
||
845 |
str += QChar::ReplacementCharacter; |
|
846 |
str += QChar(0x0020); |
|
847 |
} |
|
848 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.2.5") << utf8 << str << -1; |
|
849 |
||
850 |
// 3.3.1 |
|
851 |
utf8.clear(); |
|
852 |
utf8 += char(0xc0); |
|
853 |
str = fromInvalidUtf8Sequence(utf8); |
|
854 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.1") << utf8 << str << -1; |
|
855 |
utf8 += char(0x30); |
|
856 |
str += 0x30; |
|
857 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.1-1") << utf8 << str << -1; |
|
858 |
||
859 |
// 3.3.2 |
|
860 |
utf8.clear(); |
|
861 |
utf8 += char(0xe0); |
|
862 |
utf8 += char(0x80); |
|
863 |
str = fromInvalidUtf8Sequence(utf8); |
|
864 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2") << utf8 << str << -1; |
|
865 |
utf8 += char(0x30); |
|
866 |
str += 0x30; |
|
867 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2-1") << utf8 << str << -1; |
|
868 |
||
869 |
utf8.clear(); |
|
870 |
utf8 += char(0xe0); |
|
871 |
str = fromInvalidUtf8Sequence(utf8); |
|
872 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2-2") << utf8 << str << -1; |
|
873 |
utf8 += 0x30; |
|
874 |
str += 0x30; |
|
875 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2-3") << utf8 << str << -1; |
|
876 |
||
877 |
// 3.3.3 |
|
878 |
utf8.clear(); |
|
879 |
utf8 += char(0xf0); |
|
880 |
utf8 += char(0x80); |
|
881 |
utf8 += char(0x80); |
|
882 |
str = fromInvalidUtf8Sequence(utf8); |
|
883 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3") << utf8 << str << -1; |
|
884 |
utf8 += char(0x30); |
|
885 |
str += 0x30; |
|
886 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-1") << utf8 << str << -1; |
|
887 |
||
888 |
utf8.clear(); |
|
889 |
utf8 += char(0xf0); |
|
890 |
str = fromInvalidUtf8Sequence(utf8); |
|
891 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-2") << utf8 << str << -1; |
|
892 |
utf8 += char(0x30); |
|
893 |
str += 0x30; |
|
894 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-3") << utf8 << str << -1; |
|
895 |
||
896 |
utf8.clear(); |
|
897 |
utf8 += char(0xf0); |
|
898 |
utf8 += char(0x80); |
|
899 |
str = fromInvalidUtf8Sequence(utf8); |
|
900 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-4") << utf8 << str << -1; |
|
901 |
utf8 += char(0x30); |
|
902 |
str += 0x30; |
|
903 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-5") << utf8 << str << -1; |
|
904 |
||
905 |
// 3.3.4 |
|
906 |
utf8.clear(); |
|
907 |
utf8 += char(0xf8); |
|
908 |
utf8 += char(0x80); |
|
909 |
utf8 += char(0x80); |
|
910 |
utf8 += char(0x80); |
|
911 |
str = fromInvalidUtf8Sequence(utf8); |
|
912 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4") << utf8 << str << -1; |
|
913 |
utf8 += char(0x30); |
|
914 |
str += 0x30; |
|
915 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-1") << utf8 << str << -1; |
|
916 |
||
917 |
utf8.clear(); |
|
918 |
utf8 += char(0xf8); |
|
919 |
utf8 += char(0x80); |
|
920 |
utf8 += char(0x80); |
|
921 |
str = fromInvalidUtf8Sequence(utf8); |
|
922 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-2") << utf8 << str << -1; |
|
923 |
utf8 += char(0x30); |
|
924 |
str += 0x30; |
|
925 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-3") << utf8 << str << -1; |
|
926 |
||
927 |
utf8.clear(); |
|
928 |
utf8 += char(0xf8); |
|
929 |
utf8 += char(0x80); |
|
930 |
str = fromInvalidUtf8Sequence(utf8); |
|
931 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-4") << utf8 << str << -1; |
|
932 |
utf8 += char(0x30); |
|
933 |
str += 0x30; |
|
934 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-5") << utf8 << str << -1; |
|
935 |
||
936 |
utf8.clear(); |
|
937 |
utf8 += char(0xf8); |
|
938 |
str = fromInvalidUtf8Sequence(utf8); |
|
939 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-6") << utf8 << str << -1; |
|
940 |
utf8 += char(0x30); |
|
941 |
str += 0x30; |
|
942 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-7") << utf8 << str << -1; |
|
943 |
||
944 |
// 3.3.5 |
|
945 |
utf8.clear(); |
|
946 |
utf8 += char(0xfc); |
|
947 |
utf8 += char(0x80); |
|
948 |
utf8 += char(0x80); |
|
949 |
utf8 += char(0x80); |
|
950 |
utf8 += char(0x80); |
|
951 |
str = fromInvalidUtf8Sequence(utf8); |
|
952 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5") << utf8 << str << -1; |
|
953 |
utf8 += char(0x30); |
|
954 |
str += 0x30; |
|
955 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-1") << utf8 << str << -1; |
|
956 |
||
957 |
utf8.clear(); |
|
958 |
utf8 += char(0xfc); |
|
959 |
utf8 += char(0x80); |
|
960 |
utf8 += char(0x80); |
|
961 |
utf8 += char(0x80); |
|
962 |
str = fromInvalidUtf8Sequence(utf8); |
|
963 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-2") << utf8 << str << -1; |
|
964 |
utf8 += char(0x30); |
|
965 |
str += 0x30; |
|
966 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-3") << utf8 << str << -1; |
|
967 |
||
968 |
utf8.clear(); |
|
969 |
utf8 += char(0xfc); |
|
970 |
utf8 += char(0x80); |
|
971 |
utf8 += char(0x80); |
|
972 |
str = fromInvalidUtf8Sequence(utf8); |
|
973 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-4") << utf8 << str << -1; |
|
974 |
utf8 += char(0x30); |
|
975 |
str += 0x30; |
|
976 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-5") << utf8 << str << -1; |
|
977 |
||
978 |
utf8.clear(); |
|
979 |
utf8 += char(0xfc); |
|
980 |
utf8 += char(0x80); |
|
981 |
str = fromInvalidUtf8Sequence(utf8); |
|
982 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-6") << utf8 << str << -1; |
|
983 |
utf8 += char(0x30); |
|
984 |
str += 0x30; |
|
985 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-7") << utf8 << str << -1; |
|
986 |
||
987 |
utf8.clear(); |
|
988 |
utf8 += char(0xfc); |
|
989 |
str = fromInvalidUtf8Sequence(utf8); |
|
990 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-8") << utf8 << str << -1; |
|
991 |
utf8 += char(0x30); |
|
992 |
str += 0x30; |
|
993 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-9") << utf8 << str << -1; |
|
994 |
||
995 |
// 3.3.6 |
|
996 |
utf8.clear(); |
|
997 |
utf8 += char(0xdf); |
|
998 |
str = fromInvalidUtf8Sequence(utf8); |
|
999 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.6") << utf8 << str << -1; |
|
1000 |
utf8 += char(0x30); |
|
1001 |
str += 0x30; |
|
1002 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.6-1") << utf8 << str << -1; |
|
1003 |
||
1004 |
// 3.3.7 |
|
1005 |
utf8.clear(); |
|
1006 |
utf8 += char(0xef); |
|
1007 |
utf8 += char(0xbf); |
|
1008 |
str = fromInvalidUtf8Sequence(utf8); |
|
1009 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.7") << utf8 << str << -1; |
|
1010 |
utf8 += char(0x30); |
|
1011 |
str += 0x30; |
|
1012 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.7-1") << utf8 << str << -1; |
|
1013 |
||
1014 |
utf8.clear(); |
|
1015 |
utf8 += char(0xef); |
|
1016 |
str = fromInvalidUtf8Sequence(utf8); |
|
1017 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.7-2") << utf8 << str << -1; |
|
1018 |
utf8 += char(0x30); |
|
1019 |
str += 0x30; |
|
1020 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.7-3") << utf8 << str << -1; |
|
1021 |
||
1022 |
// 3.3.8 |
|
1023 |
utf8.clear(); |
|
1024 |
utf8 += char(0xf7); |
|
1025 |
utf8 += char(0xbf); |
|
1026 |
utf8 += char(0xbf); |
|
1027 |
str = fromInvalidUtf8Sequence(utf8); |
|
1028 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8") << utf8 << str << -1; |
|
1029 |
utf8 += char(0x30); |
|
1030 |
str += 0x30; |
|
1031 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-1") << utf8 << str << -1; |
|
1032 |
||
1033 |
utf8.clear(); |
|
1034 |
utf8 += char(0xf7); |
|
1035 |
utf8 += char(0xbf); |
|
1036 |
str = fromInvalidUtf8Sequence(utf8); |
|
1037 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-2") << utf8 << str << -1; |
|
1038 |
utf8 += char(0x30); |
|
1039 |
str += 0x30; |
|
1040 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-3") << utf8 << str << -1; |
|
1041 |
||
1042 |
utf8.clear(); |
|
1043 |
utf8 += char(0xf7); |
|
1044 |
str = fromInvalidUtf8Sequence(utf8); |
|
1045 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-4") << utf8 << str << -1; |
|
1046 |
utf8 += char(0x30); |
|
1047 |
str += 0x30; |
|
1048 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-5") << utf8 << str << -1; |
|
1049 |
||
1050 |
// 3.3.9 |
|
1051 |
utf8.clear(); |
|
1052 |
utf8 += char(0xfb); |
|
1053 |
utf8 += char(0xbf); |
|
1054 |
utf8 += char(0xbf); |
|
1055 |
utf8 += char(0xbf); |
|
1056 |
str = fromInvalidUtf8Sequence(utf8); |
|
1057 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9") << utf8 << str << -1; |
|
1058 |
utf8 += char(0x30); |
|
1059 |
str += 0x30; |
|
1060 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-1") << utf8 << str << -1; |
|
1061 |
||
1062 |
utf8.clear(); |
|
1063 |
utf8 += char(0xfb); |
|
1064 |
utf8 += char(0xbf); |
|
1065 |
utf8 += char(0xbf); |
|
1066 |
str = fromInvalidUtf8Sequence(utf8); |
|
1067 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-2") << utf8 << str << -1; |
|
1068 |
utf8 += char(0x30); |
|
1069 |
str += 0x30; |
|
1070 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-3") << utf8 << str << -1; |
|
1071 |
||
1072 |
utf8.clear(); |
|
1073 |
utf8 += char(0xfb); |
|
1074 |
utf8 += char(0xbf); |
|
1075 |
str = fromInvalidUtf8Sequence(utf8); |
|
1076 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-4") << utf8 << str << -1; |
|
1077 |
utf8 += char(0x30); |
|
1078 |
str += 0x30; |
|
1079 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-5") << utf8 << str << -1; |
|
1080 |
||
1081 |
utf8.clear(); |
|
1082 |
utf8 += char(0xfb); |
|
1083 |
str = fromInvalidUtf8Sequence(utf8); |
|
1084 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-6") << utf8 << str << -1; |
|
1085 |
utf8 += char(0x30); |
|
1086 |
str += 0x30; |
|
1087 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-7") << utf8 << str << -1; |
|
1088 |
||
1089 |
// 3.3.10 |
|
1090 |
utf8.clear(); |
|
1091 |
utf8 += char(0xfd); |
|
1092 |
utf8 += char(0xbf); |
|
1093 |
utf8 += char(0xbf); |
|
1094 |
utf8 += char(0xbf); |
|
1095 |
utf8 += char(0xbf); |
|
1096 |
str = fromInvalidUtf8Sequence(utf8); |
|
1097 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10") << utf8 << str << -1; |
|
1098 |
utf8 += char(0x30); |
|
1099 |
str += 0x30; |
|
1100 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-1") << utf8 << str << -1; |
|
1101 |
||
1102 |
utf8.clear(); |
|
1103 |
utf8 += char(0xfd); |
|
1104 |
utf8 += char(0xbf); |
|
1105 |
utf8 += char(0xbf); |
|
1106 |
utf8 += char(0xbf); |
|
1107 |
str = fromInvalidUtf8Sequence(utf8); |
|
1108 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-2") << utf8 << str << -1; |
|
1109 |
utf8 += char(0x30); |
|
1110 |
str += 0x30; |
|
1111 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-3") << utf8 << str << -1; |
|
1112 |
||
1113 |
utf8.clear(); |
|
1114 |
utf8 += char(0xfd); |
|
1115 |
utf8 += char(0xbf); |
|
1116 |
utf8 += char(0xbf); |
|
1117 |
str = fromInvalidUtf8Sequence(utf8); |
|
1118 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-4") << utf8 << str << -1; |
|
1119 |
utf8 += char(0x30); |
|
1120 |
str += 0x30; |
|
1121 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-5") << utf8 << str << -1; |
|
1122 |
||
1123 |
utf8.clear(); |
|
1124 |
utf8 += char(0xfd); |
|
1125 |
utf8 += char(0xbf); |
|
1126 |
str = fromInvalidUtf8Sequence(utf8); |
|
1127 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-6") << utf8 << str << -1; |
|
1128 |
utf8 += char(0x30); |
|
1129 |
str += 0x30; |
|
1130 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-7") << utf8 << str << -1; |
|
1131 |
||
1132 |
utf8.clear(); |
|
1133 |
utf8 += char(0xfd); |
|
1134 |
str = fromInvalidUtf8Sequence(utf8); |
|
1135 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-8") << utf8 << str << -1; |
|
1136 |
utf8 += char(0x30); |
|
1137 |
str += 0x30; |
|
1138 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-9") << utf8 << str << -1; |
|
1139 |
||
1140 |
// 3.4 |
|
1141 |
utf8.clear(); |
|
1142 |
utf8 += char(0xc0); |
|
1143 |
utf8 += char(0xe0); |
|
1144 |
utf8 += char(0x80); |
|
1145 |
utf8 += char(0xf0); |
|
1146 |
utf8 += char(0x80); |
|
1147 |
utf8 += char(0x80); |
|
1148 |
utf8 += char(0xf8); |
|
1149 |
utf8 += char(0x80); |
|
1150 |
utf8 += char(0x80); |
|
1151 |
utf8 += char(0x80); |
|
1152 |
utf8 += char(0xfc); |
|
1153 |
utf8 += char(0x80); |
|
1154 |
utf8 += char(0x80); |
|
1155 |
utf8 += char(0x80); |
|
1156 |
utf8 += char(0x80); |
|
1157 |
utf8 += char(0xdf); |
|
1158 |
utf8 += char(0xef); |
|
1159 |
utf8 += char(0xbf); |
|
1160 |
utf8 += char(0xf7); |
|
1161 |
utf8 += char(0xbf); |
|
1162 |
utf8 += char(0xbf); |
|
1163 |
utf8 += char(0xfb); |
|
1164 |
utf8 += char(0xbf); |
|
1165 |
utf8 += char(0xbf); |
|
1166 |
utf8 += char(0xbf); |
|
1167 |
utf8 += char(0xfd); |
|
1168 |
utf8 += char(0xbf); |
|
1169 |
utf8 += char(0xbf); |
|
1170 |
utf8 += char(0xbf); |
|
1171 |
utf8 += char(0xbf); |
|
1172 |
str = fromInvalidUtf8Sequence(utf8); |
|
1173 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.4") << utf8 << str << -1; |
|
1174 |
||
1175 |
// 3.5.1 |
|
1176 |
utf8.clear(); |
|
1177 |
utf8 += char(0xfe); |
|
1178 |
str = fromInvalidUtf8Sequence(utf8); |
|
1179 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.5.1") << utf8 << str << -1; |
|
1180 |
||
1181 |
// 3.5.2 |
|
1182 |
utf8.clear(); |
|
1183 |
utf8 += char(0xff); |
|
1184 |
str = fromInvalidUtf8Sequence(utf8); |
|
1185 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.5.1") << utf8 << str << -1; |
|
1186 |
||
1187 |
// 3.5.2 |
|
1188 |
utf8.clear(); |
|
1189 |
utf8 += char(0xfe); |
|
1190 |
utf8 += char(0xfe); |
|
1191 |
utf8 += char(0xff); |
|
1192 |
str = fromInvalidUtf8Sequence(utf8); |
|
1193 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.5.1") << utf8 << str << -1; |
|
1194 |
||
1195 |
// 4.1.1 |
|
1196 |
utf8.clear(); |
|
1197 |
utf8 += char(0xc0); |
|
1198 |
utf8 += char(0xaf); |
|
1199 |
str = QChar(QChar::ReplacementCharacter); |
|
1200 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.1.1") << utf8 << str << -1; |
|
1201 |
||
1202 |
// 4.1.2 |
|
1203 |
utf8.clear(); |
|
1204 |
utf8 += char(0xe0); |
|
1205 |
utf8 += char(0x80); |
|
1206 |
utf8 += char(0xaf); |
|
1207 |
str = QChar(QChar::ReplacementCharacter); |
|
1208 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.1.2") << utf8 << str << -1; |
|
1209 |
||
1210 |
// 4.1.3 |
|
1211 |
utf8.clear(); |
|
1212 |
utf8 += char(0xf0); |
|
1213 |
utf8 += char(0x80); |
|
1214 |
utf8 += char(0x80); |
|
1215 |
utf8 += char(0xaf); |
|
1216 |
str = QChar(QChar::ReplacementCharacter); |
|
1217 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.1.3") << utf8 << str << -1; |
|
1218 |
||
1219 |
// 4.1.4 |
|
1220 |
utf8.clear(); |
|
1221 |
utf8 += char(0xf8); |
|
1222 |
utf8 += char(0x80); |
|
1223 |
utf8 += char(0x80); |
|
1224 |
utf8 += char(0x80); |
|
1225 |
utf8 += char(0xaf); |
|
1226 |
str = fromInvalidUtf8Sequence(utf8); |
|
1227 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.1.4") << utf8 << str << -1; |
|
1228 |
||
1229 |
// 4.1.5 |
|
1230 |
utf8.clear(); |
|
1231 |
utf8 += char(0xfc); |
|
1232 |
utf8 += char(0x80); |
|
1233 |
utf8 += char(0x80); |
|
1234 |
utf8 += char(0x80); |
|
1235 |
utf8 += char(0x80); |
|
1236 |
utf8 += char(0xaf); |
|
1237 |
str = fromInvalidUtf8Sequence(utf8); |
|
1238 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.1.5") << utf8 << str << -1; |
|
1239 |
||
1240 |
// 4.2.1 |
|
1241 |
utf8.clear(); |
|
1242 |
utf8 += char(0xc1); |
|
1243 |
utf8 += char(0xbf); |
|
1244 |
str = QChar(QChar::ReplacementCharacter); |
|
1245 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.2.1") << utf8 << str << -1; |
|
1246 |
||
1247 |
// 4.2.2 |
|
1248 |
utf8.clear(); |
|
1249 |
utf8 += char(0xe0); |
|
1250 |
utf8 += char(0x9f); |
|
1251 |
utf8 += char(0xbf); |
|
1252 |
str = QChar(QChar::ReplacementCharacter); |
|
1253 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.2.2") << utf8 << str << -1; |
|
1254 |
||
1255 |
// 4.2.3 |
|
1256 |
utf8.clear(); |
|
1257 |
utf8 += char(0xf0); |
|
1258 |
utf8 += char(0x8f); |
|
1259 |
utf8 += char(0xbf); |
|
1260 |
utf8 += char(0xbf); |
|
1261 |
str = QChar(QChar::ReplacementCharacter); |
|
1262 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.2.3") << utf8 << str << -1; |
|
1263 |
||
1264 |
// 4.2.4 |
|
1265 |
utf8.clear(); |
|
1266 |
utf8 += char(0xf8); |
|
1267 |
utf8 += char(0x87); |
|
1268 |
utf8 += char(0xbf); |
|
1269 |
utf8 += char(0xbf); |
|
1270 |
utf8 += char(0xbf); |
|
1271 |
str = fromInvalidUtf8Sequence(utf8); |
|
1272 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.2.4") << utf8 << str << -1; |
|
1273 |
||
1274 |
// 4.2.5 |
|
1275 |
utf8.clear(); |
|
1276 |
utf8 += char(0xfc); |
|
1277 |
utf8 += char(0x83); |
|
1278 |
utf8 += char(0xbf); |
|
1279 |
utf8 += char(0xbf); |
|
1280 |
utf8 += char(0xbf); |
|
1281 |
utf8 += char(0xbf); |
|
1282 |
str = fromInvalidUtf8Sequence(utf8); |
|
1283 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.2.5") << utf8 << str << -1; |
|
1284 |
||
1285 |
// 4.3.1 |
|
1286 |
utf8.clear(); |
|
1287 |
utf8 += char(0xc0); |
|
1288 |
utf8 += char(0x80); |
|
1289 |
str = QChar(QChar::ReplacementCharacter); |
|
1290 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.3.1") << utf8 << str << -1; |
|
1291 |
||
1292 |
// 4.3.2 |
|
1293 |
utf8.clear(); |
|
1294 |
utf8 += char(0xe0); |
|
1295 |
utf8 += char(0x80); |
|
1296 |
utf8 += char(0x80); |
|
1297 |
str = QChar(QChar::ReplacementCharacter); |
|
1298 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.3.2") << utf8 << str << -1; |
|
1299 |
||
1300 |
// 4.3.3 |
|
1301 |
utf8.clear(); |
|
1302 |
utf8 += char(0xf0); |
|
1303 |
utf8 += char(0x80); |
|
1304 |
utf8 += char(0x80); |
|
1305 |
utf8 += char(0x80); |
|
1306 |
str = QChar(QChar::ReplacementCharacter); |
|
1307 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.3.3") << utf8 << str << -1; |
|
1308 |
||
1309 |
// 4.3.4 |
|
1310 |
utf8.clear(); |
|
1311 |
utf8 += char(0xf8); |
|
1312 |
utf8 += char(0x80); |
|
1313 |
utf8 += char(0x80); |
|
1314 |
utf8 += char(0x80); |
|
1315 |
utf8 += char(0x80); |
|
1316 |
str = fromInvalidUtf8Sequence(utf8); |
|
1317 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.3.4") << utf8 << str << -1; |
|
1318 |
||
1319 |
// 4.3.5 |
|
1320 |
utf8.clear(); |
|
1321 |
utf8 += char(0xfc); |
|
1322 |
utf8 += char(0x80); |
|
1323 |
utf8 += char(0x80); |
|
1324 |
utf8 += char(0x80); |
|
1325 |
utf8 += char(0x80); |
|
1326 |
utf8 += char(0x80); |
|
1327 |
str = fromInvalidUtf8Sequence(utf8); |
|
1328 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.3.5") << utf8 << str << -1; |
|
1329 |
||
1330 |
// 5.1.1 |
|
1331 |
utf8.clear(); |
|
1332 |
utf8 += char(0xed); |
|
1333 |
utf8 += char(0xa0); |
|
1334 |
utf8 += char(0x80); |
|
1335 |
str = QChar(QChar::ReplacementCharacter); |
|
1336 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.1") << utf8 << str << -1; |
|
1337 |
||
1338 |
// 5.1.2 |
|
1339 |
utf8.clear(); |
|
1340 |
utf8 += char(0xed); |
|
1341 |
utf8 += char(0xad); |
|
1342 |
utf8 += char(0xbf); |
|
1343 |
str = QChar(QChar::ReplacementCharacter); |
|
1344 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.2") << utf8 << str << -1; |
|
1345 |
||
1346 |
// 5.1.3 |
|
1347 |
utf8.clear(); |
|
1348 |
utf8 += char(0xed); |
|
1349 |
utf8 += char(0xae); |
|
1350 |
utf8 += char(0x80); |
|
1351 |
str = QChar(QChar::ReplacementCharacter); |
|
1352 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.3") << utf8 << str << -1; |
|
1353 |
||
1354 |
// 5.1.4 |
|
1355 |
utf8.clear(); |
|
1356 |
utf8 += char(0xed); |
|
1357 |
utf8 += char(0xaf); |
|
1358 |
utf8 += char(0xbf); |
|
1359 |
str = QChar(QChar::ReplacementCharacter); |
|
1360 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.4") << utf8 << str << -1; |
|
1361 |
||
1362 |
// 5.1.5 |
|
1363 |
utf8.clear(); |
|
1364 |
utf8 += char(0xed); |
|
1365 |
utf8 += char(0xb0); |
|
1366 |
utf8 += char(0x80); |
|
1367 |
str = QChar(QChar::ReplacementCharacter); |
|
1368 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.5") << utf8 << str << -1; |
|
1369 |
||
1370 |
// 5.1.6 |
|
1371 |
utf8.clear(); |
|
1372 |
utf8 += char(0xed); |
|
1373 |
utf8 += char(0xbe); |
|
1374 |
utf8 += char(0x80); |
|
1375 |
str = QChar(QChar::ReplacementCharacter); |
|
1376 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.6") << utf8 << str << -1; |
|
1377 |
||
1378 |
// 5.1.7 |
|
1379 |
utf8.clear(); |
|
1380 |
utf8 += char(0xed); |
|
1381 |
utf8 += char(0xbf); |
|
1382 |
utf8 += char(0xbf); |
|
1383 |
str = QChar(QChar::ReplacementCharacter); |
|
1384 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.7") << utf8 << str << -1; |
|
1385 |
||
1386 |
// 5.2.1 |
|
1387 |
utf8.clear(); |
|
1388 |
utf8 += char(0xed); |
|
1389 |
utf8 += char(0xa0); |
|
1390 |
utf8 += char(0x80); |
|
1391 |
utf8 += char(0xed); |
|
1392 |
utf8 += char(0xb0); |
|
1393 |
utf8 += char(0x80); |
|
1394 |
str.clear(); |
|
1395 |
str += QChar(QChar::ReplacementCharacter); |
|
1396 |
str += QChar(QChar::ReplacementCharacter); |
|
1397 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.1") << utf8 << str << -1; |
|
1398 |
||
1399 |
// 5.2.2 |
|
1400 |
utf8.clear(); |
|
1401 |
utf8 += char(0xed); |
|
1402 |
utf8 += char(0xa0); |
|
1403 |
utf8 += char(0x80); |
|
1404 |
utf8 += char(0xed); |
|
1405 |
utf8 += char(0xbf); |
|
1406 |
utf8 += char(0xbf); |
|
1407 |
str.clear(); |
|
1408 |
str += QChar(QChar::ReplacementCharacter); |
|
1409 |
str += QChar(QChar::ReplacementCharacter); |
|
1410 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.2") << utf8 << str << -1; |
|
1411 |
||
1412 |
// 5.2.3 |
|
1413 |
utf8.clear(); |
|
1414 |
utf8 += char(0xed); |
|
1415 |
utf8 += char(0xad); |
|
1416 |
utf8 += char(0xbf); |
|
1417 |
utf8 += char(0xed); |
|
1418 |
utf8 += char(0xb0); |
|
1419 |
utf8 += char(0x80); |
|
1420 |
str.clear(); |
|
1421 |
str += QChar(QChar::ReplacementCharacter); |
|
1422 |
str += QChar(QChar::ReplacementCharacter); |
|
1423 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.3") << utf8 << str << -1; |
|
1424 |
||
1425 |
// 5.2.4 |
|
1426 |
utf8.clear(); |
|
1427 |
utf8 += char(0xed); |
|
1428 |
utf8 += char(0xad); |
|
1429 |
utf8 += char(0xbf); |
|
1430 |
utf8 += char(0xed); |
|
1431 |
utf8 += char(0xbf); |
|
1432 |
utf8 += char(0xbf); |
|
1433 |
str.clear(); |
|
1434 |
str += QChar(QChar::ReplacementCharacter); |
|
1435 |
str += QChar(QChar::ReplacementCharacter); |
|
1436 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.4") << utf8 << str << -1; |
|
1437 |
||
1438 |
// 5.2.5 |
|
1439 |
utf8.clear(); |
|
1440 |
utf8 += char(0xed); |
|
1441 |
utf8 += char(0xae); |
|
1442 |
utf8 += char(0x80); |
|
1443 |
utf8 += char(0xed); |
|
1444 |
utf8 += char(0xb0); |
|
1445 |
utf8 += char(0x80); |
|
1446 |
str.clear(); |
|
1447 |
str += QChar(QChar::ReplacementCharacter); |
|
1448 |
str += QChar(QChar::ReplacementCharacter); |
|
1449 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.5") << utf8 << str << -1; |
|
1450 |
||
1451 |
// 5.2.6 |
|
1452 |
utf8.clear(); |
|
1453 |
utf8 += char(0xed); |
|
1454 |
utf8 += char(0xae); |
|
1455 |
utf8 += char(0x80); |
|
1456 |
utf8 += char(0xed); |
|
1457 |
utf8 += char(0xbf); |
|
1458 |
utf8 += char(0xbf); |
|
1459 |
str.clear(); |
|
1460 |
str += QChar(QChar::ReplacementCharacter); |
|
1461 |
str += QChar(QChar::ReplacementCharacter); |
|
1462 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.6") << utf8 << str << -1; |
|
1463 |
||
1464 |
// 5.2.7 |
|
1465 |
utf8.clear(); |
|
1466 |
utf8 += char(0xed); |
|
1467 |
utf8 += char(0xaf); |
|
1468 |
utf8 += char(0xbf); |
|
1469 |
utf8 += char(0xed); |
|
1470 |
utf8 += char(0xb0); |
|
1471 |
utf8 += char(0x80); |
|
1472 |
str.clear(); |
|
1473 |
str += QChar(QChar::ReplacementCharacter); |
|
1474 |
str += QChar(QChar::ReplacementCharacter); |
|
1475 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.7") << utf8 << str << -1; |
|
1476 |
||
1477 |
// 5.2.8 |
|
1478 |
utf8.clear(); |
|
1479 |
utf8 += char(0xed); |
|
1480 |
utf8 += char(0xaf); |
|
1481 |
utf8 += char(0xbf); |
|
1482 |
utf8 += char(0xed); |
|
1483 |
utf8 += char(0xbf); |
|
1484 |
utf8 += char(0xbf); |
|
1485 |
str.clear(); |
|
1486 |
str += QChar(QChar::ReplacementCharacter); |
|
1487 |
str += QChar(QChar::ReplacementCharacter); |
|
1488 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.8") << utf8 << str << -1; |
|
1489 |
||
1490 |
// 5.3.1 |
|
1491 |
utf8.clear(); |
|
1492 |
utf8 += char(0xef); |
|
1493 |
utf8 += char(0xbf); |
|
1494 |
utf8 += char(0xbe); |
|
1495 |
str = QChar(QChar::ReplacementCharacter); |
|
1496 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.3.1") << utf8 << str << -1; |
|
1497 |
||
1498 |
// 5.3.2 |
|
1499 |
utf8.clear(); |
|
1500 |
utf8 += char(0xef); |
|
1501 |
utf8 += char(0xbf); |
|
1502 |
utf8 += char(0xbf); |
|
1503 |
str = QChar(QChar::ReplacementCharacter); |
|
1504 |
QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.3.2") << utf8 << str << -1; |
|
1505 |
} |
|
1506 |
||
1507 |
void tst_QTextCodec::utf8Codec() |
|
1508 |
{ |
|
1509 |
QTextCodec *codec = QTextCodec::codecForMib(106); // UTF-8 |
|
1510 |
QVERIFY(codec != 0); |
|
1511 |
||
1512 |
QFETCH(QByteArray, utf8); |
|
1513 |
QFETCH(QString, res); |
|
1514 |
QFETCH(int, len); |
|
1515 |
||
1516 |
QString str = codec->toUnicode(utf8.isNull() ? 0 : utf8.constData(), |
|
1517 |
len < 0 ? qstrlen(utf8.constData()) : len); |
|
1518 |
QCOMPARE(str, res); |
|
1519 |
||
1520 |
str = QString::fromUtf8(utf8.isNull() ? 0 : utf8.constData(), len); |
|
1521 |
QCOMPARE(str, res); |
|
1522 |
} |
|
1523 |
||
1524 |
void tst_QTextCodec::utf8bom_data() |
|
1525 |
{ |
|
1526 |
QTest::addColumn<QByteArray>("data"); |
|
1527 |
QTest::addColumn<QString>("result"); |
|
1528 |
||
1529 |
QTest::newRow("nobom") |
|
1530 |
<< QByteArray("\302\240", 2) |
|
1531 |
<< QString("\240"); |
|
1532 |
||
1533 |
{ |
|
1534 |
static const ushort data[] = { 0x201d }; |
|
1535 |
QTest::newRow("nobom 2") |
|
1536 |
<< QByteArray("\342\200\235", 3) |
|
1537 |
<< QString::fromUtf16(data, sizeof(data)/sizeof(short)); |
|
1538 |
} |
|
1539 |
||
1540 |
{ |
|
1541 |
static const ushort data[] = { 0xf000 }; |
|
1542 |
QTest::newRow("bom1") |
|
1543 |
<< QByteArray("\357\200\200", 3) |
|
1544 |
<< QString::fromUtf16(data, sizeof(data)/sizeof(short)); |
|
1545 |
} |
|
1546 |
||
1547 |
{ |
|
1548 |
static const ushort data[] = { 0xfec0 }; |
|
1549 |
QTest::newRow("bom2") |
|
1550 |
<< QByteArray("\357\273\200", 3) |
|
1551 |
<< QString::fromUtf16(data, sizeof(data)/sizeof(short)); |
|
1552 |
} |
|
1553 |
||
1554 |
{ |
|
1555 |
QTest::newRow("normal-bom") |
|
1556 |
<< QByteArray("\357\273\277a", 4) |
|
1557 |
<< QString("a"); |
|
1558 |
} |
|
1559 |
||
1560 |
{ |
|
1561 |
static const ushort data[] = { 0x61, 0xfeff, 0x62 }; |
|
1562 |
QTest::newRow("middle-bom") |
|
1563 |
<< QByteArray("a\357\273\277b", 5) |
|
1564 |
<< QString::fromUtf16(data, sizeof(data)/sizeof(short)); |
|
1565 |
} |
|
1566 |
} |
|
1567 |
||
1568 |
void tst_QTextCodec::utf8bom() |
|
1569 |
{ |
|
1570 |
QFETCH(QByteArray, data); |
|
1571 |
QFETCH(QString, result); |
|
1572 |
||
1573 |
QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8 |
|
1574 |
Q_ASSERT(codec); |
|
1575 |
||
1576 |
QCOMPARE(codec->toUnicode(data.constData(), data.length(), 0), result); |
|
1577 |
||
1578 |
QTextCodec::ConverterState state; |
|
1579 |
QCOMPARE(codec->toUnicode(data.constData(), data.length(), &state), result); |
|
1580 |
} |
|
1581 |
||
1582 |
void tst_QTextCodec::utfHeaders_data() |
|
1583 |
{ |
|
1584 |
QTest::addColumn<QByteArray>("codecName"); |
|
1585 |
QTest::addColumn<int>("flags"); |
|
1586 |
QTest::addColumn<QByteArray>("encoded"); |
|
1587 |
QTest::addColumn<QString>("unicode"); |
|
1588 |
QTest::addColumn<bool>("toUnicode"); |
|
1589 |
||
1590 |
QTest::newRow("utf8 bom") |
|
1591 |
<< QByteArray("UTF-8") |
|
1592 |
<< 0 |
|
1593 |
<< QByteArray("\xef\xbb\xbfhello") |
|
1594 |
<< QString::fromLatin1("hello") |
|
1595 |
<< true; |
|
1596 |
QTest::newRow("utf8 nobom") |
|
1597 |
<< QByteArray("UTF-8") |
|
1598 |
<< 0 |
|
1599 |
<< QByteArray("hello") |
|
1600 |
<< QString::fromLatin1("hello") |
|
1601 |
<< true; |
|
1602 |
QTest::newRow("utf8 bom ignore header") |
|
1603 |
<< QByteArray("UTF-8") |
|
1604 |
<< (int)QTextCodec::IgnoreHeader |
|
1605 |
<< QByteArray("\xef\xbb\xbfhello") |
|
1606 |
<< (QString(QChar(0xfeff)) + QString::fromLatin1("hello")) |
|
1607 |
<< true; |
|
1608 |
QTest::newRow("utf8 nobom ignore header") |
|
1609 |
<< QByteArray("UTF-8") |
|
1610 |
<< (int)QTextCodec::IgnoreHeader |
|
1611 |
<< QByteArray("hello") |
|
1612 |
<< QString::fromLatin1("hello") |
|
1613 |
<< true; |
|
1614 |
||
1615 |
QTest::newRow("utf16 bom be") |
|
1616 |
<< QByteArray("UTF-16") |
|
1617 |
<< 0 |
|
1618 |
<< QByteArray("\xfe\xff\0h\0e\0l", 8) |
|
1619 |
<< QString::fromLatin1("hel") |
|
1620 |
<< true; |
|
1621 |
QTest::newRow("utf16 bom le") |
|
1622 |
<< QByteArray("UTF-16") |
|
1623 |
<< 0 |
|
1624 |
<< QByteArray("\xff\xfeh\0e\0l\0", 8) |
|
1625 |
<< QString::fromLatin1("hel") |
|
1626 |
<< true; |
|
1627 |
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { |
|
1628 |
QTest::newRow("utf16 nobom") |
|
1629 |
<< QByteArray("UTF-16") |
|
1630 |
<< 0 |
|
1631 |
<< QByteArray("\0h\0e\0l", 6) |
|
1632 |
<< QString::fromLatin1("hel") |
|
1633 |
<< true; |
|
1634 |
QTest::newRow("utf16 bom be ignore header") |
|
1635 |
<< QByteArray("UTF-16") |
|
1636 |
<< (int)QTextCodec::IgnoreHeader |
|
1637 |
<< QByteArray("\xfe\xff\0h\0e\0l", 8) |
|
1638 |
<< (QString(QChar(0xfeff)) + QString::fromLatin1("hel")) |
|
1639 |
<< true; |
|
1640 |
} else { |
|
1641 |
QTest::newRow("utf16 nobom") |
|
1642 |
<< QByteArray("UTF-16") |
|
1643 |
<< 0 |
|
1644 |
<< QByteArray("h\0e\0l\0", 6) |
|
1645 |
<< QString::fromLatin1("hel") |
|
1646 |
<< true; |
|
1647 |
QTest::newRow("utf16 bom le ignore header") |
|
1648 |
<< QByteArray("UTF-16") |
|
1649 |
<< (int)QTextCodec::IgnoreHeader |
|
1650 |
<< QByteArray("\xff\xfeh\0e\0l\0", 8) |
|
1651 |
<< (QString(QChar(0xfeff)) + QString::fromLatin1("hel")) |
|
1652 |
<< true; |
|
1653 |
} |
|
1654 |
||
1655 |
QTest::newRow("utf16-be bom be") |
|
1656 |
<< QByteArray("UTF-16BE") |
|
1657 |
<< 0 |
|
1658 |
<< QByteArray("\xfe\xff\0h\0e\0l", 8) |
|
1659 |
<< QString::fromLatin1("hel") |
|
1660 |
<< true; |
|
1661 |
QTest::newRow("utf16-be nobom") |
|
1662 |
<< QByteArray("UTF-16BE") |
|
1663 |
<< 0 |
|
1664 |
<< QByteArray("\0h\0e\0l", 6) |
|
1665 |
<< QString::fromLatin1("hel") |
|
1666 |
<< true; |
|
1667 |
QTest::newRow("utf16-be bom be ignore header") |
|
1668 |
<< QByteArray("UTF-16BE") |
|
1669 |
<< (int)QTextCodec::IgnoreHeader |
|
1670 |
<< QByteArray("\xfe\xff\0h\0e\0l", 8) |
|
1671 |
<< (QString(QChar(0xfeff)) + QString::fromLatin1("hel")) |
|
1672 |
<< true; |
|
1673 |
||
1674 |
QTest::newRow("utf16-le bom le") |
|
1675 |
<< QByteArray("UTF-16LE") |
|
1676 |
<< 0 |
|
1677 |
<< QByteArray("\xff\xfeh\0e\0l\0", 8) |
|
1678 |
<< QString::fromLatin1("hel") |
|
1679 |
<< true; |
|
1680 |
QTest::newRow("utf16-le nobom") |
|
1681 |
<< QByteArray("UTF-16LE") |
|
1682 |
<< 0 |
|
1683 |
<< QByteArray("h\0e\0l\0", 6) |
|
1684 |
<< QString::fromLatin1("hel") |
|
1685 |
<< true; |
|
1686 |
QTest::newRow("utf16-le bom le ignore header") |
|
1687 |
<< QByteArray("UTF-16LE") |
|
1688 |
<< (int)QTextCodec::IgnoreHeader |
|
1689 |
<< QByteArray("\xff\xfeh\0e\0l\0", 8) |
|
1690 |
<< (QString(QChar(0xfeff)) + QString::fromLatin1("hel")) |
|
1691 |
<< true; |
|
1692 |
||
1693 |
||
1694 |
QTest::newRow("utf32 bom be") |
|
1695 |
<< QByteArray("UTF-32") |
|
1696 |
<< 0 |
|
1697 |
<< QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16) |
|
1698 |
<< QString::fromLatin1("hel") |
|
1699 |
<< true; |
|
1700 |
QTest::newRow("utf32 bom le") |
|
1701 |
<< QByteArray("UTF-32") |
|
1702 |
<< 0 |
|
1703 |
<< QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16) |
|
1704 |
<< QString::fromLatin1("hel") |
|
1705 |
<< true; |
|
1706 |
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { |
|
1707 |
QTest::newRow("utf32 nobom") |
|
1708 |
<< QByteArray("UTF-32") |
|
1709 |
<< 0 |
|
1710 |
<< QByteArray("\0\0\0h\0\0\0e\0\0\0l", 12) |
|
1711 |
<< QString::fromLatin1("hel") |
|
1712 |
<< true; |
|
1713 |
QTest::newRow("utf32 bom be ignore header") |
|
1714 |
<< QByteArray("UTF-32") |
|
1715 |
<< (int)QTextCodec::IgnoreHeader |
|
1716 |
<< QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16) |
|
1717 |
<< (QString(QChar(0xfeff)) + QString::fromLatin1("hel")) |
|
1718 |
<< true; |
|
1719 |
} else { |
|
1720 |
QTest::newRow("utf32 nobom") |
|
1721 |
<< QByteArray("UTF-32") |
|
1722 |
<< 0 |
|
1723 |
<< QByteArray("h\0\0\0e\0\0\0l\0\0\0", 12) |
|
1724 |
<< QString::fromLatin1("hel") |
|
1725 |
<< true; |
|
1726 |
QTest::newRow("utf32 bom le ignore header") |
|
1727 |
<< QByteArray("UTF-32") |
|
1728 |
<< (int)QTextCodec::IgnoreHeader |
|
1729 |
<< QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16) |
|
1730 |
<< (QString(QChar(0xfeff)) + QString::fromLatin1("hel")) |
|
1731 |
<< true; |
|
1732 |
} |
|
1733 |
||
1734 |
||
1735 |
QTest::newRow("utf32-be bom be") |
|
1736 |
<< QByteArray("UTF-32BE") |
|
1737 |
<< 0 |
|
1738 |
<< QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16) |
|
1739 |
<< QString::fromLatin1("hel") |
|
1740 |
<< true; |
|
1741 |
QTest::newRow("utf32-be nobom") |
|
1742 |
<< QByteArray("UTF-32BE") |
|
1743 |
<< 0 |
|
1744 |
<< QByteArray("\0\0\0h\0\0\0e\0\0\0l", 12) |
|
1745 |
<< QString::fromLatin1("hel") |
|
1746 |
<< true; |
|
1747 |
QTest::newRow("utf32-be bom be ignore header") |
|
1748 |
<< QByteArray("UTF-32BE") |
|
1749 |
<< (int)QTextCodec::IgnoreHeader |
|
1750 |
<< QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16) |
|
1751 |
<< (QString(QChar(0xfeff)) + QString::fromLatin1("hel")) |
|
1752 |
<< true; |
|
1753 |
||
1754 |
||
1755 |
QTest::newRow("utf32-le bom le") |
|
1756 |
<< QByteArray("UTF-32LE") |
|
1757 |
<< 0 |
|
1758 |
<< QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16) |
|
1759 |
<< QString::fromLatin1("hel") |
|
1760 |
<< true; |
|
1761 |
QTest::newRow("utf32-le nobom") |
|
1762 |
<< QByteArray("UTF-32LE") |
|
1763 |
<< 0 |
|
1764 |
<< QByteArray("h\0\0\0e\0\0\0l\0\0\0", 12) |
|
1765 |
<< QString::fromLatin1("hel") |
|
1766 |
<< true; |
|
1767 |
QTest::newRow("utf32-le bom le ignore header") |
|
1768 |
<< QByteArray("UTF-32LE") |
|
1769 |
<< (int)QTextCodec::IgnoreHeader |
|
1770 |
<< QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16) |
|
1771 |
<< (QString(QChar(0xfeff)) + QString::fromLatin1("hel")) |
|
1772 |
<< true; |
|
1773 |
} |
|
1774 |
||
1775 |
void tst_QTextCodec::utfHeaders() |
|
1776 |
{ |
|
1777 |
QFETCH(QByteArray, codecName); |
|
1778 |
QTextCodec *codec = QTextCodec::codecForName(codecName); |
|
1779 |
QVERIFY(codec != 0); |
|
1780 |
||
1781 |
QFETCH(int, flags); |
|
1782 |
QTextCodec::ConversionFlags cFlags = QTextCodec::ConversionFlags(flags); |
|
1783 |
QTextCodec::ConverterState state(cFlags); |
|
1784 |
||
1785 |
QFETCH(QByteArray, encoded); |
|
1786 |
QFETCH(QString, unicode); |
|
1787 |
||
1788 |
QFETCH(bool, toUnicode); |
|
1789 |
||
1790 |
QLatin1String ignoreReverseTestOn = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? QLatin1String(" le") : QLatin1String(" be"); |
|
1791 |
QString rowName(QTest::currentDataTag()); |
|
1792 |
||
1793 |
for (int i = 0; i < encoded.length(); ++i) |
|
1794 |
qDebug() << hex << " " << (uint)(uchar)encoded.at(i); |
|
1795 |
if (toUnicode) { |
|
1796 |
QString result = codec->toUnicode(encoded.constData(), encoded.length(), &state); |
|
1797 |
for (int i = 0; i < result.length(); ++i) |
|
1798 |
qDebug() << hex << " " << (uint)result.at(i).unicode(); |
|
1799 |
QCOMPARE(result.length(), unicode.length()); |
|
1800 |
QCOMPARE(result, unicode); |
|
1801 |
||
1802 |
if (!rowName.endsWith("nobom") && !rowName.contains(ignoreReverseTestOn)) { |
|
1803 |
QTextCodec::ConverterState state2(cFlags); |
|
1804 |
QByteArray reencoded = codec->fromUnicode(unicode.unicode(), unicode.length(), &state2); |
|
1805 |
QCOMPARE(reencoded, encoded); |
|
1806 |
} |
|
1807 |
} else { |
|
1808 |
QByteArray result = codec->fromUnicode(unicode.unicode(), unicode.length(), &state); |
|
1809 |
QCOMPARE(result, encoded); |
|
1810 |
} |
|
1811 |
} |
|
1812 |
||
1813 |
void tst_QTextCodec::codecForHtml() |
|
1814 |
{ |
|
1815 |
QByteArray html("<html><head></head><body>blah</body></html>"); |
|
1816 |
||
1817 |
QCOMPARE(QTextCodec::codecForHtml(html)->mibEnum(), 4); // latin 1 |
|
1818 |
||
1819 |
QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 106); // UTF-8 |
|
1820 |
||
1821 |
html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-15\" /></head></html>"; |
|
1822 |
QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 111); // latin 15 |
|
1823 |
||
1824 |
html = "<html><head><meta content=\"text/html; charset=ISO-8859-15\" http-equiv=\"content-type\" /></head></html>"; |
|
1825 |
QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 111); // latin 15 |
|
1826 |
||
1827 |
html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=invalid-foo\" /></head></html>"; |
|
1828 |
QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 106); // UTF-8 |
|
1829 |
QCOMPARE(QTextCodec::codecForHtml(html)->mibEnum(), 4); // latin 1 |
|
1830 |
} |
|
1831 |
||
1832 |
void tst_QTextCodec::codecForUtfText_data() |
|
1833 |
{ |
|
1834 |
QTest::addColumn<QByteArray>("encoded"); |
|
1835 |
QTest::addColumn<bool>("detected"); |
|
1836 |
QTest::addColumn<int>("mib"); |
|
1837 |
||
1838 |
||
1839 |
QTest::newRow("utf8 bom") |
|
1840 |
<< QByteArray("\xef\xbb\xbfhello") |
|
1841 |
<< true |
|
1842 |
<< 106; |
|
1843 |
QTest::newRow("utf8 nobom") |
|
1844 |
<< QByteArray("hello") |
|
1845 |
<< false |
|
1846 |
<< 0; |
|
1847 |
||
1848 |
QTest::newRow("utf16 bom be") |
|
1849 |
<< QByteArray("\xfe\xff\0h\0e\0l", 8) |
|
1850 |
<< true |
|
1851 |
<< 1013; |
|
1852 |
QTest::newRow("utf16 bom le") |
|
1853 |
<< QByteArray("\xff\xfeh\0e\0l\0", 8) |
|
1854 |
<< true |
|
1855 |
<< 1014; |
|
1856 |
QTest::newRow("utf16 nobom") |
|
1857 |
<< QByteArray("\0h\0e\0l", 6) |
|
1858 |
<< false |
|
1859 |
<< 0; |
|
1860 |
||
1861 |
QTest::newRow("utf32 bom be") |
|
1862 |
<< QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16) |
|
1863 |
<< true |
|
1864 |
<< 1018; |
|
1865 |
QTest::newRow("utf32 bom le") |
|
1866 |
<< QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16) |
|
1867 |
<< true |
|
1868 |
<< 1019; |
|
1869 |
QTest::newRow("utf32 nobom") |
|
1870 |
<< QByteArray("\0\0\0h\0\0\0e\0\0\0l", 12) |
|
1871 |
<< false |
|
1872 |
<< 0; |
|
1873 |
} |
|
1874 |
||
1875 |
void tst_QTextCodec::codecForUtfText() |
|
1876 |
{ |
|
1877 |
QFETCH(QByteArray, encoded); |
|
1878 |
QFETCH(bool, detected); |
|
1879 |
QFETCH(int, mib); |
|
1880 |
||
1881 |
QTextCodec *codec = QTextCodec::codecForUtfText(encoded, 0); |
|
1882 |
if (detected) |
|
1883 |
QCOMPARE(codec->mibEnum(), mib); |
|
1884 |
else |
|
1885 |
QVERIFY(codec == 0); |
|
1886 |
} |
|
1887 |
||
1888 |
#ifdef Q_OS_UNIX |
|
1889 |
void tst_QTextCodec::toLocal8Bit() |
|
1890 |
{ |
|
1891 |
#ifdef QT_NO_PROCESS |
|
1892 |
QSKIP("This test requires QProcess", SkipAll); |
|
1893 |
#else |
|
1894 |
QProcess process; |
|
1895 |
process.start("echo/echo"); |
|
1896 |
QString string(QChar(0x410)); |
|
1897 |
process.write((const char*)string.utf16(), string.length()*2); |
|
1898 |
||
1899 |
process.closeWriteChannel(); |
|
1900 |
process.waitForFinished(); |
|
1901 |
QCOMPARE(process.exitStatus(), QProcess::NormalExit); |
|
1902 |
QCOMPARE(process.exitCode(), 0); |
|
1903 |
#endif |
|
1904 |
} |
|
1905 |
#endif |
|
1906 |
||
1907 |
QTEST_MAIN(tst_QTextCodec) |
|
1908 |
#include "tst_qtextcodec.moc" |