merged RC_1_1 into master

This commit is contained in:
arvidn 2016-10-09 20:09:44 -04:00
commit 9453fbd54b
23 changed files with 269 additions and 265 deletions

View File

@ -3,7 +3,7 @@ language: cpp
matrix: matrix:
include: include:
- env: variant=test_barebones toolset=gcc lint=1 - env: variant=test_barebones toolset=gcc lint=1
- env: variant=test_debug sim=1 ssl=openssl crypto=libcrypto toolset=gcc-ubsan - env: variant=test_debug sim=1 ssl=openssl crypto=libcrypto toolset=gcc-sanitizer
- env: variant=test_release coverage=1 toolset=gcc-coverage - env: variant=test_release coverage=1 toolset=gcc-coverage
- env: autotools=1 toolset=gcc - env: autotools=1 toolset=gcc
- os: osx - os: osx
@ -64,10 +64,13 @@ before_install:
- if [ "$coverage" == "1" ]; then - if [ "$coverage" == "1" ]; then
pip install --user codecov; pip install --user codecov;
fi fi
- 'if [[ $toolset == "gcc-ubsan" ]]; then export test_args=testing.arg="--no-stderr-redirect"; fi' - 'if [[ $toolset == "gcc-sanitizer" ]]; then export test_args=testing.arg="--no-stderr-redirect"; fi'
- 'echo "toolset: " ${toolset}' - 'echo "toolset: " ${toolset}'
- 'echo "coverage_toolset: " ${coverage_toolset}' - 'echo "coverage_toolset: " ${coverage_toolset}'
- 'echo "variant: " ${variant}' - 'echo "variant: " ${variant}'
# disable leak checking for now. it reports some suspicious reports against some
# tests
- export ASAN_OPTIONS=detect_leaks=0;
install: install:
@ -76,8 +79,8 @@ install:
g++-5 --version; g++-5 --version;
echo "using gcc : : ccache g++-5 : <cxxflags>-std=c++11 ;" >> ~/user-config.jam; echo "using gcc : : ccache g++-5 : <cxxflags>-std=c++11 ;" >> ~/user-config.jam;
fi' fi'
- 'if [[ $toolset == "gcc-ubsan" ]]; then - 'if [[ $toolset == "gcc-sanitizer" ]]; then
echo "using gcc : ubsan : ccache g++-5 : <cxxflags>-std=c++11 <compileflags>-fsanitize=undefined <compileflags>-fno-sanitize-recover=undefined <linkflags>-fsanitize=undefined <linkflags>-fno-sanitize-recover=undefined ;" >> ~/user-config.jam; echo "using gcc : sanitizer : ccache g++-5 : <cxxflags>-std=c++11 <compileflags>-fsanitize=address,undefined <compileflags>-fno-sanitize-recover=address,undefined <linkflags>-fsanitize=address,undefined <linkflags>-fno-sanitize-recover=address,undefined ;" >> ~/user-config.jam;
fi' fi'
- 'if [[ $toolset == "gcc-coverage" ]]; then - 'if [[ $toolset == "gcc-coverage" ]]; then
echo "using gcc : coverage : ccache g++-5 --coverage : <cxxflags>-std=c++11 <linkflags>--coverage ;" >> ~/user-config.jam; echo "using gcc : coverage : ccache g++-5 --coverage : <cxxflags>-std=c++11 <linkflags>--coverage ;" >> ~/user-config.jam;
@ -155,8 +158,9 @@ script:
bjam -j3 warnings-as-errors=on ssl=$ssl crypto=$crypto debug-iterators=on picker-debugging=on invariant-checks=full $toolset variant=$variant link=shared install location=./lib; bjam -j3 warnings-as-errors=on ssl=$ssl crypto=$crypto debug-iterators=on picker-debugging=on invariant-checks=full $toolset variant=$variant link=shared install location=./lib;
fi' fi'
# a binary built with sanitizer does not interact well with python
- cd bindings/python - cd bindings/python
- 'if [[ "$toolset" != "gcc-ubsan" && "$variant" != "" ]]; then - 'if [[ "$toolset" != "gcc-sanitizer" && "$variant" != "" ]]; then
bjam -j3 warnings-as-errors=on ssl=$ssl crypto=$crypto debug-iterators=on picker-debugging=on invariant-checks=full $toolset variant=$variant stage_module libtorrent-link=shared install-type=LIB dll-path=../../lib && bjam -j3 warnings-as-errors=on ssl=$ssl crypto=$crypto debug-iterators=on picker-debugging=on invariant-checks=full $toolset variant=$variant stage_module libtorrent-link=shared install-type=LIB dll-path=../../lib &&
LD_LIBRARY_PATH=../../lib DYLD_LIBRARY_PATH=../../lib python test.py; LD_LIBRARY_PATH=../../lib DYLD_LIBRARY_PATH=../../lib python test.py;
fi' fi'

View File

@ -122,7 +122,7 @@ std::shared_ptr<http_connection> test_request(io_service& ios
, int* handler_called , int* handler_called
, std::string const& auth = std::string()) , std::string const& auth = std::string())
{ {
std::fprintf(stderr, " ===== TESTING: %s =====\n", url.c_str()); std::fprintf(stdout, " ===== TESTING: %s =====\n", url.c_str());
auto h = std::make_shared<http_connection>(ios auto h = std::make_shared<http_connection>(ios
, res , res
@ -405,7 +405,7 @@ void run_test(lt::aux::proxy_settings ps, std::string url, int expect_size, int
TEST_EQUAL(counters.size(), expect_counters.size()); TEST_EQUAL(counters.size(), expect_counters.size());
for (int i = 0; i < int(counters.size()); ++i) for (int i = 0; i < int(counters.size()); ++i)
{ {
if (counters[i] != expect_counters[i]) std::fprintf(stderr, "i=%d\n", i); if (counters[i] != expect_counters[i]) std::fprintf(stdout, "i=%d\n", i);
TEST_EQUAL(counters[i], expect_counters[i]); TEST_EQUAL(counters[i], expect_counters[i]);
} }
} }

View File

@ -193,7 +193,7 @@ TORRENT_TEST(event_completed)
// we there can only be one event // we there can only be one event
const bool has_event = str.find("&event=") != std::string::npos; const bool has_event = str.find("&event=") != std::string::npos;
std::fprintf(stderr, "- %s\n", str.c_str()); std::fprintf(stdout, "- %s\n", str.c_str());
// there is exactly 0 or 1 events. // there is exactly 0 or 1 events.
TEST_EQUAL(int(has_start) + int(has_completed) + int(has_stopped) TEST_EQUAL(int(has_start) + int(has_completed) + int(has_stopped)
@ -664,7 +664,7 @@ TORRENT_TEST(try_next)
for (int i = 0; i < int(tr.size()); ++i) for (int i = 0; i < int(tr.size()); ++i)
{ {
std::fprintf(stderr, "tracker \"%s\"\n", tr[i].url.c_str()); std::fprintf(stdout, "tracker \"%s\"\n", tr[i].url.c_str());
if (tr[i].url == "http://tracker.com:8080/announce") if (tr[i].url == "http://tracker.com:8080/announce")
{ {
TEST_EQUAL(tr[i].fails, 0); TEST_EQUAL(tr[i].fails, 0);

View File

@ -67,7 +67,7 @@ POSSIBILITY OF SUCH DAMAGE.
#define DEBUG_WEB_SERVER 0 #define DEBUG_WEB_SERVER 0
#define DLOG if (DEBUG_WEB_SERVER) fprintf #define DLOG if (DEBUG_WEB_SERVER) std::fprintf
using namespace libtorrent; using namespace libtorrent;
namespace lt = libtorrent; namespace lt = libtorrent;
@ -192,7 +192,7 @@ alert const* wait_for_alert(lt::session& ses, int type, char const* name)
{ {
if (should_print(a)) if (should_print(a))
{ {
std::fprintf(stderr, "%s: %s: [%s] %s\n", time_now_string(), name std::fprintf(stdout, "%s: %s: [%s] %s\n", time_now_string(), name
, a->what(), a->message().c_str()); , a->what(), a->message().c_str());
} }
if (a->type() == type && !ret) if (a->type() == type && !ret)
@ -273,7 +273,7 @@ void save_file(char const* filename, char const* data, int size)
TEST_CHECK(!ec); TEST_CHECK(!ec);
if (ec) if (ec)
{ {
std::fprintf(stderr, "ERROR opening file '%s': %s\n", filename, ec.message().c_str()); std::fprintf(stdout, "ERROR opening file '%s': %s\n", filename, ec.message().c_str());
return; return;
} }
file::iovec_t b = { (void*)data, size_t(size) }; file::iovec_t b = { (void*)data, size_t(size) };
@ -281,7 +281,7 @@ void save_file(char const* filename, char const* data, int size)
TEST_CHECK(!ec); TEST_CHECK(!ec);
if (ec) if (ec)
{ {
std::fprintf(stderr, "ERROR writing file '%s': %s\n", filename, ec.message().c_str()); std::fprintf(stdout, "ERROR writing file '%s': %s\n", filename, ec.message().c_str());
return; return;
} }
@ -303,12 +303,12 @@ bool print_alerts(lt::session& ses, char const* name
if (predicate && predicate(a)) ret = true; if (predicate && predicate(a)) ret = true;
if (peer_disconnected_alert const* p = alert_cast<peer_disconnected_alert>(a)) if (peer_disconnected_alert const* p = alert_cast<peer_disconnected_alert>(a))
{ {
std::fprintf(stderr, "%s: %s: [%s] (%s): %s\n", time_now_string(), name, (a)->what(), print_endpoint(p->ip).c_str(), p->message().c_str()); std::fprintf(stdout, "%s: %s: [%s] (%s): %s\n", time_now_string(), name, (a)->what(), print_endpoint(p->ip).c_str(), p->message().c_str());
} }
else if (should_print(a) else if (should_print(a)
&& !no_output) && !no_output)
{ {
std::fprintf(stderr, "%s: %s: [%s] %s\n", time_now_string(), name, (a)->what(), (a)->message().c_str()); std::fprintf(stdout, "%s: %s: [%s] %s\n", time_now_string(), name, (a)->what(), (a)->message().c_str());
} }
TEST_CHECK(alert_cast<fastresume_rejected_alert>(a) == nullptr || allow_failed_fastresume); TEST_CHECK(alert_cast<fastresume_rejected_alert>(a) == nullptr || allow_failed_fastresume);
@ -316,7 +316,7 @@ bool print_alerts(lt::session& ses, char const* name
peer_error_alert const* pea = alert_cast<peer_error_alert>(a); peer_error_alert const* pea = alert_cast<peer_error_alert>(a);
if (pea) if (pea)
{ {
std::fprintf(stderr, "%s: peer error: %s\n", time_now_string(), pea->error.message().c_str()); std::fprintf(stdout, "%s: peer error: %s\n", time_now_string(), pea->error.message().c_str());
TEST_CHECK((!handles.empty() && h.status().is_seeding) TEST_CHECK((!handles.empty() && h.status().is_seeding)
|| pea->error.message() == "connecting to peer" || pea->error.message() == "connecting to peer"
|| pea->error.message() == "closing connection to ourself" || pea->error.message() == "closing connection to ourself"
@ -334,7 +334,7 @@ bool print_alerts(lt::session& ses, char const* name
invalid_request_alert const* ira = alert_cast<invalid_request_alert>(a); invalid_request_alert const* ira = alert_cast<invalid_request_alert>(a);
if (ira) if (ira)
{ {
std::fprintf(stderr, "peer error: %s\n", ira->message().c_str()); std::fprintf(stdout, "peer error: %s\n", ira->message().c_str());
TEST_CHECK(false); TEST_CHECK(false);
} }
} }
@ -387,7 +387,7 @@ void wait_for_downloading(lt::session& ses, char const* name)
} while (a); } while (a);
if (!downloading_done) if (!downloading_done)
{ {
std::fprintf(stderr, "%s: did not receive a state_changed_alert indicating " std::fprintf(stdout, "%s: did not receive a state_changed_alert indicating "
"the torrent is downloading. waited: %d ms\n" "the torrent is downloading. waited: %d ms\n"
, name, int(total_milliseconds(clock_type::now() - start))); , name, int(total_milliseconds(clock_type::now() - start)));
} }
@ -400,7 +400,7 @@ void print_ses_rate(float time
{ {
if (st1) if (st1)
{ {
std::fprintf(stderr, "%3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time std::fprintf(stdout, "%3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time
, int(st1->download_payload_rate / 1000) , int(st1->download_payload_rate / 1000)
, int(st1->upload_payload_rate / 1000) , int(st1->upload_payload_rate / 1000)
, int(st1->progress * 100) , int(st1->progress * 100)
@ -409,7 +409,7 @@ void print_ses_rate(float time
, st1->errc ? (" [" + st1->errc.message() + "]").c_str() : ""); , st1->errc ? (" [" + st1->errc.message() + "]").c_str() : "");
} }
if (st2) if (st2)
std::fprintf(stderr, " : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time std::fprintf(stdout, " : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time
, int(st2->download_payload_rate / 1000) , int(st2->download_payload_rate / 1000)
, int(st2->upload_payload_rate / 1000) , int(st2->upload_payload_rate / 1000)
, int(st2->progress * 100) , int(st2->progress * 100)
@ -417,7 +417,7 @@ void print_ses_rate(float time
, st2->connect_candidates , st2->connect_candidates
, st2->errc ? (" [" + st1->errc.message() + "]").c_str() : ""); , st2->errc ? (" [" + st1->errc.message() + "]").c_str() : "");
if (st3) if (st3)
std::fprintf(stderr, " : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time std::fprintf(stdout, " : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time
, int(st3->download_payload_rate / 1000) , int(st3->download_payload_rate / 1000)
, int(st3->upload_payload_rate / 1000) , int(st3->upload_payload_rate / 1000)
, int(st3->progress * 100) , int(st3->progress * 100)
@ -425,7 +425,7 @@ void print_ses_rate(float time
, st3->connect_candidates , st3->connect_candidates
, st3->errc ? (" [" + st1->errc.message() + "]").c_str() : ""); , st3->errc ? (" [" + st1->errc.message() + "]").c_str() : "");
std::fprintf(stderr, "\n"); std::fprintf(stdout, "\n");
} }
#ifdef _WIN32 #ifdef _WIN32
@ -445,7 +445,7 @@ static std::map<int, proxy_t> running_proxies;
void stop_proxy(int port) void stop_proxy(int port)
{ {
std::fprintf(stderr, "stopping proxy on port %d\n", port); std::fprintf(stdout, "stopping proxy on port %d\n", port);
// don't shut down proxies until the test is // don't shut down proxies until the test is
// completely done. This saves a lot of time. // completely done. This saves a lot of time.
// they're closed at the end of main() by // they're closed at the end of main() by
@ -471,7 +471,7 @@ pid_type async_run(char const* cmdline)
if (ret == 0) if (ret == 0)
{ {
int error = GetLastError(); int error = GetLastError();
std::fprintf(stderr, "failed (%d) %s\n", error, error_code(error, system_category()).message().c_str()); std::fprintf(stdout, "failed (%d) %s\n", error, error_code(error, system_category()).message().c_str());
return 0; return 0;
} }
return pi.dwProcessId; return pi.dwProcessId;
@ -497,7 +497,7 @@ pid_type async_run(char const* cmdline)
int ret = posix_spawnp(&p, argv[0], nullptr, nullptr, &argv[0], nullptr); int ret = posix_spawnp(&p, argv[0], nullptr, nullptr, &argv[0], nullptr);
if (ret != 0) if (ret != 0)
{ {
std::fprintf(stderr, "failed (%d) %s\n", errno, strerror(errno)); std::fprintf(stdout, "failed (%d) %s\n", errno, strerror(errno));
return 0; return 0;
} }
return p; return p;
@ -586,13 +586,13 @@ int start_proxy(int proxy_type)
char buf[512]; char buf[512];
std::snprintf(buf, sizeof(buf), "%s --port %d%s", cmd, port, auth); std::snprintf(buf, sizeof(buf), "%s --port %d%s", cmd, port, auth);
std::fprintf(stderr, "%s starting proxy on port %d (%s %s)...\n", time_now_string(), port, type, auth); std::fprintf(stdout, "%s starting proxy on port %d (%s %s)...\n", time_now_string(), port, type, auth);
std::fprintf(stderr, "%s\n", buf); std::fprintf(stdout, "%s\n", buf);
pid_type r = async_run(buf); pid_type r = async_run(buf);
if (r == 0) abort(); if (r == 0) abort();
proxy_t t = { r, proxy_type }; proxy_t t = { r, proxy_type };
running_proxies.insert(std::make_pair(port, t)); running_proxies.insert(std::make_pair(port, t));
std::fprintf(stderr, "%s launched\n", time_now_string()); std::fprintf(stdout, "%s launched\n", time_now_string());
std::this_thread::sleep_for(lt::milliseconds(500)); std::this_thread::sleep_for(lt::milliseconds(500));
return port; return port;
} }
@ -684,7 +684,7 @@ void create_random_files(std::string const& path, const int file_sizes[], int nu
int to_write = file_sizes[i]; int to_write = file_sizes[i];
file f(full_path, file::write_only, ec); file f(full_path, file::write_only, ec);
if (ec) std::fprintf(stderr, "failed to create file \"%s\": (%d) %s\n" if (ec) std::fprintf(stdout, "failed to create file \"%s\": (%d) %s\n"
, full_path.c_str(), ec.value(), ec.message().c_str()); , full_path.c_str(), ec.value(), ec.message().c_str());
std::int64_t offset = 0; std::int64_t offset = 0;
while (to_write > 0) while (to_write > 0)
@ -692,7 +692,7 @@ void create_random_files(std::string const& path, const int file_sizes[], int nu
int s = (std::min)(to_write, 300000); int s = (std::min)(to_write, 300000);
file::iovec_t b = { random_data, size_t(s)}; file::iovec_t b = { random_data, size_t(s)};
f.writev(offset, &b, 1, ec); f.writev(offset, &b, 1, ec);
if (ec) std::fprintf(stderr, "failed to write file \"%s\": (%d) %s\n" if (ec) std::fprintf(stdout, "failed to write file \"%s\": (%d) %s\n"
, full_path.c_str(), ec.value(), ec.message().c_str()); , full_path.c_str(), ec.value(), ec.message().c_str());
offset += s; offset += s;
to_write -= s; to_write -= s;
@ -726,7 +726,7 @@ std::shared_ptr<torrent_info> create_torrent(std::ostream* file
int res = load_file(ssl_certificate, file_buf, ec); int res = load_file(ssl_certificate, file_buf, ec);
if (ec || res < 0) if (ec || res < 0)
{ {
std::fprintf(stderr, "failed to load SSL certificate: %s\n", ec.message().c_str()); std::fprintf(stdout, "failed to load SSL certificate: %s\n", ec.message().c_str());
} }
else else
{ {
@ -840,7 +840,7 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3
} }
char ih_hex[41]; char ih_hex[41];
aux::to_hex(t->info_hash(), ih_hex); aux::to_hex(t->info_hash(), ih_hex);
std::fprintf(stderr, "generated torrent: %s tmp1%s/temporary\n", ih_hex, suffix.c_str()); std::fprintf(stdout, "generated torrent: %s tmp1%s/temporary\n", ih_hex, suffix.c_str());
} }
else else
{ {
@ -861,7 +861,7 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3
torrent_handle tor1 = ses1->add_torrent(param, ec); torrent_handle tor1 = ses1->add_torrent(param, ec);
if (ec) if (ec)
{ {
std::fprintf(stderr, "ses1.add_torrent: %s\n", ec.message().c_str()); std::fprintf(stdout, "ses1.add_torrent: %s\n", ec.message().c_str());
return std::make_tuple(torrent_handle(), torrent_handle(), torrent_handle()); return std::make_tuple(torrent_handle(), torrent_handle(), torrent_handle());
} }
tor1.super_seeding(super_seeding); tor1.super_seeding(super_seeding);
@ -914,16 +914,16 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3
if (use_ssl_ports) if (use_ssl_ports)
{ {
port = ses2->ssl_listen_port(); port = ses2->ssl_listen_port();
std::fprintf(stderr, "%s: ses2->ssl_listen_port(): %d\n", time_now_string(), port); std::fprintf(stdout, "%s: ses2->ssl_listen_port(): %d\n", time_now_string(), port);
} }
if (port == 0) if (port == 0)
{ {
port = ses2->listen_port(); port = ses2->listen_port();
std::fprintf(stderr, "%s: ses2->listen_port(): %d\n", time_now_string(), port); std::fprintf(stdout, "%s: ses2->listen_port(): %d\n", time_now_string(), port);
} }
std::fprintf(stderr, "%s: ses1: connecting peer port: %d\n" std::fprintf(stdout, "%s: ses1: connecting peer port: %d\n"
, time_now_string(), port); , time_now_string(), port);
tor1.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec) tor1.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec)
, std::uint16_t(port))); , std::uint16_t(port)));
@ -946,10 +946,10 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3
if (port == 0) port = ses2->listen_port(); if (port == 0) port = ses2->listen_port();
if (port2 == 0) port2 = ses1->listen_port(); if (port2 == 0) port2 = ses1->listen_port();
std::fprintf(stderr, "ses3: connecting peer port: %d\n", port); std::fprintf(stdout, "ses3: connecting peer port: %d\n", port);
tor3.connect_peer(tcp::endpoint( tor3.connect_peer(tcp::endpoint(
address::from_string("127.0.0.1", ec), std::uint16_t(port))); address::from_string("127.0.0.1", ec), std::uint16_t(port)));
std::fprintf(stderr, "ses3: connecting peer port: %d\n", port2); std::fprintf(stdout, "ses3: connecting peer port: %d\n", port2);
tor3.connect_peer(tcp::endpoint( tor3.connect_peer(tcp::endpoint(
address::from_string("127.0.0.1", ec) address::from_string("127.0.0.1", ec)
, std::uint16_t(port2))); , std::uint16_t(port2)));
@ -981,13 +981,13 @@ int start_web_server(bool ssl, bool chunked_encoding, bool keepalive)
std::snprintf(buf, sizeof(buf), "python ../web_server.py %d %d %d %d" std::snprintf(buf, sizeof(buf), "python ../web_server.py %d %d %d %d"
, port, chunked_encoding , ssl, keepalive); , port, chunked_encoding , ssl, keepalive);
std::fprintf(stderr, "%s starting web_server on port %d...\n", time_now_string(), port); std::fprintf(stdout, "%s starting web_server on port %d...\n", time_now_string(), port);
std::fprintf(stderr, "%s\n", buf); std::fprintf(stdout, "%s\n", buf);
pid_type r = async_run(buf); pid_type r = async_run(buf);
if (r == 0) abort(); if (r == 0) abort();
web_server_pid = r; web_server_pid = r;
std::fprintf(stderr, "%s launched\n", time_now_string()); std::fprintf(stdout, "%s launched\n", time_now_string());
std::this_thread::sleep_for(lt::milliseconds(500)); std::this_thread::sleep_for(lt::milliseconds(500));
return port; return port;
} }
@ -995,7 +995,7 @@ int start_web_server(bool ssl, bool chunked_encoding, bool keepalive)
void stop_web_server() void stop_web_server()
{ {
if (web_server_pid == 0) return; if (web_server_pid == 0) return;
std::fprintf(stderr, "stopping web server\n"); std::fprintf(stdout, "stopping web server\n");
stop_process(web_server_pid); stop_process(web_server_pid);
web_server_pid = 0; web_server_pid = 0;
} }

View File

@ -40,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <exception> #include <exception>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include <cstdio> // for snprintf #include <cstdio> // for std::snprintf
#include <cinttypes> // for PRId64 et.al. #include <cinttypes> // for PRId64 et.al.
#include <boost/preprocessor/cat.hpp> #include <boost/preprocessor/cat.hpp>

View File

@ -93,7 +93,7 @@ void peer_connection::assign_bandwidth(int channel, int amount)
{ {
m_quota += amount; m_quota += amount;
#ifdef VERBOSE_LOGGING #ifdef VERBOSE_LOGGING
std::cerr << " [" << m_name std::cout << " [" << m_name
<< "] assign bandwidth, " << amount << std::endl; << "] assign bandwidth, " << amount << std::endl;
#endif #endif
TEST_CHECK(amount > 0); TEST_CHECK(amount > 0);
@ -151,7 +151,7 @@ void run_test(connections_t& v
, bandwidth_manager& manager , bandwidth_manager& manager
, std::function<void()> f = &nop) , std::function<void()> f = &nop)
{ {
std::cerr << "-------------" << std::endl; std::cout << "-------------" << std::endl;
std::for_each(v.begin(), v.end() std::for_each(v.begin(), v.end()
, std::bind(&peer_connection::start, _1)); , std::bind(&peer_connection::start, _1));
@ -185,7 +185,7 @@ void spawn_connections(connections_t& v, bandwidth_manager& bwm
void test_equal_connections(int num, int limit) void test_equal_connections(int num, int limit)
{ {
std::cerr << "\ntest equal connections " << num << " " << limit << std::endl; std::cout << "\ntest equal connections " << num << " " << limit << std::endl;
bandwidth_manager manager(0); bandwidth_manager manager(0);
global_bwc.throttle(limit); global_bwc.throttle(limit);
@ -202,19 +202,19 @@ void test_equal_connections(int num, int limit)
{ {
sum += (*i)->m_quota; sum += (*i)->m_quota;
std::cerr << (*i)->m_quota / sample_time std::cout << (*i)->m_quota / sample_time
<< " target: " << (limit / num) << " eps: " << err << std::endl; << " target: " << (limit / num) << " eps: " << err << std::endl;
TEST_CHECK(close_to((*i)->m_quota / sample_time, float(limit) / num, err)); TEST_CHECK(close_to((*i)->m_quota / sample_time, float(limit) / num, err));
} }
sum /= sample_time; sum /= sample_time;
std::cerr << "sum: " << sum << " target: " << limit << std::endl; std::cout << "sum: " << sum << " target: " << limit << std::endl;
TEST_CHECK(sum > 0); TEST_CHECK(sum > 0);
TEST_CHECK(close_to(sum, float(limit), 50)); TEST_CHECK(close_to(sum, float(limit), 50));
} }
void test_connections_variable_rate(int num, int limit, int torrent_limit) void test_connections_variable_rate(int num, int limit, int torrent_limit)
{ {
std::cerr << "\ntest connections variable rate" << num std::cout << "\ntest connections variable rate" << num
<< " l: " << limit << " l: " << limit
<< " t: " << torrent_limit << " t: " << torrent_limit
<< std::endl; << std::endl;
@ -243,19 +243,19 @@ void test_connections_variable_rate(int num, int limit, int torrent_limit)
{ {
sum += (*i)->m_quota; sum += (*i)->m_quota;
std::cerr << (*i)->m_quota / sample_time std::cout << (*i)->m_quota / sample_time
<< " target: " << limit << " eps: " << err << std::endl; << " target: " << limit << " eps: " << err << std::endl;
TEST_CHECK(close_to((*i)->m_quota / sample_time, float(limit), err)); TEST_CHECK(close_to((*i)->m_quota / sample_time, float(limit), err));
} }
sum /= sample_time; sum /= sample_time;
std::cerr << "sum: " << sum << " target: " << (limit * num) << std::endl; std::cout << "sum: " << sum << " target: " << (limit * num) << std::endl;
TEST_CHECK(sum > 0); TEST_CHECK(sum > 0);
TEST_CHECK(close_to(sum, float(limit) * num, limit * 0.3f * num)); TEST_CHECK(close_to(sum, float(limit) * num, limit * 0.3f * num));
} }
void test_single_peer(int limit, bool torrent_limit) void test_single_peer(int limit, bool torrent_limit)
{ {
std::cerr << "\ntest single peer " << limit << " " << torrent_limit << std::endl; std::cout << "\ntest single peer " << limit << " " << torrent_limit << std::endl;
bandwidth_manager manager(0); bandwidth_manager manager(0);
bandwidth_channel t1; bandwidth_channel t1;
global_bwc.throttle(0); global_bwc.throttle(0);
@ -276,14 +276,14 @@ void test_single_peer(int limit, bool torrent_limit)
sum += (*i)->m_quota; sum += (*i)->m_quota;
} }
sum /= sample_time; sum /= sample_time;
std::cerr << sum << " target: " << limit << std::endl; std::cout << sum << " target: " << limit << std::endl;
TEST_CHECK(sum > 0); TEST_CHECK(sum > 0);
TEST_CHECK(close_to(sum, float(limit), 1000)); TEST_CHECK(close_to(sum, float(limit), 1000));
} }
void test_torrents(int num, int limit1, int limit2, int global_limit) void test_torrents(int num, int limit1, int limit2, int global_limit)
{ {
std::cerr << "\ntest equal torrents " << num std::cout << "\ntest equal torrents " << num
<< " l1: " << limit1 << " l1: " << limit1
<< " l2: " << limit2 << " l2: " << limit2
<< " g: " << global_limit << std::endl; << " g: " << global_limit << std::endl;
@ -317,7 +317,7 @@ void test_torrents(int num, int limit1, int limit2, int global_limit)
sum += (*i)->m_quota; sum += (*i)->m_quota;
} }
sum /= sample_time; sum /= sample_time;
std::cerr << sum << " target: " << limit1 << std::endl; std::cout << sum << " target: " << limit1 << std::endl;
TEST_CHECK(sum > 0); TEST_CHECK(sum > 0);
TEST_CHECK(close_to(sum, float(limit1), 1000)); TEST_CHECK(close_to(sum, float(limit1), 1000));
@ -328,14 +328,14 @@ void test_torrents(int num, int limit1, int limit2, int global_limit)
sum += (*i)->m_quota; sum += (*i)->m_quota;
} }
sum /= sample_time; sum /= sample_time;
std::cerr << sum << " target: " << limit2 << std::endl; std::cout << sum << " target: " << limit2 << std::endl;
TEST_CHECK(sum > 0); TEST_CHECK(sum > 0);
TEST_CHECK(close_to(sum, float(limit2), 1000)); TEST_CHECK(close_to(sum, float(limit2), 1000));
} }
void test_torrents_variable_rate(int num, int limit, int global_limit) void test_torrents_variable_rate(int num, int limit, int global_limit)
{ {
std::cerr << "\ntest torrents variable rate" << num std::cout << "\ntest torrents variable rate" << num
<< " l: " << limit << " l: " << limit
<< " g: " << global_limit << std::endl; << " g: " << global_limit << std::endl;
bandwidth_manager manager(0); bandwidth_manager manager(0);
@ -367,7 +367,7 @@ void test_torrents_variable_rate(int num, int limit, int global_limit)
sum += (*i)->m_quota; sum += (*i)->m_quota;
} }
sum /= sample_time; sum /= sample_time;
std::cerr << sum << " target: " << limit << std::endl; std::cout << sum << " target: " << limit << std::endl;
TEST_CHECK(sum > 0); TEST_CHECK(sum > 0);
TEST_CHECK(close_to(sum, float(limit), 1000)); TEST_CHECK(close_to(sum, float(limit), 1000));
@ -378,14 +378,14 @@ void test_torrents_variable_rate(int num, int limit, int global_limit)
sum += (*i)->m_quota; sum += (*i)->m_quota;
} }
sum /= sample_time; sum /= sample_time;
std::cerr << sum << " target: " << limit << std::endl; std::cout << sum << " target: " << limit << std::endl;
TEST_CHECK(sum > 0); TEST_CHECK(sum > 0);
TEST_CHECK(close_to(sum, float(limit), 1000)); TEST_CHECK(close_to(sum, float(limit), 1000));
} }
void test_peer_priority(int limit, bool torrent_limit) void test_peer_priority(int limit, bool torrent_limit)
{ {
std::cerr << "\ntest peer priority " << limit << " " << torrent_limit << std::endl; std::cout << "\ntest peer priority " << limit << " " << torrent_limit << std::endl;
bandwidth_manager manager(0); bandwidth_manager manager(0);
bandwidth_channel t1; bandwidth_channel t1;
global_bwc.throttle(0); global_bwc.throttle(0);
@ -411,18 +411,18 @@ void test_peer_priority(int limit, bool torrent_limit)
sum += (*i)->m_quota; sum += (*i)->m_quota;
} }
sum /= sample_time; sum /= sample_time;
std::cerr << sum << " target: " << limit << std::endl; std::cout << sum << " target: " << limit << std::endl;
TEST_CHECK(sum > 0); TEST_CHECK(sum > 0);
TEST_CHECK(close_to(sum, float(limit), 50)); TEST_CHECK(close_to(sum, float(limit), 50));
std::cerr << "non-prioritized rate: " << p->m_quota / sample_time std::cout << "non-prioritized rate: " << p->m_quota / sample_time
<< " target: " << (limit / 200 / 10) << std::endl; << " target: " << (limit / 200 / 10) << std::endl;
TEST_CHECK(close_to(p->m_quota / sample_time, float(limit) / 200 / 10, 5)); TEST_CHECK(close_to(p->m_quota / sample_time, float(limit) / 200 / 10, 5));
} }
void test_no_starvation(int limit) void test_no_starvation(int limit)
{ {
std::cerr << "\ntest no starvation " << limit << std::endl; std::cout << "\ntest no starvation " << limit << std::endl;
bandwidth_manager manager(0); bandwidth_manager manager(0);
bandwidth_channel t1; bandwidth_channel t1;
bandwidth_channel t2; bandwidth_channel t2;
@ -447,11 +447,11 @@ void test_no_starvation(int limit)
sum += (*i)->m_quota; sum += (*i)->m_quota;
} }
sum /= sample_time; sum /= sample_time;
std::cerr << sum << " target: " << limit << std::endl; std::cout << sum << " target: " << limit << std::endl;
TEST_CHECK(sum > 0); TEST_CHECK(sum > 0);
TEST_CHECK(close_to(sum, float(limit), 50)); TEST_CHECK(close_to(sum, float(limit), 50));
std::cerr << "non-prioritized rate: " << p->m_quota / sample_time std::cout << "non-prioritized rate: " << p->m_quota / sample_time
<< " target: " << (limit / 200 / num_peers) << std::endl; << " target: " << (limit / 200 / num_peers) << std::endl;
TEST_CHECK(close_to(p->m_quota / sample_time, float(limit) / 200 / num_peers, 5)); TEST_CHECK(close_to(p->m_quota / sample_time, float(limit) / 200 / num_peers, 5));
} }

View File

@ -62,7 +62,7 @@ void test_checking(int flags = read_only_files)
using namespace libtorrent; using namespace libtorrent;
namespace lt = libtorrent; namespace lt = libtorrent;
std::fprintf(stderr, "\n==== TEST CHECKING %s%s%s=====\n\n" std::fprintf(stdout, "\n==== TEST CHECKING %s%s%s=====\n\n"
, (flags & read_only_files) ? "read-only-files ":"" , (flags & read_only_files) ? "read-only-files ":""
, (flags & corrupt_files) ? "corrupt ":"" , (flags & corrupt_files) ? "corrupt ":""
, (flags & incomplete_files) ? "incomplete ":""); , (flags & incomplete_files) ? "incomplete ":"");
@ -86,14 +86,14 @@ void test_checking(int flags = read_only_files)
// in case the previous run was terminated // in case the previous run was terminated
error_code ec; error_code ec;
remove_all("tmp1_checking", ec); remove_all("tmp1_checking", ec);
if (ec) std::fprintf(stderr, "ERROR: removing tmp1_checking: (%d) %s\n" if (ec) std::fprintf(stdout, "ERROR: removing tmp1_checking: (%d) %s\n"
, ec.value(), ec.message().c_str()); , ec.value(), ec.message().c_str());
create_directory("tmp1_checking", ec); create_directory("tmp1_checking", ec);
if (ec) std::fprintf(stderr, "ERROR: creating directory tmp1_checking: (%d) %s\n" if (ec) std::fprintf(stdout, "ERROR: creating directory tmp1_checking: (%d) %s\n"
, ec.value(), ec.message().c_str()); , ec.value(), ec.message().c_str());
create_directory(combine_path("tmp1_checking", "test_torrent_dir"), ec); create_directory(combine_path("tmp1_checking", "test_torrent_dir"), ec);
if (ec) std::fprintf(stderr, "ERROR: creating directory test_torrent_dir: (%d) %s\n" if (ec) std::fprintf(stdout, "ERROR: creating directory test_torrent_dir: (%d) %s\n"
, ec.value(), ec.message().c_str()); , ec.value(), ec.message().c_str());
file_storage fs; file_storage fs;
@ -109,14 +109,14 @@ void test_checking(int flags = read_only_files)
// calculate the hash for all pieces // calculate the hash for all pieces
set_piece_hashes(t, "tmp1_checking", ec); set_piece_hashes(t, "tmp1_checking", ec);
if (ec) std::fprintf(stderr, "ERROR: set_piece_hashes: (%d) %s\n" if (ec) std::fprintf(stdout, "ERROR: set_piece_hashes: (%d) %s\n"
, ec.value(), ec.message().c_str()); , ec.value(), ec.message().c_str());
std::vector<char> buf; std::vector<char> buf;
bencode(std::back_inserter(buf), t.generate()); bencode(std::back_inserter(buf), t.generate());
auto ti = std::make_shared<torrent_info>(&buf[0], int(buf.size()), ec); auto ti = std::make_shared<torrent_info>(&buf[0], int(buf.size()), ec);
std::fprintf(stderr, "generated torrent: %s tmp1_checking/test_torrent_dir\n" std::fprintf(stdout, "generated torrent: %s tmp1_checking/test_torrent_dir\n"
, aux::to_hex(ti->info_hash()).c_str()); , aux::to_hex(ti->info_hash()).c_str());
// truncate every file in half // truncate every file in half
@ -133,10 +133,10 @@ void test_checking(int flags = read_only_files)
error_code ec; error_code ec;
file f(path, file::read_write, ec); file f(path, file::read_write, ec);
if (ec) std::fprintf(stderr, "ERROR: opening file \"%s\": (%d) %s\n" if (ec) std::fprintf(stdout, "ERROR: opening file \"%s\": (%d) %s\n"
, path.c_str(), ec.value(), ec.message().c_str()); , path.c_str(), ec.value(), ec.message().c_str());
f.set_size(file_sizes[i] / 2, ec); f.set_size(file_sizes[i] / 2, ec);
if (ec) std::fprintf(stderr, "ERROR: truncating file \"%s\": (%d) %s\n" if (ec) std::fprintf(stdout, "ERROR: truncating file \"%s\": (%d) %s\n"
, path.c_str(), ec.value(), ec.message().c_str()); , path.c_str(), ec.value(), ec.message().c_str());
} }
} }
@ -144,7 +144,7 @@ void test_checking(int flags = read_only_files)
// overwrite the files with new random data // overwrite the files with new random data
if (flags & corrupt_files) if (flags & corrupt_files)
{ {
std::fprintf(stderr, "corrupt file test. overwriting files\n"); std::fprintf(stdout, "corrupt file test. overwriting files\n");
// increase the size of some files. When they're read only that forces // increase the size of some files. When they're read only that forces
// the checker to open them in write-mode to truncate them // the checker to open them in write-mode to truncate them
static const int file_sizes2[] = static const int file_sizes2[] =
@ -156,7 +156,7 @@ void test_checking(int flags = read_only_files)
// make the files read only // make the files read only
if (flags & read_only_files) if (flags & read_only_files)
{ {
std::fprintf(stderr, "making files read-only\n"); std::fprintf(stdout, "making files read-only\n");
for (int i = 0; i < num_files; ++i) for (int i = 0; i < num_files; ++i)
{ {
char name[1024]; char name[1024];
@ -166,7 +166,7 @@ void test_checking(int flags = read_only_files)
std::string path = combine_path(combine_path("tmp1_checking", "test_torrent_dir"), dirname); std::string path = combine_path(combine_path("tmp1_checking", "test_torrent_dir"), dirname);
path = combine_path(path, name); path = combine_path(path, name);
std::fprintf(stderr, " %s\n", path.c_str()); std::fprintf(stdout, " %s\n", path.c_str());
#ifdef TORRENT_WINDOWS #ifdef TORRENT_WINDOWS
SetFileAttributesA(path.c_str(), FILE_ATTRIBUTE_READONLY); SetFileAttributesA(path.c_str(), FILE_ATTRIBUTE_READONLY);
@ -237,7 +237,7 @@ void test_checking(int flags = read_only_files)
// read-only here, we expect the checking to fail. // read-only here, we expect the checking to fail.
TEST_CHECK(st.errc); TEST_CHECK(st.errc);
if (st.errc) if (st.errc)
std::fprintf(stderr, "error: %s\n", st.errc.message().c_str()); std::fprintf(stdout, "error: %s\n", st.errc.message().c_str());
// wait a while to make sure libtorrent survived the error // wait a while to make sure libtorrent survived the error
std::this_thread::sleep_for(lt::milliseconds(1000)); std::this_thread::sleep_for(lt::milliseconds(1000));
@ -246,13 +246,13 @@ void test_checking(int flags = read_only_files)
TEST_CHECK(!st.is_seeding); TEST_CHECK(!st.is_seeding);
TEST_CHECK(st.errc); TEST_CHECK(st.errc);
if (st.errc) if (st.errc)
std::fprintf(stderr, "error: %s\n", st.errc.message().c_str()); std::fprintf(stdout, "error: %s\n", st.errc.message().c_str());
} }
else else
{ {
TEST_CHECK(!st.errc); TEST_CHECK(!st.errc);
if (st.errc) if (st.errc)
std::fprintf(stderr, "error: %s\n", st.errc.message().c_str()); std::fprintf(stdout, "error: %s\n", st.errc.message().c_str());
} }
} }
@ -260,7 +260,7 @@ void test_checking(int flags = read_only_files)
{ {
TEST_CHECK(st.is_seeding); TEST_CHECK(st.is_seeding);
if (st.errc) if (st.errc)
std::fprintf(stderr, "error: %s\n", st.errc.message().c_str()); std::fprintf(stdout, "error: %s\n", st.errc.message().c_str());
} }
// make the files writable again // make the files writable again
@ -284,7 +284,7 @@ void test_checking(int flags = read_only_files)
} }
remove_all("tmp1_checking", ec); remove_all("tmp1_checking", ec);
if (ec) std::fprintf(stderr, "ERROR: removing tmp1_checking: (%d) %s\n" if (ec) std::fprintf(stdout, "ERROR: removing tmp1_checking: (%d) %s\n"
, ec.value(), ec.message().c_str()); , ec.value(), ec.message().c_str());
} }

View File

@ -235,7 +235,7 @@ void send_dht_request(node& node, char const* msg, udp::endpoint const& ep
bdecode_node decoded; bdecode_node decoded;
error_code ec; error_code ec;
bdecode(msg_buf, msg_buf + size, decoded, ec); bdecode(msg_buf, msg_buf + size, decoded, ec);
if (ec) std::fprintf(stderr, "bdecode failed: %s\n", ec.message().c_str()); if (ec) std::fprintf(stdout, "bdecode failed: %s\n", ec.message().c_str());
dht::msg m(decoded, ep); dht::msg m(decoded, ep);
node.incoming(m); node.incoming(m);
@ -280,7 +280,7 @@ void send_dht_response(node& node, bdecode_node const& request, udp::endpoint co
bdecode_node decoded; bdecode_node decoded;
error_code ec; error_code ec;
bdecode(msg_buf, msg_buf + size, decoded, ec); bdecode(msg_buf, msg_buf + size, decoded, ec);
if (ec) std::fprintf(stderr, "bdecode failed: %s\n", ec.message().c_str()); if (ec) std::fprintf(stdout, "bdecode failed: %s\n", ec.message().c_str());
dht::msg m(decoded, ep); dht::msg m(decoded, ep);
node.incoming(m); node.incoming(m);
@ -334,18 +334,18 @@ void announce_immutable_items(node& node, udp::endpoint const* eps
bdecode_node parsed[5]; bdecode_node parsed[5];
char error_string[200]; char error_string[200];
// std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); // std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
int ret = verify_message(response, desc, parsed, error_string); int ret = verify_message(response, desc, parsed, error_string);
if (ret) if (ret)
{ {
TEST_EQUAL(parsed[4].string_value(), "r"); TEST_EQUAL(parsed[4].string_value(), "r");
token = parsed[2].string_value().to_string(); token = parsed[2].string_value().to_string();
// std::fprintf(stderr, "got token: %s\n", token.c_str()); // std::fprintf(stdout, "got token: %s\n", token.c_str());
} }
else else
{ {
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
std::fprintf(stderr, " invalid get response: %s\n", error_string); std::fprintf(stdout, " invalid get response: %s\n", error_string);
TEST_ERROR(error_string); TEST_ERROR(error_string);
} }
@ -373,14 +373,14 @@ void announce_immutable_items(node& node, udp::endpoint const* eps
if (ret) if (ret)
{ {
if (parsed2[0].string_value() != "r") if (parsed2[0].string_value() != "r")
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
TEST_EQUAL(parsed2[0].string_value(), "r"); TEST_EQUAL(parsed2[0].string_value(), "r");
} }
else else
{ {
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
std::fprintf(stderr, " invalid put response: %s\n", error_string); std::fprintf(stdout, " invalid put response: %s\n", error_string);
TEST_ERROR(error_string); TEST_ERROR(error_string);
} }
} }
@ -489,7 +489,7 @@ struct obs : dht::dht_observer
char buf[1024]; char buf[1024];
vsnprintf(buf, sizeof(buf), fmt, v); vsnprintf(buf, sizeof(buf), fmt, v);
va_end(v); va_end(v);
fprintf(stderr, "%s\n", buf); std::fprintf(stdout, "%s\n", buf);
m_log.push_back(buf); m_log.push_back(buf);
} }
void log_packet(message_direction_t dir, span<char const> pkt void log_packet(message_direction_t dir, span<char const> pkt
@ -761,7 +761,7 @@ TORRENT_TEST(ping)
bdecode_node pong_keys[4]; bdecode_node pong_keys[4];
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
bool ret = dht::verify_message(response, pong_desc, pong_keys, t.error_string); bool ret = dht::verify_message(response, pong_desc, pong_keys, t.error_string);
TEST_CHECK(ret); TEST_CHECK(ret);
if (ret) if (ret)
@ -771,7 +771,7 @@ TORRENT_TEST(ping)
} }
else else
{ {
std::fprintf(stderr, " invalid ping response: %s\n", t.error_string); std::fprintf(stdout, " invalid ping response: %s\n", t.error_string);
} }
} }
@ -783,7 +783,7 @@ TORRENT_TEST(invalid_message)
send_dht_request(t.dht_node, "find_node", t.source, &response); send_dht_request(t.dht_node, "find_node", t.source, &response);
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
bool ret = dht::verify_message(response, err_desc, err_keys, t.error_string); bool ret = dht::verify_message(response, err_desc, err_keys, t.error_string);
TEST_CHECK(ret); TEST_CHECK(ret);
if (ret) if (ret)
@ -801,7 +801,7 @@ TORRENT_TEST(invalid_message)
} }
else else
{ {
std::fprintf(stderr, " invalid error response: %s\n", t.error_string); std::fprintf(stdout, " invalid error response: %s\n", t.error_string);
} }
} }
@ -829,19 +829,19 @@ TORRENT_TEST(get_peers_announce)
bdecode_node peer1_keys[4]; bdecode_node peer1_keys[4];
std::string token; std::string token;
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
bool ret = dht::verify_message(response, peer1_desc, peer1_keys, t.error_string); bool ret = dht::verify_message(response, peer1_desc, peer1_keys, t.error_string);
TEST_CHECK(ret); TEST_CHECK(ret);
if (ret) if (ret)
{ {
TEST_CHECK(peer1_keys[0].string_value() == "r"); TEST_CHECK(peer1_keys[0].string_value() == "r");
token = peer1_keys[2].string_value().to_string(); token = peer1_keys[2].string_value().to_string();
// std::fprintf(stderr, "got token: %s\n", token.c_str()); // std::fprintf(stdout, "got token: %s\n", token.c_str());
} }
else else
{ {
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
std::fprintf(stderr, " invalid get_peers response: %s\n", t.error_string); std::fprintf(stdout, " invalid get_peers response: %s\n", t.error_string);
} }
send_dht_request(t.dht_node, "announce_peer", t.source, &response send_dht_request(t.dht_node, "announce_peer", t.source, &response
@ -859,7 +859,7 @@ TORRENT_TEST(get_peers_announce)
bdecode_node ann_keys[3]; bdecode_node ann_keys[3];
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
ret = dht::verify_message(response, ann_desc, ann_keys, t.error_string); ret = dht::verify_message(response, ann_desc, ann_keys, t.error_string);
TEST_CHECK(ret); TEST_CHECK(ret);
if (ret) if (ret)
@ -868,7 +868,7 @@ TORRENT_TEST(get_peers_announce)
} }
else else
{ {
std::fprintf(stderr, " invalid announce response:\n"); std::fprintf(stdout, " invalid announce response:\n");
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
} }
} }
@ -899,8 +899,8 @@ void test_scrape(address(&rand_addr)())
} }
else else
{ {
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
std::fprintf(stderr, " invalid get_peers response: %s\n", t.error_string); std::fprintf(stdout, " invalid get_peers response: %s\n", t.error_string);
} }
response.clear(); response.clear();
send_dht_request(t.dht_node, "announce_peer", t.source, &response send_dht_request(t.dht_node, "announce_peer", t.source, &response
@ -929,7 +929,7 @@ void test_scrape(address(&rand_addr)())
bdecode_node peer2_keys[5]; bdecode_node peer2_keys[5];
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
bool ret = dht::verify_message(response, peer2_desc, peer2_keys, t.error_string); bool ret = dht::verify_message(response, peer2_desc, peer2_keys, t.error_string);
TEST_CHECK(ret); TEST_CHECK(ret);
if (ret) if (ret)
@ -942,15 +942,15 @@ void test_scrape(address(&rand_addr)())
downloaders.from_string(peer2_keys[2].string_ptr()); downloaders.from_string(peer2_keys[2].string_ptr());
seeds.from_string(peer2_keys[3].string_ptr()); seeds.from_string(peer2_keys[3].string_ptr());
std::fprintf(stderr, "seeds: %f\n", seeds.size()); std::fprintf(stdout, "seeds: %f\n", seeds.size());
std::fprintf(stderr, "downloaders: %f\n", downloaders.size()); std::fprintf(stdout, "downloaders: %f\n", downloaders.size());
TEST_CHECK(fabs(seeds.size() - 50.f) <= 3.f); TEST_CHECK(fabs(seeds.size() - 50.f) <= 3.f);
TEST_CHECK(fabs(downloaders.size() - 50.f) <= 3.f); TEST_CHECK(fabs(downloaders.size() - 50.f) <= 3.f);
} }
else else
{ {
std::fprintf(stderr, "invalid get_peers response:\n"); std::fprintf(stdout, "invalid get_peers response:\n");
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
} }
} }
@ -1012,14 +1012,14 @@ void test_id_enforcement(address(&rand_addr)())
} }
else else
{ {
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
TEST_ERROR("invalid error response"); TEST_ERROR("invalid error response");
} }
} }
else else
{ {
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
std::fprintf(stderr, " invalid error response: %s\n", t.error_string); std::fprintf(stdout, " invalid error response: %s\n", t.error_string);
} }
// a node with invalid node-id shouldn't be added to routing table. // a node with invalid node-id shouldn't be added to routing table.
@ -1043,7 +1043,7 @@ void test_id_enforcement(address(&rand_addr)())
bdecode_node nodes_keys[3]; bdecode_node nodes_keys[3];
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
ret = dht::verify_message(response, nodes_desc, nodes_keys, t.error_string); ret = dht::verify_message(response, nodes_desc, nodes_keys, t.error_string);
TEST_CHECK(ret); TEST_CHECK(ret);
if (ret) if (ret)
@ -1052,8 +1052,8 @@ void test_id_enforcement(address(&rand_addr)())
} }
else else
{ {
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
std::fprintf(stderr, " invalid error response: %s\n", t.error_string); std::fprintf(stdout, " invalid error response: %s\n", t.error_string);
} }
// node with valid node-id should be added to routing table. // node with valid node-id should be added to routing table.
TEST_EQUAL(std::get<0>(t.dht_node.size()), nodes_num + 1); TEST_EQUAL(std::get<0>(t.dht_node.size()), nodes_num + 1);
@ -1098,9 +1098,9 @@ TORRENT_TEST(bloom_filter)
// these are test vectors from BEP 33 // these are test vectors from BEP 33
// http://www.bittorrent.org/beps/bep_0033.html // http://www.bittorrent.org/beps/bep_0033.html
std::fprintf(stderr, "test.size: %f\n", test.size()); std::fprintf(stdout, "test.size: %f\n", test.size());
std::string const bf_str = test.to_string(); std::string const bf_str = test.to_string();
std::fprintf(stderr, "%s\n", aux::to_hex(bf_str).c_str()); std::fprintf(stdout, "%s\n", aux::to_hex(bf_str).c_str());
if (supports_ipv6()) if (supports_ipv6())
{ {
TEST_CHECK(fabs(test.size() - 1224.93f) < 0.001); TEST_CHECK(fabs(test.size() - 1224.93f) < 0.001);
@ -1207,12 +1207,12 @@ void test_put(address(&rand_addr)())
for (int with_salt = 0; with_salt < 2; ++with_salt) for (int with_salt = 0; with_salt < 2; ++with_salt)
{ {
seq = sequence_number(4); seq = sequence_number(4);
std::fprintf(stderr, "\nTEST GET/PUT%s \ngenerating ed25519 keys\n\n" std::fprintf(stdout, "\nTEST GET/PUT%s \ngenerating ed25519 keys\n\n"
, with_salt ? " with-salt" : " no-salt"); , with_salt ? " with-salt" : " no-salt");
std::array<char, 32> seed = ed25519_create_seed(); std::array<char, 32> seed = ed25519_create_seed();
std::tie(pk, sk) = ed25519_create_keypair(seed); std::tie(pk, sk) = ed25519_create_keypair(seed);
std::fprintf(stderr, "pub: %s priv: %s\n" std::fprintf(stdout, "pub: %s priv: %s\n"
, aux::to_hex(pk.bytes).c_str() , aux::to_hex(pk.bytes).c_str()
, aux::to_hex(sk.bytes).c_str()); , aux::to_hex(sk.bytes).c_str());
@ -1223,7 +1223,7 @@ void test_put(address(&rand_addr)())
if (with_salt) h.update(salt); if (with_salt) h.update(salt);
sha1_hash target_id = h.final(); sha1_hash target_id = h.final();
std::fprintf(stderr, "target_id: %s\n" std::fprintf(stdout, "target_id: %s\n"
, aux::to_hex(target_id).c_str()); , aux::to_hex(target_id).c_str());
send_dht_request(t.dht_node, "get", t.source, &response send_dht_request(t.dht_node, "get", t.source, &response
@ -1246,14 +1246,14 @@ void test_put(address(&rand_addr)())
{ {
TEST_EQUAL(desc_keys[4].string_value(), "r"); TEST_EQUAL(desc_keys[4].string_value(), "r");
token = desc_keys[2].string_value().to_string(); token = desc_keys[2].string_value().to_string();
std::fprintf(stderr, "get response: %s\n" std::fprintf(stdout, "get response: %s\n"
, print_entry(response).c_str()); , print_entry(response).c_str());
std::fprintf(stderr, "got token: %s\n", aux::to_hex(token).c_str()); std::fprintf(stdout, "got token: %s\n", aux::to_hex(token).c_str());
} }
else else
{ {
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
std::fprintf(stderr, " invalid get response: %s\n%s\n" std::fprintf(stdout, " invalid get response: %s\n%s\n"
, t.error_string, print_entry(response).c_str()); , t.error_string, print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
} }
@ -1274,13 +1274,13 @@ void test_put(address(&rand_addr)())
ret = verify_message(response, desc2, desc2_keys, t.error_string); ret = verify_message(response, desc2, desc2_keys, t.error_string);
if (ret) if (ret)
{ {
std::fprintf(stderr, "put response: %s\n" std::fprintf(stdout, "put response: %s\n"
, print_entry(response).c_str()); , print_entry(response).c_str());
TEST_EQUAL(desc2_keys[0].string_value(), "r"); TEST_EQUAL(desc2_keys[0].string_value(), "r");
} }
else else
{ {
std::fprintf(stderr, " invalid put response: %s\n%s\n" std::fprintf(stdout, " invalid put response: %s\n%s\n"
, t.error_string, print_entry(response).c_str()); , t.error_string, print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
} }
@ -1288,7 +1288,7 @@ void test_put(address(&rand_addr)())
send_dht_request(t.dht_node, "get", t.source, &response send_dht_request(t.dht_node, "get", t.source, &response
, msg_args().target(target_id)); , msg_args().target(target_id));
std::fprintf(stderr, "target_id: %s\n" std::fprintf(stdout, "target_id: %s\n"
, aux::to_hex(target_id).c_str()); , aux::to_hex(target_id).c_str());
key_desc_t const desc3[] = key_desc_t const desc3[] =
@ -1307,14 +1307,14 @@ void test_put(address(&rand_addr)())
ret = verify_message(response, desc3, desc3_keys, t.error_string); ret = verify_message(response, desc3, desc3_keys, t.error_string);
if (ret == 0) if (ret == 0)
{ {
std::fprintf(stderr, "msg: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str());
std::fprintf(stderr, " invalid get response: %s\n%s\n" std::fprintf(stdout, " invalid get response: %s\n%s\n"
, t.error_string, print_entry(response).c_str()); , t.error_string, print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
} }
else else
{ {
std::fprintf(stderr, "get response: %s\n" std::fprintf(stdout, "get response: %s\n"
, print_entry(response).c_str()); , print_entry(response).c_str());
char value[1020]; char value[1020];
char* ptr = value; char* ptr = value;
@ -1333,7 +1333,7 @@ void test_put(address(&rand_addr)())
// break the signature // break the signature
sig.bytes[2] ^= 0xaa; sig.bytes[2] ^= 0xaa;
std::fprintf(stderr, "PUT broken signature\n"); std::fprintf(stdout, "PUT broken signature\n");
TEST_CHECK(verify_mutable_item(itemv, salt, seq, pk, sig) != 1); TEST_CHECK(verify_mutable_item(itemv, salt, seq, pk, sig) != 1);
@ -1349,14 +1349,14 @@ void test_put(address(&rand_addr)())
ret = verify_message(response, desc_error, desc_error_keys, t.error_string); ret = verify_message(response, desc_error, desc_error_keys, t.error_string);
if (ret) if (ret)
{ {
std::fprintf(stderr, "put response: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "put response: %s\n", print_entry(response).c_str());
TEST_EQUAL(desc_error_keys[1].string_value(), "e"); TEST_EQUAL(desc_error_keys[1].string_value(), "e");
// 206 is the code for invalid signature // 206 is the code for invalid signature
TEST_EQUAL(desc_error_keys[0].list_int_value_at(0), 206); TEST_EQUAL(desc_error_keys[0].list_int_value_at(0), 206);
} }
else else
{ {
std::fprintf(stderr, " invalid put response: %s\n%s\n" std::fprintf(stdout, " invalid put response: %s\n%s\n"
, t.error_string, print_entry(response).c_str()); , t.error_string, print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
} }
@ -1397,7 +1397,7 @@ void test_put(address(&rand_addr)())
TEST_CHECK(item_target_id(salt, pk) == target_id); TEST_CHECK(item_target_id(salt, pk) == target_id);
std::fprintf(stderr, "PUT CAS 1\n"); std::fprintf(stdout, "PUT CAS 1\n");
send_dht_request(t.dht_node, "put", t.source, &response send_dht_request(t.dht_node, "put", t.source, &response
, msg_args() , msg_args()
@ -1412,18 +1412,18 @@ void test_put(address(&rand_addr)())
ret = verify_message(response, desc2, desc2_keys, t.error_string); ret = verify_message(response, desc2, desc2_keys, t.error_string);
if (ret) if (ret)
{ {
std::fprintf(stderr, "put response: %s\n" std::fprintf(stdout, "put response: %s\n"
, print_entry(response).c_str()); , print_entry(response).c_str());
TEST_EQUAL(desc2_keys[0].string_value(), "r"); TEST_EQUAL(desc2_keys[0].string_value(), "r");
} }
else else
{ {
std::fprintf(stderr, " invalid put response: %s\n%s\n" std::fprintf(stdout, " invalid put response: %s\n%s\n"
, t.error_string, print_entry(response).c_str()); , t.error_string, print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
} }
std::fprintf(stderr, "PUT CAS 2\n"); std::fprintf(stdout, "PUT CAS 2\n");
// put the same message again. This should fail because the // put the same message again. This should fail because the
// CAS hash is outdated, it's not the hash of the value that's // CAS hash is outdated, it's not the hash of the value that's
@ -1441,7 +1441,7 @@ void test_put(address(&rand_addr)())
ret = verify_message(response, desc_error, desc_error_keys, t.error_string); ret = verify_message(response, desc_error, desc_error_keys, t.error_string);
if (ret) if (ret)
{ {
std::fprintf(stderr, "put response: %s\n" std::fprintf(stdout, "put response: %s\n"
, print_entry(response).c_str()); , print_entry(response).c_str());
TEST_EQUAL(desc_error_keys[1].string_value(), "e"); TEST_EQUAL(desc_error_keys[1].string_value(), "e");
// 301 is the error code for CAS hash mismatch // 301 is the error code for CAS hash mismatch
@ -1449,7 +1449,7 @@ void test_put(address(&rand_addr)())
} }
else else
{ {
std::fprintf(stderr, " invalid put response: %s\n%s\nExpected failure 301 (CAS hash mismatch)\n" std::fprintf(stdout, " invalid put response: %s\n%s\nExpected failure 301 (CAS hash mismatch)\n"
, t.error_string, print_entry(response).c_str()); , t.error_string, print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
} }
@ -1671,7 +1671,7 @@ void test_routing_table(address(&rand_addr)())
TEST_CHECK((id[2] & 0xf8) == (prefixes[i][2] & 0xf8)); TEST_CHECK((id[2] & 0xf8) == (prefixes[i][2] & 0xf8));
TEST_CHECK(id[19] == rs[i]); TEST_CHECK(id[19] == rs[i]);
std::fprintf(stderr, "IP address: %s r: %d node ID: %s\n", ips[i] std::fprintf(stdout, "IP address: %s r: %d node ID: %s\n", ips[i]
, rs[i], aux::to_hex(id).c_str()); , rs[i], aux::to_hex(id).c_str());
} }
} }
@ -1734,7 +1734,7 @@ void test_bootstrap(address(&rand_addr)())
} }
else else
{ {
std::fprintf(stderr, " invalid find_node request: %s\n", print_entry(response).c_str()); std::fprintf(stdout, " invalid find_node request: %s\n", print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
return; return;
} }
@ -1765,7 +1765,7 @@ void test_bootstrap(address(&rand_addr)())
} }
else else
{ {
std::fprintf(stderr, " invalid find_node request: %s\n", print_entry(response).c_str()); std::fprintf(stdout, " invalid find_node request: %s\n", print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
return; return;
} }
@ -1836,7 +1836,7 @@ void test_short_nodes(address(&rand_addr)())
} }
else else
{ {
std::fprintf(stderr, " invalid find_node request: %s\n", print_entry(response).c_str()); std::fprintf(stdout, " invalid find_node request: %s\n", print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
return; return;
} }
@ -1921,7 +1921,7 @@ void test_get_peers(address(&rand_addr)())
} }
else else
{ {
std::fprintf(stderr, " invalid get_peers request: %s\n", print_entry(response).c_str()); std::fprintf(stdout, " invalid get_peers request: %s\n", print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
return; return;
} }
@ -1964,7 +1964,7 @@ void test_get_peers(address(&rand_addr)())
} }
else else
{ {
std::fprintf(stderr, " invalid get_peers request: %s\n", print_entry(response).c_str()); std::fprintf(stdout, " invalid get_peers request: %s\n", print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
return; return;
} }
@ -1980,7 +1980,7 @@ void test_get_peers(address(&rand_addr)())
for (std::list<std::pair<udp::endpoint, entry> >::iterator i = g_sent_packets.begin() for (std::list<std::pair<udp::endpoint, entry> >::iterator i = g_sent_packets.begin()
, end(g_sent_packets.end()); i != end; ++i) , end(g_sent_packets.end()); i != end; ++i)
{ {
// std::fprintf(stderr, " %s:%d: %s\n", i->first.address().to_string(ec).c_str() // std::fprintf(stdout, " %s:%d: %s\n", i->first.address().to_string(ec).c_str()
// , i->first.port(), i->second.to_string().c_str()); // , i->first.port(), i->second.to_string().c_str());
TEST_EQUAL(i->second["q"].string(), "announce_peer"); TEST_EQUAL(i->second["q"].string(), "announce_peer");
} }
@ -2064,7 +2064,7 @@ void test_mutable_get(address(&rand_addr)(), bool const with_salt)
} }
else else
{ {
std::fprintf(stderr, " invalid get request: %s\n", print_entry(response).c_str()); std::fprintf(stdout, " invalid get request: %s\n", print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
return; return;
} }
@ -2149,7 +2149,7 @@ TORRENT_TEST(immutable_get)
} }
else else
{ {
std::fprintf(stderr, " invalid get request: %s\n", print_entry(response).c_str()); std::fprintf(stdout, " invalid get request: %s\n", print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
return; return;
} }
@ -2221,7 +2221,7 @@ TORRENT_TEST(immutable_put)
bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string); bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string);
if (!ret) if (!ret)
{ {
std::fprintf(stderr, " invalid get request: %s\n", print_entry(response).c_str()); std::fprintf(stdout, " invalid get request: %s\n", print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
continue; continue;
} }
@ -2264,7 +2264,7 @@ TORRENT_TEST(immutable_put)
} }
else else
{ {
std::fprintf(stderr, " invalid immutable put request: %s\n", print_entry(response).c_str()); std::fprintf(stdout, " invalid immutable put request: %s\n", print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
continue; continue;
} }
@ -2322,7 +2322,7 @@ TORRENT_TEST(mutable_put)
bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string); bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string);
if (!ret) if (!ret)
{ {
std::fprintf(stderr, " invalid get request: %s\n", print_entry(response).c_str()); std::fprintf(stdout, " invalid get request: %s\n", print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
continue; continue;
} }
@ -2369,7 +2369,7 @@ TORRENT_TEST(mutable_put)
} }
else else
{ {
std::fprintf(stderr, " invalid put request: %s\n", print_entry(response).c_str()); std::fprintf(stdout, " invalid put request: %s\n", print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
continue; continue;
} }
@ -2437,7 +2437,7 @@ TORRENT_TEST(traversal_done)
bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string); bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string);
if (!ret) if (!ret)
{ {
std::fprintf(stderr, " invalid get request: %s\n", print_entry(response).c_str()); std::fprintf(stdout, " invalid get request: %s\n", print_entry(response).c_str());
TEST_ERROR(t.error_string); TEST_ERROR(t.error_string);
continue; continue;
} }
@ -2521,7 +2521,7 @@ TORRENT_TEST(dht_dual_stack)
} }
else else
{ {
std::fprintf(stderr, "find_node response: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "find_node response: %s\n", print_entry(response).c_str());
TEST_ERROR(error_string); TEST_ERROR(error_string);
} }
@ -2553,7 +2553,7 @@ TORRENT_TEST(dht_dual_stack)
} }
else else
{ {
std::fprintf(stderr, "find_node response: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "find_node response: %s\n", print_entry(response).c_str());
TEST_ERROR(error_string); TEST_ERROR(error_string);
} }
@ -2592,7 +2592,7 @@ TORRENT_TEST(dht_dual_stack)
} }
else else
{ {
std::fprintf(stderr, "find_node response: %s\n", print_entry(response).c_str()); std::fprintf(stdout, "find_node response: %s\n", print_entry(response).c_str());
TEST_ERROR(error_string); TEST_ERROR(error_string);
} }
} }
@ -2680,7 +2680,7 @@ TORRENT_TEST(verify_message)
error_code ec; error_code ec;
char const test_msg[] = "d1:A4:test1:Bd2:B15:test22:B25:test3ee"; char const test_msg[] = "d1:A4:test1:Bd2:B15:test22:B25:test3ee";
bdecode(test_msg, test_msg + sizeof(test_msg)-1, ent, ec); bdecode(test_msg, test_msg + sizeof(test_msg)-1, ent, ec);
std::fprintf(stderr, "%s\n", print_entry(ent).c_str()); std::fprintf(stdout, "%s\n", print_entry(ent).c_str());
bool ret = verify_message(ent, msg_desc, msg_keys, error_string); bool ret = verify_message(ent, msg_desc, msg_keys, error_string);
TEST_CHECK(ret); TEST_CHECK(ret);
@ -2697,7 +2697,7 @@ TORRENT_TEST(verify_message)
char const test_msg2[] = "d1:A4:test1:Cd2:C15:test22:C25:test3ee"; char const test_msg2[] = "d1:A4:test1:Cd2:C15:test22:C25:test3ee";
bdecode(test_msg2, test_msg2 + sizeof(test_msg2)-1, ent, ec); bdecode(test_msg2, test_msg2 + sizeof(test_msg2)-1, ent, ec);
std::fprintf(stderr, "%s\n", print_entry(ent).c_str()); std::fprintf(stdout, "%s\n", print_entry(ent).c_str());
ret = verify_message(ent, msg_desc, msg_keys, error_string); ret = verify_message(ent, msg_desc, msg_keys, error_string);
TEST_CHECK(ret); TEST_CHECK(ret);
@ -2715,35 +2715,35 @@ TORRENT_TEST(verify_message)
char const test_msg3[] = "d1:Cd2:C15:test22:C25:test3ee"; char const test_msg3[] = "d1:Cd2:C15:test22:C25:test3ee";
bdecode(test_msg3, test_msg3 + sizeof(test_msg3)-1, ent, ec); bdecode(test_msg3, test_msg3 + sizeof(test_msg3)-1, ent, ec);
std::fprintf(stderr, "%s\n", print_entry(ent).c_str()); std::fprintf(stdout, "%s\n", print_entry(ent).c_str());
ret = verify_message(ent, msg_desc, msg_keys, error_string); ret = verify_message(ent, msg_desc, msg_keys, error_string);
TEST_CHECK(!ret); TEST_CHECK(!ret);
std::fprintf(stderr, "%s\n", error_string); std::fprintf(stdout, "%s\n", error_string);
TEST_EQUAL(error_string, std::string("missing 'A' key")); TEST_EQUAL(error_string, std::string("missing 'A' key"));
char const test_msg4[] = "d1:A6:foobare"; char const test_msg4[] = "d1:A6:foobare";
bdecode(test_msg4, test_msg4 + sizeof(test_msg4)-1, ent, ec); bdecode(test_msg4, test_msg4 + sizeof(test_msg4)-1, ent, ec);
std::fprintf(stderr, "%s\n", print_entry(ent).c_str()); std::fprintf(stdout, "%s\n", print_entry(ent).c_str());
ret = verify_message(ent, msg_desc, msg_keys, error_string); ret = verify_message(ent, msg_desc, msg_keys, error_string);
TEST_CHECK(!ret); TEST_CHECK(!ret);
std::fprintf(stderr, "%s\n", error_string); std::fprintf(stdout, "%s\n", error_string);
TEST_EQUAL(error_string, std::string("invalid value for 'A'")); TEST_EQUAL(error_string, std::string("invalid value for 'A'"));
char const test_msg5[] = "d1:A4:test1:Cd2:C15:test2ee"; char const test_msg5[] = "d1:A4:test1:Cd2:C15:test2ee";
bdecode(test_msg5, test_msg5 + sizeof(test_msg5)-1, ent, ec); bdecode(test_msg5, test_msg5 + sizeof(test_msg5)-1, ent, ec);
std::fprintf(stderr, "%s\n", print_entry(ent).c_str()); std::fprintf(stdout, "%s\n", print_entry(ent).c_str());
ret = verify_message(ent, msg_desc, msg_keys, error_string); ret = verify_message(ent, msg_desc, msg_keys, error_string);
TEST_CHECK(!ret); TEST_CHECK(!ret);
std::fprintf(stderr, "%s\n", error_string); std::fprintf(stdout, "%s\n", error_string);
TEST_EQUAL(error_string, std::string("missing 'C2' key")); TEST_EQUAL(error_string, std::string("missing 'C2' key"));
// test empty strings [ { "":1 }, "" ] // test empty strings [ { "":1 }, "" ]
char const test_msg6[] = "ld0:i1ee0:e"; char const test_msg6[] = "ld0:i1ee0:e";
bdecode(test_msg6, test_msg6 + sizeof(test_msg6)-1, ent, ec); bdecode(test_msg6, test_msg6 + sizeof(test_msg6)-1, ent, ec);
std::fprintf(stderr, "%s\n", print_entry(ent).c_str()); std::fprintf(stdout, "%s\n", print_entry(ent).c_str());
TEST_CHECK(ent.type() == bdecode_node::list_t); TEST_CHECK(ent.type() == bdecode_node::list_t);
if (ent.type() == bdecode_node::list_t) if (ent.type() == bdecode_node::list_t)
{ {
@ -3040,7 +3040,7 @@ TORRENT_TEST(invalid_error_msg)
bdecode_node decoded; bdecode_node decoded;
error_code ec; error_code ec;
bdecode(msg_buf, msg_buf + size, decoded, ec); bdecode(msg_buf, msg_buf + size, decoded, ec);
if (ec) std::fprintf(stderr, "bdecode failed: %s\n", ec.message().c_str()); if (ec) std::fprintf(stdout, "bdecode failed: %s\n", ec.message().c_str());
dht::msg m(decoded, source); dht::msg m(decoded, source);
node.incoming(m); node.incoming(m);
@ -3102,7 +3102,7 @@ TORRENT_TEST(rpc_invalid_error_msg)
bdecode_node decoded; bdecode_node decoded;
error_code ec; error_code ec;
bdecode(msg_buf, msg_buf + size, decoded, ec); bdecode(msg_buf, msg_buf + size, decoded, ec);
if (ec) std::fprintf(stderr, "bdecode failed: %s\n", ec.message().c_str()); if (ec) std::fprintf(stdout, "bdecode failed: %s\n", ec.message().c_str());
dht::msg m(decoded, source); dht::msg m(decoded, source);
node_id nid; node_id nid;
@ -3281,7 +3281,7 @@ TORRENT_TEST(distance_exp)
for (auto const& t : distance_tests) for (auto const& t : distance_tests)
{ {
std::fprintf(stderr, "%s %s: %d\n" std::fprintf(stdout, "%s %s: %d\n"
, std::get<0>(t), std::get<1>(t), std::get<2>(t)); , std::get<0>(t), std::get<1>(t), std::get<2>(t));
TEST_EQUAL(distance_exp( TEST_EQUAL(distance_exp(
@ -3307,7 +3307,7 @@ TORRENT_TEST(compare_ip_cidr)
for (auto const& t : v4tests) for (auto const& t : v4tests)
{ {
std::fprintf(stderr, "%s %s\n", std::get<0>(t), std::get<1>(t)); std::fprintf(stdout, "%s %s\n", std::get<0>(t), std::get<1>(t));
TEST_EQUAL(compare_ip_cidr( TEST_EQUAL(compare_ip_cidr(
addr4(std::get<0>(t)), addr4(std::get<1>(t))), std::get<2>(t)); addr4(std::get<0>(t)), addr4(std::get<1>(t))), std::get<2>(t));
} }

View File

@ -99,7 +99,7 @@ TORRENT_TEST(file_status)
TEST_CHECK(!ec); TEST_CHECK(!ec);
int diff = int(st2.mtime - st1.mtime); int diff = int(st2.mtime - st1.mtime);
std::fprintf(stderr, "timestamp difference: %d seconds. expected approx. 3 seconds\n" std::fprintf(stdout, "timestamp difference: %d seconds. expected approx. 3 seconds\n"
, diff); , diff);
TEST_CHECK(diff >= 2 && diff <= 4); TEST_CHECK(diff >= 2 && diff <= 4);
@ -110,7 +110,7 @@ TORRENT_TEST(directory)
error_code ec; error_code ec;
create_directory("file_test_dir", ec); create_directory("file_test_dir", ec);
if (ec) std::fprintf(stderr, "create_directory: %s\n", ec.message().c_str()); if (ec) std::fprintf(stdout, "create_directory: %s\n", ec.message().c_str());
TEST_CHECK(!ec); TEST_CHECK(!ec);
std::string cwd = current_working_directory(); std::string cwd = current_working_directory();
@ -125,7 +125,7 @@ TORRENT_TEST(directory)
std::string f = i.file(); std::string f = i.file();
TEST_CHECK(files.count(f) == 0); TEST_CHECK(files.count(f) == 0);
files.insert(f); files.insert(f);
std::fprintf(stderr, " %s\n", f.c_str()); std::fprintf(stdout, " %s\n", f.c_str());
} }
TEST_CHECK(files.count("abc") == 1); TEST_CHECK(files.count("abc") == 1);
@ -142,13 +142,13 @@ TORRENT_TEST(directory)
std::string f = i.file(); std::string f = i.file();
TEST_CHECK(files.count(f) == 0); TEST_CHECK(files.count(f) == 0);
files.insert(f); files.insert(f);
std::fprintf(stderr, " %s\n", f.c_str()); std::fprintf(stdout, " %s\n", f.c_str());
} }
remove_all("file_test_dir", ec); remove_all("file_test_dir", ec);
if (ec) std::fprintf(stderr, "remove_all: %s\n", ec.message().c_str()); if (ec) std::fprintf(stdout, "remove_all: %s\n", ec.message().c_str());
remove_all("file_test_dir2", ec); remove_all("file_test_dir2", ec);
if (ec) std::fprintf(stderr, "remove_all: %s\n", ec.message().c_str()); if (ec) std::fprintf(stdout, "remove_all: %s\n", ec.message().c_str());
} }
// test path functions // test path functions
@ -291,20 +291,20 @@ TORRENT_TEST(file)
TEST_CHECK(f.open("test_file", file::read_write, ec)); TEST_CHECK(f.open("test_file", file::read_write, ec));
#endif #endif
if (ec) if (ec)
std::fprintf(stderr, "open failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); std::fprintf(stdout, "open failed: [%s] %s\n", ec.category().name(), ec.message().c_str());
TEST_EQUAL(ec, error_code()); TEST_EQUAL(ec, error_code());
if (ec) std::fprintf(stderr, "%s\n", ec.message().c_str()); if (ec) std::fprintf(stdout, "%s\n", ec.message().c_str());
file::iovec_t b = {(void*)"test", 4}; file::iovec_t b = {(void*)"test", 4};
TEST_EQUAL(f.writev(0, &b, 1, ec), 4); TEST_EQUAL(f.writev(0, &b, 1, ec), 4);
if (ec) if (ec)
std::fprintf(stderr, "writev failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); std::fprintf(stdout, "writev failed: [%s] %s\n", ec.category().name(), ec.message().c_str());
TEST_CHECK(!ec); TEST_CHECK(!ec);
char test_buf[5] = {0}; char test_buf[5] = {0};
b.iov_base = test_buf; b.iov_base = test_buf;
b.iov_len = 4; b.iov_len = 4;
TEST_EQUAL(f.readv(0, &b, 1, ec), 4); TEST_EQUAL(f.readv(0, &b, 1, ec), 4);
if (ec) if (ec)
std::fprintf(stderr, "readv failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); std::fprintf(stdout, "readv failed: [%s] %s\n", ec.category().name(), ec.message().c_str());
TEST_EQUAL(ec, error_code()); TEST_EQUAL(ec, error_code());
TEST_CHECK(std::strcmp(test_buf, "test") == 0); TEST_CHECK(std::strcmp(test_buf, "test") == 0);
f.close(); f.close();
@ -321,26 +321,26 @@ TORRENT_TEST(hard_link)
file f; file f;
TEST_CHECK(f.open("original_file", file::read_write, ec)); TEST_CHECK(f.open("original_file", file::read_write, ec));
if (ec) if (ec)
std::fprintf(stderr, "open failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); std::fprintf(stdout, "open failed: [%s] %s\n", ec.category().name(), ec.message().c_str());
TEST_EQUAL(ec, error_code()); TEST_EQUAL(ec, error_code());
file::iovec_t b = {(void*)"abcdefghijklmnopqrstuvwxyz", 26}; file::iovec_t b = {(void*)"abcdefghijklmnopqrstuvwxyz", 26};
TEST_EQUAL(f.writev(0, &b, 1, ec), 26); TEST_EQUAL(f.writev(0, &b, 1, ec), 26);
if (ec) if (ec)
std::fprintf(stderr, "writev failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); std::fprintf(stdout, "writev failed: [%s] %s\n", ec.category().name(), ec.message().c_str());
TEST_EQUAL(ec, error_code()); TEST_EQUAL(ec, error_code());
f.close(); f.close();
hard_link("original_file", "second_link", ec); hard_link("original_file", "second_link", ec);
if (ec) if (ec)
std::fprintf(stderr, "hard_link failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); std::fprintf(stdout, "hard_link failed: [%s] %s\n", ec.category().name(), ec.message().c_str());
TEST_EQUAL(ec, error_code()); TEST_EQUAL(ec, error_code());
TEST_CHECK(f.open("second_link", file::read_write, ec)); TEST_CHECK(f.open("second_link", file::read_write, ec));
if (ec) if (ec)
std::fprintf(stderr, "open failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); std::fprintf(stdout, "open failed: [%s] %s\n", ec.category().name(), ec.message().c_str());
TEST_EQUAL(ec, error_code()); TEST_EQUAL(ec, error_code());
char test_buf[27] = {0}; char test_buf[27] = {0};
@ -348,18 +348,18 @@ TORRENT_TEST(hard_link)
b.iov_len = 27; b.iov_len = 27;
TEST_EQUAL(f.readv(0, &b, 1, ec), 26); TEST_EQUAL(f.readv(0, &b, 1, ec), 26);
if (ec) if (ec)
std::fprintf(stderr, "readv failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); std::fprintf(stdout, "readv failed: [%s] %s\n", ec.category().name(), ec.message().c_str());
TEST_EQUAL(ec, error_code()); TEST_EQUAL(ec, error_code());
TEST_CHECK(std::strcmp(test_buf, "abcdefghijklmnopqrstuvwxyz") == 0); TEST_CHECK(std::strcmp(test_buf, "abcdefghijklmnopqrstuvwxyz") == 0);
f.close(); f.close();
remove("original_file", ec); remove("original_file", ec);
if (ec) if (ec)
std::fprintf(stderr, "remove failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); std::fprintf(stdout, "remove failed: [%s] %s\n", ec.category().name(), ec.message().c_str());
remove("second_link", ec); remove("second_link", ec);
if (ec) if (ec)
std::fprintf(stderr, "remove failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); std::fprintf(stdout, "remove failed: [%s] %s\n", ec.category().name(), ec.message().c_str());
} }
TORRENT_TEST(coalesce_buffer) TORRENT_TEST(coalesce_buffer)
@ -368,13 +368,13 @@ TORRENT_TEST(coalesce_buffer)
file f; file f;
TEST_CHECK(f.open("test_file", file::read_write, ec)); TEST_CHECK(f.open("test_file", file::read_write, ec));
if (ec) if (ec)
std::fprintf(stderr, "open failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); std::fprintf(stdout, "open failed: [%s] %s\n", ec.category().name(), ec.message().c_str());
TEST_EQUAL(ec, error_code()); TEST_EQUAL(ec, error_code());
if (ec) std::fprintf(stderr, "%s\n", ec.message().c_str()); if (ec) std::fprintf(stdout, "%s\n", ec.message().c_str());
file::iovec_t b[2] = {{(void*)"test", 4}, {(void*)"foobar", 6}}; file::iovec_t b[2] = {{(void*)"test", 4}, {(void*)"foobar", 6}};
TEST_EQUAL(f.writev(0, b, 2, ec, file::coalesce_buffers), 4 + 6); TEST_EQUAL(f.writev(0, b, 2, ec, file::coalesce_buffers), 4 + 6);
if (ec) if (ec)
std::fprintf(stderr, "writev failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); std::fprintf(stdout, "writev failed: [%s] %s\n", ec.category().name(), ec.message().c_str());
TEST_CHECK(!ec); TEST_CHECK(!ec);
char test_buf1[5] = {0}; char test_buf1[5] = {0};
char test_buf2[7] = {0}; char test_buf2[7] = {0};
@ -385,7 +385,7 @@ TORRENT_TEST(coalesce_buffer)
TEST_EQUAL(f.readv(0, b, 2, ec), 4 + 6); TEST_EQUAL(f.readv(0, b, 2, ec), 4 + 6);
if (ec) if (ec)
{ {
std::fprintf(stderr, "readv failed: [%s] %s\n" std::fprintf(stdout, "readv failed: [%s] %s\n"
, ec.category().name(), ec.message().c_str()); , ec.category().name(), ec.message().c_str());
} }
TEST_EQUAL(ec, error_code()); TEST_EQUAL(ec, error_code());

View File

@ -64,7 +64,7 @@ TORRENT_TEST(corrupt)
std::vector<char> zipped; std::vector<char> zipped;
error_code ec; error_code ec;
load_file(combine_path("..", "corrupt.gz"), zipped, ec, 1000000); load_file(combine_path("..", "corrupt.gz"), zipped, ec, 1000000);
if (ec) fprintf(stderr, "failed to open file: (%d) %s\n", ec.value() if (ec) std::fprintf(stderr, "failed to open file: (%d) %s\n", ec.value()
, ec.message().c_str()); , ec.message().c_str());
TEST_CHECK(!ec); TEST_CHECK(!ec);

View File

@ -57,12 +57,12 @@ char data_buffer[4000];
void print_http_header(http_parser const& p) void print_http_header(http_parser const& p)
{ {
std::cerr << time_now_string() << " < " << p.status_code() << " " << p.message() << std::endl; std::cout << time_now_string() << " < " << p.status_code() << " " << p.message() << std::endl;
for (std::multimap<std::string, std::string>::const_iterator i for (std::multimap<std::string, std::string>::const_iterator i
= p.headers().begin(), end(p.headers().end()); i != end; ++i) = p.headers().begin(), end(p.headers().end()); i != end; ++i)
{ {
std::cerr << time_now_string() << " < " << i->first << ": " << i->second << std::endl; std::cout << time_now_string() << " < " << i->first << ": " << i->second << std::endl;
} }
} }
@ -71,7 +71,7 @@ void http_connect_handler(http_connection& c)
++connect_handler_called; ++connect_handler_called;
TEST_CHECK(c.socket().is_open()); TEST_CHECK(c.socket().is_open());
error_code ec; error_code ec;
std::cerr << time_now_string() << " connected to: " << print_endpoint(c.socket().remote_endpoint(ec)) std::cout << time_now_string() << " connected to: " << print_endpoint(c.socket().remote_endpoint(ec))
<< std::endl; << std::endl;
// this is not necessarily true when using a proxy and proxying hostnames // this is not necessarily true when using a proxy and proxying hostnames
// TEST_CHECK(c.socket().remote_endpoint(ec).address() == address::from_string("127.0.0.1", ec)); // TEST_CHECK(c.socket().remote_endpoint(ec).address() == address::from_string("127.0.0.1", ec));
@ -111,9 +111,9 @@ void run_test(std::string const& url, int size, int status, int connected
{ {
reset_globals(); reset_globals();
std::cerr << " ===== TESTING: " << url << " =====" << std::endl; std::cout << " ===== TESTING: " << url << " =====" << std::endl;
std::cerr << time_now_string() std::cout << time_now_string()
<< " expecting: size: " << size << " expecting: size: " << size
<< " status: " << status << " status: " << status
<< " connected: " << connected << " connected: " << connected
@ -126,14 +126,14 @@ void run_test(std::string const& url, int size, int status, int connected
ios.reset(); ios.reset();
error_code e; error_code e;
ios.run(e); ios.run(e);
if (e) std::cerr << time_now_string() << " run failed: " << e.message() << std::endl; if (e) std::cout << time_now_string() << " run failed: " << e.message() << std::endl;
std::cerr << time_now_string() << " connect_handler_called: " << connect_handler_called << std::endl; std::cout << time_now_string() << " connect_handler_called: " << connect_handler_called << std::endl;
std::cerr << time_now_string() << " handler_called: " << handler_called << std::endl; std::cout << time_now_string() << " handler_called: " << handler_called << std::endl;
std::cerr << time_now_string() << " status: " << http_status << std::endl; std::cout << time_now_string() << " status: " << http_status << std::endl;
std::cerr << time_now_string() << " size: " << data_size << std::endl; std::cout << time_now_string() << " size: " << data_size << std::endl;
std::cerr << time_now_string() << " expected-size: " << size << std::endl; std::cout << time_now_string() << " expected-size: " << size << std::endl;
std::cerr << time_now_string() << " error_code: " << g_error_code.message() << std::endl; std::cout << time_now_string() << " error_code: " << g_error_code.message() << std::endl;
TEST_CHECK(connect_handler_called == connected); TEST_CHECK(connect_handler_called == connected);
TEST_CHECK(handler_called == 1); TEST_CHECK(handler_called == 1);
TEST_CHECK(data_size == size || size == -1); TEST_CHECK(data_size == size || size == -1);
@ -148,11 +148,11 @@ void write_test_file()
error_code ec; error_code ec;
file test_file("test_file", file::write_only, ec); file test_file("test_file", file::write_only, ec);
TEST_CHECK(!ec); TEST_CHECK(!ec);
if (ec) std::fprintf(stderr, "file error: %s\n", ec.message().c_str()); if (ec) std::fprintf(stdout, "file error: %s\n", ec.message().c_str());
file::iovec_t b = { data_buffer, 3216}; file::iovec_t b = { data_buffer, 3216};
test_file.writev(0, &b, 1, ec); test_file.writev(0, &b, 1, ec);
TEST_CHECK(!ec); TEST_CHECK(!ec);
if (ec) std::fprintf(stderr, "file error: %s\n", ec.message().c_str()); if (ec) std::fprintf(stdout, "file error: %s\n", ec.message().c_str());
test_file.close(); test_file.close();
} }

View File

@ -45,12 +45,12 @@ using namespace libtorrent;
bool cast_vote(ip_voter& ipv, address ext_ip, address voter) bool cast_vote(ip_voter& ipv, address ext_ip, address voter)
{ {
bool new_ip = ipv.cast_vote(ext_ip, 1, voter); bool new_ip = ipv.cast_vote(ext_ip, 1, voter);
std::fprintf(stderr, "%15s -> %-15s\n" std::fprintf(stdout, "%15s -> %-15s\n"
, print_address(voter).c_str() , print_address(voter).c_str()
, print_address(ext_ip).c_str()); , print_address(ext_ip).c_str());
if (new_ip) if (new_ip)
{ {
std::fprintf(stderr, " \x1b[1mnew external IP: %s\x1b[0m\n" std::fprintf(stdout, " \x1b[1mnew external IP: %s\x1b[0m\n"
, print_address(ipv.external_address()).c_str()); , print_address(ipv.external_address()).c_str());
} }
return new_ip; return new_ip;

View File

@ -92,12 +92,12 @@ TORRENT_TEST(insert)
{ {
int index = (i + 0xfff0) & 0xffff; int index = (i + 0xfff0) & 0xffff;
pb.insert(index, reinterpret_cast<int*>(size_t(index) + 1)); pb.insert(index, reinterpret_cast<int*>(size_t(index) + 1));
std::fprintf(stderr, "insert: %u (mask: %x)\n", index, int(pb.capacity() - 1)); std::fprintf(stdout, "insert: %u (mask: %x)\n", index, int(pb.capacity() - 1));
TEST_EQUAL(pb.capacity(), 512); TEST_EQUAL(pb.capacity(), 512);
if (i >= 14) if (i >= 14)
{ {
index = (index - 14) & 0xffff; index = (index - 14) & 0xffff;
std::fprintf(stderr, "remove: %u\n", index); std::fprintf(stdout, "remove: %u\n", index);
TEST_CHECK(pb.remove(index) == reinterpret_cast<int*>(size_t(index) + 1)); TEST_CHECK(pb.remove(index) == reinterpret_cast<int*>(size_t(index) + 1));
TEST_EQUAL(pb.size(), 14); TEST_EQUAL(pb.size(), 14);
} }

View File

@ -226,7 +226,7 @@ bool verify_pick(std::shared_ptr<piece_picker> p
std::set<piece_block> blocks; std::set<piece_block> blocks;
std::copy(picked.begin(), picked.end() std::copy(picked.begin(), picked.end()
, std::insert_iterator<std::set<piece_block> >(blocks, blocks.end())); , std::insert_iterator<std::set<piece_block> >(blocks, blocks.end()));
std::cerr << " verify: " << picked.size() << " " << blocks.size() << std::endl; std::cout << " verify: " << picked.size() << " " << blocks.size() << std::endl;
return picked.size() == blocks.size(); return picked.size() == blocks.size();
} }
@ -443,12 +443,12 @@ TORRENT_TEST(get_downloaders)
p->mark_as_downloading(piece_block(0, 0), &tmp2); p->mark_as_downloading(piece_block(0, 0), &tmp2);
std::fprintf(stderr, "num_peers: %d\n", p->num_peers(piece_block(0, 0))); std::fprintf(stdout, "num_peers: %d\n", p->num_peers(piece_block(0, 0)));
TEST_EQUAL(p->num_peers(piece_block(0, 0)), 2); TEST_EQUAL(p->num_peers(piece_block(0, 0)), 2);
p->abort_download(piece_block(0, 0), &tmp1); p->abort_download(piece_block(0, 0), &tmp1);
std::fprintf(stderr, "num_peers: %d\n", p->num_peers(piece_block(0, 0))); std::fprintf(stdout, "num_peers: %d\n", p->num_peers(piece_block(0, 0)));
TEST_EQUAL(p->num_peers(piece_block(0, 0)), 1); TEST_EQUAL(p->num_peers(piece_block(0, 0)), 1);
} }

View File

@ -71,9 +71,9 @@ TORRENT_TEST(primitives)
int delay = ae.next_announce_in(); int delay = ae.next_announce_in();
TEST_CHECK(delay > last); TEST_CHECK(delay > last);
last = delay; last = delay;
std::fprintf(stderr, "%d, ", delay); std::fprintf(stdout, "%d, ", delay);
} }
std::fprintf(stderr, "\n"); std::fprintf(stdout, "\n");
// test error codes // test error codes
TEST_CHECK(error_code(errors::http_error).message() == "HTTP error"); TEST_CHECK(error_code(errors::http_error).message() == "HTTP error");
@ -86,7 +86,7 @@ TORRENT_TEST(primitives)
TEST_CHECK(error_code(errors::unauthorized, http_category()).message() == "401 Unauthorized"); TEST_CHECK(error_code(errors::unauthorized, http_category()).message() == "401 Unauthorized");
TEST_CHECK(error_code(errors::service_unavailable, http_category()).message() == "503 Service Unavailable"); TEST_CHECK(error_code(errors::service_unavailable, http_category()).message() == "503 Service Unavailable");
// test snprintf // test std::snprintf
char msg[10]; char msg[10];
std::snprintf(msg, sizeof(msg), "too %s format string", "long"); std::snprintf(msg, sizeof(msg), "too %s format string", "long");

View File

@ -169,7 +169,7 @@ void test_remap_files(storage_mode_t storage_mode = storage_mode_sparse)
print_alerts(ses, "ses"); print_alerts(ses, "ses");
} }
fprintf(stderr, "%s\n", name.c_str()); std::fprintf(stderr, "%s\n", name.c_str());
TEST_CHECK(exists(name)); TEST_CHECK(exists(name));
} }

View File

@ -99,14 +99,14 @@ TORRENT_TEST(resolve_links)
test_torrent_t const& e = test_torrents[i]; test_torrent_t const& e = test_torrents[i];
std::string p = combine_path(path, e.filename1) + ".torrent"; std::string p = combine_path(path, e.filename1) + ".torrent";
std::fprintf(stderr, "loading %s\n", p.c_str()); std::fprintf(stdout, "loading %s\n", p.c_str());
std::shared_ptr<torrent_info> ti1 = std::make_shared<torrent_info>(p); std::shared_ptr<torrent_info> ti1 = std::make_shared<torrent_info>(p);
p = combine_path(path, e.filename2) + ".torrent"; p = combine_path(path, e.filename2) + ".torrent";
std::fprintf(stderr, "loading %s\n", p.c_str()); std::fprintf(stdout, "loading %s\n", p.c_str());
std::shared_ptr<torrent_info> ti2 = std::make_shared<torrent_info>(p); std::shared_ptr<torrent_info> ti2 = std::make_shared<torrent_info>(p);
std::fprintf(stderr, "resolving\n"); std::fprintf(stdout, "resolving\n");
resolve_links l(ti1); resolve_links l(ti1);
l.match(ti2, "."); l.match(ti2, ".");
@ -122,7 +122,7 @@ TORRENT_TEST(resolve_links)
for (int i = 0; i < int(links.size()); ++i) for (int i = 0; i < int(links.size()); ++i)
{ {
TORRENT_ASSERT(i < fs.num_files()); TORRENT_ASSERT(i < fs.num_files());
std::fprintf(stderr, "%*s --> %s : %d\n" std::fprintf(stdout, "%*s --> %s : %d\n"
, int(fs.file_name(i).size()) , int(fs.file_name(i).size())
, fs.file_name(i).data() , fs.file_name(i).data()
, links[i].ti ? aux::to_hex(links[i].ti->info_hash()).c_str() , links[i].ti ? aux::to_hex(links[i].ti->info_hash()).c_str()

View File

@ -45,11 +45,11 @@ using namespace libtorrent;
void fun(std::condition_variable* s, std::mutex* m, int* waiting, int i) void fun(std::condition_variable* s, std::mutex* m, int* waiting, int i)
{ {
std::fprintf(stderr, "thread %d waiting\n", i); std::fprintf(stdout, "thread %d waiting\n", i);
std::unique_lock<std::mutex> l(*m); std::unique_lock<std::mutex> l(*m);
*waiting += 1; *waiting += 1;
s->wait(l); s->wait(l);
std::fprintf(stderr, "thread %d done\n", i); std::fprintf(stdout, "thread %d done\n", i);
} }
void increment(std::condition_variable* s, std::mutex* m, int* waiting, std::atomic<int>* c) void increment(std::condition_variable* s, std::mutex* m, int* waiting, std::atomic<int>* c)

View File

@ -73,7 +73,7 @@ void test_running_torrent(std::shared_ptr<torrent_info> info, std::int64_t file_
torrent_handle h = ses.add_torrent(p, ec); torrent_handle h = ses.add_torrent(p, ec);
if (ec) if (ec)
{ {
std::fprintf(stderr, "add_torrent: %s\n", ec.message().c_str()); std::fprintf(stdout, "add_torrent: %s\n", ec.message().c_str());
return; return;
} }

View File

@ -495,70 +495,70 @@ TORRENT_TEST(verify_encoding)
// valid 2-byte sequence // valid 2-byte sequence
test = "filename\xc2\xa1"; test = "filename\xc2\xa1";
TEST_CHECK(verify_encoding(test)); TEST_CHECK(verify_encoding(test));
std::fprintf(stderr, "%s\n", test.c_str()); std::fprintf(stdout, "%s\n", test.c_str());
TEST_CHECK(test == "filename\xc2\xa1"); TEST_CHECK(test == "filename\xc2\xa1");
// truncated 2-byte sequence // truncated 2-byte sequence
test = "filename\xc2"; test = "filename\xc2";
TEST_CHECK(!verify_encoding(test)); TEST_CHECK(!verify_encoding(test));
std::fprintf(stderr, "%s\n", test.c_str()); std::fprintf(stdout, "%s\n", test.c_str());
TEST_CHECK(test == "filename_"); TEST_CHECK(test == "filename_");
// valid 3-byte sequence // valid 3-byte sequence
test = "filename\xe2\x9f\xb9"; test = "filename\xe2\x9f\xb9";
TEST_CHECK(verify_encoding(test)); TEST_CHECK(verify_encoding(test));
std::fprintf(stderr, "%s\n", test.c_str()); std::fprintf(stdout, "%s\n", test.c_str());
TEST_CHECK(test == "filename\xe2\x9f\xb9"); TEST_CHECK(test == "filename\xe2\x9f\xb9");
// truncated 3-byte sequence // truncated 3-byte sequence
test = "filename\xe2\x9f"; test = "filename\xe2\x9f";
TEST_CHECK(!verify_encoding(test)); TEST_CHECK(!verify_encoding(test));
std::fprintf(stderr, "%s\n", test.c_str()); std::fprintf(stdout, "%s\n", test.c_str());
TEST_CHECK(test == "filename_"); TEST_CHECK(test == "filename_");
// truncated 3-byte sequence // truncated 3-byte sequence
test = "filename\xe2"; test = "filename\xe2";
TEST_CHECK(!verify_encoding(test)); TEST_CHECK(!verify_encoding(test));
std::fprintf(stderr, "%s\n", test.c_str()); std::fprintf(stdout, "%s\n", test.c_str());
TEST_CHECK(test == "filename_"); TEST_CHECK(test == "filename_");
// valid 4-byte sequence // valid 4-byte sequence
test = "filename\xf0\x9f\x92\x88"; test = "filename\xf0\x9f\x92\x88";
TEST_CHECK(verify_encoding(test)); TEST_CHECK(verify_encoding(test));
std::fprintf(stderr, "%s\n", test.c_str()); std::fprintf(stdout, "%s\n", test.c_str());
TEST_CHECK(test == "filename\xf0\x9f\x92\x88"); TEST_CHECK(test == "filename\xf0\x9f\x92\x88");
// truncated 4-byte sequence // truncated 4-byte sequence
test = "filename\xf0\x9f\x92"; test = "filename\xf0\x9f\x92";
TEST_CHECK(!verify_encoding(test)); TEST_CHECK(!verify_encoding(test));
std::fprintf(stderr, "%s\n", test.c_str()); std::fprintf(stdout, "%s\n", test.c_str());
TEST_CHECK(test == "filename_"); TEST_CHECK(test == "filename_");
// 5-byte utf-8 sequence (not allowed) // 5-byte utf-8 sequence (not allowed)
test = "filename\xf8\x9f\x9f\x9f\x9f""foobar"; test = "filename\xf8\x9f\x9f\x9f\x9f""foobar";
TEST_CHECK(!verify_encoding(test)); TEST_CHECK(!verify_encoding(test));
std::fprintf(stderr, "%s\n", test.c_str()); std::fprintf(stdout, "%s\n", test.c_str());
TEST_CHECK(test == "filename_____foobar"); TEST_CHECK(test == "filename_____foobar");
// redundant (overlong) 2-byte sequence // redundant (overlong) 2-byte sequence
// ascii code 0x2e encoded with a leading 0 // ascii code 0x2e encoded with a leading 0
test = "filename\xc0\xae"; test = "filename\xc0\xae";
TEST_CHECK(!verify_encoding(test)); TEST_CHECK(!verify_encoding(test));
std::fprintf(stderr, "%s\n", test.c_str()); std::fprintf(stdout, "%s\n", test.c_str());
TEST_CHECK(test == "filename__"); TEST_CHECK(test == "filename__");
// redundant (overlong) 3-byte sequence // redundant (overlong) 3-byte sequence
// ascii code 0x2e encoded with two leading 0s // ascii code 0x2e encoded with two leading 0s
test = "filename\xe0\x80\xae"; test = "filename\xe0\x80\xae";
TEST_CHECK(!verify_encoding(test)); TEST_CHECK(!verify_encoding(test));
std::fprintf(stderr, "%s\n", test.c_str()); std::fprintf(stdout, "%s\n", test.c_str());
TEST_CHECK(test == "filename___"); TEST_CHECK(test == "filename___");
// redundant (overlong) 4-byte sequence // redundant (overlong) 4-byte sequence
// ascii code 0x2e encoded with three leading 0s // ascii code 0x2e encoded with three leading 0s
test = "filename\xf0\x80\x80\xae"; test = "filename\xf0\x80\x80\xae";
TEST_CHECK(!verify_encoding(test)); TEST_CHECK(!verify_encoding(test));
std::fprintf(stderr, "%s\n", test.c_str()); std::fprintf(stdout, "%s\n", test.c_str());
TEST_CHECK(test == "filename____"); TEST_CHECK(test == "filename____");
} }
@ -610,12 +610,12 @@ TORRENT_TEST(parse_torrents)
std::string root_dir = parent_path(current_working_directory()); std::string root_dir = parent_path(current_working_directory());
for (int i = 0; i < int(sizeof(test_torrents)/sizeof(test_torrents[0])); ++i) for (int i = 0; i < int(sizeof(test_torrents)/sizeof(test_torrents[0])); ++i)
{ {
std::fprintf(stderr, "loading %s\n", test_torrents[i].file); std::fprintf(stdout, "loading %s\n", test_torrents[i].file);
std::string filename = combine_path(combine_path(root_dir, "test_torrents") std::string filename = combine_path(combine_path(root_dir, "test_torrents")
, test_torrents[i].file); , test_torrents[i].file);
auto ti = std::make_shared<torrent_info>(filename, ec); auto ti = std::make_shared<torrent_info>(filename, ec);
TEST_CHECK(!ec); TEST_CHECK(!ec);
if (ec) std::fprintf(stderr, " loading(\"%s\") -> failed %s\n", filename.c_str() if (ec) std::fprintf(stdout, " loading(\"%s\") -> failed %s\n", filename.c_str()
, ec.message().c_str()); , ec.message().c_str());
if (std::string(test_torrents[i].file) == "whitespace_url.torrent") if (std::string(test_torrents[i].file) == "whitespace_url.torrent")
@ -730,7 +730,7 @@ TORRENT_TEST(parse_torrents)
int const last = ti->map_file(i, (std::max)(fs.file_size(i)-1, std::int64_t(0)), 0).piece; int const last = ti->map_file(i, (std::max)(fs.file_size(i)-1, std::int64_t(0)), 0).piece;
int const flags = fs.file_flags(i); int const flags = fs.file_flags(i);
sha1_hash const ih = fs.hash(i); sha1_hash const ih = fs.hash(i);
std::fprintf(stderr, " %11" PRId64 " %c%c%c%c [ %4d, %4d ] %7u %s %s %s%s\n" std::fprintf(stdout, " %11" PRId64 " %c%c%c%c [ %4d, %4d ] %7u %s %s %s%s\n"
, fs.file_size(i) , fs.file_size(i)
, (flags & file_storage::flag_pad_file)?'p':'-' , (flags & file_storage::flag_pad_file)?'p':'-'
, (flags & file_storage::flag_executable)?'x':'-' , (flags & file_storage::flag_executable)?'x':'-'
@ -748,10 +748,10 @@ TORRENT_TEST(parse_torrents)
for (int i = 0; i < int(sizeof(test_error_torrents)/sizeof(test_error_torrents[0])); ++i) for (int i = 0; i < int(sizeof(test_error_torrents)/sizeof(test_error_torrents[0])); ++i)
{ {
error_code ec; error_code ec;
std::fprintf(stderr, "loading %s\n", test_error_torrents[i].file); std::fprintf(stdout, "loading %s\n", test_error_torrents[i].file);
auto ti = std::make_shared<torrent_info>(combine_path( auto ti = std::make_shared<torrent_info>(combine_path(
combine_path(root_dir, "test_torrents"), test_error_torrents[i].file), ec); combine_path(root_dir, "test_torrents"), test_error_torrents[i].file), ec);
std::fprintf(stderr, "E: \"%s\"\nexpected: \"%s\"\n", ec.message().c_str() std::fprintf(stdout, "E: \"%s\"\nexpected: \"%s\"\n", ec.message().c_str()
, test_error_torrents[i].error.message().c_str()); , test_error_torrents[i].error.message().c_str());
TEST_CHECK(ec.message() == test_error_torrents[i].error.message()); TEST_CHECK(ec.message() == test_error_torrents[i].error.message());
} }
@ -840,7 +840,7 @@ void test_resolve_duplicates(int test_case)
{ {
std::string p = ti.files().file_path(i); std::string p = ti.files().file_path(i);
convert_path_to_posix(p); convert_path_to_posix(p);
std::fprintf(stderr, "%s == %s\n", p.c_str(), filenames[test_case][i]); std::fprintf(stdout, "%s == %s\n", p.c_str(), filenames[test_case][i]);
TEST_EQUAL(p, filenames[test_case][i]); TEST_EQUAL(p, filenames[test_case][i]);
} }
@ -899,7 +899,7 @@ TORRENT_TEST(copy)
std::string p = a->files().file_path(i); std::string p = a->files().file_path(i);
convert_path_to_posix(p); convert_path_to_posix(p);
TEST_EQUAL(p, expected_files[i]); TEST_EQUAL(p, expected_files[i]);
std::fprintf(stderr, "%s\n", p.c_str()); std::fprintf(stdout, "%s\n", p.c_str());
TEST_EQUAL(a->files().hash(i), file_hashes[i]); TEST_EQUAL(a->files().hash(i), file_hashes[i]);
} }
@ -921,7 +921,7 @@ TORRENT_TEST(copy)
std::string p = b->files().file_path(i); std::string p = b->files().file_path(i);
convert_path_to_posix(p); convert_path_to_posix(p);
TEST_EQUAL(p, expected_files[i]); TEST_EQUAL(p, expected_files[i]);
std::fprintf(stderr, "%s\n", p.c_str()); std::fprintf(stdout, "%s\n", p.c_str());
TEST_EQUAL(b->files().hash(i), file_hashes[i]); TEST_EQUAL(b->files().hash(i), file_hashes[i]);
} }

View File

@ -486,7 +486,7 @@ TORRENT_TEST(current_tracker)
file.close(); file.close();
char tracker_url[200]; char tracker_url[200];
snprintf(tracker_url, sizeof(tracker_url), "http://127.0.0.1:%d/announce" std::snprintf(tracker_url, sizeof(tracker_url), "http://127.0.0.1:%d/announce"
, http_port); , http_port);
t->add_tracker(tracker_url, 0); t->add_tracker(tracker_url, 0);
@ -513,9 +513,9 @@ TORRENT_TEST(current_tracker)
status = h.status(); status = h.status();
TEST_CHECK(status.current_tracker.empty()); TEST_CHECK(status.current_tracker.empty());
fprintf(stderr, "destructing session\n"); std::fprintf(stderr, "destructing session\n");
s.reset(); s.reset();
fprintf(stderr, "done\n"); std::fprintf(stderr, "done\n");
} }
void test_proxy(bool proxy_trackers) void test_proxy(bool proxy_trackers)

View File

@ -274,7 +274,7 @@ void test_parse(char const* in, char const* expected)
std::string out; std::string out;
xml_parse(str(in), std::bind(&parser_callback xml_parse(str(in), std::bind(&parser_callback
, std::ref(out), _1, _2, _3, _4, _5)); , std::ref(out), _1, _2, _3, _4, _5));
std::fprintf(stderr, "in: %s\n out: %s\nexpected: %s\n" std::fprintf(stdout, "in: %s\n out: %s\nexpected: %s\n"
, in, out.c_str(), expected); , in, out.c_str(), expected);
TEST_EQUAL(out, expected); TEST_EQUAL(out, expected);
} }
@ -284,10 +284,10 @@ TORRENT_TEST(upnp_parser1)
parse_state xml_s; parse_state xml_s;
xml_parse(upnp_xml, std::bind(&find_control_url, _1, _2, _3, std::ref(xml_s))); xml_parse(upnp_xml, std::bind(&find_control_url, _1, _2, _3, std::ref(xml_s)));
std::cerr << "namespace " << xml_s.service_type << std::endl; std::cout << "namespace " << xml_s.service_type << std::endl;
std::cerr << "url_base: " << xml_s.url_base << std::endl; std::cout << "url_base: " << xml_s.url_base << std::endl;
std::cerr << "control_url: " << xml_s.control_url << std::endl; std::cout << "control_url: " << xml_s.control_url << std::endl;
std::cerr << "model: " << xml_s.model << std::endl; std::cout << "model: " << xml_s.model << std::endl;
TEST_EQUAL(xml_s.url_base, "http://192.168.0.1:5678"); TEST_EQUAL(xml_s.url_base, "http://192.168.0.1:5678");
TEST_EQUAL(xml_s.control_url, "/WANIPConnection"); TEST_EQUAL(xml_s.control_url, "/WANIPConnection");
TEST_EQUAL(xml_s.model, "D-Link Router"); TEST_EQUAL(xml_s.model, "D-Link Router");
@ -298,10 +298,10 @@ TORRENT_TEST(upnp_parser2)
parse_state xml_s; parse_state xml_s;
xml_parse(upnp_xml2, std::bind(&find_control_url, _1, _2, _3, std::ref(xml_s))); xml_parse(upnp_xml2, std::bind(&find_control_url, _1, _2, _3, std::ref(xml_s)));
std::cerr << "namespace " << xml_s.service_type << std::endl; std::cout << "namespace " << xml_s.service_type << std::endl;
std::cerr << "url_base: " << xml_s.url_base << std::endl; std::cout << "url_base: " << xml_s.url_base << std::endl;
std::cerr << "control_url: " << xml_s.control_url << std::endl; std::cout << "control_url: " << xml_s.control_url << std::endl;
std::cerr << "model: " << xml_s.model << std::endl; std::cout << "model: " << xml_s.model << std::endl;
TEST_EQUAL(xml_s.url_base, "http://192.168.1.1:49152"); TEST_EQUAL(xml_s.url_base, "http://192.168.1.1:49152");
TEST_EQUAL(xml_s.control_url, "/upnp/control/WANPPPConn1"); TEST_EQUAL(xml_s.control_url, "/upnp/control/WANPPPConn1");
TEST_EQUAL(xml_s.model, "Wireless-G ADSL Home Gateway"); TEST_EQUAL(xml_s.model, "Wireless-G ADSL Home Gateway");

View File

@ -90,7 +90,7 @@ void test_transfer(lt::session& ses, std::shared_ptr<torrent_info> torrent_file
static char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"}; static char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"};
std::fprintf(stderr, "\n\n ==== TESTING === proxy: %s ==== protocol: %s " std::fprintf(stdout, "\n\n ==== TESTING === proxy: %s ==== protocol: %s "
"==== seed: %s === transfer-encoding: %s === corruption: %s " "==== seed: %s === transfer-encoding: %s === corruption: %s "
"==== keepalive: %s\n\n\n" "==== keepalive: %s\n\n\n"
, test_name[proxy], protocol, url_seed ? "URL seed" : "HTTP seed" , test_name[proxy], protocol, url_seed ? "URL seed" : "HTTP seed"
@ -169,17 +169,17 @@ void test_transfer(lt::session& ses, std::shared_ptr<torrent_info> torrent_file
if (test_ban && th.url_seeds().empty() && th.http_seeds().empty()) if (test_ban && th.url_seeds().empty() && th.http_seeds().empty())
{ {
std::fprintf(stderr, "testing ban: URL seed removed\n"); std::fprintf(stdout, "testing ban: URL seed removed\n");
// when we don't have any web seeds left, we know we successfully banned it // when we don't have any web seeds left, we know we successfully banned it
break; break;
} }
if (s.is_seeding) if (s.is_seeding)
{ {
std::fprintf(stderr, "SEEDING\n"); std::fprintf(stdout, "SEEDING\n");
std::fprintf(stderr, "session.payload: %d session.redundant: %d\n" std::fprintf(stdout, "session.payload: %d session.redundant: %d\n"
, int(cnt["net.recv_payload_bytes"]), int(cnt["net.recv_redundant_bytes"])); , int(cnt["net.recv_payload_bytes"]), int(cnt["net.recv_redundant_bytes"]));
std::fprintf(stderr, "torrent.payload: %d torrent.redundant: %d\n" std::fprintf(stdout, "torrent.payload: %d torrent.redundant: %d\n"
, int(s.total_payload_download), int(s.total_redundant_bytes)); , int(s.total_payload_download), int(s.total_redundant_bytes));
TEST_EQUAL(s.total_payload_download - s.total_redundant_bytes, total_size - pad_file_size); TEST_EQUAL(s.total_payload_download - s.total_redundant_bytes, total_size - pad_file_size);
@ -226,7 +226,7 @@ void test_transfer(lt::session& ses, std::shared_ptr<torrent_info> torrent_file
&& cnt["disk.disk_blocks_in_use"] && cnt["disk.disk_blocks_in_use"]
== (torrent_file->total_size() + 0x3fff) / 0x4000) == (torrent_file->total_size() + 0x3fff) / 0x4000)
break; break;
std::fprintf(stderr, "cache_size: %d/%d\n", int(cnt["disk.read_cache_blocks"]) std::fprintf(stdout, "cache_size: %d/%d\n", int(cnt["disk.read_cache_blocks"])
, int(cnt["disk.disk_blocks_in_use"])); , int(cnt["disk.disk_blocks_in_use"]));
std::this_thread::sleep_for(lt::milliseconds(100)); std::this_thread::sleep_for(lt::milliseconds(100));
} }
@ -262,7 +262,7 @@ void test_transfer(lt::session& ses, std::shared_ptr<torrent_info> torrent_file
{ {
bool const expect = !fs.pad_file_at(i); bool const expect = !fs.pad_file_at(i);
std::string file_path = combine_path(save_path, fs.file_path(i)); std::string file_path = combine_path(save_path, fs.file_path(i));
std::fprintf(stderr, "checking file: %s\n", file_path.c_str()); std::fprintf(stdout, "checking file: %s\n", file_path.c_str());
TEST_EQUAL(exists(file_path), expect); TEST_EQUAL(exists(file_path), expect);
} }
} }
@ -291,7 +291,7 @@ int EXPORT run_http_suite(int proxy, char const* protocol, bool test_url_seed
{ {
char url[512]; 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/" + save_path).c_str(), protocol, port);
std::fprintf(stderr, "testing: %s\n", url); std::fprintf(stdout, "testing: %s\n", url);
create_directories(combine_path(save_path, "torrent_dir"), ec); create_directories(combine_path(save_path, "torrent_dir"), ec);
@ -365,7 +365,7 @@ int EXPORT run_http_suite(int proxy, char const* protocol, bool test_url_seed
{ {
char url[512]; char url[512];
std::snprintf(url, sizeof(url), "%s://127.0.0.1:%d/%s/seed", protocol, port, save_path.c_str()); std::snprintf(url, sizeof(url), "%s://127.0.0.1:%d/%s/seed", protocol, port, save_path.c_str());
std::fprintf(stderr, "testing: %s\n", url); std::fprintf(stdout, "testing: %s\n", url);
// there's really just one test case for http seeds // there's really just one test case for http seeds
test_cases.push_back(torrent_args().file("589824,name=seed") test_cases.push_back(torrent_args().file("589824,name=seed")
@ -374,7 +374,7 @@ int EXPORT run_http_suite(int proxy, char const* protocol, bool test_url_seed
for (int a = 0; a < int(test_cases.size()); ++a) for (int a = 0; a < int(test_cases.size()); ++a)
{ {
std::fprintf(stderr, "\n\n ==== test case %d ====\n\n\n", a); std::fprintf(stdout, "\n\n ==== test case %d ====\n\n\n", a);
std::shared_ptr<torrent_info> torrent_file = make_test_torrent(test_cases[a]); std::shared_ptr<torrent_info> torrent_file = make_test_torrent(test_cases[a]);