extend piece_picker unit test and comment out unused function

This commit is contained in:
Arvid Norberg 2015-02-15 22:01:15 +00:00
parent cb6d3cdd44
commit 5ea0db3145
3 changed files with 57 additions and 7 deletions

View File

@ -341,7 +341,7 @@ namespace libtorrent
void check_peers();
#endif
int get_block_state(piece_block block) const;
// int get_block_state(piece_block block) const;
// returns true if any client is currently downloading this
// piece-block, or if it's queued for downloading by some client

View File

@ -267,6 +267,7 @@ namespace libtorrent
// blocks that are allocated from the m_block_info array.
m_free_block_infos.push_back(i->info_idx);
TORRENT_ASSERT(find_dl_piece(download_state, i->index) == i);
m_piece_map[i->index].download_state = piece_pos::piece_open;
m_downloads[download_state].erase(i);
@ -1603,7 +1604,6 @@ namespace libtorrent
--m_num_passed;
}
erase_download_piece(i);
p.download_state = piece_pos::piece_open;
return;
}
@ -1657,11 +1657,12 @@ namespace libtorrent
if (p.have()) return;
if (p.download_queue() != piece_pos::piece_open)
int state = p.download_queue();
if (state != piece_pos::piece_open)
{
std::vector<downloading_piece>::iterator i
= find_dl_piece(p.download_queue(), index);
TORRENT_ASSERT(i != m_downloads[p.download_queue()].end());
= find_dl_piece(state, index);
TORRENT_ASSERT(i != m_downloads[state].end());
// decrement num_passed here to compensate
// for the unconditional increment further down
if (i->passed_hash_check) --m_num_passed;
@ -3000,7 +3001,7 @@ get_out:
return i;
}
/*
int piece_picker::get_block_state(piece_block block) const
{
TORRENT_ASSERT(block.block_index != piece_block::invalid.block_index);
@ -3022,7 +3023,7 @@ get_out:
TORRENT_ASSERT(info[block.block_index].piece_index == block.piece_index);
return info[block.block_index].state;
}
*/
bool piece_picker::is_requested(piece_block block) const
{
#ifdef TORRENT_USE_VALGRIND

View File

@ -825,6 +825,37 @@ int test_main()
TEST_EQUAL(p->cursor(), 7);
TEST_EQUAL(p->reverse_cursor(), 0);
// sweep in, set_piece_priority()
print_title("test cursors. sweep in, set_piece_priority");
p = setup_picker("7654321", " ", "", "");
for (int left = 0, right = 6; left <= 3 && right >= 3; ++left, --right)
{
TEST_EQUAL(p->cursor(), left);
TEST_EQUAL(p->reverse_cursor(), right + 1);
p->set_piece_priority(left, 0);
p->set_piece_priority(right, 0);
}
TEST_CHECK(p->is_finished());
TEST_CHECK(!p->is_seeding());
TEST_EQUAL(p->cursor(), 7);
TEST_EQUAL(p->reverse_cursor(), 0);
// sweep in, we_have()
print_title("test cursors. sweep in, we_have");
p = setup_picker("7654321", " ", "", "");
for (int left = 0, right = 6; left <= 3 && right >= 3; ++left, --right)
{
TEST_EQUAL(p->cursor(), left);
TEST_EQUAL(p->reverse_cursor(), right + 1);
p->we_have(left);
p->we_have(right);
}
TEST_CHECK(p->is_finished());
TEST_CHECK(p->is_seeding());
TEST_EQUAL(p->cursor(), 7);
TEST_EQUAL(p->reverse_cursor(), 0);
print_title("test cursors. sweep up, we_dont_have");
p = setup_picker("7654321", "*******", "", "");
TEST_CHECK(p->is_finished());
@ -859,6 +890,24 @@ int test_main()
TEST_EQUAL(p->cursor(), 0);
TEST_EQUAL(p->reverse_cursor(), 7);
print_title("test cursors. sweep out, we_dont_have");
p = setup_picker("7654321", "*******", "", "");
TEST_CHECK(p->is_finished());
TEST_CHECK(p->is_seeding());
TEST_EQUAL(p->cursor(), 7);
TEST_EQUAL(p->reverse_cursor(), 0);
for (int left = 3, right = 3; left >= 0 && right < 7; --left, ++right)
{
p->we_dont_have(left);
p->we_dont_have(right);
TEST_EQUAL(p->cursor(), left);
TEST_EQUAL(p->reverse_cursor(), right + 1);
}
TEST_CHECK(!p->is_finished());
TEST_CHECK(!p->is_seeding());
TEST_EQUAL(p->cursor(), 0);
TEST_EQUAL(p->reverse_cursor(), 7);
// test cursors
print_title("test cursors");
p = setup_picker("7654321", " ", "", "");