Ensure that the user codecs are listed in QTextCodec::availableCodecs
Codecs registered by creating new QTextCodec instances should be listed there. Task-number: QTBUG-32500 Change-Id: I56c00e0d6bbfef55a6cbd571bcf9aa2cf333ef3a Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
parent
bad93acfba
commit
b02eb3b436
@ -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;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user