fixing warnings in tests code, part4

This commit is contained in:
Alden Torres 2018-01-25 09:34:39 -05:00 committed by Arvid Norberg
parent 308cbfe097
commit 6d5b90968b
23 changed files with 131 additions and 65 deletions

View File

@ -100,10 +100,12 @@ TORRENT_TEST(priority_limit)
TEST_EQUAL(alerts.size(), 200); TEST_EQUAL(alerts.size(), 200);
} }
namespace {
void test_notify_fun(int& cnt) void test_notify_fun(int& cnt)
{ {
++cnt; ++cnt;
} }
} // anonymous namespace
TORRENT_TEST(notify_function) TORRENT_TEST(notify_function)
{ {
@ -148,6 +150,7 @@ TORRENT_TEST(notify_function)
} }
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
namespace {
int plugin_alerts[3] = { 0, 0, 0 }; int plugin_alerts[3] = { 0, 0, 0 };
struct test_plugin : lt::plugin struct test_plugin : lt::plugin
@ -159,7 +162,7 @@ struct test_plugin : lt::plugin
} }
int m_index; int m_index;
}; };
} // anonymous namespace
#endif #endif
TORRENT_TEST(extensions) TORRENT_TEST(extensions)
@ -271,4 +274,3 @@ TORRENT_TEST(dropped_alerts)
// it should have been cleared now though // it should have been cleared now though
TEST_CHECK(mgr.dropped_alerts().none()); TEST_CHECK(mgr.dropped_alerts().none());
} }

View File

@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "test.hpp" #include "test.hpp"
#include "setup_transfer.hpp" #include "setup_transfer.hpp"
namespace {
void test_swarm() void test_swarm()
{ {
using namespace lt; using namespace lt;
@ -136,6 +138,8 @@ void test_swarm()
p3 = ses3.abort(); p3 = ses3.abort();
} }
} // anonymous namespace
TORRENT_TEST(auto_unchoke) TORRENT_TEST(auto_unchoke)
{ {
using namespace lt; using namespace lt;
@ -156,4 +160,3 @@ TORRENT_TEST(auto_unchoke)
remove_all("./tmp2_unchoke", ec); remove_all("./tmp2_unchoke", ec);
remove_all("./tmp3_unchoke", ec); remove_all("./tmp3_unchoke", ec);
} }

View File

@ -73,7 +73,6 @@ struct peer_connection: bandwidth_socket, std::enable_shared_from_this<peer_conn
{} {}
bool is_disconnecting() const override { return false; } bool is_disconnecting() const override { return false; }
bool ignore_bandwidth_limits() { return m_ignore_limits; }
void assign_bandwidth(int channel, int amount) override; void assign_bandwidth(int channel, int amount) override;
void throttle(int limit) { m_bandwidth_channel.throttle(limit); } void throttle(int limit) { m_bandwidth_channel.throttle(limit); }
@ -91,7 +90,7 @@ struct peer_connection: bandwidth_socket, std::enable_shared_from_this<peer_conn
std::int64_t m_quota; std::int64_t m_quota;
}; };
void peer_connection::assign_bandwidth(int channel, int amount) void peer_connection::assign_bandwidth(int /*channel*/, int amount)
{ {
m_quota += amount; m_quota += amount;
#ifdef VERBOSE_LOGGING #ifdef VERBOSE_LOGGING

View File

@ -46,6 +46,8 @@ using namespace lt;
// test vectors from bittorrent protocol description // test vectors from bittorrent protocol description
// http://www.bittorrent.com/protocol.html // http://www.bittorrent.com/protocol.html
namespace {
std::string encode(entry const& e) std::string encode(entry const& e)
{ {
std::string ret; std::string ret;
@ -58,6 +60,8 @@ entry decode(std::string const& str)
return bdecode(str.begin(), str.end()); return bdecode(str.begin(), str.end());
} }
} // anonymous namespace
TORRENT_TEST(strings) TORRENT_TEST(strings)
{ {
entry e("spam"); entry e("spam");
@ -152,7 +156,7 @@ TORRENT_TEST(lazy_entry)
TEST_CHECK(ret == 0); TEST_CHECK(ret == 0);
std::printf("%s\n", print_entry(e).c_str()); std::printf("%s\n", print_entry(e).c_str());
std::pair<const char*, int> section = e.data_section(); std::pair<const char*, int> 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(section.second == sizeof(b) - 1);
TEST_CHECK(e.type() == lazy_entry::int_t); TEST_CHECK(e.type() == lazy_entry::int_t);
TEST_CHECK(e.int_value() == 12453); TEST_CHECK(e.int_value() == 12453);
@ -166,7 +170,7 @@ TORRENT_TEST(lazy_entry)
TEST_CHECK(ret == 0); TEST_CHECK(ret == 0);
std::printf("%s\n", print_entry(e).c_str()); std::printf("%s\n", print_entry(e).c_str());
std::pair<const char*, int> section = e.data_section(); std::pair<const char*, int> 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(section.second == sizeof(b) - 1);
TEST_CHECK(e.type() == lazy_entry::string_t); TEST_CHECK(e.type() == lazy_entry::string_t);
TEST_CHECK(e.string_value() == std::string("abcdefghijklmnopqrstuvwxyz")); TEST_CHECK(e.string_value() == std::string("abcdefghijklmnopqrstuvwxyz"));
@ -181,7 +185,7 @@ TORRENT_TEST(lazy_entry)
TEST_CHECK(ret == 0); TEST_CHECK(ret == 0);
std::printf("%s\n", print_entry(e).c_str()); std::printf("%s\n", print_entry(e).c_str());
std::pair<const char*, int> section = e.data_section(); std::pair<const char*, int> 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(section.second == sizeof(b) - 1);
TEST_CHECK(e.type() == lazy_entry::list_t); TEST_CHECK(e.type() == lazy_entry::list_t);
TEST_CHECK(e.list_size() == 2); 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_value() == std::string("aaa"));
TEST_CHECK(e.list_at(1)->string_length() == 3); TEST_CHECK(e.list_at(1)->string_length() == 3);
section = e.list_at(1)->data_section(); 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); TEST_CHECK(section.second == 5);
} }
@ -203,7 +207,7 @@ TORRENT_TEST(lazy_entry)
TEST_CHECK(ret == 0); TEST_CHECK(ret == 0);
std::printf("%s\n", print_entry(e).c_str()); std::printf("%s\n", print_entry(e).c_str());
std::pair<const char*, int> section = e.data_section(); std::pair<const char*, int> 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(section.second == sizeof(b) - 1);
TEST_CHECK(e.type() == lazy_entry::dict_t); TEST_CHECK(e.type() == lazy_entry::dict_t);
TEST_CHECK(e.dict_size() == 4); TEST_CHECK(e.dict_size() == 4);
@ -309,7 +313,7 @@ TORRENT_TEST(lazy_entry)
std::printf("%s\n", buf); std::printf("%s\n", buf);
lazy_entry e; lazy_entry e;
error_code ec; error_code ec;
int ret = lazy_bdecode((char*)buf, (char*)buf + sizeof(buf), e, ec); int ret = lazy_bdecode(reinterpret_cast<char*>(buf), reinterpret_cast<char*>(buf) + sizeof(buf), e, ec);
TEST_CHECK(ret == -1); TEST_CHECK(ret == -1);
} }
@ -492,7 +496,7 @@ TORRENT_TEST(lazy_entry)
std::printf("%s\n", print_entry(e).c_str()); std::printf("%s\n", print_entry(e).c_str());
pascal_string ps = e.dict_find_pstr("foobar"); 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); TEST_EQUAL(ps.len, 6);
ps = e.dict_find_pstr("foobar2"); ps = e.dict_find_pstr("foobar2");
@ -512,7 +516,7 @@ TORRENT_TEST(lazy_entry)
TEST_EQUAL(e.list_size(), 2); TEST_EQUAL(e.list_size(), 2);
pascal_string ps = e.list_pstr_at(0); 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); TEST_EQUAL(ps.len, 6);
ps = e.list_pstr_at(1); ps = e.list_pstr_at(1);
@ -539,7 +543,7 @@ TORRENT_TEST(lazy_entry)
lazy_entry e; lazy_entry e;
error_code ec; 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(ret, 0);
TEST_EQUAL(e.type(), lazy_entry::list_t); TEST_EQUAL(e.type(), lazy_entry::list_t);
TEST_EQUAL(e.list_size(), 1000); TEST_EQUAL(e.list_size(), 1000);
@ -563,7 +567,7 @@ TORRENT_TEST(lazy_entry)
std::printf("%s\n", buf.c_str()); std::printf("%s\n", buf.c_str());
lazy_entry e; lazy_entry e;
error_code ec; 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(ret, 0);
TEST_EQUAL(e.type(), lazy_entry::dict_t); TEST_EQUAL(e.type(), lazy_entry::dict_t);
TEST_EQUAL(e.dict_size(), 1000); TEST_EQUAL(e.dict_size(), 1000);
@ -635,4 +639,3 @@ TORRENT_TEST(lazy_entry)
} }
} }
#endif // TORRENT_NO_DEPRECATE #endif // TORRENT_NO_DEPRECATE

View File

@ -131,7 +131,7 @@ TORRENT_TEST(bitfield)
TEST_EQUAL(test1.count(), 101); TEST_EQUAL(test1.count(), 101);
std::uint8_t b1[] = { 0x08, 0x10 }; std::uint8_t b1[] = { 0x08, 0x10 };
test1.assign((char*)b1, 14); test1.assign(reinterpret_cast<char*>(b1), 14);
print_bitfield(test1); print_bitfield(test1);
TEST_EQUAL(test1.count(), 2); TEST_EQUAL(test1.count(), 2);
TEST_EQUAL(test1.get_bit(3), false); TEST_EQUAL(test1.get_bit(3), false);

View File

@ -50,31 +50,31 @@ namespace {
struct test_storage_impl : storage_interface struct test_storage_impl : storage_interface
{ {
explicit test_storage_impl(file_storage const& fs) : storage_interface(fs) {} 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<iovec_t const> bufs int readv(span<iovec_t const> 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); return bufs_size(bufs);
} }
int writev(span<iovec_t const> bufs int writev(span<iovec_t const> 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); return bufs_size(bufs);
} }
bool has_any_file(storage_error& ec) override { return false; } bool has_any_file(storage_error&) override { return false; }
void set_file_priority(aux::vector<download_priority_t, file_index_t> const& prio void set_file_priority(aux::vector<download_priority_t, file_index_t> const&
, storage_error& ec) override {} , storage_error&) override {}
status_t move_storage(std::string const& save_path, move_flags_t flags status_t move_storage(std::string const&, move_flags_t
, storage_error& ec) override { return status_t::no_error; } , storage_error&) override { return status_t::no_error; }
bool verify_resume_data(add_torrent_params const& rd bool verify_resume_data(add_torrent_params const&
, aux::vector<std::string, file_index_t> const& links , aux::vector<std::string, file_index_t> const&
, storage_error& ec) override { return true; } , storage_error&) override { return true; }
void release_files(storage_error& ec) override {} void release_files(storage_error&) override {}
void rename_file(file_index_t index, std::string const& new_filename void rename_file(file_index_t, std::string const&
, storage_error& ec) override {} , storage_error&) override {}
void delete_files(remove_flags_t, storage_error& ec) override {} void delete_files(remove_flags_t, storage_error&) override {}
}; };
struct allocator : buffer_allocator_interface struct allocator : buffer_allocator_interface
@ -90,6 +90,8 @@ struct allocator : buffer_allocator_interface
for (auto ref : refs) for (auto ref : refs)
m_cache.reclaim_block(m_storage, ref); m_cache.reclaim_block(m_storage, ref);
} }
virtual ~allocator() = default;
private: private:
block_cache& m_cache; block_cache& m_cache;
storage_interface* m_storage; storage_interface* m_storage;
@ -509,4 +511,3 @@ TORRENT_TEST(delete_piece)
TEST_CHECK(bc.num_pieces() == 0); TEST_CHECK(bc.num_pieces() == 0);
} }

View File

@ -38,6 +38,8 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace lt; using namespace lt;
namespace {
void test_set_and_get() void test_set_and_get()
{ {
bloom_filter<32> filter; bloom_filter<32> filter;
@ -120,6 +122,8 @@ void test_to_from_string()
TEST_EQUAL(memcmp(compare, bits_out.c_str(), 4), 0); TEST_EQUAL(memcmp(compare, bits_out.c_str(), 4), 0);
} }
} // anonymous namespace
TORRENT_TEST(bloom_filter) TORRENT_TEST(bloom_filter)
{ {
test_set_and_get(); test_set_and_get();
@ -130,4 +134,3 @@ TORRENT_TEST(bloom_filter)
// TODO: test size() // TODO: test size()
// TODO: test clear() // TODO: test clear()
} }

View File

@ -71,6 +71,8 @@ struct log_t : lt::dht::dht_logger
std::printf("%s [%s] %s", prefix[dir], print_endpoint(node).c_str() std::printf("%s [%s] %s", prefix[dir], print_endpoint(node).c_str()
, msg.c_str()); , msg.c_str());
} }
virtual ~log_t() = default;
}; };
#endif #endif
@ -100,4 +102,3 @@ TORRENT_TEST(dos_blocker)
#endif #endif
#endif #endif
} }

View File

@ -94,7 +94,7 @@ int read_message(tcp::socket& s, char* buffer, int max_size)
return -1; 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); , boost::asio::transfer_all(), ec);
if (ec) if (ec)
{ {
@ -739,7 +739,7 @@ TORRENT_TEST(multiple_bitfields)
print_session_log(*ses); print_session_log(*ses);
std::string bitfield; std::string bitfield;
bitfield.resize(ti->num_pieces(), '0'); bitfield.resize(std::size_t(ti->num_pieces()), '0');
send_bitfield(s, bitfield.c_str()); send_bitfield(s, bitfield.c_str());
print_session_log(*ses); print_session_log(*ses);
bitfield[0] = '1'; bitfield[0] = '1';
@ -970,6 +970,8 @@ TORRENT_TEST(invalid_request)
send_request(s, req); send_request(s, req);
} }
namespace {
void have_all_test(bool const incoming) void have_all_test(bool const incoming)
{ {
sha1_hash ih; sha1_hash ih;
@ -1007,6 +1009,8 @@ void have_all_test(bool const incoming)
} }
} }
} // anonymous namespace
TORRENT_TEST(outgoing_have_all) TORRENT_TEST(outgoing_have_all)
{ {
std::cout << "\n === test outgoing have-all ===\n" << std::endl; 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 // TODO: test sending invalid requests (out of bound piece index, offsets and
// sizes) // sizes)

View File

@ -51,7 +51,7 @@ int touch_file(std::string const& filename, int size)
std::vector<char> v; std::vector<char> v;
v.resize(aux::numeric_cast<std::size_t>(size)); v.resize(aux::numeric_cast<std::size_t>(size));
for (int i = 0; i < size; ++i) for (int i = 0; i < size; ++i)
v[i] = i & 255; v[std::size_t(i)] = char(i & 255);
file f; file f;
error_code ec; error_code ec;

View File

@ -65,11 +65,11 @@ TORRENT_TEST(init)
aux::vector<std::int64_t, file_index_t> vec; aux::vector<std::int64_t, file_index_t> vec;
fp.export_progress(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) for (file_index_t i(0); i < vec.end_index(); ++i)
sum += vec[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.init(picker, fs);
fp.export_progress(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) for (file_index_t i(0); i < vec.end_index(); ++i)
sum += vec[i]; sum += vec[i];
TEST_EQUAL(int(sum), fs.piece_size(idx)); TEST_EQUAL(sum, fs.piece_size(idx));
} }
} }

View File

@ -39,6 +39,8 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace lt; using namespace lt;
namespace {
void setup_test_storage(file_storage& st) void setup_test_storage(file_storage& st)
{ {
st.add_file(combine_path("test", "a"), 10000); 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); TEST_EQUAL(st.num_pieces(), (100000 + 0x3fff) / 0x4000);
} }
} // anonymous namespace
TORRENT_TEST(coalesce_path) TORRENT_TEST(coalesce_path)
{ {
file_storage st; 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))); 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<int> file_sizes void test_optimize(std::vector<int> file_sizes
, int const alignment , int const alignment
, int const pad_file_limit , int const pad_file_limit
@ -462,12 +468,14 @@ void test_optimize(std::vector<int> file_sizes
else else
{ {
TEST_EQUAL(fs.file_name(idx), std::to_string(expect)); 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; ++idx;
} }
} }
} // anonymous namespace
TORRENT_TEST(optimize_order_large_first) TORRENT_TEST(optimize_order_large_first)
{ {
test_optimize({1000, 3000, 10000}, 1024, 1024, false, {2, -1, 1, 0}); 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 file attributes
// TODO: test symlinks // TODO: test symlinks
// TODO: test reorder_file (make sure internal_file_entry::swap() is used) // TODO: test reorder_file (make sure internal_file_entry::swap() is used)

View File

@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace lt; using namespace lt;
namespace {
struct test_node : list_node<test_node> struct test_node : list_node<test_node>
{ {
explicit test_node(int v) : val(v) {} explicit test_node(int v) : val(v) {}
@ -52,6 +54,8 @@ void compare(linked_list<test_node> const& list, int* array, int size)
} }
} }
} // anonymous namespace
TORRENT_TEST(push_back) TORRENT_TEST(push_back)
{ {
test_node n0(0); test_node n0(0);
@ -195,4 +199,3 @@ TORRENT_TEST(iterate_backward)
it.prev(); it.prev();
TEST_EQUAL(it.get(), static_cast<test_node*>(nullptr)); TEST_EQUAL(it.get(), static_cast<test_node*>(nullptr));
} }

View File

@ -49,6 +49,8 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace lt; using namespace lt;
namespace {
struct mock_torrent; struct mock_torrent;
struct mock_peer_connection struct mock_peer_connection
@ -64,7 +66,7 @@ struct mock_peer_connection
, m_disconnect_called(false) , m_disconnect_called(false)
, m_torrent(*tor) , m_torrent(*tor)
{ {
for (int i = 0; i < 20; ++i) m_id[i] = rand(); aux::random_bytes(m_id);
} }
virtual ~mock_peer_connection() = default; virtual ~mock_peer_connection() = default;
@ -73,7 +75,7 @@ struct mock_peer_connection
bool should_log(peer_log_alert::direction_t) const noexcept override bool should_log(peer_log_alert::direction_t) const noexcept override
{ return true; } { 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 , char const* fmt, ...) const noexcept override
{ {
va_list v; va_list v;
@ -200,6 +202,8 @@ void connect_peer(peer_list& p, mock_torrent& t, torrent_state& st)
static torrent_peer_allocator allocator; static torrent_peer_allocator allocator;
} // anonymous namespace
// test multiple peers with the same IP // test multiple peers with the same IP
// when disallowing it // when disallowing it
TORRENT_TEST(multiple_ips_disallowed) TORRENT_TEST(multiple_ips_disallowed)
@ -371,11 +375,13 @@ TORRENT_TEST(update_peer_port_collide)
st.erased.clear(); st.erased.clear();
} }
namespace {
std::shared_ptr<mock_peer_connection> shared_from_this(lt::peer_connection_interface* p) std::shared_ptr<mock_peer_connection> shared_from_this(lt::peer_connection_interface* p)
{ {
return std::static_pointer_cast<mock_peer_connection>( return std::static_pointer_cast<mock_peer_connection>(
static_cast<mock_peer_connection*>(p)->shared_from_this()); static_cast<mock_peer_connection*>(p)->shared_from_this());
} }
} // anonymous namespace
// test ip filter // test ip filter
TORRENT_TEST(ip_filter) TORRENT_TEST(ip_filter)

View File

@ -46,6 +46,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "setup_transfer.hpp" #include "setup_transfer.hpp"
#include <iostream> #include <iostream>
namespace {
void test_pex() void test_pex()
{ {
using namespace lt; using namespace lt;
@ -148,6 +150,7 @@ void test_pex()
p2 = ses2.abort(); p2 = ses2.abort();
p3 = ses3.abort(); p3 = ses3.abort();
} }
} // anonymous namespace
#endif // TORRENT_DISABLE_EXTENSIONS #endif // TORRENT_DISABLE_EXTENSIONS
TORRENT_TEST(pex) TORRENT_TEST(pex)

View File

@ -527,14 +527,14 @@ TORRENT_TEST(pick_whole_pieces)
, &peer_struct, options, empty_vector); , &peer_struct, options, empty_vector);
TEST_EQUAL(int(picked.size()), 3); TEST_EQUAL(int(picked.size()), 3);
for (int i = 0; i < blocks_per_piece && i < int(picked.size()); ++i) 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", ""); p = setup_picker("1111111", " ", "1111111", "");
picked = pick_pieces(p, "****** ", 1, blocks_per_piece picked = pick_pieces(p, "****** ", 1, blocks_per_piece
, &peer_struct, options, empty_vector); , &peer_struct, options, empty_vector);
TEST_EQUAL(int(picked.size()), blocks_per_piece); TEST_EQUAL(int(picked.size()), blocks_per_piece);
for (int i = 0; i < blocks_per_piece && i < int(picked.size()); ++i) 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", " ", "", ""); p = setup_picker("2221222", " ", "", "");
picked = pick_pieces(p, "*******", 1, 7 * blocks_per_piece picked = pick_pieces(p, "*******", 1, 7 * blocks_per_piece

View File

@ -52,6 +52,8 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace lt; using namespace lt;
using std::ignore; using std::ignore;
namespace {
alert_category_t const mask = alert::all_categories & ~(alert::performance_warning | alert::stats_notification); alert_category_t const mask = alert::all_categories & ~(alert::performance_warning | alert::stats_notification);
int peer_disconnects = 0; int peer_disconnects = 0;
@ -386,6 +388,8 @@ done:
sp.push_back(ses2.abort()); sp.push_back(ses2.abort());
} }
} // anonymous namespace
TORRENT_TEST(priority) TORRENT_TEST(priority)
{ {
using namespace lt; using namespace lt;

View File

@ -39,6 +39,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/hex.hpp" // to_hex #include "libtorrent/hex.hpp" // to_hex
#include "libtorrent/aux_/path.hpp" #include "libtorrent/aux_/path.hpp"
namespace {
enum flags_t enum flags_t
{ {
seed_mode = 1, seed_mode = 1,
@ -149,6 +151,8 @@ void test_read_piece(int flags)
, ec.value(), ec.message().c_str()); , ec.value(), ec.message().c_str());
} }
} // anonymous namespace
TORRENT_TEST(read_piece) TORRENT_TEST(read_piece)
{ {
test_read_piece(0); test_read_piece(0);
@ -163,4 +167,3 @@ TORRENT_TEST(time_critical)
{ {
test_read_piece(time_critical); test_read_piece(time_critical);
} }

View File

@ -170,6 +170,7 @@ TORRENT_TEST(read_resume_mismatching_torrent)
TEST_CHECK(!atp.ti); TEST_CHECK(!atp.ti);
} }
namespace {
std::shared_ptr<torrent_info> generate_torrent() std::shared_ptr<torrent_info> generate_torrent()
{ {
file_storage fs; file_storage fs;
@ -186,7 +187,7 @@ std::shared_ptr<torrent_info> generate_torrent()
for (piece_index_t i(0); i < fs.end_piece(); ++i) for (piece_index_t i(0); i < fs.end_piece(); ++i)
{ {
sha1_hash ph; sha1_hash ph;
for (int k = 0; k < 20; ++k) ph[k] = lt::random(0xff); aux::random_bytes(ph);
t.set_hash(i, ph); t.set_hash(i, ph);
} }
@ -194,6 +195,7 @@ std::shared_ptr<torrent_info> generate_torrent()
bencode(std::back_inserter(buf), t.generate()); bencode(std::back_inserter(buf), t.generate());
return std::make_shared<torrent_info>(buf, from_span); return std::make_shared<torrent_info>(buf, from_span);
} }
} // anonymous namespace
TORRENT_TEST(read_resume_torrent) TORRENT_TEST(read_resume_torrent)
{ {

View File

@ -347,6 +347,8 @@ TORRENT_TEST(piece_slots)
} }
} }
namespace {
void test_piece_slots_seed(settings_pack const& sett) void test_piece_slots_seed(settings_pack const& sett)
{ {
// make sure the "pieces" field is correctly accepted from resume data // 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) TORRENT_TEST(piece_slots_seed)
{ {
test_piece_slots_seed(settings()); test_piece_slots_seed(settings());

View File

@ -51,6 +51,8 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace lt; using namespace lt;
namespace {
void test_running_torrent(std::shared_ptr<torrent_info> info, std::int64_t file_size) void test_running_torrent(std::shared_ptr<torrent_info> info, std::int64_t file_size)
{ {
settings_pack pack = settings(); settings_pack pack = settings();
@ -79,7 +81,7 @@ void test_running_torrent(std::shared_ptr<torrent_info> info, std::int64_t file_
return; return;
} }
aux::vector<download_priority_t, file_index_t> ones(info->num_files(), 1_pri); aux::vector<download_priority_t, file_index_t> ones(std::size_t(info->num_files()), 1_pri);
h.prioritize_files(ones); h.prioritize_files(ones);
torrent_status st = h.status(); torrent_status st = h.status();
@ -87,7 +89,7 @@ void test_running_torrent(std::shared_ptr<torrent_info> info, std::int64_t file_
TEST_EQUAL(st.total_wanted, file_size); // we want the single file TEST_EQUAL(st.total_wanted, file_size); // we want the single file
TEST_EQUAL(st.total_wanted_done, 0); TEST_EQUAL(st.total_wanted_done, 0);
aux::vector<download_priority_t, file_index_t> prio(info->num_files(), 1_pri); aux::vector<download_priority_t, file_index_t> prio(std::size_t(info->num_files()), 1_pri);
prio[file_index_t(0)] = 0_pri; prio[file_index_t(0)] = 0_pri;
h.prioritize_files(prio); h.prioritize_files(prio);
st = h.status(); st = h.status();
@ -128,9 +130,9 @@ void test_running_torrent(std::shared_ptr<torrent_info> info, std::int64_t file_
h.piece_priority(piece_index_t(0), 1_pri); h.piece_priority(piece_index_t(0), 1_pri);
st = h.status(); st = h.status();
TEST_CHECK(st.pieces.size() > 0 && st.pieces[piece_index_t(0)] == false); TEST_CHECK(st.pieces.size() > 0 && st.pieces[piece_index_t(0)] == false);
std::vector<char> piece(info->piece_length()); std::vector<char> piece(std::size_t(info->piece_length()));
for (int i = 0; i < int(piece.size()); ++i) 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); h.add_piece(piece_index_t(0), &piece[0], torrent_handle::overwrite_existing);
// wait until the piece is done writing and hashing // wait until the piece is done writing and hashing
@ -147,7 +149,8 @@ void test_running_torrent(std::shared_ptr<torrent_info> info, std::int64_t file_
if (rpa) if (rpa)
{ {
std::cout << "SUCCEEDED!" << std::endl; 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->size == info->piece_size(piece_index_t(0)));
TEST_CHECK(rpa->piece == 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))); TEST_CHECK(hasher(piece).final() == info->hash_for_piece(piece_index_t(0)));
@ -155,6 +158,8 @@ void test_running_torrent(std::shared_ptr<torrent_info> info, std::int64_t file_
} }
} }
} // anonymous namespace
TORRENT_TEST(long_names) TORRENT_TEST(long_names)
{ {
entry info; entry info;
@ -297,7 +302,7 @@ TORRENT_TEST(torrent)
std::vector<char> piece(128 * 1024); std::vector<char> piece(128 * 1024);
for (int i = 0; i < int(piece.size()); ++i) 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 // calculate the hash for all pieces
sha1_hash ph = hasher(piece).final(); sha1_hash ph = hasher(piece).final();
@ -340,7 +345,7 @@ TORRENT_TEST(duplicate_is_not_error)
std::vector<char> piece(128 * 1024); std::vector<char> piece(128 * 1024);
for (int i = 0; i < int(piece.size()); ++i) 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 // calculate the hash for all pieces
sha1_hash ph = hasher(piece).final(); sha1_hash ph = hasher(piece).final();
@ -456,7 +461,9 @@ TORRENT_TEST(torrent_status)
TEST_EQUAL(static_cast<int>(torrent_status::error_file_exception), -5); TEST_EQUAL(static_cast<int>(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(); lt::settings_pack pack = settings();
// we're not testing the hash check, just accept the data we write // 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))); torrents.push_back(ses.add_torrent(std::move(p)));
} }
std::vector<download_priority_t> pieces(torrents[5].torrent_file()->num_pieces(), 0_pri); std::vector<download_priority_t> pieces(
std::size_t(torrents[5].torrent_file()->num_pieces()), 0_pri);
torrents[5].prioritize_pieces(pieces); torrents[5].prioritize_pieces(pieces);
torrent_handle finished = torrents[5]; 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}); TEST_EQUAL(torrents[3].queue_position(), queue_position_t{4});
} }
} // anonymous namespace
TORRENT_TEST(queue) TORRENT_TEST(queue)
{ {
test_queue(add_torrent_params()); 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")); TEST_EQUAL(h.status().save_path, complete("save_path_1"));
} }

View File

@ -267,6 +267,7 @@ TORRENT_TEST(parse_external_ip6)
} }
#endif #endif
namespace {
peer_entry extract_peer(char const* peer_field, error_code expected_ec, bool expected_ret) peer_entry extract_peer(char const* peer_field, error_code expected_ec, bool expected_ret)
{ {
error_code ec; 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); TEST_EQUAL(expected_ec, ec);
return result; return result;
} }
} // anonymous namespace
TORRENT_TEST(extract_peer) TORRENT_TEST(extract_peer)
{ {
@ -320,6 +322,8 @@ TORRENT_TEST(extract_peer_missing_port)
, errors::invalid_tracker_response, false); , errors::invalid_tracker_response, false);
} }
namespace {
bool connect_alert(lt::alert const* a, tcp::endpoint& ep) bool connect_alert(lt::alert const* a, tcp::endpoint& ep)
{ {
if (peer_connect_alert const* pc = alert_cast<peer_connect_alert>(a)) if (peer_connect_alert const* pc = alert_cast<peer_connect_alert>(a))
@ -402,6 +406,8 @@ void test_udp_tracker(std::string const& iface, address tracker, tcp::endpoint c
stop_udp_tracker(); stop_udp_tracker();
} }
} // anonymous namespace
TORRENT_TEST(udp_tracker_v4) TORRENT_TEST(udp_tracker_v4)
{ {
test_udp_tracker("127.0.0.1", address_v4::any(), ep("1.3.3.7", 1337)); 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"); std::printf("done\n");
} }
namespace {
void test_proxy(bool proxy_trackers) void test_proxy(bool proxy_trackers)
{ {
int http_port = start_web_server(); int http_port = start_web_server();
@ -607,6 +615,8 @@ void test_proxy(bool proxy_trackers)
std::printf("done\n"); std::printf("done\n");
} }
} // anonymous namespace
TORRENT_TEST(tracker_proxy) TORRENT_TEST(tracker_proxy)
{ {
std::printf("\n\nnot proxying tracker connections (expect to reach the tracker)\n\n"); 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 #ifndef TORRENT_DISABLE_LOGGING
namespace {
void test_stop_tracker_timeout(int const timeout) void test_stop_tracker_timeout(int const timeout)
{ {
// trick the min interval so that the stopped anounce is permitted immediately // 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; if (num <= 0 && expected <= 0) return count;
} }
return count;
}; };
settings_pack p = settings(); 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); int const count = count_stopped_events(s, (timeout == 0) ? 0 : 1);
TEST_EQUAL(count, (timeout == 0) ? 0 : 1); TEST_EQUAL(count, (timeout == 0) ? 0 : 1);
} }
} // anonymous namespace
TORRENT_TEST(stop_tracker_timeout) TORRENT_TEST(stop_tracker_timeout)
{ {
@ -706,4 +717,3 @@ TORRENT_TEST(stop_tracker_timeout_zero_timeout)
test_stop_tracker_timeout(0); test_stop_tracker_timeout(0);
} }
#endif #endif

View File

@ -95,7 +95,7 @@ TORRENT_TEST(web_seed_redirect)
// disable keep-alive because otherwise the test will choke on seeing // disable keep-alive because otherwise the test will choke on seeing
// the disconnect (from the redirect) // 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(); stop_web_server();