aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-04-23 22:21:55 +0300
committerAqua-sama <aqua@iserlohn-fortress.net>2020-04-23 22:21:55 +0300
commit36e669345ecec7accd5dedf6099c9cce2e254063 (patch)
treec1844068fd8a497db1e7897f927d1e8f32b68510
parentmove subprojects/plugin_hostlist to plugins/smolblok_hostlist (diff)
downloadsmolbote-36e669345ecec7accd5dedf6099c9cce2e254063.tar.xz
Add smolblok-load utility
-rw-r--r--plugins/smolblok_hostlist/meson.build9
-rw-r--r--staging/smolblok/meson.build10
-rw-r--r--staging/smolblok/smolblok.cpp22
-rw-r--r--staging/smolblok/smolblok.hpp34
-rw-r--r--staging/smolblok/test/loader.cpp25
5 files changed, 69 insertions, 31 deletions
diff --git a/plugins/smolblok_hostlist/meson.build b/plugins/smolblok_hostlist/meson.build
index a3e64a7..7dde699 100644
--- a/plugins/smolblok_hostlist/meson.build
+++ b/plugins/smolblok_hostlist/meson.build
@@ -20,16 +20,17 @@ plugin = shared_library('smolblokHostlistPlugin',
)
# tests
-test('rule parsing', executable('rule',
- sources: 'test/rule.cpp',
- dependencies: [dep_qt5, dep_catch, dep_hostlistfilter]))
+test('rule', executable('rule', sources: 'test/rule.cpp', dependencies: [dep_qt5, dep_catch, dep_hostlistfilter]), suite: 'hostlist')
test('filterlist', executable('filterlist',
sources: 'test/filterlist.cpp',
dependencies: [dep_qt5, dep_catch, dep_hostlistfilter]),
- env: 'HOSTLIST_TXT='+meson.current_source_dir()/'test/hostlist.txt'
+ env: 'HOSTLIST_TXT='+meson.current_source_dir()/'test/hostlist.txt',
+ suite: 'hostlist'
)
+test('plugin', smolblok_load, workdir: meson.build_root(), args: plugin.full_path(), suite: 'hostlist')
+
# fuzzer
if meson.get_compiler('cpp').has_multi_arguments('-g', '-fsanitize=fuzzer')
executable('hostlist-fuzzer',
diff --git a/staging/smolblok/meson.build b/staging/smolblok/meson.build
index 8ae0c74..6105179 100644
--- a/staging/smolblok/meson.build
+++ b/staging/smolblok/meson.build
@@ -7,9 +7,11 @@ dep_smolblok = declare_dependency(
)
)
-test('smolblok', executable('filterlist',
- dependencies: [ dep_qt5, dep_catch, dep_smolblok ],
- sources: [ 'test/main.cpp' ]
- )
+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)
+
diff --git a/staging/smolblok/smolblok.cpp b/staging/smolblok/smolblok.cpp
index 26d46cb..465c348 100644
--- a/staging/smolblok/smolblok.cpp
+++ b/staging/smolblok/smolblok.cpp
@@ -10,28 +10,6 @@
#include <QFile>
#include <QSettings>
-bool smolblok::registerFormatPlugin(const QString &format, const QString &filename)
-{
- if(format.isEmpty() || filename.isEmpty()) {
- return false;
- }
-
- auto *plugin = new QPluginLoader(filename);
- if(!plugin->load()) {
- delete plugin;
- return false;
- }
-
- auto *instance = qobject_cast<FilterPlugin *>(plugin->instance());
- if(instance == nullptr) {
- delete plugin;
- return false;
- }
-
- m_formats[format] = PluginInfo{ plugin, instance };
- return false;
-}
-
bool smolblok::addSubscriptions(const QString &filename)
{
if(filename.isEmpty()) {
diff --git a/staging/smolblok/smolblok.hpp b/staging/smolblok/smolblok.hpp
index d3e63fb..e547d67 100644
--- a/staging/smolblok/smolblok.hpp
+++ b/staging/smolblok/smolblok.hpp
@@ -17,13 +17,45 @@
class smolblok
{
public:
+ smolblok() = default;
~smolblok()
{
for(auto &plugin : m_formats) {
delete plugin.loader;
}
}
- bool registerFormatPlugin(const QString &format, const QString &filename);
+
+ auto registerFormatPlugin(const QString &format, const QString &filename)
+ {
+ struct {
+ bool loaded = false;
+ QString error;
+ } ret;
+
+ if(format.isEmpty() || filename.isEmpty()) {
+ ret.error = "Format or filename is empty";
+ return ret;
+ }
+
+ auto *plugin = new QPluginLoader(filename);
+ if(!plugin->load()) {
+ ret.error = plugin->errorString();
+ delete plugin;
+ return ret;
+ }
+
+ auto *instance = qobject_cast<FilterPlugin *>(plugin->instance());
+ if(instance == nullptr) {
+ ret.error = "Unable to cast";
+ delete plugin;
+ return ret;
+ }
+
+ m_formats[format] = PluginInfo{ plugin, instance };
+ ret.loaded = true;
+ return ret;
+ }
+
const auto formats() const
{
return m_formats.keys();
diff --git a/staging/smolblok/test/loader.cpp b/staging/smolblok/test/loader.cpp
new file mode 100644
index 0000000..9e27a26
--- /dev/null
+++ b/staging/smolblok/test/loader.cpp
@@ -0,0 +1,25 @@
+#include "smolblok.hpp"
+#include <spdlog/spdlog.h>
+
+int main(int argc, char** argv)
+{
+ if(argc != 2) {
+ spdlog::error("usage: {} path/to/plugin.so", argv[0]);
+ return -1;
+ }
+
+ smolblok filter;
+ {
+ const auto r = filter.registerFormatPlugin("unused", argv[1]);
+ if(r.loaded) {
+ spdlog::info("Loaded plugin {}", argv[1]);
+ } else {
+ spdlog::error("Failed loading plugin {}", argv[1]);
+ spdlog::error(qUtf8Printable(r.error));
+ return -1;
+ }
+ }
+
+ return 0;
+}
+