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

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

(trunk libT) #4051 "Use composition for the tr_history fields in tr_peer" -- fixed.

If we use composition on these objects we can save a handful of pointers per peer. This isn't a big deal, but it's an easy/safe change to do.

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