made tests build and pass in trunk. fixed issues in trunk revealed by the tests. fixed failing torrent invariant check in trunk and rc0.13
This commit is contained in:
@@ -75,7 +75,7 @@ void run_test(std::string const& url, int size, int status, int connected
|
||||
|
||||
boost::shared_ptr<http_connection> h(new http_connection(ios, cq
|
||||
, &::http_handler, true, &::http_connect_handler));
|
||||
h->get(url, seconds(30), &ps);
|
||||
h->get(url, seconds(30), 0, &ps);
|
||||
ios.reset();
|
||||
ios.run();
|
||||
|
||||
|
@@ -39,17 +39,11 @@ boost::shared_ptr<piece_picker> setup_picker(
|
||||
|
||||
std::vector<bool> have = string2vec(have_str);
|
||||
|
||||
std::vector<piece_picker::downloading_piece> unfinished;
|
||||
piece_picker::downloading_piece pp;
|
||||
std::vector<piece_picker::block_info> blocks(blocks_per_piece * num_pieces);
|
||||
|
||||
for (int i = 0; i < num_pieces; ++i)
|
||||
{
|
||||
if (partial[i] == 0) break;
|
||||
|
||||
if (partial[i] == ' ') continue;
|
||||
pp.index = i;
|
||||
pp.info = &blocks[i * blocks_per_piece];
|
||||
|
||||
int blocks = 0;
|
||||
if (partial[i] >= '0' && partial[i] <= '9')
|
||||
@@ -57,15 +51,35 @@ boost::shared_ptr<piece_picker> setup_picker(
|
||||
else
|
||||
blocks = partial[i] - 'a' + 10;
|
||||
|
||||
int counter = 0;
|
||||
if (blocks & 1)
|
||||
pp.info[0].state = piece_picker::block_info::state_finished;
|
||||
{
|
||||
++counter;
|
||||
p->mark_as_finished(piece_block(i, 0), 0);
|
||||
}
|
||||
if (blocks & 2)
|
||||
pp.info[1].state = piece_picker::block_info::state_finished;
|
||||
{
|
||||
++counter;
|
||||
p->mark_as_finished(piece_block(i, 1), 0);
|
||||
}
|
||||
if (blocks & 4)
|
||||
pp.info[2].state = piece_picker::block_info::state_finished;
|
||||
{
|
||||
++counter;
|
||||
p->mark_as_finished(piece_block(i, 2), 0);
|
||||
}
|
||||
if (blocks & 8)
|
||||
pp.info[3].state = piece_picker::block_info::state_finished;
|
||||
unfinished.push_back(pp);
|
||||
{
|
||||
++counter;
|
||||
p->mark_as_finished(piece_block(i, 3), 0);
|
||||
}
|
||||
|
||||
piece_picker::downloading_piece st;
|
||||
p->piece_info(i, st);
|
||||
TEST_CHECK(st.writing == 0);
|
||||
TEST_CHECK(st.requested == 0);
|
||||
TEST_CHECK(st.index == i);
|
||||
|
||||
TEST_CHECK(st.finished == counter);
|
||||
}
|
||||
|
||||
for (int i = 0; i < num_pieces; ++i)
|
||||
@@ -78,26 +92,7 @@ boost::shared_ptr<piece_picker> setup_picker(
|
||||
TEST_CHECK(p->piece_priority(i) == prio);
|
||||
}
|
||||
|
||||
std::vector<int> verify_pieces;
|
||||
p->files_checked(have, unfinished, verify_pieces);
|
||||
|
||||
for (std::vector<piece_picker::downloading_piece>::iterator i = unfinished.begin()
|
||||
, end(unfinished.end()); i != end; ++i)
|
||||
{
|
||||
for (int j = 0; j < blocks_per_piece; ++j)
|
||||
TEST_CHECK(p->is_finished(piece_block(i->index, j)) == (i->info[j].state == piece_picker::block_info::state_finished));
|
||||
|
||||
piece_picker::downloading_piece st;
|
||||
p->piece_info(i->index, st);
|
||||
TEST_CHECK(st.writing == 0);
|
||||
TEST_CHECK(st.requested == 0);
|
||||
TEST_CHECK(st.index == i->index);
|
||||
int counter = 0;
|
||||
for (int j = 0; j < blocks_per_piece; ++j)
|
||||
if (i->info[j].state == piece_picker::block_info::state_finished) ++counter;
|
||||
|
||||
TEST_CHECK(st.finished == counter);
|
||||
}
|
||||
p->init(have);
|
||||
|
||||
for (int i = 0; i < num_pieces; ++i)
|
||||
{
|
||||
|
@@ -25,6 +25,16 @@ void on_read_piece(int ret, disk_io_job const& j, char const* data, int size)
|
||||
TEST_CHECK(std::equal(j.buffer, j.buffer + ret, data));
|
||||
}
|
||||
|
||||
void on_check_resume_data(int ret, disk_io_job const& j)
|
||||
{
|
||||
std::cerr << "on_check_resume_data ret: " << ret << " " << j.piece << std::endl;
|
||||
}
|
||||
|
||||
void on_check_files(int ret, disk_io_job const& j)
|
||||
{
|
||||
std::cerr << "on_check_files ret: " << ret << " " << j.piece << std::endl;
|
||||
}
|
||||
|
||||
void run_storage_tests(boost::intrusive_ptr<torrent_info> info
|
||||
, path const& test_path
|
||||
, libtorrent::storage_mode_t storage_mode)
|
||||
@@ -90,28 +100,15 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
|
||||
disk_io_thread io(ios);
|
||||
boost::shared_ptr<int> dummy(new int);
|
||||
boost::intrusive_ptr<piece_manager> pm = new piece_manager(dummy, info
|
||||
, test_path, fp, io, default_storage_constructor);
|
||||
, test_path, fp, io, default_storage_constructor, storage_mode);
|
||||
boost::mutex lock;
|
||||
libtorrent::aux::piece_checker_data d;
|
||||
|
||||
std::vector<bool> pieces;
|
||||
num_pieces = 0;
|
||||
std::string error_msg;
|
||||
entry frd;
|
||||
pm->verify_resume_data(frd, error_msg);
|
||||
TEST_CHECK(pm->check_fastresume(d, pieces, num_pieces
|
||||
, storage_mode, error_msg) == false);
|
||||
bool finished = false;
|
||||
float progress;
|
||||
num_pieces = 0;
|
||||
boost::recursive_mutex mutex;
|
||||
bool error;
|
||||
while (!finished)
|
||||
boost::tie(finished, progress) = pm->check_files(pieces, num_pieces, mutex, error);
|
||||
|
||||
TEST_CHECK(num_pieces == std::count(pieces.begin(), pieces.end()
|
||||
, true));
|
||||
pm->async_check_fastresume(&frd, &on_check_resume_data);
|
||||
test_sleep(2000);
|
||||
|
||||
pm->async_check_files(&on_check_files);
|
||||
test_sleep(2000);
|
||||
|
||||
boost::function<void(int, disk_io_job const&)> none;
|
||||
TEST_CHECK(exists(test_path / "temp_storage"));
|
||||
|
Reference in New Issue
Block a user