2013-01-31 04:39:14 +01:00
/*
Copyright ( c ) 2013 , Arvid Norberg
All rights reserved .
Redistribution and use in source and binary forms , with or without
modification , are permitted provided that the following conditions
are met :
* Redistributions of source code must retain the above copyright
notice , this list of conditions and the following disclaimer .
* Redistributions in binary form must reproduce the above copyright
notice , this list of conditions and the following disclaimer in
the documentation and / or other materials provided with the distribution .
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS " AS IS "
AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR
CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS
INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN
CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE )
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE .
*/
# include "test.hpp"
# include "libtorrent/file.hpp"
# include "libtorrent/torrent_info.hpp"
2013-09-01 08:52:50 +02:00
# include "libtorrent/bencode.hpp"
2013-01-31 04:39:14 +01:00
2013-02-26 06:57:29 +01:00
# if TORRENT_USE_IOSTREAM
# include <sstream>
# endif
2013-01-31 04:39:14 +01:00
struct test_torrent_t
{
char const * file ;
} ;
using namespace libtorrent ;
test_torrent_t test_torrents [ ] =
{
{ " base.torrent " } ,
{ " empty_path.torrent " } ,
{ " parent_path.torrent " } ,
{ " hidden_parent_path.torrent " } ,
{ " single_multi_file.torrent " } ,
{ " slash_path.torrent " } ,
{ " backslash_path.torrent " } ,
{ " url_list.torrent " } ,
{ " url_list2.torrent " } ,
{ " url_list3.torrent " } ,
{ " httpseed.torrent " } ,
{ " empty_httpseed.torrent " } ,
2013-02-06 19:51:42 +01:00
{ " long_name.torrent " } ,
2013-02-24 11:02:26 +01:00
{ " whitespace_url.torrent " } ,
{ " duplicate_files.torrent " } ,
2013-02-25 02:54:38 +01:00
{ " pad_file.torrent " } ,
{ " creation_date.torrent " } ,
2013-02-26 06:57:29 +01:00
{ " no_creation_date.torrent " } ,
{ " url_seed.torrent " } ,
{ " url_seed_multi.torrent " } ,
{ " url_seed_multi_space.torrent " } ,
{ " url_seed_multi_space_nolist.torrent " } ,
2013-02-26 08:32:53 +01:00
{ " root_hash.torrent " } ,
2013-10-24 09:22:44 +02:00
{ " empty_path_multi.torrent " } ,
2013-12-05 08:40:57 +01:00
{ " invalid_name3.torrent " } ,
2013-02-25 02:54:38 +01:00
} ;
struct test_failing_torrent_t
{
char const * file ;
error_code error ; // the expected error
} ;
test_failing_torrent_t test_error_torrents [ ] =
{
{ " missing_piece_len.torrent " , errors : : torrent_missing_piece_length } ,
{ " invalid_piece_len.torrent " , errors : : torrent_missing_piece_length } ,
{ " negative_piece_len.torrent " , errors : : torrent_missing_piece_length } ,
{ " no_name.torrent " , errors : : torrent_missing_name } ,
{ " invalid_name.torrent " , errors : : torrent_missing_name } ,
{ " invalid_name2.torrent " , errors : : torrent_invalid_name } ,
{ " invalid_info.torrent " , errors : : torrent_missing_info } ,
{ " string.torrent " , errors : : torrent_is_no_dict } ,
2013-02-26 08:32:53 +01:00
{ " negative_size.torrent " , errors : : torrent_invalid_length } ,
2013-02-25 02:54:38 +01:00
{ " negative_file_size.torrent " , errors : : torrent_file_parse_failed } ,
{ " invalid_path_list.torrent " , errors : : torrent_file_parse_failed } ,
{ " missing_path_list.torrent " , errors : : torrent_file_parse_failed } ,
{ " invalid_pieces.torrent " , errors : : torrent_missing_pieces } ,
{ " unaligned_pieces.torrent " , errors : : torrent_invalid_hashes } ,
2013-02-26 08:32:53 +01:00
{ " invalid_root_hash.torrent " , errors : : torrent_invalid_hashes } ,
2013-03-05 01:32:57 +01:00
{ " invalid_root_hash2.torrent " , errors : : torrent_missing_pieces } ,
2013-02-26 08:32:53 +01:00
{ " invalid_file_size.torrent " , errors : : torrent_file_parse_failed } ,
2013-01-31 04:39:14 +01:00
} ;
2013-09-01 08:52:50 +02:00
namespace libtorrent
{
// defined in torrent_info.cpp
TORRENT_EXPORT bool verify_encoding ( std : : string & target , bool path = true ) ;
TORRENT_EXPORT std : : string sanitize_path ( std : : string const & p ) ;
}
2013-02-26 08:32:53 +01:00
// TODO: test remap_files
2013-02-24 11:02:26 +01:00
// TODO: merkle torrents. specifically torrent_info::add_merkle_nodes and torrent with "root hash"
// TODO: torrent with 'p' (padfile) attribute
// TODO: torrent with 'h' (hidden) attribute
// TODO: torrent with 'x' (executable) attribute
// TODO: torrent with 'l' (symlink) attribute
// TODO: creating a merkle torrent (torrent_info::build_merkle_list)
// TODO: torrent with multiple trackers in multiple tiers, making sure we shuffle them (how do you test shuffling?, load it multiple times and make sure it's in different order at least once)
2013-01-31 04:39:14 +01:00
int test_main ( )
{
2013-09-01 08:52:50 +02:00
error_code ec ;
// test merkle_*() functions
// this is the structure:
// 0
// 1 2
// 3 4 5 6
// 7 8 9 10 11 12 13 14
// num_leafs = 8
TEST_EQUAL ( merkle_num_leafs ( 1 ) , 1 ) ;
TEST_EQUAL ( merkle_num_leafs ( 2 ) , 2 ) ;
TEST_EQUAL ( merkle_num_leafs ( 3 ) , 4 ) ;
TEST_EQUAL ( merkle_num_leafs ( 4 ) , 4 ) ;
TEST_EQUAL ( merkle_num_leafs ( 5 ) , 8 ) ;
TEST_EQUAL ( merkle_num_leafs ( 6 ) , 8 ) ;
TEST_EQUAL ( merkle_num_leafs ( 7 ) , 8 ) ;
TEST_EQUAL ( merkle_num_leafs ( 8 ) , 8 ) ;
TEST_EQUAL ( merkle_num_leafs ( 9 ) , 16 ) ;
TEST_EQUAL ( merkle_num_leafs ( 10 ) , 16 ) ;
TEST_EQUAL ( merkle_num_leafs ( 11 ) , 16 ) ;
TEST_EQUAL ( merkle_num_leafs ( 12 ) , 16 ) ;
TEST_EQUAL ( merkle_num_leafs ( 13 ) , 16 ) ;
TEST_EQUAL ( merkle_num_leafs ( 14 ) , 16 ) ;
TEST_EQUAL ( merkle_num_leafs ( 15 ) , 16 ) ;
TEST_EQUAL ( merkle_num_leafs ( 16 ) , 16 ) ;
TEST_EQUAL ( merkle_num_leafs ( 17 ) , 32 ) ;
TEST_EQUAL ( merkle_num_leafs ( 18 ) , 32 ) ;
// parents
TEST_EQUAL ( merkle_get_parent ( 1 ) , 0 ) ;
TEST_EQUAL ( merkle_get_parent ( 2 ) , 0 ) ;
TEST_EQUAL ( merkle_get_parent ( 3 ) , 1 ) ;
TEST_EQUAL ( merkle_get_parent ( 4 ) , 1 ) ;
TEST_EQUAL ( merkle_get_parent ( 5 ) , 2 ) ;
TEST_EQUAL ( merkle_get_parent ( 6 ) , 2 ) ;
TEST_EQUAL ( merkle_get_parent ( 7 ) , 3 ) ;
TEST_EQUAL ( merkle_get_parent ( 8 ) , 3 ) ;
TEST_EQUAL ( merkle_get_parent ( 9 ) , 4 ) ;
TEST_EQUAL ( merkle_get_parent ( 10 ) , 4 ) ;
TEST_EQUAL ( merkle_get_parent ( 11 ) , 5 ) ;
TEST_EQUAL ( merkle_get_parent ( 12 ) , 5 ) ;
TEST_EQUAL ( merkle_get_parent ( 13 ) , 6 ) ;
TEST_EQUAL ( merkle_get_parent ( 14 ) , 6 ) ;
// siblings
TEST_EQUAL ( merkle_get_sibling ( 1 ) , 2 ) ;
TEST_EQUAL ( merkle_get_sibling ( 2 ) , 1 ) ;
TEST_EQUAL ( merkle_get_sibling ( 3 ) , 4 ) ;
TEST_EQUAL ( merkle_get_sibling ( 4 ) , 3 ) ;
TEST_EQUAL ( merkle_get_sibling ( 5 ) , 6 ) ;
TEST_EQUAL ( merkle_get_sibling ( 6 ) , 5 ) ;
TEST_EQUAL ( merkle_get_sibling ( 7 ) , 8 ) ;
TEST_EQUAL ( merkle_get_sibling ( 8 ) , 7 ) ;
TEST_EQUAL ( merkle_get_sibling ( 9 ) , 10 ) ;
TEST_EQUAL ( merkle_get_sibling ( 10 ) , 9 ) ;
TEST_EQUAL ( merkle_get_sibling ( 11 ) , 12 ) ;
TEST_EQUAL ( merkle_get_sibling ( 12 ) , 11 ) ;
TEST_EQUAL ( merkle_get_sibling ( 13 ) , 14 ) ;
TEST_EQUAL ( merkle_get_sibling ( 14 ) , 13 ) ;
// total number of nodes given the number of leafs
TEST_EQUAL ( merkle_num_nodes ( 1 ) , 1 ) ;
TEST_EQUAL ( merkle_num_nodes ( 2 ) , 3 ) ;
TEST_EQUAL ( merkle_num_nodes ( 4 ) , 7 ) ;
TEST_EQUAL ( merkle_num_nodes ( 8 ) , 15 ) ;
TEST_EQUAL ( merkle_num_nodes ( 16 ) , 31 ) ;
// test sanitize_path
# ifdef TORRENT_WINDOWS
TEST_EQUAL ( sanitize_path ( " /a/b/c " ) , " a \\ b \\ c " ) ;
TEST_EQUAL ( sanitize_path ( " a/../c " ) , " a \\ c " ) ;
# else
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
// test torrent parsing
entry info ;
info [ " pieces " ] = " aaaaaaaaaaaaaaaaaaaa " ;
info [ " name.utf-8 " ] = " test1 " ;
info [ " name " ] = " test__ " ;
info [ " piece length " ] = 16 * 1024 ;
info [ " length " ] = 3245 ;
entry torrent ;
torrent [ " info " ] = info ;
std : : vector < char > buf ;
bencode ( std : : back_inserter ( buf ) , torrent ) ;
torrent_info ti ( & buf [ 0 ] , buf . size ( ) , ec ) ;
std : : cerr < < ti . name ( ) < < std : : endl ;
TEST_CHECK ( ti . name ( ) = = " test1 " ) ;
# ifdef TORRENT_WINDOWS
info [ " name.utf-8 " ] = " c:/test1/test2/test3 " ;
# else
info [ " name.utf-8 " ] = " /test1/test2/test3 " ;
# endif
torrent [ " info " ] = info ;
buf . clear ( ) ;
bencode ( std : : back_inserter ( buf ) , torrent ) ;
torrent_info ti2 ( & buf [ 0 ] , buf . size ( ) , ec ) ;
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 ;
buf . clear ( ) ;
bencode ( std : : back_inserter ( buf ) , torrent ) ;
torrent_info ti3 ( & buf [ 0 ] , buf . size ( ) , ec ) ;
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
// verify_encoding
std : : string test = " \b ?filename=4 " ;
TEST_CHECK ( ! verify_encoding ( test ) ) ;
# ifdef TORRENT_WINDOWS
TEST_CHECK ( test = = " __filename=4 " ) ;
# else
TEST_CHECK ( test = = " _?filename=4 " ) ;
# endif
test = " filename=4 " ;
TEST_CHECK ( verify_encoding ( test ) ) ;
TEST_CHECK ( test = = " filename=4 " ) ;
// valid 2-byte sequence
test = " filename \xc2 \xa1 " ;
TEST_CHECK ( verify_encoding ( test ) ) ;
fprintf ( stderr , " %s \n " , test . c_str ( ) ) ;
TEST_CHECK ( test = = " filename \xc2 \xa1 " ) ;
// truncated 2-byte sequence
test = " filename \xc2 " ;
TEST_CHECK ( ! verify_encoding ( test ) ) ;
fprintf ( stderr , " %s \n " , test . c_str ( ) ) ;
TEST_CHECK ( test = = " filename_ " ) ;
// valid 3-byte sequence
test = " filename \xe2 \x9f \xb9 " ;
TEST_CHECK ( verify_encoding ( test ) ) ;
fprintf ( stderr , " %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 ) ) ;
fprintf ( stderr , " %s \n " , test . c_str ( ) ) ;
TEST_CHECK ( test = = " filename_ " ) ;
// truncated 3-byte sequence
test = " filename \xe2 " ;
TEST_CHECK ( ! verify_encoding ( test ) ) ;
fprintf ( stderr , " %s \n " , test . c_str ( ) ) ;
TEST_CHECK ( test = = " filename_ " ) ;
// valid 4-byte sequence
test = " filename \xf0 \x9f \x92 \x88 " ;
TEST_CHECK ( verify_encoding ( test ) ) ;
fprintf ( stderr , " %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 ) ) ;
fprintf ( stderr , " %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 ) ) ;
fprintf ( stderr , " %s \n " , test . c_str ( ) ) ;
TEST_CHECK ( test = = " filename_____foobar " ) ;
// trim_path_element
fprintf ( stderr , " TORRENT_MAX_PATH: %d \n " , TORRENT_MAX_PATH ) ;
// 1100 characters
test = " abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij012345.txt " ;
std : : string comparison = test ;
trim_path_element ( test ) ;
if ( comparison . size ( ) > TORRENT_MAX_PATH )
{
comparison . resize ( TORRENT_MAX_PATH - 4 ) ;
comparison + = " .txt " ; // the extension is supposed to be preserved
}
TEST_EQUAL ( test , comparison ) ;
// extensions > 15 characters are ignored
test = " abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789 "
" abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij.123456789abcdefghij0123456789 " ;
comparison = test ;
trim_path_element ( test ) ;
if ( comparison . size ( ) > TORRENT_MAX_PATH )
comparison . resize ( TORRENT_MAX_PATH ) ;
TEST_EQUAL ( test , comparison ) ;
2013-06-17 17:56:58 +02:00
std : : string root_dir = parent_path ( current_working_directory ( ) ) ;
2013-01-31 04:39:14 +01:00
for ( int i = 0 ; i < sizeof ( test_torrents ) / sizeof ( test_torrents [ 0 ] ) ; + + i )
{
fprintf ( stderr , " loading %s \n " , test_torrents [ i ] . file ) ;
2013-06-17 17:56:58 +02:00
boost : : intrusive_ptr < torrent_info > ti ( new torrent_info ( combine_path ( combine_path ( root_dir , " test_torrents " ) , test_torrents [ i ] . file ) , ec ) ) ;
2013-01-31 04:39:14 +01:00
TEST_CHECK ( ! ec ) ;
if ( ec ) fprintf ( stderr , " -> failed %s \n " , ec . message ( ) . c_str ( ) ) ;
2013-02-24 11:02:26 +01:00
if ( std : : string ( test_torrents [ i ] . file ) = = " whitespace_url.torrent " )
{
// make sure we trimmed the url
2013-06-17 09:47:47 +02:00
TEST_CHECK ( ti - > trackers ( ) . size ( ) > 0 ) ;
if ( ti - > trackers ( ) . size ( ) > 0 )
TEST_CHECK ( ti - > trackers ( ) [ 0 ] . url = = " udp://test.com/announce " ) ;
2013-02-24 11:02:26 +01:00
}
else if ( std : : string ( test_torrents [ i ] . file ) = = " duplicate_files.torrent " )
{
// make sure we disambiguated the files
TEST_EQUAL ( ti - > num_files ( ) , 2 ) ;
2013-05-12 00:00:54 +02:00
TEST_CHECK ( ti - > file_at ( 0 ) . path = = combine_path ( combine_path ( " temp " , " foo " ) , " bar.txt " ) ) ;
TEST_CHECK ( ti - > file_at ( 1 ) . path = = combine_path ( combine_path ( " temp " , " foo " ) , " bar.1.txt " ) ) ;
2013-02-24 11:02:26 +01:00
}
2013-02-25 02:54:38 +01:00
else if ( std : : string ( test_torrents [ i ] . file ) = = " pad_file.torrent " )
{
TEST_EQUAL ( ti - > num_files ( ) , 2 ) ;
TEST_CHECK ( ti - > file_at ( 0 ) . pad_file = = false ) ;
TEST_CHECK ( ti - > file_at ( 1 ) . pad_file = = true ) ;
}
else if ( std : : string ( test_torrents [ i ] . file ) = = " creation_date.torrent " )
{
TEST_CHECK ( * ti - > creation_date ( ) = = 1234567 ) ;
}
2013-02-26 06:57:29 +01:00
else if ( std : : string ( test_torrents [ i ] . file ) = = " no_creation_date.torrent " )
{
TEST_CHECK ( ! ti - > creation_date ( ) ) ;
}
else if ( std : : string ( test_torrents [ i ] . file ) = = " url_seed.torrent " )
{
TEST_EQUAL ( ti - > web_seeds ( ) . size ( ) , 1 ) ;
TEST_EQUAL ( ti - > web_seeds ( ) [ 0 ] . url , " http://test.com/file " ) ;
# ifndef TORRENT_NO_DEPRECATE
TEST_EQUAL ( ti - > http_seeds ( ) . size ( ) , 0 ) ;
TEST_EQUAL ( ti - > url_seeds ( ) . size ( ) , 1 ) ;
TEST_EQUAL ( ti - > url_seeds ( ) [ 0 ] , " http://test.com/file " ) ;
# endif
}
else if ( std : : string ( test_torrents [ i ] . file ) = = " url_seed_multi.torrent " )
{
TEST_EQUAL ( ti - > web_seeds ( ) . size ( ) , 1 ) ;
TEST_EQUAL ( ti - > web_seeds ( ) [ 0 ] . url , " http://test.com/file/ " ) ;
# ifndef TORRENT_NO_DEPRECATE
TEST_EQUAL ( ti - > http_seeds ( ) . size ( ) , 0 ) ;
TEST_EQUAL ( ti - > url_seeds ( ) . size ( ) , 1 ) ;
TEST_EQUAL ( ti - > url_seeds ( ) [ 0 ] , " http://test.com/file/ " ) ;
# endif
}
else if ( std : : string ( test_torrents [ i ] . file ) = = " url_seed_multi_space.torrent "
| | std : : string ( test_torrents [ i ] . file ) = = " url_seed_multi_space_nolist.torrent " )
{
TEST_EQUAL ( ti - > web_seeds ( ) . size ( ) , 1 ) ;
TEST_EQUAL ( ti - > web_seeds ( ) [ 0 ] . url , " http://test.com/test%20file/foo%20bar/ " ) ;
# ifndef TORRENT_NO_DEPRECATE
TEST_EQUAL ( ti - > http_seeds ( ) . size ( ) , 0 ) ;
TEST_EQUAL ( ti - > url_seeds ( ) . size ( ) , 1 ) ;
TEST_EQUAL ( ti - > url_seeds ( ) [ 0 ] , " http://test.com/test%20file/foo%20bar/ " ) ;
# endif
}
2013-12-05 08:40:57 +01:00
else if ( std : : string ( test_torrents [ i ] . file ) = = " invalid_name3.torrent " )
{
TEST_EQUAL ( ti - > name ( ) , " foobar " ) ;
}
2013-02-24 11:02:26 +01:00
2013-08-12 09:30:57 +02:00
file_storage const & fs = ti - > files ( ) ;
for ( int i = 0 ; i < fs . num_files ( ) ; + + i )
2013-01-31 04:39:14 +01:00
{
2013-08-12 09:30:57 +02:00
int first = ti - > map_file ( i , 0 , 0 ) . piece ;
int last = ti - > map_file ( i , ( std : : max ) ( fs . file_size ( i ) - 1 , size_type ( 0 ) ) , 0 ) . piece ;
int flags = fs . file_flags ( i ) ;
2013-09-25 21:44:29 +02:00
fprintf ( stderr , " %11 " PRId64 " %c%c%c%c [ %4d, %4d ] %7u %s %s %s%s \n "
2013-08-12 09:30:57 +02:00
, fs . file_size ( i )
, ( flags & file_storage : : flag_pad_file ) ? ' p ' : ' - '
, ( flags & file_storage : : flag_executable ) ? ' x ' : ' - '
, ( flags & file_storage : : flag_hidden ) ? ' h ' : ' - '
, ( flags & file_storage : : flag_symlink ) ? ' l ' : ' - '
2013-01-31 04:39:14 +01:00
, first , last
2013-08-12 09:30:57 +02:00
, boost : : uint32_t ( fs . mtime ( i ) )
, fs . hash ( i ) ! = sha1_hash ( 0 ) ? to_hex ( fs . hash ( i ) . to_string ( ) ) . c_str ( ) : " "
, fs . file_path ( i ) . c_str ( )
, flags & file_storage : : flag_symlink ? " -> " : " "
, flags & file_storage : : flag_symlink ? fs . symlink ( i ) . c_str ( ) : " " ) ;
2013-01-31 04:39:14 +01:00
}
2013-02-24 11:02:26 +01:00
2013-02-26 06:57:29 +01:00
// test swap
# if !defined TORRENT_NO_DEPRECATE && TORRENT_USE_IOSTREAM
std : : stringstream str1 ;
ti - > print ( str1 ) ;
torrent_info temp ( " temp " , ec ) ;
temp . swap ( * ti ) ;
std : : stringstream str2 ;
temp . print ( str2 ) ;
TEST_EQUAL ( str1 . str ( ) , str2 . str ( ) ) ;
# endif
2013-01-31 04:39:14 +01:00
}
2013-02-25 02:54:38 +01:00
for ( int i = 0 ; i < sizeof ( test_error_torrents ) / sizeof ( test_error_torrents [ 0 ] ) ; + + i )
{
error_code ec ;
fprintf ( stderr , " loading %s \n " , test_error_torrents [ i ] . file ) ;
2013-06-17 17:56:58 +02:00
boost : : intrusive_ptr < torrent_info > ti ( new torrent_info ( combine_path ( combine_path ( root_dir , " test_torrents " ) , test_error_torrents [ i ] . file ) , ec ) ) ;
2013-02-25 02:54:38 +01:00
fprintf ( stderr , " E: %s \n expected: %s \n " , ec . message ( ) . c_str ( ) , test_error_torrents [ i ] . error . message ( ) . c_str ( ) ) ;
TEST_EQUAL ( ec , test_error_torrents [ i ] . error ) ;
}
2013-02-09 23:02:05 +01:00
return 0 ;
2013-01-31 04:39:14 +01:00
}