summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2018-03-23 19:00:30 +0100
committerLiang Qi <liang.qi@qt.io>2018-04-05 19:56:47 +0000
commit3c8181de7006cab3c2d736dfb4adabe9b2ffaf4e (patch)
tree8e5e9c36cfdd6c4239abb993a03567d28e02f29f /tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
parentf1fc449016333525aef5bde51c2de666f2da1790 (diff)
Kludge QLocale test order to fix fall-out from setDefault()
This makes an irreversible global change: tests that do it will mess with other tests. So make sure they're all last. This required splitting up one test; and revealed another that secretly depended on being run with C as default locale. Task-number: QTBUG-67276 Change-Id: Ic24ef48b2c9bd5c37c1f11260b437628019624ca Reviewed-by: Kari Oikarinen <kari.oikarinen@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools/qlocale/tst_qlocale.cpp')
-rw-r--r--tests/auto/corelib/tools/qlocale/tst_qlocale.cpp38
1 files changed, 28 insertions, 10 deletions
diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
index d5e2935d28..c6c16a5982 100644
--- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
@@ -79,9 +79,7 @@ private slots:
void ctor();
void emptyCtor();
- void legacyNames();
void consistentC();
- void unixLocaleName();
void matchingLocales();
void stringToDouble_data();
void stringToDouble();
@@ -108,8 +106,6 @@ private slots:
void toDateTime();
void negativeNumbers();
void numberOptions();
- void testNames_data();
- void testNames();
void dayName_data();
void dayName();
void standaloneDayName_data();
@@ -143,6 +139,15 @@ private slots:
void systemLocale();
+ // *** ORDER-DEPENDENCY *** (This Is Bad.)
+ // Test order is determined by order of declaration here: *all* tests that
+ // QLocale::setDefault() *must* appear *after* all other tests !
+ void defaulted_ctor(); // This one must be the first of these.
+ void legacyNames();
+ void unixLocaleName();
+ void testNames_data();
+ void testNames();
+ // DO NOT add tests here unless they QLocale::setDefault(); see above.
private:
QString m_decimal, m_thousand, m_sdate, m_ldate, m_time;
QString m_sysapp;
@@ -232,6 +237,23 @@ void tst_QLocale::ctor()
TEST_CTOR(Chinese, LatinScript, UnitedStates, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China);
#undef TEST_CTOR
+}
+
+void tst_QLocale::defaulted_ctor()
+{
+ QLocale default_locale = QLocale::system();
+ QLocale::Language default_lang = default_locale.language();
+ QLocale::Country default_country = default_locale.country();
+
+ qDebug("Default: %s/%s", QLocale::languageToString(default_lang).toLatin1().constData(),
+ QLocale::countryToString(default_country).toLatin1().constData());
+
+ {
+ QLocale l(QLocale::C, QLocale::AnyCountry);
+ QCOMPARE(l.language(), QLocale::C);
+ QCOMPARE(l.country(), QLocale::AnyCountry);
+ }
+
#define TEST_CTOR(req_lang, req_country, exp_lang, exp_country) \
{ \
QLocale l(QLocale::req_lang, QLocale::req_country); \
@@ -239,11 +261,6 @@ void tst_QLocale::ctor()
QCOMPARE((int)l.country(), (int)exp_country); \
}
- {
- QLocale l(QLocale::C, QLocale::AnyCountry);
- QCOMPARE(l.language(), QLocale::C);
- QCOMPARE(l.country(), QLocale::AnyCountry);
- }
TEST_CTOR(AnyLanguage, AnyCountry, default_lang, default_country)
TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry)
TEST_CTOR(Aymara, AnyCountry, default_lang, default_country)
@@ -1961,10 +1978,11 @@ void tst_QLocale::testNames_data()
QTest::addColumn<int>("language");
QTest::addColumn<int>("country");
+ QLocale::setDefault(QLocale(QLocale::C)); // Ensures predictable fall-backs
+
for (int i = 0; i < locale_data_count; ++i) {
const QLocaleData &item = locale_data[i];
-
const QString testName = QLatin1String("data_") + QString::number(i) + QLatin1String(" (")
+ QLocale::languageToString((QLocale::Language)item.m_language_id)
+ QLatin1Char('/') + QLocale::countryToString((QLocale::Country)item.m_country_id)