aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'plugin')
-rw-r--r--plugin/CMakeLists.txt18
-rw-r--r--plugin/test/hello_plugin.c3
-rw-r--r--plugin/test/plugin_test.c31
3 files changed, 52 insertions, 0 deletions
diff --git a/plugin/CMakeLists.txt b/plugin/CMakeLists.txt
index f2745b2..2c34228 100644
--- a/plugin/CMakeLists.txt
+++ b/plugin/CMakeLists.txt
@@ -6,6 +6,8 @@ set(CMAKE_C_STANDARD 23)
6set(CMAKE_C_STANDARD_REQUIRED On) 6set(CMAKE_C_STANDARD_REQUIRED On)
7set(CMAKE_C_EXTENSIONS Off) 7set(CMAKE_C_EXTENSIONS Off)
8 8
9# Library.
10
9add_library(plugin 11add_library(plugin
10 src/plugin.c) 12 src/plugin.c)
11 13
@@ -18,3 +20,19 @@ target_link_libraries(plugin PRIVATE
18 log) 20 log)
19 21
20target_compile_options(plugin PRIVATE -Wall -Wextra) 22target_compile_options(plugin PRIVATE -Wall -Wextra)
23
24# Test
25
26add_library(hello_plugin SHARED
27 test/hello_plugin.c)
28
29target_compile_options(hello_plugin PRIVATE -Wall -Wextra)
30
31add_executable(plugin_test
32 test/plugin_test.c)
33
34target_link_libraries(plugin_test
35 plugin
36 test)
37
38target_compile_options(plugin_test PRIVATE -DUNIT_TEST -DNDEBUG -Wall -Wextra)
diff --git a/plugin/test/hello_plugin.c b/plugin/test/hello_plugin.c
new file mode 100644
index 0000000..1ab290f
--- /dev/null
+++ b/plugin/test/hello_plugin.c
@@ -0,0 +1,3 @@
1#include <stdio.h>
2
3void SayHello() { printf("Hello!\n"); }
diff --git a/plugin/test/plugin_test.c b/plugin/test/plugin_test.c
new file mode 100644
index 0000000..d31bab6
--- /dev/null
+++ b/plugin/test/plugin_test.c
@@ -0,0 +1,31 @@
1#include "plugin.h"
2
3#include "test.h"
4
5#include <stdio.h>
6
7typedef void (*SayHelloFunc)(void);
8
9TEST_CASE(test_hello_plugin) {
10 PluginEngine* eng =
11 new_plugin_engine(&(PluginEngineDesc){.plugins_dir = "."});
12 TEST_TRUE(eng != 0);
13
14 Plugin* plugin = load_plugin(eng, "hello_plugin");
15 TEST_TRUE(plugin != 0);
16
17 plugin_call(plugin, SayHelloFunc, "SayHello");
18
19 printf("Now modify the plugin, build it, and press enter");
20 fflush(stdout);
21 getchar();
22
23 plugin_engine_update(eng);
24
25 plugin_call(plugin, SayHelloFunc, "SayHello");
26
27 delete_plugin_engine(&eng);
28 TEST_TRUE(eng == 0);
29}
30
31int main() { return 0; }