equal
deleted
inserted
replaced
429 |
429 |
430 QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8 |
430 QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8 |
431 Q_ASSERT(codec); |
431 Q_ASSERT(codec); |
432 |
432 |
433 const QByteArray asDecoded(codec->fromUnicode(input)); |
433 const QByteArray asDecoded(codec->fromUnicode(input)); |
|
434 QCOMPARE(asDecoded, QByteArray("?")); |
|
435 |
|
436 QByteArray ffff("\357\277\277"); |
434 QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull); |
437 QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull); |
435 QVERIFY(codec->toUnicode(asDecoded.constData(), asDecoded.length(), &state) == QChar(0)); |
438 QVERIFY(codec->toUnicode(ffff.constData(), ffff.length(), &state) == QChar(0)); |
436 QVERIFY(codec->toUnicode(asDecoded) == QChar(0xfffd)); |
439 QVERIFY(codec->toUnicode(ffff) == QChar(0xfffd)); |
437 } |
440 } |
438 |
441 |
439 void tst_QTextCodec::flagF7808080() const |
442 void tst_QTextCodec::flagF7808080() const |
440 { |
443 { |
441 /* This test case stems from test not-wf-sa-170, tests/qxmlstream/XML-Test-Suite/xmlconf/xmltest/not-wf/sa/166.xml, |
444 /* This test case stems from test not-wf-sa-170, tests/qxmlstream/XML-Test-Suite/xmlconf/xmltest/not-wf/sa/166.xml, |
492 } |
495 } |
493 |
496 |
494 /* When 0xEFBFBF is preceeded by what seems to be an arbitrary character, |
497 /* When 0xEFBFBF is preceeded by what seems to be an arbitrary character, |
495 * QTextCodec fails to flag it. */ |
498 * QTextCodec fails to flag it. */ |
496 { |
499 { |
497 QEXPECT_FAIL("", "This is a bug and needs to be fixed.", Continue); |
|
498 QByteArray start("B"); |
500 QByteArray start("B"); |
499 start.append(invalidInput); |
501 start.append(invalidInput); |
500 |
502 |
501 QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull); |
503 QTextCodec::ConverterState state(QTextCodec::ConvertInvalidToNull); |
502 QVERIFY(codec->toUnicode(start.constData(), start.length(), &state) == QChar(0)); |
504 QVERIFY(codec->toUnicode(start.constData(), start.length(), &state) == QString::fromLatin1("B\0", 2)); |
503 } |
505 } |
504 } |
506 } |
505 |
507 |
506 void tst_QTextCodec::decode0D() const |
508 void tst_QTextCodec::decode0D() const |
507 { |
509 { |
742 utf8 += char(0xbf); |
744 utf8 += char(0xbf); |
743 utf8 += char(0xbd); |
745 utf8 += char(0xbd); |
744 str = QChar(QChar::ReplacementCharacter); |
746 str = QChar(QChar::ReplacementCharacter); |
745 QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.3") << utf8 << str << -1; |
747 QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.3") << utf8 << str << -1; |
746 |
748 |
747 // 2.3.4 U+0010FFFF |
749 // 2.3.4 U+0010FFFD |
748 utf8.clear(); |
750 utf8.clear(); |
749 utf8 += char(0xf4); |
751 utf8 += char(0xf4); |
750 utf8 += char(0x8f); |
752 utf8 += char(0x8f); |
751 utf8 += char(0xbf); |
753 utf8 += char(0xbf); |
752 utf8 += char(0xbf); |
754 utf8 += char(0xbd); |
753 str.clear(); |
755 str.clear(); |
754 str += QChar(0xdbff); |
756 str += QChar(0xdbff); |
755 str += QChar(0xdfff); |
757 str += QChar(0xdffd); |
756 QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.4") << utf8 << str << -1; |
758 QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 2.3.4") << utf8 << str << -1; |
757 |
759 |
758 // 2.3.5 U+00110000 |
760 // 2.3.5 U+00110000 |
759 utf8.clear(); |
761 utf8.clear(); |
760 utf8 += char(0xf4); |
762 utf8 += char(0xf4); |
1985 } |
1987 } |
1986 |
1988 |
1987 |
1989 |
1988 void tst_QTextCodec::threadSafety() |
1990 void tst_QTextCodec::threadSafety() |
1989 { |
1991 { |
|
1992 QList<QByteArray> codecList = QTextCodec::availableCodecs(); |
|
1993 QList<int> mibList = QTextCodec::availableMibs(); |
1990 #ifndef QT_NO_CONCURRENT |
1994 #ifndef QT_NO_CONCURRENT |
1991 QThreadPool::globalInstance()->setMaxThreadCount(12); |
1995 QThreadPool::globalInstance()->setMaxThreadCount(12); |
1992 |
1996 |
1993 QFuture<QByteArray> res = QtConcurrent::mapped(codecList, loadAndConvert); |
1997 QFuture<QByteArray> res = QtConcurrent::mapped(codecList, loadAndConvert); |
1994 |
1998 |
1995 |
1999 |
1996 QFuture<int> res2 = QtConcurrent::mapped(mibList, loadAndConvertMIB); |
2000 QFuture<int> res2 = QtConcurrent::mapped(mibList, loadAndConvertMIB); |
1997 |
2001 |
1998 QCOMPARE(res.results(), codecList); |
2002 QCOMPARE(res.results(), codecList); |
1999 QCOMPARE(res2.results(), mibList); |
2003 QCOMPARE(res2.results(), mibList); |
2000 #else |
|
2001 QSKIP("This function is not yet supported with QT_NO_CONCURRENT defined.", SkipAll); |
|
2002 #endif |
2004 #endif |
2003 } |
2005 } |
2004 |
2006 |
2005 void tst_QTextCodec::invalidNames() |
2007 void tst_QTextCodec::invalidNames() |
2006 { |
2008 { |
2174 QByteArray koi8_u_ba; |
2176 QByteArray koi8_u_ba; |
2175 for (int x=0x20; x<=0xff; ++x) { |
2177 for (int x=0x20; x<=0xff; ++x) { |
2176 koi8_u_ba.append(x); |
2178 koi8_u_ba.append(x); |
2177 } |
2179 } |
2178 QTest::newRow("KOI8-U") << QByteArray("KOI8-U") << koi8_u_ba; |
2180 QTest::newRow("KOI8-U") << QByteArray("KOI8-U") << koi8_u_ba; |
|
2181 |
|
2182 |
|
2183 QByteArray big5_ba; |
|
2184 for (unsigned char u=0xa1; u<=0xf9; u++) { |
|
2185 if (u==0xc8) { |
|
2186 continue; |
|
2187 } |
|
2188 for (unsigned char v=0x40; v<=0x7e; v++) { |
|
2189 big5_ba.append(u); |
|
2190 big5_ba.append(v); |
|
2191 } |
|
2192 unsigned char v_up; |
|
2193 switch (u) { |
|
2194 case 0xa3: v_up=0xbf; break; |
|
2195 case 0xc7: v_up=0xfc; break; |
|
2196 case 0xf9: v_up=0xd5; break; |
|
2197 default: v_up=0xfe; |
|
2198 } |
|
2199 |
|
2200 for (unsigned char v=0xa1; v<=v_up; v++) { |
|
2201 if (u==0xa2 && (v==0xcc || v==0xce)) { |
|
2202 continue; |
|
2203 } |
|
2204 big5_ba.append(u); |
|
2205 big5_ba.append(v); |
|
2206 } |
|
2207 } |
|
2208 |
|
2209 QTest::newRow("BIG5") << QByteArray("BIG5") << big5_ba; |
|
2210 |
|
2211 QByteArray gb2312_ba; |
|
2212 for (unsigned char u=0xa1; u<=0xf7; u++) { |
|
2213 for (unsigned char v=0xa1; v<=0xfe; v++) { |
|
2214 gb2312_ba.append(u); |
|
2215 gb2312_ba.append(v); |
|
2216 } |
|
2217 } |
|
2218 |
|
2219 QTest::newRow("GB2312") << QByteArray("GB2312") << gb2312_ba; |
2179 } |
2220 } |
2180 |
2221 |
2181 void tst_QTextCodec::moreToFromUnicode() |
2222 void tst_QTextCodec::moreToFromUnicode() |
2182 { |
2223 { |
2183 QFETCH( QByteArray, codecName ); |
2224 QFETCH( QByteArray, codecName ); |