summaryrefslogtreecommitdiff
path: root/src/plugins/remotelinux/filesystemaccess_test.cpp
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2022-03-16 20:21:49 +0100
committerJarek Kobus <jaroslaw.kobus@qt.io>2022-03-18 08:36:59 +0000
commit481df466e273f01afd0eee873ae1b8e1907a87c4 (patch)
tree1281a0daa92dabd0d450a8063307cfd8c769fb82 /src/plugins/remotelinux/filesystemaccess_test.cpp
parentde8a67a412acee39a5f3d50855b92e9712536440 (diff)
downloadqt-creator-481df466e273f01afd0eee873ae1b8e1907a87c4.tar.gz
Fix FileSystemAccessTest::testFileActions() flakiness
Always add " > /dev/null 2>&1" infix so that the output of e.g. "rm" command, when failed, is redirected to dev/null. Enclose the input data in runInShell() with quotation marks and escape all the characters in passed data accordingly. Pass the "-e" option to echo in order to turn on the escaping mode. Add a new test for testCreateRemoteFile(). Change-Id: I7db07b57035242279cac7dd77a80ac6dd05bfb1f Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/plugins/remotelinux/filesystemaccess_test.cpp')
-rw-r--r--src/plugins/remotelinux/filesystemaccess_test.cpp56
1 files changed, 49 insertions, 7 deletions
diff --git a/src/plugins/remotelinux/filesystemaccess_test.cpp b/src/plugins/remotelinux/filesystemaccess_test.cpp
index 1cf68a056c..58680b6a85 100644
--- a/src/plugins/remotelinux/filesystemaccess_test.cpp
+++ b/src/plugins/remotelinux/filesystemaccess_test.cpp
@@ -95,7 +95,11 @@ void FileSystemAccessTest::initTestCase()
QVERIFY(!newDev.isNull());
devMgr->addDevice(newDev);
}
+ if (filePath.exists()) // Do initial cleanup after possible leftovers from previously failed test
+ QVERIFY(filePath.removeRecursively());
+ QVERIFY(!filePath.exists());
QVERIFY(filePath.createDir());
+ QVERIFY(filePath.exists());
}
void FileSystemAccessTest::cleanupTestCase()
@@ -106,7 +110,43 @@ void FileSystemAccessTest::cleanupTestCase()
QVERIFY(baseFilePath().removeRecursively());
}
-void FileSystemAccessTest::testDirStatuses()
+void FileSystemAccessTest::testCreateRemoteFile_data()
+{
+ QTest::addColumn<QByteArray>("data");
+
+ QTest::newRow("Spaces") << QByteArray("Line with spaces");
+ QTest::newRow("Newlines") << QByteArray("Some \n\n newlines \n");
+ QTest::newRow("Carriage return") << QByteArray("Line with carriage \r return");
+ QTest::newRow("Tab") << QByteArray("Line with \t tab");
+ QTest::newRow("Apostrophe") << QByteArray("Line with apostrophe's character");
+ QTest::newRow("Quotation marks") << QByteArray("Line with \"quotation marks\"");
+ QTest::newRow("Backslash 1") << QByteArray("Line with \\ backslash");
+ QTest::newRow("Backslash 2") << QByteArray("Line with \\\" backslash");
+ QTest::newRow("Command output") << QByteArray("The date is: $(date +%D)");
+
+ const int charSize = sizeof(char) * 0x100;
+ QByteArray charString(charSize, Qt::Uninitialized);
+ char *data = charString.data();
+ for (int c = 0; c < charSize; ++c)
+ data[c] = c;
+ QTest::newRow("All Characters") << charString;
+}
+
+void FileSystemAccessTest::testCreateRemoteFile()
+{
+ QFETCH(QByteArray, data);
+
+ const FilePath testFilePath = baseFilePath() / "test_file";
+
+ QVERIFY(!testFilePath.exists());
+ QVERIFY(testFilePath.writeFileContents(data));
+ QVERIFY(testFilePath.exists());
+ QCOMPARE(testFilePath.fileContents(), data);
+ QVERIFY(testFilePath.removeFile());
+ QVERIFY(!testFilePath.exists());
+}
+
+void FileSystemAccessTest::testDirStatus()
{
FilePath filePath = baseFilePath();
QVERIFY(filePath.exists());
@@ -142,7 +182,7 @@ void FileSystemAccessTest::testBytesAvailable()
void FileSystemAccessTest::testFileActions()
{
- FilePath testFilePath = createFile("test");
+ const FilePath testFilePath = createFile("test");
QVERIFY(testFilePath.exists());
QVERIFY(testFilePath.isFile());
@@ -153,15 +193,17 @@ void FileSystemAccessTest::testFileActions()
QVERIFY(testFilePath.isReadableFile());
QVERIFY(testFilePath.isExecutableFile());
- QByteArray content("Test");
+ const QByteArray content("Test");
testFilePath.writeFileContents(content);
- // ToDo: remove ".contains", make fileContents exact equal content
- QVERIFY(testFilePath.fileContents().contains(content));
+ QCOMPARE(testFilePath.fileContents(), content);
- QVERIFY(testFilePath.renameFile(baseFilePath() / "test1"));
+ const FilePath newTestFilePath = baseFilePath() / "test1";
// It is Ok that FilePath doesn't change itself after rename.
- FilePath newTestFilePath = baseFilePath() / "test1";
+ // FilePath::renameFile() is a const method!
+ QVERIFY(testFilePath.renameFile(newTestFilePath));
+ QVERIFY(!testFilePath.exists());
QVERIFY(newTestFilePath.exists());
+ QCOMPARE(newTestFilePath.fileContents(), content);
QVERIFY(!testFilePath.removeFile());
QVERIFY(newTestFilePath.exists());
QVERIFY(newTestFilePath.removeFile());