diff options
Diffstat (limited to 'tests/benchmarks/corelib/time')
-rw-r--r-- | tests/benchmarks/corelib/time/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tests/benchmarks/corelib/time/qdate/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp | 66 | ||||
-rw-r--r-- | tests/benchmarks/corelib/time/qdatetime/CMakeLists.txt | 8 | ||||
-rw-r--r-- | tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp (renamed from tests/benchmarks/corelib/time/qdatetime/main.cpp) | 195 | ||||
-rw-r--r-- | tests/benchmarks/corelib/time/qtimezone/CMakeLists.txt | 7 | ||||
-rw-r--r-- | tests/benchmarks/corelib/time/qtimezone/tst_bench_qtimezone.cpp (renamed from tests/benchmarks/corelib/time/qtimezone/main.cpp) | 79 |
7 files changed, 166 insertions, 197 deletions
diff --git a/tests/benchmarks/corelib/time/CMakeLists.txt b/tests/benchmarks/corelib/time/CMakeLists.txt index 086650edb6..7c9de68486 100644 --- a/tests/benchmarks/corelib/time/CMakeLists.txt +++ b/tests/benchmarks/corelib/time/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from time.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause add_subdirectory(qdate) add_subdirectory(qdatetime) diff --git a/tests/benchmarks/corelib/time/qdate/CMakeLists.txt b/tests/benchmarks/corelib/time/qdate/CMakeLists.txt index edc55463d8..e4ef5e3edc 100644 --- a/tests/benchmarks/corelib/time/qdate/CMakeLists.txt +++ b/tests/benchmarks/corelib/time/qdate/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qdate.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_bench_qdate Binary: @@ -7,6 +8,6 @@ qt_internal_add_benchmark(tst_bench_qdate SOURCES tst_bench_qdate.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp b/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp index f8ca632beb..7dde3bf426 100644 --- a/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp +++ b/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp @@ -1,34 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module 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) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QDate> #include <QTest> #include <QList> +using namespace Qt::StringLiterals; class tst_QDate : public QObject { @@ -58,6 +34,9 @@ private Q_SLOTS: void addDays(); void addMonths(); void addYears(); + + void fromString_data(); + void fromString(); }; QList<QDate> tst_QDate::daily(qint64 start, qint64 end) @@ -149,7 +128,7 @@ void tst_QDate::daysInYear() { const auto list = yearly(1601, 2401); QBENCHMARK { - for (const QDate date : list) + for (const QDate &date : list) date.daysInYear(); } } @@ -167,7 +146,7 @@ void tst_QDate::getSetDate() QDate store; const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - for (const auto test : list) { + for (const auto &test : list) { int year, month, day; test.getDate(&year, &month, &day); store.setDate(year, month, day); @@ -181,7 +160,7 @@ void tst_QDate::addDays() QDate store; const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - for (const auto test : list) + for (const auto &test : list) store = test.addDays(17); } Q_UNUSED(store); @@ -192,7 +171,7 @@ void tst_QDate::addMonths() QDate store; const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - for (const auto test : list) + for (const auto &test : list) store = test.addMonths(17); } Q_UNUSED(store); @@ -203,11 +182,34 @@ void tst_QDate::addYears() QDate store; const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - for (const auto test : list) + for (const auto &test : list) store = test.addYears(17); } Q_UNUSED(store); } +void tst_QDate::fromString_data() +{ + QTest::addColumn<QString>("string"); + QTest::addColumn<QString>("format"); + QTest::addColumn<int>("baseYear"); + + QTest::newRow("yyyyMMdd") << u"20240412"_s << u"yyyyMMdd"_s << 2000; + QTest::newRow("yyyy-MM-dd") << u"2024-04-12"_s << u"yyyy-MM-dd"_s << 2000; + QTest::newRow("YYYYMMDD") << u"20240412"_s << u"YYYYMMDD"_s << 2000; // Invalid, QTBUG-124465. +} + +void tst_QDate::fromString() +{ + QFETCH(const QString, string); + QFETCH(const QString, format); + QFETCH(const int, baseYear); + QDate date; + QBENCHMARK { + date = QDate::fromString(string, format, baseYear); + } + Q_UNUSED(date); +} + QTEST_MAIN(tst_QDate) #include "tst_bench_qdate.moc" diff --git a/tests/benchmarks/corelib/time/qdatetime/CMakeLists.txt b/tests/benchmarks/corelib/time/qdatetime/CMakeLists.txt index 2585b0d25d..14c0b9c730 100644 --- a/tests/benchmarks/corelib/time/qdatetime/CMakeLists.txt +++ b/tests/benchmarks/corelib/time/qdatetime/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qdatetime.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_bench_qdatetime Binary: @@ -6,7 +7,8 @@ qt_internal_add_benchmark(tst_bench_qdatetime SOURCES - main.cpp - PUBLIC_LIBRARIES + tst_bench_qdatetime.cpp + LIBRARIES Qt::Test + Qt::CorePrivate ) diff --git a/tests/benchmarks/corelib/time/qdatetime/main.cpp b/tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp index c6d2b84597..1c86eae009 100644 --- a/tests/benchmarks/corelib/time/qdatetime/main.cpp +++ b/tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp @@ -1,59 +1,25 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module 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) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QDateTime> #include <QTimeZone> #include <QTest> #include <QList> #include <qdebug.h> +#include <QtCore/private/qdatetime_p.h> class tst_QDateTime : public QObject { Q_OBJECT - enum : qint64 - { - SECS_PER_DAY = 86400, - MSECS_PER_DAY = 86400000, - JULIAN_DAY_1950 = 2433283, - JULIAN_DAY_1960 = 2436935, - JULIAN_DAY_1970 = 2440588, // Epoch - JULIAN_DAY_2010 = 2455198, - JULIAN_DAY_2011 = 2455563, - JULIAN_DAY_2020 = 2458850, - JULIAN_DAY_2050 = 2469808, - JULIAN_DAY_2060 = 2473460 - }; - static QList<QDateTime> daily(qint64 start, qint64 end); +#if QT_CONFIG(timezone) static QList<QDateTime> norse(qint64 start, qint64 end); +#endif + void decade_data(); private Q_SLOTS: + void create_data() { decade_data(); } void create(); void isNull(); void isValid(); @@ -62,27 +28,35 @@ private Q_SLOTS: void timeSpec(); void offsetFromUtc(); void timeZoneAbbreviation(); + void toMSecsSinceEpoch_data() { decade_data(); } void toMSecsSinceEpoch(); - void toMSecsSinceEpoch1950(); - void toMSecsSinceEpoch2050(); +#if QT_CONFIG(timezone) + void toMSecsSinceEpochTz_data() { decade_data(); } void toMSecsSinceEpochTz(); - void toMSecsSinceEpoch1950Tz(); - void toMSecsSinceEpoch2050Tz(); +#endif void setDate(); void setTime(); +#if QT_DEPRECATED_SINCE(6, 9) void setTimeSpec(); void setOffsetFromUtc(); +#endif void setMSecsSinceEpoch(); +#if QT_CONFIG(timezone) void setMSecsSinceEpochTz(); +#endif void toString(); void toStringTextFormat(); void toStringIsoFormat(); void addDays(); +#if QT_CONFIG(timezone) void addDaysTz(); - void addMSecs(); void addMSecsTz(); +#endif + void addMSecs(); +#if QT_DEPRECATED_SINCE(6, 9) void toTimeSpec(); void toOffsetFromUtc(); +#endif void daysTo(); void msecsTo(); void equivalent(); @@ -99,33 +73,64 @@ private Q_SLOTS: void fromStringIso(); void fromMSecsSinceEpoch(); void fromMSecsSinceEpochUtc(); +#if QT_CONFIG(timezone) void fromMSecsSinceEpochTz(); +#endif }; +using namespace QtPrivate::DateTimeConstants; +constexpr qint64 JULIAN_DAY_1 = 1721426; +constexpr qint64 JULIAN_DAY_11 = 1725078; +constexpr qint64 JULIAN_DAY_1890 = 2411369; +constexpr qint64 JULIAN_DAY_1900 = 2415021; +constexpr qint64 JULIAN_DAY_1950 = 2433283; +constexpr qint64 JULIAN_DAY_1960 = 2436935; +constexpr qint64 JULIAN_DAY_1970 = 2440588; // Epoch +constexpr qint64 JULIAN_DAY_2010 = 2455198; +constexpr qint64 JULIAN_DAY_2011 = 2455563; +constexpr qint64 JULIAN_DAY_2020 = 2458850; +constexpr qint64 JULIAN_DAY_2050 = 2469808; +constexpr qint64 JULIAN_DAY_2060 = 2473460; + +void tst_QDateTime::decade_data() +{ + QTest::addColumn<qint64>("startJd"); + QTest::addColumn<qint64>("stopJd"); + + QTest::newRow("first-decade-CE") << JULIAN_DAY_1 << JULIAN_DAY_11; + QTest::newRow("1890s") << JULIAN_DAY_1890 << JULIAN_DAY_1900; + QTest::newRow("1950s") << JULIAN_DAY_1950 << JULIAN_DAY_1960; + QTest::newRow("2010s") << JULIAN_DAY_2010 << JULIAN_DAY_2020; + QTest::newRow("2050s") << JULIAN_DAY_2050 << JULIAN_DAY_2060; +} + QList<QDateTime> tst_QDateTime::daily(qint64 start, qint64 end) { QList<QDateTime> list; list.reserve(end - start); for (int jd = start; jd < end; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + list.append(QDateTime(QDate::fromJulianDay(jd).startOfDay())); return list; } - +#if QT_CONFIG(timezone) QList<QDateTime> tst_QDateTime::norse(qint64 start, qint64 end) { const QTimeZone cet("Europe/Oslo"); QList<QDateTime> list; list.reserve(end - start); for (int jd = start; jd < end; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); + list.append(QDateTime(QDate::fromJulianDay(jd).startOfDay(cet))); return list; } - +#endif void tst_QDateTime::create() { + QFETCH(const qint64, startJd); + QFETCH(const qint64, stopJd); + const QTime noon = QTime::fromMSecsSinceStartOfDay(43200); QBENCHMARK { - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) { - QDateTime test(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)); + for (int jd = startJd; jd < stopJd; ++jd) { + QDateTime test(QDate::fromJulianDay(jd), noon); Q_UNUSED(test); } } @@ -196,64 +201,29 @@ void tst_QDateTime::timeZoneAbbreviation() void tst_QDateTime::toMSecsSinceEpoch() { - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - test.toMSecsSinceEpoch(); - } -} - -void tst_QDateTime::toMSecsSinceEpoch1950() -{ - const auto list = daily(JULIAN_DAY_1950, JULIAN_DAY_1960); + QFETCH(const qint64, startJd); + QFETCH(const qint64, stopJd); + const auto list = daily(startJd, stopJd); QBENCHMARK { for (const QDateTime &test : list) test.toMSecsSinceEpoch(); } } - -void tst_QDateTime::toMSecsSinceEpoch2050() -{ - const auto list = daily(JULIAN_DAY_2050, JULIAN_DAY_2060); - QBENCHMARK { - for (const QDateTime &test : list) - test.toMSecsSinceEpoch(); - } -} - +#if QT_CONFIG(timezone) void tst_QDateTime::toMSecsSinceEpochTz() { - qint64 result; - const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - result = test.toMSecsSinceEpoch(); - } - Q_UNUSED(result); -} - -void tst_QDateTime::toMSecsSinceEpoch1950Tz() -{ - qint64 result; - const auto list = norse(JULIAN_DAY_1950, JULIAN_DAY_1960); - QBENCHMARK { - for (const QDateTime &test : list) - result = test.toMSecsSinceEpoch(); - } - Q_UNUSED(result); -} + QFETCH(const qint64, startJd); + QFETCH(const qint64, stopJd); + const auto list = norse(startJd, stopJd); -void tst_QDateTime::toMSecsSinceEpoch2050Tz() -{ qint64 result; - const auto list = norse(JULIAN_DAY_2050, JULIAN_DAY_2060); QBENCHMARK { for (const QDateTime &test : list) result = test.toMSecsSinceEpoch(); } Q_UNUSED(result); } - +#endif void tst_QDateTime::setDate() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); @@ -272,6 +242,9 @@ void tst_QDateTime::setTime() } } +#if QT_DEPRECATED_SINCE(6, 9) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED void tst_QDateTime::setTimeSpec() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); @@ -289,6 +262,8 @@ void tst_QDateTime::setOffsetFromUtc() test.setOffsetFromUtc(3600); } } +QT_WARNING_POP +#endif // 6.9 deprecation void tst_QDateTime::setMSecsSinceEpoch() { @@ -299,7 +274,7 @@ void tst_QDateTime::setMSecsSinceEpoch() test.setMSecsSinceEpoch(msecs); } } - +#if QT_CONFIG(timezone) void tst_QDateTime::setMSecsSinceEpochTz() { const qint64 msecs = qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970 + 180) * MSECS_PER_DAY; @@ -309,7 +284,7 @@ void tst_QDateTime::setMSecsSinceEpochTz() test.setMSecsSinceEpoch(msecs); } } - +#endif void tst_QDateTime::toString() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011); @@ -347,7 +322,7 @@ void tst_QDateTime::addDays() } Q_UNUSED(next); } - +#if QT_CONFIG(timezone) void tst_QDateTime::addDaysTz() { const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); @@ -356,7 +331,7 @@ void tst_QDateTime::addDaysTz() QDateTime result = test.addDays(1); } } - +#endif void tst_QDateTime::addMSecs() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); @@ -367,7 +342,7 @@ void tst_QDateTime::addMSecs() } Q_UNUSED(next); } - +#if QT_CONFIG(timezone) void tst_QDateTime::addMSecsTz() { const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); @@ -376,7 +351,10 @@ void tst_QDateTime::addMSecsTz() QDateTime result = test.addMSecs(1); } } - +#endif +#if QT_DEPRECATED_SINCE(6, 9) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED void tst_QDateTime::toTimeSpec() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); @@ -394,6 +372,8 @@ void tst_QDateTime::toOffsetFromUtc() test.toOffsetFromUtc(3600); } } +QT_WARNING_POP +#endif void tst_QDateTime::daysTo() { @@ -434,7 +414,7 @@ void tst_QDateTime::equivalentUtc() { bool result = false; const QDateTime other = QDateTime::fromMSecsSinceEpoch( - qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC); + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, QTimeZone::UTC); const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { for (const QDateTime &test : list) @@ -460,7 +440,7 @@ void tst_QDateTime::lessThanUtc() { bool result = false; const QDateTime other = QDateTime::fromMSecsSinceEpoch( - qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC); + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, QTimeZone::UTC); const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { for (const QDateTime &test : list) @@ -544,7 +524,7 @@ void tst_QDateTime::fromMSecsSinceEpoch() const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970; QBENCHMARK { for (int jd = start; jd < end; ++jd) - QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, Qt::LocalTime); + QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY); } } @@ -554,10 +534,10 @@ void tst_QDateTime::fromMSecsSinceEpochUtc() const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970; QBENCHMARK { for (int jd = start; jd < end; ++jd) - QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, Qt::UTC); + QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, QTimeZone::UTC); } } - +#if QT_CONFIG(timezone) void tst_QDateTime::fromMSecsSinceEpochTz() { const int start = JULIAN_DAY_2010 - JULIAN_DAY_1970; @@ -568,7 +548,8 @@ void tst_QDateTime::fromMSecsSinceEpochTz() QDateTime test = QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, cet); } } +#endif QTEST_MAIN(tst_QDateTime) -#include "main.moc" +#include "tst_bench_qdatetime.moc" diff --git a/tests/benchmarks/corelib/time/qtimezone/CMakeLists.txt b/tests/benchmarks/corelib/time/qtimezone/CMakeLists.txt index c6487499af..f80b64be2d 100644 --- a/tests/benchmarks/corelib/time/qtimezone/CMakeLists.txt +++ b/tests/benchmarks/corelib/time/qtimezone/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qtimezone.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_bench_qtimezone Binary: @@ -6,7 +7,7 @@ qt_internal_add_benchmark(tst_bench_qtimezone SOURCES - main.cpp - PUBLIC_LIBRARIES + tst_bench_qtimezone.cpp + LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/time/qtimezone/main.cpp b/tests/benchmarks/corelib/time/qtimezone/tst_bench_qtimezone.cpp index 509d62d3bb..db8b910d98 100644 --- a/tests/benchmarks/corelib/time/qtimezone/main.cpp +++ b/tests/benchmarks/corelib/time/qtimezone/tst_bench_qtimezone.cpp @@ -1,31 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2019 Crimson AS <info@crimson.no> -** Copyright (C) 2018 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module 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) 2022 The Qt Company Ltd. +// Copyright (C) 2019 Crimson AS <info@crimson.no> +// Copyright (C) 2018 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTimeZone> #include <QTest> @@ -39,6 +15,7 @@ class tst_QTimeZone : public QObject Q_OBJECT private Q_SLOTS: +#if QT_CONFIG(timezone) void isTimeZoneIdAvailable(); void systemTimeZone(); void zoneByName_data(); @@ -49,31 +26,35 @@ private Q_SLOTS: void transitionsForward(); void transitionsReverse_data() { transitionList_data(); } void transitionsReverse(); +#endif }; static QList<QByteArray> enoughZones() { #ifdef EXHAUSTIVE - auto available = QTimeZone::availableTimeZoneIds(); - QList<QByteArray> result; - result.reserve(available.size() + 1); - for (conat auto &name : available) - result << name; + QList<QByteArray> result = QTimeZone::availableTimeZoneIds(); #else - QList<QByteArray> result { QByteArray("UTC"), - // Those named overtly in tst_QDateTime: - QByteArray("Europe/Oslo"), QByteArray("America/Vancouver"), - QByteArray("Europe/Berlin"), QByteArray("America/Sao_Paulo"), - QByteArray("Pacific/Auckland"), QByteArray("Australia/Eucla"), - QByteArray("Asia/Kathmandu"), QByteArray("Pacific/Kiritimati"), - QByteArray("Pacific/Apia"), QByteArray("UTC+12:00"), - QByteArray("Australia/Sydney"), QByteArray("Asia/Singapore"), - QByteArray("Australia/Brisbane") }; + QList<QByteArray> result { + QByteArray("UTC"), + // Those named overtly in tst_QDateTime - special cases first: + QByteArray("UTC-02:00"), QByteArray("UTC+02:00"), QByteArray("UTC+12:00"), + QByteArray("Etc/GMT+3"), QByteArray("GMT-2"), QByteArray("GMT"), + // ... then ordinary names in alphabetic order: + QByteArray("America/New_York"), QByteArray("America/Sao_Paulo"), + QByteArray("America/Vancouver"), + QByteArray("Asia/Kathmandu"), QByteArray("Asia/Singapore"), + QByteArray("Australia/Brisbane"), QByteArray("Australia/Eucla"), + QByteArray("Australia/Sydney"), + QByteArray("Europe/Berlin"), QByteArray("Europe/Helsinki"), + QByteArray("Europe/Rome"), QByteArray("Europe/Oslo"), + QByteArray("Pacific/Apia"), QByteArray("Pacific/Auckland"), + QByteArray("Pacific/Kiritimati") + }; #endif result << QByteArray("Vulcan/ShiKahr"); // invalid: also worth testing return result; } - +#if QT_CONFIG(timezone) void tst_QTimeZone::isTimeZoneIdAvailable() { const QList<QByteArray> available = QTimeZone::availableTimeZoneIds(); @@ -89,7 +70,6 @@ void tst_QTimeZone::systemTimeZone() QTimeZone::systemTimeZone(); } } - void tst_QTimeZone::zoneByName_data() { QTest::addColumn<QByteArray>("name"); @@ -126,9 +106,9 @@ void tst_QTimeZone::transitionList() { QFETCH(QByteArray, name); const QTimeZone zone = name.isEmpty() ? QTimeZone::systemTimeZone() : QTimeZone(name); - const QDateTime early = QDate(1625, 6, 8).startOfDay(Qt::UTC); // Cassini's birth date + const QDateTime early = QDate(1625, 6, 8).startOfDay(QTimeZone::UTC); // Cassini's birth date const QDateTime late // End of 32-bit signed time_t - = QDateTime::fromSecsSinceEpoch(std::numeric_limits<qint32>::max(), Qt::UTC); + = QDateTime::fromSecsSinceEpoch(std::numeric_limits<qint32>::max(), QTimeZone::UTC); QTimeZone::OffsetDataList seq; QBENCHMARK { seq = zone.transitions(early, late); @@ -140,7 +120,7 @@ void tst_QTimeZone::transitionsForward() { QFETCH(QByteArray, name); const QTimeZone zone = name.isEmpty() ? QTimeZone::systemTimeZone() : QTimeZone(name); - const QDateTime early = QDate(1625, 6, 8).startOfDay(Qt::UTC); // Cassini's birth date + const QDateTime early = QDate(1625, 6, 8).startOfDay(QTimeZone::UTC); // Cassini's birth date QBENCHMARK { QTimeZone::OffsetData tran = zone.nextTransition(early); while (tran.atUtc.isValid()) @@ -153,14 +133,15 @@ void tst_QTimeZone::transitionsReverse() QFETCH(QByteArray, name); const QTimeZone zone = name.isEmpty() ? QTimeZone::systemTimeZone() : QTimeZone(name); const QDateTime late // End of 32-bit signed time_t - = QDateTime::fromSecsSinceEpoch(std::numeric_limits<qint32>::max(), Qt::UTC); + = QDateTime::fromSecsSinceEpoch(std::numeric_limits<qint32>::max(), QTimeZone::UTC); QBENCHMARK { QTimeZone::OffsetData tran = zone.previousTransition(late); while (tran.atUtc.isValid()) tran = zone.previousTransition(tran.atUtc); } } +#endif QTEST_MAIN(tst_QTimeZone) -#include "main.moc" +#include "tst_bench_qtimezone.moc" |