summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2019-03-19 11:45:20 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2020-07-01 16:00:34 +0200
commitda7f4a4c7652f0c26b5492330e55936abf173c12 (patch)
treeb12c0e320d644ec218d8dde4949503e1ecee9bc9 /tests/auto/corelib
parentb2bd2708b6f0e4d7fffbafc1ffd05c10578277aa (diff)
Replace a constant with a predicate function using it
Rather than naming a "GMT" string so as to repeatedly test whether a date-time's string representation ends in it, use a simple lambda to do the test, so that the string is only used in one place anyway. Makes the test code more readable. Change-Id: I5afad9ad5d58702bea7f24e5e5688ea4d738ae0d Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index ffbc839d9d..9d5a949277 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -956,11 +956,13 @@ void tst_QDateTime::toString_textDate()
void tst_QDateTime::toString_textDate_extra()
{
- QLatin1String GMT("GMT");
+ auto endsWithGmt = [](const QDateTime &dt) {
+ return dt.toString().endsWith(QLatin1String("GMT"));
+ };
QDateTime dt = QDateTime::fromMSecsSinceEpoch(0, Qt::LocalTime);
- QVERIFY(!dt.toString().endsWith(GMT));
+ QVERIFY(!endsWithGmt(dt));
dt = QDateTime::fromMSecsSinceEpoch(0, Qt::UTC).toLocalTime();
- QVERIFY(!dt.toString().endsWith(GMT));
+ QVERIFY(!endsWithGmt(dt));
#if QT_CONFIG(timezone)
# if defined Q_OS_UNIX && !defined Q_OS_DARWIN && !defined Q_OS_ANDROID
@@ -980,7 +982,7 @@ void tst_QDateTime::toString_textDate_extra()
QVERIFY(dt.toString().startsWith(QLatin1String("Wed Dec 31 16:00:00 1969 ")));
# endif
dt = dt.toLocalTime();
- QVERIFY(!dt.toString().endsWith(GMT));
+ QVERIFY(!endsWithGmt(dt));
} else {
qDebug("Missed zone test: no America/Vancouver zone available");
}
@@ -993,7 +995,7 @@ void tst_QDateTime::toString_textDate_extra()
QVERIFY(dt.toString().startsWith(QLatin1String("Thu Jan 1 01:00:00 1970 ")));
# endif
dt = dt.toLocalTime();
- QVERIFY(!dt.toString().endsWith(GMT));
+ QVERIFY(!endsWithGmt(dt));
} else {
qDebug("Missed zone test: no Europe/Berlin zone available");
}
@@ -1004,7 +1006,7 @@ void tst_QDateTime::toString_textDate_extra()
QCOMPARE(dt.toString(), QLatin1String("Thu Jan 1 00:00:00 1970"));
#endif
dt = QDateTime::fromMSecsSinceEpoch(0, Qt::UTC);
- QVERIFY(dt.toString().endsWith(GMT));
+ QVERIFY(endsWithGmt(dt));
}
#endif // datestring