forked from qt-creator/qt-creator
Process: Add a test for reading the errorChannel
Change-Id: I3b1d35c8ef2be91ddd1591a0fa2dafedc268f916 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -97,9 +97,21 @@ static void doCrash()
|
|||||||
qFatal("The application has crashed purposefully!");
|
qFatal("The application has crashed purposefully!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int envVarIntWithDefault(const char *varName, int defaultValue)
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
const int result = qEnvironmentVariableIntValue(varName, &ok);
|
||||||
|
return ok ? result : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
int ProcessTestApp::SimpleTest::main()
|
int ProcessTestApp::SimpleTest::main()
|
||||||
{
|
{
|
||||||
std::cout << s_simpleTestData << std::endl;
|
const QProcess::ProcessChannel processChannel
|
||||||
|
= QProcess::ProcessChannel(envVarIntWithDefault(envVar(), 0));
|
||||||
|
if (processChannel == QProcess::StandardOutput)
|
||||||
|
std::cout << s_outputData << std::endl;
|
||||||
|
else
|
||||||
|
std::cerr << s_errorData << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -81,7 +81,6 @@ private:
|
|||||||
const Utils::Environment m_environment;
|
const Utils::Environment m_environment;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char s_simpleTestData[] = "Test process successfully executed.";
|
|
||||||
static const char s_runBlockingStdOutSubProcessMagicWord[] = "42";
|
static const char s_runBlockingStdOutSubProcessMagicWord[] = "42";
|
||||||
|
|
||||||
// Expect ending lines detected at '|':
|
// Expect ending lines detected at '|':
|
||||||
|
@@ -153,6 +153,7 @@ private slots:
|
|||||||
void mergedChannels();
|
void mergedChannels();
|
||||||
void destroyBlockingProcess_data();
|
void destroyBlockingProcess_data();
|
||||||
void destroyBlockingProcess();
|
void destroyBlockingProcess();
|
||||||
|
void flushFinishedWhileWaitingForReadyRead_data();
|
||||||
void flushFinishedWhileWaitingForReadyRead();
|
void flushFinishedWhileWaitingForReadyRead();
|
||||||
void crash();
|
void crash();
|
||||||
void crashAfterOneSecond();
|
void crashAfterOneSecond();
|
||||||
@@ -1269,9 +1270,22 @@ void tst_Process::destroyBlockingProcess()
|
|||||||
QVERIFY(!process.waitForFinished(1000));
|
QVERIFY(!process.waitForFinished(1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_Process::flushFinishedWhileWaitingForReadyRead_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QProcess::ProcessChannel>("processChannel");
|
||||||
|
QTest::addColumn<QByteArray>("expectedData");
|
||||||
|
|
||||||
|
QTest::newRow("StandardOutput") << QProcess::StandardOutput << QByteArray(s_outputData);
|
||||||
|
QTest::newRow("StandardError") << QProcess::StandardError << QByteArray(s_errorData);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_Process::flushFinishedWhileWaitingForReadyRead()
|
void tst_Process::flushFinishedWhileWaitingForReadyRead()
|
||||||
{
|
{
|
||||||
SubProcessConfig subConfig(ProcessTestApp::SimpleTest::envVar(), {});
|
QFETCH(QProcess::ProcessChannel, processChannel);
|
||||||
|
QFETCH(QByteArray, expectedData);
|
||||||
|
|
||||||
|
SubProcessConfig subConfig(ProcessTestApp::SimpleTest::envVar(),
|
||||||
|
QString::number(int(processChannel)));
|
||||||
Process process;
|
Process process;
|
||||||
subConfig.setupSubProcess(&process);
|
subConfig.setupSubProcess(&process);
|
||||||
|
|
||||||
@@ -1284,14 +1298,17 @@ void tst_Process::flushFinishedWhileWaitingForReadyRead()
|
|||||||
QByteArray reply;
|
QByteArray reply;
|
||||||
while (process.state() == QProcess::Running) {
|
while (process.state() == QProcess::Running) {
|
||||||
process.waitForReadyRead(500);
|
process.waitForReadyRead(500);
|
||||||
reply += process.readAllRawStandardOutput();
|
if (processChannel == QProcess::StandardOutput)
|
||||||
|
reply += process.readAllRawStandardOutput();
|
||||||
|
else
|
||||||
|
reply += process.readAllRawStandardError();
|
||||||
if (timer.hasExpired())
|
if (timer.hasExpired())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
QCOMPARE(process.state(), QProcess::NotRunning);
|
QCOMPARE(process.state(), QProcess::NotRunning);
|
||||||
QVERIFY(!timer.hasExpired());
|
QVERIFY(!timer.hasExpired());
|
||||||
QVERIFY(reply.contains(s_simpleTestData));
|
QVERIFY(reply.contains(expectedData));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_Process::crash()
|
void tst_Process::crash()
|
||||||
|
Reference in New Issue
Block a user