Made more tst_QLocale tests data-driven

This should improve reporting and ensure we know about each failing
case, not just the first, when one fails.

Change-Id: Ic00272201f69a2fd8508df23b1d746ea605aa539
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Kari Oikarinen <kari.oikarinen@qt.io>
This commit is contained in:
Edward Welbourne 2018-07-10 14:26:20 +02:00
parent 3c0f33e4a0
commit 9d52eb9ed0

View File

@ -118,8 +118,10 @@ private slots:
void monthName(); void monthName();
void standaloneMonthName(); void standaloneMonthName();
void defaultNumeringSystem_data();
void defaultNumeringSystem(); void defaultNumeringSystem();
void ampm_data();
void ampm(); void ampm();
void currency(); void currency();
void quoteString(); void quoteString();
@ -127,6 +129,7 @@ private slots:
void weekendDays(); void weekendDays();
void listPatterns(); void listPatterns();
void measurementSystems_data();
void measurementSystems(); void measurementSystems();
void QTBUG_26035_positivesign(); void QTBUG_26035_positivesign();
@ -135,6 +138,7 @@ private slots:
void formattedDataSize_data(); void formattedDataSize_data();
void formattedDataSize(); void formattedDataSize();
void bcp47Name_data();
void bcp47Name(); void bcp47Name();
void systemLocale_data(); void systemLocale_data();
@ -145,6 +149,7 @@ private slots:
// QLocale::setDefault() *must* appear *after* all other tests ! // QLocale::setDefault() *must* appear *after* all other tests !
void defaulted_ctor(); // This one must be the first of these. void defaulted_ctor(); // This one must be the first of these.
void legacyNames(); void legacyNames();
void unixLocaleName_data();
void unixLocaleName(); void unixLocaleName();
void testNames_data(); void testNames_data();
void testNames(); void testNames();
@ -670,22 +675,32 @@ void tst_QLocale::matchingLocales()
QVERIFY(locales.contains(ru_RU)); QVERIFY(locales.contains(ru_RU));
} }
void tst_QLocale::unixLocaleName_data()
{
QTest::addColumn<QLocale::Language>("lang");
QTest::addColumn<QLocale::Country>("land");
QTest::addColumn<QString>("expect");
#define ADDROW(nom, lang, land, name) \
QTest::newRow(nom) << QLocale::lang << QLocale::land << QStringLiteral(name)
ADDROW("C_any", C, AnyCountry, "C");
ADDROW("en_any", English, AnyCountry, "en_US");
ADDROW("en_GB", English, UnitedKingdom, "en_GB");
ADDROW("ay_GB", Aymara, UnitedKingdom, "C");
#undef ADDROW
}
void tst_QLocale::unixLocaleName() void tst_QLocale::unixLocaleName()
{ {
#define TEST_NAME(req_lang, req_country, exp_name) \ QFETCH(QLocale::Language, lang);
{ \ QFETCH(QLocale::Country, land);
QLocale l(QLocale::req_lang, QLocale::req_country); \ QFETCH(QString, expect);
QCOMPARE(l.name(), QString(exp_name)); \
}
QLocale::setDefault(QLocale(QLocale::C)); QLocale::setDefault(QLocale(QLocale::C));
TEST_NAME(C, AnyCountry, "C") QLocale locale(lang, land);
TEST_NAME(English, AnyCountry, "en_US") QCOMPARE(locale.name(), expect);
TEST_NAME(English, UnitedKingdom, "en_GB")
TEST_NAME(Aymara, UnitedKingdom, "C")
#undef TEST_NAME
} }
void tst_QLocale::stringToDouble_data() void tst_QLocale::stringToDouble_data()
@ -2189,75 +2204,56 @@ void tst_QLocale::underflowOverflow()
QVERIFY(!ok); QVERIFY(!ok);
} }
void tst_QLocale::defaultNumeringSystem_data()
{
QTest::addColumn<QString>("expect");
QTest::newRow("sk_SK") << QStringLiteral("123");
QTest::newRow("ta_IN") << QStringLiteral("123");
QTest::newRow("te_IN") << QStringLiteral("123");
QTest::newRow("hi_IN") << QStringLiteral("123");
QTest::newRow("gu_IN") << QStringLiteral("123");
QTest::newRow("kn_IN") << QStringLiteral("123");
QTest::newRow("pa_IN") << QStringLiteral("123");
QTest::newRow("ne_IN") << QString::fromUtf8("१२३");
QTest::newRow("mr_IN") << QString::fromUtf8("१२३");
QTest::newRow("ml_IN") << QStringLiteral("123");
QTest::newRow("kok_IN") << QStringLiteral("123");
}
void tst_QLocale::defaultNumeringSystem() void tst_QLocale::defaultNumeringSystem()
{ {
QLocale sk("sk_SK"); QFETCH(QString, expect);
QCOMPARE(sk.toString(123), QLatin1String("123")); QLatin1String name(QTest::currentDataTag());
QLocale locale(name);
QCOMPARE(locale.toString(123), expect);
}
QLocale ta("ta_IN"); void tst_QLocale::ampm_data()
QCOMPARE(ta.toString(123), QLatin1String("123")); {
QTest::addColumn<QString>("morn");
QTest::addColumn<QString>("even");
QLocale te("te_IN"); QTest::newRow("C") << QStringLiteral("AM") << QStringLiteral("PM");
QCOMPARE(te.toString(123), QLatin1String("123")); QTest::newRow("de_DE") << QStringLiteral("AM") << QStringLiteral("PM");
QTest::newRow("sv_SE") << QStringLiteral("fm") << QStringLiteral("em");
QLocale hi("hi_IN"); QTest::newRow("nl_NL") << QStringLiteral("a.m.") << QStringLiteral("p.m.");
QCOMPARE(hi.toString(123), QLatin1String("123")); QTest::newRow("uk_UA") << QString::fromUtf8("\320\264\320\277")
<< QString::fromUtf8("\320\277\320\277");
QLocale gu("gu_IN"); QTest::newRow("tr_TR") << QString::fromUtf8("\303\226\303\226")
QCOMPARE(gu.toString(123), QLatin1String("123")); << QString::fromUtf8("\303\226\123");
QTest::newRow("id_ID") << QStringLiteral("AM") << QStringLiteral("PM");
QLocale kn("kn_IN"); QTest::newRow("ta_LK") << QString::fromUtf8("முற்பகல்") << QString::fromUtf8("பிற்பகல்");
QCOMPARE(kn.toString(123), QLatin1String("123"));
QLocale pa("pa_IN");
QCOMPARE(pa.toString(123), QLatin1String("123"));
QLocale ne("ne_IN");
QCOMPARE(ne.toString(123), QString::fromUtf8("१२३"));
QLocale mr("mr_IN");
QCOMPARE(mr.toString(123), QString::fromUtf8("१२३"));
QLocale ml("ml_IN");
QCOMPARE(ml.toString(123), QLatin1String("123"));
QLocale kok("kok_IN");
QCOMPARE(kok.toString(123), QLatin1String("123"));
} }
void tst_QLocale::ampm() void tst_QLocale::ampm()
{ {
QLocale c(QLocale::C); QFETCH(QString, morn);
QCOMPARE(c.amText(), QLatin1String("AM")); QFETCH(QString, even);
QCOMPARE(c.pmText(), QLatin1String("PM")); QLatin1String name(QTest::currentDataTag());
QLocale locale(name == QLatin1String("C") ? QLocale(QLocale::C) : QLocale(name));
QLocale de("de_DE"); QCOMPARE(locale.amText(), morn);
QCOMPARE(de.amText(), QLatin1String("AM")); QCOMPARE(locale.pmText(), even);
QCOMPARE(de.pmText(), QLatin1String("PM"));
QLocale sv("sv_SE");
QCOMPARE(sv.amText(), QLatin1String("fm"));
QCOMPARE(sv.pmText(), QLatin1String("em"));
QLocale nn("nl_NL");
QCOMPARE(nn.amText(), QLatin1String("a.m."));
QCOMPARE(nn.pmText(), QLatin1String("p.m."));
QLocale ua("uk_UA");
QCOMPARE(ua.amText(), QString::fromUtf8("\320\264\320\277"));
QCOMPARE(ua.pmText(), QString::fromUtf8("\320\277\320\277"));
QLocale tr("tr_TR");
QCOMPARE(tr.amText(), QString::fromUtf8("\303\226\303\226"));
QCOMPARE(tr.pmText(), QString::fromUtf8("\303\226\123"));
QLocale id("id_ID");
QCOMPARE(id.amText(), QLatin1String("AM"));
QCOMPARE(id.pmText(), QLatin1String("PM"));
QLocale ta("ta_LK");
QCOMPARE(ta.amText(), QString::fromUtf8("முற்பகல்"));
QCOMPARE(ta.pmText(), QString::fromUtf8("பிற்பகல்"));
} }
void tst_QLocale::dateFormat() void tst_QLocale::dateFormat()
@ -2534,19 +2530,21 @@ void tst_QLocale::listPatterns()
"ccc" "\xe5\x92\x8c" "ddd")); "ccc" "\xe5\x92\x8c" "ddd"));
} }
void tst_QLocale::measurementSystems_data()
{
QTest::addColumn<QLocale>("locale");
QTest::addColumn<QLocale::MeasurementSystem>("system");
QTest::newRow("en_US") << QLocale(QLocale::English, QLocale::UnitedStates) << QLocale::ImperialUSSystem;
QTest::newRow("en_GB") << QLocale(QLocale::English, QLocale::UnitedKingdom) << QLocale::ImperialUKSystem;
QTest::newRow("en_AU") << QLocale(QLocale::English, QLocale::Australia) << QLocale::MetricSystem;
QTest::newRow("de") << QLocale(QLocale::German) << QLocale::MetricSystem;
}
void tst_QLocale::measurementSystems() void tst_QLocale::measurementSystems()
{ {
QLocale locale(QLocale::English, QLocale::UnitedStates); QFETCH(QLocale, locale);
QCOMPARE(locale.measurementSystem(), QLocale::ImperialUSSystem); QFETCH(QLocale::MeasurementSystem, system);
QCOMPARE(locale.measurementSystem(), system);
locale = QLocale(QLocale::English, QLocale::UnitedKingdom);
QCOMPARE(locale.measurementSystem(), QLocale::ImperialUKSystem);
locale = QLocale(QLocale::English, QLocale::Australia);
QCOMPARE(locale.measurementSystem(), QLocale::MetricSystem);
locale = QLocale(QLocale::German);
QCOMPARE(locale.measurementSystem(), QLocale::MetricSystem);
} }
void tst_QLocale::QTBUG_26035_positivesign() void tst_QLocale::QTBUG_26035_positivesign()
@ -2711,25 +2709,33 @@ void tst_QLocale::formattedDataSize()
QCOMPARE(QLocale(language).formattedDataSize(bytes, decimalPlaces, units), output); QCOMPARE(QLocale(language).formattedDataSize(bytes, decimalPlaces, units), output);
} }
void tst_QLocale::bcp47Name() void tst_QLocale::bcp47Name_data()
{ {
QCOMPARE(QLocale("C").bcp47Name(), QStringLiteral("en")); QTest::addColumn<QString>("expect");
QCOMPARE(QLocale("en").bcp47Name(), QStringLiteral("en"));
QCOMPARE(QLocale("en_US").bcp47Name(), QStringLiteral("en")); QTest::newRow("C") << QStringLiteral("en");
QCOMPARE(QLocale("en_GB").bcp47Name(), QStringLiteral("en-GB")); QTest::newRow("en") << QStringLiteral("en");
QCOMPARE(QLocale("en_DE").bcp47Name(), QStringLiteral("en-DE")); QTest::newRow("en_US") << QStringLiteral("en");
QCOMPARE(QLocale("de_DE").bcp47Name(), QStringLiteral("de")); QTest::newRow("en_GB") << QStringLiteral("en-GB");
QCOMPARE(QLocale("sr_RS").bcp47Name(), QStringLiteral("sr")); QTest::newRow("en_DE") << QStringLiteral("en-DE");
QCOMPARE(QLocale("sr_Cyrl_RS").bcp47Name(), QStringLiteral("sr")); QTest::newRow("de_DE") << QStringLiteral("de");
QCOMPARE(QLocale("sr_Latn_RS").bcp47Name(), QStringLiteral("sr-Latn")); QTest::newRow("sr_RS") << QStringLiteral("sr");
QCOMPARE(QLocale("sr_ME").bcp47Name(), QStringLiteral("sr-ME")); QTest::newRow("sr_Cyrl_RS") << QStringLiteral("sr");
QCOMPARE(QLocale("sr_Cyrl_ME").bcp47Name(), QStringLiteral("sr-Cyrl-ME")); QTest::newRow("sr_Latn_RS") << QStringLiteral("sr-Latn");
QCOMPARE(QLocale("sr_Latn_ME").bcp47Name(), QStringLiteral("sr-ME")); QTest::newRow("sr_ME") << QStringLiteral("sr-ME");
QTest::newRow("sr_Cyrl_ME") << QStringLiteral("sr-Cyrl-ME");
QTest::newRow("sr_Latn_ME") << QStringLiteral("sr-ME");
// Fall back to defaults when country isn't in CLDR for this language: // Fall back to defaults when country isn't in CLDR for this language:
QCOMPARE(QLocale("sr_HR").bcp47Name(), QStringLiteral("sr")); QTest::newRow("sr_HR") << QStringLiteral("sr");
QCOMPARE(QLocale("sr_Cyrl_HR").bcp47Name(), QStringLiteral("sr")); QTest::newRow("sr_Cyrl_HR") << QStringLiteral("sr");
QCOMPARE(QLocale("sr_Latn_HR").bcp47Name(), QStringLiteral("sr-Latn")); QTest::newRow("sr_Latn_HR") << QStringLiteral("sr-Latn");
}
void tst_QLocale::bcp47Name()
{
QFETCH(QString, expect);
QCOMPARE(QLocale(QLatin1String(QTest::currentDataTag())).bcp47Name(), expect);
} }
class MySystemLocale : public QSystemLocale class MySystemLocale : public QSystemLocale