Files
FWS-PacManage/tests/flatpak-manager.test.cpp
T
BlackAngelTV 71eb962b00 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>
2026-08-29 13:34:50 +02:00

103 lines
3.5 KiB
C++

#include "flatpak-manager.h"
#include <cassert>
#include <iostream>
static void testParseSearchOutput_parsesAlignedRows() {
std::string output =
"Name Description Application ID Version Branch Remotes\n"
"Firefox Fast and privacy-aware browser org.mozilla.firefox 128.0.2 stable flathub\n"
"Calculator Simple calculator org.gnome.Calculator 46.0 stable flathub\n";
auto pkgs = FlatpakManager::parseSearchOutput(output);
assert(pkgs.size() == 2);
assert(pkgs[0].name == "org.mozilla.firefox");
assert(pkgs[0].version == "128.0.2");
assert(pkgs[0].repository == "flathub");
// The display name is prefixed to the description.
assert(pkgs[0].description == "Firefox — Fast and privacy-aware browser");
assert(pkgs[1].name == "org.gnome.Calculator");
}
static void testParseSearchOutput_keepsMultiWordDescriptions() {
std::string output =
"Name Description Application ID Version Branch Remotes\n"
"Spotify Desktop music player with sync org.spotify.Client 1.2.3 stable flathub\n";
auto pkgs = FlatpakManager::parseSearchOutput(output);
assert(pkgs.size() == 1);
assert(pkgs[0].name == "org.spotify.Client");
assert(pkgs[0].description == "Spotify — Desktop music player with sync");
}
static void testParseSearchOutput_ignoresVersionLikeTokens() {
// Versions such as 128.0.2 must not be mistaken for an application ID.
std::string output =
"Name Description Application ID Version Branch Remotes\n"
"GIMP Image editor org.gimp.GIMP 2.10.36 stable flathub\n";
auto pkgs = FlatpakManager::parseSearchOutput(output);
assert(pkgs.size() == 1);
assert(pkgs[0].name == "org.gimp.GIMP");
assert(pkgs[0].version == "2.10.36");
}
static void testParseSearchOutput_emptyInput() {
assert(FlatpakManager::parseSearchOutput("").empty());
}
static void testParseInstalledOutput_parsesTabSeparated() {
std::string output =
"org.mozilla.firefox\t128.0.2\tflathub\n"
"org.gnome.Calculator\t46.0\tflathub\n";
auto pkgs = FlatpakManager::parseInstalledOutput(output);
assert(pkgs.size() == 2);
assert(pkgs[0].name == "org.mozilla.firefox");
assert(pkgs[0].version == "128.0.2");
assert(pkgs[0].repository == "flathub");
assert(pkgs[0].installed);
assert(!pkgs[0].updateAvailable);
}
static void testParseInstalledOutput_emptyInput() {
assert(FlatpakManager::parseInstalledOutput("").empty());
}
static void testParseUpdatesOutput_parsesRows() {
std::string output =
"org.mozilla.firefox\t130.0\n"
"org.gnome.Calculator\t47.0\n";
auto pkgs = FlatpakManager::parseUpdatesOutput(output);
assert(pkgs.size() == 2);
assert(pkgs[0].name == "org.mozilla.firefox");
assert(pkgs[0].version == "130.0");
assert(pkgs[0].installed);
assert(pkgs[0].updateAvailable);
}
static void testParseUpdatesOutput_emptyInput() {
assert(FlatpakManager::parseUpdatesOutput("").empty());
}
int main() {
testParseSearchOutput_parsesAlignedRows();
testParseSearchOutput_keepsMultiWordDescriptions();
testParseSearchOutput_ignoresVersionLikeTokens();
testParseSearchOutput_emptyInput();
testParseInstalledOutput_parsesTabSeparated();
testParseInstalledOutput_emptyInput();
testParseUpdatesOutput_parsesRows();
testParseUpdatesOutput_emptyInput();
std::cout << "All flatpak-manager tests passed." << std::endl;
return 0;
}