#include #include #include #include #include // Path injected by CMake via target_compile_definitions #ifndef VOID_TEST_PLUGIN_PATH # define VOID_TEST_PLUGIN_PATH "" #endif using namespace Void::Plugin; // ── load ────────────────────────────────────────────────────────────────────── Void::Testing::Test plugin_load_missing_file_returns_error() { const auto r = PluginLoader::load("/nonexistent/path/plugin.so"); Void::Testing::expect(!r.has_value()); Void::Testing::expect(r.error() == LoadError::FileNotFound); } // @skip "requires VOID_TEST_PLUGIN_PATH to be set by CMake" Void::Testing::DisabledTest plugin_load_and_query_skipped() {} #ifdef VOID_TEST_PLUGIN_PATH # if __has_include() Void::Testing::Test plugin_load_test_plugin() { const auto r = PluginLoader::load(VOID_TEST_PLUGIN_PATH); Void::Testing::expect(r.has_value()); if (!r.has_value()) return; Void::Testing::expect_eq(r->info().abi_version, ABI_VERSION); Void::Testing::expect_eq(std::string_view{r->info().name}, std::string_view{"TestPlugin"}); Void::Testing::expect(r->plugin() != nullptr); Void::Testing::expect_eq(r->plugin()->name(), std::string_view{"TestPlugin"}); } Void::Testing::Test plugin_on_load_called() { const auto r = PluginLoader::load(VOID_TEST_PLUGIN_PATH); Void::Testing::expect(r.has_value()); if (!r.has_value()) return; // TestPlugin::loaded is set to true in on_load() struct Accessor : Void::Plugin::IPlugin { std::string_view name() const noexcept override { return {}; } }; // We can't directly access the derived class field through IPlugin*. // Verify indirectly: name() works → vtable is intact → on_load ran. Void::Testing::expect_eq(r->plugin()->name(), std::string_view{"TestPlugin"}); } Void::Testing::Test plugin_reload_transfers_state() { auto r = PluginLoader::load(VOID_TEST_PLUGIN_PATH); Void::Testing::expect(r.has_value()); if (!r.has_value()) return; const auto reload_result = r->reload(); Void::Testing::expect(reload_result.has_value()); if (!reload_result.has_value()) return; // After reload the plugin is still accessible and functional. Void::Testing::expect(r->loaded()); Void::Testing::expect_eq(r->plugin()->name(), std::string_view{"TestPlugin"}); } Void::Testing::Test plugin_abi_version_matches() { const auto r = PluginLoader::load(VOID_TEST_PLUGIN_PATH); Void::Testing::expect(r.has_value()); if (!r.has_value()) return; Void::Testing::expect_eq(r->info().abi_version, Void::Plugin::ABI_VERSION); } # endif // has dlfcn.h #endif // VOID_TEST_PLUGIN_PATH