transmision: upgrade 2.22 -> 2.31
[tomato.git] / release / src / router / transmission / libtransmission / test-peer-id.c
blobb0f46bc5acecb9832359547a2d4a823130918213
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "transmission.h"
5 #include "session.h"
6 #include "utils.h"
7 #include "version.h"
9 #undef VERBOSE
11 #ifdef VERBOSE
12 #define check( A ) \
13 { \
14 ++test; \
15 if( A ){ \
16 fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
17 } else { \
18 fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
19 return test; \
20 } \
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 } \
31 #endif
33 int
34 main( void )
36 int i;
37 int test = 0;
38 uint8_t peer_id[PEER_ID_LEN+1];
40 for( i = 0; i < 100000; ++i )
42 int j;
43 int val = 0;
45 tr_peerIdInit( peer_id );
47 check( strlen( (char*)peer_id ) == PEER_ID_LEN );
48 check( !memcmp( peer_id, PEERID_PREFIX, 8 ) );
50 for( j = 8; j < PEER_ID_LEN; ++j )
52 char tmp[2] = { peer_id[j], '\0' };
53 val += strtoul( tmp, NULL, 36 );
56 check( ( val % 36 ) == 0 );
59 return 0;