source: trunk/libtransmission/blocklist-test.c @ 6729

Last change on this file since 6729 was 6729, checked in by muks, 14 years ago

(win32) Don't use files in /tmp/ for test on win32

File size: 3.1 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include "transmission.h"
5#include "blocklist.h"
6#include "net.h"
7#include "utils.h"
8
9#define VERBOSE 0
10
11#define check(A) { \
12    ++test; \
13    if (A) { \
14        if( VERBOSE ) \
15            fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
16    } else { \
17        if( VERBOSE ) \
18            fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
19        return test; \
20    } \
21}
22
23static void
24createTestBlocklist( const char * tmpfile )
25{
26    const char * lines[] = { "Austin Law Firm:216.16.1.144-216.16.1.151",
27                             "Sargent Controls and Aerospace:216.19.18.0-216.19.18.255",
28                             "Corel Corporation:216.21.157.192-216.21.157.223",
29                             "Fox Speed Channel:216.79.131.192-216.79.131.223" };
30    FILE * out;
31    int i;
32    const int lineCount = sizeof(lines) / sizeof(lines[0]);
33
34    /* create the ascii file to feed to libtransmission */
35    out = fopen( tmpfile, "w+" );
36    for( i=0; i<lineCount; ++i )
37        fprintf( out, "%s\n", lines[i] );
38    fclose( out );
39}
40
41int
42main( void )
43{
44#ifndef WIN32
45    char * tmpfile_txt = "/tmp/transmission-blocklist-test.txt";
46    char * tmpfile_bin = "/tmp/transmission-blocklist-test.bin";
47#else
48    char * tmpfile_txt = "transmission-blocklist-test.txt";
49    char * tmpfile_bin = "transmission-blocklist-test.bin";
50#endif
51    struct in_addr addr;
52    int test = 0;
53    tr_blocklist * b;
54
55    remove( tmpfile_txt );
56    remove( tmpfile_bin );
57
58    b = _tr_blocklistNew( tmpfile_bin, TRUE );
59    createTestBlocklist( tmpfile_txt );
60    _tr_blocklistSetContent( b, tmpfile_txt );
61
62    /* now run some tests */
63    check( !tr_netResolve( "216.16.1.143", &addr ) );
64    check( !_tr_blocklistHasAddress( b, &addr ) );
65    check( !tr_netResolve( "216.16.1.144", &addr ) );
66    check(  _tr_blocklistHasAddress( b, &addr ) );
67    check( !tr_netResolve( "216.16.1.145", &addr ) );
68    check(  _tr_blocklistHasAddress( b, &addr ) );
69    check( !tr_netResolve( "216.16.1.146", &addr ) );
70    check(  _tr_blocklistHasAddress( b, &addr ) );
71    check( !tr_netResolve( "216.16.1.147", &addr ) );
72    check(  _tr_blocklistHasAddress( b, &addr ) );
73    check( !tr_netResolve( "216.16.1.148", &addr ) );
74    check(  _tr_blocklistHasAddress( b, &addr ) );
75    check( !tr_netResolve( "216.16.1.149", &addr ) );
76    check(  _tr_blocklistHasAddress( b, &addr ) );
77    check( !tr_netResolve( "216.16.1.150", &addr ) );
78    check(  _tr_blocklistHasAddress( b, &addr ) );
79    check( !tr_netResolve( "216.16.1.151", &addr ) );
80    check(  _tr_blocklistHasAddress( b, &addr ) );
81    check( !tr_netResolve( "216.16.1.152", &addr ) );
82    check( !_tr_blocklistHasAddress( b, &addr ) );
83    check( !tr_netResolve( "216.16.1.153", &addr ) );
84    check( !_tr_blocklistHasAddress( b, &addr ) );
85    check( !tr_netResolve( "217.0.0.1", &addr ) );
86    check( !_tr_blocklistHasAddress( b, &addr ) );
87    check( !tr_netResolve( "255.0.0.1", &addr ) );
88
89    /* cleanup */
90    _tr_blocklistFree( b );
91    remove( tmpfile_txt );
92    remove( tmpfile_bin );
93    return 0;
94}
Note: See TracBrowser for help on using the repository browser.