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

« back to all changes in this revision

Viewing changes to libtransmission/test-peer-id.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:
2
2
#include <stdlib.h>
3
3
#include <string.h>
4
4
#include "transmission.h"
 
5
#include "session.h"
5
6
#include "utils.h"
6
 
 
7
 
#define VERBOSE 0
8
 
 
9
 
#define check(A) { \
10
 
    ++test; \
11
 
    if (A) { \
12
 
        if( VERBOSE ) \
 
7
#include "version.h"
 
8
 
 
9
#undef VERBOSE
 
10
 
 
11
#ifdef VERBOSE
 
12
  #define check( A ) \
 
13
    { \
 
14
        ++test; \
 
15
        if( A ){ \
13
16
            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
 
}
 
17
        } else { \
 
18
            fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
 
19
            return test; \
 
20
        } \
 
21
    }
 
22
#else
 
23
  #define check( A ) \
 
24
    { \
 
25
        ++test; \
 
26
        if( !( A ) ){ \
 
27
            fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
 
28
            return test; \
 
29
        } \
 
30
    }
 
31
#endif
20
32
 
21
33
int
22
34
main( void )
24
36
    int i;
25
37
    int test = 0;
26
38
 
27
 
    for( i=0; i<100000; ++i )
 
39
    for( i = 0; i < 100000; ++i )
28
40
    {
29
 
        int j;
30
 
        int val = 0;
 
41
        int       j;
 
42
        int       val = 0;
31
43
        uint8_t * pch = tr_peerIdNew( );
32
44
 
33
45
        check( strlen( (char*)pch ) == 20 );
34
46
        check( !memcmp( pch, PEERID_PREFIX, 8 ) );
35
47
 
36
 
        for( j=8; j<20; ++j ) {
 
48
        for( j = 8; j < 20; ++j )
 
49
        {
37
50
            char tmp[2] = { pch[j], '\0' };
38
51
            val += strtoul( tmp, NULL, 36 );
39
52
        }
45
58
 
46
59
    return 0;
47
60
}
 
61