aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-12-07 12:22:15 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2020-12-07 12:22:15 +0200
commit92b3c2dcff3e85ad3d455f6ab845d9a97d3b525b (patch)
treea850643f7b86e6cebfddbeec98d7c372478d379c /lib
parentHostlist filter plugin can rewrite hostnames (diff)
downloadsmolbote-92b3c2dcff3e85ad3d455f6ab845d9a97d3b525b.tar.xz
Rewrite meson build scripts into cmakelists
Diffstat (limited to 'lib')
-rw-r--r--lib/bookmarks/CMakeLists.txt6
-rw-r--r--lib/bookmarks/meson.build16
-rw-r--r--lib/configuration/CMakeLists.txt24
-rw-r--r--lib/configuration/configuration.cpp10
-rw-r--r--lib/configuration/configuration.h4
-rw-r--r--lib/configuration/meson.build22
-rw-r--r--lib/configuration/test/main.cpp39
-rw-r--r--lib/configuration/test/qt.cpp71
-rw-r--r--lib/downloads/CMakeLists.txt6
-rw-r--r--lib/downloads/meson.build19
-rw-r--r--lib/pluginloader/CMakeLists.txt54
-rw-r--r--lib/pluginloader/meson.build68
-rw-r--r--lib/pluginloader/pluginloader.cpp4
-rw-r--r--lib/pluginloader/pluginloader.h9
-rw-r--r--lib/pluginloader/test/pluginloader-sigmatch.cpp56
-rw-r--r--lib/session_formats/CMakeLists.txt8
-rw-r--r--lib/session_formats/meson.build9
-rw-r--r--lib/session_formats/session_json.hpp2
-rw-r--r--lib/smolblok/CMakeLists.txt8
-rw-r--r--lib/smolblok/meson.build15
20 files changed, 227 insertions, 223 deletions
diff --git a/lib/bookmarks/CMakeLists.txt b/lib/bookmarks/CMakeLists.txt
new file mode 100644
index 0000000..50c2942
--- /dev/null
+++ b/lib/bookmarks/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_library(bookmarks STATIC
+ bookmarkmodel.h
+ bookmarkformat.cpp bookmarkitem.cpp bookmarkmodel.cpp
+ formats/xbel.cpp formats/ffjson.cpp)
+target_link_libraries(bookmarks PUBLIC Qt5::Widgets)
+target_include_directories(bookmarks PUBLIC .)
diff --git a/lib/bookmarks/meson.build b/lib/bookmarks/meson.build
deleted file mode 100644
index 81c1ece..0000000
--- a/lib/bookmarks/meson.build
+++ /dev/null
@@ -1,16 +0,0 @@
-bookmarks_moc = mod_qt5.preprocess(
- moc_headers: [ 'bookmarkmodel.h' ],
- dependencies: dep_qt5
-)
-
-bookmarks_lib = static_library('bookmarks',
- [ bookmarks_moc,
- 'bookmarkformat.cpp', 'formats/xbel.cpp', 'formats/ffjson.cpp',
- 'bookmarkitem.cpp', 'bookmarkmodel.cpp' ],
- dependencies: dep_qt5
-)
-
-dep_bookmarks = declare_dependency(
- include_directories: include_directories('.'),
- link_with: bookmarks_lib
-)
diff --git a/lib/configuration/CMakeLists.txt b/lib/configuration/CMakeLists.txt
new file mode 100644
index 0000000..6484a70
--- /dev/null
+++ b/lib/configuration/CMakeLists.txt
@@ -0,0 +1,24 @@
+add_library(configuration STATIC configuration.cpp qt_specialization.cpp)
+target_link_libraries(configuration PUBLIC Qt5::Widgets)
+target_include_directories(configuration INTERFACE .)
+
+add_executable(conf_parser test/main.cpp)
+target_compile_definitions(conf_parser PRIVATE NO_QT_SPEC)
+target_sanitize(conf_parser)
+target_link_libraries(conf_parser PRIVATE configuration Catch2::Catch2)
+
+add_executable(conf_parser_qt test/qt.cpp)
+target_link_libraries(conf_parser_qt PRIVATE configuration Catch2::Catch2)
+
+add_test(NAME conf_parser COMMAND conf_parser
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test")
+add_test(NAME conf_parser_qt COMMAND conf_parser_qt -platform offscreen
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test")
+set_tests_properties(conf_parser PROPERTIES ENVIRONMENT "CONFIGFILE=${CMAKE_CURRENT_SOURCE_DIR}/test/defaultrc.ini")
+set_tests_properties(conf_parser_qt PROPERTIES ENVIRONMENT "CONFIGFILE=${CMAKE_CURRENT_SOURCE_DIR}/test/defaultrc.ini")
+
+if(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
+ add_executable(conf_fuzzer configuration.cpp)
+ target_compile_definitions(conf_fuzzer PRIVATE FUZZER NO_QT_SPEC)
+ target_sanitize_fuzzer(conf_fuzzer)
+endif()
diff --git a/lib/configuration/configuration.cpp b/lib/configuration/configuration.cpp
index 66617ed..d11b342 100644
--- a/lib/configuration/configuration.cpp
+++ b/lib/configuration/configuration.cpp
@@ -10,19 +10,18 @@
#include <algorithm>
#include <fstream>
#include <iostream>
-#include <sstream>
#include <stdexcept>
#ifndef NO_QT_SPEC
#include <QStandardPaths>
#endif
-static Configuration *s_conf = nullptr;
+static const Configuration *s_conf = nullptr;
Configuration::Configuration()
: use_global(true)
{
- if(!s_conf) {
+ if(s_conf == nullptr) {
throw std::runtime_error("Trying to use default Configuration, but none has been set!");
}
}
@@ -139,8 +138,7 @@ void Configuration::read(std::basic_istream<char> &input)
void Configuration::setValue(const std::string &key, const std::string &value)
{
if(use_global) {
- s_conf->setValue(key, value);
- return;
+ throw std::runtime_error("Global configuration is read-only!");
}
if(this->count(key) == 0) {
@@ -167,7 +165,7 @@ bool Configuration::make_global()
return true;
}
-Configuration *Configuration::instance()
+const Configuration *Configuration::instance()
{
return s_conf;
}
diff --git a/lib/configuration/configuration.h b/lib/configuration/configuration.h
index af55f62..a80d8e5 100644
--- a/lib/configuration/configuration.h
+++ b/lib/configuration/configuration.h
@@ -29,7 +29,7 @@
#define param_typestate(X)
#endif
-typedef std::variant<std::string, int, bool> conf_value_t;
+using conf_value_t = std::variant<std::string, int, bool>;
template <typename T>
concept concept_value_t = std::is_arithmetic<T>::value || std::is_same<T, bool>::value || std::is_constructible<T, std::string>::value;
@@ -131,7 +131,7 @@ public:
bool make_global();
private:
- static Configuration *instance();
+ static const Configuration *instance();
const std::string m_homePath;
const bool use_global = false;
diff --git a/lib/configuration/meson.build b/lib/configuration/meson.build
deleted file mode 100644
index 5e3e4b2..0000000
--- a/lib/configuration/meson.build
+++ /dev/null
@@ -1,22 +0,0 @@
-dep_configuration = declare_dependency(
- include_directories: include_directories('.'),
- link_with: static_library('configuration', ['configuration.cpp', 'qt_specialization.cpp'], dependencies: dep_qt5)
-)
-
-test('conf parser', executable('configuration-parser',
- sources: [ 'test/main.cpp' ],
- dependencies: [ dep_qt5, dep_catch, dep_configuration ]
- ),
- env: 'CONFIGFILE='+meson.current_source_dir()/'test/defaultrc.ini',
- args: [ '-platform', 'offscreen' ],
- workdir: meson.current_source_dir()/'test'
-)
-
-if meson.get_compiler('cpp').has_multi_arguments('-g', '-fsanitize=fuzzer')
-executable('configuration-fuzzer',
- sources: 'configuration.cpp',
- cpp_args: [ '-g', '-fsanitize=fuzzer', '-DNO_QT_SPEC', '-DFUZZER' ],
- link_args: [ '-fsanitize=fuzzer' ]
-# args: [ '-seed=1', '-max_total_time=24', meson.current_source_dir()/'test/corpus' ]
-)
-endif
diff --git a/lib/configuration/test/main.cpp b/lib/configuration/test/main.cpp
index d83f7af..9c83f8b 100644
--- a/lib/configuration/test/main.cpp
+++ b/lib/configuration/test/main.cpp
@@ -1,9 +1,7 @@
-#define CATCH_CONFIG_RUNNER
-
// clazy:excludeall=non-pod-global-static
+#define CATCH_CONFIG_MAIN
#include "configuration.h"
-#include <QApplication>
#include <catch2/catch.hpp>
SCENARIO("Configuration")
@@ -32,7 +30,7 @@ SCENARIO("Configuration")
WHEN("reading default values")
{
REQUIRE(conf.value<std::string>("name"));
- REQUIRE(conf.value<std::string>("name").value() == std::string());
+ REQUIRE(conf.value<std::string>("name").value().empty());
REQUIRE(conf.value<int>("number"));
REQUIRE(conf.value<int>("number").value() == 0);
REQUIRE(conf.value<bool>("toggle"));
@@ -43,7 +41,7 @@ SCENARIO("Configuration")
REQUIRE(!conf.value<std::string>("nullopt"));
REQUIRE(conf.value<std::string>("main/name"));
- REQUIRE(conf.value<std::string>("main/name").value() == std::string());
+ REQUIRE(conf.value<std::string>("main/name").value().empty());
REQUIRE(conf.value<int>("main/number"));
REQUIRE(conf.value<int>("main/number").value() == 0);
REQUIRE(conf.value<bool>("main/toggle"));
@@ -101,30 +99,6 @@ SCENARIO("Configuration")
REQUIRE(conf.value<std::string>("toggle").value() == "true");
REQUIRE(conf.value<std::string>("main/toggle").value() == "false");
}
-
- THEN("Qt cast specialization")
- {
- REQUIRE(conf.value<QString>("name").value() == "Top level");
- REQUIRE(conf.value<QString>("number").value() == "12");
- REQUIRE(conf.value<QString>("toggle").value() == "true");
- REQUIRE(conf.value<QString>("main/toggle").value() == "false");
- REQUIRE(!conf.value<QString>("nullopt"));
-
- REQUIRE(conf.value<QStringList>("list").value() == QStringList({ "one", "two", "three", "for four" }));
- REQUIRE(!conf.value<QStringList>("nullopt"));
- }
-
- THEN("Qt shortcut")
- {
- REQUIRE(conf.value<std::string>("qt/shortcut") == "Ctrl+Q");
- QAction action;
- REQUIRE(conf.shortcut<QAction>(action, "qt/shortcut").shortcut().toString() == "Ctrl+Q");
- REQUIRE(conf.shortcut<QAction>(action, "qt/nil").shortcut().toString() == "Ctrl+Q");
-
- QKeySequence sequence;
- REQUIRE(conf.shortcut<QKeySequence>(sequence, "qt/shortcut").toString() == "Ctrl+Q");
- REQUIRE(conf.shortcut<QKeySequence>(sequence, "qt/nil").toString() == "Ctrl+Q");
- }
}
}
@@ -167,10 +141,3 @@ SCENARIO("Configuration")
}
}
}
-
-int main(int argc, char **argv)
-{
- QApplication app(argc, argv);
- int result = Catch::Session().run(argc, argv);
- return result;
-}
diff --git a/lib/configuration/test/qt.cpp b/lib/configuration/test/qt.cpp
new file mode 100644
index 0000000..44114df
--- /dev/null
+++ b/lib/configuration/test/qt.cpp
@@ -0,0 +1,71 @@
+// clazy:excludeall=non-pod-global-static
+#define CATCH_CONFIG_RUNNER
+
+#include "configuration.h"
+#include <QApplication>
+#include <catch2/catch.hpp>
+
+SCENARIO("Configuration")
+{
+ GIVEN("a Configuration object with some initial values")
+ {
+ Configuration conf{
+ { "name", std::string() },
+ { "over", std::string() },
+ // this entry is not in the conf file
+ { "other", std::string("not in cfg") },
+ // commented out entry in the conf file
+ { "comment", std::string("123.456") },
+ { "number", 0 },
+ { "toggle", false },
+
+ { "main/name", std::string() },
+ { "main/number", 0 },
+ { "main/toggle", true },
+
+ { "extra/name", std::string() },
+ { "extra/number", 0 },
+ { "extra/toggle", false },
+ };
+
+ WHEN("reading default values")
+ {
+ }
+
+ WHEN("reading configuration file")
+ {
+ conf.read_file(std::getenv("CONFIGFILE"));
+
+ THEN("Qt cast specialization")
+ {
+ REQUIRE(conf.value<QString>("name").value() == "Top level");
+ REQUIRE(conf.value<QString>("number").value() == "12");
+ REQUIRE(conf.value<QString>("toggle").value() == "true");
+ REQUIRE(conf.value<QString>("main/toggle").value() == "false");
+ REQUIRE(!conf.value<QString>("nullopt"));
+
+ REQUIRE(conf.value<QStringList>("list").value() == QStringList({ "one", "two", "three", "for four" }));
+ REQUIRE(!conf.value<QStringList>("nullopt"));
+ }
+
+ THEN("Qt shortcut")
+ {
+ REQUIRE(conf.value<std::string>("qt/shortcut") == "Ctrl+Q");
+ QAction action;
+ REQUIRE(conf.shortcut<QAction>(action, "qt/shortcut").shortcut().toString() == "Ctrl+Q");
+ REQUIRE(conf.shortcut<QAction>(action, "qt/nil").shortcut().toString() == "Ctrl+Q");
+
+ QKeySequence sequence;
+ REQUIRE(conf.shortcut<QKeySequence>(sequence, "qt/shortcut").toString() == "Ctrl+Q");
+ REQUIRE(conf.shortcut<QKeySequence>(sequence, "qt/nil").toString() == "Ctrl+Q");
+ }
+ }
+ }
+}
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ int result = Catch::Session().run(argc, argv);
+ return result;
+}
diff --git a/lib/downloads/CMakeLists.txt b/lib/downloads/CMakeLists.txt
new file mode 100644
index 0000000..984d332
--- /dev/null
+++ b/lib/downloads/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_library(downloads
+ downloadswidget.h downloadswidget.cpp downloadsform.ui
+ widgets/downloaditemwidget.h widgets/downloaditemwidget.cpp widgets/downloaditemform.ui
+ widgets/elidedlabel.h widgets/elidedlabel.cpp)
+target_link_libraries(downloads PUBLIC Qt5::WebEngineWidgets)
+target_include_directories(downloads PUBLIC .)
diff --git a/lib/downloads/meson.build b/lib/downloads/meson.build
deleted file mode 100644
index 9b86391..0000000
--- a/lib/downloads/meson.build
+++ /dev/null
@@ -1,19 +0,0 @@
-downloads_inc = include_directories('.')
-downloads_moc = mod_qt5.preprocess(
- moc_headers: ['downloadswidget.h', 'widgets/downloaditemwidget.h', 'widgets/elidedlabel.h'],
- ui_files: ['downloadsform.ui', 'widgets/downloaditemform.ui'],
- dependencies: dep_qt5
-)
-
-downloads_lib = static_library('downloads',
- ['downloadswidget.cpp', downloads_moc,
- 'widgets/downloaditemwidget.cpp', 'widgets/elidedlabel.cpp'],
- dependencies: dep_qt5
-)
-
-dep_downloads = declare_dependency(
- include_directories: downloads_inc,
- link_with: downloads_lib,
- sources: ['downloadswidget.cpp', downloads_moc,
- 'widgets/downloaditemwidget.cpp', 'widgets/elidedlabel.cpp']
-)
diff --git a/lib/pluginloader/CMakeLists.txt b/lib/pluginloader/CMakeLists.txt
new file mode 100644
index 0000000..e0c8270
--- /dev/null
+++ b/lib/pluginloader/CMakeLists.txt
@@ -0,0 +1,54 @@
+find_program(SSL openssl)
+find_program(PYTHON python3)
+
+# generate a keypair
+add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/keypair.pem"
+ COMMAND ${SSL} genrsa -out "${CMAKE_CURRENT_BINARY_DIR}/keypair.pem" 4096)
+
+# export public key
+add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pubkey.pem"
+ DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/keypair.pem"
+ COMMAND ${SSL} rsa -in "${CMAKE_CURRENT_BINARY_DIR}/keypair.pem" -pubout -out "${CMAKE_CURRENT_BINARY_DIR}/pubkey.pem")
+
+# turn the public key into a header
+add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/publicKey.h"
+ DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pubkey.pem"
+ COMMAND ${PYTHON} "${CMAKE_CURRENT_SOURCE_DIR}/ssl-keygen.py"
+ --private "${CMAKE_CURRENT_BINARY_DIR}/keypair.pem"
+ --public "${CMAKE_CURRENT_BINARY_DIR}/pubkey.pem"
+ --output "${CMAKE_CURRENT_BINARY_DIR}/publicKey.h" --array-name=publicKey_pem)
+
+add_library(pluginloader STATIC pluginloader.h pluginloader.cpp "${CMAKE_CURRENT_BINARY_DIR}/publicKey.h")
+target_link_libraries(pluginloader PUBLIC OpenSSL::SSL Qt5::Core)
+target_include_directories(pluginloader PUBLIC . PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
+
+## Testing
+# sigmatch
+add_executable(pluginloader_sigmatch test/pluginloader-sigmatch.cpp)
+target_link_libraries(pluginloader_sigmatch PRIVATE pluginloader Catch2::Catch2 fmt)
+#target_sanitize(pluginloader_sigmatch)
+
+# load
+add_executable(pluginloader_load test/pluginloader-load.cpp)
+target_link_libraries(pluginloader_load PRIVATE pluginloader Catch2::Catch2 fmt)
+target_sanitize(pluginloader_load)
+
+# generate a random file and properly sign it
+add_test(NAME good.dat COMMAND ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/write-random.py --output=good.dat)
+add_test(NAME good.dat.sig COMMAND ${SSL} dgst -sha256 -sign=keypair.pem -out=good.dat.sig good.dat)
+set_tests_properties(good.dat.sig PROPERTIES DEPENDS good.dat)
+# generate a random file and improperly sign it
+add_test(NAME bad.dat COMMAND ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/write-random.py --output=bad.dat)
+add_test(NAME bad.dat.sig COMMAND ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/write-random.py --output=bad.dat.sig)
+# generate a random file and don't sign it
+add_test(NAME none.dat COMMAND ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/write-random.py --output=none.dat)
+
+add_test(NAME pluginloader_sigmatch COMMAND pluginloader_sigmatch)
+set_tests_properties(pluginloader_sigmatch PROPERTIES
+ DEPENDS "good.dat;good.dat.sig;bad.dat;bad.dat.sig;none.dat"
+ REQUIRED_FILES "good.dat;good.dat.sig;bad.dat;bad.dat.sig;none.dat"
+ ENVIRONMENT "SIGNEDFILE=${CMAKE_CURRENT_BINARY_DIR}/good.dat;UNSIGNEDFILE=${CMAKE_CURRENT_BINARY_DIR}/none.dat;BADSIGNEDFILE=${CMAKE_CURRENT_BINARY_DIR}/bad.dat")
+
+# make sure this fails when no plugin or an invalid file is passed
+#test('load', poi_plugin_loader, suite: 'pluginloader', should_fail: true)
+#test('load', poi_plugin_loader, suite: 'pluginloader', args: files('meson.build'), should_fail: true)
diff --git a/lib/pluginloader/meson.build b/lib/pluginloader/meson.build
deleted file mode 100644
index 5e7c39c..0000000
--- a/lib/pluginloader/meson.build
+++ /dev/null
@@ -1,68 +0,0 @@
-python = import('python')
-python3 = python.find_installation('python3')
-
-openssl = find_program('openssl', required: true)
-
-private_pem = custom_target('privateKey.pem',
- output: 'privateKey.pem',
- command: [ openssl, 'genrsa', '-out', '@OUTPUT@', '4096' ]
-)
-
-public_pem = custom_target('publicKey.pem',
- input: private_pem,
- output: 'publicKey.pem',
- command: [ openssl, 'rsa', '-in', '@INPUT@', '-pubout', '-out', '@OUTPUT@' ]
-)
-
-publicKey_h = custom_target('publicKey_h',
- input: files('ssl-keygen.py'),
- output: 'publicKey.h',
- command: [python3, '@INPUT@',
- '--private', private_pem, '--public', public_pem,
- '--output=@OUTPUT@', '--array-name=publicKey_pem']
-)
-
-dep_pluginloader = declare_dependency(
- include_directories: include_directories('.'),
- link_with: static_library('plugin',
- ['pluginloader.cpp', publicKey_h],
- include_directories: include_directories('.'),
- dependencies: [dep_qt5, dependency('openssl', required: true)])
-)
-
-# generate a test file that would be signed
-unsignedfile_dat = custom_target('unsignedfile.dat', input: 'write-random.py', output: 'unsignedfile.dat', command: [ python3, '@INPUT@', '--output=@OUTPUT@' ])
-
-signedfile_dat = custom_target('signedfile.dat', input: 'write-random.py', output: 'signedfile.dat', command: [ python3, '@INPUT@', '--output=@OUTPUT@' ])
-
-badsignedfile_dat = custom_target('badsignedfile.dat', input: 'write-random.py', output: 'badsignedfile.dat', command: [ python3, '@INPUT@', '--output=@OUTPUT@' ])
-badsignedfile_sig = custom_target('badsignedfile.dat.sig', input: 'write-random.py', output: 'badsignedfile.dat.sig', command: [ python3, '@INPUT@', '--output=@OUTPUT@' ])
-
-# sign test file
-signedfile_sig = custom_target('signedfile.dat.sig',
- input: signedfile_dat,
- output: 'signedfile.dat.sig',
- command: [ openssl, 'dgst', '-sha256', '-sign', private_pem, '-out', '@OUTPUT@', '@INPUT@' ]
-)
-
-signedfile_idep = declare_dependency(sources: [ unsignedfile_dat, signedfile_dat, signedfile_sig, badsignedfile_dat, badsignedfile_sig ])
-
-pluginloader_sigmatch = executable('pluginloader-sigmatch',
- sources: [ 'test/pluginloader-sigmatch.cpp' ],
- dependencies: [ dep_qt5, dep_catch, dep_pluginloader, signedfile_idep ]
-)
-
-test('signature matching', pluginloader_sigmatch, suite: 'pluginloader',
- env: {
- 'SIGNEDFILE' : signedfile_dat.full_path(),
- 'UNSIGNEDFILE': unsignedfile_dat.full_path(),
- 'BADSIGNEDFILE': badsignedfile_dat.full_path()
- },
-)
-
-poi_plugin_loader = executable('poi-plugin-load', dependencies: [ dep_qt5, dep_spdlog, dep_pluginloader ], sources: 'test/pluginloader-load.cpp')
-
-# make sure this fails when no plugin or an invalid file is passed
-test('load', poi_plugin_loader, suite: 'pluginloader', should_fail: true)
-test('load', poi_plugin_loader, suite: 'pluginloader', args: files('meson.build'), should_fail: true)
-
diff --git a/lib/pluginloader/pluginloader.cpp b/lib/pluginloader/pluginloader.cpp
index ce84c7a..d4c3dff 100644
--- a/lib/pluginloader/pluginloader.cpp
+++ b/lib/pluginloader/pluginloader.cpp
@@ -17,8 +17,8 @@
bool PluginLoader::verify(const char *hashName)
{
const std::filesystem::path plugin_path(fileName().toStdString());
- if(!std::filesystem::is_regular_file(plugin_path)) {
- m_sigError = tr("A plugin is required, but none was found.");
+ if(!std::filesystem::exists(plugin_path)) {
+ m_sigError = tr("Plugin doesn't exist.");
return false;
}
diff --git a/lib/pluginloader/pluginloader.h b/lib/pluginloader/pluginloader.h
index cc67901..bb5e1e0 100644
--- a/lib/pluginloader/pluginloader.h
+++ b/lib/pluginloader/pluginloader.h
@@ -16,13 +16,12 @@ public:
SigChecked = (1 << 1),
SigEnforced = (1 << 2),
};
- typedef unsigned int signature_state_t;
- static signature_state_t signature_state(bool ignore, bool check, bool enforce)
+ static constexpr signature_level signature_state(bool ignore, bool check, bool enforce)
{
- return (static_cast<unsigned int>(enforce) << 2) | (static_cast<unsigned int>(check) << 1) | static_cast<unsigned int>(ignore);
+ return enforce ? signature_level::SigEnforced : (check ? signature_level::SigChecked : signature_level::SigIgnored);
}
- PluginLoader(const QString &fileName, const signature_state_t state, QObject *parent = nullptr)
+ PluginLoader(const QString &fileName, const signature_level state, QObject *parent = nullptr)
: QPluginLoader(fileName, parent)
, m_state(state)
{
@@ -45,6 +44,6 @@ public:
bool verify(const char *hashName = "SHA256");
private:
- const signature_state_t m_state;
+ const signature_level m_state;
QString m_sigError;
};
diff --git a/lib/pluginloader/test/pluginloader-sigmatch.cpp b/lib/pluginloader/test/pluginloader-sigmatch.cpp
index 0f4789a..fab8b5a 100644
--- a/lib/pluginloader/test/pluginloader-sigmatch.cpp
+++ b/lib/pluginloader/test/pluginloader-sigmatch.cpp
@@ -23,28 +23,40 @@ TEST_CASE("PluginLoader::signature_state")
REQUIRE(PluginLoader::signature_state(true, true, true) >= PluginLoader::SigEnforced);
}
-TEST_CASE("files")
+SCENARIO("PluginLoader")
{
- REQUIRE(qEnvironmentVariableIsSet("UNSIGNEDFILE"));
- REQUIRE(qEnvironmentVariableIsSet("SIGNEDFILE"));
- REQUIRE(qEnvironmentVariableIsSet("BADSIGNEDFILE"));
-}
-
-TEST_CASE("PluginLoader::verify missing plugin")
-{
- const auto state = PluginLoader::signature_state(false, false, false);
- PluginLoader loader("", state);
-
- REQUIRE_FALSE(loader.verify());
- REQUIRE_FALSE(loader.errorString().isEmpty());
-}
-
-TEST_CASE("PluginLoader::verify signature ignored")
-{
- const auto state = PluginLoader::signature_state(true, false, false);
- PluginLoader loader(qgetenv("UNSIGNEDFILE"), state);
-
- REQUIRE(loader.verify());
+ GIVEN("no plugin") {
+ const auto state = PluginLoader::signature_state(false, false, false);
+ PluginLoader loader("", state);
+
+ CHECK_FALSE(loader.verify());
+ CHECK_FALSE(loader.errorString().isEmpty());
+ }
+
+ GIVEN("A plugin with no signature")
+ {
+ const auto f = qgetenv("UNSIGNEDFILE");
+ REQUIRE(!f.isEmpty());
+
+ WHEN("sig is ignored") {
+ const auto state = PluginLoader::signature_state(true, false, false);
+ PluginLoader loader(f, state);
+
+ THEN("verify ok") {
+ REQUIRE(loader.verify());
+ }
+ }
+ }
+
+ GIVEN("A signed plugin")
+ {
+ REQUIRE(qEnvironmentVariableIsSet("SIGNEDFILE"));
+ }
+
+ GIVEN("A badly signed plugin")
+ {
+ REQUIRE(qEnvironmentVariableIsSet("BADSIGNEDFILE"));
+ }
}
TEST_CASE("PluginLoader::verify signature checked [avialable]")
@@ -96,4 +108,4 @@ TEST_CASE("PluginLoader::verify signature enforced [bad]")
REQUIRE_FALSE(loader.verify());
REQUIRE_FALSE(loader.errorString().isEmpty());
-}
+} \ No newline at end of file
diff --git a/lib/session_formats/CMakeLists.txt b/lib/session_formats/CMakeLists.txt
new file mode 100644
index 0000000..75a472c
--- /dev/null
+++ b/lib/session_formats/CMakeLists.txt
@@ -0,0 +1,8 @@
+add_library(session_formats STATIC session_json.hpp session_json.cpp)
+target_link_libraries(session_formats PUBLIC Qt5::Core)
+target_include_directories(session_formats INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} PUBLIC "${CMAKE_SOURCE_DIR}/include")
+
+add_executable(session_json test/json.cpp)
+target_link_libraries(session_json PRIVATE session_formats Catch2::Catch2)
+target_sanitize(session_json)
+add_test(NAME session-json_format COMMAND session_json) \ No newline at end of file
diff --git a/lib/session_formats/meson.build b/lib/session_formats/meson.build
deleted file mode 100644
index d5680cb..0000000
--- a/lib/session_formats/meson.build
+++ /dev/null
@@ -1,9 +0,0 @@
-lib_session_formats = declare_dependency(
- include_directories: [ '.', plugininterfaces_include ],
- link_with: static_library('sessionformats', [ 'session_json.cpp' ], include_directories: plugininterfaces_include, dependencies: dep_qt5)
-)
-
-test('session-json format', executable('session_json',
- sources: 'test/json.cpp',
- dependencies: [ dep_qt5, dep_catch, lib_session_formats ]
-))
diff --git a/lib/session_formats/session_json.hpp b/lib/session_formats/session_json.hpp
index 142d9ef..2de6f5b 100644
--- a/lib/session_formats/session_json.hpp
+++ b/lib/session_formats/session_json.hpp
@@ -10,7 +10,7 @@
#define SESSION_JSON_HPP
#include <QJsonObject>
-#include "smolbote/session.hpp"
+#include <smolbote/session.hpp>
class JsonSession : public Session
{
diff --git a/lib/smolblok/CMakeLists.txt b/lib/smolblok/CMakeLists.txt
new file mode 100644
index 0000000..80d419a
--- /dev/null
+++ b/lib/smolblok/CMakeLists.txt
@@ -0,0 +1,8 @@
+add_library(smolblok STATIC smolblok.hpp smolblok.cpp)
+target_link_libraries(smolblok PUBLIC Qt5::WebEngineWidgets)
+target_include_directories(smolblok
+ INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
+ PUBLIC "${CMAKE_SOURCE_DIR}/include")
+
+add_executable(smolblok-load test/loader.cpp)
+target_link_libraries(smolblok-load PRIVATE smolblok fmt spdlog) \ No newline at end of file
diff --git a/lib/smolblok/meson.build b/lib/smolblok/meson.build
deleted file mode 100644
index ea9e715..0000000
--- a/lib/smolblok/meson.build
+++ /dev/null
@@ -1,15 +0,0 @@
-dep_smolblok = declare_dependency(
- include_directories: [ '.', smolbote_interfaces ],
- link_with: library('smolblok', [ 'smolblok.cpp' ], include_directories: smolbote_interfaces, dependencies: dep_qt5)
-)
-
-poi_sourceset.add(dep_smolblok)
-
-smolblok_load = executable('smolblok-load',
- dependencies: [ dep_qt5, dep_spdlog, dep_smolblok ],
- sources: [ 'test/loader.cpp' ]
-)
-
-test('load', smolblok_load, suite: 'smolblok', should_fail: true)
-test('load', smolblok_load, suite: 'smolblok', args: files('meson.build'), should_fail: true)
-