refactor: port ServerAppTests to QtTests
This commit is contained in:
parent
14cb921d4c
commit
63e87c16d1
4 changed files with 65 additions and 53 deletions
|
|
@ -61,7 +61,17 @@ create_test(
|
|||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/deskflow"
|
||||
)
|
||||
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
#this test does not work properly on windows / mac os
|
||||
create_test(
|
||||
NAME ServerAppTests
|
||||
DEPENDS app
|
||||
LIBS arch base
|
||||
SOURCE ServerAppTests.cpp
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/deskflow"
|
||||
)
|
||||
|
||||
create_test(
|
||||
NAME X11LayoutParserTests
|
||||
DEPENDS app
|
||||
|
|
|
|||
40
src/unittests/deskflow/ServerAppTests.cpp
Normal file
40
src/unittests/deskflow/ServerAppTests.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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 "ServerAppTests.h"
|
||||
|
||||
#include "deskflow/ServerApp.h"
|
||||
#include "deskflow/ServerArgs.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class MockServerApp : public ServerApp
|
||||
{
|
||||
public:
|
||||
MockServerApp() : ServerApp(nullptr)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
void ServerAppTests::version()
|
||||
{
|
||||
MockServerApp app;
|
||||
QVERIFY(!app.args().m_config);
|
||||
|
||||
std::stringstream buffer;
|
||||
std::streambuf *old = std::cout.rdbuf(buffer.rdbuf());
|
||||
|
||||
app.version();
|
||||
|
||||
std::cout.rdbuf(old);
|
||||
|
||||
static QRegularExpression yearReg(".*[0-9]{4}-[0-9]{4} Deskflow Devs.*");
|
||||
auto result = yearReg.match(QString::fromLatin1(buffer.str()));
|
||||
QVERIFY(result.hasMatch());
|
||||
}
|
||||
|
||||
QTEST_MAIN(ServerAppTests)
|
||||
15
src/unittests/deskflow/ServerAppTests.h
Normal file
15
src/unittests/deskflow/ServerAppTests.h
Normal 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 ServerAppTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
// Test are run in order top to bottom
|
||||
void version();
|
||||
};
|
||||
|
|
@ -1,53 +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 "deskflow/ArgParser.h"
|
||||
#include "deskflow/ServerApp.h"
|
||||
#include "deskflow/ServerArgs.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using ::testing::NiceMock;
|
||||
|
||||
class MockServerApp : public ServerApp
|
||||
{
|
||||
public:
|
||||
MockServerApp() : ServerApp(nullptr)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
TEST(ServerAppTests, runInner_will_handle_configuration_lifetime)
|
||||
{
|
||||
NiceMock<MockServerApp> app;
|
||||
|
||||
EXPECT_FALSE(app.args().m_config);
|
||||
|
||||
const char *argv[]{"deskflow-server"};
|
||||
app.runInner(1, const_cast<char **>(argv), [](int, char **) { return 0; });
|
||||
|
||||
EXPECT_TRUE(app.args().m_config);
|
||||
}
|
||||
|
||||
TEST(ServerAppTests, version_printsYear)
|
||||
{
|
||||
NiceMock<MockServerApp> app;
|
||||
std::stringstream buffer;
|
||||
std::streambuf *old = std::cout.rdbuf(buffer.rdbuf());
|
||||
|
||||
app.version();
|
||||
|
||||
std::cout.rdbuf(old);
|
||||
|
||||
#ifdef WIN32
|
||||
// regex is god awful on windows, so just check that there is a copyright
|
||||
EXPECT_THAT(buffer.str(), testing::HasSubstr("Deskflow Devs"));
|
||||
#else
|
||||
std::string expectedPattern = ".*[0-9]{4}-[0-9]{4} Deskflow Devs.*";
|
||||
EXPECT_THAT(buffer.str(), testing::MatchesRegex(expectedPattern));
|
||||
#endif // WIN32
|
||||
}
|
||||
Loading…
Reference in a new issue