summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-09-25 14:02:04 +0200
committerLiang Qi <liang.qi@theqtcompany.com>2015-09-25 14:02:04 +0200
commita1ad9a74ebb3c556c5f70f7e03be68b09598ac53 (patch)
tree615a96db418219a57a745a5899e39a9ac90744ec /tests/auto/corelib
parent6d78b7a0c46ea04f4bb771d960e2f7dff1362341 (diff)
parent462f355e4fb16cc7a1838fa2dda0f763eee58c84 (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/corelib')
-rw-r--r--tests/auto/corelib/global/qnumeric/qnumeric.pro2
-rw-r--r--tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp160
-rw-r--r--tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp4
-rw-r--r--tests/auto/corelib/io/qprocess/qprocess.pri1
-rw-r--r--tests/auto/corelib/io/qprocess/testProcessHang/main.cpp62
-rw-r--r--tests/auto/corelib/io/qprocess/testProcessHang/testProcessHang.pro4
-rw-r--r--tests/auto/corelib/io/qprocess/tst_qprocess.cpp235
-rw-r--r--tests/auto/corelib/io/qsettings/tst_qsettings.cpp4
-rw-r--r--tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp94
-rw-r--r--tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp15
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp6
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/qmimedatabase-cache.pro2
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp2
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/qmimedatabase-xml.pro2
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp2
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/testdata.qrc1
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/text-x-objcsrc.xml7
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp87
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h8
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/yast2-metapackage-handler-mimetypes.xml2
-rw-r--r--tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp2
-rw-r--r--tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp18
-rw-r--r--tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp386
-rw-r--r--tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h1
-rw-r--r--tests/auto/corelib/tools/qset/tst_qset.cpp24
-rw-r--r--tests/auto/corelib/tools/qtime/tst_qtime.cpp2
26 files changed, 959 insertions, 174 deletions
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 &regexp,
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()