From 4d67b9dcfbb379d9d65a5a1fec74600273941637 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 28 Apr 2020 18:15:54 +0200 Subject: Get rid of QTextCodec in QTextStream Use QStringConverter instead. Also change the default encoding of QTextStream to utf8. Change-Id: I30682e75fe0462d1a937539f773640c83a2d82e1 Reviewed-by: Thiago Macieira --- tests/auto/corelib/global/qglobal/tst_qglobal.cpp | 59 ---------------- .../serialization/qtextstream/tst_qtextstream.cpp | 11 ++- .../dom/qdom/testdata/toString_01/doc_euc-jp.xml | 78 ---------------------- .../qdom/testdata/toString_01/doc_iso-2022-jp.xml | 78 ---------------------- tests/auto/xml/dom/qdom/tst_qdom.cpp | 65 +++++++----------- 5 files changed, 30 insertions(+), 261 deletions(-) delete mode 100644 tests/auto/xml/dom/qdom/testdata/toString_01/doc_euc-jp.xml delete mode 100644 tests/auto/xml/dom/qdom/testdata/toString_01/doc_iso-2022-jp.xml (limited to 'tests') diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index 047130d5ea..cde4ea9633 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -30,7 +30,6 @@ #include #include -#include #include #include @@ -50,8 +49,6 @@ private slots: void qCoreAppStartupFunction(); void qCoreAppStartupFunctionRestart(); void integerForSize(); - void qprintable(); - void qprintable_data(); void buildAbiEndianness(); void testqOverload(); }; @@ -450,62 +447,6 @@ void tst_QGlobal::integerForSize() typedef QPair stringpair; Q_DECLARE_METATYPE(stringpair) -void tst_QGlobal::qprintable() -{ - QFETCH(QVector, localestrings); - QFETCH(int, utf8index); - - QVERIFY(utf8index >= 0 && utf8index < localestrings.count()); - if (utf8index < 0 || utf8index >= localestrings.count()) - return; - - const char *const utf8string = localestrings.at(utf8index).second; - - QString string = QString::fromUtf8(utf8string); - - for (const stringpair &pair : qAsConst(localestrings)) { - QTextCodec *codec = QTextCodec::codecForName(pair.first); - if (!codec) - continue; - QTextCodec::setCodecForLocale(codec); - // test qPrintable() - QVERIFY(qstrcmp(qPrintable(string), pair.second) == 0); - for (const stringpair &pair2 : qAsConst(localestrings)) { - if (pair2.second == pair.second) - continue; - QVERIFY(qstrcmp(qPrintable(string), pair2.second) != 0); - } - // test qUtf8Printable() - QVERIFY(qstrcmp(qUtf8Printable(string), utf8string) == 0); - for (const stringpair &pair2 : qAsConst(localestrings)) { - if (qstrcmp(pair2.second, utf8string) == 0) - continue; - QVERIFY(qstrcmp(qUtf8Printable(string), pair2.second) != 0); - } - } - - QTextCodec::setCodecForLocale(0); -} - -void tst_QGlobal::qprintable_data() -{ - QTest::addColumn >("localestrings"); - QTest::addColumn("utf8index"); // index of utf8 string - - // Unicode: HIRAGANA LETTER A, I, U, E, O (U+3442, U+3444, U+3446, U+3448, U+344a) - static const char *const utf8string = "\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a"; - static const char *const eucjpstring = "\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa"; - static const char *const sjisstring = "\x82\xa0\x82\xa2\x82\xa4\x82\xa6\x82\xa8"; - - QVector japanesestrings; - japanesestrings << stringpair("UTF-8", utf8string) - << stringpair("EUC-JP", eucjpstring) - << stringpair("Shift_JIS", sjisstring); - - QTest::newRow("Japanese") << japanesestrings << 0; - -} - void tst_QGlobal::buildAbiEndianness() { #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index 07960f1348..a79d1af314 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -37,10 +37,10 @@ #include #include #include +#include #include #include #include -#include #if QT_CONFIG(process) # include #endif @@ -245,7 +245,7 @@ private: void runOnExit() { QByteArray buffer; - QTextStream(&buffer) << "This will try to use QTextCodec::codecForLocale" << Qt::endl; + QTextStream(&buffer) << "This will try to use QStringConverter::Utf8" << Qt::endl; } Q_DESTRUCTOR_FUNCTION(runOnExit) @@ -277,8 +277,8 @@ void tst_QTextStream::getSetCheck() { // Initialize codecs QTextStream obj1; - // QTextCodec * QTextStream::encoding() - // void QTextStream::setEncoding() + // QTextStream::encoding() + // QTextStream::setEncoding() obj1.setEncoding(QStringConverter::Utf32BE); QCOMPARE(QStringConverter::Utf32BE, obj1.encoding()); obj1.setEncoding(QStringConverter::Utf8); @@ -402,7 +402,7 @@ void tst_QTextStream::cleanupTestCase() void tst_QTextStream::construction() { QTextStream stream; - QCOMPARE(stream.codec(), QTextCodec::codecForLocale()); + QCOMPARE(stream.encoding(), QStringConverter::Utf8); QCOMPARE(stream.device(), static_cast(0)); QCOMPARE(stream.string(), static_cast(0)); @@ -1766,7 +1766,6 @@ void tst_QTextStream::utf8IncompleteAtBufferBoundary() QFile::remove(testFileName); QFile data(testFileName); - QTextCodec *utf8Codec = QTextCodec::codecForMib(106); QString lineContents = QString::fromUtf8("\342\200\223" // U+2013 EN DASH "\342\200\223" "\342\200\223" diff --git a/tests/auto/xml/dom/qdom/testdata/toString_01/doc_euc-jp.xml b/tests/auto/xml/dom/qdom/testdata/toString_01/doc_euc-jp.xml deleted file mode 100644 index 887ab5ec30..0000000000 --- a/tests/auto/xml/dom/qdom/testdata/toString_01/doc_euc-jp.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - -<週報> - <年月週> - <年度>1997 - <月度>1 - <週>1 - - - <氏名> - <氏>山田 - <名>太郎 - - - <業務報告リスト> - <業務報告> - <業務名>XMLエディターの作成 - <業務コード>X3355-23 - <工数管理> - <見積もり工数>1600 - <実績工数>320 - <当月見積もり工数>160 - <当月実績工数>24 - - <予定項目リスト> - <予定項目> -

XMLエディターの基本仕様の作成

- - - <実施事項リスト> - <実施事項> -

XMLエディターの基本仕様の作成

- - <実施事項> -

競合他社製品の機能調査

- - - <上長への要請事項リスト> - <上長への要請事項> -

特になし

- - - <問題点対策> -

XMLとは何かわからない。

- - - - <業務報告> - <業務名>検索エンジンの開発 - <業務コード>S8821-76 - <工数管理> - <見積もり工数>120 - <実績工数>6 - <当月見積もり工数>32 - <当月実績工数>2 - - <予定項目リスト> - <予定項目> -

gooの機能を調べてみる

- - - <実施事項リスト> - <実施事項> -

更に、どういう検索エンジンがあるか調査する

- - - <上長への要請事項リスト> - <上長への要請事項> -

開発をするのはめんどうなので、Yahoo!を買収して下さい。

- - - <問題点対策> -

検索エンジンで車を走らせることができない。(要調査)

- - - - diff --git a/tests/auto/xml/dom/qdom/testdata/toString_01/doc_iso-2022-jp.xml b/tests/auto/xml/dom/qdom/testdata/toString_01/doc_iso-2022-jp.xml deleted file mode 100644 index 9a8e8545ac..0000000000 --- a/tests/auto/xml/dom/qdom/testdata/toString_01/doc_iso-2022-jp.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - -<$B=5Js(B> - <$BG/7n=5(B> - <$BG/EY(B>1997 - <$B7nEY(B>1 - <$B=5(B>1 - - - <$B;aL>(B> - <$B;a(B>$B;3ED(B - <$BL>(B>$BB@O:(B(B> - (B> - - <$B6HL3Js9p%j%9%H(B> - <$B6HL3Js9p(B> - <$B6HL3L>(B>XML$B%(%G%#%?!<$N:n@.(B(B> - <$B6HL3%3!<%I(B>X3355-23 - <$B9)?t4IM}(B> - <$B8+@Q$b$j9)?t(B>1600 - <$B320 - <$BEv7n8+@Q$b$j9)?t(B>160 - <$BEv7n24 - - <$BM=Dj9`L\%j%9%H(B> - <$BM=Dj9`L\(B> -

XML$B%(%G%#%?!<$N4pK\;EMM$N:n@.(B

- - - <$B - <$B -

XML$B%(%G%#%?!<$N4pK\;EMM$N:n@.(B

- - <$B -

$B6%9gB> - - - <$B>eD9$X$NMW@A;v9`%j%9%H(B> - <$B>eD9$X$NMW@A;v9`(B> -

$BFC$K$J$7(B

- eD9$X$NMW@A;v9`(B> - eD9$X$NMW@A;v9`%j%9%H(B> - <$BLdBjE@BP:v(B> -

XML$B$H$O2?$+$o$+$i$J$$!#(B

- - - - <$B6HL3Js9p(B> - <$B6HL3L>(B>$B8!:w%(%s%8%s$N3+H/(B(B> - <$B6HL3%3!<%I(B>S8821-76 - <$B9)?t4IM}(B> - <$B8+@Q$b$j9)?t(B>120 - <$B6 - <$BEv7n8+@Q$b$j9)?t(B>32 - <$BEv7n2 - - <$BM=Dj9`L\%j%9%H(B> - <$BM=Dj9`L\(B> -

goo$B$N5!G=$rD4$Y$F$_$k(B

- - - <$B - <$B -

$B99$K!"$I$&$$$&8!:w%(%s%8%s$,$"$k$+D4::$9$k(B

- - - <$B>eD9$X$NMW@A;v9`%j%9%H(B> - <$B>eD9$X$NMW@A;v9`(B> -

$B3+H/$r$9$k$N$O$a$s$I$&$J$N$G!"(BYahoo!$B$rGc<}$7$F2<$5$$!#(B

- eD9$X$NMW@A;v9`(B> - eD9$X$NMW@A;v9`%j%9%H(B> - <$BLdBjE@BP:v(B> -

$B8!:w%(%s%8%s$G - - - - diff --git a/tests/auto/xml/dom/qdom/tst_qdom.cpp b/tests/auto/xml/dom/qdom/tst_qdom.cpp index 7cb110eab7..65cdaeb3c6 100644 --- a/tests/auto/xml/dom/qdom/tst_qdom.cpp +++ b/tests/auto/xml/dom/qdom/tst_qdom.cpp @@ -299,8 +299,6 @@ void tst_QDom::toString_01_data() QTest::newRow( "04" ) << QString(prefix + "/doc04.xml"); QTest::newRow( "05" ) << QString(prefix + "/doc05.xml"); - QTest::newRow( "euc-jp" ) << QString(prefix + "/doc_euc-jp.xml"); - QTest::newRow( "iso-2022-jp" ) << QString(prefix + "/doc_iso-2022-jp.xml"); QTest::newRow( "little-endian" ) << QString(prefix + "/doc_little-endian.xml"); QTest::newRow( "utf-16" ) << QString(prefix + "/doc_utf-16.xml"); QTest::newRow( "utf-8" ) << QString(prefix + "/doc_utf-8.xml"); @@ -576,48 +574,39 @@ void tst_QDom::saveWithSerialization() const // Read the document QVERIFY(doc.setContent(&f)); - QByteArray codecName; - - foreach (codecName, m_testCodecs) { - /* Write out doc in the specified codec. */ - QByteArray storage; - QBuffer writeDevice(&storage); - QVERIFY(writeDevice.open(QIODevice::WriteOnly)); + QByteArray storage; + QBuffer writeDevice(&storage); + QVERIFY(writeDevice.open(QIODevice::WriteOnly)); - QTextStream s(&writeDevice); - QTextCodec *codec = QTextCodec::codecForName(codecName); - QVERIFY2(codec, qPrintable(QString::fromLatin1("Failed to load codec %1").arg(QString::fromLatin1(codecName.constData())))); - s.setCodec(codec); + QTextStream s(&writeDevice); - doc.save(s, 0, QDomNode::EncodingFromTextStream); - s.flush(); - writeDevice.close(); + doc.save(s, 0, QDomNode::EncodingFromTextStream); + s.flush(); + writeDevice.close(); - QBuffer readDevice(&storage); - QVERIFY(readDevice.open(QIODevice::ReadOnly)); + QBuffer readDevice(&storage); + QVERIFY(readDevice.open(QIODevice::ReadOnly)); - QDomDocument result; + QDomDocument result; - QString msg; - int line = 0; - int column = 0; + QString msg; + int line = 0; + int column = 0; - QVERIFY2(result.setContent(&readDevice, &msg, &line, &column), - qPrintable(QString::fromLatin1("Failed for codec %1: line %2, column %3: %4, content: %5") - .arg(QString::fromLatin1(codecName.constData()), - QString::number(line), - QString::number(column), - msg, - codec->toUnicode(storage)))); - if(!compareDocuments(doc, result)) - { - QCOMPARE(doc.toString(), result.toString()); + QVERIFY2(result.setContent(&readDevice, &msg, &line, &column), + qPrintable(QString::fromLatin1("Failed: line %2, column %3: %4, content: %5") + .arg(QString::number(line), + QString::number(column), + msg, + QString::fromUtf8(storage)))); + if (!compareDocuments(doc, result)) + { + QCOMPARE(doc.toString(), result.toString()); - /* We put this one here as well, in case the QCOMPARE above for some strange reason - * nevertheless succeeds. */ - QVERIFY2(false, qPrintable(QString::fromLatin1("Failed for codec %1").arg(QString::fromLatin1(codecName.constData())))); - } + /* We put this one here as well, in case the QCOMPARE above for some strange reason + * nevertheless succeeds. */ + QVERIFY2(false, qPrintable(QString::fromLatin1("Failed to serialize test data"))); } } @@ -633,8 +622,6 @@ void tst_QDom::saveWithSerialization_data() const QTest::newRow("doc04.xml") << QString(prefix + "/doc04.xml"); QTest::newRow("doc05.xml") << QString(prefix + "/doc05.xml"); - QTest::newRow("doc_euc-jp.xml") << QString(prefix + "/doc_euc-jp.xml"); - QTest::newRow("doc_iso-2022-jp.xml") << QString(prefix + "/doc_iso-2022-jp.xml"); QTest::newRow("doc_little-endian.xml") << QString(prefix + "/doc_little-endian.xml"); QTest::newRow("doc_utf-16.xml") << QString(prefix + "/doc_utf-16.xml"); QTest::newRow("doc_utf-8.xml") << QString(prefix + "/doc_utf-8.xml"); @@ -1800,7 +1787,6 @@ void tst_QDom::germanUmlautToByteArray() const QBuffer buffer(&data); QVERIFY(buffer.open(QIODevice::WriteOnly)); QTextStream ts(&buffer); - ts.setCodec("UTF-8"); ts << d.toString(); buffer.close(); @@ -1832,7 +1818,6 @@ void tst_QDom::germanUmlautToFile() const QTemporaryFile file; QVERIFY(file.open()); QTextStream ts(&file); - ts.setCodec("UTF-8"); ts << d.toString(); file.close(); -- cgit v1.2.3