Changeset 8158


Ignore:
Timestamp:
Apr 5, 2009, 11:16:45 PM (13 years ago)
Author:
charles
Message:

(trunk) fix another new bencode bug. add some more unit tests for benc.

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bencode-test.c

    r8108 r8158  
    486486}
    487487
     488static int
     489testParse2( void )
     490{
     491    tr_benc top;
     492    tr_benc top2;
     493    int64_t intVal;
     494    const char * strVal;
     495    double realVal;
     496    tr_bool boolVal;
     497    int len;
     498    char * benc;
     499    const uint8_t * end;
     500
     501    tr_bencInitDict( &top, 0 );
     502    tr_bencDictAddBool( &top, "this-is-a-bool", TRUE );
     503    tr_bencDictAddInt( &top, "this-is-an-int", 1234 );
     504    tr_bencDictAddReal( &top, "this-is-a-real", 0.5 );
     505    tr_bencDictAddStr( &top, "this-is-a-string", "this-is-a-string" );
     506
     507    benc = tr_bencSave( &top, &len );
     508    check( !strcmp( benc, "d14:this-is-a-booli1e14:this-is-a-real8:0.50000016:this-is-a-string16:this-is-a-string14:this-is-an-inti1234ee" ) )
     509    check( !tr_bencParse( benc, benc+len, &top2, &end ) )
     510    check( (char*)end == benc + len )
     511    check( tr_bencIsDict( &top2 ) )
     512    check( tr_bencDictFindInt( &top, "this-is-an-int", &intVal ) )
     513    check( intVal == 1234 )
     514    check( tr_bencDictFindBool( &top, "this-is-a-bool", &boolVal ) )
     515    check( boolVal == TRUE )
     516    check( tr_bencDictFindStr( &top, "this-is-a-string", &strVal ) )
     517    check( !strcmp( strVal, "this-is-a-string" ) )
     518    check( tr_bencDictFindReal( &top, "this-is-a-real", &realVal ) )
     519    check( (int)(realVal*100) == 50 )
     520
     521    tr_bencFree( &top2 );
     522    tr_free( benc );
     523    tr_bencFree( &top );
     524
     525    return 0;
     526}
     527
    488528int
    489529main( void )
     
    507547
    508548    if(( i = testBool( )))
     549        return i;
     550
     551    if(( i = testParse2( )))
    509552        return i;
    510553
  • trunk/libtransmission/bencode.c

    r8157 r8158  
    11211121
    11221122    len = strlen( buf );
    1123     evbuffer_add_printf( evbuf, "%lu:", (unsigned long)buf );
     1123    evbuffer_add_printf( evbuf, "%lu:", (unsigned long)len );
    11241124    evbuffer_add( evbuf, buf, len );
    11251125}
  • trunk/libtransmission/json-test.c

    r7907 r8158  
    145145    tr_benc top;
    146146    const char * in = " ";
    147     const int err = tr_jsonParse( in, strlen( in ), &top, NULL );
     147    int err;
     148
     149    top.type = 0;
     150    err = tr_jsonParse( in, strlen( in ), &top, NULL );
    148151
    149152    check( err );
Note: See TracChangeset for help on using the changeset viewer.