feat: remove toml config file only use our QSettings based format
remove deskflow/Config and related tests
This commit is contained in:
parent
e30025ea8b
commit
4a5f173422
12 changed files with 6 additions and 419 deletions
|
|
@ -38,26 +38,25 @@ runs:
|
||||||
xorg-dev libx11-dev libxtst-dev libssl-dev \
|
xorg-dev libx11-dev libxtst-dev libssl-dev \
|
||||||
libglib2.0-dev libxkbfile-dev qt6-base-dev qt6-tools-dev \
|
libglib2.0-dev libxkbfile-dev qt6-base-dev qt6-tools-dev \
|
||||||
libgtk-3-dev libgtest-dev libgmock-dev \
|
libgtk-3-dev libgtest-dev libgmock-dev \
|
||||||
libei-dev libportal-dev libtomlplusplus-dev libcli11-dev \
|
libei-dev libportal-dev libcli11-dev \
|
||||||
help2man -y >/dev/null
|
help2man -y >/dev/null
|
||||||
elif [ ${{inputs.like}} == "fedora" ]; then
|
elif [ ${{inputs.like}} == "fedora" ]; then
|
||||||
dnf install -y cmake make ninja-build gcc-c++ \
|
dnf install -y cmake make ninja-build gcc-c++ \
|
||||||
rpm-build openssl-devel glib2-devel \
|
rpm-build openssl-devel glib2-devel \
|
||||||
libXtst-devel libxkbfile-devel qt6-qtbase-devel qt6-qttools-devel \
|
libXtst-devel libxkbfile-devel qt6-qtbase-devel qt6-qttools-devel \
|
||||||
gtk3-devel gtest-devel gmock-devel \
|
gtk3-devel gtest-devel gmock-devel \
|
||||||
libei-devel libportal-devel tomlplusplus-devel \
|
libei-devel libportal-devel cli11-devel help2man
|
||||||
cli11-devel help2man
|
|
||||||
elif [ ${{inputs.like}} == "suse" ]; then
|
elif [ ${{inputs.like}} == "suse" ]; then
|
||||||
zypper refresh
|
zypper refresh
|
||||||
zypper install -y --force-resolution \
|
zypper install -y --force-resolution \
|
||||||
cmake make ninja gcc-c++ rpm-build libopenssl-devel \
|
cmake make ninja gcc-c++ rpm-build libopenssl-devel \
|
||||||
glib2-devel libXtst-devel libxkbfile-devel qt6-base-devel qt6-tools-devel gtk3-devel \
|
glib2-devel libXtst-devel libxkbfile-devel qt6-base-devel qt6-tools-devel gtk3-devel \
|
||||||
googletest-devel googlemock-devel libei-devel \
|
googletest-devel googlemock-devel libei-devel \
|
||||||
libportal-devel tomlplusplus-devel cli11-devel help2man
|
libportal-devel cli11-devel help2man
|
||||||
elif [ ${{ inputs.like }} == "arch" ]; then
|
elif [ ${{ inputs.like }} == "arch" ]; then
|
||||||
pacman -Syu --noconfirm base-devel cmake ninja \
|
pacman -Syu --noconfirm base-devel cmake ninja \
|
||||||
gcc openssl glib2 libxtst libxkbfile gtest libei libportal \
|
gcc openssl glib2 libxtst libxkbfile gtest libei libportal \
|
||||||
qt6-base qt6-tools qt6-svg gtk3 tomlplusplus cli11 help2man doxygen graphviz rsync
|
qt6-base qt6-tools qt6-svg gtk3 cli11 help2man doxygen graphviz rsync
|
||||||
else
|
else
|
||||||
echo "Unknown like"
|
echo "Unknown like"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ depends=(
|
||||||
openssl
|
openssl
|
||||||
qt6-base
|
qt6-base
|
||||||
qt6-svg
|
qt6-svg
|
||||||
tomlplusplus
|
|
||||||
)
|
)
|
||||||
|
|
||||||
options=('!debug')
|
options=('!debug')
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ cleanup:
|
||||||
- /lib/cmake
|
- /lib/cmake
|
||||||
- /lib/pkgconfig
|
- /lib/pkgconfig
|
||||||
- /share/pkgconfig
|
- /share/pkgconfig
|
||||||
- /share/tomlplusplus
|
|
||||||
- /share/cmake
|
- /share/cmake
|
||||||
- /share/doc
|
- /share/doc
|
||||||
- /share/gir-1.0
|
- /share/gir-1.0
|
||||||
|
|
@ -72,13 +71,6 @@ modules:
|
||||||
url: https://github.com/CLIUtils/CLI11
|
url: https://github.com/CLIUtils/CLI11
|
||||||
tag: v2.5.0
|
tag: v2.5.0
|
||||||
commit: 4160d259d961cd393fd8d67590a8c7d210207348
|
commit: 4160d259d961cd393fd8d67590a8c7d210207348
|
||||||
- name: tomlplusplus
|
|
||||||
buildsystem: cmake-ninja
|
|
||||||
sources:
|
|
||||||
- type: git
|
|
||||||
url: https://github.com/marzer/tomlplusplus
|
|
||||||
tag: v3.4.0
|
|
||||||
commit: 30172438cee64926dc41fdd9c11fb3ba5b2ba9de
|
|
||||||
- name: gtest
|
- name: gtest
|
||||||
buildsystem: cmake-ninja
|
buildsystem: cmake-ninja
|
||||||
sources:
|
sources:
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ To build Deskflow you will a minimum of:
|
||||||
- [libportal] 0.8+ (linux, bsd)
|
- [libportal] 0.8+ (linux, bsd)
|
||||||
- [libei] 1.3+ (linux, bsd)
|
- [libei] 1.3+ (linux, bsd)
|
||||||
- [google_test] ^
|
- [google_test] ^
|
||||||
- [tomlplusplus] ^
|
|
||||||
- [cli11] ^
|
- [cli11] ^
|
||||||
|
|
||||||
> ^ Will be fetched if not found on the host system.
|
> ^ Will be fetched if not found on the host system.
|
||||||
|
|
@ -76,7 +75,6 @@ After configuring you should be able to run make to build all targets.
|
||||||
[cmake]:https://cmake.org/
|
[cmake]:https://cmake.org/
|
||||||
[openssl]:https://www.openssl.org/
|
[openssl]:https://www.openssl.org/
|
||||||
[google_test]:https://github.com/google/googletest
|
[google_test]:https://github.com/google/googletest
|
||||||
[tomlplusplus]:https://github.com/marzer/tomlplusplus
|
|
||||||
[cli11]:https://github.com/CLIUtils/CLI11
|
[cli11]:https://github.com/CLIUtils/CLI11
|
||||||
[libei]:https://gitlab.freedesktop.org/libinput/libei
|
[libei]:https://gitlab.freedesktop.org/libinput/libei
|
||||||
[libportal]:https://github.com/flatpak/libportal
|
[libportal]:https://github.com/flatpak/libportal
|
||||||
|
|
|
||||||
|
|
@ -803,25 +803,6 @@ section: links
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
# Example file for `--config-toml` arg
|
|
||||||
|
|
||||||
```
|
|
||||||
[server.args]
|
|
||||||
no-daemon = true
|
|
||||||
no-tray = true
|
|
||||||
debug = "DEBUG"
|
|
||||||
name = "moe"
|
|
||||||
address = ":24800"
|
|
||||||
|
|
||||||
[client.args]
|
|
||||||
no-daemon = true
|
|
||||||
no-tray = true
|
|
||||||
debug = "DEBUG2"
|
|
||||||
name = "larry"
|
|
||||||
_last = "moe:24800"
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
# Example `.env` file
|
# Example `.env` file
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@
|
||||||
#include "common/Constants.h"
|
#include "common/Constants.h"
|
||||||
#include "common/ExitCodes.h"
|
#include "common/ExitCodes.h"
|
||||||
#include "common/Settings.h"
|
#include "common/Settings.h"
|
||||||
#include "deskflow/Config.h"
|
|
||||||
#include "deskflow/DeskflowException.h"
|
#include "deskflow/DeskflowException.h"
|
||||||
#include "deskflow/ProtocolTypes.h"
|
#include "deskflow/ProtocolTypes.h"
|
||||||
|
|
||||||
|
|
@ -143,9 +142,7 @@ void App::loggingFilterWarning() const
|
||||||
|
|
||||||
void App::initApp(int argc, const char **argv)
|
void App::initApp(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
std::string configFilename;
|
|
||||||
CLI::App cliApp{kAppDescription};
|
CLI::App cliApp{kAppDescription};
|
||||||
cliApp.add_option("--config-toml", configFilename, "Use TOML configuration file");
|
|
||||||
|
|
||||||
// Allow legacy args.
|
// Allow legacy args.
|
||||||
cliApp.allow_extras();
|
cliApp.allow_extras();
|
||||||
|
|
@ -157,14 +154,7 @@ void App::initApp(int argc, const char **argv)
|
||||||
cliApp.exit(e);
|
cliApp.exit(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!configFilename.empty()) {
|
|
||||||
Config config(configFilename, configSection());
|
|
||||||
if (config.load(argv[0])) {
|
|
||||||
parseArgs();
|
parseArgs();
|
||||||
}
|
|
||||||
} else {
|
|
||||||
parseArgs();
|
|
||||||
}
|
|
||||||
|
|
||||||
// set log filter
|
// set log filter
|
||||||
if (const auto logLevel = qPrintable(Settings::logLevelText()); !CLOG->setFilter(logLevel)) {
|
if (const auto logLevel = qPrintable(Settings::logLevelText()); !CLOG->setFilter(logLevel)) {
|
||||||
|
|
|
||||||
|
|
@ -21,26 +21,6 @@ else()
|
||||||
message(STATUS "CLI11 INC_DIR: ${cli11_inc_dir}")
|
message(STATUS "CLI11 INC_DIR: ${cli11_inc_dir}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(tomlplusplus QUIET)
|
|
||||||
if(tomlplusplus_FOUND)
|
|
||||||
message(STATUS "tomlplusplus [System] Version: ${tomlplusplus_VERSION}")
|
|
||||||
set(tomlPP_lib tomlplusplus::tomlplusplus)
|
|
||||||
else()
|
|
||||||
# Be sure to update the version and MD5 together
|
|
||||||
# Save our copy with .h not .hpp for compatibliy with system version < 3.4
|
|
||||||
set(TOMLPP_VERSION 3.4.0)
|
|
||||||
set(TOMLPP_MD5 caefb3b60119731fb4b4d24b6339e7fb)
|
|
||||||
file(
|
|
||||||
DOWNLOAD "https://raw.githubusercontent.com/marzer/tomlplusplus/refs/tags/v${TOMLPP_VERSION}/toml.hpp"
|
|
||||||
"${CMAKE_BINARY_DIR}/include/toml++/toml.h"
|
|
||||||
SHOW_PROGRESS
|
|
||||||
EXPECTED_MD5 ${TOMLPP_MD5}
|
|
||||||
)
|
|
||||||
set(tomlPP_inc_dir "${CMAKE_BINARY_DIR}/include")
|
|
||||||
message(STATUS "tomlplusplus [Downloaded] Version: 3.4.0")
|
|
||||||
message(STATUS "tomlplusplus INC DIR: ${tomlPP_inc_dir}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
####################Start Making Library#########################
|
####################Start Making Library#########################
|
||||||
set(lib_name app)
|
set(lib_name app)
|
||||||
|
|
||||||
|
|
@ -76,8 +56,6 @@ add_library(${lib_name} STATIC ${PLATFORM_CODE}
|
||||||
Clipboard.h
|
Clipboard.h
|
||||||
ClipboardChunk.cpp
|
ClipboardChunk.cpp
|
||||||
ClipboardChunk.h
|
ClipboardChunk.h
|
||||||
Config.cpp
|
|
||||||
Config.h
|
|
||||||
CoreArgParser.cpp
|
CoreArgParser.cpp
|
||||||
CoreArgParser.h
|
CoreArgParser.h
|
||||||
CoreArgs.h
|
CoreArgs.h
|
||||||
|
|
@ -132,14 +110,13 @@ add_library(${lib_name} STATIC ${PLATFORM_CODE}
|
||||||
target_link_libraries(${lib_name} PUBLIC common Qt6::Core Qt6::Network)
|
target_link_libraries(${lib_name} PUBLIC common Qt6::Core Qt6::Network)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_link_libraries(${lib_name} PRIVATE ${cli11_lib} ${tomlPP_lib})
|
target_link_libraries(${lib_name} PRIVATE ${cli11_lib})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
${lib_name}
|
${lib_name}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${cli11_inc_dir}
|
${cli11_inc_dir}
|
||||||
${tomlPP_inc_dir}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
|
|
@ -154,7 +131,6 @@ if(UNIX)
|
||||||
mt
|
mt
|
||||||
server
|
server
|
||||||
${cli11_lib}
|
${cli11_lib}
|
||||||
${tomlPP_lib}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(NOT APPLE)
|
if(NOT APPLE)
|
||||||
|
|
|
||||||
|
|
@ -1,110 +0,0 @@
|
||||||
/*
|
|
||||||
* Deskflow -- mouse and keyboard sharing utility
|
|
||||||
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "Config.h"
|
|
||||||
|
|
||||||
#include "base/Log.h"
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <filesystem>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
// Use .h for fallback with 3.3.0
|
|
||||||
#include <toml++/toml.h>
|
|
||||||
|
|
||||||
namespace deskflow {
|
|
||||||
|
|
||||||
Config::Config(const std::string &filename, const std::string §ion) : m_filename(filename), m_section(section)
|
|
||||||
{
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *const *Config::argv() const
|
|
||||||
{
|
|
||||||
return m_argv.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
int Config::argc() const
|
|
||||||
{
|
|
||||||
return static_cast<int>(m_argv.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Config::load(const std::string &firstArg)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!firstArg.empty()) {
|
|
||||||
m_args.push_back(firstArg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_filename.empty()) {
|
|
||||||
throw NoConfigFilenameError();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!std::filesystem::exists(m_filename)) {
|
|
||||||
LOG_ERR("config file not found: %s", m_filename.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
toml::table configTable;
|
|
||||||
try {
|
|
||||||
LOG_INFO("loading config file: %s", m_filename.c_str());
|
|
||||||
configTable = toml::parse_file(m_filename);
|
|
||||||
|
|
||||||
} catch (const toml::parse_error &err) {
|
|
||||||
LOG_ERR("toml parse error: %s", err.what());
|
|
||||||
throw ParseError();
|
|
||||||
} catch (const std::exception &err) {
|
|
||||||
LOG_ERR("unknown parse error: %s", err.what());
|
|
||||||
throw ParseError();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!configTable.contains(m_section)) {
|
|
||||||
LOG_WARN("no %s section found in config file", m_section.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto §ion = configTable[m_section];
|
|
||||||
const auto args = section["args"];
|
|
||||||
if (!args.is_table()) {
|
|
||||||
LOG_WARN("no args table found in config file");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string specialLastArg = "";
|
|
||||||
const auto &table = *(args.as_table());
|
|
||||||
for (const auto &pair : table) {
|
|
||||||
const auto &key = pair.first;
|
|
||||||
if (key.str() == "_last") {
|
|
||||||
specialLastArg = pair.second.as_string()->get();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_args.push_back("--" + std::string(key.str()));
|
|
||||||
|
|
||||||
if (pair.second.is_string()) {
|
|
||||||
const auto value = pair.second.as_string()->get();
|
|
||||||
m_args.push_back(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!specialLastArg.empty()) {
|
|
||||||
m_args.push_back(specialLastArg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_args.empty()) {
|
|
||||||
LOG_WARN("no args loaded from config file");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto &arg : m_args) {
|
|
||||||
m_argv.push_back(arg.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace deskflow
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
/*
|
|
||||||
* Deskflow -- mouse and keyboard sharing utility
|
|
||||||
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace deskflow {
|
|
||||||
|
|
||||||
//! App configuration
|
|
||||||
/*!
|
|
||||||
Parses a configuration file describing start args and potentially other
|
|
||||||
configuration options in future. The configuration file is in TOML format.
|
|
||||||
|
|
||||||
Initially this class was created to as a developer convenience; it is a
|
|
||||||
convenient place to specify args without needing to fiddle with IDE configs.
|
|
||||||
*/
|
|
||||||
class Config
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
class ParseError : public std::runtime_error
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit ParseError() : std::runtime_error("failed to parse config file")
|
|
||||||
{
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class NoConfigFilenameError : public std::runtime_error
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit NoConfigFilenameError() : std::runtime_error("no config file specified")
|
|
||||||
{
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit Config(const std::string &filename, const std::string §ion);
|
|
||||||
|
|
||||||
bool load(const std::string &firstArg);
|
|
||||||
const char *const *argv() const;
|
|
||||||
int argc() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string m_filename;
|
|
||||||
std::string m_section;
|
|
||||||
std::vector<std::string> m_args;
|
|
||||||
std::vector<const char *> m_argv;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace deskflow
|
|
||||||
|
|
@ -29,14 +29,6 @@ create_test(
|
||||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/deskflow"
|
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/deskflow"
|
||||||
)
|
)
|
||||||
|
|
||||||
create_test(
|
|
||||||
NAME ConfigTests
|
|
||||||
DEPENDS app
|
|
||||||
LIBS arch base ${extra_libs}
|
|
||||||
SOURCE ConfigTests.cpp
|
|
||||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/deskflow"
|
|
||||||
)
|
|
||||||
|
|
||||||
create_test(
|
create_test(
|
||||||
NAME IKeyStateTests
|
NAME IKeyStateTests
|
||||||
DEPENDS app
|
DEPENDS app
|
||||||
|
|
|
||||||
|
|
@ -1,144 +0,0 @@
|
||||||
/*
|
|
||||||
* Deskflow -- mouse and keyboard sharing utility
|
|
||||||
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
|
||||||
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "ConfigTests.h"
|
|
||||||
|
|
||||||
#include "deskflow/Config.h"
|
|
||||||
|
|
||||||
using namespace deskflow;
|
|
||||||
const auto kTestFilename = "tmp/test/test.toml";
|
|
||||||
|
|
||||||
void ConfigTests::initTestCase()
|
|
||||||
{
|
|
||||||
QDir dir;
|
|
||||||
QVERIFY(dir.mkpath("tmp/test"));
|
|
||||||
|
|
||||||
m_arch.init();
|
|
||||||
m_log.setFilter(LogLevel::Debug2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigTests::loadFile()
|
|
||||||
{
|
|
||||||
QFile testFile(kTestFilename);
|
|
||||||
QVERIFY(testFile.open(QIODevice::WriteOnly | QIODevice::Text));
|
|
||||||
|
|
||||||
QTextStream out(&testFile);
|
|
||||||
out << "[test.args]\n"
|
|
||||||
R"(test-arg = "test opt")";
|
|
||||||
|
|
||||||
testFile.close();
|
|
||||||
QVERIFY(!testFile.isOpen());
|
|
||||||
|
|
||||||
Config config(kTestFilename, "test");
|
|
||||||
|
|
||||||
const auto result = config.load("test");
|
|
||||||
QVERIFY(result);
|
|
||||||
QCOMPARE(config.argc(), 3);
|
|
||||||
QCOMPARE(config.argv()[0], "test");
|
|
||||||
QCOMPARE(config.argv()[1], "--test-arg");
|
|
||||||
QCOMPARE(config.argv()[2], "test opt");
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigTests::load_EmptyFile()
|
|
||||||
{
|
|
||||||
Config config("", "test");
|
|
||||||
QVERIFY_THROWS_EXCEPTION(Config::NoConfigFilenameError, config.load("test"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigTests::load_NonExsitingFile()
|
|
||||||
{
|
|
||||||
Config config("nonexistent.toml", "test");
|
|
||||||
|
|
||||||
const auto result = config.load("test");
|
|
||||||
QVERIFY(!result);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigTests::load_InvalidConfig()
|
|
||||||
{
|
|
||||||
QFile testFile(kTestFilename);
|
|
||||||
QVERIFY(testFile.open(QIODevice::WriteOnly));
|
|
||||||
|
|
||||||
QVERIFY(testFile.write("foobar"));
|
|
||||||
|
|
||||||
testFile.close();
|
|
||||||
QVERIFY(!testFile.isOpen());
|
|
||||||
|
|
||||||
Config config(kTestFilename, "test");
|
|
||||||
QVERIFY_THROWS_EXCEPTION(Config::ParseError, config.load("test"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigTests::load_missingSections()
|
|
||||||
{
|
|
||||||
QFile testFile(kTestFilename);
|
|
||||||
QVERIFY(testFile.open(QIODevice::WriteOnly));
|
|
||||||
|
|
||||||
testFile.close();
|
|
||||||
QVERIFY(!testFile.isOpen());
|
|
||||||
|
|
||||||
Config config(kTestFilename, "missing");
|
|
||||||
const auto result = config.load("test");
|
|
||||||
QVERIFY(!result);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigTests::load_badTable()
|
|
||||||
{
|
|
||||||
QFile testFile(kTestFilename);
|
|
||||||
QVERIFY(testFile.open(QIODevice::WriteOnly));
|
|
||||||
|
|
||||||
QVERIFY(testFile.write("[test]"));
|
|
||||||
|
|
||||||
testFile.close();
|
|
||||||
QVERIFY(!testFile.isOpen());
|
|
||||||
|
|
||||||
Config config(kTestFilename, "test");
|
|
||||||
|
|
||||||
const auto result = config.load("test");
|
|
||||||
QVERIFY(!result);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigTests::load_lastArg()
|
|
||||||
{
|
|
||||||
QFile testFile(kTestFilename);
|
|
||||||
QVERIFY(testFile.open(QIODevice::WriteOnly));
|
|
||||||
|
|
||||||
QVERIFY(testFile.write(
|
|
||||||
"[test.args]\n"
|
|
||||||
R"(_last = "test last")"
|
|
||||||
"\n"
|
|
||||||
R"(test-second = true)"
|
|
||||||
));
|
|
||||||
|
|
||||||
testFile.close();
|
|
||||||
QVERIFY(!testFile.isOpen());
|
|
||||||
|
|
||||||
deskflow::Config config(kTestFilename, "test");
|
|
||||||
|
|
||||||
const auto result = config.load("test-first");
|
|
||||||
QVERIFY(result);
|
|
||||||
QCOMPARE(config.argc(), 3);
|
|
||||||
QCOMPARE(config.argv()[0], "test-first");
|
|
||||||
QCOMPARE(config.argv()[1], "--test-second");
|
|
||||||
QCOMPARE(config.argv()[2], "test last");
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigTests::load_noArgs()
|
|
||||||
{
|
|
||||||
QFile testFile(kTestFilename);
|
|
||||||
QVERIFY(testFile.open(QIODevice::WriteOnly));
|
|
||||||
|
|
||||||
QVERIFY(testFile.write("[test.args]"));
|
|
||||||
|
|
||||||
testFile.close();
|
|
||||||
QVERIFY(!testFile.isOpen());
|
|
||||||
|
|
||||||
deskflow::Config config(kTestFilename, "test");
|
|
||||||
|
|
||||||
const auto result = config.load("");
|
|
||||||
QVERIFY(!result);
|
|
||||||
}
|
|
||||||
|
|
||||||
QTEST_MAIN(ConfigTests)
|
|
||||||
|
|
@ -1,29 +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 "base/Log.h"
|
|
||||||
|
|
||||||
#include <QTest>
|
|
||||||
|
|
||||||
class ConfigTests : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
private Q_SLOTS:
|
|
||||||
// Test are run in order top to bottom
|
|
||||||
void initTestCase();
|
|
||||||
void loadFile();
|
|
||||||
void load_EmptyFile();
|
|
||||||
void load_NonExsitingFile();
|
|
||||||
void load_InvalidConfig();
|
|
||||||
void load_missingSections();
|
|
||||||
void load_badTable();
|
|
||||||
void load_lastArg();
|
|
||||||
void load_noArgs();
|
|
||||||
|
|
||||||
private:
|
|
||||||
Arch m_arch;
|
|
||||||
Log m_log;
|
|
||||||
};
|
|
||||||
Loading…
Reference in a new issue