* Use Deskflow Name * Remove business-oriented options from issue templates * Remove business-oriented workflow * Bump version to 3.0.0 (to avoid confusion with previously used version numbers 1.x & 2.x) * Update readme to reflect new project name and goals * Found some more "synergy" to rename * Rename `synlib` to `app` * Rename `syntool` to `deskflow-legacy` * Rename `synwinhk` to `dfwhook` * Rename dirs from synergy to deskflow * Rename more "Synergy" files * Rename app bundle ID * Fixed copyright typo * Rename only title in serial key dialog (to be moved downstream later) * Preserve original serial key window for moving downstream * Restore dialogs ready for moving downstream * Rename `QDeskflowApplication` to `DeskflowApplication` (the Q is confusing) * Restore Volker's original project name * Fixed mimetype * Fixed weird grammar * Fixed (more) weird grammar * Broken link, restoring (but we should move all links out of source) * Broken link, restoring (but we should move all links out of source) * Add write permission to valgrind-analysis.yml * Restore AUR conflicts * Apply Clang format * Update ChangeLog * Back out version change --------- Co-authored-by: Nick Bolton <nick@symless.com>
193 lines
5.8 KiB
C++
193 lines
5.8 KiB
C++
/*
|
|
* Deskflow -- mouse and keyboard sharing utility
|
|
* Copyright (C) 2024 Symless Ltd.
|
|
*
|
|
* This package is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* found in the file LICENSE that should have accompanied this file.
|
|
*
|
|
* This package 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.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "gui/config/ConfigScopes.h"
|
|
|
|
#include "gmock/gmock.h"
|
|
#include <gmock/gmock.h>
|
|
#include <gtest/gtest.h>
|
|
#include <memory>
|
|
|
|
using namespace testing;
|
|
using namespace deskflow::gui;
|
|
using namespace deskflow::gui::proxy;
|
|
|
|
namespace {
|
|
|
|
class QSettingsProxyMock : public QSettingsProxy {
|
|
public:
|
|
MOCK_METHOD(void, loadSystem, (), (override));
|
|
MOCK_METHOD(void, loadUser, (), (override));
|
|
MOCK_METHOD(QString, fileName, (), (const, override));
|
|
MOCK_METHOD(void, sync, (), (override));
|
|
MOCK_METHOD(bool, isWritable, (), (const, override));
|
|
MOCK_METHOD(bool, contains, (const QString &), (const, override));
|
|
MOCK_METHOD(QVariant, value, (const QString &), (const, override));
|
|
MOCK_METHOD(
|
|
QVariant, value, (const QString &, const QVariant &), (const, override));
|
|
MOCK_METHOD(void, setValue, (const QString &, const QVariant &), (override));
|
|
};
|
|
|
|
struct DepsMock : public ConfigScopes::Deps {
|
|
DepsMock() {
|
|
ON_CALL(*this, makeUserSettings()).WillByDefault(Return(m_pUserSettings));
|
|
ON_CALL(*this, makeSystemSettings())
|
|
.WillByDefault(Return(m_pSystemSettings));
|
|
}
|
|
|
|
MOCK_METHOD(
|
|
std::shared_ptr<QSettingsProxy>, makeUserSettings, (), (override));
|
|
MOCK_METHOD(
|
|
std::shared_ptr<QSettingsProxy>, makeSystemSettings, (), (override));
|
|
|
|
std::shared_ptr<QSettingsProxyMock> m_pUserSettings =
|
|
std::make_shared<NiceMock<QSettingsProxyMock>>();
|
|
std::shared_ptr<QSettingsProxyMock> m_pSystemSettings =
|
|
std::make_shared<NiceMock<QSettingsProxyMock>>();
|
|
};
|
|
|
|
} // namespace
|
|
|
|
TEST(ConfigScopesTests, ctor_callsMakeUserSettings) {
|
|
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
|
|
|
EXPECT_CALL(*deps, makeUserSettings()).Times(1);
|
|
|
|
ConfigScopes configScopes(deps);
|
|
}
|
|
|
|
TEST(ConfigScopesTests, ctor_callsMakeSystemSettings) {
|
|
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
|
|
|
EXPECT_CALL(*deps, makeSystemSettings()).Times(1);
|
|
|
|
ConfigScopes configScopes(deps);
|
|
}
|
|
|
|
TEST(ConfigScopesTests, save_syncsBothScopes) {
|
|
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
|
|
|
ConfigScopes configScopes(deps);
|
|
|
|
EXPECT_CALL(*deps->m_pUserSettings, sync()).Times(1);
|
|
EXPECT_CALL(*deps->m_pSystemSettings, sync()).Times(1);
|
|
|
|
configScopes.save();
|
|
}
|
|
|
|
TEST(ConfigScopesTests, activeSettings_returnsUserSettingsByDefault) {
|
|
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
|
|
|
ConfigScopes configScopes(deps);
|
|
|
|
EXPECT_EQ(&configScopes.activeSettings(), deps->m_pUserSettings.get());
|
|
}
|
|
|
|
TEST(ConfigScopesTests, activeSettings_returnsSystemSettingsWhenSystemScope) {
|
|
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
|
|
|
ConfigScopes configScopes(deps);
|
|
configScopes.setActiveScope(ConfigScopes::Scope::System);
|
|
|
|
EXPECT_EQ(&configScopes.activeSettings(), deps->m_pSystemSettings.get());
|
|
}
|
|
|
|
TEST(ConfigScopesTests, setActiveScope_setsCurrentScope) {
|
|
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
|
|
|
ConfigScopes configScopes(deps);
|
|
|
|
configScopes.setActiveScope(ConfigScopes::Scope::System);
|
|
|
|
EXPECT_EQ(configScopes.activeScope(), ConfigScopes::Scope::System);
|
|
}
|
|
|
|
TEST(
|
|
ConfigScopesTests,
|
|
isActiveScopeWritable_returnsTrueWhenUserSettingsWritable) {
|
|
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
|
|
|
ConfigScopes configScopes(deps);
|
|
|
|
EXPECT_CALL(*deps->m_pUserSettings, isWritable()).WillOnce(Return(true));
|
|
|
|
EXPECT_TRUE(configScopes.isActiveScopeWritable());
|
|
}
|
|
|
|
TEST(
|
|
ConfigScopesTests,
|
|
scopeContains_byDefault_returnsTrueWhenUserSettingsContainsKey) {
|
|
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
|
|
|
ON_CALL(*deps->m_pUserSettings, contains(_)).WillByDefault(Return(true));
|
|
|
|
ConfigScopes configScopes(deps);
|
|
|
|
EXPECT_TRUE(configScopes.scopeContains("stub"));
|
|
}
|
|
|
|
TEST(
|
|
ConfigScopesTests,
|
|
scopeContains_userScope_returnsTrueWhenUserSettingsContainsKey) {
|
|
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
|
|
|
ON_CALL(*deps->m_pUserSettings, contains(_)).WillByDefault(Return(true));
|
|
|
|
ConfigScopes configScopes(deps);
|
|
|
|
EXPECT_TRUE(configScopes.scopeContains("stub", ConfigScopes::Scope::User));
|
|
}
|
|
|
|
TEST(
|
|
ConfigScopesTests,
|
|
scopeContains_systemScope_returnsTrueWhenSystemSettingsContainsKey) {
|
|
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
|
|
|
ON_CALL(*deps->m_pSystemSettings, contains(_)).WillByDefault(Return(true));
|
|
|
|
ConfigScopes configScopes(deps);
|
|
|
|
EXPECT_TRUE(configScopes.scopeContains("stub", ConfigScopes::Scope::System));
|
|
}
|
|
|
|
TEST(ConfigScopesTests, activeFilePath_returnsUserSettingsFileNameByDefault) {
|
|
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
|
ON_CALL(*deps->m_pUserSettings, fileName()).WillByDefault(Return("test"));
|
|
|
|
ConfigScopes configScopes(deps);
|
|
|
|
EXPECT_EQ(configScopes.activeFilePath(), "test");
|
|
}
|
|
|
|
TEST(ConfigScopesTests, getFromScope_byDefault_returnsValueFromActiveSettings) {
|
|
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
|
ON_CALL(*deps->m_pUserSettings, value(_, _)).WillByDefault(Return("test"));
|
|
|
|
ConfigScopes configScopes(deps);
|
|
|
|
EXPECT_EQ(configScopes.getFromScope("stub"), "test");
|
|
}
|
|
|
|
TEST(ConfigScopesTests, setInScope_byDefault_setsValueInActiveSettings) {
|
|
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
|
|
|
ConfigScopes configScopes(deps);
|
|
|
|
EXPECT_CALL(*deps->m_pUserSettings, setValue(_, _)).Times(1);
|
|
|
|
configScopes.setInScope("stub", "test");
|
|
}
|