From afda26ce5d0534d85219a2fe858aa0e05037cf09 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 15 Dec 2016 09:47:19 +0100 Subject: [PATCH] QDateTime test: clarify overflow-check An overflow-check needed the datum for the "min" test to be minus the datum for the "max" test; so explicitly make the former use -max() instead of synthesising it as min()+1. This simplifies the explanation of why that's needed, too. Clarify the overflow-check's comment at the same time. Change-Id: I41f56764fdf5e8c749bfae7a685e5fb77d37b3a8 Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 013ede23de..db42e8c5a4 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -608,10 +608,8 @@ void tst_QDateTime::setMSecsSinceEpoch_data() << QDateTime(QDate::fromJulianDay(0x7fffffff), QTime(21, 59, 59, 999), Qt::UTC) << QDateTime(QDate::fromJulianDay(0x7fffffff), QTime(23, 59, 59, 999)); QTest::newRow("min") - // + 1 because, in the reference check below, calling addMSecs(qint64min) - // will internally apply unary minus to -qint64min, resulting in a - // positive value 1 too big for qint64max, causing an overflow. - << std::numeric_limits::min() + 1 + // Use -max(), which is min() + 1, to simplify filtering out overflow cases: + << -std::numeric_limits::max() << QDateTime(QDate(-292275056, 5, 16), QTime(16, 47, 4, 193), Qt::UTC) << QDateTime(QDate(-292275056, 5, 16), QTime(17, 47, 4, 193), Qt::LocalTime); QTest::newRow("max") @@ -689,8 +687,8 @@ void tst_QDateTime::fromMSecsSinceEpoch() QDateTime dtUtc = QDateTime::fromMSecsSinceEpoch(msecs, Qt::UTC); QDateTime dtOffset = QDateTime::fromMSecsSinceEpoch(msecs, Qt::OffsetFromUTC, 60*60); - // LocalTime will overflow for min or max, depending on whether you're - // East or West of Greenwich. The test passes at GMT. + // LocalTime will overflow for "min" or "max" tests, depending on whether + // you're East or West of Greenwich. In UTC, we won't overflow. if (localTimeType == LocalTimeIsUtc || msecs != std::numeric_limits::max() * localTimeType) QCOMPARE(dtLocal, utc);