extend file_storage unit test a bit

This commit is contained in:
Arvid Norberg 2015-02-16 21:53:23 +00:00
parent 5ea0db3145
commit 3d47a1fb81
4 changed files with 63 additions and 14 deletions

View File

@ -275,7 +275,7 @@ namespace libtorrent
// The ``mtime`` argument is optional and can be set to 0. If non-zero,
// it is the posix time of the last modification time of this file.
//
// ``symlink_path`` is the path the is a symlink to. To make this a
// ``symlink_path`` is the path the file is a symlink to. To make this a
// symlink you also need to set the file_storage::flag_symlink file flag.
//
// If more files than one are added, certain restrictions to their paths
@ -296,12 +296,6 @@ namespace libtorrent
// that filenames are expected to be UTF-8 encoded.
void rename_file(int index, std::string const& new_filename);
// this is a low-level function that sets the name of a file
// by making it reference a buffer that is not owned by the file_storage.
// it's an optimization used when loading .torrent files, to not
// duplicate names in memory.
void rename_file_borrow(int index, char const* new_filename, int len);
#ifndef TORRENT_NO_DEPRECATE
TORRENT_DEPRECATED_PREFIX
void add_file(file_entry const& fe, char const* infohash = NULL) TORRENT_DEPRECATED;

View File

@ -286,12 +286,6 @@ namespace libtorrent
update_path_index(m_files[index]);
}
void file_storage::rename_file_borrow(int index, char const* new_filename, int len)
{
TORRENT_ASSERT_PRECOND(index >= 0 && index < int(m_files.size()));
m_files[index].set_name(new_filename, true, len);
}
namespace
{
bool compare_file_offset(internal_file_entry const& lhs, internal_file_entry const& rhs)

View File

@ -85,7 +85,11 @@ int test_main()
st.rename_file(0, combine_path("test", combine_path("c", "d")));
TEST_EQUAL(st.file_path(0, "."), combine_path(".", combine_path("test"
, combine_path("c", "d"))));
TEST_EQUAL(st.file_path(0, ""), combine_path("test"
, combine_path("c", "d")));
// files with absolute paths should ignore the save_path argument
// passed in to file_path()
#ifdef TORRENT_WINDOWS
st.rename_file(0, "c:\\tmp\\a");
TEST_EQUAL(st.file_path(0, "."), "c:\\tmp\\a");
@ -96,7 +100,9 @@ int test_main()
}
{
// test set_name
// test set_name. Make sure the name of the torrent is not encoded
// in the paths of each individual file. When changing the name of the
// torrent, the path of the files should change too
file_storage st;
setup_test_storage(st);
@ -106,19 +112,57 @@ int test_main()
}
{
// test rename_file
file_storage st;
st.add_file("a", 10000);
TEST_EQUAL(st.file_path(0, ""), "a");
st.rename_file(0, combine_path("test", combine_path("c", "d")));
TEST_EQUAL(st.file_path(0, "."), combine_path(".", combine_path("test", combine_path("c", "d"))));
TEST_EQUAL(st.file_path(0, ""), combine_path("test", combine_path("c", "d")));
#ifdef TORRENT_WINDOWS
st.rename_file(0, "c:\\tmp\\a");
TEST_EQUAL(st.file_path(0, "."), "c:\\tmp\\a");
TEST_EQUAL(st.file_path(0, "c:\\test-1\\test2"), "c:\\tmp\\a");
#else
st.rename_file(0, "/tmp/a");
TEST_EQUAL(st.file_path(0, "."), "/tmp/a");
TEST_EQUAL(st.file_path(0, "/usr/local/temp"), "/tmp/a");
#endif
st.rename_file(0, combine_path("tmp", "a"));
TEST_EQUAL(st.file_path(0, "."), combine_path("tmp", "a"));
}
{
// test applying pointer offset
file_storage st;
char const filename[] = "test1fooba";
st.add_file_borrow(filename, 5, combine_path("test-torrent-1", "test1")
, 10);
// test filename_ptr and filename_len
TEST_EQUAL(st.file_name_ptr(0), filename);
TEST_EQUAL(st.file_name_len(0), 5);
TEST_EQUAL(st.file_path(0, ""), combine_path("test-torrent-1", "test1"));
TEST_EQUAL(st.file_path(0, "tmp"), combine_path("tmp"
, combine_path("test-torrent-1", "test1")));
// apply a pointer offset of 5 bytes. The name of the file should
// change to "fooba".
st.apply_pointer_offset(5);
TEST_EQUAL(st.file_path(0, ""), combine_path("test-torrent-1", "fooba"));
TEST_EQUAL(st.file_path(0, "tmp"), combine_path("tmp"
, combine_path("test-torrent-1", "fooba")));
// test filename_ptr and filename_len
TEST_EQUAL(st.file_name_ptr(0), filename + 5);
TEST_EQUAL(st.file_name_len(0), 5);
}
{

View File

@ -124,6 +124,23 @@ namespace libtorrent
// TODO: torrent with 'l' (symlink) attribute
// TODO: creating a merkle torrent (torrent_info::build_merkle_list)
// TODO: torrent with multiple trackers in multiple tiers, making sure we shuffle them (how do you test shuffling?, load it multiple times and make sure it's in different order at least once)
// TODO: sanitize_append_path_element with all kinds of UTF-8 sequences, including invalid ones
// TODO: torrents with a missing name
// TODO: torrents with a zero-length name
// TODO: torrents with a merkle tree and add_merkle_nodes
// TODO: torrent with a non-dictionary info-section
// TODO: torrents with DHT nodes
// TODO: torrent with url-list as a single string
// TODO: torrent with http seed as a single string
// TODO: torrent with a comment
// TODO: torrent with an SSL cert
// TODO: torrent with attributes (executable and hidden)
// TODO: torrent_info::add_tracker
// TODO: torrent_info::add_url_seed
// TODO: torrent_info::add_http_seed
// TODO: torrent_info::unload
// TODO: torrent_info constructor that takes an invalid bencoded buffer
// TODO: verify_encoding with a string that triggers character replacement
int test_torrent_parse()
{