source: trunk/libtransmission/rpc-test.c @ 6140

Last change on this file since 6140 was 6140, checked in by charles, 14 years ago

(libT) allow custom blocklists... now all you need to do is place a file in the blocklists/ folder and Transmission will automatically use it the next time it starts.

File size: 1.8 KB
Line 
1#include <stdio.h> /* fprintf */
2#include <string.h> /* strcmp */
3#include "transmission.h"
4#include "utils.h"
5
6#define VERBOSE 0
7
8int test = 0;
9
10#define check(A) { \
11    ++test; \
12    if (A) { \
13        if( VERBOSE ) \
14            fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
15    } else { \
16        if( VERBOSE ) \
17            fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
18        return test; \
19    } \
20}
21
22extern char* cidrize( const char * in );
23
24extern int tr_rpcTestACL( const void           * unused,
25                          const char           * acl,
26                          char                ** setme_errmsg );
27
28static int
29testWildcard( const char * in, const char * expected )
30{
31    int ok;
32    char * str = cidrize( in );
33/* fprintf( stderr, "in [%s] out [%s] should be [%s]\n", in, str, expected ); */
34    ok = expected ? !strcmp( expected, str ) : !str;
35    tr_free( str );
36    return ok;
37}
38
39static int
40test_acl( void )
41{
42    int err;
43    char * errmsg = NULL;
44
45    check( testWildcard( "192.*.*.*", "192.0.0.0/8" ) );
46    check( testWildcard( "192.64.*.*", "192.64.0.0/16" ) );
47    check( testWildcard( "192.64.0.*", "192.64.0.0/24" ) );
48    check( testWildcard( "192.64.0.1", "192.64.0.1/32" ) );
49    check( testWildcard( "+192.*.*.*,-192.64.*.*", "+192.0.0.0/8,-192.64.0.0/16" ) );
50
51    err = tr_rpcTestACL( NULL, "+192.*.*.*", &errmsg );
52    check( !err );
53    check( !errmsg );
54    err = tr_rpcTestACL( NULL, "+192.*.8.*", &errmsg );
55    check( err );
56    check( errmsg );
57    tr_free( errmsg );
58    errmsg = NULL;
59    err = tr_rpcTestACL( NULL, "+192.*.*.*,-192.168.*.*", &errmsg );
60    check( !err );
61    check( !errmsg );
62
63    return 0;
64}
65
66int
67main( void )
68{
69    int i;
70
71    if(( i = test_acl( )))
72        return i;
73
74    return 0;
75}
Note: See TracBrowser for help on using the repository browser.