Skip to content

Commit

Permalink
fixing warnings in tests code, part3
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml authored and arvidn committed Jan 25, 2018
1 parent 4fef787 commit 8d379dd
Show file tree
Hide file tree
Showing 21 changed files with 115 additions and 51 deletions.
6 changes: 5 additions & 1 deletion test/test_alert_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions test/test_bandwidth_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion test/test_bitfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -63,6 +65,8 @@ void test_iterators(bitfield& test1)
TEST_EQUAL(num, test1.count());
}

} // anonymous namespace

TORRENT_TEST(bitfield)
{
bitfield test1(10, false);
Expand Down
4 changes: 4 additions & 0 deletions test/test_dht.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -1767,6 +1769,8 @@ void test_routing_table(address(&rand_addr)())
}
}

} // anonymous namespace

TORRENT_TEST(routing_table_v4)
{
test_routing_table(rand_v4);
Expand Down
1 change: 0 additions & 1 deletion test/test_enum_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 6 additions & 1 deletion test/test_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;

Expand All @@ -61,6 +64,8 @@ int touch_file(std::string const& filename, int size)
return 0;
}

} // anonymous namespace

TORRENT_TEST(create_directory)
{
error_code ec;
Expand Down
4 changes: 4 additions & 0 deletions test/test_flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/test_hasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/test_listen_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions test/test_magnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ TORRENT_TEST(invalid_web_seed_escaping)
TEST_CHECK(ec);
}

namespace {

auto const yes = default_priority;
auto const no = dont_download;

Expand All @@ -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"
Expand Down
11 changes: 5 additions & 6 deletions test/test_part_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -136,4 +136,3 @@ TORRENT_TEST(part_file)
if (ec) std::printf("exists: %s\n", ec.message().c_str());
}
}

4 changes: 2 additions & 2 deletions test/test_peer_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion test/test_piece_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion test/test_privacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ POSSIBILITY OF SUCH DAMAGE.

using namespace lt;

namespace {

char const* proxy_name[] = {
"none",
"socks4",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -330,4 +334,3 @@ TORRENT_TEST(anon_i2p)
test_proxy(settings_pack::i2p_proxy, force_proxy_mode);
}
#endif

5 changes: 4 additions & 1 deletion test/test_recheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -115,4 +119,3 @@ TORRENT_TEST(recheck)
TEST_CHECK(st1.progress_ppm <= 1000000);
wait_for_complete(ses1, tor1);
}

12 changes: 10 additions & 2 deletions test/test_resume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -943,6 +947,8 @@ namespace test_mode {
#endif
}

namespace {

void test_seed_mode(test_mode_t const flags)
{
lt::session ses(settings());
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -1278,4 +1287,3 @@ TORRENT_TEST(paused)
// more than just the torrent_status from test_resume_flags. Also http seeds
// and trackers for instance
}

5 changes: 4 additions & 1 deletion test/test_sliding_average.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -111,4 +115,3 @@ TORRENT_TEST(sliding_average)
TEST_CHECK(abs(avg.mean() - 250) < 50);
TEST_CHECK(abs(avg.avg_deviation() - 250) < 80);
}

Loading

0 comments on commit 8d379dd

Please sign in to comment.