diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index e16e00de91..2d5b879c41 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -1000,9 +1000,21 @@ public: } } + void writeAfterStart(const char *buf, int count) + { + dataToWrite = QByteArray(buf, count); + } + + void start(const QString &program) + { + QProcess::start(program); + writePendingData(); + } + public slots: void terminateSlot() { + writePendingData(); // In cases 3 and 4 we haven't written the data yet. if (killing || (n == 4 && state() != Running)) { // Don't try to kill the process before it is running - that can // be hazardous, as the actual child process might not be running @@ -1024,9 +1036,19 @@ public slots: waitedForFinished = true; } +private: + void writePendingData() + { + if (!dataToWrite.isEmpty()) { + write(dataToWrite); + dataToWrite.clear(); + } + } + private: int n; bool killing; + QByteArray dataToWrite; }; //----------------------------------------------------------------------------- @@ -1049,11 +1071,10 @@ void tst_QProcess::softExitInSlots() for (int i = 0; i < 5; ++i) { SoftExitProcess proc(i); + proc.writeAfterStart("OLEBOLE", 8); // include the \0 proc.start(appName); - proc.write("OLEBOLE", 8); // include the \0 - QTestEventLoop::instance().enterLoop(10); + QTRY_VERIFY(proc.waitedForFinished); QCOMPARE(proc.state(), QProcess::NotRunning); - QVERIFY(proc.waitedForFinished); } }