2014-11-08 17:58:18 +01:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2014, Arvid Norberg
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libtorrent/session.hpp"
|
|
|
|
#include "libtorrent/add_torrent_params.hpp"
|
|
|
|
#include "libtorrent/torrent_info.hpp"
|
|
|
|
#include "libtorrent/random.hpp"
|
|
|
|
#include "libtorrent/create_torrent.hpp"
|
2015-07-14 04:19:55 +02:00
|
|
|
#include "libtorrent/alert_types.hpp"
|
|
|
|
#include "libtorrent/entry.hpp"
|
2015-07-25 07:34:53 +02:00
|
|
|
#include "libtorrent/bencode.hpp"
|
2017-11-28 22:59:46 +01:00
|
|
|
#include "libtorrent/peer_info.hpp"
|
2014-11-08 17:58:18 +01:00
|
|
|
|
|
|
|
#include <boost/make_shared.hpp>
|
|
|
|
|
|
|
|
#include "test.hpp"
|
|
|
|
#include "setup_transfer.hpp"
|
2016-08-21 18:15:19 +02:00
|
|
|
#include "settings.hpp"
|
2014-11-08 17:58:18 +01:00
|
|
|
|
|
|
|
using namespace libtorrent;
|
2015-09-02 07:30:40 +02:00
|
|
|
namespace lt = libtorrent;
|
2014-11-08 17:58:18 +01:00
|
|
|
|
2015-07-14 04:19:55 +02:00
|
|
|
std::vector<char> generate_resume_data(torrent_info* ti
|
|
|
|
, char const* file_priorities = "")
|
2014-11-08 17:58:18 +01:00
|
|
|
{
|
|
|
|
entry rd;
|
|
|
|
|
|
|
|
rd["file-format"] = "libtorrent resume file";
|
|
|
|
rd["file-version"] = 1;
|
|
|
|
rd["info-hash"] = ti->info_hash().to_string();
|
|
|
|
rd["blocks per piece"] = (std::max)(1, ti->piece_length() / 0x4000);
|
2015-07-27 09:01:19 +02:00
|
|
|
rd["pieces"] = std::string(ti->num_pieces(), '\x01');
|
2014-11-08 17:58:18 +01:00
|
|
|
|
|
|
|
rd["total_uploaded"] = 1337;
|
|
|
|
rd["total_downloaded"] = 1338;
|
|
|
|
rd["active_time"] = 1339;
|
|
|
|
rd["seeding_time"] = 1340;
|
|
|
|
rd["num_seeds"] = 1341;
|
|
|
|
rd["num_downloaders"] = 1342;
|
|
|
|
rd["upload_rate_limit"] = 1343;
|
|
|
|
rd["download_rate_limit"] = 1344;
|
|
|
|
rd["max_connections"] = 1345;
|
|
|
|
rd["max_uploads"] = 1346;
|
|
|
|
rd["seed_mode"] = 0;
|
|
|
|
rd["super_seeding"] = 0;
|
|
|
|
rd["added_time"] = 1347;
|
|
|
|
rd["completed_time"] = 1348;
|
2018-04-20 13:03:36 +02:00
|
|
|
rd["last_scrape"] = 1;
|
|
|
|
rd["last_download"] = 2;
|
|
|
|
rd["last_upload"] = 3;
|
2014-11-08 17:58:18 +01:00
|
|
|
rd["finished_time"] = 1352;
|
2015-07-14 04:19:55 +02:00
|
|
|
if (file_priorities && file_priorities[0])
|
|
|
|
{
|
|
|
|
entry::list_type& file_prio = rd["file_priority"].list();
|
|
|
|
for (int i = 0; file_priorities[i]; ++i)
|
|
|
|
file_prio.push_back(entry(file_priorities[i] - '0'));
|
|
|
|
}
|
2014-11-08 17:58:18 +01:00
|
|
|
|
|
|
|
rd["piece_priority"] = std::string(ti->num_pieces(), '\x01');
|
|
|
|
rd["auto_managed"] = 0;
|
|
|
|
rd["sequential_download"] = 0;
|
|
|
|
rd["paused"] = 0;
|
|
|
|
entry::list_type& trackers = rd["trackers"].list();
|
|
|
|
trackers.push_back(entry(entry::list_t));
|
|
|
|
trackers.back().list().push_back(entry("http://resume_data_tracker.com/announce"));
|
|
|
|
entry::list_type& url_list = rd["url-list"].list();
|
|
|
|
url_list.push_back(entry("http://resume_data_url_seed.com"));
|
|
|
|
|
|
|
|
entry::list_type& httpseeds = rd["httpseeds"].list();
|
|
|
|
httpseeds.push_back(entry("http://resume_data_http_seed.com"));
|
|
|
|
|
2014-11-19 10:23:08 +01:00
|
|
|
#ifdef TORRENT_WINDOWS
|
|
|
|
rd["save_path"] = "c:\\resume_data save_path";
|
|
|
|
#else
|
2014-11-08 17:58:18 +01:00
|
|
|
rd["save_path"] = "/resume_data save_path";
|
2014-11-19 10:23:08 +01:00
|
|
|
#endif
|
2014-11-08 17:58:18 +01:00
|
|
|
|
|
|
|
std::vector<char> ret;
|
|
|
|
bencode(back_inserter(ret), rd);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-09-02 07:30:40 +02:00
|
|
|
torrent_handle test_resume_flags(lt::session& ses, int flags
|
2015-07-14 04:19:55 +02:00
|
|
|
, char const* file_priorities = "1111", char const* resume_file_prio = "")
|
2014-11-08 17:58:18 +01:00
|
|
|
{
|
|
|
|
boost::shared_ptr<torrent_info> ti = generate_torrent();
|
|
|
|
|
|
|
|
add_torrent_params p;
|
2015-05-30 06:31:23 +02:00
|
|
|
|
2014-11-08 17:58:18 +01:00
|
|
|
p.ti = ti;
|
|
|
|
p.flags = flags;
|
2014-11-19 10:23:08 +01:00
|
|
|
#ifdef TORRENT_WINDOWS
|
|
|
|
p.save_path = "c:\\add_torrent_params save_path";
|
|
|
|
#else
|
2014-11-08 17:58:18 +01:00
|
|
|
p.save_path = "/add_torrent_params save_path";
|
2014-11-19 10:23:08 +01:00
|
|
|
#endif
|
2014-11-08 17:58:18 +01:00
|
|
|
p.trackers.push_back("http://add_torrent_params_tracker.com/announce");
|
|
|
|
p.url_seeds.push_back("http://add_torrent_params_url_seed.com");
|
|
|
|
|
2015-07-14 04:19:55 +02:00
|
|
|
std::vector<char> rd = generate_resume_data(ti.get(), resume_file_prio);
|
2014-11-08 17:58:18 +01:00
|
|
|
p.resume_data.swap(rd);
|
|
|
|
|
|
|
|
p.max_uploads = 1;
|
|
|
|
p.max_connections = 2;
|
|
|
|
p.upload_limit = 3;
|
|
|
|
p.download_limit = 4;
|
2015-07-14 04:19:55 +02:00
|
|
|
|
|
|
|
std::vector<boost::uint8_t> priorities_vector;
|
|
|
|
for (int i = 0; file_priorities[i]; ++i)
|
|
|
|
priorities_vector.push_back(file_priorities[i] - '0');
|
|
|
|
|
|
|
|
p.file_priorities = priorities_vector;
|
2014-11-08 17:58:18 +01:00
|
|
|
|
|
|
|
torrent_handle h = ses.add_torrent(p);
|
|
|
|
torrent_status s = h.status();
|
|
|
|
TEST_EQUAL(s.info_hash, ti->info_hash());
|
2015-07-14 04:19:55 +02:00
|
|
|
return h;
|
2014-11-08 17:58:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void default_tests(torrent_status const& s)
|
|
|
|
{
|
2015-01-27 23:18:13 +01:00
|
|
|
// allow some slack in the time stamps since they are reported as
|
|
|
|
// relative times. If the computer is busy while running the unit test
|
|
|
|
// or running under valgrind it may take several seconds
|
2018-04-20 13:03:36 +02:00
|
|
|
int const now = duration_cast<seconds>(clock_type::now().time_since_epoch()).count();
|
|
|
|
TEST_CHECK(s.last_scrape >= now - 1);
|
|
|
|
TEST_CHECK(s.time_since_download >= now - 2);
|
|
|
|
TEST_CHECK(s.time_since_upload >= now - 3);
|
2015-01-27 23:18:13 +01:00
|
|
|
TEST_CHECK(s.active_time >= 1339);
|
|
|
|
|
2018-04-20 13:03:36 +02:00
|
|
|
TEST_CHECK(s.last_scrape < now - 1 + 10);
|
|
|
|
TEST_CHECK(s.time_since_download < now - 2 + 10);
|
|
|
|
TEST_CHECK(s.time_since_upload < now - 3 + 10);
|
2015-01-27 23:18:13 +01:00
|
|
|
TEST_CHECK(s.active_time < 1339 + 10);
|
2015-01-19 04:14:35 +01:00
|
|
|
|
2017-11-28 22:59:46 +01:00
|
|
|
TEST_CHECK(s.finished_time >= 1352);
|
|
|
|
TEST_CHECK(s.seeding_time >= 1340);
|
|
|
|
TEST_CHECK(s.added_time >= 1347);
|
|
|
|
TEST_CHECK(s.completed_time >= 1348);
|
|
|
|
|
|
|
|
TEST_CHECK(s.finished_time < 1352 + 5);
|
|
|
|
TEST_CHECK(s.seeding_time < 1340 + 5);
|
|
|
|
TEST_CHECK(s.added_time < 1347 + 5);
|
|
|
|
TEST_CHECK(s.completed_time < 1348 + 5);
|
2014-11-08 17:58:18 +01:00
|
|
|
}
|
|
|
|
|
2016-10-24 04:01:09 +02:00
|
|
|
void test_file_sizes(bool allocate)
|
|
|
|
{
|
|
|
|
error_code ec;
|
|
|
|
remove_all("test_resume", ec);
|
|
|
|
|
|
|
|
lt::settings_pack pack = settings();
|
|
|
|
// we're not testing the hash check, just accept the data we write
|
|
|
|
pack.set_bool(settings_pack::disable_hash_checks, true);
|
|
|
|
lt::session ses(pack);
|
|
|
|
boost::shared_ptr<torrent_info> ti = generate_torrent();
|
|
|
|
add_torrent_params p;
|
|
|
|
p.ti = ti;
|
|
|
|
p.save_path = ".";
|
|
|
|
if (allocate) p.storage_mode = storage_mode_allocate;
|
|
|
|
torrent_handle h = ses.add_torrent(p);
|
|
|
|
|
|
|
|
wait_for_downloading(ses, "ses");
|
|
|
|
|
|
|
|
std::vector<char> piece(ti->piece_length(), 0);
|
|
|
|
h.add_piece(0, piece.data());
|
|
|
|
|
|
|
|
h.save_resume_data();
|
|
|
|
alert const* a = wait_for_alert(ses, save_resume_data_alert::alert_type);
|
|
|
|
TEST_CHECK(a);
|
|
|
|
|
|
|
|
save_resume_data_alert const* ra = alert_cast<save_resume_data_alert>(a);
|
|
|
|
TEST_CHECK(ra);
|
|
|
|
if (ra)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s\n", ra->resume_data->to_string().c_str());
|
|
|
|
bool const has_file_sizes = ra->resume_data->dict().count("file sizes") == 1;
|
|
|
|
TEST_CHECK(has_file_sizes);
|
|
|
|
if (!has_file_sizes) return;
|
|
|
|
// { 'file sizes': [ [ size, timestamp], [...], ... ] }
|
|
|
|
boost::int64_t const file_size = (*ra->resume_data)["file sizes"].list()
|
|
|
|
.front().list().front().integer();
|
|
|
|
if (allocate)
|
|
|
|
{
|
|
|
|
TEST_EQUAL(file_size, ti->files().file_size(0));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TEST_EQUAL(file_size, ti->piece_length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(file_sizes_allocate)
|
|
|
|
{
|
|
|
|
test_file_sizes(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(file_sizes)
|
|
|
|
{
|
|
|
|
test_file_sizes(false);
|
|
|
|
}
|
|
|
|
|
2015-07-25 07:34:53 +02:00
|
|
|
TORRENT_TEST(piece_priorities)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-25 07:34:53 +02:00
|
|
|
boost::shared_ptr<torrent_info> ti = generate_torrent();
|
|
|
|
add_torrent_params p;
|
|
|
|
p.ti = ti;
|
|
|
|
p.save_path = ".";
|
|
|
|
torrent_handle h = ses.add_torrent(p);
|
|
|
|
|
|
|
|
h.piece_priority(0, 0);
|
|
|
|
h.piece_priority(ti->num_pieces()-1, 0);
|
|
|
|
|
|
|
|
h.save_resume_data();
|
|
|
|
alert const* a = wait_for_alert(ses, save_resume_data_alert::alert_type);
|
|
|
|
|
|
|
|
TEST_CHECK(a);
|
2016-10-24 04:01:09 +02:00
|
|
|
save_resume_data_alert const* ra = alert_cast<save_resume_data_alert>(a);
|
|
|
|
TEST_CHECK(ra);
|
|
|
|
if (ra)
|
2015-07-25 07:34:53 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr, "%s\n", ra->resume_data->to_string().c_str());
|
|
|
|
entry::string_type prios = (*ra->resume_data)["piece_priority"].string();
|
2015-08-20 01:33:20 +02:00
|
|
|
TEST_EQUAL(int(prios.size()), ti->num_pieces());
|
2015-07-25 07:34:53 +02:00
|
|
|
TEST_EQUAL(prios[0], '\0');
|
|
|
|
TEST_EQUAL(prios[1], '\x04');
|
|
|
|
TEST_EQUAL(prios[ti->num_pieces()-1], '\0');
|
|
|
|
|
|
|
|
bencode(std::back_inserter(p.resume_data), *ra->resume_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
ses.remove_torrent(h);
|
|
|
|
|
|
|
|
// now, make sure the piece priorities are loaded correctly
|
|
|
|
h = ses.add_torrent(p);
|
2015-07-27 09:01:19 +02:00
|
|
|
|
2015-07-25 07:34:53 +02:00
|
|
|
TEST_EQUAL(h.piece_priority(0), 0);
|
|
|
|
TEST_EQUAL(h.piece_priority(1), 4);
|
|
|
|
TEST_EQUAL(h.piece_priority(ti->num_pieces()-1), 0);
|
|
|
|
}
|
|
|
|
|
2015-07-14 04:19:55 +02:00
|
|
|
// TODO: test what happens when loading a resume file with both piece priorities
|
|
|
|
// and file priorities (file prio should take presedence)
|
|
|
|
|
|
|
|
// TODO: make sure a resume file only ever contain file priorities OR piece
|
|
|
|
// priorities. Never both.
|
|
|
|
|
|
|
|
// TODO: generally save
|
|
|
|
|
|
|
|
TORRENT_TEST(file_priorities_default)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-14 04:19:55 +02:00
|
|
|
std::vector<int> file_priorities = test_resume_flags(ses, 0, "", "").file_priorities();
|
|
|
|
|
|
|
|
TEST_EQUAL(file_priorities.size(), 3);
|
2015-07-27 09:01:19 +02:00
|
|
|
TEST_EQUAL(file_priorities[0], 4);
|
|
|
|
TEST_EQUAL(file_priorities[1], 4);
|
|
|
|
TEST_EQUAL(file_priorities[2], 4);
|
2015-07-14 04:19:55 +02:00
|
|
|
}
|
|
|
|
|
2017-07-09 18:07:28 +02:00
|
|
|
// As long as the add_torrent_params priorities are empty, the file_priorities
|
|
|
|
// from the resume data should take effect
|
|
|
|
TORRENT_TEST(file_priorities_in_resume)
|
|
|
|
{
|
|
|
|
lt::session ses(settings());
|
|
|
|
std::vector<int> file_priorities = test_resume_flags(ses, 0, "", "123").file_priorities();
|
|
|
|
|
|
|
|
TEST_EQUAL(file_priorities.size(), 3);
|
|
|
|
TEST_EQUAL(file_priorities[0], 1);
|
|
|
|
TEST_EQUAL(file_priorities[1], 2);
|
|
|
|
TEST_EQUAL(file_priorities[2], 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if both resume data and add_torrent_params has file_priorities, the
|
|
|
|
// add_torrent_params one take precedence
|
|
|
|
TORRENT_TEST(file_priorities_in_resume_and_params)
|
|
|
|
{
|
|
|
|
lt::session ses(settings());
|
|
|
|
std::vector<int> file_priorities = test_resume_flags(ses, 0, "456", "123").file_priorities();
|
|
|
|
|
|
|
|
TEST_EQUAL(file_priorities.size(), 3);
|
|
|
|
TEST_EQUAL(file_priorities[0], 4);
|
|
|
|
TEST_EQUAL(file_priorities[1], 5);
|
|
|
|
TEST_EQUAL(file_priorities[2], 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we set flag_override_resume_data, it should no affect file priorities
|
|
|
|
TORRENT_TEST(file_priorities_override_resume)
|
|
|
|
{
|
|
|
|
lt::session ses(settings());
|
|
|
|
std::vector<int> file_priorities = test_resume_flags(ses
|
|
|
|
, add_torrent_params::flag_override_resume_data, "", "123").file_priorities();
|
|
|
|
|
|
|
|
TEST_EQUAL(file_priorities.size(), 3);
|
|
|
|
TEST_EQUAL(file_priorities[0], 1);
|
|
|
|
TEST_EQUAL(file_priorities[1], 2);
|
|
|
|
TEST_EQUAL(file_priorities[2], 3);
|
|
|
|
}
|
|
|
|
|
2015-07-14 04:19:55 +02:00
|
|
|
TORRENT_TEST(file_priorities_resume_seed_mode)
|
|
|
|
{
|
|
|
|
// in share mode file priorities should always be 0
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-14 04:19:55 +02:00
|
|
|
std::vector<int> file_priorities = test_resume_flags(ses,
|
|
|
|
add_torrent_params::flag_share_mode, "", "123").file_priorities();
|
|
|
|
|
|
|
|
TEST_EQUAL(file_priorities.size(), 3);
|
|
|
|
TEST_EQUAL(file_priorities[0], 0);
|
|
|
|
TEST_EQUAL(file_priorities[1], 0);
|
|
|
|
TEST_EQUAL(file_priorities[2], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(file_priorities_seed_mode)
|
|
|
|
{
|
|
|
|
// in share mode file priorities should always be 0
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-14 04:19:55 +02:00
|
|
|
std::vector<int> file_priorities = test_resume_flags(ses,
|
|
|
|
add_torrent_params::flag_share_mode, "123", "").file_priorities();
|
|
|
|
|
|
|
|
TEST_EQUAL(file_priorities.size(), 3);
|
|
|
|
TEST_EQUAL(file_priorities[0], 0);
|
|
|
|
TEST_EQUAL(file_priorities[1], 0);
|
|
|
|
TEST_EQUAL(file_priorities[2], 0);
|
|
|
|
}
|
|
|
|
|
2015-08-06 02:13:58 +02:00
|
|
|
TORRENT_TEST(zero_file_prio)
|
|
|
|
{
|
2018-07-29 10:33:09 +02:00
|
|
|
lt::session ses(settings());
|
|
|
|
boost::shared_ptr<torrent_info> ti = generate_torrent();
|
|
|
|
add_torrent_params p;
|
|
|
|
p.ti = ti;
|
|
|
|
p.save_path = ".";
|
|
|
|
|
|
|
|
entry rd;
|
|
|
|
|
|
|
|
rd["file-format"] = "libtorrent resume file";
|
|
|
|
rd["file-version"] = 1;
|
|
|
|
rd["info-hash"] = ti->info_hash().to_string();
|
|
|
|
rd["blocks per piece"] = (std::max)(1, ti->piece_length() / 0x4000);
|
2015-08-06 02:13:58 +02:00
|
|
|
|
2018-07-29 10:33:09 +02:00
|
|
|
// set file priorities to 0
|
|
|
|
rd["file_priority"] = entry::list_type(100, entry(0));
|
|
|
|
|
|
|
|
rd["pieces"] = std::string(ti->num_pieces(), '\x01');
|
|
|
|
|
|
|
|
bencode(back_inserter(p.resume_data), rd);
|
|
|
|
|
|
|
|
torrent_handle h = ses.add_torrent(p);
|
|
|
|
|
|
|
|
torrent_status s = h.status();
|
|
|
|
TEST_EQUAL(s.total_wanted, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(mixing_file_and_piece_prio)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-08-06 02:13:58 +02:00
|
|
|
boost::shared_ptr<torrent_info> ti = generate_torrent();
|
|
|
|
add_torrent_params p;
|
|
|
|
p.ti = ti;
|
|
|
|
p.save_path = ".";
|
|
|
|
|
|
|
|
entry rd;
|
|
|
|
|
|
|
|
rd["file-format"] = "libtorrent resume file";
|
|
|
|
rd["file-version"] = 1;
|
|
|
|
rd["info-hash"] = ti->info_hash().to_string();
|
|
|
|
rd["blocks per piece"] = (std::max)(1, ti->piece_length() / 0x4000);
|
|
|
|
|
2018-07-29 10:33:09 +02:00
|
|
|
// set file priorities to 0
|
|
|
|
rd["file_priority"] = entry::list_type(100, entry(0));
|
2015-08-06 02:13:58 +02:00
|
|
|
|
2018-07-29 10:33:09 +02:00
|
|
|
rd["pieces"] = std::string(ti->num_pieces(), '\x01');
|
2015-08-06 02:13:58 +02:00
|
|
|
|
2018-07-29 10:33:09 +02:00
|
|
|
// but set the piece priorities to 1. these take precedence
|
|
|
|
rd["piece_priority"] = std::string(ti->num_pieces(), '\x01');
|
2015-08-06 02:13:58 +02:00
|
|
|
|
|
|
|
bencode(back_inserter(p.resume_data), rd);
|
|
|
|
|
|
|
|
torrent_handle h = ses.add_torrent(p);
|
|
|
|
|
|
|
|
torrent_status s = h.status();
|
2018-07-29 10:33:09 +02:00
|
|
|
TEST_EQUAL(s.total_wanted, ti->total_size());
|
2015-08-06 02:13:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_seed_mode(bool file_prio, bool pieces_have, bool piece_prio
|
|
|
|
, bool all_files_zero = false)
|
2015-07-27 09:01:19 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr, "test_seed_mode file_prio: %d pieces_have: %d piece_prio: %d\n"
|
|
|
|
, file_prio, pieces_have, piece_prio);
|
|
|
|
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-27 09:01:19 +02:00
|
|
|
boost::shared_ptr<torrent_info> ti = generate_torrent();
|
|
|
|
add_torrent_params p;
|
|
|
|
p.ti = ti;
|
|
|
|
p.save_path = ".";
|
|
|
|
|
|
|
|
entry rd;
|
|
|
|
|
|
|
|
rd["file-format"] = "libtorrent resume file";
|
|
|
|
rd["file-version"] = 1;
|
|
|
|
rd["info-hash"] = ti->info_hash().to_string();
|
|
|
|
rd["blocks per piece"] = (std::max)(1, ti->piece_length() / 0x4000);
|
|
|
|
|
|
|
|
if (file_prio)
|
|
|
|
{
|
|
|
|
// this should take it out of seed_mode
|
|
|
|
entry::list_type& file_prio = rd["file_priority"].list();
|
|
|
|
file_prio.push_back(entry(0));
|
2015-08-06 02:13:58 +02:00
|
|
|
if (all_files_zero)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 100; ++i)
|
|
|
|
{
|
|
|
|
file_prio.push_back(entry(0));
|
|
|
|
}
|
|
|
|
}
|
2015-07-27 09:01:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string pieces(ti->num_pieces(), '\x01');
|
|
|
|
if (pieces_have)
|
|
|
|
{
|
|
|
|
pieces[0] = '\0';
|
|
|
|
}
|
|
|
|
rd["pieces"] = pieces;
|
|
|
|
|
|
|
|
std::string pieces_prio(ti->num_pieces(), '\x01');
|
|
|
|
if (piece_prio)
|
|
|
|
{
|
|
|
|
pieces_prio[0] = '\0';
|
|
|
|
}
|
|
|
|
rd["piece_priority"] = pieces_prio;
|
|
|
|
|
|
|
|
rd["seed_mode"] = 1;
|
|
|
|
|
|
|
|
bencode(back_inserter(p.resume_data), rd);
|
|
|
|
|
|
|
|
torrent_handle h = ses.add_torrent(p);
|
|
|
|
|
|
|
|
torrent_status s = h.status();
|
|
|
|
if (file_prio || piece_prio || pieces_have)
|
|
|
|
{
|
|
|
|
TEST_EQUAL(s.seed_mode, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TEST_EQUAL(s.seed_mode, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(seed_mode_file_prio)
|
|
|
|
{
|
|
|
|
test_seed_mode(true, false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(seed_mode_piece_prio)
|
|
|
|
{
|
|
|
|
test_seed_mode(false, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(seed_mode_piece_have)
|
|
|
|
{
|
|
|
|
test_seed_mode(false, false, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(seed_mode_preserve)
|
|
|
|
{
|
|
|
|
test_seed_mode(false, false, false);
|
|
|
|
}
|
|
|
|
|
2017-11-28 22:59:46 +01:00
|
|
|
TORRENT_TEST(seed_mode_load_peers)
|
|
|
|
{
|
|
|
|
lt::session ses(settings());
|
|
|
|
boost::shared_ptr<torrent_info> ti = generate_torrent();
|
|
|
|
add_torrent_params p;
|
|
|
|
p.ti = ti;
|
|
|
|
p.save_path = ".";
|
|
|
|
|
|
|
|
entry rd;
|
|
|
|
|
|
|
|
rd["file-format"] = "libtorrent resume file";
|
|
|
|
rd["file-version"] = 1;
|
|
|
|
rd["info-hash"] = ti->info_hash().to_string();
|
|
|
|
rd["blocks per piece"] = std::max(1, ti->piece_length() / 0x4000);
|
|
|
|
|
|
|
|
rd["pieces"] = std::string(ti->num_pieces(), '\x01');
|
|
|
|
rd["piece_priority"] = std::string(ti->num_pieces(), '\x01');
|
|
|
|
rd["seed_mode"] = 1;
|
|
|
|
rd["peers"] = "\x01\x02\x03\x04\x30\x39";
|
|
|
|
|
|
|
|
bencode(back_inserter(p.resume_data), rd);
|
|
|
|
|
|
|
|
torrent_handle h = ses.add_torrent(p);
|
|
|
|
|
|
|
|
wait_for_alert(ses, torrent_checked_alert::alert_type, "seed_mode_load_peers");
|
|
|
|
|
|
|
|
std::vector<peer_list_entry> peers;
|
|
|
|
h.get_full_peer_list(peers);
|
|
|
|
|
|
|
|
TEST_EQUAL(peers.size(), 1);
|
|
|
|
TEST_CHECK(peers[0].ip == tcp::endpoint(address::from_string("1.2.3.4"), 12345));
|
|
|
|
}
|
|
|
|
|
2015-07-14 04:19:55 +02:00
|
|
|
TORRENT_TEST(resume_save_load)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-14 04:19:55 +02:00
|
|
|
torrent_handle h = test_resume_flags(ses, 0, "123", "");
|
|
|
|
|
|
|
|
h.save_resume_data();
|
|
|
|
|
|
|
|
save_resume_data_alert const* a = alert_cast<save_resume_data_alert>(
|
|
|
|
wait_for_alert(ses, save_resume_data_alert::alert_type
|
|
|
|
, "resume_save_load"));
|
|
|
|
|
|
|
|
TEST_CHECK(a);
|
|
|
|
if (a == NULL) return;
|
|
|
|
|
|
|
|
TEST_CHECK(a->resume_data);
|
|
|
|
|
|
|
|
entry& e = *a->resume_data.get();
|
|
|
|
entry::list_type& l = e["file_priority"].list();
|
|
|
|
entry::list_type::iterator i = l.begin();
|
|
|
|
|
|
|
|
TEST_EQUAL(l.size(), 3);
|
|
|
|
TEST_EQUAL(*i++, 1);
|
|
|
|
TEST_EQUAL(*i++, 2);
|
|
|
|
TEST_EQUAL(*i++, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(resume_save_load_resume)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-14 04:19:55 +02:00
|
|
|
torrent_handle h = test_resume_flags(ses, 0, "", "123");
|
|
|
|
|
|
|
|
h.save_resume_data();
|
|
|
|
|
|
|
|
save_resume_data_alert const* a = alert_cast<save_resume_data_alert>(
|
|
|
|
wait_for_alert(ses, save_resume_data_alert::alert_type
|
|
|
|
, "resume_save_load"));
|
|
|
|
|
|
|
|
TEST_CHECK(a);
|
|
|
|
if (a == NULL) return;
|
|
|
|
|
|
|
|
TEST_CHECK(a->resume_data);
|
|
|
|
|
|
|
|
entry& e = *a->resume_data.get();
|
|
|
|
entry::list_type& l = e["file_priority"].list();
|
|
|
|
entry::list_type::iterator i = l.begin();
|
|
|
|
|
|
|
|
TEST_EQUAL(l.size(), 3);
|
|
|
|
TEST_EQUAL(*i++, 1);
|
|
|
|
TEST_EQUAL(*i++, 2);
|
|
|
|
TEST_EQUAL(*i++, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(file_priorities_resume_override)
|
|
|
|
{
|
|
|
|
// make sure that an empty file_priorities vector in add_torrent_params won't
|
|
|
|
// override the resume data file priorities, even when override resume data
|
|
|
|
// flag is set.
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-14 04:19:55 +02:00
|
|
|
std::vector<int> file_priorities = test_resume_flags(ses,
|
|
|
|
add_torrent_params::flag_override_resume_data, "", "123").file_priorities();
|
|
|
|
|
|
|
|
TEST_EQUAL(file_priorities.size(), 3);
|
|
|
|
TEST_EQUAL(file_priorities[0], 1);
|
|
|
|
TEST_EQUAL(file_priorities[1], 2);
|
|
|
|
TEST_EQUAL(file_priorities[2], 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(file_priorities_resume)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-14 04:19:55 +02:00
|
|
|
std::vector<int> file_priorities = test_resume_flags(ses, 0, "", "123").file_priorities();
|
|
|
|
|
|
|
|
TEST_EQUAL(file_priorities.size(), 3);
|
|
|
|
TEST_EQUAL(file_priorities[0], 1);
|
|
|
|
TEST_EQUAL(file_priorities[1], 2);
|
|
|
|
TEST_EQUAL(file_priorities[2], 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(file_priorities1)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-14 04:19:55 +02:00
|
|
|
std::vector<int> file_priorities = test_resume_flags(ses, 0, "010").file_priorities();
|
|
|
|
|
|
|
|
TEST_EQUAL(file_priorities.size(), 3);
|
|
|
|
TEST_EQUAL(file_priorities[0], 0);
|
|
|
|
TEST_EQUAL(file_priorities[1], 1);
|
|
|
|
TEST_EQUAL(file_priorities[2], 0);
|
|
|
|
|
|
|
|
//#error save resume data and assert the file priorities are preserved
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(file_priorities2)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-14 04:19:55 +02:00
|
|
|
std::vector<int> file_priorities = test_resume_flags(ses, 0, "123").file_priorities();
|
|
|
|
|
|
|
|
TEST_EQUAL(file_priorities.size(), 3);
|
|
|
|
TEST_EQUAL(file_priorities[0], 1);
|
|
|
|
TEST_EQUAL(file_priorities[1], 2);
|
|
|
|
TEST_EQUAL(file_priorities[2], 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(file_priorities3)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-14 04:19:55 +02:00
|
|
|
std::vector<int> file_priorities = test_resume_flags(ses, 0, "4321").file_priorities();
|
|
|
|
|
|
|
|
TEST_EQUAL(file_priorities.size(), 3);
|
|
|
|
TEST_EQUAL(file_priorities[0], 4);
|
|
|
|
TEST_EQUAL(file_priorities[1], 3);
|
|
|
|
TEST_EQUAL(file_priorities[2], 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(plain)
|
2014-11-08 17:58:18 +01:00
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2014-11-08 17:58:18 +01:00
|
|
|
|
2015-07-14 04:19:55 +02:00
|
|
|
torrent_status s = test_resume_flags(ses, 0).status();
|
2014-11-08 17:58:18 +01:00
|
|
|
default_tests(s);
|
2014-11-19 10:23:08 +01:00
|
|
|
#ifdef TORRENT_WINDOWS
|
|
|
|
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
|
|
|
#else
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
2014-11-19 10:23:08 +01:00
|
|
|
#endif
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.sequential_download, false);
|
|
|
|
TEST_EQUAL(s.paused, false);
|
|
|
|
TEST_EQUAL(s.auto_managed, false);
|
|
|
|
TEST_EQUAL(s.seed_mode, false);
|
|
|
|
TEST_EQUAL(s.super_seeding, false);
|
|
|
|
TEST_EQUAL(s.share_mode, false);
|
|
|
|
TEST_EQUAL(s.upload_mode, false);
|
|
|
|
TEST_EQUAL(s.ip_filter_applies, false);
|
|
|
|
TEST_EQUAL(s.connections_limit, 1345);
|
|
|
|
TEST_EQUAL(s.uploads_limit, 1346);
|
2015-07-14 04:19:55 +02:00
|
|
|
}
|
2014-11-08 17:58:18 +01:00
|
|
|
|
2015-07-14 04:19:55 +02:00
|
|
|
TORRENT_TEST(use_resume_save_path)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-14 04:19:55 +02:00
|
|
|
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_use_resume_save_path).status();
|
2014-11-08 17:58:18 +01:00
|
|
|
default_tests(s);
|
2014-11-19 10:23:08 +01:00
|
|
|
#ifdef TORRENT_WINDOWS
|
|
|
|
TEST_EQUAL(s.save_path, "c:\\resume_data save_path");
|
|
|
|
#else
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.save_path, "/resume_data save_path");
|
2014-11-19 10:23:08 +01:00
|
|
|
#endif
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.sequential_download, false);
|
|
|
|
TEST_EQUAL(s.paused, false);
|
|
|
|
TEST_EQUAL(s.auto_managed, false);
|
|
|
|
TEST_EQUAL(s.seed_mode, false);
|
|
|
|
TEST_EQUAL(s.super_seeding, false);
|
|
|
|
TEST_EQUAL(s.share_mode, false);
|
|
|
|
TEST_EQUAL(s.upload_mode, false);
|
|
|
|
TEST_EQUAL(s.ip_filter_applies, false);
|
|
|
|
TEST_EQUAL(s.connections_limit, 1345);
|
|
|
|
TEST_EQUAL(s.uploads_limit, 1346);
|
2015-07-14 04:19:55 +02:00
|
|
|
}
|
2014-11-08 17:58:18 +01:00
|
|
|
|
2015-07-14 04:19:55 +02:00
|
|
|
TORRENT_TEST(override_resume_data)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-14 04:19:55 +02:00
|
|
|
torrent_status s = test_resume_flags(ses
|
|
|
|
, add_torrent_params::flag_override_resume_data
|
|
|
|
| add_torrent_params::flag_paused).status();
|
2014-11-08 17:58:18 +01:00
|
|
|
|
|
|
|
default_tests(s);
|
2014-11-19 10:23:08 +01:00
|
|
|
#ifdef TORRENT_WINDOWS
|
|
|
|
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
|
|
|
#else
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
2014-11-19 10:23:08 +01:00
|
|
|
#endif
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.sequential_download, false);
|
|
|
|
TEST_EQUAL(s.paused, true);
|
|
|
|
TEST_EQUAL(s.auto_managed, false);
|
|
|
|
TEST_EQUAL(s.seed_mode, false);
|
|
|
|
TEST_EQUAL(s.super_seeding, false);
|
|
|
|
TEST_EQUAL(s.share_mode, false);
|
|
|
|
TEST_EQUAL(s.upload_mode, false);
|
|
|
|
TEST_EQUAL(s.ip_filter_applies, false);
|
|
|
|
TEST_EQUAL(s.connections_limit, 2);
|
|
|
|
TEST_EQUAL(s.uploads_limit, 1);
|
2015-07-14 04:19:55 +02:00
|
|
|
}
|
2014-11-08 17:58:18 +01:00
|
|
|
|
2015-07-14 04:19:55 +02:00
|
|
|
TORRENT_TEST(seed_mode)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-14 04:19:55 +02:00
|
|
|
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_override_resume_data
|
|
|
|
| add_torrent_params::flag_seed_mode).status();
|
2014-11-08 17:58:18 +01:00
|
|
|
default_tests(s);
|
2014-11-19 10:23:08 +01:00
|
|
|
#ifdef TORRENT_WINDOWS
|
|
|
|
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
|
|
|
#else
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
2014-11-19 10:23:08 +01:00
|
|
|
#endif
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.sequential_download, false);
|
|
|
|
TEST_EQUAL(s.paused, false);
|
|
|
|
TEST_EQUAL(s.auto_managed, false);
|
|
|
|
TEST_EQUAL(s.seed_mode, true);
|
|
|
|
TEST_EQUAL(s.super_seeding, false);
|
|
|
|
TEST_EQUAL(s.share_mode, false);
|
|
|
|
TEST_EQUAL(s.upload_mode, false);
|
|
|
|
TEST_EQUAL(s.ip_filter_applies, false);
|
|
|
|
TEST_EQUAL(s.connections_limit, 2);
|
|
|
|
TEST_EQUAL(s.uploads_limit, 1);
|
2015-07-14 04:19:55 +02:00
|
|
|
}
|
2014-11-08 17:58:18 +01:00
|
|
|
|
2015-07-14 04:19:55 +02:00
|
|
|
TORRENT_TEST(upload_mode)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-14 04:19:55 +02:00
|
|
|
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_upload_mode).status();
|
2014-11-08 17:58:18 +01:00
|
|
|
default_tests(s);
|
2014-11-19 10:23:08 +01:00
|
|
|
#ifdef TORRENT_WINDOWS
|
|
|
|
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
|
|
|
#else
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
2014-11-19 10:23:08 +01:00
|
|
|
#endif
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.sequential_download, false);
|
|
|
|
TEST_EQUAL(s.paused, false);
|
|
|
|
TEST_EQUAL(s.auto_managed, false);
|
|
|
|
TEST_EQUAL(s.seed_mode, false);
|
|
|
|
TEST_EQUAL(s.super_seeding, false);
|
|
|
|
TEST_EQUAL(s.share_mode, false);
|
|
|
|
TEST_EQUAL(s.upload_mode, true);
|
|
|
|
TEST_EQUAL(s.ip_filter_applies, false);
|
|
|
|
TEST_EQUAL(s.connections_limit, 1345);
|
|
|
|
TEST_EQUAL(s.uploads_limit, 1346);
|
2015-07-14 04:19:55 +02:00
|
|
|
}
|
2014-11-08 17:58:18 +01:00
|
|
|
|
2015-07-14 04:19:55 +02:00
|
|
|
TORRENT_TEST(share_mode)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-07-14 04:19:55 +02:00
|
|
|
torrent_status s = test_resume_flags(ses
|
|
|
|
, add_torrent_params::flag_override_resume_data
|
|
|
|
| add_torrent_params::flag_share_mode).status();
|
2014-11-08 17:58:18 +01:00
|
|
|
default_tests(s);
|
2014-11-19 10:23:08 +01:00
|
|
|
#ifdef TORRENT_WINDOWS
|
|
|
|
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
|
|
|
#else
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
2014-11-19 10:23:08 +01:00
|
|
|
#endif
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.sequential_download, false);
|
|
|
|
TEST_EQUAL(s.paused, false);
|
|
|
|
TEST_EQUAL(s.auto_managed, false);
|
|
|
|
TEST_EQUAL(s.seed_mode, false);
|
|
|
|
TEST_EQUAL(s.super_seeding, false);
|
|
|
|
TEST_EQUAL(s.share_mode, true);
|
|
|
|
TEST_EQUAL(s.upload_mode, false);
|
|
|
|
TEST_EQUAL(s.ip_filter_applies, false);
|
|
|
|
TEST_EQUAL(s.connections_limit, 2);
|
|
|
|
TEST_EQUAL(s.uploads_limit, 1);
|
2015-07-14 04:19:55 +02:00
|
|
|
}
|
2014-11-08 17:58:18 +01:00
|
|
|
|
2015-07-14 04:19:55 +02:00
|
|
|
TORRENT_TEST(auto_managed)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2014-11-08 17:58:18 +01:00
|
|
|
// resume data overrides the auto-managed flag
|
2015-07-14 04:19:55 +02:00
|
|
|
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_auto_managed).status();
|
2014-11-08 17:58:18 +01:00
|
|
|
default_tests(s);
|
2014-11-19 10:23:08 +01:00
|
|
|
#ifdef TORRENT_WINDOWS
|
|
|
|
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
|
|
|
#else
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
2014-11-19 10:23:08 +01:00
|
|
|
#endif
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.sequential_download, false);
|
|
|
|
TEST_EQUAL(s.paused, false);
|
|
|
|
TEST_EQUAL(s.auto_managed, false);
|
|
|
|
TEST_EQUAL(s.seed_mode, false);
|
|
|
|
TEST_EQUAL(s.super_seeding, false);
|
|
|
|
TEST_EQUAL(s.share_mode, false);
|
|
|
|
TEST_EQUAL(s.upload_mode, false);
|
|
|
|
TEST_EQUAL(s.ip_filter_applies, false);
|
|
|
|
TEST_EQUAL(s.connections_limit, 1345);
|
|
|
|
TEST_EQUAL(s.uploads_limit, 1346);
|
2015-07-14 04:19:55 +02:00
|
|
|
}
|
2014-11-08 17:58:18 +01:00
|
|
|
|
2015-07-14 04:19:55 +02:00
|
|
|
TORRENT_TEST(paused)
|
|
|
|
{
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2014-11-08 17:58:18 +01:00
|
|
|
// resume data overrides the paused flag
|
2015-07-14 04:19:55 +02:00
|
|
|
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_paused).status();
|
2014-11-08 17:58:18 +01:00
|
|
|
default_tests(s);
|
2014-11-19 10:23:08 +01:00
|
|
|
#ifdef TORRENT_WINDOWS
|
|
|
|
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
|
|
|
#else
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
2014-11-19 10:23:08 +01:00
|
|
|
#endif
|
2014-11-08 17:58:18 +01:00
|
|
|
TEST_EQUAL(s.sequential_download, false);
|
|
|
|
TEST_EQUAL(s.paused, false);
|
|
|
|
TEST_EQUAL(s.auto_managed, false);
|
|
|
|
TEST_EQUAL(s.seed_mode, false);
|
|
|
|
TEST_EQUAL(s.super_seeding, false);
|
|
|
|
TEST_EQUAL(s.share_mode, false);
|
|
|
|
TEST_EQUAL(s.upload_mode, false);
|
|
|
|
TEST_EQUAL(s.ip_filter_applies, false);
|
|
|
|
TEST_EQUAL(s.connections_limit, 1345);
|
|
|
|
TEST_EQUAL(s.uploads_limit, 1346);
|
|
|
|
|
2015-01-15 20:13:45 +01:00
|
|
|
// TODO: test all other resume flags here too. This would require returning
|
2014-11-08 17:58:18 +01:00
|
|
|
// more than just the torrent_status from test_resume_flags. Also http seeds
|
|
|
|
// and trackers for instance
|
|
|
|
}
|
|
|
|
|
2015-09-29 07:51:01 +02:00
|
|
|
TORRENT_TEST(url_seed_resume_data)
|
|
|
|
{
|
|
|
|
// merge url seeds with resume data
|
|
|
|
fprintf(stderr, "flags: merge_resume_http_seeds\n");
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-09-29 07:51:01 +02:00
|
|
|
torrent_handle h = test_resume_flags(ses,
|
|
|
|
add_torrent_params::flag_merge_resume_http_seeds);
|
|
|
|
std::set<std::string> us = h.url_seeds();
|
|
|
|
std::set<std::string> ws = h.http_seeds();
|
|
|
|
|
|
|
|
TEST_EQUAL(us.size(), 3);
|
|
|
|
TEST_EQUAL(std::count(us.begin(), us.end()
|
|
|
|
, "http://add_torrent_params_url_seed.com"), 1);
|
|
|
|
TEST_EQUAL(std::count(us.begin(), us.end()
|
|
|
|
, "http://torrent_file_url_seed.com/"), 1);
|
|
|
|
TEST_EQUAL(std::count(us.begin(), us.end()
|
|
|
|
, "http://resume_data_url_seed.com/"), 1);
|
|
|
|
|
|
|
|
TEST_EQUAL(ws.size(), 1);
|
|
|
|
TEST_EQUAL(std::count(ws.begin(), ws.end()
|
|
|
|
, "http://resume_data_http_seed.com"), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_TEST(resume_override_torrent)
|
|
|
|
{
|
|
|
|
// resume data overrides the .torrent_file
|
|
|
|
fprintf(stderr, "flags: no merge_resume_http_seed\n");
|
2016-08-21 18:15:19 +02:00
|
|
|
lt::session ses(settings());
|
2015-09-29 07:51:01 +02:00
|
|
|
torrent_handle h = test_resume_flags(ses,
|
|
|
|
add_torrent_params::flag_merge_resume_trackers);
|
|
|
|
std::set<std::string> us = h.url_seeds();
|
|
|
|
std::set<std::string> ws = h.http_seeds();
|
|
|
|
|
|
|
|
TEST_EQUAL(ws.size(), 1);
|
|
|
|
TEST_EQUAL(std::count(ws.begin(), ws.end()
|
|
|
|
, "http://resume_data_http_seed.com"), 1);
|
|
|
|
|
|
|
|
TEST_EQUAL(us.size(), 1);
|
|
|
|
TEST_EQUAL(std::count(us.begin(), us.end()
|
|
|
|
, "http://resume_data_url_seed.com/"), 1);
|
|
|
|
}
|
2014-11-08 17:58:18 +01:00
|
|
|
|