From 883b120d2f39c532cdd1a98d962af83be5adc4bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christian=20Str=C3=B8mme?= Date: Fri, 3 Jun 2011 17:55:09 +0200 Subject: [PATCH] Fix QProcess emitting two started signals on X11 On X11 QProcess would emit two started signals when calling QProcess::waitForStarted(). We should expect that the private implementation of waitForStarted() should emit the started signal and return true or false appropriately. Task-number: QTBUG-7039 Change-Id: I3d381399ab7a39bf57db03a110fa6747a4fc6a24 Reviewed-by: pending Reviewed-on: http://codereview.qt.nokia.com/331 Reviewed-by: Thiago Macieira --- src/corelib/io/qprocess.cpp | 11 ++++------- tests/auto/qprocess/tst_qprocess.cpp | 28 ++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 70a70c2..af43ab7 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1673,13 +1673,10 @@ QProcessEnvironment QProcess::processEnvironment() const bool QProcess::waitForStarted(int msecs) { Q_D(QProcess); - if (d->processState == QProcess::Starting) { - if (!d->waitForStarted(msecs)) - return false; - setProcessState(QProcess::Running); - emit started(); - } - return d->processState == QProcess::Running; + if (d->processState == QProcess::Running) + return true; + + return d->waitForStarted(msecs); } /*! \reimp diff --git a/tests/auto/qprocess/tst_qprocess.cpp b/tests/auto/qprocess/tst_qprocess.cpp index 91e0abe..f54dfa3 100644 --- a/tests/auto/qprocess/tst_qprocess.cpp +++ b/tests/auto/qprocess/tst_qprocess.cpp @@ -73,7 +73,7 @@ Q_DECLARE_METATYPE(QProcess::ProcessState); { \ const bool ret = Process.Fn; \ if (ret == false) \ - qWarning("QProcess error: %d: %s", Process.error(), qPrintable(Process.errorString())); \ + qWarning("QProcess error: %d: %s", Process.error(), qPrintable(Process.errorString())); \ QVERIFY(ret); \ } @@ -157,6 +157,7 @@ private slots: void startFinishStartFinish(); void invalidProgramString_data(); void invalidProgramString(); + void onlyOneStartedSignal(); // 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) @@ -2089,7 +2090,7 @@ void tst_QProcess::setStandardInputFile() #endif QPROCESS_VERIFY(process, waitForFinished()); - QByteArray all = process.readAll(); + QByteArray all = process.readAll(); QCOMPARE(all.size(), int(sizeof data) - 1); // testProcessEcho drops the ending \0 QVERIFY(all == data); } @@ -2442,6 +2443,29 @@ void tst_QProcess::invalidProgramString() QVERIFY(!QProcess::startDetached(programString)); } +//----------------------------------------------------------------------------- +void tst_QProcess::onlyOneStartedSignal() +{ + QProcess process; + + QSignalSpy spyStarted(&process, SIGNAL(started())); + QSignalSpy spyFinished(&process, SIGNAL(finished(int, QProcess::ExitStatus))); + + process.start("testProcessNormal/testProcessNormal"); + QVERIFY(process.waitForStarted(5000)); + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(spyStarted.count(), 1); + QCOMPARE(spyFinished.count(), 1); + + spyStarted.clear(); + spyFinished.clear(); + + process.start("testProcessNormal/testProcessNormal"); + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(spyStarted.count(), 1); + QCOMPARE(spyFinished.count(), 1); +} + QTEST_MAIN(tst_QProcess) #include "tst_qprocess.moc" #endif -- 2.7.4