diff --git a/test/test_alert_manager.cpp b/test/test_alert_manager.cpp index e4e58cc87..850bb52ff 100644 --- a/test/test_alert_manager.cpp +++ b/test/test_alert_manager.cpp @@ -100,10 +100,12 @@ TORRENT_TEST(priority_limit) TEST_EQUAL(alerts.size(), 200); } +namespace { void test_notify_fun(int& cnt) { ++cnt; } +} // anonymous namespace TORRENT_TEST(notify_function) { @@ -148,6 +150,7 @@ TORRENT_TEST(notify_function) } #ifndef TORRENT_DISABLE_EXTENSIONS +namespace { int plugin_alerts[3] = { 0, 0, 0 }; struct test_plugin : lt::plugin @@ -159,7 +162,7 @@ struct test_plugin : lt::plugin } int m_index; }; - +} // anonymous namespace #endif TORRENT_TEST(extensions) @@ -271,4 +274,3 @@ TORRENT_TEST(dropped_alerts) // it should have been cleared now though TEST_CHECK(mgr.dropped_alerts().none()); } - diff --git a/test/test_auto_unchoke.cpp b/test/test_auto_unchoke.cpp index 42a1a6c35..6b3ce3c67 100644 --- a/test/test_auto_unchoke.cpp +++ b/test/test_auto_unchoke.cpp @@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "test.hpp" #include "setup_transfer.hpp" +namespace { + void test_swarm() { using namespace lt; @@ -136,6 +138,8 @@ void test_swarm() p3 = ses3.abort(); } +} // anonymous namespace + TORRENT_TEST(auto_unchoke) { using namespace lt; @@ -156,4 +160,3 @@ TORRENT_TEST(auto_unchoke) remove_all("./tmp2_unchoke", ec); remove_all("./tmp3_unchoke", ec); } - diff --git a/test/test_bandwidth_limiter.cpp b/test/test_bandwidth_limiter.cpp index 898993bdb..986b4e217 100644 --- a/test/test_bandwidth_limiter.cpp +++ b/test/test_bandwidth_limiter.cpp @@ -73,7 +73,6 @@ struct peer_connection: bandwidth_socket, std::enable_shared_from_this section = e.data_section(); - TEST_CHECK(std::memcmp(b, section.first, section.second) == 0); + TEST_CHECK(std::memcmp(b, section.first, std::size_t(section.second)) == 0); TEST_CHECK(section.second == sizeof(b) - 1); TEST_CHECK(e.type() == lazy_entry::int_t); TEST_CHECK(e.int_value() == 12453); @@ -166,7 +170,7 @@ TORRENT_TEST(lazy_entry) TEST_CHECK(ret == 0); std::printf("%s\n", print_entry(e).c_str()); std::pair section = e.data_section(); - TEST_CHECK(std::memcmp(b, section.first, section.second) == 0); + TEST_CHECK(std::memcmp(b, section.first, std::size_t(section.second)) == 0); TEST_CHECK(section.second == sizeof(b) - 1); TEST_CHECK(e.type() == lazy_entry::string_t); TEST_CHECK(e.string_value() == std::string("abcdefghijklmnopqrstuvwxyz")); @@ -181,7 +185,7 @@ TORRENT_TEST(lazy_entry) TEST_CHECK(ret == 0); std::printf("%s\n", print_entry(e).c_str()); std::pair section = e.data_section(); - TEST_CHECK(std::memcmp(b, section.first, section.second) == 0); + TEST_CHECK(std::memcmp(b, section.first, std::size_t(section.second)) == 0); TEST_CHECK(section.second == sizeof(b) - 1); TEST_CHECK(e.type() == lazy_entry::list_t); TEST_CHECK(e.list_size() == 2); @@ -191,7 +195,7 @@ TORRENT_TEST(lazy_entry) TEST_CHECK(e.list_at(1)->string_value() == std::string("aaa")); TEST_CHECK(e.list_at(1)->string_length() == 3); section = e.list_at(1)->data_section(); - TEST_CHECK(std::memcmp("3:aaa", section.first, section.second) == 0); + TEST_CHECK(std::memcmp("3:aaa", section.first, std::size_t(section.second)) == 0); TEST_CHECK(section.second == 5); } @@ -203,7 +207,7 @@ TORRENT_TEST(lazy_entry) TEST_CHECK(ret == 0); std::printf("%s\n", print_entry(e).c_str()); std::pair section = e.data_section(); - TEST_CHECK(std::memcmp(b, section.first, section.second) == 0); + TEST_CHECK(std::memcmp(b, section.first, std::size_t(section.second)) == 0); TEST_CHECK(section.second == sizeof(b) - 1); TEST_CHECK(e.type() == lazy_entry::dict_t); TEST_CHECK(e.dict_size() == 4); @@ -309,7 +313,7 @@ TORRENT_TEST(lazy_entry) std::printf("%s\n", buf); lazy_entry e; error_code ec; - int ret = lazy_bdecode((char*)buf, (char*)buf + sizeof(buf), e, ec); + int ret = lazy_bdecode(reinterpret_cast(buf), reinterpret_cast(buf) + sizeof(buf), e, ec); TEST_CHECK(ret == -1); } @@ -492,7 +496,7 @@ TORRENT_TEST(lazy_entry) std::printf("%s\n", print_entry(e).c_str()); pascal_string ps = e.dict_find_pstr("foobar"); - TEST_EQUAL(memcmp(ps.ptr, "barfoo", ps.len), 0); + TEST_EQUAL(std::memcmp(ps.ptr, "barfoo", std::size_t(ps.len)), 0); TEST_EQUAL(ps.len, 6); ps = e.dict_find_pstr("foobar2"); @@ -512,7 +516,7 @@ TORRENT_TEST(lazy_entry) TEST_EQUAL(e.list_size(), 2); pascal_string ps = e.list_pstr_at(0); - TEST_EQUAL(memcmp(ps.ptr, "foobar", ps.len), 0); + TEST_EQUAL(std::memcmp(ps.ptr, "foobar", std::size_t(ps.len)), 0); TEST_EQUAL(ps.len, 6); ps = e.list_pstr_at(1); @@ -539,7 +543,7 @@ TORRENT_TEST(lazy_entry) lazy_entry e; error_code ec; - int ret = lazy_bdecode((char*)&buf[0], (char*)&buf[0] + buf.size(), e, ec); + int ret = lazy_bdecode(buf.data(), buf.data() + buf.size(), e, ec); TEST_EQUAL(ret, 0); TEST_EQUAL(e.type(), lazy_entry::list_t); TEST_EQUAL(e.list_size(), 1000); @@ -563,7 +567,7 @@ TORRENT_TEST(lazy_entry) std::printf("%s\n", buf.c_str()); lazy_entry e; error_code ec; - int ret = lazy_bdecode((char*)&buf[0], (char*)&buf[0] + buf.size(), e, ec); + int ret = lazy_bdecode(buf.data(), buf.data() + buf.size(), e, ec); TEST_EQUAL(ret, 0); TEST_EQUAL(e.type(), lazy_entry::dict_t); TEST_EQUAL(e.dict_size(), 1000); @@ -635,4 +639,3 @@ TORRENT_TEST(lazy_entry) } } #endif // TORRENT_NO_DEPRECATE - diff --git a/test/test_bitfield.cpp b/test/test_bitfield.cpp index 138899b1a..c4ee6bfea 100644 --- a/test/test_bitfield.cpp +++ b/test/test_bitfield.cpp @@ -131,7 +131,7 @@ TORRENT_TEST(bitfield) TEST_EQUAL(test1.count(), 101); std::uint8_t b1[] = { 0x08, 0x10 }; - test1.assign((char*)b1, 14); + test1.assign(reinterpret_cast(b1), 14); print_bitfield(test1); TEST_EQUAL(test1.count(), 2); TEST_EQUAL(test1.get_bit(3), false); diff --git a/test/test_block_cache.cpp b/test/test_block_cache.cpp index bca792bfb..fd17bf0bf 100644 --- a/test/test_block_cache.cpp +++ b/test/test_block_cache.cpp @@ -50,31 +50,31 @@ namespace { struct test_storage_impl : storage_interface { explicit test_storage_impl(file_storage const& fs) : storage_interface(fs) {} - void initialize(storage_error& ec) override {} + void initialize(storage_error&) override {} int readv(span bufs - , piece_index_t piece, int offset, open_mode_t flags, storage_error& ec) override + , piece_index_t, int /*offset*/, open_mode_t, storage_error&) override { return bufs_size(bufs); } int writev(span bufs - , piece_index_t piece, int offset, open_mode_t flags, storage_error& ec) override + , piece_index_t, int /*offset*/, open_mode_t, storage_error&) override { return bufs_size(bufs); } - bool has_any_file(storage_error& ec) override { return false; } - void set_file_priority(aux::vector const& prio - , storage_error& ec) override {} - status_t move_storage(std::string const& save_path, move_flags_t flags - , storage_error& ec) override { return status_t::no_error; } - bool verify_resume_data(add_torrent_params const& rd - , aux::vector const& links - , storage_error& ec) override { return true; } - void release_files(storage_error& ec) override {} - void rename_file(file_index_t index, std::string const& new_filename - , storage_error& ec) override {} - void delete_files(remove_flags_t, storage_error& ec) override {} + bool has_any_file(storage_error&) override { return false; } + void set_file_priority(aux::vector const& + , storage_error&) override {} + status_t move_storage(std::string const&, move_flags_t + , storage_error&) override { return status_t::no_error; } + bool verify_resume_data(add_torrent_params const& + , aux::vector const& + , storage_error&) override { return true; } + void release_files(storage_error&) override {} + void rename_file(file_index_t, std::string const& + , storage_error&) override {} + void delete_files(remove_flags_t, storage_error&) override {} }; struct allocator : buffer_allocator_interface @@ -90,6 +90,8 @@ struct allocator : buffer_allocator_interface for (auto ref : refs) m_cache.reclaim_block(m_storage, ref); } + + virtual ~allocator() = default; private: block_cache& m_cache; storage_interface* m_storage; @@ -509,4 +511,3 @@ TORRENT_TEST(delete_piece) TEST_CHECK(bc.num_pieces() == 0); } - diff --git a/test/test_bloom_filter.cpp b/test/test_bloom_filter.cpp index b034b9716..874d86b40 100644 --- a/test/test_bloom_filter.cpp +++ b/test/test_bloom_filter.cpp @@ -38,6 +38,8 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; +namespace { + void test_set_and_get() { bloom_filter<32> filter; @@ -120,6 +122,8 @@ void test_to_from_string() TEST_EQUAL(memcmp(compare, bits_out.c_str(), 4), 0); } +} // anonymous namespace + TORRENT_TEST(bloom_filter) { test_set_and_get(); @@ -130,4 +134,3 @@ TORRENT_TEST(bloom_filter) // TODO: test size() // TODO: test clear() } - diff --git a/test/test_dos_blocker.cpp b/test/test_dos_blocker.cpp index f0fb17be1..efbb93feb 100644 --- a/test/test_dos_blocker.cpp +++ b/test/test_dos_blocker.cpp @@ -71,6 +71,8 @@ struct log_t : lt::dht::dht_logger std::printf("%s [%s] %s", prefix[dir], print_endpoint(node).c_str() , msg.c_str()); } + + virtual ~log_t() = default; }; #endif @@ -100,4 +102,3 @@ TORRENT_TEST(dos_blocker) #endif #endif } - diff --git a/test/test_fast_extension.cpp b/test/test_fast_extension.cpp index 915eccc45..5e1244bbd 100644 --- a/test/test_fast_extension.cpp +++ b/test/test_fast_extension.cpp @@ -94,7 +94,7 @@ int read_message(tcp::socket& s, char* buffer, int max_size) return -1; } - boost::asio::read(s, boost::asio::buffer(buffer, length) + boost::asio::read(s, boost::asio::buffer(buffer, std::size_t(length)) , boost::asio::transfer_all(), ec); if (ec) { @@ -739,7 +739,7 @@ TORRENT_TEST(multiple_bitfields) print_session_log(*ses); std::string bitfield; - bitfield.resize(ti->num_pieces(), '0'); + bitfield.resize(std::size_t(ti->num_pieces()), '0'); send_bitfield(s, bitfield.c_str()); print_session_log(*ses); bitfield[0] = '1'; @@ -970,6 +970,8 @@ TORRENT_TEST(invalid_request) send_request(s, req); } +namespace { + void have_all_test(bool const incoming) { sha1_hash ih; @@ -1007,6 +1009,8 @@ void have_all_test(bool const incoming) } } +} // anonymous namespace + TORRENT_TEST(outgoing_have_all) { std::cout << "\n === test outgoing have-all ===\n" << std::endl; @@ -1023,4 +1027,3 @@ TORRENT_TEST(incoming_have_all) // TODO: test sending invalid requests (out of bound piece index, offsets and // sizes) - diff --git a/test/test_file.cpp b/test/test_file.cpp index 7b6433945..6e3afc763 100644 --- a/test/test_file.cpp +++ b/test/test_file.cpp @@ -51,7 +51,7 @@ int touch_file(std::string const& filename, int size) std::vector v; v.resize(aux::numeric_cast(size)); for (int i = 0; i < size; ++i) - v[i] = i & 255; + v[std::size_t(i)] = char(i & 255); file f; error_code ec; diff --git a/test/test_file_progress.cpp b/test/test_file_progress.cpp index 22c383c82..85ff7e3f0 100644 --- a/test/test_file_progress.cpp +++ b/test/test_file_progress.cpp @@ -65,11 +65,11 @@ TORRENT_TEST(init) aux::vector vec; fp.export_progress(vec); - std::uint64_t sum = 0; + std::int64_t sum = 0; for (file_index_t i(0); i < vec.end_index(); ++i) sum += vec[i]; - TEST_EQUAL(int(sum), fs.piece_size(idx)); + TEST_EQUAL(sum, fs.piece_size(idx)); } } @@ -96,11 +96,11 @@ TORRENT_TEST(init2) fp.init(picker, fs); fp.export_progress(vec); - std::uint64_t sum = 0; + std::int64_t sum = 0; for (file_index_t i(0); i < vec.end_index(); ++i) sum += vec[i]; - TEST_EQUAL(int(sum), fs.piece_size(idx)); + TEST_EQUAL(sum, fs.piece_size(idx)); } } diff --git a/test/test_file_storage.cpp b/test/test_file_storage.cpp index 20911a0d0..4703f9ca0 100644 --- a/test/test_file_storage.cpp +++ b/test/test_file_storage.cpp @@ -39,6 +39,8 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; +namespace { + void setup_test_storage(file_storage& st) { st.add_file(combine_path("test", "a"), 10000); @@ -76,6 +78,8 @@ void setup_test_storage(file_storage& st) TEST_EQUAL(st.num_pieces(), (100000 + 0x3fff) / 0x4000); } +} // anonymous namespace + TORRENT_TEST(coalesce_path) { file_storage st; @@ -426,6 +430,8 @@ TORRENT_TEST(piece_range) TEST_CHECK(aux::file_piece_range_exclusive(fs, file_index_t(1)) == std::make_tuple(piece_index_t(3), piece_index_t(7))); } +namespace { + void test_optimize(std::vector file_sizes , int const alignment , int const pad_file_limit @@ -462,12 +468,14 @@ void test_optimize(std::vector file_sizes else { TEST_EQUAL(fs.file_name(idx), std::to_string(expect)); - TEST_EQUAL(fs.file_size(idx), file_sizes[expect]); + TEST_EQUAL(fs.file_size(idx), file_sizes[std::size_t(expect)]); } ++idx; } } +} // anonymous namespace + TORRENT_TEST(optimize_order_large_first) { test_optimize({1000, 3000, 10000}, 1024, 1024, false, {2, -1, 1, 0}); @@ -618,4 +626,3 @@ TORRENT_TEST(map_block_mid) // TODO: test file attributes // TODO: test symlinks // TODO: test reorder_file (make sure internal_file_entry::swap() is used) - diff --git a/test/test_linked_list.cpp b/test/test_linked_list.cpp index 2b94fd2ea..783e11e80 100644 --- a/test/test_linked_list.cpp +++ b/test/test_linked_list.cpp @@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; +namespace { + struct test_node : list_node { explicit test_node(int v) : val(v) {} @@ -52,6 +54,8 @@ void compare(linked_list const& list, int* array, int size) } } +} // anonymous namespace + TORRENT_TEST(push_back) { test_node n0(0); @@ -195,4 +199,3 @@ TORRENT_TEST(iterate_backward) it.prev(); TEST_EQUAL(it.get(), static_cast(nullptr)); } - diff --git a/test/test_peer_list.cpp b/test/test_peer_list.cpp index c83dfceef..a25484ee5 100644 --- a/test/test_peer_list.cpp +++ b/test/test_peer_list.cpp @@ -49,6 +49,8 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; +namespace { + struct mock_torrent; struct mock_peer_connection @@ -64,7 +66,7 @@ struct mock_peer_connection , m_disconnect_called(false) , m_torrent(*tor) { - for (int i = 0; i < 20; ++i) m_id[i] = rand(); + aux::random_bytes(m_id); } virtual ~mock_peer_connection() = default; @@ -73,7 +75,7 @@ struct mock_peer_connection bool should_log(peer_log_alert::direction_t) const noexcept override { return true; } - void peer_log(peer_log_alert::direction_t dir, char const* event + void peer_log(peer_log_alert::direction_t, char const* /*event*/ , char const* fmt, ...) const noexcept override { va_list v; @@ -200,6 +202,8 @@ void connect_peer(peer_list& p, mock_torrent& t, torrent_state& st) static torrent_peer_allocator allocator; +} // anonymous namespace + // test multiple peers with the same IP // when disallowing it TORRENT_TEST(multiple_ips_disallowed) @@ -371,11 +375,13 @@ TORRENT_TEST(update_peer_port_collide) st.erased.clear(); } +namespace { std::shared_ptr shared_from_this(lt::peer_connection_interface* p) { return std::static_pointer_cast( static_cast(p)->shared_from_this()); } +} // anonymous namespace // test ip filter TORRENT_TEST(ip_filter) diff --git a/test/test_pex.cpp b/test/test_pex.cpp index 7606c3e7e..65bac455a 100644 --- a/test/test_pex.cpp +++ b/test/test_pex.cpp @@ -46,6 +46,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "setup_transfer.hpp" #include +namespace { + void test_pex() { using namespace lt; @@ -148,6 +150,7 @@ void test_pex() p2 = ses2.abort(); p3 = ses3.abort(); } +} // anonymous namespace #endif // TORRENT_DISABLE_EXTENSIONS TORRENT_TEST(pex) diff --git a/test/test_piece_picker.cpp b/test/test_piece_picker.cpp index 3a4b06d64..837c7dd75 100644 --- a/test/test_piece_picker.cpp +++ b/test/test_piece_picker.cpp @@ -527,14 +527,14 @@ TORRENT_TEST(pick_whole_pieces) , &peer_struct, options, empty_vector); TEST_EQUAL(int(picked.size()), 3); for (int i = 0; i < blocks_per_piece && i < int(picked.size()); ++i) - TEST_EQUAL(picked[i].piece_index, piece_index_t(2)); + TEST_EQUAL(picked[std::size_t(i)].piece_index, piece_index_t(2)); p = setup_picker("1111111", " ", "1111111", ""); picked = pick_pieces(p, "****** ", 1, blocks_per_piece , &peer_struct, options, empty_vector); TEST_EQUAL(int(picked.size()), blocks_per_piece); for (int i = 0; i < blocks_per_piece && i < int(picked.size()); ++i) - TEST_EQUAL(picked[i].block_index, i); + TEST_EQUAL(picked[std::size_t(i)].block_index, i); p = setup_picker("2221222", " ", "", ""); picked = pick_pieces(p, "*******", 1, 7 * blocks_per_piece diff --git a/test/test_priority.cpp b/test/test_priority.cpp index ce0d57845..39f1c456d 100644 --- a/test/test_priority.cpp +++ b/test/test_priority.cpp @@ -52,6 +52,8 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; using std::ignore; +namespace { + alert_category_t const mask = alert::all_categories & ~(alert::performance_warning | alert::stats_notification); int peer_disconnects = 0; @@ -386,6 +388,8 @@ done: sp.push_back(ses2.abort()); } +} // anonymous namespace + TORRENT_TEST(priority) { using namespace lt; diff --git a/test/test_read_piece.cpp b/test/test_read_piece.cpp index 858d421a2..2c4dc1ef7 100644 --- a/test/test_read_piece.cpp +++ b/test/test_read_piece.cpp @@ -39,6 +39,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/hex.hpp" // to_hex #include "libtorrent/aux_/path.hpp" +namespace { + enum flags_t { seed_mode = 1, @@ -149,6 +151,8 @@ void test_read_piece(int flags) , ec.value(), ec.message().c_str()); } +} // anonymous namespace + TORRENT_TEST(read_piece) { test_read_piece(0); @@ -163,4 +167,3 @@ TORRENT_TEST(time_critical) { test_read_piece(time_critical); } - diff --git a/test/test_read_resume.cpp b/test/test_read_resume.cpp index c96f4d8cf..1107e8d6f 100644 --- a/test/test_read_resume.cpp +++ b/test/test_read_resume.cpp @@ -170,6 +170,7 @@ TORRENT_TEST(read_resume_mismatching_torrent) TEST_CHECK(!atp.ti); } +namespace { std::shared_ptr generate_torrent() { file_storage fs; @@ -186,7 +187,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); } @@ -194,6 +195,7 @@ std::shared_ptr generate_torrent() bencode(std::back_inserter(buf), t.generate()); return std::make_shared(buf, from_span); } +} // anonymous namespace TORRENT_TEST(read_resume_torrent) { diff --git a/test/test_resume.cpp b/test/test_resume.cpp index 5928d9220..8479efd71 100644 --- a/test/test_resume.cpp +++ b/test/test_resume.cpp @@ -347,6 +347,8 @@ TORRENT_TEST(piece_slots) } } +namespace { + void test_piece_slots_seed(settings_pack const& sett) { // make sure the "pieces" field is correctly accepted from resume data @@ -399,6 +401,8 @@ void test_piece_slots_seed(settings_pack const& sett) } } +} // anonymous namespace + TORRENT_TEST(piece_slots_seed) { test_piece_slots_seed(settings()); diff --git a/test/test_torrent.cpp b/test/test_torrent.cpp index 2d8d5dff6..0791e12b5 100644 --- a/test/test_torrent.cpp +++ b/test/test_torrent.cpp @@ -51,6 +51,8 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; +namespace { + void test_running_torrent(std::shared_ptr info, std::int64_t file_size) { settings_pack pack = settings(); @@ -79,7 +81,7 @@ void test_running_torrent(std::shared_ptr info, std::int64_t file_ return; } - aux::vector ones(info->num_files(), 1_pri); + aux::vector ones(std::size_t(info->num_files()), 1_pri); h.prioritize_files(ones); torrent_status st = h.status(); @@ -87,7 +89,7 @@ void test_running_torrent(std::shared_ptr info, std::int64_t file_ TEST_EQUAL(st.total_wanted, file_size); // we want the single file TEST_EQUAL(st.total_wanted_done, 0); - aux::vector prio(info->num_files(), 1_pri); + aux::vector prio(std::size_t(info->num_files()), 1_pri); prio[file_index_t(0)] = 0_pri; h.prioritize_files(prio); st = h.status(); @@ -128,9 +130,9 @@ void test_running_torrent(std::shared_ptr info, std::int64_t file_ h.piece_priority(piece_index_t(0), 1_pri); st = h.status(); TEST_CHECK(st.pieces.size() > 0 && st.pieces[piece_index_t(0)] == false); - std::vector piece(info->piece_length()); + std::vector piece(std::size_t(info->piece_length())); for (int i = 0; i < int(piece.size()); ++i) - piece[i] = (i % 26) + 'A'; + piece[std::size_t(i)] = (i % 26) + 'A'; h.add_piece(piece_index_t(0), &piece[0], torrent_handle::overwrite_existing); // wait until the piece is done writing and hashing @@ -147,7 +149,8 @@ void test_running_torrent(std::shared_ptr info, std::int64_t file_ if (rpa) { std::cout << "SUCCEEDED!" << std::endl; - TEST_CHECK(memcmp(&piece[0], rpa->buffer.get(), info->piece_size(piece_index_t(0))) == 0); + TEST_CHECK(std::memcmp(&piece[0], rpa->buffer.get() + , std::size_t(info->piece_size(piece_index_t(0)))) == 0); TEST_CHECK(rpa->size == info->piece_size(piece_index_t(0))); TEST_CHECK(rpa->piece == piece_index_t(0)); TEST_CHECK(hasher(piece).final() == info->hash_for_piece(piece_index_t(0))); @@ -155,6 +158,8 @@ void test_running_torrent(std::shared_ptr info, std::int64_t file_ } } +} // anonymous namespace + TORRENT_TEST(long_names) { entry info; @@ -297,7 +302,7 @@ TORRENT_TEST(torrent) std::vector piece(128 * 1024); for (int i = 0; i < int(piece.size()); ++i) - piece[i] = (i % 26) + 'A'; + piece[std::size_t(i)] = (i % 26) + 'A'; // calculate the hash for all pieces sha1_hash ph = hasher(piece).final(); @@ -340,7 +345,7 @@ TORRENT_TEST(duplicate_is_not_error) std::vector piece(128 * 1024); for (int i = 0; i < int(piece.size()); ++i) - piece[i] = (i % 26) + 'A'; + piece[std::size_t(i)] = (i % 26) + 'A'; // calculate the hash for all pieces sha1_hash ph = hasher(piece).final(); @@ -456,7 +461,9 @@ TORRENT_TEST(torrent_status) TEST_EQUAL(static_cast(torrent_status::error_file_exception), -5); } -void test_queue(add_torrent_params p) +namespace { + +void test_queue(add_torrent_params) { lt::settings_pack pack = settings(); // we're not testing the hash check, just accept the data we write @@ -481,7 +488,8 @@ void test_queue(add_torrent_params p) torrents.push_back(ses.add_torrent(std::move(p))); } - std::vector pieces(torrents[5].torrent_file()->num_pieces(), 0_pri); + std::vector pieces( + std::size_t(torrents[5].torrent_file()->num_pieces()), 0_pri); torrents[5].prioritize_pieces(pieces); torrent_handle finished = torrents[5]; @@ -562,6 +570,8 @@ void test_queue(add_torrent_params p) TEST_EQUAL(torrents[3].queue_position(), queue_position_t{4}); } +} // anonymous namespace + TORRENT_TEST(queue) { test_queue(add_torrent_params()); @@ -589,4 +599,3 @@ TORRENT_TEST(test_move_storage_no_metadata) TEST_EQUAL(h.status().save_path, complete("save_path_1")); } - diff --git a/test/test_tracker.cpp b/test/test_tracker.cpp index bfb4af1a4..060d9536c 100644 --- a/test/test_tracker.cpp +++ b/test/test_tracker.cpp @@ -267,6 +267,7 @@ TORRENT_TEST(parse_external_ip6) } #endif +namespace { peer_entry extract_peer(char const* peer_field, error_code expected_ec, bool expected_ret) { error_code ec; @@ -280,6 +281,7 @@ peer_entry extract_peer(char const* peer_field, error_code expected_ec, bool exp TEST_EQUAL(expected_ec, ec); return result; } +} // anonymous namespace TORRENT_TEST(extract_peer) { @@ -320,6 +322,8 @@ TORRENT_TEST(extract_peer_missing_port) , errors::invalid_tracker_response, false); } +namespace { + bool connect_alert(lt::alert const* a, tcp::endpoint& ep) { if (peer_connect_alert const* pc = alert_cast(a)) @@ -402,6 +406,8 @@ void test_udp_tracker(std::string const& iface, address tracker, tcp::endpoint c stop_udp_tracker(); } +} // anonymous namespace + TORRENT_TEST(udp_tracker_v4) { test_udp_tracker("127.0.0.1", address_v4::any(), ep("1.3.3.7", 1337)); @@ -547,6 +553,8 @@ TORRENT_TEST(current_tracker) std::printf("done\n"); } +namespace { + void test_proxy(bool proxy_trackers) { int http_port = start_web_server(); @@ -607,6 +615,8 @@ void test_proxy(bool proxy_trackers) std::printf("done\n"); } +} // anonymous namespace + TORRENT_TEST(tracker_proxy) { std::printf("\n\nnot proxying tracker connections (expect to reach the tracker)\n\n"); @@ -618,6 +628,7 @@ TORRENT_TEST(tracker_proxy) } #ifndef TORRENT_DISABLE_LOGGING +namespace { void test_stop_tracker_timeout(int const timeout) { // trick the min interval so that the stopped anounce is permitted immediately @@ -653,7 +664,6 @@ void test_stop_tracker_timeout(int const timeout) } if (num <= 0 && expected <= 0) return count; } - return count; }; settings_pack p = settings(); @@ -693,6 +703,7 @@ void test_stop_tracker_timeout(int const timeout) int const count = count_stopped_events(s, (timeout == 0) ? 0 : 1); TEST_EQUAL(count, (timeout == 0) ? 0 : 1); } +} // anonymous namespace TORRENT_TEST(stop_tracker_timeout) { @@ -706,4 +717,3 @@ TORRENT_TEST(stop_tracker_timeout_zero_timeout) test_stop_tracker_timeout(0); } #endif - diff --git a/test/test_web_seed_redirect.cpp b/test/test_web_seed_redirect.cpp index 18dccf07a..4f0ac2e26 100644 --- a/test/test_web_seed_redirect.cpp +++ b/test/test_web_seed_redirect.cpp @@ -95,7 +95,7 @@ TORRENT_TEST(web_seed_redirect) // disable keep-alive because otherwise the test will choke on seeing // the disconnect (from the redirect) - test_transfer(ses, torrent_file, 0, nullptr, "http", true, false, false, false); + test_transfer(ses, torrent_file, 0, "http", true, false, false, false); } stop_web_server();