7daed397d523c59c1382ca7763e0147451732164
[profile/ivi/qtbase.git] / tests / auto / corelib / codecs / qtextcodec / tst_qtextcodec.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
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 #include <QThreadPool>
51
52 class tst_QTextCodec : public QObject
53 {
54     Q_OBJECT
55
56 private slots:
57     void threadSafety();
58
59     void toUnicode_data();
60     void toUnicode();
61     void codecForName_data();
62     void codecForName();
63     void fromUnicode_data();
64     void fromUnicode();
65     void toUnicode_codecForHtml();
66     void toUnicode_incremental();
67     void codecForLocale();
68
69     void asciiToIscii() const;
70     void flagCodepointFFFF() const;
71     void flagF7808080() const;
72     void flagEFBFBF() const;
73     void decode0D() const;
74     void aliasForUTF16() const;
75     void mibForTSCII() const;
76
77     void utf8Codec_data();
78     void utf8Codec();
79
80     void utf8bom_data();
81     void utf8bom();
82
83     void utfHeaders_data();
84     void utfHeaders();
85
86     void codecForHtml();
87
88     void codecForUtfText_data();
89     void codecForUtfText();
90
91 #if defined(Q_OS_UNIX) && !defined(QT_NO_PROCESS)
92     void toLocal8Bit();
93 #endif
94
95     void invalidNames();
96     void checkAliases_data();
97     void checkAliases();
98
99     void moreToFromUnicode_data();
100     void moreToFromUnicode();
101
102     void shiftJis();
103 };
104
105 void tst_QTextCodec::toUnicode_data()
106 {
107     QTest::addColumn<QString>("fileName");
108     QTest::addColumn<QString>("codecName");
109
110     QTest::newRow( "korean-eucKR" ) << QFINDTESTDATA("korean.txt") << "eucKR";
111     QTest::newRow( "UTF-8" ) << QFINDTESTDATA("utf8.txt") << "UTF-8";
112 }
113
114 void tst_QTextCodec::toUnicode()
115 {
116     QFETCH( QString, fileName );
117     QFETCH( QString, codecName );
118
119     QFile file( fileName );
120
121     if ( file.open( QIODevice::ReadOnly ) ) {
122         QByteArray ba = file.readAll();
123         QVERIFY(!ba.isEmpty());
124         QTextCodec *c = QTextCodec::codecForName( codecName.toLatin1() );
125         QVERIFY(c != 0);
126         QString uniString = c->toUnicode( ba );
127         if (codecName == QLatin1String("UTF-8")) {
128             QCOMPARE(uniString, QString::fromUtf8(ba));
129             QCOMPARE(ba, uniString.toUtf8());
130         }
131         QVERIFY(!uniString.isEmpty());
132         QCOMPARE( ba, c->fromUnicode( uniString ) );
133
134         if (codecName == QLatin1String("eucKR")) {
135             char ch = '\0';
136             QVERIFY(c->toUnicode(&ch, 1).isEmpty());
137             QVERIFY(c->toUnicode(&ch, 1).isNull());
138         }
139     } else {
140         QFAIL(qPrintable("File could not be opened: " + file.errorString()));
141     }
142 }
143
144 void tst_QTextCodec::codecForName_data()
145 {
146     QTest::addColumn<QString>("hint");
147     QTest::addColumn<QString>("actualCodecName");
148
149     QTest::newRow("data1") << "iso88591" << "ISO-8859-1";
150     QTest::newRow("data2") << "iso88592" << "ISO-8859-2";
151     QTest::newRow("data3") << " IsO(8)8/5*9-2 " << "ISO-8859-2";
152     QTest::newRow("data4") << " IsO(8)8/5*2-9 " << "";
153     QTest::newRow("data5") << "latin2" << "ISO-8859-2";
154 }
155
156 void tst_QTextCodec::codecForName()
157 {
158     QFETCH(QString, hint);
159     QFETCH(QString, actualCodecName);
160
161     QTextCodec *codec = QTextCodec::codecForName(hint.toLatin1());
162     if (actualCodecName.isEmpty()) {
163         QVERIFY(codec == 0);
164     } else {
165         QVERIFY(codec != 0);
166         QCOMPARE(QString(codec->name()), actualCodecName);
167     }
168 }
169
170 void tst_QTextCodec::fromUnicode_data()
171 {
172     QTest::addColumn<QString>("codecName");
173     QTest::addColumn<bool>("eightBit");
174
175     QTest::newRow("data1") << "ISO-8859-1" << true;
176     QTest::newRow("data2") << "ISO-8859-2" << true;
177     QTest::newRow("data3") << "ISO-8859-3" << true;
178     QTest::newRow("data4") << "ISO-8859-4" << true;
179     QTest::newRow("data5") << "ISO-8859-5" << true;
180     QTest::newRow("data6") << "ISO-8859-6" << true;
181     QTest::newRow("data7") << "ISO-8859-7" << true;
182     QTest::newRow("data8") << "ISO-8859-8" << true;
183     QTest::newRow("data9") << "ISO-8859-9" << true;
184     QTest::newRow("data10") << "ISO-8859-10" << true;
185     QTest::newRow("data13") << "ISO-8859-13" << true;
186     QTest::newRow("data14") << "ISO-8859-14" << true;
187     QTest::newRow("data15") << "ISO-8859-15" << true;
188     QTest::newRow("data16") << "ISO-8859-16" << true;
189
190     QTest::newRow("data18") << "IBM850" << true;
191     QTest::newRow("data19") << "IBM874" << true;
192     QTest::newRow("data20") << "IBM866" << true;
193
194     QTest::newRow("data21") << "windows-1250" << true;
195     QTest::newRow("data22") << "windows-1251" << true;
196     QTest::newRow("data23") << "windows-1252" << true;
197     QTest::newRow("data24") << "windows-1253" << true;
198     QTest::newRow("data25") << "windows-1254" << true;
199     QTest::newRow("data26") << "windows-1255" << true;
200     QTest::newRow("data27") << "windows-1256" << true;
201     QTest::newRow("data28") << "windows-1257" << true;
202     QTest::newRow("data28") << "windows-1258" << true;
203
204     QTest::newRow("data29") << "Apple Roman" << true;
205     QTest::newRow("data29") << "WINSAMI2" << true;
206     QTest::newRow("data30") << "TIS-620" << true;
207     QTest::newRow("data31") << "roman8" << true;
208
209     QTest::newRow("data32") << "SJIS" << false;
210     QTest::newRow("data33") << "EUC-KR" << false;
211
212     // all codecs from documentation
213     QTest::newRow("doc2") << "Big5" << false;
214     QTest::newRow("doc3") << "Big5-HKSCS" << false;
215     QTest::newRow("doc4") << "CP949" << false;
216     QTest::newRow("doc5") << "EUC-JP" << false;
217     QTest::newRow("doc6") << "EUC-KR" << false;
218     //QTest::newRow("doc7") << "GB18030-0" << false; // only GB18030 works
219     QTest::newRow("doc7-bis") << "GB18030" << false;
220     QTest::newRow("doc8") << "IBM 850" << false;
221     QTest::newRow("doc9") << "IBM 866" << false;
222     QTest::newRow("doc10") << "IBM 874" << false;
223     QTest::newRow("doc11") << "ISO 2022-JP" << false;
224     //ISO 8859-1 to 10 and  ISO 8859-13 to 16 tested previously
225     // Iscii-Bng, Dev, Gjr, Knd, Mlm, Ori, Pnj, Tlg, and Tml  tested in Iscii test
226     //QTest::newRow("doc12") << "JIS X 0201" << false; //actually not there
227     //QTest::newRow("doc13") << "JIS X 0208" << false; // actually not there
228     QTest::newRow("doc14") << "KOI8-R" << false;
229     QTest::newRow("doc15") << "KOI8-U" << false;
230     //QTest::newRow("doc16") << "MuleLao-1" << false; //only on x11
231     QTest::newRow("doc17") << "ROMAN8" << false;
232     QTest::newRow("doc18") << "Shift-JIS" << false;
233     QTest::newRow("doc19") << "TIS-620" << false;
234     QTest::newRow("doc20") << "TSCII" << false;
235     QTest::newRow("doc21") << "UTF-8" << false;
236     QTest::newRow("doc22") << "UTF-16" << false;
237     QTest::newRow("doc23") << "UTF-16BE" << false;
238     QTest::newRow("doc24") << "UTF-16LE" << false;
239     QTest::newRow("doc25") << "UTF-32" << false;
240     QTest::newRow("doc26") << "UTF-32BE" << false;
241     QTest::newRow("doc27") << "UTF-32LE" << false;
242     //Windows-1250 to 1258 tested previously
243     QTest::newRow("doc3") << "WINSAMI2" << false;
244 }
245
246 void tst_QTextCodec::fromUnicode()
247 {
248     QFETCH(QString, codecName);
249     QFETCH(bool, eightBit);
250
251     QTextCodec *codec = QTextCodec::codecForName(codecName.toLatin1());
252     QVERIFY(codec != 0);
253
254     // Check if the reverse lookup is what we expect
255     if (eightBit) {
256         char chars[128];
257         for (int i = 0; i < 128; ++i)
258             chars[i] = i + 128;
259         QString s = codec->toUnicode(chars, 128);
260         QByteArray c = codec->fromUnicode(s);
261         QCOMPARE(c.size(), 128);
262
263         int numberOfQuestionMarks = 0;
264         for (int i = 0; i < 128; ++i) {
265             if (c.at(i) == '?')
266                 ++numberOfQuestionMarks;
267             else
268                 QCOMPARE(c.at(i), char(i + 128));
269         }
270         QVERIFY(numberOfQuestionMarks != 128);
271     }
272
273     /*
274         If the encoding is a superset of ASCII, test that the byte
275         array is correct (no off by one, no trailing '\0').
276     */
277     QByteArray result = codec->fromUnicode(QString("abc"));
278     if (result.startsWith("a")) {
279         QCOMPARE(result.size(), 3);
280         QCOMPARE(result, QByteArray("abc"));
281     } else {
282         QVERIFY(true);
283     }
284 }
285
286 void tst_QTextCodec::toUnicode_codecForHtml()
287 {
288     QFile file(QFINDTESTDATA("QT4-crashtest.txt"));
289     QVERIFY(file.open(QFile::ReadOnly));
290
291     QByteArray data = file.readAll();
292     QTextCodec *codec = Qt::codecForHtml(data);
293     codec->toUnicode(data); // this line crashes
294 }
295
296
297 void tst_QTextCodec::toUnicode_incremental()
298 {
299     QByteArray ba;
300     ba += char(0xf0);
301     ba += char(0x90);
302     ba += char(0x80);
303     ba += char(0x80);
304     ba += char(0xf4);
305     ba += char(0x8f);
306     ba += char(0xbf);
307     ba += char(0xbd);
308
309     QString expected = QString::fromUtf8(ba);
310
311     QString incremental;
312     QTextDecoder *utf8Decoder = QTextCodec::codecForMib(106)->makeDecoder();
313
314     QString actual;
315     for (int i = 0; i < ba.size(); ++i)
316         utf8Decoder->toUnicode(&actual, ba.constData() + i, 1);
317
318     QCOMPARE(actual, expected);
319
320
321     delete utf8Decoder;
322 }
323
324 void tst_QTextCodec::codecForLocale()
325 {
326     QTextCodec *codec = QTextCodec::codecForLocale();
327     QVERIFY(codec != 0);
328
329     // The rest of this test is for Unix only
330 #if defined(Q_OS_UNIX)
331     // get a time string that is locale-encoded
332     QByteArray originalLocaleEncodedTimeString;
333     originalLocaleEncodedTimeString.resize(1024);
334     time_t t;
335     time(&t);
336     int r = strftime(originalLocaleEncodedTimeString.data(),
337                      originalLocaleEncodedTimeString.size(),
338                      "%A%a%B%b%Z",
339                      localtime(&t));
340     QVERIFY(r != 0);
341     originalLocaleEncodedTimeString.resize(r);
342
343     QString unicodeTimeString = codec->toUnicode(originalLocaleEncodedTimeString);
344     QByteArray localeEncodedTimeString = codec->fromUnicode(unicodeTimeString);
345     QCOMPARE(localeEncodedTimeString, originalLocaleEncodedTimeString);
346
347     // find a codec that is not the codecForLocale()
348     QTextCodec *codec2 = 0;
349     foreach (int mib, QTextCodec::availableMibs()) {
350         if (mib != codec->mibEnum()) {
351             codec2 = QTextCodec::codecForMib(mib);
352             if (codec2)
353                 break;
354         }
355     }
356
357     // Only run the rest of the test if we could find a codec that is not
358     // already the codecForLocale().
359     if (codec2) {
360         // set it, codecForLocale() should return it now
361         QTextCodec::setCodecForLocale(codec2);
362         QCOMPARE(QTextCodec::codecForLocale(), codec2);
363
364         // reset back to the default
365         QTextCodec::setCodecForLocale(0);
366         QCOMPARE(QTextCodec::codecForLocale(), codec);
367     }
368 #endif
369 }
370
371 void tst_QTextCodec::asciiToIscii() const
372 {
373     /* Add all low, 7-bit ASCII characters. */
374     QString ascii;
375     const int len = 0xA0 - 1;
376     ascii.resize(len);
377
378     for(int i = 0; i < len; ++i)
379         ascii[i] = QChar(i + 1);
380
381     static const char *const isciiCodecs[] =
382     {
383         "Iscii-Mlm",
384         "Iscii-Knd",
385         "Iscii-Tlg",
386         "Iscii-Tml",
387         "Iscii-Ori",
388         "Iscii-Gjr",
389         "Iscii-Pnj",
390         "Iscii-Bng",
391         "Iscii-Dev"
392     };
393     const int isciiCodecsLen = sizeof(isciiCodecs) / sizeof(const char *);
394
395     for(int i = 0; i < isciiCodecsLen; ++i) {
396         /* For each codec. */
397
398         const QTextCodec *const textCodec = QTextCodec::codecForName(isciiCodecs[i]);
399         QVERIFY(textCodec);
400
401         for(int i2 = 0; i2 < len; ++i2) {
402             /* For each character in ascii. */
403             const QChar c(ascii[i2]);
404             QVERIFY2(textCodec->canEncode(c), qPrintable(QString::fromLatin1("Failed to encode %1 with encoding %2")
405                                                          .arg(QString::number(c.unicode()), QString::fromLatin1(textCodec->name().constData()))));
406         }
407
408         QVERIFY2(textCodec->canEncode(ascii), qPrintable(QString::fromLatin1("Failed for full string with encoding %1")
409                                                          .arg(QString::fromLatin1(textCodec->name().constData()))));
410     }
411 }
412
413 void tst_QTextCodec::flagCodepointFFFF() const
414 {
415     // This is an invalid Unicode codepoint.
416     const QChar ch(0xFFFF);
417     QString input(ch);
418
419     QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8
420     QVERIFY(codec);
421
422     const QByteArray asDecoded(codec->fromUnicode(input));
423     QCOMPARE(asDecoded, QByteArray("?"));
424
425     QByteArray ffff("\357\277\277");
426     QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull);
427     QVERIFY(codec->toUnicode(ffff.constData(), ffff.length(), &state) == QChar(0));
428     QVERIFY(codec->toUnicode(ffff) == QChar(0xfffd));
429 }
430
431 void tst_QTextCodec::flagF7808080() const
432 {
433     /* This test case stems from test not-wf-sa-170, tests/qxmlstream/XML-Test-Suite/xmlconf/xmltest/not-wf/sa/166.xml,
434      * whose description reads:
435      *
436      * "Four byte UTF-8 encodings can encode UCS-4 characters
437      *  which are beyond the range of legal XML characters
438      *  (and can't be expressed in Unicode surrogate pairs).
439      *  This document holds such a character."
440      *
441      *  In binary, this is:
442      *  11110111100000001000000010000000
443      *  *       *       *       *
444      *  11110www10xxxxxx10yyyyyy10zzzzzz
445      *
446      *  With multibyte logic removed it is the codepoint 0x1C0000.
447      */
448     QByteArray input;
449     input.resize(4);
450     input[0] = char(0xF7);
451     input[1] = char(0x80);
452     input[2] = char(0x80);
453     input[3] = char(0x80);
454
455     QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8
456     QVERIFY(codec);
457
458     //QVERIFY(!codec->canEncode(QChar(0x1C0000)));
459
460     QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull);
461     QVERIFY(codec->toUnicode(input.constData(), input.length(), &state) == QChar(0));
462 }
463
464 void tst_QTextCodec::flagEFBFBF() const
465 {
466     QByteArray invalidInput;
467     invalidInput.resize(3);
468     invalidInput[0] = char(0xEF);
469     invalidInput[1] = char(0xBF);
470     invalidInput[2] = char(0xBF);
471
472     const QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8
473     QVERIFY(codec);
474
475     {
476         //QVERIFY(!codec->canEncode(QChar(0xFFFF)));
477         QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull);
478         QVERIFY(codec->toUnicode(invalidInput.constData(), invalidInput.length(), &state) == QChar(0));
479
480         QByteArray start("<?pi ");
481         start.append(invalidInput);
482         start.append("?>");
483     }
484
485     /* When 0xEFBFBF is preceded by what seems to be an arbitrary character,
486      * QTextCodec fails to flag it. */
487     {
488         QByteArray start("B");
489         start.append(invalidInput);
490
491         QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull);
492         QVERIFY(codec->toUnicode(start.constData(), start.length(), &state) == QString::fromLatin1("B\0", 2));
493     }
494 }
495
496 void tst_QTextCodec::decode0D() const
497 {
498     QByteArray input;
499     input.resize(3);
500     input[0] = 'A';
501     input[1] = '\r';
502     input[2] = 'B';
503
504     QCOMPARE(QString::fromUtf8(input.constData()).toUtf8(), input);
505 }
506
507 void tst_QTextCodec::aliasForUTF16() const
508 {
509     QVERIFY(QTextCodec::codecForName("UTF-16")->aliases().isEmpty());
510 }
511
512 void tst_QTextCodec::mibForTSCII() const
513 {
514     QTextCodec *codec = QTextCodec::codecForName("TSCII");
515     QVERIFY(codec);
516     QCOMPARE(codec->mibEnum(), 2107);
517 }
518
519 static QString fromInvalidUtf8Sequence(const QByteArray &ba)
520 {
521     return QString().fill(QChar::ReplacementCharacter, ba.size());
522 }
523
524 // copied from tst_QString::fromUtf8_data()
525 void tst_QTextCodec::utf8Codec_data()
526 {
527     QTest::addColumn<QByteArray>("utf8");
528     QTest::addColumn<QString>("res");
529     QTest::addColumn<int>("len");
530     QString str;
531
532     QTest::newRow("str0") << QByteArray("abcdefgh") << QString("abcdefgh") << -1;
533     QTest::newRow("str0-len") << QByteArray("abcdefgh") << QString("abc") << 3;
534     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;
535     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;
536
537     str += QChar(0x05e9);
538     str += QChar(0x05d3);
539     str += QChar(0x05d2);
540     QTest::newRow("str2") << QByteArray("\327\251\327\223\327\222") << str << -1;
541
542     str = QChar(0x05e9);
543     QTest::newRow("str2-len") << QByteArray("\327\251\327\223\327\222") << str << 2;
544
545     str = QChar(0x20ac);
546     str += " some text";
547     QTest::newRow("str3") << QByteArray("\342\202\254 some text") << str << -1;
548
549     str = QChar(0x20ac);
550     str += " some ";
551     QTest::newRow("str3-len") << QByteArray("\342\202\254 some text") << str << 9;
552
553     str = "hello";
554     str += QChar::ReplacementCharacter;
555     str += QChar(0x68);
556     str += QChar::ReplacementCharacter;
557     str += QChar::ReplacementCharacter;
558     str += QChar::ReplacementCharacter;
559     str += QChar::ReplacementCharacter;
560     str += QChar(0x61);
561     str += QChar::ReplacementCharacter;
562     QTest::newRow("invalid utf8") << QByteArray("hello\344h\344\344\366\344a\304") << str << -1;
563     QTest::newRow("invalid utf8-len") << QByteArray("hello\344h\344\344\366\344a\304") << QString("hello") << 5;
564
565     str = "Prohl";
566     str += QChar::ReplacementCharacter;
567     str += QChar::ReplacementCharacter;
568     str += "e";
569     str += QChar::ReplacementCharacter;
570     str += " plugin";
571     str += QChar::ReplacementCharacter;
572     str += " Netscape";
573
574     QTest::newRow("task28417") << QByteArray("Prohl\355\276e\350 plugin\371 Netscape") << str << -1;
575     QTest::newRow("task28417-len") << QByteArray("Prohl\355\276e\350 plugin\371 Netscape") << QString("") << 0;
576
577     QTest::newRow("null-1") << QByteArray() << QString() << -1;
578     QTest::newRow("null0") << QByteArray() << QString() << 0;
579     // QTest::newRow("null5") << QByteArray() << QString() << 5;
580     QTest::newRow("empty-1") << QByteArray("\0abcd", 5) << QString() << -1;
581     QTest::newRow("empty0") << QByteArray() << QString() << 0;
582     QTest::newRow("empty5") << QByteArray("\0abcd", 5) << QString::fromAscii("\0abcd", 5) << 5;
583     QTest::newRow("other-1") << QByteArray("ab\0cd", 5) << QString::fromAscii("ab") << -1;
584     QTest::newRow("other5") << QByteArray("ab\0cd", 5) << QString::fromAscii("ab\0cd", 5) << 5;
585
586     str = "Old Italic: ";
587     str += QChar(0xd800);
588     str += QChar(0xdf00);
589     str += QChar(0xd800);
590     str += QChar(0xdf01);
591     str += QChar(0xd800);
592     str += QChar(0xdf02);
593     str += QChar(0xd800);
594     str += QChar(0xdf03);
595     str += QChar(0xd800);
596     str += QChar(0xdf04);
597     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;
598
599     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;
600
601     // from http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html
602
603     // 2.1.1 U+00000000
604     QByteArray utf8;
605     utf8 += char(0x00);
606     str = QChar(QChar::Null);
607     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.1") << utf8 << str << 1;
608
609     // 2.1.2 U+00000080
610     utf8.clear();
611     utf8 += char(0xc2);
612     utf8 += char(0x80);
613     str = QChar(0x80);
614     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.2") << utf8 << str << -1;
615
616     // 2.1.3 U+00000800
617     utf8.clear();
618     utf8 += char(0xe0);
619     utf8 += char(0xa0);
620     utf8 += char(0x80);
621     str = QChar(0x800);
622     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.3") << utf8 << str << -1;
623
624     // 2.1.4 U+00010000
625     utf8.clear();
626     utf8 += char(0xf0);
627     utf8 += char(0x90);
628     utf8 += char(0x80);
629     utf8 += char(0x80);
630     str.clear();
631     str += QChar(0xd800);
632     str += QChar(0xdc00);
633     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.4") << utf8 << str << -1;
634
635     // 2.1.5 U+00200000 (not a valid Unicode character)
636     utf8.clear();
637     utf8 += char(0xf8);
638     utf8 += char(0x88);
639     utf8 += char(0x80);
640     utf8 += char(0x80);
641     utf8 += char(0x80);
642     str = fromInvalidUtf8Sequence(utf8);
643     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.5") << utf8 << str << -1;
644
645     // 2.1.6 U+04000000 (not a valid Unicode character)
646     utf8.clear();
647     utf8 += char(0xfc);
648     utf8 += char(0x84);
649     utf8 += char(0x80);
650     utf8 += char(0x80);
651     utf8 += char(0x80);
652     utf8 += char(0x80);
653     str = fromInvalidUtf8Sequence(utf8);
654     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.6") << utf8 << str << -1;
655
656     // 2.2.1 U+0000007F
657     utf8.clear();
658     utf8 += char(0x7f);
659     str = QChar(0x7f);
660     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.1") << utf8 << str << -1;
661
662     // 2.2.2 U+000007FF
663     utf8.clear();
664     utf8 += char(0xdf);
665     utf8 += char(0xbf);
666     str = QChar(0x7ff);
667     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.2") << utf8 << str << -1;
668
669     // 2.2.3 U+000FFFF
670     utf8.clear();
671     utf8 += char(0xef);
672     utf8 += char(0xbf);
673     utf8 += char(0xbf);
674     str.clear();
675     str += QChar::ReplacementCharacter;
676     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.3") << utf8 << str << -1;
677
678     // 2.2.4 U+001FFFFF
679     utf8.clear();
680     utf8 += char(0xf7);
681     utf8 += char(0xbf);
682     utf8 += char(0xbf);
683     utf8 += char(0xbf);
684     str.clear();
685     str += QChar(QChar::ReplacementCharacter);
686     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.4") << utf8 << str << -1;
687
688     // 2.2.5 U+03FFFFFF (not a valid Unicode character)
689     utf8.clear();
690     utf8 += char(0xfb);
691     utf8 += char(0xbf);
692     utf8 += char(0xbf);
693     utf8 += char(0xbf);
694     utf8 += char(0xbf);
695     str = fromInvalidUtf8Sequence(utf8);
696     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.5") << utf8 << str << -1;
697
698     // 2.2.6 U+7FFFFFFF
699     utf8.clear();
700     utf8 += char(0xfd);
701     utf8 += char(0xbf);
702     utf8 += char(0xbf);
703     utf8 += char(0xbf);
704     utf8 += char(0xbf);
705     utf8 += char(0xbf);
706     str = fromInvalidUtf8Sequence(utf8);
707     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.6") << utf8 << str << -1;
708
709     // 2.3.1 U+0000D7FF
710     utf8.clear();
711     utf8 += char(0xed);
712     utf8 += char(0x9f);
713     utf8 += char(0xbf);
714     str = QChar(0xd7ff);
715     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.1") << utf8 << str << -1;
716
717     // 2.3.2 U+0000E000
718     utf8.clear();
719     utf8 += char(0xee);
720     utf8 += char(0x80);
721     utf8 += char(0x80);
722     str = QChar(0xe000);
723     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.2") << utf8 << str << -1;
724
725     // 2.3.3 U+0000FFFD
726     utf8.clear();
727     utf8 += char(0xef);
728     utf8 += char(0xbf);
729     utf8 += char(0xbd);
730     str = QChar(QChar::ReplacementCharacter);
731     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.3") << utf8 << str << -1;
732
733     // 2.3.4 U+0010FFFD
734     utf8.clear();
735     utf8 += char(0xf4);
736     utf8 += char(0x8f);
737     utf8 += char(0xbf);
738     utf8 += char(0xbd);
739     str.clear();
740     str += QChar(0xdbff);
741     str += QChar(0xdffd);
742     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.4") << utf8 << str << -1;
743
744     // 2.3.5 U+00110000
745     utf8.clear();
746     utf8 += char(0xf4);
747     utf8 += char(0x90);
748     utf8 += char(0x80);
749     utf8 += char(0x80);
750     str.clear();
751     str += QChar(QChar::ReplacementCharacter);
752     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.5") << utf8 << str << -1;
753
754     // 3.1.1
755     utf8.clear();
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.1") << utf8 << str << -1;
759
760     // 3.1.2
761     utf8.clear();
762     utf8 += char(0xbf);
763     str = fromInvalidUtf8Sequence(utf8);
764     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.2") << utf8 << str << -1;
765
766     // 3.1.3
767     utf8.clear();
768     utf8 += char(0x80);
769     utf8 += char(0xbf);
770     str = fromInvalidUtf8Sequence(utf8);
771     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.3") << utf8 << str << -1;
772
773     // 3.1.4
774     utf8.clear();
775     utf8 += char(0x80);
776     utf8 += char(0xbf);
777     utf8 += char(0x80);
778     str = fromInvalidUtf8Sequence(utf8);
779     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.4") << utf8 << str << -1;
780
781     // 3.1.5
782     utf8.clear();
783     utf8 += char(0x80);
784     utf8 += char(0xbf);
785     utf8 += char(0x80);
786     utf8 += char(0xbf);
787     str = fromInvalidUtf8Sequence(utf8);
788     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.5") << utf8 << str << -1;
789
790     // 3.1.6
791     utf8.clear();
792     utf8 += char(0x80);
793     utf8 += char(0xbf);
794     utf8 += char(0x80);
795     utf8 += char(0xbf);
796     utf8 += char(0x80);
797     str = fromInvalidUtf8Sequence(utf8);
798     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.6") << utf8 << str << -1;
799
800     // 3.1.7
801     utf8.clear();
802     utf8 += char(0x80);
803     utf8 += char(0xbf);
804     utf8 += char(0x80);
805     utf8 += char(0xbf);
806     utf8 += char(0x80);
807     utf8 += char(0xbf);
808     str = fromInvalidUtf8Sequence(utf8);
809     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.7") << utf8 << str << -1;
810
811     // 3.1.8
812     utf8.clear();
813     utf8 += char(0x80);
814     utf8 += char(0xbf);
815     utf8 += char(0x80);
816     utf8 += char(0xbf);
817     utf8 += char(0x80);
818     utf8 += char(0xbf);
819     utf8 += char(0x80);
820     str = fromInvalidUtf8Sequence(utf8);
821     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.8") << utf8 << str << -1;
822
823     // 3.1.9
824     utf8.clear();
825     for (uint i = 0x80; i<= 0xbf; ++i)
826         utf8 += i;
827     str = fromInvalidUtf8Sequence(utf8);
828     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.9") << utf8 << str << -1;
829
830     // 3.2.1
831     utf8.clear();
832     str.clear();
833     for (uint i = 0xc8; i <= 0xdf; ++i) {
834         utf8 += i;
835         utf8 += char(0x20);
836
837         str += QChar::ReplacementCharacter;
838         str += QChar(0x0020);
839     }
840     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.2.1") << utf8 << str << -1;
841
842     // 3.2.2
843     utf8.clear();
844     str.clear();
845     for (uint i = 0xe0; i <= 0xef; ++i) {
846         utf8 += i;
847         utf8 += char(0x20);
848
849         str += QChar::ReplacementCharacter;
850         str += QChar(0x0020);
851     }
852     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.2.2") << utf8 << str << -1;
853
854     // 3.2.3
855     utf8.clear();
856     str.clear();
857     for (uint i = 0xf0; i <= 0xf7; ++i) {
858         utf8 += i;
859         utf8 += 0x20;
860
861         str += QChar::ReplacementCharacter;
862         str += QChar(0x0020);
863     }
864     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.2.3") << utf8 << str << -1;
865
866     // 3.2.4
867     utf8.clear();
868     str.clear();
869     for (uint i = 0xf8; i <= 0xfb; ++i) {
870         utf8 += i;
871         utf8 += 0x20;
872
873         str += QChar::ReplacementCharacter;
874         str += QChar(0x0020);
875     }
876     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.2.4") << utf8 << str << -1;
877
878     // 3.2.5
879     utf8.clear();
880     str.clear();
881     for (uint i = 0xfc; i <= 0xfd; ++i) {
882         utf8 += i;
883         utf8 += 0x20;
884
885         str += QChar::ReplacementCharacter;
886         str += QChar(0x0020);
887     }
888     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.2.5") << utf8 << str << -1;
889
890     // 3.3.1
891     utf8.clear();
892     utf8 += char(0xc0);
893     str = fromInvalidUtf8Sequence(utf8);
894     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.1") << utf8 << str << -1;
895     utf8 += char(0x30);
896     str += 0x30;
897     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.1-1") << utf8 << str << -1;
898
899     // 3.3.2
900     utf8.clear();
901     utf8 += char(0xe0);
902     utf8 += char(0x80);
903     str = fromInvalidUtf8Sequence(utf8);
904     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2") << utf8 << str << -1;
905     utf8 += char(0x30);
906     str += 0x30;
907     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2-1") << utf8 << str << -1;
908
909     utf8.clear();
910     utf8 += char(0xe0);
911     str = fromInvalidUtf8Sequence(utf8);
912     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2-2") << utf8 << str << -1;
913     utf8 += 0x30;
914     str += 0x30;
915     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2-3") << utf8 << str << -1;
916
917     // 3.3.3
918     utf8.clear();
919     utf8 += char(0xf0);
920     utf8 += char(0x80);
921     utf8 += char(0x80);
922     str = fromInvalidUtf8Sequence(utf8);
923     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3") << utf8 << str << -1;
924     utf8 += char(0x30);
925     str += 0x30;
926     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-1") << utf8 << str << -1;
927
928     utf8.clear();
929     utf8 += char(0xf0);
930     str = fromInvalidUtf8Sequence(utf8);
931     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-2") << 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.3-3") << utf8 << str << -1;
935
936     utf8.clear();
937     utf8 += char(0xf0);
938     utf8 += char(0x80);
939     str = fromInvalidUtf8Sequence(utf8);
940     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-4") << utf8 << str << -1;
941     utf8 += char(0x30);
942     str += 0x30;
943     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-5") << utf8 << str << -1;
944
945     // 3.3.4
946     utf8.clear();
947     utf8 += char(0xf8);
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.4") << 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.4-1") << utf8 << str << -1;
956
957     utf8.clear();
958     utf8 += char(0xf8);
959     utf8 += char(0x80);
960     utf8 += char(0x80);
961     str = fromInvalidUtf8Sequence(utf8);
962     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-2") << utf8 << str << -1;
963     utf8 += char(0x30);
964     str += 0x30;
965     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-3") << utf8 << str << -1;
966
967     utf8.clear();
968     utf8 += char(0xf8);
969     utf8 += char(0x80);
970     str = fromInvalidUtf8Sequence(utf8);
971     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-4") << utf8 << str << -1;
972     utf8 += char(0x30);
973     str += 0x30;
974     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-5") << utf8 << str << -1;
975
976     utf8.clear();
977     utf8 += char(0xf8);
978     str = fromInvalidUtf8Sequence(utf8);
979     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-6") << utf8 << str << -1;
980     utf8 += char(0x30);
981     str += 0x30;
982     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-7") << utf8 << str << -1;
983
984     // 3.3.5
985     utf8.clear();
986     utf8 += char(0xfc);
987     utf8 += char(0x80);
988     utf8 += char(0x80);
989     utf8 += char(0x80);
990     utf8 += char(0x80);
991     str = fromInvalidUtf8Sequence(utf8);
992     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5") << utf8 << str << -1;
993     utf8 += char(0x30);
994     str += 0x30;
995     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-1") << utf8 << str << -1;
996
997     utf8.clear();
998     utf8 += char(0xfc);
999     utf8 += char(0x80);
1000     utf8 += char(0x80);
1001     utf8 += char(0x80);
1002     str = fromInvalidUtf8Sequence(utf8);
1003     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-2") << utf8 << str << -1;
1004     utf8 += char(0x30);
1005     str += 0x30;
1006     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-3") << utf8 << str << -1;
1007
1008     utf8.clear();
1009     utf8 += char(0xfc);
1010     utf8 += char(0x80);
1011     utf8 += char(0x80);
1012     str = fromInvalidUtf8Sequence(utf8);
1013     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-4") << utf8 << str << -1;
1014     utf8 += char(0x30);
1015     str += 0x30;
1016     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-5") << utf8 << str << -1;
1017
1018     utf8.clear();
1019     utf8 += char(0xfc);
1020     utf8 += char(0x80);
1021     str = fromInvalidUtf8Sequence(utf8);
1022     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-6") << utf8 << str << -1;
1023     utf8 += char(0x30);
1024     str += 0x30;
1025     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-7") << utf8 << str << -1;
1026
1027     utf8.clear();
1028     utf8 += char(0xfc);
1029     str = fromInvalidUtf8Sequence(utf8);
1030     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-8") << utf8 << str << -1;
1031     utf8 += char(0x30);
1032     str += 0x30;
1033     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-9") << utf8 << str << -1;
1034
1035     // 3.3.6
1036     utf8.clear();
1037     utf8 += char(0xdf);
1038     str = fromInvalidUtf8Sequence(utf8);
1039     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.6") << utf8 << str << -1;
1040     utf8 += char(0x30);
1041     str += 0x30;
1042     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.6-1") << utf8 << str << -1;
1043
1044     // 3.3.7
1045     utf8.clear();
1046     utf8 += char(0xef);
1047     utf8 += char(0xbf);
1048     str = fromInvalidUtf8Sequence(utf8);
1049     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.7") << utf8 << str << -1;
1050     utf8 += char(0x30);
1051     str += 0x30;
1052     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.7-1") << utf8 << str << -1;
1053
1054     utf8.clear();
1055     utf8 += char(0xef);
1056     str = fromInvalidUtf8Sequence(utf8);
1057     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.7-2") << 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.7-3") << utf8 << str << -1;
1061
1062     // 3.3.8
1063     utf8.clear();
1064     utf8 += char(0xf7);
1065     utf8 += char(0xbf);
1066     utf8 += char(0xbf);
1067     str = fromInvalidUtf8Sequence(utf8);
1068     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8") << utf8 << str << -1;
1069     utf8 += char(0x30);
1070     str += 0x30;
1071     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-1") << utf8 << str << -1;
1072
1073     utf8.clear();
1074     utf8 += char(0xf7);
1075     utf8 += char(0xbf);
1076     str = fromInvalidUtf8Sequence(utf8);
1077     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-2") << utf8 << str << -1;
1078     utf8 += char(0x30);
1079     str += 0x30;
1080     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-3") << utf8 << str << -1;
1081
1082     utf8.clear();
1083     utf8 += char(0xf7);
1084     str = fromInvalidUtf8Sequence(utf8);
1085     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-4") << utf8 << str << -1;
1086     utf8 += char(0x30);
1087     str += 0x30;
1088     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-5") << utf8 << str << -1;
1089
1090     // 3.3.9
1091     utf8.clear();
1092     utf8 += char(0xfb);
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.9") << 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.9-1") << utf8 << str << -1;
1101
1102     utf8.clear();
1103     utf8 += char(0xfb);
1104     utf8 += char(0xbf);
1105     utf8 += char(0xbf);
1106     str = fromInvalidUtf8Sequence(utf8);
1107     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-2") << utf8 << str << -1;
1108     utf8 += char(0x30);
1109     str += 0x30;
1110     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-3") << utf8 << str << -1;
1111
1112     utf8.clear();
1113     utf8 += char(0xfb);
1114     utf8 += char(0xbf);
1115     str = fromInvalidUtf8Sequence(utf8);
1116     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-4") << utf8 << str << -1;
1117     utf8 += char(0x30);
1118     str += 0x30;
1119     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-5") << utf8 << str << -1;
1120
1121     utf8.clear();
1122     utf8 += char(0xfb);
1123     str = fromInvalidUtf8Sequence(utf8);
1124     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-6") << utf8 << str << -1;
1125     utf8 += char(0x30);
1126     str += 0x30;
1127     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-7") << utf8 << str << -1;
1128
1129     // 3.3.10
1130     utf8.clear();
1131     utf8 += char(0xfd);
1132     utf8 += char(0xbf);
1133     utf8 += char(0xbf);
1134     utf8 += char(0xbf);
1135     utf8 += char(0xbf);
1136     str = fromInvalidUtf8Sequence(utf8);
1137     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10") << utf8 << str << -1;
1138     utf8 += char(0x30);
1139     str += 0x30;
1140     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-1") << utf8 << str << -1;
1141
1142     utf8.clear();
1143     utf8 += char(0xfd);
1144     utf8 += char(0xbf);
1145     utf8 += char(0xbf);
1146     utf8 += char(0xbf);
1147     str = fromInvalidUtf8Sequence(utf8);
1148     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-2") << utf8 << str << -1;
1149     utf8 += char(0x30);
1150     str += 0x30;
1151     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-3") << utf8 << str << -1;
1152
1153     utf8.clear();
1154     utf8 += char(0xfd);
1155     utf8 += char(0xbf);
1156     utf8 += char(0xbf);
1157     str = fromInvalidUtf8Sequence(utf8);
1158     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-4") << utf8 << str << -1;
1159     utf8 += char(0x30);
1160     str += 0x30;
1161     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-5") << utf8 << str << -1;
1162
1163     utf8.clear();
1164     utf8 += char(0xfd);
1165     utf8 += char(0xbf);
1166     str = fromInvalidUtf8Sequence(utf8);
1167     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-6") << utf8 << str << -1;
1168     utf8 += char(0x30);
1169     str += 0x30;
1170     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-7") << utf8 << str << -1;
1171
1172     utf8.clear();
1173     utf8 += char(0xfd);
1174     str = fromInvalidUtf8Sequence(utf8);
1175     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-8") << utf8 << str << -1;
1176     utf8 += char(0x30);
1177     str += 0x30;
1178     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-9") << utf8 << str << -1;
1179
1180     // 3.4
1181     utf8.clear();
1182     utf8 += char(0xc0);
1183     utf8 += char(0xe0);
1184     utf8 += char(0x80);
1185     utf8 += char(0xf0);
1186     utf8 += char(0x80);
1187     utf8 += char(0x80);
1188     utf8 += char(0xf8);
1189     utf8 += char(0x80);
1190     utf8 += char(0x80);
1191     utf8 += char(0x80);
1192     utf8 += char(0xfc);
1193     utf8 += char(0x80);
1194     utf8 += char(0x80);
1195     utf8 += char(0x80);
1196     utf8 += char(0x80);
1197     utf8 += char(0xdf);
1198     utf8 += char(0xef);
1199     utf8 += char(0xbf);
1200     utf8 += char(0xf7);
1201     utf8 += char(0xbf);
1202     utf8 += char(0xbf);
1203     utf8 += char(0xfb);
1204     utf8 += char(0xbf);
1205     utf8 += char(0xbf);
1206     utf8 += char(0xbf);
1207     utf8 += char(0xfd);
1208     utf8 += char(0xbf);
1209     utf8 += char(0xbf);
1210     utf8 += char(0xbf);
1211     utf8 += char(0xbf);
1212     str = fromInvalidUtf8Sequence(utf8);
1213     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.4") << utf8 << str << -1;
1214
1215     // 3.5.1
1216     utf8.clear();
1217     utf8 += char(0xfe);
1218     str = fromInvalidUtf8Sequence(utf8);
1219     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.5.1") << utf8 << str << -1;
1220
1221     // 3.5.2
1222     utf8.clear();
1223     utf8 += char(0xff);
1224     str = fromInvalidUtf8Sequence(utf8);
1225     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.5.1") << utf8 << str << -1;
1226
1227     // 3.5.2
1228     utf8.clear();
1229     utf8 += char(0xfe);
1230     utf8 += char(0xfe);
1231     utf8 += char(0xff);
1232     str = fromInvalidUtf8Sequence(utf8);
1233     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.5.1") << utf8 << str << -1;
1234
1235     // 4.1.1
1236     utf8.clear();
1237     utf8 += char(0xc0);
1238     utf8 += char(0xaf);
1239     str = QChar(QChar::ReplacementCharacter);
1240     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.1.1") << utf8 << str << -1;
1241
1242     // 4.1.2
1243     utf8.clear();
1244     utf8 += char(0xe0);
1245     utf8 += char(0x80);
1246     utf8 += char(0xaf);
1247     str = QChar(QChar::ReplacementCharacter);
1248     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.1.2") << utf8 << str << -1;
1249
1250     // 4.1.3
1251     utf8.clear();
1252     utf8 += char(0xf0);
1253     utf8 += char(0x80);
1254     utf8 += char(0x80);
1255     utf8 += char(0xaf);
1256     str = QChar(QChar::ReplacementCharacter);
1257     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.1.3") << utf8 << str << -1;
1258
1259     // 4.1.4
1260     utf8.clear();
1261     utf8 += char(0xf8);
1262     utf8 += char(0x80);
1263     utf8 += char(0x80);
1264     utf8 += char(0x80);
1265     utf8 += char(0xaf);
1266     str = fromInvalidUtf8Sequence(utf8);
1267     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.1.4") << utf8 << str << -1;
1268
1269     // 4.1.5
1270     utf8.clear();
1271     utf8 += char(0xfc);
1272     utf8 += char(0x80);
1273     utf8 += char(0x80);
1274     utf8 += char(0x80);
1275     utf8 += char(0x80);
1276     utf8 += char(0xaf);
1277     str = fromInvalidUtf8Sequence(utf8);
1278     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.1.5") << utf8 << str << -1;
1279
1280     // 4.2.1
1281     utf8.clear();
1282     utf8 += char(0xc1);
1283     utf8 += char(0xbf);
1284     str = QChar(QChar::ReplacementCharacter);
1285     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.2.1") << utf8 << str << -1;
1286
1287     // 4.2.2
1288     utf8.clear();
1289     utf8 += char(0xe0);
1290     utf8 += char(0x9f);
1291     utf8 += char(0xbf);
1292     str = QChar(QChar::ReplacementCharacter);
1293     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.2.2") << utf8 << str << -1;
1294
1295     // 4.2.3
1296     utf8.clear();
1297     utf8 += char(0xf0);
1298     utf8 += char(0x8f);
1299     utf8 += char(0xbf);
1300     utf8 += char(0xbf);
1301     str = QChar(QChar::ReplacementCharacter);
1302     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.2.3") << utf8 << str << -1;
1303
1304     // 4.2.4
1305     utf8.clear();
1306     utf8 += char(0xf8);
1307     utf8 += char(0x87);
1308     utf8 += char(0xbf);
1309     utf8 += char(0xbf);
1310     utf8 += char(0xbf);
1311     str = fromInvalidUtf8Sequence(utf8);
1312     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.2.4") << utf8 << str << -1;
1313
1314     // 4.2.5
1315     utf8.clear();
1316     utf8 += char(0xfc);
1317     utf8 += char(0x83);
1318     utf8 += char(0xbf);
1319     utf8 += char(0xbf);
1320     utf8 += char(0xbf);
1321     utf8 += char(0xbf);
1322     str = fromInvalidUtf8Sequence(utf8);
1323     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.2.5") << utf8 << str << -1;
1324
1325     // 4.3.1
1326     utf8.clear();
1327     utf8 += char(0xc0);
1328     utf8 += char(0x80);
1329     str = QChar(QChar::ReplacementCharacter);
1330     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.3.1") << utf8 << str << -1;
1331
1332     // 4.3.2
1333     utf8.clear();
1334     utf8 += char(0xe0);
1335     utf8 += char(0x80);
1336     utf8 += char(0x80);
1337     str = QChar(QChar::ReplacementCharacter);
1338     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.3.2") << utf8 << str << -1;
1339
1340     // 4.3.3
1341     utf8.clear();
1342     utf8 += char(0xf0);
1343     utf8 += char(0x80);
1344     utf8 += char(0x80);
1345     utf8 += char(0x80);
1346     str = QChar(QChar::ReplacementCharacter);
1347     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.3.3") << utf8 << str << -1;
1348
1349     // 4.3.4
1350     utf8.clear();
1351     utf8 += char(0xf8);
1352     utf8 += char(0x80);
1353     utf8 += char(0x80);
1354     utf8 += char(0x80);
1355     utf8 += char(0x80);
1356     str = fromInvalidUtf8Sequence(utf8);
1357     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.3.4") << utf8 << str << -1;
1358
1359     // 4.3.5
1360     utf8.clear();
1361     utf8 += char(0xfc);
1362     utf8 += char(0x80);
1363     utf8 += char(0x80);
1364     utf8 += char(0x80);
1365     utf8 += char(0x80);
1366     utf8 += char(0x80);
1367     str = fromInvalidUtf8Sequence(utf8);
1368     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.3.5") << utf8 << str << -1;
1369
1370     // 5.1.1
1371     utf8.clear();
1372     utf8 += char(0xed);
1373     utf8 += char(0xa0);
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.1") << utf8 << str << -1;
1377
1378     // 5.1.2
1379     utf8.clear();
1380     utf8 += char(0xed);
1381     utf8 += char(0xad);
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.2") << utf8 << str << -1;
1385
1386     // 5.1.3
1387     utf8.clear();
1388     utf8 += char(0xed);
1389     utf8 += char(0xae);
1390     utf8 += char(0x80);
1391     str = QChar(QChar::ReplacementCharacter);
1392     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.3") << utf8 << str << -1;
1393
1394     // 5.1.4
1395     utf8.clear();
1396     utf8 += char(0xed);
1397     utf8 += char(0xaf);
1398     utf8 += char(0xbf);
1399     str = QChar(QChar::ReplacementCharacter);
1400     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.4") << utf8 << str << -1;
1401
1402     // 5.1.5
1403     utf8.clear();
1404     utf8 += char(0xed);
1405     utf8 += char(0xb0);
1406     utf8 += char(0x80);
1407     str = QChar(QChar::ReplacementCharacter);
1408     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.5") << utf8 << str << -1;
1409
1410     // 5.1.6
1411     utf8.clear();
1412     utf8 += char(0xed);
1413     utf8 += char(0xbe);
1414     utf8 += char(0x80);
1415     str = QChar(QChar::ReplacementCharacter);
1416     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.6") << utf8 << str << -1;
1417
1418     // 5.1.7
1419     utf8.clear();
1420     utf8 += char(0xed);
1421     utf8 += char(0xbf);
1422     utf8 += char(0xbf);
1423     str = QChar(QChar::ReplacementCharacter);
1424     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.7") << utf8 << str << -1;
1425
1426     // 5.2.1
1427     utf8.clear();
1428     utf8 += char(0xed);
1429     utf8 += char(0xa0);
1430     utf8 += char(0x80);
1431     utf8 += char(0xed);
1432     utf8 += char(0xb0);
1433     utf8 += char(0x80);
1434     str.clear();
1435     str += QChar(QChar::ReplacementCharacter);
1436     str += QChar(QChar::ReplacementCharacter);
1437     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.1") << utf8 << str << -1;
1438
1439     // 5.2.2
1440     utf8.clear();
1441     utf8 += char(0xed);
1442     utf8 += char(0xa0);
1443     utf8 += char(0x80);
1444     utf8 += char(0xed);
1445     utf8 += char(0xbf);
1446     utf8 += char(0xbf);
1447     str.clear();
1448     str += QChar(QChar::ReplacementCharacter);
1449     str += QChar(QChar::ReplacementCharacter);
1450     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.2") << utf8 << str << -1;
1451
1452     // 5.2.3
1453     utf8.clear();
1454     utf8 += char(0xed);
1455     utf8 += char(0xad);
1456     utf8 += char(0xbf);
1457     utf8 += char(0xed);
1458     utf8 += char(0xb0);
1459     utf8 += char(0x80);
1460     str.clear();
1461     str += QChar(QChar::ReplacementCharacter);
1462     str += QChar(QChar::ReplacementCharacter);
1463     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.3") << utf8 << str << -1;
1464
1465     // 5.2.4
1466     utf8.clear();
1467     utf8 += char(0xed);
1468     utf8 += char(0xad);
1469     utf8 += char(0xbf);
1470     utf8 += char(0xed);
1471     utf8 += char(0xbf);
1472     utf8 += char(0xbf);
1473     str.clear();
1474     str += QChar(QChar::ReplacementCharacter);
1475     str += QChar(QChar::ReplacementCharacter);
1476     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.4") << utf8 << str << -1;
1477
1478     // 5.2.5
1479     utf8.clear();
1480     utf8 += char(0xed);
1481     utf8 += char(0xae);
1482     utf8 += char(0x80);
1483     utf8 += char(0xed);
1484     utf8 += char(0xb0);
1485     utf8 += char(0x80);
1486     str.clear();
1487     str += QChar(QChar::ReplacementCharacter);
1488     str += QChar(QChar::ReplacementCharacter);
1489     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.5") << utf8 << str << -1;
1490
1491     // 5.2.6
1492     utf8.clear();
1493     utf8 += char(0xed);
1494     utf8 += char(0xae);
1495     utf8 += char(0x80);
1496     utf8 += char(0xed);
1497     utf8 += char(0xbf);
1498     utf8 += char(0xbf);
1499     str.clear();
1500     str += QChar(QChar::ReplacementCharacter);
1501     str += QChar(QChar::ReplacementCharacter);
1502     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.6") << utf8 << str << -1;
1503
1504     // 5.2.7
1505     utf8.clear();
1506     utf8 += char(0xed);
1507     utf8 += char(0xaf);
1508     utf8 += char(0xbf);
1509     utf8 += char(0xed);
1510     utf8 += char(0xb0);
1511     utf8 += char(0x80);
1512     str.clear();
1513     str += QChar(QChar::ReplacementCharacter);
1514     str += QChar(QChar::ReplacementCharacter);
1515     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.7") << utf8 << str << -1;
1516
1517     // 5.2.8
1518     utf8.clear();
1519     utf8 += char(0xed);
1520     utf8 += char(0xaf);
1521     utf8 += char(0xbf);
1522     utf8 += char(0xed);
1523     utf8 += char(0xbf);
1524     utf8 += char(0xbf);
1525     str.clear();
1526     str += QChar(QChar::ReplacementCharacter);
1527     str += QChar(QChar::ReplacementCharacter);
1528     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.8") << utf8 << str << -1;
1529
1530     // 5.3.1
1531     utf8.clear();
1532     utf8 += char(0xef);
1533     utf8 += char(0xbf);
1534     utf8 += char(0xbe);
1535     str = QChar(QChar::ReplacementCharacter);
1536     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.3.1") << utf8 << str << -1;
1537
1538     // 5.3.2
1539     utf8.clear();
1540     utf8 += char(0xef);
1541     utf8 += char(0xbf);
1542     utf8 += char(0xbf);
1543     str = QChar(QChar::ReplacementCharacter);
1544     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.3.2") << utf8 << str << -1;
1545 }
1546
1547 void tst_QTextCodec::utf8Codec()
1548 {
1549     QTextCodec *codec = QTextCodec::codecForMib(106); // UTF-8
1550     QVERIFY(codec != 0);
1551
1552     QFETCH(QByteArray, utf8);
1553     QFETCH(QString, res);
1554     QFETCH(int, len);
1555
1556     QString str = codec->toUnicode(utf8.isNull() ? 0 : utf8.constData(),
1557                                    len < 0 ? qstrlen(utf8.constData()) : len);
1558     QCOMPARE(str, res);
1559
1560     str = QString::fromUtf8(utf8.isNull() ? 0 : utf8.constData(), len);
1561     QCOMPARE(str, res);
1562 }
1563
1564 void tst_QTextCodec::utf8bom_data()
1565 {
1566     QTest::addColumn<QByteArray>("data");
1567     QTest::addColumn<QString>("result");
1568
1569     QTest::newRow("nobom")
1570         << QByteArray("\302\240", 2)
1571         << QString("\240");
1572
1573     {
1574         static const ushort data[] = { 0x201d };
1575         QTest::newRow("nobom 2")
1576             << QByteArray("\342\200\235", 3)
1577             << QString::fromUtf16(data, sizeof(data)/sizeof(short));
1578     }
1579
1580     {
1581         static const ushort data[] = { 0xf000 };
1582         QTest::newRow("bom1")
1583             << QByteArray("\357\200\200", 3)
1584             << QString::fromUtf16(data, sizeof(data)/sizeof(short));
1585     }
1586
1587     {
1588         static const ushort data[] = { 0xfec0 };
1589         QTest::newRow("bom2")
1590             << QByteArray("\357\273\200", 3)
1591             << QString::fromUtf16(data, sizeof(data)/sizeof(short));
1592     }
1593
1594     {
1595         QTest::newRow("normal-bom")
1596             << QByteArray("\357\273\277a", 4)
1597             << QString("a");
1598     }
1599
1600     {
1601         static const ushort data[] = { 0x61, 0xfeff, 0x62 };
1602         QTest::newRow("middle-bom")
1603             << QByteArray("a\357\273\277b", 5)
1604             << QString::fromUtf16(data, sizeof(data)/sizeof(short));
1605     }
1606 }
1607
1608 void tst_QTextCodec::utf8bom()
1609 {
1610     QFETCH(QByteArray, data);
1611     QFETCH(QString, result);
1612
1613     QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8
1614     QVERIFY(codec);
1615
1616     QCOMPARE(codec->toUnicode(data.constData(), data.length(), 0), result);
1617
1618     QTextCodec::ConverterState state;
1619     QCOMPARE(codec->toUnicode(data.constData(), data.length(), &state), result);
1620 }
1621
1622 void tst_QTextCodec::utfHeaders_data()
1623 {
1624     QTest::addColumn<QByteArray>("codecName");
1625     QTest::addColumn<int>("flags");
1626     QTest::addColumn<QByteArray>("encoded");
1627     QTest::addColumn<QString>("unicode");
1628     QTest::addColumn<bool>("toUnicode");
1629
1630     QTest::newRow("utf8 bom")
1631         << QByteArray("UTF-8")
1632         << 0
1633         << QByteArray("\xef\xbb\xbfhello")
1634         << QString::fromLatin1("hello")
1635         << true;
1636     QTest::newRow("utf8 nobom")
1637         << QByteArray("UTF-8")
1638         << 0
1639         << QByteArray("hello")
1640         << QString::fromLatin1("hello")
1641         << true;
1642     QTest::newRow("utf8 bom ignore header")
1643         << QByteArray("UTF-8")
1644         << (int)QTextCodec::IgnoreHeader
1645         << QByteArray("\xef\xbb\xbfhello")
1646         << (QString(QChar(0xfeff)) + QString::fromLatin1("hello"))
1647         << true;
1648     QTest::newRow("utf8 nobom ignore header")
1649         << QByteArray("UTF-8")
1650         << (int)QTextCodec::IgnoreHeader
1651         << QByteArray("hello")
1652         << QString::fromLatin1("hello")
1653         << true;
1654
1655     QTest::newRow("utf16 bom be")
1656         << QByteArray("UTF-16")
1657         << 0
1658         << QByteArray("\xfe\xff\0h\0e\0l", 8)
1659         << QString::fromLatin1("hel")
1660         << true;
1661     QTest::newRow("utf16 bom le")
1662         << QByteArray("UTF-16")
1663         << 0
1664         << QByteArray("\xff\xfeh\0e\0l\0", 8)
1665         << QString::fromLatin1("hel")
1666         << true;
1667     if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
1668         QTest::newRow("utf16 nobom")
1669             << QByteArray("UTF-16")
1670             << 0
1671             << QByteArray("\0h\0e\0l", 6)
1672             << QString::fromLatin1("hel")
1673             << true;
1674         QTest::newRow("utf16 bom be ignore header")
1675             << QByteArray("UTF-16")
1676             << (int)QTextCodec::IgnoreHeader
1677             << QByteArray("\xfe\xff\0h\0e\0l", 8)
1678             << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1679             << true;
1680     } else {
1681         QTest::newRow("utf16 nobom")
1682             << QByteArray("UTF-16")
1683             << 0
1684             << QByteArray("h\0e\0l\0", 6)
1685             << QString::fromLatin1("hel")
1686             << true;
1687         QTest::newRow("utf16 bom le ignore header")
1688             << QByteArray("UTF-16")
1689             << (int)QTextCodec::IgnoreHeader
1690             << QByteArray("\xff\xfeh\0e\0l\0", 8)
1691             << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1692             << true;
1693     }
1694
1695     QTest::newRow("utf16-be bom be")
1696         << QByteArray("UTF-16BE")
1697         << 0
1698         << QByteArray("\xfe\xff\0h\0e\0l", 8)
1699         << QString::fromLatin1("hel")
1700         << true;
1701     QTest::newRow("utf16-be nobom")
1702         << QByteArray("UTF-16BE")
1703         << 0
1704         << QByteArray("\0h\0e\0l", 6)
1705         << QString::fromLatin1("hel")
1706         << true;
1707     QTest::newRow("utf16-be bom be ignore header")
1708         << QByteArray("UTF-16BE")
1709         << (int)QTextCodec::IgnoreHeader
1710         << QByteArray("\xfe\xff\0h\0e\0l", 8)
1711         << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1712         << true;
1713
1714     QTest::newRow("utf16-le bom le")
1715         << QByteArray("UTF-16LE")
1716         << 0
1717         << QByteArray("\xff\xfeh\0e\0l\0", 8)
1718         << QString::fromLatin1("hel")
1719         << true;
1720     QTest::newRow("utf16-le nobom")
1721         << QByteArray("UTF-16LE")
1722         << 0
1723         << QByteArray("h\0e\0l\0", 6)
1724         << QString::fromLatin1("hel")
1725         << true;
1726     QTest::newRow("utf16-le bom le ignore header")
1727         << QByteArray("UTF-16LE")
1728         << (int)QTextCodec::IgnoreHeader
1729         << QByteArray("\xff\xfeh\0e\0l\0", 8)
1730         << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1731         << true;
1732
1733
1734     QTest::newRow("utf32 bom be")
1735         << QByteArray("UTF-32")
1736         << 0
1737         << QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16)
1738         << QString::fromLatin1("hel")
1739         << true;
1740     QTest::newRow("utf32 bom le")
1741         << QByteArray("UTF-32")
1742         << 0
1743         << QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16)
1744         << QString::fromLatin1("hel")
1745         << true;
1746     if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
1747         QTest::newRow("utf32 nobom")
1748             << QByteArray("UTF-32")
1749             << 0
1750             << QByteArray("\0\0\0h\0\0\0e\0\0\0l", 12)
1751             << QString::fromLatin1("hel")
1752             << true;
1753         QTest::newRow("utf32 bom be ignore header")
1754             << QByteArray("UTF-32")
1755             << (int)QTextCodec::IgnoreHeader
1756             << QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16)
1757             << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1758             << true;
1759     } else {
1760         QTest::newRow("utf32 nobom")
1761             << QByteArray("UTF-32")
1762             << 0
1763             << QByteArray("h\0\0\0e\0\0\0l\0\0\0", 12)
1764             << QString::fromLatin1("hel")
1765             << true;
1766         QTest::newRow("utf32 bom le ignore header")
1767             << QByteArray("UTF-32")
1768             << (int)QTextCodec::IgnoreHeader
1769             << QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16)
1770             << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1771             << true;
1772     }
1773
1774
1775     QTest::newRow("utf32-be bom be")
1776         << QByteArray("UTF-32BE")
1777         << 0
1778         << QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16)
1779         << QString::fromLatin1("hel")
1780         << true;
1781     QTest::newRow("utf32-be nobom")
1782         << QByteArray("UTF-32BE")
1783         << 0
1784         << QByteArray("\0\0\0h\0\0\0e\0\0\0l", 12)
1785         << QString::fromLatin1("hel")
1786         << true;
1787     QTest::newRow("utf32-be bom be ignore header")
1788         << QByteArray("UTF-32BE")
1789         << (int)QTextCodec::IgnoreHeader
1790         << QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16)
1791         << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1792         << true;
1793
1794
1795     QTest::newRow("utf32-le bom le")
1796         << QByteArray("UTF-32LE")
1797         << 0
1798         << QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16)
1799         << QString::fromLatin1("hel")
1800         << true;
1801     QTest::newRow("utf32-le nobom")
1802         << QByteArray("UTF-32LE")
1803         << 0
1804         << QByteArray("h\0\0\0e\0\0\0l\0\0\0", 12)
1805         << QString::fromLatin1("hel")
1806         << true;
1807     QTest::newRow("utf32-le bom le ignore header")
1808         << QByteArray("UTF-32LE")
1809         << (int)QTextCodec::IgnoreHeader
1810         << QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16)
1811         << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1812         << true;
1813 }
1814
1815 void tst_QTextCodec::utfHeaders()
1816 {
1817     QFETCH(QByteArray, codecName);
1818     QTextCodec *codec = QTextCodec::codecForName(codecName);
1819     QVERIFY(codec != 0);
1820
1821     QFETCH(int, flags);
1822     QTextCodec::ConversionFlags cFlags = QTextCodec::ConversionFlags(flags);
1823     QTextCodec::ConverterState state(cFlags);
1824
1825     QFETCH(QByteArray, encoded);
1826     QFETCH(QString, unicode);
1827
1828     QFETCH(bool, toUnicode);
1829
1830     QLatin1String ignoreReverseTestOn = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? QLatin1String(" le") : QLatin1String(" be");
1831     QString rowName(QTest::currentDataTag());
1832
1833     if (toUnicode) {
1834         QString result = codec->toUnicode(encoded.constData(), encoded.length(), &state);
1835         QCOMPARE(result.length(), unicode.length());
1836         QCOMPARE(result, unicode);
1837
1838         if (!rowName.endsWith("nobom") && !rowName.contains(ignoreReverseTestOn)) {
1839             QTextCodec::ConverterState state2(cFlags);
1840             QByteArray reencoded = codec->fromUnicode(unicode.unicode(), unicode.length(), &state2);
1841             QCOMPARE(reencoded, encoded);
1842         }
1843     } else {
1844         QByteArray result = codec->fromUnicode(unicode.unicode(), unicode.length(), &state);
1845         QCOMPARE(result, encoded);
1846     }
1847 }
1848
1849 void tst_QTextCodec::codecForHtml()
1850 {
1851     QByteArray html("<html><head></head><body>blah</body></html>");
1852
1853     QCOMPARE(QTextCodec::codecForHtml(html)->mibEnum(), 4); // latin 1
1854
1855     QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 106); // UTF-8
1856
1857     html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-15\" /></head></html>";
1858     QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 111); // latin 15
1859
1860     html = "<html><head><meta content=\"text/html; charset=ISO-8859-15\" http-equiv=\"content-type\" /></head></html>";
1861     QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 111); // latin 15
1862
1863     html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=invalid-foo\" /></head></html>";
1864     QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 106); // UTF-8
1865     QCOMPARE(QTextCodec::codecForHtml(html)->mibEnum(), 4); // latin 1
1866 }
1867
1868 void tst_QTextCodec::codecForUtfText_data()
1869 {
1870     QTest::addColumn<QByteArray>("encoded");
1871     QTest::addColumn<bool>("detected");
1872     QTest::addColumn<int>("mib");
1873
1874
1875     QTest::newRow("utf8 bom")
1876         << QByteArray("\xef\xbb\xbfhello")
1877         << true
1878         << 106;
1879     QTest::newRow("utf8 nobom")
1880         << QByteArray("hello")
1881         << false
1882         << 0;
1883
1884     QTest::newRow("utf16 bom be")
1885         << QByteArray("\xfe\xff\0h\0e\0l", 8)
1886         << true
1887         << 1013;
1888     QTest::newRow("utf16 bom le")
1889         << QByteArray("\xff\xfeh\0e\0l\0", 8)
1890         << true
1891         << 1014;
1892     QTest::newRow("utf16 nobom")
1893         << QByteArray("\0h\0e\0l", 6)
1894         << false
1895         << 0;
1896
1897     QTest::newRow("utf32 bom be")
1898         << QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16)
1899         << true
1900         << 1018;
1901     QTest::newRow("utf32 bom le")
1902         << QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16)
1903         << true
1904         << 1019;
1905     QTest::newRow("utf32 nobom")
1906         << QByteArray("\0\0\0h\0\0\0e\0\0\0l", 12)
1907         << false
1908         << 0;
1909 }
1910
1911 void tst_QTextCodec::codecForUtfText()
1912 {
1913     QFETCH(QByteArray, encoded);
1914     QFETCH(bool, detected);
1915     QFETCH(int, mib);
1916
1917     QTextCodec *codec = QTextCodec::codecForUtfText(encoded, 0);
1918     if (detected)
1919         QCOMPARE(codec->mibEnum(), mib);
1920     else
1921         QVERIFY(codec == 0);
1922 }
1923
1924 #if defined(Q_OS_UNIX) && !defined(QT_NO_PROCESS)
1925 void tst_QTextCodec::toLocal8Bit()
1926 {
1927     QProcess process;
1928     process.start("echo/echo");
1929     QString string(QChar(0x410));
1930     process.write((const char*)string.utf16(), string.length()*2);
1931
1932     process.closeWriteChannel();
1933     process.waitForFinished();
1934     QCOMPARE(process.exitStatus(), QProcess::NormalExit);
1935     QCOMPARE(process.exitCode(), 0);
1936 }
1937 #endif
1938
1939 class LoadAndConvert: public QRunnable
1940 {
1941 public:
1942     LoadAndConvert(const QByteArray &source, QByteArray *destination)
1943         : codecName(source), target(destination)
1944     {}
1945     QByteArray codecName;
1946     QByteArray *target;
1947     void run()
1948     {
1949         QTextCodec *c = QTextCodec::codecForName(codecName);
1950         if (!c) {
1951             qWarning() << "WARNING" << codecName << "not found?";
1952             return;
1953         }
1954         QString str = QString::fromLatin1(codecName);
1955         QByteArray b = c->fromUnicode(str);
1956         c->toUnicode(b);
1957         *target = codecName;
1958     }
1959 };
1960
1961 class LoadAndConvertMIB: public QRunnable
1962 {
1963 public:
1964     LoadAndConvertMIB(int mib, int *target)
1965         : mib(mib), target(target)
1966     {}
1967     int mib;
1968     int *target;
1969     void run()
1970     {
1971         QTextCodec *c = QTextCodec::codecForMib(mib);
1972         if (!c) {
1973             qWarning() << "WARNING" << mib << "not found?";
1974             return;
1975         }
1976         QString str = QString::number(mib);
1977         QByteArray b = c->fromUnicode(str);
1978         c->toUnicode(b);
1979         *target = mib;
1980     }
1981 };
1982
1983
1984 void tst_QTextCodec::threadSafety()
1985 {
1986     QList<QByteArray> codecList = QTextCodec::availableCodecs();
1987     QList<int> mibList = QTextCodec::availableMibs();
1988     QThreadPool::globalInstance()->setMaxThreadCount(12);
1989
1990     QVector<QByteArray> res;
1991     res.resize(codecList.size());
1992     for (int i = 0; i < codecList.size(); ++i) {
1993         QThreadPool::globalInstance()->start(new LoadAndConvert(codecList.at(i), &res[i]));
1994     }
1995
1996     QVector<int> res2;
1997     res2.resize(mibList.size());
1998     for (int i = 0; i < mibList.size(); ++i) {
1999         QThreadPool::globalInstance()->start(new LoadAndConvertMIB(mibList.at(i), &res2[i]));
2000     }
2001
2002     // wait for all threads to finish working
2003     QThreadPool::globalInstance()->waitForDone();
2004
2005     QCOMPARE(res.toList(), codecList);
2006     QCOMPARE(res2.toList(), mibList);
2007 }
2008
2009 void tst_QTextCodec::invalidNames()
2010 {
2011     QVERIFY(!QTextCodec::codecForName(""));
2012     QVERIFY(!QTextCodec::codecForName(QByteArray()));
2013     QVERIFY(!QTextCodec::codecForName("-"));
2014     QVERIFY(!QTextCodec::codecForName("\1a\2b\3a\4d\5c\6s\7a\xffr\xec_\x9c_"));
2015     QVERIFY(!QTextCodec::codecForName("\n"));
2016     QVERIFY(!QTextCodec::codecForName("don't exist"));
2017     QByteArray huge = "azertyuiop^$qsdfghjklm<wxcvbn,;:=1234567890�_";
2018     huge = huge + huge + huge + huge + huge + huge + huge + huge;
2019     huge = huge + huge + huge + huge + huge + huge + huge + huge;
2020     huge = huge + huge + huge + huge + huge + huge + huge + huge;
2021     huge = huge + huge + huge + huge + huge + huge + huge + huge;
2022     QVERIFY(!QTextCodec::codecForName(huge));
2023 }
2024
2025 void tst_QTextCodec::checkAliases_data()
2026 {
2027     QTest::addColumn<QByteArray>("codecName");
2028     QList<QByteArray> codecList = QTextCodec::availableCodecs();
2029     foreach (const QByteArray &a, codecList) {
2030         QTest::newRow( a.constData() ) << a;
2031     }
2032 }
2033
2034 void tst_QTextCodec::checkAliases()
2035 {
2036     QFETCH( QByteArray, codecName );
2037     QTextCodec *c = QTextCodec::codecForName(codecName);
2038     QVERIFY(c);
2039     QCOMPARE(QTextCodec::codecForName(codecName), c);
2040     QCOMPARE(QTextCodec::codecForName(c->name()), c);
2041
2042     foreach(const QByteArray &a, c->aliases()) {
2043         QCOMPARE(QTextCodec::codecForName(a), c);
2044     }
2045 }
2046
2047
2048 void tst_QTextCodec::moreToFromUnicode_data() {
2049     QTest::addColumn<QByteArray>("codecName");
2050     QTest::addColumn<QByteArray>("testData");
2051
2052     QTest::newRow("russian") << QByteArray("ISO-8859-5")
2053         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF\x00");
2054
2055     QTest::newRow("arabic") << QByteArray("ISO-8859-6")
2056         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA4\xAC\xAD\xBB\xBF\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2");
2057
2058     QTest::newRow("greek") << QByteArray("ISO-8859-7")
2059         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA6\xA7\xA8\xA9\xAB\xAC\xAD\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE");
2060
2061     QTest::newRow("turkish") << QByteArray("ISO-8859-9")
2062         << QByteArray("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2063
2064     QTest::newRow("latin1") << QByteArray("ISO-8859-1")
2065         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2066
2067     QByteArray sms7bit_ba;
2068     for (int i=1; i <= 0x7f; ++i) {
2069         if (i!='\x1b') {
2070             sms7bit_ba.append(i);
2071         }
2072     }
2073
2074     QTest::newRow("latin2") << QByteArray("ISO-8859-2")
2075         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2076
2077     QTest::newRow("latin3") << QByteArray("ISO-8859-3")
2078         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBF\xC0\xC1\xC2\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2079
2080     QTest::newRow("latin4") << QByteArray("ISO-8859-4")
2081         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2082
2083     QTest::newRow("russian 2") << QByteArray("ISO-8859-5")
2084         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2085
2086     QTest::newRow("arabic 2") << QByteArray("ISO-8859-6")
2087         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA4\xAC\xAD\xBB\xBF\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2");
2088
2089     QTest::newRow("greek 2") << QByteArray("ISO-8859-7")
2090         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA6\xA7\xA8\xA9\xAB\xAC\xAD\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE");
2091
2092     QTest::newRow("latin5") << QByteArray("ISO-8859-9")
2093         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2094
2095     QTest::newRow("latin6") << QByteArray("ISO-8859-10")
2096         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2097
2098 #if 0
2099     QByteArray iso8859_11_ba;
2100     for (int x=0x20; x<=0x7f; ++x) {
2101         iso8859_11_ba.append(x);
2102     }
2103     for (int x=0xa0; x<0xff; ++x) {
2104         if ((x>=0xdb && x<0xdf) || x>0xfb){
2105             continue;
2106         }
2107         iso8859_11_ba.append(x);
2108     }
2109     QTest::newRow("latin-thai") << QByteArray("ISO-8859-11") << iso8859_11_ba;
2110 #endif
2111
2112     QTest::newRow("latin7") << QByteArray("ISO-8859-13")
2113         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2114
2115     QTest::newRow("celtic") << QByteArray("ISO-8859-14")
2116         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2117
2118     QTest::newRow("latin9") << QByteArray("ISO-8859-15")
2119         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2120
2121     QTest::newRow("latin10") << QByteArray("ISO-8859-16")
2122         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2123
2124     QTest::newRow("cp850") << QByteArray("CP850")
2125         << QByteArray("\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff");
2126
2127     QTest::newRow("cp874") << QByteArray("CP874")
2128         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x85\x91\x92\x93\x94\x95\x96\x97\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB");
2129
2130     QTest::newRow("cp1250") << QByteArray("CP1250")
2131         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x82\x84\x85\x86\x87\x89\x8A\x8B\x8C\x8D\x8E\x8F\x91\x92\x93\x94\x95\x96\x97\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2132
2133     QTest::newRow("cp1251") << QByteArray("CP1251")
2134         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2135
2136     QTest::newRow("cp1252") << QByteArray("CP1252")
2137         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8E\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2138
2139     QTest::newRow("cp1253") << QByteArray("CP1253")
2140         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x82\x83\x84\x85\x86\x87\x89\x8B\x91\x92\x93\x94\x95\x96\x97\x99\x9B\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE");
2141
2142     QTest::newRow("cp1254") << QByteArray("CP1254")
2143         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2144
2145     QTest::newRow("cp1255") << QByteArray("CP1255")
2146         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x82\x83\x84\x85\x86\x87\x88\x89,x8B\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9B\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFD\xFE");
2147
2148     QTest::newRow("cp1256") << QByteArray("CP1256")
2149         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2150
2151     QTest::newRow("cp1257") << QByteArray("CP1257")
2152         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x82\x84\x85\x86\x87\x89\x8B\x8D\x8E\x8F\x91\x92\x93\x94\x95\x96\x97\x99\x9B\x9D\x9E\xA0\xA2\xA3\xA4\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2153
2154     QTest::newRow("cp1258") << QByteArray("CP1258")
2155         << QByteArray("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F\x80\x82\x83\x84\x85\x86\x87\x88\x89\x8B\x8C\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9B\x9C\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
2156
2157     QByteArray koi8_r_ba;
2158     for (int x=0x20; x<=0xff; ++x) {
2159         if (x!=0x9A && x!=0xbf) {
2160             koi8_r_ba.append(x);
2161         }
2162     }
2163     QTest::newRow("KOI8-R") << QByteArray("KOI8-R") << koi8_r_ba;
2164
2165     QByteArray koi8_u_ba;
2166     for (int x=0x20; x<=0xff; ++x) {
2167         koi8_u_ba.append(x);
2168     }
2169     QTest::newRow("KOI8-U") << QByteArray("KOI8-U") << koi8_u_ba;
2170
2171
2172     QByteArray big5_ba;
2173     for (unsigned char u=0xa1; u<=0xf9; u++) {
2174         if (u==0xc8) {
2175             continue;
2176         }
2177         for (unsigned char v=0x40; v<=0x7e; v++) {
2178             big5_ba.append(u);
2179             big5_ba.append(v);
2180         }
2181         unsigned char v_up;
2182         switch (u) {
2183             case 0xa3: v_up=0xbf; break;
2184             case 0xc7: v_up=0xfc; break;
2185             case 0xf9: v_up=0xd5; break;
2186             default: v_up=0xfe;
2187         }
2188
2189         for (unsigned char v=0xa1; v<=v_up; v++) {
2190             if (u==0xa2 && (v==0xcc || v==0xce)) {
2191                 continue;
2192             }
2193             big5_ba.append(u);
2194             big5_ba.append(v);
2195         }
2196     }
2197
2198     QTest::newRow("BIG5") << QByteArray("BIG5") << big5_ba;
2199
2200     QByteArray gb2312_ba;
2201     for (unsigned char u=0xa1; u<=0xf7; u++) {
2202         for (unsigned char v=0xa1; v<=0xfe; v++) {
2203             gb2312_ba.append(u);
2204             gb2312_ba.append(v);
2205         }
2206     }
2207
2208     QTest::newRow("GB2312") << QByteArray("GB2312") << gb2312_ba;
2209 }
2210
2211 void tst_QTextCodec::moreToFromUnicode()
2212 {
2213     QFETCH( QByteArray, codecName );
2214     QFETCH( QByteArray, testData );
2215
2216     QTextCodec *c = QTextCodec::codecForName( codecName.data() );
2217     QVERIFY(c);
2218
2219     QString uStr = c->toUnicode(testData);
2220     QByteArray cStr = c->fromUnicode(uStr);
2221     QCOMPARE(testData, cStr);
2222 }
2223
2224 void tst_QTextCodec::shiftJis()
2225 {
2226     QByteArray backslashTilde("\\~");
2227     QTextCodec* codec = QTextCodec::codecForName("shift_jis");
2228     QString string = codec->toUnicode(backslashTilde);
2229     QCOMPARE(string.length(), 2);
2230     QCOMPARE(string.at(0), QChar(QLatin1Char('\\')));
2231     QCOMPARE(string.at(1), QChar(QLatin1Char('~')));
2232
2233     QByteArray encoded = codec->fromUnicode(string);
2234     QCOMPARE(encoded, backslashTilde);
2235 }
2236
2237 struct DontCrashAtExit {
2238     ~DontCrashAtExit() {
2239         QTextCodec *c = QTextCodec::codecForName("utf8");
2240         if (c)
2241             c->toUnicode("azerty");
2242
2243     }
2244 } dontCrashAtExit;
2245
2246
2247 QTEST_MAIN(tst_QTextCodec)
2248 #include "tst_qtextcodec.moc"