Process: Make multiRead test platform independent

Change-Id: Ife58e7b2a41ac35f8137acfc66ff827672f75de9
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Jarek Kobus
2023-12-06 14:47:56 +01:00
parent 1ea1ea7747
commit 2304dbb395
3 changed files with 28 additions and 10 deletions

View File

@@ -115,6 +115,23 @@ int ProcessTestApp::SimpleTest::main()
return 0;
}
int ProcessTestApp::ChannelEchoer::main()
{
const QProcess::ProcessChannel processChannel
= QProcess::ProcessChannel(envVarIntWithDefault(envVar(), 0));
while (true) {
std::string input;
std::cin >> input;
if (input == "exit")
return 0;
if (processChannel == QProcess::StandardOutput)
std::cout << input << std::endl;
else
std::cerr << input << std::endl;
}
return 0;
}
int ProcessTestApp::ExitCode::main()
{
const int exitCode = qEnvironmentVariableIntValue(envVar());

View File

@@ -44,6 +44,7 @@ public:
// of the subprocess. The following subprocess classes are defined:
SUB_PROCESS(SimpleTest);
SUB_PROCESS(ChannelEchoer);
SUB_PROCESS(ExitCode);
SUB_PROCESS(RunBlockingStdOut);
SUB_PROCESS(LineCallback);

View File

@@ -121,7 +121,6 @@ private slots:
}
void multiRead();
void splitArgs_data();
void splitArgs();
void prepareArgs_data();
@@ -247,30 +246,31 @@ Q_DECLARE_METATYPE(Utils::ProcessResult)
void tst_Process::multiRead()
{
if (HostOsInfo::isWindowsHost())
QSKIP("This test uses /bin/sh.");
SubProcessConfig subConfig(ProcessTestApp::ChannelEchoer::envVar(), {});
QByteArray buffer;
Process process;
subConfig.setupSubProcess(&process);
process.setCommand({"/bin/sh", {}});
process.setProcessChannelMode(QProcess::SeparateChannels);
process.setProcessMode(Utils::ProcessMode::Writer);
process.start();
QVERIFY(process.waitForStarted());
process.writeRaw("echo hi\n");
process.writeRaw("hi\n");
QVERIFY(process.waitForReadyRead(1000));
buffer = process.readAllRawStandardOutput();
buffer.replace("\r\n", "\n"); // Needed for Windows only
QCOMPARE(buffer, QByteArray("hi\n"));
process.writeRaw("echo you\n");
process.writeRaw("you\n");
QVERIFY(process.waitForReadyRead(1000));
buffer = process.readAllRawStandardOutput();
buffer.replace("\r\n", "\n"); // Needed for Windows only
QCOMPARE(buffer, QByteArray("you\n"));
process.writeRaw("exit\n");
QVERIFY(process.waitForFinished(1000));
}
void tst_Process::splitArgs_data()