forked from qt-creator/qt-creator
tst_qtcprocess: Add testPipe
Change-Id: I5b54231d201960eb6909780e4a2c5b9860b7e523 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -134,6 +134,7 @@ private slots:
|
|||||||
void recursiveBlockingProcess();
|
void recursiveBlockingProcess();
|
||||||
void quitBlockingProcess_data();
|
void quitBlockingProcess_data();
|
||||||
void quitBlockingProcess();
|
void quitBlockingProcess();
|
||||||
|
void tarPipe();
|
||||||
|
|
||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
|
|
||||||
@@ -1439,6 +1440,60 @@ void tst_QtcProcess::quitBlockingProcess()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QtcProcess::tarPipe()
|
||||||
|
{
|
||||||
|
if (!FilePath::fromString("tar").searchInPath().isExecutableFile())
|
||||||
|
QSKIP("This test uses \"tar\" command.");
|
||||||
|
|
||||||
|
QtcProcess sourceProcess;
|
||||||
|
QtcProcess targetProcess;
|
||||||
|
|
||||||
|
targetProcess.setProcessMode(ProcessMode::Writer);
|
||||||
|
|
||||||
|
QObject::connect(&sourceProcess, &QtcProcess::readyReadStandardOutput,
|
||||||
|
&targetProcess, [&sourceProcess, &targetProcess]() {
|
||||||
|
targetProcess.writeRaw(sourceProcess.readAllRawStandardOutput());
|
||||||
|
});
|
||||||
|
|
||||||
|
QTemporaryDir sourceDir;
|
||||||
|
QVERIFY(sourceDir.isValid());
|
||||||
|
QTemporaryDir destinationDir;
|
||||||
|
QVERIFY(destinationDir.isValid());
|
||||||
|
|
||||||
|
const FilePath sourcePath = FilePath::fromString(sourceDir.path());
|
||||||
|
const FilePath sourceArchive = sourcePath / "archive";
|
||||||
|
QVERIFY(sourceArchive.createDir());
|
||||||
|
const FilePath sourceFile = sourceArchive / "file1.txt";
|
||||||
|
QVERIFY(sourceFile.writeFileContents("bla bla"));
|
||||||
|
|
||||||
|
const FilePath destinationPath = FilePath::fromString(destinationDir.path());
|
||||||
|
const FilePath destinationArchive = destinationPath / "archive";
|
||||||
|
const FilePath destinationFile = destinationArchive / "file1.txt";
|
||||||
|
|
||||||
|
QVERIFY(!destinationArchive.exists());
|
||||||
|
QVERIFY(!destinationFile.exists());
|
||||||
|
|
||||||
|
sourceProcess.setCommand({"tar", {"cvf", "-", "-C", sourcePath.nativePath(), "."}});
|
||||||
|
targetProcess.setCommand({"tar", {"xvf", "-", "-C", destinationPath.nativePath()}});
|
||||||
|
|
||||||
|
targetProcess.start();
|
||||||
|
QVERIFY(targetProcess.waitForStarted());
|
||||||
|
|
||||||
|
sourceProcess.start();
|
||||||
|
QVERIFY(sourceProcess.waitForFinished());
|
||||||
|
|
||||||
|
if (targetProcess.isRunning()) {
|
||||||
|
targetProcess.closeWriteChannel();
|
||||||
|
QVERIFY(targetProcess.waitForFinished(2000));
|
||||||
|
}
|
||||||
|
|
||||||
|
QCOMPARE(targetProcess.exitCode(), 0);
|
||||||
|
QCOMPARE(targetProcess.result(), ProcessResult::FinishedWithSuccess);
|
||||||
|
QVERIFY(destinationArchive.exists());
|
||||||
|
QVERIFY(destinationFile.exists());
|
||||||
|
QCOMPARE(sourceFile.fileSize(), destinationFile.fileSize());
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN(tst_QtcProcess)
|
QTEST_GUILESS_MAIN(tst_QtcProcess)
|
||||||
|
|
||||||
#include "tst_qtcprocess.moc"
|
#include "tst_qtcprocess.moc"
|
||||||
|
Reference in New Issue
Block a user