From 9bc849f9c4fe921763859d9c8f363563d6a59548 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 9 Feb 2021 16:29:00 +0100 Subject: [PATCH] Make QDate's text round-trip test do actual comparisons Previously the only test was that it produced no warnings, if anyone paused to read the output to notice them. Change-Id: I225ca99c7ec316186702c0fdb355585374c014a4 Reviewed-by: Thiago Macieira --- tests/auto/corelib/time/qdate/tst_qdate.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp index 53cb70403c..6f8699bc98 100644 --- a/tests/auto/corelib/time/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Copyright (C) 2016 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -1542,11 +1542,13 @@ void tst_QDate::printNegativeYear() const void tst_QDate::roundtripString() const { /* This code path should not result in warnings. */ - const QDate theDate(QDate::currentDate()); - theDate.fromString(theDate.toString(Qt::TextDate), Qt::TextDate); + const QDate date(QDate::currentDate()); + QCOMPARE(date.fromString(date.toString(Qt::TextDate), Qt::TextDate), date); - const QDateTime theDateTime(QDateTime::currentDateTime()); - theDateTime.fromString(theDateTime.toString(Qt::TextDate), Qt::TextDate); + const QDateTime now(QDateTime::currentDateTime()); + // TextDate discards milliseconds, so clip to whole second: + const QDateTime when = now.addMSecs(-now.time().msec()); + QCOMPARE(when.fromString(when.toString(Qt::TextDate), Qt::TextDate), when); } #endif