diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2017-05-30 13:53:33 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2017-06-13 16:49:38 +0000 |
commit | 7ad55ca65f42351e231f31f7a9253ae6eaf1ebb3 (patch) | |
tree | 580e4f422f13456c5019449e342b664e917e3afd /tests/auto/corelib/io/qprocess/tst_qprocess.cpp | |
parent | 424d9e9e56314bae09a0dcbf09be0e3c0c9e0ac6 (diff) |
Support standard channel redirection in QProcess::startDetached
[ChangeLog][QtCore][QProcess] Added support for standard channel
redirection using setStandard{Input|Output|Error}File to
QProcess::startDetached.
Task-number: QTBUG-2058
Task-number: QTBUG-37656
Change-Id: Iafb9bd7899f752d0305e3410ad4dcb7ef598dc79
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/io/qprocess/tst_qprocess.cpp')
-rw-r--r-- | tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index f8268f5991..6b1516600f 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -126,6 +126,7 @@ private slots: void systemEnvironment(); void lockupsInStartDetached(); void waitForReadyReadForNonexistantProcess(); + void detachedProcessParameters_data(); void detachedProcessParameters(); void startFinishStartFinish(); void invalidProgramString_data(); @@ -2030,13 +2031,25 @@ void tst_QProcess::fileWriterProcess() } while (stopWatch.elapsed() < 3000); } +void tst_QProcess::detachedProcessParameters_data() +{ + QTest::addColumn<QString>("outChannel"); + QTest::newRow("none") << QString(); + QTest::newRow("stdout") << QString("stdout"); + QTest::newRow("stderr") << QString("stderr"); +} + void tst_QProcess::detachedProcessParameters() { + QFETCH(QString, outChannel); qint64 pid; QFile infoFile(m_temporaryDir.path() + QLatin1String("/detachedinfo.txt")); if (infoFile.exists()) QVERIFY(infoFile.remove()); + QFile channelFile(m_temporaryDir.path() + QLatin1String("detachedinfo2.txt")); + if (channelFile.exists()) + QVERIFY(channelFile.remove()); QString workingDir = QDir::currentPath() + "/testDetached"; @@ -2054,7 +2067,15 @@ void tst_QProcess::detachedProcessParameters() process.setCreateProcessArgumentsModifier( [&modifierCalls] (QProcess::CreateProcessArguments *) { modifierCalls++; }); #endif - process.setArguments(QStringList(infoFile.fileName())); + QStringList args(infoFile.fileName()); + if (!outChannel.isEmpty()) { + args << QStringLiteral("--out-channel=") + outChannel; + if (outChannel == "stdout") + process.setStandardOutputFile(channelFile.fileName()); + else if (outChannel == "stderr") + process.setStandardErrorFile(channelFile.fileName()); + } + process.setArguments(args); process.setWorkingDirectory(workingDir); process.setProcessEnvironment(environment); QVERIFY(process.startDetached(&pid)); @@ -2071,9 +2092,22 @@ void tst_QProcess::detachedProcessParameters() QString actualWorkingDir = QString::fromUtf8(infoFile.readLine()).trimmed(); QByteArray processIdString = infoFile.readLine().trimmed(); QByteArray actualEnvVarValue = infoFile.readLine().trimmed(); + QByteArray infoFileContent; + if (!outChannel.isEmpty()) { + infoFile.seek(0); + infoFileContent = infoFile.readAll(); + } infoFile.close(); infoFile.remove(); + if (!outChannel.isEmpty()) { + QVERIFY(channelFile.open(QIODevice::ReadOnly | QIODevice::Text)); + QByteArray channelContent = channelFile.readAll(); + channelFile.close(); + channelFile.remove(); + QCOMPARE(channelContent, infoFileContent); + } + bool ok = false; qint64 actualPid = processIdString.toLongLong(&ok); QVERIFY(ok); |