source: trunk/libtransmission/test-peer-id.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: 921 bytes
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include "transmission.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    int i;
25    int test = 0;
26
27    for( i=0; i<100000; ++i )
28    {
29        int j;
30        int val = 0;
31        uint8_t * pch = tr_peerIdNew( );
32
33        check( strlen( (char*)pch ) == 20 );
34        check( !memcmp( pch, PEERID_PREFIX, 8 ) );
35
36        for( j=8; j<20; ++j ) {
37            char tmp[2] = { pch[j], '\0' };
38            val += strtoul( tmp, NULL, 36 );
39        }
40
41        check( ( val % 36 ) == 0 );
42
43        tr_free( pch );
44    }
45
46    return 0;
47}
Note: See TracBrowser for help on using the repository browser.