summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/time
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-03-01 14:17:00 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2021-05-04 15:21:48 +0100
commit517745fc9de02f174e1d93527e84c35502fbd8b0 (patch)
tree03a2dec86c249b99e8a0fba8769ddbef61e17dba /tests/auto/corelib/time
parent5e89c1406e12b59b5818bd497c9aba4673e05577 (diff)
Ensure setDateTime clears status also when short
Previously, if multiplication overflowed when trying to set the date and time of a formerly short-form QDateTime, its status didn't get set to reflect the failed validity check. Added a test that now correctly detects that it's produced an invalid date-time on overflow, where previously it produced a wrong valid date-time. Change-Id: Id46ca34d1e32e9b9b0630f3723cefd1c13b5761e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/time')
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index 166ce260a5..ce0e899a25 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -717,6 +717,13 @@ void tst_QDateTime::setMSecsSinceEpoch()
QDateTime reference(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC);
QCOMPARE(dt, reference.addMSecs(msecs));
+
+ if ((localTimeType == LocalTimeAheadOfUtc && msecs == std::numeric_limits<qint64>::max())
+ || (localTimeType == LocalTimeBehindUtc && msecs == std::numeric_limits<qint64>::min())) {
+ QDateTime curt = QDate(1970, 1, 1).startOfDay(); // initially in short-form
+ curt.setMSecsSinceEpoch(msecs); // Overflows due to offset
+ QVERIFY(!curt.isValid());
+ }
}
void tst_QDateTime::fromMSecsSinceEpoch_data()