diff --git a/simulation/create_torrent.cpp b/simulation/create_torrent.cpp index 815423e46..471022944 100644 --- a/simulation/create_torrent.cpp +++ b/simulation/create_torrent.cpp @@ -58,7 +58,7 @@ lt::add_torrent_params create_torrent(int const idx, bool const seed std::string path = save_path(idx); lt::error_code ec; lt::create_directory(path, ec); - if (ec) std::fprintf(stderr, "failed to create directory: \"%s\": %s\n" + if (ec) std::printf("failed to create directory: \"%s\": %s\n" , path.c_str(), ec.message().c_str()); std::ofstream file(lt::combine_path(path, name).c_str()); params.ti = ::create_torrent(&file, name, 0x4000, num_pieces + idx, false); diff --git a/simulation/fake_peer.hpp b/simulation/fake_peer.hpp index d9b9acf6e..65b06166b 100644 --- a/simulation/fake_peer.hpp +++ b/simulation/fake_peer.hpp @@ -296,11 +296,11 @@ struct fake_node m_socket.bind(asio::ip::udp::endpoint(asio::ip::address_v4::any(), port), ec); TEST_CHECK(!ec); - fprintf(stderr, "fake_node::async_read_some\n"); + std::printf("fake_node::async_read_some\n"); m_socket.async_receive(boost::asio::buffer(m_in_buffer) , [&] (boost::system::error_code const& ec, size_t bytes_transferred) { - fprintf(stderr, "fake_node::async_read_some callback. ec: %s transferred: %d\n" + std::fprintf("fake_node::async_read_some callback. ec: %s transferred: %d\n" , ec.message().c_str(), int(bytes_transferred)); if (ec) return; diff --git a/simulation/setup_swarm.cpp b/simulation/setup_swarm.cpp index 41e9f4350..85640da3a 100644 --- a/simulation/setup_swarm.cpp +++ b/simulation/setup_swarm.cpp @@ -268,7 +268,7 @@ void setup_swarm(int num_nodes int const swarm_id = test_counter(); std::string path = save_path(swarm_id, 0); lt::create_directory(path, ec); - if (ec) std::fprintf(stderr, "failed to create directory: \"%s\": %s\n" + if (ec) std::printf("failed to create directory: \"%s\": %s\n" , path.c_str(), ec.message().c_str()); std::ofstream file(lt::combine_path(path, "temporary").c_str()); auto ti = ::create_torrent(&file, "temporary", 0x4000, 9, false); diff --git a/simulation/test_auto_manage.cpp b/simulation/test_auto_manage.cpp index ea51f998d..f2dc1232c 100644 --- a/simulation/test_auto_manage.cpp +++ b/simulation/test_auto_manage.cpp @@ -329,13 +329,13 @@ TORRENT_TEST(seed_limit) int num_seeding = 0; for (alert* a : alerts) { - std::fprintf(stderr, "%-3d %s\n", int(duration_cast(a->timestamp() + std::printf("%-3d %s\n", int(duration_cast(a->timestamp() - start_time).count()), a->message().c_str()); if (alert_cast(a)) { ++num_started; - std::fprintf(stderr, "started: %d checking: %d seeding: %d\n" + std::printf("started: %d checking: %d seeding: %d\n" , num_started, num_checking, num_seeding); } else if (alert_cast(a)) @@ -343,7 +343,7 @@ TORRENT_TEST(seed_limit) TEST_CHECK(num_started > 0); --num_started; - std::fprintf(stderr, "started: %d checking: %d seeding: %d\n" + std::printf("started: %d checking: %d seeding: %d\n" , num_started, num_checking, num_seeding); } else if (state_changed_alert* sc = alert_cast(a)) @@ -358,7 +358,7 @@ TORRENT_TEST(seed_limit) else if (sc->state == torrent_status::seeding) ++num_seeding; - std::fprintf(stderr, "started: %d checking: %d seeding: %d\n" + std::printf("started: %d checking: %d seeding: %d\n" , num_started, num_checking, num_seeding); // while at least one torrent is checking, there may be another @@ -418,13 +418,13 @@ TORRENT_TEST(download_limit) int num_downloading = 0; for (alert* a : alerts) { - std::fprintf(stderr, "%-3d %s\n", int(duration_cast(a->timestamp() + std::printf("%-3d %s\n", int(duration_cast(a->timestamp() - start_time).count()), a->message().c_str()); if (alert_cast(a)) { ++num_started; - std::fprintf(stderr, "started: %d checking: %d downloading: %d\n" + std::printf("started: %d checking: %d downloading: %d\n" , num_started, num_checking, num_downloading); } else if (alert_cast(a)) @@ -432,7 +432,7 @@ TORRENT_TEST(download_limit) TEST_CHECK(num_started > 0); --num_started; - std::fprintf(stderr, "started: %d checking: %d downloading: %d\n" + std::printf("started: %d checking: %d downloading: %d\n" , num_started, num_checking, num_downloading); } else if (state_changed_alert* sc = alert_cast(a)) @@ -447,7 +447,7 @@ TORRENT_TEST(download_limit) else if (sc->state == torrent_status::downloading) ++num_downloading; - std::fprintf(stderr, "started: %d checking: %d downloading: %d\n" + std::printf("started: %d checking: %d downloading: %d\n" , num_started, num_checking, num_downloading); // while at least one torrent is checking, there may be another @@ -514,7 +514,7 @@ TORRENT_TEST(checking_announce) int num_announce = 0; for (alert* a : alerts) { - std::fprintf(stderr, "%-3d %s\n", int(duration_cast(a->timestamp() + std::printf("%-3d %s\n", int(duration_cast(a->timestamp() - start_time).count()), a->message().c_str()); if (alert_cast(a)) ++num_announce; @@ -564,7 +564,7 @@ TORRENT_TEST(paused_checking) for (alert* a : alerts) { - std::fprintf(stderr, "%-3d %s\n", int(duration_cast(a->timestamp() + std::printf("%-3d %s\n", int(duration_cast(a->timestamp() - start_time).count()), a->message().c_str()); if (state_changed_alert* sc = alert_cast(a)) { @@ -613,7 +613,7 @@ TORRENT_TEST(stop_when_ready) int num_paused = 0; for (alert* a : alerts) { - std::fprintf(stderr, "%-3d %s\n", int(duration_cast(a->timestamp() + std::printf("%-3d %s\n", int(duration_cast(a->timestamp() - start_time).count()), a->message().c_str()); if (alert_cast(a)) @@ -685,7 +685,7 @@ TORRENT_TEST(resume_reject_when_paused) for (alert* a : alerts) { - std::fprintf(stderr, "%-3d %-25s %s\n", int(duration_cast(a->timestamp() + std::printf("%-3d %-25s %s\n", int(duration_cast(a->timestamp() - start_time).count()) , a->what() , a->message().c_str()); @@ -756,7 +756,7 @@ TORRENT_TEST(no_resume_when_paused) for (alert* a : alerts) { - std::fprintf(stderr, "%-3d %-25s %s\n", int(duration_cast(a->timestamp() + std::printf("%-3d %-25s %s\n", int(duration_cast(a->timestamp() - start_time).count()) , a->what() , a->message().c_str()); @@ -818,7 +818,7 @@ TORRENT_TEST(no_resume_when_started) for (alert* a : alerts) { - std::fprintf(stderr, "%-3d %-25s %s\n", int(duration_cast(a->timestamp() + std::printf("%-3d %-25s %s\n", int(duration_cast(a->timestamp() - start_time).count()) , a->what() , a->message().c_str()); diff --git a/simulation/test_http_connection.cpp b/simulation/test_http_connection.cpp index 2adeb2793..85525c21e 100644 --- a/simulation/test_http_connection.cpp +++ b/simulation/test_http_connection.cpp @@ -122,7 +122,7 @@ std::shared_ptr test_request(io_service& ios , int* handler_called , std::string const& auth = std::string()) { - std::fprintf(stdout, " ===== TESTING: %s =====\n", url.c_str()); + std::printf(" ===== TESTING: %s =====\n", url.c_str()); auto h = std::make_shared(ios , 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()); for (int i = 0; i < int(counters.size()); ++i) { - if (counters[i] != expect_counters[i]) std::fprintf(stdout, "i=%d\n", i); + if (counters[i] != expect_counters[i]) std::printf("i=%d\n", i); TEST_EQUAL(counters[i], expect_counters[i]); } } diff --git a/simulation/test_pe_crypto.cpp b/simulation/test_pe_crypto.cpp index fb724d98c..9528cfc8e 100644 --- a/simulation/test_pe_crypto.cpp +++ b/simulation/test_pe_crypto.cpp @@ -56,11 +56,11 @@ char const* pe_policy(std::uint8_t policy) void display_pe_settings(libtorrent::settings_pack const& s) { - std::fprintf(stderr, "out_enc_policy - %s\tin_enc_policy - %s\n" + std::printf("out_enc_policy - %s\tin_enc_policy - %s\n" , pe_policy(s.get_int(settings_pack::out_enc_policy)) , pe_policy(s.get_int(settings_pack::in_enc_policy))); - std::fprintf(stderr, "enc_level - %s\t\tprefer_rc4 - %s\n" + std::printf("enc_level - %s\t\tprefer_rc4 - %s\n" , s.get_int(settings_pack::allowed_enc_level) == settings_pack::pe_plaintext ? "plaintext" : s.get_int(settings_pack::allowed_enc_level) == settings_pack::pe_rc4 ? "rc4" : s.get_int(settings_pack::allowed_enc_level) == settings_pack::pe_both ? "both" : "unknown" @@ -191,7 +191,7 @@ TORRENT_TEST(disabled_failing) #else TORRENT_TEST(disabled) { - std::fprintf(stderr, "PE test not run because it's disabled\n"); + std::printf("PE test not run because it's disabled\n"); } #endif diff --git a/simulation/test_socks5.cpp b/simulation/test_socks5.cpp index cc697d85b..8c14c6204 100644 --- a/simulation/test_socks5.cpp +++ b/simulation/test_socks5.cpp @@ -92,7 +92,7 @@ void run_test(Setup const& setup // happened sim::timer t(sim, lt::seconds(100), [&](boost::system::error_code const&) { - std::fprintf(stderr, "shutting down\n"); + std::printf("shutting down\n"); // shut down zombie = ses->abort(); ses.reset(); diff --git a/simulation/test_tracker.cpp b/simulation/test_tracker.cpp index d18eeab55..5d34694ed 100644 --- a/simulation/test_tracker.cpp +++ b/simulation/test_tracker.cpp @@ -193,7 +193,7 @@ TORRENT_TEST(event_completed) // we there can only be one event const bool has_event = str.find("&event=") != std::string::npos; - std::fprintf(stdout, "- %s\n", str.c_str()); + std::printf("- %s\n", str.c_str()); // there is exactly 0 or 1 events. 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) { - std::fprintf(stdout, "tracker \"%s\"\n", tr[i].url.c_str()); + std::printf("tracker \"%s\"\n", tr[i].url.c_str()); if (tr[i].url == "http://tracker.com:8080/announce") { TEST_EQUAL(tr[i].fails, 0); diff --git a/simulation/test_web_seed.cpp b/simulation/test_web_seed.cpp index f07aa70c8..4bc93c087 100644 --- a/simulation/test_web_seed.cpp +++ b/simulation/test_web_seed.cpp @@ -148,7 +148,7 @@ void run_test(Setup const& setup // happened sim::timer t(sim, lt::seconds(100), [&](boost::system::error_code const& ec) { - fprintf(stderr, "shutting down\n"); + std::printf("shutting down\n"); // shut down zombie = ses->abort(); ses.reset(); diff --git a/test/bittorrent_peer.cpp b/test/bittorrent_peer.cpp index 3d830a2d8..cf9dae3b1 100644 --- a/test/bittorrent_peer.cpp +++ b/test/bittorrent_peer.cpp @@ -329,7 +329,7 @@ void peer_conn::on_msg_length(error_code const& ec, size_t) unsigned int length = read_uint32(ptr); if (length > sizeof(buffer)) { - std::fprintf(stderr, "len: %u\n", length); + std::printf("len: %u\n", length); close("ERROR RECEIVE MESSAGE PREFIX: packet too big", error_code()); return; } @@ -482,7 +482,7 @@ void peer_conn::on_message(error_code const& ec, size_t bytes_transferred) } } --outstanding_requests; - std::fprintf(stderr, "REJECT: [ piece: %d start: %d length: %d ]\n", piece, start, length); + std::printf("REJECT: [ piece: %d start: %d length: %d ]\n", piece, start, length); } else if (msg == 0) // choke { @@ -520,7 +520,7 @@ bool peer_conn::verify_piece(int piece, int start, char const* ptr, int size) { if (buf[i] != fill) { - std::fprintf(stderr, "received invalid block. piece %d block %d\n", piece, start / 0x4000); + std::printf("received invalid block. piece %d block %d\n", piece, start / 0x4000); exit(1); return false; } diff --git a/test/dht_server.cpp b/test/dht_server.cpp index 8148ebc23..fb15f7730 100644 --- a/test/dht_server.cpp +++ b/test/dht_server.cpp @@ -72,24 +72,24 @@ struct dht_server m_socket.open(udp::v4(), ec); if (ec) { - std::fprintf(stderr, "Error opening listen DHT socket: %s\n", ec.message().c_str()); + std::printf("Error opening listen DHT socket: %s\n", ec.message().c_str()); return; } m_socket.bind(udp::endpoint(address_v4::any(), 0), ec); if (ec) { - std::fprintf(stderr, "Error binding DHT socket to port 0: %s\n", ec.message().c_str()); + std::printf("Error binding DHT socket to port 0: %s\n", ec.message().c_str()); return; } m_port = m_socket.local_endpoint(ec).port(); if (ec) { - std::fprintf(stderr, "Error getting local endpoint of DHT socket: %s\n", ec.message().c_str()); + std::printf("Error getting local endpoint of DHT socket: %s\n", ec.message().c_str()); return; } - std::fprintf(stderr, "%s: DHT initialized on port %d\n", time_now_string(), m_port); + std::printf("%s: DHT initialized on port %d\n", time_now_string(), m_port); m_thread = std::make_shared(&dht_server::thread_fun, this); } @@ -136,7 +136,7 @@ struct dht_server if (ec) { - std::fprintf(stderr, "Error receiving on DHT socket: %s\n", ec.message().c_str()); + std::printf("Error receiving on DHT socket: %s\n", ec.message().c_str()); return; } @@ -151,7 +151,7 @@ struct dht_server } catch (std::exception const& e) { - std::fprintf(stderr, "failed to decode DHT message: %s\n", e.what()); + std::printf("failed to decode DHT message: %s\n", e.what()); } } } diff --git a/test/enum_if.cpp b/test/enum_if.cpp index 1a7aabd20..468e4d6a8 100644 --- a/test/enum_if.cpp +++ b/test/enum_if.cpp @@ -45,7 +45,7 @@ int main() address def_gw = get_default_gateway(ios, ec); if (ec) { - std::fprintf(stderr, "%s\n", ec.message().c_str()); + std::printf("%s\n", ec.message().c_str()); return 1; } diff --git a/test/main.cpp b/test/main.cpp index be6c327d1..0fc14eb38 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -91,7 +91,7 @@ void output_test_log_to_terminal() dup2(old_stderr, fileno(stderr)); fseek(current_test->output, 0, SEEK_SET); - std::fprintf(stderr, "\x1b[1m[%s]\x1b[0m\n\n", current_test->name); + std::printf("\x1b[1m[%s]\x1b[0m\n\n", current_test->name); char buf[4096]; int size = 0; do { @@ -146,7 +146,7 @@ LONG WINAPI seh_exception_handler(LPEXCEPTION_POINTERS p) #undef EXC }; - std::fprintf(stderr, "exception: (0x%x) %s caught:\n%s\n" + std::printf("exception: (0x%x) %s caught:\n%s\n" , code, name, stack_text); output_test_log_to_terminal(); @@ -189,7 +189,7 @@ void sig_handler(int sig) #endif #undef SIG }; - std::fprintf(stderr, "signal: (%d) %s caught:\n%s\n" + std::printf("signal: (%d) %s caught:\n%s\n" , sig, name, stack_text); output_test_log_to_terminal(); @@ -326,7 +326,7 @@ EXPORT int main(int argc, char const* argv[]) create_directory(test_dir, ec); if (ec) { - std::fprintf(stderr, "Failed to create test directory: %s\n", ec.message().c_str()); + std::printf("Failed to create test directory: %s\n", ec.message().c_str()); return 1; } int ret; @@ -336,19 +336,19 @@ EXPORT int main(int argc, char const* argv[]) ret = chdir(dir); if (ret != 0) { - std::fprintf(stderr, "failed to change directory to \"%s\": %s" + std::printf("failed to change directory to \"%s\": %s" , dir, strerror(errno)); return 1; } #endif - std::fprintf(stderr, "test: %s\ncwd = \"%s\"\nrnd: %x\n" + std::printf("test: %s\ncwd = \"%s\"\nrnd: %x\n" , executable, test_dir.c_str(), libtorrent::random(0xffffffff)); int total_failures = 0; if (_g_num_unit_tests == 0) { - std::fprintf(stderr, "\x1b[31mTEST_ERROR: no unit tests registered\x1b[0m\n"); + std::printf("\x1b[31mTEST_ERROR: no unit tests registered\x1b[0m\n"); return 1; } @@ -380,13 +380,13 @@ EXPORT int main(int argc, char const* argv[]) } else { - std::fprintf(stderr, "failed to redirect output: (%d) %s\n" + std::printf("failed to redirect output: (%d) %s\n" , errno, strerror(errno)); } } else { - std::fprintf(stderr, "failed to create temporary file for redirecting " + std::printf("failed to create temporary file for redirecting " "output: (%d) %s\n", errno, strerror(errno)); } } @@ -449,17 +449,17 @@ EXPORT int main(int argc, char const* argv[]) if (!tests_to_run.empty()) { - std::fprintf(stderr, "\x1b[1mUNKONWN tests:\x1b[0m\n"); + std::printf("\x1b[1mUNKONWN tests:\x1b[0m\n"); for (std::set::iterator i = tests_to_run.begin() , end(tests_to_run.end()); i != end; ++i) { - std::fprintf(stderr, " %s\n", i->c_str()); + std::printf(" %s\n", i->c_str()); } } if (num_run == 0) { - std::fprintf(stderr, "\x1b[31mTEST_ERROR: no unit tests run\x1b[0m\n"); + std::printf("\x1b[31mTEST_ERROR: no unit tests run\x1b[0m\n"); return 1; } @@ -480,7 +480,7 @@ EXPORT int main(int argc, char const* argv[]) { remove_all(test_dir, ec); if (ec) - std::fprintf(stderr, "failed to remove test dir: %s\n", ec.message().c_str()); + std::printf("failed to remove test dir: %s\n", ec.message().c_str()); } #endif diff --git a/test/make_torrent.cpp b/test/make_torrent.cpp index c4a461212..e8f73f1ac 100644 --- a/test/make_torrent.cpp +++ b/test/make_torrent.cpp @@ -193,7 +193,7 @@ void generate_files(libtorrent::torrent_info const& ti, std::string const& path int ret = st.writev(b, i, 0, 0, ec); if (ret != piece_size || ec) { - std::fprintf(stderr, "ERROR writing files: (%d expected %d) %s\n" + std::printf("ERROR writing files: (%d expected %d) %s\n" , ret, piece_size, ec.ec.message().c_str()); } } diff --git a/test/peer_server.cpp b/test/peer_server.cpp index 63aff5c3d..a4fece7dc 100644 --- a/test/peer_server.cpp +++ b/test/peer_server.cpp @@ -70,30 +70,30 @@ struct peer_server m_acceptor.open(tcp::v4(), ec); if (ec) { - std::fprintf(stderr, "PEER Error opening peer listen socket: %s\n", ec.message().c_str()); + std::printf("PEER Error opening peer listen socket: %s\n", ec.message().c_str()); return; } m_acceptor.bind(tcp::endpoint(address_v4::any(), 0), ec); if (ec) { - std::fprintf(stderr, "PEER Error binding peer socket to port 0: %s\n", ec.message().c_str()); + std::printf("PEER Error binding peer socket to port 0: %s\n", ec.message().c_str()); return; } m_port = m_acceptor.local_endpoint(ec).port(); if (ec) { - std::fprintf(stderr, "PEER Error getting local endpoint of peer socket: %s\n", ec.message().c_str()); + std::printf("PEER Error getting local endpoint of peer socket: %s\n", ec.message().c_str()); return; } m_acceptor.listen(10, ec); if (ec) { - std::fprintf(stderr, "PEER Error listening on peer socket: %s\n", ec.message().c_str()); + std::printf("PEER Error listening on peer socket: %s\n", ec.message().c_str()); return; } - std::fprintf(stderr, "%s: PEER peer initialized on port %d\n", time_now_string(), m_port); + std::printf("%s: PEER peer initialized on port %d\n", time_now_string(), m_port); m_thread = std::make_shared(&peer_server::thread_fun, this); } @@ -136,11 +136,11 @@ struct peer_server if (ec) { - std::fprintf(stderr, "PEER Error accepting connection on peer socket: %s\n", ec.message().c_str()); + std::printf("PEER Error accepting connection on peer socket: %s\n", ec.message().c_str()); return; } - std::fprintf(stderr, "%s: PEER incoming peer connection\n", time_now_string()); + std::printf("%s: PEER incoming peer connection\n", time_now_string()); ++m_peer_requests; socket.close(ec); } diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index ab0e476fc..001729f2d 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -192,7 +192,7 @@ alert const* wait_for_alert(lt::session& ses, int type, char const* name) { if (should_print(a)) { - std::fprintf(stdout, "%s: %s: [%s] %s\n", time_now_string(), name + std::printf("%s: %s: [%s] %s\n", time_now_string(), name , a->what(), a->message().c_str()); } if (a->type() == type && !ret) @@ -273,7 +273,7 @@ void save_file(char const* filename, char const* data, int size) TEST_CHECK(!ec); if (ec) { - std::fprintf(stdout, "ERROR opening file '%s': %s\n", filename, ec.message().c_str()); + std::printf("ERROR opening file '%s': %s\n", filename, ec.message().c_str()); return; } 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); if (ec) { - std::fprintf(stdout, "ERROR writing file '%s': %s\n", filename, ec.message().c_str()); + std::printf("ERROR writing file '%s': %s\n", filename, ec.message().c_str()); return; } @@ -303,12 +303,12 @@ bool print_alerts(lt::session& ses, char const* name if (predicate && predicate(a)) ret = true; if (peer_disconnected_alert const* p = alert_cast(a)) { - 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()); + std::printf("%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) && !no_output) { - std::fprintf(stdout, "%s: %s: [%s] %s\n", time_now_string(), name, (a)->what(), (a)->message().c_str()); + std::printf("%s: %s: [%s] %s\n", time_now_string(), name, (a)->what(), (a)->message().c_str()); } TEST_CHECK(alert_cast(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(a); if (pea) { - std::fprintf(stdout, "%s: peer error: %s\n", time_now_string(), pea->error.message().c_str()); + std::printf("%s: peer error: %s\n", time_now_string(), pea->error.message().c_str()); TEST_CHECK((!handles.empty() && h.status().is_seeding) || pea->error.message() == "connecting to peer" || pea->error.message() == "closing connection to ourself" @@ -334,7 +334,7 @@ bool print_alerts(lt::session& ses, char const* name invalid_request_alert const* ira = alert_cast(a); if (ira) { - std::fprintf(stdout, "peer error: %s\n", ira->message().c_str()); + std::printf("peer error: %s\n", ira->message().c_str()); TEST_CHECK(false); } } @@ -387,7 +387,7 @@ void wait_for_downloading(lt::session& ses, char const* name) } while (a); if (!downloading_done) { - std::fprintf(stdout, "%s: did not receive a state_changed_alert indicating " + std::printf("%s: did not receive a state_changed_alert indicating " "the torrent is downloading. waited: %d ms\n" , name, int(total_milliseconds(clock_type::now() - start))); } @@ -400,7 +400,7 @@ void print_ses_rate(float time { if (st1) { - std::fprintf(stdout, "%3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time + std::printf("%3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time , int(st1->download_payload_rate / 1000) , int(st1->upload_payload_rate / 1000) , int(st1->progress * 100) @@ -409,7 +409,7 @@ void print_ses_rate(float time , st1->errc ? (" [" + st1->errc.message() + "]").c_str() : ""); } if (st2) - std::fprintf(stdout, " : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time + std::printf(" : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time , int(st2->download_payload_rate / 1000) , int(st2->upload_payload_rate / 1000) , int(st2->progress * 100) @@ -417,7 +417,7 @@ void print_ses_rate(float time , st2->connect_candidates , st2->errc ? (" [" + st1->errc.message() + "]").c_str() : ""); if (st3) - std::fprintf(stdout, " : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time + std::printf(" : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time , int(st3->download_payload_rate / 1000) , int(st3->upload_payload_rate / 1000) , int(st3->progress * 100) @@ -425,7 +425,7 @@ void print_ses_rate(float time , st3->connect_candidates , st3->errc ? (" [" + st1->errc.message() + "]").c_str() : ""); - std::fprintf(stdout, "\n"); + std::printf("\n"); } #ifdef _WIN32 @@ -445,7 +445,7 @@ static std::map running_proxies; void stop_proxy(int port) { - std::fprintf(stdout, "stopping proxy on port %d\n", port); + std::printf("stopping proxy on port %d\n", port); // don't shut down proxies until the test is // completely done. This saves a lot of time. // they're closed at the end of main() by @@ -471,7 +471,7 @@ pid_type async_run(char const* cmdline) if (ret == 0) { int error = GetLastError(); - std::fprintf(stdout, "failed (%d) %s\n", error, error_code(error, system_category()).message().c_str()); + std::printf("failed (%d) %s\n", error, error_code(error, system_category()).message().c_str()); return 0; } 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); if (ret != 0) { - std::fprintf(stdout, "failed (%d) %s\n", errno, strerror(errno)); + std::printf("failed (%d) %s\n", errno, strerror(errno)); return 0; } return p; @@ -586,13 +586,13 @@ int start_proxy(int proxy_type) char buf[512]; std::snprintf(buf, sizeof(buf), "%s --port %d%s", cmd, port, auth); - std::fprintf(stdout, "%s starting proxy on port %d (%s %s)...\n", time_now_string(), port, type, auth); - std::fprintf(stdout, "%s\n", buf); + std::printf("%s starting proxy on port %d (%s %s)...\n", time_now_string(), port, type, auth); + std::printf("%s\n", buf); pid_type r = async_run(buf); if (r == 0) abort(); proxy_t t = { r, proxy_type }; running_proxies.insert(std::make_pair(port, t)); - std::fprintf(stdout, "%s launched\n", time_now_string()); + std::printf("%s launched\n", time_now_string()); std::this_thread::sleep_for(lt::milliseconds(500)); 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]; file f(full_path, file::write_only, ec); - if (ec) std::fprintf(stdout, "failed to create file \"%s\": (%d) %s\n" + if (ec) std::printf("failed to create file \"%s\": (%d) %s\n" , full_path.c_str(), ec.value(), ec.message().c_str()); std::int64_t offset = 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); file::iovec_t b = { random_data, size_t(s)}; f.writev(offset, &b, 1, ec); - if (ec) std::fprintf(stdout, "failed to write file \"%s\": (%d) %s\n" + if (ec) std::printf("failed to write file \"%s\": (%d) %s\n" , full_path.c_str(), ec.value(), ec.message().c_str()); offset += s; to_write -= s; @@ -726,7 +726,7 @@ std::shared_ptr create_torrent(std::ostream* file int res = load_file(ssl_certificate, file_buf, ec); if (ec || res < 0) { - std::fprintf(stdout, "failed to load SSL certificate: %s\n", ec.message().c_str()); + std::printf("failed to load SSL certificate: %s\n", ec.message().c_str()); } else { @@ -840,7 +840,7 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3 } char ih_hex[41]; aux::to_hex(t->info_hash(), ih_hex); - std::fprintf(stdout, "generated torrent: %s tmp1%s/temporary\n", ih_hex, suffix.c_str()); + std::printf("generated torrent: %s tmp1%s/temporary\n", ih_hex, suffix.c_str()); } else { @@ -861,7 +861,7 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3 torrent_handle tor1 = ses1->add_torrent(param, ec); if (ec) { - std::fprintf(stdout, "ses1.add_torrent: %s\n", ec.message().c_str()); + std::printf("ses1.add_torrent: %s\n", ec.message().c_str()); return std::make_tuple(torrent_handle(), torrent_handle(), torrent_handle()); } tor1.super_seeding(super_seeding); @@ -914,16 +914,16 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3 if (use_ssl_ports) { port = ses2->ssl_listen_port(); - std::fprintf(stdout, "%s: ses2->ssl_listen_port(): %d\n", time_now_string(), port); + std::printf("%s: ses2->ssl_listen_port(): %d\n", time_now_string(), port); } if (port == 0) { port = ses2->listen_port(); - std::fprintf(stdout, "%s: ses2->listen_port(): %d\n", time_now_string(), port); + std::printf("%s: ses2->listen_port(): %d\n", time_now_string(), port); } - std::fprintf(stdout, "%s: ses1: connecting peer port: %d\n" + std::printf("%s: ses1: connecting peer port: %d\n" , time_now_string(), port); tor1.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec) , 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 (port2 == 0) port2 = ses1->listen_port(); - std::fprintf(stdout, "ses3: connecting peer port: %d\n", port); + std::printf("ses3: connecting peer port: %d\n", port); tor3.connect_peer(tcp::endpoint( address::from_string("127.0.0.1", ec), std::uint16_t(port))); - std::fprintf(stdout, "ses3: connecting peer port: %d\n", port2); + std::printf("ses3: connecting peer port: %d\n", port2); tor3.connect_peer(tcp::endpoint( address::from_string("127.0.0.1", ec) , 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" , port, chunked_encoding , ssl, keepalive); - std::fprintf(stdout, "%s starting web_server on port %d...\n", time_now_string(), port); + std::printf("%s starting web_server on port %d...\n", time_now_string(), port); - std::fprintf(stdout, "%s\n", buf); + std::printf("%s\n", buf); pid_type r = async_run(buf); if (r == 0) abort(); web_server_pid = r; - std::fprintf(stdout, "%s launched\n", time_now_string()); + std::printf("%s launched\n", time_now_string()); std::this_thread::sleep_for(lt::milliseconds(500)); return port; } @@ -995,7 +995,7 @@ int start_web_server(bool ssl, bool chunked_encoding, bool keepalive) void stop_web_server() { if (web_server_pid == 0) return; - std::fprintf(stdout, "stopping web server\n"); + std::printf("stopping web server\n"); stop_process(web_server_pid); web_server_pid = 0; } diff --git a/test/swarm_suite.cpp b/test/swarm_suite.cpp index e9dc7992b..8203660ba 100644 --- a/test/swarm_suite.cpp +++ b/test/swarm_suite.cpp @@ -54,7 +54,7 @@ void test_swarm(int flags) using namespace libtorrent; namespace lt = libtorrent; - std::fprintf(stderr, "\n\n ==== TEST SWARM === %s%s%s%s%s ===\n\n\n" + std::printf("\n\n ==== TEST SWARM === %s%s%s%s%s ===\n\n\n" , (flags & super_seeding) ? "super-seeding ": "" , (flags & strict_super_seeding) ? "strict-super-seeding ": "" , (flags & seed_mode) ? "seed-mode ": "" @@ -207,19 +207,19 @@ void test_swarm(int flags) alert const* ret; while ((ret = ses1.wait_for_alert(seconds(2)))) { - std::fprintf(stderr, "wait returned: %d ms\n" + std::printf("wait returned: %d ms\n" , int(total_milliseconds(clock_type::now() - start))); std::vector alerts; ses1.pop_alerts(&alerts); for (std::vector::iterator i = alerts.begin() , end(alerts.end()); i != end; ++i) { - std::fprintf(stderr, "%s\n", ret->message().c_str()); + std::printf("%s\n", ret->message().c_str()); } start = clock_type::now(); } - std::fprintf(stderr, "loop returned: %d ms\n" + std::printf("loop returned: %d ms\n" , int(total_milliseconds(clock_type::now() - start))); // this allows shutting down the sessions in parallel @@ -229,7 +229,7 @@ void test_swarm(int flags) time_point end = clock_type::now(); - std::fprintf(stderr, "time: %d ms\n", int(total_milliseconds(end - start))); + std::printf("time: %d ms\n", int(total_milliseconds(end - start))); TEST_CHECK(end - start < milliseconds(3000)); TEST_CHECK(end - start > milliseconds(1900)); diff --git a/test/test.cpp b/test/test.cpp index 0d9c4d4bb..e3f14ccd7 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -50,7 +50,7 @@ void report_failure(char const* err, char const* file, int line) { char buf[500]; std::snprintf(buf, sizeof(buf), "\x1b[41m***** %s:%d \"%s\" *****\x1b[0m\n", file, line, err); - std::fprintf(stderr, "\n%s\n", buf); + std::printf("\n%s\n", buf); failure_strings.push_back(buf); ++_g_test_failures; } @@ -64,7 +64,7 @@ int print_failures() if (len > longest_name) longest_name = len; } - std::fprintf(stderr, "\n\n"); + std::printf("\n\n"); for (int i = 0; i < _g_num_unit_tests; ++i) { @@ -72,22 +72,22 @@ int print_failures() if (_g_unit_tests[i].num_failures == 0) { - std::fprintf(stderr, "\x1b[32m[%-*s] ***PASS***\n" + std::printf("\x1b[32m[%-*s] ***PASS***\n" , longest_name, _g_unit_tests[i].name); } else { - std::fprintf(stderr, "\x1b[31m[%-*s] %d FAILURES\n" + std::printf("\x1b[31m[%-*s] %d FAILURES\n" , longest_name , _g_unit_tests[i].name , _g_unit_tests[i].num_failures); } } - std::fprintf(stderr, "\x1b[0m"); + std::printf("\x1b[0m"); if (_g_test_failures > 0) - std::fprintf(stderr, "\n\n\x1b[41m == %d TEST(S) FAILED ==\x1b[0m\n\n\n", _g_test_failures); + std::printf("\n\n\x1b[41m == %d TEST(S) FAILED ==\x1b[0m\n\n\n", _g_test_failures); return _g_test_failures; } diff --git a/test/test_alert_manager.cpp b/test/test_alert_manager.cpp index 61e5734cb..ac304f1a8 100644 --- a/test/test_alert_manager.cpp +++ b/test/test_alert_manager.cpp @@ -205,7 +205,7 @@ TORRENT_TEST(wait_for_alert) time_point end = clock_type::now(); TEST_EQUAL(a, static_cast(nullptr)); - std::fprintf(stderr, "delay: %d ms (expected 1 second)\n" + std::printf("delay: %d ms (expected 1 second)\n" , int(total_milliseconds(end - start))); TEST_CHECK(end - start > milliseconds(900)); TEST_CHECK(end - start < milliseconds(1100)); @@ -216,7 +216,7 @@ TORRENT_TEST(wait_for_alert) a = mgr.wait_for_alert(seconds(1)); end = clock_type::now(); - std::fprintf(stderr, "delay: %d ms\n", int(total_milliseconds(end - start))); + std::printf("delay: %d ms\n", int(total_milliseconds(end - start))); TEST_CHECK(end - start < milliseconds(1)); TEST_CHECK(a->type() == torrent_added_alert::alert_type); @@ -229,7 +229,7 @@ TORRENT_TEST(wait_for_alert) a = mgr.wait_for_alert(seconds(10)); end = clock_type::now(); - std::fprintf(stderr, "delay: %d ms\n", int(total_milliseconds(end - start))); + std::printf("delay: %d ms\n", int(total_milliseconds(end - start))); TEST_CHECK(end - start < milliseconds(500)); TEST_CHECK(a->type() == torrent_added_alert::alert_type); diff --git a/test/test_auto_unchoke.cpp b/test/test_auto_unchoke.cpp index 29bd22975..c79a72796 100644 --- a/test/test_auto_unchoke.cpp +++ b/test/test_auto_unchoke.cpp @@ -99,7 +99,7 @@ void test_swarm() std::map cnt = get_counters(ses1); - std::fprintf(stderr, "allowed_upload_slots: %d\n", int(cnt["ses.num_unchoke_slots"])); + std::printf("allowed_upload_slots: %d\n", int(cnt["ses.num_unchoke_slots"])); TEST_EQUAL(cnt["ses.num_unchoke_slots"], 1); for (int i = 0; i < 200; ++i) { @@ -108,7 +108,7 @@ void test_swarm() print_alerts(ses3, "ses3"); cnt = get_counters(ses1); - std::fprintf(stderr, "allowed unchoked: %d\n", int(cnt["ses.num_unchoke_slots"])); + std::printf("allowed unchoked: %d\n", int(cnt["ses.num_unchoke_slots"])); if (cnt["ses.num_unchoke_slots"] >= 2) break; torrent_status st1 = tor1.status(); diff --git a/test/test_checking.cpp b/test/test_checking.cpp index 4d8739dfc..06a19e27d 100644 --- a/test/test_checking.cpp +++ b/test/test_checking.cpp @@ -62,7 +62,7 @@ void test_checking(int flags = read_only_files) using namespace libtorrent; namespace lt = libtorrent; - std::fprintf(stdout, "\n==== TEST CHECKING %s%s%s=====\n\n" + std::printf("\n==== TEST CHECKING %s%s%s=====\n\n" , (flags & read_only_files) ? "read-only-files ":"" , (flags & corrupt_files) ? "corrupt ":"" , (flags & incomplete_files) ? "incomplete ":""); @@ -86,14 +86,14 @@ void test_checking(int flags = read_only_files) // in case the previous run was terminated error_code ec; remove_all("tmp1_checking", ec); - if (ec) std::fprintf(stdout, "ERROR: removing tmp1_checking: (%d) %s\n" + if (ec) std::printf("ERROR: removing tmp1_checking: (%d) %s\n" , ec.value(), ec.message().c_str()); create_directory("tmp1_checking", ec); - if (ec) std::fprintf(stdout, "ERROR: creating directory tmp1_checking: (%d) %s\n" + if (ec) std::printf("ERROR: creating directory tmp1_checking: (%d) %s\n" , ec.value(), ec.message().c_str()); create_directory(combine_path("tmp1_checking", "test_torrent_dir"), ec); - if (ec) std::fprintf(stdout, "ERROR: creating directory test_torrent_dir: (%d) %s\n" + if (ec) std::printf("ERROR: creating directory test_torrent_dir: (%d) %s\n" , ec.value(), ec.message().c_str()); file_storage fs; @@ -109,14 +109,14 @@ void test_checking(int flags = read_only_files) // calculate the hash for all pieces set_piece_hashes(t, "tmp1_checking", ec); - if (ec) std::fprintf(stdout, "ERROR: set_piece_hashes: (%d) %s\n" + if (ec) std::printf("ERROR: set_piece_hashes: (%d) %s\n" , ec.value(), ec.message().c_str()); std::vector buf; bencode(std::back_inserter(buf), t.generate()); auto ti = std::make_shared(&buf[0], int(buf.size()), ec); - std::fprintf(stdout, "generated torrent: %s tmp1_checking/test_torrent_dir\n" + std::printf("generated torrent: %s tmp1_checking/test_torrent_dir\n" , aux::to_hex(ti->info_hash()).c_str()); // truncate every file in half @@ -133,10 +133,10 @@ void test_checking(int flags = read_only_files) error_code ec; file f(path, file::read_write, ec); - if (ec) std::fprintf(stdout, "ERROR: opening file \"%s\": (%d) %s\n" + if (ec) std::printf("ERROR: opening file \"%s\": (%d) %s\n" , path.c_str(), ec.value(), ec.message().c_str()); f.set_size(file_sizes[i] / 2, ec); - if (ec) std::fprintf(stdout, "ERROR: truncating file \"%s\": (%d) %s\n" + if (ec) std::printf("ERROR: truncating file \"%s\": (%d) %s\n" , 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 if (flags & corrupt_files) { - std::fprintf(stdout, "corrupt file test. overwriting files\n"); + std::printf("corrupt file test. overwriting files\n"); // increase the size of some files. When they're read only that forces // the checker to open them in write-mode to truncate them static const int file_sizes2[] = @@ -156,7 +156,7 @@ void test_checking(int flags = read_only_files) // make the files read only if (flags & read_only_files) { - std::fprintf(stdout, "making files read-only\n"); + std::printf("making files read-only\n"); for (int i = 0; i < num_files; ++i) { 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); path = combine_path(path, name); - std::fprintf(stdout, " %s\n", path.c_str()); + std::printf(" %s\n", path.c_str()); #ifdef TORRENT_WINDOWS 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. TEST_CHECK(st.errc); if (st.errc) - std::fprintf(stdout, "error: %s\n", st.errc.message().c_str()); + std::printf("error: %s\n", st.errc.message().c_str()); // wait a while to make sure libtorrent survived the error 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.errc); if (st.errc) - std::fprintf(stdout, "error: %s\n", st.errc.message().c_str()); + std::printf("error: %s\n", st.errc.message().c_str()); } else { TEST_CHECK(!st.errc); if (st.errc) - std::fprintf(stdout, "error: %s\n", st.errc.message().c_str()); + std::printf("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); if (st.errc) - std::fprintf(stdout, "error: %s\n", st.errc.message().c_str()); + std::printf("error: %s\n", st.errc.message().c_str()); } // make the files writable again @@ -284,7 +284,7 @@ void test_checking(int flags = read_only_files) } remove_all("tmp1_checking", ec); - if (ec) std::fprintf(stdout, "ERROR: removing tmp1_checking: (%d) %s\n" + if (ec) std::printf("ERROR: removing tmp1_checking: (%d) %s\n" , ec.value(), ec.message().c_str()); } diff --git a/test/test_dht.cpp b/test/test_dht.cpp index 979ac685f..e796d7f8b 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -235,7 +235,7 @@ void send_dht_request(node& node, char const* msg, udp::endpoint const& ep bdecode_node decoded; error_code ec; bdecode(msg_buf, msg_buf + size, decoded, ec); - if (ec) std::fprintf(stdout, "bdecode failed: %s\n", ec.message().c_str()); + if (ec) std::printf("bdecode failed: %s\n", ec.message().c_str()); dht::msg m(decoded, ep); node.incoming(m); @@ -280,7 +280,7 @@ void send_dht_response(node& node, bdecode_node const& request, udp::endpoint co bdecode_node decoded; error_code ec; bdecode(msg_buf, msg_buf + size, decoded, ec); - if (ec) std::fprintf(stdout, "bdecode failed: %s\n", ec.message().c_str()); + if (ec) std::printf("bdecode failed: %s\n", ec.message().c_str()); dht::msg m(decoded, ep); node.incoming(m); @@ -334,18 +334,18 @@ void announce_immutable_items(node& node, udp::endpoint const* eps bdecode_node parsed[5]; char error_string[200]; -// std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); +// std::printf("msg: %s\n", print_entry(response).c_str()); int ret = verify_message(response, desc, parsed, error_string); if (ret) { TEST_EQUAL(parsed[4].string_value(), "r"); token = parsed[2].string_value().to_string(); -// std::fprintf(stdout, "got token: %s\n", token.c_str()); +// std::printf("got token: %s\n", token.c_str()); } else { - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); - std::fprintf(stdout, " invalid get response: %s\n", error_string); + std::printf("msg: %s\n", print_entry(response).c_str()); + std::printf(" invalid get response: %s\n", error_string); TEST_ERROR(error_string); } @@ -373,14 +373,14 @@ void announce_immutable_items(node& node, udp::endpoint const* eps if (ret) { if (parsed2[0].string_value() != "r") - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); + std::printf("msg: %s\n", print_entry(response).c_str()); TEST_EQUAL(parsed2[0].string_value(), "r"); } else { - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); - std::fprintf(stdout, " invalid put response: %s\n", error_string); + std::printf("msg: %s\n", print_entry(response).c_str()); + std::printf(" invalid put response: %s\n", error_string); TEST_ERROR(error_string); } } @@ -489,7 +489,7 @@ struct obs : dht::dht_observer char buf[1024]; vsnprintf(buf, sizeof(buf), fmt, v); va_end(v); - std::fprintf(stdout, "%s\n", buf); + std::printf("%s\n", buf); m_log.push_back(buf); } void log_packet(message_direction_t dir, span pkt @@ -761,7 +761,7 @@ TORRENT_TEST(ping) bdecode_node pong_keys[4]; - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); + std::printf("msg: %s\n", print_entry(response).c_str()); bool ret = dht::verify_message(response, pong_desc, pong_keys, t.error_string); TEST_CHECK(ret); if (ret) @@ -771,7 +771,7 @@ TORRENT_TEST(ping) } else { - std::fprintf(stdout, " invalid ping response: %s\n", t.error_string); + std::printf(" 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); - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); + std::printf("msg: %s\n", print_entry(response).c_str()); bool ret = dht::verify_message(response, err_desc, err_keys, t.error_string); TEST_CHECK(ret); if (ret) @@ -801,7 +801,7 @@ TORRENT_TEST(invalid_message) } else { - std::fprintf(stdout, " invalid error response: %s\n", t.error_string); + std::printf(" invalid error response: %s\n", t.error_string); } } @@ -829,19 +829,19 @@ TORRENT_TEST(get_peers_announce) bdecode_node peer1_keys[4]; std::string token; - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); + std::printf("msg: %s\n", print_entry(response).c_str()); bool ret = dht::verify_message(response, peer1_desc, peer1_keys, t.error_string); TEST_CHECK(ret); if (ret) { TEST_CHECK(peer1_keys[0].string_value() == "r"); token = peer1_keys[2].string_value().to_string(); -// std::fprintf(stdout, "got token: %s\n", token.c_str()); +// std::printf("got token: %s\n", token.c_str()); } else { - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); - std::fprintf(stdout, " invalid get_peers response: %s\n", t.error_string); + std::printf("msg: %s\n", print_entry(response).c_str()); + std::printf(" invalid get_peers response: %s\n", t.error_string); } 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]; - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); + std::printf("msg: %s\n", print_entry(response).c_str()); ret = dht::verify_message(response, ann_desc, ann_keys, t.error_string); TEST_CHECK(ret); if (ret) @@ -868,7 +868,7 @@ TORRENT_TEST(get_peers_announce) } else { - std::fprintf(stdout, " invalid announce response:\n"); + std::printf(" invalid announce response:\n"); TEST_ERROR(t.error_string); } } @@ -899,8 +899,8 @@ void test_scrape(address(&rand_addr)()) } else { - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); - std::fprintf(stdout, " invalid get_peers response: %s\n", t.error_string); + std::printf("msg: %s\n", print_entry(response).c_str()); + std::printf(" invalid get_peers response: %s\n", t.error_string); } response.clear(); 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]; - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); + std::printf("msg: %s\n", print_entry(response).c_str()); bool ret = dht::verify_message(response, peer2_desc, peer2_keys, t.error_string); TEST_CHECK(ret); if (ret) @@ -942,15 +942,15 @@ void test_scrape(address(&rand_addr)()) downloaders.from_string(peer2_keys[2].string_ptr()); seeds.from_string(peer2_keys[3].string_ptr()); - std::fprintf(stdout, "seeds: %f\n", seeds.size()); - std::fprintf(stdout, "downloaders: %f\n", downloaders.size()); + std::printf("seeds: %f\n", seeds.size()); + std::printf("downloaders: %f\n", downloaders.size()); TEST_CHECK(fabs(seeds.size() - 50.f) <= 3.f); TEST_CHECK(fabs(downloaders.size() - 50.f) <= 3.f); } else { - std::fprintf(stdout, "invalid get_peers response:\n"); + std::printf("invalid get_peers response:\n"); TEST_ERROR(t.error_string); } } @@ -1012,14 +1012,14 @@ void test_id_enforcement(address(&rand_addr)()) } else { - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); + std::printf("msg: %s\n", print_entry(response).c_str()); TEST_ERROR("invalid error response"); } } else { - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); - std::fprintf(stdout, " invalid error response: %s\n", t.error_string); + std::printf("msg: %s\n", print_entry(response).c_str()); + std::printf(" invalid error response: %s\n", t.error_string); } // 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]; - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); + std::printf("msg: %s\n", print_entry(response).c_str()); ret = dht::verify_message(response, nodes_desc, nodes_keys, t.error_string); TEST_CHECK(ret); if (ret) @@ -1052,8 +1052,8 @@ void test_id_enforcement(address(&rand_addr)()) } else { - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); - std::fprintf(stdout, " invalid error response: %s\n", t.error_string); + std::printf("msg: %s\n", print_entry(response).c_str()); + std::printf(" invalid error response: %s\n", t.error_string); } // node with valid node-id should be added to routing table. 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 // http://www.bittorrent.org/beps/bep_0033.html - std::fprintf(stdout, "test.size: %f\n", test.size()); + std::printf("test.size: %f\n", test.size()); std::string const bf_str = test.to_string(); - std::fprintf(stdout, "%s\n", aux::to_hex(bf_str).c_str()); + std::printf("%s\n", aux::to_hex(bf_str).c_str()); if (supports_ipv6()) { 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) { seq = sequence_number(4); - std::fprintf(stdout, "\nTEST GET/PUT%s \ngenerating ed25519 keys\n\n" + std::printf("\nTEST GET/PUT%s \ngenerating ed25519 keys\n\n" , with_salt ? " with-salt" : " no-salt"); std::array seed = ed25519_create_seed(); std::tie(pk, sk) = ed25519_create_keypair(seed); - std::fprintf(stdout, "pub: %s priv: %s\n" + std::printf("pub: %s priv: %s\n" , aux::to_hex(pk.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); sha1_hash target_id = h.final(); - std::fprintf(stdout, "target_id: %s\n" + std::printf("target_id: %s\n" , aux::to_hex(target_id).c_str()); 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"); token = desc_keys[2].string_value().to_string(); - std::fprintf(stdout, "get response: %s\n" + std::printf("get response: %s\n" , print_entry(response).c_str()); - std::fprintf(stdout, "got token: %s\n", aux::to_hex(token).c_str()); + std::printf("got token: %s\n", aux::to_hex(token).c_str()); } else { - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); - std::fprintf(stdout, " invalid get response: %s\n%s\n" + std::printf("msg: %s\n", print_entry(response).c_str()); + std::printf(" invalid get response: %s\n%s\n" , t.error_string, print_entry(response).c_str()); 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); if (ret) { - std::fprintf(stdout, "put response: %s\n" + std::printf("put response: %s\n" , print_entry(response).c_str()); TEST_EQUAL(desc2_keys[0].string_value(), "r"); } else { - std::fprintf(stdout, " invalid put response: %s\n%s\n" + std::printf(" invalid put response: %s\n%s\n" , t.error_string, print_entry(response).c_str()); 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 , msg_args().target(target_id)); - std::fprintf(stdout, "target_id: %s\n" + std::printf("target_id: %s\n" , aux::to_hex(target_id).c_str()); 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); if (ret == 0) { - std::fprintf(stdout, "msg: %s\n", print_entry(response).c_str()); - std::fprintf(stdout, " invalid get response: %s\n%s\n" + std::printf("msg: %s\n", print_entry(response).c_str()); + std::printf(" invalid get response: %s\n%s\n" , t.error_string, print_entry(response).c_str()); TEST_ERROR(t.error_string); } else { - std::fprintf(stdout, "get response: %s\n" + std::printf("get response: %s\n" , print_entry(response).c_str()); char value[1020]; char* ptr = value; @@ -1333,7 +1333,7 @@ void test_put(address(&rand_addr)()) // break the signature sig.bytes[2] ^= 0xaa; - std::fprintf(stdout, "PUT broken signature\n"); + std::printf("PUT broken signature\n"); 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); if (ret) { - std::fprintf(stdout, "put response: %s\n", print_entry(response).c_str()); + std::printf("put response: %s\n", print_entry(response).c_str()); TEST_EQUAL(desc_error_keys[1].string_value(), "e"); // 206 is the code for invalid signature TEST_EQUAL(desc_error_keys[0].list_int_value_at(0), 206); } else { - std::fprintf(stdout, " invalid put response: %s\n%s\n" + std::printf(" invalid put response: %s\n%s\n" , t.error_string, print_entry(response).c_str()); TEST_ERROR(t.error_string); } @@ -1397,7 +1397,7 @@ void test_put(address(&rand_addr)()) TEST_CHECK(item_target_id(salt, pk) == target_id); - std::fprintf(stdout, "PUT CAS 1\n"); + std::printf("PUT CAS 1\n"); send_dht_request(t.dht_node, "put", t.source, &response , msg_args() @@ -1412,18 +1412,18 @@ void test_put(address(&rand_addr)()) ret = verify_message(response, desc2, desc2_keys, t.error_string); if (ret) { - std::fprintf(stdout, "put response: %s\n" + std::printf("put response: %s\n" , print_entry(response).c_str()); TEST_EQUAL(desc2_keys[0].string_value(), "r"); } else { - std::fprintf(stdout, " invalid put response: %s\n%s\n" + std::printf(" invalid put response: %s\n%s\n" , t.error_string, print_entry(response).c_str()); TEST_ERROR(t.error_string); } - std::fprintf(stdout, "PUT CAS 2\n"); + std::printf("PUT CAS 2\n"); // put the same message again. This should fail because the // 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); if (ret) { - std::fprintf(stdout, "put response: %s\n" + std::printf("put response: %s\n" , print_entry(response).c_str()); TEST_EQUAL(desc_error_keys[1].string_value(), "e"); // 301 is the error code for CAS hash mismatch @@ -1449,7 +1449,7 @@ void test_put(address(&rand_addr)()) } else { - std::fprintf(stdout, " invalid put response: %s\n%s\nExpected failure 301 (CAS hash mismatch)\n" + std::printf(" invalid put response: %s\n%s\nExpected failure 301 (CAS hash mismatch)\n" , t.error_string, print_entry(response).c_str()); 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[19] == rs[i]); - std::fprintf(stdout, "IP address: %s r: %d node ID: %s\n", ips[i] + std::printf("IP address: %s r: %d node ID: %s\n", ips[i] , rs[i], aux::to_hex(id).c_str()); } } @@ -1734,7 +1734,7 @@ void test_bootstrap(address(&rand_addr)()) } else { - std::fprintf(stdout, " invalid find_node request: %s\n", print_entry(response).c_str()); + std::printf(" invalid find_node request: %s\n", print_entry(response).c_str()); TEST_ERROR(t.error_string); return; } @@ -1765,7 +1765,7 @@ void test_bootstrap(address(&rand_addr)()) } else { - std::fprintf(stdout, " invalid find_node request: %s\n", print_entry(response).c_str()); + std::printf(" invalid find_node request: %s\n", print_entry(response).c_str()); TEST_ERROR(t.error_string); return; } @@ -1836,7 +1836,7 @@ void test_short_nodes(address(&rand_addr)()) } else { - std::fprintf(stdout, " invalid find_node request: %s\n", print_entry(response).c_str()); + std::printf(" invalid find_node request: %s\n", print_entry(response).c_str()); TEST_ERROR(t.error_string); return; } @@ -1921,7 +1921,7 @@ void test_get_peers(address(&rand_addr)()) } else { - std::fprintf(stdout, " invalid get_peers request: %s\n", print_entry(response).c_str()); + std::printf(" invalid get_peers request: %s\n", print_entry(response).c_str()); TEST_ERROR(t.error_string); return; } @@ -1964,7 +1964,7 @@ void test_get_peers(address(&rand_addr)()) } else { - std::fprintf(stdout, " invalid get_peers request: %s\n", print_entry(response).c_str()); + std::printf(" invalid get_peers request: %s\n", print_entry(response).c_str()); TEST_ERROR(t.error_string); return; } @@ -1980,7 +1980,7 @@ void test_get_peers(address(&rand_addr)()) for (std::list >::iterator i = g_sent_packets.begin() , end(g_sent_packets.end()); i != end; ++i) { -// std::fprintf(stdout, " %s:%d: %s\n", i->first.address().to_string(ec).c_str() +// std::printf(" %s:%d: %s\n", i->first.address().to_string(ec).c_str() // , i->first.port(), i->second.to_string().c_str()); TEST_EQUAL(i->second["q"].string(), "announce_peer"); } @@ -2064,7 +2064,7 @@ void test_mutable_get(address(&rand_addr)(), bool const with_salt) } else { - std::fprintf(stdout, " invalid get request: %s\n", print_entry(response).c_str()); + std::printf(" invalid get request: %s\n", print_entry(response).c_str()); TEST_ERROR(t.error_string); return; } @@ -2149,7 +2149,7 @@ TORRENT_TEST(immutable_get) } else { - std::fprintf(stdout, " invalid get request: %s\n", print_entry(response).c_str()); + std::printf(" invalid get request: %s\n", print_entry(response).c_str()); TEST_ERROR(t.error_string); return; } @@ -2221,7 +2221,7 @@ TORRENT_TEST(immutable_put) bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string); if (!ret) { - std::fprintf(stdout, " invalid get request: %s\n", print_entry(response).c_str()); + std::printf(" invalid get request: %s\n", print_entry(response).c_str()); TEST_ERROR(t.error_string); continue; } @@ -2264,7 +2264,7 @@ TORRENT_TEST(immutable_put) } else { - std::fprintf(stdout, " invalid immutable put request: %s\n", print_entry(response).c_str()); + std::printf(" invalid immutable put request: %s\n", print_entry(response).c_str()); TEST_ERROR(t.error_string); continue; } @@ -2322,7 +2322,7 @@ TORRENT_TEST(mutable_put) bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string); if (!ret) { - std::fprintf(stdout, " invalid get request: %s\n", print_entry(response).c_str()); + std::printf(" invalid get request: %s\n", print_entry(response).c_str()); TEST_ERROR(t.error_string); continue; } @@ -2369,7 +2369,7 @@ TORRENT_TEST(mutable_put) } else { - std::fprintf(stdout, " invalid put request: %s\n", print_entry(response).c_str()); + std::printf(" invalid put request: %s\n", print_entry(response).c_str()); TEST_ERROR(t.error_string); continue; } @@ -2437,7 +2437,7 @@ TORRENT_TEST(traversal_done) bool const ret = verify_message(response, get_item_desc, get_item_keys, t.error_string); if (!ret) { - std::fprintf(stdout, " invalid get request: %s\n", print_entry(response).c_str()); + std::printf(" invalid get request: %s\n", print_entry(response).c_str()); TEST_ERROR(t.error_string); continue; } @@ -2521,7 +2521,7 @@ TORRENT_TEST(dht_dual_stack) } else { - std::fprintf(stdout, "find_node response: %s\n", print_entry(response).c_str()); + std::printf("find_node response: %s\n", print_entry(response).c_str()); TEST_ERROR(error_string); } @@ -2553,7 +2553,7 @@ TORRENT_TEST(dht_dual_stack) } else { - std::fprintf(stdout, "find_node response: %s\n", print_entry(response).c_str()); + std::printf("find_node response: %s\n", print_entry(response).c_str()); TEST_ERROR(error_string); } @@ -2592,7 +2592,7 @@ TORRENT_TEST(dht_dual_stack) } else { - std::fprintf(stdout, "find_node response: %s\n", print_entry(response).c_str()); + std::printf("find_node response: %s\n", print_entry(response).c_str()); TEST_ERROR(error_string); } } @@ -2680,7 +2680,7 @@ TORRENT_TEST(verify_message) error_code ec; char const test_msg[] = "d1:A4:test1:Bd2:B15:test22:B25:test3ee"; bdecode(test_msg, test_msg + sizeof(test_msg)-1, ent, ec); - std::fprintf(stdout, "%s\n", print_entry(ent).c_str()); + std::printf("%s\n", print_entry(ent).c_str()); bool ret = verify_message(ent, msg_desc, msg_keys, error_string); TEST_CHECK(ret); @@ -2697,7 +2697,7 @@ TORRENT_TEST(verify_message) char const test_msg2[] = "d1:A4:test1:Cd2:C15:test22:C25:test3ee"; bdecode(test_msg2, test_msg2 + sizeof(test_msg2)-1, ent, ec); - std::fprintf(stdout, "%s\n", print_entry(ent).c_str()); + std::printf("%s\n", print_entry(ent).c_str()); ret = verify_message(ent, msg_desc, msg_keys, error_string); TEST_CHECK(ret); @@ -2715,35 +2715,35 @@ TORRENT_TEST(verify_message) char const test_msg3[] = "d1:Cd2:C15:test22:C25:test3ee"; bdecode(test_msg3, test_msg3 + sizeof(test_msg3)-1, ent, ec); - std::fprintf(stdout, "%s\n", print_entry(ent).c_str()); + std::printf("%s\n", print_entry(ent).c_str()); ret = verify_message(ent, msg_desc, msg_keys, error_string); TEST_CHECK(!ret); - std::fprintf(stdout, "%s\n", error_string); + std::printf("%s\n", error_string); TEST_EQUAL(error_string, std::string("missing 'A' key")); char const test_msg4[] = "d1:A6:foobare"; bdecode(test_msg4, test_msg4 + sizeof(test_msg4)-1, ent, ec); - std::fprintf(stdout, "%s\n", print_entry(ent).c_str()); + std::printf("%s\n", print_entry(ent).c_str()); ret = verify_message(ent, msg_desc, msg_keys, error_string); TEST_CHECK(!ret); - std::fprintf(stdout, "%s\n", error_string); + std::printf("%s\n", error_string); TEST_EQUAL(error_string, std::string("invalid value for 'A'")); char const test_msg5[] = "d1:A4:test1:Cd2:C15:test2ee"; bdecode(test_msg5, test_msg5 + sizeof(test_msg5)-1, ent, ec); - std::fprintf(stdout, "%s\n", print_entry(ent).c_str()); + std::printf("%s\n", print_entry(ent).c_str()); ret = verify_message(ent, msg_desc, msg_keys, error_string); TEST_CHECK(!ret); - std::fprintf(stdout, "%s\n", error_string); + std::printf("%s\n", error_string); TEST_EQUAL(error_string, std::string("missing 'C2' key")); // test empty strings [ { "":1 }, "" ] char const test_msg6[] = "ld0:i1ee0:e"; bdecode(test_msg6, test_msg6 + sizeof(test_msg6)-1, ent, ec); - std::fprintf(stdout, "%s\n", print_entry(ent).c_str()); + std::printf("%s\n", print_entry(ent).c_str()); TEST_CHECK(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; error_code ec; bdecode(msg_buf, msg_buf + size, decoded, ec); - if (ec) std::fprintf(stdout, "bdecode failed: %s\n", ec.message().c_str()); + if (ec) std::printf("bdecode failed: %s\n", ec.message().c_str()); dht::msg m(decoded, source); node.incoming(m); @@ -3102,7 +3102,7 @@ TORRENT_TEST(rpc_invalid_error_msg) bdecode_node decoded; error_code ec; bdecode(msg_buf, msg_buf + size, decoded, ec); - if (ec) std::fprintf(stdout, "bdecode failed: %s\n", ec.message().c_str()); + if (ec) std::printf("bdecode failed: %s\n", ec.message().c_str()); dht::msg m(decoded, source); node_id nid; @@ -3281,7 +3281,7 @@ TORRENT_TEST(distance_exp) for (auto const& t : distance_tests) { - std::fprintf(stdout, "%s %s: %d\n" + std::printf("%s %s: %d\n" , std::get<0>(t), std::get<1>(t), std::get<2>(t)); TEST_EQUAL(distance_exp( @@ -3307,7 +3307,7 @@ TORRENT_TEST(compare_ip_cidr) for (auto const& t : v4tests) { - std::fprintf(stdout, "%s %s\n", std::get<0>(t), std::get<1>(t)); + std::printf("%s %s\n", std::get<0>(t), std::get<1>(t)); TEST_EQUAL(compare_ip_cidr( addr4(std::get<0>(t)), addr4(std::get<1>(t))), std::get<2>(t)); } diff --git a/test/test_fast_extension.cpp b/test/test_fast_extension.cpp index e07f9ac7c..747035477 100644 --- a/test/test_fast_extension.cpp +++ b/test/test_fast_extension.cpp @@ -62,7 +62,7 @@ void log(char const* fmt, ...) vsnprintf(buf, sizeof(buf), fmt, v); va_end(v); - std::fprintf(stderr, "\x1b[1m\x1b[36m%s: %s\x1b[0m\n" + std::printf("\x1b[1m\x1b[36m%s: %s\x1b[0m\n" , time_now_string(), buf); } diff --git a/test/test_fence.cpp b/test/test_fence.cpp index b01dc374a..4f0f9998e 100644 --- a/test/test_fence.cpp +++ b/test/test_fence.cpp @@ -153,7 +153,7 @@ TORRENT_TEST(double_fence) // since we have outstanding jobs, no need // to post anything TEST_CHECK(ret_int == disk_job_fence::fence_post_none); - std::fprintf(stderr, "ret: %d\n", ret_int); + std::printf("ret: %d\n", ret_int); ret = fence.is_blocked(&test_job[9]); TEST_CHECK(ret == true); diff --git a/test/test_ffs.cpp b/test/test_ffs.cpp index f1566d5c3..bf0d85489 100644 --- a/test/test_ffs.cpp +++ b/test/test_ffs.cpp @@ -72,7 +72,7 @@ TORRENT_TEST(count_leading_zeros) for (auto const& t : tests) { - std::fprintf(stderr, "%s\n", t.first); + std::printf("%s\n", t.first); std::uint32_t buf[5]; to_binary(t.first, buf); TEST_EQUAL(aux::count_leading_zeros_sw({buf, 5}), t.second); diff --git a/test/test_file.cpp b/test/test_file.cpp index 1b7d8c3fc..ba4cec88d 100644 --- a/test/test_file.cpp +++ b/test/test_file.cpp @@ -99,7 +99,7 @@ TORRENT_TEST(file_status) TEST_CHECK(!ec); int diff = int(st2.mtime - st1.mtime); - std::fprintf(stdout, "timestamp difference: %d seconds. expected approx. 3 seconds\n" + std::printf("timestamp difference: %d seconds. expected approx. 3 seconds\n" , diff); TEST_CHECK(diff >= 2 && diff <= 4); @@ -110,7 +110,7 @@ TORRENT_TEST(directory) error_code ec; create_directory("file_test_dir", ec); - if (ec) std::fprintf(stdout, "create_directory: %s\n", ec.message().c_str()); + if (ec) std::printf("create_directory: %s\n", ec.message().c_str()); TEST_CHECK(!ec); std::string cwd = current_working_directory(); @@ -125,7 +125,7 @@ TORRENT_TEST(directory) std::string f = i.file(); TEST_CHECK(files.count(f) == 0); files.insert(f); - std::fprintf(stdout, " %s\n", f.c_str()); + std::printf(" %s\n", f.c_str()); } TEST_CHECK(files.count("abc") == 1); @@ -142,13 +142,13 @@ TORRENT_TEST(directory) std::string f = i.file(); TEST_CHECK(files.count(f) == 0); files.insert(f); - std::fprintf(stdout, " %s\n", f.c_str()); + std::printf(" %s\n", f.c_str()); } remove_all("file_test_dir", ec); - if (ec) std::fprintf(stdout, "remove_all: %s\n", ec.message().c_str()); + if (ec) std::printf("remove_all: %s\n", ec.message().c_str()); remove_all("file_test_dir2", ec); - if (ec) std::fprintf(stdout, "remove_all: %s\n", ec.message().c_str()); + if (ec) std::printf("remove_all: %s\n", ec.message().c_str()); } // test path functions @@ -291,20 +291,20 @@ TORRENT_TEST(file) TEST_CHECK(f.open("test_file", file::read_write, ec)); #endif if (ec) - std::fprintf(stdout, "open failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); + std::printf("open failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); TEST_EQUAL(ec, error_code()); - if (ec) std::fprintf(stdout, "%s\n", ec.message().c_str()); + if (ec) std::printf("%s\n", ec.message().c_str()); file::iovec_t b = {(void*)"test", 4}; TEST_EQUAL(f.writev(0, &b, 1, ec), 4); if (ec) - std::fprintf(stdout, "writev failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); + std::printf("writev failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); TEST_CHECK(!ec); char test_buf[5] = {0}; b.iov_base = test_buf; b.iov_len = 4; TEST_EQUAL(f.readv(0, &b, 1, ec), 4); if (ec) - std::fprintf(stdout, "readv failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); + std::printf("readv failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); TEST_EQUAL(ec, error_code()); TEST_CHECK(std::strcmp(test_buf, "test") == 0); f.close(); @@ -321,26 +321,26 @@ TORRENT_TEST(hard_link) file f; TEST_CHECK(f.open("original_file", file::read_write, ec)); if (ec) - std::fprintf(stdout, "open failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); + std::printf("open failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); TEST_EQUAL(ec, error_code()); file::iovec_t b = {(void*)"abcdefghijklmnopqrstuvwxyz", 26}; TEST_EQUAL(f.writev(0, &b, 1, ec), 26); if (ec) - std::fprintf(stdout, "writev failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); + std::printf("writev failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); TEST_EQUAL(ec, error_code()); f.close(); hard_link("original_file", "second_link", ec); if (ec) - std::fprintf(stdout, "hard_link failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); + std::printf("hard_link failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); TEST_EQUAL(ec, error_code()); TEST_CHECK(f.open("second_link", file::read_write, ec)); if (ec) - std::fprintf(stdout, "open failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); + std::printf("open failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); TEST_EQUAL(ec, error_code()); char test_buf[27] = {0}; @@ -348,18 +348,18 @@ TORRENT_TEST(hard_link) b.iov_len = 27; TEST_EQUAL(f.readv(0, &b, 1, ec), 26); if (ec) - std::fprintf(stdout, "readv failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); + std::printf("readv failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); TEST_EQUAL(ec, error_code()); TEST_CHECK(std::strcmp(test_buf, "abcdefghijklmnopqrstuvwxyz") == 0); f.close(); remove("original_file", ec); if (ec) - std::fprintf(stdout, "remove failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); + std::printf("remove failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); remove("second_link", ec); if (ec) - std::fprintf(stdout, "remove failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); + std::printf("remove failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); } TORRENT_TEST(coalesce_buffer) @@ -368,13 +368,13 @@ TORRENT_TEST(coalesce_buffer) file f; TEST_CHECK(f.open("test_file", file::read_write, ec)); if (ec) - std::fprintf(stdout, "open failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); + std::printf("open failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); TEST_EQUAL(ec, error_code()); - if (ec) std::fprintf(stdout, "%s\n", ec.message().c_str()); + if (ec) std::printf("%s\n", ec.message().c_str()); file::iovec_t b[2] = {{(void*)"test", 4}, {(void*)"foobar", 6}}; TEST_EQUAL(f.writev(0, b, 2, ec, file::coalesce_buffers), 4 + 6); if (ec) - std::fprintf(stdout, "writev failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); + std::printf("writev failed: [%s] %s\n", ec.category().name(), ec.message().c_str()); TEST_CHECK(!ec); char test_buf1[5] = {0}; char test_buf2[7] = {0}; @@ -385,7 +385,7 @@ TORRENT_TEST(coalesce_buffer) TEST_EQUAL(f.readv(0, b, 2, ec), 4 + 6); if (ec) { - std::fprintf(stdout, "readv failed: [%s] %s\n" + std::printf("readv failed: [%s] %s\n" , ec.category().name(), ec.message().c_str()); } TEST_EQUAL(ec, error_code()); diff --git a/test/test_file_storage.cpp b/test/test_file_storage.cpp index cfe2743a1..d717141ba 100644 --- a/test/test_file_storage.cpp +++ b/test/test_file_storage.cpp @@ -204,8 +204,8 @@ TORRENT_TEST(file_path_hash) fs.add_file(combine_path("temp_storage", "Foo"), 17); fs.add_file(combine_path("temp_storage", "foo"), 612); - std::fprintf(stderr, "path: %s\n", fs.file_path(0).c_str()); - std::fprintf(stderr, "file: %s\n", fs.file_path(1).c_str()); + std::printf("path: %s\n", fs.file_path(0).c_str()); + std::printf("file: %s\n", fs.file_path(1).c_str()); std::uint32_t file_hash0 = fs.file_path_hash(0, "a"); std::uint32_t file_hash1 = fs.file_path_hash(1, "a"); TEST_EQUAL(file_hash0, file_hash1); diff --git a/test/test_gzip.cpp b/test/test_gzip.cpp index d6b46e8fe..0f6c10e48 100644 --- a/test/test_gzip.cpp +++ b/test/test_gzip.cpp @@ -43,7 +43,7 @@ TORRENT_TEST(zeroes) std::vector zipped; error_code ec; load_file(combine_path("..", "zeroes.gz"), zipped, ec, 1000000); - if (ec) std::fprintf(stderr, "failed to open file: (%d) %s\n", ec.value() + if (ec) std::printf("failed to open file: (%d) %s\n", ec.value() , ec.message().c_str()); TEST_CHECK(!ec); @@ -51,7 +51,7 @@ TORRENT_TEST(zeroes) inflate_gzip(&zipped[0], int(zipped.size()), inflated, 1000000, ec); if (ec) { - std::fprintf(stderr, "failed to unzip: %s\n", ec.message().c_str()); + std::printf("failed to unzip: %s\n", ec.message().c_str()); } TEST_CHECK(!ec); TEST_CHECK(inflated.size() > 0); @@ -64,7 +64,7 @@ TORRENT_TEST(corrupt) std::vector zipped; error_code ec; load_file(combine_path("..", "corrupt.gz"), zipped, ec, 1000000); - if (ec) std::fprintf(stderr, "failed to open file: (%d) %s\n", ec.value() + if (ec) std::printf("failed to open file: (%d) %s\n", ec.value() , ec.message().c_str()); TEST_CHECK(!ec); diff --git a/test/test_http_connection.cpp b/test/test_http_connection.cpp index 79bd7c548..b7e660807 100644 --- a/test/test_http_connection.cpp +++ b/test/test_http_connection.cpp @@ -148,11 +148,11 @@ void write_test_file() error_code ec; file test_file("test_file", file::write_only, ec); TEST_CHECK(!ec); - if (ec) std::fprintf(stdout, "file error: %s\n", ec.message().c_str()); + if (ec) std::printf("file error: %s\n", ec.message().c_str()); file::iovec_t b = { data_buffer, 3216}; test_file.writev(0, &b, 1, ec); TEST_CHECK(!ec); - if (ec) std::fprintf(stdout, "file error: %s\n", ec.message().c_str()); + if (ec) std::printf("file error: %s\n", ec.message().c_str()); test_file.close(); } diff --git a/test/test_ip_voter.cpp b/test/test_ip_voter.cpp index b660f378f..0efc20762 100644 --- a/test/test_ip_voter.cpp +++ b/test/test_ip_voter.cpp @@ -45,12 +45,12 @@ using namespace libtorrent; bool cast_vote(ip_voter& ipv, address ext_ip, address voter) { bool new_ip = ipv.cast_vote(ext_ip, 1, voter); - std::fprintf(stdout, "%15s -> %-15s\n" + std::printf("%15s -> %-15s\n" , print_address(voter).c_str() , print_address(ext_ip).c_str()); if (new_ip) { - std::fprintf(stdout, " \x1b[1mnew external IP: %s\x1b[0m\n" + std::printf(" \x1b[1mnew external IP: %s\x1b[0m\n" , print_address(ipv.external_address()).c_str()); } return new_ip; diff --git a/test/test_magnet.cpp b/test/test_magnet.cpp index ec405a54f..3cd4bf4fe 100644 --- a/test/test_magnet.cpp +++ b/test/test_magnet.cpp @@ -125,7 +125,7 @@ TORRENT_TEST(magnet) "&dht=127.0.0.1:43"; torrent_handle t = s->add_torrent(p, ec); TEST_CHECK(!ec); - if (ec) std::fprintf(stderr, "%s\n", ec.message().c_str()); + if (ec) std::printf("%s\n", ec.message().c_str()); std::vector trackers = t.trackers(); TEST_EQUAL(trackers.size(), 3); @@ -146,7 +146,7 @@ TORRENT_TEST(magnet) "&xt=urn:btih:c352cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"; torrent_handle t2 = s->add_torrent(p, ec); TEST_CHECK(!ec); - if (ec) std::fprintf(stderr, "%s\n", ec.message().c_str()); + if (ec) std::printf("%s\n", ec.message().c_str()); trackers = t2.trackers(); TEST_EQUAL(trackers.size(), 2); @@ -159,24 +159,24 @@ TORRENT_TEST(magnet) "&dn=Ubuntu+11.04+%28Final%29"; torrent_handle t3 = s->add_torrent(p, ec); TEST_CHECK(!ec); - if (ec) std::fprintf(stderr, "%s\n", ec.message().c_str()); + if (ec) std::printf("%s\n", ec.message().c_str()); trackers = t3.trackers(); TEST_EQUAL(trackers.size(), 3); if (trackers.size() > 0) { TEST_EQUAL(trackers[0].url, "udp://tracker.openbittorrent.com:80"); - std::fprintf(stderr, "1: %s\n", trackers[0].url.c_str()); + std::printf("1: %s\n", trackers[0].url.c_str()); } if (trackers.size() > 1) { TEST_EQUAL(trackers[1].url, "udp://tracker.publicbt.com:80"); - std::fprintf(stderr, "2: %s\n", trackers[1].url.c_str()); + std::printf("2: %s\n", trackers[1].url.c_str()); } if (trackers.size() > 2) { TEST_EQUAL(trackers[2].url, "udp://tracker.ccc.de:80"); - std::fprintf(stderr, "3: %s\n", trackers[2].url.c_str()); + std::printf("3: %s\n", trackers[2].url.c_str()); } sha1_hash const ih = t.info_hash(); @@ -191,7 +191,7 @@ TORRENT_TEST(magnet) int ret = bdecode(&buf[0], &buf[0] + buf.size(), session_state2, ec); TEST_CHECK(ret == 0); - std::fprintf(stderr, "session_state\n%s\n", print_entry(session_state2).c_str()); + std::printf("session_state\n%s\n", print_entry(session_state2).c_str()); // make sure settings that haven't been changed from their defaults are not saved TEST_CHECK(session_state2.dict_find("settings") @@ -199,7 +199,7 @@ TORRENT_TEST(magnet) s->load_state(session_state2); -#define CMP_SET(x) std::fprintf(stderr, #x ": %d %d\n"\ +#define CMP_SET(x) std::printf(#x ": %d %d\n"\ , s->get_settings().get_int(settings_pack:: x)\ , pack.get_int(settings_pack:: x)); \ TEST_EQUAL(s->get_settings().get_int(settings_pack:: x), pack.get_int(settings_pack:: x)) @@ -307,7 +307,7 @@ TORRENT_TEST(parse_dht_node) add_torrent_params p; parse_magnet_uri("magnet:?xt=urn:btih:cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd&dn=foo&dht=127.0.0.1:43", p, ec); TEST_CHECK(!ec); - if (ec) std::fprintf(stderr, "%s\n", ec.message().c_str()); + if (ec) std::printf("%s\n", ec.message().c_str()); ec.clear(); TEST_EQUAL(p.dht_nodes.size(), 1); diff --git a/test/test_packet_buffer.cpp b/test/test_packet_buffer.cpp index c04160511..c4bdd9849 100644 --- a/test/test_packet_buffer.cpp +++ b/test/test_packet_buffer.cpp @@ -92,12 +92,12 @@ TORRENT_TEST(insert) { int index = (i + 0xfff0) & 0xffff; pb.insert(index, reinterpret_cast(size_t(index) + 1)); - std::fprintf(stdout, "insert: %u (mask: %x)\n", index, int(pb.capacity() - 1)); + std::printf("insert: %u (mask: %x)\n", index, int(pb.capacity() - 1)); TEST_EQUAL(pb.capacity(), 512); if (i >= 14) { index = (index - 14) & 0xffff; - std::fprintf(stdout, "remove: %u\n", index); + std::printf("remove: %u\n", index); TEST_CHECK(pb.remove(index) == reinterpret_cast(size_t(index) + 1)); TEST_EQUAL(pb.size(), 14); } diff --git a/test/test_part_file.cpp b/test/test_part_file.cpp index f9f9eac6e..4131a7293 100644 --- a/test/test_part_file.cpp +++ b/test/test_part_file.cpp @@ -44,22 +44,22 @@ TORRENT_TEST(part_file) std::string cwd = complete("."); remove_all(combine_path(cwd, "partfile_test_dir"), ec); - if (ec) std::fprintf(stderr, "remove_all: %s\n", ec.message().c_str()); + if (ec) std::printf("remove_all: %s\n", ec.message().c_str()); remove_all(combine_path(cwd, "partfile_test_dir2"), ec); - if (ec) std::fprintf(stderr, "remove_all: %s\n", ec.message().c_str()); + if (ec) std::printf("remove_all: %s\n", ec.message().c_str()); int piece_size = 16 * 0x4000; char buf[1024]; { create_directory(combine_path(cwd, "partfile_test_dir"), ec); - if (ec) std::fprintf(stderr, "create_directory: %s\n", ec.message().c_str()); + if (ec) std::printf("create_directory: %s\n", ec.message().c_str()); create_directory(combine_path(cwd, "partfile_test_dir2"), ec); - if (ec) std::fprintf(stderr, "create_directory: %s\n", ec.message().c_str()); + if (ec) std::printf("create_directory: %s\n", ec.message().c_str()); part_file pf(combine_path(cwd, "partfile_test_dir"), "partfile.parts", 100, piece_size); pf.flush_metadata(ec); - if (ec) std::fprintf(stderr, "flush_metadata: %s\n", ec.message().c_str()); + if (ec) std::printf("flush_metadata: %s\n", ec.message().c_str()); // since we don't have anything in the part file, it will have // not have been created yet @@ -71,17 +71,17 @@ TORRENT_TEST(part_file) file::iovec_t v = {&buf, 1024}; pf.writev(&v, 1, 10, 0, ec); - if (ec) std::fprintf(stderr, "part_file::writev: %s\n", ec.message().c_str()); + if (ec) std::printf("part_file::writev: %s\n", ec.message().c_str()); pf.flush_metadata(ec); - if (ec) std::fprintf(stderr, "flush_metadata: %s\n", ec.message().c_str()); + if (ec) std::printf("flush_metadata: %s\n", ec.message().c_str()); // now wwe should have created the partfile TEST_CHECK(exists(combine_path(combine_path(cwd, "partfile_test_dir"), "partfile.parts"))); pf.move_partfile(combine_path(cwd, "partfile_test_dir2"), ec); TEST_CHECK(!ec); - if (ec) std::fprintf(stderr, "move_partfile: %s\n", ec.message().c_str()); + if (ec) std::printf("move_partfile: %s\n", ec.message().c_str()); TEST_CHECK(!exists(combine_path(combine_path(cwd, "partfile_test_dir"), "partfile.parts"))); TEST_CHECK(exists(combine_path(combine_path(cwd, "partfile_test_dir2"), "partfile.parts"))); @@ -89,7 +89,7 @@ TORRENT_TEST(part_file) memset(buf, 0, sizeof(buf)); pf.readv(&v, 1, 10, 0, ec); - if (ec) std::fprintf(stderr, "part_file::readv: %s\n", ec.message().c_str()); + if (ec) std::printf("part_file::readv: %s\n", ec.message().c_str()); for (int i = 0; i < 1024; ++i) TEST_CHECK(buf[i] == char(i)); @@ -103,7 +103,7 @@ TORRENT_TEST(part_file) file::iovec_t v = {&buf, 1024}; pf.readv(&v, 1, 10, 0, ec); - if (ec) std::fprintf(stderr, "part_file::readv: %s\n", ec.message().c_str()); + if (ec) std::printf("part_file::readv: %s\n", ec.message().c_str()); for (int i = 0; i < 1024; ++i) TEST_CHECK(buf[i] == char(i)); @@ -113,32 +113,32 @@ TORRENT_TEST(part_file) std::string output_filename = combine_path(combine_path(cwd, "partfile_test_dir") , "part_file_test_export"); file output(output_filename, file::read_write, ec); - if (ec) std::fprintf(stderr, "export open file: %s\n", ec.message().c_str()); + if (ec) std::printf("export open file: %s\n", ec.message().c_str()); pf.export_file(output, 10 * piece_size, 1024, ec); - if (ec) std::fprintf(stderr, "export_file: %s\n", ec.message().c_str()); + if (ec) std::printf("export_file: %s\n", ec.message().c_str()); pf.free_piece(10); pf.flush_metadata(ec); - if (ec) std::fprintf(stderr, "flush_metadata: %s\n", ec.message().c_str()); + if (ec) std::printf("flush_metadata: %s\n", ec.message().c_str()); // we just removed the last piece. The partfile does not // contain anything anymore, it should have deleted itself TEST_CHECK(!exists(combine_path(combine_path(cwd, "partfile_test_dir2"), "partfile.parts"), ec)); TEST_CHECK(!ec); - if (ec) std::fprintf(stderr, "exists: %s\n", ec.message().c_str()); + if (ec) std::printf("exists: %s\n", ec.message().c_str()); output.close(); // verify that the exported file is what we expect it to be output.open(output_filename, file::read_only, ec); - if (ec) std::fprintf(stderr, "exported file open: %s\n", ec.message().c_str()); + if (ec) std::printf("exported file open: %s\n", ec.message().c_str()); memset(buf, 0, sizeof(buf)); output.readv(0, &v, 1, ec); - if (ec) std::fprintf(stderr, "exported file read: %s\n", ec.message().c_str()); + if (ec) std::printf("exported file read: %s\n", ec.message().c_str()); for (int i = 0; i < 1024; ++i) TEST_CHECK(buf[i] == char(i)); diff --git a/test/test_pe_crypto.cpp b/test/test_pe_crypto.cpp index def3de0dd..52c9b17f7 100644 --- a/test/test_pe_crypto.cpp +++ b/test/test_pe_crypto.cpp @@ -143,7 +143,7 @@ TORRENT_TEST(rc4) sha1_hash test1_key = hasher("test1_key",8).final(); sha1_hash test2_key = hasher("test2_key",8).final(); - std::fprintf(stderr, "testing RC4 handler\n"); + std::printf("testing RC4 handler\n"); rc4_handler rc41; rc41.set_incoming_key(test2_key); rc41.set_outgoing_key(test1_key); @@ -156,6 +156,6 @@ TORRENT_TEST(rc4) #else TORRENT_TEST(disabled) { - std::fprintf(stderr, "PE test not run because it's disabled\n"); + std::printf("PE test not run because it's disabled\n"); } #endif diff --git a/test/test_peer_list.cpp b/test/test_peer_list.cpp index 38121b306..936a5e247 100644 --- a/test/test_peer_list.cpp +++ b/test/test_peer_list.cpp @@ -517,7 +517,7 @@ TORRENT_TEST(erase_peers) TEST_CHECK(peer); if (peer == nullptr || st.erased.size() > 0) { - std::fprintf(stderr, "unexpected rejection of peer: %s | %d in list. " + std::printf("unexpected rejection of peer: %s | %d in list. " "added peer %p, erased %d peers\n" , print_endpoint(ep).c_str(), p.num_peers(), peer , int(st.erased.size())); diff --git a/test/test_piece_picker.cpp b/test/test_piece_picker.cpp index d49b94b31..3935c8af0 100644 --- a/test/test_piece_picker.cpp +++ b/test/test_piece_picker.cpp @@ -443,12 +443,12 @@ TORRENT_TEST(get_downloaders) p->mark_as_downloading(piece_block(0, 0), &tmp2); - std::fprintf(stdout, "num_peers: %d\n", p->num_peers(piece_block(0, 0))); + std::printf("num_peers: %d\n", p->num_peers(piece_block(0, 0))); TEST_EQUAL(p->num_peers(piece_block(0, 0)), 2); p->abort_download(piece_block(0, 0), &tmp1); - std::fprintf(stdout, "num_peers: %d\n", p->num_peers(piece_block(0, 0))); + std::printf("num_peers: %d\n", p->num_peers(piece_block(0, 0))); TEST_EQUAL(p->num_peers(piece_block(0, 0)), 1); } diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index 973ecb1fd..9abb50401 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -71,9 +71,9 @@ TORRENT_TEST(primitives) int delay = ae.next_announce_in(); TEST_CHECK(delay > last); last = delay; - std::fprintf(stdout, "%d, ", delay); + std::printf("%d, ", delay); } - std::fprintf(stdout, "\n"); + std::printf("\n"); // test error codes TEST_CHECK(error_code(errors::http_error).message() == "HTTP error"); diff --git a/test/test_priority.cpp b/test/test_priority.cpp index 0c0de1bc4..bc3b661f8 100644 --- a/test/test_priority.cpp +++ b/test/test_priority.cpp @@ -237,7 +237,7 @@ void test_transfer(settings_pack const& sett, bool test_deprecated = false) tor2.pause(); wait_for_alert(ses2, torrent_paused_alert::alert_type, "ses2"); - std::fprintf(stderr, "save resume data\n"); + std::printf("save resume data\n"); tor2.save_resume_data(); std::vector resume_data; @@ -258,12 +258,12 @@ void test_transfer(settings_pack const& sett, bool test_deprecated = false) { bencode(std::back_inserter(resume_data) , *alert_cast(a)->resume_data); - std::fprintf(stderr, "saved resume data\n"); + std::printf("saved resume data\n"); goto done; } else if (alert_cast(a)) { - std::fprintf(stderr, "save resume failed\n"); + std::printf("save resume failed\n"); goto done; } if (total_seconds(clock_type::now() - start) > 10) @@ -276,7 +276,7 @@ done: if (resume_data.empty()) return; - std::fprintf(stderr, "%s\n", &resume_data[0]); + std::printf("%s\n", &resume_data[0]); ses2.remove_torrent(tor2); @@ -368,7 +368,7 @@ done: if (peer_disconnects >= 2) { - std::fprintf(stderr, "too many disconnects (%d), exiting\n", peer_disconnects); + std::printf("too many disconnects (%d), exiting\n", peer_disconnects); break; } @@ -377,7 +377,7 @@ done: st2 = tor2.status(); if (!st2.is_seeding) - std::fprintf(stderr, "ses2 failed to reconnect to ses1!\n"); + std::printf("ses2 failed to reconnect to ses1!\n"); TEST_CHECK(st2.is_seeding); sp.push_back(ses1.abort()); diff --git a/test/test_privacy.cpp b/test/test_privacy.cpp index dc0362b9e..66dd6878b 100644 --- a/test/test_privacy.cpp +++ b/test/test_privacy.cpp @@ -90,7 +90,7 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags) // if DHT is disabled, we won't get any requests to it flags &= ~expect_dht_msg; #endif - std::fprintf(stderr, "\n=== TEST == proxy: %s anonymous-mode: %s\n\n", proxy_name[proxy_type], (flags & force_proxy_mode) ? "yes" : "no"); + std::printf("\n=== TEST == proxy: %s anonymous-mode: %s\n\n", proxy_name[proxy_type], (flags & force_proxy_mode) ? "yes" : "no"); int http_port = start_web_server(); int udp_port = start_udp_tracker(); int dht_port = start_dht(); @@ -227,7 +227,7 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags) if (flags & expect_http_reject) TEST_CHECK(std::find(rejected_trackers.begin(), rejected_trackers.end(), http_tracker_url) != rejected_trackers.end()); - std::fprintf(stderr, "%s: ~session\n", time_now_string()); + std::printf("%s: ~session\n", time_now_string()); session_proxy pr = s->abort(); delete s; diff --git a/test/test_random.cpp b/test/test_random.cpp index 25b16d053..d31668a0d 100644 --- a/test/test_random.cpp +++ b/test/test_random.cpp @@ -57,7 +57,7 @@ TORRENT_TEST(random) { const int expected = repetitions / 256; // expect each bucket to be within 15% of the expected value - std::fprintf(stderr, "%d: %f\n", i, float(buckets[i] - expected) * 100.f / expected); + std::printf("%d: %f\n", i, float(buckets[i] - expected) * 100.f / expected); TEST_CHECK(abs(buckets[i] - expected) < expected / 6); } } diff --git a/test/test_read_piece.cpp b/test/test_read_piece.cpp index 060bff56e..826aef4eb 100644 --- a/test/test_read_piece.cpp +++ b/test/test_read_piece.cpp @@ -49,20 +49,20 @@ void test_read_piece(int flags) using namespace libtorrent; namespace lt = libtorrent; - std::fprintf(stderr, "==== TEST READ PIECE =====\n"); + std::printf("==== TEST READ PIECE =====\n"); // in case the previous run was terminated error_code ec; remove_all("tmp1_read_piece", ec); - if (ec) std::fprintf(stderr, "ERROR: removing tmp1_read_piece: (%d) %s\n" + if (ec) std::printf("ERROR: removing tmp1_read_piece: (%d) %s\n" , ec.value(), ec.message().c_str()); create_directory("tmp1_read_piece", ec); - if (ec) std::fprintf(stderr, "ERROR: creating directory tmp1_read_piece: (%d) %s\n" + if (ec) std::printf("ERROR: creating directory tmp1_read_piece: (%d) %s\n" , ec.value(), ec.message().c_str()); create_directory(combine_path("tmp1_read_piece", "test_torrent"), ec); - if (ec) std::fprintf(stderr, "ERROR: creating directory test_torrent: (%d) %s\n" + if (ec) std::printf("ERROR: creating directory test_torrent: (%d) %s\n" , ec.value(), ec.message().c_str()); file_storage fs; @@ -79,14 +79,14 @@ void test_read_piece(int flags) // calculate the hash for all pieces set_piece_hashes(t, "tmp1_read_piece", ec); - if (ec) std::fprintf(stderr, "ERROR: set_piece_hashes: (%d) %s\n" + if (ec) std::printf("ERROR: set_piece_hashes: (%d) %s\n" , ec.value(), ec.message().c_str()); std::vector buf; bencode(std::back_inserter(buf), t.generate()); auto ti = std::make_shared(&buf[0], int(buf.size()), ec); - std::fprintf(stderr, "generated torrent: %s tmp1_read_piece/test_torrent\n" + std::printf("generated torrent: %s tmp1_read_piece/test_torrent\n" , aux::to_hex(ti->info_hash()).c_str()); const int mask = alert::all_categories @@ -143,7 +143,7 @@ void test_read_piece(int flags) } remove_all("tmp1_read_piece", ec); - if (ec) std::fprintf(stderr, "ERROR: removing tmp1_read_piece: (%d) %s\n" + if (ec) std::printf("ERROR: removing tmp1_read_piece: (%d) %s\n" , ec.value(), ec.message().c_str()); } diff --git a/test/test_recheck.cpp b/test/test_recheck.cpp index 2cdc1f399..9cf94d81c 100644 --- a/test/test_recheck.cpp +++ b/test/test_recheck.cpp @@ -60,7 +60,7 @@ void wait_for_complete(lt::session& ses, torrent_handle h) { print_alerts(ses, "ses1"); torrent_status st = h.status(); - std::fprintf(stderr, "%f s - %f %%\n" + std::printf("%f s - %f %%\n" , total_milliseconds(clock_type::now() - last_change) / 1000.f , st.progress_ppm / 10000.f); if (st.progress_ppm == 1000000) return; @@ -87,7 +87,7 @@ TORRENT_TEST(recheck) sett.set_bool(settings_pack::enable_dht, false); lt::session ses1(sett); create_directory("tmp1_recheck", ec); - if (ec) std::fprintf(stderr, "create_directory: %s\n", ec.message().c_str()); + if (ec) std::printf("create_directory: %s\n", ec.message().c_str()); std::ofstream file("tmp1_recheck/temporary"); std::shared_ptr t = ::create_torrent(&file, "temporary", 4 * 1024 * 1024 , 7, false); @@ -100,7 +100,7 @@ TORRENT_TEST(recheck) param.save_path = "tmp1_recheck"; param.flags |= add_torrent_params::flag_seed_mode; torrent_handle tor1 = ses1.add_torrent(param, ec); - if (ec) std::fprintf(stderr, "add_torrent: %s\n", ec.message().c_str()); + if (ec) std::printf("add_torrent: %s\n", ec.message().c_str()); wait_for_listen(ses1, "ses1"); diff --git a/test/test_remap_files.cpp b/test/test_remap_files.cpp index edcbd1d73..21d971a56 100644 --- a/test/test_remap_files.cpp +++ b/test/test_remap_files.cpp @@ -169,7 +169,7 @@ void test_remap_files(storage_mode_t storage_mode = storage_mode_sparse) print_alerts(ses, "ses"); } - std::fprintf(stderr, "%s\n", name.c_str()); + std::printf("%s\n", name.c_str()); TEST_CHECK(exists(name)); } @@ -178,7 +178,7 @@ void test_remap_files(storage_mode_t storage_mode = storage_mode_sparse) torrent_status st = tor1.status(); TEST_EQUAL(st.is_seeding, true); - std::fprintf(stderr, "\ntesting force recheck\n\n"); + std::printf("\ntesting force recheck\n\n"); // test force rechecking a seeding torrent with remapped files tor1.force_recheck(); diff --git a/test/test_resolve_links.cpp b/test/test_resolve_links.cpp index 0a636559c..c44b18ed7 100644 --- a/test/test_resolve_links.cpp +++ b/test/test_resolve_links.cpp @@ -99,14 +99,14 @@ TORRENT_TEST(resolve_links) test_torrent_t const& e = test_torrents[i]; std::string p = combine_path(path, e.filename1) + ".torrent"; - std::fprintf(stdout, "loading %s\n", p.c_str()); + std::printf("loading %s\n", p.c_str()); std::shared_ptr ti1 = std::make_shared(p); p = combine_path(path, e.filename2) + ".torrent"; - std::fprintf(stdout, "loading %s\n", p.c_str()); + std::printf("loading %s\n", p.c_str()); std::shared_ptr ti2 = std::make_shared(p); - std::fprintf(stdout, "resolving\n"); + std::printf("resolving\n"); resolve_links l(ti1); l.match(ti2, "."); @@ -122,7 +122,7 @@ TORRENT_TEST(resolve_links) for (int i = 0; i < int(links.size()); ++i) { TORRENT_ASSERT(i < fs.num_files()); - std::fprintf(stdout, "%*s --> %s : %d\n" + std::printf("%*s --> %s : %d\n" , int(fs.file_name(i).size()) , fs.file_name(i).data() , links[i].ti ? aux::to_hex(links[i].ti->info_hash()).c_str() @@ -160,7 +160,7 @@ TORRENT_TEST(range_lookup_duplicated_files) auto ti1 = std::make_shared(&tmp1[0], int(tmp1.size()), ec); auto ti2 = std::make_shared(&tmp2[0], int(tmp2.size()), ec); - std::fprintf(stderr, "resolving\n"); + std::printf("resolving\n"); resolve_links l(ti1); l.match(ti2, "."); diff --git a/test/test_resume.cpp b/test/test_resume.cpp index 2b8621b72..4bb26234e 100644 --- a/test/test_resume.cpp +++ b/test/test_resume.cpp @@ -126,7 +126,7 @@ std::vector generate_resume_data(torrent_info* ti std::vector ret; bencode(back_inserter(ret), rd); - std::fprintf(stderr, "%s\n", rd.to_string().c_str()); + std::printf("%s\n", rd.to_string().c_str()); return ret; } @@ -216,7 +216,7 @@ void test_piece_priorities(bool test_deprecated = false) TEST_CHECK(a); if (save_resume_data_alert const* ra = alert_cast(a)) { - std::fprintf(stderr, "%s\n", ra->resume_data->to_string().c_str()); + std::printf("%s\n", ra->resume_data->to_string().c_str()); entry::string_type prios = (*ra->resume_data)["piece_priority"].string(); TEST_EQUAL(int(prios.size()), ti->num_pieces()); TEST_EQUAL(prios[0], '\0'); @@ -616,7 +616,7 @@ TORRENT_TEST(paused_deprecated) TORRENT_TEST(url_seed_resume_data_deprecated) { // merge url seeds with resume data - std::fprintf(stderr, "flags: merge_resume_http_seeds\n"); + std::printf("flags: merge_resume_http_seeds\n"); lt::session ses(settings()); torrent_handle h = test_resume_flags(ses, add_torrent_params::flag_merge_resume_http_seeds, "", "", true); @@ -639,7 +639,7 @@ TORRENT_TEST(url_seed_resume_data_deprecated) TORRENT_TEST(resume_override_torrent_deprecated) { // resume data overrides the .torrent_file - std::fprintf(stderr, "flags: no merge_resume_http_seed\n"); + std::printf("flags: no merge_resume_http_seed\n"); lt::session ses(settings()); torrent_handle h = test_resume_flags(ses, add_torrent_params::flag_merge_resume_trackers, "", "", true); @@ -695,7 +695,7 @@ TORRENT_TEST(file_priorities_seed_mode) void test_zero_file_prio(bool test_deprecated = false) { - std::fprintf(stderr, "test_file_prio\n"); + std::printf("test_file_prio\n"); lt::session ses(settings()); std::shared_ptr ti = generate_torrent(); @@ -761,7 +761,7 @@ TORRENT_TEST(zero_file_prio) void test_seed_mode(bool const file_prio, bool const pieces_have, bool const piece_prio , bool const all_files_zero = false, bool const test_deprecated = false) { - std::fprintf(stderr, "test_seed_mode file_prio: %d pieces_have: %d piece_prio: %d\n" + std::printf("test_seed_mode file_prio: %d pieces_have: %d piece_prio: %d\n" , file_prio, pieces_have, piece_prio); lt::session ses(settings()); @@ -925,7 +925,7 @@ TORRENT_TEST(resume_save_load_resume) entry::list_type& l = e["file_priority"].list(); entry::list_type::iterator i = l.begin(); - std::fprintf(stderr, "%s\n", e.to_string().c_str()); + std::printf("%s\n", e.to_string().c_str()); TEST_EQUAL(l.size(), 3); TEST_EQUAL(*i++, 1); diff --git a/test/test_sha1_hash.cpp b/test/test_sha1_hash.cpp index 6eb686a75..7c519e398 100644 --- a/test/test_sha1_hash.cpp +++ b/test/test_sha1_hash.cpp @@ -140,7 +140,7 @@ TORRENT_TEST(count_leading_zeroes) for (auto const& t : tests) { - std::fprintf(stderr, "%s\n", t.first); + std::printf("%s\n", t.first); TEST_EQUAL(to_hash(t.first).count_leading_zeroes(), t.second); } } diff --git a/test/test_ssl.cpp b/test/test_ssl.cpp index 5aa6b150c..6782de469 100644 --- a/test/test_ssl.cpp +++ b/test/test_ssl.cpp @@ -105,7 +105,7 @@ bool on_alert(alert const* a) if (strcmp(e->error.category().name(), boost::asio::error::get_ssl_category().name()) == 0) ++ssl_peer_disconnects; - std::fprintf(stderr, "--- peer_errors: %d ssl_disconnects: %d\n" + std::printf("--- peer_errors: %d ssl_disconnects: %d\n" , peer_errors, ssl_peer_disconnects); } @@ -117,7 +117,7 @@ bool on_alert(alert const* a) if (strcmp(e->error.category().name(), boost::asio::error::get_ssl_category().name()) == 0) ++ssl_peer_disconnects; - std::fprintf(stderr, "--- peer_errors: %d ssl_disconnects: %d\n" + std::printf("--- peer_errors: %d ssl_disconnects: %d\n" , peer_errors, ssl_peer_disconnects); } return false; @@ -133,7 +133,7 @@ void test_ssl(int test_idx, bool use_utp) test_config_t const& test = test_config[test_idx]; - std::fprintf(stderr, "\n%s TEST: %s Protocol: %s\n\n", time_now_string(), test.name, use_utp ? "uTP": "TCP"); + std::printf("\n%s TEST: %s Protocol: %s\n\n", time_now_string(), test.name, use_utp ? "uTP": "TCP"); // in case the previous run was terminated error_code ec; @@ -230,7 +230,7 @@ void test_ssl(int test_idx, bool use_utp) // connect the peers after setting the certificates if (test.use_ssl_ports == false) port += 20; - std::fprintf(stderr, "\n\n%s: ses1: connecting peer port: %d\n\n\n" + std::printf("\n\n%s: ses1: connecting peer port: %d\n\n\n" , time_now_string(), port); tor1.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec) , port)); @@ -262,7 +262,7 @@ void test_ssl(int test_idx, bool use_utp) if (peer_disconnects >= 2) { - std::fprintf(stderr, "too many disconnects (%d), breaking\n", peer_disconnects); + std::printf("too many disconnects (%d), breaking\n", peer_disconnects); break; } @@ -284,15 +284,15 @@ void test_ssl(int test_idx, bool use_utp) std::this_thread::sleep_for(lt::milliseconds(100)); } - std::fprintf(stderr, "peer_errors: %d expected_errors: %d\n" + std::printf("peer_errors: %d expected_errors: %d\n" , peer_errors, test.peer_errors); TEST_EQUAL(peer_errors > 0, test.peer_errors > 0); - std::fprintf(stderr, "ssl_disconnects: %d expected: %d\n", ssl_peer_disconnects, test.ssl_disconnects); + std::printf("ssl_disconnects: %d expected: %d\n", ssl_peer_disconnects, test.ssl_disconnects); TEST_EQUAL(ssl_peer_disconnects > 0, test.ssl_disconnects > 0); - std::fprintf(stderr, "%s: EXPECT: %s\n", time_now_string(), test.expected_to_complete ? "SUCCEESS" : "FAILURE"); - std::fprintf(stderr, "%s: RESULT: %s\n", time_now_string(), tor2.status().is_seeding ? "SUCCEESS" : "FAILURE"); + std::printf("%s: EXPECT: %s\n", time_now_string(), test.expected_to_complete ? "SUCCEESS" : "FAILURE"); + std::printf("%s: RESULT: %s\n", time_now_string(), tor2.status().is_seeding ? "SUCCEESS" : "FAILURE"); TEST_EQUAL(tor2.status().is_seeding, test.expected_to_complete); // this allows shutting down the sessions in parallel @@ -348,19 +348,19 @@ bool try_connect(libtorrent::session& ses1, int port { using boost::asio::ssl::context; - std::fprintf(stderr, "\nMALICIOUS PEER TEST: "); - if (flags & invalid_certificate) std::fprintf(stderr, "invalid-certificate "); - else if (flags & valid_certificate) std::fprintf(stderr, "valid-certificate "); - else std::fprintf(stderr, "no-certificate "); + std::printf("\nMALICIOUS PEER TEST: "); + if (flags & invalid_certificate) std::printf("invalid-certificate "); + else if (flags & valid_certificate) std::printf("valid-certificate "); + else std::printf("no-certificate "); - if (flags & invalid_sni_hash) std::fprintf(stderr, "invalid-SNI-hash "); - else if (flags & valid_sni_hash) std::fprintf(stderr, "valid-SNI-hash "); - else std::fprintf(stderr, "no-SNI-hash "); + if (flags & invalid_sni_hash) std::printf("invalid-SNI-hash "); + else if (flags & valid_sni_hash) std::printf("valid-SNI-hash "); + else std::printf("no-SNI-hash "); - if (flags & valid_bittorrent_hash) std::fprintf(stderr, "valid-bittorrent-hash "); - else std::fprintf(stderr, "invalid-bittorrent-hash "); + if (flags & valid_bittorrent_hash) std::printf("valid-bittorrent-hash "); + else std::printf("invalid-bittorrent-hash "); - std::fprintf(stderr, " port: %d\n", port); + std::printf(" port: %d\n", port); error_code ec; boost::asio::io_service ios; @@ -379,7 +379,7 @@ bool try_connect(libtorrent::session& ses1, int port ctx.set_verify_mode(context::verify_none, ec); if (ec) { - std::fprintf(stderr, "Failed to set SSL verify mode: %s\n" + std::printf("Failed to set SSL verify mode: %s\n" , ec.message().c_str()); TEST_CHECK(!ec); return false; @@ -399,38 +399,38 @@ bool try_connect(libtorrent::session& ses1, int port if (flags & (valid_certificate | invalid_certificate)) { - std::fprintf(stderr, "set_password_callback\n"); + std::printf("set_password_callback\n"); ctx.set_password_callback(std::bind(&password_callback, _1, _2, "test"), ec); if (ec) { - std::fprintf(stderr, "Failed to set certificate password callback: %s\n" + std::printf("Failed to set certificate password callback: %s\n" , ec.message().c_str()); TEST_CHECK(!ec); return false; } - std::fprintf(stderr, "use_certificate_file \"%s\"\n", certificate.c_str()); + std::printf("use_certificate_file \"%s\"\n", certificate.c_str()); ctx.use_certificate_file(certificate, context::pem, ec); if (ec) { - std::fprintf(stderr, "Failed to set certificate file: %s\n" + std::printf("Failed to set certificate file: %s\n" , ec.message().c_str()); TEST_CHECK(!ec); return false; } - std::fprintf(stderr, "use_private_key_file \"%s\"\n", private_key.c_str()); + std::printf("use_private_key_file \"%s\"\n", private_key.c_str()); ctx.use_private_key_file(private_key, context::pem, ec); if (ec) { - std::fprintf(stderr, "Failed to set private key: %s\n" + std::printf("Failed to set private key: %s\n" , ec.message().c_str()); TEST_CHECK(!ec); return false; } - std::fprintf(stderr, "use_tmp_dh_file \"%s\"\n", dh_params.c_str()); + std::printf("use_tmp_dh_file \"%s\"\n", dh_params.c_str()); ctx.use_tmp_dh_file(dh_params, ec); if (ec) { - std::fprintf(stderr, "Failed to set DH params: %s\n" + std::printf("Failed to set DH params: %s\n" , ec.message().c_str()); TEST_CHECK(!ec); return false; @@ -439,14 +439,14 @@ bool try_connect(libtorrent::session& ses1, int port boost::asio::ssl::stream ssl_sock(ios, ctx); - std::fprintf(stderr, "connecting 127.0.0.1:%d\n", port); + std::printf("connecting 127.0.0.1:%d\n", port); ssl_sock.lowest_layer().connect(tcp::endpoint( address_v4::from_string("127.0.0.1"), port), ec); print_alerts(ses1, "ses1", true, true, true, &on_alert); if (ec) { - std::fprintf(stderr, "Failed to connect: %s\n" + std::printf("Failed to connect: %s\n" , ec.message().c_str()); TEST_CHECK(!ec); return false; @@ -455,7 +455,7 @@ bool try_connect(libtorrent::session& ses1, int port if (flags & valid_sni_hash) { std::string name = to_hex(t->info_hash().to_string()); - std::fprintf(stderr, "SNI: %s\n", name.c_str()); + std::printf("SNI: %s\n", name.c_str()); SSL_set_tlsext_host_name(ssl_sock.native_handle(), name.c_str()); } else if (flags & invalid_sni_hash) @@ -466,17 +466,17 @@ bool try_connect(libtorrent::session& ses1, int port for (int i = 0; i < 40; ++i) name += hex_alphabet[rand() % 16]; - std::fprintf(stderr, "SNI: %s\n", name.c_str()); + std::printf("SNI: %s\n", name.c_str()); SSL_set_tlsext_host_name(ssl_sock.native_handle(), name.c_str()); } - std::fprintf(stderr, "SSL handshake\n"); + std::printf("SSL handshake\n"); ssl_sock.handshake(boost::asio::ssl::stream_base::client, ec); print_alerts(ses1, "ses1", true, true, true, &on_alert); if (ec) { - std::fprintf(stderr, "Failed SSL handshake: %s\n" + std::printf("Failed SSL handshake: %s\n" , ec.message().c_str()); return false; } @@ -501,40 +501,40 @@ bool try_connect(libtorrent::session& ses1, int port // fill in the peer-id std::generate(handshake + 48, handshake + 68, &rand); - std::fprintf(stderr, "bittorrent handshake\n"); + std::printf("bittorrent handshake\n"); boost::asio::write(ssl_sock, boost::asio::buffer(handshake, (sizeof(handshake) - 1)), ec); print_alerts(ses1, "ses1", true, true, true, &on_alert); if (ec) { - std::fprintf(stderr, "failed to write bittorrent handshake: %s\n" + std::printf("failed to write bittorrent handshake: %s\n" , ec.message().c_str()); return false; } char buf[68]; - std::fprintf(stderr, "read bittorrent handshake\n"); + std::printf("read bittorrent handshake\n"); boost::asio::read(ssl_sock, boost::asio::buffer(buf, sizeof(buf)), ec); print_alerts(ses1, "ses1", true, true, true, &on_alert); if (ec) { - std::fprintf(stderr, "failed to read bittorrent handshake: %s\n" + std::printf("failed to read bittorrent handshake: %s\n" , ec.message().c_str()); return false; } if (memcmp(buf, "\x13" "BitTorrent protocol", 20) != 0) { - std::fprintf(stderr, "invalid bittorrent handshake\n"); + std::printf("invalid bittorrent handshake\n"); return false; } if (memcmp(buf + 28, &t->info_hash()[0], 20) != 0) { - std::fprintf(stderr, "invalid info-hash in bittorrent handshake\n"); + std::printf("invalid info-hash in bittorrent handshake\n"); return false; } - std::fprintf(stderr, "successfully connected over SSL and shook hand over bittorrent\n"); + std::printf("successfully connected over SSL and shook hand over bittorrent\n"); return true; } diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 43c708d85..62ee58dff 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -93,7 +93,7 @@ void on_check_resume_data(disk_io_job const* j, bool* done) void print_error(char const* call, int ret, storage_error const& ec) { - std::fprintf(stderr, "%s: %s() returned: %d error: \"%s\" in file: %d operation: %d\n" + std::printf("%s: %s() returned: %d error: \"%s\" in file: %d operation: %d\n" , time_now_string(), call, ret, ec.ec.message().c_str(), ec.file, ec.operation); } @@ -140,7 +140,7 @@ std::shared_ptr setup_torrent(file_storage& fs if (ec) { - std::fprintf(stderr, "torrent_info constructor failed: %s\n" + std::printf("torrent_info constructor failed: %s\n" , ec.message().c_str()); } @@ -158,7 +158,7 @@ std::shared_ptr setup_torrent(file_storage& fs if (se) { TEST_ERROR(se.ec.message().c_str()); - std::fprintf(stderr, "default_storage::initialize %s: %d\n", se.ec.message().c_str(), int(se.file)); + std::printf("default_storage::initialize %s: %d\n", se.ec.message().c_str(), int(se.file)); } return s; @@ -357,7 +357,7 @@ void test_remove(std::string const& test_path, bool unbuffered) if (se) { TEST_ERROR(se.ec.message().c_str()); - std::fprintf(stderr, "default_storage::delete_files %s: %d\n", se.ec.message().c_str(), int(se.file)); + std::printf("default_storage::delete_files %s: %d\n", se.ec.message().c_str(), int(se.file)); } TEST_CHECK(!exists(combine_path(test_path, "temp_storage"))); @@ -395,7 +395,7 @@ void test_rename(std::string const& test_path) s->rename_file(0, "new_filename", se); if (se.ec) { - std::fprintf(stderr, "default_storage::rename_file failed: %s\n" + std::printf("default_storage::rename_file failed: %s\n" , se.ec.message().c_str()); } TEST_CHECK(!se.ec); @@ -528,7 +528,7 @@ void run_test(bool unbuffered) // make sure the files have the correct size std::string base = combine_path(test_path, "temp_storage"); - std::fprintf(stderr, "base = \"%s\"\n", base.c_str()); + std::printf("base = \"%s\"\n", base.c_str()); TEST_EQUAL(file_size(combine_path(base, "test1.tmp")), 17); TEST_EQUAL(file_size(combine_path(base, "test2.tmp")), 612); @@ -1265,7 +1265,7 @@ void delete_dirs(std::string path) remove_all(path, ec); if (ec && ec != boost::system::errc::no_such_file_or_directory) { - std::fprintf(stderr, "remove_all \"%s\": %s\n" + std::printf("remove_all \"%s\": %s\n" , path.c_str(), ec.message().c_str()); } TEST_CHECK(!exists(path)); diff --git a/test/test_string.cpp b/test/test_string.cpp index 47fb2a13c..004c28c30 100644 --- a/test/test_string.cpp +++ b/test/test_string.cpp @@ -197,7 +197,7 @@ TORRENT_TEST(escape_string) error_code ec; TEST_CHECK(unescape_string(escape_path(test_string), ec) == test_string); TEST_CHECK(!ec); - if (ec) std::fprintf(stderr, "%s\n", ec.message().c_str()); + if (ec) std::printf("%s\n", ec.message().c_str()); // need_encoding char const* test_string2 = "!@$&()-_/,.%?"; @@ -278,7 +278,7 @@ void test_parse_interface(char const* input , std::vector expected , std::string output) { - std::fprintf(stderr, "parse interface: %s\n", input); + std::printf("parse interface: %s\n", input); auto const list = parse_listen_interfaces(input); TEST_EQUAL(list.size(), expected.size()); if (list.size() == expected.size()) diff --git a/test/test_threads.cpp b/test/test_threads.cpp index b620dfd05..f6642567c 100644 --- a/test/test_threads.cpp +++ b/test/test_threads.cpp @@ -45,11 +45,11 @@ using namespace libtorrent; void fun(std::condition_variable* s, std::mutex* m, int* waiting, int i) { - std::fprintf(stdout, "thread %d waiting\n", i); + std::printf("thread %d waiting\n", i); std::unique_lock l(*m); *waiting += 1; s->wait(l); - std::fprintf(stdout, "thread %d done\n", i); + std::printf("thread %d done\n", i); } void increment(std::condition_variable* s, std::mutex* m, int* waiting, std::atomic* c) diff --git a/test/test_torrent.cpp b/test/test_torrent.cpp index 7f8f5266f..adc7748d3 100644 --- a/test/test_torrent.cpp +++ b/test/test_torrent.cpp @@ -73,7 +73,7 @@ void test_running_torrent(std::shared_ptr info, std::int64_t file_ torrent_handle h = ses.add_torrent(p, ec); if (ec) { - std::fprintf(stdout, "add_torrent: %s\n", ec.message().c_str()); + std::printf("add_torrent: %s\n", ec.message().c_str()); return; } diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index c43ca3cb7..0a80ea5e7 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -495,70 +495,70 @@ TORRENT_TEST(verify_encoding) // valid 2-byte sequence test = "filename\xc2\xa1"; TEST_CHECK(verify_encoding(test)); - std::fprintf(stdout, "%s\n", test.c_str()); + std::printf("%s\n", test.c_str()); TEST_CHECK(test == "filename\xc2\xa1"); // truncated 2-byte sequence test = "filename\xc2"; TEST_CHECK(!verify_encoding(test)); - std::fprintf(stdout, "%s\n", test.c_str()); + std::printf("%s\n", test.c_str()); TEST_CHECK(test == "filename_"); // valid 3-byte sequence test = "filename\xe2\x9f\xb9"; TEST_CHECK(verify_encoding(test)); - std::fprintf(stdout, "%s\n", test.c_str()); + std::printf("%s\n", test.c_str()); TEST_CHECK(test == "filename\xe2\x9f\xb9"); // truncated 3-byte sequence test = "filename\xe2\x9f"; TEST_CHECK(!verify_encoding(test)); - std::fprintf(stdout, "%s\n", test.c_str()); + std::printf("%s\n", test.c_str()); TEST_CHECK(test == "filename_"); // truncated 3-byte sequence test = "filename\xe2"; TEST_CHECK(!verify_encoding(test)); - std::fprintf(stdout, "%s\n", test.c_str()); + std::printf("%s\n", test.c_str()); TEST_CHECK(test == "filename_"); // valid 4-byte sequence test = "filename\xf0\x9f\x92\x88"; TEST_CHECK(verify_encoding(test)); - std::fprintf(stdout, "%s\n", test.c_str()); + std::printf("%s\n", test.c_str()); TEST_CHECK(test == "filename\xf0\x9f\x92\x88"); // truncated 4-byte sequence test = "filename\xf0\x9f\x92"; TEST_CHECK(!verify_encoding(test)); - std::fprintf(stdout, "%s\n", test.c_str()); + std::printf("%s\n", test.c_str()); TEST_CHECK(test == "filename_"); // 5-byte utf-8 sequence (not allowed) test = "filename\xf8\x9f\x9f\x9f\x9f""foobar"; TEST_CHECK(!verify_encoding(test)); - std::fprintf(stdout, "%s\n", test.c_str()); + std::printf("%s\n", test.c_str()); TEST_CHECK(test == "filename_____foobar"); // redundant (overlong) 2-byte sequence // ascii code 0x2e encoded with a leading 0 test = "filename\xc0\xae"; TEST_CHECK(!verify_encoding(test)); - std::fprintf(stdout, "%s\n", test.c_str()); + std::printf("%s\n", test.c_str()); TEST_CHECK(test == "filename__"); // redundant (overlong) 3-byte sequence // ascii code 0x2e encoded with two leading 0s test = "filename\xe0\x80\xae"; TEST_CHECK(!verify_encoding(test)); - std::fprintf(stdout, "%s\n", test.c_str()); + std::printf("%s\n", test.c_str()); TEST_CHECK(test == "filename___"); // redundant (overlong) 4-byte sequence // ascii code 0x2e encoded with three leading 0s test = "filename\xf0\x80\x80\xae"; TEST_CHECK(!verify_encoding(test)); - std::fprintf(stdout, "%s\n", test.c_str()); + std::printf("%s\n", test.c_str()); TEST_CHECK(test == "filename____"); } @@ -610,12 +610,12 @@ TORRENT_TEST(parse_torrents) std::string root_dir = parent_path(current_working_directory()); for (int i = 0; i < int(sizeof(test_torrents)/sizeof(test_torrents[0])); ++i) { - std::fprintf(stdout, "loading %s\n", test_torrents[i].file); + std::printf("loading %s\n", test_torrents[i].file); std::string filename = combine_path(combine_path(root_dir, "test_torrents") , test_torrents[i].file); auto ti = std::make_shared(filename, ec); TEST_CHECK(!ec); - if (ec) std::fprintf(stdout, " loading(\"%s\") -> failed %s\n", filename.c_str() + if (ec) std::printf(" loading(\"%s\") -> failed %s\n", filename.c_str() , ec.message().c_str()); 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 flags = fs.file_flags(i); sha1_hash const ih = fs.hash(i); - std::fprintf(stdout, " %11" PRId64 " %c%c%c%c [ %4d, %4d ] %7u %s %s %s%s\n" + std::printf(" %11" PRId64 " %c%c%c%c [ %4d, %4d ] %7u %s %s %s%s\n" , fs.file_size(i) , (flags & file_storage::flag_pad_file)?'p':'-' , (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) { error_code ec; - std::fprintf(stdout, "loading %s\n", test_error_torrents[i].file); + std::printf("loading %s\n", test_error_torrents[i].file); auto ti = std::make_shared(combine_path( combine_path(root_dir, "test_torrents"), test_error_torrents[i].file), ec); - std::fprintf(stdout, "E: \"%s\"\nexpected: \"%s\"\n", ec.message().c_str() + std::printf("E: \"%s\"\nexpected: \"%s\"\n", ec.message().c_str() , test_error_torrents[i].error.message().c_str()); 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); convert_path_to_posix(p); - std::fprintf(stdout, "%s == %s\n", p.c_str(), filenames[test_case][i]); + std::printf("%s == %s\n", p.c_str(), 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); convert_path_to_posix(p); TEST_EQUAL(p, expected_files[i]); - std::fprintf(stdout, "%s\n", p.c_str()); + std::printf("%s\n", p.c_str()); TEST_EQUAL(a->files().hash(i), file_hashes[i]); } @@ -921,7 +921,7 @@ TORRENT_TEST(copy) std::string p = b->files().file_path(i); convert_path_to_posix(p); TEST_EQUAL(p, expected_files[i]); - std::fprintf(stdout, "%s\n", p.c_str()); + std::printf("%s\n", p.c_str()); TEST_EQUAL(b->files().hash(i), file_hashes[i]); } diff --git a/test/test_tracker.cpp b/test/test_tracker.cpp index 72e1f1bf7..6447f99ef 100644 --- a/test/test_tracker.cpp +++ b/test/test_tracker.cpp @@ -356,7 +356,7 @@ TORRENT_TEST(udp_tracker) break; std::this_thread::sleep_for(lt::milliseconds(100)); - std::fprintf(stderr, "UDP: %d / %d\n", int(num_udp_announces()) + std::printf("UDP: %d / %d\n", int(num_udp_announces()) , int(prev_udp_announces) + 1); } @@ -376,13 +376,13 @@ TORRENT_TEST(udp_tracker) break; std::this_thread::sleep_for(lt::milliseconds(100)); - std::fprintf(stderr, "UDP: %d / %d\n", int(num_udp_announces()) + std::printf("UDP: %d / %d\n", int(num_udp_announces()) , int(prev_udp_announces) + 1); } - std::fprintf(stderr, "destructing session\n"); + std::printf("destructing session\n"); s.reset(); - std::fprintf(stderr, "done\n"); + std::printf("done\n"); // we should have announced the stopped event now TEST_EQUAL(num_udp_announces(), prev_udp_announces + 2); @@ -454,13 +454,13 @@ TORRENT_TEST(http_peers) TEST_EQUAL(expected_peers.count(i->ip), 1); } - std::fprintf(stderr, "destructing session\n"); + std::printf("destructing session\n"); s.reset(); - std::fprintf(stderr, "done\n"); + std::printf("done\n"); - std::fprintf(stderr, "stop_web_server\n"); + std::printf("stop_web_server\n"); stop_web_server(); - std::fprintf(stderr, "done\n"); + std::printf("done\n"); } TORRENT_TEST(current_tracker) @@ -513,9 +513,9 @@ TORRENT_TEST(current_tracker) status = h.status(); TEST_CHECK(status.current_tracker.empty()); - std::fprintf(stderr, "destructing session\n"); + std::printf("destructing session\n"); s.reset(); - std::fprintf(stderr, "done\n"); + std::printf("done\n"); } void test_proxy(bool proxy_trackers) @@ -569,21 +569,21 @@ void test_proxy(bool proxy_trackers) TEST_CHECK(a != nullptr); } - std::fprintf(stderr, "destructing session\n"); + std::printf("destructing session\n"); s.reset(); - std::fprintf(stderr, "done\n"); + std::printf("done\n"); - std::fprintf(stderr, "stop_web_server\n"); + std::printf("stop_web_server\n"); stop_web_server(); - std::fprintf(stderr, "done\n"); + std::printf("done\n"); } TORRENT_TEST(tracker_proxy) { - std::fprintf(stderr, "\n\nnot proxying tracker connections (expect to reach the tracker)\n\n"); + std::printf("\n\nnot proxying tracker connections (expect to reach the tracker)\n\n"); test_proxy(false); - std::fprintf(stderr, "\n\nproxying tracker connections through non-existent proxy (do not expect to reach the tracker)\n\n"); + std::printf("\n\nproxying tracker connections through non-existent proxy (do not expect to reach the tracker)\n\n"); test_proxy(true); } diff --git a/test/test_transfer.cpp b/test/test_transfer.cpp index 19fa70f5e..32c8b17ba 100644 --- a/test/test_transfer.cpp +++ b/test/test_transfer.cpp @@ -126,7 +126,7 @@ void test_transfer(int proxy_type, settings_pack const& sett { char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"}; - std::fprintf(stderr, "\n\n ==== TESTING %s proxy ==== disk-full: %s\n\n\n" + std::printf("\n\n ==== TESTING %s proxy ==== disk-full: %s\n\n\n" , test_name[proxy_type], test_disk_full ? "true": "false"); // in case the previous run was terminated @@ -302,21 +302,21 @@ void test_transfer(int proxy_type, settings_pack const& sett print_alerts(ses2, "ses2", true, true, true, &on_alert); lt::error_code err = tor2.status().errc; - std::fprintf(stderr, "error: \"%s\"\n", err.message().c_str()); + std::printf("error: \"%s\"\n", err.message().c_str()); TEST_CHECK(!err); tor2.set_upload_mode(false); // at this point we probably disconnected the seed // so we need to reconnect as well - std::fprintf(stderr, "%s: reconnecting peer\n", time_now_string()); + std::printf("%s: reconnecting peer\n", time_now_string()); error_code ec; tor2.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec) , ses1.listen_port())); TEST_CHECK(tor2.status().is_finished == false); - std::fprintf(stderr, "disconnects: %d\n", peer_disconnects); + std::printf("disconnects: %d\n", peer_disconnects); TEST_CHECK(peer_disconnects >= 2); - std::fprintf(stderr, "%s: discovered disk full mode. Raise limit and disable upload-mode\n", time_now_string()); + std::printf("%s: discovered disk full mode. Raise limit and disable upload-mode\n", time_now_string()); peer_disconnects = 0; continue; } @@ -448,7 +448,7 @@ TORRENT_TEST(allocate) { using namespace libtorrent; // test storage_mode_allocate - std::fprintf(stderr, "full allocation mode\n"); + std::printf("full allocation mode\n"); test_transfer(0, settings_pack(), false, storage_mode_allocate); cleanup(); diff --git a/test/test_upnp.cpp b/test/test_upnp.cpp index 1ba1f0c81..4ea386071 100644 --- a/test/test_upnp.cpp +++ b/test/test_upnp.cpp @@ -158,7 +158,7 @@ void run_upnp_test(char const* root_filename, char const* router_model, char con FILE* xml_file = fopen("upnp.xml", "w+"); if (xml_file == nullptr) { - std::fprintf(stderr, "failed to open file 'upnp.xml': %s\n", strerror(errno)); + std::printf("failed to open file 'upnp.xml': %s\n", strerror(errno)); TEST_CHECK(false); return; } @@ -187,7 +187,7 @@ void run_upnp_test(char const* root_filename, char const* router_model, char con ios.poll(ec); if (ec) { - std::fprintf(stderr, "io_service::run(): %s\n", ec.message().c_str()); + std::printf("io_service::run(): %s\n", ec.message().c_str()); ec.clear(); break; } @@ -207,7 +207,7 @@ void run_upnp_test(char const* root_filename, char const* router_model, char con ios.poll(ec); if (ec) { - std::fprintf(stderr, "io_service::run(): %s\n", ec.message().c_str()); + std::printf("io_service::run(): %s\n", ec.message().c_str()); ec.clear(); break; } @@ -233,7 +233,7 @@ void run_upnp_test(char const* root_filename, char const* router_model, char con ios.poll(ec); if (ec) { - std::fprintf(stderr, "io_service::run(): %s\n", ec.message().c_str()); + std::printf("io_service::run(): %s\n", ec.message().c_str()); ec.clear(); break; } diff --git a/test/test_utf8.cpp b/test/test_utf8.cpp index 8e9b27319..df5fb2c47 100644 --- a/test/test_utf8.cpp +++ b/test/test_utf8.cpp @@ -57,7 +57,7 @@ void verify_transforms(char const* utf8_source, int utf8_source_len = -1) if (ret != conversionOK && utf8_source_len < 10) { for (char const* i = utf8_source; *i != 0; ++i) - std::fprintf(stderr, "%x ", UTF8(*i)); + std::printf("%x ", UTF8(*i)); } std::vector utf32(utf8_source_len); @@ -70,7 +70,7 @@ void verify_transforms(char const* utf8_source, int utf8_source_len = -1) if (ret != conversionOK && utf8_source_len < 10) { for (char const* i = utf8_source; *i != 0; ++i) - std::fprintf(stderr, "%x ", UTF8(*i)); + std::printf("%x ", UTF8(*i)); } std::vector utf8(utf8_source_len); @@ -83,7 +83,7 @@ void verify_transforms(char const* utf8_source, int utf8_source_len = -1) if (ret != conversionOK && utf8_source_len < 10) { for (char const* i = utf8_source; *i != 0; ++i) - std::fprintf(stderr, "%x ", UTF8(*i)); + std::printf("%x ", UTF8(*i)); } TEST_EQUAL(out8 - &utf8[0], utf8_source_len); @@ -102,7 +102,7 @@ void verify_transforms(char const* utf8_source, int utf8_source_len = -1) if (ret != conversionOK && utf8_source_len < 10) { for (char const* i = utf8_source; *i != 0; ++i) - std::fprintf(stderr, "%x ", UTF8(*i)); + std::printf("%x ", UTF8(*i)); } std::vector utf16(utf8_source_len); @@ -115,7 +115,7 @@ void verify_transforms(char const* utf8_source, int utf8_source_len = -1) if (ret != conversionOK && utf8_source_len < 10) { for (char const* i = utf8_source; *i != 0; ++i) - std::fprintf(stderr, "%x ", UTF8(*i)); + std::printf("%x ", UTF8(*i)); } std::vector utf8(utf8_source_len); @@ -128,7 +128,7 @@ void verify_transforms(char const* utf8_source, int utf8_source_len = -1) if (ret != conversionOK && utf8_source_len < 10) { for (char const* i = utf8_source; *i != 0; ++i) - std::fprintf(stderr, "%x ", UTF8(*i)); + std::printf("%x ", UTF8(*i)); } TEST_EQUAL(out8 - &utf8[0], utf8_source_len); @@ -147,9 +147,9 @@ void expect_error(char const* utf8, ConversionResult expect) TEST_EQUAL(ret, expect); if (ret != expect) { - std::fprintf(stderr, "%d expected %d\n", ret, expect); + std::printf("%d expected %d\n", ret, expect); for (char const* i = utf8; *i != 0; ++i) - std::fprintf(stderr, "%x ", UTF8(*i)); + std::printf("%x ", UTF8(*i)); } in8 = (UTF8 const*)utf8; @@ -161,9 +161,9 @@ void expect_error(char const* utf8, ConversionResult expect) TEST_EQUAL(ret, expect); if (ret != expect) { - std::fprintf(stderr, "%d expected %d\n", ret, expect); + std::printf("%d expected %d\n", ret, expect); for (char const* i = utf8; *i != 0; ++i) - std::fprintf(stderr, "%x ", UTF8(*i)); + std::printf("%x ", UTF8(*i)); } } @@ -172,7 +172,7 @@ TORRENT_TEST(utf8) std::vector utf8_source; error_code ec; load_file(combine_path("..", "utf8_test.txt"), utf8_source, ec, 1000000); - if (ec) std::fprintf(stderr, "failed to open file: (%d) %s\n", ec.value() + if (ec) std::printf("failed to open file: (%d) %s\n", ec.value() , ec.message().c_str()); TEST_CHECK(!ec); diff --git a/test/test_web_seed_redirect.cpp b/test/test_web_seed_redirect.cpp index 22f03a2f2..b0a320da0 100644 --- a/test/test_web_seed_redirect.cpp +++ b/test/test_web_seed_redirect.cpp @@ -53,7 +53,7 @@ TORRENT_TEST(web_seed_redirect) file f("test_file", file::write_only, ec); if (ec) { - std::fprintf(stderr, "failed to create file \"test_file\": (%d) %s\n" + std::printf("failed to create file \"test_file\": (%d) %s\n" , ec.value(), ec.message().c_str()); TEST_ERROR("failed to create file"); return; @@ -77,7 +77,7 @@ TORRENT_TEST(web_seed_redirect) if (ec) { - std::fprintf(stderr, "error creating hashes for test torrent: %s\n" + std::printf("error creating hashes for test torrent: %s\n" , ec.message().c_str()); TEST_ERROR("failed to create hashes"); return; diff --git a/test/test_xml.cpp b/test/test_xml.cpp index a86d886d2..d60506502 100644 --- a/test/test_xml.cpp +++ b/test/test_xml.cpp @@ -274,7 +274,7 @@ void test_parse(char const* in, char const* expected) std::string out; xml_parse(str(in), std::bind(&parser_callback , std::ref(out), _1, _2, _3, _4, _5)); - std::fprintf(stdout, "in: %s\n out: %s\nexpected: %s\n" + std::printf("in: %s\n out: %s\nexpected: %s\n" , in, out.c_str(), expected); TEST_EQUAL(out, expected); } diff --git a/test/udp_tracker.cpp b/test/udp_tracker.cpp index aff4cead4..191561d21 100644 --- a/test/udp_tracker.cpp +++ b/test/udp_tracker.cpp @@ -66,13 +66,13 @@ struct udp_tracker { if (ec) { - std::fprintf(stderr, "%s: UDP tracker, read failed: %s\n", time_now_string(), ec.message().c_str()); + std::printf("%s: UDP tracker, read failed: %s\n", time_now_string(), ec.message().c_str()); return; } if (bytes_transferred < 16) { - std::fprintf(stderr, "%s: UDP message too short (from: %s)\n", time_now_string(), print_endpoint(*from).c_str()); + std::printf("%s: UDP message too short (from: %s)\n", time_now_string(), print_endpoint(*from).c_str()); return; } @@ -81,7 +81,7 @@ struct udp_tracker return; } - std::fprintf(stderr, "%s: UDP message %d bytes\n", time_now_string(), int(bytes_transferred)); + std::printf("%s: UDP message %d bytes\n", time_now_string(), int(bytes_transferred)); char* ptr = buffer; detail::read_uint64(ptr); @@ -94,23 +94,23 @@ struct udp_tracker { case 0: // connect - std::fprintf(stderr, "%s: UDP connect from %s\n", time_now_string() + std::printf("%s: UDP connect from %s\n", time_now_string() , print_endpoint(*from).c_str()); ptr = buffer; detail::write_uint32(0, ptr); // action = connect detail::write_uint32(transaction_id, ptr); // transaction_id detail::write_uint64(10, ptr); // connection_id m_socket.send_to(boost::asio::buffer(buffer, 16), *from, 0, e); - if (e) std::fprintf(stderr, "%s: UDP send_to failed. ERROR: %s\n" + if (e) std::printf("%s: UDP send_to failed. ERROR: %s\n" , time_now_string(), e.message().c_str()); - else std::fprintf(stderr, "%s: UDP sent response to: %s\n" + else std::printf("%s: UDP sent response to: %s\n" , time_now_string(), print_endpoint(*from).c_str()); break; case 1: // announce ++m_udp_announces; - std::fprintf(stderr, "%s: UDP announce [%d]\n", time_now_string() + std::printf("%s: UDP announce [%d]\n", time_now_string() , int(m_udp_announces)); ptr = buffer; detail::write_uint32(1, ptr); // action = announce @@ -120,17 +120,17 @@ struct udp_tracker detail::write_uint32(1, ptr); // complete // 0 peers m_socket.send_to(boost::asio::buffer(buffer, 20), *from, 0, e); - if (e) std::fprintf(stderr, "%s: UDP send_to failed. ERROR: %s\n" + if (e) std::printf("%s: UDP send_to failed. ERROR: %s\n" , time_now_string(), e.message().c_str()); - else std::fprintf(stderr, "%s: UDP sent response to: %s\n" + else std::printf("%s: UDP sent response to: %s\n" , time_now_string(), print_endpoint(*from).c_str()); break; case 2: // ignore scrapes - std::fprintf(stderr, "%s: UDP scrape (ignored)\n", time_now_string()); + std::printf("%s: UDP scrape (ignored)\n", time_now_string()); break; default: - std::fprintf(stderr, "%s: UDP unknown message: %d\n", time_now_string() + std::printf("%s: UDP unknown message: %d\n", time_now_string() , action); break; } @@ -150,24 +150,24 @@ struct udp_tracker m_socket.open(udp::v4(), ec); if (ec) { - std::fprintf(stderr, "UDP Error opening listen UDP tracker socket: %s\n", ec.message().c_str()); + std::printf("UDP Error opening listen UDP tracker socket: %s\n", ec.message().c_str()); return; } m_socket.bind(udp::endpoint(address_v4::any(), 0), ec); if (ec) { - std::fprintf(stderr, "UDP Error binding UDP tracker socket to port 0: %s\n", ec.message().c_str()); + std::printf("UDP Error binding UDP tracker socket to port 0: %s\n", ec.message().c_str()); return; } m_port = m_socket.local_endpoint(ec).port(); if (ec) { - std::fprintf(stderr, "UDP Error getting local endpoint of UDP tracker socket: %s\n", ec.message().c_str()); + std::printf("UDP Error getting local endpoint of UDP tracker socket: %s\n", ec.message().c_str()); return; } - std::fprintf(stderr, "%s: UDP tracker initialized on port %d\n", time_now_string(), m_port); + std::printf("%s: UDP tracker initialized on port %d\n", time_now_string(), m_port); m_thread = std::make_shared(&udp_tracker::thread_fun, this); } @@ -210,11 +210,11 @@ struct udp_tracker if (ec) { - std::fprintf(stderr, "UDP Error running UDP tracker service: %s\n", ec.message().c_str()); + std::printf("UDP Error running UDP tracker service: %s\n", ec.message().c_str()); return; } - std::fprintf(stderr, "UDP exiting UDP tracker thread\n"); + std::printf("UDP exiting UDP tracker thread\n"); } }; diff --git a/test/web_seed_suite.cpp b/test/web_seed_suite.cpp index 761199bc8..a50113a65 100644 --- a/test/web_seed_suite.cpp +++ b/test/web_seed_suite.cpp @@ -90,7 +90,7 @@ void test_transfer(lt::session& ses, std::shared_ptr torrent_file static char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"}; - std::fprintf(stdout, "\n\n ==== TESTING === proxy: %s ==== protocol: %s " + std::printf("\n\n ==== TESTING === proxy: %s ==== protocol: %s " "==== seed: %s === transfer-encoding: %s === corruption: %s " "==== keepalive: %s\n\n\n" , test_name[proxy], protocol, url_seed ? "URL seed" : "HTTP seed" @@ -103,7 +103,7 @@ void test_transfer(lt::session& ses, std::shared_ptr torrent_file proxy_port = start_proxy(proxy); if (proxy_port < 0) { - std::fprintf(stderr, "failed to start proxy"); + std::printf("failed to start proxy"); return; } settings_pack pack; @@ -169,17 +169,17 @@ void test_transfer(lt::session& ses, std::shared_ptr torrent_file if (test_ban && th.url_seeds().empty() && th.http_seeds().empty()) { - std::fprintf(stdout, "testing ban: URL seed removed\n"); + std::printf("testing ban: URL seed removed\n"); // when we don't have any web seeds left, we know we successfully banned it break; } if (s.is_seeding) { - std::fprintf(stdout, "SEEDING\n"); - std::fprintf(stdout, "session.payload: %d session.redundant: %d\n" + std::printf("SEEDING\n"); + std::printf("session.payload: %d session.redundant: %d\n" , int(cnt["net.recv_payload_bytes"]), int(cnt["net.recv_redundant_bytes"])); - std::fprintf(stdout, "torrent.payload: %d torrent.redundant: %d\n" + std::printf("torrent.payload: %d torrent.redundant: %d\n" , 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); @@ -226,7 +226,7 @@ void test_transfer(lt::session& ses, std::shared_ptr torrent_file && cnt["disk.disk_blocks_in_use"] == (torrent_file->total_size() + 0x3fff) / 0x4000) break; - std::fprintf(stdout, "cache_size: %d/%d\n", int(cnt["disk.read_cache_blocks"]) + std::printf("cache_size: %d/%d\n", int(cnt["disk.read_cache_blocks"]) , int(cnt["disk.disk_blocks_in_use"])); std::this_thread::sleep_for(lt::milliseconds(100)); } @@ -262,7 +262,7 @@ void test_transfer(lt::session& ses, std::shared_ptr torrent_file { bool const expect = !fs.pad_file_at(i); std::string file_path = combine_path(save_path, fs.file_path(i)); - std::fprintf(stdout, "checking file: %s\n", file_path.c_str()); + std::printf("checking file: %s\n", file_path.c_str()); 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]; std::snprintf(url, sizeof(url), ("%s://127.0.0.1:%d/" + save_path).c_str(), protocol, port); - std::fprintf(stdout, "testing: %s\n", url); + std::printf("testing: %s\n", url); 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]; std::snprintf(url, sizeof(url), "%s://127.0.0.1:%d/%s/seed", protocol, port, save_path.c_str()); - std::fprintf(stdout, "testing: %s\n", url); + std::printf("testing: %s\n", url); // there's really just one test case for http seeds 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) { - std::fprintf(stdout, "\n\n ==== test case %d ====\n\n\n", a); + std::printf("\n\n ==== test case %d ====\n\n\n", a); std::shared_ptr torrent_file = make_test_torrent(test_cases[a]); @@ -384,7 +384,7 @@ int EXPORT run_http_suite(int proxy, char const* protocol, bool test_url_seed if (ec) { - std::fprintf(stderr, "error creating hashes for test torrent: %s\n" + std::printf("error creating hashes for test torrent: %s\n" , ec.message().c_str()); TEST_CHECK(false); return 0;