forked from premiere/premiere-libtorrent
fixing warnings in tests code, part1 (#2700)
This commit is contained in:
parent
ed7ef8fdd6
commit
13e54a3da8
|
@ -50,7 +50,7 @@ namespace
|
|||
secret_key sk;
|
||||
public_key pk;
|
||||
signature sig;
|
||||
std::vector<char> msg(int(message.size()) / 2);
|
||||
std::vector<char> msg(message.size() / 2);
|
||||
|
||||
aux::from_hex(seed, s.data());
|
||||
std::tie(pk, sk) = ed25519_create_keypair(s);
|
||||
|
@ -208,7 +208,7 @@ TORRENT_TEST(create_seed)
|
|||
|
||||
int n1 = 0;
|
||||
int n2 = 0;
|
||||
for (int i = 0; i < 32; i++)
|
||||
for (std::size_t i = 0; i < 32; i++)
|
||||
{
|
||||
if (s1[i] != 0) n1++;
|
||||
if (s2[i] != 0) n2++;
|
||||
|
|
|
@ -47,6 +47,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
using namespace lt;
|
||||
using std::ignore;
|
||||
|
||||
namespace {
|
||||
|
||||
bool all_of(std::vector<bool> const& v)
|
||||
{
|
||||
return std::all_of(v.begin(), v.end(), [](bool v){ return v; });
|
||||
|
@ -196,6 +198,8 @@ void test_remap_files(storage_mode_t storage_mode = storage_mode_sparse)
|
|||
TEST_CHECK(st.is_seeding);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TORRENT_TEST(remap_files)
|
||||
{
|
||||
test_remap_files();
|
||||
|
|
|
@ -94,7 +94,7 @@ void test_remove_torrent(remove_flags_t const remove_options
|
|||
|
||||
if (test == partial_download)
|
||||
{
|
||||
std::vector<download_priority_t> priorities(num_pieces, low_priority);
|
||||
std::vector<download_priority_t> priorities(std::size_t(num_pieces), low_priority);
|
||||
// set half of the pieces to priority 0
|
||||
std::fill(priorities.begin(), priorities.begin() + (num_pieces / 2), dont_download);
|
||||
tor2.prioritize_pieces(priorities);
|
||||
|
|
|
@ -41,9 +41,13 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
using namespace lt;
|
||||
|
||||
namespace {
|
||||
|
||||
span<char const> f(span<char const> x) { return x; }
|
||||
span<span<char>> g(span<span<char>> x) { return x; }
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TORRENT_TEST(span_vector)
|
||||
{
|
||||
std::vector<char> v1 = {1,2,3,4};
|
||||
|
@ -52,6 +56,8 @@ TORRENT_TEST(span_vector)
|
|||
TEST_CHECK(a.size() == 4);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void do_span_temp_vector(span<char const> a)
|
||||
{
|
||||
std::vector<char> v1 = {1,2,3,4};
|
||||
|
@ -59,6 +65,8 @@ void do_span_temp_vector(span<char const> a)
|
|||
TEST_CHECK(a.size() == 4);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TORRENT_TEST(span_temp_vector)
|
||||
{
|
||||
do_span_temp_vector(std::vector<char>{1,2,3,4});
|
||||
|
|
|
@ -60,6 +60,8 @@ using namespace std::placeholders;
|
|||
using namespace lt;
|
||||
using std::ignore;
|
||||
|
||||
namespace {
|
||||
|
||||
auto const alert_mask = alert::all_categories
|
||||
& ~alert::progress_notification
|
||||
& ~alert::stats_notification;
|
||||
|
@ -233,7 +235,7 @@ void test_ssl(int test_idx, bool use_utp)
|
|||
std::printf("\n\n%s: ses1: connecting peer port: %d\n\n\n"
|
||||
, time_now_string(), port);
|
||||
tor1.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec)
|
||||
, port));
|
||||
, std::uint16_t(port)));
|
||||
|
||||
const int timeout = 40;
|
||||
for (int i = 0; i < timeout; ++i)
|
||||
|
@ -301,7 +303,7 @@ void test_ssl(int test_idx, bool use_utp)
|
|||
p2 = ses2.abort();
|
||||
}
|
||||
|
||||
std::string password_callback(int length, boost::asio::ssl::context::password_purpose p
|
||||
std::string password_callback(int /*length*/, boost::asio::ssl::context::password_purpose p
|
||||
, std::string pw)
|
||||
{
|
||||
if (p != boost::asio::ssl::context::for_reading) return "";
|
||||
|
@ -442,7 +444,7 @@ bool try_connect(lt::session& ses1, int port
|
|||
|
||||
std::printf("connecting 127.0.0.1:%d\n", port);
|
||||
ssl_sock.lowest_layer().connect(tcp::endpoint(
|
||||
address_v4::from_string("127.0.0.1"), port), ec);
|
||||
address_v4::from_string("127.0.0.1"), std::uint16_t(port)), ec);
|
||||
print_alerts(ses1, "ses1", true, true, &on_alert);
|
||||
|
||||
if (ec)
|
||||
|
@ -599,6 +601,8 @@ void test_malicious_peer()
|
|||
TEST_EQUAL(success, attacks[i].expect);
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
#endif // TORRENT_USE_OPENSSL
|
||||
|
||||
TORRENT_TEST(malicious_peer)
|
||||
|
|
|
@ -59,7 +59,7 @@ TORRENT_TEST(hex)
|
|||
TEST_CHECK(aux::from_hex({str, 40}, bin));
|
||||
char hex[41];
|
||||
aux::to_hex(bin, hex);
|
||||
TEST_CHECK(strcmp(hex, str) == 0);
|
||||
TEST_CHECK(std::strcmp(hex, str) == 0);
|
||||
|
||||
TEST_CHECK(aux::to_hex({"\x55\x73",2}) == "5573");
|
||||
TEST_CHECK(aux::to_hex({"\xaB\xd0",2}) == "abd0");
|
||||
|
@ -68,9 +68,9 @@ TORRENT_TEST(hex)
|
|||
|
||||
for (int i = 1; i < 255; ++i)
|
||||
{
|
||||
bool const hex = strchr(hex_chars, i) != nullptr;
|
||||
char const c = i;
|
||||
TEST_EQUAL(aux::is_hex(c), hex);
|
||||
bool const hex_loop = std::strchr(hex_chars, i) != nullptr;
|
||||
char const c = char(i);
|
||||
TEST_EQUAL(aux::is_hex(c), hex_loop);
|
||||
}
|
||||
|
||||
TEST_EQUAL(aux::hex_to_int('0'), 0);
|
||||
|
@ -355,6 +355,8 @@ TORRENT_TEST(path)
|
|||
#endif
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void test_parse_interface(char const* input
|
||||
, std::vector<listen_interface_t> expected
|
||||
, std::string output)
|
||||
|
@ -371,6 +373,8 @@ void test_parse_interface(char const* input
|
|||
TEST_EQUAL(print_listen_interfaces(list), output);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TORRENT_TEST(parse_list)
|
||||
{
|
||||
std::vector<std::string> list;
|
||||
|
|
|
@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
using namespace lt;
|
||||
|
||||
namespace {
|
||||
|
||||
void fun(std::condition_variable* s, std::mutex* m, int* waiting, int i)
|
||||
{
|
||||
std::printf("thread %d waiting\n", i);
|
||||
|
@ -71,6 +73,8 @@ void decrement(std::condition_variable* s, std::mutex* m, int* waiting, std::ato
|
|||
--*c;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TORRENT_TEST(threads)
|
||||
{
|
||||
std::condition_variable cond;
|
||||
|
|
|
@ -41,6 +41,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
using namespace lt;
|
||||
|
||||
namespace {
|
||||
|
||||
void check_timer_loop(std::mutex& m, time_point& last, std::condition_variable& cv)
|
||||
{
|
||||
std::unique_lock<std::mutex> l(m);
|
||||
|
@ -49,13 +51,15 @@ void check_timer_loop(std::mutex& m, time_point& last, std::condition_variable&
|
|||
|
||||
for (int i = 0; i < 10000; ++i)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m);
|
||||
std::lock_guard<std::mutex> ll(m);
|
||||
time_point now = clock_type::now();
|
||||
TEST_CHECK(now >= last);
|
||||
last = now;
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TORRENT_TEST(time)
|
||||
{
|
||||
// make sure the time classes have correct semantics
|
||||
|
|
|
@ -84,6 +84,8 @@ TORRENT_TEST(mutable_torrents)
|
|||
}
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
struct test_torrent_t
|
||||
{
|
||||
char const* file;
|
||||
|
@ -163,6 +165,8 @@ test_failing_torrent_t test_error_torrents[] =
|
|||
{ "no_files.torrent", errors::no_files_in_torrent},
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// TODO: test remap_files
|
||||
// TODO: merkle torrents. specifically torrent_info::add_merkle_nodes and torrent with "root hash"
|
||||
// TODO: torrent with 'p' (padfile) attribute
|
||||
|
@ -666,9 +670,9 @@ TORRENT_TEST(parse_torrents)
|
|||
|
||||
std::vector<char> buf;
|
||||
bencode(std::back_inserter(buf), torrent);
|
||||
torrent_info ti(buf, from_span);
|
||||
std::cout << ti.name() << std::endl;
|
||||
TEST_CHECK(ti.name() == "test1");
|
||||
torrent_info ti1(buf, from_span);
|
||||
std::cout << ti1.name() << std::endl;
|
||||
TEST_CHECK(ti1.name() == "test1");
|
||||
|
||||
#ifdef TORRENT_WINDOWS
|
||||
info["name.utf-8"] = "c:/test1/test2/test3";
|
||||
|
|
|
@ -46,6 +46,8 @@ using namespace lt;
|
|||
|
||||
using lt::portmap_protocol;
|
||||
|
||||
namespace {
|
||||
|
||||
broadcast_socket* sock = nullptr;
|
||||
int g_port = 0;
|
||||
|
||||
|
@ -115,14 +117,14 @@ struct callback_info
|
|||
|
||||
std::list<callback_info> callbacks;
|
||||
|
||||
namespace
|
||||
namespace // TODO: remove this nested namespace
|
||||
{
|
||||
struct upnp_callback : aux::portmap_callback
|
||||
{
|
||||
void on_port_mapping(port_mapping_t const mapping
|
||||
, address const& ip, int port
|
||||
, portmap_protocol const protocol, error_code const& err
|
||||
, portmap_transport const transport) override
|
||||
, portmap_transport) override
|
||||
{
|
||||
callback_info info = {mapping, port, err};
|
||||
callbacks.push_back(info);
|
||||
|
@ -132,12 +134,12 @@ namespace
|
|||
<< ", error: \"" << err.message() << "\"\n";
|
||||
}
|
||||
#ifndef TORRENT_DISABLE_LOGGING
|
||||
virtual bool should_log_portmap(portmap_transport transport) const override
|
||||
virtual bool should_log_portmap(portmap_transport) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void log_portmap(portmap_transport transport, char const* msg) const override
|
||||
virtual void log_portmap(portmap_transport, char const* msg) const override
|
||||
{
|
||||
std::cout << "UPnP: " << msg << std::endl;
|
||||
//TODO: store the log and verify that some key messages are there
|
||||
|
@ -253,6 +255,8 @@ void run_upnp_test(char const* root_filename, char const* router_model, char con
|
|||
delete sock;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TORRENT_TEST(upnp)
|
||||
{
|
||||
run_upnp_test(combine_path("..", "root1.xml").c_str(), "Xtreme N GIGABIT Router", "wipconn", 1);
|
||||
|
|
|
@ -47,6 +47,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
using namespace lt;
|
||||
|
||||
namespace {
|
||||
|
||||
void test_transfer()
|
||||
{
|
||||
// in case the previous run was terminated
|
||||
|
@ -132,6 +134,8 @@ void test_transfer()
|
|||
p2 = ses2.abort();
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TORRENT_TEST(utp)
|
||||
{
|
||||
test_transfer();
|
||||
|
|
|
@ -36,6 +36,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <iostream>
|
||||
#include <functional>
|
||||
|
||||
namespace {
|
||||
|
||||
char upnp_xml[] =
|
||||
"<root>"
|
||||
"<specVersion>"
|
||||
|
@ -306,6 +308,8 @@ void test_parse(char const* in, char const* expected)
|
|||
TEST_EQUAL(out, expected);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TORRENT_TEST(upnp_parser1)
|
||||
{
|
||||
parse_state xml_s;
|
||||
|
|
Loading…
Reference in New Issue