From d6113123b8666c32d4b718f089806a968aabe2d2 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Mon, 30 Sep 2024 18:37:16 -0700 Subject: Add plugin test. --- plugin/CMakeLists.txt | 18 ++++++++++++++++++ plugin/test/hello_plugin.c | 3 +++ plugin/test/plugin_test.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 plugin/test/hello_plugin.c create mode 100644 plugin/test/plugin_test.c 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) set(CMAKE_C_STANDARD_REQUIRED On) set(CMAKE_C_EXTENSIONS Off) +# Library. + add_library(plugin src/plugin.c) @@ -18,3 +20,19 @@ target_link_libraries(plugin PRIVATE log) target_compile_options(plugin PRIVATE -Wall -Wextra) + +# Test + +add_library(hello_plugin SHARED + test/hello_plugin.c) + +target_compile_options(hello_plugin PRIVATE -Wall -Wextra) + +add_executable(plugin_test + test/plugin_test.c) + +target_link_libraries(plugin_test + plugin + test) + +target_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 @@ +#include + +void 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 @@ +#include "plugin.h" + +#include "test.h" + +#include + +typedef void (*SayHelloFunc)(void); + +TEST_CASE(test_hello_plugin) { + PluginEngine* eng = + new_plugin_engine(&(PluginEngineDesc){.plugins_dir = "."}); + TEST_TRUE(eng != 0); + + Plugin* plugin = load_plugin(eng, "hello_plugin"); + TEST_TRUE(plugin != 0); + + plugin_call(plugin, SayHelloFunc, "SayHello"); + + printf("Now modify the plugin, build it, and press enter"); + fflush(stdout); + getchar(); + + plugin_engine_update(eng); + + plugin_call(plugin, SayHelloFunc, "SayHello"); + + delete_plugin_engine(&eng); + TEST_TRUE(eng == 0); +} + +int main() { return 0; } -- cgit v1.2.3