diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2023-03-18 12:37:51 -0700 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-05-15 19:10:03 +0200 |
commit | 48b6c8503ae92a0480f8a1a63d979e689ae34a80 (patch) | |
tree | c20ed17f0f0e1d2c0c14c80a922655322c21fca2 /tests | |
parent | fb40737b0db8ab9f6f7f7ecdc17e5819545f041b (diff) |
QProcess/Unix: enable setChildProcessModifier for startDetached
Do this by making the actual child-execution code common between
startProcess() and startDetached(). It does mean we've moved the chdir()
operation from the child to the grandchild process, though.
[ChangeLog][QtCore][QProcess] The modifier function set with
setChildProcessModifier() will now also be executed when the process is
started with startDetached().
Change-Id: Icfe44ecf285a480fafe4fffd174d9aa57dd7dfff
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index f51721e966..285126b826 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -111,6 +111,7 @@ private slots: void createProcessArgumentsModifier(); #endif // Q_OS_WIN #if defined(Q_OS_UNIX) + void setChildProcessModifier_data(); void setChildProcessModifier(); void throwInChildProcessModifier(); #endif @@ -1446,8 +1447,16 @@ static void childProcessModifier(int fd) QT_CLOSE(fd); } +void tst_QProcess::setChildProcessModifier_data() +{ + QTest::addColumn<bool>("detached"); + QTest::newRow("normal") << false; + QTest::newRow("detached") << true; +} + void tst_QProcess::setChildProcessModifier() { + QFETCH(bool, detached); int pipes[2] = { -1 , -1 }; QVERIFY(qt_safe_pipe(pipes) == 0); @@ -1455,20 +1464,24 @@ void tst_QProcess::setChildProcessModifier() process.setChildProcessModifier([pipes]() { ::childProcessModifier(pipes[1]); }); - process.start("testProcessNormal/testProcessNormal"); - if (process.state() != QProcess::Starting) - QCOMPARE(process.state(), QProcess::Running); - QVERIFY2(process.waitForStarted(5000), qPrintable(process.errorString())); + process.setProgram("testProcessNormal/testProcessNormal"); + if (detached) { + process.startDetached(); + } else { + process.start("testProcessNormal/testProcessNormal"); + if (process.state() != QProcess::Starting) + QCOMPARE(process.state(), QProcess::Running); + QVERIFY2(process.waitForStarted(5000), qPrintable(process.errorString())); + QVERIFY2(process.waitForFinished(5000), qPrintable(process.errorString())); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); + } char buf[sizeof messageFromChildProcess] = {}; qt_safe_close(pipes[1]); QCOMPARE(qt_safe_read(pipes[0], buf, sizeof(buf)), qint64(sizeof(messageFromChildProcess)) - 1); QCOMPARE(buf, messageFromChildProcess); qt_safe_close(pipes[0]); - - QVERIFY2(process.waitForFinished(5000), qPrintable(process.errorString())); - QCOMPARE(process.exitStatus(), QProcess::NormalExit); - QCOMPARE(process.exitCode(), 0); } void tst_QProcess::throwInChildProcessModifier() |