Ignore:
Timestamp:
May 12, 2008, 5:54:57 PM (14 years ago)
Author:
charles
Message:

add benc-to-json conversion + unit tests.

File:
1 edited

Legend:

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

    r5772 r5821  
    272272
    273273static int
    274 testPHPSnippet( const char * benc_str, const char * expected )
     274testJSONSnippet( const char * benc_str, const char * expected )
    275275{
    276276    tr_benc top;
    277277    char * serialized;
    278278    tr_bencLoad( benc_str, strlen( benc_str ), &top, NULL );
    279     serialized = tr_bencSaveAsSerializedPHP( &top, NULL );
     279    serialized = tr_bencSaveAsJSON( &top, NULL );
    280280    check( !strcmp( serialized, expected ) );
    281281    tr_free( serialized );
     
    285285
    286286static int
    287 testPHP( void )
     287testJSON( void )
    288288{
    289289    int val;
     
    292292
    293293    benc_str = "i6e";
    294     expected = "i:6;";
    295     if(( val = testPHPSnippet( benc_str, expected )))
     294    expected = "6";
     295    if(( val = testJSONSnippet( benc_str, expected )))
    296296        return val;
    297297
    298     benc_str = "d3:cow3:moo4:spam4:eggse";
    299     expected = "a:2:{s:3:\"cow\";s:3:\"moo\";s:4:\"spam\";s:4:\"eggs\";}";
    300     if(( val = testPHPSnippet( benc_str, expected )))
     298    benc_str = "d5:helloi1e5:worldi2ee";
     299    expected = "{ \"hello\": 1, \"world\": 2 }";
     300    if(( val = testJSONSnippet( benc_str, expected )))
    301301        return val;
    302302
    303     benc_str = "l3:cow3:moo4:spam4:eggse";
    304     expected = "a:4:{i:0;s:3:\"cow\";i:1;s:3:\"moo\";i:2;s:4:\"spam\";i:3;s:4:\"eggs\";}";
    305     if(( val = testPHPSnippet( benc_str, expected )))
     303    benc_str = "d5:helloi1e5:worldi2e3:fooli1ei2ei3ee";
     304    expected = "{ \"foo\": [ 1, 2, 3 ], \"hello\": 1, \"world\": 2 }";
     305    if(( val = testJSONSnippet( benc_str, expected )))
     306        return val;
     307
     308    benc_str = "d5:helloi1e5:worldi2e3:fooli1ei2ei3ed1:ai0eee";
     309    expected = "{ \"foo\": [ 1, 2, 3, { \"a\": 0 } ], \"hello\": 1, \"world\": 2 }";
     310    if(( val = testJSONSnippet( benc_str, expected )))
    306311        return val;
    307312
     
    355360        return i;
    356361
    357     if(( i = testPHP( )))
     362    if(( i = testJSON( )))
    358363        return i;
    359364
Note: See TracChangeset for help on using the changeset viewer.