Skip to content

Commit

Permalink
Rework tst_QTimeZone::windowsId() to use initializer-lists
Browse files Browse the repository at this point in the history
Instead of clearing a list repeatedly to then repopulate it by
appending entries.

Change-Id: I82594d69c1cb145defff43d84f92f8410d8997aa
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
ediosyncratic committed Feb 5, 2024
1 parent 83f0796 commit 46c1936
Showing 1 changed file with 48 additions and 40 deletions.
88 changes: 48 additions & 40 deletions tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,46 +998,54 @@ void tst_QTimeZone::windowsId()
QByteArray("CST6CDT"));
QCOMPARE(QTimeZone::windowsIdToDefaultIanaId(QByteArray()), QByteArray());

// No country is sorted list of all zones
QList<QByteArray> list;
list << "America/Chicago" << "America/Indiana/Knox" << "America/Indiana/Tell_City"
<< "America/Matamoros" << "America/Menominee" << "America/North_Dakota/Beulah"
<< "America/North_Dakota/Center" << "America/North_Dakota/New_Salem"
<< "America/Ojinaga" << "America/Rainy_River" << "America/Rankin_Inlet"
<< "America/Resolute" << "America/Winnipeg" << "CST6CDT";
QCOMPARE(QTimeZone::windowsIdToIanaIds("Central Standard Time"), list);

// Check country with no match returns empty list
list.clear();
QCOMPARE(QTimeZone::windowsIdToIanaIds("Central Standard Time", QLocale::NewZealand),
list);

// Check valid country returns list in preference order
list.clear();
list << "America/Winnipeg" << "America/Rainy_River" << "America/Rankin_Inlet"
<< "America/Resolute";
QCOMPARE(QTimeZone::windowsIdToIanaIds("Central Standard Time", QLocale::Canada), list);

list.clear();
list << "America/Matamoros" << "America/Ojinaga";
QCOMPARE(QTimeZone::windowsIdToIanaIds("Central Standard Time", QLocale::Mexico), list);

list.clear();
list << "America/Chicago" << "America/Indiana/Knox" << "America/Indiana/Tell_City"
<< "America/Menominee" << "America/North_Dakota/Beulah" << "America/North_Dakota/Center"
<< "America/North_Dakota/New_Salem";
QCOMPARE(QTimeZone::windowsIdToIanaIds("Central Standard Time", QLocale::UnitedStates),
list);

list.clear();
list << "CST6CDT";
QCOMPARE(QTimeZone::windowsIdToIanaIds("Central Standard Time", QLocale::AnyTerritory),
list);

// Check no windowsId return empty
list.clear();
QCOMPARE(QTimeZone::windowsIdToIanaIds(QByteArray()), list);
QCOMPARE(QTimeZone::windowsIdToIanaIds(QByteArray(), QLocale::AnyTerritory), list);
{
// With no country, expect sorted list of all zones for ID
const QList<QByteArray> list = {
"America/Chicago", "America/Indiana/Knox", "America/Indiana/Tell_City",
"America/Matamoros", "America/Menominee", "America/North_Dakota/Beulah",
"America/North_Dakota/Center", "America/North_Dakota/New_Salem",
"America/Ojinaga", "America/Rainy_River", "America/Rankin_Inlet",
"America/Resolute", "America/Winnipeg", "CST6CDT"
};
QCOMPARE(QTimeZone::windowsIdToIanaIds("Central Standard Time"), list);
}
{
// Check country with no match returns empty list
const QList<QByteArray> empty;
QCOMPARE(QTimeZone::windowsIdToIanaIds("Central Standard Time", QLocale::NewZealand),
empty);
}
{
// Check valid country returns list in preference order
const QList<QByteArray> list = {
"America/Winnipeg", "America/Rainy_River", "America/Rankin_Inlet", "America/Resolute"
};
QCOMPARE(QTimeZone::windowsIdToIanaIds("Central Standard Time", QLocale::Canada), list);
}
{
const QList<QByteArray> list = { "America/Matamoros", "America/Ojinaga" };
QCOMPARE(QTimeZone::windowsIdToIanaIds("Central Standard Time", QLocale::Mexico), list);
}
{
const QList<QByteArray> list = {
"America/Chicago", "America/Indiana/Knox", "America/Indiana/Tell_City",
"America/Menominee", "America/North_Dakota/Beulah", "America/North_Dakota/Center",
"America/North_Dakota/New_Salem"
};
QCOMPARE(QTimeZone::windowsIdToIanaIds("Central Standard Time", QLocale::UnitedStates),
list);
}
{
const QList<QByteArray> list = { "CST6CDT" };
QCOMPARE(QTimeZone::windowsIdToIanaIds("Central Standard Time", QLocale::AnyTerritory),
list);
}
{
// Check empty if given no windowsId:
const QList<QByteArray> empty;
QCOMPARE(QTimeZone::windowsIdToIanaIds(QByteArray()), empty);
QCOMPARE(QTimeZone::windowsIdToIanaIds(QByteArray(), QLocale::AnyTerritory), empty);
}
}

void tst_QTimeZone::isValidId_data()
Expand Down

0 comments on commit 46c1936

Please sign in to comment.