summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/io/qprocess/tst_qprocess.cpp68
-rw-r--r--tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp17
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp2
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp2
-rw-r--r--tests/auto/corelib/kernel/qsharedmemory/qsharedmemory.pro4
-rw-r--r--tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp2
-rw-r--r--tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp88
7 files changed, 144 insertions, 39 deletions
diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
index e5195000aa..c47e88b0e6 100644
--- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
+++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
@@ -141,6 +141,8 @@ private slots:
void startStopStartStop();
void startStopStartStopBuffers_data();
void startStopStartStopBuffers();
+ void processEventsInAReadyReadSlot_data();
+ void processEventsInAReadyReadSlot();
// 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)
@@ -153,6 +155,7 @@ private slots:
protected slots:
void readFromProcess();
void exitLoopSlot();
+ void processApplicationEvents();
#ifndef Q_OS_WINCE
void restartProcess();
void waitForReadyReadInAReadyReadSlotSlot();
@@ -471,6 +474,11 @@ void tst_QProcess::exitLoopSlot()
QTestEventLoop::instance().exitLoop();
}
+void tst_QProcess::processApplicationEvents()
+{
+ QCoreApplication::processEvents();
+}
+
#ifndef Q_OS_WINCE
// Reading and writing to a process is not supported on Qt/CE
void tst_QProcess::echoTest2()
@@ -688,11 +696,7 @@ void tst_QProcess::waitForFinished()
process.start("testProcessOutput/testProcessOutput");
-#if !defined(Q_OS_WINCE)
- QVERIFY(process.waitForFinished(5000));
-#else
- QVERIFY(process.waitForFinished(30000));
-#endif
+ QVERIFY(process.waitForFinished());
QCOMPARE(process.exitStatus(), QProcess::NormalExit);
#if defined (Q_OS_WINCE)
@@ -916,12 +920,7 @@ void tst_QProcess::hardExit()
proc.start("testProcessEcho/testProcessEcho");
#endif
-#ifndef Q_OS_WINCE
- QVERIFY(proc.waitForStarted(5000));
-#else
- QVERIFY(proc.waitForStarted(10000));
-#endif
-
+ QVERIFY2(proc.waitForStarted(), qPrintable(proc.errorString()));
proc.kill();
QVERIFY(proc.waitForFinished(5000));
@@ -1417,24 +1416,17 @@ void tst_QProcess::spaceArgsTest()
QString program = programs.at(i);
process.start(program, args);
-#if defined(Q_OS_WINCE)
- const int timeOutMS = 10000;
-#else
- const int timeOutMS = 5000;
-#endif
QByteArray errorMessage;
- bool started = process.waitForStarted(timeOutMS);
+ bool started = process.waitForStarted();
if (!started)
errorMessage = startFailMessage(program, process);
QVERIFY2(started, errorMessage.constData());
- QVERIFY(process.waitForFinished(timeOutMS));
+ QVERIFY(process.waitForFinished());
QCOMPARE(process.exitStatus(), QProcess::NormalExit);
QCOMPARE(process.exitCode(), 0);
#if !defined(Q_OS_WINCE)
QStringList actual = QString::fromLatin1(process.readAll()).split("|");
-#endif
-#if !defined(Q_OS_WINCE)
QVERIFY(!actual.isEmpty());
// not interested in the program name, it might be different.
actual.removeFirst();
@@ -1459,8 +1451,6 @@ void tst_QProcess::spaceArgsTest()
#if !defined(Q_OS_WINCE)
actual = QString::fromLatin1(process.readAll()).split("|");
-#endif
-#if !defined(Q_OS_WINCE)
QVERIFY(!actual.isEmpty());
// not interested in the program name, it might be different.
actual.removeFirst();
@@ -1482,13 +1472,8 @@ void tst_QProcess::nativeArguments()
proc.start(QString::fromLatin1("testProcessSpacesArgs/nospace"), QStringList());
-#if !defined(Q_OS_WINCE)
- QVERIFY(proc.waitForStarted(5000));
- QVERIFY(proc.waitForFinished(5000));
-#else
- QVERIFY(proc.waitForStarted(10000));
- QVERIFY(proc.waitForFinished(10000));
-#endif
+ QVERIFY2(proc.waitForStarted(), qPrintable(proc.errorString()));
+ QVERIFY(proc.waitForFinished());
QCOMPARE(proc.exitStatus(), QProcess::NormalExit);
QCOMPARE(proc.exitCode(), 0);
@@ -2550,6 +2535,31 @@ void tst_QProcess::startStopStartStopBuffers()
}
}
+void tst_QProcess::processEventsInAReadyReadSlot_data()
+{
+ QTest::addColumn<bool>("callWaitForReadyRead");
+
+ QTest::newRow("no waitForReadyRead") << false;
+ QTest::newRow("waitForReadyRead") << true;
+}
+
+void tst_QProcess::processEventsInAReadyReadSlot()
+{
+ // Test whether processing events in a readyReadXXX slot crashes. (QTBUG-48697)
+ QFETCH(bool, callWaitForReadyRead);
+ QProcess process;
+ QObject::connect(&process, &QProcess::readyReadStandardOutput,
+ this, &tst_QProcess::processApplicationEvents);
+ process.start("testProcessEcho/testProcessEcho");
+ QVERIFY(process.waitForStarted());
+ const QByteArray data(156, 'x');
+ process.write(data.constData(), data.size() + 1);
+ if (callWaitForReadyRead)
+ QVERIFY(process.waitForReadyRead());
+ if (process.state() == QProcess::Running)
+ QVERIFY(process.waitForFinished());
+}
+
#endif //QT_NO_PROCESS
QTEST_MAIN(tst_QProcess)
diff --git a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp
index 439da8b1a3..2852420557 100644
--- a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp
+++ b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp
@@ -223,6 +223,8 @@ private slots:
void alignAccountingStyle();
void setCodec();
+ void textModeOnEmptyRead();
+
private:
void generateLineData(bool for_QString);
void generateAllData(bool for_QString);
@@ -3040,6 +3042,21 @@ void tst_QTextStream::int_write_with_locale()
QCOMPARE(result, output);
}
+void tst_QTextStream::textModeOnEmptyRead()
+{
+ const QString filename("textmodetest.txt");
+ QFile::remove(filename); // Remove file if exists
+
+
+ QFile file(filename);
+ QVERIFY(file.open(QIODevice::ReadWrite | QIODevice::Text));
+ QTextStream stream(&file);
+ QVERIFY(file.isTextModeEnabled());
+ QString emptyLine = stream.readLine(); // Text mode flag cleared here
+ QVERIFY(file.isTextModeEnabled());
+}
+
+
// ------------------------------------------------------------------------------
QTEST_MAIN(tst_QTextStream)
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
index b1ae4292d0..fbb6a30917 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -1473,7 +1473,7 @@ static QByteArray createTypeName(const char *begin, const char *va)
}
if (tn.endsWith('>'))
tn += ' ';
- tn += ">";
+ tn += '>';
return tn;
}
#endif
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index 540cd66715..23f8ff5857 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -275,8 +275,10 @@ static void playWithObjects()
void tst_QObject::initTestCase()
{
+#ifndef QT_NO_PROCESS
const QString testDataDir = QFileInfo(QFINDTESTDATA("signalbug")).absolutePath();
QVERIFY2(QDir::setCurrent(testDataDir), qPrintable("Could not chdir to " + testDataDir));
+#endif
}
void tst_QObject::disconnect()
diff --git a/tests/auto/corelib/kernel/qsharedmemory/qsharedmemory.pro b/tests/auto/corelib/kernel/qsharedmemory/qsharedmemory.pro
index a36b15c906..69062a9741 100644
--- a/tests/auto/corelib/kernel/qsharedmemory/qsharedmemory.pro
+++ b/tests/auto/corelib/kernel/qsharedmemory/qsharedmemory.pro
@@ -1,3 +1,5 @@
TEMPLATE = subdirs
-SUBDIRS = sharedmemoryhelper test
+!winrt: SUBDIRS = sharedmemoryhelper
+
+SUBDIRS += test
diff --git a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp
index a4c918ed23..b6f6d2a7f3 100644
--- a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp
+++ b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp
@@ -133,7 +133,9 @@ tst_QSharedMemory::~tst_QSharedMemory()
void tst_QSharedMemory::initTestCase()
{
+#ifndef QT_NO_PROCESS
QVERIFY2(!m_helperBinary.isEmpty(), "Could not find helper binary");
+#endif
}
void tst_QSharedMemory::init()
diff --git a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp
index 3bed64a76a..fe465df395 100644
--- a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp
+++ b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp
@@ -357,28 +357,46 @@ void tst_QAtomicIntegerXX::loadAcquireStoreRelease()
void tst_QAtomicIntegerXX::refDeref()
{
QFETCH(LargeInt, value);
- T nextValue = T(value + 1);
- T prevValue = T(value - 1);
+ const bool needToPreventOverflow = TypeIsSigned && value == std::numeric_limits<T>::max();
+ const bool needToPreventUnderflow = TypeIsSigned && value == std::numeric_limits<T>::min();
+ T nextValue = T(value);
+ if (!needToPreventOverflow)
+ ++nextValue;
+ T prevValue = T(value);
+ if (!needToPreventUnderflow)
+ --prevValue;
QAtomicInteger<T> atomic(value);
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.ref(), (nextValue != 0));
QCOMPARE(atomic.load(), nextValue);
QCOMPARE(atomic.deref(), (value != 0));
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.deref(), (prevValue != 0));
QCOMPARE(atomic.load(), prevValue);
QCOMPARE(atomic.ref(), (value != 0));
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(++atomic, nextValue);
QCOMPARE(--atomic, T(value));
+ }
+ if (!needToPreventUnderflow) {
QCOMPARE(--atomic, prevValue);
QCOMPARE(++atomic, T(value));
+ }
+ if (!needToPreventOverflow) {
QCOMPARE(atomic++, T(value));
QCOMPARE(atomic--, nextValue);
+ }
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic--, T(value));
QCOMPARE(atomic++, prevValue);
+ }
QCOMPARE(atomic.load(), T(value));
}
@@ -481,53 +499,80 @@ void tst_QAtomicIntegerXX::fetchAndAdd()
QFETCH(LargeInt, value);
QAtomicInteger<T> atomic(value);
- // note: this test has undefined behavior for signed max and min
T parcel1 = 42;
T parcel2 = T(0-parcel1);
- T newValue1 = T(value) + parcel1;
- T newValue2 = T(value) + parcel2;
+ const bool needToPreventOverflow = TypeIsSigned && value > std::numeric_limits<T>::max() + parcel2;
+ const bool needToPreventUnderflow = TypeIsSigned && value < std::numeric_limits<T>::min() + parcel1;
+
+ T newValue1 = T(value);
+ if (!needToPreventOverflow)
+ newValue1 += parcel1;
+ T newValue2 = T(value);
+ if (!needToPreventUnderflow)
+ newValue2 += parcel2;
+
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndAddRelaxed(parcel1), T(value));
QCOMPARE(atomic.load(), newValue1);
QCOMPARE(atomic.fetchAndAddRelaxed(parcel2), newValue1);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndAddRelaxed(parcel2), T(value));
QCOMPARE(atomic.load(), newValue2);
QCOMPARE(atomic.fetchAndAddRelaxed(parcel1), newValue2);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndAddAcquire(parcel1), T(value));
QCOMPARE(atomic.load(), newValue1);
QCOMPARE(atomic.fetchAndAddAcquire(parcel2), newValue1);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndAddAcquire(parcel2), T(value));
QCOMPARE(atomic.load(), newValue2);
QCOMPARE(atomic.fetchAndAddAcquire(parcel1), newValue2);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndAddRelease(parcel1), T(value));
QCOMPARE(atomic.loadAcquire(), newValue1);
QCOMPARE(atomic.fetchAndAddRelease(parcel2), newValue1);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndAddRelease(parcel2), T(value));
QCOMPARE(atomic.loadAcquire(), newValue2);
QCOMPARE(atomic.fetchAndAddRelease(parcel1), newValue2);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndAddOrdered(parcel1), T(value));
QCOMPARE(atomic.loadAcquire(), newValue1);
QCOMPARE(atomic.fetchAndAddOrdered(parcel2), newValue1);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndAddOrdered(parcel2), T(value));
QCOMPARE(atomic.loadAcquire(), newValue2);
QCOMPARE(atomic.fetchAndAddOrdered(parcel1), newValue2);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
// operator+=
+ if (!needToPreventOverflow) {
QCOMPARE(atomic += parcel1, newValue1);
QCOMPARE(atomic += parcel2, T(value));
+ }
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic += parcel2, newValue2);
QCOMPARE(atomic += parcel1, T(value));
+ }
}
void tst_QAtomicIntegerXX::fetchAndSub()
@@ -535,53 +580,80 @@ void tst_QAtomicIntegerXX::fetchAndSub()
QFETCH(LargeInt, value);
QAtomicInteger<T> atomic(value);
- // note: this test has undefined behavior for signed max and min
T parcel1 = 42;
T parcel2 = T(0-parcel1);
- T newValue1 = T(value) - parcel1;
- T newValue2 = T(value) - parcel2;
+ const bool needToPreventOverflow = TypeIsSigned && value > std::numeric_limits<T>::max() - parcel1;
+ const bool needToPreventUnderflow = TypeIsSigned && value < std::numeric_limits<T>::min() - parcel2;
+
+ T newValue1 = T(value);
+ if (!needToPreventUnderflow)
+ newValue1 -= parcel1;
+ T newValue2 = T(value);
+ if (!needToPreventOverflow)
+ newValue2 -= parcel2;
+
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndSubRelaxed(parcel1), T(value));
QCOMPARE(atomic.load(), newValue1);
QCOMPARE(atomic.fetchAndSubRelaxed(parcel2), newValue1);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndSubRelaxed(parcel2), T(value));
QCOMPARE(atomic.load(), newValue2);
QCOMPARE(atomic.fetchAndSubRelaxed(parcel1), newValue2);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndSubAcquire(parcel1), T(value));
QCOMPARE(atomic.load(), newValue1);
QCOMPARE(atomic.fetchAndSubAcquire(parcel2), newValue1);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndSubAcquire(parcel2), T(value));
QCOMPARE(atomic.load(), newValue2);
QCOMPARE(atomic.fetchAndSubAcquire(parcel1), newValue2);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndSubRelease(parcel1), T(value));
QCOMPARE(atomic.loadAcquire(), newValue1);
QCOMPARE(atomic.fetchAndSubRelease(parcel2), newValue1);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndSubRelease(parcel2), T(value));
QCOMPARE(atomic.loadAcquire(), newValue2);
QCOMPARE(atomic.fetchAndSubRelease(parcel1), newValue2);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndSubOrdered(parcel1), T(value));
QCOMPARE(atomic.loadAcquire(), newValue1);
QCOMPARE(atomic.fetchAndSubOrdered(parcel2), newValue1);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndSubOrdered(parcel2), T(value));
QCOMPARE(atomic.loadAcquire(), newValue2);
QCOMPARE(atomic.fetchAndSubOrdered(parcel1), newValue2);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
// operator-=
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic -= parcel1, newValue1);
QCOMPARE(atomic -= parcel2, T(value));
+ }
+ if (!needToPreventOverflow) {
QCOMPARE(atomic -= parcel2, newValue2);
QCOMPARE(atomic -= parcel1, T(value));
+ }
}
void tst_QAtomicIntegerXX::addSub()