summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-05-25 09:29:06 -0700
committerThiago Macieira <thiago.macieira@intel.com>2023-06-03 08:50:53 -0700
commit4ce97e25d30d870e97a353230b59fea82ffbd2e5 (patch)
treece0d037c76522009949be6a3706a35f027a84bf5
parent0ab091c92f1d214ebee01e9e26725e15497bdd53 (diff)
tst_QProcess: put the tests in the right order
They were in the right order before rebasing multiple times. kdiff3 is currently broken, so I don't know what happened. Change-Id: Ib5ce7a497e034ebabb2cfffd17626fcf46c541fd Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--tests/auto/corelib/io/qprocess/tst_qprocess.cpp148
1 files changed, 73 insertions, 75 deletions
diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
index 540df04f73..7c318f0ca7 100644
--- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
+++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
@@ -1450,6 +1450,79 @@ 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_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);
+
+ QProcess process;
+ process.setChildProcessModifier([pipes]() {
+ ::childProcessModifier(pipes[1]);
+ });
+ 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]);
+}
+
+void tst_QProcess::throwInChildProcessModifier()
+{
+#ifndef __cpp_exceptions
+ Q_SKIP("Exceptions disabled.");
+#else
+ QProcess process;
+ process.setChildProcessModifier([]() {
+ throw 42;
+ });
+ process.setProgram("testProcessNormal/testProcessNormal");
+
+ process.start();
+ QVERIFY(!process.waitForStarted(5000));
+ QCOMPARE(process.state(), QProcess::NotRunning);
+ QCOMPARE(process.error(), QProcess::FailedToStart);
+ QVERIFY2(process.errorString().contains("childProcessModifier"),
+ qPrintable(process.errorString()));
+
+ // try again, to ensure QProcess internal state wasn't corrupted
+ process.start();
+ QVERIFY(!process.waitForStarted(5000));
+ QCOMPARE(process.state(), QProcess::NotRunning);
+ QCOMPARE(process.error(), QProcess::FailedToStart);
+ QVERIFY2(process.errorString().contains("childProcessModifier"),
+ qPrintable(process.errorString()));
+#endif
+}
+
void tst_QProcess::unixProcessParameters_data()
{
QTest::addColumn<QProcess::UnixProcessParameters>("params");
@@ -1559,81 +1632,6 @@ void tst_QProcess::unixProcessParametersAndChildModifier()
}
#endif
-#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_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);
-
- QProcess process;
- process.setChildProcessModifier([pipes]() {
- ::childProcessModifier(pipes[1]);
- });
- 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]);
-}
-
-void tst_QProcess::throwInChildProcessModifier()
-{
-#ifndef __cpp_exceptions
- Q_SKIP("Exceptions disabled.");
-#else
- QProcess process;
- process.setChildProcessModifier([]() {
- throw 42;
- });
- process.setProgram("testProcessNormal/testProcessNormal");
-
- process.start();
- QVERIFY(!process.waitForStarted(5000));
- QCOMPARE(process.state(), QProcess::NotRunning);
- QCOMPARE(process.error(), QProcess::FailedToStart);
- QVERIFY2(process.errorString().contains("childProcessModifier"),
- qPrintable(process.errorString()));
-
- // try again, to ensure QProcess internal state wasn't corrupted
- process.start();
- QVERIFY(!process.waitForStarted(5000));
- QCOMPARE(process.state(), QProcess::NotRunning);
- QCOMPARE(process.error(), QProcess::FailedToStart);
- QVERIFY2(process.errorString().contains("childProcessModifier"),
- qPrintable(process.errorString()));
-#endif
-}
-#endif
-
void tst_QProcess::exitCodeTest()
{
for (int i = 0; i < 255; ++i) {