diff --git a/include/libtorrent/alert_manager.hpp b/include/libtorrent/alert_manager.hpp index fe07ba38a..7a9b9dd50 100644 --- a/include/libtorrent/alert_manager.hpp +++ b/include/libtorrent/alert_manager.hpp @@ -135,9 +135,7 @@ namespace libtorrent { // this mutex protects everything. Since it's held while executing user // callbacks (the notify function and extension on_alert()) it must be - // recursive to post new alerts. This is implemented by storing the - // current thread-id in m_mutex_holder, if it matches ours, we don't need - // to lock + // recursive to support recursively post new alerts. mutable std::recursive_mutex m_mutex; std::condition_variable_any m_condition; std::atomic m_alert_mask; diff --git a/simulation/test_swarm.cpp b/simulation/test_swarm.cpp index 49a084133..31b56dad8 100644 --- a/simulation/test_swarm.cpp +++ b/simulation/test_swarm.cpp @@ -96,6 +96,25 @@ TORRENT_TEST(seed_mode_disable_hash_checks) { return false; }); } +TORRENT_TEST(seed_mode_suggest) +{ + setup_swarm(2, swarm_test::upload + // add session + , [](lt::settings_pack& pack) { + pack.set_int(settings_pack::suggest_mode, settings_pack::suggest_read_cache); + pack.set_int(settings_pack::cache_size, 2); + } + // add torrent + , [](lt::add_torrent_params& params) { + params.flags |= torrent_flags::seed_mode; + } + // on alert + , [](lt::alert const* a, lt::session& ses) {} + // terminate + , [](int ticks, lt::session& ses) -> bool + { return true; }); +} + TORRENT_TEST(plain) { setup_swarm(2, swarm_test::download @@ -167,6 +186,7 @@ TORRENT_TEST(suggest) , [](lt::settings_pack& pack) { pack.set_int(settings_pack::suggest_mode, settings_pack::suggest_read_cache); pack.set_int(settings_pack::max_suggest_pieces, 10); + pack.set_int(settings_pack::cache_size, 2); } // add torrent , [](lt::add_torrent_params&) {} @@ -362,7 +382,7 @@ TORRENT_TEST(stop_start_seed_graceful) TORRENT_TEST(shutdown) { - setup_swarm(2, swarm_test::download + setup_swarm(4, swarm_test::download // add session , [](lt::settings_pack&) {} // add torrent diff --git a/test/test_create_torrent.cpp b/test/test_create_torrent.cpp index d13464a76..9820d211d 100644 --- a/test/test_create_torrent.cpp +++ b/test/test_create_torrent.cpp @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/torrent_info.hpp" #include "libtorrent/create_torrent.hpp" #include "libtorrent/bencode.hpp" +#include "libtorrent/announce_entry.hpp" #include "libtorrent/aux_/escape_string.hpp" // for convert_path_to_posix #include "libtorrent/announce_entry.hpp" @@ -98,3 +99,23 @@ TORRENT_TEST(piece_size) } } +TORRENT_TEST(create_torrent_round_trip) +{ + char const test_torrent[] = "d8:announce26:udp://testurl.com/announce7:comment22:this is a test comment13:creation datei1337e4:infod6:lengthi12345e4:name6:foobar12:piece lengthi65536e6:pieces20:ababababababababababee"; + lt::torrent_info info1(test_torrent, lt::from_span); + TEST_EQUAL(info1.comment(), "this is a test comment"); + TEST_EQUAL(info1.trackers().size(), 1); + TEST_EQUAL(info1.trackers().front().url, "udp://testurl.com/announce"); + + lt::create_torrent t(info1); + + std::vector buffer; + lt::bencode(std::back_inserter(buffer), t.generate()); + lt::torrent_info info2(buffer, lt::from_span); + + TEST_EQUAL(info2.comment(), "this is a test comment"); + TEST_EQUAL(info2.trackers().size(), 1); + TEST_EQUAL(info2.trackers().front().url, "udp://testurl.com/announce"); + TEST_CHECK(info1.info_hash() == info2.info_hash()); +} +