diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2015-09-25 14:02:04 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-09-25 14:02:04 +0200 |
commit | a1ad9a74ebb3c556c5f70f7e03be68b09598ac53 (patch) | |
tree | 615a96db418219a57a745a5899e39a9ac90744ec /tests/auto | |
parent | 6d78b7a0c46ea04f4bb771d960e2f7dff1362341 (diff) | |
parent | 462f355e4fb16cc7a1838fa2dda0f763eee58c84 (diff) |
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts:
src/corelib/io/io.pri
src/corelib/io/qdatastream.cpp
src/corelib/io/qdatastream.h
src/network/socket/qabstractsocket.cpp
src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp
src/plugins/platforms/cocoa/qcocoaaccessibilityelement.h
src/widgets/styles/qgtkstyle.cpp
tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/qmimedatabase-cache.pro
tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/qmimedatabase-xml.pro
tests/auto/dbus/qdbusconnection/qdbusconnection.pro
tests/auto/dbus/qdbuspendingcall/tst_qdbuspendingcall.cpp
tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
Change-Id: I347549a024eb5bfa986699e0a11f96cc55c797a7
Diffstat (limited to 'tests/auto')
70 files changed, 1844 insertions, 635 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 38e705e02f..e905a416a6 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -32,8 +32,11 @@ cross_compile: SUBDIRS -= tools cmake installed_cma # Disable the QtDBus tests if we can't connect to the session bus qtHaveModule(dbus) { - !system("dbus-send --session --type=signal / local.AutotestCheck.Hello"): { - warning("QtDBus is enabled but session bus is not available. Please check the installation.") + !system("dbus-send --session --type=signal / local.AutotestCheck.Hello >/dev/null 2>&1") { + contains(QT_CONFIG, dbus-linked): \ + error("QtDBus is enabled but session bus is not available. Please check the installation.") + else: \ + warning("QtDBus is enabled with runtime support, but session bus is not available. Skipping QtDBus tests.") SUBDIRS -= dbus } } else { diff --git a/tests/auto/corelib/global/qnumeric/qnumeric.pro b/tests/auto/corelib/global/qnumeric/qnumeric.pro index 114ad4886c..188bb5b463 100644 --- a/tests/auto/corelib/global/qnumeric/qnumeric.pro +++ b/tests/auto/corelib/global/qnumeric/qnumeric.pro @@ -1,6 +1,6 @@ CONFIG += testcase TARGET = tst_qnumeric -QT = core testlib +QT = core-private testlib SOURCES = tst_qnumeric.cpp intel_icc: QMAKE_CXXFLAGS += -fp-model strict intel_icl: QMAKE_CXXFLAGS += /fp:strict diff --git a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp index fdc8bc6aab..59a536ed25 100644 --- a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp +++ b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp @@ -34,6 +34,7 @@ #include <QtTest/QtTest> #include <QtGlobal> +#include "private/qnumeric_p.h" #include <math.h> #include <float.h> @@ -50,6 +51,10 @@ private slots: void floatDistance(); void floatDistance_double_data(); void floatDistance_double(); + void addOverflow_data(); + void addOverflow(); + void mulOverflow_data(); + void mulOverflow(); }; void tst_QNumeric::fuzzyCompare_data() @@ -206,5 +211,160 @@ void tst_QNumeric::floatDistance_double() QCOMPARE(qFloatDistance(val1, val2), expectedDistance); } +void tst_QNumeric::addOverflow_data() +{ + QTest::addColumn<int>("size"); + QTest::newRow("quint8") << 8; + QTest::newRow("quint16") << 16; + QTest::newRow("quint32") << 32; + QTest::newRow("quint64") << 64; + QTest::newRow("ulong") << 48; // it's either 32- or 64-bit, so on average it's 48 :-) +} + +// Note: in release mode, all the tests may be statically determined and only the calls +// to QTest::toString and QTest::qCompare will remain. +template <typename Int> static void addOverflow_template() +{ +#if defined(Q_CC_MSVC) && Q_CC_MSVC < 1900 + QSKIP("Test disabled, this test generates an Internal Compiler Error compiling"); +#else + const Int max = std::numeric_limits<Int>::max(); + Int r; + + // basic values + QCOMPARE(add_overflow(Int(0), Int(0), &r), false); + QCOMPARE(r, Int(0)); + QCOMPARE(add_overflow(Int(1), Int(0), &r), false); + QCOMPARE(r, Int(1)); + QCOMPARE(add_overflow(Int(0), Int(1), &r), false); + QCOMPARE(r, Int(1)); + + // half-way through max + QCOMPARE(add_overflow(Int(max/2), Int(max/2), &r), false); + QCOMPARE(r, Int(max / 2 * 2)); + QCOMPARE(add_overflow(Int(max/2 - 1), Int(max/2 + 1), &r), false); + QCOMPARE(r, Int(max / 2 * 2)); + QCOMPARE(add_overflow(Int(max/2 + 1), Int(max/2), &r), false); + QCOMPARE(r, max); + QCOMPARE(add_overflow(Int(max/2), Int(max/2 + 1), &r), false); + QCOMPARE(r, max); + + // more than half + QCOMPARE(add_overflow(Int(max/4 * 3), Int(max/4), &r), false); + QCOMPARE(r, Int(max / 4 * 4)); + + // max + QCOMPARE(add_overflow(max, Int(0), &r), false); + QCOMPARE(r, max); + QCOMPARE(add_overflow(Int(0), max, &r), false); + QCOMPARE(r, max); + + // 64-bit issues + if (max > std::numeric_limits<uint>::max()) { + QCOMPARE(add_overflow(Int(std::numeric_limits<uint>::max()), Int(std::numeric_limits<uint>::max()), &r), false); + QCOMPARE(r, Int(2 * Int(std::numeric_limits<uint>::max()))); + } + + // overflows + QCOMPARE(add_overflow(max, Int(1), &r), true); + QCOMPARE(add_overflow(Int(1), max, &r), true); + QCOMPARE(add_overflow(Int(max/2 + 1), Int(max/2 + 1), &r), true); +#endif +} + +void tst_QNumeric::addOverflow() +{ + QFETCH(int, size); + if (size == 8) + addOverflow_template<quint8>(); + if (size == 16) + addOverflow_template<quint16>(); + if (size == 32) + addOverflow_template<quint32>(); + if (size == 48) + addOverflow_template<ulong>(); // not really 48-bit + if (size == 64) + addOverflow_template<quint64>(); +} + +void tst_QNumeric::mulOverflow_data() +{ + addOverflow_data(); +} + +// Note: in release mode, all the tests may be statically determined and only the calls +// to QTest::toString and QTest::qCompare will remain. +template <typename Int> static void mulOverflow_template() +{ +#if defined(Q_CC_MSVC) && Q_CC_MSVC < 1900 + QSKIP("Test disabled, this test generates an Internal Compiler Error compiling"); +#else + const Int max = std::numeric_limits<Int>::max(); + const Int middle = Int(max >> (sizeof(Int) * CHAR_BIT / 2)); + Int r; + + // basic multiplications + QCOMPARE(mul_overflow(Int(0), Int(0), &r), false); + QCOMPARE(r, Int(0)); + QCOMPARE(mul_overflow(Int(1), Int(0), &r), false); + QCOMPARE(r, Int(0)); + QCOMPARE(mul_overflow(Int(0), Int(1), &r), false); + QCOMPARE(r, Int(0)); + QCOMPARE(mul_overflow(max, Int(0), &r), false); + QCOMPARE(r, Int(0)); + QCOMPARE(mul_overflow(Int(0), max, &r), false); + QCOMPARE(r, Int(0)); + + QCOMPARE(mul_overflow(Int(1), Int(1), &r), false); + QCOMPARE(r, Int(1)); + QCOMPARE(mul_overflow(Int(1), max, &r), false); + QCOMPARE(r, max); + QCOMPARE(mul_overflow(max, Int(1), &r), false); + QCOMPARE(r, max); + + // almost max + QCOMPARE(mul_overflow(middle, middle, &r), false); + QCOMPARE(r, Int(max - 2 * middle)); + QCOMPARE(mul_overflow(Int(middle + 1), middle, &r), false); + QCOMPARE(r, Int(middle << (sizeof(Int) * CHAR_BIT / 2))); + QCOMPARE(mul_overflow(middle, Int(middle + 1), &r), false); + QCOMPARE(r, Int(middle << (sizeof(Int) * CHAR_BIT / 2))); + QCOMPARE(mul_overflow(Int(max / 2), Int(2), &r), false); + QCOMPARE(r, Int(max & ~Int(1))); + QCOMPARE(mul_overflow(Int(max / 4), Int(4), &r), false); + QCOMPARE(r, Int(max & ~Int(3))); + + // overflows + QCOMPARE(mul_overflow(max, Int(2), &r), true); + QCOMPARE(mul_overflow(Int(max / 2), Int(3), &r), true); + QCOMPARE(mul_overflow(Int(middle + 1), Int(middle + 1), &r), true); +#endif +} + +template <typename Int, bool enabled = sizeof(Int) <= sizeof(void*)> struct MulOverflowDispatch; +template <typename Int> struct MulOverflowDispatch<Int, true> +{ + void operator()() { mulOverflow_template<Int>(); } +}; +template <typename Int> struct MulOverflowDispatch<Int, false> +{ + void operator()() { QSKIP("This type is too big for this architecture"); } +}; + +void tst_QNumeric::mulOverflow() +{ + QFETCH(int, size); + if (size == 8) + MulOverflowDispatch<quint8>()(); + if (size == 16) + MulOverflowDispatch<quint16>()(); + if (size == 32) + MulOverflowDispatch<quint32>()(); + if (size == 48) + MulOverflowDispatch<ulong>()(); // not really 48-bit + if (size == 64) + MulOverflowDispatch<quint64>()(); +} + QTEST_APPLESS_MAIN(tst_QNumeric) #include "tst_qnumeric.moc" diff --git a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp index 7eaab02ed0..43c644ca43 100644 --- a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp @@ -264,7 +264,9 @@ static int NColorRoles[] = { QPalette::ToolTipText + 1, // Qt_5_2 QPalette::ToolTipText + 1, // Qt_5_3 QPalette::ToolTipText + 1, // Qt_5_4 - 0 // add the correct value for Qt_5_5 here later + QPalette::ToolTipText + 1, // Qt_5_5 + QPalette::ToolTipText + 1, // Qt_5_6 + 0 // add the correct value for Qt_5_7 here later }; // Testing get/set functions diff --git a/tests/auto/corelib/io/qprocess/qprocess.pri b/tests/auto/corelib/io/qprocess/qprocess.pri index 430251fbf1..a43c823846 100644 --- a/tests/auto/corelib/io/qprocess/qprocess.pri +++ b/tests/auto/corelib/io/qprocess/qprocess.pri @@ -4,6 +4,7 @@ SUBPROGRAMS = \ testProcessEcho2 \ testProcessEcho3 \ testProcessEnvironment \ + testProcessHang \ testProcessNormal \ testProcessOutput \ testProcessDeadWhileReading \ diff --git a/tests/auto/corelib/io/qprocess/testProcessHang/main.cpp b/tests/auto/corelib/io/qprocess/testProcessHang/main.cpp new file mode 100644 index 0000000000..e06502f738 --- /dev/null +++ b/tests/auto/corelib/io/qprocess/testProcessHang/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Intel Corporation. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <stdio.h> + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) +# include <windows.h> + +void sleepForever() +{ + ::Sleep(INFINITE); +} +#else +# include <unistd.h> + +void sleepForever() +{ + ::pause(); +} +#endif + +int main() +{ + puts("ready."); + fflush(stdout); + fprintf(stderr, "ready.\n"); + fflush(stderr); + + // sleep forever, simulating a hung application + sleepForever(); + return 0; +} diff --git a/tests/auto/corelib/io/qprocess/testProcessHang/testProcessHang.pro b/tests/auto/corelib/io/qprocess/testProcessHang/testProcessHang.pro new file mode 100644 index 0000000000..e236e05c7d --- /dev/null +++ b/tests/auto/corelib/io/qprocess/testProcessHang/testProcessHang.pro @@ -0,0 +1,4 @@ +SOURCES = main.cpp +CONFIG -= qt app_bundle +CONFIG += console +DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index de4467d897..8c3a96f10d 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Intel Corporation. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -116,7 +117,8 @@ private slots: void setStandardInputFile(); void setStandardOutputFile_data(); void setStandardOutputFile(); - void setStandardOutputFile2(); + void setStandardOutputFileNullDevice(); + void setStandardOutputFileAndWaitForBytesWritten(); void setStandardOutputProcess_data(); void setStandardOutputProcess(); void removeFileWhileProcessIsRunning(); @@ -150,6 +152,9 @@ private slots: void onlyOneStartedSignal(); void finishProcessBeforeReadingDone(); void waitForStartedWithoutStart(); + void startStopStartStop(); + void startStopStartStopBuffers_data(); + void startStopStartStopBuffers(); // keep these at the end, since they use lots of processes and sometimes // caused obscure failures to occur in tests that followed them (esp. on the Mac) @@ -215,7 +220,6 @@ void tst_QProcess::getSetCheck() QCOMPARE(QProcess::ProcessChannel(QProcess::StandardError), obj1.readChannel()); } -//----------------------------------------------------------------------------- void tst_QProcess::constructing() { QProcess process; @@ -277,7 +281,6 @@ void tst_QProcess::simpleStart() QCOMPARE(qvariant_cast<QProcess::ProcessState>(spy.at(2).at(0)), QProcess::NotRunning); } -//----------------------------------------------------------------------------- void tst_QProcess::startWithOpen() { QProcess p; @@ -295,7 +298,6 @@ void tst_QProcess::startWithOpen() QVERIFY(p.waitForFinished(5000)); } -//----------------------------------------------------------------------------- void tst_QProcess::startWithOldOpen() { // similar to the above, but we start with start() actually @@ -314,7 +316,6 @@ void tst_QProcess::startWithOldOpen() QVERIFY(p.waitForFinished(5000)); } -//----------------------------------------------------------------------------- void tst_QProcess::execute() { QCOMPARE(QProcess::execute("testProcessNormal/testProcessNormal", @@ -322,7 +323,6 @@ void tst_QProcess::execute() QCOMPARE(QProcess::execute("nonexistingexe"), -2); } -//----------------------------------------------------------------------------- void tst_QProcess::startDetached() { QProcess proc; @@ -334,7 +334,6 @@ void tst_QProcess::startDetached() QCOMPARE(QProcess::startDetached("nonexistingexe"), false); } -//----------------------------------------------------------------------------- void tst_QProcess::readFromProcess() { int lines = 0; @@ -344,7 +343,6 @@ void tst_QProcess::readFromProcess() } } -//----------------------------------------------------------------------------- void tst_QProcess::crashTest() { qRegisterMetaType<QProcess::ProcessState>("QProcess::ProcessState"); @@ -387,7 +385,6 @@ void tst_QProcess::crashTest() QCOMPARE(qvariant_cast<QProcess::ProcessState>(stateSpy.at(2).at(0)), QProcess::NotRunning); } -//----------------------------------------------------------------------------- void tst_QProcess::crashTest2() { process = new QProcess; @@ -423,7 +420,6 @@ void tst_QProcess::crashTest2() #ifndef Q_OS_WINCE //Reading and writing to a process is not supported on Qt/CE -//----------------------------------------------------------------------------- void tst_QProcess::echoTest_data() { QTest::addColumn<QByteArray>("input"); @@ -438,8 +434,6 @@ void tst_QProcess::echoTest_data() QTest::newRow("10000 bytes") << QByteArray(10000, '@'); } -//----------------------------------------------------------------------------- - void tst_QProcess::echoTest() { QFETCH(QByteArray, input); @@ -484,14 +478,11 @@ void tst_QProcess::echoTest() } #endif -//----------------------------------------------------------------------------- void tst_QProcess::exitLoopSlot() { QTestEventLoop::instance().exitLoop(); } -//----------------------------------------------------------------------------- - #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::echoTest2() @@ -543,7 +534,6 @@ void tst_QProcess::echoTest2() #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) // Reading and writing to a process is not supported on Qt/CE -//----------------------------------------------------------------------------- void tst_QProcess::echoTestGui() { QProcess process; @@ -572,7 +562,6 @@ void tst_QProcess::testSetNamedPipeHandleState() } #endif // !Q_OS_WINCE && Q_OS_WIN -//----------------------------------------------------------------------------- #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) // Batch files are not supported on Windows CE void tst_QProcess::batFiles_data() @@ -601,7 +590,6 @@ void tst_QProcess::batFiles() } #endif // !Q_OS_WINCE && Q_OS_WIN -//----------------------------------------------------------------------------- void tst_QProcess::exitStatus_data() { QTest::addColumn<QStringList>("processList"); @@ -644,7 +632,7 @@ void tst_QProcess::exitStatus() process->deleteLater(); process = 0; } -//----------------------------------------------------------------------------- + #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::loopBackTest() @@ -670,7 +658,6 @@ void tst_QProcess::loopBackTest() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::readTimeoutAndThenCrash() @@ -754,7 +741,6 @@ void tst_QProcess::deadWhileReading() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::restartProcessDeadlock() @@ -784,7 +770,6 @@ void tst_QProcess::restartProcess() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::closeWriteChannel() @@ -812,7 +797,6 @@ void tst_QProcess::closeWriteChannel() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE" void tst_QProcess::closeReadChannel() @@ -844,7 +828,6 @@ void tst_QProcess::closeReadChannel() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::openModes() @@ -889,7 +872,6 @@ void tst_QProcess::openModes() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::emitReadyReadOnlyWhenNewDataArrives() @@ -925,7 +907,6 @@ void tst_QProcess::emitReadyReadOnlyWhenNewDataArrives() } #endif -//----------------------------------------------------------------------------- void tst_QProcess::hardExit() { QProcess proc; @@ -949,7 +930,6 @@ void tst_QProcess::hardExit() QCOMPARE(int(proc.error()), int(QProcess::Crashed)); } -//----------------------------------------------------------------------------- void tst_QProcess::softExit() { QProcess proc; @@ -1059,7 +1039,6 @@ private: QByteArray dataToWrite; }; -//----------------------------------------------------------------------------- void tst_QProcess::softExitInSlots_data() { QTest::addColumn<QString>("appName"); @@ -1069,7 +1048,6 @@ void tst_QProcess::softExitInSlots_data() #endif QTest::newRow("console app") << "testProcessEcho2/testProcessEcho2"; } -//----------------------------------------------------------------------------- void tst_QProcess::softExitInSlots() { @@ -1085,7 +1063,6 @@ void tst_QProcess::softExitInSlots() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::mergedChannels() @@ -1110,7 +1087,6 @@ void tst_QProcess::mergedChannels() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE @@ -1165,7 +1141,6 @@ void tst_QProcess::forwardedChannels() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::atEnd() @@ -1226,7 +1201,6 @@ private: int exitCode; }; -//----------------------------------------------------------------------------- void tst_QProcess::processInAThread() { for (int i = 0; i < 10; ++i) { @@ -1237,7 +1211,6 @@ void tst_QProcess::processInAThread() } } -//----------------------------------------------------------------------------- void tst_QProcess::processesInMultipleThreads() { for (int i = 0; i < 10; ++i) { @@ -1262,7 +1235,6 @@ void tst_QProcess::processesInMultipleThreads() } } -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForFinishedWithTimeout() @@ -1283,7 +1255,6 @@ void tst_QProcess::waitForFinishedWithTimeout() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForReadyReadInAReadyReadSlot() @@ -1312,7 +1283,6 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlot() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForReadyReadInAReadyReadSlotSlot() @@ -1324,7 +1294,6 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlotSlot() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForBytesWrittenInABytesWrittenSlot() @@ -1351,7 +1320,6 @@ void tst_QProcess::waitForBytesWrittenInABytesWrittenSlot() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForBytesWrittenInABytesWrittenSlotSlot() @@ -1361,7 +1329,7 @@ void tst_QProcess::waitForBytesWrittenInABytesWrittenSlotSlot() QTestEventLoop::instance().exitLoop(); } #endif -//----------------------------------------------------------------------------- + void tst_QProcess::spaceArgsTest_data() { QTest::addColumn<QStringList>("args"); @@ -1414,7 +1382,6 @@ static QByteArray startFailMessage(const QString &program, const QProcess &proce return result; } -//----------------------------------------------------------------------------- void tst_QProcess::spaceArgsTest() { QFETCH(QStringList, args); @@ -1487,7 +1454,6 @@ void tst_QProcess::spaceArgsTest() #if defined(Q_OS_WIN) -//----------------------------------------------------------------------------- void tst_QProcess::nativeArguments() { QProcess proc; @@ -1531,7 +1497,6 @@ void tst_QProcess::nativeArguments() #endif -//----------------------------------------------------------------------------- void tst_QProcess::exitCodeTest() { for (int i = 0; i < 255; ++i) { @@ -1548,7 +1513,6 @@ void tst_QProcess::exitCodeTest() } } -//----------------------------------------------------------------------------- void tst_QProcess::failToStart() { #if defined(QPROCESS_USE_SPAWN) && !defined(Q_OS_QNX) @@ -1622,7 +1586,6 @@ void tst_QProcess::failToStart() } } -//----------------------------------------------------------------------------- void tst_QProcess::failToStartWithWait() { #if defined(QPROCESS_USE_SPAWN) && !defined(Q_OS_QNX) @@ -1655,7 +1618,6 @@ void tst_QProcess::failToStartWithWait() } } -//----------------------------------------------------------------------------- void tst_QProcess::failToStartWithEventLoop() { #if defined(QPROCESS_USE_SPAWN) && !defined(Q_OS_QNX) @@ -1729,7 +1691,6 @@ void tst_QProcess::failToStartEmptyArgs() QCOMPARE(process.error(), QProcess::FailedToStart); } -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::removeFileWhileProcessIsRunning() @@ -1748,7 +1709,6 @@ void tst_QProcess::removeFileWhileProcessIsRunning() QVERIFY(process.waitForFinished(5000)); } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // OS doesn't support environment variables void tst_QProcess::setEnvironment_data() @@ -1826,7 +1786,6 @@ void tst_QProcess::setEnvironment() } } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // OS doesn't support environment variables void tst_QProcess::setProcessEnvironment_data() @@ -1867,7 +1826,7 @@ void tst_QProcess::setProcessEnvironment() } } #endif -//----------------------------------------------------------------------------- + void tst_QProcess::systemEnvironment() { #if defined (Q_OS_WINCE) @@ -1883,7 +1842,6 @@ void tst_QProcess::systemEnvironment() #endif } -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::spaceInName() @@ -1896,7 +1854,6 @@ void tst_QProcess::spaceInName() } #endif -//----------------------------------------------------------------------------- void tst_QProcess::lockupsInStartDetached() { // Check that QProcess doesn't cause a lock up at this program's @@ -1910,7 +1867,6 @@ void tst_QProcess::lockupsInStartDetached() QProcess::startDetached("yjhbrty"); } -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::atEnd2() @@ -1929,7 +1885,6 @@ void tst_QProcess::atEnd2() } #endif -//----------------------------------------------------------------------------- void tst_QProcess::waitForReadyReadForNonexistantProcess() { // Start a program that doesn't exist, process events and then try to waitForReadyRead @@ -1961,7 +1916,6 @@ void tst_QProcess::waitForReadyReadForNonexistantProcess() QCOMPARE(finishedSpy2.count(), 0); } -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::setStandardInputFile() @@ -1991,7 +1945,6 @@ void tst_QProcess::setStandardInputFile() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::setStandardOutputFile_data() @@ -2022,23 +1975,6 @@ void tst_QProcess::setStandardOutputFile_data() << true; } -//----------------------------------------------------------------------------- -#ifndef Q_OS_WINCE -void tst_QProcess::setStandardOutputFile2() -{ - static const char testdata[] = "Test data."; - - QProcess process; - process.setStandardOutputFile(QProcess::nullDevice()); - process.start("testProcessEcho2/testProcessEcho2"); - process.write(testdata, sizeof testdata); - QPROCESS_VERIFY(process,waitForFinished()); - QCOMPARE(process.bytesAvailable(), Q_INT64_C(0)); - - QVERIFY(!QFileInfo(QProcess::nullDevice()).isFile()); -} -#endif - void tst_QProcess::setStandardOutputFile() { static const char data[] = "Original data. "; @@ -2087,25 +2023,60 @@ void tst_QProcess::setStandardOutputFile() QCOMPARE(all.size(), expectedsize); } + +void tst_QProcess::setStandardOutputFileNullDevice() +{ + static const char testdata[] = "Test data."; + + QProcess process; + process.setStandardOutputFile(QProcess::nullDevice()); + process.start("testProcessEcho2/testProcessEcho2"); + process.write(testdata, sizeof testdata); + QPROCESS_VERIFY(process,waitForFinished()); + QCOMPARE(process.bytesAvailable(), Q_INT64_C(0)); + + QVERIFY(!QFileInfo(QProcess::nullDevice()).isFile()); +} + +void tst_QProcess::setStandardOutputFileAndWaitForBytesWritten() +{ + static const char testdata[] = "Test data."; + + QFile file("data"); + QProcess process; + process.setStandardOutputFile(file.fileName()); + process.start("testProcessEcho2/testProcessEcho2"); + process.write(testdata, sizeof testdata); + process.waitForBytesWritten(); + QPROCESS_VERIFY(process, waitForFinished()); + + // open the file again and verify the data + QVERIFY(file.open(QIODevice::ReadOnly)); + QByteArray all = file.readAll(); + file.close(); + + QCOMPARE(all, QByteArray::fromRawData(testdata, sizeof testdata - 1)); +} #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::setStandardOutputProcess_data() { QTest::addColumn<bool>("merged"); - QTest::newRow("separate") << false; - QTest::newRow("merged") << true; + QTest::addColumn<bool>("waitForBytesWritten"); + QTest::newRow("separate") << false << false; + QTest::newRow("separate with waitForBytesWritten") << false << true; + QTest::newRow("merged") << true << false; } void tst_QProcess::setStandardOutputProcess() { - QProcess source; QProcess sink; QFETCH(bool, merged); + QFETCH(bool, waitForBytesWritten); source.setReadChannelMode(merged ? QProcess::MergedChannels : QProcess::SeparateChannels); source.setStandardOutputProcess(&sink); @@ -2114,6 +2085,8 @@ void tst_QProcess::setStandardOutputProcess() QByteArray data("Hello, World"); source.write(data); + if (waitForBytesWritten) + source.waitForBytesWritten(); source.closeWriteChannel(); QPROCESS_VERIFY(source, waitForFinished()); QPROCESS_VERIFY(sink, waitForFinished()); @@ -2126,7 +2099,6 @@ void tst_QProcess::setStandardOutputProcess() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::fileWriterProcess() @@ -2154,7 +2126,6 @@ void tst_QProcess::fileWriterProcess() } #endif -//----------------------------------------------------------------------------- void tst_QProcess::detachedWorkingDirectoryAndPid() { qint64 pid; @@ -2198,7 +2169,6 @@ void tst_QProcess::detachedWorkingDirectoryAndPid() QCOMPARE(actualPid, pid); } -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::switchReadChannels() @@ -2248,7 +2218,6 @@ void tst_QProcess::discardUnwantedOutput() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Q_OS_WIN - setWorkingDirectory will chdir before starting the process on unices // Windows CE does not support working directory logic @@ -2270,7 +2239,6 @@ void tst_QProcess::setWorkingDirectory() process = 0; } -//----------------------------------------------------------------------------- void tst_QProcess::setNonExistentWorkingDirectory() { process = new QProcess; @@ -2297,7 +2265,6 @@ void tst_QProcess::setNonExistentWorkingDirectory() } #endif -//----------------------------------------------------------------------------- void tst_QProcess::startFinishStartFinish() { QProcess process; @@ -2316,7 +2283,6 @@ void tst_QProcess::startFinishStartFinish() } } -//----------------------------------------------------------------------------- void tst_QProcess::invalidProgramString_data() { QTest::addColumn<QString>("programString"); @@ -2344,7 +2310,6 @@ void tst_QProcess::invalidProgramString() QVERIFY(!QProcess::startDetached(programString)); } -//----------------------------------------------------------------------------- void tst_QProcess::onlyOneStartedSignal() { qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); @@ -2371,8 +2336,6 @@ void tst_QProcess::onlyOneStartedSignal() QCOMPARE(spyFinished.count(), 1); } -//----------------------------------------------------------------------------- - class BlockOnReadStdOut : public QObject { Q_OBJECT @@ -2404,12 +2367,110 @@ void tst_QProcess::finishProcessBeforeReadingDone() QCOMPARE(lines.last(), QStringLiteral("10239 -this is a number")); } +//----------------------------------------------------------------------------- void tst_QProcess::waitForStartedWithoutStart() { QProcess process; QVERIFY(!process.waitForStarted(5000)); } +//----------------------------------------------------------------------------- +void tst_QProcess::startStopStartStop() +{ + // we actually do start-stop x 3 :-) + QProcess process; + process.start("testProcessNormal/testProcessNormal"); + QVERIFY(process.waitForFinished()); + QCOMPARE(process.exitCode(), 0); + + process.start("testExitCodes/testExitCodes", QStringList() << "1"); + QVERIFY(process.waitForFinished()); + QCOMPARE(process.exitCode(), 1); + + process.start("testProcessNormal/testProcessNormal"); + QVERIFY(process.waitForFinished()); + QCOMPARE(process.exitCode(), 0); +} + +//----------------------------------------------------------------------------- +void tst_QProcess::startStopStartStopBuffers_data() +{ + QTest::addColumn<int>("channelMode1"); + QTest::addColumn<int>("channelMode2"); + + QTest::newRow("separate-separate") << int(QProcess::SeparateChannels) << int(QProcess::SeparateChannels); + QTest::newRow("separate-merged") << int(QProcess::SeparateChannels) << int(QProcess::MergedChannels); + QTest::newRow("merged-separate") << int(QProcess::MergedChannels) << int(QProcess::SeparateChannels); + QTest::newRow("merged-merged") << int(QProcess::MergedChannels) << int(QProcess::MergedChannels); + QTest::newRow("merged-forwarded") << int(QProcess::MergedChannels) << int(QProcess::ForwardedChannels); +} + +void tst_QProcess::startStopStartStopBuffers() +{ + QFETCH(int, channelMode1); + QFETCH(int, channelMode2); + + QProcess process; + process.setProcessChannelMode(QProcess::ProcessChannelMode(channelMode1)); + process.start("testProcessHang/testProcessHang"); + QVERIFY2(process.waitForReadyRead(), process.errorString().toLocal8Bit()); + if (channelMode1 == QProcess::SeparateChannels || channelMode1 == QProcess::ForwardedOutputChannel) { + process.setReadChannel(QProcess::StandardError); + if (process.bytesAvailable() == 0) + QVERIFY(process.waitForReadyRead()); + process.setReadChannel(QProcess::StandardOutput); + } + + // We want to test that the write buffer still has bytes after the child + // exiting. We do that by writing to a child process that never reads. We + // just have to write more data than a pipe can hold, so that even if + // QProcess finds the pipe writable (during waitForFinished() or in the + // QWindowsPipeWriter thread), some data will remain. The worst case I know + // of is Linux, which defaults to 64 kB of buffer. + + process.write(QByteArray(128 * 1024, 'a')); + QVERIFY(process.bytesToWrite() > 0); + process.kill(); + + QVERIFY(process.waitForFinished()); + +#ifndef Q_OS_WIN + // confirm that our buffers are still full + // Note: this doesn't work on Windows because our buffers are drained into + // QWindowsPipeWriter before being sent to the child process. + QVERIFY(process.bytesToWrite() > 0); + QVERIFY(process.bytesAvailable() > 0); // channelMode1 is not ForwardedChannels + if (channelMode1 == QProcess::SeparateChannels || channelMode1 == QProcess::ForwardedOutputChannel) { + process.setReadChannel(QProcess::StandardError); + QVERIFY(process.bytesAvailable() > 0); + process.setReadChannel(QProcess::StandardOutput); + } +#endif + + process.setProcessChannelMode(QProcess::ProcessChannelMode(channelMode2)); + process.start("testProcessEcho2/testProcessEcho2", QIODevice::ReadWrite | QIODevice::Text); + + // the buffers should now be empty + QCOMPARE(process.bytesToWrite(), qint64(0)); + QCOMPARE(process.bytesAvailable(), qint64(0)); + process.setReadChannel(QProcess::StandardError); + QCOMPARE(process.bytesAvailable(), qint64(0)); + process.setReadChannel(QProcess::StandardOutput); + + process.write("line3\n"); + process.closeWriteChannel(); + QVERIFY(process.waitForFinished()); + QCOMPARE(process.exitCode(), 0); + + if (channelMode2 == QProcess::MergedChannels) { + QCOMPARE(process.readAll(), QByteArray("lliinnee33\n\n")); + } else if (channelMode2 != QProcess::ForwardedChannels) { + QCOMPARE(process.readAllStandardOutput(), QByteArray("line3\n")); + if (channelMode2 == QProcess::SeparateChannels) + QCOMPARE(process.readAllStandardError(), QByteArray("line3\n")); + } +} + #endif //QT_NO_PROCESS QTEST_MAIN(tst_QProcess) diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index d7b126e65c..9c2ffa80d4 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -37,6 +37,7 @@ #include <QtCore/QSettings> #include <private/qsettings_p.h> #include <QtCore/QCoreApplication> +#include <QtCore/QDateTime> #include <QtCore/QtGlobal> #include <QtCore/QMetaType> #include <QtCore/QString> @@ -1202,6 +1203,9 @@ void tst_QSettings::testVariantTypes() QList<QVariant> l4; l4 << QVariant(m2) << QVariant(l2) << QVariant(l3); testVal("key13", l4, QVariantList, List); + QDateTime dt = QDateTime::currentDateTime(); + dt.setOffsetFromUtc(3600); + testVal("key14", dt, QDateTime, DateTime); // We store key sequences as strings instead of binary variant blob, for improved // readability in the resulting format. diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp index 9d1e1c9657..7d85377c7a 100644 --- a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -94,6 +94,9 @@ private slots: void testChainedSelectionClear(); void testClearCurrentIndex(); + void QTBUG48402_data(); + void QTBUG48402(); + private: QAbstractItemModel *model; QItemSelectionModel *selection; @@ -2756,5 +2759,96 @@ void tst_QItemSelectionModel::testClearCurrentIndex() QCOMPARE(currentIndexSpy.size(), 2); } +void tst_QItemSelectionModel::QTBUG48402_data() +{ + QTest::addColumn<int>("rows"); + QTest::addColumn<int>("columns"); + + QTest::addColumn<int>("selectTop"); + QTest::addColumn<int>("selectLeft"); + QTest::addColumn<int>("selectBottom"); + QTest::addColumn<int>("selectRight"); + + QTest::addColumn<int>("removeTop"); + QTest::addColumn<int>("removeBottom"); + + QTest::addColumn<int>("deselectTop"); + QTest::addColumn<int>("deselectLeft"); + QTest::addColumn<int>("deselectBottom"); + QTest::addColumn<int>("deselectRight"); + + QTest::newRow("4x4 top intersection") + << 4 << 4 + << 0 << 2 << 1 << 3 + << 1 << 1 + << 1 << 2 << 1 << 3; + + QTest::newRow("4x4 bottom intersection") + << 4 << 4 + << 0 << 2 << 1 << 3 + << 0 << 0 + << 0 << 2 << 0 << 3; + + QTest::newRow("4x4 middle intersection") + << 4 << 4 + << 0 << 2 << 2 << 3 + << 1 << 1 + << 1 << 2 << 1 << 3; + + QTest::newRow("4x4 full inclusion") + << 4 << 4 + << 0 << 2 << 1 << 3 + << 0 << 1 + << 0 << 2 << 1 << 3; +} +class QTBUG48402_helper : public QObject +{ + Q_OBJECT +public: + QModelIndex tl; + QModelIndex br; +public slots: + void changed(const QItemSelection &selected, const QItemSelection &deselected) + { + tl = deselected.first().topLeft(); + br = deselected.first().bottomRight(); + } +}; + +void tst_QItemSelectionModel::QTBUG48402() +{ + QFETCH(int, rows); + QFETCH(int, columns); + QFETCH(int, selectTop); + QFETCH(int, selectLeft); + QFETCH(int, selectBottom); + QFETCH(int, selectRight); + QFETCH(int, removeTop); + QFETCH(int, removeBottom); + QFETCH(int, deselectTop); + QFETCH(int, deselectLeft); + QFETCH(int, deselectBottom); + QFETCH(int, deselectRight); + + MyStandardItemModel model(rows, columns); + QItemSelectionModel selections(&model); + + QModelIndex stl = model.index(selectTop, selectLeft); + QModelIndex sbr = model.index(selectBottom, selectRight); + QModelIndex dtl = model.index(deselectTop, deselectLeft); + QModelIndex dbr = model.index(deselectBottom, deselectRight); + + selections.select(QItemSelection(stl, sbr), QItemSelectionModel::ClearAndSelect); + QTBUG48402_helper helper; + helper.connect(&selections, &QItemSelectionModel::selectionChanged, &helper, &QTBUG48402_helper::changed); + QVERIFY(selections.isSelected(stl)); + QVERIFY(selections.isSelected(sbr)); + QVERIFY(selections.hasSelection()); + + model.removeRows(removeTop, removeBottom - removeTop + 1); + + QCOMPARE(QItemSelectionRange(helper.tl, helper.br), QItemSelectionRange(dtl, dbr)); +} + QTEST_MAIN(tst_QItemSelectionModel) #include "tst_qitemselectionmodel.moc" diff --git a/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp b/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp index f555d2e58e..c8bb4cda6e 100644 --- a/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp +++ b/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp @@ -207,22 +207,11 @@ void tst_QEventLoop::processEvents() QCOMPARE(awakeSpy.count(), 1); // allow any session manager to complete its handshake, so that - // there are no pending events left. + // there are no pending events left. This tests that we are able + // to process all events from the queue, otherwise it will hang. while (eventLoop.processEvents()) ; - // On mac we get application started events at this point, - // so process events one more time just to be sure. - eventLoop.processEvents(); - - // no events to process, QEventLoop::processEvents() should return - // false - aboutToBlockSpy.clear(); - awakeSpy.clear(); - QVERIFY(!eventLoop.processEvents()); - QCOMPARE(aboutToBlockSpy.count(), 0); - QCOMPARE(awakeSpy.count(), 1); - // make sure the test doesn't block forever int timerId = startTimer(100); diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index e64a113c10..d4e83933a9 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -972,7 +972,7 @@ QT_FOR_EACH_STATIC_CORE_POINTER(ADD_METATYPE_TEST_ROW) QTest::newRow("QPair<P,C>") << ::qMetaTypeId<QPair<P,C> >() << false << true << false << false; QTest::newRow("QPair<P,M>") << ::qMetaTypeId<QPair<P,M> >() << true << true << false << false; QTest::newRow("QPair<P,P>") << ::qMetaTypeId<QPair<P,P> >() << true << false << false << false; - QTest::newRow("FlagsDataEnum") << ::qMetaTypeId<FlagsDataEnum>() << false << true << false << true; + QTest::newRow("FlagsDataEnum") << ::qMetaTypeId<FlagsDataEnum>() << true << true << false << true; // invalid ids. QTest::newRow("-1") << -1 << false << false << false << false; @@ -1052,9 +1052,9 @@ void tst_QMetaType::flagsBinaryCompatibility5_0() QFETCH(quint32, id); QFETCH(quint32, flags); - quint32 mask_5_0 = 0x1ff; // Only compare the values that were already defined in 5.0 + quint32 mask_5_0 = 0x1fb; // Only compare the values that were already defined in 5.0 - QCOMPARE(quint32(QMetaType::typeFlags(id)) & mask_5_0, flags); + QCOMPARE(quint32(QMetaType::typeFlags(id)) & mask_5_0, flags & mask_5_0); } void tst_QMetaType::construct_data() diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/qmimedatabase-cache.pro b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/qmimedatabase-cache.pro index 8a5ea47627..e661ff8412 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/qmimedatabase-cache.pro +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/qmimedatabase-cache.pro @@ -10,3 +10,5 @@ RESOURCES += $$QT_SOURCE_TREE/src/corelib/mimetypes/mimetypes.qrc RESOURCES += ../testdata.qrc *-g++*:QMAKE_CXXFLAGS += -W -Wall -Wextra -Wshadow -Wno-long-long -Wnon-virtual-dtor + +unix:!mac:!qnx: DEFINES += USE_XDG_DATA_DIRS diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp index 7f78312582..2113672821 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp @@ -39,7 +39,7 @@ #include "../tst_qmimedatabase.cpp" -void tst_QMimeDatabase::init() +void tst_QMimeDatabase::initTestCaseInternal() { #ifdef QT_NO_PROCESS QSKIP("No qprocess support", SkipAll); diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/qmimedatabase-xml.pro b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/qmimedatabase-xml.pro index 13c9c7c3ba..160f359116 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/qmimedatabase-xml.pro +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/qmimedatabase-xml.pro @@ -11,3 +11,5 @@ RESOURCES += $$QT_SOURCE_TREE/src/corelib/mimetypes/mimetypes.qrc RESOURCES += ../testdata.qrc *-g++*:QMAKE_CXXFLAGS += -W -Wall -Wextra -Wshadow -Wno-long-long -Wnon-virtual-dtor + +unix:!mac:!qnx: DEFINES += USE_XDG_DATA_DIRS diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp index e24b1b1249..c4a1dab697 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp @@ -33,7 +33,7 @@ #include "../tst_qmimedatabase.h" -void tst_QMimeDatabase::init() +void tst_QMimeDatabase::initTestCaseInternal() { qputenv("QT_NO_MIME_CACHE", "1"); } diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/testdata.qrc b/tests/auto/corelib/mimetypes/qmimedatabase/testdata.qrc index 48d3204473..4654a61660 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/testdata.qrc +++ b/tests/auto/corelib/mimetypes/qmimedatabase/testdata.qrc @@ -2,6 +2,7 @@ <qresource prefix="/qt-project.org/qmime"> <file alias="yast2-metapackage-handler-mimetypes.xml">yast2-metapackage-handler-mimetypes.xml</file> <file alias="qml-again.xml">qml-again.xml</file> + <file alias="text-x-objcsrc.xml">text-x-objcsrc.xml</file> <file alias="test.qml">test.qml</file> </qresource> </RCC> diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/text-x-objcsrc.xml b/tests/auto/corelib/mimetypes/qmimedatabase/text-x-objcsrc.xml new file mode 100644 index 0000000000..e262dc634d --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/text-x-objcsrc.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> + <mime-type type="text/x-objcsrc"> + <comment>Objective-C source code</comment> + <glob-deleteall/> + </mime-type> +</mime-info> diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp index 12abaf47c5..dd04849f87 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp @@ -38,6 +38,8 @@ #include <QtCore/QElapsedTimer> #include <QtCore/QFile> #include <QtCore/QFileInfo> +#include <QtCore/QStandardPaths> +#include <QtCore/QTemporaryDir> #include <QtCore/QTextStream> #include <QFutureSynchronizer> #include <QtConcurrent/QtConcurrentRun> @@ -46,6 +48,7 @@ static const char yastFileName[] ="yast2-metapackage-handler-mimetypes.xml"; static const char qmlAgainFileName[] ="qml-again.xml"; +static const char textXObjCSrcFileName[] ="text-x-objcsrc.xml"; #define RESOURCE_PREFIX ":/qt-project.org/qmime/" void initializeLang() @@ -117,30 +120,31 @@ tst_QMimeDatabase::tst_QMimeDatabase() void tst_QMimeDatabase::initTestCase() { + QStandardPaths::setTestModeEnabled(true); + m_localMimeDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/mime"; + if (QDir(m_localMimeDir).exists()) { + QVERIFY2(QDir(m_localMimeDir).removeRecursively(), qPrintable(m_localMimeDir + ": " + qt_error_string())); + } + QString errorMessage; + +#ifdef USE_XDG_DATA_DIRS + // Create a temporary "global" XDG data dir for later use + // It will initially contain a copy of freedesktop.org.xml QVERIFY2(m_temporaryDir.isValid(), ("Could not create temporary subdir: " + m_temporaryDir.errorString()).toUtf8()); - - // Create a "global" and a "local" XDG data dir, right here. - // The local dir will be empty initially, while the global dir will contain a copy of freedesktop.org.xml - const QDir here = QDir(m_temporaryDir.path()); - m_globalXdgDir = m_temporaryDir.path() + QStringLiteral("/global"); - m_localXdgDir = m_temporaryDir.path() + QStringLiteral("/local"); - const QString globalPackageDir = m_globalXdgDir + QStringLiteral("/mime/packages"); - QVERIFY(here.mkpath(globalPackageDir) && here.mkpath(m_localXdgDir)); + QVERIFY(here.mkpath(globalPackageDir)); qputenv("XDG_DATA_DIRS", QFile::encodeName(m_globalXdgDir)); - qputenv("XDG_DATA_HOME", QFile::encodeName(m_localXdgDir)); - qDebug() << "\nLocal XDG_DATA_HOME: " << m_localXdgDir - << "\nGlobal XDG_DATA_DIRS: " << m_globalXdgDir; + qDebug() << "\nGlobal XDG_DATA_DIRS: " << m_globalXdgDir; const QString freeDesktopXml = QStringLiteral("freedesktop.org.xml"); const QString xmlFileName = QLatin1String(RESOURCE_PREFIX) + freeDesktopXml; const QString xmlTargetFileName = globalPackageDir + QLatin1Char('/') + freeDesktopXml; - QString errorMessage; QVERIFY2(copyResourceFile(xmlFileName, xmlTargetFileName, &errorMessage), qPrintable(errorMessage)); +#endif m_testSuite = QFINDTESTDATA("testfiles"); if (m_testSuite.isEmpty()) @@ -151,8 +155,22 @@ void tst_QMimeDatabase::initTestCase() QVERIFY2(QFile::exists(m_yastMimeTypes), qPrintable(errorMessage.arg(yastFileName))); m_qmlAgainFileName = QLatin1String(RESOURCE_PREFIX) + qmlAgainFileName; QVERIFY2(QFile::exists(m_qmlAgainFileName), qPrintable(errorMessage.arg(qmlAgainFileName))); + m_textXObjCSrcFileName = QLatin1String(RESOURCE_PREFIX) + textXObjCSrcFileName; + QVERIFY2(QFile::exists(m_textXObjCSrcFileName), qPrintable(errorMessage.arg(textXObjCSrcFileName))); + + initTestCaseInternal(); + m_isUsingCacheProvider = !qEnvironmentVariableIsSet("QT_NO_MIME_CACHE"); +} - init(); +void tst_QMimeDatabase::init() +{ + // clean up local data from previous runs + QDir(m_localMimeDir).removeRecursively(); +} + +void tst_QMimeDatabase::cleanupTestCase() +{ + QDir(m_localMimeDir).removeRecursively(); } void tst_QMimeDatabase::mimeTypeForName() @@ -853,6 +871,10 @@ QT_END_NAMESPACE void tst_QMimeDatabase::installNewGlobalMimeType() { +#if !defined(USE_XDG_DATA_DIRS) + QSKIP("This test requires XDG_DATA_DIRS"); +#endif + #ifdef QT_NO_PROCESS QSKIP("This test requires QProcess support"); #else @@ -867,6 +889,8 @@ void tst_QMimeDatabase::installNewGlobalMimeType() QFile::remove(destFile); const QString destQmlFile = destDir + QLatin1String(qmlAgainFileName); QFile::remove(destQmlFile); + const QString destTextXObjCSrcFile = destDir + QLatin1String(textXObjCSrcFileName); + QFile::remove(destTextXObjCSrcFile); //qDebug() << destFile; if (!QFileInfo(destDir).isDir()) @@ -874,11 +898,12 @@ void tst_QMimeDatabase::installNewGlobalMimeType() QString errorMessage; QVERIFY2(copyResourceFile(m_yastMimeTypes, destFile, &errorMessage), qPrintable(errorMessage)); QVERIFY2(copyResourceFile(m_qmlAgainFileName, destQmlFile, &errorMessage), qPrintable(errorMessage)); - if (!waitAndRunUpdateMimeDatabase(mimeDir)) + QVERIFY2(copyResourceFile(m_textXObjCSrcFileName, destTextXObjCSrcFile, &errorMessage), qPrintable(errorMessage)); + if (m_isUsingCacheProvider && !waitAndRunUpdateMimeDatabase(mimeDir)) QSKIP("shared-mime-info not found, skipping mime.cache test"); QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(), - QString::fromLatin1("text/x-suse-ymu")); + QString::fromLatin1("text/x-SuSE-ymu")); QVERIFY(db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); checkHasMimeType("text/x-suse-ymp"); @@ -890,10 +915,18 @@ void tst_QMimeDatabase::installNewGlobalMimeType() QCOMPARE(db.mimeTypeForFile(qmlTestFile).name(), QString::fromLatin1("text/x-qml")); + // ensure we can access the empty glob list + { + QMimeType objcsrc = db.mimeTypeForName(QStringLiteral("text/x-objcsrc")); + QVERIFY(objcsrc.isValid()); + qDebug() << objcsrc.globPatterns(); + } + // Now test removing it again - QFile::remove(destFile); - QFile::remove(destQmlFile); - if (!waitAndRunUpdateMimeDatabase(mimeDir)) + QVERIFY(QFile::remove(destFile)); + QVERIFY(QFile::remove(destQmlFile)); + QVERIFY(QFile::remove(destTextXObjCSrcFile)); + if (m_isUsingCacheProvider && !waitAndRunUpdateMimeDatabase(mimeDir)) QSKIP("shared-mime-info not found, skipping mime.cache test"); QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(), QString::fromLatin1("application/octet-stream")); @@ -911,8 +944,7 @@ void tst_QMimeDatabase::installNewLocalMimeType() QMimeDatabase db; QVERIFY(!db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); - const QString mimeDir = m_localXdgDir + QLatin1String("/mime"); - const QString destDir = mimeDir + QLatin1String("/packages/"); + const QString destDir = m_localMimeDir + QLatin1String("/packages/"); QDir().mkpath(destDir); const QString destFile = destDir + QLatin1String(yastFileName); QFile::remove(destFile); @@ -921,15 +953,16 @@ void tst_QMimeDatabase::installNewLocalMimeType() QString errorMessage; QVERIFY2(copyResourceFile(m_yastMimeTypes, destFile, &errorMessage), qPrintable(errorMessage)); QVERIFY2(copyResourceFile(m_qmlAgainFileName, destQmlFile, &errorMessage), qPrintable(errorMessage)); - if (!runUpdateMimeDatabase(mimeDir)) { + if (m_isUsingCacheProvider && !runUpdateMimeDatabase(m_localMimeDir)) { const QString skipWarning = QStringLiteral("shared-mime-info not found, skipping mime.cache test (") - + QDir::toNativeSeparators(mimeDir) + QLatin1Char(')'); + + QDir::toNativeSeparators(m_localMimeDir) + QLatin1Char(')'); QSKIP(qPrintable(skipWarning)); } QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(), - QString::fromLatin1("text/x-suse-ymu")); + QString::fromLatin1("text/x-SuSE-ymu")); QVERIFY(db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); + QCOMPARE(db.mimeTypeForName(QLatin1String("text/x-SuSE-ymu")).comment(), QString("URL of a YaST Meta Package")); checkHasMimeType("text/x-suse-ymp"); // Test that a double-definition of a mimetype doesn't lead to sniffing ("conflicting globs"). @@ -941,16 +974,16 @@ void tst_QMimeDatabase::installNewLocalMimeType() QString::fromLatin1("text/x-qml")); // Now test removing the local mimetypes again (note, this leaves a mostly-empty mime.cache file) - QFile::remove(destFile); - QFile::remove(destQmlFile); - if (!waitAndRunUpdateMimeDatabase(mimeDir)) + QVERIFY(QFile::remove(destFile)); + QVERIFY(QFile::remove(destQmlFile)); + if (m_isUsingCacheProvider && !waitAndRunUpdateMimeDatabase(m_localMimeDir)) QSKIP("shared-mime-info not found, skipping mime.cache test"); QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(), QString::fromLatin1("application/octet-stream")); QVERIFY(!db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); // And now the user goes wild and uses rm -rf - QFile::remove(mimeDir + QString::fromLatin1("/mime.cache")); + QFile::remove(m_localMimeDir + QString::fromLatin1("/mime.cache")); QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(), QString::fromLatin1("application/octet-stream")); QVERIFY(!db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h index 26def8f290..f12beafe86 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h @@ -46,6 +46,8 @@ public: private slots: void initTestCase(); + void init(); + void cleanupTestCase(); void mimeTypeForName(); void mimeTypeForFileName_data(); @@ -86,14 +88,16 @@ private slots: void installNewLocalMimeType(); private: - void init(); // test-specific + void initTestCaseInternal(); // test-specific QString m_globalXdgDir; - QString m_localXdgDir; + QString m_localMimeDir; QString m_yastMimeTypes; QString m_qmlAgainFileName; + QString m_textXObjCSrcFileName; QTemporaryDir m_temporaryDir; QString m_testSuite; + bool m_isUsingCacheProvider; }; #endif // TST_QMIMEDATABASE_H diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/yast2-metapackage-handler-mimetypes.xml b/tests/auto/corelib/mimetypes/qmimedatabase/yast2-metapackage-handler-mimetypes.xml index ef3035ef4a..bb352b7ba2 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/yast2-metapackage-handler-mimetypes.xml +++ b/tests/auto/corelib/mimetypes/qmimedatabase/yast2-metapackage-handler-mimetypes.xml @@ -7,7 +7,7 @@ <glob pattern="*.ymp"/> </mime-type> - <mime-type type="text/x-suse-ymu"> + <mime-type type="text/x-SuSE-ymu"> <comment>URL of a YaST Meta Package</comment> <glob pattern="*.ymu"/> </mime-type> diff --git a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp index 5e9b7370b9..ed7b446172 100644 --- a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp +++ b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp @@ -240,7 +240,7 @@ void tst_QThreadStorage::adoptedThreads() QTestEventLoop::instance().enterLoop(2); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(Pointer::count, c); + QTRY_COMPARE(Pointer::count, c); } QBasicAtomicInt cleanupOrder = Q_BASIC_ATOMIC_INITIALIZER(0); diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp index 6961426f59..bde9433a24 100644 --- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp +++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp @@ -50,6 +50,8 @@ private Q_SLOTS: void qthash(); void range(); void rangeCommutative(); + + void setGlobalQHashSeed(); }; void tst_QHashFunctions::qhash() @@ -207,5 +209,21 @@ void tst_QHashFunctions::rangeCommutative() (void)qHashRangeCommutative(hashables, hashables + numHashables); } +void tst_QHashFunctions::setGlobalQHashSeed() +{ + // Setter works as advertised + qSetGlobalQHashSeed(0x10101010); + QCOMPARE(qGlobalQHashSeed(), 0x10101010); + + // Creating a new QHash doesn't reset the seed + QHash<QString, int> someHash; + someHash.insert("foo", 42); + QCOMPARE(qGlobalQHashSeed(), 0x10101010); + + // Reset works as advertised + qSetGlobalQHashSeed(-1); + QVERIFY(qGlobalQHashSeed() != -1); +} + QTEST_APPLESS_MAIN(tst_QHashFunctions) #include "tst_qhashfunctions.moc" diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index 6b7614b7b9..8ddd4979b6 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>. -** Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> +** Copyright (C) 2015 Giuseppe D'Angelo <dangelog@gmail.com>. +** Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -306,19 +306,6 @@ static void testMatch(const QRegularExpression ®exp, matchType, matchOptions, result); - - // offset <= 0 tested above; now also test stringrefs not spanning over - // the entire subject. Note that the offset can be negative, hence the above - // tests can't be merged into this one - for (int i = 1; i <= offset; ++i) { - testMatchImpl<QREMatch>(regexp, - matchingMethodForStringRef, - QStringRef(&subject, i, subject.length() - i), - offset - i, - matchType, - matchOptions, - result); - } } typedef QRegularExpressionMatch (QRegularExpression::*QREMatchStringPMF)(const QString &, int, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const; @@ -737,6 +724,18 @@ void tst_QRegularExpression::normalMatch_data() // *** m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << "bcd"; + QTest::newRow("match12") + << QRegularExpression("\\Bbcd\\B") + << "abcde" + << 1 + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + // *** + + m.clear(); m.isValid = true; QTest::newRow("nomatch01") << QRegularExpression("\\d+") << "a string" @@ -1710,3 +1709,360 @@ void tst_QRegularExpression::JOptionUsage() re.optimize(); QCOMPARE(re.isValid(), isValid); } + +void tst_QRegularExpression::QStringAndQStringRefEquivalence() +{ + const QString subject = QStringLiteral("Mississippi"); + { + const QRegularExpression re("\\Biss\\B"); + QVERIFY(re.isValid()); + { + const QRegularExpressionMatch match = re.match(subject); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 1); + QCOMPARE(match.capturedEnd(), 4); + } + { + const QRegularExpressionMatch match = re.match(QStringRef(&subject)); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 1); + QCOMPARE(match.capturedEnd(), 4); + } + { + const QRegularExpressionMatch match = re.match(subject, 1); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 1); + QCOMPARE(match.capturedEnd(), 4); + } + { + const QRegularExpressionMatch match = re.match(QStringRef(&subject), 1); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 1); + QCOMPARE(match.capturedEnd(), 4); + } + { + const QRegularExpressionMatch match = re.match(subject.mid(1)); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 3); + QCOMPARE(match.capturedEnd(), 6); + } + { + const QRegularExpressionMatch match = re.match(subject.midRef(1)); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 3); + QCOMPARE(match.capturedEnd(), 6); + } + { + const QRegularExpressionMatch match = re.match(subject.mid(1), 1); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 3); + QCOMPARE(match.capturedEnd(), 6); + } + { + const QRegularExpressionMatch match = re.match(subject.midRef(1), 1); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 3); + QCOMPARE(match.capturedEnd(), 6); + } + { + const QRegularExpressionMatch match = re.match(subject, 4); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 4); + QCOMPARE(match.capturedEnd(), 7); + } + { + const QRegularExpressionMatch match = re.match(QStringRef(&subject), 4); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 4); + QCOMPARE(match.capturedEnd(), 7); + } + { + const QRegularExpressionMatch match = re.match(subject.mid(4)); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(!match.hasMatch()); + } + { + const QRegularExpressionMatch match = re.match(subject.midRef(4)); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(!match.hasMatch()); + } + + { + QRegularExpressionMatchIterator i = re.globalMatch(subject); + QVERIFY(i.isValid()); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match1 = i.next(); + consistencyCheck(match1); + QVERIFY(match1.isValid()); + QVERIFY(match1.hasMatch()); + QCOMPARE(match1.captured(), QStringLiteral("iss")); + QCOMPARE(match1.capturedStart(), 1); + QCOMPARE(match1.capturedEnd(), 4); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match2 = i.next(); + consistencyCheck(match2); + QVERIFY(match2.isValid()); + QVERIFY(match2.hasMatch()); + QCOMPARE(match2.captured(), QStringLiteral("iss")); + QCOMPARE(match2.capturedStart(), 4); + QCOMPARE(match2.capturedEnd(), 7); + + QVERIFY(!i.hasNext()); + } + { + QRegularExpressionMatchIterator i = re.globalMatch(QStringRef(&subject)); + QVERIFY(i.isValid()); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match1 = i.next(); + consistencyCheck(match1); + QVERIFY(match1.isValid()); + QVERIFY(match1.hasMatch()); + QCOMPARE(match1.captured(), QStringLiteral("iss")); + QCOMPARE(match1.capturedStart(), 1); + QCOMPARE(match1.capturedEnd(), 4); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match2 = i.next(); + consistencyCheck(match2); + QVERIFY(match2.isValid()); + QVERIFY(match2.hasMatch()); + QCOMPARE(match2.captured(), QStringLiteral("iss")); + QCOMPARE(match2.capturedStart(), 4); + QCOMPARE(match2.capturedEnd(), 7); + + QVERIFY(!i.hasNext()); + } + { + QRegularExpressionMatchIterator i = re.globalMatch(subject, 1); + QVERIFY(i.isValid()); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match1 = i.next(); + consistencyCheck(match1); + QVERIFY(match1.isValid()); + QVERIFY(match1.hasMatch()); + QCOMPARE(match1.captured(), QStringLiteral("iss")); + QCOMPARE(match1.capturedStart(), 1); + QCOMPARE(match1.capturedEnd(), 4); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match2 = i.next(); + consistencyCheck(match2); + QVERIFY(match2.isValid()); + QVERIFY(match2.hasMatch()); + QCOMPARE(match2.captured(), QStringLiteral("iss")); + QCOMPARE(match2.capturedStart(), 4); + QCOMPARE(match2.capturedEnd(), 7); + + QVERIFY(!i.hasNext()); + } + { + QRegularExpressionMatchIterator i = re.globalMatch(QStringRef(&subject), 1); + QVERIFY(i.isValid()); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match1 = i.next(); + consistencyCheck(match1); + QVERIFY(match1.isValid()); + QVERIFY(match1.hasMatch()); + QCOMPARE(match1.captured(), QStringLiteral("iss")); + QCOMPARE(match1.capturedStart(), 1); + QCOMPARE(match1.capturedEnd(), 4); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match2 = i.next(); + consistencyCheck(match2); + QVERIFY(match2.isValid()); + QVERIFY(match2.hasMatch()); + QCOMPARE(match2.captured(), QStringLiteral("iss")); + QCOMPARE(match2.capturedStart(), 4); + QCOMPARE(match2.capturedEnd(), 7); + + QVERIFY(!i.hasNext()); + } + { + QRegularExpressionMatchIterator i = re.globalMatch(subject.mid(1)); + QVERIFY(i.isValid()); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match = i.next(); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 3); + QCOMPARE(match.capturedEnd(), 6); + + QVERIFY(!i.hasNext()); + } + { + QRegularExpressionMatchIterator i = re.globalMatch(subject.midRef(1)); + QVERIFY(i.isValid()); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match = i.next(); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 3); + QCOMPARE(match.capturedEnd(), 6); + + QVERIFY(!i.hasNext()); + } + { + QRegularExpressionMatchIterator i = re.globalMatch(subject.mid(1), 1); + QVERIFY(i.isValid()); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match = i.next(); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 3); + QCOMPARE(match.capturedEnd(), 6); + + QVERIFY(!i.hasNext()); + } + { + QRegularExpressionMatchIterator i = re.globalMatch(subject.midRef(1), 1); + QVERIFY(i.isValid()); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match = i.next(); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 3); + QCOMPARE(match.capturedEnd(), 6); + + QVERIFY(!i.hasNext()); + } + { + QRegularExpressionMatchIterator i = re.globalMatch(subject.mid(1), 1); + QVERIFY(i.isValid()); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match = i.next(); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 3); + QCOMPARE(match.capturedEnd(), 6); + + QVERIFY(!i.hasNext()); + } + { + QRegularExpressionMatchIterator i = re.globalMatch(subject.midRef(1), 1); + QVERIFY(i.isValid()); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match = i.next(); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 3); + QCOMPARE(match.capturedEnd(), 6); + + QVERIFY(!i.hasNext()); + } + + { + QRegularExpressionMatchIterator i = re.globalMatch(subject, 4); + QVERIFY(i.isValid()); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match = i.next(); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 4); + QCOMPARE(match.capturedEnd(), 7); + + QVERIFY(!i.hasNext()); + } + { + QRegularExpressionMatchIterator i = re.globalMatch(QStringRef(&subject), 4); + QVERIFY(i.isValid()); + + consistencyCheck(i); + QVERIFY(i.hasNext()); + const QRegularExpressionMatch match = i.next(); + consistencyCheck(match); + QVERIFY(match.isValid()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(), QStringLiteral("iss")); + QCOMPARE(match.capturedStart(), 4); + QCOMPARE(match.capturedEnd(), 7); + + QVERIFY(!i.hasNext()); + } + { + QRegularExpressionMatchIterator i = re.globalMatch(subject.mid(4)); + consistencyCheck(i); + QVERIFY(i.isValid()); + QVERIFY(!i.hasNext()); + } + { + QRegularExpressionMatchIterator i = re.globalMatch(subject.midRef(4)); + consistencyCheck(i); + QVERIFY(i.isValid()); + QVERIFY(!i.hasNext()); + } + } +} diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h index 578a4129ec..aed262d15d 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h @@ -72,6 +72,7 @@ private slots: void regularExpressionMatch(); void JOptionUsage_data(); void JOptionUsage(); + void QStringAndQStringRefEquivalence(); private: void provideRegularExpressions(); diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp index ef0ebabd66..134d257d64 100644 --- a/tests/auto/corelib/tools/qset/tst_qset.cpp +++ b/tests/auto/corelib/tools/qset/tst_qset.cpp @@ -970,24 +970,6 @@ void tst_QSet::initializerList() #endif } -QT_BEGIN_NAMESPACE -extern Q_CORE_EXPORT QBasicAtomicInt qt_qhash_seed; // from qhash.cpp -QT_END_NAMESPACE - -class QtQHashSeedSaver { - int oldSeed, newSeed; -public: - explicit QtQHashSeedSaver(int seed) - : oldSeed(qt_qhash_seed.fetchAndStoreRelaxed(seed)), - newSeed(seed) - {} - ~QtQHashSeedSaver() - { - // only restore when no-one else changed the seed in the meantime: - qt_qhash_seed.testAndSetRelaxed(newSeed, oldSeed); - } -}; - void tst_QSet::qhash() { // @@ -995,14 +977,14 @@ void tst_QSet::qhash() // { // create some deterministic initial state: - const QtQHashSeedSaver seed1(0); + qSetGlobalQHashSeed(0); QSet<int> s1; s1.reserve(4); s1 << 400 << 300 << 200 << 100; // also change the seed: - const QtQHashSeedSaver seed2(0x10101010); + qSetGlobalQHashSeed(0x10101010); QSet<int> s2; s2.reserve(100); // provoke different bucket counts @@ -1049,7 +1031,7 @@ void tst_QSet::intersects() s1 << 200; QVERIFY(s1.intersects(s2)); - const QtQHashSeedSaver seedSaver(0x10101010); + qSetGlobalQHashSeed(0x10101010); QSet<int> s3; s3 << 500; QVERIFY(!s1.intersects(s3)); diff --git a/tests/auto/corelib/tools/qtime/tst_qtime.cpp b/tests/auto/corelib/tools/qtime/tst_qtime.cpp index 9a9101b7e9..213b817c3d 100644 --- a/tests/auto/corelib/tools/qtime/tst_qtime.cpp +++ b/tests/auto/corelib/tools/qtime/tst_qtime.cpp @@ -84,6 +84,8 @@ void tst_QTime::addSecs_data() QTest::newRow("Data0") << QTime(0,0,0) << 200 << QTime(0,3,20); QTest::newRow("Data1") << QTime(0,0,0) << 20 << QTime(0,0,20); + QTest::newRow("overflow") << QTime(0,0,0) << (INT_MAX / 1000 + 1) + << QTime(0,0,0).addSecs((INT_MAX / 1000 + 1) % 86400); } void tst_QTime::addSecs() diff --git a/tests/auto/dbus/dbus.pro b/tests/auto/dbus/dbus.pro index cd845d7043..bd1fef5193 100644 --- a/tests/auto/dbus/dbus.pro +++ b/tests/auto/dbus/dbus.pro @@ -3,6 +3,7 @@ SUBDIRS=\ qdbusabstractadaptor \ qdbusabstractinterface \ qdbusconnection \ + qdbusconnection_no_app \ qdbusconnection_no_bus \ qdbuscontext \ qdbusinterface \ @@ -16,7 +17,7 @@ SUBDIRS=\ qdbusservicewatcher \ qdbustype \ qdbusthreading \ - qdbusxmlparser \ + qdbusxmlparser !contains(QT_CONFIG,private_tests): SUBDIRS -= \ qdbusmarshall \ diff --git a/tests/auto/dbus/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp b/tests/auto/dbus/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp index 22984743e7..7a73dddfe3 100644 --- a/tests/auto/dbus/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp +++ b/tests/auto/dbus/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp @@ -346,7 +346,7 @@ void syncPeer() // wait for the sync signal with the right ID QEventLoop loop; QDBusConnection con("peer"); - con.connect(serviceName, objectPath, interfaceName, "syncReceived", + con.connect(QString(), objectPath, interfaceName, "syncReceived", QStringList() << reqId, QString(), &loop, SLOT(quit())); QDBusMessage req = QDBusMessage::createMethodCall(serviceName, objectPath, interfaceName, "requestSync"); diff --git a/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp b/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp index d862e4321c..2db687e21b 100644 --- a/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp +++ b/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp @@ -1012,8 +1012,14 @@ void tst_QDBusAbstractInterface::followSignal() QVERIFY(!con.interface()->isServiceRegistered(serviceToFollow)); Pinger control = getPinger(""); - // we need to connect the signal somewhere in order for D-Bus to enable the rules - QTestEventLoop::instance().connect(p.data(), SIGNAL(voidSignal()), SLOT(exitLoop())); + // connect our test signal + // FRAGILE CODE AHEAD: + // Connection order is important: we connect the control first because that + // needs to be delivered last, to ensure that we don't exitLoop() before + // the signal delivery to QSignalSpy is posted to the current thread. That + // happens because QDBusConnectionPrivate runs in a separate thread and + // uses a QMultiHash and insertMulti prepends to the list of items with the + // same key. QTestEventLoop::instance().connect(control.data(), SIGNAL(voidSignal()), SLOT(exitLoop())); QSignalSpy s(p.data(), SIGNAL(voidSignal())); diff --git a/tests/auto/dbus/qdbusconnection/qdbusconnection.pro b/tests/auto/dbus/qdbusconnection/qdbusconnection.pro index 8c729aaf33..3fcf3e076b 100644 --- a/tests/auto/dbus/qdbusconnection/qdbusconnection.pro +++ b/tests/auto/dbus/qdbusconnection/qdbusconnection.pro @@ -2,3 +2,4 @@ CONFIG += testcase TARGET = tst_qdbusconnection QT = core dbus testlib SOURCES += tst_qdbusconnection.cpp +HEADERS += tst_qdbusconnection.h diff --git a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp index a3de878ffb..7cd8c875ec 100644 --- a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp +++ b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Intel Corporation. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -30,34 +31,15 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + +#include "tst_qdbusconnection.h" + #include <qcoreapplication.h> #include <qdebug.h> #include <QtTest/QtTest> #include <QtDBus/QtDBus> -class BaseObject: public QObject -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "local.BaseObject") -public: - BaseObject(QObject *parent = 0) : QObject(parent) { } -public slots: - void anotherMethod() { } -}; - -class MyObject: public BaseObject -{ - Q_OBJECT -public slots: - void method(const QDBusMessage &msg); - -public: - static QString path; - int callCount; - MyObject(QObject *parent = 0) : BaseObject(parent), callCount(0) {} -}; - void MyObject::method(const QDBusMessage &msg) { path = msg.path(); @@ -65,19 +47,6 @@ void MyObject::method(const QDBusMessage &msg) //qDebug() << msg; } -class MyObjectWithoutInterface: public QObject -{ - Q_OBJECT -public slots: - void method(const QDBusMessage &msg); - -public: - static QString path; - static QString interface; - int callCount; - MyObjectWithoutInterface(QObject *parent = 0) : QObject(parent), callCount(0) {} -}; - void MyObjectWithoutInterface::method(const QDBusMessage &msg) { path = msg.path(); @@ -86,72 +55,6 @@ void MyObjectWithoutInterface::method(const QDBusMessage &msg) //qDebug() << msg; } -class tst_QDBusConnection: public QObject -{ - Q_OBJECT - - int signalsReceived; -public slots: - void oneSlot() { ++signalsReceived; } - void exitLoop() { ++signalsReceived; QTestEventLoop::instance().exitLoop(); } - void secondCallWithCallback(); - -private slots: - void noConnection(); - void connectToBus(); - void connectToPeer(); - void connect(); - void send(); - void sendWithGui(); - void sendAsync(); - void sendSignal(); - void sendSignalToName(); - void sendSignalToOtherName(); - - void registerObject_data(); - void registerObject(); - void registerObjectWithInterface_data(); - void registerObjectWithInterface(); - void registerObjectPeer_data(); - void registerObjectPeer(); - void registerObject2(); - void registerObjectPeer2(); - - void registerQObjectChildren(); - void registerQObjectChildrenPeer(); - - void callSelf(); - void callSelfByAnotherName_data(); - void callSelfByAnotherName(); - void multipleInterfacesInQObject(); - - void slotsWithLessParameters(); - void nestedCallWithCallback(); - - void serviceRegistrationRaceCondition(); - - void registerVirtualObject(); - void callVirtualObject(); - void callVirtualObjectLocal(); - -public: - QString serviceName() const { return "org.qtproject.Qt.Autotests.QDBusConnection"; } - bool callMethod(const QDBusConnection &conn, const QString &path); - bool callMethod(const QDBusConnection &conn, const QString &path, const QString &interface); - bool callMethodPeer(const QDBusConnection &conn, const QString &path); -}; - -class QDBusSpy: public QObject -{ - Q_OBJECT -public slots: - void handlePing(const QString &str) { args.clear(); args << str; } - void asyncReply(const QDBusMessage &msg) { args = msg.arguments(); } - -public: - QList<QVariant> args; -}; - void tst_QDBusConnection::noConnection() { QDBusConnection con = QDBusConnection::connectToBus("unix:path=/dev/null", "testconnection"); @@ -187,12 +90,13 @@ void tst_QDBusConnection::sendSignal() msg << QLatin1String("ping"); QVERIFY(con.send(msg)); - - QTest::qWait(1000); } void tst_QDBusConnection::sendSignalToName() { + if (!QCoreApplication::instance()) + QSKIP("Test requires a QCoreApplication"); // because of the qWait() + QDBusSpy spy; QDBusConnection con = QDBusConnection::sessionBus(); @@ -215,6 +119,9 @@ void tst_QDBusConnection::sendSignalToName() void tst_QDBusConnection::sendSignalToOtherName() { + if (!QCoreApplication::instance()) + QSKIP("Test requires a QCoreApplication"); // because of the qWait() + QDBusSpy spy; QDBusConnection con = QDBusConnection::sessionBus(); @@ -252,6 +159,9 @@ void tst_QDBusConnection::send() void tst_QDBusConnection::sendWithGui() { + if (!QCoreApplication::instance()) + QSKIP("Test requires a QCoreApplication"); + QDBusConnection con = QDBusConnection::sessionBus(); QVERIFY(con.isConnected()); @@ -268,6 +178,9 @@ void tst_QDBusConnection::sendWithGui() void tst_QDBusConnection::sendAsync() { + if (!QCoreApplication::instance()) + QSKIP("Test requires a QCoreApplication"); + QDBusConnection con = QDBusConnection::sessionBus(); QVERIFY(con.isConnected()); @@ -289,6 +202,9 @@ void tst_QDBusConnection::connect() QDBusConnection con = QDBusConnection::sessionBus(); + if (!QCoreApplication::instance()) + return; // cannot receive signals in this thread without QCoreApplication + con.connect(con.baseService(), "/org/kde/selftest", "org.kde.selftest", "ping", &spy, SLOT(handlePing(QString))); @@ -482,58 +398,6 @@ void tst_QDBusConnection::registerObjectWithInterface() QVERIFY(!callMethod(con, path, interface)); } -class MyServer : public QDBusServer -{ - Q_OBJECT -public: - MyServer(QString path) : m_path(path), m_connections() - { - connect(this, SIGNAL(newConnection(QDBusConnection)), SLOT(handleConnection(QDBusConnection))); - } - - bool registerObject(const QDBusConnection& c) - { - QDBusConnection conn(c); - if (!conn.registerObject(m_path, &m_obj, QDBusConnection::ExportAllSlots)) - return false; - if (!(conn.objectRegisteredAt(m_path) == &m_obj)) - return false; - return true; - } - - bool registerObject() - { - Q_FOREACH (const QString &name, m_connections) { - if (!registerObject(QDBusConnection(name))) - return false; - } - return true; - } - - void unregisterObject() - { - Q_FOREACH (const QString &name, m_connections) { - QDBusConnection c(name); - c.unregisterObject(m_path); - } - } - -public slots: - void handleConnection(const QDBusConnection& c) - { - m_connections << c.name(); - QVERIFY(isConnected()); - QVERIFY(c.isConnected()); - QVERIFY(registerObject(c)); - } - -private: - MyObject m_obj; - QString m_path; - QStringList m_connections; -}; - - void tst_QDBusConnection::registerObjectPeer_data() { QTest::addColumn<QString>("path"); @@ -547,16 +411,22 @@ void tst_QDBusConnection::registerObjectPeer_data() void tst_QDBusConnection::registerObjectPeer() { + if (!QCoreApplication::instance()) + QSKIP("Test requires a QCoreApplication"); + QFETCH(QString, path); MyServer server(path); QDBusConnection::connectToPeer(server.address(), "beforeFoo"); + QTestEventLoop::instance().enterLoop(2); + QVERIFY(!QTestEventLoop::instance().timeout()); { QDBusConnection con = QDBusConnection::connectToPeer(server.address(), "foo"); - QCoreApplication::processEvents(); + QTestEventLoop::instance().enterLoop(2); + QVERIFY(!QTestEventLoop::instance().timeout()); QVERIFY(con.isConnected()); MyObject obj; @@ -565,6 +435,7 @@ void tst_QDBusConnection::registerObjectPeer() } QDBusConnection::connectToPeer(server.address(), "afterFoo"); + QTestEventLoop::instance().enterLoop(2); { QDBusConnection con("foo"); @@ -617,7 +488,6 @@ void tst_QDBusConnection::registerObject2() MyObject obj; QVERIFY(con.registerObject("/", &obj, QDBusConnection::ExportAllSlots)); QVERIFY(callMethod(con, "/")); - qDebug() << obj.path; QCOMPARE(obj.path, QString("/")); } // make sure it's gone @@ -629,7 +499,6 @@ void tst_QDBusConnection::registerObject2() QVERIFY(con.registerObject("/p1", &obj, QDBusConnection::ExportAllSlots)); QVERIFY(!callMethod(con, "/")); QVERIFY(callMethod(con, "/p1")); - qDebug() << obj.path; QCOMPARE(obj.path, QString("/p1")); // re-register it somewhere else @@ -693,38 +562,15 @@ void tst_QDBusConnection::registerObject2() } } -class MyServer2 : public QDBusServer -{ - Q_OBJECT -public: - MyServer2() : m_conn("none") - { - connect(this, SIGNAL(newConnection(QDBusConnection)), SLOT(handleConnection(QDBusConnection))); - } - - QDBusConnection connection() - { - return m_conn; - } - -public slots: - void handleConnection(const QDBusConnection& c) - { - m_conn = c; - QVERIFY(isConnected()); - QVERIFY(m_conn.isConnected()); - } - -private: - MyObject m_obj; - QDBusConnection m_conn; -}; - void tst_QDBusConnection::registerObjectPeer2() { + if (!QCoreApplication::instance()) + QSKIP("Test requires a QCoreApplication"); + MyServer2 server; QDBusConnection con = QDBusConnection::connectToPeer(server.address(), "foo"); - QCoreApplication::processEvents(); + QTestEventLoop::instance().enterLoop(2); + QVERIFY(!QTestEventLoop::instance().timeout()); QVERIFY(con.isConnected()); QDBusConnection srv_con = server.connection(); @@ -741,7 +587,6 @@ void tst_QDBusConnection::registerObjectPeer2() MyObject obj; QVERIFY(con.registerObject("/", &obj, QDBusConnection::ExportAllSlots)); QVERIFY(callMethodPeer(srv_con, "/")); - qDebug() << obj.path; QCOMPARE(obj.path, QString("/")); } // make sure it's gone @@ -753,7 +598,6 @@ void tst_QDBusConnection::registerObjectPeer2() QVERIFY(con.registerObject("/p1", &obj, QDBusConnection::ExportAllSlots)); QVERIFY(!callMethodPeer(srv_con, "/")); QVERIFY(callMethodPeer(srv_con, "/p1")); - qDebug() << obj.path; QCOMPARE(obj.path, QString("/p1")); // re-register it somewhere else @@ -877,8 +721,13 @@ void tst_QDBusConnection::registerQObjectChildren() void tst_QDBusConnection::registerQObjectChildrenPeer() { + if (!QCoreApplication::instance()) + QSKIP("Test requires a QCoreApplication"); + MyServer2 server; QDBusConnection con = QDBusConnection::connectToPeer(server.address(), "foo"); + QTestEventLoop::instance().enterLoop(2); + QVERIFY(!QTestEventLoop::instance().timeout()); QCoreApplication::processEvents(); QVERIFY(con.isConnected()); @@ -968,22 +817,6 @@ bool tst_QDBusConnection::callMethodPeer(const QDBusConnection &conn, const QStr return (MyObject::path == path); } -class TestObject : public QObject -{ -Q_OBJECT -public: - TestObject(QObject *parent = 0) : QObject(parent) {} - ~TestObject() {} - - QString func; - -public slots: - void test0() { func = "test0"; } - void test1(int i) { func = "test1 " + QString::number(i); } - int test2() { func = "test2"; return 43; } - int test3(int i) { func = "test2"; return i + 1; } -}; - void tst_QDBusConnection::callSelf() { TestObject testObject; @@ -1020,6 +853,9 @@ void tst_QDBusConnection::callSelfByAnotherName_data() void tst_QDBusConnection::callSelfByAnotherName() { + if (!QCoreApplication::instance()) + QSKIP("Test requires a QCoreApplication"); + static int counter = 0; QString sname = serviceName() + QString::number(counter++); @@ -1092,6 +928,9 @@ void tst_QDBusConnection::multipleInterfacesInQObject() void tst_QDBusConnection::slotsWithLessParameters() { + if (!QCoreApplication::instance()) + QSKIP("Test requires a QCoreApplication"); + QDBusConnection con = QDBusConnection::sessionBus(); QDBusMessage signal = QDBusMessage::createSignal("/", "org.qtproject.TestCase", @@ -1118,7 +957,6 @@ void tst_QDBusConnection::slotsWithLessParameters() void tst_QDBusConnection::secondCallWithCallback() { - qDebug("Hello"); QDBusConnection con = QDBusConnection::sessionBus(); QDBusMessage msg = QDBusMessage::createMethodCall(con.baseService(), "/test", QString(), "test0"); @@ -1127,6 +965,9 @@ void tst_QDBusConnection::secondCallWithCallback() void tst_QDBusConnection::nestedCallWithCallback() { + if (!QCoreApplication::instance()) + QSKIP("Test requires a QCoreApplication"); + TestObject testObject; QDBusConnection connection = QDBusConnection::sessionBus(); QVERIFY(connection.registerObject("/test", &testObject, @@ -1142,22 +983,11 @@ void tst_QDBusConnection::nestedCallWithCallback() QCOMPARE(signalsReceived, 1); } -class RaceConditionSignalWaiter : public QObject -{ - Q_OBJECT -public: - int count; - RaceConditionSignalWaiter() : count (0) {} - virtual ~RaceConditionSignalWaiter() {} - -public slots: - void countUp() { ++count; emit done(); } -signals: - void done(); -}; - void tst_QDBusConnection::serviceRegistrationRaceCondition() { + if (!QCoreApplication::instance()) + QSKIP("Test requires a QCoreApplication"); + // There was a race condition in the updating of list of name owners in // Qt D-Bus. When the user connects to a signal coming from a given // service, we must listen for NameOwnerChanged signals relevant to that @@ -1209,39 +1039,6 @@ void tst_QDBusConnection::serviceRegistrationRaceCondition() QCOMPARE(recv.count, 1); } -class VirtualObject: public QDBusVirtualObject -{ - Q_OBJECT -public: - VirtualObject() :success(true) {} - - QString introspect(const QString & /* path */) const - { - return QString(); - } - - bool handleMessage(const QDBusMessage &message, const QDBusConnection &connection) { - ++callCount; - lastMessage = message; - - if (success) { - QDBusMessage reply = message.createReply(replyArguments); - connection.send(reply); - } - emit messageReceived(message); - return success; - } -signals: - void messageReceived(const QDBusMessage &message) const; - -public: - mutable QDBusMessage lastMessage; - QVariantList replyArguments; - mutable int callCount; - bool success; -}; - - void tst_QDBusConnection::registerVirtualObject() { QDBusConnection con = QDBusConnection::sessionBus(); @@ -1324,6 +1121,9 @@ void tst_QDBusConnection::registerVirtualObject() void tst_QDBusConnection::callVirtualObject() { + if (!QCoreApplication::instance()) + QSKIP("Test requires a QCoreApplication"); + QDBusConnection con = QDBusConnection::sessionBus(); QVERIFY(con.isConnected()); @@ -1381,7 +1181,6 @@ void tst_QDBusConnection::callVirtualObject() QVERIFY(!QTestEventLoop::instance().timeout()); QTest::qWait(100); QVERIFY(errorReply.isError()); - qDebug() << errorReply.reply().arguments(); QCOMPARE(errorReply.reply().errorName(), QString("org.freedesktop.DBus.Error.UnknownObject")); QDBusConnection::disconnectFromBus("con2"); @@ -1422,7 +1221,7 @@ void tst_QDBusConnection::callVirtualObjectLocal() QString MyObject::path; QString MyObjectWithoutInterface::path; QString MyObjectWithoutInterface::interface; -QTEST_MAIN(tst_QDBusConnection) - -#include "tst_qdbusconnection.moc" +#ifndef tst_QDBusConnection +QTEST_MAIN(tst_QDBusConnection) +#endif diff --git a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.h b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.h new file mode 100644 index 0000000000..a53ba320f8 --- /dev/null +++ b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.h @@ -0,0 +1,287 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Intel Corporation. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TST_QDBUSCONNECTION_H +#define TST_QDBUSCONNECTION_H + +#include <QObject> +#include <QtDBus/QtDBus> +#include <QtTest/QtTest> + +class BaseObject: public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "local.BaseObject") +public: + BaseObject(QObject *parent = 0) : QObject(parent) { } +public slots: + void anotherMethod() { } +}; + +class MyObject: public BaseObject +{ + Q_OBJECT +public slots: + void method(const QDBusMessage &msg); + +public: + static QString path; + int callCount; + MyObject(QObject *parent = 0) : BaseObject(parent), callCount(0) {} +}; + +class MyObjectWithoutInterface: public QObject +{ + Q_OBJECT +public slots: + void method(const QDBusMessage &msg); + +public: + static QString path; + static QString interface; + int callCount; + MyObjectWithoutInterface(QObject *parent = 0) : QObject(parent), callCount(0) {} +}; + +class tst_QDBusConnection: public QObject +{ + Q_OBJECT + + int signalsReceived; +public slots: + void oneSlot() { ++signalsReceived; } + void exitLoop() { ++signalsReceived; QTestEventLoop::instance().exitLoop(); } + void secondCallWithCallback(); + +private slots: + void noConnection(); + void connectToBus(); + void connectToPeer(); + void connect(); + void send(); + void sendWithGui(); + void sendAsync(); + void sendSignal(); + void sendSignalToName(); + void sendSignalToOtherName(); + + void registerObject_data(); + void registerObject(); + void registerObjectWithInterface_data(); + void registerObjectWithInterface(); + void registerObjectPeer_data(); + void registerObjectPeer(); + void registerObject2(); + void registerObjectPeer2(); + + void registerQObjectChildren(); + void registerQObjectChildrenPeer(); + + void callSelf(); + void callSelfByAnotherName_data(); + void callSelfByAnotherName(); + void multipleInterfacesInQObject(); + + void slotsWithLessParameters(); + void nestedCallWithCallback(); + + void serviceRegistrationRaceCondition(); + + void registerVirtualObject(); + void callVirtualObject(); + void callVirtualObjectLocal(); + +public: + QString serviceName() const { return "org.qtproject.Qt.Autotests.QDBusConnection"; } + bool callMethod(const QDBusConnection &conn, const QString &path); + bool callMethod(const QDBusConnection &conn, const QString &path, const QString &interface); + bool callMethodPeer(const QDBusConnection &conn, const QString &path); +}; + +class QDBusSpy: public QObject +{ + Q_OBJECT +public slots: + void handlePing(const QString &str) { args.clear(); args << str; } + void asyncReply(const QDBusMessage &msg) { args = msg.arguments(); } + +public: + QList<QVariant> args; +}; + +class MyServer : public QDBusServer +{ + Q_OBJECT +public: + MyServer(QString path) : m_path(path), m_connections() + { + connect(this, SIGNAL(newConnection(QDBusConnection)), SLOT(handleConnection(QDBusConnection))); + } + + bool registerObject(const QDBusConnection& c) + { + QDBusConnection conn(c); + if (!conn.registerObject(m_path, &m_obj, QDBusConnection::ExportAllSlots)) + return false; + if (!(conn.objectRegisteredAt(m_path) == &m_obj)) + return false; + return true; + } + + bool registerObject() + { + Q_FOREACH (const QString &name, m_connections) { + if (!registerObject(QDBusConnection(name))) + return false; + } + return true; + } + + void unregisterObject() + { + Q_FOREACH (const QString &name, m_connections) { + QDBusConnection c(name); + c.unregisterObject(m_path); + } + } + +public slots: + void handleConnection(const QDBusConnection& c) + { + m_connections << c.name(); + QVERIFY(isConnected()); + QVERIFY(c.isConnected()); + QVERIFY(registerObject(c)); + QTestEventLoop::instance().exitLoop(); + } + +private: + MyObject m_obj; + QString m_path; + QStringList m_connections; +}; + +class MyServer2 : public QDBusServer +{ + Q_OBJECT +public: + MyServer2() : m_conn("none") + { + connect(this, SIGNAL(newConnection(QDBusConnection)), SLOT(handleConnection(QDBusConnection))); + } + + QDBusConnection connection() + { + return m_conn; + } + +public slots: + void handleConnection(const QDBusConnection& c) + { + m_conn = c; + QVERIFY(isConnected()); + QVERIFY(m_conn.isConnected()); + QTestEventLoop::instance().exitLoop(); + } + +private: + MyObject m_obj; + QDBusConnection m_conn; +}; + +class TestObject : public QObject +{ +Q_OBJECT +public: + TestObject(QObject *parent = 0) : QObject(parent) {} + ~TestObject() {} + + QString func; + +public slots: + void test0() { func = "test0"; } + void test1(int i) { func = "test1 " + QString::number(i); } + int test2() { func = "test2"; return 43; } + int test3(int i) { func = "test2"; return i + 1; } +}; + +class RaceConditionSignalWaiter : public QObject +{ + Q_OBJECT +public: + int count; + RaceConditionSignalWaiter() : count (0) {} + virtual ~RaceConditionSignalWaiter() {} + +public slots: + void countUp() { ++count; emit done(); } +signals: + void done(); +}; + +class VirtualObject: public QDBusVirtualObject +{ + Q_OBJECT +public: + VirtualObject() :success(true) {} + + QString introspect(const QString & /* path */) const + { + return QString(); + } + + bool handleMessage(const QDBusMessage &message, const QDBusConnection &connection) { + ++callCount; + lastMessage = message; + + if (success) { + QDBusMessage reply = message.createReply(replyArguments); + connection.send(reply); + } + emit messageReceived(message); + return success; + } +signals: + void messageReceived(const QDBusMessage &message) const; + +public: + mutable QDBusMessage lastMessage; + QVariantList replyArguments; + mutable int callCount; + bool success; +}; + + +#endif // TST_QDBUSCONNECTION_H + diff --git a/tests/auto/dbus/qdbusconnection_no_app/qdbusconnection_no_app.pro b/tests/auto/dbus/qdbusconnection_no_app/qdbusconnection_no_app.pro new file mode 100644 index 0000000000..ba3a13caa9 --- /dev/null +++ b/tests/auto/dbus/qdbusconnection_no_app/qdbusconnection_no_app.pro @@ -0,0 +1,6 @@ +CONFIG += testcase +TARGET = tst_qdbusconnection_no_app +QT = core dbus testlib +SOURCES += tst_qdbusconnection_no_app.cpp +HEADERS += ../qdbusconnection/tst_qdbusconnection.h +DEFINES += SRCDIR=\\\"$$PWD/\\\" tst_QDBusConnection=tst_QDBusConnection_NoApplication diff --git a/tests/auto/dbus/qdbusconnection_no_app/tst_qdbusconnection_no_app.cpp b/tests/auto/dbus/qdbusconnection_no_app/tst_qdbusconnection_no_app.cpp new file mode 100644 index 0000000000..816f75f82e --- /dev/null +++ b/tests/auto/dbus/qdbusconnection_no_app/tst_qdbusconnection_no_app.cpp @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Intel Corporation. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Ugly hack, look away +#include "../qdbusconnection/tst_qdbusconnection.cpp" + +QTEST_APPLESS_MAIN(tst_QDBusConnection_NoApplication) diff --git a/tests/auto/dbus/qdbuspendingcall/tst_qdbuspendingcall.cpp b/tests/auto/dbus/qdbuspendingcall/tst_qdbuspendingcall.cpp index 9833d17a1c..8cb9aa70e9 100644 --- a/tests/auto/dbus/qdbuspendingcall/tst_qdbuspendingcall.cpp +++ b/tests/auto/dbus/qdbuspendingcall/tst_qdbuspendingcall.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Intel Corporation. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -172,10 +173,6 @@ QDBusPendingCall tst_QDBusPendingCall::sendError() void tst_QDBusPendingCall::waitForFinished() { QDBusPendingCall ac = sendMessage(); - QVERIFY(!ac.isFinished()); - QVERIFY(!ac.isError()); - QCOMPARE(ac.reply().type(), QDBusMessage::InvalidMessage); - ac.waitForFinished(); QVERIFY(ac.isFinished()); QVERIFY(!ac.isError()); @@ -195,10 +192,6 @@ void tst_QDBusPendingCall::waitForFinished() void tst_QDBusPendingCall::waitForFinished_error() { QDBusPendingCall ac = sendError(); - QVERIFY(!ac.isFinished()); - QVERIFY(!ac.isError()); - QCOMPARE(ac.reply().type(), QDBusMessage::InvalidMessage); - ac.waitForFinished(); QVERIFY(ac.isFinished()); QVERIFY(ac.isError()); @@ -254,10 +247,6 @@ void tst_QDBusPendingCall::callWithCallback_localLoop_errorReply() void tst_QDBusPendingCall::watcher() { QDBusPendingCall ac = sendMessage(); - QVERIFY(!ac.isFinished()); - QVERIFY(!ac.isError()); - QCOMPARE(ac.reply().type(), QDBusMessage::InvalidMessage); - callCount = 0; watchArgument = 0; @@ -284,10 +273,6 @@ void tst_QDBusPendingCall::watcher() void tst_QDBusPendingCall::watcher_error() { QDBusPendingCall ac = sendError(); - QVERIFY(!ac.isFinished()); - QVERIFY(!ac.isError()); - QCOMPARE(ac.reply().type(), QDBusMessage::InvalidMessage); - callCount = 0; watchArgument = 0; @@ -312,10 +297,6 @@ void tst_QDBusPendingCall::watcher_error() void tst_QDBusPendingCall::watcher_waitForFinished() { QDBusPendingCall ac = sendMessage(); - QVERIFY(!ac.isFinished()); - QVERIFY(!ac.isError()); - QCOMPARE(ac.reply().type(), QDBusMessage::InvalidMessage); - callCount = 0; watchArgument = 0; @@ -391,10 +372,6 @@ void tst_QDBusPendingCall::watcher_waitForFinished_threaded() void tst_QDBusPendingCall::watcher_waitForFinished_alreadyFinished() { QDBusPendingCall ac = sendMessage(); - QVERIFY(!ac.isFinished()); - QVERIFY(!ac.isError()); - QCOMPARE(ac.reply().type(), QDBusMessage::InvalidMessage); - ac.waitForFinished(); QVERIFY(ac.isFinished()); QVERIFY(!ac.isError()); @@ -425,10 +402,6 @@ void tst_QDBusPendingCall::watcher_waitForFinished_alreadyFinished() void tst_QDBusPendingCall::watcher_waitForFinished_alreadyFinished_eventLoop() { QDBusPendingCall ac = sendMessage(); - QVERIFY(!ac.isFinished()); - QVERIFY(!ac.isError()); - QCOMPARE(ac.reply().type(), QDBusMessage::InvalidMessage); - ac.waitForFinished(); QVERIFY(ac.isFinished()); QVERIFY(!ac.isError()); @@ -462,10 +435,6 @@ void tst_QDBusPendingCall::watcher_waitForFinished_alreadyFinished_eventLoop() void tst_QDBusPendingCall::watcher_waitForFinished_error() { QDBusPendingCall ac = sendError(); - QVERIFY(!ac.isFinished()); - QVERIFY(!ac.isError()); - QCOMPARE(ac.reply().type(), QDBusMessage::InvalidMessage); - callCount = 0; watchArgument = 0; diff --git a/tests/auto/dbus/qdbusservicewatcher/tst_qdbusservicewatcher.cpp b/tests/auto/dbus/qdbusservicewatcher/tst_qdbusservicewatcher.cpp index 9dd2e4bb83..e7fa1e6484 100644 --- a/tests/auto/dbus/qdbusservicewatcher/tst_qdbusservicewatcher.cpp +++ b/tests/auto/dbus/qdbusservicewatcher/tst_qdbusservicewatcher.cpp @@ -49,8 +49,11 @@ private slots: void watchForCreation(); void watchForDisappearance(); + void watchForDisappearanceUniqueConnection(); void watchForOwnerChange(); void modeChange(); + void disconnectedConnection(); + void setConnection(); }; tst_QDBusServiceWatcher::tst_QDBusServiceWatcher() @@ -155,6 +158,40 @@ void tst_QDBusServiceWatcher::watchForDisappearance() QVERIFY(spyO.at(0).at(2).toString().isEmpty()); } +void tst_QDBusServiceWatcher::watchForDisappearanceUniqueConnection() +{ + QDBusConnection con = QDBusConnection::sessionBus(); + QVERIFY(con.isConnected()); + + // second connection + QString watchedName = QDBusConnection::connectToBus(QDBusConnection::SessionBus, "session2").baseService(); + QVERIFY(!watchedName.isEmpty()); + + QDBusServiceWatcher watcher(watchedName, con, QDBusServiceWatcher::WatchForUnregistration); + watcher.setObjectName("watcher for disappearance"); + + QSignalSpy spyR(&watcher, SIGNAL(serviceRegistered(QString))); + QSignalSpy spyU(&watcher, SIGNAL(serviceUnregistered(QString))); + QSignalSpy spyO(&watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString))); + QTestEventLoop::instance().connect(&watcher, SIGNAL(serviceUnregistered(QString)), SLOT(exitLoop())); + + // unregister it: + QDBusConnection::disconnectFromBus("session2"); + + QTestEventLoop::instance().enterLoop(1); + QVERIFY(!QTestEventLoop::instance().timeout()); + + QCOMPARE(spyR.count(), 0); + + QCOMPARE(spyU.count(), 1); + QCOMPARE(spyU.at(0).at(0).toString(), watchedName); + + QCOMPARE(spyO.count(), 1); + QCOMPARE(spyO.at(0).at(0).toString(), watchedName); + QCOMPARE(spyO.at(0).at(1).toString(), watchedName); + QVERIFY(spyO.at(0).at(2).toString().isEmpty()); +} + void tst_QDBusServiceWatcher::watchForOwnerChange() { QDBusConnection con = QDBusConnection::sessionBus(); @@ -263,5 +300,72 @@ void tst_QDBusServiceWatcher::modeChange() QVERIFY(spyO.at(0).at(2).toString().isEmpty()); } +void tst_QDBusServiceWatcher::disconnectedConnection() +{ + QDBusConnection con(""); + QVERIFY(!con.isConnected()); + + QDBusServiceWatcher watcher(serviceName, con, QDBusServiceWatcher::WatchForRegistration); + watcher.addWatchedService("com.example.somethingelse"); + watcher.addWatchedService("org.freedesktop.DBus"); + + watcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration); + watcher.setWatchMode(QDBusServiceWatcher::WatchForOwnerChange); + + watcher.setWatchedServices(QStringList()); +} + +void tst_QDBusServiceWatcher::setConnection() +{ + // begin with a disconnected connection + QDBusConnection con(""); + QVERIFY(!con.isConnected()); + + QDBusServiceWatcher watcher(serviceName, con, QDBusServiceWatcher::WatchForRegistration); + + QSignalSpy spyR(&watcher, SIGNAL(serviceRegistered(QString))); + QSignalSpy spyU(&watcher, SIGNAL(serviceUnregistered(QString))); + QTestEventLoop::instance().connect(&watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)), SLOT(exitLoop())); + + // move to the session bus + con = QDBusConnection::sessionBus(); + QVERIFY(con.isConnected()); + watcher.setConnection(con); + + // register a name + QVERIFY(con.registerService(serviceName)); + + QTestEventLoop::instance().enterLoop(1); + QVERIFY(!QTestEventLoop::instance().timeout()); + + QCOMPARE(spyR.count(), 1); + QCOMPARE(spyR.at(0).at(0).toString(), serviceName); + QCOMPARE(spyU.count(), 0); + + // is the system bus available? + if (!QDBusConnection::systemBus().isConnected()) + return; + + // connect to the system bus and ask to watch that base service + QString watchedName = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "system2").baseService(); + watcher.setWatchedServices(QStringList() << watchedName); + watcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration); + + // move to the system bus + watcher.setConnection(QDBusConnection::systemBus()); + spyR.clear(); + spyU.clear(); + + QDBusConnection::disconnectFromBus("system2"); + + QTestEventLoop::instance().enterLoop(1); + QVERIFY(!QTestEventLoop::instance().timeout()); + + QCOMPARE(spyR.count(), 0); + + QCOMPARE(spyU.count(), 1); + QCOMPARE(spyU.at(0).at(0).toString(), watchedName); +} + QTEST_MAIN(tst_QDBusServiceWatcher) #include "tst_qdbusservicewatcher.moc" diff --git a/tests/auto/dbus/qdbusxmlparser/tst_qdbusxmlparser.cpp b/tests/auto/dbus/qdbusxmlparser/tst_qdbusxmlparser.cpp index 4dbe0aae7d..c57292b7db 100644 --- a/tests/auto/dbus/qdbusxmlparser/tst_qdbusxmlparser.cpp +++ b/tests/auto/dbus/qdbusxmlparser/tst_qdbusxmlparser.cpp @@ -64,15 +64,10 @@ private slots: void properties(); }; -QT_BEGIN_NAMESPACE -// Avoid QHash randomization so that the order of the XML attributes is stable -extern Q_CORE_EXPORT QBasicAtomicInt qt_qhash_seed; // from qhash.cpp -QT_END_NAMESPACE - void tst_QDBusXmlParser::initTestCase() { // Always initialize the hash seed to 0 to get reliable test results - qt_qhash_seed.store(0); + qSetGlobalQHashSeed(0); } void tst_QDBusXmlParser::parsing_data() diff --git a/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp b/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp index d2fae0e5e3..bff762fd04 100644 --- a/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp +++ b/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp @@ -324,6 +324,11 @@ void tst_QIcoImageFormat::pngCompression() QImage image; reader.jumpToImage(index); + + QSize size = reader.size(); + QCOMPARE(size.width(), width); + QCOMPARE(size.height(), height); + reader.read(&image); QCOMPARE(image.width(), width); diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 5cade82b6b..2c363e3d69 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -171,7 +171,7 @@ void tst_QGuiApplication::focusObject() int argc = 0; QGuiApplication app(argc, 0); - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This fails. Figure out why."); QObject obj1, obj2, obj3; @@ -342,7 +342,7 @@ void tst_QGuiApplication::changeFocusWindow() int argc = 0; QGuiApplication app(argc, 0); - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This fails. Figure out why."); const QRect screenGeometry = QGuiApplication::primaryScreen()->availableVirtualGeometry(); @@ -416,11 +416,11 @@ void tst_QGuiApplication::keyboardModifiers() QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier); // shortcut events - QWindowSystemInterface::tryHandleShortcutEvent(window.data(), Qt::Key_5, Qt::MetaModifier); + QTest::keyEvent(QTest::Shortcut, window.data(), Qt::Key_5, Qt::MetaModifier); QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::MetaModifier); - QWindowSystemInterface::tryHandleShortcutEvent(window.data(), Qt::Key_Period, Qt::NoModifier); + QTest::keyEvent(QTest::Shortcut, window.data(), Qt::Key_Period, Qt::NoModifier); QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier); - QWindowSystemInterface::tryHandleShortcutEvent(window.data(), Qt::Key_0, Qt::ControlModifier); + QTest::keyEvent(QTest::Shortcut, window.data(), Qt::Key_0, Qt::ControlModifier); QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier); // key events diff --git a/tests/auto/gui/kernel/qguieventloop/BLACKLIST b/tests/auto/gui/kernel/qguieventloop/BLACKLIST deleted file mode 100644 index 688df0192b..0000000000 --- a/tests/auto/gui/kernel/qguieventloop/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[processEvents] -ubuntu-14.04 diff --git a/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp b/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp index a36e31e2e2..e3b71e40d1 100644 --- a/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp +++ b/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp @@ -191,7 +191,7 @@ void tst_qinputmethod::cursorRectangle() { QCOMPARE(qApp->inputMethod()->cursorRectangle(), QRectF()); - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This fails. Figure out why."); DummyWindow window; @@ -289,9 +289,12 @@ void tst_qinputmethod::inputDirection() void tst_qinputmethod::inputMethodAccepted() { - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This fails. Figure out why."); + if (!QGuiApplication::platformName().compare(QLatin1String("xcb"), Qt::CaseInsensitive)) + QSKIP("XCB: depends on dedicated platform context."); + InputItem disabledItem; disabledItem.setEnabled(false); diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index ccb8c759c6..2219306b81 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -286,7 +286,7 @@ void tst_QWindow::positioning() QSKIP("This platform does not support non-fullscreen windows"); } - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This fails. Figure out why."); // Some platforms enforce minimum widths for windows, which can cause extra resize @@ -476,7 +476,7 @@ void tst_QWindow::isExposed() window.hide(); - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This is flaky. Figure out why."); QCoreApplication::processEvents(); @@ -487,7 +487,7 @@ void tst_QWindow::isExposed() void tst_QWindow::isActive() { - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This fails. Figure out why."); Window window; @@ -1134,7 +1134,7 @@ void tst_QWindow::close() void tst_QWindow::activateAndClose() { - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This fails. Figure out why."); for (int i = 0; i < 10; ++i) { @@ -1388,7 +1388,7 @@ void tst_QWindow::tabletEvents() void tst_QWindow::windowModality_QTBUG27039() { - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This fails. Figure out why."); QWindow parent; @@ -1483,7 +1483,7 @@ void tst_QWindow::mask() void tst_QWindow::initialSize() { - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This fails. Figure out why."); QSize defaultSize(0,0); @@ -1524,7 +1524,7 @@ void tst_QWindow::initialSize() void tst_QWindow::modalDialog() { - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This fails. Figure out why."); QWindow normalWindow; @@ -1550,7 +1550,7 @@ void tst_QWindow::modalDialog() void tst_QWindow::modalDialogClosingOneOfTwoModal() { - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This fails. Figure out why."); QWindow normalWindow; @@ -1588,7 +1588,7 @@ void tst_QWindow::modalDialogClosingOneOfTwoModal() void tst_QWindow::modalWithChildWindow() { - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This fails. Figure out why."); QWindow normalWindow; @@ -1622,7 +1622,7 @@ void tst_QWindow::modalWithChildWindow() void tst_QWindow::modalWindowModallity() { - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This fails. Figure out why."); QWindow normal_window; diff --git a/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp b/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp index 48a15641b2..1cb7972cc6 100644 --- a/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp +++ b/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp @@ -288,7 +288,7 @@ void tst_QOpenGlConfig::testBugList() void tst_QOpenGlConfig::testDefaultWindowsBlacklist() { - if (qGuiApp->platformName() != QStringLiteral("windows")) + if (QGuiApplication::platformName().compare(QLatin1String("windows"), Qt::CaseInsensitive)) QSKIP("Only applicable to Windows"); QFile f(QStringLiteral(":/qt-project.org/windows/openglblacklists/default.json")); diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index 1e0c3d0a75..70d2842a93 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -149,7 +149,7 @@ void tst_QFont::exactMatch() #endif - if (QGuiApplication::platformName() == QLatin1String("xcb")) { + if (!QGuiApplication::platformName().compare("xcb", Qt::CaseInsensitive)) { QVERIFY(QFont("sans").exactMatch()); QVERIFY(QFont("sans-serif").exactMatch()); QVERIFY(QFont("serif").exactMatch()); @@ -608,6 +608,11 @@ void tst_QFont::serialize_data() font.setStyleName("Regular Black Condensed"); // This wasn't read until 5.4. QTest::newRow("styleName") << font << QDataStream::Qt_5_4; + + font = basicFont; + font.setCapitalization(QFont::AllUppercase); + // This wasn't read until 5.6. + QTest::newRow("capitalization") << font << QDataStream::Qt_5_6; } void tst_QFont::serialize() diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index 18da61925d..de0c2d6dbe 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -1985,7 +1985,12 @@ void tst_QTextLayout::textWidthVsWIdth() "./libs -I/home/ettrich/dev/creator/tools -I../../plugins -I../../shared/scriptwrapper -I../../libs/3rdparty/botan/build -Idialogs -Iactionmanager -Ieditorma" "nager -Iprogressmanager -Iscriptmanager -I.moc/debug-shared -I.uic -o .obj/debug-shared/sidebar.o sidebar.cpp")); - // textWidth includes right bearing, but it should never be LARGER than width if there is space for at least one character + // The naturalTextWidth includes right bearing, but should never be LARGER than line width if + // there is space for at least one character. Unfortunately that assumption may not hold if the + // font engine fails to report an accurate minimum right bearing for the font, eg. when the + // minimum right bearing reported by the font engine doesn't cover all the glyphs in the font. + // The result is that this test may fail in some cases. We should fix this by running the test + // with a font that we know have no suprising right bearings. See qtextlayout.cpp for details. for (int width = 100; width < 1000; ++width) { layout.beginLayout(); QTextLine line = layout.createLine(); diff --git a/tests/auto/network/access/qnetworkreply/BLACKLIST b/tests/auto/network/access/qnetworkreply/BLACKLIST index 5012b356c2..3ec580ddde 100644 --- a/tests/auto/network/access/qnetworkreply/BLACKLIST +++ b/tests/auto/network/access/qnetworkreply/BLACKLIST @@ -3,12 +3,6 @@ osx ubuntu-14.04 [ioGetFromBuiltinHttp:https+limited] ubuntu-14.04 -[ioGetFromHttpBrokenServer:no-newline] -osx -[synchronousRequest:https] -osx -[SslHandshakeFailedError] -osx [httpAbort] * [backgroundRequestInterruption:ftp, bg, nobg] diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index b448a1db12..debdc6bcb3 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -1078,11 +1078,7 @@ protected: // clean up QAbstractSocket's residue: while (client->bytesToWrite() > 0) { qDebug() << "Still having" << client->bytesToWrite() << "bytes to write, doing that now"; -#ifdef Q_OS_OSX - if (!client->waitForBytesWritten(4000)) { -#else - if (!client->waitForBytesWritten(2000)) { -#endif + if (!client->waitForBytesWritten(10000)) { qDebug() << "ERROR: FastSender:" << client->error() << "cleaning up residue"; return; } @@ -1102,11 +1098,7 @@ protected: measuredSentBytes += writeNextData(client, bytesToWrite); while (client->bytesToWrite() > 0) { -#ifdef Q_OS_OSX - if (!client->waitForBytesWritten(4000)) { -#else - if (!client->waitForBytesWritten(2000)) { -#endif + if (!client->waitForBytesWritten(10000)) { qDebug() << "ERROR: FastSender:" << client->error() << "during blocking write"; return; } @@ -8211,7 +8203,7 @@ public slots: m_receivedData += data; if (!m_parsedHeaders && m_receivedData.contains("\r\n\r\n")) { m_parsedHeaders = true; - QTimer::singleShot(qrand()%10, this, SLOT(closeDelayed())); // simulate random network latency + QTimer::singleShot(qrand()%60, this, SLOT(closeDelayed())); // simulate random network latency // This server simulates a web server connection closing, e.g. because of Apaches MaxKeepAliveRequests or KeepAliveTimeout // In this case QNAM needs to re-send the upload data but it had a bug which then corrupts the upload // This test catches that. @@ -8317,11 +8309,12 @@ void tst_QNetworkReply::putWithServerClosingConnectionImmediately() // get the request started and the incoming socket connected QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); //qDebug() << "correct=" << server.m_correctUploads << "corrupt=" << server.m_corruptUploads << "expected=" <<numUploads; // Sanity check because ecause of 9c2ecf89 most replies will error out but we want to make sure at least some of them worked - QVERIFY(server.m_correctUploads > 5); + QVERIFY(server.m_correctUploads > 2); // Because actually important is that we don't get any corruption: QCOMPARE(server.m_corruptUploads, 0); diff --git a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp index e074ecae1d..8069865d93 100644 --- a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp +++ b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp @@ -83,22 +83,12 @@ private slots: void isInSubnet(); void isLoopback_data(); void isLoopback(); + void isMulticast_data(); + void isMulticast(); void convertv4v6_data(); void convertv4v6(); }; -QT_BEGIN_NAMESPACE -namespace QTest { - template<> - char *toString(const QHostAddress &addr) - { - if (addr.protocol() == QAbstractSocket::UnknownNetworkLayerProtocol) - return qstrdup("<invalid>"); - return qstrdup(addr.toString().toLatin1()); - } -} -QT_END_NAMESPACE - tst_QHostAddress::tst_QHostAddress() { } @@ -631,6 +621,9 @@ void tst_QHostAddress::isLoopback_data() QTest::addColumn<QHostAddress>("address"); QTest::addColumn<bool>("result"); + QTest::newRow("default") << QHostAddress() << false; + QTest::newRow("invalid") << QHostAddress("&&&") << false; + QTest::newRow("ipv6_loop") << QHostAddress(QHostAddress::LocalHostIPv6) << true; QTest::newRow("::1") << QHostAddress("::1") << true; @@ -639,7 +632,6 @@ void tst_QHostAddress::isLoopback_data() QTest::newRow("127.0.0.2") << QHostAddress("127.0.0.2") << true; QTest::newRow("127.3.2.1") << QHostAddress("127.3.2.1") << true; - QTest::newRow("default") << QHostAddress() << false; QTest::newRow("1.2.3.4") << QHostAddress("1.2.3.4") << false; QTest::newRow("10.0.0.4") << QHostAddress("10.0.0.4") << false; QTest::newRow("192.168.3.4") << QHostAddress("192.168.3.4") << false; @@ -650,10 +642,12 @@ void tst_QHostAddress::isLoopback_data() QTest::newRow("AnyIPv6") << QHostAddress(QHostAddress::AnyIPv6) << false; QTest::newRow("Broadcast") << QHostAddress(QHostAddress::Broadcast) << false; QTest::newRow("Null") << QHostAddress(QHostAddress::Null) << false; + QTest::newRow("ipv6-all-ffff") << QHostAddress("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") << false; QTest::newRow("::ffff:127.0.0.1") << QHostAddress("::ffff:127.0.0.1") << true; QTest::newRow("::ffff:127.0.0.2") << QHostAddress("::ffff:127.0.0.2") << true; QTest::newRow("::ffff:127.3.2.1") << QHostAddress("::ffff:127.3.2.1") << true; + } void tst_QHostAddress::isLoopback() @@ -664,6 +658,50 @@ void tst_QHostAddress::isLoopback() QCOMPARE(address.isLoopback(), result); } +void tst_QHostAddress::isMulticast_data() +{ + QTest::addColumn<QHostAddress>("address"); + QTest::addColumn<bool>("result"); + + QTest::newRow("default") << QHostAddress() << false; + QTest::newRow("invalid") << QHostAddress("&&&") << false; + + QTest::newRow("ipv6_loop") << QHostAddress(QHostAddress::LocalHostIPv6) << false; + QTest::newRow("::1") << QHostAddress("::1") << false; + QTest::newRow("ipv4_loop") << QHostAddress(QHostAddress::LocalHost) << false; + QTest::newRow("127.0.0.1") << QHostAddress("127.0.0.1") << false; + QTest::newRow("::") << QHostAddress("::") << false; + QTest::newRow("Any") << QHostAddress(QHostAddress::Any) << false; + QTest::newRow("AnyIPv4") << QHostAddress(QHostAddress::AnyIPv4) << false; + QTest::newRow("AnyIPv6") << QHostAddress(QHostAddress::AnyIPv6) << false; + QTest::newRow("Broadcast") << QHostAddress(QHostAddress::Broadcast) << false; + QTest::newRow("Null") << QHostAddress(QHostAddress::Null) << false; + + QTest::newRow("223.255.255.255") << QHostAddress("223.255.255.255") << false; + QTest::newRow("224.0.0.0") << QHostAddress("224.0.0.0") << true; + QTest::newRow("239.255.255.255") << QHostAddress("239.255.255.255") << true; + QTest::newRow("240.0.0.0") << QHostAddress("240.0.0.0") << false; + + QTest::newRow("::ffff:223.255.255.255") << QHostAddress("::ffff:223.255.255.255") << false; + QTest::newRow("::ffff:224.0.0.0") << QHostAddress("::ffff:224.0.0.0") << true; + QTest::newRow("::ffff:239.255.255.255") << QHostAddress("::ffff:239.255.255.255") << true; + QTest::newRow("::ffff:240.0.0.0") << QHostAddress("::ffff:240.0.0.0") << false; + + QTest::newRow("fc00::") << QHostAddress("fc00::") << false; + QTest::newRow("fe80::") << QHostAddress("fe80::") << false; + QTest::newRow("fec0::") << QHostAddress("fec0::") << false; + QTest::newRow("ff00::") << QHostAddress("ff00::") << true; + QTest::newRow("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") << QHostAddress("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") << true; +} + +void tst_QHostAddress::isMulticast() +{ + QFETCH(QHostAddress, address); + QFETCH(bool, result); + + QCOMPARE(address.isMulticast(), result); +} + void tst_QHostAddress::convertv4v6_data() { QTest::addColumn<QHostAddress>("source"); diff --git a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp index b3ffe74b67..f7798bbb70 100644 --- a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp +++ b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp @@ -58,6 +58,7 @@ private slots: void loopbackIPv4(); void loopbackIPv6(); void localAddress(); + void interfaceFromXXX_data(); void interfaceFromXXX(); void copyInvalidInterface(); @@ -188,35 +189,42 @@ void tst_QNetworkInterface::localAddress() QVERIFY(all.contains(local)); } -void tst_QNetworkInterface::interfaceFromXXX() +void tst_QNetworkInterface::interfaceFromXXX_data() { + QTest::addColumn<QNetworkInterface>("iface"); + QList<QNetworkInterface> allInterfaces = QNetworkInterface::allInterfaces(); + foreach (QNetworkInterface iface, allInterfaces) + QTest::newRow(iface.name().toLocal8Bit()) << iface; +} + +void tst_QNetworkInterface::interfaceFromXXX() +{ + QFETCH(QNetworkInterface, iface); - foreach (QNetworkInterface iface, allInterfaces) { - QVERIFY(QNetworkInterface::interfaceFromName(iface.name()).isValid()); - foreach (QNetworkAddressEntry entry, iface.addressEntries()) { - QVERIFY(!entry.ip().isNull()); + QVERIFY(QNetworkInterface::interfaceFromName(iface.name()).isValid()); + foreach (QNetworkAddressEntry entry, iface.addressEntries()) { + QVERIFY(!entry.ip().isNull()); - if (!entry.netmask().isNull()) { - QCOMPARE(entry.netmask().protocol(), entry.ip().protocol()); + if (!entry.netmask().isNull()) { + QCOMPARE(entry.netmask().protocol(), entry.ip().protocol()); - // if the netmask is known, the broadcast is known - // but only for IPv4 (there is no such thing as broadcast in IPv6) - if (entry.ip().protocol() == QAbstractSocket::IPv4Protocol) { - QVERIFY(!entry.broadcast().isNull()); + // if the netmask is known, the broadcast is known + // but only for IPv4 (there is no such thing as broadcast in IPv6) + if (entry.ip().protocol() == QAbstractSocket::IPv4Protocol) { + QVERIFY(!entry.broadcast().isNull()); - // verify that the broadcast address is correct - quint32 ip = entry.ip().toIPv4Address(); - quint32 mask = entry.netmask().toIPv4Address(); - quint32 bcast = entry.broadcast().toIPv4Address(); + // verify that the broadcast address is correct + quint32 ip = entry.ip().toIPv4Address(); + quint32 mask = entry.netmask().toIPv4Address(); + quint32 bcast = entry.broadcast().toIPv4Address(); - QCOMPARE(bcast, ip | ~mask); - } + QCOMPARE(bcast, ip | ~mask); } - - if (!entry.broadcast().isNull()) - QCOMPARE(entry.broadcast().protocol(), entry.ip().protocol()); } + + if (!entry.broadcast().isNull()) + QCOMPARE(entry.broadcast().protocol(), entry.ip().protocol()); } } diff --git a/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp b/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp index 44081d474f..71125f463a 100644 --- a/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp +++ b/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp @@ -243,13 +243,13 @@ void tst_PlatformSocketEngine::udpLoopbackTest() QVERIFY(available > 0); QByteArray answer; answer.resize(available); - QHostAddress senderAddress; - quint16 senderPort = 0; - QVERIFY(udpSocket.readDatagram(answer.data(), answer.size(), - &senderAddress, - &senderPort) == message1.size()); - QCOMPARE(senderAddress, QHostAddress("127.0.0.1")); - QVERIFY(senderPort != 0); + QIpPacketHeader header; + QCOMPARE(udpSocket.readDatagram(answer.data(), answer.size(), + &header, QAbstractSocketEngine::WantDatagramSender), + qint64(message1.size())); + QVERIFY(header.senderAddress == QHostAddress("127.0.0.1")); + QCOMPARE(header.senderAddress, QHostAddress("127.0.0.1")); + QVERIFY(header.senderPort != 0); } //--------------------------------------------------------------------------- @@ -291,13 +291,13 @@ void tst_PlatformSocketEngine::udpIPv6LoopbackTest() QVERIFY(available > 0); QByteArray answer; answer.resize(available); - QHostAddress senderAddress; - quint16 senderPort = 0; - QVERIFY(udpSocket.readDatagram(answer.data(), answer.size(), - &senderAddress, - &senderPort) == message1.size()); - QCOMPARE(senderAddress, QHostAddress("::1")); - QVERIFY(senderPort != 0); + QIpPacketHeader header; + QCOMPARE(udpSocket.readDatagram(answer.data(), answer.size(), + &header, QAbstractSocketEngine::WantDatagramSender), + qint64(message1.size())); + QVERIFY(header.senderAddress == QHostAddress("::1")); + QCOMPARE(header.senderAddress, QHostAddress("::1")); + QVERIFY(header.senderPort != 0); } } @@ -323,9 +323,9 @@ void tst_PlatformSocketEngine::broadcastTest() = "MOOT wtf is a MOOT? talk english not your sutpiD ENGLISH."; qint64 written = broadcastSocket.writeDatagram(trollMessage.data(), trollMessage.size(), - QHostAddress::Broadcast, - port); + QIpPacketHeader(QHostAddress::Broadcast, port)); + QVERIFY2(written != -1, qt_error_string().toLocal8Bit()); QCOMPARE((int)written, trollMessage.size()); // Wait until we receive it ourselves @@ -636,7 +636,7 @@ void tst_PlatformSocketEngine::invalidSend() QTest::ignoreMessage(QtWarningMsg, PLATFORMSOCKETENGINESTRING "::writeDatagram() was" " called by a socket other than QAbstractSocket::UdpSocket"); - QCOMPARE(socket.writeDatagram("hei", 3, QHostAddress::LocalHost, 143), + QCOMPARE(socket.writeDatagram("hei", 3, QIpPacketHeader(QHostAddress::LocalHost, 143)), (qlonglong) -1); } diff --git a/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp b/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp index 66fd74017e..8da656aab7 100644 --- a/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp +++ b/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp @@ -591,13 +591,13 @@ void tst_QSocks5SocketEngine::udpTest() QVERIFY(available > 0); QByteArray answer; answer.resize(available); - QHostAddress senderAddress; - quint16 senderPort = 0; - QVERIFY(udpSocket.readDatagram(answer.data(), answer.size(), - &senderAddress, - &senderPort) == message1.size()); - QCOMPARE(senderAddress, udpSocket2.localAddress()); - QCOMPARE(senderPort, udpSocket2.localPort()); + QIpPacketHeader header; + QCOMPARE(udpSocket.readDatagram(answer.data(), answer.size(), + &header, QAbstractSocketEngine::WantDatagramSender), + qint64(message1.size())); + QVERIFY(header.senderAddress == udpSocket2.localAddress()); + QCOMPARE(header.senderAddress, udpSocket2.localAddress()); + QCOMPARE(header.senderPort, udpSocket2.localPort()); } void tst_QSocks5SocketEngine::tcpSocketBlockingTest() diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index dc41a93906..09d9448e10 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -56,7 +56,6 @@ #endif Q_DECLARE_METATYPE(QHostAddress) -Q_DECLARE_METATYPE(QNetworkInterface) QT_FORWARD_DECLARE_CLASS(QUdpSocket) @@ -848,7 +847,11 @@ void tst_QUdpSocket::writeDatagramToNonExistingPeer_data() QTest::addColumn<bool>("bind"); QTest::addColumn<QHostAddress>("peerAddress"); QHostAddress localhost(QHostAddress::LocalHost); - QHostAddress remote = QHostInfo::fromName(QtNetworkSettings::serverName()).addresses().first(); + QList<QHostAddress> serverAddresses(QHostInfo::fromName(QtNetworkSettings::serverName()).addresses()); + if (serverAddresses.isEmpty()) + return; + + QHostAddress remote = serverAddresses.first(); QTest::newRow("localhost-unbound") << false << localhost; QTest::newRow("localhost-bound") << true << localhost; @@ -858,6 +861,8 @@ void tst_QUdpSocket::writeDatagramToNonExistingPeer_data() void tst_QUdpSocket::writeDatagramToNonExistingPeer() { + if (QHostInfo::fromName(QtNetworkSettings::serverName()).addresses().isEmpty()) + QFAIL("Could not find test server address"); QFETCH(bool, bind); QFETCH(QHostAddress, peerAddress); @@ -879,7 +884,11 @@ void tst_QUdpSocket::writeToNonExistingPeer_data() { QTest::addColumn<QHostAddress>("peerAddress"); QHostAddress localhost(QHostAddress::LocalHost); - QHostAddress remote = QHostInfo::fromName(QtNetworkSettings::serverName()).addresses().first(); + QList<QHostAddress> serverAddresses(QHostInfo::fromName(QtNetworkSettings::serverName()).addresses()); + if (serverAddresses.isEmpty()) + return; + + QHostAddress remote = serverAddresses.first(); // write (required to be connected) QTest::newRow("localhost") << localhost; QTest::newRow("remote") << remote; @@ -888,6 +897,8 @@ void tst_QUdpSocket::writeToNonExistingPeer_data() void tst_QUdpSocket::writeToNonExistingPeer() { QSKIP("Connected-mode UDP sockets and their behaviour are erratic"); + if (QHostInfo::fromName(QtNetworkSettings::serverName()).addresses().isEmpty()) + QFAIL("Could not find test server address"); QFETCH(QHostAddress, peerAddress); quint16 peerPort = 34534; qRegisterMetaType<QAbstractSocket::SocketError>("QAbstractSocket::SocketError"); @@ -1114,6 +1125,9 @@ void tst_QUdpSocket::multicastTtlOption_data() void tst_QUdpSocket::multicastTtlOption() { +#ifdef Q_OS_WINRT + QSKIP("WinRT does not support multicast."); +#endif QFETCH_GLOBAL(bool, setProxy); QFETCH(QHostAddress, bindAddress); QFETCH(int, ttl); @@ -1156,6 +1170,9 @@ void tst_QUdpSocket::multicastLoopbackOption_data() void tst_QUdpSocket::multicastLoopbackOption() { +#ifdef Q_OS_WINRT + QSKIP("WinRT does not support multicast."); +#endif QFETCH_GLOBAL(bool, setProxy); QFETCH(QHostAddress, bindAddress); QFETCH(int, loopback); @@ -1186,6 +1203,9 @@ void tst_QUdpSocket::multicastJoinBeforeBind_data() void tst_QUdpSocket::multicastJoinBeforeBind() { +#ifdef Q_OS_WINRT + QSKIP("WinRT does not support multicast."); +#endif QFETCH(QHostAddress, groupAddress); QUdpSocket udpSocket; @@ -1206,6 +1226,9 @@ void tst_QUdpSocket::multicastLeaveAfterClose_data() void tst_QUdpSocket::multicastLeaveAfterClose() { +#ifdef Q_OS_WINRT + QSKIP("WinRT does not support multicast."); +#endif QFETCH_GLOBAL(bool, setProxy); QFETCH(QHostAddress, groupAddress); if (setProxy) @@ -1247,6 +1270,9 @@ void tst_QUdpSocket::setMulticastInterface_data() void tst_QUdpSocket::setMulticastInterface() { +#ifdef Q_OS_WINRT + QSKIP("WinRT does not support multicast."); +#endif QFETCH_GLOBAL(bool, setProxy); QFETCH(QNetworkInterface, iface); QFETCH(QHostAddress, address); @@ -1295,6 +1321,9 @@ void tst_QUdpSocket::multicast_data() void tst_QUdpSocket::multicast() { +#ifdef Q_OS_WINRT + QSKIP("WinRT does not support multicast."); +#endif QFETCH_GLOBAL(bool, setProxy); QFETCH(QHostAddress, bindAddress); QFETCH(bool, bindResult); diff --git a/tests/auto/other/lancelot/tst_lancelot.cpp b/tests/auto/other/lancelot/tst_lancelot.cpp index 6da3d06ba8..3022114403 100644 --- a/tests/auto/other/lancelot/tst_lancelot.cpp +++ b/tests/auto/other/lancelot/tst_lancelot.cpp @@ -259,13 +259,9 @@ void tst_Lancelot::paint(QPaintDevice *device, GraphicsEngine engine, const QStr QTEST_MAIN(tst_Lancelot) #undef main -QT_BEGIN_NAMESPACE -extern Q_DECL_IMPORT QBasicAtomicInt qt_qhash_seed; // from qhash.cpp -QT_END_NAMESPACE - int main(int argc, char *argv[]) { - qt_qhash_seed.store(0); // Avoid rendering variations caused by QHash randomization + qSetGlobalQHashSeed(0); // Avoid rendering variations caused by QHash randomization QBaselineTest::handleCmdLineArgs(&argc, &argv); return _realmain(argc, argv); diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index a4da17e9b7..142b62ac68 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -1715,7 +1715,7 @@ static QRect characterRect(const QTextEdit &edit, int offset) int h = fm.height(); qreal x = line.cursorToX(relativeOffset); - QRect r(layoutPosition.x() + x, layoutPosition.y() + line.y(), w, h); + QRect r(layoutPosition.x() + x, layoutPosition.y() + line.y() + line.ascent() + fm.descent() - h, w, h); r.moveTo(edit.viewport()->mapToGlobal(r.topLeft())); return r; diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp index 9b76bca28c..42d929c4a1 100644 --- a/tests/auto/testlib/selftests/tst_selftests.cpp +++ b/tests/auto/testlib/selftests/tst_selftests.cpp @@ -625,6 +625,13 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& logge for (int n = 0; n < loggers.count(); ++n) { QString logger = loggers[n]; +#if defined(Q_OS_WIN) + if (n == 0 && subdir == QLatin1String("crashes")) { // Remove stack trace which is output to stdout. + const int exceptionLogStart = actualOutputs.first().indexOf("A crash occurred in "); + if (exceptionLogStart >= 0) + actualOutputs[0].truncate(exceptionLogStart); + } +#endif // Q_OS_WIN QList<QByteArray> res = splitLines(actualOutputs[n]); const QString expectedFileName = expectedFileNameFromTest(subdir, logger); QList<QByteArray> exp = expectedResult(expectedFileName); diff --git a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp index e62ce3ceb5..2982d80477 100644 --- a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp +++ b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp @@ -557,7 +557,7 @@ void tst_QDialog::snapToDefaultButton() #ifdef QT_NO_CURSOR QSKIP("Test relies on there being a cursor"); #else - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: Wayland does not support setting the cursor position."); QPoint topLeftPos = QApplication::desktop()->availableGeometry().topLeft(); diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp index ed34c67aad..7e6e5908ee 100644 --- a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp @@ -57,6 +57,8 @@ #include "../../../../../src/widgets/dialogs/qfilesystemmodel_p.h" #include "../../../../../src/widgets/dialogs/qfiledialog_p.h" +#include <qpa/qplatformdialoghelper.h> + #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) #include "../../../network-settings.h" #endif @@ -134,6 +136,8 @@ private slots: void QTBUG6558_showDirsOnly(); void QTBUG4842_selectFilterWithHideNameFilterDetails(); void dontShowCompleterOnRoot(); + void nameFilterParsing_data(); + void nameFilterParsing(); private: void cleanupSettingsFile(); @@ -459,7 +463,7 @@ void tst_QFileDialog2::task180459_lastDirectory_data() void tst_QFileDialog2::task180459_lastDirectory() { - if (qApp->platformName().toLower() == QStringLiteral("cocoa")) + if (!QGuiApplication::platformName().compare(QLatin1String("cocoa"), Qt::CaseInsensitive)) QSKIP("Insignificant on OSX"); //QTBUG-39183 //first visit the temp directory and close the dialog QNonNativeFileDialog *dlg = new QNonNativeFileDialog(0, "", tempDir.path()); @@ -1353,5 +1357,24 @@ void tst_QFileDialog2::dontShowCompleterOnRoot() QTRY_VERIFY(lineEdit->completer()->popup()->isHidden()); } +void tst_QFileDialog2::nameFilterParsing_data() +{ + QTest::addColumn<QString>("filterString"); + QTest::addColumn<QStringList>("filters"); + + // QTBUG-47923: Do not trip over "*,v". + QTest::newRow("text") << "plain text document (*.txt *.asc *,v *.doc)" + << (QStringList() << "*.txt" << "*.asc" << "*,v" << "*.doc"); + QTest::newRow("html") << "HTML document (*.html *.htm)" + << (QStringList() << "*.html" << "*.htm"); +} + +void tst_QFileDialog2::nameFilterParsing() +{ + QFETCH(QString, filterString); + QFETCH(QStringList, filters); + QCOMPARE(QPlatformFileDialogHelper::cleanFilterList(filterString), filters); +} + QTEST_MAIN(tst_QFileDialog2) #include "tst_qfiledialog2.moc" diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 27b90db2e6..7d5946dc5f 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -181,6 +181,7 @@ private slots: void mapToGlobal(); void mapToGlobalWithoutScene(); void QTBUG_43780_visibility(); + void forwardTouchEvent(); }; // Subclass that exposes the protected functions. @@ -3765,5 +3766,73 @@ void tst_QGraphicsProxyWidget::QTBUG_43780_visibility() QVERIFY(comboPopup->isVisible()); } +class TouchWidget : public QWidget +{ +public: + TouchWidget(QWidget *parent = 0) : QWidget(parent) {} + + bool event(QEvent *event) + { + switch (event->type()) { + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + event->accept(); + return true; + break; + default: + break; + } + + return QWidget::event(event); + } +}; + +// QTBUG_45737 +void tst_QGraphicsProxyWidget::forwardTouchEvent() +{ + QGraphicsScene *scene = new QGraphicsScene; + + TouchWidget *widget = new TouchWidget; + + widget->setAttribute(Qt::WA_AcceptTouchEvents); + + QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget; + + proxy->setAcceptTouchEvents(true); + proxy->setWidget(widget); + + scene->addItem(proxy); + + QGraphicsView *view = new QGraphicsView(scene); + + view->show(); + + EventSpy eventSpy(widget); + + QTouchDevice *device = new QTouchDevice; + device->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(device); + + QCOMPARE(eventSpy.counts[QEvent::TouchBegin], 0); + QCOMPARE(eventSpy.counts[QEvent::TouchUpdate], 0); + QCOMPARE(eventSpy.counts[QEvent::TouchEnd], 0); + + QTest::touchEvent(view, device).press(0, QPoint(10, 10), view); + QTest::touchEvent(view, device).move(0, QPoint(15, 15), view); + QTest::touchEvent(view, device).move(0, QPoint(16, 16), view); + QTest::touchEvent(view, device).release(0, QPoint(15, 15), view); + + QApplication::processEvents(); + + QCOMPARE(eventSpy.counts[QEvent::TouchBegin], 1); + QCOMPARE(eventSpy.counts[QEvent::TouchUpdate], 2); + QCOMPARE(eventSpy.counts[QEvent::TouchEnd], 1); + + delete view; + delete proxy; + delete scene; +} + QTEST_MAIN(tst_QGraphicsProxyWidget) #include "tst_qgraphicsproxywidget.moc" diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 087a19c6dd..e1ed9f5e23 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -145,7 +145,7 @@ class tst_QGraphicsView : public QObject public: tst_QGraphicsView() - : platformName(qApp->platformName().toLower()) + : platformName(QGuiApplication::platformName().toLower()) { } private slots: void initTestCase(); @@ -255,7 +255,6 @@ private slots: void task186827_deleteReplayedItem(); void task207546_focusCrash(); void task210599_unsetDragWhileDragging(); - void task236394_sendShortcutOverrideEvent(); void task239729_noViewUpdate_data(); void task239729_noViewUpdate(); void task239047_fitInViewSmallViewport(); @@ -3370,14 +3369,6 @@ void tst_QGraphicsView::task210599_unsetDragWhileDragging() QCOMPARE(basePos, view.mapFromScene(0, 0)); } -void tst_QGraphicsView::task236394_sendShortcutOverrideEvent() -{ - QGraphicsView view; - view.show(); - QKeyEvent event(QEvent::ShortcutOverride, Qt::Key_A, 0, QString("A")); - QApplication::sendEvent(&view, &event); -} - class ChangedListener : public QObject { Q_OBJECT diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp index 4edf5d1a3b..6d5f5a1c60 100644 --- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp @@ -253,7 +253,6 @@ private slots: void taskQTBUG_25333_adjustViewOptionsForIndex(); void taskQTBUG_18539_emitLayoutChanged(); void taskQTBUG_8176_emitOnExpandAll(); - void taskQTBUG_34717_collapseAtBottom(); void taskQTBUG_37813_crash(); void taskQTBUG_45697_crash(); void testInitialFocus(); @@ -2365,7 +2364,7 @@ void tst_QTreeView::selectionOrderTest() void tst_QTreeView::selection() { - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This causes a crash triggered by setVisible(false)"); QTreeView treeView; @@ -4283,35 +4282,6 @@ void tst_QTreeView::taskQTBUG_8176_emitOnExpandAll() QCOMPARE(spy2.size(), 1); // item2 is collapsed } -// From QTBUG_34717 (QTreeWidget crashes when scrolling to the end -// of an expanded tree, then collapse all) -// The test passes simply if it doesn't crash. -void tst_QTreeView::taskQTBUG_34717_collapseAtBottom() -{ - QTreeWidget treeWidget; - treeWidget.header()->setSectionResizeMode(QHeaderView::ResizeToContents); - treeWidget.setColumnCount(2); - QTreeWidgetItem *mainItem = new QTreeWidgetItem(&treeWidget, QStringList() << "Root"); - for (int i = 0; i < 200; ++i) { - QTreeWidgetItem *item = new QTreeWidgetItem(mainItem, QStringList(QString("Item"))); - new QTreeWidgetItem(item, QStringList() << "Child" << "1"); - new QTreeWidgetItem(item, QStringList() << "Child" << "2"); - new QTreeWidgetItem(item, QStringList() << "Child" << "3"); - } - treeWidget.show(); - treeWidget.expandAll(); - treeWidget.scrollToBottom(); - treeWidget.collapseAll(); - - treeWidget.setAnimated(true); - treeWidget.expandAll(); - treeWidget.scrollToBottom(); - mainItem->setExpanded(false); - - PublicView *pview = (PublicView*) &treeWidget; - QVERIFY(pview->sizeHintForColumn(1) >= 0); -} - void tst_QTreeView::testInitialFocus() { QTreeWidget treeWidget; diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp index 727bc41478..117c53a2bb 100644 --- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp @@ -161,6 +161,7 @@ private slots: void taskQTBUG2844_visualItemRect(); void setChildIndicatorPolicy(); + void taskQTBUG_34717_collapseAtBottom(); void task20345_sortChildren(); void getMimeDataWithInvalidItem(); @@ -3378,9 +3379,41 @@ void tst_QTreeWidget::setChildIndicatorPolicy() QTRY_COMPARE(delegate.numPaints, 1); } +// From QTBUG_34717 (QTreeWidget crashes when scrolling to the end +// of an expanded tree, then collapse all) +// The test passes simply if it doesn't crash. +void tst_QTreeWidget::taskQTBUG_34717_collapseAtBottom() +{ + struct PublicTreeWidget: public QTreeWidget + { + inline int sizeHintForColumn(int column) const { return QTreeWidget::sizeHintForColumn(column); } + }; + PublicTreeWidget treeWidget; + treeWidget.header()->setSectionResizeMode(QHeaderView::ResizeToContents); + treeWidget.setColumnCount(2); + QTreeWidgetItem *mainItem = new QTreeWidgetItem(&treeWidget, QStringList() << "Root"); + for (int i = 0; i < 200; ++i) { + QTreeWidgetItem *item = new QTreeWidgetItem(mainItem, QStringList(QString("Item"))); + new QTreeWidgetItem(item, QStringList() << "Child" << "1"); + new QTreeWidgetItem(item, QStringList() << "Child" << "2"); + new QTreeWidgetItem(item, QStringList() << "Child" << "3"); + } + treeWidget.show(); + treeWidget.expandAll(); + treeWidget.scrollToBottom(); + treeWidget.collapseAll(); + + treeWidget.setAnimated(true); + treeWidget.expandAll(); + treeWidget.scrollToBottom(); + mainItem->setExpanded(false); + + QVERIFY(treeWidget.sizeHintForColumn(1) >= 0); +} + void tst_QTreeWidget::task20345_sortChildren() { - if (qApp->platformName().toLower() == QLatin1String("wayland")) + if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) QSKIP("Wayland: This causes a crash triggered by setVisible(false)"); // This test case is considered successful if it is executed (no crash in sorting) diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 34bd575646..f3f4467b80 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -627,7 +627,7 @@ void tst_QWidget::getSetCheck() } tst_QWidget::tst_QWidget() - : m_platform(qApp->platformName().toLower()) + : m_platform(QGuiApplication::platformName().toLower()) , m_windowsAnimationsEnabled(windowsAnimationsEnabled()) { if (m_windowsAnimationsEnabled) // Disable animations which can interfere with screen grabbing in moveChild(), showAndMoveChild() diff --git a/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp b/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp index 7d48ab760d..dfc53c9164 100644 --- a/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp +++ b/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp @@ -212,7 +212,7 @@ void tst_QWindowContainer::testActivation() // Under KDE (ubuntu 12.10), we experience that doing two activateWindow in a row // does not work. The second gets ignored by the window manager, even though the // timestamp in the xcb connection is unique for both. - if (QGuiApplication::platformName() == "xcb") + if (!QGuiApplication::platformName().compare(QLatin1String("xcb"), Qt::CaseInsensitive)) QTest::qWait(100); window->requestActivate(); diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp index e8a0916dc5..d41398046f 100644 --- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp +++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp @@ -285,6 +285,7 @@ typedef QList<Qt::Key> KeyList; void tst_QDateTimeEdit::getSetCheck() { QDateTimeEdit obj1; + QCOMPARE(obj1.inputMethodQuery(Qt::ImHints), QVariant(int(Qt::ImhPreferNumbers))); obj1.setDisplayFormat("dd/MM/yyyy hh:mm:ss.zzz d/M/yy h:m:s.z AP"); // Section QDateTimeEdit::currentSection() // void QDateTimeEdit::setCurrentSection(Section) @@ -306,6 +307,11 @@ void tst_QDateTimeEdit::getSetCheck() QCOMPARE(QDateTimeEdit::MonthSection, obj1.currentSection()); obj1.setCurrentSection(QDateTimeEdit::YearSection); QCOMPARE(QDateTimeEdit::YearSection, obj1.currentSection()); + + QDateEdit dateEdit; + QCOMPARE(dateEdit.inputMethodQuery(Qt::ImHints), QVariant(int(Qt::ImhPreferNumbers))); + QTimeEdit timeEdit; + QCOMPARE(timeEdit.inputMethodQuery(Qt::ImHints), QVariant(int(Qt::ImhPreferNumbers))); } tst_QDateTimeEdit::tst_QDateTimeEdit() diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 802c6c3e2c..396dad4fa5 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -306,6 +306,7 @@ private slots: void clearButton(); void clearButtonVisibleAfterSettingText_QTBUG_45518(); void sideWidgets(); + void sideWidgetsActionEvents(); void shouldShowPlaceholderText_data(); void shouldShowPlaceholderText(); @@ -4320,6 +4321,13 @@ void tst_QLineEdit::clearButtonVisibleAfterSettingText_QTBUG_45518() #endif // QT_BUILD_INTERNAL } +static inline QIcon sideWidgetTestIcon() +{ + QImage image(QSize(20, 20), QImage::Format_ARGB32); + image.fill(Qt::yellow); + return QIcon(QPixmap::fromImage(image)); +} + void tst_QLineEdit::sideWidgets() { QWidget testWidget; @@ -4327,9 +4335,7 @@ void tst_QLineEdit::sideWidgets() QLineEdit *lineEdit = new QLineEdit(&testWidget); l->addWidget(lineEdit); l->addSpacerItem(new QSpacerItem(0, 50, QSizePolicy::Ignored, QSizePolicy::Fixed)); - QImage image(QSize(20, 20), QImage::Format_ARGB32); - image.fill(Qt::yellow); - QAction *iconAction = new QAction(QIcon(QPixmap::fromImage(image)), QString(), lineEdit); + QAction *iconAction = new QAction(sideWidgetTestIcon(), QString(), lineEdit); QWidgetAction *label1Action = new QWidgetAction(lineEdit); label1Action->setDefaultWidget(new QLabel(QStringLiteral("l1"))); QWidgetAction *label2Action = new QWidgetAction(lineEdit); @@ -4356,6 +4362,38 @@ void tst_QLineEdit::sideWidgets() lineEdit->addAction(iconAction); } +void tst_QLineEdit::sideWidgetsActionEvents() +{ + // QTBUG-39660, verify whether action events are handled by the widget. + QWidget testWidget; + QVBoxLayout *l = new QVBoxLayout(&testWidget); + QLineEdit *lineEdit = new QLineEdit(&testWidget); + l->addWidget(lineEdit); + l->addSpacerItem(new QSpacerItem(0, 50, QSizePolicy::Ignored, QSizePolicy::Fixed)); + QAction *iconAction = lineEdit->addAction(sideWidgetTestIcon(), QLineEdit::LeadingPosition); + testWidget.move(300, 300); + testWidget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&testWidget)); + + QWidget *toolButton = Q_NULLPTR; + foreach (QWidget *w, iconAction->associatedWidgets()) { + if (qobject_cast<QToolButton *>(w)) { + toolButton = w; + break; + } + } + QVERIFY(toolButton); + + QVERIFY(toolButton->isVisible()); + QVERIFY(toolButton->isEnabled()); + + iconAction->setEnabled(false); + QVERIFY(!toolButton->isEnabled()); + + iconAction->setVisible(false); + QVERIFY(!toolButton->isVisible()); +} + Q_DECLARE_METATYPE(Qt::AlignmentFlag) void tst_QLineEdit::shouldShowPlaceholderText_data() { diff --git a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp index e7de027b22..e23634c515 100644 --- a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp +++ b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp @@ -518,7 +518,7 @@ void tst_QMdiArea::subWindowActivated2() #ifdef Q_OS_MAC QSKIP("QTBUG-25298: This test is unstable on Mac."); #endif - if (qApp->platformName().toLower() == QStringLiteral("xcb")) + if (!QGuiApplication::platformName().compare(QLatin1String("xcb"), Qt::CaseInsensitive)) QSKIP("QTBUG-25298: Unstable on some X11 window managers"); QTRY_COMPARE(spy.count(), 1); QVERIFY(!mdiArea.activeSubWindow()); diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp index 843bb3437c..5ae0733965 100644 --- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp +++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp @@ -363,7 +363,7 @@ void tst_QMenu::keyboardNavigation_data() QTest::newRow("data9") << Qt::Key(Qt::Key_Down) << Qt::KeyboardModifiers(Qt::NoModifier) << 3 << 0 << false << false<< true; QTest::newRow("data10") << Qt::Key(Qt::Key_Return) << Qt::KeyboardModifiers(Qt::NoModifier) << 3 << 0 << false << true << false; - if (qApp->platformName().toLower() != QStringLiteral("xcb")) { + if (QGuiApplication::platformName().compare(QLatin1String("xcb"), Qt::CaseInsensitive)) { // Test shortcuts. QTest::newRow("shortcut0") << Qt::Key(Qt::Key_V) << Qt::KeyboardModifiers(Qt::AltModifier) << 5 << 0 << true << true << false; } diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index 9e24f373eb..baf60551c4 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -128,7 +128,7 @@ private slots: void taskQTBUG4965_escapeEaten(); #endif void taskQTBUG11823_crashwithInvisibleActions(); - void closeOnSecondClick(); + void closeOnSecondClickAndOpenOnThirdClick(); void cornerWidgets_data(); void cornerWidgets(); @@ -1312,7 +1312,7 @@ void tst_QMenuBar::taskQTBUG11823_crashwithInvisibleActions() QCOMPARE(menubar.activeAction(), m); //the active action shouldn't have changed } -void tst_QMenuBar::closeOnSecondClick() // QTBUG-32807, menu should close on 2nd click. +void tst_QMenuBar::closeOnSecondClickAndOpenOnThirdClick() // QTBUG-32807, menu should close on 2nd click. { QMainWindow mainWindow; mainWindow.resize(300, 200); @@ -1322,17 +1322,20 @@ void tst_QMenuBar::closeOnSecondClick() // QTBUG-32807, menu should close on 2nd #endif QMenuBar *menuBar = mainWindow.menuBar(); menuBar->setNativeMenuBar(false); - QMenu *fileMenu = menuBar->addMenu(QStringLiteral("closeOnSecondClick")); + QMenu *fileMenu = menuBar->addMenu(QStringLiteral("OpenCloseOpen")); fileMenu->addAction(QStringLiteral("Quit")); mainWindow.show(); QApplication::setActiveWindow(&mainWindow); QVERIFY(QTest::qWaitForWindowActive(&mainWindow)); const QPoint center = menuBar->actionGeometry(fileMenu->menuAction()).center(); + const QPoint globalPos = menuBar->mapToGlobal(center); QTest::mouseMove(menuBar, center); QTest::mouseClick(menuBar, Qt::LeftButton, 0, center); QTRY_VERIFY(fileMenu->isVisible()); - QTest::mouseClick(menuBar, Qt::LeftButton, 0, center); + QTest::mouseClick(fileMenu, Qt::LeftButton, 0, fileMenu->mapFromGlobal(globalPos)); QTRY_VERIFY(!fileMenu->isVisible()); + QTest::mouseClick(menuBar, Qt::LeftButton, 0, center); + QTRY_VERIFY(fileMenu->isVisible()); } Q_DECLARE_METATYPE(Qt::Corner) diff --git a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp index 05dd834c76..34b05c5291 100644 --- a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp @@ -165,6 +165,7 @@ Q_DECLARE_METATYPE(QLocale::Country) void tst_QSpinBox::getSetCheck() { QSpinBox obj1; + QCOMPARE(obj1.inputMethodQuery(Qt::ImHints), QVariant(int(Qt::ImhDigitsOnly))); // int QSpinBox::singleStep() // void QSpinBox::setSingleStep(int) obj1.setSingleStep(0); @@ -202,6 +203,7 @@ void tst_QSpinBox::getSetCheck() QCOMPARE(INT_MAX, obj1.value()); QDoubleSpinBox obj2; + QCOMPARE(obj2.inputMethodQuery(Qt::ImHints), QVariant(int(Qt::ImhFormattedNumbersOnly))); // double QDoubleSpinBox::singleStep() // void QDoubleSpinBox::setSingleStep(double) obj2.setSingleStep(0.0); |