refactor: port ServerTests to QtTests

remove TEST_ENV items from Server
This commit is contained in:
sithlord48
2025-04-06 23:34:02 -04:00
committed by Nick Bolton
parent d742901775
commit b56a282a9c
7 changed files with 57 additions and 43 deletions

View File

@ -44,8 +44,7 @@ Server::Server(
ServerConfig &config, PrimaryClient *primaryClient, deskflow::Screen *screen, IEventQueue *events,
deskflow::ServerArgs const &args
)
: m_mock(false),
m_primaryClient(primaryClient),
: m_primaryClient(primaryClient),
m_active(primaryClient),
m_seqNum(0),
m_xDelta(0),
@ -178,10 +177,6 @@ Server::Server(
Server::~Server()
{
if (m_mock) {
return;
}
// remove event handlers and timers
m_events->removeHandler(EventTypes::KeyStateKeyDown, m_inputFilter);
m_events->removeHandler(EventTypes::KeyStateKeyUp, m_inputFilter);

View File

@ -129,16 +129,6 @@ public:
Server &operator=(Server const &) = delete;
Server &operator=(Server &&) = delete;
#ifdef TEST_ENV
Server() : m_mock(true), m_config(nullptr)
{
}
void setActive(BaseClientProxy *active)
{
m_active = active;
}
#endif
//! @name manipulators
//@{
@ -356,9 +346,6 @@ private:
// force the cursor off of \p client
void forceLeaveClient(BaseClientProxy *client);
public:
bool m_mock;
private:
class ClipboardInfo
{

View File

@ -1,24 +0,0 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2014 - 2016 Symless Ltd.
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#include "lib/server/Server.h"
#include <gtest/gtest.h>
TEST(ServerTests, SwitchToScreenInfo_alloc_screen)
{
auto info = Server::SwitchToScreenInfo::alloc("test");
EXPECT_STREQ(info->m_screen, "test");
}
TEST(ServerTests, KeyboardBroadcastInfo_alloc_stateAndSceens)
{
auto info = Server::KeyboardBroadcastInfo::alloc(Server::KeyboardBroadcastInfo::State::kOn, "test");
EXPECT_EQ(info->m_state, Server::KeyboardBroadcastInfo::State::kOn);
EXPECT_STREQ(info->m_screens, "test");
}

View File

@ -47,6 +47,7 @@ add_subdirectory(common)
add_subdirectory(deskflow)
add_subdirectory(gui)
add_subdirectory(platform)
add_subdirectory(server)
#make sure to use CI only plugin on Unix
if (UNIX AND NOT APPLE)

View File

@ -0,0 +1,15 @@
# SPDX-FileCopyrightText: 2025 Deskflow Developers
# SPDX-License-Identifier: MIT
if(WIN32)
set(extra_libs version ${cli11_lib} ${tomlPP_lib} app mt net)
endif()
create_test(
NAME ServerTests
DEPENDS server
LIBS base arch ${extra_libs}
SOURCE ServerTests.cpp
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/server"
)

View File

@ -0,0 +1,25 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
* SPDX-FileCopyrightText: (C) 2014 - 2016 Symless Ltd.
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#include "ServerTests.h"
#include "../../lib/server/Server.h"
void ServerTests::SwitchToScreenInfo_alloc_screen()
{
auto actual = Server::SwitchToScreenInfo::alloc("test");
QCOMPARE(actual->m_screen, "test");
}
void ServerTests::KeyboardBroadcastInfo_alloc_stateAndSceens()
{
auto info = Server::KeyboardBroadcastInfo::alloc(Server::KeyboardBroadcastInfo::State::kOn, "test");
QCOMPARE(info->m_state, Server::KeyboardBroadcastInfo::State::kOn);
QCOMPARE(info->m_screens, "test");
}
QTEST_MAIN(ServerTests)

View File

@ -0,0 +1,15 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#include <QTest>
class ServerTests : public QObject
{
Q_OBJECT
private slots:
void SwitchToScreenInfo_alloc_screen();
void KeyboardBroadcastInfo_alloc_stateAndSceens();
};