Ignore:
Timestamp:
May 13, 2008, 12:52:58 PM (14 years ago)
Author:
charles
Message:

fix bug in the benc-to-json converter.
add rison-to-json converter so we can pass commands to transmission in a uri.
add unit tests for the new code.

File:
1 edited

Legend:

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

    r5821 r5828  
    22#include "transmission.h"
    33#include "bencode.h"
     4#include "json.h"
    45#include "utils.h" /* tr_free */
    56
     
    272273
    273274static int
     275testRISONSnippet( const char * rison_str, const char * expected )
     276{
     277    char * serialized = tr_rison2json( rison_str, -1 );
     278#if 0
     279fprintf( stderr, " expected: [%s]\n", expected );
     280fprintf( stderr, "      got: [%s]\n", serialized );
     281#endif
     282    check( !strcmp( serialized, expected ) );
     283    tr_free( serialized );
     284    return 0;
     285}
     286
     287static int
     288testRISON( void )
     289{
     290    int val;
     291    const char * rison;
     292    const char * expected;
     293
     294    rison = "(a:0,b:foo,c:'23skidoo')";
     295    expected = "{ \"a\": 0, \"b\": \"foo\", \"c\": \"23skidoo\" }";
     296    if(( val = testRISONSnippet( rison, expected )))
     297        return val;
     298
     299    return 0;
     300}
     301
     302static int
    274303testJSONSnippet( const char * benc_str, const char * expected )
    275304{
     
    278307    tr_bencLoad( benc_str, strlen( benc_str ), &top, NULL );
    279308    serialized = tr_bencSaveAsJSON( &top, NULL );
     309#if 0
     310fprintf( stderr, " expected: [%s]\n", expected );
     311fprintf( stderr, "      got: [%s]\n", serialized );
     312#endif
    280313    check( !strcmp( serialized, expected ) );
    281314    tr_free( serialized );
     
    308341    benc_str = "d5:helloi1e5:worldi2e3:fooli1ei2ei3ed1:ai0eee";
    309342    expected = "{ \"foo\": [ 1, 2, 3, { \"a\": 0 } ], \"hello\": 1, \"world\": 2 }";
     343    if(( val = testJSONSnippet( benc_str, expected )))
     344        return val;
     345
     346    benc_str = "d4:argsd6:statuslee6:result7:successe";
     347    expected = "{ \"args\": { \"status\": [  ] }, \"result\": \"success\" }";
    310348    if(( val = testJSONSnippet( benc_str, expected )))
    311349        return val;
     
    363401        return i;
    364402
     403    if(( i = testRISON( )))
     404        return i;
     405
    365406    if(( i = testStackSmash( )))
    366407        return i;
Note: See TracChangeset for help on using the changeset viewer.