libStatGen Software 1
Loading...
Searching...
No Matches
SamRecordPoolTest Class Reference

Static Public Member Functions

static void testSamRecordPool ()
 

Detailed Description

Definition at line 23 of file TestSamRecordPool.h.

Member Function Documentation

◆ testSamRecordPool()

void SamRecordPoolTest::testSamRecordPool ( )
static

Definition at line 29 of file TestSamRecordPool.cpp.

30{
31
32 // Attempt to allocate with max size 0,
33 // fails to get a record.
34 SamRecordPool pool(0);
35 assert(pool.getRecord() == NULL);
36
37 // Up the max size to 3.
38 pool.setMaxAllocatedRecs(3);
39
40 // Successfully get 1st record.
41 SamRecord* rec1 = pool.getRecord();
42 assert(rec1 != NULL);
43
44 // Successfully get 2nd record.
45 SamRecord* rec2 = pool.getRecord();
46 assert(rec2 != NULL);
47 assert(rec2 != rec1);
48
49 // Successfully get 3rd record.
50 SamRecord* rec3 = pool.getRecord();
51 assert(rec3 != NULL);
52 assert((rec3 != rec1) && (rec3 != rec2));
53
54 // Fail to get a 4th record.
55 assert(pool.getRecord() == NULL);
56
57 // Release a record and confirm its reuse.
58 pool.releaseRecord(rec2);
59 SamRecord* rec = pool.getRecord();
60 assert(rec == rec2);
61
62 // Release multiple records and check reuse.
63 pool.releaseRecord(rec3);
64 pool.releaseRecord(rec1);
65 pool.releaseRecord(rec);
66 SamRecord* release1 = pool.getRecord();
67 SamRecord* release2 = pool.getRecord();
68 SamRecord* release3 = pool.getRecord();
69 assert(release1 == rec3);
70 assert(release2 == rec1);
71 assert(release3 == rec);
72 assert(pool.getRecord() == NULL);
73
74 // Up the max allocated size but don't allocate any, then
75 // reduce the max allocated size and release all the records
76 // but the already allocated records will still be used.
77 pool.setMaxAllocatedRecs(4);
78 pool.setMaxAllocatedRecs(0);
79 pool.releaseRecord(release3);
80 pool.releaseRecord(release1);
81 pool.releaseRecord(release2);
82 rec1 = pool.getRecord();
83 rec2 = pool.getRecord();
84 rec3 = pool.getRecord();
85 assert(rec1 == release3);
86 assert(rec2 == release1);
87 assert(rec3 == release2);
88 assert(pool.getRecord() == NULL);
89
90
91 // Up the max allocated size and allocate another record.
92 pool.setMaxAllocatedRecs(4);
93 rec = pool.getRecord();
94 assert(rec != NULL);
95 assert(rec != rec1);
96 assert(rec != rec2);
97 assert(rec != rec3);
98 assert(pool.getRecord() == NULL);
99}
Class providing an easy to use interface to get/set/operate on the fields in a SAM/BAM record.
Definition SamRecord.h:52

The documentation for this class was generated from the following files: