Files
Library/tests/standalone/Plugin/Plugin.cpp
T
faumaray 6fa77eed93 Windows: make plugin and runtime test guards portable
- Do not build the pthread-based C ABI fixtures on Windows (their tests
  skip without the path macros); the C++ plugin fixtures still build.
- Plugin tests: drop the dlfcn.h proxy guard now that Windows uses
  LoadLibrary; mark the C ABI hardening file @requires-posix.
- RuntimeSignals is POSIX-only (@requires-posix).

Refs #65
2026-12-06 02:56:59 +03:00

80 lines
2.8 KiB
C++

#include <Void/Plugin/Loader.hpp>
#include <Void/Plugin/Plugin.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <string_view>
// 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
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 // VOID_TEST_PLUGIN_PATH