2021-07-27 09:50:43 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "filesystemaccess_test.h"
|
|
|
|
|
|
|
|
|
|
#include "linuxdevice.h"
|
|
|
|
|
#include "remotelinux_constants.h"
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/devicesupport/devicemanager.h>
|
|
|
|
|
#include <ssh/sshconnection.h>
|
2022-01-04 15:11:49 +01:00
|
|
|
#include <utils/filepath.h>
|
2021-07-27 09:50:43 +02:00
|
|
|
|
|
|
|
|
#include <QDebug>
|
2022-01-04 15:11:49 +01:00
|
|
|
#include <QTest>
|
2021-07-27 09:50:43 +02:00
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace RemoteLinux {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
static const char TEST_IP[] = "127.0.0.1";
|
2022-01-04 15:11:49 +01:00
|
|
|
static const char TEST_DIR[] = "/tmp/testdir";
|
|
|
|
|
static const FilePath baseFilePath = FilePath::fromString("ssh://" + QString(TEST_IP)
|
|
|
|
|
+ QString(TEST_DIR));
|
2021-07-27 09:50:43 +02:00
|
|
|
|
|
|
|
|
TestLinuxDeviceFactory::TestLinuxDeviceFactory()
|
|
|
|
|
: IDeviceFactory("test")
|
|
|
|
|
{
|
|
|
|
|
setDisplayName("Generic Linux Device");
|
|
|
|
|
setIcon(QIcon());
|
|
|
|
|
setCanCreate(true);
|
|
|
|
|
setConstructionFunction(&LinuxDevice::create);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IDevice::Ptr TestLinuxDeviceFactory::create() const
|
|
|
|
|
{
|
|
|
|
|
LinuxDevice::Ptr newDev = LinuxDevice::create();
|
|
|
|
|
qDebug() << "device : " << newDev->type();
|
|
|
|
|
newDev->setType("test");
|
|
|
|
|
QSsh::SshConnectionParameters sshParams = newDev->sshParameters();
|
|
|
|
|
sshParams.setHost(TEST_IP);
|
|
|
|
|
sshParams.setPort(22);
|
|
|
|
|
newDev->setSshParameters(sshParams);
|
|
|
|
|
return newDev;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-04 15:11:49 +01:00
|
|
|
FilePath createFile(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
FilePath testFilePath = baseFilePath / name;
|
|
|
|
|
FilePath dummyFilePath = FilePath::fromString("ssh://" + QString(TEST_IP) + "/dev/null");
|
|
|
|
|
dummyFilePath.copyFile(testFilePath);
|
|
|
|
|
return testFilePath;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-27 09:50:43 +02:00
|
|
|
void FileSystemAccessTest::initTestCase()
|
|
|
|
|
{
|
2022-01-04 15:11:49 +01:00
|
|
|
FilePath filePath = baseFilePath;
|
2021-07-27 09:50:43 +02:00
|
|
|
|
|
|
|
|
if (DeviceManager::deviceForPath(filePath) == nullptr) {
|
|
|
|
|
DeviceManager *const devMgr = DeviceManager::instance();
|
|
|
|
|
const IDevice::Ptr newDev = m_testLinuxDeviceFactory.create();
|
|
|
|
|
QVERIFY(!newDev.isNull());
|
|
|
|
|
devMgr->addDevice(newDev);
|
|
|
|
|
}
|
2022-01-04 15:11:49 +01:00
|
|
|
QVERIFY(filePath.createDir());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileSystemAccessTest::cleanupTestCase()
|
|
|
|
|
{
|
|
|
|
|
QVERIFY(baseFilePath.exists());
|
|
|
|
|
QVERIFY(baseFilePath.removeRecursively());
|
2021-07-27 09:50:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileSystemAccessTest::testDirStatuses()
|
|
|
|
|
{
|
2022-01-04 15:11:49 +01:00
|
|
|
FilePath filePath = baseFilePath;
|
2021-07-27 09:50:43 +02:00
|
|
|
QVERIFY(filePath.exists());
|
|
|
|
|
QVERIFY(filePath.isDir());
|
|
|
|
|
QVERIFY(filePath.isWritableDir());
|
|
|
|
|
|
2022-01-04 15:11:49 +01:00
|
|
|
FilePath testFilePath = createFile("test");
|
2021-07-27 09:50:43 +02:00
|
|
|
QVERIFY(testFilePath.exists());
|
|
|
|
|
QVERIFY(testFilePath.isFile());
|
|
|
|
|
|
|
|
|
|
bool fileExists = false;
|
|
|
|
|
filePath.iterateDirectory(
|
|
|
|
|
[&fileExists](const FilePath &filePath) {
|
2022-01-04 15:11:49 +01:00
|
|
|
if (filePath.baseName() == "test") {
|
2021-07-27 09:50:43 +02:00
|
|
|
fileExists = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
},
|
2022-01-21 12:22:54 +01:00
|
|
|
{{"test"}, QDir::Files});
|
2021-07-27 09:50:43 +02:00
|
|
|
|
|
|
|
|
QVERIFY(fileExists);
|
|
|
|
|
QVERIFY(testFilePath.removeFile());
|
|
|
|
|
QVERIFY(!testFilePath.exists());
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-04 15:46:55 +01:00
|
|
|
void FileSystemAccessTest::testBytesAvailable()
|
|
|
|
|
{
|
|
|
|
|
FilePath testFilePath = FilePath::fromString("ssh://" + QString(TEST_IP) + "/tmp");
|
|
|
|
|
QVERIFY(testFilePath.exists());
|
|
|
|
|
QVERIFY(testFilePath.bytesAvailable() > 0);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-27 09:50:43 +02:00
|
|
|
void FileSystemAccessTest::testFileActions()
|
|
|
|
|
{
|
2022-01-04 15:11:49 +01:00
|
|
|
FilePath testFilePath = createFile("test");
|
2021-07-27 09:50:43 +02:00
|
|
|
QVERIFY(testFilePath.exists());
|
|
|
|
|
QVERIFY(testFilePath.isFile());
|
|
|
|
|
|
|
|
|
|
testFilePath.setPermissions(QFile::ReadOther | QFile::WriteOther | QFile::ExeOther
|
|
|
|
|
| QFile::ReadGroup | QFile::WriteGroup | QFile::ExeGroup
|
|
|
|
|
| QFile::ReadUser | QFile::WriteUser | QFile::ExeUser);
|
|
|
|
|
QVERIFY(testFilePath.isWritableFile());
|
|
|
|
|
QVERIFY(testFilePath.isReadableFile());
|
|
|
|
|
QVERIFY(testFilePath.isExecutableFile());
|
|
|
|
|
|
|
|
|
|
QByteArray content("Test");
|
|
|
|
|
testFilePath.writeFileContents(content);
|
|
|
|
|
// ToDo: remove ".contains", make fileContents exact equal content
|
|
|
|
|
QVERIFY(testFilePath.fileContents().contains(content));
|
|
|
|
|
|
2022-01-04 15:11:49 +01:00
|
|
|
QVERIFY(testFilePath.renameFile(baseFilePath / "test1"));
|
2021-07-27 09:50:43 +02:00
|
|
|
// It is Ok that FilePath doesn't change itself after rename.
|
2022-01-04 15:11:49 +01:00
|
|
|
FilePath newTestFilePath = baseFilePath / "test1";
|
2021-07-27 09:50:43 +02:00
|
|
|
QVERIFY(newTestFilePath.exists());
|
|
|
|
|
QVERIFY(!testFilePath.removeFile());
|
|
|
|
|
QVERIFY(newTestFilePath.exists());
|
|
|
|
|
QVERIFY(newTestFilePath.removeFile());
|
|
|
|
|
QVERIFY(!newTestFilePath.exists());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // Internal
|
|
|
|
|
} // RemoteLinux
|