Ignore:
Timestamp:
Dec 12, 2008, 2:12:17 AM (13 years ago)
Author:
charles
Message:

(trunk libT) #1559 (partial): add tr_bencDictMerge() + unit tests. patch by KyleK and charles_

File:
1 edited

Legend:

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

    r6842 r7359  
    362362}
    363363
     364static int
     365testMerge( void )
     366{
     367    tr_benc dest, src;
     368    int64_t i;
     369    const char * s;
     370
     371    /* initial dictionary (default values)  */
     372    tr_bencInitDict( &dest, 10 );
     373    tr_bencDictAddInt( &dest, "i1", 1 );
     374    tr_bencDictAddInt( &dest, "i2", 2 );
     375    tr_bencDictAddInt( &dest, "i4", -35 ); /* remains untouched */
     376    tr_bencDictAddStr( &dest, "s5", "abc" );
     377    tr_bencDictAddStr( &dest, "s6", "def" );
     378    tr_bencDictAddStr( &dest, "s7", "127.0.0.1" ); /* remains untouched */
     379
     380    /* new dictionary, will overwrite items in dest  */
     381    tr_bencInitDict( &src, 10 );
     382    tr_bencDictAddInt( &src, "i1", 1 );     /* same value */
     383    tr_bencDictAddInt( &src, "i2", 4 );     /* new value */
     384    tr_bencDictAddInt( &src, "i3", 3 );     /* new key:value */
     385    tr_bencDictAddStr( &src, "s5", "abc" ); /* same value */
     386    tr_bencDictAddStr( &src, "s6", "xyz" ); /* new value */
     387    tr_bencDictAddStr( &src, "s8", "ghi" ); /* new key:value */
     388
     389    tr_bencMergeDicts( &dest, /*const*/ &src );
     390
     391    check( tr_bencDictFindInt( &dest, "i1", &i ));
     392    check( i == 1);
     393    check( tr_bencDictFindInt( &dest, "i2", &i ));
     394    check( i == 4);
     395    check( tr_bencDictFindInt( &dest, "i3", &i ));
     396    check( i == 3);
     397    check( tr_bencDictFindInt( &dest, "i4", &i ));
     398    check( i == -35);
     399    check( tr_bencDictFindStr( &dest, "s5", &s ));
     400    check( strcmp( "abc", s ) == 0 );
     401    check( tr_bencDictFindStr( &dest, "s6", &s ));
     402    check( strcmp( "xyz", s ) == 0 );
     403    check( tr_bencDictFindStr( &dest, "s7", &s ));
     404    check( strcmp( "127.0.0.1", s ) == 0 );
     405    check( tr_bencDictFindStr( &dest, "s8", &s ));
     406    check( strcmp( "ghi", s ) == 0 );
     407
     408    tr_bencFree( &dest );
     409    tr_bencFree( &src );
     410    return 0;
     411}
     412
    364413static int
    365414testStackSmash( int depth )
     
    397446    int i;
    398447
    399     if( ( i = testInt( ) ) )
    400         return i;
    401 
    402     if( ( i = testStr( ) ) )
    403         return i;
    404 
    405     if( ( i = testParse( ) ) )
    406         return i;
    407 
    408     if( ( i = testJSON( ) ) )
     448    if(( i = testInt( )))
     449        return i;
     450
     451    if(( i = testStr( )))
     452        return i;
     453
     454    if(( i = testParse( )))
     455        return i;
     456
     457    if(( i = testJSON( )))
     458        return i;
     459
     460    if(( i = testMerge( )))
    409461        return i;
    410462
Note: See TracChangeset for help on using the changeset viewer.