2008-03-29 21:05:51 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "transmission.h"
|
|
|
|
#include "blocklist.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
2009-01-23 18:44:15 +00:00
|
|
|
#undef VERBOSE
|
2008-03-29 21:05:51 +00:00
|
|
|
|
2009-01-23 18:44:15 +00:00
|
|
|
#ifdef VERBOSE
|
|
|
|
#define check( A ) \
|
2008-09-23 19:11:04 +00:00
|
|
|
{ \
|
|
|
|
++test; \
|
|
|
|
if( A ){ \
|
2009-01-23 18:44:15 +00:00
|
|
|
fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
|
2008-09-23 19:11:04 +00:00
|
|
|
} else { \
|
2009-01-23 18:44:15 +00:00
|
|
|
fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
|
2008-09-23 19:11:04 +00:00
|
|
|
return test; \
|
|
|
|
} \
|
|
|
|
}
|
2009-01-23 18:44:15 +00:00
|
|
|
#else
|
|
|
|
#define check( A )\
|
|
|
|
{ \
|
|
|
|
++test; \
|
|
|
|
if( !( A ) ){ \
|
|
|
|
fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
|
|
|
|
return test; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#endif
|
2008-03-29 21:05:51 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
createTestBlocklist( const char * tmpfile )
|
|
|
|
{
|
|
|
|
const char * lines[] = { "Austin Law Firm:216.16.1.144-216.16.1.151",
|
|
|
|
"Sargent Controls and Aerospace:216.19.18.0-216.19.18.255",
|
|
|
|
"Corel Corporation:216.21.157.192-216.21.157.223",
|
|
|
|
"Fox Speed Channel:216.79.131.192-216.79.131.223" };
|
2008-09-23 19:11:04 +00:00
|
|
|
FILE * out;
|
|
|
|
int i;
|
|
|
|
const int lineCount = sizeof( lines ) / sizeof( lines[0] );
|
2008-03-29 21:05:51 +00:00
|
|
|
|
|
|
|
/* create the ascii file to feed to libtransmission */
|
|
|
|
out = fopen( tmpfile, "w+" );
|
2008-09-23 19:11:04 +00:00
|
|
|
for( i = 0; i < lineCount; ++i )
|
2008-03-29 21:05:51 +00:00
|
|
|
fprintf( out, "%s\n", lines[i] );
|
|
|
|
fclose( out );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main( void )
|
|
|
|
{
|
2008-09-06 07:26:29 +00:00
|
|
|
#ifndef WIN32
|
2009-01-23 18:44:15 +00:00
|
|
|
const char * tmpfile_txt = "/tmp/transmission-blocklist-test.txt";
|
|
|
|
const char * tmpfile_bin = "/tmp/transmission-blocklist-test.bin";
|
2008-09-06 07:26:29 +00:00
|
|
|
#else
|
2009-01-23 18:44:15 +00:00
|
|
|
const char * tmpfile_txt = "transmission-blocklist-test.txt";
|
|
|
|
const char * tmpfile_bin = "transmission-blocklist-test.bin";
|
2008-09-06 07:26:29 +00:00
|
|
|
#endif
|
2008-12-02 03:41:58 +00:00
|
|
|
struct tr_address addr;
|
2008-09-23 19:11:04 +00:00
|
|
|
int test = 0;
|
2008-04-01 19:20:21 +00:00
|
|
|
tr_blocklist * b;
|
2008-03-29 21:05:51 +00:00
|
|
|
|
2008-04-01 19:20:21 +00:00
|
|
|
remove( tmpfile_txt );
|
|
|
|
remove( tmpfile_bin );
|
2008-03-29 21:05:51 +00:00
|
|
|
|
2008-04-01 19:20:21 +00:00
|
|
|
b = _tr_blocklistNew( tmpfile_bin, TRUE );
|
|
|
|
createTestBlocklist( tmpfile_txt );
|
|
|
|
_tr_blocklistSetContent( b, tmpfile_txt );
|
2008-03-29 21:05:51 +00:00
|
|
|
|
|
|
|
/* now run some tests */
|
2008-12-02 03:41:58 +00:00
|
|
|
check( tr_pton( "216.16.1.143", &addr ) );
|
2008-04-01 19:20:21 +00:00
|
|
|
check( !_tr_blocklistHasAddress( b, &addr ) );
|
2008-12-02 03:41:58 +00:00
|
|
|
check( tr_pton( "216.16.1.144", &addr ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
check( _tr_blocklistHasAddress( b, &addr ) );
|
2008-12-02 03:41:58 +00:00
|
|
|
check( tr_pton( "216.16.1.145", &addr ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
check( _tr_blocklistHasAddress( b, &addr ) );
|
2008-12-02 03:41:58 +00:00
|
|
|
check( tr_pton( "216.16.1.146", &addr ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
check( _tr_blocklistHasAddress( b, &addr ) );
|
2008-12-02 03:41:58 +00:00
|
|
|
check( tr_pton( "216.16.1.147", &addr ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
check( _tr_blocklistHasAddress( b, &addr ) );
|
2008-12-02 03:41:58 +00:00
|
|
|
check( tr_pton( "216.16.1.148", &addr ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
check( _tr_blocklistHasAddress( b, &addr ) );
|
2008-12-02 03:41:58 +00:00
|
|
|
check( tr_pton( "216.16.1.149", &addr ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
check( _tr_blocklistHasAddress( b, &addr ) );
|
2008-12-02 03:41:58 +00:00
|
|
|
check( tr_pton( "216.16.1.150", &addr ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
check( _tr_blocklistHasAddress( b, &addr ) );
|
2008-12-02 03:41:58 +00:00
|
|
|
check( tr_pton( "216.16.1.151", &addr ) );
|
2008-09-23 19:11:04 +00:00
|
|
|
check( _tr_blocklistHasAddress( b, &addr ) );
|
2008-12-02 03:41:58 +00:00
|
|
|
check( tr_pton( "216.16.1.152", &addr ) );
|
2008-04-01 19:20:21 +00:00
|
|
|
check( !_tr_blocklistHasAddress( b, &addr ) );
|
2008-12-02 03:41:58 +00:00
|
|
|
check( tr_pton( "216.16.1.153", &addr ) );
|
2008-04-01 19:20:21 +00:00
|
|
|
check( !_tr_blocklistHasAddress( b, &addr ) );
|
2008-12-02 03:41:58 +00:00
|
|
|
check( tr_pton( "217.0.0.1", &addr ) );
|
2008-04-01 19:20:21 +00:00
|
|
|
check( !_tr_blocklistHasAddress( b, &addr ) );
|
2008-12-02 03:41:58 +00:00
|
|
|
check( tr_pton( "255.0.0.1", &addr ) );
|
2008-03-29 21:05:51 +00:00
|
|
|
|
2008-04-01 19:20:21 +00:00
|
|
|
/* cleanup */
|
|
|
|
_tr_blocklistFree( b );
|
|
|
|
remove( tmpfile_txt );
|
|
|
|
remove( tmpfile_bin );
|
2008-03-29 21:05:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|