forked from premiere/premiere-libtorrent
make tests pass
This commit is contained in:
parent
b496eff206
commit
c9d7e54d7b
|
@ -1559,10 +1559,12 @@ namespace libtorrent
|
|||
// torrent or not. Defaults to true.
|
||||
bool m_apply_ip_filter:1;
|
||||
|
||||
// if set to true, add tracker URLs loaded from resume
|
||||
// data into this torrent instead of replacing them
|
||||
bool m_merge_resume_trackers:1;
|
||||
|
||||
// this is true when our effective inactive state is different from our
|
||||
// actual inactive state. Whenever this state changes, there is a
|
||||
// quarantine period until we change the effective state. This is to avoid
|
||||
// flapping. If the state changes back during this period, we cancel the
|
||||
// quarantine
|
||||
bool m_pending_active_change:1;
|
||||
// ----
|
||||
|
||||
// the number of bytes of padding files
|
||||
|
@ -1676,13 +1678,6 @@ namespace libtorrent
|
|||
// progress parts per million (the number of
|
||||
// millionths of completeness)
|
||||
unsigned int m_progress_ppm:20;
|
||||
|
||||
// this is true when our effective inactive state is different from our
|
||||
// actual inactive state. Whenever this state changes, there is a
|
||||
// quarantine period until we change the effective state. This is to avoid
|
||||
// flapping. If the state changes back during this period, we cancel the
|
||||
// quarantine
|
||||
bool m_pending_active_change:1;
|
||||
};
|
||||
|
||||
struct torrent_ref_holder
|
||||
|
|
|
@ -657,9 +657,9 @@ TORRENT_TEST(stop_when_ready)
|
|||
});
|
||||
}
|
||||
|
||||
// This test makes sure that the fastresume check will still run, and
|
||||
// potentially fail, for stopped torrents. The actual checking of files won't
|
||||
// start until the torrent is un-paused/resumed though
|
||||
// This test makes sure that the fastresume check will still run for stopped
|
||||
// torrents. The actual checking of files won't start until the torrent is
|
||||
// un-paused/resumed though
|
||||
TORRENT_TEST(resume_reject_when_paused)
|
||||
{
|
||||
run_test(
|
||||
|
@ -672,13 +672,11 @@ TORRENT_TEST(resume_reject_when_paused)
|
|||
lt::add_torrent_params params = create_torrent(0, true);
|
||||
|
||||
// the torrent is not auto managed and paused. Once the resume data
|
||||
// check completes, it will stay paused but the resume_rejected_alert
|
||||
// will be posted
|
||||
// check completes, it will stay paused but the state_changed_alert
|
||||
// will be posted, when it goes to check the files
|
||||
params.flags &= ~add_torrent_params::flag_auto_managed;
|
||||
params.flags |= add_torrent_params::flag_paused;
|
||||
|
||||
// an empty dictionary will be rejected
|
||||
params.resume_data = {'d', 'e'};
|
||||
ses.async_add_torrent(params);
|
||||
},
|
||||
|
||||
|
@ -689,7 +687,7 @@ TORRENT_TEST(resume_reject_when_paused)
|
|||
lt::time_point start_time = alerts[0]->timestamp();
|
||||
|
||||
int num_piece_finished = 0;
|
||||
int resume_rejected = 0;
|
||||
int checking_files = 0;
|
||||
int state_changed = 0;
|
||||
|
||||
for (alert* a : alerts)
|
||||
|
@ -702,13 +700,11 @@ TORRENT_TEST(resume_reject_when_paused)
|
|||
if (alert_cast<piece_finished_alert>(a))
|
||||
++num_piece_finished;
|
||||
|
||||
if (alert_cast<fastresume_rejected_alert>(a))
|
||||
++resume_rejected;
|
||||
|
||||
if (auto sc = alert_cast<state_changed_alert>(a))
|
||||
{
|
||||
if (sc->state == torrent_status::checking_files)
|
||||
++state_changed;
|
||||
++checking_files;
|
||||
++state_changed;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -725,8 +721,12 @@ TORRENT_TEST(resume_reject_when_paused)
|
|||
}
|
||||
|
||||
TEST_EQUAL(num_piece_finished, 0);
|
||||
TEST_EQUAL(resume_rejected, 1);
|
||||
// it should not actually check the files (since it's paused)
|
||||
// if the files were checked, the state would change to downloading
|
||||
// immediately, and state_changed would be 2. This asserts that's not
|
||||
// the case.
|
||||
TEST_EQUAL(state_changed, 1);
|
||||
TEST_EQUAL(checking_files, 1);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace libtorrent
|
|||
, char const* name
|
||||
, boost::uint64_t const flag)
|
||||
{
|
||||
if (n.dict_find_int_value(name, -1) == -1)
|
||||
if (n.dict_find_int_value(name, 0) == 0)
|
||||
{
|
||||
current_flags &= ~flag;
|
||||
}
|
||||
|
|
|
@ -194,19 +194,25 @@ namespace libtorrent
|
|||
|
||||
if (!resume_data.url_seeds.empty())
|
||||
{
|
||||
if ((atp.flags & add_torrent_params::flag_merge_resume_http_seeds) == 0)
|
||||
atp.url_seeds.clear();
|
||||
|
||||
atp.url_seeds.insert(atp.url_seeds.end()
|
||||
, resume_data.url_seeds.begin()
|
||||
, resume_data.url_seeds.end());
|
||||
if ((resume_data.flags & add_torrent_params::flag_merge_resume_http_seeds) == 0)
|
||||
if ((atp.flags & add_torrent_params::flag_merge_resume_http_seeds) == 0)
|
||||
atp.flags |= add_torrent_params::flag_override_web_seeds;
|
||||
}
|
||||
|
||||
if (!resume_data.http_seeds.empty())
|
||||
{
|
||||
if ((atp.flags & add_torrent_params::flag_merge_resume_http_seeds) == 0)
|
||||
atp.http_seeds.clear();
|
||||
|
||||
atp.http_seeds.insert(atp.http_seeds.end()
|
||||
, resume_data.http_seeds.begin()
|
||||
, resume_data.http_seeds.end());
|
||||
if ((resume_data.flags & add_torrent_params::flag_merge_resume_http_seeds) == 0)
|
||||
if ((atp.flags & add_torrent_params::flag_merge_resume_http_seeds) == 0)
|
||||
atp.flags |= add_torrent_params::flag_override_web_seeds;
|
||||
}
|
||||
|
||||
|
@ -248,7 +254,8 @@ namespace libtorrent
|
|||
atp.max_connections = resume_data.max_connections;
|
||||
atp.max_uploads = resume_data.max_uploads;
|
||||
atp.trackerid = resume_data.trackerid;
|
||||
atp.file_priorities = resume_data.file_priorities;
|
||||
if (!resume_data.file_priorities.empty())
|
||||
atp.file_priorities = resume_data.file_priorities;
|
||||
|
||||
boost::uint64_t const mask =
|
||||
add_torrent_params::flag_seed_mode
|
||||
|
@ -260,6 +267,11 @@ namespace libtorrent
|
|||
atp.flags &= ~mask;
|
||||
atp.flags |= resume_data.flags & mask;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (atp.file_priorities.empty())
|
||||
atp.file_priorities = resume_data.file_priorities;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -4676,8 +4676,9 @@ namespace aux {
|
|||
|
||||
// we don't have a torrent file. If the user provided
|
||||
// resume data, there may be some metadata in there
|
||||
// TODO: this logic could probably be less spaghetti looking by being
|
||||
// moved to a function with early exits
|
||||
// TODO: 4 the logic of loading the .torrent file from the resume data
|
||||
// should be moved into read_resume_data()
|
||||
/*
|
||||
if ((!params.ti || !params.ti->is_valid())
|
||||
&& !params.resume_data.empty())
|
||||
{
|
||||
|
@ -4745,6 +4746,7 @@ namespace aux {
|
|||
}
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
// is the torrent already active?
|
||||
boost::shared_ptr<torrent> torrent_ptr = find_torrent(*ih).lock();
|
||||
|
|
|
@ -872,7 +872,7 @@ namespace libtorrent
|
|||
std::vector<file_slice> f = fs.map_block(i, 0, 1);
|
||||
TORRENT_ASSERT(!f.empty());
|
||||
|
||||
const int file_index = f[0].file_index;
|
||||
int const file_index = f[0].file_index;
|
||||
error_code error;
|
||||
boost::int64_t const size = m_stat_cache.get_filesize(f[0].file_index
|
||||
, fs, m_save_path, error);
|
||||
|
@ -895,7 +895,7 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
if (seed && size != fs.file_size(i))
|
||||
if (seed && size != fs.file_size(file_index))
|
||||
{
|
||||
// the resume data indicates we're a seed, but this file has
|
||||
// the wrong size. Reject the resume data
|
||||
|
|
|
@ -254,7 +254,7 @@ namespace libtorrent
|
|||
, m_lsd_seq(0)
|
||||
, m_magnet_link(false)
|
||||
, m_apply_ip_filter((p.flags & add_torrent_params::flag_apply_ip_filter) != 0)
|
||||
, m_merge_resume_trackers((p.flags & add_torrent_params::flag_merge_resume_trackers) != 0)
|
||||
, m_pending_active_change(false)
|
||||
, m_padding(0)
|
||||
, m_priority(0)
|
||||
, m_incomplete(0xffffff)
|
||||
|
@ -277,7 +277,6 @@ namespace libtorrent
|
|||
, m_downloaded(0xffffff)
|
||||
, m_last_scrape((std::numeric_limits<boost::int16_t>::min)())
|
||||
, m_progress_ppm(0)
|
||||
, m_pending_active_change(false)
|
||||
{
|
||||
// we cannot log in the constructor, because it relies on shared_from_this
|
||||
// being initialized, which happens after the constructor returns.
|
||||
|
@ -294,7 +293,7 @@ namespace libtorrent
|
|||
// if there is resume data already, we don't need to trigger the initial save
|
||||
// resume data
|
||||
//TODO: 4 maybe m_need_save_resume_data should be another flag in add_torrent_params
|
||||
if (!p.resume_data.empty() && (p.flags & add_torrent_params::flag_override_resume_data) == 0)
|
||||
if (!p.have_pieces.empty() /* && (p.flags & add_torrent_params::flag_override_resume_data) == 0 */ )
|
||||
m_need_save_resume_data = false;
|
||||
|
||||
#if TORRENT_USE_UNC_PATHS
|
||||
|
@ -401,7 +400,16 @@ namespace libtorrent
|
|||
|
||||
if (m_torrent_file->is_valid())
|
||||
{
|
||||
m_seed_mode = (p.flags & add_torrent_params::flag_seed_mode) != 0;
|
||||
// setting file- or piece priorities for seed mode makes no sense. If a
|
||||
// torrent ends up in seed mode by accident, it can be very confusing,
|
||||
// so assume the seed mode flag is not intended and don't enable it in
|
||||
// that case. Also, if the resume data says we're missing a piece, we
|
||||
// can't be in seed-mode.
|
||||
m_seed_mode = (p.flags & add_torrent_params::flag_seed_mode) != 0
|
||||
&& std::count(p.file_priorities.begin(), p.file_priorities.end(), 0) == 0
|
||||
&& std::count(p.piece_priorities.begin(), p.piece_priorities.end(), 0) == 0
|
||||
&& std::count(p.have_pieces.begin(), p.have_pieces.end(), 0) == 0;
|
||||
|
||||
m_connections_initialized = true;
|
||||
m_block_size_shift = root2((std::min)(block_size, m_torrent_file->piece_length()));
|
||||
}
|
||||
|
@ -1938,7 +1946,7 @@ namespace libtorrent
|
|||
|
||||
// if we've already loaded file priorities, don't load piece priorities,
|
||||
// they will interfere.
|
||||
if (!m_seed_mode && m_add_torrent_params && m_file_priority.empty())
|
||||
if (m_add_torrent_params && m_file_priority.empty())
|
||||
{
|
||||
for (int i = 0; i < int(m_add_torrent_params->piece_priorities.size()); ++i)
|
||||
{
|
||||
|
@ -2359,7 +2367,10 @@ namespace libtorrent
|
|||
}
|
||||
|
||||
// only report this error if the user actually provided resume data
|
||||
if ((j->error || j->ret != 0) && m_add_torrent_params
|
||||
// (i.e. m_add_torrent_params->have_pieces)
|
||||
if ((j->error || j->ret != 0)
|
||||
&& m_add_torrent_params
|
||||
&& !m_add_torrent_params->have_pieces.empty()
|
||||
&& m_ses.alerts().should_post<fastresume_rejected_alert>())
|
||||
{
|
||||
m_ses.alerts().emplace_alert<fastresume_rejected_alert>(get_handle()
|
||||
|
|
|
@ -72,7 +72,9 @@ struct test_storage_impl : storage_interface
|
|||
virtual void rename_file(int index, std::string const& new_filenamem
|
||||
, storage_error& ec) TORRENT_OVERRIDE {}
|
||||
virtual void delete_files(storage_error& ec) TORRENT_OVERRIDE {}
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
virtual void finalize_file(int, storage_error&) TORRENT_OVERRIDE {}
|
||||
#endif
|
||||
};
|
||||
|
||||
static void nop() {}
|
||||
|
@ -80,7 +82,7 @@ static void nop() {}
|
|||
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
|
||||
#define INITIALIZE_JOB(j) j.in_use = true;
|
||||
#else
|
||||
#define INITIALIZE_JOB(j)
|
||||
#define INITIALIZE_JOB(j)
|
||||
#endif
|
||||
|
||||
#define TEST_SETUP \
|
||||
|
|
|
@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/time.hpp"
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/read_resume_data.hpp"
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
|
@ -68,13 +69,13 @@ bool on_alert(alert const* a)
|
|||
void cleanup()
|
||||
{
|
||||
error_code ec;
|
||||
remove_all("tmp1_priorities", ec);
|
||||
remove_all("tmp2_priorities", ec);
|
||||
remove_all("tmp1_priorities_moved", ec);
|
||||
remove_all("tmp2_priorities_moved", ec);
|
||||
remove_all("tmp1_priority", ec);
|
||||
remove_all("tmp2_priority", ec);
|
||||
remove_all("tmp1_priority_moved", ec);
|
||||
remove_all("tmp2_priority_moved", ec);
|
||||
}
|
||||
|
||||
void test_transfer(settings_pack const& sett)
|
||||
void test_transfer(settings_pack const& sett, bool test_deprecated = false)
|
||||
{
|
||||
// this allows shutting down the sessions in parallel
|
||||
std::vector<session_proxy> sp;
|
||||
|
@ -285,11 +286,23 @@ done:
|
|||
|
||||
std::cout << "re-adding" << std::endl;
|
||||
add_torrent_params p;
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
if (test_deprecated)
|
||||
{
|
||||
p.resume_data = resume_data;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
error_code ec;
|
||||
p = read_resume_data(&resume_data[0], resume_data.size(), ec);
|
||||
TEST_CHECK(!ec);
|
||||
}
|
||||
p.flags &= ~add_torrent_params::flag_paused;
|
||||
p.flags &= ~add_torrent_params::flag_auto_managed;
|
||||
p.ti = t;
|
||||
p.save_path = "tmp2_priority";
|
||||
p.resume_data = resume_data;
|
||||
|
||||
tor2 = ses2.add_torrent(p, ec);
|
||||
tor2.prioritize_pieces(priorities);
|
||||
std::cout << "resetting priorities" << std::endl;
|
||||
|
@ -379,6 +392,16 @@ TORRENT_TEST(priority)
|
|||
cleanup();
|
||||
}
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
TORRENT_TEST(priority_deprecated)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
settings_pack p;
|
||||
test_transfer(p, true);
|
||||
cleanup();
|
||||
}
|
||||
#endif
|
||||
|
||||
// test to set piece and file priority on a torrent that doesn't have metadata
|
||||
// yet
|
||||
TORRENT_TEST(no_metadata_file_prio)
|
||||
|
|
|
@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/entry.hpp"
|
||||
#include "libtorrent/bencode.hpp"
|
||||
#include "libtorrent/read_resume_data.hpp"
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
|
@ -98,9 +99,6 @@ std::vector<char> generate_resume_data(torrent_info* ti
|
|||
rd["super_seeding"] = 0;
|
||||
rd["added_time"] = 1347;
|
||||
rd["completed_time"] = 1348;
|
||||
rd["last_scrape"] = 1349;
|
||||
rd["last_download"] = 1350;
|
||||
rd["last_upload"] = 1351;
|
||||
rd["finished_time"] = 1352;
|
||||
if (file_priorities && file_priorities[0])
|
||||
{
|
||||
|
@ -131,15 +129,40 @@ std::vector<char> generate_resume_data(torrent_info* ti
|
|||
std::vector<char> ret;
|
||||
bencode(back_inserter(ret), rd);
|
||||
|
||||
fprintf(stderr, "%s\n", rd.to_string().c_str());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
torrent_handle test_resume_flags(lt::session& ses, int flags
|
||||
, char const* file_priorities = "1111", char const* resume_file_prio = "")
|
||||
, char const* file_priorities = "1111", char const* resume_file_prio = ""
|
||||
, bool const test_deprecated = false)
|
||||
{
|
||||
boost::shared_ptr<torrent_info> ti = generate_torrent();
|
||||
|
||||
add_torrent_params p;
|
||||
std::vector<char> rd = generate_resume_data(ti.get(), resume_file_prio);
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
if (test_deprecated)
|
||||
{
|
||||
p.resume_data.swap(rd);
|
||||
|
||||
p.trackers.push_back("http://add_torrent_params_tracker.com/announce");
|
||||
p.url_seeds.push_back("http://add_torrent_params_url_seed.com");
|
||||
|
||||
p.max_uploads = 1;
|
||||
p.max_connections = 2;
|
||||
p.upload_limit = 3;
|
||||
p.download_limit = 4;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
error_code ec;
|
||||
p = read_resume_data(&rd[0], rd.size(), ec);
|
||||
TEST_CHECK(!ec);
|
||||
}
|
||||
|
||||
p.ti = ti;
|
||||
p.flags = flags;
|
||||
|
@ -148,22 +171,15 @@ torrent_handle test_resume_flags(lt::session& ses, int flags
|
|||
#else
|
||||
p.save_path = "/add_torrent_params save_path";
|
||||
#endif
|
||||
p.trackers.push_back("http://add_torrent_params_tracker.com/announce");
|
||||
p.url_seeds.push_back("http://add_torrent_params_url_seed.com");
|
||||
|
||||
std::vector<char> rd = generate_resume_data(ti.get(), resume_file_prio);
|
||||
p.resume_data.swap(rd);
|
||||
if (file_priorities[0])
|
||||
{
|
||||
std::vector<boost::uint8_t> priorities_vector;
|
||||
for (int i = 0; file_priorities[i]; ++i)
|
||||
priorities_vector.push_back(file_priorities[i] - '0');
|
||||
|
||||
p.max_uploads = 1;
|
||||
p.max_connections = 2;
|
||||
p.upload_limit = 3;
|
||||
p.download_limit = 4;
|
||||
|
||||
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;
|
||||
p.file_priorities = priorities_vector;
|
||||
}
|
||||
|
||||
torrent_handle h = ses.add_torrent(p);
|
||||
torrent_status s = h.status();
|
||||
|
@ -176,14 +192,7 @@ void default_tests(torrent_status const& s)
|
|||
// 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
|
||||
TEST_CHECK(s.last_scrape >= 1349);
|
||||
TEST_CHECK(s.time_since_download >= 1350);
|
||||
TEST_CHECK(s.time_since_upload >= 1351);
|
||||
TEST_CHECK(s.active_time >= 1339);
|
||||
|
||||
TEST_CHECK(s.last_scrape < 1349 + 10);
|
||||
TEST_CHECK(s.time_since_download < 1350 + 10);
|
||||
TEST_CHECK(s.time_since_upload < 1351 + 10);
|
||||
TEST_CHECK(s.active_time < 1339 + 10);
|
||||
|
||||
TEST_EQUAL(s.finished_time, 1352);
|
||||
|
@ -192,7 +201,7 @@ void default_tests(torrent_status const& s)
|
|||
TEST_EQUAL(s.completed_time, 1348);
|
||||
}
|
||||
|
||||
TORRENT_TEST(piece_priorities)
|
||||
void test_piece_priorities(bool test_deprecated = false)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
|
@ -218,7 +227,23 @@ TORRENT_TEST(piece_priorities)
|
|||
TEST_EQUAL(prios[1], '\x04');
|
||||
TEST_EQUAL(prios[ti->num_pieces()-1], '\0');
|
||||
|
||||
bencode(std::back_inserter(p.resume_data), *ra->resume_data);
|
||||
std::vector<char> resume_data;
|
||||
bencode(std::back_inserter(resume_data), *ra->resume_data);
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
if (test_deprecated)
|
||||
{
|
||||
p.resume_data = resume_data;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
error_code ec;
|
||||
p = read_resume_data(&resume_data[0], resume_data.size(), ec);
|
||||
TEST_CHECK(!ec);
|
||||
p.ti = ti;
|
||||
p.save_path = ".";
|
||||
}
|
||||
}
|
||||
|
||||
ses.remove_torrent(h);
|
||||
|
@ -231,13 +256,426 @@ TORRENT_TEST(piece_priorities)
|
|||
TEST_EQUAL(h.piece_priority(ti->num_pieces()-1), 0);
|
||||
}
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
TORRENT_TEST(piece_priorities_deprecated)
|
||||
{
|
||||
test_piece_priorities(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
TORRENT_TEST(piece_priorities)
|
||||
{
|
||||
test_piece_priorities();
|
||||
}
|
||||
|
||||
|
||||
// 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
|
||||
// TODO: generally save
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
TORRENT_TEST(file_priorities_default_deprecated)
|
||||
{
|
||||
lt::session ses;
|
||||
std::vector<int> file_priorities = test_resume_flags(ses, 0, "", "", true).file_priorities();
|
||||
|
||||
TEST_EQUAL(file_priorities.size(), 3);
|
||||
TEST_EQUAL(file_priorities[0], 4);
|
||||
TEST_EQUAL(file_priorities[1], 4);
|
||||
TEST_EQUAL(file_priorities[2], 4);
|
||||
}
|
||||
|
||||
TORRENT_TEST(file_priorities_resume_seed_mode_deprecated)
|
||||
{
|
||||
// in share mode file priorities should always be 0
|
||||
lt::session ses;
|
||||
std::vector<int> file_priorities = test_resume_flags(ses,
|
||||
add_torrent_params::flag_share_mode, "", "123", true).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_deprecated)
|
||||
{
|
||||
// in share mode file priorities should always be 0
|
||||
lt::session ses;
|
||||
std::vector<int> file_priorities = test_resume_flags(ses,
|
||||
add_torrent_params::flag_share_mode, "123", "", true).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(resume_save_load_deprecated)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
torrent_handle h = test_resume_flags(ses, 0, "123", "", true);
|
||||
|
||||
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_deprecated)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
torrent_handle h = test_resume_flags(ses, 0, "", "123", true);
|
||||
|
||||
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_deprecated)
|
||||
{
|
||||
// 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.
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
std::vector<int> file_priorities = test_resume_flags(ses,
|
||||
add_torrent_params::flag_override_resume_data, "", "123", true).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_deprecated)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
std::vector<int> file_priorities = test_resume_flags(ses, 0, "", "123", true).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_deprecated)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
std::vector<int> file_priorities = test_resume_flags(ses, 0, "010", "", true).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_deprecated)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
std::vector<int> file_priorities = test_resume_flags(ses, 0, "123", "", true).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_deprecated)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
std::vector<int> file_priorities = test_resume_flags(ses, 0, "4321", "", true).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_deprecated)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
|
||||
torrent_status s = test_resume_flags(ses, 0, "", "", true).status();
|
||||
default_tests(s);
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
||||
#else
|
||||
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
|
||||
TORRENT_TEST(use_resume_save_path_deprecated)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_use_resume_save_path, "", "", true).status();
|
||||
default_tests(s);
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(s.save_path, "c:\\resume_data save_path");
|
||||
#else
|
||||
TEST_EQUAL(s.save_path, "/resume_data save_path");
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
|
||||
TORRENT_TEST(override_resume_data_deprecated)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
torrent_status s = test_resume_flags(ses
|
||||
, add_torrent_params::flag_override_resume_data
|
||||
| add_torrent_params::flag_paused, "", "", true).status();
|
||||
|
||||
default_tests(s);
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
||||
#else
|
||||
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
|
||||
TORRENT_TEST(seed_mode_deprecated)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_override_resume_data
|
||||
| add_torrent_params::flag_seed_mode, "", "", true).status();
|
||||
default_tests(s);
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
||||
#else
|
||||
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
|
||||
TORRENT_TEST(upload_mode_deprecated)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_upload_mode, "", "", true).status();
|
||||
default_tests(s);
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
||||
#else
|
||||
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
|
||||
TORRENT_TEST(share_mode_deprecated)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
torrent_status s = test_resume_flags(ses
|
||||
, add_torrent_params::flag_override_resume_data
|
||||
| add_torrent_params::flag_share_mode, "", "", true).status();
|
||||
default_tests(s);
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
||||
#else
|
||||
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
|
||||
TORRENT_TEST(auto_managed_deprecated)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
// resume data overrides the auto-managed flag
|
||||
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_auto_managed, "", "", true).status();
|
||||
default_tests(s);
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
||||
#else
|
||||
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
|
||||
TORRENT_TEST(paused_deprecated)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
// resume data overrides the paused flag
|
||||
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_paused, "", "", true).status();
|
||||
default_tests(s);
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
||||
#else
|
||||
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
||||
#endif
|
||||
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);
|
||||
|
||||
// TODO: test all other resume flags here too. This would require returning
|
||||
// more than just the torrent_status from test_resume_flags. Also http seeds
|
||||
// and trackers for instance
|
||||
}
|
||||
|
||||
TORRENT_TEST(url_seed_resume_data_deprecated)
|
||||
{
|
||||
// merge url seeds with resume data
|
||||
fprintf(stderr, "flags: merge_resume_http_seeds\n");
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
torrent_handle h = test_resume_flags(ses,
|
||||
add_torrent_params::flag_merge_resume_http_seeds, "", "", true);
|
||||
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_deprecated)
|
||||
{
|
||||
// resume data overrides the .torrent_file
|
||||
fprintf(stderr, "flags: no merge_resume_http_seed\n");
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
torrent_handle h = test_resume_flags(ses,
|
||||
add_torrent_params::flag_merge_resume_trackers, "", "", true);
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
|
||||
TORRENT_TEST(file_priorities_default)
|
||||
{
|
||||
|
@ -276,7 +714,7 @@ TORRENT_TEST(file_priorities_seed_mode)
|
|||
TEST_EQUAL(file_priorities[2], 0);
|
||||
}
|
||||
|
||||
TORRENT_TEST(zero_file_prio)
|
||||
void test_zero_file_prio(bool test_deprecated = false)
|
||||
{
|
||||
fprintf(stderr, "test_file_prio\n");
|
||||
|
||||
|
@ -305,7 +743,23 @@ TORRENT_TEST(zero_file_prio)
|
|||
std::string pieces_prio(ti->num_pieces(), '\x01');
|
||||
rd["piece_priority"] = pieces_prio;
|
||||
|
||||
bencode(back_inserter(p.resume_data), rd);
|
||||
std::vector<char> resume_data;
|
||||
bencode(back_inserter(resume_data), rd);
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
if (test_deprecated)
|
||||
{
|
||||
p.resume_data = resume_data;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
error_code ec;
|
||||
p = read_resume_data(&resume_data[0], resume_data.size(), ec);
|
||||
TEST_CHECK(!ec);
|
||||
p.ti = ti;
|
||||
p.save_path = ".";
|
||||
}
|
||||
|
||||
torrent_handle h = ses.add_torrent(p);
|
||||
|
||||
|
@ -313,8 +767,20 @@ TORRENT_TEST(zero_file_prio)
|
|||
TEST_EQUAL(s.total_wanted, 0);
|
||||
}
|
||||
|
||||
void test_seed_mode(bool file_prio, bool pieces_have, bool piece_prio
|
||||
, bool all_files_zero = false)
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
TORRENT_TEST(zero_file_prio_deprecated)
|
||||
{
|
||||
test_zero_file_prio(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
TORRENT_TEST(zero_file_prio)
|
||||
{
|
||||
test_zero_file_prio();
|
||||
}
|
||||
|
||||
void test_seed_mode(bool const file_prio, bool const pieces_have, bool const piece_prio
|
||||
, bool const all_files_zero = false, bool const test_deprecated = false)
|
||||
{
|
||||
fprintf(stderr, "test_seed_mode file_prio: %d pieces_have: %d piece_prio: %d\n"
|
||||
, file_prio, pieces_have, piece_prio);
|
||||
|
@ -363,7 +829,23 @@ void test_seed_mode(bool file_prio, bool pieces_have, bool piece_prio
|
|||
|
||||
rd["seed_mode"] = 1;
|
||||
|
||||
bencode(back_inserter(p.resume_data), rd);
|
||||
std::vector<char> resume_data;
|
||||
bencode(back_inserter(resume_data), rd);
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
if (test_deprecated)
|
||||
{
|
||||
p.resume_data = resume_data;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
error_code ec;
|
||||
p = read_resume_data(&resume_data[0], resume_data.size(), ec);
|
||||
TEST_CHECK(!ec);
|
||||
p.ti = ti;
|
||||
p.save_path = ".";
|
||||
}
|
||||
|
||||
torrent_handle h = ses.add_torrent(p);
|
||||
|
||||
|
@ -377,6 +859,27 @@ void test_seed_mode(bool file_prio, bool pieces_have, bool piece_prio
|
|||
TEST_EQUAL(s.seed_mode, true);
|
||||
}
|
||||
}
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
TORRENT_TEST(seed_mode_file_prio_deprecated)
|
||||
{
|
||||
test_seed_mode(true, false, false, true);
|
||||
}
|
||||
|
||||
TORRENT_TEST(seed_mode_piece_prio_deprecated)
|
||||
{
|
||||
test_seed_mode(false, true, false, true);
|
||||
}
|
||||
|
||||
TORRENT_TEST(seed_mode_piece_have_deprecated)
|
||||
{
|
||||
test_seed_mode(false, false, true, true);
|
||||
}
|
||||
|
||||
TORRENT_TEST(seed_mode_preserve_deprecated)
|
||||
{
|
||||
test_seed_mode(false, false, false, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
TORRENT_TEST(seed_mode_file_prio)
|
||||
{
|
||||
|
@ -446,28 +949,14 @@ TORRENT_TEST(resume_save_load_resume)
|
|||
entry::list_type& l = e["file_priority"].list();
|
||||
entry::list_type::iterator i = l.begin();
|
||||
|
||||
fprintf(stderr, "%s\n", e.to_string().c_str());
|
||||
|
||||
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.
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
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)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
|
@ -542,61 +1031,12 @@ TORRENT_TEST(plain)
|
|||
TEST_EQUAL(s.uploads_limit, 1346);
|
||||
}
|
||||
|
||||
TORRENT_TEST(use_resume_save_path)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_use_resume_save_path).status();
|
||||
default_tests(s);
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(s.save_path, "c:\\resume_data save_path");
|
||||
#else
|
||||
TEST_EQUAL(s.save_path, "/resume_data save_path");
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
|
||||
TORRENT_TEST(override_resume_data)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
torrent_status s = test_resume_flags(ses
|
||||
, add_torrent_params::flag_override_resume_data
|
||||
| add_torrent_params::flag_paused).status();
|
||||
|
||||
default_tests(s);
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
||||
#else
|
||||
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
|
||||
TORRENT_TEST(seed_mode)
|
||||
{
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
torrent_status s = test_resume_flags(ses, add_torrent_params::flag_override_resume_data
|
||||
| add_torrent_params::flag_seed_mode).status();
|
||||
torrent_status s = test_resume_flags(ses
|
||||
, add_torrent_params::flag_seed_mode).status();
|
||||
default_tests(s);
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
||||
|
@ -611,8 +1051,8 @@ TORRENT_TEST(seed_mode)
|
|||
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);
|
||||
TEST_EQUAL(s.connections_limit, 1345);
|
||||
TEST_EQUAL(s.uploads_limit, 1346);
|
||||
}
|
||||
|
||||
TORRENT_TEST(upload_mode)
|
||||
|
@ -643,8 +1083,7 @@ TORRENT_TEST(share_mode)
|
|||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
torrent_status s = test_resume_flags(ses
|
||||
, add_torrent_params::flag_override_resume_data
|
||||
| add_torrent_params::flag_share_mode).status();
|
||||
, add_torrent_params::flag_share_mode).status();
|
||||
default_tests(s);
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
|
||||
|
@ -659,8 +1098,8 @@ TORRENT_TEST(share_mode)
|
|||
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);
|
||||
TEST_EQUAL(s.connections_limit, 1345);
|
||||
TEST_EQUAL(s.uploads_limit, 1346);
|
||||
}
|
||||
|
||||
TORRENT_TEST(auto_managed)
|
||||
|
@ -677,7 +1116,7 @@ TORRENT_TEST(auto_managed)
|
|||
#endif
|
||||
TEST_EQUAL(s.sequential_download, false);
|
||||
TEST_EQUAL(s.paused, false);
|
||||
TEST_EQUAL(s.auto_managed, false);
|
||||
TEST_EQUAL(s.auto_managed, true);
|
||||
TEST_EQUAL(s.seed_mode, false);
|
||||
TEST_EQUAL(s.super_seeding, false);
|
||||
TEST_EQUAL(s.share_mode, false);
|
||||
|
@ -700,7 +1139,7 @@ TORRENT_TEST(paused)
|
|||
TEST_EQUAL(s.save_path, "/add_torrent_params save_path");
|
||||
#endif
|
||||
TEST_EQUAL(s.sequential_download, false);
|
||||
TEST_EQUAL(s.paused, false);
|
||||
TEST_EQUAL(s.paused, true);
|
||||
TEST_EQUAL(s.auto_managed, false);
|
||||
TEST_EQUAL(s.seed_mode, false);
|
||||
TEST_EQUAL(s.super_seeding, false);
|
||||
|
@ -715,47 +1154,3 @@ TORRENT_TEST(paused)
|
|||
// and trackers for instance
|
||||
}
|
||||
|
||||
TORRENT_TEST(url_seed_resume_data)
|
||||
{
|
||||
// merge url seeds with resume data
|
||||
fprintf(stderr, "flags: merge_resume_http_seeds\n");
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
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");
|
||||
settings_pack sett = settings();
|
||||
lt::session ses(sett);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
#include "test_utils.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
#include "libtorrent/storage.hpp"
|
||||
#include "libtorrent/file_pool.hpp"
|
||||
|
@ -43,6 +44,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/create_torrent.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/read_resume_data.hpp"
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
|
@ -614,7 +616,7 @@ void run_test(bool unbuffered)
|
|||
test_rename(test_path);
|
||||
}
|
||||
|
||||
TORRENT_TEST(fastresume)
|
||||
void test_fastresume(bool const test_deprecated)
|
||||
{
|
||||
std::string test_path = current_working_directory();
|
||||
error_code ec;
|
||||
|
@ -635,17 +637,7 @@ TORRENT_TEST(fastresume)
|
|||
|
||||
entry resume;
|
||||
{
|
||||
const int mask = alert::all_categories
|
||||
& ~(alert::progress_notification
|
||||
| alert::performance_warning
|
||||
| alert::stats_notification);
|
||||
|
||||
settings_pack pack;
|
||||
pack.set_bool(settings_pack::enable_lsd, false);
|
||||
pack.set_bool(settings_pack::enable_natpmp, false);
|
||||
pack.set_bool(settings_pack::enable_upnp, false);
|
||||
pack.set_bool(settings_pack::enable_dht, false);
|
||||
pack.set_int(settings_pack::alert_mask, mask);
|
||||
settings_pack pack = settings();
|
||||
lt::session ses(pack);
|
||||
|
||||
error_code ec;
|
||||
|
@ -695,26 +687,30 @@ TORRENT_TEST(fastresume)
|
|||
|
||||
// make sure the fast resume check fails! since we removed the file
|
||||
{
|
||||
const int mask = alert::all_categories
|
||||
& ~(alert::progress_notification
|
||||
| alert::performance_warning
|
||||
| alert::stats_notification);
|
||||
|
||||
settings_pack pack;
|
||||
pack.set_bool(settings_pack::enable_lsd, false);
|
||||
pack.set_bool(settings_pack::enable_natpmp, false);
|
||||
pack.set_bool(settings_pack::enable_upnp, false);
|
||||
pack.set_bool(settings_pack::enable_dht, false);
|
||||
pack.set_int(settings_pack::alert_mask, mask);
|
||||
settings_pack pack = settings();
|
||||
lt::session ses(pack);
|
||||
|
||||
std::vector<char> resume_data;
|
||||
bencode(std::back_inserter(resume_data), resume);
|
||||
|
||||
add_torrent_params p;
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
if (test_deprecated)
|
||||
{
|
||||
p.resume_data = resume_data;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
p = read_resume_data(&resume_data[0], resume_data.size(), ec);
|
||||
TEST_CHECK(!ec);
|
||||
}
|
||||
|
||||
p.flags &= ~add_torrent_params::flag_paused;
|
||||
p.flags &= ~add_torrent_params::flag_auto_managed;
|
||||
p.ti = boost::make_shared<torrent_info>(boost::cref(*t));
|
||||
p.save_path = combine_path(test_path, "tmp1");
|
||||
p.storage_mode = storage_mode_compact;
|
||||
bencode(std::back_inserter(p.resume_data), resume);
|
||||
torrent_handle h = ses.add_torrent(p, ec);
|
||||
|
||||
alert const* a = wait_for_alert(ses, fastresume_rejected_alert::alert_type
|
||||
|
@ -728,13 +724,26 @@ TORRENT_TEST(fastresume)
|
|||
<< "': " << ec.message() << std::endl;
|
||||
}
|
||||
|
||||
TORRENT_TEST(fastresume)
|
||||
{
|
||||
test_fastresume(false);
|
||||
}
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
TORRENT_TEST(fastresume_deprecated)
|
||||
{
|
||||
test_fastresume(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool got_file_rename_alert(alert const* a)
|
||||
{
|
||||
return alert_cast<libtorrent::file_renamed_alert>(a)
|
||||
|| alert_cast<libtorrent::file_rename_failed_alert>(a);
|
||||
}
|
||||
|
||||
TORRENT_TEST(rename_file_fastresume)
|
||||
void test_rename_file_fastresume(bool test_deprecated)
|
||||
{
|
||||
std::string test_path = current_working_directory();
|
||||
error_code ec;
|
||||
|
@ -752,17 +761,7 @@ TORRENT_TEST(rename_file_fastresume)
|
|||
|
||||
entry resume;
|
||||
{
|
||||
const int mask = alert::all_categories
|
||||
& ~(alert::progress_notification
|
||||
| alert::performance_warning
|
||||
| alert::stats_notification);
|
||||
|
||||
settings_pack pack;
|
||||
pack.set_bool(settings_pack::enable_lsd, false);
|
||||
pack.set_bool(settings_pack::enable_natpmp, false);
|
||||
pack.set_bool(settings_pack::enable_upnp, false);
|
||||
pack.set_bool(settings_pack::enable_dht, false);
|
||||
pack.set_int(settings_pack::alert_mask, mask);
|
||||
settings_pack pack = settings();
|
||||
lt::session ses(pack);
|
||||
|
||||
add_torrent_params p;
|
||||
|
@ -799,24 +798,27 @@ TORRENT_TEST(rename_file_fastresume)
|
|||
|
||||
// make sure the fast resume check succeeds, even though we renamed the file
|
||||
{
|
||||
const int mask = alert::all_categories
|
||||
& ~(alert::progress_notification
|
||||
| alert::performance_warning
|
||||
| alert::stats_notification);
|
||||
|
||||
settings_pack pack;
|
||||
pack.set_bool(settings_pack::enable_lsd, false);
|
||||
pack.set_bool(settings_pack::enable_natpmp, false);
|
||||
pack.set_bool(settings_pack::enable_upnp, false);
|
||||
pack.set_bool(settings_pack::enable_dht, false);
|
||||
pack.set_int(settings_pack::alert_mask, mask);
|
||||
settings_pack pack = settings();
|
||||
lt::session ses(pack);
|
||||
|
||||
add_torrent_params p;
|
||||
std::vector<char> resume_data;
|
||||
bencode(std::back_inserter(resume_data), resume);
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
if (test_deprecated)
|
||||
{
|
||||
p.resume_data = resume_data;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
p = read_resume_data(&resume_data[0], resume_data.size(), ec);
|
||||
TEST_CHECK(!ec);
|
||||
}
|
||||
p.ti = boost::make_shared<torrent_info>(boost::cref(*t));
|
||||
p.save_path = combine_path(test_path, "tmp2");
|
||||
p.storage_mode = storage_mode_compact;
|
||||
bencode(std::back_inserter(p.resume_data), resume);
|
||||
torrent_handle h = ses.add_torrent(p, ec);
|
||||
|
||||
torrent_status stat;
|
||||
|
@ -846,6 +848,18 @@ TORRENT_TEST(rename_file_fastresume)
|
|||
<< "': " << ec.message() << std::endl;
|
||||
}
|
||||
|
||||
TORRENT_TEST(rename_file_fastresume)
|
||||
{
|
||||
test_rename_file_fastresume(false);
|
||||
}
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
TORRENT_TEST(rename_file_fastresume_deprecated)
|
||||
{
|
||||
test_rename_file_fastresume(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
void alloc_iov(file::iovec_t* iov, int num_bufs)
|
||||
{
|
||||
for (int i = 0; i < num_bufs; ++i)
|
||||
|
|
Loading…
Reference in New Issue