tst_QProcess: Use a QTemporaryDir for files to be created.
Ensure the test works in a working directory with read-only permission and that the file names are unique. The test can then be executed repeatedly by COIN even in case left-over hanging process helpers still lock the files. Also disambiguate the "data" files used by various tests. Task-number: QTBUG-47370 Change-Id: I3b9c7b70828da78f400196fcbba27bc61ea4538f Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
This commit is contained in:
parent
45470e71bc
commit
adc4894fca
@ -38,6 +38,7 @@
|
|||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
#include <QtCore/QThread>
|
#include <QtCore/QThread>
|
||||||
|
#include <QtCore/QTemporaryDir>
|
||||||
#include <QtCore/QRegExp>
|
#include <QtCore/QRegExp>
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QMetaType>
|
#include <QtCore/QMetaType>
|
||||||
@ -172,6 +173,7 @@ protected slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
qint64 bytesAvailable;
|
qint64 bytesAvailable;
|
||||||
|
QTemporaryDir m_temporaryDir;
|
||||||
#endif //QT_NO_PROCESS
|
#endif //QT_NO_PROCESS
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -180,6 +182,7 @@ void tst_QProcess::initTestCase()
|
|||||||
#ifdef QT_NO_PROCESS
|
#ifdef QT_NO_PROCESS
|
||||||
QSKIP("This test requires QProcess support");
|
QSKIP("This test requires QProcess support");
|
||||||
#else
|
#else
|
||||||
|
QVERIFY2(m_temporaryDir.isValid(), qPrintable(m_temporaryDir.errorString()));
|
||||||
// chdir to our testdata path and execute helper apps relative to that.
|
// chdir to our testdata path and execute helper apps relative to that.
|
||||||
QString testdata_dir = QFileInfo(QFINDTESTDATA("testProcessNormal")).absolutePath();
|
QString testdata_dir = QFileInfo(QFINDTESTDATA("testProcessNormal")).absolutePath();
|
||||||
QVERIFY2(QDir::setCurrent(testdata_dir), qPrintable("Could not chdir to " + testdata_dir));
|
QVERIFY2(QDir::setCurrent(testdata_dir), qPrintable("Could not chdir to " + testdata_dir));
|
||||||
@ -1709,7 +1712,7 @@ void tst_QProcess::failToStartEmptyArgs()
|
|||||||
// Reading and writing to a process is not supported on Qt/CE
|
// Reading and writing to a process is not supported on Qt/CE
|
||||||
void tst_QProcess::removeFileWhileProcessIsRunning()
|
void tst_QProcess::removeFileWhileProcessIsRunning()
|
||||||
{
|
{
|
||||||
QFile file("removeFile.txt");
|
QFile file(m_temporaryDir.path() + QLatin1String("/removeFile.txt"));
|
||||||
QVERIFY(file.open(QFile::WriteOnly));
|
QVERIFY(file.open(QFile::WriteOnly));
|
||||||
|
|
||||||
QProcess process;
|
QProcess process;
|
||||||
@ -1940,13 +1943,13 @@ void tst_QProcess::setStandardInputFile()
|
|||||||
{
|
{
|
||||||
static const char data[] = "A bunch\1of\2data\3\4\5\6\7...";
|
static const char data[] = "A bunch\1of\2data\3\4\5\6\7...";
|
||||||
QProcess process;
|
QProcess process;
|
||||||
QFile file("data");
|
QFile file(m_temporaryDir.path() + QLatin1String("/data-sif"));
|
||||||
|
|
||||||
QVERIFY(file.open(QIODevice::WriteOnly));
|
QVERIFY(file.open(QIODevice::WriteOnly));
|
||||||
file.write(data, sizeof data);
|
file.write(data, sizeof data);
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
process.setStandardInputFile("data");
|
process.setStandardInputFile(file.fileName());
|
||||||
process.start("testProcessEcho/testProcessEcho");
|
process.start("testProcessEcho/testProcessEcho");
|
||||||
|
|
||||||
QVERIFY(process.waitForFinished());
|
QVERIFY(process.waitForFinished());
|
||||||
@ -2008,7 +2011,7 @@ void tst_QProcess::setStandardOutputFile()
|
|||||||
QIODevice::OpenMode mode = append ? QIODevice::Append : QIODevice::Truncate;
|
QIODevice::OpenMode mode = append ? QIODevice::Append : QIODevice::Truncate;
|
||||||
|
|
||||||
// create the destination file with data
|
// create the destination file with data
|
||||||
QFile file("data");
|
QFile file(m_temporaryDir.path() + QLatin1String("/data-stdof-") + QLatin1String(QTest::currentDataTag()));
|
||||||
QVERIFY(file.open(QIODevice::WriteOnly));
|
QVERIFY(file.open(QIODevice::WriteOnly));
|
||||||
file.write(data, sizeof data - 1);
|
file.write(data, sizeof data - 1);
|
||||||
file.close();
|
file.close();
|
||||||
@ -2017,9 +2020,9 @@ void tst_QProcess::setStandardOutputFile()
|
|||||||
QProcess process;
|
QProcess process;
|
||||||
process.setReadChannelMode(channelMode);
|
process.setReadChannelMode(channelMode);
|
||||||
if (channelToTest == QProcess::StandardOutput)
|
if (channelToTest == QProcess::StandardOutput)
|
||||||
process.setStandardOutputFile("data", mode);
|
process.setStandardOutputFile(file.fileName(), mode);
|
||||||
else
|
else
|
||||||
process.setStandardErrorFile("data", mode);
|
process.setStandardErrorFile(file.fileName(), mode);
|
||||||
|
|
||||||
process.start("testProcessEcho2/testProcessEcho2");
|
process.start("testProcessEcho2/testProcessEcho2");
|
||||||
process.write(testdata, sizeof testdata);
|
process.write(testdata, sizeof testdata);
|
||||||
@ -2066,10 +2069,11 @@ void tst_QProcess::setStandardOutputFileAndWaitForBytesWritten()
|
|||||||
{
|
{
|
||||||
static const char testdata[] = "Test data.";
|
static const char testdata[] = "Test data.";
|
||||||
|
|
||||||
QFile file("data");
|
QFile file(m_temporaryDir.path() + QLatin1String("/data-stdofawfbw"));
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.setStandardOutputFile(file.fileName());
|
process.setStandardOutputFile(file.fileName());
|
||||||
process.start("testProcessEcho2/testProcessEcho2");
|
process.start("testProcessEcho2/testProcessEcho2");
|
||||||
|
QVERIFY2(process.waitForStarted(), qPrintable(process.errorString()));
|
||||||
process.write(testdata, sizeof testdata);
|
process.write(testdata, sizeof testdata);
|
||||||
process.waitForBytesWritten();
|
process.waitForBytesWritten();
|
||||||
QVERIFY(process.waitForFinished());
|
QVERIFY(process.waitForFinished());
|
||||||
@ -2143,14 +2147,15 @@ void tst_QProcess::fileWriterProcess()
|
|||||||
|
|
||||||
QTime stopWatch;
|
QTime stopWatch;
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
const QString fileName = QLatin1String("fileWriterProcess.txt");
|
const QString fileName = m_temporaryDir.path() + QLatin1String("/fileWriterProcess.txt");
|
||||||
|
const QString binary = QDir::currentPath() + QLatin1String("/fileWriterProcess/fileWriterProcess");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (QFile::exists(fileName))
|
if (QFile::exists(fileName))
|
||||||
QVERIFY(QFile::remove(fileName));
|
QVERIFY(QFile::remove(fileName));
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.start("fileWriterProcess/fileWriterProcess",
|
process.setWorkingDirectory(m_temporaryDir.path());
|
||||||
QIODevice::ReadWrite | QIODevice::Text);
|
process.start(binary, QIODevice::ReadWrite | QIODevice::Text);
|
||||||
process.write(stdinStr);
|
process.write(stdinStr);
|
||||||
process.closeWriteChannel();
|
process.closeWriteChannel();
|
||||||
while (process.bytesToWrite()) {
|
while (process.bytesToWrite()) {
|
||||||
@ -2173,8 +2178,9 @@ void tst_QProcess::detachedWorkingDirectoryAndPid()
|
|||||||
QTest::qSleep(1000);
|
QTest::qSleep(1000);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QFile infoFile(QDir::currentPath() + QLatin1String("/detachedinfo.txt"));
|
QFile infoFile(m_temporaryDir.path() + QLatin1String("/detachedinfo.txt"));
|
||||||
infoFile.remove();
|
if (infoFile.exists())
|
||||||
|
QVERIFY(infoFile.remove());
|
||||||
|
|
||||||
QString workingDir = QDir::currentPath() + "/testDetached";
|
QString workingDir = QDir::currentPath() + "/testDetached";
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user