replaced boost.filesystem with custom functions (improves efficiency and drops unnecessary dependencies and improves libtorrent portability)
This commit is contained in:
@@ -38,24 +38,26 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/convenience.hpp>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "libtorrent/assert.hpp"
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/create_torrent.hpp"
|
||||
|
||||
using boost::filesystem::remove_all;
|
||||
using boost::filesystem::create_directory;
|
||||
using namespace libtorrent;
|
||||
namespace sf = boost::filesystem;
|
||||
|
||||
bool tests_failure = false;
|
||||
|
||||
void report_failure(char const* err, char const* file, int line)
|
||||
{
|
||||
#ifdef TORRENT_WINDOWS
|
||||
HANDLE console = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, 0, CONSOLE_TEXTMODE_BUFFER, 0);
|
||||
SetConsoleTextAttribute(console, FOREGROUND_RED);
|
||||
std::cerr << "\n**** " << file << ":" << line << " \"" << err << " ****\n\n";
|
||||
CloseHandle(console);
|
||||
#else
|
||||
std::cerr << "\033[31m" << file << ":" << line << " \"" << err << "\"\033[0m\n";
|
||||
#endif
|
||||
tests_failure = true;
|
||||
}
|
||||
|
||||
@@ -106,9 +108,9 @@ void test_sleep(int millisec)
|
||||
|
||||
void stop_web_server(int port)
|
||||
{
|
||||
std::stringstream cmd;
|
||||
cmd << "kill `cat ./lighty" << port << ".pid` >/dev/null";
|
||||
system(cmd.str().c_str());
|
||||
char buf[100];
|
||||
snprintf(buf, sizeof(buf), "kill `cat ./lighty%d.pid` >/dev/null", port);
|
||||
system(buf);
|
||||
}
|
||||
|
||||
void start_web_server(int port, bool ssl)
|
||||
@@ -117,6 +119,7 @@ void start_web_server(int port, bool ssl)
|
||||
|
||||
if (ssl)
|
||||
{
|
||||
fprintf(stderr, "generating SSL key\n");
|
||||
system("echo . > tmp");
|
||||
system("echo test province >>tmp");
|
||||
system("echo test city >> tmp");
|
||||
@@ -128,38 +131,56 @@ void start_web_server(int port, bool ssl)
|
||||
"-days 365 -nodes <tmp");
|
||||
}
|
||||
|
||||
std::ofstream f("lighty_config");
|
||||
f << "server.modules = (\"mod_access\", \"mod_redirect\", \"mod_setenv\")\n"
|
||||
"server.document-root = \"" << fs::initial_path<fs::path>().string() << "\"\n"
|
||||
error_code ec;
|
||||
file f("lighty_config", file::write_only, ec);
|
||||
if (ec)
|
||||
{
|
||||
fprintf(stderr, "error writing lighty config file: %s\n", ec.message().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// this requires lighttpd to be built with ssl support.
|
||||
// The port distribution for mac is not built with ssl
|
||||
// support by default.
|
||||
char buf[1024];
|
||||
int buf_size = snprintf(buf, sizeof(buf),
|
||||
"server.modules = (\"mod_access\", \"mod_redirect\", \"mod_setenv\")\n"
|
||||
"server.document-root = \"%s\"\n"
|
||||
"server.range-requests = \"enable\"\n"
|
||||
"server.port = " << port << "\n"
|
||||
"server.pid-file = \"./lighty" << port << ".pid\"\n"
|
||||
"server.port = %d\n"
|
||||
"server.pid-file = \"./lighty%d.pid\"\n"
|
||||
"url.redirect = ("
|
||||
"\"^/redirect$\" => \"" << (ssl?"https":"http") << "://127.0.0.1:" << port << "/test_file\""
|
||||
", \"^/infinite_redirect$\" => \"" << (ssl?"https":"http") << "://127.0.0.1:" << port << "/infinite_redirect\""
|
||||
"\"^/redirect$\" => \"%s://127.0.0.1:%d/test_file\""
|
||||
", \"^/infinite_redirect$\" => \"%s://127.0.0.1:%d/infinite_redirect\""
|
||||
", \"^/relative/redirect$\" => \"../test_file\""
|
||||
")\n"
|
||||
"$HTTP[\"url\"] == \"/test_file.gz\" {\n"
|
||||
" setenv.add-response-header = ( \"Content-Encoding\" => \"gzip\" )\n"
|
||||
"# mimetype.assign = ()\n"
|
||||
"}\n";
|
||||
// this requires lighttpd to be built with ssl support.
|
||||
// The port distribution for mac is not built with ssl
|
||||
// support by default.
|
||||
if (ssl)
|
||||
f << "ssl.engine = \"enable\"\n"
|
||||
"ssl.pemfile = \"server.pem\"\n";
|
||||
"}\n"
|
||||
"ssl.engine = \"%s\"\n"
|
||||
"ssl.pemfile = \"server.pem\"\n"
|
||||
, current_working_directory().c_str(), port, port
|
||||
, (ssl?"https":"http"), port, (ssl?"https":"http"), port
|
||||
, (ssl?"enable":"disable"));
|
||||
file::iovec_t b = { buf, buf_size };
|
||||
f.writev(0, &b, 1, ec);
|
||||
if (ec)
|
||||
{
|
||||
fprintf(stderr, "error writing lighty config file: %s\n", ec.message().c_str());
|
||||
return;
|
||||
}
|
||||
f.close();
|
||||
|
||||
fprintf(stderr, "starting lighty\n\n%s\n\n", buf);
|
||||
system("lighttpd -f lighty_config 2> lighty.err >lighty.log &");
|
||||
test_sleep(1000);
|
||||
}
|
||||
|
||||
void stop_proxy(int port)
|
||||
{
|
||||
std::stringstream cmd;
|
||||
cmd << "delegated -P" << port << " -Fkill";
|
||||
system(cmd.str().c_str());
|
||||
char buf[100];
|
||||
snprintf(buf, sizeof(buf), "delegated -P%d -Fkill", port);
|
||||
system(buf);
|
||||
}
|
||||
|
||||
void start_proxy(int port, int proxy_type)
|
||||
@@ -167,29 +188,39 @@ void start_proxy(int port, int proxy_type)
|
||||
using namespace libtorrent;
|
||||
|
||||
stop_proxy(port);
|
||||
std::stringstream cmd;
|
||||
// we need to echo n since dg will ask us to configure it
|
||||
cmd << "echo n | delegated -P" << port << " ADMIN=test@test.com "
|
||||
"PERMIT=\"*:*:localhost\" REMITTABLE=+,https RELAY=proxy,delegate";
|
||||
|
||||
char const* type = "";
|
||||
char const* auth = "";
|
||||
|
||||
switch (proxy_type)
|
||||
{
|
||||
case proxy_settings::socks4:
|
||||
cmd << " SERVER=socks4";
|
||||
type = "socks4";
|
||||
break;
|
||||
case proxy_settings::socks5:
|
||||
cmd << " SERVER=socks5";
|
||||
type = "socks5";
|
||||
break;
|
||||
case proxy_settings::socks5_pw:
|
||||
cmd << " SERVER=socks5 AUTHORIZER=-list{testuser:testpass}";
|
||||
type = "socks5";
|
||||
auth = "AUTHORIZER=-list{testuser:testpass}";
|
||||
break;
|
||||
case proxy_settings::http:
|
||||
cmd << " SERVER=http";
|
||||
type = "http";
|
||||
break;
|
||||
case proxy_settings::http_pw:
|
||||
cmd << " SERVER=http AUTHORIZER=-list{testuser:testpass}";
|
||||
type = "http";
|
||||
auth = "AUTHORIZER=-list{testuser:testpass}";
|
||||
break;
|
||||
}
|
||||
system(cmd.str().c_str());
|
||||
|
||||
char buf[512];
|
||||
// we need to echo n since dg will ask us to configure it
|
||||
snprintf(buf, sizeof(buf), "echo n | delegated -P%d ADMIN=test@test.com "
|
||||
"PERMIT=\"*:*:localhost\" REMITTABLE=+,https RELAY=proxy,delegate "
|
||||
"SERVER=%s %s"
|
||||
, port, type, auth);
|
||||
|
||||
system(buf);
|
||||
test_sleep(1000);
|
||||
}
|
||||
|
||||
@@ -208,11 +239,9 @@ boost::intrusive_ptr<torrent_info> create_torrent(std::ostream* file, int piece_
|
||||
char const* invalid_tracker_url = "http:";
|
||||
char const* invalid_tracker_protocol = "foo://non/existent-name.com/announce";
|
||||
|
||||
using namespace boost::filesystem;
|
||||
|
||||
file_storage fs;
|
||||
int total_size = piece_size * num_pieces;
|
||||
fs.add_file(path("temporary"), total_size);
|
||||
fs.add_file("temporary", total_size);
|
||||
libtorrent::create_torrent t(fs, piece_size);
|
||||
t.add_tracker(tracker_url);
|
||||
t.add_tracker(invalid_tracker_url);
|
||||
@@ -239,6 +268,7 @@ boost::intrusive_ptr<torrent_info> create_torrent(std::ostream* file, int piece_
|
||||
|
||||
std::vector<char> tmp;
|
||||
std::back_insert_iterator<std::vector<char> > out(tmp);
|
||||
|
||||
bencode(out, t.generate());
|
||||
return boost::intrusive_ptr<torrent_info>(new torrent_info(&tmp[0], tmp.size()));
|
||||
}
|
||||
@@ -250,8 +280,6 @@ setup_transfer(session* ses1, session* ses2, session* ses3
|
||||
, boost::intrusive_ptr<torrent_info>* torrent, bool super_seeding
|
||||
, add_torrent_params const* p)
|
||||
{
|
||||
using namespace boost::filesystem;
|
||||
|
||||
assert(ses1);
|
||||
assert(ses2);
|
||||
|
||||
@@ -282,14 +310,15 @@ setup_transfer(session* ses1, session* ses2, session* ses3
|
||||
boost::intrusive_ptr<torrent_info> t;
|
||||
if (torrent == 0)
|
||||
{
|
||||
create_directory("./tmp1" + suffix);
|
||||
error_code ec;
|
||||
create_directory("./tmp1" + suffix, ec);
|
||||
std::ofstream file(("./tmp1" + suffix + "/temporary").c_str());
|
||||
t = ::create_torrent(&file, piece_size, 19);
|
||||
file.close();
|
||||
if (clear_files)
|
||||
{
|
||||
remove_all("./tmp2" + suffix + "/temporary");
|
||||
remove_all("./tmp3" + suffix + "/temporary");
|
||||
remove_all("./tmp2" + suffix + "/temporary", ec);
|
||||
remove_all("./tmp3" + suffix + "/temporary", ec);
|
||||
}
|
||||
char ih_hex[41];
|
||||
to_hex((char const*)&t->info_hash()[0], 20, ih_hex);
|
||||
|
@@ -66,6 +66,23 @@ void report_failure(char const* str, char const* file, int line);
|
||||
TEST_ERROR("Exception thrown: " #x); \
|
||||
}
|
||||
|
||||
#define TEST_EQUAL(x, y) \
|
||||
try { \
|
||||
if (x != y) { \
|
||||
std::stringstream s; \
|
||||
s << "TEST_EQUAL_ERROR: " << #x << ": " << x << " expected: " << y << std::endl; \
|
||||
TEST_REPORT_AUX(s.str().c_str(), __FILE__, __LINE__); \
|
||||
} \
|
||||
} \
|
||||
catch (std::exception& e) \
|
||||
{ \
|
||||
TEST_ERROR("Exception thrown: " #x " :" + std::string(e.what())); \
|
||||
} \
|
||||
catch (...) \
|
||||
{ \
|
||||
TEST_ERROR("Exception thrown: " #x); \
|
||||
}
|
||||
|
||||
#define TEST_ERROR(x) \
|
||||
TEST_REPORT_AUX((std::string("ERROR: \"") + x + "\"").c_str(), __FILE__, __LINE__)
|
||||
|
||||
|
@@ -4,14 +4,10 @@
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
|
||||
using boost::filesystem::remove_all;
|
||||
using boost::filesystem::exists;
|
||||
|
||||
void test_swarm()
|
||||
{
|
||||
using namespace libtorrent;
|
||||
@@ -102,12 +98,12 @@ void test_swarm()
|
||||
int test_main()
|
||||
{
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
// in case the previous run was terminated
|
||||
try { remove_all("./tmp1_unchoke"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp2_unchoke"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp3_unchoke"); } catch (std::exception&) {}
|
||||
// in case the previous run was t r catch (std::exception&) {}erminated
|
||||
error_code ec;
|
||||
remove_all("./tmp1_unchoke", ec);
|
||||
remove_all("./tmp2_unchoke", ec);
|
||||
remove_all("./tmp3_unchoke", ec);
|
||||
|
||||
test_swarm();
|
||||
|
||||
@@ -116,9 +112,9 @@ int test_main()
|
||||
TEST_CHECK(!exists("./tmp2_unchoke/temporary"));
|
||||
TEST_CHECK(!exists("./tmp3_unchoke/temporary"));
|
||||
|
||||
remove_all("./tmp1_unchoke");
|
||||
remove_all("./tmp2_unchoke");
|
||||
remove_all("./tmp3_unchoke");
|
||||
remove_all("./tmp1_unchoke", ec);
|
||||
remove_all("./tmp2_unchoke", ec);
|
||||
remove_all("./tmp3_unchoke", ec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -35,13 +35,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
|
||||
using boost::filesystem::remove_all;
|
||||
|
||||
void test_lsd()
|
||||
{
|
||||
using namespace libtorrent;
|
||||
@@ -122,18 +119,18 @@ void test_lsd()
|
||||
int test_main()
|
||||
{
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
// in case the previous run was terminated
|
||||
try { remove_all("./tmp1_lsd"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp2_lsd"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp3_lsd"); } catch (std::exception&) {}
|
||||
error_code ec;
|
||||
remove_all("./tmp1_lsd", ec);
|
||||
remove_all("./tmp2_lsd", ec);
|
||||
remove_all("./tmp3_lsd", ec);
|
||||
|
||||
test_lsd();
|
||||
|
||||
remove_all("./tmp1_lsd");
|
||||
remove_all("./tmp2_lsd");
|
||||
remove_all("./tmp3_lsd");
|
||||
remove_all("./tmp1_lsd", ec);
|
||||
remove_all("./tmp2_lsd", ec);
|
||||
remove_all("./tmp3_lsd", ec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -34,15 +34,12 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/convenience.hpp>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
#include "libtorrent/extensions/metadata_transfer.hpp"
|
||||
#include "libtorrent/extensions/ut_metadata.hpp"
|
||||
|
||||
using boost::filesystem::remove_all;
|
||||
using boost::tuples::ignore;
|
||||
|
||||
void test_transfer(bool clear_files, bool disconnect
|
||||
@@ -104,16 +101,15 @@ void test_transfer(bool clear_files, bool disconnect
|
||||
TEST_CHECK(tor2.is_seed());
|
||||
if (tor2.is_seed()) std::cerr << "done\n";
|
||||
|
||||
using boost::filesystem::remove_all;
|
||||
remove_all("./tmp1_meta");
|
||||
remove_all("./tmp2_meta");
|
||||
remove_all("./tmp3_meta");
|
||||
error_code ec;
|
||||
remove_all("./tmp1_meta", ec);
|
||||
remove_all("./tmp2_meta", ec);
|
||||
remove_all("./tmp3_meta", ec);
|
||||
}
|
||||
|
||||
int test_main()
|
||||
{
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
// test to disconnect one client prematurely
|
||||
test_transfer(true, true, &create_metadata_plugin);
|
||||
@@ -129,8 +125,9 @@ int test_main()
|
||||
// test where both have data (to trigger the file check)
|
||||
test_transfer(false, false, &create_ut_metadata_plugin);
|
||||
|
||||
remove_all("./tmp1");
|
||||
remove_all("./tmp2");
|
||||
error_code ec;
|
||||
remove_all("./tmp1", ec);
|
||||
remove_all("./tmp2", ec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -36,7 +36,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/pe_crypto.hpp"
|
||||
#include "libtorrent/session.hpp"
|
||||
#include <boost/filesystem/convenience.hpp>
|
||||
|
||||
#include "setup_transfer.hpp"
|
||||
#include "test.hpp"
|
||||
@@ -126,10 +125,10 @@ void test_transfer(libtorrent::pe_settings::enc_policy policy,
|
||||
ses1.remove_torrent(tor1);
|
||||
ses2.remove_torrent(tor2);
|
||||
|
||||
using boost::filesystem::remove_all;
|
||||
remove_all("./tmp1_pe");
|
||||
remove_all("./tmp2_pe");
|
||||
remove_all("./tmp3_pe");
|
||||
error_code ec;
|
||||
remove_all("./tmp1_pe", ec);
|
||||
remove_all("./tmp2_pe", ec);
|
||||
remove_all("./tmp3_pe", ec);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -36,13 +36,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/extensions/ut_pex.hpp"
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
|
||||
using boost::filesystem::remove_all;
|
||||
|
||||
void test_pex()
|
||||
{
|
||||
using namespace libtorrent;
|
||||
@@ -135,18 +132,18 @@ void test_pex()
|
||||
int test_main()
|
||||
{
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
// in case the previous run was terminated
|
||||
try { remove_all("./tmp1_pex"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp2_pex"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp3_pex"); } catch (std::exception&) {}
|
||||
error_code ec;
|
||||
remove_all("./tmp1_pex", ec);
|
||||
remove_all("./tmp2_pex", ec);
|
||||
remove_all("./tmp3_pex", ec);
|
||||
|
||||
test_pex();
|
||||
|
||||
remove_all("./tmp1_pex");
|
||||
remove_all("./tmp2_pex");
|
||||
remove_all("./tmp3_pex");
|
||||
remove_all("./tmp1_pex", ec);
|
||||
remove_all("./tmp2_pex", ec);
|
||||
remove_all("./tmp3_pex", ec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/escape_string.hpp"
|
||||
#include "libtorrent/broadcast_socket.hpp"
|
||||
#include "libtorrent/identify_client.hpp"
|
||||
#include "libtorrent/file.hpp"
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
#include "libtorrent/kademlia/node_id.hpp"
|
||||
#include "libtorrent/kademlia/routing_table.hpp"
|
||||
@@ -57,7 +58,7 @@ using namespace boost::tuples;
|
||||
using boost::bind;
|
||||
|
||||
namespace libtorrent {
|
||||
fs::path sanitize_path(fs::path const& p);
|
||||
std::string sanitize_path(std::string const& p);
|
||||
}
|
||||
|
||||
sha1_hash to_hash(char const* s)
|
||||
@@ -365,6 +366,69 @@ void find_control_url(int type, char const* string, parse_state& state);
|
||||
int test_main()
|
||||
{
|
||||
using namespace libtorrent;
|
||||
error_code ec;
|
||||
|
||||
// test path functions
|
||||
TEST_EQUAL(combine_path("test1/", "test2"), "test1/test2");
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(combine_path("test1\\", "test2"), "test1\\test2");
|
||||
TEST_EQUAL(combine_path("test1", "test2"), "test1\\test2");
|
||||
#else
|
||||
TEST_EQUAL(combine_path("test1", "test2"), "test1/test2");
|
||||
#endif
|
||||
|
||||
TEST_EQUAL(extension("blah"), "");
|
||||
TEST_EQUAL(extension("blah.exe"), ".exe");
|
||||
TEST_EQUAL(extension("blah.foo.bar"), ".bar");
|
||||
TEST_EQUAL(extension("blah.foo."), ".");
|
||||
|
||||
TEST_EQUAL(filename("blah"), "blah");
|
||||
TEST_EQUAL(filename("/blah/foo/bar"), "bar");
|
||||
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(is_root_path("c:\\blah"), false);
|
||||
TEST_EQUAL(is_root_path("c:\\"), true);
|
||||
TEST_EQUAL(is_root_path("\\\\"), true);
|
||||
TEST_EQUAL(is_root_path("\\\\foobar"), false);
|
||||
#else
|
||||
TEST_EQUAL(is_root_path("/blah"), false);
|
||||
TEST_EQUAL(is_root_path("/"), true);
|
||||
#endif
|
||||
|
||||
// if has_parent_path() returns false
|
||||
// parent_path() should return the empty string
|
||||
TEST_EQUAL(parent_path("blah"), "");
|
||||
TEST_EQUAL(has_parent_path("blah"), false);
|
||||
TEST_EQUAL(parent_path("/blah/foo/bar"), "/blah/foo/");
|
||||
TEST_EQUAL(has_parent_path("/blah/foo/bar"), true);
|
||||
TEST_EQUAL(parent_path("/blah/foo/bar/"), "/blah/foo/");
|
||||
TEST_EQUAL(has_parent_path("/blah/foo/bar/"), true);
|
||||
TEST_EQUAL(parent_path("/a"), "/");
|
||||
TEST_EQUAL(has_parent_path("/a"), true);
|
||||
TEST_EQUAL(parent_path("/"), "");
|
||||
TEST_EQUAL(has_parent_path("/"), false);
|
||||
TEST_EQUAL(parent_path(""), "");
|
||||
TEST_EQUAL(has_parent_path(""), false);
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(parent_path("\\\\"), "");
|
||||
TEST_EQUAL(has_parent_path("\\\\"), false);
|
||||
TEST_EQUAL(parent_path("c:\\"), "");
|
||||
TEST_EQUAL(has_parent_path("c:\\"), false);
|
||||
TEST_EQUAL(parent_path("c:\\a"), "c:\\");
|
||||
TEST_EQUAL(has_parent_path("c:\\a"), true);
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(is_complete("c:\\foo\\bar"), true);
|
||||
TEST_EQUAL(is_complete("\\\\foo\\bar"), true);
|
||||
TEST_EQUAL(is_complete("foo/bar"), false);
|
||||
TEST_EQUAL(is_complete("\\\\"), true);
|
||||
#else
|
||||
TEST_EQUAL(is_complete("/foo/bar"), true);
|
||||
TEST_EQUAL(is_complete("foo/bar"), false);
|
||||
TEST_EQUAL(is_complete("/"), true);
|
||||
TEST_EQUAL(is_complete(""), false);
|
||||
#endif
|
||||
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
// test search_torrent_entry
|
||||
@@ -417,43 +481,52 @@ int test_main()
|
||||
|
||||
// test maybe_url_encode
|
||||
|
||||
TEST_CHECK(maybe_url_encode("http://test:test@abc.com/abc<>abc") == "http://test:test@abc.com:80/abc%3c%3eabc");
|
||||
TEST_CHECK(maybe_url_encode("http://abc.com/foo bar") == "http://abc.com:80/foo%20bar");
|
||||
TEST_CHECK(maybe_url_encode("abc") == "abc");
|
||||
TEST_CHECK(maybe_url_encode("http://abc.com/abc") == "http://abc.com/abc");
|
||||
TEST_EQUAL(maybe_url_encode("http://test:test@abc.com/abc<>abc"), "http://test:test@abc.com:80/abc%3c%3eabc");
|
||||
TEST_EQUAL(maybe_url_encode("http://abc.com/foo bar"), "http://abc.com:80/foo%20bar");
|
||||
TEST_EQUAL(maybe_url_encode("abc"), "abc");
|
||||
TEST_EQUAL(maybe_url_encode("http://abc.com/abc"), "http://abc.com/abc");
|
||||
|
||||
// test sanitize_path
|
||||
|
||||
TEST_CHECK(sanitize_path("/a/b/c").string() == "a/b/c");
|
||||
TEST_CHECK(sanitize_path("a/../c").string() == "a/c");
|
||||
TEST_CHECK(sanitize_path("/.././c").string() == "c");
|
||||
TEST_CHECK(sanitize_path("dev:").string() == "");
|
||||
TEST_CHECK(sanitize_path("c:/b").string() == "b");
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_CHECK(sanitize_path("c:\\.\\c").string() == "c");
|
||||
TEST_EQUAL(sanitize_path("/a/b/c"), "a\\b\\c");
|
||||
TEST_EQUAL(sanitize_path("a/../c"), "a\\c");
|
||||
#else
|
||||
TEST_CHECK(sanitize_path("//./c").string() == "c");
|
||||
TEST_EQUAL(sanitize_path("/a/b/c"), "a/b/c");
|
||||
TEST_EQUAL(sanitize_path("a/../c"), "a/c");
|
||||
#endif
|
||||
TEST_EQUAL(sanitize_path("/.././c"), "c");
|
||||
TEST_EQUAL(sanitize_path("dev:"), "");
|
||||
TEST_EQUAL(sanitize_path("c:/b"), "b");
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_EQUAL(sanitize_path("c:\\.\\c"), "c");
|
||||
TEST_EQUAL(sanitize_path("\\c"), "c");
|
||||
#else
|
||||
TEST_EQUAL(sanitize_path("//./c"), "c");
|
||||
#endif
|
||||
|
||||
// make sure the time classes have correct semantics
|
||||
|
||||
TEST_CHECK(total_milliseconds(milliseconds(100)) == 100);
|
||||
TEST_CHECK(total_milliseconds(milliseconds(1)) == 1);
|
||||
TEST_CHECK(total_milliseconds(seconds(1)) == 1000);
|
||||
TEST_EQUAL(total_milliseconds(milliseconds(100)), 100);
|
||||
TEST_EQUAL(total_milliseconds(milliseconds(1)), 1);
|
||||
TEST_EQUAL(total_milliseconds(seconds(1)), 1000);
|
||||
|
||||
|
||||
// make sure the assumption we use in policy's peer list hold
|
||||
std::multimap<address, int> peers;
|
||||
std::multimap<address, int>::iterator i;
|
||||
peers.insert(std::make_pair(address::from_string("::1"), 0));
|
||||
peers.insert(std::make_pair(address::from_string("::2"), 3));
|
||||
peers.insert(std::make_pair(address::from_string("::3"), 5));
|
||||
i = peers.find(address::from_string("::2"));
|
||||
TEST_CHECK(i != peers.end());
|
||||
if (i != peers.end())
|
||||
if (supports_ipv6())
|
||||
{
|
||||
TEST_CHECK(i->first == address::from_string("::2"));
|
||||
TEST_CHECK(i->second == 3);
|
||||
// make sure the assumption we use in policy's peer list hold
|
||||
std::multimap<address, int> peers;
|
||||
std::multimap<address, int>::iterator i;
|
||||
peers.insert(std::make_pair(address::from_string("::1", ec), 0));
|
||||
peers.insert(std::make_pair(address::from_string("::2", ec), 3));
|
||||
peers.insert(std::make_pair(address::from_string("::3", ec), 5));
|
||||
i = peers.find(address::from_string("::2", ec));
|
||||
TEST_CHECK(i != peers.end());
|
||||
if (i != peers.end())
|
||||
{
|
||||
TEST_CHECK(i->first == address::from_string("::2", ec));
|
||||
TEST_CHECK(i->second == 3);
|
||||
}
|
||||
}
|
||||
|
||||
// test identify_client
|
||||
@@ -500,7 +573,6 @@ int test_main()
|
||||
|
||||
// test url parsing
|
||||
|
||||
error_code ec;
|
||||
TEST_CHECK(parse_url_components("http://foo:bar@host.com:80/path/to/file", ec)
|
||||
== make_tuple("http", "foo:bar", "host.com", 80, "/path/to/file"));
|
||||
|
||||
@@ -817,13 +889,21 @@ int test_main()
|
||||
torrent["info"] = info;
|
||||
torrent_info ti2(torrent);
|
||||
std::cerr << ti2.name() << std::endl;
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_CHECK(ti2.name() == "test1\\test2\\test3");
|
||||
#else
|
||||
TEST_CHECK(ti2.name() == "test1/test2/test3");
|
||||
#endif
|
||||
|
||||
info["name.utf-8"] = "test2/../test3/.././../../test4";
|
||||
torrent["info"] = info;
|
||||
torrent_info ti3(torrent);
|
||||
std::cerr << ti3.name() << std::endl;
|
||||
#ifdef TORRENT_WINDOWS
|
||||
TEST_CHECK(ti3.name() == "test2\\test3\\test4");
|
||||
#else
|
||||
TEST_CHECK(ti3.name() == "test2/test3/test4");
|
||||
#endif
|
||||
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
// test kademlia functions
|
||||
|
@@ -40,14 +40,11 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/thread.hpp"
|
||||
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/convenience.hpp>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
const int piece_size = 16 * 1024 * 16;
|
||||
const int block_size = 16 * 1024;
|
||||
@@ -61,7 +58,7 @@ char* piece2 = page_aligned_allocator::malloc(piece_size);
|
||||
void on_read_piece(int ret, disk_io_job const& j, char const* data, int size)
|
||||
{
|
||||
std::cerr << "on_read_piece piece: " << j.piece << std::endl;
|
||||
TEST_CHECK(ret == size);
|
||||
TEST_EQUAL(ret, size);
|
||||
if (ret > 0) TEST_CHECK(std::equal(j.buffer, j.buffer + ret, data));
|
||||
}
|
||||
|
||||
@@ -95,7 +92,7 @@ void on_check_files(int ret, disk_io_job const& j, bool* done)
|
||||
|
||||
void on_read(int ret, disk_io_job const& j, bool* done)
|
||||
{
|
||||
std::cerr << "on_read ret: " << ret;
|
||||
std::cerr << "on_read ret: " << ret << std::endl;
|
||||
*done = true;
|
||||
|
||||
if (ret < 0)
|
||||
@@ -109,8 +106,8 @@ void on_read(int ret, disk_io_job const& j, bool* done)
|
||||
void on_move_storage(int ret, disk_io_job const& j, std::string path)
|
||||
{
|
||||
std::cerr << "on_move_storage ret: " << ret << " path: " << j.str << std::endl;
|
||||
TEST_CHECK(ret == 0);
|
||||
TEST_CHECK(j.str == path);
|
||||
TEST_EQUAL(ret, 0);
|
||||
TEST_EQUAL(j.str, path);
|
||||
}
|
||||
|
||||
void print_error(int ret, boost::scoped_ptr<storage_interface> const& s)
|
||||
@@ -160,7 +157,7 @@ struct test_storage : storage_interface
|
||||
virtual int sparse_end(int start) const
|
||||
{ return start; }
|
||||
|
||||
virtual bool move_storage(fs::path save_path)
|
||||
virtual bool move_storage(std::string const& save_path)
|
||||
{ return false; }
|
||||
|
||||
virtual bool verify_resume_data(lazy_entry const& rd, error_code& error)
|
||||
@@ -189,7 +186,7 @@ struct test_storage : storage_interface
|
||||
};
|
||||
|
||||
storage_interface* create_test_storage(file_storage const& fs
|
||||
, file_storage const* mapped, fs::path const& path, file_pool& fp)
|
||||
, file_storage const* mapped, std::string const& path, file_pool& fp)
|
||||
{
|
||||
return new test_storage;
|
||||
}
|
||||
@@ -243,6 +240,7 @@ void run_elevator_test()
|
||||
boost::intrusive_ptr<torrent_info> ti = ::create_torrent(0, 16, 6000);
|
||||
|
||||
{
|
||||
error_code ec;
|
||||
disk_io_thread dio(ios, &nop);
|
||||
boost::intrusive_ptr<piece_manager> pm(new piece_manager(boost::shared_ptr<void>(), ti, ""
|
||||
, fp, dio, &create_test_storage, storage_mode_sparse));
|
||||
@@ -260,9 +258,12 @@ void run_elevator_test()
|
||||
}
|
||||
|
||||
for (int i = 0; i < 101; ++i)
|
||||
ios.run_one();
|
||||
{
|
||||
ios.run_one(ec);
|
||||
if (ec) std::cerr << "run_one: " << ec.message() << std::endl;
|
||||
}
|
||||
|
||||
TEST_CHECK(job_counter == 0);
|
||||
TEST_EQUAL(job_counter, 0);
|
||||
|
||||
// test the elevator going down
|
||||
add_job_down(dio, 5999, pm);
|
||||
@@ -276,9 +277,12 @@ void run_elevator_test()
|
||||
}
|
||||
|
||||
for (int i = 0; i < 101; ++i)
|
||||
ios.run_one();
|
||||
{
|
||||
ios.run_one(ec);
|
||||
if (ec) std::cerr << "run_one: " << ec.message() << std::endl;
|
||||
}
|
||||
|
||||
TEST_CHECK(job_counter == 0);
|
||||
TEST_EQUAL(job_counter, 0);
|
||||
|
||||
dio.join();
|
||||
}
|
||||
@@ -286,14 +290,18 @@ void run_elevator_test()
|
||||
|
||||
void run_storage_tests(boost::intrusive_ptr<torrent_info> info
|
||||
, file_storage& fs
|
||||
, path const& test_path
|
||||
, std::string const& test_path
|
||||
, libtorrent::storage_mode_t storage_mode
|
||||
, bool unbuffered)
|
||||
{
|
||||
TORRENT_ASSERT(fs.num_files() > 0);
|
||||
create_directory(test_path / "temp_storage");
|
||||
remove_all(test_path / "temp_storage2");
|
||||
remove_all(test_path / "part0");
|
||||
error_code ec;
|
||||
create_directory(combine_path(test_path, "temp_storage"), ec);
|
||||
if (ec) std::cerr << "create_directory: " << ec.message() << std::endl;
|
||||
remove_all(combine_path(test_path, "temp_storage2"), ec);
|
||||
if (ec) std::cerr << "remove_all: " << ec.message() << std::endl;
|
||||
remove_all(combine_path(test_path, "part0"), ec);
|
||||
if (ec) std::cerr << "remove_all: " << ec.message() << std::endl;
|
||||
|
||||
int num_pieces = fs.num_pieces();
|
||||
TEST_CHECK(info->num_pieces() == num_pieces);
|
||||
@@ -373,6 +381,7 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
|
||||
{
|
||||
ios.reset();
|
||||
ios.run_one(ec);
|
||||
if (ec) std::cerr << "run_one: " << ec.message() << std::endl;
|
||||
}
|
||||
|
||||
done = false;
|
||||
@@ -381,6 +390,7 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
|
||||
{
|
||||
ios.reset();
|
||||
ios.run_one(ec);
|
||||
if (ec) std::cerr << "run_one: " << ec.message() << std::endl;
|
||||
}
|
||||
|
||||
done = false;
|
||||
@@ -393,47 +403,53 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
|
||||
{
|
||||
ios.reset();
|
||||
ios.run_one(ec);
|
||||
if (ec) std::cerr << "run_one: " << ec.message() << std::endl;
|
||||
}
|
||||
|
||||
// test rename_file
|
||||
remove(test_path / "part0");
|
||||
TEST_CHECK(exists(test_path / "temp_storage/test1.tmp"));
|
||||
TEST_CHECK(!exists(test_path / "part0"));
|
||||
remove(combine_path(test_path, "part0"), ec);
|
||||
if (ec) std::cerr << "remove: " << ec.message() << std::endl;
|
||||
TEST_CHECK(exists(combine_path(test_path, "temp_storage/test1.tmp")));
|
||||
TEST_CHECK(!exists(combine_path(test_path, "part0")));
|
||||
boost::function<void(int, disk_io_job const&)> none;
|
||||
pm->async_rename_file(0, "part0", none);
|
||||
|
||||
test_sleep(1000);
|
||||
ios.reset();
|
||||
ios.poll(ec);
|
||||
if (ec) std::cerr << "poll: " << ec.message() << std::endl;
|
||||
|
||||
TEST_CHECK(!exists(test_path / "temp_storage/test1.tmp"));
|
||||
TEST_CHECK(!exists(test_path / "temp_storage2"));
|
||||
TEST_CHECK(exists(test_path / "part0"));
|
||||
TEST_CHECK(!exists(combine_path(test_path, "temp_storage/test1.tmp")));
|
||||
TEST_CHECK(!exists(combine_path(test_path, "temp_storage2")));
|
||||
TEST_CHECK(exists(combine_path(test_path, "part0")));
|
||||
|
||||
// test move_storage with two files in the root directory
|
||||
TEST_CHECK(exists(test_path / "temp_storage"));
|
||||
pm->async_move_storage(test_path / "temp_storage2", bind(on_move_storage, _1, _2, (test_path / "temp_storage2").string()));
|
||||
TEST_CHECK(exists(combine_path(test_path, "temp_storage")));
|
||||
pm->async_move_storage(combine_path(test_path, "temp_storage2")
|
||||
, bind(on_move_storage, _1, _2, combine_path(test_path, "temp_storage2")));
|
||||
|
||||
test_sleep(2000);
|
||||
ios.reset();
|
||||
ios.poll(ec);
|
||||
if (ec) std::cerr << "poll: " << ec.message() << std::endl;
|
||||
|
||||
if (fs.num_files() > 1)
|
||||
{
|
||||
TEST_CHECK(!exists(test_path / "temp_storage"));
|
||||
TEST_CHECK(exists(test_path / "temp_storage2/temp_storage"));
|
||||
TEST_CHECK(!exists(combine_path(test_path, "temp_storage")));
|
||||
TEST_CHECK(exists(combine_path(test_path, "temp_storage2/temp_storage")));
|
||||
}
|
||||
TEST_CHECK(exists(test_path / "temp_storage2/part0"));
|
||||
TEST_CHECK(exists(combine_path(test_path, "temp_storage2/part0")));
|
||||
|
||||
pm->async_move_storage(test_path, bind(on_move_storage, _1, _2, test_path.string()));
|
||||
pm->async_move_storage(test_path, bind(on_move_storage, _1, _2, test_path));
|
||||
|
||||
test_sleep(2000);
|
||||
ios.reset();
|
||||
ios.poll(ec);
|
||||
if (ec) std::cerr << "poll: " << ec.message() << std::endl;
|
||||
|
||||
TEST_CHECK(exists(test_path / "part0"));
|
||||
TEST_CHECK(!exists(test_path / "temp_storage2/temp_storage"));
|
||||
TEST_CHECK(!exists(test_path / "temp_storage2/part0"));
|
||||
TEST_CHECK(exists(combine_path(test_path, "part0")));
|
||||
TEST_CHECK(!exists(combine_path(test_path, "temp_storage2/temp_storage")));
|
||||
TEST_CHECK(!exists(combine_path(test_path, "temp_storage2/part0")));
|
||||
|
||||
r.piece = 0;
|
||||
r.start = 0;
|
||||
@@ -449,23 +465,31 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
|
||||
test_sleep(2000);
|
||||
ios.reset();
|
||||
ios.poll(ec);
|
||||
if (ec) std::cerr << "poll: " << ec.message() << std::endl;
|
||||
|
||||
TEST_CHECK(!exists(test_path / "part0"));
|
||||
TEST_CHECK(exists(test_path / "temp_storage/test1.tmp"));
|
||||
TEST_CHECK(!exists(combine_path(test_path, "part0")));
|
||||
TEST_CHECK(exists(combine_path(test_path, "temp_storage/test1.tmp")));
|
||||
|
||||
ios.reset();
|
||||
ios.poll(ec);
|
||||
if (ec) std::cerr << "poll: " << ec.message() << std::endl;
|
||||
|
||||
io.join();
|
||||
remove_all(test_path / "temp_storage2");
|
||||
remove_all(test_path / "part0");
|
||||
remove_all(combine_path(test_path, "temp_storage2"), ec);
|
||||
if (ec) std::cerr << "remove_all: " << ec.message() << std::endl;
|
||||
remove_all(combine_path(test_path, "part0"), ec);
|
||||
if (ec) std::cerr << "remove_all: " << ec.message() << std::endl;
|
||||
}
|
||||
page_aligned_allocator::free(piece);
|
||||
}
|
||||
|
||||
void test_remove(path const& test_path, bool unbuffered)
|
||||
void test_remove(std::string const& test_path, bool unbuffered)
|
||||
{
|
||||
file_storage fs;
|
||||
error_code ec;
|
||||
remove_all(combine_path(test_path, "temp_storage"), ec);
|
||||
if (ec) std::cerr << "remove_all: " << ec.message() << std::endl;
|
||||
TEST_CHECK(!exists(combine_path(test_path, "temp_storage")));
|
||||
fs.add_file("temp_storage/test1.tmp", 8);
|
||||
fs.add_file("temp_storage/folder1/test2.tmp", 8);
|
||||
fs.add_file("temp_storage/folder2/test3.tmp", 0);
|
||||
@@ -494,12 +518,12 @@ void test_remove(path const& test_path, bool unbuffered)
|
||||
// allocate the files and create the directories
|
||||
s->initialize(true);
|
||||
|
||||
TEST_CHECK(exists(test_path / "temp_storage/_folder3/subfolder/test5.tmp"));
|
||||
TEST_CHECK(exists(test_path / "temp_storage/folder2/test3.tmp"));
|
||||
TEST_CHECK(exists(combine_path(test_path, "temp_storage/_folder3/subfolder/test5.tmp")));
|
||||
TEST_CHECK(exists(combine_path(test_path, "temp_storage/folder2/test3.tmp")));
|
||||
|
||||
s->delete_files();
|
||||
|
||||
TEST_CHECK(!exists(test_path / "temp_storage"));
|
||||
TEST_CHECK(!exists(combine_path(test_path, "temp_storage")));
|
||||
}
|
||||
|
||||
namespace
|
||||
@@ -520,14 +544,16 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void test_check_files(path const& test_path
|
||||
void test_check_files(std::string const& test_path
|
||||
, libtorrent::storage_mode_t storage_mode
|
||||
, bool unbuffered)
|
||||
{
|
||||
boost::intrusive_ptr<torrent_info> info;
|
||||
|
||||
error_code ec;
|
||||
const int piece_size = 16 * 1024;
|
||||
remove_all(test_path / "temp_storage");
|
||||
remove_all(combine_path(test_path, "temp_storage"), ec);
|
||||
if (ec) std::cerr << "remove_all: " << ec.message() << std::endl;
|
||||
file_storage fs;
|
||||
fs.add_file("temp_storage/test1.tmp", piece_size);
|
||||
fs.add_file("temp_storage/test2.tmp", piece_size * 2);
|
||||
@@ -545,13 +571,16 @@ void test_check_files(path const& test_path
|
||||
t.set_hash(2, sha1_hash(0));
|
||||
t.set_hash(3, hasher(piece2, piece_size).final());
|
||||
|
||||
create_directory(test_path / "temp_storage");
|
||||
create_directory(combine_path(test_path, "temp_storage"), ec);
|
||||
if (ec) std::cerr << "create_directory: " << ec.message() << std::endl;
|
||||
|
||||
std::ofstream f;
|
||||
f.open((test_path / "temp_storage/test1.tmp").string().c_str(), std::ios::trunc | std::ios::binary);
|
||||
f.open(combine_path(test_path, "temp_storage/test1.tmp").c_str()
|
||||
, std::ios::trunc | std::ios::binary);
|
||||
f.write(piece0, sizeof(piece0));
|
||||
f.close();
|
||||
f.open((test_path / "temp_storage/test3.tmp").string().c_str(), std::ios::trunc | std::ios::binary);
|
||||
f.open(combine_path(test_path, "temp_storage/test3.tmp").c_str()
|
||||
, std::ios::trunc | std::ios::binary);
|
||||
f.write(piece2, sizeof(piece2));
|
||||
f.close();
|
||||
|
||||
@@ -565,7 +594,6 @@ void test_check_files(path const& test_path
|
||||
, test_path, fp, io, default_storage_constructor, storage_mode);
|
||||
mutex lock;
|
||||
|
||||
error_code ec;
|
||||
bool done = false;
|
||||
lazy_entry frd;
|
||||
pm->async_check_fastresume(&frd, boost::bind(&on_check_resume_data, _1, _2, &done));
|
||||
@@ -574,6 +602,7 @@ void test_check_files(path const& test_path
|
||||
{
|
||||
ios.reset();
|
||||
ios.run_one(ec);
|
||||
if (ec) std::cerr << "run_one: " << ec.message() << std::endl;
|
||||
}
|
||||
|
||||
bool pieces[4] = {false, false, false, false};
|
||||
@@ -584,22 +613,25 @@ void test_check_files(path const& test_path
|
||||
{
|
||||
ios.reset();
|
||||
ios.run_one(ec);
|
||||
if (ec) std::cerr << "run_one: " << ec.message() << std::endl;
|
||||
}
|
||||
TEST_CHECK(pieces[0] == true);
|
||||
TEST_CHECK(pieces[1] == false);
|
||||
TEST_CHECK(pieces[2] == false);
|
||||
TEST_CHECK(pieces[3] == true);
|
||||
TEST_EQUAL(pieces[0], true);
|
||||
TEST_EQUAL(pieces[1], false);
|
||||
TEST_EQUAL(pieces[2], false);
|
||||
TEST_EQUAL(pieces[3], true);
|
||||
io.join();
|
||||
}
|
||||
|
||||
void run_test(path const& test_path, bool unbuffered)
|
||||
void run_test(std::string const& test_path, bool unbuffered)
|
||||
{
|
||||
std::cerr << "\n=== " << test_path.string() << " ===\n" << std::endl;
|
||||
std::cerr << "\n=== " << test_path << " ===\n" << std::endl;
|
||||
|
||||
boost::intrusive_ptr<torrent_info> info;
|
||||
|
||||
{
|
||||
remove_all(test_path / "temp_storage");
|
||||
error_code ec;
|
||||
remove_all(combine_path(test_path, "temp_storage"), ec);
|
||||
if (ec) std::cerr << "remove_all: " << ec.message() << std::endl;
|
||||
file_storage fs;
|
||||
fs.add_file("temp_storage/test1.tmp", 17);
|
||||
fs.add_file("temp_storage/test2.tmp", 612);
|
||||
@@ -621,25 +653,23 @@ void run_test(path const& test_path, bool unbuffered)
|
||||
run_storage_tests(info, fs, test_path, storage_mode_compact, unbuffered);
|
||||
|
||||
// make sure the files have the correct size
|
||||
TEST_CHECK(file_size(test_path / "temp_storage" / "test1.tmp") == 17);
|
||||
TEST_CHECK(file_size(test_path / "temp_storage" / "test2.tmp") == 612);
|
||||
TEST_CHECK(exists(test_path / "temp_storage/test3.tmp"));
|
||||
TEST_CHECK(exists(test_path / "temp_storage/test4.tmp"));
|
||||
TEST_CHECK(file_size(test_path / "temp_storage" / "test5.tmp") == 3253);
|
||||
TEST_CHECK(file_size(test_path / "temp_storage" / "test6.tmp") == 841);
|
||||
TEST_CHECK(file_size(test_path / "temp_storage" / "test7.tmp") == last_file_size - piece_size);
|
||||
std::cerr << file_size(test_path / "temp_storage" / "test1.tmp") << std::endl;
|
||||
std::cerr << file_size(test_path / "temp_storage" / "test2.tmp") << std::endl;
|
||||
std::cerr << file_size(test_path / "temp_storage" / "test3.tmp") << std::endl;
|
||||
std::cerr << file_size(test_path / "temp_storage" / "test4.tmp") << std::endl;
|
||||
std::cerr << file_size(test_path / "temp_storage" / "test5.tmp") << std::endl;
|
||||
std::cerr << file_size(test_path / "temp_storage" / "test6.tmp") << std::endl;
|
||||
remove_all(test_path / "temp_storage");
|
||||
std::string base = combine_path(test_path, "temp_storage");
|
||||
TEST_EQUAL(file_size(combine_path(base, "test1.tmp")), 17);
|
||||
TEST_EQUAL(file_size(combine_path(base, "test2.tmp")), 612);
|
||||
// these files should have been allocated since they are 0 sized
|
||||
TEST_CHECK(exists(combine_path(base, "test3.tmp")));
|
||||
TEST_CHECK(exists(combine_path(base, "test4.tmp")));
|
||||
TEST_EQUAL(file_size(combine_path(base, "test5.tmp")), 3253);
|
||||
TEST_EQUAL(file_size(combine_path(base, "test6.tmp")), 841);
|
||||
TEST_EQUAL(file_size(combine_path(base, "test7.tmp")), last_file_size - piece_size);
|
||||
remove_all(combine_path(test_path, "temp_storage"), ec);
|
||||
if (ec) std::cerr << "remove_all: " << ec.message() << std::endl;
|
||||
}
|
||||
|
||||
// ==============================================
|
||||
|
||||
{
|
||||
error_code ec;
|
||||
file_storage fs;
|
||||
fs.add_file("temp_storage/test1.tmp", 3 * piece_size);
|
||||
libtorrent::create_torrent t(fs, piece_size, -1, 0);
|
||||
@@ -654,8 +684,9 @@ void run_test(path const& test_path, bool unbuffered)
|
||||
|
||||
run_storage_tests(info, fs, test_path, storage_mode_compact, unbuffered);
|
||||
|
||||
TEST_CHECK(file_size(test_path / "temp_storage" / "test1.tmp") == piece_size * 3);
|
||||
remove_all(test_path / "temp_storage");
|
||||
TEST_EQUAL(file_size(combine_path(test_path, "temp_storage/test1.tmp")), piece_size * 3);
|
||||
remove_all(combine_path(test_path, "temp_storage"), ec);
|
||||
if (ec) std::cerr << "remove_all: " << ec.message() << std::endl;
|
||||
|
||||
// ==============================================
|
||||
|
||||
@@ -663,10 +694,11 @@ void run_test(path const& test_path, bool unbuffered)
|
||||
|
||||
run_storage_tests(info, fs, test_path, storage_mode_allocate, unbuffered);
|
||||
|
||||
std::cerr << file_size(test_path / "temp_storage" / "test1.tmp") << std::endl;
|
||||
TEST_CHECK(file_size(test_path / "temp_storage" / "test1.tmp") == 3 * piece_size);
|
||||
std::cerr << file_size(combine_path(test_path, "temp_storage/test1.tmp")) << std::endl;
|
||||
TEST_EQUAL(file_size(combine_path(test_path, "temp_storage/test1.tmp")), 3 * piece_size);
|
||||
|
||||
remove_all(test_path / "temp_storage");
|
||||
remove_all(combine_path(test_path, "temp_storage"), ec);
|
||||
if (ec) std::cerr << "remove_all: " << ec.message() << std::endl;
|
||||
|
||||
}
|
||||
|
||||
@@ -682,15 +714,18 @@ void run_test(path const& test_path, bool unbuffered)
|
||||
test_check_files(test_path, storage_mode_compact, unbuffered);
|
||||
}
|
||||
|
||||
void test_fastresume(path const& test_path)
|
||||
void test_fastresume(std::string const& test_path)
|
||||
{
|
||||
error_code ec;
|
||||
std::cout << "\n\n=== test fastresume ===" << std::endl;
|
||||
remove_all(test_path / "tmp1");
|
||||
create_directory(test_path / "tmp1");
|
||||
std::ofstream file((test_path / "tmp1/temporary").external_file_string().c_str());
|
||||
remove_all(combine_path(test_path, "tmp1"), ec);
|
||||
if (ec) std::cerr << "remove_all: " << ec.message() << std::endl;
|
||||
create_directory(combine_path(test_path, "tmp1"), ec);
|
||||
if (ec) std::cerr << "create_directory: " << ec.message() << std::endl;
|
||||
std::ofstream file(combine_path(test_path, "tmp1/temporary").c_str());
|
||||
boost::intrusive_ptr<torrent_info> t = ::create_torrent(&file);
|
||||
file.close();
|
||||
TEST_CHECK(exists(test_path / "tmp1/temporary"));
|
||||
TEST_CHECK(exists(combine_path(test_path, "tmp1/temporary")));
|
||||
|
||||
entry resume;
|
||||
{
|
||||
@@ -698,8 +733,7 @@ void test_fastresume(path const& test_path)
|
||||
ses.set_alert_mask(alert::all_categories);
|
||||
|
||||
torrent_handle h = ses.add_torrent(boost::intrusive_ptr<torrent_info>(new torrent_info(*t))
|
||||
, test_path / "tmp1", entry()
|
||||
, storage_mode_compact);
|
||||
, combine_path(test_path, "tmp1"), entry(), storage_mode_compact);
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
@@ -715,7 +749,7 @@ void test_fastresume(path const& test_path)
|
||||
resume = h.write_resume_data();
|
||||
ses.remove_torrent(h, session::delete_files);
|
||||
}
|
||||
TEST_CHECK(!exists(test_path / "tmp1/temporary"));
|
||||
TEST_CHECK(!exists(combine_path(test_path, "tmp1/temporary")));
|
||||
#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM
|
||||
resume.print(std::cout);
|
||||
#endif
|
||||
@@ -724,7 +758,7 @@ void test_fastresume(path const& test_path)
|
||||
{
|
||||
session ses(fingerprint(" ", 0,0,0,0), 0);
|
||||
ses.set_alert_mask(alert::all_categories);
|
||||
torrent_handle h = ses.add_torrent(t, test_path / "tmp1", resume
|
||||
torrent_handle h = ses.add_torrent(t, combine_path(test_path, "tmp1"), resume
|
||||
, storage_mode_compact);
|
||||
|
||||
std::auto_ptr<alert> a = ses.pop_alert();
|
||||
@@ -742,7 +776,8 @@ void test_fastresume(path const& test_path)
|
||||
}
|
||||
TEST_CHECK(dynamic_cast<fastresume_rejected_alert*>(a.get()) != 0);
|
||||
}
|
||||
remove_all(test_path / "tmp1");
|
||||
remove_all(combine_path(test_path, "tmp1"), ec);
|
||||
if (ec) std::cerr << "remove_all: " << ec.message() << std::endl;
|
||||
}
|
||||
|
||||
bool got_file_rename_alert(alert* a)
|
||||
@@ -751,15 +786,18 @@ bool got_file_rename_alert(alert* a)
|
||||
|| dynamic_cast<libtorrent::file_rename_failed_alert*>(a);
|
||||
}
|
||||
|
||||
void test_rename_file_in_fastresume(path const& test_path)
|
||||
void test_rename_file_in_fastresume(std::string const& test_path)
|
||||
{
|
||||
error_code ec;
|
||||
std::cout << "\n\n=== test rename file in fastresume ===" << std::endl;
|
||||
remove_all(test_path / "tmp2");
|
||||
create_directory(test_path / "tmp2");
|
||||
std::ofstream file((test_path / "tmp2/temporary").external_file_string().c_str());
|
||||
remove_all(combine_path(test_path, "tmp2"), ec);
|
||||
if (ec) std::cerr << "remove_all: " << ec.message() << std::endl;
|
||||
create_directory(combine_path(test_path, "tmp2"), ec);
|
||||
if (ec) std::cerr << "create_directory: " << ec.message() << std::endl;
|
||||
std::ofstream file(combine_path(test_path, "tmp2/temporary").c_str());
|
||||
boost::intrusive_ptr<torrent_info> t = ::create_torrent(&file);
|
||||
file.close();
|
||||
TEST_CHECK(exists(test_path / "tmp2/temporary"));
|
||||
TEST_CHECK(exists(combine_path(test_path, "tmp2/temporary")));
|
||||
|
||||
entry resume;
|
||||
{
|
||||
@@ -767,7 +805,7 @@ void test_rename_file_in_fastresume(path const& test_path)
|
||||
ses.set_alert_mask(alert::all_categories);
|
||||
|
||||
torrent_handle h = ses.add_torrent(boost::intrusive_ptr<torrent_info>(new torrent_info(*t))
|
||||
, test_path / "tmp2", entry()
|
||||
, combine_path(test_path, "tmp2"), entry()
|
||||
, storage_mode_compact);
|
||||
|
||||
h.rename_file(0, "testing_renamed_files");
|
||||
@@ -786,8 +824,8 @@ void test_rename_file_in_fastresume(path const& test_path)
|
||||
resume = h.write_resume_data();
|
||||
ses.remove_torrent(h);
|
||||
}
|
||||
TEST_CHECK(!exists(test_path / "tmp2/temporary"));
|
||||
TEST_CHECK(exists(test_path / "tmp2/testing_renamed_files"));
|
||||
TEST_CHECK(!exists(combine_path(test_path, "tmp2/temporary")));
|
||||
TEST_CHECK(exists(combine_path(test_path, "tmp2/testing_renamed_files")));
|
||||
TEST_CHECK(resume.dict().find("mapped_files") != resume.dict().end());
|
||||
#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM
|
||||
resume.print(std::cout);
|
||||
@@ -797,7 +835,7 @@ void test_rename_file_in_fastresume(path const& test_path)
|
||||
{
|
||||
session ses(fingerprint(" ", 0,0,0,0), 0);
|
||||
ses.set_alert_mask(alert::all_categories);
|
||||
torrent_handle h = ses.add_torrent(t, test_path / "tmp2", resume
|
||||
torrent_handle h = ses.add_torrent(t, combine_path(test_path, "tmp2"), resume
|
||||
, storage_mode_compact);
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
@@ -815,7 +853,8 @@ void test_rename_file_in_fastresume(path const& test_path)
|
||||
#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM
|
||||
resume.print(std::cout);
|
||||
#endif
|
||||
remove_all(test_path / "tmp2");
|
||||
remove_all(combine_path(test_path, "tmp2"), ec);
|
||||
if (ec) std::cerr << "remove_all: " << ec.message() << std::endl;
|
||||
}
|
||||
|
||||
int test_main()
|
||||
@@ -831,11 +870,11 @@ int test_main()
|
||||
for (char* p = piece2, *end(piece2 + piece_size); p < end; ++p)
|
||||
*p = rand();
|
||||
|
||||
std::vector<path> test_paths;
|
||||
std::vector<std::string> test_paths;
|
||||
char* env = std::getenv("TORRENT_TEST_PATHS");
|
||||
if (env == 0)
|
||||
{
|
||||
test_paths.push_back(initial_path<path>());
|
||||
test_paths.push_back(current_working_directory());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -36,22 +36,19 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
|
||||
using boost::filesystem::remove_all;
|
||||
using boost::filesystem::exists;
|
||||
|
||||
void test_swarm(bool super_seeding = false, bool strict = false, bool seed_mode = false, bool time_critical = false)
|
||||
{
|
||||
using namespace libtorrent;
|
||||
|
||||
// in case the previous run was terminated
|
||||
try { remove_all("./tmp1_swarm"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp2_swarm"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp3_swarm"); } catch (std::exception&) {}
|
||||
error_code ec;
|
||||
remove_all("./tmp1_swarm", ec);
|
||||
remove_all("./tmp2_swarm", ec);
|
||||
remove_all("./tmp3_swarm", ec);
|
||||
|
||||
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48000, 49000), "0.0.0.0", 0);
|
||||
session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49000, 50000), "0.0.0.0", 0);
|
||||
@@ -201,15 +198,14 @@ void test_swarm(bool super_seeding = false, bool strict = false, bool seed_mode
|
||||
TEST_CHECK(!exists("./tmp2_swarm/temporary"));
|
||||
TEST_CHECK(!exists("./tmp3_swarm/temporary"));
|
||||
|
||||
remove_all("./tmp1_swarm");
|
||||
remove_all("./tmp2_swarm");
|
||||
remove_all("./tmp3_swarm");
|
||||
remove_all("./tmp1_swarm", ec);
|
||||
remove_all("./tmp2_swarm", ec);
|
||||
remove_all("./tmp3_swarm", ec);
|
||||
}
|
||||
|
||||
int test_main()
|
||||
{
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
// with time critical pieces
|
||||
test_swarm(false, false, false, true);
|
||||
|
@@ -34,8 +34,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/convenience.hpp>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
@@ -43,7 +41,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/extensions/ut_metadata.hpp"
|
||||
#include "libtorrent/extensions/lt_trackers.hpp"
|
||||
|
||||
using boost::filesystem::remove_all;
|
||||
using boost::tuples::ignore;
|
||||
|
||||
int test_main()
|
||||
|
@@ -37,14 +37,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/bencode.hpp"
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
|
||||
using boost::filesystem::remove_all;
|
||||
using boost::filesystem::exists;
|
||||
using boost::filesystem::create_directory;
|
||||
using namespace libtorrent;
|
||||
using boost::tuples::ignore;
|
||||
|
||||
@@ -52,10 +48,11 @@ using boost::tuples::ignore;
|
||||
void test_rate()
|
||||
{
|
||||
// in case the previous run was terminated
|
||||
try { remove_all("./tmp1_transfer"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp2_transfer"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp1_transfer_moved"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp2_transfer_moved"); } catch (std::exception&) {}
|
||||
error_code ec;
|
||||
remove_all("./tmp1_transfer", ec);
|
||||
remove_all("./tmp2_transfer", ec);
|
||||
remove_all("./tmp1_transfer_moved", ec);
|
||||
remove_all("./tmp2_transfer_moved", ec);
|
||||
|
||||
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48575, 49000), "0.0.0.0", 0);
|
||||
session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49575, 50000), "0.0.0.0", 0);
|
||||
@@ -63,7 +60,7 @@ void test_rate()
|
||||
torrent_handle tor1;
|
||||
torrent_handle tor2;
|
||||
|
||||
create_directory("./tmp1_transfer");
|
||||
create_directory("./tmp1_transfer", ec);
|
||||
std::ofstream file("./tmp1_transfer/temporary");
|
||||
boost::intrusive_ptr<torrent_info> t = ::create_torrent(&file, 4 * 1024 * 1024, 7);
|
||||
file.close();
|
||||
@@ -114,7 +111,7 @@ void print_alert(alert const& a)
|
||||
// simulate a full disk
|
||||
struct test_storage : storage_interface
|
||||
{
|
||||
test_storage(file_storage const& fs, fs::path const& p, file_pool& fp)
|
||||
test_storage(file_storage const& fs, std::string const& p, file_pool& fp)
|
||||
: m_lower_layer(default_storage_constructor(fs, 0, p, fp))
|
||||
, m_written(0)
|
||||
, m_limit(16 * 1024 * 2)
|
||||
@@ -174,7 +171,7 @@ struct test_storage : storage_interface
|
||||
virtual int sparse_end(int start) const
|
||||
{ return m_lower_layer->sparse_end(start); }
|
||||
|
||||
virtual bool move_storage(fs::path save_path)
|
||||
virtual bool move_storage(std::string const& save_path)
|
||||
{ return m_lower_layer->move_storage(save_path); }
|
||||
|
||||
virtual bool verify_resume_data(lazy_entry const& rd, error_code& error)
|
||||
@@ -207,7 +204,7 @@ struct test_storage : storage_interface
|
||||
};
|
||||
|
||||
storage_interface* test_storage_constructor(file_storage const& fs
|
||||
, file_storage const*, fs::path const& path, file_pool& fp)
|
||||
, file_storage const*, std::string const& path, file_pool& fp)
|
||||
{
|
||||
return new test_storage(fs, path, fp);
|
||||
}
|
||||
@@ -215,10 +212,11 @@ storage_interface* test_storage_constructor(file_storage const& fs
|
||||
void test_transfer(bool test_disk_full = false, bool test_allowed_fast = false)
|
||||
{
|
||||
// in case the previous run was terminated
|
||||
try { remove_all("./tmp1_transfer"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp2_transfer"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp1_transfer_moved"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp2_transfer_moved"); } catch (std::exception&) {}
|
||||
error_code ec;
|
||||
remove_all("./tmp1_transfer", ec);
|
||||
remove_all("./tmp2_transfer", ec);
|
||||
remove_all("./tmp1_transfer_moved", ec);
|
||||
remove_all("./tmp2_transfer_moved", ec);
|
||||
|
||||
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48075, 49000), "0.0.0.0", 0);
|
||||
session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49075, 50000), "0.0.0.0", 0);
|
||||
@@ -242,7 +240,7 @@ void test_transfer(bool test_disk_full = false, bool test_allowed_fast = false)
|
||||
torrent_handle tor1;
|
||||
torrent_handle tor2;
|
||||
|
||||
create_directory("./tmp1_transfer");
|
||||
create_directory("./tmp1_transfer", ec);
|
||||
std::ofstream file("./tmp1_transfer/temporary");
|
||||
boost::intrusive_ptr<torrent_info> t = ::create_torrent(&file, 16 * 1024);
|
||||
file.close();
|
||||
@@ -456,7 +454,6 @@ void test_transfer(bool test_disk_full = false, bool test_allowed_fast = false)
|
||||
int test_main()
|
||||
{
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
#ifdef NDEBUG
|
||||
// test rate only makes sense in release mode
|
||||
@@ -471,10 +468,11 @@ int test_main()
|
||||
// test allowed fast
|
||||
test_transfer(false, true);
|
||||
|
||||
try { remove_all("./tmp1_transfer"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp2_transfer"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp1_transfer_moved"); } catch (std::exception&) {}
|
||||
try { remove_all("./tmp2_transfer_moved"); } catch (std::exception&) {}
|
||||
error_code ec;
|
||||
remove_all("./tmp1_transfer", ec);
|
||||
remove_all("./tmp2_transfer", ec);
|
||||
remove_all("./tmp1_transfer_moved", ec);
|
||||
remove_all("./tmp2_transfer_moved", ec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -38,13 +38,11 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/create_torrent.hpp"
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <fstream>
|
||||
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
|
||||
using namespace boost::filesystem;
|
||||
using namespace libtorrent;
|
||||
|
||||
// proxy: 0=none, 1=socks4, 2=socks5, 3=socks5_pw 4=http 5=http_pw
|
||||
@@ -60,7 +58,8 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file, int proxy)
|
||||
ses.set_alert_mask(~alert::progress_notification);
|
||||
ses.listen_on(std::make_pair(51000, 52000));
|
||||
ses.set_download_rate_limit(torrent_file->total_size() / 10);
|
||||
remove_all("./tmp2_web_seed");
|
||||
error_code ec;
|
||||
remove_all("./tmp2_web_seed", ec);
|
||||
|
||||
char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"};
|
||||
|
||||
@@ -139,22 +138,16 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file, int proxy)
|
||||
|
||||
if (proxy) stop_proxy(8002);
|
||||
|
||||
TEST_CHECK(exists("./tmp2_web_seed" / torrent_file->file_at(0).path));
|
||||
remove_all("./tmp2_web_seed");
|
||||
TEST_CHECK(exists(combine_path("./tmp2_web_seed", torrent_file->file_at(0).path)));
|
||||
remove_all("./tmp2_web_seed", ec);
|
||||
}
|
||||
|
||||
int test_main()
|
||||
{
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
try {
|
||||
create_directory("./tmp1_web_seed");
|
||||
} catch (std::exception&) {}
|
||||
|
||||
try {
|
||||
create_directory("./tmp1_web_seed/test_torrent_dir");
|
||||
} catch (std::exception&) {}
|
||||
error_code ec;
|
||||
create_directories("./tmp1_web_seed/test_torrent_dir", ec);
|
||||
|
||||
char random_data[300000];
|
||||
std::srand(10);
|
||||
@@ -169,7 +162,7 @@ int test_main()
|
||||
std::ofstream("./tmp1_web_seed/test_torrent_dir/test7").write(random_data, 300000);
|
||||
|
||||
file_storage fs;
|
||||
add_files(fs, path("./tmp1_web_seed/test_torrent_dir"));
|
||||
add_files(fs, "./tmp1_web_seed/test_torrent_dir");
|
||||
|
||||
libtorrent::create_torrent t(fs, 16 * 1024);
|
||||
t.add_url_seed("http://127.0.0.1:8000/tmp1_web_seed");
|
||||
@@ -187,7 +180,7 @@ int test_main()
|
||||
test_transfer(torrent_file, 0);
|
||||
|
||||
stop_web_server(8000);
|
||||
remove_all("./tmp1_web_seed");
|
||||
remove_all("./tmp1_web_seed", ec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user