|
|
|
|
#include <ServerContext.hpp>
|
|
|
|
|
#include <SessionContext.hpp>
|
|
|
|
|
#include <Catch/catch.hpp>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
void TestSession::theTorrentExists() {
|
|
|
|
|
torrents_.emplace_back();
|
|
|
|
|
libtorrent::sha1_hash sha1_hash;
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << torrent_id;
|
|
|
|
|
ss >> sha1_hash;
|
|
|
|
|
torrents_.back().hash_ = sha1_hash;
|
|
|
|
|
torrents_.back().valid = true;
|
|
|
|
|
REQUIRE(get_torrents().size() == 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestSessionSettings::set_int(int type, int value) {
|
|
|
|
|
if (type == download_rate_limit) {
|
|
|
|
|
download_rate_limit_ = value;
|
|
|
|
|
}
|
|
|
|
|
if (type == upload_rate_limit) {
|
|
|
|
|
upload_rate_limit_ = value;
|
|
|
|
|
}
|
|
|
|
|
if (type == enable_dht) {
|
|
|
|
|
enable_dht_ = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void TestSessionSettings::set_bool(int type, int value) {
|
|
|
|
|
set_int(type, value);
|
|
|
|
|
}
|
|
|
|
|
int TestSessionSettings::get_int(int type) const {
|
|
|
|
|
if (type == download_rate_limit) {
|
|
|
|
|
return download_rate_limit_;
|
|
|
|
|
}
|
|
|
|
|
if (type == upload_rate_limit) {
|
|
|
|
|
return upload_rate_limit_;
|
|
|
|
|
}
|
|
|
|
|
if (type == enable_dht) {
|
|
|
|
|
return enable_dht_;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
bool TestSessionSettings::get_bool(int type) { return get_int(type); }
|
|
|
|
|
std::string TestSessionSettings::get_str(int type) {
|
|
|
|
|
if (type == listen_interfaces) {
|
|
|
|
|
return listen_interfaces_;
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
void TestSessionSettings::set_str(int type, std::string value) {
|
|
|
|
|
if (type == listen_interfaces) {
|
|
|
|
|
listen_interfaces_ = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bool TestSession::is_valid() {
|
|
|
|
|
return valid;
|
|
|
|
|
}
|
|
|
|
|
TestSessionSettings TestSession::get_settings() {
|
|
|
|
|
return settings_;
|
|
|
|
|
}
|
|
|
|
|
bool TestSession::is_paused() const {
|
|
|
|
|
return paused;
|
|
|
|
|
}
|
|
|
|
|
void TestSession::pause() {
|
|
|
|
|
paused = true;
|
|
|
|
|
}
|
|
|
|
|
void TestSession::resume() {
|
|
|
|
|
paused = false;
|
|
|
|
|
}
|
|
|
|
|
int TestSession::listen_port() {
|
|
|
|
|
return std::stoi(settings_.listen_interfaces_.substr(8, settings_.listen_interfaces_.size() - 8));
|
|
|
|
|
}
|
|
|
|
|
bool TestSession::is_dht_running() const {
|
|
|
|
|
return settings_.enable_dht_;
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
auto res = TestTorrent();
|
|
|
|
|
res.valid = false;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestSession::apply_settings(TestSessionSettings settings) {
|
|
|
|
|
settings_ = settings;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void TestSession::async_add_torrent(const libtorrent::add_torrent_params &settings) {
|
|
|
|
|
torrents_.emplace_back(settings);
|
|
|
|
|
};
|