2008-06-04 17:14:58 +00:00
|
|
|
#include "transmission.h"
|
2008-07-21 16:11:47 +00:00
|
|
|
#include "bencode.h"
|
2008-09-05 14:31:58 +00:00
|
|
|
#include "rpcimpl.h"
|
2008-06-04 17:14:58 +00:00
|
|
|
#include "utils.h"
|
|
|
|
|
2009-01-23 18:44:15 +00:00
|
|
|
#undef VERBOSE
|
2012-08-18 16:07:05 +00:00
|
|
|
#include "libtransmission-test.h"
|
2008-06-04 17:14:58 +00:00
|
|
|
|
2008-07-21 16:11:47 +00:00
|
|
|
static int
|
|
|
|
test_list( void )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
int64_t i;
|
2008-07-21 16:11:47 +00:00
|
|
|
const char * str;
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_benc top;
|
2008-07-21 16:11:47 +00:00
|
|
|
|
|
|
|
tr_rpc_parse_list_str( &top, "12", -1 );
|
|
|
|
check( tr_bencIsInt( &top ) );
|
|
|
|
check( tr_bencGetInt( &top, &i ) );
|
2012-10-14 18:56:37 +00:00
|
|
|
check_int_eq ( 12, i );
|
2008-07-21 16:11:47 +00:00
|
|
|
tr_bencFree( &top );
|
|
|
|
|
|
|
|
tr_rpc_parse_list_str( &top, "12", 1 );
|
|
|
|
check( tr_bencIsInt( &top ) );
|
|
|
|
check( tr_bencGetInt( &top, &i ) );
|
2012-10-14 18:56:37 +00:00
|
|
|
check_int_eq ( 1, i );
|
2008-07-21 16:11:47 +00:00
|
|
|
tr_bencFree( &top );
|
|
|
|
|
|
|
|
tr_rpc_parse_list_str( &top, "6,7", -1 );
|
|
|
|
check( tr_bencIsList( &top ) );
|
|
|
|
check( tr_bencListSize( &top ) == 2 );
|
|
|
|
check( tr_bencGetInt( tr_bencListChild( &top, 0 ), &i ) );
|
2012-10-14 18:56:37 +00:00
|
|
|
check_int_eq ( 6, i );
|
2008-07-21 16:11:47 +00:00
|
|
|
check( tr_bencGetInt( tr_bencListChild( &top, 1 ), &i ) );
|
2012-10-14 18:56:37 +00:00
|
|
|
check_int_eq ( 7, i );
|
2008-07-21 16:11:47 +00:00
|
|
|
tr_bencFree( &top );
|
|
|
|
|
|
|
|
tr_rpc_parse_list_str( &top, "asdf", -1 );
|
|
|
|
check( tr_bencIsString( &top ) );
|
|
|
|
check( tr_bencGetStr( &top, &str ) );
|
2012-10-14 18:56:37 +00:00
|
|
|
check_streq( "asdf", str );
|
2008-07-21 16:11:47 +00:00
|
|
|
tr_bencFree( &top );
|
|
|
|
|
|
|
|
tr_rpc_parse_list_str( &top, "1,3-5", -1 );
|
|
|
|
check( tr_bencIsList( &top ) );
|
|
|
|
check( tr_bencListSize( &top ) == 4 );
|
|
|
|
check( tr_bencGetInt( tr_bencListChild( &top, 0 ), &i ) );
|
2012-10-14 18:56:37 +00:00
|
|
|
check_int_eq( 1, i );
|
2008-07-21 16:11:47 +00:00
|
|
|
check( tr_bencGetInt( tr_bencListChild( &top, 1 ), &i ) );
|
2012-10-14 18:56:37 +00:00
|
|
|
check_int_eq( 3, i );
|
2008-07-21 16:11:47 +00:00
|
|
|
check( tr_bencGetInt( tr_bencListChild( &top, 2 ), &i ) );
|
2012-10-14 18:56:37 +00:00
|
|
|
check_int_eq( 4, i );
|
2008-07-21 16:11:47 +00:00
|
|
|
check( tr_bencGetInt( tr_bencListChild( &top, 3 ), &i ) );
|
2012-10-14 18:56:37 +00:00
|
|
|
check_int_eq( 5, i );
|
2008-07-21 16:11:47 +00:00
|
|
|
tr_bencFree( &top );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-18 16:07:05 +00:00
|
|
|
MAIN_SINGLE_TEST(test_list)
|