Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions test/nextcloud_add_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ macro(nextcloud_add_benchmark test_class)
add_executable(${OWNCLOUD_TEST_CLASS}Bench benchmarks/bench${OWNCLOUD_TEST_CLASS_LOWERCASE}.cpp)
set_target_properties(${OWNCLOUD_TEST_CLASS}Bench PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIRECTORY})

target_link_libraries(${OWNCLOUD_TEST_CLASS}Bench
target_link_libraries(${OWNCLOUD_TEST_CLASS}Bench PRIVATE
Nextcloud::sync
testutils
nextcloudCore
Expand All @@ -112,8 +112,20 @@ macro(nextcloud_add_benchmark test_class)
Qt::Core5Compat
)

if (WIN32)
target_link_libraries(${OWNCLOUD_TEST_CLASS}Bench PRIVATE
nextcloudsync_vfs_cfapi
)
endif()

if (LINUX)
target_link_libraries(${OWNCLOUD_TEST_CLASS}Bench PRIVATE
nextcloudsync_vfs_xattr
)
endif()

IF(BUILD_UPDATER)
target_link_libraries(${OWNCLOUD_TEST_CLASS}Bench
target_link_libraries(${OWNCLOUD_TEST_CLASS}Bench PRIVATE
updater
)
endif()
Expand Down
32 changes: 25 additions & 7 deletions test/syncenginetestutils.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2020 ownCloud GmbH
Expand All @@ -14,6 +14,10 @@
#include "gui/sharepermissions.h"
#include "httplogger.h"

#if defined Q_OS_WINDOWS
#include "vfs/cfapi/cfapiwrapper.h"
#endif

#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
Expand Down Expand Up @@ -1217,7 +1221,7 @@
_serverVersion = version;
}

FakeFolder::FakeFolder(const FileInfo &fileTemplate, const OCC::Optional<FileInfo> &localFileInfo, const QString &remotePath)
FakeFolder::FakeFolder(const FileInfo &fileTemplate, const OCC::Optional<FileInfo> &localFileInfo, const QString &remotePath, OCC::Vfs::Mode vfsMode)
: _localModifier(_tempDir.path())
{
// Needs to be done once
Expand Down Expand Up @@ -1253,8 +1257,7 @@
});
});

// Ensure we have a valid VfsOff instance "running"
switchToVfs(_syncEngine->syncOptions()._vfs);
setupVfs(vfsMode);

// A new folder will update the local file state database on first sync.
// To have a state matching what users will encounter, we have to a sync
Expand Down Expand Up @@ -1417,6 +1420,22 @@
QVERIFY(false);
}

QSharedPointer<OCC::Vfs> FakeFolder::setupVfs(OCC::Vfs::Mode vfsMode)
{
auto vfsPlugin = QSharedPointer<OCC::Vfs>(createVfsFromPlugin(vfsMode).release());
QObject::connect(&syncEngine().syncFileStatusTracker(), &OCC::SyncFileStatusTracker::fileStatusChanged,
vfsPlugin.data(), &OCC::Vfs::fileStatusChanged);
switchToVfs(vfsPlugin);

#if defined Q_OS_WINDOWS
if (vfsMode == OCC::Vfs::Mode::WindowsCfApi) {
OCC::CfApiWrapper::setPinState(localPath(), OCC::PinState::Unspecified, OCC::CfApiWrapper::NoRecurse);
}
#endif

return vfsPlugin;
}

void FakeFolder::toDisk(QDir &dir, const FileInfo &templateFi)
{
for(const auto &child : templateFi.children) {
Expand Down Expand Up @@ -1447,11 +1466,10 @@
QFile f { diskChild.filePath() };
f.open(QFile::ReadOnly);
auto content = f.read(1);
if (content.size() == 0) {
qWarning() << "Empty file at:" << diskChild.filePath();
continue;
auto contentChar = char{};
if (content.size() > 0) {
contentChar = content.at(0);
}
char contentChar = content.at(0);
templateFi.children.insert(diskChild.fileName(), FileInfo{diskChild.fileName(), diskChild.size(), contentChar, diskChild.lastModified()});
}
}
Expand Down
9 changes: 8 additions & 1 deletion test/syncenginetestutils.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud GmbH
Expand All @@ -9,8 +9,9 @@
*/
#pragma once

#include "account.h"

Check failure on line 12 in test/syncenginetestutils.h

View workflow job for this annotation

GitHub Actions / build

test/syncenginetestutils.h:12:10 [clang-diagnostic-error]

'account.h' file not found
#include "common/result.h"
#include "common/vfs.h"
#include "creds/abstractcredentials.h"
#include "logger.h"
#include "filesystem.h"
Expand Down Expand Up @@ -579,7 +580,11 @@
QString _serverVersion = QStringLiteral("10.0.0");

public:
FakeFolder(const FileInfo &fileTemplate, const OCC::Optional<FileInfo> &localFileInfo = {}, const QString &remotePath = {});
#if defined Q_OS_WINDOWS
FakeFolder(const FileInfo &fileTemplate, const OCC::Optional<FileInfo> &localFileInfo = {}, const QString &remotePath = {}, OCC::Vfs::Mode vfsMode = OCC::Vfs::Mode::WindowsCfApi);
#else
FakeFolder(const FileInfo &fileTemplate, const OCC::Optional<FileInfo> &localFileInfo = {}, const QString &remotePath = {}, OCC::Vfs::Mode vfsMode = OCC::Vfs::Mode::Off);
#endif

void switchToVfs(QSharedPointer<OCC::Vfs> vfs);

Expand Down Expand Up @@ -634,6 +639,8 @@
return execUntilFinished();
}

QSharedPointer<OCC::Vfs> setupVfs(OCC::Vfs::Mode vfsMode);

private:
static void toDisk(QDir &dir, const FileInfo &templateFi);

Expand Down
49 changes: 10 additions & 39 deletions test/testsynccfapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* any purpose.
*/

#include <QtTest>

Check failure on line 10 in test/testsynccfapi.cpp

View workflow job for this annotation

GitHub Actions / build

test/testsynccfapi.cpp:10:10 [clang-diagnostic-error]

'QtTest' file not found
#include "syncenginetestutils.h"
#include "common/vfs.h"
#include "config.h"
Expand Down Expand Up @@ -97,18 +97,6 @@
journal.schedulePathForRemoteDiscovery(record._path);
}

QSharedPointer<Vfs> setupVfs(FakeFolder &folder)
{
auto cfapiVfs = QSharedPointer<Vfs>(createVfsFromPlugin(Vfs::WindowsCfApi).release());
QObject::connect(&folder.syncEngine().syncFileStatusTracker(), &SyncFileStatusTracker::fileStatusChanged,
cfapiVfs.data(), &Vfs::fileStatusChanged);
folder.switchToVfs(cfapiVfs);

::setPinState(folder.localPath(), PinState::Unspecified, cfapi::NoRecurse);

return cfapiVfs;
}

class TestSyncCfApi : public QObject
{
Q_OBJECT
Expand All @@ -133,7 +121,7 @@
void testReplaceFileByIdenticalFile()
{
FakeFolder fakeFolder{FileInfo{}};
auto vfs = setupVfs(fakeFolder);
auto vfs = fakeFolder.syncEngine().syncOptions()._vfs;
ItemCompletedSpy completeSpy(fakeFolder);

// Create a new local (non-placeholder) file
Expand Down Expand Up @@ -172,7 +160,7 @@
void testReplaceOnlineOnlyFile()
{
FakeFolder fakeFolder{FileInfo{}};
auto vfs = setupVfs(fakeFolder);
auto vfs = fakeFolder.syncEngine().syncOptions()._vfs;

// Create a new local (non-placeholder) file
fakeFolder.localModifier().insert("file");
Expand Down Expand Up @@ -206,7 +194,6 @@
QFETCH(bool, doLocalDiscovery);

FakeFolder fakeFolder{ FileInfo() };
setupVfs(fakeFolder);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
ItemCompletedSpy completeSpy(fakeFolder);

Expand Down Expand Up @@ -335,7 +322,6 @@
void testVirtualFileConflict()
{
FakeFolder fakeFolder{ FileInfo() };
setupVfs(fakeFolder);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
ItemCompletedSpy completeSpy(fakeFolder);

Expand Down Expand Up @@ -394,7 +380,6 @@
void testWithNormalSync()
{
FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
setupVfs(fakeFolder);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
ItemCompletedSpy completeSpy(fakeFolder);

Expand Down Expand Up @@ -429,7 +414,6 @@
void testVirtualFileDownload()
{
FakeFolder fakeFolder{ FileInfo() };
setupVfs(fakeFolder);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
ItemCompletedSpy completeSpy(fakeFolder);

Expand Down Expand Up @@ -531,7 +515,6 @@
void testVirtualFileDownloadResume()
{
FakeFolder fakeFolder{ FileInfo() };
setupVfs(fakeFolder);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
ItemCompletedSpy completeSpy(fakeFolder);

Expand Down Expand Up @@ -568,7 +551,6 @@
void testNewFilesNotVirtual()
{
FakeFolder fakeFolder{ FileInfo() };
setupVfs(fakeFolder);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

fakeFolder.remoteModifier().mkdir("A");
Expand All @@ -588,7 +570,6 @@
void testDownloadRecursive()
{
FakeFolder fakeFolder{ FileInfo() };
setupVfs(fakeFolder);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

// Create a virtual file for remote files
Expand Down Expand Up @@ -662,7 +643,6 @@
void testRenameVirtual()
{
FakeFolder fakeFolder{ FileInfo() };
setupVfs(fakeFolder);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
ItemCompletedSpy completeSpy(fakeFolder);

Expand Down Expand Up @@ -711,7 +691,6 @@
void testRenameVirtual2()
{
FakeFolder fakeFolder{ FileInfo() };
setupVfs(fakeFolder);
ItemCompletedSpy completeSpy(fakeFolder);
auto cleanup = [&]() {
completeSpy.clear();
Expand Down Expand Up @@ -767,7 +746,6 @@
fakeFolder.remoteModifier().remove("A/a2");
fakeFolder.remoteModifier().insert("A/a1", 1024 * 1024);
fakeFolder.remoteModifier().insert("A/a2", 1024 * 1024);
setupVfs(fakeFolder);

QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
Expand Down Expand Up @@ -877,7 +855,6 @@
// TODO: Part of this test related to A/a3 is always failing on CI but never fails locally
// I had to comment it out as this prevents from running all other tests with no working ways to fix that
FakeFolder fakeFolder{ FileInfo{} };
setupVfs(fakeFolder);

// Create a suffix-vfs baseline

Expand Down Expand Up @@ -937,7 +914,6 @@
void testNewVirtuals()
{
FakeFolder fakeFolder{ FileInfo() };
setupVfs(fakeFolder);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

fakeFolder.remoteModifier().mkdir("local");
Expand Down Expand Up @@ -1018,7 +994,7 @@
void testAvailability()
{
FakeFolder fakeFolder{ FileInfo() };
auto vfs = setupVfs(fakeFolder);
auto vfs = fakeFolder.syncEngine().syncOptions()._vfs;
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

fakeFolder.remoteModifier().mkdir("local");
Expand Down Expand Up @@ -1080,7 +1056,7 @@
void testPinStateLocals()
{
FakeFolder fakeFolder{ FileInfo() };
auto vfs = setupVfs(fakeFolder);
auto vfs = fakeFolder.syncEngine().syncOptions()._vfs;
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

fakeFolder.remoteModifier().mkdir("local");
Expand Down Expand Up @@ -1159,7 +1135,6 @@
void testEmptyFolderInOnlineOnlyRoot()
{
FakeFolder fakeFolder{ FileInfo() };
setupVfs(fakeFolder);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
ItemCompletedSpy completeSpy(fakeFolder);

Expand All @@ -1186,7 +1161,7 @@
void testIncompatiblePins()
{
FakeFolder fakeFolder{ FileInfo() };
auto vfs = setupVfs(fakeFolder);
auto vfs = fakeFolder.syncEngine().syncOptions()._vfs;
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

fakeFolder.remoteModifier().mkdir("local");
Expand Down Expand Up @@ -1239,7 +1214,6 @@
QFETCH(int, errorKind);

FakeFolder fakeFolder{ FileInfo() };
setupVfs(fakeFolder);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

fakeFolder.remoteModifier().mkdir("online");
Expand Down Expand Up @@ -1303,7 +1277,6 @@
void testDataFingerPrint()
{
FakeFolder fakeFolder{ FileInfo{} };
setupVfs(fakeFolder);

fakeFolder.remoteModifier().mkdir("a");
fakeFolder.remoteModifier().mkdir("a/b");
Expand All @@ -1329,7 +1302,6 @@
void testLockFile_lockedFileReadOnly_afterSync()
{
FakeFolder fakeFolder{ FileInfo{} };
setupVfs(fakeFolder);

ItemCompletedSpy completeSpy(fakeFolder);

Expand Down Expand Up @@ -1368,7 +1340,7 @@
void testLinkFileDownload()
{
FakeFolder fakeFolder{FileInfo{}};
auto vfs = setupVfs(fakeFolder);
auto vfs = fakeFolder.syncEngine().syncOptions()._vfs;

qInfo("Starting .lnk test. It might hand and will get killed after timeout...");

Expand Down Expand Up @@ -1415,7 +1387,7 @@
void testFolderDoesNotUpdatePlaceholderMetadata()
{
FakeFolder fakeFolder{FileInfo{}};
auto vfs = setupVfs(fakeFolder);
auto vfs = fakeFolder.syncEngine().syncOptions()._vfs;

fakeFolder.remoteModifier().mkdir("A");
fakeFolder.remoteModifier().insert("A/file");
Expand All @@ -1429,7 +1401,6 @@
void testRemoteTypeChangeExistingLocalMustGetRemoved()
{
FakeFolder fakeFolder{FileInfo{}};
setupVfs(fakeFolder);

// test file change to directory on remote
fakeFolder.remoteModifier().mkdir("a");
Expand Down Expand Up @@ -1457,7 +1428,7 @@
QSKIP("not applicable");
#endif
FakeFolder fakeFolder{FileInfo{}};
auto vfs = setupVfs(fakeFolder);
auto vfs = fakeFolder.syncEngine().syncOptions()._vfs;

QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
Expand Down Expand Up @@ -1492,7 +1463,7 @@
void renameOnBothSides()
{
FakeFolder fakeFolder { FileInfo::A12_B12_C12_S12() };
auto vfs = setupVfs(fakeFolder);
auto vfs = fakeFolder.syncEngine().syncOptions()._vfs;

// Test that renaming a file within a directory that was renamed on the other side actually do a rename.

Expand Down Expand Up @@ -1521,7 +1492,7 @@
void createFolderAndFiles()
{
FakeFolder fakeFolder {FileInfo{}};
auto vfs = setupVfs(fakeFolder);
auto vfs = fakeFolder.syncEngine().syncOptions()._vfs;

fakeFolder.remoteModifier().mkdir("first folder");

Expand Down
Loading
Loading