commits
tags
#include <doctest/doctest.h>
#include "torlinkc/engine/reconcile.hpp"
#include "test_support.hpp"
using namespace torlinkc;
namespace {
QueueItem item(std::string id, DownloadStatus status, std::int64_t addedAt = 1) {
QueueItem it;
it.id = std::move(id);
it.magnet = "magnet:?xt=urn:btih:" + std::string(40, '1');
it.status = status;
it.speed = 123;
it.peers = 7;
it.eta = 42.0;
it.addedAt = addedAt;
return it;
}
} // namespace
TEST_CASE("reconcileQueue drops completed items") {
auto out = reconcileQueue({item("a", DownloadStatus::Completed)});
CHECK(out.empty());
}
TEST_CASE("reconcileQueue dedupes by id, keeping the first occurrence") {
auto a1 = item("a", DownloadStatus::Paused, 1);
auto a2 = item("a", DownloadStatus::Failed, 2);
auto out = reconcileQueue({a1, a2});
REQUIRE(out.size() == 1);
CHECK(out[0].status == DownloadStatus::Paused);
}
TEST_CASE("reconcileQueue preserves failed, paused, and queued status") {
auto out = reconcileQueue({
item("f", DownloadStatus::Failed),
item("p", DownloadStatus::Paused),
item("q", DownloadStatus::Queued),
});
REQUIRE(out.size() == 3);
CHECK(out[0].status == DownloadStatus::Failed);
CHECK(out[1].status == DownloadStatus::Paused);
CHECK(out[2].status == DownloadStatus::Queued);
}
TEST_CASE("reconcileQueue downgrades anything else to downloading") {
auto out = reconcileQueue({item("d", DownloadStatus::Downloading)});
REQUIRE(out.size() == 1);
CHECK(out[0].status == DownloadStatus::Downloading);
}
TEST_CASE("reconcileQueue zeroes live-only stats that never survive a restart") {
auto out = reconcileQueue({item("a", DownloadStatus::Paused)});
REQUIRE(out.size() == 1);
CHECK(out[0].speed == 0);
CHECK(out[0].peers == 0);
CHECK_FALSE(out[0].eta.has_value());
}
TEST_CASE("reconcileQueue skips entries with an empty id") {
auto out = reconcileQueue({item("", DownloadStatus::Paused)});
CHECK(out.empty());
}