summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2018-09-03 14:05:55 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2019-11-25 08:50:27 +0100
commit2bf6a94cf60aa53f8a18f71dd4dce047c52dfc64 (patch)
tree61fbd70babe708c6776e863beb948f9de9adb7d8
parent2ed7831ff636f4fbaec27524d416d63c2fd773bf (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. Fixes: QTBUG-79965 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> (cherry picked from commit 017ac02ec459378074a44487f171cc909e947f4a) Reviewed-by: Heikki Halmet <heikki.halmet@qt.io> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
-rw-r--r--tests/auto/corelib/tools/qlocale/tst_qlocale.cpp34
1 files changed, 17 insertions, 17 deletions
diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
index 0549951070..4fbf502399 100644
--- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
@@ -1666,23 +1666,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"));