Files
FWS-PacManage/tests/pacman-manager.test.cpp
T
BlackAngelTV ad31e5c597 fix(crashes): stop destroying QThread workers while still running
Deleting SearchWorker/ListWorker/InstallWorker from the `finished` ->
`deleteLater` connection aborted the app with
"QThread: Destroyed while thread is still running" (SIGABRT) whenever a
list loaded or a package op finished. The deferred delete raced the
thread teardown because these workers have no event loop to process it
after run() returns.

Wait for the thread to complete (wait() clears the running flag, and by
then run() already emitted finished) before scheduling deleteLater, and
bind every cross-thread signal to the MainWindow context object so the
handlers run queued on the GUI thread instead of inside the worker.

Also drop the intrusive popups (removal confirmation, pacman/sudo
unavailable, empty-search notice) in favour of status bar messages, and
let sudo take the password via -S so no per-op polkit dialog is shown.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-28 15:13:15 +02:00

111 lines
3.4 KiB
C++

#include "pacman-manager.h"
#include <cassert>
#include <iostream>
static void testParseInstalledOutput_parsesSimpleLines() {
std::string output = "firefox 128.0\nvim 9.1.0000\n";
auto pkgs = PacmanManager::parseInstalledOutput(output);
assert(pkgs.size() == 2);
assert(pkgs[0].name == "firefox");
assert(pkgs[0].version == "128.0");
assert(pkgs[0].installed);
assert(pkgs[1].name == "vim");
assert(pkgs[1].version == "9.1.0000");
}
static void testParseInstalledOutput_keepsHyphensInNames() {
// Hyphenated package names must not be split on the dash (python-pip, not python)
std::string output = "python-pip 24.0-1\n";
auto pkgs = PacmanManager::parseInstalledOutput(output);
assert(pkgs.size() == 1);
assert(pkgs[0].name == "python-pip");
assert(pkgs[0].version == "24.0-1");
}
static void testParseInstalledOutput_skipsEmptyLines() {
std::string output = "firefox 128.0\n\nvim 9.1.0000\n";
auto pkgs = PacmanManager::parseInstalledOutput(output);
assert(pkgs.size() == 2);
}
static void testParseInstalledOutput_emptyInput() {
auto pkgs = PacmanManager::parseInstalledOutput("");
assert(pkgs.empty());
}
static void testParseInstalledSizes_parsesBlocks() {
std::string output =
"Name : firefox\n"
"Version : 128.0-1\n"
"Installed Size : 263.47 MiB\n"
"Install Date : 2026-01-01\n"
"\n"
"Name : vim\n"
"Installed Size : 12.3 MiB\n";
auto sizes = PacmanManager::parseInstalledSizes(output);
assert(sizes.size() == 2);
assert(sizes["firefox"] == "263.47 MiB");
assert(sizes["vim"] == "12.3 MiB");
}
static void testParseInstalledSizes_emptyInput() {
assert(PacmanManager::parseInstalledSizes("").empty());
}
static void testParseSyncRepos_skipsHeader() {
std::string output =
"Repository Name Version\n"
"core linux 6.6-1\n"
"extra firefox 128.0-1\n"
"multilib gcc-libs 13.2-1\n";
auto repos = PacmanManager::parseSyncRepos(output);
assert(repos.size() == 3);
assert(repos["linux"] == "core");
assert(repos["firefox"] == "extra");
assert(repos["gcc-libs"] == "multilib");
}
static void testParseSyncRepos_emptyInput() {
assert(PacmanManager::parseSyncRepos("").empty());
}
static void testAuthFailed_detectsWrongPassword() {
assert(PacmanManager::authFailed(
"[sudo] password for alice: Sorry, try again.\nsudo: 1 incorrect password attempt"));
}
static void testAuthFailed_detectsMissingPassword() {
assert(PacmanManager::authFailed("sudo: a password is required"));
}
static void testAuthFailed_ignoresPacmanErrors() {
assert(!PacmanManager::authFailed("error: target not found: firefox"));
assert(!PacmanManager::authFailed("warning: firefox is up to date"));
}
int main() {
testParseInstalledOutput_parsesSimpleLines();
testParseInstalledOutput_keepsHyphensInNames();
testParseInstalledOutput_skipsEmptyLines();
testParseInstalledOutput_emptyInput();
testParseInstalledSizes_parsesBlocks();
testParseInstalledSizes_emptyInput();
testParseSyncRepos_skipsHeader();
testParseSyncRepos_emptyInput();
testAuthFailed_detectsWrongPassword();
testAuthFailed_detectsMissingPassword();
testAuthFailed_ignoresPacmanErrors();
std::cout << "All pacman-manager tests passed." << std::endl;
return 0;
}