diff options
Diffstat (limited to 'tests/auto/corelib/time/qtime/tst_qtime.cpp')
-rw-r--r-- | tests/auto/corelib/time/qtime/tst_qtime.cpp | 244 |
1 files changed, 52 insertions, 192 deletions
diff --git a/tests/auto/corelib/time/qtime/tst_qtime.cpp b/tests/auto/corelib/time/qtime/tst_qtime.cpp index 3626f61ac7..c0fdb07115 100644 --- a/tests/auto/corelib/time/qtime/tst_qtime.cpp +++ b/tests/auto/corelib/time/qtime/tst_qtime.cpp @@ -1,32 +1,8 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <private/qglobal_p.h> +#include <private/qcomparisontesthelper_p.h> #include <QTest> #include "qdatetime.h" #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) @@ -52,12 +28,11 @@ private Q_SLOTS: void addMSecs(); void addSecs_data(); void addSecs(); + void orderingCompiles(); void operator_eq_eq_data(); void operator_eq_eq(); - void operator_lt(); - void operator_gt(); - void operator_lt_eq(); - void operator_gt_eq(); + void ordering_data(); + void ordering(); #if QT_CONFIG(datestring) # if QT_CONFIG(datetimeparser) void fromStringFormat_data(); @@ -309,7 +284,7 @@ void tst_QTime::secsTo_data() QTest::newRow("disregard msec (1s)") << QTime(12, 30, 1, 500) << QTime(12, 30, 2, 400) << 1; QTest::newRow("disregard msec (0s)") << QTime(12, 30, 1, 500) << QTime(12, 30, 1, 900) << 0; QTest::newRow("disregard msec (-1s)") << QTime(12, 30, 2, 400) << QTime(12, 30, 1, 500) << -1; - QTest::newRow("disregard msec (0s)") << QTime(12, 30, 1, 900) << QTime(12, 30, 1, 500) << 0; + QTest::newRow("disregard msec (-0s)") << QTime(12, 30, 1, 900) << QTime(12, 30, 1, 500) << 0; } void tst_QTime::secsTo() @@ -345,6 +320,11 @@ void tst_QTime::msecsTo() QCOMPARE( t1.msecsTo( t2 ), delta ); } +void tst_QTime::orderingCompiles() +{ + QTestPrivate::testAllComparisonOperatorsCompile<QTime>(); +} + void tst_QTime::operator_eq_eq_data() { QTest::addColumn<QTime>("t1"); @@ -370,169 +350,42 @@ void tst_QTime::operator_eq_eq() QFETCH(QTime, t2); QFETCH(bool, expectEqual); - bool equal = t1 == t2; - QCOMPARE(equal, expectEqual); - bool notEqual = t1 != t2; - QCOMPARE(notEqual, !expectEqual); + QT_TEST_EQUALITY_OPS(t1, t2, expectEqual); - if (equal) + if (expectEqual) QVERIFY(qHash(t1) == qHash(t2)); } -void tst_QTime::operator_lt() +void tst_QTime::ordering_data() { - QTime t1(0,0,0,0); - QTime t2(0,0,0,0); - QVERIFY( !(t1 < t2) ); - - t1 = QTime(12,34,56,20); - t2 = QTime(12,34,56,30); - QVERIFY( t1 < t2 ); - - t1 = QTime(13,34,46,20); - t2 = QTime(13,34,56,20); - QVERIFY( t1 < t2 ); - - t1 = QTime(13,24,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( t1 < t2 ); - - t1 = QTime(12,34,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( t1 < t2 ); - - t1 = QTime(14,34,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( !(t1 < t2) ); - - t1 = QTime(13,44,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( !(t1 < t2) ); - - t1 = QTime(13,34,56,20); - t2 = QTime(13,34,46,20); - QVERIFY( !(t1 < t2) ); - - t1 = QTime(13,44,56,30); - t2 = QTime(13,44,56,20); - QVERIFY( !(t1 < t2) ); + QTest::addColumn<QTime>("left"); + QTest::addColumn<QTime>("right"); + QTest::addColumn<Qt::strong_ordering>("expectedOrdering"); + + auto generateRow = [](QTime t1, QTime t2, Qt::strong_ordering ordering) { + const QByteArray t1Str = t1.toString("hh:mm:ss.zz").toLatin1(); + const QByteArray t2Str = t2.toString("hh:mm:ss.zz").toLatin1(); + QTest::addRow("%s_vs_%s", t1Str.constData(), t2Str.constData()) << t1 << t2 << ordering; + }; + + generateRow(QTime(0, 0), QTime(0, 0), Qt::strong_ordering::equivalent); + generateRow(QTime(12, 34, 56, 20), QTime(12, 34, 56, 30), Qt::strong_ordering::less); + generateRow(QTime(13, 34, 46, 20), QTime(13, 34, 56, 20), Qt::strong_ordering::less); + generateRow(QTime(13, 24, 56, 20), QTime(13, 34, 56, 20), Qt::strong_ordering::less); + generateRow(QTime(12, 34, 56, 20), QTime(13, 34, 56, 20), Qt::strong_ordering::less); + generateRow(QTime(14, 34, 56, 20), QTime(13, 34, 56, 20), Qt::strong_ordering::greater); + generateRow(QTime(13, 44, 56, 20), QTime(13, 34, 56, 20), Qt::strong_ordering::greater); + generateRow(QTime(13, 34, 56, 20), QTime(13, 34, 46, 20), Qt::strong_ordering::greater); + generateRow(QTime(13, 34, 56, 30), QTime(13, 34, 56, 20), Qt::strong_ordering::greater); } -void tst_QTime::operator_gt() +void tst_QTime::ordering() { - QTime t1(0,0,0,0); - QTime t2(0,0,0,0); - QVERIFY( !(t1 > t2) ); + QFETCH(QTime, left); + QFETCH(QTime, right); + QFETCH(Qt::strong_ordering, expectedOrdering); - t1 = QTime(12,34,56,20); - t2 = QTime(12,34,56,30); - QVERIFY( !(t1 > t2) ); - - t1 = QTime(13,34,46,20); - t2 = QTime(13,34,56,20); - QVERIFY( !(t1 > t2) ); - - t1 = QTime(13,24,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( !(t1 > t2) ); - - t1 = QTime(12,34,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( !(t1 > t2) ); - - t1 = QTime(14,34,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( t1 > t2 ); - - t1 = QTime(13,44,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( t1 > t2 ); - - t1 = QTime(13,34,56,20); - t2 = QTime(13,34,46,20); - QVERIFY( t1 > t2 ); - - t1 = QTime(13,44,56,30); - t2 = QTime(13,44,56,20); - QVERIFY( t1 > t2 ); -} - -void tst_QTime::operator_lt_eq() -{ - QTime t1(0,0,0,0); - QTime t2(0,0,0,0); - QVERIFY( t1 <= t2 ); - - t1 = QTime(12,34,56,20); - t2 = QTime(12,34,56,30); - QVERIFY( t1 <= t2 ); - - t1 = QTime(13,34,46,20); - t2 = QTime(13,34,56,20); - QVERIFY( t1 <= t2 ); - - t1 = QTime(13,24,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( t1 <= t2 ); - - t1 = QTime(12,34,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( t1 <= t2 ); - - t1 = QTime(14,34,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( !(t1 <= t2) ); - - t1 = QTime(13,44,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( !(t1 <= t2) ); - - t1 = QTime(13,34,56,20); - t2 = QTime(13,34,46,20); - QVERIFY( !(t1 <= t2) ); - - t1 = QTime(13,44,56,30); - t2 = QTime(13,44,56,20); - QVERIFY( !(t1 <= t2) ); -} - -void tst_QTime::operator_gt_eq() -{ - QTime t1(0,0,0,0); - QTime t2(0,0,0,0); - QVERIFY( t1 >= t2 ); - - t1 = QTime(12,34,56,20); - t2 = QTime(12,34,56,30); - QVERIFY( !(t1 >= t2) ); - - t1 = QTime(13,34,46,20); - t2 = QTime(13,34,56,20); - QVERIFY( !(t1 >= t2) ); - - t1 = QTime(13,24,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( !(t1 >= t2) ); - - t1 = QTime(12,34,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( !(t1 >= t2) ); - - t1 = QTime(14,34,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( t1 >= t2 ); - - t1 = QTime(13,44,56,20); - t2 = QTime(13,34,56,20); - QVERIFY( t1 >= t2 ); - - t1 = QTime(13,34,56,20); - t2 = QTime(13,34,46,20); - QVERIFY( t1 >= t2 ); - - t1 = QTime(13,44,56,30); - t2 = QTime(13,44,56,20); - QVERIFY( t1 >= t2 ); + QT_TEST_ALL_COMPARISON_OPS(left, right, expectedOrdering); } #if QT_CONFIG(datestring) @@ -553,11 +406,18 @@ void tst_QTime::fromStringFormat_data() QTest::newRow("data7") << QString("25") << QString("hh") << invalidTime(); QTest::newRow("data8") << QString("22pm") << QString("Hap") << QTime(22, 0, 0); QTest::newRow("data9") << QString("2221") << QString("hhhh") << invalidTime(); - QTest::newRow("data10") << QString("02:23PM") << QString("hh:mmAP") << QTime(14,23,0,0); - QTest::newRow("data11") << QString("02:23pm") << QString("hh:mmap") << QTime(14,23,0,0); - QTest::newRow("short-msecs-lt100") << QString("10:12:34:045") << QString("hh:m:ss:z") << QTime(10,12,34,45); - QTest::newRow("short-msecs-gt100") << QString("10:12:34:45") << QString("hh:m:ss:z") << QTime(10,12,34,450); - QTest::newRow("late") << QString("23:59:59.999") << QString("hh:mm:ss.z") << QTime(23, 59, 59, 999); + // Parsing of am/pm indicators is case-insensitive + QTest::newRow("pm-upper") << QString("02:23PM") << QString("hh:mmAp") << QTime(14, 23); + QTest::newRow("pm-lower") << QString("02:23pm") << QString("hh:mmaP") << QTime(14, 23); + QTest::newRow("pm-as-upper") << QString("02:23Pm") << QString("hh:mmAP") << QTime(14, 23); + QTest::newRow("pm-as-lower") << QString("02:23pM") << QString("hh:mmap") << QTime(14, 23); + // Millisecond parsing must interpolate 0s only at the end and notice them at the start. + QTest::newRow("short-msecs-lt100") + << QString("10:12:34:045") << QString("hh:m:ss:z") << QTime(10, 12, 34, 45); + QTest::newRow("short-msecs-gt100") + << QString("10:12:34:45") << QString("hh:m:ss:z") << QTime(10, 12, 34, 450); + QTest::newRow("late") + << QString("23:59:59.999") << QString("hh:mm:ss.z") << QTime(23, 59, 59, 999); // Test unicode handling. QTest::newRow("emoji in format string 1") @@ -711,7 +571,7 @@ void tst_QTime::fromStringDateFormat_data() << Qt::RFC2822Date << invalidTime(); // The common date text used by the "invalid character" tests, just to be // sure *it's* not what's invalid: - QTest::newRow("RFC 850 and 1036 invalid character at end") + QTest::newRow("RFC 850 and 1036 no invalid character") << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100") << Qt::RFC2822Date << QTime(8, 0, 0); |