summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlbert Astals Cid <albert.astals.cid@kdab.com>2018-01-02 10:48:34 +0100
committerAlbert Astals Cid <albert.astals.cid@kdab.com>2018-03-02 09:52:14 +0000
commit78e92997ed35ddc8bb6f7f6c0a4fffba026d5d8f (patch)
tree664e5e4bfa78c1d07316a18a48e503c197048fc0 /tests
parentfdddb3a4814f588e3ee87a6c1a0a6791f6ef0298 (diff)
QLocale: Update the system private on QLocale default constructor if needed
When first starting an Android app we have invocation order issue, to load the platform plugin we create the default QLocale (needed by the resource locator code to see if :/qt/etc/qt.conf exists) so when the android platform plugin loads and creates its own QSystemLocale, the QLocale defaultLocalePrivate is already created and pointing to globalLocaleData which means that systemData won't be called and thus the code that triggers the call to QLocalePrivate::updateSystemPrivate won't be called when calling QLocale(). I thought of two ways of fixing this, one was calling QLocalePrivate::updateSystemPrivatea() from the QAndroidSystemLocale constructor, but giving the responsibility to not break things to the plugin seems a little fragile, so making the check on QLocale() seems better. Without this patch an Android app doing QApplication app(argc, argv); qDebug() << QLocale().name(); qDebug() << QLocale().name(); qDebug() << QLocale::system().name(); qDebug() << QLocale().name(); would print "" "" "ca_ES" "ca_ES" now it correctly prints "ca_ES" the four times. Task-number: QTBUG-41385 Change-Id: I2cf419f59aa008fa3aca11295fe7d42c40bcc32e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qlocale/tst_qlocale.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
index fc1ac7cf0f..d5e2935d28 100644
--- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
@@ -141,6 +141,8 @@ private slots:
void formattedDataSize();
void bcp47Name();
+ void systemLocale();
+
private:
QString m_decimal, m_thousand, m_sdate, m_ldate, m_time;
QString m_sysapp;
@@ -2641,5 +2643,49 @@ void tst_QLocale::bcp47Name()
QCOMPARE(QLocale("sr_Latn_HR").bcp47Name(), QStringLiteral("sr-Latn"));
}
+class MySystemLocale : public QSystemLocale
+{
+public:
+ MySystemLocale(const QLocale &locale) : m_locale(locale)
+ {
+ }
+
+ QVariant query(QueryType /*type*/, QVariant /*in*/) const override
+ {
+ return QVariant();
+ }
+
+ QLocale fallbackUiLocale() const override
+ {
+ return m_locale;
+ }
+
+private:
+ const QLocale m_locale;
+};
+
+void tst_QLocale::systemLocale()
+{
+ QLocale originalLocale;
+
+ MySystemLocale *sLocale = new MySystemLocale(QLocale("uk"));
+ QCOMPARE(QLocale().language(), QLocale::Ukrainian);
+ QCOMPARE(QLocale::system().language(), QLocale::Ukrainian);
+ delete sLocale;
+
+ sLocale = new MySystemLocale(QLocale("ca"));
+ QCOMPARE(QLocale().language(), QLocale::Catalan);
+ QCOMPARE(QLocale::system().language(), QLocale::Catalan);
+ delete sLocale;
+
+ sLocale = new MySystemLocale(QLocale("de"));
+ QCOMPARE(QLocale().language(), QLocale::German);
+ QCOMPARE(QLocale::system().language(), QLocale::German);
+ delete sLocale;
+
+ QCOMPARE(QLocale(), originalLocale);
+ QCOMPARE(QLocale::system(), originalLocale);
+}
+
QTEST_MAIN(tst_QLocale)
#include "tst_qlocale.moc"