forked from qt-creator/qt-creator
RemoteLinux: Move test actions to special test dir
Change-Id: I9be4a1e7de1ae1accc507109bcf5f3b6188a8925 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -28,12 +28,12 @@
|
|||||||
#include "linuxdevice.h"
|
#include "linuxdevice.h"
|
||||||
#include "remotelinux_constants.h"
|
#include "remotelinux_constants.h"
|
||||||
|
|
||||||
#include <utils/filepath.h>
|
|
||||||
#include <projectexplorer/devicesupport/devicemanager.h>
|
#include <projectexplorer/devicesupport/devicemanager.h>
|
||||||
#include <ssh/sshconnection.h>
|
#include <ssh/sshconnection.h>
|
||||||
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
#include <QTest>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QTest>
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
@@ -42,6 +42,9 @@ namespace RemoteLinux {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
static const char TEST_IP[] = "127.0.0.1";
|
static const char TEST_IP[] = "127.0.0.1";
|
||||||
|
static const char TEST_DIR[] = "/tmp/testdir";
|
||||||
|
static const FilePath baseFilePath = FilePath::fromString("ssh://" + QString(TEST_IP)
|
||||||
|
+ QString(TEST_DIR));
|
||||||
|
|
||||||
TestLinuxDeviceFactory::TestLinuxDeviceFactory()
|
TestLinuxDeviceFactory::TestLinuxDeviceFactory()
|
||||||
: IDeviceFactory("test")
|
: IDeviceFactory("test")
|
||||||
@@ -64,9 +67,17 @@ IDevice::Ptr TestLinuxDeviceFactory::create() const
|
|||||||
return newDev;
|
return newDev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FilePath createFile(const QString &name)
|
||||||
|
{
|
||||||
|
FilePath testFilePath = baseFilePath / name;
|
||||||
|
FilePath dummyFilePath = FilePath::fromString("ssh://" + QString(TEST_IP) + "/dev/null");
|
||||||
|
dummyFilePath.copyFile(testFilePath);
|
||||||
|
return testFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
void FileSystemAccessTest::initTestCase()
|
void FileSystemAccessTest::initTestCase()
|
||||||
{
|
{
|
||||||
FilePath filePath = FilePath::fromString("ssh://"+ QString(TEST_IP) +"/tmp");
|
FilePath filePath = baseFilePath;
|
||||||
|
|
||||||
if (DeviceManager::deviceForPath(filePath) == nullptr) {
|
if (DeviceManager::deviceForPath(filePath) == nullptr) {
|
||||||
DeviceManager *const devMgr = DeviceManager::instance();
|
DeviceManager *const devMgr = DeviceManager::instance();
|
||||||
@@ -74,25 +85,30 @@ void FileSystemAccessTest::initTestCase()
|
|||||||
QVERIFY(!newDev.isNull());
|
QVERIFY(!newDev.isNull());
|
||||||
devMgr->addDevice(newDev);
|
devMgr->addDevice(newDev);
|
||||||
}
|
}
|
||||||
|
QVERIFY(filePath.createDir());
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileSystemAccessTest::cleanupTestCase()
|
||||||
|
{
|
||||||
|
QVERIFY(baseFilePath.exists());
|
||||||
|
QVERIFY(baseFilePath.removeRecursively());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileSystemAccessTest::testDirStatuses()
|
void FileSystemAccessTest::testDirStatuses()
|
||||||
{
|
{
|
||||||
FilePath filePath = FilePath::fromString("ssh://" + QString(TEST_IP) + "/tmp");
|
FilePath filePath = baseFilePath;
|
||||||
QVERIFY(filePath.exists());
|
QVERIFY(filePath.exists());
|
||||||
QVERIFY(filePath.isDir());
|
QVERIFY(filePath.isDir());
|
||||||
QVERIFY(filePath.isWritableDir());
|
QVERIFY(filePath.isWritableDir());
|
||||||
|
|
||||||
FilePath testFilePath = FilePath::fromString("ssh://" + QString(TEST_IP) + "/tmp/test");
|
FilePath testFilePath = createFile("test");
|
||||||
FilePath dummyFilePath = FilePath::fromString("ssh://" + QString(TEST_IP) + "/dev/null");
|
|
||||||
dummyFilePath.copyFile(testFilePath);
|
|
||||||
QVERIFY(testFilePath.exists());
|
QVERIFY(testFilePath.exists());
|
||||||
QVERIFY(testFilePath.isFile());
|
QVERIFY(testFilePath.isFile());
|
||||||
|
|
||||||
bool fileExists = false;
|
bool fileExists = false;
|
||||||
filePath.iterateDirectory(
|
filePath.iterateDirectory(
|
||||||
[&fileExists](const FilePath &filePath) {
|
[&fileExists](const FilePath &filePath) {
|
||||||
if (filePath.baseName() == "test"){
|
if (filePath.baseName() == "test") {
|
||||||
fileExists = true;
|
fileExists = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -104,14 +120,11 @@ void FileSystemAccessTest::testDirStatuses()
|
|||||||
QVERIFY(fileExists);
|
QVERIFY(fileExists);
|
||||||
QVERIFY(testFilePath.removeFile());
|
QVERIFY(testFilePath.removeFile());
|
||||||
QVERIFY(!testFilePath.exists());
|
QVERIFY(!testFilePath.exists());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileSystemAccessTest::testFileActions()
|
void FileSystemAccessTest::testFileActions()
|
||||||
{
|
{
|
||||||
FilePath testFilePath = FilePath::fromString("ssh://" + QString(TEST_IP) + "/tmp/test");
|
FilePath testFilePath = createFile("test");
|
||||||
FilePath dummyFilePath = FilePath::fromString("ssh://" + QString(TEST_IP) + "/dev/null");
|
|
||||||
dummyFilePath.copyFile(testFilePath);
|
|
||||||
QVERIFY(testFilePath.exists());
|
QVERIFY(testFilePath.exists());
|
||||||
QVERIFY(testFilePath.isFile());
|
QVERIFY(testFilePath.isFile());
|
||||||
|
|
||||||
@@ -127,9 +140,9 @@ void FileSystemAccessTest::testFileActions()
|
|||||||
// ToDo: remove ".contains", make fileContents exact equal content
|
// ToDo: remove ".contains", make fileContents exact equal content
|
||||||
QVERIFY(testFilePath.fileContents().contains(content));
|
QVERIFY(testFilePath.fileContents().contains(content));
|
||||||
|
|
||||||
QVERIFY(testFilePath.renameFile(FilePath::fromString("ssh://" + QString(TEST_IP) + "/tmp/test1")));
|
QVERIFY(testFilePath.renameFile(baseFilePath / "test1"));
|
||||||
// It is Ok that FilePath doesn't change itself after rename.
|
// It is Ok that FilePath doesn't change itself after rename.
|
||||||
FilePath newTestFilePath = FilePath::fromString("ssh://" + QString(TEST_IP) + "/tmp/test1");
|
FilePath newTestFilePath = baseFilePath / "test1";
|
||||||
QVERIFY(newTestFilePath.exists());
|
QVERIFY(newTestFilePath.exists());
|
||||||
QVERIFY(!testFilePath.removeFile());
|
QVERIFY(!testFilePath.removeFile());
|
||||||
QVERIFY(newTestFilePath.exists());
|
QVERIFY(newTestFilePath.exists());
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ class TestLinuxDeviceFactory final : public ProjectExplorer::IDeviceFactory
|
|||||||
public:
|
public:
|
||||||
TestLinuxDeviceFactory();
|
TestLinuxDeviceFactory();
|
||||||
|
|
||||||
Utils::FilePaths defaultKeys() const;
|
|
||||||
|
|
||||||
ProjectExplorer::IDevice::Ptr create() const override;
|
ProjectExplorer::IDevice::Ptr create() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -49,6 +47,7 @@ class FileSystemAccessTest : public QObject
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
|
void cleanupTestCase();
|
||||||
|
|
||||||
void testDirStatuses();
|
void testDirStatuses();
|
||||||
void testFileActions();
|
void testFileActions();
|
||||||
|
|||||||
@@ -404,7 +404,6 @@ QString LinuxDevice::userAtHost() const
|
|||||||
|
|
||||||
bool LinuxDevice::handlesFile(const FilePath &filePath) const
|
bool LinuxDevice::handlesFile(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
DEBUG("handlesFile " << filePath.scheme() << filePath.host() << userAtHost());
|
|
||||||
return filePath.scheme() == "ssh" && filePath.host() == userAtHost();
|
return filePath.scheme() == "ssh" && filePath.host() == userAtHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,7 +554,7 @@ bool LinuxDevice::removeRecursively(const FilePath &filePath) const
|
|||||||
// We are expecting this only to be called in a context of build directories or similar.
|
// We are expecting this only to be called in a context of build directories or similar.
|
||||||
// Chicken out in some cases that _might_ be user code errors.
|
// Chicken out in some cases that _might_ be user code errors.
|
||||||
QTC_ASSERT(path.startsWith('/'), return false);
|
QTC_ASSERT(path.startsWith('/'), return false);
|
||||||
const int levelsNeeded = path.startsWith("/home/") ? 4 : 3;
|
const int levelsNeeded = path.startsWith("/home/") ? 3 : 2;
|
||||||
QTC_ASSERT(path.count('/') >= levelsNeeded, return false);
|
QTC_ASSERT(path.count('/') >= levelsNeeded, return false);
|
||||||
|
|
||||||
return d->runInShell({"rm", {"-rf", "--", path}});
|
return d->runInShell({"rm", {"-rf", "--", path}});
|
||||||
|
|||||||
Reference in New Issue
Block a user