tst_qprocess: Port to Qt 5 connection syntax.

Task-number: QTBUG-47370
Change-Id: I09489a6fb4598238fa5e0120bf751fe5af6f31af
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2015-09-25 11:29:10 +02:00
parent 4954ad6dbc
commit f322e2aa08

View File

@ -62,6 +62,10 @@ if (ret == false) \
QVERIFY(ret); \ QVERIFY(ret); \
} }
typedef void (QProcess::*QProcessFinishedSignal1)(int);
typedef void (QProcess::*QProcessFinishedSignal2)(int, QProcess::ExitStatus);
typedef void (QProcess::*QProcessErrorSignal)(QProcess::ProcessError);
class tst_QProcess : public QObject class tst_QProcess : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -260,7 +264,7 @@ void tst_QProcess::simpleStart()
process = new QProcess; process = new QProcess;
QSignalSpy spy(process, &QProcess::stateChanged); QSignalSpy spy(process, &QProcess::stateChanged);
QVERIFY(spy.isValid()); QVERIFY(spy.isValid());
connect(process, SIGNAL(readyRead()), this, SLOT(readFromProcess())); connect(process, &QIODevice::readyRead, this, &tst_QProcess::readFromProcess);
/* valgrind dislike SUID binaries(those that have the `s'-flag set), which /* valgrind dislike SUID binaries(those that have the `s'-flag set), which
* makes it fail to start the process. For this reason utilities like `ping' won't * makes it fail to start the process. For this reason utilities like `ping' won't
@ -356,8 +360,8 @@ void tst_QProcess::crashTest()
qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus");
QSignalSpy spy(process, &QProcess::errorOccurred); QSignalSpy spy(process, &QProcess::errorOccurred);
QSignalSpy spy2(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QSignalSpy spy2(process, static_cast<QProcessErrorSignal>(&QProcess::error));
QSignalSpy spy3(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QSignalSpy spy3(process, static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QVERIFY(spy.isValid()); QVERIFY(spy.isValid());
QVERIFY(spy2.isValid()); QVERIFY(spy2.isValid());
@ -394,13 +398,14 @@ void tst_QProcess::crashTest2()
qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError");
qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus");
QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::errorOccurred)); QSignalSpy spy(process, static_cast<QProcessErrorSignal>(&QProcess::errorOccurred));
QSignalSpy spy2(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QSignalSpy spy2(process, static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QVERIFY(spy.isValid()); QVERIFY(spy.isValid());
QVERIFY(spy2.isValid()); QVERIFY(spy2.isValid());
QObject::connect(process, SIGNAL(finished(int)), this, SLOT(exitLoopSlot())); QObject::connect(process, static_cast<QProcessFinishedSignal1>(&QProcess::finished),
this, &tst_QProcess::exitLoopSlot);
QTestEventLoop::instance().enterLoop(30); QTestEventLoop::instance().enterLoop(30);
if (QTestEventLoop::instance().timeout()) if (QTestEventLoop::instance().timeout())
@ -439,7 +444,7 @@ void tst_QProcess::echoTest()
QFETCH(QByteArray, input); QFETCH(QByteArray, input);
process = new QProcess; process = new QProcess;
connect(process, SIGNAL(readyRead()), this, SLOT(exitLoopSlot())); connect(process, &QIODevice::readyRead, this, &tst_QProcess::exitLoopSlot);
process->start("testProcessEcho/testProcessEcho"); process->start("testProcessEcho/testProcessEcho");
QVERIFY(process->waitForStarted(5000)); QVERIFY(process->waitForStarted(5000));
@ -489,7 +494,7 @@ void tst_QProcess::echoTest2()
{ {
process = new QProcess; process = new QProcess;
connect(process, SIGNAL(readyRead()), this, SLOT(exitLoopSlot())); connect(process, &QIODevice::readyRead, this, &tst_QProcess::exitLoopSlot);
process->start("testProcessEcho2/testProcessEcho2"); process->start("testProcessEcho2/testProcessEcho2");
QVERIFY(process->waitForStarted(5000)); QVERIFY(process->waitForStarted(5000));
@ -676,7 +681,7 @@ void tst_QProcess::readTimeoutAndThenCrash()
qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError");
QSignalSpy spy(process, &QProcess::errorOccurred); QSignalSpy spy(process, &QProcess::errorOccurred);
QSignalSpy spy2(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QSignalSpy spy2(process, static_cast<QProcessErrorSignal>(&QProcess::error));
QVERIFY(spy.isValid()); QVERIFY(spy.isValid());
QVERIFY(spy2.isValid()); QVERIFY(spy2.isValid());
@ -751,14 +756,15 @@ void tst_QProcess::restartProcessDeadlock()
// because of the way QProcessManager uses its locks. // because of the way QProcessManager uses its locks.
QProcess proc; QProcess proc;
process = &proc; process = &proc;
connect(process, SIGNAL(finished(int)), this, SLOT(restartProcess())); connect(process, static_cast<QProcessFinishedSignal1>(&QProcess::finished),
this, &tst_QProcess::restartProcess);
process->start("testProcessEcho/testProcessEcho"); process->start("testProcessEcho/testProcessEcho");
QCOMPARE(process->write("", 1), qlonglong(1)); QCOMPARE(process->write("", 1), qlonglong(1));
QVERIFY(process->waitForFinished(5000)); QVERIFY(process->waitForFinished(5000));
process->disconnect(SIGNAL(finished(int))); QObject::disconnect(process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), Q_NULLPTR, Q_NULLPTR);
QCOMPARE(process->write("", 1), qlonglong(1)); QCOMPARE(process->write("", 1), qlonglong(1));
QVERIFY(process->waitForFinished(5000)); QVERIFY(process->waitForFinished(5000));
@ -878,7 +884,7 @@ void tst_QProcess::emitReadyReadOnlyWhenNewDataArrives()
{ {
QProcess proc; QProcess proc;
connect(&proc, SIGNAL(readyRead()), this, SLOT(exitLoopSlot())); connect(&proc, &QIODevice::readyRead, this, &tst_QProcess::exitLoopSlot);
QSignalSpy spy(&proc, &QProcess::readyRead); QSignalSpy spy(&proc, &QProcess::readyRead);
QVERIFY(spy.isValid()); QVERIFY(spy.isValid());
@ -898,7 +904,7 @@ void tst_QProcess::emitReadyReadOnlyWhenNewDataArrives()
QVERIFY(QTestEventLoop::instance().timeout()); QVERIFY(QTestEventLoop::instance().timeout());
QVERIFY(!proc.waitForReadyRead(250)); QVERIFY(!proc.waitForReadyRead(250));
QObject::disconnect(&proc, SIGNAL(readyRead()), 0, 0); QObject::disconnect(&proc, &QIODevice::readyRead, Q_NULLPTR, Q_NULLPTR);
proc.write("B"); proc.write("B");
QVERIFY(proc.waitForReadyRead(5000)); QVERIFY(proc.waitForReadyRead(5000));
@ -960,30 +966,30 @@ public:
SoftExitProcess(int n) : waitedForFinished(false), n(n), killing(false) SoftExitProcess(int n) : waitedForFinished(false), n(n), killing(false)
{ {
connect(this, SIGNAL(finished(int,QProcess::ExitStatus)), connect(this, static_cast<QProcessFinishedSignal2>(&QProcess::finished),
this, SLOT(finishedSlot(int,QProcess::ExitStatus))); this, &SoftExitProcess::finishedSlot);
switch (n) { switch (n) {
case 0: case 0:
setReadChannelMode(QProcess::MergedChannels); setReadChannelMode(QProcess::MergedChannels);
connect(this, SIGNAL(readyRead()), this, SLOT(terminateSlot())); connect(this, &QIODevice::readyRead, this, &SoftExitProcess::terminateSlot);
break; break;
case 1: case 1:
connect(this, SIGNAL(readyReadStandardOutput()), connect(this, &QProcess::readyReadStandardOutput,
this, SLOT(terminateSlot())); this, &SoftExitProcess::terminateSlot);
break; break;
case 2: case 2:
connect(this, SIGNAL(readyReadStandardError()), connect(this, &QProcess::readyReadStandardError,
this, SLOT(terminateSlot())); this, &SoftExitProcess::terminateSlot);
break; break;
case 3: case 3:
connect(this, SIGNAL(started()), connect(this, &QProcess::started,
this, SLOT(terminateSlot())); this, &SoftExitProcess::terminateSlot);
break; break;
case 4: case 4:
default: default:
connect(this, SIGNAL(stateChanged(QProcess::ProcessState)), connect(this, &QProcess::stateChanged,
this, SLOT(terminateSlot())); this, &SoftExitProcess::terminateSlot);
break; break;
} }
} }
@ -1179,8 +1185,8 @@ protected:
exitCode = 90210; exitCode = 90210;
QProcess process; QProcess process;
connect(&process, SIGNAL(finished(int)), this, SLOT(catchExitCode(int)), connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished),
Qt::DirectConnection); this, &TestThread::catchExitCode, Qt::DirectConnection);
process.start("testProcessEcho/testProcessEcho"); process.start("testProcessEcho/testProcessEcho");
@ -1260,8 +1266,9 @@ void tst_QProcess::waitForFinishedWithTimeout()
void tst_QProcess::waitForReadyReadInAReadyReadSlot() void tst_QProcess::waitForReadyReadInAReadyReadSlot()
{ {
process = new QProcess(this); process = new QProcess(this);
connect(process, SIGNAL(readyRead()), this, SLOT(waitForReadyReadInAReadyReadSlotSlot())); connect(process, &QIODevice::readyRead, this, &tst_QProcess::waitForReadyReadInAReadyReadSlotSlot);
connect(process, SIGNAL(finished(int)), this, SLOT(exitLoopSlot())); connect(process, static_cast<QProcessFinishedSignal1>(&QProcess::finished),
this, &tst_QProcess::exitLoopSlot);
bytesAvailable = 0; bytesAvailable = 0;
process->start("testProcessEcho/testProcessEcho"); process->start("testProcessEcho/testProcessEcho");
@ -1299,7 +1306,7 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlotSlot()
void tst_QProcess::waitForBytesWrittenInABytesWrittenSlot() void tst_QProcess::waitForBytesWrittenInABytesWrittenSlot()
{ {
process = new QProcess(this); process = new QProcess(this);
connect(process, SIGNAL(bytesWritten(qint64)), this, SLOT(waitForBytesWrittenInABytesWrittenSlotSlot())); connect(process, &QIODevice::bytesWritten, this, &tst_QProcess::waitForBytesWrittenInABytesWrittenSlotSlot);
bytesAvailable = 0; bytesAvailable = 0;
process->start("testProcessEcho/testProcessEcho"); process->start("testProcessEcho/testProcessEcho");
@ -1525,9 +1532,9 @@ void tst_QProcess::failToStart()
QProcess process; QProcess process;
QSignalSpy stateSpy(&process, &QProcess::stateChanged); QSignalSpy stateSpy(&process, &QProcess::stateChanged);
QSignalSpy errorSpy(&process, &QProcess::errorOccurred); QSignalSpy errorSpy(&process, &QProcess::errorOccurred);
QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error));
QSignalSpy finishedSpy(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished));
QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QVERIFY(stateSpy.isValid()); QVERIFY(stateSpy.isValid());
QVERIFY(errorSpy.isValid()); QVERIFY(errorSpy.isValid());
@ -1597,9 +1604,9 @@ void tst_QProcess::failToStartWithWait()
QProcess process; QProcess process;
QEventLoop loop; QEventLoop loop;
QSignalSpy errorSpy(&process, &QProcess::errorOccurred); QSignalSpy errorSpy(&process, &QProcess::errorOccurred);
QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error));
QSignalSpy finishedSpy(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished));
QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QVERIFY(errorSpy.isValid()); QVERIFY(errorSpy.isValid());
QVERIFY(errorSpy2.isValid()); QVERIFY(errorSpy2.isValid());
@ -1629,9 +1636,9 @@ void tst_QProcess::failToStartWithEventLoop()
QProcess process; QProcess process;
QEventLoop loop; QEventLoop loop;
QSignalSpy errorSpy(&process, &QProcess::errorOccurred); QSignalSpy errorSpy(&process, &QProcess::errorOccurred);
QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error));
QSignalSpy finishedSpy(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished));
QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QVERIFY(errorSpy.isValid()); QVERIFY(errorSpy.isValid());
QVERIFY(errorSpy2.isValid()); QVERIFY(errorSpy2.isValid());
@ -1669,7 +1676,7 @@ void tst_QProcess::failToStartEmptyArgs()
qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError");
QProcess process; QProcess process;
QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QSignalSpy errorSpy(&process, static_cast<QProcessErrorSignal>(&QProcess::error));
QVERIFY(errorSpy.isValid()); QVERIFY(errorSpy.isValid());
switch (startOverload) { switch (startOverload) {
@ -1893,9 +1900,9 @@ void tst_QProcess::waitForReadyReadForNonexistantProcess()
QProcess process; QProcess process;
QSignalSpy errorSpy(&process, &QProcess::errorOccurred); QSignalSpy errorSpy(&process, &QProcess::errorOccurred);
QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error));
QSignalSpy finishedSpy1(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); QSignalSpy finishedSpy1(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished));
QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QVERIFY(errorSpy.isValid()); QVERIFY(errorSpy.isValid());
QVERIFY(errorSpy2.isValid()); QVERIFY(errorSpy2.isValid());
@ -2291,7 +2298,7 @@ void tst_QProcess::invalidProgramString()
qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError");
QSignalSpy spy(&process, &QProcess::errorOccurred); QSignalSpy spy(&process, &QProcess::errorOccurred);
QSignalSpy spy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); QSignalSpy spy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error));
QVERIFY(spy.isValid()); QVERIFY(spy.isValid());
QVERIFY(spy2.isValid()); QVERIFY(spy2.isValid());
@ -2309,7 +2316,7 @@ void tst_QProcess::onlyOneStartedSignal()
QProcess process; QProcess process;
QSignalSpy spyStarted(&process, &QProcess::started); QSignalSpy spyStarted(&process, &QProcess::started);
QSignalSpy spyFinished(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); QSignalSpy spyFinished(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QVERIFY(spyStarted.isValid()); QVERIFY(spyStarted.isValid());
QVERIFY(spyFinished.isValid()); QVERIFY(spyFinished.isValid());
@ -2335,7 +2342,7 @@ class BlockOnReadStdOut : public QObject
public: public:
BlockOnReadStdOut(QProcess *process) BlockOnReadStdOut(QProcess *process)
{ {
connect(process, SIGNAL(readyReadStandardOutput()), SLOT(block())); connect(process, &QProcess::readyReadStandardOutput, this, &BlockOnReadStdOut::block);
} }
public slots: public slots:
@ -2350,7 +2357,8 @@ void tst_QProcess::finishProcessBeforeReadingDone()
QProcess process; QProcess process;
BlockOnReadStdOut blocker(&process); BlockOnReadStdOut blocker(&process);
QEventLoop loop; QEventLoop loop;
connect(&process, SIGNAL(finished(int)), &loop, SLOT(quit())); connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished),
&loop, &QEventLoop::quit);
process.start("testProcessOutput/testProcessOutput"); process.start("testProcessOutput/testProcessOutput");
QVERIFY(process.waitForStarted()); QVERIFY(process.waitForStarted());
loop.exec(); loop.exec();