test: cover flatpak parsing and plugin discovery
Unit-test the flatpak parsers (search rows, installed/update columns) and the plugin manager end-to-end: built-in registration, runtime discovery of the sample plugin, enable/disable persistence, reload and install-hint exposure. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
3 files changed
+197
No files matched your search
@@ -0,0 +1,74 @@
|
||||
#include "plugin-manager.h"
|
||||
#include "pacman-manager.h"
|
||||
#include "flatpak-manager.h"
|
||||
#include <QCoreApplication>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
// Exercises PluginManager end-to-end: built-in registration plus runtime
|
||||
// discovery of the example plugin (built into build/plugins by CMake when
|
||||
// FWS_BUILD_EXAMPLE_PLUGIN=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 ships an install hint so the app can offer to install the tool
|
||||
// (pacman -S flatpak) when it is missing on the system.
|
||||
pm.registerBuiltin({"flatpak", "Flatpak", "1.0.0", "Flatpak", "FWS",
|
||||
false, "", false, "flatpak"},
|
||||
new FlatpakManager());
|
||||
pm.discoverExternal();
|
||||
|
||||
// Built-ins + the sample plugin dropped next to the test binary.
|
||||
assert(pm.providers().size() == 3);
|
||||
|
||||
// Install hints are exposed per provider; the sample plugin omits its
|
||||
// optional hint symbol, which must read back as empty.
|
||||
const auto& providers = pm.providers();
|
||||
for (const auto& entry : providers) {
|
||||
if (entry.info.id == "flatpak") assert(entry.info.installHint == "flatpak");
|
||||
if (entry.info.id == "sample") assert(entry.info.installHint.empty());
|
||||
}
|
||||
assert(pm.findAvailable("flatpak") != nullptr);
|
||||
|
||||
// External 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->manager != nullptr);
|
||||
assert(sample->manager->getName() == "sample");
|
||||
assert(sample->manager->isAvailable());
|
||||
|
||||
// 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 list.
|
||||
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);
|
||||
|
||||
// Reload keeps built-ins (same instance) and rescans external plugins.
|
||||
IPackageManager* pacmanBefore = pacman;
|
||||
pm.reload();
|
||||
assert(pm.managerFor("pacman") == pacmanBefore);
|
||||
assert(pm.findAvailable("sample") != nullptr);
|
||||
|
||||
// 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;
|
||||
}
|
||||
Reference in new issue
Block a user