diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2023-03-18 11:08:38 -0700 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-05-15 00:12:43 +0200 |
commit | df2131426ecc9711b5ac67a45fde7d760c8f2df2 (patch) | |
tree | e92437c7eb24380bf69d18006536a055b24ec324 | |
parent | 49eb9021e37268f124e836aeeba92a8f36a74804 (diff) | |
download | qtbase-df2131426ecc9711b5ac67a45fde7d760c8f2df2.tar.gz |
tst_QProcess: move setChildProcessModifier test to a Q_OS_UNIX section
There's no need to say it's getting skipped on Windows. moc *can* parse
the #ifdefs these days.
Pick-to: 6.5
Change-Id: Icfe44ecf285a480fafe4fffd174d95c709ff6a74
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
-rw-r--r-- | tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 77 |
1 files changed, 38 insertions, 39 deletions
diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 2d9242a118..4d54e8db27 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -42,7 +42,6 @@ private slots: void getSetCheck(); void constructing(); void simpleStart(); - void setChildProcessModifier(); void startCommand(); void startWithOpen(); void startWithOldOpen(); @@ -111,6 +110,9 @@ private slots: void nativeArguments(); void createProcessArgumentsModifier(); #endif // Q_OS_WIN +#if defined(Q_OS_UNIX) + void setChildProcessModifier(); +#endif void exitCodeTest(); void systemEnvironment(); void lockupsInStartDetached(); @@ -253,44 +255,6 @@ void tst_QProcess::simpleStart() QCOMPARE(qvariant_cast<QProcess::ProcessState>(spy.at(2).at(0)), QProcess::NotRunning); } -#ifdef Q_OS_UNIX -static const char messageFromChildProcess[] = "Message from the child process"; -static void childProcessModifier(int fd) -{ - QT_WRITE(fd, messageFromChildProcess, sizeof(messageFromChildProcess) - 1); - QT_CLOSE(fd); -} -#endif - -void tst_QProcess::setChildProcessModifier() -{ -#ifdef Q_OS_UNIX - int pipes[2] = { -1 , -1 }; - QVERIFY(qt_safe_pipe(pipes) == 0); - - QProcess process; - 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())); - - 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); -#else - QSKIP("Unix-only test"); -#endif -} - void tst_QProcess::startCommand() { QProcess process; @@ -1472,6 +1436,41 @@ void tst_QProcess::createProcessArgumentsModifier() } #endif // Q_OS_WIN +#ifdef Q_OS_UNIX +static constexpr char messageFromChildProcess[] = "Message from the child process"; +static_assert(std::char_traits<char>::length(messageFromChildProcess) <= PIPE_BUF); +static void childProcessModifier(int fd) +{ + QT_WRITE(fd, messageFromChildProcess, strlen(messageFromChildProcess)); + QT_CLOSE(fd); +} + +void tst_QProcess::setChildProcessModifier() +{ + int pipes[2] = { -1 , -1 }; + QVERIFY(qt_safe_pipe(pipes) == 0); + + QProcess process; + 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())); + + 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); +} +#endif + void tst_QProcess::exitCodeTest() { for (int i = 0; i < 255; ++i) { |