~ubuntu-branches/ubuntu/precise/transmission/precise

« back to all changes in this revision

Viewing changes to libtransmission/peer-msgs-test.c

  • Committer: Bazaar Package Importer
  • Author(s): Leo Costela
  • Date: 2009-05-17 19:39:51 UTC
  • mto: (1.3.4 upstream) (2.2.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: james.westby@ubuntu.com-20090517193951-k8x15sqoxzf7cuyx
ImportĀ upstreamĀ versionĀ 1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include "transmission.h"
 
3
#include "net.h"
 
4
#include "peer-msgs.h"
 
5
#include "utils.h"
 
6
 
 
7
#undef VERBOSE
 
8
 
 
9
#ifdef VERBOSE
 
10
  #define check( A ) \
 
11
    { \
 
12
        ++test; \
 
13
        if( A ){ \
 
14
            fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
 
15
        } else { \
 
16
            fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
 
17
            return test; \
 
18
        } \
 
19
    }
 
20
#else
 
21
  #define check( A ) \
 
22
    { \
 
23
        ++test; \
 
24
        if( !( A ) ){ \
 
25
            fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
 
26
            return test; \
 
27
        } \
 
28
    }
 
29
#endif
 
30
 
 
31
int
 
32
main( void )
 
33
{
 
34
    uint32_t           i;
 
35
    int                test = 0;
 
36
    uint8_t            infohash[SHA_DIGEST_LENGTH];
 
37
    struct tr_address  addr;
 
38
    tr_piece_index_t   pieceCount = 1313;
 
39
    size_t             numwant;
 
40
    size_t             numgot;
 
41
    tr_piece_index_t pieces[] = { 1059, 431, 808, 1217, 287, 376, 1188, 353, 508 };
 
42
    tr_piece_index_t buf[16];
 
43
 
 
44
    for( i = 0; i < SHA_DIGEST_LENGTH; ++i )
 
45
        infohash[i] = 0xaa;
 
46
    tr_pton( "80.4.4.200", &addr );
 
47
 
 
48
    numwant = 7;
 
49
    numgot = tr_generateAllowedSet( buf, numwant, pieceCount, infohash, &addr );
 
50
    check( numgot == numwant );
 
51
    for( i=0; i<numgot; ++i )
 
52
        check( buf[i] == pieces[i] );
 
53
 
 
54
    numwant = 9;
 
55
    numgot = tr_generateAllowedSet( buf, numwant, pieceCount, infohash, &addr );
 
56
    check( numgot == numwant );
 
57
    for( i=0; i<numgot; ++i )
 
58
        check( buf[i] == pieces[i] );
 
59
 
 
60
    return 0;
 
61
}
 
62