Skip to content

Commit

Permalink
add test skeleton for OCC::FolderStatusModel
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien committed Feb 12, 2025
1 parent 93e39c8 commit 9949d0c
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/gui/folderman.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
class TestFolderMan;
class TestCfApiShellExtensionsIPC;
class TestShareModel;
class TestFolderStatusModel;

Check warning on line 32 in src/gui/folderman.h

View workflow job for this annotation

GitHub Actions / build

src/gui/folderman.h:32:7 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'TestFolderStatusModel' is non-const and globally accessible, consider making it const
class ShareTestHelper;

Check warning on line 33 in src/gui/folderman.h

View workflow job for this annotation

GitHub Actions / build

src/gui/folderman.h:33:7 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'ShareTestHelper' is non-const and globally accessible, consider making it const
class EndToEndTestHelper;
class TestSyncConflictsModel;
Expand Down Expand Up @@ -413,6 +414,7 @@ private slots:
friend class ::TestCfApiShellExtensionsIPC;
friend class ::ShareTestHelper;
friend class ::EndToEndTestHelper;
friend class ::TestFolderStatusModel;
};

} // namespace OCC
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ nextcloud_add_test(SyncConflictsModel)
nextcloud_add_test(DateFieldBackend)
nextcloud_add_test(ClientStatusReporting)

nextcloud_add_test(FolderStatusModel)

target_link_libraries(SecureFileDropTest PRIVATE Nextcloud::sync)
configure_file(fake2eelocksucceeded.json "${PROJECT_BINARY_DIR}/bin/fake2eelocksucceeded.json" COPYONLY)
configure_file(fakefiledrope2eefoldermetadata.json "${PROJECT_BINARY_DIR}/bin/fakefiledrope2eefoldermetadata.json" COPYONLY)
Expand Down
1 change: 1 addition & 0 deletions test/syncenginetestutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ class FakeFolder
[[nodiscard]] OCC::AccountPtr account() const { return _account; }
[[nodiscard]] OCC::SyncEngine &syncEngine() const { return *_syncEngine; }
[[nodiscard]] OCC::SyncJournalDb &syncJournal() const { return *_journalDb; }
[[nodiscard]] FakeQNAM* networkAccessManager() const { return _fakeQnam; }

FileModifier &localModifier() { return _localModifier; }
FileInfo &remoteModifier() { return _fakeQnam->currentRemoteState(); }
Expand Down
81 changes: 81 additions & 0 deletions test/testfolderstatusmodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*

Check notice on line 1 in test/testfolderstatusmodel.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on test/testfolderstatusmodel.cpp

File test/testfolderstatusmodel.cpp does not conform to Custom style guidelines. (lines 15, 35, 53, 54, 55, 56, 57)
* Copyright (C) by Matthieu Gallien <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/

#include <QtTest>

Check failure on line 15 in test/testfolderstatusmodel.cpp

View workflow job for this annotation

GitHub Actions / build

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

'QtTest' file not found
#include <QStandardPaths>
#include <QAbstractItemModelTester>

#include "accountstate.h"
#include "folderman.h"
#include "folderstatusmodel.h"
#include "logger.h"
#include "syncenginetestutils.h"
#include "testhelper.h"

using namespace OCC;
using namespace OCC::Utility;

class TestFolderStatusModel : public QObject

Check warning on line 29 in test/testfolderstatusmodel.cpp

View workflow job for this annotation

GitHub Actions / build

test/testfolderstatusmodel.cpp:29:7 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields:
{
Q_OBJECT

std::unique_ptr<FolderMan> _folderMan;

public:

private Q_SLOTS:
void initTestCase()
{
Logger::instance()->setLogFlush(true);
Logger::instance()->setLogDebug(true);

QStandardPaths::setTestModeEnabled(true);

_folderMan.reset(new FolderMan{});
}

void startModel()
{
FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};

const auto account = fakeFolder.account();
const auto capabilities = QVariantMap {
{QStringLiteral("end-to-end-encryption"), QVariantMap {
{QStringLiteral("enabled"), true},
{QStringLiteral("api-version"), QString::number(2.0)},
}},
};
account->setCapabilities(capabilities);
account->setCredentials(new FakeCredentials{fakeFolder.networkAccessManager()});
account->setUrl(QUrl(("owncloud://somehost/owncloud")));
auto accountState = FakeAccountState(account);
QVERIFY(accountState.isConnected());

auto folderDef = folderDefinition(fakeFolder.localPath());
folderDef.targetPath = "";
const auto folder = FolderMan::instance()->addFolder(&accountState, folderDef);
QVERIFY(folder);

FolderStatusModel test;
test.setAccountState(&accountState);

QSKIP("Initial test implementation is known to be broken");
QAbstractItemModelTester modeltester(&test);

test.fetchMore({});
}
};

QTEST_MAIN(TestFolderStatusModel)

Check warning on line 80 in test/testfolderstatusmodel.cpp

View workflow job for this annotation

GitHub Actions / build

test/testfolderstatusmodel.cpp:80:12 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'TestFolderStatusModel' is non-const and globally accessible, consider making it const
#include "testfolderstatusmodel.moc"

0 comments on commit 9949d0c

Please sign in to comment.