Skip to content
Closed
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
1 change: 0 additions & 1 deletion src/gui/connectionvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ void ConnectionValidator::slotUserFetched(UserInfo *userInfo)

#ifndef TOKEN_AUTH_ONLY
connect(_account->e2e(), &ClientSideEncryption::initializationFinished, this, &ConnectionValidator::reportConnected);
_account->e2e()->setAccount(_account);
_account->e2e()->initialize(nullptr);
#else
reportResult(Connected);
Expand Down
2 changes: 2 additions & 0 deletions src/gui/folderman.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef FOLDERMAN_H
#define FOLDERMAN_H

#include <QByteArray>

Check failure on line 10 in src/gui/folderman.h

View workflow job for this annotation

GitHub Actions / build

src/gui/folderman.h:10:10 [clang-diagnostic-error]

'QByteArray' file not found
#include <QObject>
#include <QQueue>
#include <QList>
Expand All @@ -27,6 +27,7 @@
class EndToEndTestHelper;
class TestSyncConflictsModel;
class TestRemoteWipe;
class FolderManTestHelper;

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

View workflow job for this annotation

GitHub Actions / build

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

variable 'FolderManTestHelper' is non-const and globally accessible, consider making it const

namespace OCC {

Expand Down Expand Up @@ -415,6 +416,7 @@
friend class ::EndToEndTestHelper;
friend class ::TestFolderStatusModel;
friend class ::TestRemoteWipe;
friend class ::FolderManTestHelper;
};

} // namespace OCC
Expand Down
1 change: 1 addition & 0 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ AccountPtr Account::create()
{
AccountPtr acc = AccountPtr(new Account);
acc->setSharedThis(acc);
acc->_e2e.setAccount(acc);
return acc;
}

Expand Down
7 changes: 7 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_library(testutils
sharetestutils.cpp
endtoendtestutils.cpp
activitylistmodeltestutils.cpp
foldermantestutils.cpp
)

target_link_libraries(testutils PUBLIC Nextcloud::sync Qt::Test Qt::Core5Compat)
Expand Down Expand Up @@ -144,6 +145,12 @@ nextcloud_add_test(Folder)
nextcloud_add_test(FolderMan)
nextcloud_add_test(RemoteWipe)

if(NOT BUILD_FILE_PROVIDER_MODULE)
# the File Provider build crashes this test in CI for some reason
# I'm not yet sure what's causing it as it works fine with a classic build...
nextcloud_add_test(AccountSettings)
endif()

configure_file(test_journal.db "${PROJECT_BINARY_DIR}/bin/test_journal.db" COPYONLY)

find_package(CMocka)
Expand Down
17 changes: 17 additions & 0 deletions test/foldermantestutils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "foldermantestutils.h"

FolderManTestHelper::FolderManTestHelper(QObject *parent)

Check warning on line 8 in test/foldermantestutils.cpp

View workflow job for this annotation

GitHub Actions / build

test/foldermantestutils.cpp:8:1 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: fm
: QObject{parent}
{

}

FolderManTestHelper::~FolderManTestHelper()

Check warning on line 14 in test/foldermantestutils.cpp

View workflow job for this annotation

GitHub Actions / build

test/foldermantestutils.cpp:14:22 [modernize-use-equals-default]

use '= default' to define a trivial destructor
{

}
25 changes: 25 additions & 0 deletions test/foldermantestutils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#pragma once

#include <QObject>

Check failure on line 8 in test/foldermantestutils.h

View workflow job for this annotation

GitHub Actions / build

test/foldermantestutils.h:8:10 [clang-diagnostic-error]

'QObject' file not found

#include "gui/folderman.h"

using namespace OCC;

Check warning on line 12 in test/foldermantestutils.h

View workflow job for this annotation

GitHub Actions / build

test/foldermantestutils.h:12:7 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'namespace' is non-const and globally accessible, consider making it const

/// Helper class to enable usage of FolderMan::instance() from within the
/// tested code.
class FolderManTestHelper : public QObject

Check warning on line 16 in test/foldermantestutils.h

View workflow job for this annotation

GitHub Actions / build

test/foldermantestutils.h:16:36 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'QObject' is non-const and globally accessible, consider making it const

Check warning on line 16 in test/foldermantestutils.h

View workflow job for this annotation

GitHub Actions / build

test/foldermantestutils.h:16:7 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'FolderManTestHelper' is non-const and globally accessible, consider making it const
{
Q_OBJECT

public:
explicit FolderManTestHelper(QObject *parent = nullptr);
~FolderManTestHelper() override;

FolderMan fm;
};
59 changes: 59 additions & 0 deletions test/testaccountsettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: CC0-1.0
*
* This software is in the public domain, furnished "as is", without technical
* support, and with no warranty, express or implied, as to its usefulness for
* any purpose.
*/

#include <QtTest>

Check failure on line 10 in test/testaccountsettings.cpp

View workflow job for this annotation

GitHub Actions / build

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

'QtTest' file not found

#include "account.h"
#include "testhelper.h"
#include "foldermantestutils.h"
#include "logger.h"

#include "accountsettings.h"

using namespace OCC;

class TestAccountSettings : public QObject

Check warning on line 21 in test/testaccountsettings.cpp

View workflow job for this annotation

GitHub Actions / build

test/testaccountsettings.cpp:21:7 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: FolderManTestHelper,
{
Q_OBJECT

FolderManTestHelper helper;

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

QStandardPaths::setTestModeEnabled(true);
}

void test_whenAccountStateIsNotConnected_doesNotCrash()
{
auto account = Account::create();
auto accountState = new FakeAccountState(account);
accountState->setStateForTesting(OCC::AccountState::SignedOut);
QCOMPARE_EQ(accountState->state(), OCC::AccountState::SignedOut);
AccountSettings a(accountState);
}

void test_whenAccountStateIsConnected_doesNotCrash()
{
// this occurred because ConnectionValidator used to set the account
// inside a Account's _e2e member, instead of letting Account itself
// do that.

auto account = Account::create();
auto accountState = new FakeAccountState(account);
QCOMPARE_EQ(accountState->state(), OCC::AccountState::Connected);
AccountSettings a(accountState);
}
};

QTEST_MAIN(TestAccountSettings)

Check warning on line 58 in test/testaccountsettings.cpp

View workflow job for this annotation

GitHub Actions / build

test/testaccountsettings.cpp:58:12 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'TestAccountSettings' is non-const and globally accessible, consider making it const
#include "testaccountsettings.moc"
10 changes: 10 additions & 0 deletions test/testhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef TESTHELPER_H
#define TESTHELPER_H

#include "gui/accountstate.h"

Check failure on line 9 in test/testhelper.h

View workflow job for this annotation

GitHub Actions / build

test/testhelper.h:9:10 [clang-diagnostic-error]

'gui/accountstate.h' file not found
#include "gui/folder.h"
#include "creds/httpcredentials.h"

Expand Down Expand Up @@ -44,6 +44,16 @@
public slots:
void checkConnectivity() override {};

void setStateForTesting(OCC::AccountState::State state)
{
if (_state == state) {
return;
}

_state = state;
Q_EMIT stateChanged(state);
}

private slots:
void setState(OCC::AccountState::State state) override { Q_UNUSED(state) };
};
Expand Down
Loading