Fix duplicate data row name in tst_QTextCodec::utf8Codec test.
[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("ISO-8859-1") << "ISO-8859-1" << true;
176     QTest::newRow("ISO-8859-2") << "ISO-8859-2" << true;
177     QTest::newRow("ISO-8859-3") << "ISO-8859-3" << true;
178     QTest::newRow("ISO-8859-4") << "ISO-8859-4" << true;
179     QTest::newRow("ISO-8859-5") << "ISO-8859-5" << true;
180     QTest::newRow("ISO-8859-6") << "ISO-8859-6" << true;
181     QTest::newRow("ISO-8859-7") << "ISO-8859-7" << true;
182     QTest::newRow("ISO-8859-8") << "ISO-8859-8" << true;
183     QTest::newRow("ISO-8859-9") << "ISO-8859-9" << true;
184     QTest::newRow("ISO-8859-10") << "ISO-8859-10" << true;
185     QTest::newRow("ISO-8859-13") << "ISO-8859-13" << true;
186     QTest::newRow("ISO-8859-14") << "ISO-8859-14" << true;
187     QTest::newRow("ISO-8859-15") << "ISO-8859-15" << true;
188     QTest::newRow("ISO-8859-16") << "ISO-8859-16" << true;
189
190     QTest::newRow("IBM850") << "IBM850" << true;
191     QTest::newRow("IBM874") << "IBM874" << true;
192     QTest::newRow("IBM866") << "IBM866" << true;
193
194     QTest::newRow("windows-1250") << "windows-1250" << true;
195     QTest::newRow("windows-1251") << "windows-1251" << true;
196     QTest::newRow("windows-1252") << "windows-1252" << true;
197     QTest::newRow("windows-1253") << "windows-1253" << true;
198     QTest::newRow("windows-1254") << "windows-1254" << true;
199     QTest::newRow("windows-1255") << "windows-1255" << true;
200     QTest::newRow("windows-1256") << "windows-1256" << true;
201     QTest::newRow("windows-1257") << "windows-1257" << true;
202     QTest::newRow("windows-1258") << "windows-1258" << true;
203
204     QTest::newRow("Apple Roman") << "Apple Roman" << true;
205     QTest::newRow("WINSAMI2") << "WINSAMI2" << true;
206     QTest::newRow("TIS-620") << "TIS-620" << true;
207     QTest::newRow("roman8") << "roman8" << true;
208     QTest::newRow("SJIS") << "SJIS" << false;
209
210     // all codecs from documentation
211     QTest::newRow("Big5") << "Big5" << false;
212     QTest::newRow("Big5-HKSCS") << "Big5-HKSCS" << false;
213     QTest::newRow("CP949") << "CP949" << false;
214     QTest::newRow("EUC-JP") << "EUC-JP" << false;
215     QTest::newRow("EUC-KR") << "EUC-KR" << false;
216     //QTest::newRow("GB18030-0") << "GB18030-0" << false; // only GB18030 works
217     QTest::newRow("GB18030") << "GB18030" << false;
218     QTest::newRow("IBM 850") << "IBM 850" << false;
219     QTest::newRow("IBM 866") << "IBM 866" << false;
220     QTest::newRow("IBM 874") << "IBM 874" << false;
221     QTest::newRow("ISO 2022-JP") << "ISO 2022-JP" << false;
222     //ISO 8859-1 to 10 and  ISO 8859-13 to 16 tested previously
223     // Iscii-Bng, Dev, Gjr, Knd, Mlm, Ori, Pnj, Tlg, and Tml  tested in Iscii test
224     //QTest::newRow("JIS X 0201") << "JIS X 0201" << false; // actually not there
225     //QTest::newRow("JIS X 0208") << "JIS X 0208" << false; // actually not there
226     QTest::newRow("KOI8-R") << "KOI8-R" << false;
227     QTest::newRow("KOI8-U") << "KOI8-U" << false;
228     //QTest::newRow("MuleLao-1") << "MuleLao-1" << false; //only on x11
229     QTest::newRow("ROMAN8") << "ROMAN8" << false;
230     QTest::newRow("Shift-JIS") << "Shift-JIS" << false;
231     QTest::newRow("TIS-620") << "TIS-620" << false;
232     QTest::newRow("TSCII") << "TSCII" << false;
233     QTest::newRow("UTF-8") << "UTF-8" << false;
234     QTest::newRow("UTF-16") << "UTF-16" << false;
235     QTest::newRow("UTF-16BE") << "UTF-16BE" << false;
236     QTest::newRow("UTF-16LE") << "UTF-16LE" << false;
237     QTest::newRow("UTF-32") << "UTF-32" << false;
238     QTest::newRow("UTF-32BE") << "UTF-32BE" << false;
239     QTest::newRow("UTF-32LE") << "UTF-32LE" << false;
240     //Windows-1250 to 1258 tested previously
241 }
242
243 void tst_QTextCodec::fromUnicode()
244 {
245     QFETCH(QString, codecName);
246     QFETCH(bool, eightBit);
247
248     QTextCodec *codec = QTextCodec::codecForName(codecName.toLatin1());
249     QVERIFY(codec != 0);
250
251     // Check if the reverse lookup is what we expect
252     if (eightBit) {
253         char chars[128];
254         for (int i = 0; i < 128; ++i)
255             chars[i] = i + 128;
256         QString s = codec->toUnicode(chars, 128);
257         QByteArray c = codec->fromUnicode(s);
258         QCOMPARE(c.size(), 128);
259
260         int numberOfQuestionMarks = 0;
261         for (int i = 0; i < 128; ++i) {
262             if (c.at(i) == '?')
263                 ++numberOfQuestionMarks;
264             else
265                 QCOMPARE(c.at(i), char(i + 128));
266         }
267         QVERIFY(numberOfQuestionMarks != 128);
268     }
269
270     /*
271         If the encoding is a superset of ASCII, test that the byte
272         array is correct (no off by one, no trailing '\0').
273     */
274     QByteArray result = codec->fromUnicode(QString("abc"));
275     if (result.startsWith("a")) {
276         QCOMPARE(result.size(), 3);
277         QCOMPARE(result, QByteArray("abc"));
278     } else {
279         QVERIFY(true);
280     }
281 }
282
283 void tst_QTextCodec::toUnicode_codecForHtml()
284 {
285     QFile file(QFINDTESTDATA("QT4-crashtest.txt"));
286     QVERIFY(file.open(QFile::ReadOnly));
287
288     QByteArray data = file.readAll();
289     QTextCodec *codec = Qt::codecForHtml(data);
290     codec->toUnicode(data); // this line crashes
291 }
292
293
294 void tst_QTextCodec::toUnicode_incremental()
295 {
296     QByteArray ba;
297     ba += char(0xf0);
298     ba += char(0x90);
299     ba += char(0x80);
300     ba += char(0x80);
301     ba += char(0xf4);
302     ba += char(0x8f);
303     ba += char(0xbf);
304     ba += char(0xbd);
305
306     QString expected = QString::fromUtf8(ba);
307
308     QString incremental;
309     QTextDecoder *utf8Decoder = QTextCodec::codecForMib(106)->makeDecoder();
310
311     QString actual;
312     for (int i = 0; i < ba.size(); ++i)
313         utf8Decoder->toUnicode(&actual, ba.constData() + i, 1);
314
315     QCOMPARE(actual, expected);
316
317
318     delete utf8Decoder;
319 }
320
321 void tst_QTextCodec::codecForLocale()
322 {
323     QTextCodec *codec = QTextCodec::codecForLocale();
324     QVERIFY(codec != 0);
325
326     // The rest of this test is for Unix only
327 #if defined(Q_OS_UNIX)
328     // get a time string that is locale-encoded
329     QByteArray originalLocaleEncodedTimeString;
330     originalLocaleEncodedTimeString.resize(1024);
331     time_t t;
332     time(&t);
333     int r = strftime(originalLocaleEncodedTimeString.data(),
334                      originalLocaleEncodedTimeString.size(),
335                      "%A%a%B%b%Z",
336                      localtime(&t));
337     QVERIFY(r != 0);
338     originalLocaleEncodedTimeString.resize(r);
339
340     QString unicodeTimeString = codec->toUnicode(originalLocaleEncodedTimeString);
341     QByteArray localeEncodedTimeString = codec->fromUnicode(unicodeTimeString);
342     QCOMPARE(localeEncodedTimeString, originalLocaleEncodedTimeString);
343
344     // find a codec that is not the codecForLocale()
345     QTextCodec *codec2 = 0;
346     foreach (int mib, QTextCodec::availableMibs()) {
347         if (mib != codec->mibEnum()) {
348             codec2 = QTextCodec::codecForMib(mib);
349             if (codec2)
350                 break;
351         }
352     }
353
354     // Only run the rest of the test if we could find a codec that is not
355     // already the codecForLocale().
356     if (codec2) {
357         // set it, codecForLocale() should return it now
358         QTextCodec::setCodecForLocale(codec2);
359         QCOMPARE(QTextCodec::codecForLocale(), codec2);
360
361         // reset back to the default
362         QTextCodec::setCodecForLocale(0);
363         QCOMPARE(QTextCodec::codecForLocale(), codec);
364     }
365 #endif
366 }
367
368 void tst_QTextCodec::asciiToIscii() const
369 {
370     /* Add all low, 7-bit ASCII characters. */
371     QString ascii;
372     const int len = 0xA0 - 1;
373     ascii.resize(len);
374
375     for(int i = 0; i < len; ++i)
376         ascii[i] = QChar(i + 1);
377
378     static const char *const isciiCodecs[] =
379     {
380         "Iscii-Mlm",
381         "Iscii-Knd",
382         "Iscii-Tlg",
383         "Iscii-Tml",
384         "Iscii-Ori",
385         "Iscii-Gjr",
386         "Iscii-Pnj",
387         "Iscii-Bng",
388         "Iscii-Dev"
389     };
390     const int isciiCodecsLen = sizeof(isciiCodecs) / sizeof(const char *);
391
392     for(int i = 0; i < isciiCodecsLen; ++i) {
393         /* For each codec. */
394
395         const QTextCodec *const textCodec = QTextCodec::codecForName(isciiCodecs[i]);
396         QVERIFY(textCodec);
397
398         for(int i2 = 0; i2 < len; ++i2) {
399             /* For each character in ascii. */
400             const QChar c(ascii[i2]);
401             QVERIFY2(textCodec->canEncode(c), qPrintable(QString::fromLatin1("Failed to encode %1 with encoding %2")
402                                                          .arg(QString::number(c.unicode()), QString::fromLatin1(textCodec->name().constData()))));
403         }
404
405         QVERIFY2(textCodec->canEncode(ascii), qPrintable(QString::fromLatin1("Failed for full string with encoding %1")
406                                                          .arg(QString::fromLatin1(textCodec->name().constData()))));
407     }
408 }
409
410 void tst_QTextCodec::flagCodepointFFFF() const
411 {
412     // This is an invalid Unicode codepoint.
413     const QChar ch(0xFFFF);
414     QString input(ch);
415
416     QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8
417     QVERIFY(codec);
418
419     const QByteArray asDecoded(codec->fromUnicode(input));
420     QCOMPARE(asDecoded, QByteArray("?"));
421
422     QByteArray ffff("\357\277\277");
423     QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull);
424     QVERIFY(codec->toUnicode(ffff.constData(), ffff.length(), &state) == QChar(0));
425     QVERIFY(codec->toUnicode(ffff) == QChar(0xfffd));
426 }
427
428 void tst_QTextCodec::flagF7808080() const
429 {
430     /* This test case stems from test not-wf-sa-170, tests/qxmlstream/XML-Test-Suite/xmlconf/xmltest/not-wf/sa/166.xml,
431      * whose description reads:
432      *
433      * "Four byte UTF-8 encodings can encode UCS-4 characters
434      *  which are beyond the range of legal XML characters
435      *  (and can't be expressed in Unicode surrogate pairs).
436      *  This document holds such a character."
437      *
438      *  In binary, this is:
439      *  11110111100000001000000010000000
440      *  *       *       *       *
441      *  11110www10xxxxxx10yyyyyy10zzzzzz
442      *
443      *  With multibyte logic removed it is the codepoint 0x1C0000.
444      */
445     QByteArray input;
446     input.resize(4);
447     input[0] = char(0xF7);
448     input[1] = char(0x80);
449     input[2] = char(0x80);
450     input[3] = char(0x80);
451
452     QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8
453     QVERIFY(codec);
454
455     //QVERIFY(!codec->canEncode(QChar(0x1C0000)));
456
457     QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull);
458     QVERIFY(codec->toUnicode(input.constData(), input.length(), &state) == QChar(0));
459 }
460
461 void tst_QTextCodec::flagEFBFBF() const
462 {
463     QByteArray invalidInput;
464     invalidInput.resize(3);
465     invalidInput[0] = char(0xEF);
466     invalidInput[1] = char(0xBF);
467     invalidInput[2] = char(0xBF);
468
469     const QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8
470     QVERIFY(codec);
471
472     {
473         //QVERIFY(!codec->canEncode(QChar(0xFFFF)));
474         QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull);
475         QVERIFY(codec->toUnicode(invalidInput.constData(), invalidInput.length(), &state) == QChar(0));
476
477         QByteArray start("<?pi ");
478         start.append(invalidInput);
479         start.append("?>");
480     }
481
482     /* When 0xEFBFBF is preceded by what seems to be an arbitrary character,
483      * QTextCodec fails to flag it. */
484     {
485         QByteArray start("B");
486         start.append(invalidInput);
487
488         QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull);
489         QVERIFY(codec->toUnicode(start.constData(), start.length(), &state) == QString::fromLatin1("B\0", 2));
490     }
491 }
492
493 void tst_QTextCodec::decode0D() const
494 {
495     QByteArray input;
496     input.resize(3);
497     input[0] = 'A';
498     input[1] = '\r';
499     input[2] = 'B';
500
501     QCOMPARE(QString::fromUtf8(input.constData()).toUtf8(), input);
502 }
503
504 void tst_QTextCodec::aliasForUTF16() const
505 {
506     QVERIFY(QTextCodec::codecForName("UTF-16")->aliases().isEmpty());
507 }
508
509 void tst_QTextCodec::mibForTSCII() const
510 {
511     QTextCodec *codec = QTextCodec::codecForName("TSCII");
512     QVERIFY(codec);
513     QCOMPARE(codec->mibEnum(), 2107);
514 }
515
516 static QString fromInvalidUtf8Sequence(const QByteArray &ba)
517 {
518     return QString().fill(QChar::ReplacementCharacter, ba.size());
519 }
520
521 // copied from tst_QString::fromUtf8_data()
522 void tst_QTextCodec::utf8Codec_data()
523 {
524     QTest::addColumn<QByteArray>("utf8");
525     QTest::addColumn<QString>("res");
526     QTest::addColumn<int>("len");
527     QString str;
528
529     QTest::newRow("str0") << QByteArray("abcdefgh") << QString("abcdefgh") << -1;
530     QTest::newRow("str0-len") << QByteArray("abcdefgh") << QString("abc") << 3;
531     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;
532     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;
533
534     str += QChar(0x05e9);
535     str += QChar(0x05d3);
536     str += QChar(0x05d2);
537     QTest::newRow("str2") << QByteArray("\327\251\327\223\327\222") << str << -1;
538
539     str = QChar(0x05e9);
540     QTest::newRow("str2-len") << QByteArray("\327\251\327\223\327\222") << str << 2;
541
542     str = QChar(0x20ac);
543     str += " some text";
544     QTest::newRow("str3") << QByteArray("\342\202\254 some text") << str << -1;
545
546     str = QChar(0x20ac);
547     str += " some ";
548     QTest::newRow("str3-len") << QByteArray("\342\202\254 some text") << str << 9;
549
550     str = "hello";
551     str += QChar::ReplacementCharacter;
552     str += QChar(0x68);
553     str += QChar::ReplacementCharacter;
554     str += QChar::ReplacementCharacter;
555     str += QChar::ReplacementCharacter;
556     str += QChar::ReplacementCharacter;
557     str += QChar(0x61);
558     str += QChar::ReplacementCharacter;
559     QTest::newRow("invalid utf8") << QByteArray("hello\344h\344\344\366\344a\304") << str << -1;
560     QTest::newRow("invalid utf8-len") << QByteArray("hello\344h\344\344\366\344a\304") << QString("hello") << 5;
561
562     str = "Prohl";
563     str += QChar::ReplacementCharacter;
564     str += QChar::ReplacementCharacter;
565     str += "e";
566     str += QChar::ReplacementCharacter;
567     str += " plugin";
568     str += QChar::ReplacementCharacter;
569     str += " Netscape";
570
571     QTest::newRow("task28417") << QByteArray("Prohl\355\276e\350 plugin\371 Netscape") << str << -1;
572     QTest::newRow("task28417-len") << QByteArray("Prohl\355\276e\350 plugin\371 Netscape") << QString("") << 0;
573
574     QTest::newRow("null-1") << QByteArray() << QString() << -1;
575     QTest::newRow("null0") << QByteArray() << QString() << 0;
576     // QTest::newRow("null5") << QByteArray() << QString() << 5;
577     QTest::newRow("empty-1") << QByteArray("\0abcd", 5) << QString() << -1;
578     QTest::newRow("empty0") << QByteArray() << QString() << 0;
579     QTest::newRow("empty5") << QByteArray("\0abcd", 5) << QString::fromAscii("\0abcd", 5) << 5;
580     QTest::newRow("other-1") << QByteArray("ab\0cd", 5) << QString::fromAscii("ab") << -1;
581     QTest::newRow("other5") << QByteArray("ab\0cd", 5) << QString::fromAscii("ab\0cd", 5) << 5;
582
583     str = "Old Italic: ";
584     str += QChar(0xd800);
585     str += QChar(0xdf00);
586     str += QChar(0xd800);
587     str += QChar(0xdf01);
588     str += QChar(0xd800);
589     str += QChar(0xdf02);
590     str += QChar(0xd800);
591     str += QChar(0xdf03);
592     str += QChar(0xd800);
593     str += QChar(0xdf04);
594     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;
595
596     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;
597
598     // from http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html
599
600     // 2.1.1 U+00000000
601     QByteArray utf8;
602     utf8 += char(0x00);
603     str = QChar(QChar::Null);
604     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.1") << utf8 << str << 1;
605
606     // 2.1.2 U+00000080
607     utf8.clear();
608     utf8 += char(0xc2);
609     utf8 += char(0x80);
610     str = QChar(0x80);
611     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.2") << utf8 << str << -1;
612
613     // 2.1.3 U+00000800
614     utf8.clear();
615     utf8 += char(0xe0);
616     utf8 += char(0xa0);
617     utf8 += char(0x80);
618     str = QChar(0x800);
619     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.3") << utf8 << str << -1;
620
621     // 2.1.4 U+00010000
622     utf8.clear();
623     utf8 += char(0xf0);
624     utf8 += char(0x90);
625     utf8 += char(0x80);
626     utf8 += char(0x80);
627     str.clear();
628     str += QChar(0xd800);
629     str += QChar(0xdc00);
630     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.4") << utf8 << str << -1;
631
632     // 2.1.5 U+00200000 (not a valid Unicode character)
633     utf8.clear();
634     utf8 += char(0xf8);
635     utf8 += char(0x88);
636     utf8 += char(0x80);
637     utf8 += char(0x80);
638     utf8 += char(0x80);
639     str = fromInvalidUtf8Sequence(utf8);
640     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.5") << utf8 << str << -1;
641
642     // 2.1.6 U+04000000 (not a valid Unicode character)
643     utf8.clear();
644     utf8 += char(0xfc);
645     utf8 += char(0x84);
646     utf8 += char(0x80);
647     utf8 += char(0x80);
648     utf8 += char(0x80);
649     utf8 += char(0x80);
650     str = fromInvalidUtf8Sequence(utf8);
651     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.1.6") << utf8 << str << -1;
652
653     // 2.2.1 U+0000007F
654     utf8.clear();
655     utf8 += char(0x7f);
656     str = QChar(0x7f);
657     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.1") << utf8 << str << -1;
658
659     // 2.2.2 U+000007FF
660     utf8.clear();
661     utf8 += char(0xdf);
662     utf8 += char(0xbf);
663     str = QChar(0x7ff);
664     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.2") << utf8 << str << -1;
665
666     // 2.2.3 U+000FFFF
667     utf8.clear();
668     utf8 += char(0xef);
669     utf8 += char(0xbf);
670     utf8 += char(0xbf);
671     str.clear();
672     str += QChar::ReplacementCharacter;
673     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.3") << utf8 << str << -1;
674
675     // 2.2.4 U+001FFFFF
676     utf8.clear();
677     utf8 += char(0xf7);
678     utf8 += char(0xbf);
679     utf8 += char(0xbf);
680     utf8 += char(0xbf);
681     str.clear();
682     str += QChar(QChar::ReplacementCharacter);
683     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.4") << utf8 << str << -1;
684
685     // 2.2.5 U+03FFFFFF (not a valid Unicode character)
686     utf8.clear();
687     utf8 += char(0xfb);
688     utf8 += char(0xbf);
689     utf8 += char(0xbf);
690     utf8 += char(0xbf);
691     utf8 += char(0xbf);
692     str = fromInvalidUtf8Sequence(utf8);
693     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.5") << utf8 << str << -1;
694
695     // 2.2.6 U+7FFFFFFF
696     utf8.clear();
697     utf8 += char(0xfd);
698     utf8 += char(0xbf);
699     utf8 += char(0xbf);
700     utf8 += char(0xbf);
701     utf8 += char(0xbf);
702     utf8 += char(0xbf);
703     str = fromInvalidUtf8Sequence(utf8);
704     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.2.6") << utf8 << str << -1;
705
706     // 2.3.1 U+0000D7FF
707     utf8.clear();
708     utf8 += char(0xed);
709     utf8 += char(0x9f);
710     utf8 += char(0xbf);
711     str = QChar(0xd7ff);
712     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.1") << utf8 << str << -1;
713
714     // 2.3.2 U+0000E000
715     utf8.clear();
716     utf8 += char(0xee);
717     utf8 += char(0x80);
718     utf8 += char(0x80);
719     str = QChar(0xe000);
720     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.2") << utf8 << str << -1;
721
722     // 2.3.3 U+0000FFFD
723     utf8.clear();
724     utf8 += char(0xef);
725     utf8 += char(0xbf);
726     utf8 += char(0xbd);
727     str = QChar(QChar::ReplacementCharacter);
728     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.3") << utf8 << str << -1;
729
730     // 2.3.4 U+0010FFFD
731     utf8.clear();
732     utf8 += char(0xf4);
733     utf8 += char(0x8f);
734     utf8 += char(0xbf);
735     utf8 += char(0xbd);
736     str.clear();
737     str += QChar(0xdbff);
738     str += QChar(0xdffd);
739     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.4") << utf8 << str << -1;
740
741     // 2.3.5 U+00110000
742     utf8.clear();
743     utf8 += char(0xf4);
744     utf8 += char(0x90);
745     utf8 += char(0x80);
746     utf8 += char(0x80);
747     str.clear();
748     str += QChar(QChar::ReplacementCharacter);
749     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.5") << utf8 << str << -1;
750
751     // 3.1.1
752     utf8.clear();
753     utf8 += char(0x80);
754     str = fromInvalidUtf8Sequence(utf8);
755     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.1") << utf8 << str << -1;
756
757     // 3.1.2
758     utf8.clear();
759     utf8 += char(0xbf);
760     str = fromInvalidUtf8Sequence(utf8);
761     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.2") << utf8 << str << -1;
762
763     // 3.1.3
764     utf8.clear();
765     utf8 += char(0x80);
766     utf8 += char(0xbf);
767     str = fromInvalidUtf8Sequence(utf8);
768     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.3") << utf8 << str << -1;
769
770     // 3.1.4
771     utf8.clear();
772     utf8 += char(0x80);
773     utf8 += char(0xbf);
774     utf8 += char(0x80);
775     str = fromInvalidUtf8Sequence(utf8);
776     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.4") << utf8 << str << -1;
777
778     // 3.1.5
779     utf8.clear();
780     utf8 += char(0x80);
781     utf8 += char(0xbf);
782     utf8 += char(0x80);
783     utf8 += char(0xbf);
784     str = fromInvalidUtf8Sequence(utf8);
785     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.5") << utf8 << str << -1;
786
787     // 3.1.6
788     utf8.clear();
789     utf8 += char(0x80);
790     utf8 += char(0xbf);
791     utf8 += char(0x80);
792     utf8 += char(0xbf);
793     utf8 += char(0x80);
794     str = fromInvalidUtf8Sequence(utf8);
795     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.6") << utf8 << str << -1;
796
797     // 3.1.7
798     utf8.clear();
799     utf8 += char(0x80);
800     utf8 += char(0xbf);
801     utf8 += char(0x80);
802     utf8 += char(0xbf);
803     utf8 += char(0x80);
804     utf8 += char(0xbf);
805     str = fromInvalidUtf8Sequence(utf8);
806     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.7") << utf8 << str << -1;
807
808     // 3.1.8
809     utf8.clear();
810     utf8 += char(0x80);
811     utf8 += char(0xbf);
812     utf8 += char(0x80);
813     utf8 += char(0xbf);
814     utf8 += char(0x80);
815     utf8 += char(0xbf);
816     utf8 += char(0x80);
817     str = fromInvalidUtf8Sequence(utf8);
818     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.8") << utf8 << str << -1;
819
820     // 3.1.9
821     utf8.clear();
822     for (uint i = 0x80; i<= 0xbf; ++i)
823         utf8 += i;
824     str = fromInvalidUtf8Sequence(utf8);
825     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.1.9") << utf8 << str << -1;
826
827     // 3.2.1
828     utf8.clear();
829     str.clear();
830     for (uint i = 0xc8; i <= 0xdf; ++i) {
831         utf8 += i;
832         utf8 += char(0x20);
833
834         str += QChar::ReplacementCharacter;
835         str += QChar(0x0020);
836     }
837     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.2.1") << utf8 << str << -1;
838
839     // 3.2.2
840     utf8.clear();
841     str.clear();
842     for (uint i = 0xe0; i <= 0xef; ++i) {
843         utf8 += i;
844         utf8 += char(0x20);
845
846         str += QChar::ReplacementCharacter;
847         str += QChar(0x0020);
848     }
849     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.2.2") << utf8 << str << -1;
850
851     // 3.2.3
852     utf8.clear();
853     str.clear();
854     for (uint i = 0xf0; i <= 0xf7; ++i) {
855         utf8 += i;
856         utf8 += 0x20;
857
858         str += QChar::ReplacementCharacter;
859         str += QChar(0x0020);
860     }
861     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.2.3") << utf8 << str << -1;
862
863     // 3.2.4
864     utf8.clear();
865     str.clear();
866     for (uint i = 0xf8; i <= 0xfb; ++i) {
867         utf8 += i;
868         utf8 += 0x20;
869
870         str += QChar::ReplacementCharacter;
871         str += QChar(0x0020);
872     }
873     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.2.4") << utf8 << str << -1;
874
875     // 3.2.5
876     utf8.clear();
877     str.clear();
878     for (uint i = 0xfc; i <= 0xfd; ++i) {
879         utf8 += i;
880         utf8 += 0x20;
881
882         str += QChar::ReplacementCharacter;
883         str += QChar(0x0020);
884     }
885     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.2.5") << utf8 << str << -1;
886
887     // 3.3.1
888     utf8.clear();
889     utf8 += char(0xc0);
890     str = fromInvalidUtf8Sequence(utf8);
891     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.1") << utf8 << str << -1;
892     utf8 += char(0x30);
893     str += 0x30;
894     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.1-1") << utf8 << str << -1;
895
896     // 3.3.2
897     utf8.clear();
898     utf8 += char(0xe0);
899     utf8 += char(0x80);
900     str = fromInvalidUtf8Sequence(utf8);
901     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2") << utf8 << str << -1;
902     utf8 += char(0x30);
903     str += 0x30;
904     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2-1") << utf8 << str << -1;
905
906     utf8.clear();
907     utf8 += char(0xe0);
908     str = fromInvalidUtf8Sequence(utf8);
909     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2-2") << utf8 << str << -1;
910     utf8 += 0x30;
911     str += 0x30;
912     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.2-3") << utf8 << str << -1;
913
914     // 3.3.3
915     utf8.clear();
916     utf8 += char(0xf0);
917     utf8 += char(0x80);
918     utf8 += char(0x80);
919     str = fromInvalidUtf8Sequence(utf8);
920     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3") << utf8 << str << -1;
921     utf8 += char(0x30);
922     str += 0x30;
923     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-1") << utf8 << str << -1;
924
925     utf8.clear();
926     utf8 += char(0xf0);
927     str = fromInvalidUtf8Sequence(utf8);
928     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-2") << utf8 << str << -1;
929     utf8 += char(0x30);
930     str += 0x30;
931     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-3") << utf8 << str << -1;
932
933     utf8.clear();
934     utf8 += char(0xf0);
935     utf8 += char(0x80);
936     str = fromInvalidUtf8Sequence(utf8);
937     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-4") << utf8 << str << -1;
938     utf8 += char(0x30);
939     str += 0x30;
940     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.3-5") << utf8 << str << -1;
941
942     // 3.3.4
943     utf8.clear();
944     utf8 += char(0xf8);
945     utf8 += char(0x80);
946     utf8 += char(0x80);
947     utf8 += char(0x80);
948     str = fromInvalidUtf8Sequence(utf8);
949     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4") << utf8 << str << -1;
950     utf8 += char(0x30);
951     str += 0x30;
952     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-1") << utf8 << str << -1;
953
954     utf8.clear();
955     utf8 += char(0xf8);
956     utf8 += char(0x80);
957     utf8 += char(0x80);
958     str = fromInvalidUtf8Sequence(utf8);
959     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-2") << utf8 << str << -1;
960     utf8 += char(0x30);
961     str += 0x30;
962     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-3") << utf8 << str << -1;
963
964     utf8.clear();
965     utf8 += char(0xf8);
966     utf8 += char(0x80);
967     str = fromInvalidUtf8Sequence(utf8);
968     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-4") << utf8 << str << -1;
969     utf8 += char(0x30);
970     str += 0x30;
971     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-5") << utf8 << str << -1;
972
973     utf8.clear();
974     utf8 += char(0xf8);
975     str = fromInvalidUtf8Sequence(utf8);
976     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-6") << utf8 << str << -1;
977     utf8 += char(0x30);
978     str += 0x30;
979     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.4-7") << utf8 << str << -1;
980
981     // 3.3.5
982     utf8.clear();
983     utf8 += char(0xfc);
984     utf8 += char(0x80);
985     utf8 += char(0x80);
986     utf8 += char(0x80);
987     utf8 += char(0x80);
988     str = fromInvalidUtf8Sequence(utf8);
989     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5") << utf8 << str << -1;
990     utf8 += char(0x30);
991     str += 0x30;
992     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-1") << utf8 << str << -1;
993
994     utf8.clear();
995     utf8 += char(0xfc);
996     utf8 += char(0x80);
997     utf8 += char(0x80);
998     utf8 += char(0x80);
999     str = fromInvalidUtf8Sequence(utf8);
1000     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-2") << utf8 << str << -1;
1001     utf8 += char(0x30);
1002     str += 0x30;
1003     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-3") << utf8 << str << -1;
1004
1005     utf8.clear();
1006     utf8 += char(0xfc);
1007     utf8 += char(0x80);
1008     utf8 += char(0x80);
1009     str = fromInvalidUtf8Sequence(utf8);
1010     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-4") << utf8 << str << -1;
1011     utf8 += char(0x30);
1012     str += 0x30;
1013     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-5") << utf8 << str << -1;
1014
1015     utf8.clear();
1016     utf8 += char(0xfc);
1017     utf8 += char(0x80);
1018     str = fromInvalidUtf8Sequence(utf8);
1019     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-6") << utf8 << str << -1;
1020     utf8 += char(0x30);
1021     str += 0x30;
1022     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-7") << utf8 << str << -1;
1023
1024     utf8.clear();
1025     utf8 += char(0xfc);
1026     str = fromInvalidUtf8Sequence(utf8);
1027     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-8") << utf8 << str << -1;
1028     utf8 += char(0x30);
1029     str += 0x30;
1030     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.5-9") << utf8 << str << -1;
1031
1032     // 3.3.6
1033     utf8.clear();
1034     utf8 += char(0xdf);
1035     str = fromInvalidUtf8Sequence(utf8);
1036     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.6") << utf8 << str << -1;
1037     utf8 += char(0x30);
1038     str += 0x30;
1039     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.6-1") << utf8 << str << -1;
1040
1041     // 3.3.7
1042     utf8.clear();
1043     utf8 += char(0xef);
1044     utf8 += char(0xbf);
1045     str = fromInvalidUtf8Sequence(utf8);
1046     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.7") << utf8 << str << -1;
1047     utf8 += char(0x30);
1048     str += 0x30;
1049     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.7-1") << utf8 << str << -1;
1050
1051     utf8.clear();
1052     utf8 += char(0xef);
1053     str = fromInvalidUtf8Sequence(utf8);
1054     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.7-2") << utf8 << str << -1;
1055     utf8 += char(0x30);
1056     str += 0x30;
1057     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.7-3") << utf8 << str << -1;
1058
1059     // 3.3.8
1060     utf8.clear();
1061     utf8 += char(0xf7);
1062     utf8 += char(0xbf);
1063     utf8 += char(0xbf);
1064     str = fromInvalidUtf8Sequence(utf8);
1065     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8") << utf8 << str << -1;
1066     utf8 += char(0x30);
1067     str += 0x30;
1068     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-1") << utf8 << str << -1;
1069
1070     utf8.clear();
1071     utf8 += char(0xf7);
1072     utf8 += char(0xbf);
1073     str = fromInvalidUtf8Sequence(utf8);
1074     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-2") << utf8 << str << -1;
1075     utf8 += char(0x30);
1076     str += 0x30;
1077     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-3") << utf8 << str << -1;
1078
1079     utf8.clear();
1080     utf8 += char(0xf7);
1081     str = fromInvalidUtf8Sequence(utf8);
1082     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-4") << utf8 << str << -1;
1083     utf8 += char(0x30);
1084     str += 0x30;
1085     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.8-5") << utf8 << str << -1;
1086
1087     // 3.3.9
1088     utf8.clear();
1089     utf8 += char(0xfb);
1090     utf8 += char(0xbf);
1091     utf8 += char(0xbf);
1092     utf8 += char(0xbf);
1093     str = fromInvalidUtf8Sequence(utf8);
1094     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9") << utf8 << str << -1;
1095     utf8 += char(0x30);
1096     str += 0x30;
1097     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-1") << utf8 << str << -1;
1098
1099     utf8.clear();
1100     utf8 += char(0xfb);
1101     utf8 += char(0xbf);
1102     utf8 += char(0xbf);
1103     str = fromInvalidUtf8Sequence(utf8);
1104     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-2") << utf8 << str << -1;
1105     utf8 += char(0x30);
1106     str += 0x30;
1107     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-3") << utf8 << str << -1;
1108
1109     utf8.clear();
1110     utf8 += char(0xfb);
1111     utf8 += char(0xbf);
1112     str = fromInvalidUtf8Sequence(utf8);
1113     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-4") << utf8 << str << -1;
1114     utf8 += char(0x30);
1115     str += 0x30;
1116     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-5") << utf8 << str << -1;
1117
1118     utf8.clear();
1119     utf8 += char(0xfb);
1120     str = fromInvalidUtf8Sequence(utf8);
1121     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-6") << utf8 << str << -1;
1122     utf8 += char(0x30);
1123     str += 0x30;
1124     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.9-7") << utf8 << str << -1;
1125
1126     // 3.3.10
1127     utf8.clear();
1128     utf8 += char(0xfd);
1129     utf8 += char(0xbf);
1130     utf8 += char(0xbf);
1131     utf8 += char(0xbf);
1132     utf8 += char(0xbf);
1133     str = fromInvalidUtf8Sequence(utf8);
1134     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10") << utf8 << str << -1;
1135     utf8 += char(0x30);
1136     str += 0x30;
1137     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-1") << utf8 << str << -1;
1138
1139     utf8.clear();
1140     utf8 += char(0xfd);
1141     utf8 += char(0xbf);
1142     utf8 += char(0xbf);
1143     utf8 += char(0xbf);
1144     str = fromInvalidUtf8Sequence(utf8);
1145     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-2") << utf8 << str << -1;
1146     utf8 += char(0x30);
1147     str += 0x30;
1148     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-3") << utf8 << str << -1;
1149
1150     utf8.clear();
1151     utf8 += char(0xfd);
1152     utf8 += char(0xbf);
1153     utf8 += char(0xbf);
1154     str = fromInvalidUtf8Sequence(utf8);
1155     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-4") << utf8 << str << -1;
1156     utf8 += char(0x30);
1157     str += 0x30;
1158     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-5") << utf8 << str << -1;
1159
1160     utf8.clear();
1161     utf8 += char(0xfd);
1162     utf8 += char(0xbf);
1163     str = fromInvalidUtf8Sequence(utf8);
1164     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-6") << utf8 << str << -1;
1165     utf8 += char(0x30);
1166     str += 0x30;
1167     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-7") << utf8 << str << -1;
1168
1169     utf8.clear();
1170     utf8 += char(0xfd);
1171     str = fromInvalidUtf8Sequence(utf8);
1172     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-8") << utf8 << str << -1;
1173     utf8 += char(0x30);
1174     str += 0x30;
1175     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.3.10-9") << utf8 << str << -1;
1176
1177     // 3.4
1178     utf8.clear();
1179     utf8 += char(0xc0);
1180     utf8 += char(0xe0);
1181     utf8 += char(0x80);
1182     utf8 += char(0xf0);
1183     utf8 += char(0x80);
1184     utf8 += char(0x80);
1185     utf8 += char(0xf8);
1186     utf8 += char(0x80);
1187     utf8 += char(0x80);
1188     utf8 += char(0x80);
1189     utf8 += char(0xfc);
1190     utf8 += char(0x80);
1191     utf8 += char(0x80);
1192     utf8 += char(0x80);
1193     utf8 += char(0x80);
1194     utf8 += char(0xdf);
1195     utf8 += char(0xef);
1196     utf8 += char(0xbf);
1197     utf8 += char(0xf7);
1198     utf8 += char(0xbf);
1199     utf8 += char(0xbf);
1200     utf8 += char(0xfb);
1201     utf8 += char(0xbf);
1202     utf8 += char(0xbf);
1203     utf8 += char(0xbf);
1204     utf8 += char(0xfd);
1205     utf8 += char(0xbf);
1206     utf8 += char(0xbf);
1207     utf8 += char(0xbf);
1208     utf8 += char(0xbf);
1209     str = fromInvalidUtf8Sequence(utf8);
1210     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.4") << utf8 << str << -1;
1211
1212     // 3.5.1
1213     utf8.clear();
1214     utf8 += char(0xfe);
1215     str = fromInvalidUtf8Sequence(utf8);
1216     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.5.1") << utf8 << str << -1;
1217
1218     // 3.5.2
1219     utf8.clear();
1220     utf8 += char(0xff);
1221     str = fromInvalidUtf8Sequence(utf8);
1222     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.5.2") << utf8 << str << -1;
1223
1224     // 3.5.2
1225     utf8.clear();
1226     utf8 += char(0xfe);
1227     utf8 += char(0xfe);
1228     utf8 += char(0xff);
1229     str = fromInvalidUtf8Sequence(utf8);
1230     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.5.2-1") << utf8 << str << -1;
1231
1232     // 4.1.1
1233     utf8.clear();
1234     utf8 += char(0xc0);
1235     utf8 += char(0xaf);
1236     str = QChar(QChar::ReplacementCharacter);
1237     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.1.1") << utf8 << str << -1;
1238
1239     // 4.1.2
1240     utf8.clear();
1241     utf8 += char(0xe0);
1242     utf8 += char(0x80);
1243     utf8 += char(0xaf);
1244     str = QChar(QChar::ReplacementCharacter);
1245     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.1.2") << utf8 << str << -1;
1246
1247     // 4.1.3
1248     utf8.clear();
1249     utf8 += char(0xf0);
1250     utf8 += char(0x80);
1251     utf8 += char(0x80);
1252     utf8 += char(0xaf);
1253     str = QChar(QChar::ReplacementCharacter);
1254     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.1.3") << utf8 << str << -1;
1255
1256     // 4.1.4
1257     utf8.clear();
1258     utf8 += char(0xf8);
1259     utf8 += char(0x80);
1260     utf8 += char(0x80);
1261     utf8 += char(0x80);
1262     utf8 += char(0xaf);
1263     str = fromInvalidUtf8Sequence(utf8);
1264     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.1.4") << utf8 << str << -1;
1265
1266     // 4.1.5
1267     utf8.clear();
1268     utf8 += char(0xfc);
1269     utf8 += char(0x80);
1270     utf8 += char(0x80);
1271     utf8 += char(0x80);
1272     utf8 += char(0x80);
1273     utf8 += char(0xaf);
1274     str = fromInvalidUtf8Sequence(utf8);
1275     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.1.5") << utf8 << str << -1;
1276
1277     // 4.2.1
1278     utf8.clear();
1279     utf8 += char(0xc1);
1280     utf8 += char(0xbf);
1281     str = QChar(QChar::ReplacementCharacter);
1282     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.2.1") << utf8 << str << -1;
1283
1284     // 4.2.2
1285     utf8.clear();
1286     utf8 += char(0xe0);
1287     utf8 += char(0x9f);
1288     utf8 += char(0xbf);
1289     str = QChar(QChar::ReplacementCharacter);
1290     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.2.2") << utf8 << str << -1;
1291
1292     // 4.2.3
1293     utf8.clear();
1294     utf8 += char(0xf0);
1295     utf8 += char(0x8f);
1296     utf8 += char(0xbf);
1297     utf8 += char(0xbf);
1298     str = QChar(QChar::ReplacementCharacter);
1299     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.2.3") << utf8 << str << -1;
1300
1301     // 4.2.4
1302     utf8.clear();
1303     utf8 += char(0xf8);
1304     utf8 += char(0x87);
1305     utf8 += char(0xbf);
1306     utf8 += char(0xbf);
1307     utf8 += char(0xbf);
1308     str = fromInvalidUtf8Sequence(utf8);
1309     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.2.4") << utf8 << str << -1;
1310
1311     // 4.2.5
1312     utf8.clear();
1313     utf8 += char(0xfc);
1314     utf8 += char(0x83);
1315     utf8 += char(0xbf);
1316     utf8 += char(0xbf);
1317     utf8 += char(0xbf);
1318     utf8 += char(0xbf);
1319     str = fromInvalidUtf8Sequence(utf8);
1320     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.2.5") << utf8 << str << -1;
1321
1322     // 4.3.1
1323     utf8.clear();
1324     utf8 += char(0xc0);
1325     utf8 += char(0x80);
1326     str = QChar(QChar::ReplacementCharacter);
1327     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.3.1") << utf8 << str << -1;
1328
1329     // 4.3.2
1330     utf8.clear();
1331     utf8 += char(0xe0);
1332     utf8 += char(0x80);
1333     utf8 += char(0x80);
1334     str = QChar(QChar::ReplacementCharacter);
1335     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.3.2") << utf8 << str << -1;
1336
1337     // 4.3.3
1338     utf8.clear();
1339     utf8 += char(0xf0);
1340     utf8 += char(0x80);
1341     utf8 += char(0x80);
1342     utf8 += char(0x80);
1343     str = QChar(QChar::ReplacementCharacter);
1344     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.3.3") << utf8 << str << -1;
1345
1346     // 4.3.4
1347     utf8.clear();
1348     utf8 += char(0xf8);
1349     utf8 += char(0x80);
1350     utf8 += char(0x80);
1351     utf8 += char(0x80);
1352     utf8 += char(0x80);
1353     str = fromInvalidUtf8Sequence(utf8);
1354     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.3.4") << utf8 << str << -1;
1355
1356     // 4.3.5
1357     utf8.clear();
1358     utf8 += char(0xfc);
1359     utf8 += char(0x80);
1360     utf8 += char(0x80);
1361     utf8 += char(0x80);
1362     utf8 += char(0x80);
1363     utf8 += char(0x80);
1364     str = fromInvalidUtf8Sequence(utf8);
1365     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 4.3.5") << utf8 << str << -1;
1366
1367     // 5.1.1
1368     utf8.clear();
1369     utf8 += char(0xed);
1370     utf8 += char(0xa0);
1371     utf8 += char(0x80);
1372     str = QChar(QChar::ReplacementCharacter);
1373     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.1") << utf8 << str << -1;
1374
1375     // 5.1.2
1376     utf8.clear();
1377     utf8 += char(0xed);
1378     utf8 += char(0xad);
1379     utf8 += char(0xbf);
1380     str = QChar(QChar::ReplacementCharacter);
1381     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.2") << utf8 << str << -1;
1382
1383     // 5.1.3
1384     utf8.clear();
1385     utf8 += char(0xed);
1386     utf8 += char(0xae);
1387     utf8 += char(0x80);
1388     str = QChar(QChar::ReplacementCharacter);
1389     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.3") << utf8 << str << -1;
1390
1391     // 5.1.4
1392     utf8.clear();
1393     utf8 += char(0xed);
1394     utf8 += char(0xaf);
1395     utf8 += char(0xbf);
1396     str = QChar(QChar::ReplacementCharacter);
1397     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.4") << utf8 << str << -1;
1398
1399     // 5.1.5
1400     utf8.clear();
1401     utf8 += char(0xed);
1402     utf8 += char(0xb0);
1403     utf8 += char(0x80);
1404     str = QChar(QChar::ReplacementCharacter);
1405     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.5") << utf8 << str << -1;
1406
1407     // 5.1.6
1408     utf8.clear();
1409     utf8 += char(0xed);
1410     utf8 += char(0xbe);
1411     utf8 += char(0x80);
1412     str = QChar(QChar::ReplacementCharacter);
1413     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.6") << utf8 << str << -1;
1414
1415     // 5.1.7
1416     utf8.clear();
1417     utf8 += char(0xed);
1418     utf8 += char(0xbf);
1419     utf8 += char(0xbf);
1420     str = QChar(QChar::ReplacementCharacter);
1421     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.1.7") << utf8 << str << -1;
1422
1423     // 5.2.1
1424     utf8.clear();
1425     utf8 += char(0xed);
1426     utf8 += char(0xa0);
1427     utf8 += char(0x80);
1428     utf8 += char(0xed);
1429     utf8 += char(0xb0);
1430     utf8 += char(0x80);
1431     str.clear();
1432     str += QChar(QChar::ReplacementCharacter);
1433     str += QChar(QChar::ReplacementCharacter);
1434     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.1") << utf8 << str << -1;
1435
1436     // 5.2.2
1437     utf8.clear();
1438     utf8 += char(0xed);
1439     utf8 += char(0xa0);
1440     utf8 += char(0x80);
1441     utf8 += char(0xed);
1442     utf8 += char(0xbf);
1443     utf8 += char(0xbf);
1444     str.clear();
1445     str += QChar(QChar::ReplacementCharacter);
1446     str += QChar(QChar::ReplacementCharacter);
1447     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.2") << utf8 << str << -1;
1448
1449     // 5.2.3
1450     utf8.clear();
1451     utf8 += char(0xed);
1452     utf8 += char(0xad);
1453     utf8 += char(0xbf);
1454     utf8 += char(0xed);
1455     utf8 += char(0xb0);
1456     utf8 += char(0x80);
1457     str.clear();
1458     str += QChar(QChar::ReplacementCharacter);
1459     str += QChar(QChar::ReplacementCharacter);
1460     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.3") << utf8 << str << -1;
1461
1462     // 5.2.4
1463     utf8.clear();
1464     utf8 += char(0xed);
1465     utf8 += char(0xad);
1466     utf8 += char(0xbf);
1467     utf8 += char(0xed);
1468     utf8 += char(0xbf);
1469     utf8 += char(0xbf);
1470     str.clear();
1471     str += QChar(QChar::ReplacementCharacter);
1472     str += QChar(QChar::ReplacementCharacter);
1473     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.4") << utf8 << str << -1;
1474
1475     // 5.2.5
1476     utf8.clear();
1477     utf8 += char(0xed);
1478     utf8 += char(0xae);
1479     utf8 += char(0x80);
1480     utf8 += char(0xed);
1481     utf8 += char(0xb0);
1482     utf8 += char(0x80);
1483     str.clear();
1484     str += QChar(QChar::ReplacementCharacter);
1485     str += QChar(QChar::ReplacementCharacter);
1486     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.5") << utf8 << str << -1;
1487
1488     // 5.2.6
1489     utf8.clear();
1490     utf8 += char(0xed);
1491     utf8 += char(0xae);
1492     utf8 += char(0x80);
1493     utf8 += char(0xed);
1494     utf8 += char(0xbf);
1495     utf8 += char(0xbf);
1496     str.clear();
1497     str += QChar(QChar::ReplacementCharacter);
1498     str += QChar(QChar::ReplacementCharacter);
1499     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.6") << utf8 << str << -1;
1500
1501     // 5.2.7
1502     utf8.clear();
1503     utf8 += char(0xed);
1504     utf8 += char(0xaf);
1505     utf8 += char(0xbf);
1506     utf8 += char(0xed);
1507     utf8 += char(0xb0);
1508     utf8 += char(0x80);
1509     str.clear();
1510     str += QChar(QChar::ReplacementCharacter);
1511     str += QChar(QChar::ReplacementCharacter);
1512     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.7") << utf8 << str << -1;
1513
1514     // 5.2.8
1515     utf8.clear();
1516     utf8 += char(0xed);
1517     utf8 += char(0xaf);
1518     utf8 += char(0xbf);
1519     utf8 += char(0xed);
1520     utf8 += char(0xbf);
1521     utf8 += char(0xbf);
1522     str.clear();
1523     str += QChar(QChar::ReplacementCharacter);
1524     str += QChar(QChar::ReplacementCharacter);
1525     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.2.8") << utf8 << str << -1;
1526
1527     // 5.3.1
1528     utf8.clear();
1529     utf8 += char(0xef);
1530     utf8 += char(0xbf);
1531     utf8 += char(0xbe);
1532     str = QChar(QChar::ReplacementCharacter);
1533     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.3.1") << utf8 << str << -1;
1534
1535     // 5.3.2
1536     utf8.clear();
1537     utf8 += char(0xef);
1538     utf8 += char(0xbf);
1539     utf8 += char(0xbf);
1540     str = QChar(QChar::ReplacementCharacter);
1541     QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 5.3.2") << utf8 << str << -1;
1542 }
1543
1544 void tst_QTextCodec::utf8Codec()
1545 {
1546     QTextCodec *codec = QTextCodec::codecForMib(106); // UTF-8
1547     QVERIFY(codec != 0);
1548
1549     QFETCH(QByteArray, utf8);
1550     QFETCH(QString, res);
1551     QFETCH(int, len);
1552
1553     QString str = codec->toUnicode(utf8.isNull() ? 0 : utf8.constData(),
1554                                    len < 0 ? qstrlen(utf8.constData()) : len);
1555     QCOMPARE(str, res);
1556
1557     str = QString::fromUtf8(utf8.isNull() ? 0 : utf8.constData(), len);
1558     QCOMPARE(str, res);
1559 }
1560
1561 void tst_QTextCodec::utf8bom_data()
1562 {
1563     QTest::addColumn<QByteArray>("data");
1564     QTest::addColumn<QString>("result");
1565
1566     QTest::newRow("nobom")
1567         << QByteArray("\302\240", 2)
1568         << QString("\240");
1569
1570     {
1571         static const ushort data[] = { 0x201d };
1572         QTest::newRow("nobom 2")
1573             << QByteArray("\342\200\235", 3)
1574             << QString::fromUtf16(data, sizeof(data)/sizeof(short));
1575     }
1576
1577     {
1578         static const ushort data[] = { 0xf000 };
1579         QTest::newRow("bom1")
1580             << QByteArray("\357\200\200", 3)
1581             << QString::fromUtf16(data, sizeof(data)/sizeof(short));
1582     }
1583
1584     {
1585         static const ushort data[] = { 0xfec0 };
1586         QTest::newRow("bom2")
1587             << QByteArray("\357\273\200", 3)
1588             << QString::fromUtf16(data, sizeof(data)/sizeof(short));
1589     }
1590
1591     {
1592         QTest::newRow("normal-bom")
1593             << QByteArray("\357\273\277a", 4)
1594             << QString("a");
1595     }
1596
1597     {
1598         static const ushort data[] = { 0x61, 0xfeff, 0x62 };
1599         QTest::newRow("middle-bom")
1600             << QByteArray("a\357\273\277b", 5)
1601             << QString::fromUtf16(data, sizeof(data)/sizeof(short));
1602     }
1603 }
1604
1605 void tst_QTextCodec::utf8bom()
1606 {
1607     QFETCH(QByteArray, data);
1608     QFETCH(QString, result);
1609
1610     QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8
1611     QVERIFY(codec);
1612
1613     QCOMPARE(codec->toUnicode(data.constData(), data.length(), 0), result);
1614
1615     QTextCodec::ConverterState state;
1616     QCOMPARE(codec->toUnicode(data.constData(), data.length(), &state), result);
1617 }
1618
1619 void tst_QTextCodec::utfHeaders_data()
1620 {
1621     QTest::addColumn<QByteArray>("codecName");
1622     QTest::addColumn<int>("flags");
1623     QTest::addColumn<QByteArray>("encoded");
1624     QTest::addColumn<QString>("unicode");
1625     QTest::addColumn<bool>("toUnicode");
1626
1627     QTest::newRow("utf8 bom")
1628         << QByteArray("UTF-8")
1629         << 0
1630         << QByteArray("\xef\xbb\xbfhello")
1631         << QString::fromLatin1("hello")
1632         << true;
1633     QTest::newRow("utf8 nobom")
1634         << QByteArray("UTF-8")
1635         << 0
1636         << QByteArray("hello")
1637         << QString::fromLatin1("hello")
1638         << true;
1639     QTest::newRow("utf8 bom ignore header")
1640         << QByteArray("UTF-8")
1641         << (int)QTextCodec::IgnoreHeader
1642         << QByteArray("\xef\xbb\xbfhello")
1643         << (QString(QChar(0xfeff)) + QString::fromLatin1("hello"))
1644         << true;
1645     QTest::newRow("utf8 nobom ignore header")
1646         << QByteArray("UTF-8")
1647         << (int)QTextCodec::IgnoreHeader
1648         << QByteArray("hello")
1649         << QString::fromLatin1("hello")
1650         << true;
1651
1652     QTest::newRow("utf16 bom be")
1653         << QByteArray("UTF-16")
1654         << 0
1655         << QByteArray("\xfe\xff\0h\0e\0l", 8)
1656         << QString::fromLatin1("hel")
1657         << true;
1658     QTest::newRow("utf16 bom le")
1659         << QByteArray("UTF-16")
1660         << 0
1661         << QByteArray("\xff\xfeh\0e\0l\0", 8)
1662         << QString::fromLatin1("hel")
1663         << true;
1664     if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
1665         QTest::newRow("utf16 nobom")
1666             << QByteArray("UTF-16")
1667             << 0
1668             << QByteArray("\0h\0e\0l", 6)
1669             << QString::fromLatin1("hel")
1670             << true;
1671         QTest::newRow("utf16 bom be ignore header")
1672             << QByteArray("UTF-16")
1673             << (int)QTextCodec::IgnoreHeader
1674             << QByteArray("\xfe\xff\0h\0e\0l", 8)
1675             << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1676             << true;
1677     } else {
1678         QTest::newRow("utf16 nobom")
1679             << QByteArray("UTF-16")
1680             << 0
1681             << QByteArray("h\0e\0l\0", 6)
1682             << QString::fromLatin1("hel")
1683             << true;
1684         QTest::newRow("utf16 bom le ignore header")
1685             << QByteArray("UTF-16")
1686             << (int)QTextCodec::IgnoreHeader
1687             << QByteArray("\xff\xfeh\0e\0l\0", 8)
1688             << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1689             << true;
1690     }
1691
1692     QTest::newRow("utf16-be bom be")
1693         << QByteArray("UTF-16BE")
1694         << 0
1695         << QByteArray("\xfe\xff\0h\0e\0l", 8)
1696         << QString::fromLatin1("hel")
1697         << true;
1698     QTest::newRow("utf16-be nobom")
1699         << QByteArray("UTF-16BE")
1700         << 0
1701         << QByteArray("\0h\0e\0l", 6)
1702         << QString::fromLatin1("hel")
1703         << true;
1704     QTest::newRow("utf16-be bom be ignore header")
1705         << QByteArray("UTF-16BE")
1706         << (int)QTextCodec::IgnoreHeader
1707         << QByteArray("\xfe\xff\0h\0e\0l", 8)
1708         << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1709         << true;
1710
1711     QTest::newRow("utf16-le bom le")
1712         << QByteArray("UTF-16LE")
1713         << 0
1714         << QByteArray("\xff\xfeh\0e\0l\0", 8)
1715         << QString::fromLatin1("hel")
1716         << true;
1717     QTest::newRow("utf16-le nobom")
1718         << QByteArray("UTF-16LE")
1719         << 0
1720         << QByteArray("h\0e\0l\0", 6)
1721         << QString::fromLatin1("hel")
1722         << true;
1723     QTest::newRow("utf16-le bom le ignore header")
1724         << QByteArray("UTF-16LE")
1725         << (int)QTextCodec::IgnoreHeader
1726         << QByteArray("\xff\xfeh\0e\0l\0", 8)
1727         << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1728         << true;
1729
1730
1731     QTest::newRow("utf32 bom be")
1732         << QByteArray("UTF-32")
1733         << 0
1734         << QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16)
1735         << QString::fromLatin1("hel")
1736         << true;
1737     QTest::newRow("utf32 bom le")
1738         << QByteArray("UTF-32")
1739         << 0
1740         << QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16)
1741         << QString::fromLatin1("hel")
1742         << true;
1743     if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
1744         QTest::newRow("utf32 nobom")
1745             << QByteArray("UTF-32")
1746             << 0
1747             << QByteArray("\0\0\0h\0\0\0e\0\0\0l", 12)
1748             << QString::fromLatin1("hel")
1749             << true;
1750         QTest::newRow("utf32 bom be ignore header")
1751             << QByteArray("UTF-32")
1752             << (int)QTextCodec::IgnoreHeader
1753             << QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16)
1754             << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1755             << true;
1756     } else {
1757         QTest::newRow("utf32 nobom")
1758             << QByteArray("UTF-32")
1759             << 0
1760             << QByteArray("h\0\0\0e\0\0\0l\0\0\0", 12)
1761             << QString::fromLatin1("hel")
1762             << true;
1763         QTest::newRow("utf32 bom le ignore header")
1764             << QByteArray("UTF-32")
1765             << (int)QTextCodec::IgnoreHeader
1766             << QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16)
1767             << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1768             << true;
1769     }
1770
1771
1772     QTest::newRow("utf32-be bom be")
1773         << QByteArray("UTF-32BE")
1774         << 0
1775         << QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16)
1776         << QString::fromLatin1("hel")
1777         << true;
1778     QTest::newRow("utf32-be nobom")
1779         << QByteArray("UTF-32BE")
1780         << 0
1781         << QByteArray("\0\0\0h\0\0\0e\0\0\0l", 12)
1782         << QString::fromLatin1("hel")
1783         << true;
1784     QTest::newRow("utf32-be bom be ignore header")
1785         << QByteArray("UTF-32BE")
1786         << (int)QTextCodec::IgnoreHeader
1787         << QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16)
1788         << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1789         << true;
1790
1791
1792     QTest::newRow("utf32-le bom le")
1793         << QByteArray("UTF-32LE")
1794         << 0
1795         << QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16)
1796         << QString::fromLatin1("hel")
1797         << true;
1798     QTest::newRow("utf32-le nobom")
1799         << QByteArray("UTF-32LE")
1800         << 0
1801         << QByteArray("h\0\0\0e\0\0\0l\0\0\0", 12)
1802         << QString::fromLatin1("hel")
1803         << true;
1804     QTest::newRow("utf32-le bom le ignore header")
1805         << QByteArray("UTF-32LE")
1806         << (int)QTextCodec::IgnoreHeader
1807         << QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16)
1808         << (QString(QChar(0xfeff)) + QString::fromLatin1("hel"))
1809         << true;
1810 }
1811
1812 void tst_QTextCodec::utfHeaders()
1813 {
1814     QFETCH(QByteArray, codecName);
1815     QTextCodec *codec = QTextCodec::codecForName(codecName);
1816     QVERIFY(codec != 0);
1817
1818     QFETCH(int, flags);
1819     QTextCodec::ConversionFlags cFlags = QTextCodec::ConversionFlags(flags);
1820     QTextCodec::ConverterState state(cFlags);
1821
1822     QFETCH(QByteArray, encoded);
1823     QFETCH(QString, unicode);
1824
1825     QFETCH(bool, toUnicode);
1826
1827     QLatin1String ignoreReverseTestOn = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? QLatin1String(" le") : QLatin1String(" be");
1828     QString rowName(QTest::currentDataTag());
1829
1830     if (toUnicode) {
1831         QString result = codec->toUnicode(encoded.constData(), encoded.length(), &state);
1832         QCOMPARE(result.length(), unicode.length());
1833         QCOMPARE(result, unicode);
1834
1835         if (!rowName.endsWith("nobom") && !rowName.contains(ignoreReverseTestOn)) {
1836             QTextCodec::ConverterState state2(cFlags);
1837             QByteArray reencoded = codec->fromUnicode(unicode.unicode(), unicode.length(), &state2);
1838             QCOMPARE(reencoded, encoded);
1839         }
1840     } else {
1841         QByteArray result = codec->fromUnicode(unicode.unicode(), unicode.length(), &state);
1842         QCOMPARE(result, encoded);
1843     }
1844 }
1845
1846 void tst_QTextCodec::codecForHtml()
1847 {
1848     QByteArray html("<html><head></head><body>blah</body></html>");
1849
1850     QCOMPARE(QTextCodec::codecForHtml(html)->mibEnum(), 4); // latin 1
1851
1852     QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 106); // UTF-8
1853
1854     html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-15\" /></head></html>";
1855     QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 111); // latin 15
1856
1857     html = "<html><head><meta content=\"text/html; charset=ISO-8859-15\" http-equiv=\"content-type\" /></head></html>";
1858     QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 111); // latin 15
1859
1860     html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=invalid-foo\" /></head></html>";
1861     QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 106); // UTF-8
1862     QCOMPARE(QTextCodec::codecForHtml(html)->mibEnum(), 4); // latin 1
1863 }
1864
1865 void tst_QTextCodec::codecForUtfText_data()
1866 {
1867     QTest::addColumn<QByteArray>("encoded");
1868     QTest::addColumn<bool>("detected");
1869     QTest::addColumn<int>("mib");
1870
1871
1872     QTest::newRow("utf8 bom")
1873         << QByteArray("\xef\xbb\xbfhello")
1874         << true
1875         << 106;
1876     QTest::newRow("utf8 nobom")
1877         << QByteArray("hello")
1878         << false
1879         << 0;
1880
1881     QTest::newRow("utf16 bom be")
1882         << QByteArray("\xfe\xff\0h\0e\0l", 8)
1883         << true
1884         << 1013;
1885     QTest::newRow("utf16 bom le")
1886         << QByteArray("\xff\xfeh\0e\0l\0", 8)
1887         << true
1888         << 1014;
1889     QTest::newRow("utf16 nobom")
1890         << QByteArray("\0h\0e\0l", 6)
1891         << false
1892         << 0;
1893
1894     QTest::newRow("utf32 bom be")
1895         << QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16)
1896         << true
1897         << 1018;
1898     QTest::newRow("utf32 bom le")
1899         << QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16)
1900         << true
1901         << 1019;
1902     QTest::newRow("utf32 nobom")
1903         << QByteArray("\0\0\0h\0\0\0e\0\0\0l", 12)
1904         << false
1905         << 0;
1906 }
1907
1908 void tst_QTextCodec::codecForUtfText()
1909 {
1910     QFETCH(QByteArray, encoded);
1911     QFETCH(bool, detected);
1912     QFETCH(int, mib);
1913
1914     QTextCodec *codec = QTextCodec::codecForUtfText(encoded, 0);
1915     if (detected)
1916         QCOMPARE(codec->mibEnum(), mib);
1917     else
1918         QVERIFY(codec == 0);
1919 }
1920
1921 #if defined(Q_OS_UNIX) && !defined(QT_NO_PROCESS)
1922 void tst_QTextCodec::toLocal8Bit()
1923 {
1924     QProcess process;
1925     process.start("echo/echo");
1926     QString string(QChar(0x410));
1927     process.write((const char*)string.utf16(), string.length()*2);
1928
1929     process.closeWriteChannel();
1930     process.waitForFinished();
1931     QCOMPARE(process.exitStatus(), QProcess::NormalExit);
1932     QCOMPARE(process.exitCode(), 0);
1933 }
1934 #endif
1935
1936 class LoadAndConvert: public QRunnable
1937 {
1938 public:
1939     LoadAndConvert(const QByteArray &source, QByteArray *destination)
1940         : codecName(source), target(destination)
1941     {}
1942     QByteArray codecName;
1943     QByteArray *target;
1944     void run()
1945     {
1946         QTextCodec *c = QTextCodec::codecForName(codecName);
1947         if (!c) {
1948             qWarning() << "WARNING" << codecName << "not found?";
1949             return;
1950         }
1951         QString str = QString::fromLatin1(codecName);
1952         QByteArray b = c->fromUnicode(str);
1953         c->toUnicode(b);
1954         *target = codecName;
1955     }
1956 };
1957
1958 class LoadAndConvertMIB: public QRunnable
1959 {
1960 public:
1961     LoadAndConvertMIB(int mib, int *target)
1962         : mib(mib), target(target)
1963     {}
1964     int mib;
1965     int *target;
1966     void run()
1967     {
1968         QTextCodec *c = QTextCodec::codecForMib(mib);
1969         if (!c) {
1970             qWarning() << "WARNING" << mib << "not found?";
1971             return;
1972         }
1973         QString str = QString::number(mib);
1974         QByteArray b = c->fromUnicode(str);
1975         c->toUnicode(b);
1976         *target = mib;
1977     }
1978 };
1979
1980
1981 void tst_QTextCodec::threadSafety()
1982 {
1983     QList<QByteArray> codecList = QTextCodec::availableCodecs();
1984     QList<int> mibList = QTextCodec::availableMibs();
1985     QThreadPool::globalInstance()->setMaxThreadCount(12);
1986
1987     QVector<QByteArray> res;
1988     res.resize(codecList.size());
1989     for (int i = 0; i < codecList.size(); ++i) {
1990         QThreadPool::globalInstance()->start(new LoadAndConvert(codecList.at(i), &res[i]));
1991     }
1992
1993     QVector<int> res2;
1994     res2.resize(mibList.size());
1995     for (int i = 0; i < mibList.size(); ++i) {
1996         QThreadPool::globalInstance()->start(new LoadAndConvertMIB(mibList.at(i), &res2[i]));
1997     }
1998
1999     // wait for all threads to finish working
2000     QThreadPool::globalInstance()->waitForDone();
2001
2002     QCOMPARE(res.toList(), codecList);
2003     QCOMPARE(res2.toList(), mibList);
2004 }
2005
2006 void tst_QTextCodec::invalidNames()
2007 {
2008     QVERIFY(!QTextCodec::codecForName(""));
2009     QVERIFY(!QTextCodec::codecForName(QByteArray()));
2010     QVERIFY(!QTextCodec::codecForName("-"));
2011     QVERIFY(!QTextCodec::codecForName("\1a\2b\3a\4d\5c\6s\7a\xffr\xec_\x9c_"));
2012     QVERIFY(!QTextCodec::codecForName("\n"));
2013     QVERIFY(!QTextCodec::codecForName("don't exist"));
2014     QByteArray huge = "azertyuiop^$qsdfghjklm<wxcvbn,;:=1234567890�_";
2015     huge = huge + huge + huge + huge + huge + huge + huge + huge;
2016     huge = huge + huge + huge + huge + huge + huge + huge + huge;
2017     huge = huge + huge + huge + huge + huge + huge + huge + huge;
2018     huge = huge + huge + huge + huge + huge + huge + huge + huge;
2019     QVERIFY(!QTextCodec::codecForName(huge));
2020 }
2021
2022 void tst_QTextCodec::checkAliases_data()
2023 {
2024     QTest::addColumn<QByteArray>("codecName");
2025     QList<QByteArray> codecList = QTextCodec::availableCodecs();
2026     foreach (const QByteArray &a, codecList) {
2027         QTest::newRow( a.constData() ) << a;
2028     }
2029 }
2030
2031 void tst_QTextCodec::checkAliases()
2032 {
2033     QFETCH( QByteArray, codecName );
2034     QTextCodec *c = QTextCodec::codecForName(codecName);
2035     QVERIFY(c);
2036     QCOMPARE(QTextCodec::codecForName(codecName), c);
2037     QCOMPARE(QTextCodec::codecForName(c->name()), c);
2038
2039     foreach(const QByteArray &a, c->aliases()) {
2040         QCOMPARE(QTextCodec::codecForName(a), c);
2041     }
2042 }
2043
2044
2045 void tst_QTextCodec::moreToFromUnicode_data() {
2046     QTest::addColumn<QByteArray>("codecName");
2047     QTest::addColumn<QByteArray>("testData");
2048
2049     QTest::newRow("russian") << QByteArray("ISO-8859-5")
2050         << 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");
2051
2052     QTest::newRow("arabic") << QByteArray("ISO-8859-6")
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\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");
2054
2055     QTest::newRow("greek") << QByteArray("ISO-8859-7")
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\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");
2057
2058     QTest::newRow("turkish") << QByteArray("ISO-8859-9")
2059         << 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");
2060
2061     QTest::newRow("latin1") << QByteArray("ISO-8859-1")
2062         << 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");
2063
2064     QByteArray sms7bit_ba;
2065     for (int i=1; i <= 0x7f; ++i) {
2066         if (i!='\x1b') {
2067             sms7bit_ba.append(i);
2068         }
2069     }
2070
2071     QTest::newRow("latin2") << QByteArray("ISO-8859-2")
2072         << 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");
2073
2074     QTest::newRow("latin3") << QByteArray("ISO-8859-3")
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\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");
2076
2077     QTest::newRow("latin4") << QByteArray("ISO-8859-4")
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\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");
2079
2080     QTest::newRow("russian 2") << QByteArray("ISO-8859-5")
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("arabic 2") << QByteArray("ISO-8859-6")
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\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");
2085
2086     QTest::newRow("greek 2") << QByteArray("ISO-8859-7")
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\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");
2088
2089     QTest::newRow("latin5") << QByteArray("ISO-8859-9")
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\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");
2091
2092     QTest::newRow("latin6") << QByteArray("ISO-8859-10")
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 #if 0
2096     QByteArray iso8859_11_ba;
2097     for (int x=0x20; x<=0x7f; ++x) {
2098         iso8859_11_ba.append(x);
2099     }
2100     for (int x=0xa0; x<0xff; ++x) {
2101         if ((x>=0xdb && x<0xdf) || x>0xfb){
2102             continue;
2103         }
2104         iso8859_11_ba.append(x);
2105     }
2106     QTest::newRow("latin-thai") << QByteArray("ISO-8859-11") << iso8859_11_ba;
2107 #endif
2108
2109     QTest::newRow("latin7") << QByteArray("ISO-8859-13")
2110         << 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");
2111
2112     QTest::newRow("celtic") << QByteArray("ISO-8859-14")
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("latin9") << QByteArray("ISO-8859-15")
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("latin10") << QByteArray("ISO-8859-16")
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("cp850") << QByteArray("CP850")
2122         << 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");
2123
2124     QTest::newRow("cp874") << QByteArray("CP874")
2125         << 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");
2126
2127     QTest::newRow("cp1250") << QByteArray("CP1250")
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\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");
2129
2130     QTest::newRow("cp1251") << QByteArray("CP1251")
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\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");
2132
2133     QTest::newRow("cp1252") << QByteArray("CP1252")
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\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");
2135
2136     QTest::newRow("cp1253") << QByteArray("CP1253")
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\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");
2138
2139     QTest::newRow("cp1254") << QByteArray("CP1254")
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\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");
2141
2142     QTest::newRow("cp1255") << QByteArray("CP1255")
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,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");
2144
2145     QTest::newRow("cp1256") << QByteArray("CP1256")
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\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");
2147
2148     QTest::newRow("cp1257") << QByteArray("CP1257")
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\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");
2150
2151     QTest::newRow("cp1258") << QByteArray("CP1258")
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\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");
2153
2154     QByteArray koi8_r_ba;
2155     for (int x=0x20; x<=0xff; ++x) {
2156         if (x!=0x9A && x!=0xbf) {
2157             koi8_r_ba.append(x);
2158         }
2159     }
2160     QTest::newRow("KOI8-R") << QByteArray("KOI8-R") << koi8_r_ba;
2161
2162     QByteArray koi8_u_ba;
2163     for (int x=0x20; x<=0xff; ++x) {
2164         koi8_u_ba.append(x);
2165     }
2166     QTest::newRow("KOI8-U") << QByteArray("KOI8-U") << koi8_u_ba;
2167
2168
2169     QByteArray big5_ba;
2170     for (unsigned char u=0xa1; u<=0xf9; u++) {
2171         if (u==0xc8) {
2172             continue;
2173         }
2174         for (unsigned char v=0x40; v<=0x7e; v++) {
2175             big5_ba.append(u);
2176             big5_ba.append(v);
2177         }
2178         unsigned char v_up;
2179         switch (u) {
2180             case 0xa3: v_up=0xbf; break;
2181             case 0xc7: v_up=0xfc; break;
2182             case 0xf9: v_up=0xd5; break;
2183             default: v_up=0xfe;
2184         }
2185
2186         for (unsigned char v=0xa1; v<=v_up; v++) {
2187             if (u==0xa2 && (v==0xcc || v==0xce)) {
2188                 continue;
2189             }
2190             big5_ba.append(u);
2191             big5_ba.append(v);
2192         }
2193     }
2194
2195     QTest::newRow("BIG5") << QByteArray("BIG5") << big5_ba;
2196
2197     QByteArray gb2312_ba;
2198     for (unsigned char u=0xa1; u<=0xf7; u++) {
2199         for (unsigned char v=0xa1; v<=0xfe; v++) {
2200             gb2312_ba.append(u);
2201             gb2312_ba.append(v);
2202         }
2203     }
2204
2205     QTest::newRow("GB2312") << QByteArray("GB2312") << gb2312_ba;
2206 }
2207
2208 void tst_QTextCodec::moreToFromUnicode()
2209 {
2210     QFETCH( QByteArray, codecName );
2211     QFETCH( QByteArray, testData );
2212
2213     QTextCodec *c = QTextCodec::codecForName( codecName.data() );
2214     QVERIFY(c);
2215
2216     QString uStr = c->toUnicode(testData);
2217     QByteArray cStr = c->fromUnicode(uStr);
2218     QCOMPARE(testData, cStr);
2219 }
2220
2221 void tst_QTextCodec::shiftJis()
2222 {
2223     QByteArray backslashTilde("\\~");
2224     QTextCodec* codec = QTextCodec::codecForName("shift_jis");
2225     QString string = codec->toUnicode(backslashTilde);
2226     QCOMPARE(string.length(), 2);
2227     QCOMPARE(string.at(0), QChar(QLatin1Char('\\')));
2228     QCOMPARE(string.at(1), QChar(QLatin1Char('~')));
2229
2230     QByteArray encoded = codec->fromUnicode(string);
2231     QCOMPARE(encoded, backslashTilde);
2232 }
2233
2234 struct DontCrashAtExit {
2235     ~DontCrashAtExit() {
2236         QTextCodec *c = QTextCodec::codecForName("utf8");
2237         if (c)
2238             c->toUnicode("azerty");
2239
2240     }
2241 } dontCrashAtExit;
2242
2243
2244 QTEST_MAIN(tst_QTextCodec)
2245 #include "tst_qtextcodec.moc"