forked from premiere/premiere-libtorrent
more torrent parsing unit tests and fixing some previously broken by changes to parse_url_components
This commit is contained in:
parent
ba6770ccd8
commit
4241e279bd
|
@ -908,7 +908,7 @@ namespace libtorrent
|
||||||
e.size = info.dict_find_int_value("length", -1);
|
e.size = info.dict_find_int_value("length", -1);
|
||||||
if (e.size < 0)
|
if (e.size < 0)
|
||||||
{
|
{
|
||||||
ec = errors::torrent_file_parse_failed;
|
ec = errors::torrent_invalid_length;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
e.mtime = info.dict_find_int_value("mtime", 0);
|
e.mtime = info.dict_find_int_value("mtime", 0);
|
||||||
|
@ -943,11 +943,6 @@ namespace libtorrent
|
||||||
// bitcomet pad file
|
// bitcomet pad file
|
||||||
if (e.path.find("_____padding_file_") != std::string::npos)
|
if (e.path.find("_____padding_file_") != std::string::npos)
|
||||||
e.pad_file = true;
|
e.pad_file = true;
|
||||||
if (e.size < 0)
|
|
||||||
{
|
|
||||||
ec = errors::torrent_invalid_length;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_files.add_file(e, fh ? fh->string_ptr() + info_ptr_diff : 0);
|
m_files.add_file(e, fh ? fh->string_ptr() + info_ptr_diff : 0);
|
||||||
m_multifile = false;
|
m_multifile = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,11 @@ EXTRA_DIST = Jamfile \
|
||||||
test_torrents/url_seed.torrent \
|
test_torrents/url_seed.torrent \
|
||||||
test_torrents/url_seed_multi.torrent \
|
test_torrents/url_seed_multi.torrent \
|
||||||
test_torrents/url_seed_multi_space.torrent \
|
test_torrents/url_seed_multi_space.torrent \
|
||||||
test_torrents/url_seed_multi_space_nolist.torrent
|
test_torrents/url_seed_multi_space_nolist.torrent \
|
||||||
|
test_torrents/invalid_root_hash.torrent \
|
||||||
|
test_torrents/invalid_root_hash2.torrent \
|
||||||
|
test_torrents/root_hash.torrent \
|
||||||
|
test_torrents/invalid_file_size.torrent
|
||||||
|
|
||||||
EXTRA_PROGRAMS = $(test_programs)
|
EXTRA_PROGRAMS = $(test_programs)
|
||||||
|
|
||||||
|
|
|
@ -1154,16 +1154,16 @@ int test_main()
|
||||||
== make_tuple("http", "foo:bar", "host.com", 80, "/path/to/file"));
|
== make_tuple("http", "foo:bar", "host.com", 80, "/path/to/file"));
|
||||||
|
|
||||||
TEST_CHECK(parse_url_components("http://host.com/path/to/file", ec)
|
TEST_CHECK(parse_url_components("http://host.com/path/to/file", ec)
|
||||||
== make_tuple("http", "", "host.com", 80, "/path/to/file"));
|
== make_tuple("http", "", "host.com", -1, "/path/to/file"));
|
||||||
|
|
||||||
TEST_CHECK(parse_url_components("ftp://host.com:21/path/to/file", ec)
|
TEST_CHECK(parse_url_components("ftp://host.com:21/path/to/file", ec)
|
||||||
== make_tuple("ftp", "", "host.com", 21, "/path/to/file"));
|
== make_tuple("ftp", "", "host.com", 21, "/path/to/file"));
|
||||||
|
|
||||||
TEST_CHECK(parse_url_components("http://host.com/path?foo:bar@foo:", ec)
|
TEST_CHECK(parse_url_components("http://host.com/path?foo:bar@foo:", ec)
|
||||||
== make_tuple("http", "", "host.com", 80, "/path?foo:bar@foo:"));
|
== make_tuple("http", "", "host.com", -1, "/path?foo:bar@foo:"));
|
||||||
|
|
||||||
TEST_CHECK(parse_url_components("http://192.168.0.1/path/to/file", ec)
|
TEST_CHECK(parse_url_components("http://192.168.0.1/path/to/file", ec)
|
||||||
== make_tuple("http", "", "192.168.0.1", 80, "/path/to/file"));
|
== make_tuple("http", "", "192.168.0.1", -1, "/path/to/file"));
|
||||||
|
|
||||||
TEST_CHECK(parse_url_components("http://[2001:ff00::1]:42/path/to/file", ec)
|
TEST_CHECK(parse_url_components("http://[2001:ff00::1]:42/path/to/file", ec)
|
||||||
== make_tuple("http", "", "[2001:ff00::1]", 42, "/path/to/file"));
|
== make_tuple("http", "", "[2001:ff00::1]", 42, "/path/to/file"));
|
||||||
|
@ -1253,7 +1253,7 @@ int test_main()
|
||||||
TEST_CHECK(need_encoding("\n", 1) == true);
|
TEST_CHECK(need_encoding("\n", 1) == true);
|
||||||
|
|
||||||
// maybe_url_encode
|
// maybe_url_encode
|
||||||
TEST_CHECK(maybe_url_encode("http://bla.com/\n") == "http://bla.com:80/%0a");
|
TEST_CHECK(maybe_url_encode("http://bla.com/\n") == "http://bla.com/%0a");
|
||||||
std::cerr << maybe_url_encode("http://bla.com/\n") << std::endl;
|
std::cerr << maybe_url_encode("http://bla.com/\n") << std::endl;
|
||||||
TEST_CHECK(maybe_url_encode("?&") == "?&");
|
TEST_CHECK(maybe_url_encode("?&") == "?&");
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,7 @@ test_torrent_t test_torrents[] =
|
||||||
{ "url_seed_multi.torrent" },
|
{ "url_seed_multi.torrent" },
|
||||||
{ "url_seed_multi_space.torrent" },
|
{ "url_seed_multi_space.torrent" },
|
||||||
{ "url_seed_multi_space_nolist.torrent" },
|
{ "url_seed_multi_space_nolist.torrent" },
|
||||||
|
{ "root_hash.torrent" },
|
||||||
};
|
};
|
||||||
|
|
||||||
struct test_failing_torrent_t
|
struct test_failing_torrent_t
|
||||||
|
@ -87,17 +88,18 @@ test_failing_torrent_t test_error_torrents[] =
|
||||||
{ "invalid_name2.torrent", errors::torrent_invalid_name },
|
{ "invalid_name2.torrent", errors::torrent_invalid_name },
|
||||||
{ "invalid_info.torrent", errors::torrent_missing_info },
|
{ "invalid_info.torrent", errors::torrent_missing_info },
|
||||||
{ "string.torrent", errors::torrent_is_no_dict },
|
{ "string.torrent", errors::torrent_is_no_dict },
|
||||||
{ "negative_size.torrent", errors::torrent_file_parse_failed},
|
{ "negative_size.torrent", errors::torrent_invalid_length },
|
||||||
{ "negative_file_size.torrent", errors::torrent_file_parse_failed },
|
{ "negative_file_size.torrent", errors::torrent_file_parse_failed },
|
||||||
{ "invalid_path_list.torrent", errors::torrent_file_parse_failed },
|
{ "invalid_path_list.torrent", errors::torrent_file_parse_failed },
|
||||||
{ "missing_path_list.torrent", errors::torrent_file_parse_failed },
|
{ "missing_path_list.torrent", errors::torrent_file_parse_failed },
|
||||||
{ "invalid_pieces.torrent", errors::torrent_missing_pieces },
|
{ "invalid_pieces.torrent", errors::torrent_missing_pieces },
|
||||||
{ "unaligned_pieces.torrent", errors::torrent_invalid_hashes },
|
{ "unaligned_pieces.torrent", errors::torrent_invalid_hashes },
|
||||||
|
{ "invalid_root_hash.torrent", errors::torrent_invalid_hashes },
|
||||||
|
{ "invalid_root_hash2.torrent", errors::torrent_invalid_hashes },
|
||||||
|
{ "invalid_file_size.torrent", errors::torrent_file_parse_failed },
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: create a separate list of all torrents that should
|
// TODO: test remap_files
|
||||||
// fail to parse, and include the expected error code in that list
|
|
||||||
|
|
||||||
// TODO: merkle torrents. specifically torrent_info::add_merkle_nodes and torrent with "root hash"
|
// TODO: merkle torrents. specifically torrent_info::add_merkle_nodes and torrent with "root hash"
|
||||||
// TODO: torrent with 'p' (padfile) attribute
|
// TODO: torrent with 'p' (padfile) attribute
|
||||||
// TODO: torrent with 'h' (hidden) attribute
|
// TODO: torrent with 'h' (hidden) attribute
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesld4:pathl3:foo7:bar.txte6:lengthli45eeed4:pathl3:foo7:var.txte6:lengthi24124eee4:name4:temp12:piece lengthi16384e6:pieces20:‚ž¼Œ&¾ÇJW›}ÜA4u,·¼‘‡ee
|
|
@ -0,0 +1 @@
|
||||||
|
d10:created by10:libtorrent13:creation datei1359599503e4:infod6:lengthi425e4:name4:temp12:piece lengthi16384e9:root hash19:ž¼Œ&¾ÇJW›}ÜA4u,·¼‘‡ee
|
|
@ -0,0 +1 @@
|
||||||
|
d10:created by10:libtorrent13:creation datei1359599503e4:infod6:lengthi425e4:name4:temp12:piece lengthi16384e9:root hash20:‚ž¼Œ&¾ÇJW›}ÜA4u,·¼‘‡ee
|
Loading…
Reference in New Issue