diff options
Diffstat (limited to 'tests/auto/corelib/kernel')
18 files changed, 1711 insertions, 269 deletions
diff --git a/tests/auto/corelib/kernel/kernel.pro b/tests/auto/corelib/kernel/kernel.pro index f85c39e9e6..75b98bcd09 100644 --- a/tests/auto/corelib/kernel/kernel.pro +++ b/tests/auto/corelib/kernel/kernel.pro @@ -1,6 +1,8 @@ TEMPLATE=subdirs SUBDIRS=\ qcoreapplication \ + qdeadlinetimer \ + qelapsedtimer \ qeventdispatcher \ qeventloop \ qmath \ @@ -31,11 +33,11 @@ SUBDIRS=\ qobject \ qsocketnotifier -!contains(QT_CONFIG, private_tests): SUBDIRS -= \ +!qtConfig(private_tests): SUBDIRS -= \ qsocketnotifier \ qsharedmemory # This test is only applicable on Windows !win32*|winrt: SUBDIRS -= qwineventnotifier -android|ios: SUBDIRS -= qsharedmemory qsystemsemaphore +android|uikit: SUBDIRS -= qclipboard qobject qsharedmemory qsystemsemaphore diff --git a/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro b/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro index a49bb9ae1f..d166351490 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro +++ b/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro @@ -3,4 +3,4 @@ TARGET = tst_qcoreapplication QT = core testlib core-private SOURCES = tst_qcoreapplication.cpp HEADERS = tst_qcoreapplication.h -requires(contains(QT_CONFIG,private_tests)) +requires(qtConfig(private_tests)) diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp index a8de5b7a9a..0691297497 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp @@ -155,7 +155,7 @@ void tst_QCoreApplication::qAppName() void tst_QCoreApplication::argc() { -#if defined(Q_OS_WINCE) || defined(Q_OS_WINRT) +#if defined(Q_OS_WINRT) QSKIP("QCoreApplication::arguments() parses arguments from actual command line on this platform."); #endif { diff --git a/tests/auto/corelib/kernel/qdeadlinetimer/qdeadlinetimer.pro b/tests/auto/corelib/kernel/qdeadlinetimer/qdeadlinetimer.pro new file mode 100644 index 0000000000..12ad7dabc2 --- /dev/null +++ b/tests/auto/corelib/kernel/qdeadlinetimer/qdeadlinetimer.pro @@ -0,0 +1,5 @@ +CONFIG += testcase +TARGET = tst_qdeadlinetimer +QT = core testlib +SOURCES = tst_qdeadlinetimer.cpp + diff --git a/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp new file mode 100644 index 0000000000..6ab24d2480 --- /dev/null +++ b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp @@ -0,0 +1,625 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Intel Corporation. +** 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$ +** +****************************************************************************/ + +#include <QtCore/QString> +#include <QtCore/QTime> +#include <QtCore/QDeadlineTimer> +#include <QtTest/QtTest> + +#if QT_HAS_INCLUDE(<chrono>) +# include <chrono> +#endif + +static const int minResolution = 400; // the minimum resolution for the tests + +Q_DECLARE_METATYPE(Qt::TimerType) + +class tst_QDeadlineTimer : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void initTestCase_data(); + void basics(); + void foreverness(); + void current(); + void deadlines(); + void setDeadline(); + void expire(); + void stdchrono(); +}; + +void tst_QDeadlineTimer::initTestCase_data() +{ + qRegisterMetaType<Qt::TimerType>(); + QTest::addColumn<Qt::TimerType>("timerType"); + QTest::newRow("precise") << Qt::PreciseTimer; + QTest::newRow("coarse") << Qt::CoarseTimer; +} + +void tst_QDeadlineTimer::basics() +{ + QDeadlineTimer deadline; + QCOMPARE(deadline.timerType(), Qt::CoarseTimer); + + QFETCH_GLOBAL(Qt::TimerType, timerType); + deadline = QDeadlineTimer(timerType); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline, QDeadlineTimer(timerType)); + QVERIFY(!(deadline != QDeadlineTimer(timerType))); + QVERIFY(!(deadline < QDeadlineTimer())); + QVERIFY(deadline <= QDeadlineTimer()); + QVERIFY(deadline >= QDeadlineTimer()); + QVERIFY(!(deadline > QDeadlineTimer())); + QVERIFY(!(deadline < deadline)); + QVERIFY(deadline <= deadline); + QVERIFY(deadline >= deadline); + QVERIFY(!(deadline > deadline)); + + // should have expired, but we may be running too early after boot + QTRY_VERIFY_WITH_TIMEOUT(deadline.hasExpired(), 100); + + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QCOMPARE(deadline.deadline(), qint64(0)); + QCOMPARE(deadline.deadlineNSecs(), qint64(0)); + + deadline.setRemainingTime(0, timerType); + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + + deadline.setPreciseRemainingTime(0, 0, timerType); + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + + deadline.setDeadline(0, timerType); + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QCOMPARE(deadline.deadline(), qint64(0)); + QCOMPARE(deadline.deadlineNSecs(), qint64(0)); + + deadline.setPreciseDeadline(0, 0, timerType); + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QCOMPARE(deadline.deadline(), qint64(0)); + QCOMPARE(deadline.deadlineNSecs(), qint64(0)); +} + +void tst_QDeadlineTimer::foreverness() +{ + QFETCH_GLOBAL(Qt::TimerType, timerType); + // we don't check whether timerType() is our type since it's possible it detects it's forever + + QDeadlineTimer deadline = QDeadlineTimer::Forever; + QCOMPARE(deadline.timerType(), Qt::CoarseTimer); + QVERIFY(deadline.isForever()); + QVERIFY(!deadline.hasExpired()); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits<qint64>::max()); + + deadline = QDeadlineTimer(-1, timerType); + QVERIFY(deadline.isForever()); + QVERIFY(!deadline.hasExpired()); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits<qint64>::max()); + + deadline.setRemainingTime(-1, timerType); + QVERIFY(deadline.isForever()); + QVERIFY(!deadline.hasExpired()); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits<qint64>::max()); + + deadline.setPreciseRemainingTime(-1, 0, timerType); + QVERIFY(deadline.isForever()); + QVERIFY(!deadline.hasExpired()); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits<qint64>::max()); + + deadline.setPreciseRemainingTime(-1, -1, timerType); + QVERIFY(deadline.isForever()); + QVERIFY(!deadline.hasExpired()); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits<qint64>::max()); + + deadline.setDeadline(std::numeric_limits<qint64>::max(), timerType); + QVERIFY(deadline.isForever()); + QVERIFY(!deadline.hasExpired()); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits<qint64>::max()); + + deadline.setPreciseDeadline(std::numeric_limits<qint64>::max(), 0, timerType); + QVERIFY(deadline.isForever()); + QVERIFY(!deadline.hasExpired()); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits<qint64>::max()); + + QCOMPARE(deadline, deadline); + QVERIFY(!(deadline < deadline)); + QVERIFY(deadline <= deadline); + QVERIFY(deadline >= deadline); + QVERIFY(!(deadline > deadline)); + + // adding to forever must still be forever + QDeadlineTimer deadline2 = deadline + 1; + QVERIFY(deadline2.isForever()); + QVERIFY(!deadline2.hasExpired()); + QCOMPARE(deadline2.remainingTime(), qint64(-1)); + QCOMPARE(deadline2.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline2.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline2.deadlineNSecs(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline2.timerType(), deadline.timerType()); + + QCOMPARE(deadline2 - deadline, qint64(0)); + QCOMPARE(deadline2, deadline); + QVERIFY(!(deadline2 < deadline)); + QVERIFY(deadline2 <= deadline); + QVERIFY(deadline2 >= deadline); + QVERIFY(!(deadline2 > deadline)); + + // subtracting from forever is *also* forever + deadline2 = deadline - 1; + QVERIFY(deadline2.isForever()); + QVERIFY(!deadline2.hasExpired()); + QCOMPARE(deadline2.remainingTime(), qint64(-1)); + QCOMPARE(deadline2.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline2.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline2.deadlineNSecs(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline2.timerType(), deadline.timerType()); + + QCOMPARE(deadline2 - deadline, qint64(0)); + QCOMPARE(deadline2, deadline); + QVERIFY(!(deadline2 < deadline)); + QVERIFY(deadline2 <= deadline); + QVERIFY(deadline2 >= deadline); + QVERIFY(!(deadline2 > deadline)); + + // compare and order against a default-constructed object + QDeadlineTimer expired; + QVERIFY(!(deadline == expired)); + QVERIFY(deadline != expired); + QVERIFY(!(deadline < expired)); + QVERIFY(!(deadline <= expired)); + QVERIFY(deadline >= expired); + QVERIFY(deadline > expired); +} + +void tst_QDeadlineTimer::current() +{ + QFETCH_GLOBAL(Qt::TimerType, timerType); + auto deadline = QDeadlineTimer::current(timerType); + QVERIFY(deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + + // subtracting from current should be "more expired" + QDeadlineTimer earlierDeadline = deadline - 1; + QVERIFY(earlierDeadline.hasExpired()); + QVERIFY(!earlierDeadline.isForever()); + QCOMPARE(earlierDeadline.timerType(), timerType); + QCOMPARE(earlierDeadline.remainingTime(), qint64(0)); + QCOMPARE(earlierDeadline.remainingTimeNSecs(), qint64(0)); + QVERIFY(earlierDeadline.deadline() != 0); + QVERIFY(earlierDeadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(earlierDeadline.deadlineNSecs() != 0); + QVERIFY(earlierDeadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + QCOMPARE(earlierDeadline.deadline(), deadline.deadline() - 1); + QCOMPARE(earlierDeadline.deadlineNSecs(), deadline.deadlineNSecs() - 1000*1000); + + QCOMPARE(earlierDeadline - deadline, qint64(-1)); + QVERIFY(earlierDeadline != deadline); + QVERIFY(earlierDeadline < deadline); + QVERIFY(earlierDeadline <= deadline); + QVERIFY(!(earlierDeadline >= deadline)); + QVERIFY(!(earlierDeadline > deadline)); +} + +void tst_QDeadlineTimer::deadlines() +{ + QFETCH_GLOBAL(Qt::TimerType, timerType); + + QDeadlineTimer deadline(4 * minResolution, timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTime() > (3 * minResolution)); + QVERIFY(deadline.remainingTime() <= (4 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() > (3000000 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() <= (4000000 * minResolution)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + + deadline.setRemainingTime(4 * minResolution, timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTime() > (3 * minResolution)); + QVERIFY(deadline.remainingTime() <= (4 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() > (3000000 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() <= (4000000 * minResolution)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + + deadline.setPreciseRemainingTime(0, 4000000 * minResolution, timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTime() > (3 * minResolution)); + QVERIFY(deadline.remainingTime() <= (4 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() > (3000000 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() <= (4000000 * minResolution)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + + deadline.setPreciseRemainingTime(1, 0, timerType); // 1 sec + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTime() > (1000 - minResolution)); + QVERIFY(deadline.remainingTime() <= 1000); + QVERIFY(deadline.remainingTimeNSecs() > (1000 - minResolution)*1000*1000); + QVERIFY(deadline.remainingTimeNSecs() <= (1000*1000*1000)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + + // adding to a future deadline must still be further in the future + QDeadlineTimer laterDeadline = deadline + 1; + QVERIFY(!laterDeadline.hasExpired()); + QVERIFY(!laterDeadline.isForever()); + QCOMPARE(laterDeadline.timerType(), timerType); + QVERIFY(laterDeadline.remainingTime() > (1000 - minResolution)); + QVERIFY(laterDeadline.remainingTime() <= 1001); + QVERIFY(laterDeadline.remainingTimeNSecs() > (1001 - minResolution)*1000*1000); + QVERIFY(laterDeadline.remainingTimeNSecs() <= (1001*1000*1000)); + QVERIFY(laterDeadline.deadline() != 0); + QVERIFY(laterDeadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(laterDeadline.deadlineNSecs() != 0); + QVERIFY(laterDeadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + QCOMPARE(laterDeadline.deadline(), deadline.deadline() + 1); + QCOMPARE(laterDeadline.deadlineNSecs(), deadline.deadlineNSecs() + 1000*1000); + + QCOMPARE(laterDeadline - deadline, qint64(1)); + QVERIFY(laterDeadline != deadline); + QVERIFY(!(laterDeadline < deadline)); + QVERIFY(!(laterDeadline <= deadline)); + QVERIFY(laterDeadline >= deadline); + QVERIFY(laterDeadline > deadline); + + // compare and order against a default-constructed object + QDeadlineTimer expired; + QVERIFY(!(deadline == expired)); + QVERIFY(deadline != expired); + QVERIFY(!(deadline < expired)); + QVERIFY(!(deadline <= expired)); + QVERIFY(deadline >= expired); + QVERIFY(deadline > expired); + + // compare and order against a forever deadline + QDeadlineTimer forever_(QDeadlineTimer::Forever); + QVERIFY(!(deadline == forever_)); + QVERIFY(deadline != forever_); + QVERIFY(deadline < forever_); + QVERIFY(deadline <= forever_); + QVERIFY(!(deadline >= forever_)); + QVERIFY(!(deadline > forever_)); +} + +void tst_QDeadlineTimer::setDeadline() +{ + QFETCH_GLOBAL(Qt::TimerType, timerType); + auto now = QDeadlineTimer::current(timerType); + QDeadlineTimer deadline; + + deadline.setDeadline(now.deadline(), timerType); + QVERIFY(deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QCOMPARE(deadline.deadline(), now.deadline()); + // don't check deadlineNSecs! + + deadline.setPreciseDeadline(now.deadlineNSecs() / (1000 * 1000 * 1000), + now.deadlineNSecs() % (1000 * 1000 * 1000), timerType); + QVERIFY(deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QCOMPARE(deadline.deadline(), now.deadline()); + QCOMPARE(deadline.deadlineNSecs(), now.deadlineNSecs()); + + now = QDeadlineTimer::current(timerType); + deadline.setDeadline(now.deadline() + 4 * minResolution, timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTime() > (3 * minResolution)); + QVERIFY(deadline.remainingTime() <= (4 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() > (3000000 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() <= (4000000 * minResolution)); + QCOMPARE(deadline.deadline(), now.deadline() + 4 * minResolution); // yes, it's exact + // don't check deadlineNSecs! + + now = QDeadlineTimer::current(timerType); + qint64 nsec = now.deadlineNSecs() + 4000000 * minResolution; + deadline.setPreciseDeadline(nsec / (1000 * 1000 * 1000), + nsec % (1000 * 1000 * 1000), timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTime() > (3 * minResolution)); + QVERIFY(deadline.remainingTime() <= (4 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() > (3000000 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() <= (4000000 * minResolution)); + QCOMPARE(deadline.deadline(), nsec / (1000 * 1000)); + QCOMPARE(deadline.deadlineNSecs(), nsec); +} + +void tst_QDeadlineTimer::expire() +{ + QFETCH_GLOBAL(Qt::TimerType, timerType); + + QDeadlineTimer deadline(minResolution, timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + + qint64 previousDeadline = deadline.deadlineNSecs(); + + QTest::qSleep(2 * minResolution); + + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), previousDeadline); +} + +void tst_QDeadlineTimer::stdchrono() +{ +#if !QT_HAS_INCLUDE(<chrono>) + QSKIP("std::chrono not found on this system"); +#else + using namespace std::chrono; + QFETCH_GLOBAL(Qt::TimerType, timerType); + + // create some forevers + QDeadlineTimer deadline = milliseconds::max(); + QVERIFY(deadline.isForever()); + deadline = milliseconds::max(); + QVERIFY(deadline.isForever()); + deadline.setRemainingTime(milliseconds::max(), timerType); + QVERIFY(deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + deadline = nanoseconds::max(); + QVERIFY(deadline.isForever()); + deadline.setRemainingTime(nanoseconds::max(), timerType); + QVERIFY(deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + deadline = hours::max(); + QVERIFY(deadline.isForever()); + deadline.setRemainingTime(hours::max(), timerType); + QVERIFY(deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + + deadline = time_point<system_clock>::max(); + QVERIFY(deadline.isForever()); + deadline.setDeadline(time_point<system_clock>::max(), timerType); + QVERIFY(deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + deadline = time_point<steady_clock>::max(); + QVERIFY(deadline.isForever()); + deadline.setDeadline(time_point<steady_clock>::max(), timerType); + QVERIFY(deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + + QVERIFY(deadline == time_point<steady_clock>::max()); + QVERIFY(deadline == time_point<system_clock>::max()); + QCOMPARE(deadline.remainingTimeAsDuration(), nanoseconds::max()); + + // make it expired + deadline = time_point<system_clock>(); + QVERIFY(deadline.hasExpired()); + deadline.setDeadline(time_point<system_clock>(), timerType); + QVERIFY(deadline.hasExpired()); + QCOMPARE(deadline.timerType(), timerType); + deadline = time_point<steady_clock>(); + QVERIFY(deadline.hasExpired()); + deadline.setDeadline(time_point<steady_clock>(), timerType); + QVERIFY(deadline.hasExpired()); + QCOMPARE(deadline.timerType(), timerType); + + QCOMPARE(deadline.remainingTimeAsDuration(), nanoseconds::zero()); + + auto steady_before = steady_clock::now(); + auto system_before = system_clock::now(); + + QTest::qSleep(minResolution); + auto now = QDeadlineTimer::current(timerType); + QTest::qSleep(minResolution); + + auto steady_after = steady_clock::now(); + auto system_after = system_clock::now(); + + { + auto diff = duration_cast<milliseconds>(steady_after - now.deadline<steady_clock>()); + QVERIFY2(diff.count() > minResolution/2, QByteArray::number(qint64(diff.count()))); + QVERIFY2(diff.count() < 3*minResolution/2, QByteArray::number(qint64(diff.count()))); + QDeadlineTimer dt_after(steady_after, timerType); + QVERIFY2(now < dt_after, + ("now = " + QLocale().toString(now.deadlineNSecs()) + + "; after = " + QLocale().toString(dt_after.deadlineNSecs())).toLatin1()); + + diff = duration_cast<milliseconds>(now.deadline<steady_clock>() - steady_before); + QVERIFY2(diff.count() > minResolution/2, QByteArray::number(qint64(diff.count()))); + QVERIFY2(diff.count() < 3*minResolution/2, QByteArray::number(qint64(diff.count()))); + QDeadlineTimer dt_before(steady_before, timerType); + QVERIFY2(now > dt_before, + ("now = " + QLocale().toString(now.deadlineNSecs()) + + "; before = " + QLocale().toString(dt_before.deadlineNSecs())).toLatin1()); + } + { + auto diff = duration_cast<milliseconds>(system_after - now.deadline<system_clock>()); + QVERIFY2(diff.count() > minResolution/2, QByteArray::number(qint64(diff.count()))); + QVERIFY2(diff.count() < 3*minResolution/2, QByteArray::number(qint64(diff.count()))); + QDeadlineTimer dt_after(system_after, timerType); + QVERIFY2(now < dt_after, + ("now = " + QLocale().toString(now.deadlineNSecs()) + + "; after = " + QLocale().toString(dt_after.deadlineNSecs())).toLatin1()); + + diff = duration_cast<milliseconds>(now.deadline<system_clock>() - system_before); + QVERIFY2(diff.count() > minResolution/2, QByteArray::number(qint64(diff.count()))); + QVERIFY2(diff.count() < 3*minResolution/2, QByteArray::number(qint64(diff.count()))); + QDeadlineTimer dt_before(system_before, timerType); + QVERIFY2(now > dt_before, + ("now = " + QLocale().toString(now.deadlineNSecs()) + + "; before = " + QLocale().toString(dt_before.deadlineNSecs())).toLatin1()); + } + + // make it regular + now = QDeadlineTimer::current(timerType); + deadline.setRemainingTime(milliseconds(4 * minResolution), timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTimeAsDuration() > milliseconds(3 * minResolution)); + QVERIFY(deadline.remainingTimeAsDuration() < milliseconds(5 * minResolution)); + QVERIFY(deadline.remainingTimeAsDuration() > nanoseconds(3000000 * minResolution)); + QVERIFY(deadline.remainingTimeAsDuration() < nanoseconds(5000000 * minResolution)); + QVERIFY(deadline.deadline<steady_clock>() > (steady_clock::now() + milliseconds(3 * minResolution))); + QVERIFY(deadline.deadline<steady_clock>() < (steady_clock::now() + milliseconds(5 * minResolution))); + QVERIFY(deadline.deadline<system_clock>() > (system_clock::now() + milliseconds(3 * minResolution))); + QVERIFY(deadline.deadline<system_clock>() < (system_clock::now() + milliseconds(5 * minResolution))); + if (timerType == Qt::CoarseTimer) { + QVERIFY(deadline > (now + milliseconds(3 * minResolution))); + QVERIFY(deadline < (now + milliseconds(5 * minResolution))); + QVERIFY(deadline > (now + nanoseconds(3000000 * minResolution))); + QVERIFY(deadline < (now + nanoseconds(5000000 * minResolution))); + QVERIFY(deadline > milliseconds(3 * minResolution)); + QVERIFY(deadline < milliseconds(5 * minResolution)); + QVERIFY(deadline > nanoseconds(3000000 * minResolution)); + QVERIFY(deadline < nanoseconds(5000000 * minResolution)); + QVERIFY(deadline >= steady_clock::now()); + QVERIFY(deadline >= system_clock::now()); + } + + now = QDeadlineTimer::current(timerType); + deadline = QDeadlineTimer(seconds(1), timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTimeAsDuration() > (seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.remainingTimeAsDuration() <= seconds(1)); + QVERIFY(deadline.deadline<steady_clock>() > (steady_clock::now() + seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<steady_clock>() <= (steady_clock::now() + seconds(1) + milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() > (system_clock::now() + seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() <= (system_clock::now() + seconds(1) + milliseconds(minResolution))); + if (timerType == Qt::CoarseTimer) { + QVERIFY(deadline > (seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline <= seconds(1)); + } + + now = QDeadlineTimer::current(timerType); + deadline.setRemainingTime(hours(1), timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTimeAsDuration() > (hours(1) - milliseconds(minResolution))); + QVERIFY(deadline.remainingTimeAsDuration() <= hours(1)); + QVERIFY(deadline.deadline<steady_clock>() > (steady_clock::now() + hours(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<steady_clock>() <= (steady_clock::now() + hours(1) + milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() > (system_clock::now() + hours(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() <= (system_clock::now() + hours(1) + milliseconds(minResolution))); + + now = QDeadlineTimer::current(timerType); + deadline.setDeadline(system_clock::now() + seconds(1), timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTimeAsDuration() > (seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.remainingTimeAsDuration() <= seconds(1)); + QVERIFY(deadline.deadline<steady_clock>() > (steady_clock::now() + seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<steady_clock>() <= (steady_clock::now() + seconds(1) + milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() > (system_clock::now() + seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() <= (system_clock::now() + seconds(1) + milliseconds(minResolution))); + + now = QDeadlineTimer::current(timerType); + deadline.setDeadline(steady_clock::now() + seconds(1), timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTimeAsDuration() > (seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.remainingTimeAsDuration() <= seconds(1)); + QVERIFY(deadline.deadline<steady_clock>() > (steady_clock::now() + seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<steady_clock>() <= (steady_clock::now() + seconds(1) + milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() > (system_clock::now() + seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() <= (system_clock::now() + seconds(1) + milliseconds(minResolution))); +#endif +} + +QTEST_MAIN(tst_QDeadlineTimer) + +#include "tst_qdeadlinetimer.moc" diff --git a/tests/auto/corelib/kernel/qelapsedtimer/qelapsedtimer.pro b/tests/auto/corelib/kernel/qelapsedtimer/qelapsedtimer.pro new file mode 100644 index 0000000000..657a63a5d7 --- /dev/null +++ b/tests/auto/corelib/kernel/qelapsedtimer/qelapsedtimer.pro @@ -0,0 +1,5 @@ +CONFIG += testcase +TARGET = tst_qelapsedtimer +QT = core testlib +SOURCES = tst_qelapsedtimer.cpp + diff --git a/tests/auto/corelib/kernel/qelapsedtimer/tst_qelapsedtimer.cpp b/tests/auto/corelib/kernel/qelapsedtimer/tst_qelapsedtimer.cpp new file mode 100644 index 0000000000..9db001c37d --- /dev/null +++ b/tests/auto/corelib/kernel/qelapsedtimer/tst_qelapsedtimer.cpp @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +#include <QtCore/QString> +#include <QtCore/QTime> +#include <QtCore/QElapsedTimer> +#include <QtTest/QtTest> + +static const int minResolution = 50; // the minimum resolution for the tests + +QDebug operator<<(QDebug s, const QElapsedTimer &t) +{ + s.nospace() << "(" << t.msecsSinceReference() << ")"; + return s.space(); +} + +class tst_QElapsedTimer : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void statics(); + void validity(); + void basics(); + void elapsed(); +}; + +void tst_QElapsedTimer::statics() +{ + qDebug() << "Clock type is" << QElapsedTimer::clockType(); + qDebug() << "Said clock is" << (QElapsedTimer::isMonotonic() ? "monotonic" : "not monotonic"); + QElapsedTimer t; + t.start(); + qDebug() << "Current time is" << t.msecsSinceReference(); +} + +void tst_QElapsedTimer::validity() +{ + QElapsedTimer t; + + QVERIFY(!t.isValid()); // non-POD now, it should always start invalid + + t.start(); + QVERIFY(t.isValid()); + + t.invalidate(); + QVERIFY(!t.isValid()); +} + +void tst_QElapsedTimer::basics() +{ + QElapsedTimer t1; + t1.start(); + + QVERIFY(t1.msecsSinceReference() != 0); + + QCOMPARE(t1, t1); + QVERIFY(!(t1 != t1)); + QVERIFY(!(t1 < t1)); + QCOMPARE(t1.msecsTo(t1), qint64(0)); + QCOMPARE(t1.secsTo(t1), qint64(0)); + + quint64 value1 = t1.msecsSinceReference(); + qDebug() << "value1:" << value1 << "t1:" << t1; + qint64 nsecs = t1.nsecsElapsed(); + qint64 elapsed = t1.restart(); + QVERIFY(elapsed < minResolution); + QVERIFY(nsecs / 1000000 < minResolution); + + quint64 value2 = t1.msecsSinceReference(); + qDebug() << "value2:" << value2 << "t1:" << t1 + << "elapsed:" << elapsed << "nsecs:" << nsecs; + // in theory, elapsed == value2 - value1 + + // However, since QElapsedTimer keeps internally the full resolution, + // we have here a rounding error due to integer division + QVERIFY(qAbs(elapsed - qint64(value2 - value1)) <= 1); +} + +void tst_QElapsedTimer::elapsed() +{ + QElapsedTimer t1; + t1.start(); + + QTest::qSleep(4*minResolution); + QElapsedTimer t2; + t2.start(); + + QVERIFY(t1 != t2); + QVERIFY(!(t1 == t2)); + QVERIFY(t1 < t2); + QVERIFY(t1.msecsTo(t2) > 0); + + QVERIFY(t1.nsecsElapsed() > 0); + QVERIFY(t1.elapsed() > 0); + // the number of elapsed nanoseconds and milliseconds should match + QVERIFY(t1.nsecsElapsed() - t1.elapsed() * 1000000 < 1000000); + QVERIFY(t1.hasExpired(minResolution)); + QVERIFY(!t1.hasExpired(8*minResolution)); + QVERIFY(!t2.hasExpired(minResolution)); + + QVERIFY(!t1.hasExpired(-1)); + QVERIFY(!t2.hasExpired(-1)); + + qint64 elapsed = t1.restart(); + QVERIFY(elapsed > 3*minResolution); + QVERIFY(elapsed < 5*minResolution); + qint64 diff = t2.msecsTo(t1); + QVERIFY(diff < minResolution); +} + +QTEST_MAIN(tst_QElapsedTimer); + +#include "tst_qelapsedtimer.moc" diff --git a/tests/auto/corelib/kernel/qeventloop/qeventloop.pro b/tests/auto/corelib/kernel/qeventloop/qeventloop.pro index 5cd043b584..295a42aa9c 100644 --- a/tests/auto/corelib/kernel/qeventloop/qeventloop.pro +++ b/tests/auto/corelib/kernel/qeventloop/qeventloop.pro @@ -3,6 +3,6 @@ TARGET = tst_qeventloop QT = core network testlib core-private SOURCES = $$PWD/tst_qeventloop.cpp -win32:!wince:!winrt: LIBS += -luser32 +win32:!winrt: LIBS += -luser32 -contains(QT_CONFIG, glib): DEFINES += HAVE_GLIB +qtConfig(glib): DEFINES += HAVE_GLIB diff --git a/tests/auto/corelib/kernel/qmetatype/qmetatype.pro b/tests/auto/corelib/kernel/qmetatype/qmetatype.pro index 1d4e647a4b..b5f1d0fe00 100644 --- a/tests/auto/corelib/kernel/qmetatype/qmetatype.pro +++ b/tests/auto/corelib/kernel/qmetatype/qmetatype.pro @@ -6,11 +6,11 @@ SOURCES = tst_qmetatype.cpp TESTDATA=./typeFlags.bin DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 -win32-msvc*|wince|winrt { +win32-msvc*|winrt { # Prevents "fatal error C1128: number of sections exceeded object file format limit". QMAKE_CXXFLAGS += /bigobj # Reduce compile time - win32-msvc2012|wince|winrt { + win32-msvc2012|winrt { QMAKE_CXXFLAGS_RELEASE -= -O2 QMAKE_CFLAGS_RELEASE -= -O2 } diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index fbb6a30917..7d9f56ef38 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -30,6 +30,7 @@ #include <QtCore> #include <QtTest/QtTest> +#include "tst_qmetatype.h" #include "tst_qvariant_common.h" #ifdef Q_OS_LINUX @@ -464,18 +465,6 @@ void tst_QMetaType::type_fromSubString() QCOMPARE(QMetaType::type(ba), expectedType); } -#define FOR_EACH_PRIMITIVE_METATYPE(F) \ - QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F) \ - QT_FOR_EACH_STATIC_CORE_POINTER(F) \ - -#define FOR_EACH_COMPLEX_CORE_METATYPE(F) \ - QT_FOR_EACH_STATIC_CORE_CLASS(F) \ - QT_FOR_EACH_STATIC_CORE_TEMPLATE(F) - -#define FOR_EACH_CORE_METATYPE(F) \ - FOR_EACH_PRIMITIVE_METATYPE(F) \ - FOR_EACH_COMPLEX_CORE_METATYPE(F) \ - namespace { template <typename T> struct static_assert_trigger { @@ -495,234 +484,6 @@ Q_STATIC_ASSERT((!QMetaTypeId2<QList<int> >::IsBuiltIn)); Q_STATIC_ASSERT((!QMetaTypeId2<QMap<int,int> >::IsBuiltIn)); Q_STATIC_ASSERT((!QMetaTypeId2<QMetaType::Type>::IsBuiltIn)); -template <int ID> -struct MetaEnumToType {}; - -#define DEFINE_META_ENUM_TO_TYPE(MetaTypeName, MetaTypeId, RealType) \ -template<> \ -struct MetaEnumToType<QMetaType::MetaTypeName> { \ - typedef RealType Type; \ -}; -FOR_EACH_CORE_METATYPE(DEFINE_META_ENUM_TO_TYPE) -#undef DEFINE_META_ENUM_TO_TYPE - -template <int ID> -struct DefaultValueFactory -{ - typedef typename MetaEnumToType<ID>::Type Type; - static Type *create() { return new Type; } -}; - -template <> -struct DefaultValueFactory<QMetaType::Void> -{ - typedef MetaEnumToType<QMetaType::Void>::Type Type; - static Type *create() { return 0; } -}; - -template <int ID> -struct DefaultValueTraits -{ - // By default we assume that a default-constructed value (new T) is - // initialized; e.g. QCOMPARE(*(new T), *(new T)) should succeed - enum { IsInitialized = true }; -}; - -#define DEFINE_NON_INITIALIZED_DEFAULT_VALUE_TRAITS(MetaTypeName, MetaTypeId, RealType) \ -template<> struct DefaultValueTraits<QMetaType::MetaTypeName> { \ - enum { IsInitialized = false }; \ -}; -// Primitive types (int et al) aren't initialized -FOR_EACH_PRIMITIVE_METATYPE(DEFINE_NON_INITIALIZED_DEFAULT_VALUE_TRAITS) -#undef DEFINE_NON_INITIALIZED_DEFAULT_VALUE_TRAITS - -template <int ID> -struct TestValueFactory {}; - -template<> struct TestValueFactory<QMetaType::Void> { - static void *create() { return 0; } -}; - -template<> struct TestValueFactory<QMetaType::QString> { - static QString *create() { return new QString(QString::fromLatin1("QString")); } -}; -template<> struct TestValueFactory<QMetaType::Int> { - static int *create() { return new int(0x12345678); } -}; -template<> struct TestValueFactory<QMetaType::UInt> { - static uint *create() { return new uint(0x12345678); } -}; -template<> struct TestValueFactory<QMetaType::Bool> { - static bool *create() { return new bool(true); } -}; -template<> struct TestValueFactory<QMetaType::Double> { - static double *create() { return new double(3.14); } -}; -template<> struct TestValueFactory<QMetaType::QByteArray> { - static QByteArray *create() { return new QByteArray(QByteArray("QByteArray")); } -}; -template<> struct TestValueFactory<QMetaType::QByteArrayList> { - static QByteArrayList *create() { return new QByteArrayList(QByteArrayList() << "Q" << "Byte" << "Array" << "List"); } -}; -template<> struct TestValueFactory<QMetaType::QVariantMap> { - static QVariantMap *create() { return new QVariantMap(); } -}; -template<> struct TestValueFactory<QMetaType::QVariantHash> { - static QVariantHash *create() { return new QVariantHash(); } -}; -template<> struct TestValueFactory<QMetaType::QVariantList> { - static QVariantList *create() { return new QVariantList(QVariantList() << 123 << "Q" << "Variant" << "List"); } -}; -template<> struct TestValueFactory<QMetaType::QChar> { - static QChar *create() { return new QChar(QChar('q')); } -}; -template<> struct TestValueFactory<QMetaType::Long> { - static long *create() { return new long(0x12345678); } -}; -template<> struct TestValueFactory<QMetaType::Short> { - static short *create() { return new short(0x1234); } -}; -template<> struct TestValueFactory<QMetaType::Char> { - static char *create() { return new char('c'); } -}; -template<> struct TestValueFactory<QMetaType::ULong> { - static ulong *create() { return new ulong(0x12345678); } -}; -template<> struct TestValueFactory<QMetaType::UShort> { - static ushort *create() { return new ushort(0x1234); } -}; -template<> struct TestValueFactory<QMetaType::SChar> { - static signed char *create() { return new signed char(-12); } -}; -template<> struct TestValueFactory<QMetaType::UChar> { - static uchar *create() { return new uchar('u'); } -}; -template<> struct TestValueFactory<QMetaType::Float> { - static float *create() { return new float(3.14f); } -}; -template<> struct TestValueFactory<QMetaType::QObjectStar> { - static QObject * *create() { return new QObject *(0); } -}; -template<> struct TestValueFactory<QMetaType::VoidStar> { - static void * *create() { return new void *(0); } -}; -template<> struct TestValueFactory<QMetaType::LongLong> { - static qlonglong *create() { return new qlonglong(0x12345678); } -}; -template<> struct TestValueFactory<QMetaType::ULongLong> { - static qulonglong *create() { return new qulonglong(0x12345678); } -}; -template<> struct TestValueFactory<QMetaType::QStringList> { - static QStringList *create() { return new QStringList(QStringList() << "Q" << "t"); } -}; -template<> struct TestValueFactory<QMetaType::QBitArray> { - static QBitArray *create() { return new QBitArray(QBitArray(256, true)); } -}; -template<> struct TestValueFactory<QMetaType::QDate> { - static QDate *create() { return new QDate(QDate::currentDate()); } -}; -template<> struct TestValueFactory<QMetaType::QTime> { - static QTime *create() { return new QTime(QTime::currentTime()); } -}; -template<> struct TestValueFactory<QMetaType::QDateTime> { - static QDateTime *create() { return new QDateTime(QDateTime::currentDateTime()); } -}; -template<> struct TestValueFactory<QMetaType::QUrl> { - static QUrl *create() { return new QUrl("http://www.example.org"); } -}; -template<> struct TestValueFactory<QMetaType::QLocale> { - static QLocale *create() { return new QLocale(QLocale::c()); } -}; -template<> struct TestValueFactory<QMetaType::QRect> { - static QRect *create() { return new QRect(10, 20, 30, 40); } -}; -template<> struct TestValueFactory<QMetaType::QRectF> { - static QRectF *create() { return new QRectF(10, 20, 30, 40); } -}; -template<> struct TestValueFactory<QMetaType::QSize> { - static QSize *create() { return new QSize(10, 20); } -}; -template<> struct TestValueFactory<QMetaType::QSizeF> { - static QSizeF *create() { return new QSizeF(10, 20); } -}; -template<> struct TestValueFactory<QMetaType::QLine> { - static QLine *create() { return new QLine(10, 20, 30, 40); } -}; -template<> struct TestValueFactory<QMetaType::QLineF> { - static QLineF *create() { return new QLineF(10, 20, 30, 40); } -}; -template<> struct TestValueFactory<QMetaType::QPoint> { - static QPoint *create() { return new QPoint(10, 20); } -}; -template<> struct TestValueFactory<QMetaType::QPointF> { - static QPointF *create() { return new QPointF(10, 20); } -}; -template<> struct TestValueFactory<QMetaType::QEasingCurve> { - static QEasingCurve *create() { return new QEasingCurve(QEasingCurve::InOutElastic); } -}; -template<> struct TestValueFactory<QMetaType::QUuid> { - static QUuid *create() { return new QUuid(); } -}; -template<> struct TestValueFactory<QMetaType::QModelIndex> { - static QModelIndex *create() { return new QModelIndex(); } -}; -template<> struct TestValueFactory<QMetaType::QPersistentModelIndex> { - static QPersistentModelIndex *create() { return new QPersistentModelIndex(); } -}; -template<> struct TestValueFactory<QMetaType::QRegExp> { - static QRegExp *create() - { -#ifndef QT_NO_REGEXP - return new QRegExp("A*"); -#else - return 0; -#endif - } -}; -template<> struct TestValueFactory<QMetaType::QRegularExpression> { - static QRegularExpression *create() - { -#ifndef QT_NO_REGEXP - return new QRegularExpression("abc.*def"); -#else - return 0; -#endif - } -}; -template<> struct TestValueFactory<QMetaType::QJsonValue> { - static QJsonValue *create() { return new QJsonValue(123.); } -}; -template<> struct TestValueFactory<QMetaType::QJsonObject> { - static QJsonObject *create() { - QJsonObject *o = new QJsonObject(); - o->insert("a", 123.); - o->insert("b", true); - o->insert("c", QJsonValue::Null); - o->insert("d", QLatin1String("ciao")); - return o; - } -}; -template<> struct TestValueFactory<QMetaType::QJsonArray> { - static QJsonArray *create() { - QJsonArray *a = new QJsonArray(); - a->append(123.); - a->append(true); - a->append(QJsonValue::Null); - a->append(QLatin1String("ciao")); - return a; - } -}; -template<> struct TestValueFactory<QMetaType::QJsonDocument> { - static QJsonDocument *create() { - return new QJsonDocument( - QJsonDocument::fromJson("{ 'foo': 123, 'bar': [true, null, 'ciao'] }") - ); - } -}; -template<> struct TestValueFactory<QMetaType::QVariant> { - static QVariant *create() { return new QVariant(QStringList(QStringList() << "Q" << "t")); } -}; - void tst_QMetaType::create_data() { QTest::addColumn<int>("type"); @@ -951,7 +712,7 @@ void tst_QMetaType::flags_data() << bool(!QTypeInfo<RealType>::isStatic) \ << bool(QTypeInfo<RealType>::isComplex) \ << bool(QtPrivate::IsPointerToTypeDerivedFromQObject<RealType>::Value) \ - << bool(Q_IS_ENUM(RealType)); + << bool(std::is_enum<RealType>::value); QT_FOR_EACH_STATIC_CORE_CLASS(ADD_METATYPE_TEST_ROW) QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(ADD_METATYPE_TEST_ROW) QT_FOR_EACH_STATIC_CORE_POINTER(ADD_METATYPE_TEST_ROW) @@ -1798,6 +1559,7 @@ DECLARE_NONSTREAMABLE(QJsonArray) DECLARE_NONSTREAMABLE(QJsonDocument) DECLARE_NONSTREAMABLE(QObject*) DECLARE_NONSTREAMABLE(QWidget*) +DECLARE_NONSTREAMABLE(std::nullptr_t) #define DECLARE_GUI_CLASS_NONSTREAMABLE(MetaTypeName, MetaTypeId, RealType) \ DECLARE_NONSTREAMABLE(RealType) diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h new file mode 100644 index 0000000000..93ff33bb67 --- /dev/null +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h @@ -0,0 +1,280 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** +****************************************************************************/ + +// Used by both tst_qmetatype and tst_qsettings + +#ifndef TST_QMETATYPE_H +#define TST_QMETATYPE_H + +#include <qmetatype.h> +#include <float.h> + +#define FOR_EACH_PRIMITIVE_METATYPE(F) \ + QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F) \ + QT_FOR_EACH_STATIC_CORE_POINTER(F) \ + +#define FOR_EACH_COMPLEX_CORE_METATYPE(F) \ + QT_FOR_EACH_STATIC_CORE_CLASS(F) \ + QT_FOR_EACH_STATIC_CORE_TEMPLATE(F) + +#define FOR_EACH_CORE_METATYPE(F) \ + FOR_EACH_PRIMITIVE_METATYPE(F) \ + FOR_EACH_COMPLEX_CORE_METATYPE(F) \ + +template <int ID> +struct MetaEnumToType {}; + +#define DEFINE_META_ENUM_TO_TYPE(MetaTypeName, MetaTypeId, RealType) \ +template<> \ +struct MetaEnumToType<QMetaType::MetaTypeName> { \ + typedef RealType Type; \ +}; +FOR_EACH_CORE_METATYPE(DEFINE_META_ENUM_TO_TYPE) +#undef DEFINE_META_ENUM_TO_TYPE + +template <int ID> +struct DefaultValueFactory +{ + typedef typename MetaEnumToType<ID>::Type Type; + static Type *create() { return new Type; } +}; + +template <> +struct DefaultValueFactory<QMetaType::Void> +{ + typedef MetaEnumToType<QMetaType::Void>::Type Type; + static Type *create() { return 0; } +}; + +template <int ID> +struct DefaultValueTraits +{ + // By default we assume that a default-constructed value (new T) is + // initialized; e.g. QCOMPARE(*(new T), *(new T)) should succeed + enum { IsInitialized = true }; +}; + +#define DEFINE_NON_INITIALIZED_DEFAULT_VALUE_TRAITS(MetaTypeName, MetaTypeId, RealType) \ +template<> struct DefaultValueTraits<QMetaType::MetaTypeName> { \ + enum { IsInitialized = false }; \ +}; +// Primitive types (int et al) aren't initialized +FOR_EACH_PRIMITIVE_METATYPE(DEFINE_NON_INITIALIZED_DEFAULT_VALUE_TRAITS) +#undef DEFINE_NON_INITIALIZED_DEFAULT_VALUE_TRAITS + +template <int ID> +struct TestValueFactory {}; + +template<> struct TestValueFactory<QMetaType::Void> { + static void *create() { return 0; } +}; + +template<> struct TestValueFactory<QMetaType::QString> { + static QString *create() { return new QString(QString::fromLatin1("QString")); } +}; +template<> struct TestValueFactory<QMetaType::Int> { + static int *create() { return new int(INT_MIN); } +}; +template<> struct TestValueFactory<QMetaType::UInt> { + static uint *create() { return new uint(UINT_MAX); } +}; +template<> struct TestValueFactory<QMetaType::Bool> { + static bool *create() { return new bool(true); } +}; +template<> struct TestValueFactory<QMetaType::Double> { + static double *create() { return new double(DBL_MIN); } +}; +template<> struct TestValueFactory<QMetaType::QByteArray> { + static QByteArray *create() { return new QByteArray(QByteArray("QByteArray")); } +}; +template<> struct TestValueFactory<QMetaType::QByteArrayList> { + static QByteArrayList *create() { return new QByteArrayList(QByteArrayList() << "Q" << "Byte" << "Array" << "List"); } +}; +template<> struct TestValueFactory<QMetaType::QVariantMap> { + static QVariantMap *create() { return new QVariantMap(); } +}; +template<> struct TestValueFactory<QMetaType::QVariantHash> { + static QVariantHash *create() { return new QVariantHash(); } +}; +template<> struct TestValueFactory<QMetaType::QVariantList> { + static QVariantList *create() { return new QVariantList(QVariantList() << 123 << "Q" << "Variant" << "List"); } +}; +template<> struct TestValueFactory<QMetaType::QChar> { + static QChar *create() { return new QChar(QChar('q')); } +}; +template<> struct TestValueFactory<QMetaType::Long> { + static long *create() { return new long(LONG_MIN); } +}; +template<> struct TestValueFactory<QMetaType::Short> { + static short *create() { return new short(SHRT_MIN); } +}; +template<> struct TestValueFactory<QMetaType::Char> { + static char *create() { return new char('c'); } +}; +template<> struct TestValueFactory<QMetaType::ULong> { + static ulong *create() { return new ulong(ULONG_MAX); } +}; +template<> struct TestValueFactory<QMetaType::UShort> { + static ushort *create() { return new ushort(USHRT_MAX); } +}; +template<> struct TestValueFactory<QMetaType::SChar> { + static signed char *create() { return new signed char(CHAR_MIN); } +}; +template<> struct TestValueFactory<QMetaType::UChar> { + static uchar *create() { return new uchar(UCHAR_MAX); } +}; +template<> struct TestValueFactory<QMetaType::Float> { + static float *create() { return new float(FLT_MIN); } +}; +template<> struct TestValueFactory<QMetaType::QObjectStar> { + static QObject * *create() { return new QObject *(0); } +}; +template<> struct TestValueFactory<QMetaType::VoidStar> { + static void * *create() { return new void *(0); } +}; +template<> struct TestValueFactory<QMetaType::LongLong> { + static qlonglong *create() { return new qlonglong(LLONG_MIN); } +}; +template<> struct TestValueFactory<QMetaType::ULongLong> { + static qulonglong *create() { return new qulonglong(ULLONG_MAX); } +}; +template<> struct TestValueFactory<QMetaType::QStringList> { + static QStringList *create() { return new QStringList(QStringList() << "Q" << "t"); } +}; +template<> struct TestValueFactory<QMetaType::QBitArray> { + static QBitArray *create() { return new QBitArray(QBitArray(256, true)); } +}; +template<> struct TestValueFactory<QMetaType::QDate> { + static QDate *create() { return new QDate(QDate::currentDate()); } +}; +template<> struct TestValueFactory<QMetaType::QTime> { + static QTime *create() { return new QTime(QTime::currentTime()); } +}; +template<> struct TestValueFactory<QMetaType::QDateTime> { + static QDateTime *create() { return new QDateTime(QDateTime::currentDateTime()); } +}; +template<> struct TestValueFactory<QMetaType::QUrl> { + static QUrl *create() { return new QUrl("http://www.example.org"); } +}; +template<> struct TestValueFactory<QMetaType::QLocale> { + static QLocale *create() { return new QLocale(QLocale::c()); } +}; +template<> struct TestValueFactory<QMetaType::QRect> { + static QRect *create() { return new QRect(10, 20, 30, 40); } +}; +template<> struct TestValueFactory<QMetaType::QRectF> { + static QRectF *create() { return new QRectF(10, 20, 30, 40); } +}; +template<> struct TestValueFactory<QMetaType::QSize> { + static QSize *create() { return new QSize(10, 20); } +}; +template<> struct TestValueFactory<QMetaType::QSizeF> { + static QSizeF *create() { return new QSizeF(10, 20); } +}; +template<> struct TestValueFactory<QMetaType::QLine> { + static QLine *create() { return new QLine(10, 20, 30, 40); } +}; +template<> struct TestValueFactory<QMetaType::QLineF> { + static QLineF *create() { return new QLineF(10, 20, 30, 40); } +}; +template<> struct TestValueFactory<QMetaType::QPoint> { + static QPoint *create() { return new QPoint(10, 20); } +}; +template<> struct TestValueFactory<QMetaType::QPointF> { + static QPointF *create() { return new QPointF(10, 20); } +}; +template<> struct TestValueFactory<QMetaType::QEasingCurve> { + static QEasingCurve *create() { return new QEasingCurve(QEasingCurve::InOutElastic); } +}; +template<> struct TestValueFactory<QMetaType::QUuid> { + static QUuid *create() { return new QUuid(); } +}; +template<> struct TestValueFactory<QMetaType::QModelIndex> { + static QModelIndex *create() { return new QModelIndex(); } +}; +template<> struct TestValueFactory<QMetaType::QPersistentModelIndex> { + static QPersistentModelIndex *create() { return new QPersistentModelIndex(); } +}; +template<> struct TestValueFactory<QMetaType::Nullptr> { + static std::nullptr_t *create() { return new std::nullptr_t; } +}; +template<> struct TestValueFactory<QMetaType::QRegExp> { + static QRegExp *create() + { +#ifndef QT_NO_REGEXP + return new QRegExp("A*"); +#else + return 0; +#endif + } +}; +template<> struct TestValueFactory<QMetaType::QRegularExpression> { + static QRegularExpression *create() + { +#ifndef QT_NO_REGEXP + return new QRegularExpression("abc.*def"); +#else + return 0; +#endif + } +}; +template<> struct TestValueFactory<QMetaType::QJsonValue> { + static QJsonValue *create() { return new QJsonValue(123.); } +}; +template<> struct TestValueFactory<QMetaType::QJsonObject> { + static QJsonObject *create() { + QJsonObject *o = new QJsonObject(); + o->insert("a", 123.); + o->insert("b", true); + o->insert("c", QJsonValue::Null); + o->insert("d", QLatin1String("ciao")); + return o; + } +}; +template<> struct TestValueFactory<QMetaType::QJsonArray> { + static QJsonArray *create() { + QJsonArray *a = new QJsonArray(); + a->append(123.); + a->append(true); + a->append(QJsonValue::Null); + a->append(QLatin1String("ciao")); + return a; + } +}; +template<> struct TestValueFactory<QMetaType::QJsonDocument> { + static QJsonDocument *create() { + return new QJsonDocument( + QJsonDocument::fromJson("{ 'foo': 123, 'bar': [true, null, 'ciao'] }") + ); + } +}; +template<> struct TestValueFactory<QMetaType::QVariant> { + static QVariant *create() { return new QVariant(QStringList(QStringList() << "Q" << "t")); } +}; + +#endif // TST_QMETATYPE_H diff --git a/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro b/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro index 125915047a..cc51b4c661 100644 --- a/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro +++ b/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro @@ -2,9 +2,6 @@ CONFIG -= app_bundle debug_and_release CONFIG += console DESTDIR = ./ QT = core -wince { - LIBS += coredll.lib -} HEADERS += signalbug.h SOURCES += signalbug.cpp diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 333305d603..91810cdcd8 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -66,6 +66,7 @@ private slots: void connectDisconnectNotify(); void connectDisconnectNotifyPMF(); void disconnectNotify_receiverDestroyed(); + void disconnectNotify_metaObjConnection(); void connectNotify_connectSlotsByName(); void connectDisconnectNotify_shadowing(); void emitInDefinedOrder(); @@ -146,6 +147,7 @@ private slots: void noDeclarativeParentChangedOnDestruction(); void deleteLaterInAboutToBlockHandler(); void mutableFunctor(); + void checkArgumentsForNarrowing(); }; struct QObjectCreatedOnShutdown @@ -923,8 +925,7 @@ void tst_QObject::connectDisconnectNotifyPMF() // Test disconnectNotify when disconnecting by QMetaObject::Connection QVERIFY(QObject::disconnect(conn)); - // disconnectNotify() is not called, but it probably should be. - QVERIFY(s->disconnectedSignals.isEmpty()); + QVERIFY(!s->disconnectedSignals.isEmpty()); // Test connectNotify when connecting by function pointer s->clearNotifications(); @@ -969,6 +970,25 @@ void tst_QObject::disconnectNotify_receiverDestroyed() delete s; } +void tst_QObject::disconnectNotify_metaObjConnection() +{ + NotifyObject *s = new NotifyObject; + NotifyObject *r = new NotifyObject; + + QMetaObject::Connection c = QObject::connect((SenderObject*)s, SIGNAL(signal1()), + (ReceiverObject*)r, SLOT(slot1())); + QVERIFY(c); + QVERIFY(QObject::disconnect(c)); + + QCOMPARE(s->disconnectedSignals.count(), 1); + QCOMPARE(s->disconnectedSignals.at(0), QMetaMethod::fromSignal(&SenderObject::signal1)); + + delete r; + QCOMPARE(s->disconnectedSignals.count(), 1); + + delete s; +} + class ConnectByNameNotifySenderObject : public QObject { Q_OBJECT @@ -1575,11 +1595,7 @@ Q_DECLARE_METATYPE(PropertyObject::Priority) void tst_QObject::threadSignalEmissionCrash() { -#if defined(Q_OS_WINCE) - int loopCount = 100; -#else int loopCount = 1000; -#endif for (int i = 0; i < loopCount; ++i) { QTcpSocket socket; socket.connectToHost("localhost", 80); @@ -6731,6 +6747,515 @@ void tst_QObject::mutableFunctor() QCOMPARE(functor.count, 0); // but the original object should have been copied at connect time } +void tst_QObject::checkArgumentsForNarrowing() +{ + enum UnscopedEnum {}; + enum SignedUnscopedEnum { SignedUnscopedEnumV1 = -1, SignedUnscopedEnumV2 = 1 }; + + QVERIFY(sizeof(UnscopedEnum) <= sizeof(int)); + QVERIFY(sizeof(SignedUnscopedEnum) <= sizeof(int)); + + // floating point to integral + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<float, bool>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<double, bool>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, bool>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<float, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<double, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, char>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<float, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<double, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, short>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<float, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<double, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, int>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<float, long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<double, long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<float, long long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<double, long long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, long long>::value)); + + + // floating point to a smaller floating point + if (sizeof(double) > sizeof(float)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<double, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, float>::value)); + } + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<float, double>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<float, long double>::value)); + + if (sizeof(long double) > sizeof(double)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, float>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<double, long double>::value)); + + + // integral to floating point + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, long double>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<char, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<char, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<char, long double>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, long double>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, long double>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, long double>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, long double>::value)); + + + // enum to floating point + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, long double>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, long double>::value)); + + + // integral to smaller integral + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<bool, bool>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<char, char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<signed char, signed char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<signed char, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<signed char, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<signed char, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<signed char, long long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, unsigned char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, unsigned short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, unsigned int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, unsigned long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, unsigned long long>::value)); + + if (sizeof(bool) > sizeof(char)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, unsigned char>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<bool, unsigned char>::value)); + + if (sizeof(bool) > sizeof(short)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, unsigned short>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<bool, unsigned short>::value)); + + if (sizeof(bool) > sizeof(int)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, unsigned int>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<bool, unsigned int>::value)); + + if (sizeof(bool) > sizeof(long)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, unsigned long>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<bool, unsigned long>::value)); + + if (sizeof(bool) > sizeof(long long)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, unsigned long long>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<bool, unsigned long long>::value)); + + if (sizeof(short) > sizeof(char)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, signed char>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned short, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned short, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned short, signed char>::value)); + } + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<short, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<short, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<short, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<short, long long>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, unsigned short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, unsigned int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, unsigned long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, unsigned long long>::value)); + + if (sizeof(int) > sizeof(short)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, unsigned short>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned int, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned int, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned int, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned int, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned int, unsigned short>::value)); + } + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<int, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<int, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<int, long long>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned int, unsigned int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned int, unsigned long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned int, unsigned long long>::value)); + + if (sizeof(long) > sizeof(int)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, unsigned int>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, unsigned int>::value)); + } + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<long, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<long, long long>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned long, unsigned long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned long, unsigned long long>::value)); + + if (sizeof(long long) > sizeof(long)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, unsigned long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, unsigned long>::value)); + } + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<long long, long long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned long long, unsigned long long>::value)); + + + // integral to integral with different signedness. smaller ones tested above + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<signed char, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<signed char, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<signed char, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<signed char, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<signed char, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned char, signed char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned short, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned int, int>::value)); + QCOMPARE((QtPrivate::AreArgumentsNarrowedBase<unsigned int, long>::value), sizeof(int) >= sizeof(long)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned int, long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, long>::value)); + QCOMPARE((QtPrivate::AreArgumentsNarrowedBase<unsigned long, long long>::value), sizeof(long) >= sizeof(long long)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, unsigned long long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, long long>::value)); + + // enum to smaller integral + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, UnscopedEnum>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, SignedUnscopedEnum>::value)); + + if (std::is_signed<typename std::underlying_type<UnscopedEnum>::type>::value) { + if (sizeof(UnscopedEnum) > sizeof(char)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, signed char>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, signed char>::value)); + + if (sizeof(UnscopedEnum) > sizeof(short)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, short>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, short>::value)); + + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, int>::value)); + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, long>::value)); + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, long long>::value)); + } else { + if (sizeof(UnscopedEnum) > sizeof(bool)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, bool>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, bool>::value)); + + if (sizeof(UnscopedEnum) > sizeof(char)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, unsigned char>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, unsigned char>::value)); + + if (sizeof(UnscopedEnum) > sizeof(short)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, unsigned short>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, unsigned short>::value)); + + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, unsigned int>::value)); + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, unsigned long>::value)); + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, unsigned long long>::value)); + } + + QVERIFY(std::is_signed<typename std::underlying_type<SignedUnscopedEnum>::type>::value); + + if (sizeof(SignedUnscopedEnum) > sizeof(char)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, signed char>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, signed char>::value)); + + if (sizeof(SignedUnscopedEnum) > sizeof(short)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, short>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, short>::value)); + + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, int>::value)); + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, long>::value)); + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, long long>::value)); + + + enum class ScopedEnumBackedBySChar : signed char { A }; + enum class ScopedEnumBackedByUChar : unsigned char { A }; + enum class ScopedEnumBackedByShort : short { A }; + enum class ScopedEnumBackedByUShort : unsigned short { A }; + enum class ScopedEnumBackedByInt : int { A }; + enum class ScopedEnumBackedByUInt : unsigned int { A }; + enum class ScopedEnumBackedByLong : long { A }; + enum class ScopedEnumBackedByULong : unsigned long { A }; + enum class ScopedEnumBackedByLongLong : long long { A }; + enum class ScopedEnumBackedByULongLong : unsigned long long { A }; + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, ScopedEnumBackedBySChar>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, ScopedEnumBackedByUChar>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, ScopedEnumBackedByShort>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, ScopedEnumBackedByUShort>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, ScopedEnumBackedByInt>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, ScopedEnumBackedByUInt>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, ScopedEnumBackedByLong>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, ScopedEnumBackedByULong>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, ScopedEnumBackedByLongLong>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, ScopedEnumBackedByULongLong>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, signed char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, unsigned char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, unsigned short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, unsigned int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, unsigned long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, long long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, unsigned long long>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, signed char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, long long>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, unsigned char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, unsigned short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, unsigned int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, unsigned long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, unsigned long long>::value)); + + if (sizeof(short) > sizeof(char)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, char>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, signed char>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, unsigned char>::value)); + } + + if (sizeof(int) > sizeof(short)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, short>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, unsigned short>::value)); + } + + if (sizeof(long) > sizeof(int)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, int>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, unsigned int>::value)); + } + + if (sizeof(long long) > sizeof(long)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, unsigned long>::value)); + } + + // different signedness of the underlying type + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, unsigned long long>::value)); + + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, signed char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, int>::value)); + QCOMPARE((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, long>::value), sizeof(ScopedEnumBackedByUInt) >= sizeof(long)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, long>::value)); + QCOMPARE((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, long long>::value), sizeof(ScopedEnumBackedByULong) >= sizeof(long long)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, long long>::value)); + + // other types which should be always unaffected + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<void *, void *>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QString, QString>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QString &, QString &>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<const QString &, const QString &>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QObject, QObject>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QObject *, QObject *>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<const QObject *, const QObject *>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<std::nullptr_t, std::nullptr_t>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QString, QObject>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QString, QVariant>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QString, void *>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QString, long long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<bool, const QObject *&>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<int (*)(bool), void (QObject::*)()>::value)); +} + // Test for QtPrivate::HasQ_OBJECT_Macro Q_STATIC_ASSERT(QtPrivate::HasQ_OBJECT_Macro<tst_QObject>::Value); Q_STATIC_ASSERT(!QtPrivate::HasQ_OBJECT_Macro<SiblingDeleter>::Value); diff --git a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp index b6f6d2a7f3..26caff4301 100644 --- a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp +++ b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp @@ -90,7 +90,7 @@ private slots: // extreme cases void useTooMuchMemory(); -#if !defined(Q_OS_HPUX) && !defined(Q_OS_WINCE) +#if !defined(Q_OS_HPUX) void attachTooMuch(); #endif @@ -516,8 +516,7 @@ void tst_QSharedMemory::useTooMuchMemory() attach before the system runs out of resources. */ // HPUX doesn't allow for multiple attaches per process. -// For WinCE, this test nearly kills the system, so skip it. -#if !defined(Q_OS_HPUX) && !defined(Q_OS_WINCE) +#if !defined(Q_OS_HPUX) void tst_QSharedMemory::attachTooMuch() { QSKIP("disabled"); @@ -576,9 +575,7 @@ void tst_QSharedMemory::simpleProducerConsumer() char *get = (char*)consumer.data(); // On Windows CE you always have ReadWrite access. Thus // ViewMapOfFile returns the same pointer -#if !defined(Q_OS_WINCE) QVERIFY(put != get); -#endif for (int i = 0; i < size; ++i) { put[i] = 'Q'; QCOMPARE(get[i], 'Q'); diff --git a/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro b/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro index 58e4b98af7..04806de5f7 100644 --- a/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro +++ b/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro @@ -3,6 +3,6 @@ TARGET = tst_qsocketnotifier QT = core-private network-private testlib SOURCES = tst_qsocketnotifier.cpp -requires(contains(QT_CONFIG,private_tests)) +requires(qtConfig(private_tests)) include(../../../network/socket/platformsocketengine/platformsocketengine.pri) diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index 6fd192c357..fe97695d19 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -52,6 +52,7 @@ private slots: void remainingTime(); void remainingTimeDuringActivation_data(); void remainingTimeDuringActivation(); + void basic_chrono(); void livelock_data(); void livelock(); void timerInfiniteRecursion_data(); @@ -68,6 +69,7 @@ private slots: void singleShotStaticFunctionZeroTimeout(); void recurseOnTimeoutAndStopTimer(); void singleShotToFunctors(); + void singleShot_chrono(); void crossThreadSingleShotToFunctor(); void dontBlockEvents(); @@ -214,6 +216,67 @@ void tst_QTimer::remainingTimeDuringActivation() } } +namespace { + +#if QT_HAS_INCLUDE(<chrono>) + template <typename T> + std::chrono::milliseconds to_ms(T t) + { return std::chrono::duration_cast<std::chrono::milliseconds>(t); } +#endif + +} // unnamed namespace + +void tst_QTimer::basic_chrono() +{ +#if !QT_HAS_INCLUDE(<chrono>) + QSKIP("This test requires C++11 <chrono> support"); +#else + // duplicates zeroTimer, singleShotTimeout, interval and remainingTime + using namespace std::chrono; + TimerHelper helper; + QTimer timer; + timer.setInterval(to_ms(nanoseconds(0))); + timer.start(); + QCOMPARE(timer.intervalAsDuration().count(), milliseconds::rep(0)); + QCOMPARE(timer.remainingTimeAsDuration().count(), milliseconds::rep(0)); + + connect(&timer, SIGNAL(timeout()), &helper, SLOT(timeout())); + + QCoreApplication::processEvents(); + + QCOMPARE(helper.count, 1); + + helper.count = 0; + timer.start(milliseconds(100)); + QCOMPARE(helper.count, 0); + + QTest::qWait(TIMEOUT_TIMEOUT); + QVERIFY(helper.count > 0); + int oldCount = helper.count; + + QTest::qWait(TIMEOUT_TIMEOUT); + QVERIFY(helper.count > oldCount); + + helper.count = 0; + timer.start(to_ms(microseconds(200000))); + QCOMPARE(timer.intervalAsDuration().count(), milliseconds::rep(200)); + QTest::qWait(50); + QCOMPARE(helper.count, 0); + + milliseconds rt = timer.remainingTimeAsDuration(); + QVERIFY2(qAbs(rt.count() - 150) < 50, qPrintable(QString::number(rt.count()))); + + helper.count = 0; + timer.setSingleShot(true); + timer.start(milliseconds(100)); + QTest::qWait(500); + QCOMPARE(helper.count, 1); + QTest::qWait(500); + QCOMPARE(helper.count, 1); + helper.count = 0; +#endif +} + void tst_QTimer::livelock_data() { QTest::addColumn<int>("interval"); @@ -295,9 +358,6 @@ void tst_QTimer::livelock() QTRY_COMPARE(tester.timeoutsForFirst, 1); QCOMPARE(tester.timeoutsForExtra, 0); QTRY_COMPARE(tester.timeoutsForSecond, 1); -#if defined(Q_OS_WINCE) - QEXPECT_FAIL("non-zero timer", "Windows CE devices often too slow", Continue); -#endif QVERIFY(tester.postEventAtRightTime); } @@ -790,6 +850,51 @@ void tst_QTimer::singleShotToFunctors() _t = Q_NULLPTR; } +void tst_QTimer::singleShot_chrono() +{ +#if !QT_HAS_INCLUDE(<chrono>) + QSKIP("This test requires C++11 <chrono> support"); +#else + // duplicates singleShotStaticFunctionZeroTimeout and singleShotToFunctors + using namespace std::chrono; + TimerHelper helper; + + QTimer::singleShot(hours(0), &helper, SLOT(timeout())); + QTest::qWait(500); + QCOMPARE(helper.count, 1); + QTest::qWait(500); + QCOMPARE(helper.count, 1); + + TimerHelper nhelper; + + QTimer::singleShot(seconds(0), &nhelper, &TimerHelper::timeout); + QCoreApplication::processEvents(); + QCOMPARE(nhelper.count, 1); + QCoreApplication::processEvents(); + QCOMPARE(nhelper.count, 1); + + int count = 0; + QTimer::singleShot(to_ms(microseconds(0)), CountedStruct(&count)); + QCoreApplication::processEvents(); + QCOMPARE(count, 1); + + _e.reset(new QEventLoop); + QTimer::singleShot(0, &StaticEventLoop::quitEventLoop); + QCOMPARE(_e->exec(), 0); + + QObject c3; + QTimer::singleShot(milliseconds(500), &c3, CountedStruct(&count)); + QTest::qWait(800); + QCOMPARE(count, 2); + + QTimer::singleShot(0, [&count] { ++count; }); + QCoreApplication::processEvents(); + QCOMPARE(count, 3); + + _e.reset(); +#endif +} + class DontBlockEvents : public QObject { Q_OBJECT diff --git a/tests/auto/corelib/kernel/qvariant/qvariant.pro b/tests/auto/corelib/kernel/qvariant/qvariant.pro index 33e8b6e2ad..96071f9f73 100644 --- a/tests/auto/corelib/kernel/qvariant/qvariant.pro +++ b/tests/auto/corelib/kernel/qvariant/qvariant.pro @@ -5,7 +5,7 @@ INCLUDEPATH += $$PWD/../../../other/qvariant_common SOURCES = tst_qvariant.cpp RESOURCES += qvariant.qrc DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 -contains(QT_CONFIG, c++11): CONFIG += c++11 -!contains(QT_CONFIG, doubleconversion):!contains(QT_CONFIG, system-doubleconversion) { +qtConfig(c++11): CONFIG += c++11 +!qtConfig(doubleconversion):!qtConfig(system-doubleconversion) { DEFINES += QT_NO_DOUBLECONVERSION } diff --git a/tests/auto/corelib/kernel/qvariant/stream/qt5.0/qdatetime.bin b/tests/auto/corelib/kernel/qvariant/stream/qt5.0/qdatetime.bin Binary files differindex ee3da63a18..e3a897c37d 100644 --- a/tests/auto/corelib/kernel/qvariant/stream/qt5.0/qdatetime.bin +++ b/tests/auto/corelib/kernel/qvariant/stream/qt5.0/qdatetime.bin |