improved unit test for storage, modified move_storage to hopefully fix a bug. updated Changelog.

This commit is contained in:
Arvid Norberg 2007-02-25 21:11:29 +00:00
parent e051892c21
commit bb0b8c9d95
4 changed files with 47 additions and 39 deletions

View File

@ -1,4 +1,4 @@
Copyright (c) 2003 - 2006, Arvid Norberg
Copyright (c) 2003 - 2007, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,3 +1,6 @@
* fixed bug where directories would be left behind when moving storage
in some cases.
* fixed crashing bug when restarting or stopping the DHT.
* added python binding, using boost.python
* improved character conversion on windows when strings are not utf-8.
* metadata extension now respects the private flag in the torrent.

View File

@ -417,29 +417,8 @@ namespace libtorrent
m_pimpl->files.release(m_pimpl.get());
if (m_pimpl->info.num_files() == 1)
{
path single_file = m_pimpl->info.begin_files()->path;
assert(!single_file.is_complete());
if (single_file.has_branch_path())
{
assert(single_file.begin() != single_file.end());
std::string trunk = *single_file.begin();
old_path = m_pimpl->save_path / trunk;
new_path = save_path / trunk;
}
else
{
old_path = m_pimpl->save_path / single_file;
new_path = save_path / m_pimpl->info.begin_files()->path;
}
}
else
{
assert(m_pimpl->info.num_files() > 1);
old_path = m_pimpl->save_path / m_pimpl->info.name();
new_path = save_path / m_pimpl->info.name();
}
old_path = m_pimpl->save_path / m_pimpl->info.name();
new_path = save_path / m_pimpl->info.name();
try
{

View File

@ -14,17 +14,11 @@
using namespace libtorrent;
using namespace boost::filesystem;
int test_main()
const int piece_size = 16;
void run_storage_tests(torrent_info& info)
{
const int piece_size = 16;
const int half = piece_size / 2;
torrent_info info;
info.set_piece_size(piece_size);
info.add_file("temp_storage/test1.tmp", 17);
info.add_file("temp_storage/test2.tmp", 612);
info.add_file("temp_storage/test3.tmp", 0);
info.add_file("temp_storage/test4.tmp", 0);
info.add_file("temp_storage/test5.tmp", 1);
char piece0[piece_size] =
{ 6, 6, 6, 6, 6, 6, 6, 6
@ -74,13 +68,11 @@ int test_main()
s.read(piece, 2, 0, piece_size);
TEST_CHECK(std::equal(piece, piece + piece_size, piece2));
// make sure the files have the correct size
TEST_CHECK(file_size(initial_path() / "temp_storage" / "test1.tmp") == 17);
TEST_CHECK(file_size(initial_path() / "temp_storage" / "test2.tmp") == 31);
s.release_files();
}
// make sure the piece_manager can identify the pieces
{
file_pool fp;
piece_manager pm(info, initial_path(), fp);
boost::mutex lock;
@ -97,7 +89,14 @@ int test_main()
TEST_CHECK(num_pieces == std::count(pieces.begin(), pieces.end()
, true));
pm.move_storage("temp_storage2");
TEST_CHECK(!exists("temp_storage"));
TEST_CHECK(exists("temp_storage2/temp_storage"));
pm.move_storage(".");
TEST_CHECK(!exists("temp_storage2/temp_storage"));
remove_all("temp_storage2");
TEST_CHECK(pm.read(piece, 0, 0, piece_size) == piece_size);
TEST_CHECK(std::equal(piece, piece + piece_size, piece0));
@ -108,11 +107,38 @@ int test_main()
TEST_CHECK(std::equal(piece, piece + piece_size, piece2));
pm.release_files();
}
}
int test_main()
{
torrent_info info;
info.set_piece_size(piece_size);
info.add_file("temp_storage/test1.tmp", 17);
info.add_file("temp_storage/test2.tmp", 612);
info.add_file("temp_storage/test3.tmp", 0);
info.add_file("temp_storage/test4.tmp", 0);
info.add_file("temp_storage/test5.tmp", 1);
run_storage_tests(info);
// make sure the files have the correct size
TEST_CHECK(file_size(initial_path() / "temp_storage" / "test1.tmp") == 17);
TEST_CHECK(file_size(initial_path() / "temp_storage" / "test2.tmp") == 31);
TEST_CHECK(exists("temp_storage/test3.tmp"));
TEST_CHECK(exists("temp_storage/test4.tmp"));
remove_all(initial_path() / "temp_storage");
info = torrent_info();
info.set_piece_size(piece_size);
info.add_file("temp_storage/test1.tmp", 17 + 612 + 1);
run_storage_tests(info);
// 48 = piece_size * 3
TEST_CHECK(file_size(initial_path() / "temp_storage" / "test1.tmp") == 48);
remove_all(initial_path() / "temp_storage");
return 0;
}