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>
This commit is contained in:
Edward Welbourne 2018-03-23 19:00:30 +01:00 committed by Liang Qi
parent f1fc449016
commit 3c8181de70

View File

@ -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)