diff options
Diffstat (limited to 'tests/manual/corelib/time')
-rw-r--r-- | tests/manual/corelib/time/CMakeLists.txt | 4 | ||||
-rwxr-xr-x | tests/manual/corelib/time/foreachzone | 30 | ||||
-rw-r--r-- | tests/manual/corelib/time/zonechange/CMakeLists.txt | 9 | ||||
-rw-r--r-- | tests/manual/corelib/time/zonechange/tst_zonechange.cpp | 60 |
4 files changed, 103 insertions, 0 deletions
diff --git a/tests/manual/corelib/time/CMakeLists.txt b/tests/manual/corelib/time/CMakeLists.txt new file mode 100644 index 0000000000..b8e6aa2f18 --- /dev/null +++ b/tests/manual/corelib/time/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +add_subdirectory(zonechange) diff --git a/tests/manual/corelib/time/foreachzone b/tests/manual/corelib/time/foreachzone new file mode 100755 index 0000000000..480679885a --- /dev/null +++ b/tests/manual/corelib/time/foreachzone @@ -0,0 +1,30 @@ +#!/bin/sh +# Usage: foreachzone command [args...] +# +# The command is run with eval, so can include embedded shell +# metacharacters such as | and ||. It is run in a sub-shell, so can +# change environment or cd to a different directory without +# complicating later runs of the same command. +# +# It is run repeatedly, with the TZ environment variable set to each +# timezone name in turn, excluding the copies of zoneinfo/ under its +# posix/ and right/ sub-dirs. Symbolic links are included (as long as +# they point to valid zone data). +# +# For example, in the top level of a build tree, +# foreachzone ninja tst_qdate_check +# will run all the QDate tests in every time zone (this may take some +# time). + +DIR=/usr/share/zoneinfo +[ -d "$DIR" ] || DIR=/usr/lib/zoneinfo + +find $DIR -type d \( -name posix -o -name right \) -prune -o \( -type f -o -type l \) -print \ + | while read f +do + # To filter out symlinks in zoneinfo/ itself, uncomment this line: + # echo "$f" | grep -wq 'zoneinfo/.*/' || [ ! -h "$f" ] || continue + # To skip all symlinks, omit the -L here: + file -L "$f" | grep -wq 'timezone data .*, version' || continue + ( export TZ=${f#*/zoneinfo/}; eval "$@" ) +done diff --git a/tests/manual/corelib/time/zonechange/CMakeLists.txt b/tests/manual/corelib/time/zonechange/CMakeLists.txt new file mode 100644 index 0000000000..474779849f --- /dev/null +++ b/tests/manual/corelib/time/zonechange/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +qt_internal_add_manual_test(zonechange + SOURCES + tst_zonechange.cpp + LIBRARIES + Qt::Core +) diff --git a/tests/manual/corelib/time/zonechange/tst_zonechange.cpp b/tests/manual/corelib/time/zonechange/tst_zonechange.cpp new file mode 100644 index 0000000000..5ca33f1396 --- /dev/null +++ b/tests/manual/corelib/time/zonechange/tst_zonechange.cpp @@ -0,0 +1,60 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QtCore/qcoreapplication.h> + +#include <QtCore/qdatetime.h> +#if QT_CONFIG(timezone) +#include <QtCore/qtimezone.h> +#endif + +#include <chrono> +#include <thread> + +using namespace std::chrono; + +bool distinct(const QDateTime &left, const QDateTime &right) +{ + if (left == right) + return false; + + qInfo() << " Actual:" << left << "\nExpected:" << right; + return true; +} + +// Exit status: 0 success, 1 test failed, 2 test not viable. +int main(int argc, char **argv) +{ + // Other things may need this indirectly, so make sure it exists: + QCoreApplication ignored(argc, argv); + if (!qEnvironmentVariableIsEmpty("TZ")) { + qInfo("Environment variable TZ over-rides system setting; you need to clear it."); + return 2; + } + + QDateTime date = QDateTime(QDate(2020, 2, 20), QTime(20, 20, 20)); + QDateTime copy = date; + if (distinct(date, copy)) + return 1; +#if QT_CONFIG(timezone) + const auto prior = QTimeZone::systemTimeZoneId(); +#endif + + qInfo("You have two minutes in which to change the system time-zone setting."); + std::this_thread::sleep_for(120s); +#if QT_CONFIG(timezone) + if (QTimeZone::systemTimeZoneId() == prior) { + qInfo("Too slow."); + return 2; + } +#endif + + if (distinct(copy, date)) + return 1; + QDateTime copy2 = copy.addMSecs(2); + QDateTime date2 = date.addMSecs(2); + if (distinct(copy2, date2)) + return 1; + + return 0; +} |