From 070d1cd61ff578e5636140f73399c422facba2e9 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Sat, 27 Jan 2018 18:56:21 -0500 Subject: [PATCH] fixing warnings in tests code, part5 (#2736) --- test/test_buffer.cpp | 6 ++++-- test/test_checking.cpp | 5 ++++- test/test_dht.cpp | 19 ++++++++++++++++--- test/test_dht_storage.cpp | 21 ++++++++------------- test/test_dos_blocker.cpp | 2 +- test/test_file_storage.cpp | 6 +++--- test/test_gzip.cpp | 5 ++--- test/test_http_parser.cpp | 7 +++++-- test/test_ip_filter.cpp | 19 +++++++------------ test/test_magnet.cpp | 2 ++ test/test_packet_buffer.cpp | 9 ++++++--- test/test_pe_crypto.cpp | 13 ++++++++----- test/test_peer_classes.cpp | 31 +++++++++++++++---------------- test/test_peer_list.cpp | 14 ++------------ test/test_peer_priority.cpp | 3 ++- test/test_piece_picker.cpp | 9 ++++----- test/test_priority.cpp | 2 +- test/test_privacy.cpp | 4 ++-- test/test_random.cpp | 5 ++--- 19 files changed, 94 insertions(+), 88 deletions(-) diff --git a/test/test_buffer.cpp b/test/test_buffer.cpp index a27eac9a7..f990ae009 100644 --- a/test/test_buffer.cpp +++ b/test/test_buffer.cpp @@ -136,13 +136,14 @@ TORRENT_TEST(buffer_move_assign) TEST_CHECK(b2.size() >= 50); } +namespace { // -- test chained buffer -- std::set buffer_list; void free_buffer(char* m) { - std::set::iterator i = buffer_list.find(m); + auto const i = buffer_list.find(m); TEST_CHECK(i != buffer_list.end()); buffer_list.erase(i); @@ -202,6 +203,8 @@ private: std::size_t m_size; }; +} // anonymous namespace + TORRENT_TEST(chained_buffer) { char data[] = "foobar"; @@ -311,4 +314,3 @@ TORRENT_TEST(chained_buffer) } TEST_CHECK(buffer_list.empty()); } - diff --git a/test/test_checking.cpp b/test/test_checking.cpp index a3666b32d..8e7a903b3 100644 --- a/test/test_checking.cpp +++ b/test/test_checking.cpp @@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/hex.hpp" // to_hex #include "libtorrent/aux_/path.hpp" +namespace { + static const int file_sizes[] = { 0, 5, 16 - 5, 16000, 17, 10, 8000, 8000, 1,1,1,1,1,100,1,1,1,1,100,1,1,1,1,1,1 ,1,1,1,1,1,1,13,65000,34,75,2,30,400,500,23000,900,43000,400,4300,6, 4}; @@ -300,6 +302,8 @@ void test_checking(int flags = read_only_files) , ec.value(), ec.message().c_str()); } +} // anonymous namespace + TORRENT_TEST(checking) { test_checking(); @@ -329,4 +333,3 @@ TORRENT_TEST(force_recheck) { test_checking(force_recheck); } - diff --git a/test/test_dht.cpp b/test/test_dht.cpp index 4550fd181..33f75c3c0 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -1249,7 +1249,6 @@ namespace { } span const empty_salt; -} // TODO: 3 split this up into smaller tests void test_put(address(&rand_addr)()) @@ -1547,6 +1546,8 @@ void test_put(address(&rand_addr)()) } } +} // anonymous namespace + TORRENT_TEST(put_v4) { test_put(rand_v4); @@ -1784,6 +1785,8 @@ TORRENT_TEST(routing_table_v6) } #endif +namespace { + void test_bootstrap(address(&rand_addr)()) { dht_test_setup t(udp::endpoint(rand_addr(), 20)); @@ -1872,6 +1875,8 @@ void test_bootstrap(address(&rand_addr)()) TEST_EQUAL(t.dht_node.num_global_nodes(), 3); } +} // anonymous namespace + TORRENT_TEST(bootstrap_v4) { test_bootstrap(rand_v4); @@ -1886,6 +1891,8 @@ TORRENT_TEST(bootstrap_v6) #endif #if TORRENT_USE_IPV6 +namespace { + void test_bootstrap_want(address(&rand_addr)()) { dht_test_setup t(udp::endpoint(rand_addr(), 20)); @@ -1943,6 +1950,8 @@ void test_bootstrap_want(address(&rand_addr)()) } } +} // anonymous namespace + TORRENT_TEST(bootstrap_want_v4) { test_bootstrap_want(rand_v4); @@ -2040,6 +2049,8 @@ TORRENT_TEST(short_nodes_v6) } #endif +namespace { + void test_get_peers(address(&rand_addr)()) { dht_test_setup t(udp::endpoint(rand_addr(), 20)); @@ -2160,6 +2171,8 @@ void test_get_peers(address(&rand_addr)()) g_got_peers.clear(); } +} // anonymous namespace + TORRENT_TEST(get_peers_v4) { test_get_peers(rand_v4); @@ -3067,7 +3080,7 @@ TORRENT_TEST(routing_table_set_id) // table would get unbalanced and intermediate nodes would be dropped std::vector node_id_prefix; node_id_prefix.reserve(256); - for (int i = 0; i < 256; ++i) node_id_prefix.push_back(i); + for (int i = 0; i < 256; ++i) node_id_prefix.push_back(i & 0xff); aux::random_shuffle(node_id_prefix.begin(), node_id_prefix.end()); routing_table tbl(id, udp::v4(), 8, sett, &observer); for (int i = 0; i < 256; ++i) @@ -3402,7 +3415,7 @@ TORRENT_TEST(rpc_invalid_error_msg) rpc.incoming(m, &nid); bool found = false; - for (int i = 0; i < int(observer.m_log.size()); ++i) + for (std::size_t i = 0; i < observer.m_log.size(); ++i) { if (observer.m_log[i].find("reply with") != std::string::npos && observer.m_log[i].find("(malformed)") != std::string::npos diff --git a/test/test_dht_storage.cpp b/test/test_dht_storage.cpp index 617a0b0a6..0147d8352 100644 --- a/test/test_dht_storage.cpp +++ b/test/test_dht_storage.cpp @@ -186,11 +186,6 @@ TORRENT_TEST(counters) dht::dht_settings sett = test_settings(); std::unique_ptr s(create_default_dht_storage(sett)); - sha1_hash const n1 = to_hash("5fbfbff10c5d6a4ec8a88e4c6ab4c28b95eee401"); - sha1_hash const n2 = to_hash("5fbfbff10c5d6a4ec8a88e4c6ab4c28b95eee402"); - sha1_hash const n3 = to_hash("5fbfbff10c5d6a4ec8a88e4c6ab4c28b95eee403"); - sha1_hash const n4 = to_hash("5fbfbff10c5d6a4ec8a88e4c6ab4c28b95eee404"); - TEST_EQUAL(s->counters().peers, 0); TEST_EQUAL(s->counters().torrents, 0); @@ -279,7 +274,7 @@ TORRENT_TEST(peer_limit) for (int i = 0; i < 200; ++i) { - s->announce_peer(n1, tcp::endpoint(rand_v4(), lt::random(0xffff)) + s->announce_peer(n1, {rand_v4(), std::uint16_t(lt::random(0xffff))} , "torrent_name", false); dht_storage_counters cnt = s->counters(); TEST_CHECK(cnt.peers <= 42); @@ -296,7 +291,7 @@ TORRENT_TEST(torrent_limit) for (int i = 0; i < 200; ++i) { - s->announce_peer(rand_hash(), tcp::endpoint(rand_v4(), lt::random(0xffff)) + s->announce_peer(rand_hash(), {rand_v4(), std::uint16_t(lt::random(0xffff))} , "", false); dht_storage_counters cnt = s->counters(); TEST_CHECK(cnt.torrents <= 42); @@ -395,14 +390,14 @@ TORRENT_TEST(update_node_ids) std::unique_ptr s(dht_default_storage_constructor(sett)); TEST_CHECK(s != nullptr); - node_id const n1 = to_hash("0000000000000000000000000000000000000200"); - node_id const n2 = to_hash("0000000000000000000000000000000000000400"); - node_id const n3 = to_hash("0000000000000000000000000000000000000800"); + node_id const nid1 = to_hash("0000000000000000000000000000000000000200"); + node_id const nid2 = to_hash("0000000000000000000000000000000000000400"); + node_id const nid3 = to_hash("0000000000000000000000000000000000000800"); std::vector node_ids; - node_ids.push_back(n1); - node_ids.push_back(n2); - node_ids.push_back(n3); + node_ids.push_back(nid1); + node_ids.push_back(nid2); + node_ids.push_back(nid3); s->update_node_ids(node_ids); entry item; diff --git a/test/test_dos_blocker.cpp b/test/test_dos_blocker.cpp index efbb93feb..93a668399 100644 --- a/test/test_dos_blocker.cpp +++ b/test/test_dos_blocker.cpp @@ -47,7 +47,7 @@ struct log_t : lt::dht::dht_logger { bool should_log(module_t) const override { return true; } - void log(dht_logger::module_t m, char const* fmt, ...) + void log(dht_logger::module_t, char const* fmt, ...) override TORRENT_FORMAT(3, 4) { va_list v; diff --git a/test/test_file_storage.cpp b/test/test_file_storage.cpp index 4703f9ca0..6a7ee8c6e 100644 --- a/test/test_file_storage.cpp +++ b/test/test_file_storage.cpp @@ -452,10 +452,10 @@ void test_optimize(std::vector file_sizes file_index_t idx{0}; int num_pad_files = 0; std::cout << "{ "; - for (file_index_t i{0}; i != fs.end_file(); ++i) + for (file_index_t idx{0}; idx != fs.end_file(); ++idx) { - if (fs.file_flags(i) & file_storage::flag_pad_file) std::cout << "*"; - std::cout << fs.file_size(i) << " "; + if (fs.file_flags(idx) & file_storage::flag_pad_file) std::cout << "*"; + std::cout << fs.file_size(idx) << " "; } std::cout << "}\n"; for (int expect : expected_order) diff --git a/test/test_gzip.cpp b/test/test_gzip.cpp index a6935c27d..bd303bc93 100644 --- a/test/test_gzip.cpp +++ b/test/test_gzip.cpp @@ -53,8 +53,8 @@ TORRENT_TEST(zeroes) std::printf("failed to unzip: %s\n", ec.message().c_str()); } TEST_CHECK(!ec); - TEST_CHECK(inflated.size() > 0); - for (int i = 0; i < int(inflated.size()); ++i) + TEST_CHECK(!inflated.empty()); + for (std::size_t i = 0; i < inflated.size(); ++i) TEST_EQUAL(inflated[i], 0); } @@ -98,4 +98,3 @@ TORRENT_TEST(empty) inflate_gzip(empty, inflated, 1000000, ec); TEST_CHECK(ec); } - diff --git a/test/test_http_parser.cpp b/test/test_http_parser.cpp index a3c1504b0..00accebb5 100644 --- a/test/test_http_parser.cpp +++ b/test/test_http_parser.cpp @@ -39,6 +39,8 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; +namespace { + std::tuple feed_bytes(http_parser& parser, string_view str) { std::tuple ret(0, 0, false); @@ -52,7 +54,7 @@ std::tuple feed_bytes(http_parser& parser, string_view str) { int const chunk_size = std::min(chunks, int(str.size() - recv_buf.size())); if (chunk_size == 0) break; - recv_buf = str.substr(0, recv_buf.size() + chunk_size); + recv_buf = str.substr(0, recv_buf.size() + std::size_t(chunk_size)); int payload, protocol; bool error = false; std::tie(payload, protocol) = parser.incoming(recv_buf, error); @@ -72,6 +74,8 @@ std::tuple feed_bytes(http_parser& parser, string_view str) return ret; } +} // anonymous namespace + TORRENT_TEST(http_parser) { // HTTP request parser @@ -681,4 +685,3 @@ TORRENT_TEST(invalid_chunk_3) http_parser parser; feed_bytes(parser, {reinterpret_cast(invalid_chunked_input), sizeof(invalid_chunked_input)}); } - diff --git a/test/test_ip_filter.cpp b/test/test_ip_filter.cpp index c80307e4d..ed04b14a1 100644 --- a/test/test_ip_filter.cpp +++ b/test/test_ip_filter.cpp @@ -63,7 +63,6 @@ bool compare(ip_range const& lhs template void test_rules_invariant(std::vector> const& r, ip_filter const& f) { - typedef typename std::vector>::const_iterator iterator; TEST_CHECK(!r.empty()); if (r.empty()) return; @@ -79,7 +78,7 @@ void test_rules_invariant(std::vector> const& r, ip_filter const& f) TEST_CHECK(r.back().last == addr("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")); } - for (iterator i(r.begin()), j(std::next(r.begin())) + for (auto i(r.begin()), j(std::next(r.begin())) , end(r.end()); j != end; ++j, ++i) { TEST_EQUAL(f.access(i->last), i->flags); @@ -90,7 +89,6 @@ void test_rules_invariant(std::vector> const& r, ip_filter const& f) TORRENT_TEST(session_get_ip_filter) { - using namespace lt; session ses(settings()); ip_filter const& ipf = ses.get_ip_filter(); #if TORRENT_USE_IPV6 @@ -102,8 +100,6 @@ TORRENT_TEST(session_get_ip_filter) TORRENT_TEST(ip_filter) { - using namespace lt; - std::vector> range; error_code ec; @@ -268,19 +264,18 @@ TORRENT_TEST(ip_filter) f.add_rule(addr("2::1"), addr("3::"), ip_filter::blocked); f.add_rule(addr("1::"), addr("2::"), ip_filter::blocked); - std::vector> range; - range = std::get<1>(f.export_filter()); - test_rules_invariant(range, f); - - TEST_EQUAL(range.size(), 3); - TEST_CHECK(std::equal(range.begin(), range.end(), expected2, &compare)); + std::vector> rangev6; + rangev6 = std::get<1>(f.export_filter()); + test_rules_invariant(rangev6, f); + TEST_EQUAL(rangev6.size(), 3); + TEST_CHECK(std::equal(rangev6.begin(), rangev6.end(), expected2, &compare)); } #endif port_filter pf; - // default contructed port filter should allow any port + // default constructed port filter should allow any port TEST_CHECK(pf.access(0) == 0); TEST_CHECK(pf.access(65535) == 0); TEST_CHECK(pf.access(6881) == 0); diff --git a/test/test_magnet.cpp b/test/test_magnet.cpp index 0a4302f8f..e0cd02642 100644 --- a/test/test_magnet.cpp +++ b/test/test_magnet.cpp @@ -44,6 +44,7 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; #ifndef TORRENT_NO_DEPRECATE +namespace { void test_remove_url(std::string url) { lt::session s(settings()); @@ -61,6 +62,7 @@ void test_remove_url(std::string url) handles = s.get_torrents(); TEST_EQUAL(handles.size(), 0); } +} // anonymous namespace TORRENT_TEST(remove_url) { diff --git a/test/test_packet_buffer.cpp b/test/test_packet_buffer.cpp index 5f01321e9..34e940ebf 100644 --- a/test/test_packet_buffer.cpp +++ b/test/test_packet_buffer.cpp @@ -39,6 +39,8 @@ using lt::packet_ptr; using lt::packet_pool; using lt::packet; +namespace { + packet_ptr make_pkt(packet_pool& pool, int const val) { packet_ptr ret = pool.acquire(20); @@ -52,6 +54,8 @@ int get_val(packet* pkt) return *reinterpret_cast(pkt->buf); } +} // anonymous namespace + // test packet_buffer TORRENT_TEST(insert) { @@ -147,7 +151,7 @@ TORRENT_TEST(wrap2) pb.insert(0xfff3, make_pkt(pool, 1)); TEST_EQUAL(get_val(pb.at(0xfff3)), 1); - int new_index = (0xfff3 + pb.capacity()) & 0xffff; + auto const new_index = packet_buffer::index_type((0xfff3 + pb.capacity()) & 0xffff); pb.insert(new_index, make_pkt(pool, 2)); TEST_EQUAL(get_val(pb.at(new_index)), 2); @@ -168,7 +172,7 @@ TORRENT_TEST(reverse_wrap) pb.insert(0xfff3, make_pkt(pool, 1)); TEST_EQUAL(get_val(pb.at(0xfff3)), 1); - int new_index = (0xfff3 + pb.capacity()) & 0xffff; + auto const new_index = packet_buffer::index_type((0xfff3 + pb.capacity()) & 0xffff); pb.insert(new_index, make_pkt(pool, 2)); TEST_EQUAL(get_val(pb.at(new_index)), 2); @@ -179,4 +183,3 @@ TORRENT_TEST(reverse_wrap) pb.insert(0xffff, make_pkt(pool, 3)); } - diff --git a/test/test_pe_crypto.cpp b/test/test_pe_crypto.cpp index 73de20dc0..2a5987e39 100644 --- a/test/test_pe_crypto.cpp +++ b/test/test_pe_crypto.cpp @@ -45,13 +45,14 @@ POSSIBILITY OF SUCH DAMAGE. #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +namespace { void test_enc_handler(lt::crypto_plugin& a, lt::crypto_plugin& b) { int const repcount = 128; for (int rep = 0; rep < repcount; ++rep) { - int const buf_len = rand() % (512 * 1024); + std::size_t const buf_len = rand() % (512 * 1024); std::vector buf(buf_len); std::vector cmp_buf(buf_len); @@ -67,7 +68,7 @@ void test_enc_handler(lt::crypto_plugin& a, lt::crypto_plugin& b) std::tie(next_barrier, iovec_out) = a.encrypt(iovec); TEST_CHECK(buf != cmp_buf); TEST_EQUAL(iovec_out.size(), 0); - TEST_EQUAL(next_barrier, buf_len); + TEST_EQUAL(next_barrier, int(buf_len)); } { @@ -78,7 +79,7 @@ void test_enc_handler(lt::crypto_plugin& a, lt::crypto_plugin& b) std::tie(consume, produce, packet_size) = b.decrypt(iovec); TEST_CHECK(buf == cmp_buf); TEST_EQUAL(consume, 0); - TEST_EQUAL(produce, buf_len); + TEST_EQUAL(produce, int(buf_len)); TEST_EQUAL(packet_size, 0); } @@ -89,7 +90,7 @@ void test_enc_handler(lt::crypto_plugin& a, lt::crypto_plugin& b) std::tie(next_barrier, iovec_out) = b.encrypt(iovec); TEST_EQUAL(iovec_out.size(), 0); TEST_CHECK(buf != cmp_buf); - TEST_EQUAL(next_barrier, buf_len); + TEST_EQUAL(next_barrier, int(buf_len)); int consume = 0; int produce = 0; @@ -98,12 +99,14 @@ void test_enc_handler(lt::crypto_plugin& a, lt::crypto_plugin& b) std::tie(consume, produce, packet_size) = a.decrypt(iovec2); TEST_CHECK(buf == cmp_buf); TEST_EQUAL(consume, 0); - TEST_EQUAL(produce, buf_len); + TEST_EQUAL(produce, int(buf_len)); TEST_EQUAL(packet_size, 0); } } } +} // anonymous namespace + TORRENT_TEST(diffie_hellman) { using namespace lt; diff --git a/test/test_peer_classes.cpp b/test/test_peer_classes.cpp index d62f7b597..db05a9f4e 100644 --- a/test/test_peer_classes.cpp +++ b/test/test_peer_classes.cpp @@ -82,34 +82,34 @@ TORRENT_TEST(peer_class) pool.at(id2)->set_upload_limit(1000); pool.at(id2)->set_download_limit(2000); - peer_class_info i; - pool.at(id2)->get_info(&i); - TEST_EQUAL(i.upload_limit, 1000); - TEST_EQUAL(i.download_limit, 2000); + peer_class_info cls; + pool.at(id2)->get_info(&cls); + TEST_EQUAL(cls.upload_limit, 1000); + TEST_EQUAL(cls.download_limit, 2000); // test peer_class_type_filter peer_class_type_filter filter; for (int i = 0; i < 5; ++i) { - TEST_CHECK(filter.apply((lt::peer_class_type_filter::socket_type_t)i + TEST_CHECK(filter.apply(static_cast(i) , 0xffffffff) == 0xffffffff); } - filter.disallow((lt::peer_class_type_filter::socket_type_t)0, peer_class_t{0}); - TEST_CHECK(filter.apply((lt::peer_class_type_filter::socket_type_t)0 + filter.disallow(static_cast(0), peer_class_t{0}); + TEST_CHECK(filter.apply(static_cast(0) , 0xffffffff) == 0xfffffffe); - TEST_CHECK(filter.apply((lt::peer_class_type_filter::socket_type_t)1 + TEST_CHECK(filter.apply(static_cast(1) , 0xffffffff) == 0xffffffff); - filter.allow((lt::peer_class_type_filter::socket_type_t)0, peer_class_t{0}); - TEST_CHECK(filter.apply((lt::peer_class_type_filter::socket_type_t)0 + filter.allow(static_cast(0), peer_class_t{0}); + TEST_CHECK(filter.apply(static_cast(0) , 0xffffffff) == 0xffffffff); - TEST_CHECK(filter.apply((lt::peer_class_type_filter::socket_type_t)0, 0) == 0); - filter.add((lt::peer_class_type_filter::socket_type_t)0, peer_class_t{0}); - TEST_CHECK(filter.apply((lt::peer_class_type_filter::socket_type_t)0, 0) == 1); - filter.remove((lt::peer_class_type_filter::socket_type_t)0, peer_class_t{0}); - TEST_CHECK(filter.apply((lt::peer_class_type_filter::socket_type_t)0, 0) == 0); + TEST_CHECK(filter.apply(static_cast(0), 0) == 0); + filter.add(static_cast(0), peer_class_t{0}); + TEST_CHECK(filter.apply(static_cast(0), 0) == 1); + filter.remove(static_cast(0), peer_class_t{0}); + TEST_CHECK(filter.apply(static_cast(0), 0) == 0); pool.decref(id2); pool.decref(id1); @@ -150,4 +150,3 @@ TORRENT_TEST(session_peer_class_type_filter) TEST_CHECK(ses.get_peer_class_type_filter() == f); } - diff --git a/test/test_peer_list.cpp b/test/test_peer_list.cpp index a25484ee5..7f618fb18 100644 --- a/test/test_peer_list.cpp +++ b/test/test_peer_list.cpp @@ -98,7 +98,7 @@ struct mock_peer_connection bool m_disconnect_called; mock_torrent& m_torrent; - void get_peer_info(peer_info& p) const override {} + void get_peer_info(peer_info&) const override {} tcp::endpoint const& remote() const override { return m_remote; } tcp::endpoint local_endpoint() const override { return m_local; } void disconnect(error_code const& ec @@ -121,7 +121,7 @@ struct mock_torrent explicit mock_torrent(torrent_state* st) : m_p(nullptr), m_state(st) {} virtual ~mock_torrent() = default; - bool connect_to_peer(torrent_peer* peerinfo, bool ignore_limit = false) + bool connect_to_peer(torrent_peer* peerinfo) { TORRENT_ASSERT(peerinfo->connection == nullptr); if (peerinfo->connection) return false; @@ -133,16 +133,6 @@ struct mock_torrent return true; } -#ifndef TORRENT_DISABLE_LOGGING - void debug_log(const char* fmt, ...) const - { - va_list v; - va_start(v, fmt); - vprintf(fmt, v); - va_end(v); - } -#endif - peer_list* m_p; torrent_state* m_state; std::vector> m_connections; diff --git a/test/test_peer_priority.cpp b/test/test_peer_priority.cpp index fab99c5fd..698457e95 100644 --- a/test/test_peer_priority.cpp +++ b/test/test_peer_priority.cpp @@ -40,12 +40,14 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; +namespace { std::uint32_t hash_buffer(char const* buf, int len) { boost::crc_optimal<32, 0x1EDC6F41, 0xFFFFFFFF, 0xFFFFFFFF, true, true> crc; crc.process_block(buf, buf + len); return crc.checksum(); } +} // anonymous namespace TORRENT_TEST(peer_priority) { @@ -93,4 +95,3 @@ TORRENT_TEST(peer_priority) "\xff\xff\xff\xff\x55\x55\x55\x55\x00\x00\x00\x00\x00\x00\x00\x01", 32)); } } - diff --git a/test/test_piece_picker.cpp b/test/test_piece_picker.cpp index 837c7dd75..321282ee5 100644 --- a/test/test_piece_picker.cpp +++ b/test/test_piece_picker.cpp @@ -258,9 +258,9 @@ bool verify_availability(std::shared_ptr const& p, char const* a) void print_pick(std::vector const& picked) { - for (int i = 0; i < int(picked.size()); ++i) + for (auto const& p : picked) { - std::cout << "(" << picked[i].piece_index << ", " << picked[i].block_index << ") "; + std::cout << "(" << p.piece_index << ", " << p.block_index << ") "; } std::cout << std::endl; } @@ -1778,10 +1778,9 @@ TORRENT_TEST(mark_as_canceled) TORRENT_TEST(get_download_queue) { - auto p = setup_picker("1111111", " ", "1101111", "0327000"); + auto picker = setup_picker("1111111", " ", "1101111", "0327000"); - std::vector downloads - = p->get_download_queue(); + auto const downloads = picker->get_download_queue(); // the download queue should have piece 1, 2 and 3 in it TEST_EQUAL(downloads.size(), 3); diff --git a/test/test_priority.cpp b/test/test_priority.cpp index 39f1c456d..04200b589 100644 --- a/test/test_priority.cpp +++ b/test/test_priority.cpp @@ -138,7 +138,7 @@ void test_transfer(settings_pack const& sett, bool test_deprecated = false) , true, false, true, "_priority", 8 * 1024, &t, false, nullptr); int const num_pieces = tor2.torrent_file()->num_pieces(); - aux::vector priorities(num_pieces, 1_pri); + aux::vector priorities(std::size_t(num_pieces), 1_pri); // set half of the pieces to priority 0 std::fill(priorities.begin(), priorities.begin() + (num_pieces / 2), 0_pri); tor2.prioritize_pieces(priorities); diff --git a/test/test_privacy.cpp b/test/test_privacy.cpp index fa8c2263a..bf785f548 100644 --- a/test/test_privacy.cpp +++ b/test/test_privacy.cpp @@ -120,7 +120,7 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags) // since multiple sessions may exist simultaneously (because of the // pipelining of the tests) they actually need to use different ports - static int listen_port = 10000 + lt::random(50000); + static int listen_port = 10000 + int(lt::random(50000)); char iface[200]; std::snprintf(iface, sizeof(iface), "127.0.0.1:%d", listen_port); listen_port += lt::random(10) + 1; @@ -170,7 +170,7 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags) torrent_handle h = s->add_torrent(addp); std::printf("connect_peer: 127.0.0.1:%d\n", peer_port); - h.connect_peer(tcp::endpoint(address_v4::from_string("127.0.0.1"), peer_port)); + h.connect_peer({address_v4::from_string("127.0.0.1"), std::uint16_t(peer_port)}); rejected_trackers.clear(); diff --git a/test/test_random.cpp b/test/test_random.cpp index 7c3a124ff..9c47a29c2 100644 --- a/test/test_random.cpp +++ b/test/test_random.cpp @@ -44,7 +44,7 @@ TORRENT_TEST(random) for (int byte = 0; byte < 4; ++byte) { int buckets[256]; - memset(buckets, 0, sizeof(buckets)); + std::memset(buckets, 0, sizeof(buckets)); for (int i = 0; i < repetitions; ++i) { @@ -57,9 +57,8 @@ TORRENT_TEST(random) { const int expected = repetitions / 256; // expect each bucket to be within 15% of the expected value - std::printf("%d: %f\n", i, float(buckets[i] - expected) * 100.f / expected); + std::printf("%d: %f\n", i, double(buckets[i] - expected) * 100.0 / expected); TEST_CHECK(abs(buckets[i] - expected) < expected / 6); } } } -