diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2010-01-18 13:16:16 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2010-02-08 10:43:53 (GMT) |
commit | a8d09369fea1574b24309d7b7b2bb373021bf387 (patch) | |
tree | 4537704956e55669ff0c6bb07660107b0ab432ab /tests/auto/qtextcodec/tst_qtextcodec.cpp | |
parent | 941b13d52d975069d10093a873cd3a55bb2fd7dd (diff) | |
download | Qt-a8d09369fea1574b24309d7b7b2bb373021bf387.zip Qt-a8d09369fea1574b24309d7b7b2bb373021bf387.tar.gz Qt-a8d09369fea1574b24309d7b7b2bb373021bf387.tar.bz2 |
Make QTextCodec reentrant.
QTextCodec::codecForName and codedForMib were not reentrant
Reviewed-by: Brad
Reviewed-by: Denis
Diffstat (limited to 'tests/auto/qtextcodec/tst_qtextcodec.cpp')
-rw-r--r-- | tests/auto/qtextcodec/tst_qtextcodec.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/qtextcodec/tst_qtextcodec.cpp b/tests/auto/qtextcodec/tst_qtextcodec.cpp index eb348fb..65b0448 100644 --- a/tests/auto/qtextcodec/tst_qtextcodec.cpp +++ b/tests/auto/qtextcodec/tst_qtextcodec.cpp @@ -47,6 +47,8 @@ #include <qtextdocument.h> #include <time.h> #include <qprocess.h> +#include <QtConcurrentMap> +#include <QThreadPool> #ifdef Q_OS_SYMBIAN #define SRCDIR "" @@ -58,6 +60,9 @@ class tst_QTextCodec : public QObject Q_OBJECT private slots: + + void threadSafety(); + void toUnicode_data(); void toUnicode(); void codecForName_data(); @@ -1904,5 +1909,46 @@ void tst_QTextCodec::toLocal8Bit() } #endif +static QByteArray loadAndConvert(const QByteArray &codecName) +{ + QTextCodec *c = QTextCodec::codecForName(codecName); + if (!c) { + qDebug() << "WARNING " << codecName << " not found? "; + return QByteArray(); + } + QString str = QString::fromLatin1(codecName); + QByteArray b = c->fromUnicode(str); + c->toUnicode(b); + return codecName; +} + +static int loadAndConvertMIB(int mib) +{ + QTextCodec *c = QTextCodec::codecForMib(mib); + if (!c) { + qDebug() << "WARNING " << mib << " not found? "; + return 0; + } + QString str = QString::number(mib); + QByteArray b = c->fromUnicode(str); + c->toUnicode(b); + return mib; +} + + +void tst_QTextCodec::threadSafety() +{ + QThreadPool::globalInstance()->setMaxThreadCount(12); + + QList<QByteArray> codecList = QTextCodec::availableCodecs(); + QFuture<QByteArray> res = QtConcurrent::mapped(codecList, loadAndConvert); + + QList<int> mibList = QTextCodec::availableMibs(); + QFuture<int> res2 = QtConcurrent::mapped(mibList, loadAndConvertMIB); + + QCOMPARE(res.results(), codecList); + QCOMPARE(res2.results(), mibList); +} + QTEST_MAIN(tst_QTextCodec) #include "tst_qtextcodec.moc" |