summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qlocale
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2018-09-03 14:05:55 +0200
committerLiang Qi <liang.qi@qt.io>2018-09-11 14:40:22 +0000
commit017ac02ec459378074a44487f171cc909e947f4a (patch)
tree8d454dbcfac0532571221936d2119ac893569625 /tests/auto/corelib/tools/qlocale
parentdff9bb2f9b981e263d8d3d5b1ef67054297e731c (diff)
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>
Diffstat (limited to 'tests/auto/corelib/tools/qlocale')
-rw-r--r--tests/auto/corelib/tools/qlocale/tst_qlocale.cpp35
1 files changed, 17 insertions, 18 deletions
diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
index 2556c7e618..261689d401 100644
--- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
@@ -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('-'));
-
- QString expectedGMTSpecifier = expectedGMTSpecifierBase + QString("%1").arg(qAbs(diff));
- QString expectedGMTSpecifierZeroExtended
- = expectedGMTSpecifierBase + QString("0%1").arg(qAbs(diff));
-
- QVERIFY2(timeString.contains(expectedGMTSpecifier)
- || timeString.contains(expectedGMTSpecifierZeroExtended),
- qPrintable(QString("timeString `%1', expectedGMTSpecifier `%2' or `%3'")
- .arg(timeString)
- .arg(expectedGMTSpecifier)
- .arg(expectedGMTSpecifierZeroExtended)
- ));
+ QLatin1String gmt("GMT");
+ if (timeString.contains(gmt) && diff) {
+ QLatin1Char sign(diff < 0 ? '-' : '+');
+ QString number(QString::number(qAbs(diff)));
+ const QString expect = gmt + sign + number;
+
+ if (diff < 10) {
+ const QString zeroed = gmt + sign + QLatin1Char('0') + number;
+
+ 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"));