diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-04-28 18:15:54 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-05-14 07:50:19 +0200 |
commit | 4d67b9dcfbb379d9d65a5a1fec74600273941637 (patch) | |
tree | ae56788e3613bc164ec7bd3f8e38e8ba9c86d64f /tests/auto | |
parent | 33bb695a2895fb7199b256a4fd76923c32a8587a (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto')
5 files changed, 30 insertions, 261 deletions
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 <QtTest/QtTest> #include <QPair> -#include <QTextCodec> #include <QSysInfo> #include <QLatin1String> @@ -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<const char *, const char *> stringpair; Q_DECLARE_METATYPE(stringpair) -void tst_QGlobal::qprintable() -{ - QFETCH(QVector<stringpair>, 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<QVector<stringpair> >("localestrings"); - QTest::addColumn<int>("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<stringpair> 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 <QDebug> #include <QElapsedTimer> #include <QFile> +#include <QStringConverter> #include <QTcpSocket> #include <QTemporaryDir> #include <QTextStream> -#include <QTextCodec> #if QT_CONFIG(process) # include <QProcess> #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<QIODevice *>(0)); QCOMPARE(stream.string(), static_cast<QString *>(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 @@ -<?xml version="1.0" encoding="euc-jp"?>
-<!DOCTYPE 週報 SYSTEM "weekly-euc-jp.dtd">
-<!-- 週報サンプル -->
-<週報>
- <年月週>
- <年度>1997</年度>
- <月度>1</月度>
- <週>1</週>
- </年月週>
-
- <氏名>
- <氏>山田</氏>
- <名>太郎</名>
- </氏名>
-
- <業務報告リスト>
- <業務報告>
- <業務名>XMLエディターの作成</業務名>
- <業務コード>X3355-23</業務コード>
- <工数管理>
- <見積もり工数>1600</見積もり工数>
- <実績工数>320</実績工数>
- <当月見積もり工数>160</当月見積もり工数>
- <当月実績工数>24</当月実績工数>
- </工数管理>
- <予定項目リスト>
- <予定項目>
- <P>XMLエディターの基本仕様の作成</P>
- </予定項目>
- </予定項目リスト>
- <実施事項リスト>
- <実施事項>
- <P>XMLエディターの基本仕様の作成</P>
- </実施事項>
- <実施事項>
- <P>競合他社製品の機能調査</P>
- </実施事項>
- </実施事項リスト>
- <上長への要請事項リスト>
- <上長への要請事項>
- <P>特になし</P>
- </上長への要請事項>
- </上長への要請事項リスト>
- <問題点対策>
- <P>XMLとは何かわからない。</P>
- </問題点対策>
- </業務報告>
-
- <業務報告>
- <業務名>検索エンジンの開発</業務名>
- <業務コード>S8821-76</業務コード>
- <工数管理>
- <見積もり工数>120</見積もり工数>
- <実績工数>6</実績工数>
- <当月見積もり工数>32</当月見積もり工数>
- <当月実績工数>2</当月実績工数>
- </工数管理>
- <予定項目リスト>
- <予定項目>
- <P><A href="http://www.goo.ne.jp">goo</A>の機能を調べてみる</P>
- </予定項目>
- </予定項目リスト>
- <実施事項リスト>
- <実施事項>
- <P>更に、どういう検索エンジンがあるか調査する</P>
- </実施事項>
- </実施事項リスト>
- <上長への要請事項リスト>
- <上長への要請事項>
- <P>開発をするのはめんどうなので、Yahoo!を買収して下さい。</P>
- </上長への要請事項>
- </上長への要請事項リスト>
- <問題点対策>
- <P>検索エンジンで車を走らせることができない。(要調査)</P>
- </問題点対策>
- </業務報告>
- </業務報告リスト>
-</週報>
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 @@ -<?xml version="1.0" encoding="iso-2022-jp"?>
-<!DOCTY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$+$o$+$i$J$$!#(B</P>
- </$BLdBjE@BP:v(B>
- </$B6HL3Js9p(B>
-
- <$B6HL3Js9p(B>
- <$B6HL3L>(B>$B8!:w%(%s%8%s$N3+H/(B</$B6HL3L>(B>
- <$B6HL3%3!<%I(B>S8821-76</$B6HL3%3!<%I(B>
- <$B9)?t4IM}(B>
- <$B8+@Q$b$j9)?t(B>120</$B8+@Q$b$j9)?t(B>
- <$B<B@S9)?t(B>6</$B<B@S9)?t(B>
- <$BEv7n8+@Q$b$j9)?t(B>32</$BEv7n8+@Q$b$j9)?t(B>
- <$BEv7n<B@S9)?t(B>2</$BEv7n<B@S9)?t(B>
- </$B9)?t4IM}(B>
- <$BM=Dj9`L\%j%9%H(B>
- <$BM=Dj9`L\(B>
- <P><A href="http://www.goo.ne.jp">goo</A>$B$N5!G=$rD4$Y$F$_$k(B</P>
- </$BM=Dj9`L\(B>
- </$BM=Dj9`L\%j%9%H(B>
- <$B<B;\;v9`%j%9%H(B>
- <$B<B;\;v9`(B>
- <P>$B99$K!"$I$&$$$&8!:w%(%s%8%s$,$"$k$+D4::$9$k(B</P>
- </$B<B;\;v9`(B>
- </$B<B;\;v9`%j%9%H(B>
- <$B>eD9$X$NMW@A;v9`%j%9%H(B>
- <$B>eD9$X$NMW@A;v9`(B>
- <P>$B3+H/$r$9$k$N$O$a$s$I$&$J$N$G!"(BYahoo!$B$rGc<}$7$F2<$5$$!#(B</P>
- </$B>eD9$X$NMW@A;v9`(B>
- </$B>eD9$X$NMW@A;v9`%j%9%H(B>
- <$BLdBjE@BP:v(B>
- <P>$B8!:w%(%s%8%s$G<V$rAv$i$;$k$3$H$,$G$-$J$$!#!JMWD4::!K(B</P>
- </$BLdBjE@BP:v(B>
- </$B6HL3Js9p(B>
- </$B6HL3Js9p%j%9%H(B>
-</$B=5Js(B>
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(); |