fixing warnings in tests code, part8
This commit is contained in:
parent
5d230a69f2
commit
4abeacdf33
|
@ -207,7 +207,7 @@ private:
|
|||
|
||||
TORRENT_TEST(chained_buffer)
|
||||
{
|
||||
char data[] = "foobar";
|
||||
char data_test[] = "foobar";
|
||||
{
|
||||
chained_buffer b;
|
||||
|
||||
|
@ -222,7 +222,7 @@ TORRENT_TEST(chained_buffer)
|
|||
TEST_EQUAL(b.allocate_appendix(1), 0);
|
||||
|
||||
char* b1 = allocate_buffer(512);
|
||||
std::memcpy(b1, data, 6);
|
||||
std::memcpy(b1, data_test, 6);
|
||||
b.append_buffer(holder(b1, 512), 6);
|
||||
TEST_EQUAL(buffer_list.size(), 1);
|
||||
|
||||
|
@ -238,7 +238,7 @@ TORRENT_TEST(chained_buffer)
|
|||
TEST_CHECK(!b.empty());
|
||||
TEST_EQUAL(b.space_in_last_buffer(), 512 - 6);
|
||||
|
||||
bool ret = b.append({data, 6}) != nullptr;
|
||||
bool ret = b.append({data_test, 6}) != nullptr;
|
||||
|
||||
TEST_CHECK(ret == true);
|
||||
TEST_EQUAL(b.capacity(), 512 - 3);
|
||||
|
@ -252,12 +252,12 @@ TORRENT_TEST(chained_buffer)
|
|||
TEST_CHECK(ret == false);
|
||||
|
||||
char* b2 = allocate_buffer(512);
|
||||
std::memcpy(b2, data, 6);
|
||||
std::memcpy(b2, data_test, 6);
|
||||
b.append_buffer(holder(b2, 512), 6);
|
||||
TEST_EQUAL(buffer_list.size(), 2);
|
||||
|
||||
char* b3 = allocate_buffer(512);
|
||||
std::memcpy(b3, data, 6);
|
||||
std::memcpy(b3, data_test, 6);
|
||||
b.append_buffer(holder(b3, 512), 6);
|
||||
TEST_EQUAL(buffer_list.size(), 3);
|
||||
|
||||
|
@ -291,22 +291,22 @@ TORRENT_TEST(chained_buffer)
|
|||
}
|
||||
|
||||
char* b4 = allocate_buffer(20);
|
||||
std::memcpy(b4, data, 6);
|
||||
std::memcpy(b4 + 6, data, 6);
|
||||
std::memcpy(b4, data_test, 6);
|
||||
std::memcpy(b4 + 6, data_test, 6);
|
||||
b.append_buffer(holder(b4, 20), 12);
|
||||
TEST_EQUAL(b.space_in_last_buffer(), 8);
|
||||
|
||||
ret = b.append({data, 6}) != nullptr;
|
||||
ret = b.append({data_test, 6}) != nullptr;
|
||||
TEST_CHECK(ret == true);
|
||||
TEST_EQUAL(b.space_in_last_buffer(), 2);
|
||||
std::cout << b.space_in_last_buffer() << std::endl;
|
||||
ret = b.append({data, 2}) != nullptr;
|
||||
ret = b.append({data_test, 2}) != nullptr;
|
||||
TEST_CHECK(ret == true);
|
||||
TEST_EQUAL(b.space_in_last_buffer(), 0);
|
||||
std::cout << b.space_in_last_buffer() << std::endl;
|
||||
|
||||
char* b5 = allocate_buffer(20);
|
||||
std::memcpy(b5, data, 6);
|
||||
std::memcpy(b5, data_test, 6);
|
||||
b.append_buffer(holder(b5, 20), 6);
|
||||
|
||||
b.pop_front(22);
|
||||
|
|
|
@ -538,10 +538,17 @@ struct obs : dht::dht_observer
|
|||
va_list v;
|
||||
va_start(v, fmt);
|
||||
char buf[1024];
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
||||
#endif
|
||||
std::vsnprintf(buf, sizeof(buf), fmt, v);
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
va_end(v);
|
||||
std::printf("%s\n", buf);
|
||||
m_log.push_back(buf);
|
||||
m_log.emplace_back(buf);
|
||||
}
|
||||
void log_packet(message_direction_t, span<char const>
|
||||
, udp::endpoint const&) override {}
|
||||
|
@ -692,7 +699,7 @@ void print_state(std::ostream& os, routing_table const& table)
|
|||
, end2(i->live_nodes.end()); j != end2; ++j)
|
||||
{
|
||||
int bucket_size_limit = table.bucket_limit(bucket_index);
|
||||
std::uint32_t top_mask = bucket_size_limit - 1;
|
||||
std::uint32_t top_mask = std::uint32_t(bucket_size_limit - 1);
|
||||
int mask_shift = 0;
|
||||
TORRENT_ASSERT_VAL(bucket_size_limit > 0, bucket_size_limit);
|
||||
while ((top_mask & 0x80) == 0)
|
||||
|
@ -757,7 +764,7 @@ void print_state(std::ostream& os, routing_table const& table)
|
|||
// we have all the lower bits set in (bucket_size_limit-1)
|
||||
// but we want the left-most bits to be set. Shift it
|
||||
// until the MSB is set
|
||||
std::uint32_t top_mask = bucket_size_limit - 1;
|
||||
std::uint32_t top_mask = std::uint32_t(bucket_size_limit - 1);
|
||||
int mask_shift = 0;
|
||||
TORRENT_ASSERT_VAL(bucket_size_limit > 0, bucket_size_limit);
|
||||
while ((top_mask & 0x80) == 0)
|
||||
|
@ -766,7 +773,7 @@ void print_state(std::ostream& os, routing_table const& table)
|
|||
++mask_shift;
|
||||
}
|
||||
top_mask = (0xff << mask_shift) & 0xff;
|
||||
bucket_size_limit = (top_mask >> mask_shift) + 1;
|
||||
bucket_size_limit = int((top_mask >> mask_shift) + 1);
|
||||
TORRENT_ASSERT_VAL(bucket_size_limit <= 256, bucket_size_limit);
|
||||
bool sub_buckets[256];
|
||||
std::memset(sub_buckets, 0, sizeof(sub_buckets));
|
||||
|
@ -1168,12 +1175,12 @@ TORRENT_TEST(bloom_filter)
|
|||
|
||||
// these are test vectors from BEP 33
|
||||
// http://www.bittorrent.org/beps/bep_0033.html
|
||||
std::printf("test.size: %f\n", test.size());
|
||||
std::printf("test.size: %f\n", double(test.size()));
|
||||
std::string const bf_str = test.to_string();
|
||||
std::printf("%s\n", aux::to_hex(bf_str).c_str());
|
||||
if (supports_ipv6())
|
||||
{
|
||||
TEST_CHECK(fabs(test.size() - 1224.93f) < 0.001);
|
||||
TEST_CHECK(double(fabs(test.size() - 1224.93f)) < 0.001);
|
||||
TEST_CHECK(aux::to_hex(bf_str) ==
|
||||
"f6c3f5eaa07ffd91bde89f777f26fb2b"
|
||||
"ff37bdb8fb2bbaa2fd3ddde7bacfff75"
|
||||
|
@ -1194,7 +1201,7 @@ TORRENT_TEST(bloom_filter)
|
|||
}
|
||||
else
|
||||
{
|
||||
TEST_CHECK(fabs(test.size() - 257.854f) < 0.001);
|
||||
TEST_CHECK(double(fabs(test.size() - 257.854f)) < 0.001);
|
||||
TEST_CHECK(aux::to_hex(bf_str) ==
|
||||
"24c0004020043000102012743e004800"
|
||||
"37110820422110008000c0e302854835"
|
||||
|
@ -1259,7 +1266,7 @@ namespace {
|
|||
return nodes;
|
||||
}
|
||||
|
||||
span<char const> const empty_salt;
|
||||
span<char const> const empty_salt;
|
||||
|
||||
// TODO: 3 split this up into smaller tests
|
||||
void test_put(address(&rand_addr)())
|
||||
|
@ -1974,6 +1981,8 @@ TORRENT_TEST(bootstrap_want_v6)
|
|||
}
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
// test that the node ignores a nodes entry which is too short
|
||||
void test_short_nodes(address(&rand_addr)())
|
||||
{
|
||||
|
@ -2047,6 +2056,8 @@ void test_short_nodes(address(&rand_addr)())
|
|||
TEST_EQUAL(g_sent_packets.size(), 0);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TORRENT_TEST(short_nodes_v4)
|
||||
{
|
||||
test_short_nodes(rand_v4);
|
||||
|
@ -2197,6 +2208,8 @@ TORRENT_TEST(get_peers_v6)
|
|||
}
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
// TODO: 4 pass in th actual salt as the argument
|
||||
void test_mutable_get(address(&rand_addr)(), bool const with_salt)
|
||||
{
|
||||
|
@ -2282,6 +2295,8 @@ void test_mutable_get(address(&rand_addr)(), bool const with_salt)
|
|||
g_got_items.clear();
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TORRENT_TEST(mutable_get_v4)
|
||||
{
|
||||
test_mutable_get(rand_v4, false);
|
||||
|
@ -2834,7 +2849,6 @@ TORRENT_TEST(signing_test1)
|
|||
public_key pk;
|
||||
secret_key sk;
|
||||
get_test_keypair(pk, sk);
|
||||
span<char const> empty_salt;
|
||||
|
||||
signature sig;
|
||||
sig = sign_mutable_item(test_content, empty_salt, sequence_number(1), pk, sk);
|
||||
|
@ -3074,10 +3088,12 @@ TORRENT_TEST(routing_table_extended)
|
|||
print_state(std::cout, tbl);
|
||||
}
|
||||
|
||||
namespace {
|
||||
void inserter(std::set<node_id>* nodes, node_entry const& ne)
|
||||
{
|
||||
nodes->insert(nodes->begin(), ne.id);
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
TORRENT_TEST(routing_table_set_id)
|
||||
{
|
||||
|
@ -3236,7 +3252,7 @@ TORRENT_TEST(read_only_node)
|
|||
TEST_EQUAL(g_sent_packets.size(), 1);
|
||||
TEST_EQUAL(g_sent_packets.front().first, initial_node);
|
||||
|
||||
dht::key_desc_t const get_item_desc[] = {
|
||||
dht::key_desc_t const get_item_desc_ro[] = {
|
||||
{"y", bdecode_node::string_t, 1, 0},
|
||||
{"t", bdecode_node::string_t, 2, 0},
|
||||
{"q", bdecode_node::string_t, 3, 0},
|
||||
|
@ -3247,7 +3263,7 @@ TORRENT_TEST(read_only_node)
|
|||
};
|
||||
|
||||
lazy_from_entry(g_sent_packets.front().second, request);
|
||||
bool ret = verify_message(request, get_item_desc, parsed, error_string);
|
||||
bool ret = verify_message(request, get_item_desc_ro, parsed, error_string);
|
||||
|
||||
TEST_CHECK(ret);
|
||||
TEST_EQUAL(parsed[3].int_value(), 1);
|
||||
|
@ -3272,13 +3288,13 @@ TORRENT_TEST(read_only_node)
|
|||
|
||||
// both of them shouldn't have a 'ro' key.
|
||||
lazy_from_entry(g_sent_packets.front().second, request);
|
||||
ret = verify_message(request, get_item_desc, parsed, error_string);
|
||||
ret = verify_message(request, get_item_desc_ro, parsed, error_string);
|
||||
|
||||
TEST_CHECK(ret);
|
||||
TEST_CHECK(!parsed[3]);
|
||||
|
||||
lazy_from_entry(g_sent_packets.back().second, request);
|
||||
ret = verify_message(request, get_item_desc, parsed, error_string);
|
||||
ret = verify_message(request, get_item_desc_ro, parsed, error_string);
|
||||
|
||||
TEST_CHECK(ret);
|
||||
TEST_CHECK(!parsed[3]);
|
||||
|
|
|
@ -109,7 +109,7 @@ TORRENT_TEST(direct_dht_request)
|
|||
entry r;
|
||||
r["q"] = "test_good";
|
||||
requester.dht_direct_request(udp::endpoint(address::from_string("127.0.0.1")
|
||||
, responder.listen_port()), r, (void*)12345);
|
||||
, responder.listen_port()), r, reinterpret_cast<void*>(12345));
|
||||
|
||||
dht_direct_response_alert* ra = get_direct_response(requester);
|
||||
TEST_CHECK(ra);
|
||||
|
@ -120,13 +120,13 @@ TORRENT_TEST(direct_dht_request)
|
|||
TEST_EQUAL(ra->endpoint.port(), responder.listen_port());
|
||||
TEST_EQUAL(response.type(), bdecode_node::dict_t);
|
||||
TEST_EQUAL(response.dict_find_dict("r").dict_find_int_value("good"), 1);
|
||||
TEST_EQUAL(ra->userdata, (void*)12345);
|
||||
TEST_EQUAL(ra->userdata, reinterpret_cast<void*>(12345));
|
||||
}
|
||||
|
||||
// failed request
|
||||
|
||||
requester.dht_direct_request(udp::endpoint(address::from_string("127.0.0.1"), 53545)
|
||||
, r, (void*)123456);
|
||||
, r, reinterpret_cast<void*>(123456));
|
||||
|
||||
ra = get_direct_response(requester);
|
||||
TEST_CHECK(ra);
|
||||
|
@ -135,7 +135,7 @@ TORRENT_TEST(direct_dht_request)
|
|||
TEST_EQUAL(ra->endpoint.address(), address::from_string("127.0.0.1"));
|
||||
TEST_EQUAL(ra->endpoint.port(), 53545);
|
||||
TEST_EQUAL(ra->response().type(), bdecode_node::none_t);
|
||||
TEST_EQUAL(ra->userdata, (void*)123456);
|
||||
TEST_EQUAL(ra->userdata, reinterpret_cast<void*>(123456));
|
||||
}
|
||||
#endif // #if !defined TORRENT_DISABLE_EXTENSIONS && !defined TORRENT_DISABLE_DHT
|
||||
}
|
||||
|
|
|
@ -62,7 +62,14 @@ void log(char const* fmt, ...)
|
|||
va_start(v, fmt);
|
||||
|
||||
char buf[1024];
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
||||
#endif
|
||||
std::vsnprintf(buf, sizeof(buf), fmt, v);
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
va_end(v);
|
||||
|
||||
std::printf("\x1b[1m\x1b[36m%s: %s\x1b[0m\n"
|
||||
|
|
|
@ -45,6 +45,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
using namespace lt;
|
||||
|
||||
namespace {
|
||||
|
||||
io_service ios;
|
||||
resolver res(ios);
|
||||
|
||||
|
@ -65,7 +67,7 @@ void print_http_header(http_parser const& p)
|
|||
}
|
||||
}
|
||||
|
||||
void http_connect_handler(http_connection& c)
|
||||
void http_connect_handler_test(http_connection& c)
|
||||
{
|
||||
++connect_handler_called;
|
||||
TEST_CHECK(c.socket().is_open());
|
||||
|
@ -76,7 +78,7 @@ void http_connect_handler(http_connection& c)
|
|||
// TEST_CHECK(c.socket().remote_endpoint(ec).address() == address::from_string("127.0.0.1", ec));
|
||||
}
|
||||
|
||||
void http_handler(error_code const& ec, http_parser const& parser
|
||||
void http_handler_test(error_code const& ec, http_parser const& parser
|
||||
, span<char const> data, http_connection&)
|
||||
{
|
||||
++handler_called;
|
||||
|
@ -119,7 +121,7 @@ void run_test(std::string const& url, int size, int status, int connected
|
|||
<< " error: " << (ec?ec->message():"no error") << std::endl;
|
||||
|
||||
std::shared_ptr<http_connection> h = std::make_shared<http_connection>(ios
|
||||
, res, &::http_handler, true, 1024*1024, &::http_connect_handler);
|
||||
, res, &::http_handler_test, true, 1024*1024, &::http_connect_handler_test);
|
||||
h->get(url, seconds(1), 0, &ps, 5, "test/user-agent", boost::none, resolver_flags{}, auth);
|
||||
ios.reset();
|
||||
error_code e;
|
||||
|
@ -222,6 +224,8 @@ void run_suite(std::string const& protocol
|
|||
stop_web_server();
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
#ifdef TORRENT_USE_OPENSSL
|
||||
TORRENT_TEST(no_proxy_ssl) { run_suite("https", settings_pack::none); }
|
||||
TORRENT_TEST(http_ssl) { run_suite("https", settings_pack::http); }
|
||||
|
|
|
@ -80,7 +80,14 @@ struct mock_peer_connection
|
|||
{
|
||||
va_list v;
|
||||
va_start(v, fmt);
|
||||
vprintf(fmt, v);
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
||||
#endif
|
||||
std::vprintf(fmt, v);
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
va_end(v);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -98,8 +98,14 @@ void incoming_msearch(udp::endpoint const& from, span<char const> buffer)
|
|||
|
||||
TORRENT_ASSERT(g_port != 0);
|
||||
char buf[sizeof(msg) + 30];
|
||||
int len = std::snprintf(buf, sizeof(buf), msg, g_port);
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
||||
#endif
|
||||
int const len = std::snprintf(buf, sizeof(buf), msg, g_port);
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
error_code ec;
|
||||
sock->send(buf, len, ec);
|
||||
|
||||
|
@ -166,7 +172,14 @@ void run_upnp_test(char const* root_filename, char const* router_model, char con
|
|||
TEST_CHECK(false);
|
||||
return;
|
||||
}
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
||||
#endif
|
||||
std::fprintf(xml_file, &buf[0], g_port);
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
fclose(xml_file);
|
||||
|
||||
std::ofstream xml(control_name, std::ios::trunc);
|
||||
|
|
Loading…
Reference in New Issue