2024-08-08 17:41:59 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2024-08-08 17:41:59 +00:00
|
|
|
*/
|
|
|
|
|
|
2024-08-10 23:58:24 +00:00
|
|
|
#include "gui/config/ServerConfigDialogState.h"
|
2024-08-08 17:41:59 +00:00
|
|
|
#include "gui/core/ServerConnection.h"
|
|
|
|
|
|
|
|
|
|
#include "shared/gui/mocks/ServerConfigMock.h"
|
|
|
|
|
|
|
|
|
|
#include "gmock/gmock.h"
|
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
|
|
using testing::_;
|
|
|
|
|
using testing::NiceMock;
|
2024-09-17 19:00:25 +00:00
|
|
|
using namespace deskflow::gui;
|
2024-08-08 17:41:59 +00:00
|
|
|
|
|
|
|
|
class QWidget;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
struct DepsMock : public ServerConnection::Deps
|
|
|
|
|
{
|
2024-08-08 17:41:59 +00:00
|
|
|
MOCK_METHOD(
|
2025-02-15 04:37:15 +00:00
|
|
|
messages::NewClientPromptResult, showNewClientPrompt,
|
|
|
|
|
(QWidget * parent, const QString &clientName, bool previousyAccepted), (const, override)
|
2024-10-17 18:04:35 +00:00
|
|
|
);
|
2024-08-08 17:41:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
class ServerConnectionTests : public testing::Test
|
|
|
|
|
{
|
2024-08-08 17:41:59 +00:00
|
|
|
public:
|
|
|
|
|
std::shared_ptr<DepsMock> m_pDeps = std::make_shared<NiceMock<DepsMock>>();
|
|
|
|
|
NiceMock<ServerConfigMock> m_serverConfig;
|
2024-08-10 23:58:24 +00:00
|
|
|
config::ServerConfigDialogState m_serverConfigDialogState;
|
2024-08-08 17:41:59 +00:00
|
|
|
};
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
TEST_F(ServerConnectionTests, handleLogLine_newClient_shouldShowPrompt)
|
|
|
|
|
{
|
2025-03-08 16:41:14 +00:00
|
|
|
ServerConnection serverConnection(nullptr, m_serverConfig, m_serverConfigDialogState, m_pDeps);
|
2024-08-08 17:41:59 +00:00
|
|
|
|
|
|
|
|
QString clientName = "test client";
|
2025-03-08 15:59:53 +00:00
|
|
|
EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, clientName, true)).Times(0);
|
2024-08-08 17:41:59 +00:00
|
|
|
|
|
|
|
|
serverConnection.handleLogLine(R"(unrecognised client name "test client")");
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
TEST_F(ServerConnectionTests, handleLogLine_ignoredClient_shouldNotShowPrompt)
|
|
|
|
|
{
|
2025-03-08 16:41:14 +00:00
|
|
|
ServerConnection serverConnection(nullptr, m_serverConfig, m_serverConfigDialogState, m_pDeps);
|
2025-02-15 04:37:15 +00:00
|
|
|
ON_CALL(*m_pDeps, showNewClientPrompt(_, _, false))
|
|
|
|
|
.WillByDefault(testing::Return(messages::NewClientPromptResult::Ignore));
|
2024-08-08 17:41:59 +00:00
|
|
|
serverConnection.handleLogLine(R"(unrecognised client name "stub")");
|
|
|
|
|
|
2025-02-15 04:37:15 +00:00
|
|
|
EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, _, false)).Times(0);
|
2024-08-08 17:41:59 +00:00
|
|
|
|
|
|
|
|
serverConnection.handleLogLine(R"(unrecognised client name "stub")");
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
TEST_F(ServerConnectionTests, handleLogLine_serverConfigFull_shouldNotShowPrompt)
|
|
|
|
|
{
|
2025-03-08 16:41:14 +00:00
|
|
|
ServerConnection serverConnection(nullptr, m_serverConfig, m_serverConfigDialogState, m_pDeps);
|
2024-08-08 17:41:59 +00:00
|
|
|
ON_CALL(m_serverConfig, isFull()).WillByDefault(testing::Return(true));
|
|
|
|
|
|
2025-02-15 04:37:15 +00:00
|
|
|
EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, _, false)).Times(0);
|
2024-08-08 17:41:59 +00:00
|
|
|
|
|
|
|
|
serverConnection.handleLogLine(R"(unrecognised client name "test client")");
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
TEST_F(ServerConnectionTests, handleLogLine_screenExists_shouldNotShowPrompt)
|
|
|
|
|
{
|
2025-03-08 16:41:14 +00:00
|
|
|
ServerConnection serverConnection(nullptr, m_serverConfig, m_serverConfigDialogState, m_pDeps);
|
2024-08-08 17:41:59 +00:00
|
|
|
ON_CALL(m_serverConfig, screenExists(_)).WillByDefault(testing::Return(true));
|
|
|
|
|
|
2025-02-15 04:37:15 +00:00
|
|
|
EXPECT_CALL(*m_pDeps, showNewClientPrompt(_, _, false)).Times(0);
|
2024-08-08 17:41:59 +00:00
|
|
|
|
|
|
|
|
serverConnection.handleLogLine(R"(unrecognised client name "test client")");
|
|
|
|
|
}
|