Refactor: deskflow-core remove non essential options move CoreArgs and CoreArgParse to apps/deskflow-core
This commit is contained in:
parent
34f56af6d6
commit
41d5359f4d
12 changed files with 129 additions and 797 deletions
|
|
@ -5,7 +5,13 @@
|
|||
|
||||
set(target ${CMAKE_PROJECT_NAME}-core)
|
||||
|
||||
add_executable(${target} "${target}.cpp")
|
||||
add_executable(${target}
|
||||
"${target}.cpp"
|
||||
CoreArgs.h
|
||||
CoreArgParser.h
|
||||
CoreArgParser.cpp
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
# Generate rc file
|
||||
set(EXE_DESCRIPTION "${CMAKE_PROJECT_PROPER_NAME} combined server and client application")
|
||||
|
|
|
|||
98
src/apps/deskflow-core/CoreArgParser.cpp
Normal file
98
src/apps/deskflow-core/CoreArgParser.cpp
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* 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 "CoreArgParser.h"
|
||||
#include "CoreArgs.h"
|
||||
#include "VersionInfo.h"
|
||||
|
||||
#include "common/Constants.h"
|
||||
#include "common/ExitCodes.h"
|
||||
#include "common/Settings.h"
|
||||
#include "deskflow/ProtocolTypes.h"
|
||||
|
||||
const QString CoreArgParser::s_appName = QStringLiteral("%1-core").arg(kAppId);
|
||||
const QString CoreArgParser::s_headerText = QStringLiteral("%1: %2\n").arg(s_appName, kDisplayVersion);
|
||||
|
||||
CoreArgParser::CoreArgParser(const QStringList &args)
|
||||
{
|
||||
m_parser.setApplicationDescription(kAppDescription);
|
||||
m_parser.addPositionalArgument("coremode", "The mode to start in either: server or client", "coremode");
|
||||
|
||||
m_parser.addOptions(CoreArgs::options);
|
||||
m_parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
|
||||
m_parser.setOptionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsOptions);
|
||||
m_parser.parse(args);
|
||||
|
||||
m_helpText = m_parser.helpText().replace("<executable_name>", s_appName);
|
||||
m_helpText.replace("[options] coremode", "coremode [options]");
|
||||
}
|
||||
|
||||
void CoreArgParser::parse()
|
||||
{
|
||||
auto posArgs = m_parser.positionalArguments();
|
||||
if (posArgs.isEmpty()) {
|
||||
showHelpText();
|
||||
exit(s_exitSuccess);
|
||||
}
|
||||
|
||||
const QString mode = posArgs.takeFirst();
|
||||
m_serverMode = (mode.compare("server", Qt::CaseInsensitive) == 0);
|
||||
m_clientMode = (mode.compare("client", Qt::CaseInsensitive) == 0);
|
||||
|
||||
if ((!m_clientMode && !m_serverMode) || mode.isEmpty()) {
|
||||
showHelpText();
|
||||
exit(s_exitSuccess);
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::configOption)) {
|
||||
Settings::setSettingsFile(m_parser.value(CoreArgs::configOption));
|
||||
}
|
||||
}
|
||||
|
||||
[[noreturn]] void CoreArgParser::showHelpText() const
|
||||
{
|
||||
QTextStream(stdout) << helpText();
|
||||
exit(s_exitSuccess);
|
||||
}
|
||||
|
||||
QString CoreArgParser::helpText() const
|
||||
{
|
||||
return QStringLiteral("%1%2").arg(s_headerText, m_helpText);
|
||||
}
|
||||
|
||||
QString CoreArgParser::versionText() const
|
||||
{
|
||||
const static auto vString = QStringLiteral("%1 v%2, protocol v%3.%4\n%5\n");
|
||||
return vString.arg(
|
||||
s_appName, kDisplayVersion, QString::number(kProtocolMajorVersion), QString::number(kProtocolMinorVersion),
|
||||
kCopyright
|
||||
);
|
||||
}
|
||||
|
||||
QString CoreArgParser::errorText() const
|
||||
{
|
||||
return m_parser.errorText();
|
||||
}
|
||||
|
||||
bool CoreArgParser::help() const
|
||||
{
|
||||
return m_parser.isSet(CoreArgs::helpOption);
|
||||
}
|
||||
|
||||
bool CoreArgParser::version() const
|
||||
{
|
||||
return m_parser.isSet(CoreArgs::versionOption);
|
||||
}
|
||||
|
||||
bool CoreArgParser::serverMode() const
|
||||
{
|
||||
return m_serverMode;
|
||||
}
|
||||
|
||||
bool CoreArgParser::clientMode() const
|
||||
{
|
||||
return m_clientMode;
|
||||
}
|
||||
|
|
@ -33,7 +33,6 @@ public:
|
|||
bool version() const;
|
||||
bool serverMode() const;
|
||||
bool clientMode() const;
|
||||
const char *display() const;
|
||||
|
||||
private:
|
||||
[[noreturn]] void showHelpText() const;
|
||||
22
src/apps/deskflow-core/CoreArgs.h
Normal file
22
src/apps/deskflow-core/CoreArgs.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QCommandLineOption>
|
||||
/**
|
||||
* @brief The CoreArgs class
|
||||
* This class contains args for the CoreArgParser
|
||||
*/
|
||||
struct CoreArgs
|
||||
{
|
||||
inline static const auto helpOption = QCommandLineOption({"h", "help"}, "Display Help on the command line");
|
||||
inline static const auto versionOption = QCommandLineOption({"v", "version"}, "Display version information");
|
||||
inline static const auto configOption =
|
||||
QCommandLineOption({"s", "settings"}, "override configuration file to use", "configFile");
|
||||
|
||||
inline static const auto options = {helpOption, versionOption, configOption};
|
||||
};
|
||||
|
|
@ -6,12 +6,13 @@
|
|||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "CoreArgParser.h"
|
||||
|
||||
#include "arch/Arch.h"
|
||||
#include "base/EventQueue.h"
|
||||
#include "base/Log.h"
|
||||
#include "common/ExitCodes.h"
|
||||
#include "deskflow/ClientApp.h"
|
||||
#include "deskflow/CoreArgParser.h"
|
||||
#include "deskflow/ServerApp.h"
|
||||
|
||||
#if SYSAPI_WIN32
|
||||
|
|
|
|||
|
|
@ -37,9 +37,6 @@ add_library(${lib_name} STATIC ${PLATFORM_CODE}
|
|||
Clipboard.h
|
||||
ClipboardChunk.cpp
|
||||
ClipboardChunk.h
|
||||
CoreArgParser.cpp
|
||||
CoreArgParser.h
|
||||
CoreArgs.h
|
||||
DaemonApp.cpp
|
||||
DaemonApp.h
|
||||
DeskflowException.cpp
|
||||
|
|
|
|||
|
|
@ -1,199 +0,0 @@
|
|||
/*
|
||||
* 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 "CoreArgParser.h"
|
||||
#include "CoreArgs.h"
|
||||
#include "VersionInfo.h"
|
||||
#include "common/Constants.h"
|
||||
#include "common/ExitCodes.h"
|
||||
#include "common/Settings.h"
|
||||
#include "deskflow/ProtocolTypes.h"
|
||||
|
||||
const QString CoreArgParser::s_appName = QStringLiteral("%1-core").arg(kAppId);
|
||||
const QString CoreArgParser::s_headerText = QStringLiteral("%1: %2\n").arg(s_appName, kDisplayVersion);
|
||||
|
||||
CoreArgParser::CoreArgParser(const QStringList &args)
|
||||
{
|
||||
m_parser.setApplicationDescription(kAppDescription);
|
||||
m_parser.addPositionalArgument("coremode", "The mode to start in either: server or client", "coremode");
|
||||
|
||||
m_parser.addOptions(CoreArgs::options);
|
||||
m_parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
|
||||
m_parser.setOptionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsOptions);
|
||||
m_parser.parse(args);
|
||||
|
||||
m_helpText = m_parser.helpText().replace("<executable_name>", s_appName);
|
||||
m_helpText.replace("[options] coremode", "coremode [options]");
|
||||
}
|
||||
|
||||
void CoreArgParser::parse()
|
||||
{
|
||||
auto posArgs = m_parser.positionalArguments();
|
||||
if (posArgs.isEmpty()) {
|
||||
showHelpText();
|
||||
exit(s_exitSuccess);
|
||||
}
|
||||
|
||||
const QString mode = posArgs.takeFirst();
|
||||
m_serverMode = (mode.compare("server", Qt::CaseInsensitive) == 0);
|
||||
m_clientMode = (mode.compare("client", Qt::CaseInsensitive) == 0);
|
||||
|
||||
if ((!m_clientMode && !m_serverMode) || mode.isEmpty()) {
|
||||
showHelpText();
|
||||
exit(s_exitSuccess);
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::configOption)) {
|
||||
Settings::setSettingsFile(m_parser.value(CoreArgs::configOption));
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::interfaceOption)) {
|
||||
Settings::setValue(Settings::Core::Interface, m_parser.value(CoreArgs::interfaceOption));
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::portOption)) {
|
||||
Settings::setValue(Settings::Core::Port, m_parser.value(CoreArgs::portOption));
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::nameOption)) {
|
||||
Settings::setValue(Settings::Core::ScreenName, m_parser.value(CoreArgs::nameOption));
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::logLevelOption)) {
|
||||
Settings::setValue(Settings::Log::Level, Settings::logLevelToInt(m_parser.value(CoreArgs::logLevelOption)));
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::logFileOption)) {
|
||||
Settings::setValue(Settings::Log::File, m_parser.value(CoreArgs::logFileOption));
|
||||
Settings::setValue(Settings::Log::ToFile, true);
|
||||
} else {
|
||||
Settings::setValue(Settings::Log::ToFile, false);
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::secureOption)) {
|
||||
bool value =
|
||||
((m_parser.value(CoreArgs::secureOption).toLower() == "true") || (m_parser.value(CoreArgs::secureOption) == "1")
|
||||
);
|
||||
Settings::setValue(Settings::Security::TlsEnabled, value);
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::tlsCertOption)) {
|
||||
Settings::setValue(Settings::Security::Certificate, m_parser.value(CoreArgs::tlsCertOption));
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::preventSleepOption)) {
|
||||
bool value =
|
||||
((m_parser.value(CoreArgs::preventSleepOption).toLower() == "true") ||
|
||||
(m_parser.value(CoreArgs::preventSleepOption) == "1"));
|
||||
Settings::setValue(Settings::Core::PreventSleep, value);
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::displayOption)) {
|
||||
auto value = m_parser.value(CoreArgs::displayOption);
|
||||
Settings::setValue(Settings::Core::Display, value);
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::restartOption)) {
|
||||
bool value =
|
||||
((m_parser.value(CoreArgs::restartOption).toLower() == "true") ||
|
||||
(m_parser.value(CoreArgs::restartOption) == "1"));
|
||||
Settings::setValue(Settings::Core::RestartOnFailure, value);
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::useHooksOption)) {
|
||||
bool value =
|
||||
((m_parser.value(CoreArgs::useHooksOption).toLower() == "true") ||
|
||||
(m_parser.value(CoreArgs::useHooksOption) == "1"));
|
||||
Settings::setValue(Settings::Core::UseHooks, value);
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::peerCheckOption)) {
|
||||
bool value =
|
||||
((m_parser.value(CoreArgs::peerCheckOption).toLower() == "true") ||
|
||||
(m_parser.value(CoreArgs::peerCheckOption) == "1"));
|
||||
Settings::setValue(Settings::Security::CheckPeers, value);
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::serverConfigOption)) {
|
||||
Settings::setValue(Settings::Server::ExternalConfigFile, m_parser.value(CoreArgs::serverConfigOption));
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::yscrollOption)) {
|
||||
Settings::setValue(Settings::Client::ScrollSpeed, m_parser.value(CoreArgs::yscrollOption));
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::languageSyncOption)) {
|
||||
bool value =
|
||||
((m_parser.value(CoreArgs::languageSyncOption).toLower() == "true") ||
|
||||
(m_parser.value(CoreArgs::languageSyncOption) == "1"));
|
||||
Settings::setValue(Settings::Client::LanguageSync, value);
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::invertScrollOption)) {
|
||||
bool value =
|
||||
((m_parser.value(CoreArgs::invertScrollOption).toLower() == "true") ||
|
||||
(m_parser.value(CoreArgs::invertScrollOption) == "1"));
|
||||
Settings::setValue(Settings::Client::InvertScrollDirection, value);
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::remoteHostOption)) {
|
||||
Settings::setValue(Settings::Client::RemoteHost, m_parser.value(CoreArgs::remoteHostOption));
|
||||
}
|
||||
}
|
||||
|
||||
[[noreturn]] void CoreArgParser::showHelpText() const
|
||||
{
|
||||
QTextStream(stdout) << helpText();
|
||||
exit(s_exitSuccess);
|
||||
}
|
||||
|
||||
QString CoreArgParser::helpText() const
|
||||
{
|
||||
return QStringLiteral("%1%2").arg(s_headerText, m_helpText);
|
||||
}
|
||||
|
||||
QString CoreArgParser::versionText() const
|
||||
{
|
||||
const static auto vString = QStringLiteral("%1 v%2, protocol v%3.%4\n%5\n");
|
||||
return vString.arg(
|
||||
s_appName, kDisplayVersion, QString::number(kProtocolMajorVersion), QString::number(kProtocolMinorVersion),
|
||||
kCopyright
|
||||
);
|
||||
}
|
||||
|
||||
QString CoreArgParser::errorText() const
|
||||
{
|
||||
return m_parser.errorText();
|
||||
}
|
||||
|
||||
bool CoreArgParser::help() const
|
||||
{
|
||||
return m_parser.isSet(CoreArgs::helpOption);
|
||||
}
|
||||
|
||||
bool CoreArgParser::version() const
|
||||
{
|
||||
return m_parser.isSet(CoreArgs::versionOption);
|
||||
}
|
||||
|
||||
bool CoreArgParser::serverMode() const
|
||||
{
|
||||
return m_serverMode;
|
||||
}
|
||||
|
||||
bool CoreArgParser::clientMode() const
|
||||
{
|
||||
return m_clientMode;
|
||||
}
|
||||
|
||||
const char *CoreArgParser::display() const
|
||||
{
|
||||
#if WINAPI_XWINDOWS
|
||||
return qPrintable(m_parser.value(CoreArgs::displayOption));
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QCommandLineOption>
|
||||
/**
|
||||
* @brief The CoreArgs class
|
||||
* This class contains args for the CoreArgParser
|
||||
*/
|
||||
struct CoreArgs
|
||||
{
|
||||
inline static const auto displayOption =
|
||||
QCommandLineOption("display", "When in X mode, connect to the X server at <display>", "display");
|
||||
|
||||
inline static const auto helpOption = QCommandLineOption({"h", "help"}, "Display Help on the command line");
|
||||
inline static const auto versionOption = QCommandLineOption({"v", "version"}, "Display version information");
|
||||
inline static const auto configOption = QCommandLineOption(
|
||||
{"s", "settings"}, "override configuration file to use", "configFile"
|
||||
); // use -c later, now avoid breaking the serverApp args.
|
||||
inline static const auto interfaceOption = QCommandLineOption(
|
||||
{"i", "interface"},
|
||||
"Use a specific interface for the connection. Instead of any address in client mode or listening on all "
|
||||
"addresses in server mode address.\n address must be the IP address or hostname of an interface on the system.",
|
||||
"address"
|
||||
);
|
||||
inline static const auto portOption =
|
||||
QCommandLineOption({"p", "port"}, "Port to use in place of default port", "port");
|
||||
inline static const auto nameOption =
|
||||
QCommandLineOption({"n", "name"}, "use screen-name instead the hostname to identify this screen", "screen-name");
|
||||
|
||||
inline static const auto logLevelOption = QCommandLineOption(
|
||||
"log-level",
|
||||
"filter out log messages with priority below level.\nlevel may be:\nFATAL, ERROR, WARNING, NOTE, "
|
||||
"INFO, DEBUG, DEBUG1, DEBUG2.",
|
||||
"level"
|
||||
);
|
||||
|
||||
inline static const auto logFileOption = QCommandLineOption({"l", "log"}, "Write messages to file", "file");
|
||||
|
||||
inline static const auto secureOption =
|
||||
QCommandLineOption("secure", "Enable TLS encryption (default: true)", "value");
|
||||
|
||||
inline static const auto tlsCertOption =
|
||||
QCommandLineOption("tls-cert", "Use file in place of default TLS certificate path", "file");
|
||||
|
||||
inline static const auto preventSleepOption = QCommandLineOption(
|
||||
"prevent-sleep", "When true the machine will be prevented from sleeping while the program is running", "value"
|
||||
);
|
||||
|
||||
inline static const auto restartOption = QCommandLineOption(
|
||||
{"r", "restartOnFailure"}, "Set if the core should automatically restart if it fails", "value"
|
||||
);
|
||||
|
||||
inline static const auto useHooksOption =
|
||||
QCommandLineOption("useHooks", "Sets if hooks are used on Windows", "value");
|
||||
|
||||
// Server Options
|
||||
inline static const auto peerCheckOption = QCommandLineOption(
|
||||
"peerCertCheck", "Server Mode: Enable client SSL certificate checking (default: true)", "value"
|
||||
);
|
||||
|
||||
inline static const auto serverConfigOption =
|
||||
QCommandLineOption("serverConfig", "Server Mode: File to load as server config", "path");
|
||||
|
||||
// Client Options
|
||||
inline static const auto yscrollOption =
|
||||
QCommandLineOption("yscroll", "Client Mode: Vertical scrolling delta (default: 120)", "value");
|
||||
|
||||
inline static const auto languageSyncOption =
|
||||
QCommandLineOption("languageSync", "Client Mode: Sync language with client (default: false)", "value");
|
||||
|
||||
inline static const auto invertScrollOption = QCommandLineOption(
|
||||
"invertScrollDirection", "Client Mode: Set scroll direciton to be inverted (default: false)", "value"
|
||||
);
|
||||
|
||||
inline static const auto remoteHostOption =
|
||||
QCommandLineOption("remoteHost", "Client Mode: Sets the remote host in the settings file", "hostname");
|
||||
|
||||
inline static const auto options = {helpOption, versionOption, configOption, interfaceOption,
|
||||
portOption, nameOption, logLevelOption, logFileOption,
|
||||
secureOption, tlsCertOption, preventSleepOption, restartOption,
|
||||
displayOption, useHooksOption, peerCheckOption, serverConfigOption,
|
||||
yscrollOption, languageSyncOption, invertScrollOption, remoteHostOption};
|
||||
};
|
||||
|
|
@ -342,7 +342,6 @@ void CoreProcess::start(std::optional<ProcessMode> processModeOption)
|
|||
if (Settings::value(Settings::Log::ToFile).toBool()) {
|
||||
const auto logFile = Settings::value(Settings::Log::File).toString();
|
||||
QDir(QFileInfo(logFile).absolutePath()).mkpath(".");
|
||||
args.append({QStringLiteral("--log"), logFile});
|
||||
qInfo().noquote() << "log file:" << logFile;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,14 +5,6 @@ if(WIN32)
|
|||
set(extra_libs version)
|
||||
endif()
|
||||
|
||||
create_test(
|
||||
NAME CoreArgParserTests
|
||||
DEPENDS app
|
||||
LIBS ${extra_libs}
|
||||
SOURCE CoreArgParserTests.cpp
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/deskflow"
|
||||
)
|
||||
|
||||
create_test(
|
||||
NAME ClipboardTests
|
||||
DEPENDS app
|
||||
|
|
|
|||
|
|
@ -1,433 +0,0 @@
|
|||
/*
|
||||
* 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 "CoreArgParserTests.h"
|
||||
#include "common/Settings.h"
|
||||
#include "deskflow/CoreArgParser.h"
|
||||
|
||||
void CoreArgParserTests::initTestCase()
|
||||
{
|
||||
QDir dir;
|
||||
QVERIFY(dir.mkpath(m_settingsPath));
|
||||
|
||||
QFile oldSettings(m_settingsFile);
|
||||
if (oldSettings.exists())
|
||||
oldSettings.remove();
|
||||
|
||||
Settings::setSettingsFile(m_settingsFile);
|
||||
}
|
||||
|
||||
void CoreArgParserTests::interfaceLong()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--interface", "mock_address"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE(Settings::value(Settings::Core::Interface).toString(), "mock_address");
|
||||
}
|
||||
|
||||
void CoreArgParserTests::interfaceShort()
|
||||
{
|
||||
QStringList args = {"stub", "client", "-i", "address"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE(Settings::value(Settings::Core::Interface).toString(), "address");
|
||||
}
|
||||
|
||||
void CoreArgParserTests::portLong()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--port", "28771"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE(Settings::value(Settings::Core::Port).toInt(), 28771);
|
||||
}
|
||||
|
||||
void CoreArgParserTests::portShort()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--p", "18768"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE(Settings::value(Settings::Core::Port).toInt(), 18768);
|
||||
}
|
||||
|
||||
void CoreArgParserTests::nameLong()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--name", "FancyName"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE(Settings::value(Settings::Core::ScreenName).toString(), "FancyName");
|
||||
}
|
||||
|
||||
void CoreArgParserTests::nameShort()
|
||||
{
|
||||
QStringList args = {"stub", "client", "-n", "ShortName"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE(Settings::value(Settings::Core::ScreenName).toString(), "ShortName");
|
||||
}
|
||||
|
||||
void CoreArgParserTests::logLevel()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--log-level", "DEBUG1"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE(Settings::value(Settings::Log::Level).toInt(), 6);
|
||||
}
|
||||
|
||||
void CoreArgParserTests::logFile()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--log", "mock_filename"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE(Settings::value(Settings::Log::File).toString(), "mock_filename");
|
||||
}
|
||||
|
||||
void CoreArgParserTests::logFileWithSpace()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--log", "mock filename"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE(Settings::value(Settings::Log::File).toString(), "mock filename");
|
||||
}
|
||||
|
||||
void CoreArgParserTests::secure_false()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--secure", "false"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Security::TlsEnabled).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::secure_true()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--secure", "true"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Security::TlsEnabled).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::secure_0()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--secure", "0"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Security::TlsEnabled).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::secure_1()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--secure", "1"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Security::TlsEnabled).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::tlsCert()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--tls-cert", "certFile"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE(Settings::value(Settings::Security::Certificate).toString(), "certFile");
|
||||
}
|
||||
|
||||
void CoreArgParserTests::preventSleep_false()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--prevent-sleep", "false"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Core::PreventSleep).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::preventSleep_1()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--prevent-sleep", "1"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Core::PreventSleep).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::preventSleep_0()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--prevent-sleep", "0"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Core::PreventSleep).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::restartLongOption_0()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--restartOnFailure", "0"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Core::RestartOnFailure).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::restartLongOption_1()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--restartOnFailure", "1"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Core::RestartOnFailure).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::restartLongOption_false()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--restartOnFailure", "false"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Core::RestartOnFailure).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::restartLongOption_true()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--restartOnFailure", "true"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Core::RestartOnFailure).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::restartShortOption_0()
|
||||
{
|
||||
QStringList args = {"stub", "client", "-r", "0"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Core::RestartOnFailure).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::restartShortOption_1()
|
||||
{
|
||||
QStringList args = {"stub", "client", "-r", "1"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Core::RestartOnFailure).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::restartShortOption_false()
|
||||
{
|
||||
QStringList args = {"stub", "client", "-r", "false"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Core::RestartOnFailure).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::restartShortOption_true()
|
||||
{
|
||||
QStringList args = {"stub", "client", "-r", "true"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Core::RestartOnFailure).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::hookOptions_false()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--useHooks", "false"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Core::UseHooks).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::hookOptions_true()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--useHooks", "true"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Core::UseHooks).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::server_peerCheck_false()
|
||||
{
|
||||
QStringList args = {"stub", "server", "--peerCertCheck", "false"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Security::CheckPeers).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::server_peerCheck_true()
|
||||
{
|
||||
QStringList args = {"stub", "server", "--peerCertCheck", "true"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Security::CheckPeers).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::server_setConfig()
|
||||
{
|
||||
QStringList args = {"stub", "server", "--serverConfig", "afile.conf"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE("afile.conf", Settings::value(Settings::Server::ExternalConfigFile).toString());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::client_yscroll()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--yscroll", "15"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE(15, Settings::value(Settings::Client::ScrollSpeed).toInt());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::client_languageSync_true()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--languageSync", "true"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Client::LanguageSync).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::client_languageSync_false()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--languageSync", "false"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Client::LanguageSync).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::client_languageSync_1()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--languageSync", "1"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Client::LanguageSync).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::client_languageSync_0()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--languageSync", "0"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Client::LanguageSync).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::client_invertScrolling_true()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--invertScrollDirection", "true"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Client::InvertScrollDirection).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::client_invertScrolling_false()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--invertScrollDirection", "false"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Client::InvertScrollDirection).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::client_invertScrolling_1()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--invertScrollDirection", "1"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Client::InvertScrollDirection).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::client_invertScrolling_0()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--invertScrollDirection", "0"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Client::InvertScrollDirection).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::client_remoteHost()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--remoteHost", "127.0.0.1"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE("127.0.0.1", Settings::value(Settings::Client::RemoteHost).toString());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::preventSleep_true()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--prevent-sleep", "true"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Core::PreventSleep).toBool());
|
||||
}
|
||||
|
||||
QTEST_MAIN(CoreArgParserTests)
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* 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 "deskflow/CoreArgParser.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
class CoreArgParserTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
// Test are run in order top to bottom
|
||||
void interfaceLong();
|
||||
void interfaceShort();
|
||||
void portLong();
|
||||
void portShort();
|
||||
void nameLong();
|
||||
void nameShort();
|
||||
void logLevel();
|
||||
void logFile();
|
||||
void logFileWithSpace();
|
||||
void secure_false();
|
||||
void secure_true();
|
||||
void secure_0();
|
||||
void secure_1();
|
||||
void tlsCert();
|
||||
void preventSleep_true();
|
||||
void preventSleep_false();
|
||||
void preventSleep_1();
|
||||
void preventSleep_0();
|
||||
void restartLongOption_0();
|
||||
void restartLongOption_1();
|
||||
void restartLongOption_false();
|
||||
void restartLongOption_true();
|
||||
void restartShortOption_0();
|
||||
void restartShortOption_1();
|
||||
void restartShortOption_false();
|
||||
void restartShortOption_true();
|
||||
void hookOptions_false();
|
||||
void hookOptions_true();
|
||||
void server_peerCheck_false();
|
||||
void server_peerCheck_true();
|
||||
void server_setConfig();
|
||||
void client_yscroll();
|
||||
void client_languageSync_true();
|
||||
void client_languageSync_false();
|
||||
void client_languageSync_1();
|
||||
void client_languageSync_0();
|
||||
void client_invertScrolling_true();
|
||||
void client_invertScrolling_false();
|
||||
void client_invertScrolling_1();
|
||||
void client_invertScrolling_0();
|
||||
void client_remoteHost();
|
||||
|
||||
private:
|
||||
inline static const QString m_settingsPath = QStringLiteral("tmp/test");
|
||||
inline static const QString m_settingsFile = QStringLiteral("%1/Deskflow.conf").arg(m_settingsPath);
|
||||
};
|
||||
Loading…
Reference in a new issue