#include "plugin-manager.h" #include "pacman-manager.h" #include "flatpak-manager.h" #include #include #include // Exercises PluginManager end-to-end: built-in registration plus runtime // discovery of the example plugins (built into build/plugins by CMake when // FWS_BUILD_EXAMPLE_PLUGIN=ON and FWS_BUILD_EXAMPLE_ADDON=ON). int main(int argc, char* argv[]) { QCoreApplication app(argc, argv); app.setOrganizationName("Freebuff"); app.setApplicationName("PacManager"); PluginManager pm; pm.registerBuiltin({"pacman", "Pacman", "1.0.0", "Natif Arch Linux", "FWS"}, new PacmanManager()); // Flatpak and the sample plugins are dropped next to the test binary by // CMake rather than compiled in. pm.discoverExternal(); // pacman built-in + the flatpak and sample plugins dropped next to the // test binary (flatpak is optional via FWS_BUILD_FLATPAK_PLUGIN). #ifdef FWS_FLATPAK_PLUGIN_BUILT assert(pm.plugins().size() == 3); #else assert(pm.plugins().size() == 2); #endif // Install hints are exposed per provider; the sample plugin omits its // optional hint symbol (must read back empty), while the flatpak plugin // declares the OS package backing its tool. const auto& plugins = pm.plugins(); for (const auto& entry : plugins) { if (entry.info.id == "flatpak") { assert(!entry.info.builtin); assert(entry.info.installHint == "flatpak"); } if (entry.info.id == "sample") assert(entry.info.installHint.empty()); } assert(pm.findAvailable("flatpak") != nullptr); // External provider plugin metadata is exposed through the C ABI. const auto* sample = pm.findAvailable("sample"); assert(sample != nullptr); assert(sample->info.name == "Sample Provider"); assert(sample->info.version == "0.1.0"); assert(sample->info.author == "FWS"); assert(!sample->info.builtin); assert(sample->info.kind == PluginKind::Provider); assert(sample->manager != nullptr); assert(sample->plugin == nullptr); assert(sample->manager->getName() == "sample"); assert(sample->manager->isAvailable()); // The example addon is a generic extension (kind Addon), not a package // manager: it implements IPlugin and its availability proves onLoad() ran // (see plugins/example-addon/example-addon.cpp). const PluginManager::PluginEntry* addon = nullptr; for (const auto& entry : pm.plugins()) { if (entry.info.id == "example-addon") addon = &entry; } assert(addon != nullptr); assert(addon->info.kind == PluginKind::Addon); assert(addon->plugin != nullptr); assert(addon->manager == nullptr); assert(addon->info.available); assert(pm.availableAddons().size() == 1); assert(pm.availableAddons().front() == addon->plugin); // Manager lookup works by id. IPackageManager* pacman = pm.managerFor("pacman"); assert(pacman != nullptr); assert(pacman->getName() == "pacman"); // Enable/disable is persisted and filters the available lists. assert(pm.isEnabled("sample")); pm.setEnabled("sample", false); assert(!pm.isEnabled("sample")); assert(pm.findAvailable("sample") == nullptr); pm.setEnabled("sample", true); assert(pm.findAvailable("sample") != nullptr); pm.setEnabled("example-addon", false); assert(pm.availableAddons().empty()); pm.setEnabled("example-addon", true); assert(pm.availableAddons().size() == 1); // Reload keeps built-ins (same instance) and rescans external plugins: // the addon is recreated (fresh onLoad), so its instance pointer changes. IPackageManager* pacmanBefore = pacman; IPlugin* addonBefore = addon->plugin; pm.reload(); assert(pm.managerFor("pacman") == pacmanBefore); assert(pm.findAvailable("sample") != nullptr); const auto* reloadedAddon = pm.availableAddons().front(); assert(reloadedAddon != addonBefore); assert(reloadedAddon->isAvailable()); // refreshAvailability re-evaluates the presence of every tool. pm.refreshAvailability(); assert(pm.findAvailable("pacman") != nullptr); std::cout << "All plugin-manager tests passed." << std::endl; return 0; }