summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/codecs/qtextcodec.cpp8
-rw-r--r--tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp48
2 files changed, 52 insertions, 4 deletions
diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp
index 4ed7b00e53..766e48358d 100644
--- a/src/corelib/codecs/qtextcodec.cpp
+++ b/src/corelib/codecs/qtextcodec.cpp
@@ -600,9 +600,6 @@ QTextCodec* QTextCodec::codecForMib(int mib)
*/
QList<QByteArray> QTextCodec::availableCodecs()
{
-#ifdef QT_USE_ICU
- return QIcuCodec::availableCodecs();
-#else
QMutexLocker locker(textCodecsMutex());
QCoreGlobalData *globalData = QCoreGlobalData::instance();
@@ -616,8 +613,11 @@ QList<QByteArray> QTextCodec::availableCodecs()
codecs += globalData->allCodecs.at(i)->aliases();
}
- return codecs;
+#ifdef QT_USE_ICU
+ codecs += QIcuCodec::availableCodecs();
#endif
+
+ return codecs;
}
/*!
diff --git a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp
index 616fe33309..6329160998 100644
--- a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp
+++ b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp
@@ -102,6 +102,7 @@ private slots:
void moreToFromUnicode();
void shiftJis();
+ void userCodec();
};
void tst_QTextCodec::toUnicode_data()
@@ -2312,6 +2313,53 @@ void tst_QTextCodec::shiftJis()
QCOMPARE(encoded, backslashTilde);
}
+struct UserCodec : public QTextCodec
+{
+ // implement pure virtuals
+ QByteArray name() const Q_DECL_OVERRIDE
+ { return "UserCodec"; }
+ QList<QByteArray> aliases() const Q_DECL_OVERRIDE
+ { return QList<QByteArray>() << "usercodec" << "user-codec"; }
+ int mibEnum() const Q_DECL_OVERRIDE
+ { return 5000; }
+
+ virtual QString convertToUnicode(const char *, int, ConverterState *) const Q_DECL_OVERRIDE
+ { return QString(); }
+ virtual QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const Q_DECL_OVERRIDE
+ { return QByteArray(); }
+};
+
+void tst_QTextCodec::userCodec()
+{
+ // check that it isn't there
+ static bool executedOnce = false;
+ if (executedOnce)
+ QSKIP("Test already executed once");
+
+ QVERIFY(!QTextCodec::availableCodecs().contains("UserCodec"));
+ QVERIFY(!QTextCodec::codecForName("UserCodec"));
+
+ QTextCodec *codec = new UserCodec;
+ executedOnce = true;
+
+ QList<QByteArray> availableCodecs = QTextCodec::availableCodecs();
+ QVERIFY(availableCodecs.contains("UserCodec"));
+ QVERIFY(availableCodecs.contains("usercodec"));
+ QVERIFY(availableCodecs.contains("user-codec"));
+
+ QTextCodec *pcodec = QTextCodec::codecForName("UserCodec");
+ QCOMPARE(pcodec, codec);
+
+ pcodec = QTextCodec::codecForName("user-codec");
+ QCOMPARE(pcodec, codec);
+
+ pcodec = QTextCodec::codecForName("User-Codec");
+ QCOMPARE(pcodec, codec);
+
+ pcodec = QTextCodec::codecForMib(5000);
+ QCOMPARE(pcodec, codec);
+}
+
struct DontCrashAtExit {
~DontCrashAtExit() {
QTextCodec *c = QTextCodec::codecForName("utf8");