Clean up time-zone matching logic in tst_QLocale::macDefaultLocale()

The test was computing GMT with a suffix added to it for the offset;
but when the offset is zero there's no need for it.  Cleaned up the
logic so that it only checks for a "padded to two digits with zero" if
the number is single-digit (and use string arithmetic in preference to
wantonly complex .arg()ing; and use simpler names).  Since we don't
try to check anything unless GMT does appear in the string (because
the actual zone ID was used, instead of GMT with an offset), the case
of zero offset has nothing more to check than that GMT was present,
the precondition for checking anything.

Task-number: QTBUG-70322
Change-Id: I0b8abe7e63d9d72fa9cf32f188b47a78a849044b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2018-09-03 14:05:55 +02:00 committed by Liang Qi
parent dff9bb2f9b
commit 017ac02ec4

View File

@ -1802,24 +1802,23 @@ void tst_QLocale::macDefaultLocale()
// Depending on the configured time zone, the time string might not
// contain a GMT specifier. (Sometimes it just names the zone, like "CEST")
if (timeString.contains(QString("GMT"))) {
QString expectedGMTSpecifierBase("GMT");
if (diff >= 0)
expectedGMTSpecifierBase.append(QLatin1Char('+'));
else
expectedGMTSpecifierBase.append(QLatin1Char('-'));
QLatin1String gmt("GMT");
if (timeString.contains(gmt) && diff) {
QLatin1Char sign(diff < 0 ? '-' : '+');
QString number(QString::number(qAbs(diff)));
const QString expect = gmt + sign + number;
QString expectedGMTSpecifier = expectedGMTSpecifierBase + QString("%1").arg(qAbs(diff));
QString expectedGMTSpecifierZeroExtended
= expectedGMTSpecifierBase + QString("0%1").arg(qAbs(diff));
if (diff < 10) {
const QString zeroed = gmt + sign + QLatin1Char('0') + number;
QVERIFY2(timeString.contains(expectedGMTSpecifier)
|| timeString.contains(expectedGMTSpecifierZeroExtended),
qPrintable(QString("timeString `%1', expectedGMTSpecifier `%2' or `%3'")
.arg(timeString)
.arg(expectedGMTSpecifier)
.arg(expectedGMTSpecifierZeroExtended)
));
QVERIFY2(timeString.contains(expect) || timeString.contains(zeroed),
qPrintable(QString("timeString `%1', expected GMT specifier `%2' or `%3'")
.arg(timeString).arg(expect).arg(zeroed)));
} else {
QVERIFY2(timeString.contains(expect),
qPrintable(QString("timeString `%1', expected GMT specifier `%2'")
.arg(timeString).arg(expect)));
}
}
QCOMPARE(locale.dayName(1), QString("Monday"));
QCOMPARE(locale.dayName(7), QString("Sunday"));