diff --git a/test/test_block_cache.cpp b/test/test_block_cache.cpp index 4f587bcbd..bca792bfb 100644 --- a/test/test_block_cache.cpp +++ b/test/test_block_cache.cpp @@ -45,6 +45,8 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; +namespace { + struct test_storage_impl : storage_interface { explicit test_storage_impl(file_storage const& fs) : storage_interface(fs) {} @@ -463,6 +465,8 @@ void test_unaligned_read() bc.clear(jobs); } +} // anonymous namespace + TORRENT_TEST(block_cache) { test_write(); diff --git a/test/test_fast_extension.cpp b/test/test_fast_extension.cpp index 75d26c2a7..915eccc45 100644 --- a/test/test_fast_extension.cpp +++ b/test/test_fast_extension.cpp @@ -54,6 +54,8 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; using namespace std::placeholders; +namespace { + void log(char const* fmt, ...) { va_list v; @@ -469,6 +471,8 @@ std::shared_ptr setup_peer(tcp::socket& s, sha1_hash& ih return t; } +} // anonymous namespace + // makes sure that pieces that are allowed and then // rejected aren't requested again TORRENT_TEST(reject_fast) diff --git a/test/test_ip_voter.cpp b/test/test_ip_voter.cpp index fd15c6ed7..4f22154ea 100644 --- a/test/test_ip_voter.cpp +++ b/test/test_ip_voter.cpp @@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; +namespace { + bool cast_vote(ip_voter& ipv, address ext_ip, address voter) { bool new_ip = ipv.cast_vote(ext_ip, aux::session_interface::source_dht, voter); @@ -56,6 +58,8 @@ bool cast_vote(ip_voter& ipv, address ext_ip, address voter) return new_ip; } +} // anonymous namespace + // test the case where every time we get a new IP. Make sure // we don't flap TORRENT_TEST(test_random) diff --git a/test/test_lsd.cpp b/test/test_lsd.cpp index b85c708a6..7734eb71f 100644 --- a/test/test_lsd.cpp +++ b/test/test_lsd.cpp @@ -41,6 +41,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "setup_transfer.hpp" #include +namespace { + void test_lsd() { using namespace lt; @@ -97,6 +99,8 @@ void test_lsd() p2 = ses2.abort(); } +} // anonymous namespace + TORRENT_TEST(lsd) { using namespace lt; diff --git a/test/test_remap_files.cpp b/test/test_remap_files.cpp index 41918a9ce..84d4e53ef 100644 --- a/test/test_remap_files.cpp +++ b/test/test_remap_files.cpp @@ -51,7 +51,7 @@ namespace { bool all_of(std::vector const& v) { - return std::all_of(v.begin(), v.end(), [](bool v){ return v; }); + return std::all_of(v.begin(), v.end(), [](bool val){ return val; }); } void test_remap_files(storage_mode_t storage_mode = storage_mode_sparse) @@ -109,9 +109,9 @@ void test_remap_files(storage_mode_t storage_mode = storage_mode_sparse) // wait for all alerts to come back and verify the data against the expected // piece data - aux::vector pieces(fs.num_pieces(), false); - aux::vector passed(fs.num_pieces(), false); - aux::vector files(fs.num_files(), false); + aux::vector pieces(std::size_t(fs.num_pieces()), false); + aux::vector passed(std::size_t(fs.num_pieces()), false); + aux::vector files(std::size_t(fs.num_files()), false); while (!all_of(pieces) || !all_of(passed) || !all_of(files)) { @@ -132,7 +132,7 @@ void test_remap_files(storage_mode_t storage_mode = storage_mode_sparse) TEST_EQUAL(t->piece_size(idx), rp->size); std::vector const piece = generate_piece(idx, t->piece_size(idx)); - TEST_CHECK(memcmp(rp->buffer.get(), piece.data(), rp->size) == 0); + TEST_CHECK(std::memcmp(rp->buffer.get(), piece.data(), std::size_t(rp->size)) == 0); TEST_CHECK(pieces[idx] == false); pieces[idx] = true; } @@ -187,8 +187,8 @@ void test_remap_files(storage_mode_t storage_mode = storage_mode_sparse) for (int i = 0; i < 50; ++i) { - torrent_status st = tor1.status(); - if (st.is_seeding) break; + torrent_status st1 = tor1.status(); + if (st1.is_seeding) break; std::this_thread::sleep_for(lt::milliseconds(100)); print_alerts(ses, "ses"); } diff --git a/test/test_remove_torrent.cpp b/test/test_remove_torrent.cpp index faf203490..b20d09eb9 100644 --- a/test/test_remove_torrent.cpp +++ b/test/test_remove_torrent.cpp @@ -49,6 +49,8 @@ using namespace libtorrent; namespace lt = libtorrent; using std::ignore; +namespace { + enum test_case { complete_download, partial_download, @@ -167,6 +169,8 @@ void test_remove_torrent(remove_flags_t const remove_options sp.push_back(ses2.abort()); } +} // anonymous namespace + TORRENT_TEST(remove_torrent) { test_remove_torrent({}); diff --git a/test/test_resolve_links.cpp b/test/test_resolve_links.cpp index e1028a3d8..c3c7e6d26 100644 --- a/test/test_resolve_links.cpp +++ b/test/test_resolve_links.cpp @@ -119,15 +119,15 @@ TORRENT_TEST(resolve_links) if (num_matches > e.expected_matches) { file_storage const& fs = ti1->files(); - for (file_index_t i{0}; i != links.end_index(); ++i) + for (file_index_t idx{0}; idx != links.end_index(); ++idx) { - TORRENT_ASSERT(i < file_index_t{fs.num_files()}); + TORRENT_ASSERT(idx < file_index_t{fs.num_files()}); std::printf("%*s --> %s : %d\n" - , int(fs.file_name(i).size()) - , fs.file_name(i).data() - , links[i].ti - ? aux::to_hex(links[i].ti->info_hash()).c_str() - : "", static_cast(links[i].file_idx)); + , int(fs.file_name(idx).size()) + , fs.file_name(idx).data() + , links[idx].ti + ? aux::to_hex(links[idx].ti->info_hash()).c_str() + : "", static_cast(links[idx].file_idx)); } } diff --git a/test/test_resume.cpp b/test/test_resume.cpp index 7d7e3a2a2..f9553c6f4 100644 --- a/test/test_resume.cpp +++ b/test/test_resume.cpp @@ -52,6 +52,8 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; +namespace { + torrent_flags_t const flags_mask = torrent_flags::sequential_download | torrent_flags::paused @@ -77,7 +79,7 @@ std::shared_ptr generate_torrent() for (piece_index_t i(0); i < fs.end_piece(); ++i) { sha1_hash ph; - for (int k = 0; k < 20; ++k) ph[k] = lt::random(0xff); + aux::random_bytes(ph); t.set_hash(i, ph); } @@ -94,8 +96,8 @@ std::vector generate_resume_data(torrent_info* ti rd["file-format"] = "libtorrent resume file"; rd["file-version"] = 1; rd["info-hash"] = ti->info_hash().to_string(); - rd["blocks per piece"] = (std::max)(1, ti->piece_length() / 0x4000); - rd["pieces"] = std::string(ti->num_pieces(), '\x01'); + rd["blocks per piece"] = std::max(1, ti->piece_length() / 0x4000); + rd["pieces"] = std::string(std::size_t(ti->num_pieces()), '\x01'); rd["total_uploaded"] = 1337; rd["total_downloaded"] = 1338; @@ -117,7 +119,7 @@ std::vector generate_resume_data(torrent_info* ti file_prio.push_back(entry(file_priorities[i] - '0')); } - rd["piece_priority"] = std::string(ti->num_pieces(), '\x01'); + rd["piece_priority"] = std::string(std::size_t(ti->num_pieces()), '\x01'); rd["auto_managed"] = 0; rd["sequential_download"] = 0; rd["paused"] = 0; @@ -187,7 +189,7 @@ torrent_handle test_resume_flags(lt::session& ses { aux::vector priorities_vector; for (int i = 0; file_priorities[i]; ++i) - priorities_vector.push_back(download_priority_t(file_priorities[i] - '0')); + priorities_vector.push_back(download_priority_t(aux::numeric_cast(file_priorities[i] - '0'))); p.file_priorities = priorities_vector; } @@ -274,6 +276,8 @@ void test_piece_priorities(bool test_deprecated = false) TEST_EQUAL(h.piece_priority(piece_index_t(ti->num_pieces()-1)), 0_pri); } +} // anonymous namespace + #ifndef TORRENT_NO_DEPRECATE TORRENT_TEST(piece_priorities_deprecated) { @@ -296,9 +300,9 @@ TORRENT_TEST(piece_slots) { std::vector a(128 * 1024 * 8); std::vector b(128 * 1024); - std::ofstream("add_torrent_params_test/test_resume/tmp1").write(a.data(), a.size()); - std::ofstream("add_torrent_params_test/test_resume/tmp2").write(b.data(), b.size()); - std::ofstream("add_torrent_params_test/test_resume/tmp3").write(b.data(), b.size()); + std::ofstream("add_torrent_params_test/test_resume/tmp1").write(a.data(), std::streamsize(a.size())); + std::ofstream("add_torrent_params_test/test_resume/tmp2").write(b.data(), std::streamsize(b.size())); + std::ofstream("add_torrent_params_test/test_resume/tmp3").write(b.data(), std::streamsize(b.size())); } add_torrent_params p; @@ -353,9 +357,9 @@ void test_piece_slots_seed(settings_pack const& sett) { std::vector a(128 * 1024 * 8); std::vector b(128 * 1024); - std::ofstream("add_torrent_params_test/test_resume/tmp1").write(a.data(), a.size()); - std::ofstream("add_torrent_params_test/test_resume/tmp2").write(b.data(), b.size()); - std::ofstream("add_torrent_params_test/test_resume/tmp3").write(b.data(), b.size()); + std::ofstream("add_torrent_params_test/test_resume/tmp1").write(a.data(), std::streamsize(a.size())); + std::ofstream("add_torrent_params_test/test_resume/tmp2").write(b.data(), std::streamsize(b.size())); + std::ofstream("add_torrent_params_test/test_resume/tmp3").write(b.data(), std::streamsize(b.size())); } add_torrent_params p; @@ -838,10 +842,10 @@ void test_zero_file_prio(bool test_deprecated = false) file_prio.push_back(entry(0)); } - std::string pieces(ti->num_pieces(), '\x01'); + std::string pieces(std::size_t(ti->num_pieces()), '\x01'); rd["pieces"] = pieces; - std::string pieces_prio(ti->num_pieces(), '\x01'); + std::string pieces_prio(std::size_t(ti->num_pieces()), '\x01'); rd["piece_priority"] = pieces_prio; std::vector resume_data; @@ -968,14 +972,14 @@ void test_seed_mode(test_mode_t const flags) } } - std::string pieces(ti->num_pieces(), '\x01'); + std::string pieces(std::size_t(ti->num_pieces()), '\x01'); if (flags & test_mode::pieces_have) { pieces[0] = '\0'; } rd["pieces"] = pieces; - std::string pieces_prio(ti->num_pieces(), '\x01'); + std::string pieces_prio(std::size_t(ti->num_pieces()), '\x01'); if (flags & test_mode::piece_prio) { pieces_prio[0] = '\0'; diff --git a/test/test_session.cpp b/test/test_session.cpp index c6c4cb800..b82ac6f1a 100644 --- a/test/test_session.cpp +++ b/test/test_session.cpp @@ -217,7 +217,7 @@ TORRENT_TEST(session_stats) // make sure every stat index is represented in the stats_metric vector for (int i = 0; i < int(stats.size()); ++i) { - TEST_EQUAL(stats[i].value_index, i); + TEST_EQUAL(stats[std::size_t(i)].value_index, i); } TEST_EQUAL(lt::find_metric_idx("peer.incoming_connections") @@ -468,7 +468,6 @@ auto const count_dht_inits = [](session& ses) } if (num <= 0) return count; } - return count; }; TORRENT_TEST(init_dht_default_bootstrap) diff --git a/test/test_storage.cpp b/test/test_storage.cpp index e5ea10f15..a3ac9717d 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -58,23 +58,11 @@ POSSIBILITY OF SUCH DAMAGE. using namespace std::placeholders; using namespace lt; +namespace { + std::size_t const piece_size = 16 * 1024 * 16; std::size_t const half = piece_size / 2; -void signal_bool(bool* b, char const* string) -{ - *b = true; - std::cout << time_now_string() << " " << string << std::endl; -} - -void on_read_piece(int ret, disk_io_job const& j, char const* data, int size) -{ - std::cout << time_now_string() << " on_read_piece piece: " << j.piece << std::endl; - TEST_EQUAL(ret, size); - auto& buffer = boost::get(j.argument); - if (ret > 0) TEST_CHECK(std::equal(buffer.get(), buffer.get() + ret, data)); -} - void on_check_resume_data(status_t const status, storage_error const& error, bool* done) { std::cout << time_now_string() << " on_check_resume_data ret: " @@ -746,6 +734,8 @@ void test_fastresume(bool const test_deprecated) << "': " << ec.message() << std::endl; } +} // anonymous namespace + TORRENT_TEST(fastresume) { test_fastresume(false); diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index 53bf928f1..2c8d5820a 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -830,24 +830,24 @@ TORRENT_TEST(parse_torrents) } file_storage const& fs = ti->files(); - for (file_index_t i{0}; i != file_index_t(fs.num_files()); ++i) + for (file_index_t idx{0}; idx != file_index_t(fs.num_files()); ++idx) { - piece_index_t const first = ti->map_file(i, 0, 0).piece; - piece_index_t const last = ti->map_file(i, std::max(fs.file_size(i)-1, std::int64_t(0)), 0).piece; - file_flags_t const flags = fs.file_flags(i); - sha1_hash const ih = fs.hash(i); + piece_index_t const first = ti->map_file(idx, 0, 0).piece; + piece_index_t const last = ti->map_file(idx, std::max(fs.file_size(idx)-1, std::int64_t(0)), 0).piece; + file_flags_t const flags = fs.file_flags(idx); + sha1_hash const ih = fs.hash(idx); std::printf(" %11" PRId64 " %c%c%c%c [ %4d, %4d ] %7u %s %s %s%s\n" - , fs.file_size(i) + , fs.file_size(idx) , (flags & file_storage::flag_pad_file)?'p':'-' , (flags & file_storage::flag_executable)?'x':'-' , (flags & file_storage::flag_hidden)?'h':'-' , (flags & file_storage::flag_symlink)?'l':'-' , static_cast(first), static_cast(last) - , std::uint32_t(fs.mtime(i)) + , std::uint32_t(fs.mtime(idx)) , ih != sha1_hash(nullptr) ? aux::to_hex(ih).c_str() : "" - , fs.file_path(i).c_str() + , fs.file_path(idx).c_str() , flags & file_storage::flag_symlink ? "-> ": "" - , flags & file_storage::flag_symlink ? fs.symlink(i).c_str() : ""); + , flags & file_storage::flag_symlink ? fs.symlink(idx).c_str() : ""); } } @@ -911,7 +911,7 @@ void test_resolve_duplicates(int test_case) torrent_info ti(tmp, from_span); - std::vector> const filenames + aux::vector> const filenames { { // case 0 "test/temporary.txt", @@ -1017,7 +1017,7 @@ TORRENT_TEST(copy) // clear out the buffer for a, just to make sure b doesn't have any // references into it by mistake int s = a->metadata_size(); - std::memset(a->metadata().get(), 0, s); + std::memset(a->metadata().get(), 0, std::size_t(s)); a.reset(); diff --git a/test/test_transfer.cpp b/test/test_transfer.cpp index dd503357a..ffb803235 100644 --- a/test/test_transfer.cpp +++ b/test/test_transfer.cpp @@ -53,6 +53,8 @@ using namespace lt; using std::ignore; +namespace { + auto const mask = alert::all_categories & ~(alert::performance_warning | alert::stats_notification); @@ -77,8 +79,8 @@ struct test_storage : default_storage , m_limit(16 * 1024 * 2) {} - void set_file_priority(aux::vector const& p - , storage_error& ec) override {} + void set_file_priority(aux::vector const& + , storage_error&) override {} void set_limit(int lim) { @@ -175,21 +177,21 @@ void test_transfer(int proxy_type, settings_pack const& sett { proxy_port = start_proxy(proxy_type); - settings_pack pack; - pack.set_str(settings_pack::proxy_username, "testuser"); - pack.set_str(settings_pack::proxy_password, "testpass"); - pack.set_int(settings_pack::proxy_type, proxy_type); - pack.set_int(settings_pack::proxy_port, proxy_port); - pack.set_bool(settings_pack::force_proxy, true); + settings_pack pack_p; + pack_p.set_str(settings_pack::proxy_username, "testuser"); + pack_p.set_str(settings_pack::proxy_password, "testpass"); + pack_p.set_int(settings_pack::proxy_type, proxy_type); + pack_p.set_int(settings_pack::proxy_port, proxy_port); + pack_p.set_bool(settings_pack::force_proxy, true); // test resetting the proxy in quick succession. // specifically the udp_socket connecting to a new // socks5 proxy while having one connection attempt // in progress. - pack.set_str(settings_pack::proxy_hostname, "5.6.7.8"); - ses1.apply_settings(pack); - pack.set_str(settings_pack::proxy_hostname, "127.0.0.1"); - ses1.apply_settings(pack); + pack_p.set_str(settings_pack::proxy_hostname, "5.6.7.8"); + ses1.apply_settings(pack_p); + pack_p.set_str(settings_pack::proxy_hostname, "127.0.0.1"); + ses1.apply_settings(pack_p); } pack = sett; @@ -264,7 +266,7 @@ void test_transfer(int proxy_type, settings_pack const& sett , (flags & disk_full) ? &addp : ¶ms); int num_pieces = tor2.torrent_file()->num_pieces(); - std::vector priorities(num_pieces, 1); + std::vector priorities(std::size_t(num_pieces), 1); int upload_mode_timer = 0; @@ -319,7 +321,7 @@ void test_transfer(int proxy_type, settings_pack const& sett && ++upload_mode_timer > 10) { flags &= ~disk_full; - ((test_storage*)tor2.get_storage_impl())->set_limit(16 * 1024 * 1024); + static_cast(tor2.get_storage_impl())->set_limit(16 * 1024 * 1024); // if we reset the upload mode too soon, there may be more disk // jobs failing right after, putting us back in upload mode. So, @@ -340,8 +342,8 @@ void test_transfer(int proxy_type, settings_pack const& sett // at this point we probably disconnected the seed // so we need to reconnect as well std::printf("%s: reconnecting peer\n", time_now_string()); - error_code ec; - tor2.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec) + error_code ec2; + tor2.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec2) , ses1.listen_port())); TEST_CHECK(tor2.status().is_finished == false); @@ -387,6 +389,8 @@ void cleanup() remove_all("tmp2_transfer_moved", ec); } +} // anonymous namespace + #ifndef TORRENT_NO_DEPRECATE TORRENT_TEST(no_contiguous_buffers) { diff --git a/test/test_upnp.cpp b/test/test_upnp.cpp index 81f5d3441..0dd860e72 100644 --- a/test/test_upnp.cpp +++ b/test/test_upnp.cpp @@ -119,7 +119,7 @@ std::list callbacks; namespace // TODO: remove this nested namespace { - struct upnp_callback : aux::portmap_callback + struct upnp_callback final : aux::portmap_callback { void on_port_mapping(port_mapping_t const mapping , address const& ip, int port @@ -134,12 +134,12 @@ namespace // TODO: remove this nested namespace << ", error: \"" << err.message() << "\"\n"; } #ifndef TORRENT_DISABLE_LOGGING - virtual bool should_log_portmap(portmap_transport) const override + bool should_log_portmap(portmap_transport) const override { return true; } - virtual void log_portmap(portmap_transport, char const* msg) const override + void log_portmap(portmap_transport, char const* msg) const override { std::cout << "UPnP: " << msg << std::endl; //TODO: store the log and verify that some key messages are there