fixing warnings in tests code, part3

This commit is contained in:
Alden Torres 2018-01-23 14:56:03 -05:00 committed by Arvid Norberg
parent 4fef787212
commit 8d379dd944
21 changed files with 115 additions and 51 deletions

View File

@ -153,7 +153,7 @@ int plugin_alerts[3] = { 0, 0, 0 };
struct test_plugin : lt::plugin
{
explicit test_plugin(int index) : m_index(index) {}
void on_alert(alert const* a) override
void on_alert(alert const*) override
{
++plugin_alerts[m_index];
}
@ -188,12 +188,16 @@ TORRENT_TEST(extensions)
#endif
}
namespace {
void post_torrent_added(alert_manager* mgr)
{
std::this_thread::sleep_for(lt::milliseconds(10));
mgr->emplace_alert<add_torrent_alert>(torrent_handle(), add_torrent_params(), error_code());
}
} // anonymous namespace
TORRENT_TEST(wait_for_alert)
{
alert_manager mgr(100, alert::all_categories);

View File

@ -52,6 +52,8 @@ struct peer_connection;
using namespace lt;
using namespace std::placeholders;
namespace {
const float sample_time = 20.f; // seconds
//#define VERBOSE_LOGGING
@ -455,6 +457,8 @@ void test_no_starvation(int limit)
TEST_CHECK(close_to(p->m_quota / sample_time, float(limit) / 200 / num_peers, 5));
}
} // anonymous namespace
TORRENT_TEST(equal_connection)
{
test_equal_connections( 2, 20);

View File

@ -37,10 +37,12 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace lt;
namespace {
void print_bitfield(bitfield const& b)
{
std::string out;
out.reserve(b.size());
out.reserve(std::size_t(b.size()));
for (bool bit : b)
out += bit ? '1' : '0';
std::printf("%s\n", out.c_str());
@ -63,6 +65,8 @@ void test_iterators(bitfield& test1)
TEST_EQUAL(num, test1.count());
}
} // anonymous namespace
TORRENT_TEST(bitfield)
{
bitfield test1(10, false);

View File

@ -1560,6 +1560,8 @@ TORRENT_TEST(put_v6)
}
#endif
namespace {
void test_routing_table(address(&rand_addr)())
{
dht_test_setup t(udp::endpoint(rand_addr(), 20));
@ -1767,6 +1769,8 @@ void test_routing_table(address(&rand_addr)())
}
}
} // anonymous namespace
TORRENT_TEST(routing_table_v4)
{
test_routing_table(rand_v4);

View File

@ -57,7 +57,6 @@ TORRENT_TEST(is_loopback)
#if TORRENT_USE_IPV6
if (supports_ipv6())
{
error_code ec;
TEST_CHECK(is_loopback(address::from_string("::1", ec)));
TEST_CHECK(!ec);
}

View File

@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/file.hpp"
#include "libtorrent/aux_/path.hpp"
#include "libtorrent/aux_/numeric_cast.hpp"
#include "libtorrent/string_util.hpp" // for split_string
#include "libtorrent/string_view.hpp"
#include "test.hpp"
@ -41,12 +42,14 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace lt;
namespace {
int touch_file(std::string const& filename, int size)
{
using namespace lt;
std::vector<char> v;
v.resize(size);
v.resize(aux::numeric_cast<std::size_t>(size));
for (int i = 0; i < size; ++i)
v[i] = i & 255;
@ -61,6 +64,8 @@ int touch_file(std::string const& filename, int size)
return 0;
}
} // anonymous namespace
TORRENT_TEST(create_directory)
{
error_code ec;

View File

@ -40,6 +40,8 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
namespace lt = libtorrent;
namespace {
void test_add_and_get_flags(torrent_flags_t const flags)
{
session ses(settings());
@ -89,6 +91,8 @@ void test_unset_after_add(torrent_flags_t const flags)
TEST_EQUAL(h.flags() & flags, torrent_flags_t{});
}
} // anonymous namespace
TORRENT_TEST(flag_seed_mode)
{
// seed-mode (can't be set after adding)

View File

@ -87,7 +87,7 @@ TORRENT_TEST(hasher)
h.update(test_array[test], int(std::strlen(test_array[test])));
sha1_hash result;
aux::from_hex({result_array[test], 40}, (char*)&result[0]);
aux::from_hex({result_array[test], 40}, result.data());
TEST_CHECK(result == h.final());
}
}

View File

@ -83,7 +83,8 @@ namespace
, int const original_port, char const* device = "")
{
auto s = std::make_shared<aux::listen_socket_t>();
s->local_endpoint = tcp::endpoint(address::from_string(ip), port);
s->local_endpoint = tcp::endpoint(address::from_string(ip)
, aux::numeric_cast<std::uint16_t>(port));
s->original_port = original_port;
s->device = device;
return s;

View File

@ -450,6 +450,8 @@ TORRENT_TEST(invalid_web_seed_escaping)
TEST_CHECK(ec);
}
namespace {
auto const yes = default_priority;
auto const no = dont_download;
@ -459,6 +461,8 @@ void test_select_only(string_view uri, std::vector<download_priority_t> expected
TEST_CHECK(p.file_priorities == expected);
}
} // anonymous namespace
TORRENT_TEST(parse_magnet_select_only)
{
test_select_only("magnet:?xt=urn:btih:cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"

View File

@ -67,7 +67,7 @@ TORRENT_TEST(part_file)
TEST_CHECK(!exists(combine_path(combine_path(cwd, "partfile_test_dir"), "partfile.parts")));
// write something to the metadata file
for (int i = 0; i < 1024; ++i) buf[i] = i;
for (int i = 0; i < 1024; ++i) buf[i] = char(i & 0xff);
iovec_t v = buf;
pf.writev(v, piece_index_t(10), 0, ec);
@ -86,7 +86,7 @@ TORRENT_TEST(part_file)
TEST_CHECK(!exists(combine_path(combine_path(cwd, "partfile_test_dir"), "partfile.parts")));
TEST_CHECK(exists(combine_path(combine_path(cwd, "partfile_test_dir2"), "partfile.parts")));
memset(buf, 0, sizeof(buf));
std::memset(buf, 0, sizeof(buf));
pf.readv(v, piece_index_t(10), 0, ec);
if (ec) std::printf("part_file::readv: %s\n", ec.message().c_str());
@ -99,7 +99,7 @@ TORRENT_TEST(part_file)
// load the part file back in
part_file pf(combine_path(cwd, "partfile_test_dir2"), "partfile.parts", 100, piece_size);
memset(buf, 0, sizeof(buf));
std::memset(buf, 0, sizeof(buf));
iovec_t v = buf;
pf.readv(v, piece_index_t(10), 0, ec);
@ -113,9 +113,9 @@ TORRENT_TEST(part_file)
std::string output_filename = combine_path(combine_path(cwd, "partfile_test_dir")
, "part_file_test_export");
pf.export_file([](std::int64_t file_offset, span<char> buf)
pf.export_file([](std::int64_t file_offset, span<char> buf_data)
{
for (char i : buf)
for (char i : buf_data)
{
// make sure we got the bytes we expected
TEST_CHECK(i == static_cast<char>(file_offset));
@ -136,4 +136,3 @@ TORRENT_TEST(part_file)
if (ec) std::printf("exists: %s\n", ec.message().c_str());
}
}

View File

@ -146,8 +146,8 @@ struct mock_torrent
std::vector<std::shared_ptr<mock_peer_connection>> m_connections;
};
void mock_peer_connection::disconnect(error_code const& ec
, operation_t op, int error)
void mock_peer_connection::disconnect(error_code const&
, operation_t, int /*error*/)
{
m_torrent.m_p->connection_closed(*this, 0, m_torrent.m_state);
auto const i = std::find(m_torrent.m_connections.begin(), m_torrent.m_connections.end()

View File

@ -51,6 +51,8 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace lt;
using namespace std::placeholders;
namespace {
const int blocks_per_piece = 4;
typed_bitfield<piece_index_t> string2vec(char const* have_str)
@ -79,7 +81,7 @@ ipv4_peer* tmp_peer = &tmp1;
static std::vector<piece_index_t> const empty_vector;
#if TORRENT_USE_ASSERTS
namespace {
namespace { // TODO: remove the nested namespace
static struct initializer
{
initializer()
@ -293,6 +295,8 @@ piece_index_t test_pick(std::shared_ptr<piece_picker> const& p
const int options = piece_picker::rarest_first;
counters pc;
} // anonymous namespace
TORRENT_TEST(piece_block)
{
piece_index_t const zero(0);

View File

@ -48,6 +48,8 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace lt;
namespace {
char const* proxy_name[] = {
"none",
"socks4",
@ -244,6 +246,8 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
return pr;
}
} // anonymous namespace
// not using anonymous mode
// UDP fails open if we can't connect to the proxy
// or if the proxy doesn't support UDP
@ -330,4 +334,3 @@ TORRENT_TEST(anon_i2p)
test_proxy(settings_pack::i2p_proxy, force_proxy_mode);
}
#endif

View File

@ -49,6 +49,8 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace lt;
namespace {
auto const mask = alert::all_categories & ~(alert::performance_warning | alert::stats_notification);
void wait_for_complete(lt::session& ses, torrent_handle h)
@ -74,6 +76,8 @@ void wait_for_complete(lt::session& ses, torrent_handle h)
TEST_ERROR("torrent did not finish");
}
} // anonymous namespace
TORRENT_TEST(recheck)
{
error_code ec;
@ -115,4 +119,3 @@ TORRENT_TEST(recheck)
TEST_CHECK(st1.progress_ppm <= 1000000);
wait_for_complete(ses1, tor1);
}

View File

@ -246,7 +246,7 @@ void test_piece_priorities(bool test_deprecated = false)
TEST_EQUAL(int(prios.size()), ti->num_pieces());
TEST_EQUAL(prios[0], 0_pri);
TEST_EQUAL(prios[1], 4_pri);
TEST_EQUAL(prios[ti->num_pieces()-1], 0_pri);
TEST_EQUAL(prios[std::size_t(ti->num_pieces() - 1)], 0_pri);
std::vector<char> resume_data = write_resume_data_buf(ra->params);
@ -819,6 +819,8 @@ TORRENT_TEST(file_priorities_seed_mode)
TEST_EQUAL(file_priorities[2], 0_pri);
}
namespace {
void test_zero_file_prio(bool test_deprecated = false)
{
std::printf("test_file_prio\n");
@ -872,6 +874,8 @@ void test_zero_file_prio(bool test_deprecated = false)
TEST_EQUAL(s.total_wanted, 0);
}
} // anonymous namespace
#ifndef TORRENT_NO_DEPRECATE
TORRENT_TEST(zero_file_prio_deprecated)
{
@ -943,6 +947,8 @@ namespace test_mode {
#endif
}
namespace {
void test_seed_mode(test_mode_t const flags)
{
lt::session ses(settings());
@ -1020,6 +1026,9 @@ void test_seed_mode(test_mode_t const flags)
TEST_CHECK(s.flags & torrent_flags::seed_mode);
}
}
} // anonymous namespace
#ifndef TORRENT_NO_DEPRECATE
TORRENT_TEST(seed_mode_file_prio_deprecated)
{
@ -1278,4 +1287,3 @@ TORRENT_TEST(paused)
// more than just the torrent_status from test_resume_flags. Also http seeds
// and trackers for instance
}

View File

@ -33,6 +33,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "test.hpp"
#include "libtorrent/sliding_average.hpp"
namespace {
// normal distributed samples. mean=60 stddev=10
int samples[] = {
49, 51, 60, 46, 65, 53, 76, 59, 57, 54, 56, 51, 45, 80, 53, 62,
@ -44,6 +46,8 @@ int samples[] = {
67, 51, 66, 52, 48, 57, 30, 51, 72, 65, 78, 56, 74, 68, 49, 66,
63, 57, 61, 62, 64, 62, 61, 52, 67, 64, 59, 61, 69, 60, 54, 69 };
} // anonymous namespace
using namespace lt;
// make sure we react quickly for the first few samples
@ -111,4 +115,3 @@ TORRENT_TEST(sliding_average)
TEST_CHECK(abs(avg.mean() - 250) < 50);
TEST_CHECK(abs(avg.avg_deviation() - 250) < 80);
}

View File

@ -414,7 +414,7 @@ void test_rename(std::string const& test_path)
void test_check_files(std::string const& test_path
, lt::storage_mode_t storage_mode
, bool unbuffered)
, bool /*unbuffered*/)
{
std::shared_ptr<torrent_info> info;
@ -748,6 +748,7 @@ TORRENT_TEST(fastresume_deprecated)
}
#endif
namespace {
bool got_file_rename_alert(alert const* a)
{
@ -755,6 +756,8 @@ bool got_file_rename_alert(alert const* a)
|| alert_cast<lt::file_rename_failed_alert>(a);
}
} // anonymous namespace
TORRENT_TEST(rename_file)
{
std::vector<char> buf;
@ -777,7 +780,7 @@ TORRENT_TEST(rename_file)
torrent_handle h = ses.add_torrent(std::move(p), ec);
// make it a seed
std::vector<char> tmp(info->piece_length());
std::vector<char> tmp(std::size_t(info->piece_length()));
for (piece_index_t i(0); i < fs.end_piece(); ++i)
h.add_piece(i, &tmp[0]);
@ -820,6 +823,8 @@ TORRENT_TEST(rename_file)
}
}
namespace {
void test_rename_file_fastresume(bool test_deprecated)
{
std::string test_path = current_working_directory();
@ -928,6 +933,8 @@ void test_rename_file_fastresume(bool test_deprecated)
<< "': " << ec.message() << std::endl;
}
} // anonymous namespace
TORRENT_TEST(rename_file_fastresume)
{
test_rename_file_fastresume(false);
@ -940,6 +947,8 @@ TORRENT_TEST(rename_file_fastresume_deprecated)
}
#endif
namespace {
void alloc_iov(iovec_t* iov, int num_bufs)
{
for (int i = 0; i < num_bufs; ++i)
@ -957,7 +966,7 @@ void fill_pattern(iovec_t* iov, int num_bufs)
{
for (char& v : iov[i])
{
v = counter & 0xff;
v = char(counter & 0xff);
++counter;
}
}
@ -965,7 +974,7 @@ void fill_pattern(iovec_t* iov, int num_bufs)
bool check_pattern(std::vector<char> const& buf, int counter)
{
unsigned char* p = (unsigned char*)&buf[0];
unsigned char const* p = reinterpret_cast<unsigned char const*>(buf.data());
for (int k = 0; k < int(buf.size()); ++k)
{
if (p[k] != (counter & 0xff)) return false;
@ -974,15 +983,6 @@ bool check_pattern(std::vector<char> const& buf, int counter)
return true;
}
// TODO: this should take a span
void fill_pattern2(iovec_t* iov, int num_bufs)
{
for (int i = 0; i < num_bufs; ++i)
{
memset(iov[i].data(), 0xfe, iov[i].size());
}
}
// TODO: this should take a span
void free_iov(iovec_t* iov, int num_bufs)
{
@ -993,6 +993,8 @@ void free_iov(iovec_t* iov, int num_bufs)
}
}
} // anonymous namespace
TORRENT_TEST(iovec_copy_bufs)
{
iovec_t iov1[10];
@ -1088,6 +1090,8 @@ TORRENT_TEST(iovec_advance_bufs)
TORRENT_TEST(unbuffered) { run_test(true); }
TORRENT_TEST(buffered) { run_test(false); }
namespace {
file_storage make_fs()
{
file_storage fs;
@ -1105,15 +1109,15 @@ struct test_fileop
explicit test_fileop(int stripe_size) : m_stripe_size(stripe_size) {}
int operator()(file_index_t const file_index, std::int64_t const file_offset
, span<iovec_t const> bufs, storage_error& ec)
, span<iovec_t const> bufs, storage_error&)
{
size_t offset = size_t(file_offset);
std::size_t offset = size_t(file_offset);
if (file_index >= m_file_data.end_index())
{
m_file_data.resize(static_cast<int>(file_index) + 1);
}
const int write_size = std::min(m_stripe_size, bufs_size(bufs));
std::size_t const write_size = std::size_t(std::min(m_stripe_size, bufs_size(bufs)));
std::vector<char>& file = m_file_data[file_index];
@ -1122,16 +1126,16 @@ struct test_fileop
file.resize(offset + write_size);
}
int left = write_size;
int left = int(write_size);
while (left > 0)
{
const int copy_size = std::min(left, int(bufs.front().size()));
memcpy(&file[offset], bufs.front().data(), copy_size);
std::size_t const copy_size = std::size_t(std::min(left, int(bufs.front().size())));
std::memcpy(&file[offset], bufs.front().data(), copy_size);
bufs = bufs.subspan(1);
offset += copy_size;
left -= copy_size;
left -= int(copy_size);
}
return write_size;
return int(write_size);
}
int m_stripe_size;
@ -1143,18 +1147,18 @@ struct test_read_fileop
// EOF after size bytes read
explicit test_read_fileop(int size) : m_size(size), m_counter(0) {}
int operator()(file_index_t const file_index, std::int64_t const file_offset
, span<iovec_t const> bufs, storage_error& ec)
int operator()(file_index_t, std::int64_t /*file_offset*/
, span<iovec_t const> bufs, storage_error&)
{
int local_size = std::min(m_size, bufs_size(bufs));
const int read = local_size;
while (local_size > 0)
{
int const len = std::min(int(bufs.front().size()), local_size);
auto local_buf = bufs.front().first(len);
auto local_buf = bufs.front().first(std::size_t(len));
for (char& v : local_buf)
{
v = m_counter & 0xff;
v = char(m_counter & 0xff);
++m_counter;
}
local_size -= len;
@ -1174,7 +1178,7 @@ struct test_error_fileop
explicit test_error_fileop(file_index_t error_file)
: m_error_file(error_file) {}
int operator()(file_index_t const file_index, std::int64_t const file_offset
int operator()(file_index_t const file_index, std::int64_t /*file_offset*/
, span<iovec_t const> bufs, storage_error& ec)
{
if (m_error_file == file_index)
@ -1203,6 +1207,8 @@ int count_bufs(iovec_t const* bufs, int bytes)
}
}
} // anonymous namespace
TORRENT_TEST(readwritev_stripe_1)
{
const int num_bufs = 30;
@ -1345,6 +1351,8 @@ TORRENT_TEST(readwritev_zero_size_files)
TEST_CHECK(check_pattern(buf, 0));
}
namespace {
void delete_dirs(std::string path)
{
error_code ec;
@ -1357,6 +1365,8 @@ void delete_dirs(std::string path)
TEST_CHECK(!exists(path));
}
} // anonymous namespace
TORRENT_TEST(move_storage_to_self)
{
// call move_storage with the path to the exising storage. should be a no-op

View File

@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace lt;
namespace {
struct test_node : tailqueue_node<test_node>
{
explicit test_node(char n) : name(n) {}
@ -83,6 +85,8 @@ void build_chain(tailqueue<test_node>& q, char const* str)
check_chain(q, expected);
}
} // anonymous namespace
TORRENT_TEST(tailqueue)
{
tailqueue<test_node> t1;
@ -146,7 +150,7 @@ TORRENT_TEST(tailqueue)
// test get_all
build_chain(t1, "abcdef");
test_node* n = (test_node*)t1.get_all();
test_node* n = t1.get_all();
TEST_EQUAL(t1.empty(), true);
TEST_EQUAL(t1.size(), 0);
@ -155,7 +159,7 @@ TORRENT_TEST(tailqueue)
{
test_node* del = n;
TEST_EQUAL(n->name, *expected);
n = (test_node*)n->next;
n = n->next;
++expected;
delete del;
}
@ -163,4 +167,3 @@ TORRENT_TEST(tailqueue)
free_chain(t1);
free_chain(t2);
}

View File

@ -864,6 +864,8 @@ TORRENT_TEST(parse_torrents)
}
}
namespace {
void test_resolve_duplicates(int test_case)
{
file_storage fs;
@ -952,6 +954,8 @@ void test_resolve_duplicates(int test_case)
}
}
} // anonymous namespace
TORRENT_TEST(resolve_duplicates)
{
for (int i = 0; i < 4; ++i)

View File

@ -100,5 +100,3 @@ TORRENT_TEST(web_seed_redirect)
stop_web_server();
}