summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-04-28 18:15:54 +0200
committerLars Knoll <lars.knoll@qt.io>2020-05-14 07:50:19 +0200
commit4d67b9dcfbb379d9d65a5a1fec74600273941637 (patch)
treeae56788e3613bc164ec7bd3f8e38e8ba9c86d64f /tests/auto/corelib
parent33bb695a2895fb7199b256a4fd76923c32a8587a (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/corelib')
-rw-r--r--tests/auto/corelib/global/qglobal/tst_qglobal.cpp59
-rw-r--r--tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp11
2 files changed, 5 insertions, 65 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"