diff options
Diffstat (limited to 'tests/auto/corelib/io/qprocess/tst_qprocess.cpp')
-rw-r--r-- | tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 168 |
1 files changed, 86 insertions, 82 deletions
diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 0995f764b7..caefc3fc21 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -124,9 +124,9 @@ private slots: void removeFileWhileProcessIsRunning(); void fileWriterProcess(); void switchReadChannels(); -#ifdef Q_OS_WIN + void discardUnwantedOutput(); void setWorkingDirectory(); -#endif // Q_OS_WIN + void setNonExistentWorkingDirectory(); #endif // not Q_OS_WINCE void exitStatus_data(); @@ -220,7 +220,6 @@ void tst_QProcess::getSetCheck() QCOMPARE(QProcess::ProcessChannel(QProcess::StandardError), obj1.readChannel()); } -//----------------------------------------------------------------------------- void tst_QProcess::constructing() { QProcess process; @@ -282,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; @@ -300,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 @@ -319,7 +316,6 @@ void tst_QProcess::startWithOldOpen() QVERIFY(p.waitForFinished(5000)); } -//----------------------------------------------------------------------------- void tst_QProcess::execute() { QCOMPARE(QProcess::execute("testProcessNormal/testProcessNormal", @@ -327,7 +323,6 @@ void tst_QProcess::execute() QCOMPARE(QProcess::execute("nonexistingexe"), -2); } -//----------------------------------------------------------------------------- void tst_QProcess::startDetached() { QProcess proc; @@ -339,7 +334,6 @@ void tst_QProcess::startDetached() QCOMPARE(QProcess::startDetached("nonexistingexe"), false); } -//----------------------------------------------------------------------------- void tst_QProcess::readFromProcess() { int lines = 0; @@ -349,7 +343,6 @@ void tst_QProcess::readFromProcess() } } -//----------------------------------------------------------------------------- void tst_QProcess::crashTest() { qRegisterMetaType<QProcess::ProcessState>("QProcess::ProcessState"); @@ -362,11 +355,13 @@ void tst_QProcess::crashTest() qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); - QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); - QSignalSpy spy2(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); + QSignalSpy spy(process, &QProcess::errorOccurred); + QSignalSpy spy2(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy spy3(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QVERIFY(spy.isValid()); QVERIFY(spy2.isValid()); + QVERIFY(spy3.isValid()); QVERIFY(process->waitForFinished(30000)); @@ -374,7 +369,10 @@ void tst_QProcess::crashTest() QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy.at(0).at(0).constData()), QProcess::Crashed); QCOMPARE(spy2.count(), 1); - QCOMPARE(*static_cast<const QProcess::ExitStatus *>(spy2.at(0).at(1).constData()), QProcess::CrashExit); + QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy2.at(0).at(0).constData()), QProcess::Crashed); + + QCOMPARE(spy3.count(), 1); + QCOMPARE(*static_cast<const QProcess::ExitStatus *>(spy3.at(0).at(1).constData()), QProcess::CrashExit); QCOMPARE(process->exitStatus(), QProcess::CrashExit); @@ -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; @@ -397,7 +394,7 @@ void tst_QProcess::crashTest2() qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); - QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::errorOccurred)); QSignalSpy spy2(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QVERIFY(spy.isValid()); @@ -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() @@ -688,8 +675,10 @@ void tst_QProcess::readTimeoutAndThenCrash() QCOMPARE(process->error(), QProcess::Timedout); qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); - QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy spy(process, &QProcess::errorOccurred); + QSignalSpy spy2(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QVERIFY(spy.isValid()); + QVERIFY(spy2.isValid()); process->kill(); @@ -698,6 +687,8 @@ void tst_QProcess::readTimeoutAndThenCrash() QCOMPARE(spy.count(), 1); QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy.at(0).at(0).constData()), QProcess::Crashed); + QCOMPARE(spy2.count(), 1); + QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy2.at(0).at(0).constData()), QProcess::Crashed); delete process; process = 0; @@ -750,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() @@ -780,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() @@ -808,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() @@ -840,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() @@ -885,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() @@ -921,7 +907,6 @@ void tst_QProcess::emitReadyReadOnlyWhenNewDataArrives() } #endif -//----------------------------------------------------------------------------- void tst_QProcess::hardExit() { QProcess proc; @@ -945,7 +930,6 @@ void tst_QProcess::hardExit() QCOMPARE(int(proc.error()), int(QProcess::Crashed)); } -//----------------------------------------------------------------------------- void tst_QProcess::softExit() { QProcess proc; @@ -1055,7 +1039,6 @@ private: QByteArray dataToWrite; }; -//----------------------------------------------------------------------------- void tst_QProcess::softExitInSlots_data() { QTest::addColumn<QString>("appName"); @@ -1065,7 +1048,6 @@ void tst_QProcess::softExitInSlots_data() #endif QTest::newRow("console app") << "testProcessEcho2/testProcessEcho2"; } -//----------------------------------------------------------------------------- void tst_QProcess::softExitInSlots() { @@ -1081,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() @@ -1106,7 +1087,6 @@ void tst_QProcess::mergedChannels() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE @@ -1161,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() @@ -1222,7 +1201,6 @@ private: int exitCode; }; -//----------------------------------------------------------------------------- void tst_QProcess::processInAThread() { for (int i = 0; i < 10; ++i) { @@ -1233,7 +1211,6 @@ void tst_QProcess::processInAThread() } } -//----------------------------------------------------------------------------- void tst_QProcess::processesInMultipleThreads() { for (int i = 0; i < 10; ++i) { @@ -1258,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() @@ -1279,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() @@ -1308,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() @@ -1320,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() @@ -1347,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() @@ -1357,7 +1329,7 @@ void tst_QProcess::waitForBytesWrittenInABytesWrittenSlotSlot() QTestEventLoop::instance().exitLoop(); } #endif -//----------------------------------------------------------------------------- + void tst_QProcess::spaceArgsTest_data() { QTest::addColumn<QStringList>("args"); @@ -1410,7 +1382,6 @@ static QByteArray startFailMessage(const QString &program, const QProcess &proce return result; } -//----------------------------------------------------------------------------- void tst_QProcess::spaceArgsTest() { QFETCH(QStringList, args); @@ -1483,7 +1454,6 @@ void tst_QProcess::spaceArgsTest() #if defined(Q_OS_WIN) -//----------------------------------------------------------------------------- void tst_QProcess::nativeArguments() { QProcess proc; @@ -1527,7 +1497,6 @@ void tst_QProcess::nativeArguments() #endif -//----------------------------------------------------------------------------- void tst_QProcess::exitCodeTest() { for (int i = 0; i < 255; ++i) { @@ -1544,7 +1513,6 @@ void tst_QProcess::exitCodeTest() } } -//----------------------------------------------------------------------------- void tst_QProcess::failToStart() { #if defined(QPROCESS_USE_SPAWN) && !defined(Q_OS_QNX) @@ -1556,12 +1524,14 @@ void tst_QProcess::failToStart() QProcess process; QSignalSpy stateSpy(&process, &QProcess::stateChanged); - QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy errorSpy(&process, &QProcess::errorOccurred); + QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QSignalSpy finishedSpy(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QVERIFY(stateSpy.isValid()); QVERIFY(errorSpy.isValid()); + QVERIFY(errorSpy2.isValid()); QVERIFY(finishedSpy.isValid()); QVERIFY(finishedSpy2.isValid()); @@ -1578,6 +1548,7 @@ void tst_QProcess::failToStart() for (int j = 0; j < 8; ++j) { for (int i = 0; i < attempts; ++i) { QCOMPARE(errorSpy.count(), j * attempts + i); + QCOMPARE(errorSpy2.count(), j * attempts + i); process.start("/blurp"); switch (j) { @@ -1602,6 +1573,7 @@ void tst_QProcess::failToStart() QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(errorSpy.count(), j * attempts + i + 1); + QCOMPARE(errorSpy2.count(), j * attempts + i + 1); QCOMPARE(finishedSpy.count(), 0); QCOMPARE(finishedSpy2.count(), 0); @@ -1614,7 +1586,6 @@ void tst_QProcess::failToStart() } } -//----------------------------------------------------------------------------- void tst_QProcess::failToStartWithWait() { #if defined(QPROCESS_USE_SPAWN) && !defined(Q_OS_QNX) @@ -1625,11 +1596,13 @@ void tst_QProcess::failToStartWithWait() QProcess process; QEventLoop loop; - QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy errorSpy(&process, &QProcess::errorOccurred); + QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QSignalSpy finishedSpy(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QVERIFY(errorSpy.isValid()); + QVERIFY(errorSpy2.isValid()); QVERIFY(finishedSpy.isValid()); QVERIFY(finishedSpy2.isValid()); @@ -1639,12 +1612,12 @@ void tst_QProcess::failToStartWithWait() QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(errorSpy.count(), i + 1); + QCOMPARE(errorSpy2.count(), i + 1); QCOMPARE(finishedSpy.count(), 0); QCOMPARE(finishedSpy2.count(), 0); } } -//----------------------------------------------------------------------------- void tst_QProcess::failToStartWithEventLoop() { #if defined(QPROCESS_USE_SPAWN) && !defined(Q_OS_QNX) @@ -1655,16 +1628,18 @@ void tst_QProcess::failToStartWithEventLoop() QProcess process; QEventLoop loop; - QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy errorSpy(&process, &QProcess::errorOccurred); + QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QSignalSpy finishedSpy(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QVERIFY(errorSpy.isValid()); + QVERIFY(errorSpy2.isValid()); QVERIFY(finishedSpy.isValid()); QVERIFY(finishedSpy2.isValid()); // The error signal may be emitted before start() returns - connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()), Qt::QueuedConnection); + connect(&process, &QProcess::errorOccurred, &loop, &QEventLoop::quit, Qt::QueuedConnection); for (int i = 0; i < 50; ++i) { @@ -1674,6 +1649,7 @@ void tst_QProcess::failToStartWithEventLoop() QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(errorSpy.count(), i + 1); + QCOMPARE(errorSpy2.count(), i + 1); QCOMPARE(finishedSpy.count(), 0); QCOMPARE(finishedSpy2.count(), 0); } @@ -1715,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() @@ -1734,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() @@ -1812,7 +1786,6 @@ void tst_QProcess::setEnvironment() } } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // OS doesn't support environment variables void tst_QProcess::setProcessEnvironment_data() @@ -1853,7 +1826,7 @@ void tst_QProcess::setProcessEnvironment() } } #endif -//----------------------------------------------------------------------------- + void tst_QProcess::systemEnvironment() { #if defined (Q_OS_WINCE) @@ -1869,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() @@ -1882,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 @@ -1896,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() @@ -1915,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 @@ -1923,11 +1892,13 @@ void tst_QProcess::waitForReadyReadForNonexistantProcess() qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); QProcess process; - QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy errorSpy(&process, &QProcess::errorOccurred); + QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QSignalSpy finishedSpy1(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QVERIFY(errorSpy.isValid()); + QVERIFY(errorSpy2.isValid()); QVERIFY(finishedSpy1.isValid()); QVERIFY(finishedSpy2.isValid()); @@ -1939,11 +1910,12 @@ void tst_QProcess::waitForReadyReadForNonexistantProcess() #endif QCOMPARE(errorSpy.count(), 1); QCOMPARE(errorSpy.at(0).at(0).toInt(), 0); + QCOMPARE(errorSpy2.count(), 1); + QCOMPARE(errorSpy2.at(0).at(0).toInt(), 0); QCOMPARE(finishedSpy1.count(), 0); QCOMPARE(finishedSpy2.count(), 0); } -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::setStandardInputFile() @@ -1973,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() @@ -2004,7 +1975,6 @@ void tst_QProcess::setStandardOutputFile_data() << true; } -//----------------------------------------------------------------------------- void tst_QProcess::setStandardOutputFile() { static const char data[] = "Original data. "; @@ -2089,7 +2059,6 @@ void tst_QProcess::setStandardOutputFileAndWaitForBytesWritten() } #endif -//----------------------------------------------------------------------------- #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::setStandardOutputProcess_data() @@ -2130,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() @@ -2158,7 +2126,6 @@ void tst_QProcess::fileWriterProcess() } #endif -//----------------------------------------------------------------------------- void tst_QProcess::detachedWorkingDirectoryAndPid() { qint64 pid; @@ -2202,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() @@ -2233,16 +2199,38 @@ void tst_QProcess::switchReadChannels() } #endif -//----------------------------------------------------------------------------- -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +#ifndef Q_OS_WINCE +// Reading and writing to a process is not supported on Qt/CE +void tst_QProcess::discardUnwantedOutput() +{ + QProcess process; + + process.setProgram("testProcessEcho2/testProcessEcho2"); + process.start(QIODevice::WriteOnly); + process.write("Hello, World"); + process.closeWriteChannel(); + QVERIFY(process.waitForFinished(5000)); + + process.setReadChannel(QProcess::StandardOutput); + QCOMPARE(process.bytesAvailable(), Q_INT64_C(0)); + process.setReadChannel(QProcess::StandardError); + QCOMPARE(process.bytesAvailable(), Q_INT64_C(0)); +} +#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 void tst_QProcess::setWorkingDirectory() { process = new QProcess; process->setWorkingDirectory("test"); - process->start("testSetWorkingDirectory/testSetWorkingDirectory"); - QVERIFY(process->waitForFinished()); + + // use absolute path because on Windows, the executable is relative to the parent's CWD + // while on Unix with fork it's relative to the child's (with posix_spawn, it could be either). + process->start(QFileInfo("testSetWorkingDirectory/testSetWorkingDirectory").absoluteFilePath()); + + QVERIFY2(process->waitForFinished(), process->errorString().toLocal8Bit()); QByteArray workingDir = process->readAllStandardOutput(); QCOMPARE(QDir("test").canonicalPath(), QDir(workingDir.constData()).canonicalPath()); @@ -2250,9 +2238,26 @@ void tst_QProcess::setWorkingDirectory() delete process; process = 0; } + +void tst_QProcess::setNonExistentWorkingDirectory() +{ + process = new QProcess; + process->setWorkingDirectory("this/directory/should/not/exist/for/sure"); + + // use absolute path because on Windows, the executable is relative to the parent's CWD + // while on Unix with fork it's relative to the child's (with posix_spawn, it could be either). + process->start(QFileInfo("testSetWorkingDirectory/testSetWorkingDirectory").absoluteFilePath()); + QVERIFY(!process->waitForFinished()); +#ifdef QPROCESS_USE_SPAWN + QEXPECT_FAIL("", "QProcess cannot detect failure to start when using posix_spawn()", Continue); +#endif + QCOMPARE(int(process->error()), int(QProcess::FailedToStart)); + + delete process; + process = 0; +} #endif -//----------------------------------------------------------------------------- void tst_QProcess::startFinishStartFinish() { QProcess process; @@ -2271,7 +2276,6 @@ void tst_QProcess::startFinishStartFinish() } } -//----------------------------------------------------------------------------- void tst_QProcess::invalidProgramString_data() { QTest::addColumn<QString>("programString"); @@ -2286,17 +2290,19 @@ void tst_QProcess::invalidProgramString() QProcess process; qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); - QSignalSpy spy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy spy(&process, &QProcess::errorOccurred); + QSignalSpy spy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QVERIFY(spy.isValid()); + QVERIFY(spy2.isValid()); process.start(programString); QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(spy.count(), 1); + QCOMPARE(spy2.count(), 1); QVERIFY(!QProcess::startDetached(programString)); } -//----------------------------------------------------------------------------- void tst_QProcess::onlyOneStartedSignal() { qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); @@ -2323,8 +2329,6 @@ void tst_QProcess::onlyOneStartedSignal() QCOMPARE(spyFinished.count(), 1); } -//----------------------------------------------------------------------------- - class BlockOnReadStdOut : public QObject { Q_OBJECT |