diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2021-11-04 10:27:08 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2021-11-04 12:30:03 +0000 |
commit | acfe22428199afea13554e7c1293e56ac76e325a (patch) | |
tree | 071161142ec71c28abbadf5dbcb3a9c4e3ee1160 /tests | |
parent | 4d55fc911d08436a35b6e240fb6f9d8742a44512 (diff) |
Flush finished() signal when waitForReadyRead() was called
Apparently the QProcess behaves like that.
Change-Id: Idb1993b8abccbd7943582d41bd456eacc9a1c185
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/utils/qtcprocess/tst_qtcprocess.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp b/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp index 2ad9eba89d..ac0bf2f862 100644 --- a/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp +++ b/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp @@ -65,6 +65,7 @@ const char kBlockingProcess[] = "QTC_TST_BLOCKING_PROCESS"; // the recursion, as from the test point of view we meant to execute only our custom code // without further execution of the test itself. +const char testProcessData[] = "Test process successfully executed."; const char forwardedOutputData[] = "This is the output message."; const char forwardedErrorData[] = "This is the error message."; const char runBlockingStdOutSubProcessMagicWord[] = "42"; @@ -108,7 +109,7 @@ static void lineCallbackMain() static void testProcessSubProcessMain() { - std::cout << "Test process successfully executed." << std::endl; + std::cout << testProcessData << std::endl; exit(0); } @@ -207,6 +208,7 @@ private slots: void processChannelForwarding_data(); void processChannelForwarding(); void killBlockingProcess(); + void flushFinishedWhileWaitingForReadyRead(); void cleanupTestCase(); @@ -1175,6 +1177,36 @@ void tst_QtcProcess::killBlockingProcess() QVERIFY(msgHandler.testPassed()); } +void tst_QtcProcess::flushFinishedWhileWaitingForReadyRead() +{ + Environment env = Environment::systemEnvironment(); + env.set(kTestProcess, {}); + QStringList args = QCoreApplication::arguments(); + const QString binary = args.takeFirst(); + const CommandLine command(FilePath::fromString(binary), args); + + QtcProcess process; + process.setCommand(command); + process.setEnvironment(env); + process.start(); + + QVERIFY(process.waitForStarted()); + QCOMPARE(process.state(), QProcess::Running); + + QDeadlineTimer timer(1000); + QByteArray reply; + while (process.state() == QProcess::Running) { + process.waitForReadyRead(500); + reply += process.readAllStandardOutput(); + if (timer.hasExpired()) + break; + } + + QCOMPARE(process.state(), QProcess::NotRunning); + QVERIFY(!timer.hasExpired()); + QVERIFY(reply.contains(testProcessData)); +} + QTEST_MAIN(tst_QtcProcess) #include "tst_qtcprocess.moc" |