source: trunk/libtransmission/test-fastset.c @ 5126

Last change on this file since 5126 was 5126, checked in by charles, 14 years ago

svn propset svn:keywords 'Date Rev Author Id' filename

  • Property svn:keywords set to Date Rev Author Id
File size: 1.3 KB
Line 
1#include <stdio.h>
2#include "transmission.h"
3#include "net.h"
4#include "peer-mgr.h"
5#include "utils.h"
6
7#define VERBOSE 0
8
9#define check(A) { \
10    ++test; \
11    if (A) { \
12        if( VERBOSE ) \
13            fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
14    } else { \
15        if( VERBOSE ) \
16            fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
17        return test; \
18    } \
19}
20
21int
22main( void )
23{
24    uint32_t i;
25    int test = 0;
26    tr_bitfield * bitfield;
27    uint8_t infohash[SHA_DIGEST_LENGTH];
28    struct in_addr addr;
29    uint32_t sz;
30    uint32_t k;
31    int pieces[] = { 1059,431,808,1217,287,376,1188,353,508 };
32
33    for( i=0; i<SHA_DIGEST_LENGTH; ++i )
34        infohash[i] = 0xaa;
35    tr_netResolve( "80.4.4.200", &addr );
36    sz = 1313;
37
38    k = 7;
39    bitfield = tr_peerMgrGenerateAllowedSet( k, sz, infohash, &addr );
40    check( tr_bitfieldCountTrueBits( bitfield ) == k );
41    for( i=0; i<k; ++i )
42        check( tr_bitfieldHas( bitfield, pieces[i] ) );
43    tr_bitfieldFree( bitfield );
44
45    k = 9;
46    bitfield = tr_peerMgrGenerateAllowedSet( k, sz, infohash, &addr );
47    check( tr_bitfieldCountTrueBits( bitfield ) == k );
48    for( i=0; i<k; ++i )
49        check( tr_bitfieldHas( bitfield, pieces[i] ) );
50    tr_bitfieldFree( bitfield );
51
52
53    return 0;
54}
Note: See TracBrowser for help on using the repository browser.