|
|
|
|
@ -1,16 +1,17 @@
|
|
|
|
|
#include <Catch/catch.hpp> |
|
|
|
|
#include <ServerContext.hpp> |
|
|
|
|
#include <SessionContext.hpp> |
|
|
|
|
#include <Catch/catch.hpp> |
|
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
void TestSession::theTorrentExists() { |
|
|
|
|
torrents_.emplace_back(); |
|
|
|
|
auto &torrent = torrents_.back(); |
|
|
|
|
libtorrent::sha1_hash sha1_hash; |
|
|
|
|
std::stringstream ss; |
|
|
|
|
ss << torrent_id; |
|
|
|
|
ss >> sha1_hash; |
|
|
|
|
torrents_.back().hash_ = sha1_hash; |
|
|
|
|
torrents_.back().valid = true; |
|
|
|
|
torrent.hash_ = sha1_hash; |
|
|
|
|
torrent.valid = true; |
|
|
|
|
REQUIRE(get_torrents().size() == 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -77,27 +78,28 @@ std::vector<TestTorrent> &TestSession::get_torrents() {
|
|
|
|
|
return torrents_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TestTorrent TestSession::find_torrent(const libtorrent::sha1_hash &hash) { |
|
|
|
|
for (auto &torrent : torrents_) { |
|
|
|
|
if (torrent.info_hash() == hash) { |
|
|
|
|
return torrent; |
|
|
|
|
} |
|
|
|
|
TestTorrent &TestSession::find_torrent(const libtorrent::sha1_hash &hash) { |
|
|
|
|
auto itr = std::find_if(torrents_.begin(), torrents_.end(), [&](TestTorrent torrent) { |
|
|
|
|
return torrent.info_hash() == hash; |
|
|
|
|
}); |
|
|
|
|
if (itr != torrents_.end()) { |
|
|
|
|
return *itr; |
|
|
|
|
} |
|
|
|
|
auto res = TestTorrent(); |
|
|
|
|
res.valid = false; |
|
|
|
|
return res; |
|
|
|
|
return invalid_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TestSession::remove_torrent(const TestTorrent &torrent, int options = -1) { |
|
|
|
|
if (options > -1) { |
|
|
|
|
auto itr = torrents_.end(); |
|
|
|
|
for (itr = torrents_.begin(); itr != torrents_.end(); itr++) { |
|
|
|
|
if (itr->info_hash() == torrent.info_hash()) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (itr != torrents_.end()) |
|
|
|
|
torrents_.erase(itr); |
|
|
|
|
// auto itr = torrents_.end();
|
|
|
|
|
// for (itr = torrents_.begin(); itr != torrents_.end(); itr++) {
|
|
|
|
|
// if (itr->info_hash() == torrent.info_hash()) {
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// if (itr != torrents_.end())
|
|
|
|
|
torrents_.erase(std::find_if(torrents_.begin(), torrents_.end(), [&](TestTorrent a) { |
|
|
|
|
return a.info_hash() == torrent.info_hash(); |
|
|
|
|
})); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|