mirror of
https://github.com/transmission/transmission
synced 2024-12-26 01:27:28 +00:00
712ee263de
This commit also changes tr_recentHistory from being a general-purpose tool to being a little more hardcoded for the only purpose it's used, in tr_peerMgr. If its files (history.[ch]) don't find any other "customers" in libtransmission, eventually it should be demoted to being a private helper class inside of peer-mgr.c and have the history.[ch] files removed from the build.
63 lines
1.3 KiB
C
63 lines
1.3 KiB
C
#include <stdio.h>
|
|
#include <string.h> /* memset() */
|
|
|
|
#include "transmission.h"
|
|
#include "history.h"
|
|
|
|
#undef VERBOSE
|
|
|
|
static int test = 0;
|
|
|
|
#ifdef VERBOSE
|
|
#define check( A ) \
|
|
{ \
|
|
++test; \
|
|
if( A ){ \
|
|
fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
|
|
} else { \
|
|
fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
|
|
return test; \
|
|
} \
|
|
}
|
|
#else
|
|
#define check( A ) \
|
|
{ \
|
|
++test; \
|
|
if( !( A ) ){ \
|
|
fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
|
|
return test; \
|
|
} \
|
|
}
|
|
#endif
|
|
|
|
static int
|
|
test1( void )
|
|
{
|
|
tr_recentHistory h;
|
|
|
|
memset( &h, 0, sizeof( tr_recentHistory ) );
|
|
|
|
tr_historyAdd( &h, 10000, 1 );
|
|
check( (int)tr_historyGet( &h, 12000, 1000 ) == 0 )
|
|
check( (int)tr_historyGet( &h, 12000, 3000 ) == 1 )
|
|
check( (int)tr_historyGet( &h, 12000, 5000 ) == 1 )
|
|
tr_historyAdd( &h, 20000, 1 );
|
|
check( (int)tr_historyGet( &h, 22000, 1000 ) == 0 )
|
|
check( (int)tr_historyGet( &h, 22000, 3000 ) == 1 )
|
|
check( (int)tr_historyGet( &h, 22000, 15000 ) == 2 )
|
|
check( (int)tr_historyGet( &h, 22000, 20000 ) == 2 )
|
|
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
main( void )
|
|
{
|
|
int i;
|
|
|
|
if( ( i = test1( ) ) )
|
|
return i;
|
|
|
|
return 0;
|
|
}
|
|
|