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 | { \ |
---|
11 | ++test; \ |
---|
12 | if( A ){ \ |
---|
13 | if( VERBOSE ) \ |
---|
14 | fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ |
---|
15 | __LINE__ );\ |
---|
16 | } else { \ |
---|
17 | if( VERBOSE ) \ |
---|
18 | fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ |
---|
19 | __LINE__ );\ |
---|
20 | return test; \ |
---|
21 | } \ |
---|
22 | } |
---|
23 | |
---|
24 | int |
---|
25 | main( void ) |
---|
26 | { |
---|
27 | uint32_t i; |
---|
28 | int test = 0; |
---|
29 | tr_bitfield * bitfield; |
---|
30 | uint8_t infohash[SHA_DIGEST_LENGTH]; |
---|
31 | struct in_addr addr; |
---|
32 | uint32_t sz; |
---|
33 | uint32_t k; |
---|
34 | tr_piece_index_t pieces[] = |
---|
35 | { 1059, 431, 808, 1217, 287, 376, 1188, 353, 508 }; |
---|
36 | |
---|
37 | for( i = 0; i < SHA_DIGEST_LENGTH; ++i ) |
---|
38 | infohash[i] = 0xaa; |
---|
39 | tr_netResolve( "80.4.4.200", &addr ); |
---|
40 | sz = 1313; |
---|
41 | |
---|
42 | k = 7; |
---|
43 | bitfield = tr_peerMgrGenerateAllowedSet( k, sz, infohash, &addr ); |
---|
44 | check( tr_bitfieldCountTrueBits( bitfield ) == k ); |
---|
45 | for( i = 0; i < k; ++i ) |
---|
46 | check( tr_bitfieldHas( bitfield, pieces[i] ) ); |
---|
47 | tr_bitfieldFree( bitfield ); |
---|
48 | |
---|
49 | k = 9; |
---|
50 | bitfield = tr_peerMgrGenerateAllowedSet( k, sz, infohash, &addr ); |
---|
51 | check( tr_bitfieldCountTrueBits( bitfield ) == k ); |
---|
52 | for( i = 0; i < k; ++i ) |
---|
53 | check( tr_bitfieldHas( bitfield, pieces[i] ) ); |
---|
54 | tr_bitfieldFree( bitfield ); |
---|
55 | |
---|
56 | |
---|
57 | return 0; |
---|
58 | } |
---|
59 | |
---|