1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
/*
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <QObject>
#include <QTest>
#include <QSignalSpy>
#include "gui/accountstate.h"
#include "gui/folderman.h"
#include "common/utility.h"
#include "logger.h"
#include "endtoendtestutils.h"
#include <QStandardPaths>
class E2eFileTransferTest : public QObject
{
Q_OBJECT
public:
E2eFileTransferTest() = default;
private:
private slots:
void initTestCase()
{
OCC::Logger::instance()->setLogFlush(true);
OCC::Logger::instance()->setLogDebug(true);
QStandardPaths::setTestModeEnabled(true);
qRegisterMetaType<OCC::SyncResult>("OCC::SyncResult");
}
void testSyncFolder()
{
{
EndToEndTestHelper _helper;
OCC::Folder *_testFolder = nullptr;
QSignalSpy accountReady(&_helper, &EndToEndTestHelper::accountReady);
_helper.startAccountConfig();
QVERIFY(accountReady.wait(3000));
const auto accountState = _helper.accountState();
QSignalSpy accountConnected(accountState.data(), &OCC::AccountState::isConnectedChanged);
QVERIFY(accountConnected.wait(30000));
_testFolder = _helper.configureSyncFolder();
QVERIFY(_testFolder);
// Try the down-sync first
QSignalSpy folderSyncFinished(_testFolder, &OCC::Folder::syncFinished);
OCC::FolderMan::instance()->forceSyncForFolder(_testFolder);
QVERIFY(folderSyncFinished.wait(3000));
const auto testFolderPath = _testFolder->path();
const QString expectedFilePath(testFolderPath + QStringLiteral("welcome.txt"));
const QFile expectedFile(expectedFilePath);
qDebug() << "Checking if expected file exists at:" << expectedFilePath;
QVERIFY(expectedFile.exists());
// Now write a file to test the upload
const auto fileName = QStringLiteral("test_file.txt");
const QString localFilePath(_testFolder->path() + fileName);
QVERIFY(OCC::Utility::writeRandomFile(localFilePath));
OCC::FolderMan::instance()->forceSyncForFolder(_testFolder);
QVERIFY(folderSyncFinished.wait(3000));
qDebug() << "First folder sync complete";
const auto waitForServerToProcessTime = QTime::currentTime().addSecs(3);
while (QTime::currentTime() < waitForServerToProcessTime) {
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
// Do a propfind to check for this file
const QString remoteFilePath(_testFolder->remotePathTrailingSlash() + fileName);
auto checkFileExistsJob = new OCC::PropfindJob(_helper.account(), remoteFilePath, this);
QSignalSpy result(checkFileExistsJob, &OCC::PropfindJob::result);
checkFileExistsJob->setProperties(QList<QByteArray>() << "getlastmodified");
checkFileExistsJob->start();
QVERIFY(result.wait(10000));
// Now try to delete the file and check change is reflected
QFile createdFile(localFilePath);
QVERIFY(createdFile.exists());
createdFile.remove();
OCC::FolderMan::instance()->forceSyncForFolder(_testFolder);
QVERIFY(folderSyncFinished.wait(3000));
while (QTime::currentTime() < waitForServerToProcessTime) {
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
auto checkFileDeletedJob = new OCC::PropfindJob(_helper.account(), remoteFilePath, this);
QSignalSpy error(checkFileDeletedJob, &OCC::PropfindJob::finishedWithError);
checkFileDeletedJob->setProperties(QList<QByteArray>() << "getlastmodified");
checkFileDeletedJob->start();
QVERIFY(error.wait(10000));
}
QTest::qWait(10000);
}
};
QTEST_MAIN(E2eFileTransferTest)
#include "teste2efiletransfer.moc"
|