summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel
diff options
context:
space:
mode:
authorAram So <aram.so@lge.com>2016-11-14 16:42:32 +0900
committerSimon Hausmann <simon.hausmann@qt.io>2017-07-06 18:26:41 +0000
commit06904a7a772357479a1b78b8345716f8d0711b4c (patch)
tree94cbcdb03c148e1832d31aa3ee3a0b2de68e4e66 /tests/auto/corelib/kernel
parent8143f60026456f98aaf2b6afaf1edadfbeb2f1e7 (diff)
Make calling QCoreApplication::translate() thread-safe
Fixed crash on QCoreApplication::translate() call from qqmlThread while QCoreApplication::{install,remove}Translator() is called from the GUI thread. [ChangeLog][QtCore][QCoreApplication] Calling QCoreApplication::translate() is now thread-safe. Task-number: QTBUG-57095 Change-Id: Ie5340a42040a829f311c01332e05d4bbaf60462c Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r--tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp b/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp
index 66971af7b4..5bfe133966 100644
--- a/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp
+++ b/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp
@@ -50,6 +50,7 @@ private slots:
void loadFromResource();
void loadDirectory();
void dependencies();
+ void translationInThreadWhileInstallingTranslator();
private:
int languageChangeEventCounter;
@@ -287,6 +288,52 @@ void tst_QTranslator::dependencies()
}
}
+struct TranslateThread : public QThread
+{
+ bool ok = false;
+ QAtomicInt terminate;
+ QMutex startupLock;
+ QWaitCondition runningCondition;
+
+ void run() {
+ bool startSignalled = false;
+
+ while (terminate.load() == 0) {
+ const QString result = QCoreApplication::translate("QPushButton", "Hello %n world(s)!", 0, 0);
+
+ if (!startSignalled) {
+ QMutexLocker startupLocker(&startupLock);
+ runningCondition.wakeAll();
+ startSignalled = true;
+ }
+
+ ok = (result == QLatin1String("Hallo 0 Welten!"))
+ || (result == QLatin1String("Hello 0 world(s)!"));
+ if (!ok)
+ break;
+ }
+ }
+};
+
+void tst_QTranslator::translationInThreadWhileInstallingTranslator()
+{
+ TranslateThread thread;
+
+ QMutexLocker startupLocker(&thread.startupLock);
+
+ thread.start();
+
+ thread.runningCondition.wait(&thread.startupLock);
+
+ QTranslator *tor = new QTranslator;
+ tor->load("hellotr_la");
+ QCoreApplication::installTranslator(tor);
+
+ ++thread.terminate;
+
+ QVERIFY(thread.wait());
+ QVERIFY(thread.ok);
+}
QTEST_MAIN(tst_QTranslator)
#include "tst_qtranslator.moc"