From d506bcd5dedfd4145ad4a3c86dfc098846d5e084 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 19 Jan 2009 08:46:45 +0000 Subject: [PATCH] prevent torrent optimization in unit test --- include/libtorrent/create_torrent.hpp | 5 ++++- src/create_torrent.cpp | 5 +++-- test/test_storage.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/libtorrent/create_torrent.hpp b/include/libtorrent/create_torrent.hpp index db4a35ba1..93ec613d7 100644 --- a/include/libtorrent/create_torrent.hpp +++ b/include/libtorrent/create_torrent.hpp @@ -69,7 +69,10 @@ namespace libtorrent struct TORRENT_EXPORT create_torrent { - create_torrent(file_storage& fs, int piece_size = 0, int pad_file_limit = -1); + enum { optimize = 1 }; + + create_torrent(file_storage& fs, int piece_size = 0 + , int pad_file_limit = -1, int flags = optimize); create_torrent(torrent_info const& ti); entry generate() const; diff --git a/src/create_torrent.cpp b/src/create_torrent.cpp index f74cb1ae7..3a980c368 100644 --- a/src/create_torrent.cpp +++ b/src/create_torrent.cpp @@ -85,7 +85,7 @@ namespace libtorrent } } - create_torrent::create_torrent(file_storage& fs, int piece_size, int pad_file_limit) + create_torrent::create_torrent(file_storage& fs, int piece_size, int pad_file_limit, int flags) : m_files(fs) , m_creation_date(pt::second_clock::universal_time()) , m_multifile(fs.num_files() > 1) @@ -125,7 +125,8 @@ namespace libtorrent } #endif m_files.set_piece_length(piece_size); - m_files.optimize(pad_file_limit); + if (flags & optimize) + m_files.optimize(pad_file_limit); m_files.set_num_pieces(static_cast( (m_files.total_size() + m_files.piece_length() - 1) / m_files.piece_length())); m_piece_hash.resize(m_files.num_pieces()); diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 19af8b651..367a5a30d 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -233,7 +233,7 @@ void test_remove(path const& test_path) fs.add_file("temp_storage/folder2/test3.tmp", 0); fs.add_file("temp_storage/_folder3/test4.tmp", 0); fs.add_file("temp_storage/_folder3/subfolder/test5.tmp", 8); - libtorrent::create_torrent t(fs, 4); + libtorrent::create_torrent t(fs, 4, -1, 0); char buf[4] = {0, 0, 0, 0}; sha1_hash h = hasher(buf, 4).final(); @@ -287,7 +287,7 @@ void test_check_files(path const& test_path std::generate(piece0, piece0 + piece_size, std::rand); std::generate(piece2, piece2 + piece_size, std::rand); - libtorrent::create_torrent t(fs, piece_size); + libtorrent::create_torrent t(fs, piece_size, -1, 0); t.set_hash(0, hasher(piece0, piece_size).final()); t.set_hash(1, sha1_hash(0)); t.set_hash(2, sha1_hash(0)); @@ -350,7 +350,7 @@ void run_test(path const& test_path) fs.add_file("temp_storage/test4.tmp", 0); fs.add_file("temp_storage/test5.tmp", 1); - libtorrent::create_torrent t(fs, piece_size); + libtorrent::create_torrent t(fs, piece_size, -1, 0); t.set_hash(0, hasher(piece0, piece_size).final()); t.set_hash(1, hasher(piece1, piece_size).final()); t.set_hash(2, hasher(piece2, piece_size).final()); @@ -376,7 +376,7 @@ void run_test(path const& test_path) { file_storage fs; fs.add_file("temp_storage/test1.tmp", 17 + 612 + 1); - libtorrent::create_torrent t(fs, piece_size); + libtorrent::create_torrent t(fs, piece_size, -1, 0); TEST_CHECK(fs.begin()->path == "temp_storage/test1.tmp"); t.set_hash(0, hasher(piece0, piece_size).final()); t.set_hash(1, hasher(piece1, piece_size).final());