enable warnings when building tests (#1880)

This commit is contained in:
Arvid Norberg 2017-04-02 14:22:17 -04:00 committed by GitHub
parent bb9b5bf4b8
commit 64ad4f5c96
24 changed files with 223 additions and 280 deletions

View File

@ -37,13 +37,8 @@ namespace boost
#include "gil.hpp"
#include "bytes.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include "boost_python.hpp"
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#ifdef _MSC_VER
#pragma warning(push)
// warning C4996: X: was declared deprecated

View File

@ -49,6 +49,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include <memory>
using namespace libtorrent;
struct choke_state
{
choke_state() : unchoke_duration(lt::seconds(0)), choked(true) {}
@ -137,7 +139,7 @@ TORRENT_TEST(optimistic_unchoke)
}
, *atp.ti
, tcp::endpoint(addr("50.1.0.0"), 6881)
, peer_conn::idle));
, peer_conn::peer_mode_t::idle));
}
});

View File

@ -63,11 +63,7 @@ lib libtorrent_test
<target-os>windows:<library>advapi32
<library>/torrent//torrent
<export-extra>on
<toolset>darwin:<cflags>-Wno-unused-command-line-argument
# disable warning C4275: non DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier'
<toolset>msvc:<cflags>/wd4275
# disable warning C4373: virtual function overrides, previous versions of the compiler did not override when parameters only differed by const/volatile qualifiers
<toolset>msvc:<cflags>/wd4373
<conditional>@warnings
: # default build
<link>shared

View File

@ -51,27 +51,15 @@ peer_conn::peer_conn(io_service& ios
, std::function<void(int, char const*, int)> on_msg
, torrent_info const& ti
, tcp::endpoint const& ep
, peer_mode_t mode)
, peer_mode_t const mode)
: s(ios)
, m_mode(mode)
, m_ti(ti)
, read_pos(0)
, m_on_msg(std::move(on_msg))
, state(handshaking)
, choked(true)
, current_piece(-1)
, m_current_piece_is_allowed(false)
, block(0)
, m_blocks_per_piece((m_ti.piece_length() + 0x3fff) / 0x4000)
, outstanding_requests(0)
, fast_extension(false)
, blocks_received(0)
, blocks_sent(0)
, start_time(clock_type::now())
, endpoint(ep)
, restarting(false)
{
pieces.reserve(m_ti.num_pieces());
pieces.reserve(static_cast<std::size_t>(m_ti.num_pieces()));
start_conn();
}
@ -93,13 +81,13 @@ void peer_conn::on_connect(error_code const& ec)
" " // space for info-hash
"aaaaaaaaaaaaaaaaaaaa" // peer-id
"\0\0\0\x01\x02"; // interested
char* h = (char*)malloc(sizeof(handshake));
char* h = static_cast<char*>(malloc(sizeof(handshake)));
memcpy(h, handshake, sizeof(handshake));
std::memcpy(h + 28, m_ti.info_hash().data(), 20);
std::generate(h + 48, h + 68, &rand);
// for seeds, don't send the interested message
boost::asio::async_write(s, boost::asio::buffer(h, (sizeof(handshake) - 1)
- (m_mode == uploader ? 5 : 0))
- (m_mode == peer_mode_t::uploader ? 5 : 0))
, std::bind(&peer_conn::on_handshake, this, h, _1, _2));
}
@ -113,7 +101,7 @@ void peer_conn::on_handshake(char* h, error_code const& ec, size_t)
}
// read handshake
boost::asio::async_read(s, boost::asio::buffer((char*)buffer, 68)
boost::asio::async_read(s, boost::asio::buffer(buffer.data(), 68)
, std::bind(&peer_conn::on_handshake2, this, _1, _2));
}
@ -128,9 +116,9 @@ void peer_conn::on_handshake2(error_code const& ec, size_t)
// buffer is the full 68 byte handshake
// look at the extension bits
fast_extension = (((char*)buffer)[27] & 4) != 0;
fast_extension = (buffer[27] & 4) != 0;
if (m_mode == uploader)
if (m_mode == peer_mode_t::uploader)
{
write_have_all();
}
@ -146,7 +134,7 @@ void peer_conn::write_have_all()
if (fast_extension)
{
char* ptr = write_buf_proto;
char* ptr = write_buf_proto.data();
// have_all
write_uint32(1, ptr);
write_uint8(0xe, ptr);
@ -154,23 +142,25 @@ void peer_conn::write_have_all()
write_uint32(1, ptr);
write_uint8(1, ptr);
error_code ec;
boost::asio::async_write(s, boost::asio::buffer(write_buf_proto, ptr - write_buf_proto)
boost::asio::async_write(s, boost::asio::buffer(write_buf_proto.data()
, static_cast<std::size_t>(ptr - write_buf_proto.data()))
, std::bind(&peer_conn::on_have_all_sent, this, _1, _2));
}
else
{
// bitfield
int len = (m_ti.num_pieces() + 7) / 8;
char* ptr = (char*)buffer;
char* ptr = buffer.data();
write_uint32(len + 1, ptr);
write_uint8(5, ptr);
memset(ptr, 255, len);
std::fill(ptr, ptr + len, 255);
ptr += len;
// unchoke
write_uint32(1, ptr);
write_uint8(1, ptr);
error_code ec;
boost::asio::async_write(s, boost::asio::buffer((char*)buffer, len + 10)
boost::asio::async_write(s, boost::asio::buffer(buffer.data()
, static_cast<std::size_t>(len + 10))
, std::bind(&peer_conn::on_have_all_sent, this, _1, _2));
}
}
@ -184,7 +174,7 @@ void peer_conn::on_have_all_sent(error_code const& ec, size_t)
}
// read message
boost::asio::async_read(s, boost::asio::buffer((char*)buffer, 4)
boost::asio::async_read(s, boost::asio::buffer(buffer.data(), 4)
, std::bind(&peer_conn::on_msg_length, this, _1, _2));
}
@ -228,8 +218,8 @@ bool peer_conn::write_request()
" " // piece
" " // offset
" "; // length
char* m = (char*)malloc(sizeof(msg));
memcpy(m, msg, sizeof(msg));
char* m = static_cast<char*>(malloc(sizeof(msg)));
std::copy(msg, msg + sizeof(msg), m);
char* ptr = m + 5;
write_uint32(current_piece, ptr);
write_uint32(block * 16 * 1024, ptr);
@ -265,11 +255,19 @@ void peer_conn::close(char const* fmt, error_code const& ec)
{
end_time = clock_type::now();
char tmp[1024];
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
std::snprintf(tmp, sizeof(tmp), fmt, ec.message().c_str());
#ifdef __clang__
#pragma clang diagnostic pop
#endif
int time = int(total_milliseconds(end_time - start_time));
if (time == 0) time = 1;
float up = (std::int64_t(blocks_sent) * 0x4000) / time / 1000.f;
float down = (std::int64_t(blocks_received) * 0x4000) / time / 1000.f;
double const up = (std::int64_t(blocks_sent) * 0x4000) / time / 1000.0;
double const down = (std::int64_t(blocks_received) * 0x4000) / time / 1000.0;
error_code e;
char ep_str[200];
@ -305,7 +303,7 @@ void peer_conn::work_download()
}
// read message
boost::asio::async_read(s, boost::asio::buffer((char*)buffer, 4)
boost::asio::async_read(s, boost::asio::buffer(buffer.data(), 4)
, std::bind(&peer_conn::on_msg_length, this, _1, _2));
}
@ -325,9 +323,9 @@ void peer_conn::on_msg_length(error_code const& ec, size_t)
close("ERROR RECEIVE MESSAGE PREFIX: %s", ec);
return;
}
char* ptr = (char*)buffer;
char* ptr = buffer.data();
unsigned int length = read_uint32(ptr);
if (length > sizeof(buffer))
if (length > buffer.size())
{
std::printf("len: %u\n", length);
close("ERROR RECEIVE MESSAGE PREFIX: packet too big", error_code());
@ -336,12 +334,12 @@ void peer_conn::on_msg_length(error_code const& ec, size_t)
if (length == 0)
{
// keep-alive messate. read another length prefix
boost::asio::async_read(s, boost::asio::buffer((char*)buffer, 4)
boost::asio::async_read(s, boost::asio::buffer(buffer.data(), 4)
, std::bind(&peer_conn::on_msg_length, this, _1, _2));
}
else
{
boost::asio::async_read(s, boost::asio::buffer((char*)buffer, length)
boost::asio::async_read(s, boost::asio::buffer(buffer.data(), length)
, std::bind(&peer_conn::on_message, this, _1, _2));
}
}
@ -362,14 +360,14 @@ void peer_conn::on_message(error_code const& ec, size_t bytes_transferred)
close("ERROR RECEIVE MESSAGE: %s", ec);
return;
}
char* ptr = (char*)buffer;
char* ptr = buffer.data();
int msg = read_uint8(ptr);
m_on_msg(msg, ptr, int(bytes_transferred));
switch (m_mode)
{
case peer_conn::uploader:
case peer_mode_t::uploader:
if (msg == 6)
{
if (bytes_transferred != 13)
@ -390,28 +388,28 @@ void peer_conn::on_message(error_code const& ec, size_t bytes_transferred)
else
{
// read another message
boost::asio::async_read(s, boost::asio::buffer(buffer, 4)
boost::asio::async_read(s, boost::asio::buffer(buffer.data(), 4)
, std::bind(&peer_conn::on_msg_length, this, _1, _2));
}
break;
case peer_conn::downloader:
case peer_mode_t::downloader:
if (msg == 0xe) // have_all
{
// build a list of all pieces and request them all!
pieces.resize(m_ti.num_pieces());
pieces.clear();
for (int i = 0; i < int(pieces.size()); ++i)
pieces[i] = i;
pieces.push_back(i);
aux::random_shuffle(pieces.begin(), pieces.end());
}
else if (msg == 4) // have
{
int piece = detail::read_int32(ptr);
if (pieces.empty()) pieces.push_back(piece);
else pieces.insert(pieces.begin() + (rand() % pieces.size()), piece);
else pieces.insert(pieces.begin() + static_cast<int>(libtorrent::random(static_cast<std::uint32_t>(pieces.size()))), piece);
}
else if (msg == 5) // bitfield
{
pieces.reserve(m_ti.num_pieces());
pieces.reserve(static_cast<std::size_t>(m_ti.num_pieces()));
int piece = 0;
for (int i = 0; i < int(bytes_transferred); ++i)
{
@ -440,10 +438,10 @@ void peer_conn::on_message(error_code const& ec, size_t bytes_transferred)
*/
++blocks_received;
--outstanding_requests;
int piece = detail::read_int32(ptr);
int start = detail::read_int32(ptr);
int const piece = detail::read_int32(ptr);
int const start = detail::read_int32(ptr);
if (int((start + bytes_transferred) / 0x4000) == m_blocks_per_piece)
if ((start + int(bytes_transferred)) / 0x4000 == m_blocks_per_piece)
{
write_have(piece);
return;
@ -504,9 +502,9 @@ void peer_conn::on_message(error_code const& ec, size_t bytes_transferred)
}
work_download();
break;
case peer_conn::idle:
case peer_mode_t::idle:
// read another message
boost::asio::async_read(s, boost::asio::buffer(buffer, 4)
boost::asio::async_read(s, boost::asio::buffer(buffer.data(), 4)
, std::bind(&peer_conn::on_msg_length, this, _1, _2));
break;
}
@ -534,15 +532,15 @@ void peer_conn::write_piece(int piece, int start, int length)
// generate_block(write_buffer, piece, start, length);
char* ptr = write_buf_proto;
char* ptr = write_buf_proto.data();
write_uint32(9 + length, ptr);
TORRENT_ASSERT(length == 0x4000);
write_uint8(7, ptr);
write_uint32(piece, ptr);
write_uint32(start, ptr);
std::array<boost::asio::const_buffer, 2> vec;
vec[0] = boost::asio::buffer(write_buf_proto, ptr - write_buf_proto);
vec[1] = boost::asio::buffer(write_buffer, length);
vec[0] = boost::asio::buffer(write_buf_proto.data(), static_cast<std::size_t>(ptr - write_buf_proto.data()));
vec[1] = boost::asio::buffer(write_buffer.data(), static_cast<std::size_t>(length));
boost::asio::async_write(s, vec, std::bind(&peer_conn::on_have_all_sent, this, _1, _2));
++blocks_sent;
}
@ -551,11 +549,11 @@ void peer_conn::write_have(int piece)
{
using namespace libtorrent::detail;
char* ptr = write_buf_proto;
char* ptr = write_buf_proto.data();
write_uint32(5, ptr);
write_uint8(4, ptr);
write_uint32(piece, ptr);
boost::asio::async_write(s, boost::asio::buffer(write_buf_proto, 9)
boost::asio::async_write(s, boost::asio::buffer(write_buf_proto.data(), 9)
, std::bind(&peer_conn::on_have_all_sent, this, _1, _2));
}

View File

@ -41,15 +41,14 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/torrent_info.hpp"
#include "test.hpp" // for EXPORT
#include <functional>
using namespace libtorrent;
#include <array>
struct EXPORT peer_conn
{
enum peer_mode_t
enum class peer_mode_t
{ uploader, downloader, idle };
peer_conn(io_service& ios
peer_conn(libtorrent::io_service& ios
, std::function<void(int, char const*, int)> on_msg
, libtorrent::torrent_info const& ti
, libtorrent::tcp::endpoint const& ep
@ -57,17 +56,17 @@ struct EXPORT peer_conn
void start_conn();
void on_connect(error_code const& ec);
void on_handshake(char* h, error_code const& ec, size_t bytes_transferred);
void on_handshake2(error_code const& ec, size_t bytes_transferred);
void on_connect(libtorrent::error_code const& ec);
void on_handshake(char* h, libtorrent::error_code const& ec, size_t bytes_transferred);
void on_handshake2(libtorrent::error_code const& ec, size_t bytes_transferred);
void write_have_all();
void on_have_all_sent(error_code const& ec, size_t bytes_transferred);
void on_have_all_sent(libtorrent::error_code const& ec, size_t bytes_transferred);
bool write_request();
void on_req_sent(char* m, error_code const& ec, size_t bytes_transferred);
void close(char const* fmt, error_code const& ec);
void on_req_sent(char* m, libtorrent::error_code const& ec, size_t bytes_transferred);
void close(char const* fmt, libtorrent::error_code const& ec);
void work_download();
void on_msg_length(error_code const& ec, size_t bytes_transferred);
void on_message(error_code const& ec, size_t bytes_transferred);
void on_msg_length(libtorrent::error_code const& ec, size_t bytes_transferred);
void on_message(libtorrent::error_code const& ec, size_t bytes_transferred);
bool verify_piece(int piece, int start, char const* ptr, int size);
void write_piece(int piece, int start, int length);
void write_have(int piece);
@ -76,42 +75,35 @@ struct EXPORT peer_conn
private:
tcp::socket s;
char write_buf_proto[100];
std::uint32_t write_buffer[17*1024/4];
std::uint32_t buffer[17*1024/4];
libtorrent::tcp::socket s;
std::array<char, 100> write_buf_proto;
std::array<std::uint32_t, 17 * 1024 / 4> write_buffer;
std::array<char, 17 * 1024> buffer;
peer_mode_t m_mode;
torrent_info const& m_ti;
peer_mode_t const m_mode;
libtorrent::torrent_info const& m_ti;
int read_pos;
int read_pos = 0;
std::function<void(int, char const*, int)> m_on_msg;
enum state_t
{
handshaking,
sending_request,
receiving_message
};
int state;
std::vector<int> pieces;
std::vector<int> suggested_pieces;
std::vector<int> allowed_fast;
bool choked;
int current_piece; // the piece we're currently requesting blocks from
bool m_current_piece_is_allowed;
int block;
bool choked = true;
int current_piece = -1; // the piece we're currently requesting blocks from
bool m_current_piece_is_allowed = false;
int block = 0;
int const m_blocks_per_piece;
int outstanding_requests;
int outstanding_requests = 0;
// if this is true, this connection is a seed
bool fast_extension;
int blocks_received;
int blocks_sent;
time_point start_time;
time_point end_time;
tcp::endpoint endpoint;
bool restarting;
bool fast_extension = false;
int blocks_received = 0;
int blocks_sent = 0;
libtorrent::time_point start_time = libtorrent::clock_type::now();
libtorrent::time_point end_time;
libtorrent::tcp::endpoint endpoint;
bool restarting = false;
};
#endif

View File

@ -40,13 +40,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include "dht_server.hpp"
#include "test_utils.hpp"
#include <boost/detail/atomic_count.hpp>
#if TORRENT_USE_IOSTREAM
#include <iostream>
#endif
#include <thread>
#include <atomic>
#include <functional>
#include <memory>
@ -57,7 +56,7 @@ struct dht_server
{
libtorrent::io_service m_ios;
boost::detail::atomic_count m_dht_requests;
std::atomic<int> m_dht_requests;
udp::socket m_socket;
int m_port;
@ -158,7 +157,9 @@ struct dht_server
}
};
namespace {
std::shared_ptr<dht_server> g_dht;
}
int start_dht()
{

View File

@ -67,6 +67,8 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
namespace {
// these are global so we can restore them on abnormal exits and print stuff
// out, such as the log
int old_stdout = -1;
@ -75,8 +77,6 @@ bool redirect_stdout = true;
bool redirect_stderr = false;
bool keep_files = false;
extern int _g_test_idx;
// the current tests file descriptor
unit_test_t* current_test = nullptr;
@ -96,9 +96,9 @@ void output_test_log_to_terminal()
fseek(current_test->output, 0, SEEK_SET);
std::printf("\x1b[1m[%s]\x1b[0m\n\n", current_test->name);
char buf[4096];
int size = 0;
std::size_t size = 0;
do {
size = int(fread(buf, 1, sizeof(buf), current_test->output));
size = fread(buf, 1, sizeof(buf), current_test->output);
if (size > 0) fwrite(buf, 1, size, stdout);
} while (size > 0);
}
@ -158,7 +158,7 @@ LONG WINAPI seh_exception_handler(LPEXCEPTION_POINTERS p)
#else
void sig_handler(int sig)
void TORRENT_NO_RETURN sig_handler(int sig)
{
char stack_text[10000];
@ -241,6 +241,8 @@ void change_directory(std::string const& f, error_code& ec)
#endif
}
} // anonymous namespace
struct unit_directory_guard
{
std::string dir;

View File

@ -83,11 +83,12 @@ std::shared_ptr<libtorrent::torrent_info> make_test_torrent(
entry::list_type& files = info["files"].list();
for (int i = 0; i < int(args.m_files.size()); ++i)
{
int file_size = atoi(args.m_files[i].c_str());
auto const idx = static_cast<std::size_t>(i);
int file_size = atoi(args.m_files[idx].c_str());
files.push_back(entry());
entry::dictionary_type& file_entry = files.back().dict();
std::string const& ent = args.m_files[i];
std::string const& ent = args.m_files[idx];
if (ent.find("padfile") != std::string::npos)
{
file_entry["attr"].string() += "p";
@ -181,13 +182,13 @@ void generate_files(libtorrent::torrent_info const& ti, std::string const& path
for (piece_index_t i(0); i < fs.end_piece(); ++i)
{
int const piece_size = ti.piece_size(i);
buffer.resize(ti.piece_length());
buffer.resize(static_cast<std::size_t>(ti.piece_length()));
std::uint8_t const data = std::uint8_t((alternate_data
char const data = static_cast<char>((alternate_data
? 255 - static_cast<int>(i) : static_cast<int>(i)) & 0xff);
for (int o = 0; o < piece_size; ++o)
{
memcpy(&buffer[o], &data, 1);
buffer[static_cast<std::size_t>(o)] = data;
}
iovec_t b = { &buffer[0], size_t(piece_size) };

View File

@ -41,10 +41,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include "peer_server.hpp"
#include "test_utils.hpp"
#include <boost/detail/atomic_count.hpp>
#include <functional>
#include <thread>
#include <atomic>
#include <condition_variable>
#include <memory>
@ -53,18 +52,14 @@ using namespace std::placeholders;
struct peer_server
{
libtorrent::io_service m_ios;
boost::detail::atomic_count m_peer_requests;
tcp::acceptor m_acceptor;
int m_port;
std::atomic<int> m_peer_requests{0};
tcp::acceptor m_acceptor{m_ios};
int m_port = 0;
std::shared_ptr<std::thread> m_thread;
peer_server()
: m_peer_requests(0)
, m_acceptor(m_ios)
, m_port(0)
{
error_code ec;
m_acceptor.open(tcp::v4(), ec);
@ -147,8 +142,12 @@ struct peer_server
}
};
namespace {
std::shared_ptr<peer_server> g_peer;
}
int start_peer()
{
g_peer.reset(new peer_server);

View File

@ -50,6 +50,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/broadcast_socket.hpp" // for supports_ipv6()
#include "libtorrent/hex.hpp" // to_hex
#include "libtorrent/aux_/vector.hpp"
#include "test.hpp"
#include "test_utils.hpp"
@ -65,10 +66,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <csignal>
#endif
#define DEBUG_WEB_SERVER 0
#define DLOG if (DEBUG_WEB_SERVER) std::fprintf
using namespace libtorrent;
namespace lt = libtorrent;
@ -76,7 +73,9 @@ namespace lt = libtorrent;
#include <conio.h>
#endif
std::uint32_t g_addr = 0x92343023;
namespace {
std::uint32_t g_addr = 0x92343023;
}
void init_rand_address()
{
@ -98,14 +97,14 @@ sha1_hash rand_hash()
{
sha1_hash ret;
for (int i = 0; i < 20; ++i)
ret[i] = std::uint8_t(lt::random(0xff));
ret[static_cast<std::size_t>(i)] = std::uint8_t(lt::random(0xff));
return ret;
}
sha1_hash to_hash(char const* s)
{
sha1_hash ret;
aux::from_hex({s, 40}, (char*)&ret[0]);
aux::from_hex({s, 40}, ret.data());
return ret;
}
@ -114,7 +113,7 @@ address rand_v6()
{
address_v6::bytes_type bytes;
for (int i = 0; i < int(bytes.size()); ++i)
bytes[i] = std::uint8_t(lt::random(0xff));
bytes[static_cast<std::size_t>(i)] = std::uint8_t(lt::random(0xff));
return address_v6(bytes);
}
#endif
@ -150,8 +149,8 @@ std::map<std::string, std::int64_t> get_counters(libtorrent::session& s)
if (!sa) return ret;
static std::vector<stats_metric> metrics = session_stats_metrics();
for (int i = 0; i < int(metrics.size()); ++i)
ret[metrics[i].name] = sa->values[metrics[i].value_index];
for (auto const& m : metrics)
ret[m.name] = sa->values[static_cast<std::size_t>(m.value_index)];
return ret;
}
namespace {
@ -203,7 +202,6 @@ alert const* wait_for_alert(lt::session& ses, int type, char const* name, int nu
}
if (num == 0) return ret;
}
return nullptr;
}
int load_file(std::string const& filename, std::vector<char>& v
@ -246,7 +244,7 @@ int load_file(std::string const& filename, std::vector<char>& v
return -1;
}
v.resize(s);
v.resize(static_cast<std::size_t>(s));
if (s == 0)
{
fclose(f);
@ -268,29 +266,8 @@ int load_file(std::string const& filename, std::vector<char>& v
return 0;
}
void save_file(char const* filename, char const* data, int size)
{
error_code ec;
file out(filename, file::write_only, ec);
TEST_CHECK(!ec);
if (ec)
{
std::printf("ERROR opening file '%s': %s\n", filename, ec.message().c_str());
return;
}
iovec_t b = { (void*)data, size_t(size) };
out.writev(0, b, ec);
TEST_CHECK(!ec);
if (ec)
{
std::printf("ERROR writing file '%s': %s\n", filename, ec.message().c_str());
return;
}
}
bool print_alerts(lt::session& ses, char const* name
, bool allow_disconnects, bool allow_no_torrents, bool allow_failed_fastresume
, bool allow_no_torrents, bool allow_failed_fastresume
, std::function<bool(libtorrent::alert const*)> predicate, bool no_output)
{
bool ret = false;
@ -314,24 +291,6 @@ bool print_alerts(lt::session& ses, char const* name
}
TEST_CHECK(alert_cast<fastresume_rejected_alert>(a) == nullptr || allow_failed_fastresume);
/*
peer_error_alert const* pea = alert_cast<peer_error_alert>(a);
if (pea)
{
std::printf("%s: peer error: %s\n", time_now_string(), pea->error.message().c_str());
TEST_CHECK((!handles.empty() && h.status().is_seeding)
|| pea->error.message() == "connecting to peer"
|| pea->error.message() == "closing connection to ourself"
|| pea->error.message() == "duplicate connection"
|| pea->error.message() == "duplicate peer-id"
|| pea->error.message() == "upload to upload connection"
|| pea->error.message() == "stopping torrent"
|| (allow_disconnects && pea->error.message() == "Broken pipe")
|| (allow_disconnects && pea->error.message() == "Connection reset by peer")
|| (allow_disconnects && pea->error.message() == "no shared cipher")
|| (allow_disconnects && pea->error.message() == "End of file."));
}
*/
invalid_request_alert const* ira = alert_cast<invalid_request_alert>(a);
if (ira)
@ -343,22 +302,21 @@ bool print_alerts(lt::session& ses, char const* name
return ret;
}
bool listen_done = false;
bool listen_alert(libtorrent::alert const* a)
{
if (alert_cast<listen_failed_alert>(a)
|| alert_cast<listen_succeeded_alert>(a))
listen_done = true;
return true;
}
void wait_for_listen(lt::session& ses, char const* name)
{
listen_done = false;
bool listen_done = false;
alert const* a = nullptr;
do
{
print_alerts(ses, name, true, true, true, &listen_alert, false);
print_alerts(ses, name, true, true, [&listen_done](libtorrent::alert const* al)
{
if (alert_cast<listen_failed_alert>(al)
|| alert_cast<listen_succeeded_alert>(al))
{
listen_done = true;
}
return true;
}, false);
if (listen_done) break;
a = ses.wait_for_alert(milliseconds(500));
} while (a);
@ -366,23 +324,20 @@ void wait_for_listen(lt::session& ses, char const* name)
TEST_CHECK(listen_done);
}
bool downloading_done = false;
bool downloading_alert(libtorrent::alert const* a)
{
state_changed_alert const* sc = alert_cast<state_changed_alert>(a);
if (sc && sc->state == torrent_status::downloading)
downloading_done = true;
return true;
}
void wait_for_downloading(lt::session& ses, char const* name)
{
time_point start = clock_type::now();
downloading_done = false;
bool downloading_done = false;
alert const* a = nullptr;
do
{
print_alerts(ses, name, true, true, true, &downloading_alert, false);
print_alerts(ses, name, true, true, [&downloading_done](libtorrent::alert const* al)
{
state_changed_alert const* sc = alert_cast<state_changed_alert>(al);
if (sc && sc->state == torrent_status::downloading)
downloading_done = true;
return true;
}, false);
if (downloading_done) break;
if (total_seconds(clock_type::now() - start) > 10) break;
a = ses.wait_for_alert(seconds(2));
@ -395,14 +350,14 @@ void wait_for_downloading(lt::session& ses, char const* name)
}
}
void print_ses_rate(float time
void print_ses_rate(float const time
, libtorrent::torrent_status const* st1
, libtorrent::torrent_status const* st2
, libtorrent::torrent_status const* st3)
{
if (st1)
{
std::printf("%3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time
std::printf("%3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", static_cast<double>(time)
, int(st1->download_payload_rate / 1000)
, int(st1->upload_payload_rate / 1000)
, int(st1->progress * 100)
@ -411,7 +366,7 @@ void print_ses_rate(float time
, st1->errc ? (" [" + st1->errc.message() + "]").c_str() : "");
}
if (st2)
std::printf(" : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time
std::printf(" : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", static_cast<double>(time)
, int(st2->download_payload_rate / 1000)
, int(st2->upload_payload_rate / 1000)
, int(st2->progress * 100)
@ -419,7 +374,7 @@ void print_ses_rate(float time
, st2->connect_candidates
, st2->errc ? (" [" + st1->errc.message() + "]").c_str() : "");
if (st3)
std::printf(" : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time
std::printf(" : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", static_cast<double>(time)
, int(st3->download_payload_rate / 1000)
, int(st3->upload_payload_rate / 1000)
, int(st3->progress * 100)
@ -454,6 +409,8 @@ void stop_proxy(int port)
// calling stop_all_proxies().
}
namespace {
// returns 0 on failure, otherwise pid
pid_type async_run(char const* cmdline)
{
@ -519,6 +476,8 @@ void stop_process(pid_type p)
#endif
}
} // anonymous namespace
void stop_all_proxies()
{
std::map<int, proxy_t> proxies = running_proxies;
@ -541,7 +500,7 @@ int start_proxy(int proxy_type)
if (i->second.type == proxy_type) { return i->first; }
}
int port = 2000 + lt::random(6000);
int port = 2000 + static_cast<int>(lt::random(6000));
error_code ec;
io_service ios;
@ -608,15 +567,15 @@ std::shared_ptr<T> clone_ptr(std::shared_ptr<T> const& ptr)
return std::make_shared<T>(*ptr);
}
unsigned char random_byte()
{ return lt::random(0xff); }
std::uint8_t random_byte()
{ return static_cast<std::uint8_t>(lt::random(0xff)); }
std::vector<char> generate_piece(piece_index_t const idx, int const piece_size)
{
using namespace libtorrent;
std::vector<char> ret(piece_size);
std::vector<char> ret(static_cast<std::size_t>(piece_size));
std::mt19937 rng(static_cast<int>(idx));
std::mt19937 rng(static_cast<std::uint32_t>(static_cast<int>(idx)));
std::uniform_int_distribution<int> rand(-128, 127);
for (char& c : ret)
{
@ -672,10 +631,10 @@ std::shared_ptr<lt::torrent_info> make_torrent(const int file_sizes[]
void create_random_files(std::string const& path, const int file_sizes[], int num_files)
{
error_code ec;
char* random_data = (char*)malloc(300000);
aux::vector<char> random_data(300000);
for (int i = 0; i != num_files; ++i)
{
std::generate(random_data, random_data + 300000, random_byte);
std::generate(random_data.begin(), random_data.end(), random_byte);
char filename[200];
std::snprintf(filename, sizeof(filename), "test%d", i);
char dirname[200];
@ -692,8 +651,8 @@ void create_random_files(std::string const& path, const int file_sizes[], int nu
std::int64_t offset = 0;
while (to_write > 0)
{
int s = (std::min)(to_write, 300000);
iovec_t b = { random_data, size_t(s)};
int const s = std::min(to_write, static_cast<int>(random_data.size()));
iovec_t b = { random_data.data(), size_t(s)};
f.writev(offset, b, ec);
if (ec) std::printf("failed to write file \"%s\": (%d) %s\n"
, full_path.c_str(), ec.value(), ec.message().c_str());
@ -701,7 +660,6 @@ void create_random_files(std::string const& path, const int file_sizes[], int nu
to_write -= s;
}
}
free(random_data);
}
std::shared_ptr<torrent_info> create_torrent(std::ostream* file
@ -739,7 +697,7 @@ std::shared_ptr<torrent_info> create_torrent(std::ostream* file
}
}
std::vector<char> piece(piece_size);
aux::vector<char> piece(static_cast<std::size_t>(piece_size));
for (int i = 0; i < int(piece.size()); ++i)
piece[i] = (i % 26) + 'A';
@ -752,8 +710,8 @@ std::shared_ptr<torrent_info> create_torrent(std::ostream* file
{
while (total_size > 0)
{
file->write(&piece[0], (std::min)(int(piece.size()), total_size));
total_size -= int(piece.size());
file->write(&piece[0], std::min(piece.end_index(), total_size));
total_size -= piece.end_index();
}
}
@ -910,7 +868,6 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3
{
wait_for_downloading(*ses2, "ses2");
error_code ec;
int port = 0;
if (use_ssl_ports)
{
@ -960,11 +917,13 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3
return std::make_tuple(tor1, tor2, tor3);
}
namespace {
pid_type web_server_pid = 0;
}
int start_web_server(bool ssl, bool chunked_encoding, bool keepalive)
{
int port = 2000 + lt::random(6000);
int port = 2000 + static_cast<int>(lt::random(6000));
error_code ec;
io_service ios;

View File

@ -33,23 +33,19 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef SETUP_TRANSFER_HPP
#define SETUP_TRANSFER_HPP
#include "libtorrent/session.hpp"
#include <tuple>
#include "test.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/units.hpp"
namespace libtorrent
{
class alert;
struct add_torrent_params;
}
#include "libtorrent/span.hpp"
#include "libtorrent/alert.hpp"
#include "libtorrent/add_torrent_params.hpp"
EXPORT int print_failures();
EXPORT unsigned char random_byte();
EXPORT int load_file(std::string const& filename, std::vector<char>& v
, libtorrent::error_code& ec, int limit = 8000000);
EXPORT void save_file(char const* filename, char const* data, int size);
EXPORT void report_failure(char const* err, char const* file, int line);
@ -75,7 +71,6 @@ EXPORT void print_ses_rate(float time
, libtorrent::torrent_status const* st3 = NULL);
EXPORT bool print_alerts(libtorrent::session& ses, char const* name
, bool allow_disconnects = false
, bool allow_no_torrents = false
, bool allow_failed_fastresume = false
, std::function<bool(libtorrent::alert const*)> predicate

View File

@ -98,9 +98,9 @@ void test_swarm(int flags)
// this is to avoid everything finish from a single peer
// immediately. To make the swarm actually connect all
// three peers before finishing.
float rate_limit = 100000;
float const rate_limit = 100000;
int port = lt::random(100);
int const port = static_cast<int>(lt::random(100));
char iface[50];
std::snprintf(iface, sizeof(iface), "0.0.0.0:480%02d", port);
pack.set_int(settings_pack::upload_rate_limit, int(rate_limit));

View File

@ -88,6 +88,7 @@ struct unit_test_t
extern unit_test_t EXPORT _g_unit_tests[1024];
extern int EXPORT _g_num_unit_tests;
extern int EXPORT _g_test_failures;
extern int _g_test_idx;
#define TORRENT_TEST(test_name) \
static void BOOST_PP_CAT(unit_test_, test_name)(); \

View File

@ -70,7 +70,7 @@ void log(char const* fmt, ...)
void print_session_log(lt::session& ses)
{
print_alerts(ses, "ses", true, true);
print_alerts(ses, "ses", true);
}
int read_message(tcp::socket& s, char* buffer, int max_size)

View File

@ -74,8 +74,8 @@ void test_lsd()
for (int i = 0; i < 30; ++i)
{
print_alerts(ses1, "ses1", true);
print_alerts(ses2, "ses2", true);
print_alerts(ses1, "ses1");
print_alerts(ses2, "ses2");
torrent_status st1 = tor1.status();
torrent_status st2 = tor2.status();

View File

@ -148,8 +148,8 @@ void test_transfer(settings_pack const& sett, bool test_deprecated = false)
for (int i = 0; i < 200; ++i)
{
print_alerts(ses1, "ses1", true, true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, true, &on_alert);
print_alerts(ses1, "ses1", true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, &on_alert);
torrent_status st1 = tor1.status();
torrent_status st2 = tor2.status();
@ -211,8 +211,8 @@ void test_transfer(settings_pack const& sett, bool test_deprecated = false)
torrent_status st2;
for (int i = 0; i < 50; ++i)
{
print_alerts(ses1, "ses1", true, true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, true, &on_alert);
print_alerts(ses1, "ses1", true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, &on_alert);
st2 = tor2.status();
if (i % 10 == 0)
@ -313,8 +313,8 @@ done:
torrent_status st1;
for (int i = 0; i < 5; ++i)
{
print_alerts(ses1, "ses1", true, true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, true, &on_alert);
print_alerts(ses1, "ses1", true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, &on_alert);
st1 = tor1.status();
st2 = tor2.status();
@ -340,8 +340,8 @@ done:
std::cout << std::endl;
// drain alerts
print_alerts(ses1, "ses1", true, true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, true, &on_alert);
print_alerts(ses1, "ses1", true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, &on_alert);
peer_disconnects = 0;
@ -352,8 +352,8 @@ done:
st2 = tor2.status();
for (int i = 0; i < 130; ++i)
{
print_alerts(ses1, "ses1", true, true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, true, &on_alert);
print_alerts(ses1, "ses1", true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, &on_alert);
st1 = tor1.status();
st2 = tor2.status();

View File

@ -177,7 +177,7 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
for (int i = 0; i < timeout; ++i)
{
print_alerts(*s, "s", false, false, false, &alert_predicate);
print_alerts(*s, "s", false, false, &alert_predicate);
std::this_thread::sleep_for(lt::milliseconds(100));
if (num_udp_announces() >= prev_udp_announces + 1

View File

@ -239,8 +239,8 @@ void test_ssl(int test_idx, bool use_utp)
const int timeout = 40;
for (int i = 0; i < timeout; ++i)
{
print_alerts(ses1, "ses1", true, true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, true, &on_alert);
print_alerts(ses1, "ses1", true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, &on_alert);
torrent_status st1 = tor1.status();
torrent_status st2 = tor2.status();
@ -444,7 +444,7 @@ bool try_connect(libtorrent::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);
print_alerts(ses1, "ses1", true, true, true, &on_alert);
print_alerts(ses1, "ses1", true, true, &on_alert);
if (ec)
{
@ -475,7 +475,7 @@ bool try_connect(libtorrent::session& ses1, int port
std::printf("SSL handshake\n");
ssl_sock.handshake(boost::asio::ssl::stream_base::client, ec);
print_alerts(ses1, "ses1", true, true, true, &on_alert);
print_alerts(ses1, "ses1", true, true, &on_alert);
if (ec)
{
std::printf("Failed SSL handshake: %s\n"
@ -505,7 +505,7 @@ bool try_connect(libtorrent::session& ses1, int port
std::printf("bittorrent handshake\n");
boost::asio::write(ssl_sock, boost::asio::buffer(handshake, (sizeof(handshake) - 1)), ec);
print_alerts(ses1, "ses1", true, true, true, &on_alert);
print_alerts(ses1, "ses1", true, true, &on_alert);
if (ec)
{
std::printf("failed to write bittorrent handshake: %s\n"
@ -516,7 +516,7 @@ bool try_connect(libtorrent::session& ses1, int port
char buf[68];
std::printf("read bittorrent handshake\n");
boost::asio::read(ssl_sock, boost::asio::buffer(buf, sizeof(buf)), ec);
print_alerts(ses1, "ses1", true, true, true, &on_alert);
print_alerts(ses1, "ses1", true, true, &on_alert);
if (ec)
{
std::printf("failed to read bittorrent handshake: %s\n"

View File

@ -840,7 +840,7 @@ void test_rename_file_fastresume(bool test_deprecated)
bool renamed = false;
for (int i = 0; i < 30; ++i)
{
if (print_alerts(ses, "ses", true, true, true, &got_file_rename_alert)) renamed = true;
if (print_alerts(ses, "ses", true, true, &got_file_rename_alert)) renamed = true;
torrent_status s = h.status();
if (s.state == torrent_status::seeding && renamed) break;
std::this_thread::sleep_for(lt::milliseconds(100));

View File

@ -365,7 +365,7 @@ void test_udp_tracker(std::string const& iface, address tracker, tcp::endpoint c
tcp::endpoint peer_ep;
for (int i = 0; i < 50; ++i)
{
print_alerts(*s, "s", false, false, false, std::bind(&connect_alert, _1, std::ref(peer_ep)));
print_alerts(*s, "s", false, false, std::bind(&connect_alert, _1, std::ref(peer_ep)));
if (num_udp_announces() == prev_udp_announces + 1)
break;
@ -386,7 +386,7 @@ void test_udp_tracker(std::string const& iface, address tracker, tcp::endpoint c
for (int i = 0; i < 50; ++i)
{
print_alerts(*s, "s", true, true, false, std::bind(&connect_alert, _1, std::ref(peer_ep)));
print_alerts(*s, "s", true, false, std::bind(&connect_alert, _1, std::ref(peer_ep)));
if (num_udp_announces() == prev_udp_announces + 2)
break;

View File

@ -264,8 +264,8 @@ void test_transfer(int proxy_type, settings_pack const& sett
torrent_status st1 = tor1.status();
torrent_status st2 = tor2.status();
print_alerts(ses1, "ses1", true, true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, true, &on_alert);
print_alerts(ses1, "ses1", true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, &on_alert);
if (i % 10 == 0)
{
@ -298,8 +298,8 @@ void test_transfer(int proxy_type, settings_pack const& sett
// then we need to drain the alert queue, so the peer_disconnects
// counter doesn't get incremented by old alerts
print_alerts(ses1, "ses1", true, true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, true, &on_alert);
print_alerts(ses1, "ses1", true, true, &on_alert);
print_alerts(ses2, "ses2", true, true, &on_alert);
lt::error_code err = tor2.status().errc;
std::printf("error: \"%s\"\n", err.message().c_str());

View File

@ -108,8 +108,8 @@ void test_transfer()
for (int i = 0; i < timeout; ++i)
{
print_alerts(ses1, "ses1", true, true, true);
print_alerts(ses2, "ses2", true, true, true);
print_alerts(ses1, "ses1", true, true);
print_alerts(ses2, "ses2", true, true);
std::this_thread::sleep_for(lt::milliseconds(500));

View File

@ -42,10 +42,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include "udp_tracker.hpp"
#include "test_utils.hpp"
#include <boost/detail/atomic_count.hpp>
#include <functional>
#include <thread>
#include <atomic>
#include <memory>
using namespace libtorrent;
@ -55,14 +54,15 @@ struct udp_tracker
{
libtorrent::io_service m_ios;
boost::detail::atomic_count m_udp_announces;
udp::socket m_socket;
int m_port;
bool m_abort;
std::atomic<int> m_udp_announces{0};
udp::socket m_socket{m_ios};
int m_port = 0;
bool m_abort = false;
std::shared_ptr<std::thread> m_thread;
void on_udp_receive(error_code const& ec, size_t bytes_transferred, udp::endpoint* from, char* buffer, int size)
void on_udp_receive(error_code const& ec, size_t const bytes_transferred
, udp::endpoint* from, char* buffer, std::size_t const size)
{
if (ec)
{
@ -153,7 +153,8 @@ struct udp_tracker
detail::write_uint8(7, ptr);
detail::write_uint16(1337, ptr);
}
m_socket.send_to(boost::asio::buffer(buffer, ptr - buffer), *from, 0, e);
m_socket.send_to(boost::asio::buffer(buffer
, static_cast<std::size_t>(ptr - buffer)), *from, 0, e);
if (e) std::printf("%s: UDP send_to failed. ERROR: %s\n"
, time_now_string(), e.message().c_str());
else std::printf("%s: UDP sent response to: %s\n"
@ -175,10 +176,6 @@ struct udp_tracker
}
explicit udp_tracker(address iface)
: m_udp_announces(0)
, m_socket(m_ios)
, m_port(0)
, m_abort(false)
{
error_code ec;
m_socket.open(iface.is_v4() ? udp::v4() : udp::v6(), ec);
@ -202,14 +199,15 @@ struct udp_tracker
}
std::printf("%s: UDP tracker [%p] initialized on port %d\n"
, time_now_string(), this, m_port);
, time_now_string(), static_cast<void*>(this), m_port);
m_thread = std::make_shared<std::thread>(&udp_tracker::thread_fun, this);
}
void stop()
{
std::printf("%s: UDP tracker [%p], stop\n", time_now_string(), this);
std::printf("%s: UDP tracker [%p], stop\n", time_now_string()
, static_cast<void*>(this));
m_abort = true;
m_socket.cancel();
m_socket.close();
@ -218,7 +216,7 @@ struct udp_tracker
~udp_tracker()
{
std::printf("%s: UDP tracker [%p], ~udp_tracker\n"
, time_now_string(), this);
, time_now_string(), static_cast<void*>(this));
m_ios.post(std::bind(&udp_tracker::stop, this));
if (m_thread) m_thread->join();
}
@ -245,11 +243,13 @@ struct udp_tracker
return;
}
std::printf("UDP exiting UDP tracker [%p] thread\n", this);
std::printf("UDP exiting UDP tracker [%p] thread\n", static_cast<void*>(this));
}
};
namespace {
std::shared_ptr<udp_tracker> g_udp_tracker;
}
int start_udp_tracker(address iface)
{

View File

@ -111,7 +111,7 @@ void test_transfer(lt::session& ses, std::shared_ptr<torrent_info> torrent_file
pack.set_str(settings_pack::proxy_hostname, "127.0.0.1");
pack.set_str(settings_pack::proxy_username, "testuser");
pack.set_str(settings_pack::proxy_password, "testpass");
pack.set_int(settings_pack::proxy_type, (settings_pack::proxy_type_t)proxy);
pack.set_int(settings_pack::proxy_type, proxy);
pack.set_int(settings_pack::proxy_port, proxy_port);
pack.set_bool(settings_pack::proxy_peer_connections, proxy_peers);
ses.apply_settings(pack);
@ -166,7 +166,7 @@ void test_transfer(lt::session& ses, std::shared_ptr<torrent_info> torrent_file
cnt = get_counters(ses);
print_ses_rate(i / 10.f, &s, nullptr);
print_alerts(ses, " >> ses", test_ban, false, false, &on_alert);
print_alerts(ses, " >> ses", false, false, &on_alert);
if (test_ban && th.url_seeds().empty() && th.http_seeds().empty())
{
@ -255,7 +255,7 @@ void test_transfer(lt::session& ses, std::shared_ptr<torrent_info> torrent_file
// synchronize to make sure the files have been created on disk
wait_for_alert(ses, cache_flushed_alert::alert_type, "ses");
print_alerts(ses, " >> ses", true, true, false, &on_alert, true);
print_alerts(ses, " >> ses", true, false, &on_alert, true);
if (!test_ban)
{
@ -291,7 +291,7 @@ int EXPORT run_http_suite(int proxy, char const* protocol, bool test_url_seed
if (test_url_seed)
{
char url[512];
std::snprintf(url, sizeof(url), ("%s://127.0.0.1:%d/" + save_path).c_str(), protocol, port);
std::snprintf(url, sizeof(url), "%s://127.0.0.1:%d/%s", protocol, port, save_path.c_str());
std::printf("testing: %s\n", url);
create_directories(combine_path(save_path, "torrent_dir"), ec);
@ -354,7 +354,8 @@ int EXPORT run_http_suite(int proxy, char const* protocol, bool test_url_seed
.name("torrent_dir")
.url_seed(url));
std::snprintf(url, sizeof(url), ("%s://127.0.0.1:%d/" + save_path + "/test-single-file").c_str(), protocol, port);
std::snprintf(url, sizeof(url), "%s://127.0.0.1:%d/%s/test-single-file"
, protocol, port, save_path.c_str());
// test case 6 (single file torrent)
test_cases.push_back(torrent_args()
@ -373,11 +374,12 @@ int EXPORT run_http_suite(int proxy, char const* protocol, bool test_url_seed
.http_seed(url));
}
for (int a = 0; a < int(test_cases.size()); ++a)
int idx = 0;
for (auto const& c : test_cases)
{
std::printf("\n\n ==== test case %d ====\n\n\n", a);
std::printf("\n\n ==== test case %d ====\n\n\n", idx++);
std::shared_ptr<torrent_info> torrent_file = make_test_torrent(test_cases[a]);
std::shared_ptr<torrent_info> torrent_file = make_test_torrent(c);
// if test_ban is true, we create the files with alternate content (that
// doesn't match the hashes in the .torrent file)