summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2016-12-15 09:47:19 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2017-01-02 13:13:57 +0000
commitafda26ce5d0534d85219a2fe858aa0e05037cf09 (patch)
treec48e80fbdd017a489f52fc1452f4cbf7c4d39e5b /tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
parent79bf4e8f1c4415d92ab335c5a72b9e4c9332fdd3 (diff)
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 <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp')
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp10
1 files 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<qint64>::min() + 1
+ // Use -max(), which is min() + 1, to simplify filtering out overflow cases:
+ << -std::numeric_limits<qint64>::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<qint64>::max() * localTimeType)
QCOMPARE(dtLocal, utc);