source: trunk/libtransmission/history-test.c @ 12918

Last change on this file since 12918 was 12328, checked in by jordan, 11 years ago

(trunk libT) more heap pruning: avoid four unnecessary malloc() + free() calls per tr_peer.

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.

File size: 1.3 KB
Line 
1#include <stdio.h>
2#include <string.h> /* memset() */
3
4#include "transmission.h"
5#include "history.h"
6
7#undef VERBOSE
8
9static int test = 0;
10
11#ifdef VERBOSE
12  #define check( A ) \
13    { \
14        ++test; \
15        if( A ){ \
16            fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
17        } else { \
18            fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
19            return test; \
20        } \
21    }
22#else
23  #define check( A ) \
24    { \
25        ++test; \
26        if( !( A ) ){ \
27            fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
28            return test; \
29        } \
30    }
31#endif
32
33static int
34test1( void )
35{
36    tr_recentHistory h;
37
38    memset( &h, 0, sizeof( tr_recentHistory ) );
39
40    tr_historyAdd( &h, 10000, 1 );
41    check( (int)tr_historyGet( &h, 12000, 1000 ) == 0 )
42    check( (int)tr_historyGet( &h, 12000, 3000 ) == 1 )
43    check( (int)tr_historyGet( &h, 12000, 5000 ) == 1 )
44    tr_historyAdd( &h, 20000, 1 );
45    check( (int)tr_historyGet( &h, 22000,  1000 ) == 0 )
46    check( (int)tr_historyGet( &h, 22000,  3000 ) == 1 )
47    check( (int)tr_historyGet( &h, 22000, 15000 ) == 2 )
48    check( (int)tr_historyGet( &h, 22000, 20000 ) == 2 )
49
50    return 0;
51}
52
53int
54main( void )
55{
56    int i;
57
58    if( ( i = test1( ) ) )
59        return i;
60
61    return 0;
62}
63
Note: See TracBrowser for help on using the repository browser.