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