mirror of
https://github.com/transmission/transmission.git
synced 2026-04-18 07:56:33 +01:00
* build: overhaul tr_add_external_auto_library * build: use package-provided CMake config file libevent * build: use package-provided CMake config file miniupnpc * build: update libutp find module * build: make LIBNAME an optional parameter * build: use package-provided CMake config file libdeflate * build: update libb64 find module * build: update libnatpmp find module * build: update libpsl find module * build: support system fast_float library * chore: reformat long brew commands * build: support system fmt library * build: support system rapidjson library * build: support system small library * build: support system library utf8cpp * build: support system library WideInteger * build: support system library gtest * fix: incorrectly labeled test suites * build: remove unused parameters from tr_add_external_auto_library * build: update crc32c cmake script * fix: dht system library * fix: add libutp interface target * code review: move TrGtest.cmake * code review: move tr_get_fmt_version into Findfmt.cmake * code review: use option() for gtest * code review: move find_package(PkgConfig) out of loop * build: delete FindCrc32c.cmake Impossible to parse package version from distributed source files. * code review: Finddht.cmake * build: delete FindFastFloat.cmake Impossible to parse package version from distributed source files. * code review: Findfmt.cmake * code review: Findlibb64.cmake * code review: Findlibdeflate.cmake * code review: Findlibevent.cmake * code review: Findlibnatpmp.cmake * code review: Findlibpsl.cmake * code review: Findlibutp.cmake * code review: Findlibminiupnpc.cmake * code review: FindRapidJSON.cmake * build: delete FindSmall.cmake Impossible to parse package version from distributed source files. * build: only accept cmake config package for utf8cpp Impossible to parse package version from distributed source files. * build: delete FindWideInteger.cmake Impossible to parse package version from distributed source files. * build: add `USE_SYSTEM_DEFAULT` * ci: drop Fedora 40 and adopt Fedora 43 * ci: try to silence system header warnings * ci: use `cmake --install` * Revert "build: only accept cmake config package for utf8cpp" This reverts commit2158d631fd. * build: harden utf8cpp find module * chore: bump wide-integer Pick upbf9398f9daandbcc726a30f* refactor: gtest should be included with angled brackets Now that gtest is built as a system library, it should be included with angled brackets instead of quotes. * code review: fixup libutp variables before `find_package_handle_standard_args` * code review: define `WIDE_INTEGER_HAS_LIMB_TYPE_UINT64` only for targets depending on WideInteger * chore: bump wide-integer Pickup4b2258acacso that wide-integer tests won't run in Transmission project.
148 lines
5.2 KiB
C++
148 lines
5.2 KiB
C++
// This file Copyright (C) 2022 Mnemosyne LLC.
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
// License text can be found in the licenses/ folder.
|
|
|
|
#include <array>
|
|
#include <ctime> // time, size_t, time_t
|
|
#include <memory>
|
|
#include <set>
|
|
#include <string_view>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/torrent.h>
|
|
#include <libtransmission/torrents.h>
|
|
#include <libtransmission/torrent-metainfo.h>
|
|
#include <libtransmission/tr-strbuf.h>
|
|
|
|
#include "test-fixtures.h"
|
|
|
|
using TorrentsTest = ::libtransmission::test::TransmissionTest;
|
|
using namespace std::literals;
|
|
|
|
TEST_F(TorrentsTest, simpleTests)
|
|
{
|
|
auto constexpr* const TorrentFile = LIBTRANSMISSION_TEST_ASSETS_DIR "/Android-x86 8.1 r6 iso.torrent";
|
|
|
|
auto owned = std::vector<std::unique_ptr<tr_torrent>>{};
|
|
|
|
auto tm = tr_torrent_metainfo{};
|
|
EXPECT_TRUE(tm.parse_torrent_file(TorrentFile));
|
|
owned.emplace_back(std::make_unique<tr_torrent>(std::move(tm)));
|
|
auto* const tor = owned.back().get();
|
|
|
|
auto torrents = tr_torrents{};
|
|
EXPECT_TRUE(std::empty(torrents));
|
|
EXPECT_EQ(0U, std::size(torrents));
|
|
|
|
auto const id = torrents.add(tor);
|
|
EXPECT_GT(id, 0);
|
|
tor->init_id(id);
|
|
|
|
EXPECT_TRUE(std::empty(torrents.removedSince(0)));
|
|
EXPECT_FALSE(std::empty(torrents));
|
|
EXPECT_EQ(1U, std::size(torrents));
|
|
|
|
EXPECT_EQ(tor, torrents.get(id));
|
|
EXPECT_EQ(tor, torrents.get(tor->info_hash()));
|
|
EXPECT_EQ(tor, torrents.get(tor->magnet()));
|
|
|
|
tm = tr_torrent_metainfo{};
|
|
EXPECT_TRUE(tm.parse_torrent_file(TorrentFile));
|
|
EXPECT_EQ(tor, torrents.get(tm));
|
|
|
|
// cleanup
|
|
torrents.remove(tor, time(nullptr));
|
|
}
|
|
|
|
TEST_F(TorrentsTest, rangedLoop)
|
|
{
|
|
auto constexpr Filenames = std::array<std::string_view, 4>{ "Android-x86 8.1 r6 iso.torrent"sv,
|
|
"debian-11.2.0-amd64-DVD-1.iso.torrent"sv,
|
|
"ubuntu-18.04.6-desktop-amd64.iso.torrent"sv,
|
|
"ubuntu-20.04.4-desktop-amd64.iso.torrent"sv };
|
|
|
|
auto owned = std::vector<std::unique_ptr<tr_torrent>>{};
|
|
auto torrents = tr_torrents{};
|
|
auto torrents_set = std::set<tr_torrent const*>{};
|
|
|
|
for (auto const& name : Filenames)
|
|
{
|
|
auto const path = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, '/', name };
|
|
auto tm = tr_torrent_metainfo{};
|
|
EXPECT_TRUE(tm.parse_torrent_file(path));
|
|
owned.emplace_back(std::make_unique<tr_torrent>(std::move(tm)));
|
|
|
|
auto* const tor = owned.back().get();
|
|
tor->init_id(torrents.add(tor));
|
|
EXPECT_EQ(tor, torrents.get(tor->id()));
|
|
torrents_set.insert(tor);
|
|
}
|
|
|
|
for (auto* const tor : torrents)
|
|
{
|
|
EXPECT_EQ(1U, torrents_set.erase(tor));
|
|
}
|
|
EXPECT_EQ(0U, std::size(torrents_set));
|
|
}
|
|
|
|
TEST_F(TorrentsTest, removedSince)
|
|
{
|
|
auto constexpr Filenames = std::array<std::string_view, 4>{ "Android-x86 8.1 r6 iso.torrent"sv,
|
|
"debian-11.2.0-amd64-DVD-1.iso.torrent"sv,
|
|
"ubuntu-18.04.6-desktop-amd64.iso.torrent"sv,
|
|
"ubuntu-20.04.4-desktop-amd64.iso.torrent"sv };
|
|
|
|
auto owned = std::vector<std::unique_ptr<tr_torrent>>{};
|
|
auto torrents = tr_torrents{};
|
|
auto torrents_v = std::vector<tr_torrent const*>{};
|
|
torrents_v.reserve(std::size(Filenames));
|
|
|
|
// setup: add the torrents
|
|
for (auto const& name : Filenames)
|
|
{
|
|
auto const path = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, '/', name };
|
|
auto tm = tr_torrent_metainfo{};
|
|
EXPECT_TRUE(tm.parse_torrent_file(path));
|
|
owned.emplace_back(std::make_unique<tr_torrent>(std::move(tm)));
|
|
|
|
auto* const tor = owned.back().get();
|
|
tor->init_id(torrents.add(tor));
|
|
torrents_v.push_back(tor);
|
|
}
|
|
|
|
// setup: remove them at the given timestamp
|
|
auto constexpr TimeRemoved = std::array<time_t, 4>{ 100, 200, 200, 300 };
|
|
for (size_t i = 0; i < 4; ++i)
|
|
{
|
|
auto* const tor = torrents_v[i];
|
|
EXPECT_EQ(tor, torrents.get(tor->id()));
|
|
torrents.remove(torrents_v[i], TimeRemoved[i]);
|
|
EXPECT_EQ(nullptr, torrents.get(tor->id()));
|
|
}
|
|
|
|
auto remove = std::vector<tr_torrent_id_t>{};
|
|
remove = { torrents_v[3]->id() };
|
|
EXPECT_EQ(remove, torrents.removedSince(300));
|
|
EXPECT_EQ(remove, torrents.removedSince(201));
|
|
remove = { torrents_v[1]->id(), torrents_v[2]->id(), torrents_v[3]->id() };
|
|
EXPECT_EQ(remove, torrents.removedSince(200));
|
|
remove = { torrents_v[0]->id(), torrents_v[1]->id(), torrents_v[2]->id(), torrents_v[3]->id() };
|
|
EXPECT_EQ(remove, torrents.removedSince(50));
|
|
}
|
|
|
|
using TorrentsPieceSpanTest = libtransmission::test::SessionTest;
|
|
|
|
TEST_F(TorrentsPieceSpanTest, exposesFilePieceSpan)
|
|
{
|
|
auto tor = zeroTorrentInit(ZeroTorrentState::Complete);
|
|
auto file_view = tr_torrentFile(tor, 0);
|
|
EXPECT_EQ(file_view.beginPiece, 0);
|
|
EXPECT_EQ(file_view.endPiece, 32);
|
|
}
|