diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index ae2b565fa..7ecec2eb4 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -161,10 +161,12 @@ void stop_proxy(int port) } } -void start_proxy(int port, int proxy_type) +int start_proxy(int proxy_type) { using namespace libtorrent; + int port = 10000 + (rand() % 50000); + stop_proxy(port); char const* type = ""; @@ -203,6 +205,7 @@ void start_proxy(int port, int proxy_type) fprintf(stderr, "launched\n"); // apparently delegate takes a while to open its listen port test_sleep(500); + return port; } using namespace libtorrent; diff --git a/test/setup_transfer.hpp b/test/setup_transfer.hpp index f678bf990..acda8f70b 100644 --- a/test/setup_transfer.hpp +++ b/test/setup_transfer.hpp @@ -69,7 +69,7 @@ setup_transfer(libtorrent::session* ses1, libtorrent::session* ses2 int start_web_server(bool ssl = false, bool chunked = false); void stop_web_server(); -void start_proxy(int port, int type); +int start_proxy(int type); void stop_proxy(int port); void stop_tracker(); diff --git a/test/test_http_connection.cpp b/test/test_http_connection.cpp index e84ee243a..f49e044e7 100644 --- a/test/test_http_connection.cpp +++ b/test/test_http_connection.cpp @@ -134,16 +134,17 @@ void run_test(std::string const& url, int size, int status, int connected TEST_CHECK(http_status == status || status == -1); } -void run_suite(std::string const& protocol, proxy_settings const& ps, int port) +void run_suite(std::string const& protocol, proxy_settings ps, int port) { if (ps.type != proxy_settings::none) { - start_proxy(ps.port, ps.type); + ps.port = start_proxy(ps.type); } char const* test_name[] = {"no", "SOCKS4", "SOCKS5" , "SOCKS5 password protected", "HTTP", "HTTP password protected"}; - std::cout << "\n\n********************** using " << test_name[ps.type] - << " proxy **********************\n" << std::endl; + + printf("\n\n********************** using %s proxy **********************\n" + , test_name[ps.type]); typedef boost::optional err; // this requires the hosts file to be modified diff --git a/test/test_transfer.cpp b/test/test_transfer.cpp index f87969b68..7fb85acf4 100644 --- a/test/test_transfer.cpp +++ b/test/test_transfer.cpp @@ -247,13 +247,11 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48075, 49000), "0.0.0.0", 0, alert_mask); session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49075, 50000), "0.0.0.0", 0, alert_mask); - int proxy_port = (rand() % 30000) + 10000; + proxy_settings ps; if (proxy_type) { - start_proxy(proxy_port, proxy_type); - proxy_settings ps; + ps.port = start_proxy(proxy_type); ps.hostname = "127.0.0.1"; - ps.port = proxy_port; ps.username = "testuser"; ps.password = "testpass"; ps.type = (proxy_settings::proxy_type)proxy_type; @@ -585,7 +583,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe stop_tracker(); stop_web_server(); } - if (proxy_type) stop_proxy(proxy_port); + if (proxy_type) stop_proxy(ps.port); } int test_main() diff --git a/test/test_web_seed.cpp b/test/test_web_seed.cpp index 381558551..f4cc31380 100644 --- a/test/test_web_seed.cpp +++ b/test/test_web_seed.cpp @@ -70,10 +70,9 @@ void test_transfer(boost::intrusive_ptr torrent_file if (proxy) { - start_proxy(8002, proxy); proxy_settings ps; + ps.port = start_proxy(proxy); ps.hostname = "127.0.0.1"; - ps.port = 8002; ps.username = "testuser"; ps.password = "testpass"; ps.type = (proxy_settings::proxy_type)proxy;