libStatGen Software 1
Loading...
Searching...
No Matches
TestSamRecordPool.cpp
1/*
2 * Copyright (C) 2011 Regents of the University of Michigan
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "TestSamRecordPool.h"
19#include "SamRecordPool.h"
20#include <assert.h>
21
22void testSamRecordPool()
23{
24 // Call generic test.
25 SamRecordPoolTest::testSamRecordPool();
26}
27
28
29void SamRecordPoolTest::testSamRecordPool()
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