Ignore:
Timestamp:
Feb 1, 2008, 3:50:17 PM (14 years ago)
Author:
charles
Message:

fix the 1.04 bencode errors reported in the forums this morning. add regression tests.

File:
1 edited

Legend:

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

    r4882 r4893  
    138138
    139139static int
     140testString( const char * str, int isGood )
     141{
     142    benc_val_t val;
     143    const uint8_t * end = NULL;
     144    char * saved;
     145    const size_t len = strlen( str );
     146    int savedLen;
     147    int err = tr_bencParse( str, str+len, &val , &end );
     148    if( !isGood ) {
     149        check( err );
     150    } else {
     151        check( !err );
     152        check( end == (const uint8_t*)str + len );
     153        saved = tr_bencSave( &val, &savedLen );
     154        check( !strcmp( saved, str ) );
     155        check( len == (size_t)savedLen );
     156        tr_free( saved );
     157        tr_bencFree( &val );
     158    }
     159    return 0;
     160}
     161
     162static int
    140163testParse( void )
    141164{
     
    185208    tr_bencFree( &val );
    186209
    187     end = NULL;
    188     snprintf( (char*)buf, sizeof( buf ), "llleee" );
    189     err = tr_bencParse( buf, buf + sizeof( buf ), &val , &end );
    190     check( !err );
    191     check( end == buf + 6 );
    192     saved = tr_bencSave( &val, &len );
    193     check( !strcmp( saved, "llleee" ) );
    194     tr_free( saved );
    195     tr_bencFree( &val );
     210    if(( err = testString( "llleee", TRUE )))
     211        return err;
     212    if(( err = testString( "d3:cow3:moo4:spam4:eggse", TRUE )))
     213        return err;
     214    if(( err = testString( "d4:spaml1:a1:bee", TRUE )))
     215        return err;
     216#if 0
     217    if(( err = testString( "d9:publisher3:bob18:publisher.location4:home17:publisher-webpage15:www.example.come", TRUE )))
     218        return err;
     219#endif
     220    if(( err = testString( "d8:completei1e8:intervali1800e12:min intervali1800e5:peers0:e", TRUE )))
     221        return err;
     222    if(( err = testString( "d1:ai0e1:be", FALSE ))) /* odd number of children */
     223        return err;
     224    if(( err = testString( "", FALSE )))
     225        return err;
    196226
    197227    /* nested containers
     
    208238    check( !strcmp( saved, "lld1:ai64e1:bi32eeee" ) );
    209239    tr_free( saved );
    210     tr_bencFree( &val );
    211 
    212     end = NULL;
    213     snprintf( (char*)buf, sizeof( buf ), "d8:completei1e8:intervali1800e12:min intervali1800e5:peers0:e" );
    214     err = tr_bencParse( buf, buf+sizeof( buf ), &val, &end );
    215     check( !err );
    216     check( end == buf + strlen( (const char*)buf ) );
    217240    tr_bencFree( &val );
    218241
Note: See TracChangeset for help on using the changeset viewer.