TestSamRecordPool.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "TestSamRecordPool.h"
00019 #include "SamRecordPool.h"
00020 #include <assert.h>
00021
00022 void testSamRecordPool()
00023 {
00024
00025 SamRecordPoolTest::testSamRecordPool();
00026 }
00027
00028
00029 void SamRecordPoolTest::testSamRecordPool()
00030 {
00031
00032
00033
00034 SamRecordPool pool(0);
00035 assert(pool.getRecord() == NULL);
00036
00037
00038 pool.setMaxAllocatedRecs(3);
00039
00040
00041 SamRecord* rec1 = pool.getRecord();
00042 assert(rec1 != NULL);
00043
00044
00045 SamRecord* rec2 = pool.getRecord();
00046 assert(rec2 != NULL);
00047 assert(rec2 != rec1);
00048
00049
00050 SamRecord* rec3 = pool.getRecord();
00051 assert(rec3 != NULL);
00052 assert((rec3 != rec1) && (rec3 != rec2));
00053
00054
00055 assert(pool.getRecord() == NULL);
00056
00057
00058 pool.releaseRecord(rec2);
00059 SamRecord* rec = pool.getRecord();
00060 assert(rec == rec2);
00061
00062
00063 pool.releaseRecord(rec3);
00064 pool.releaseRecord(rec1);
00065 pool.releaseRecord(rec);
00066 SamRecord* release1 = pool.getRecord();
00067 SamRecord* release2 = pool.getRecord();
00068 SamRecord* release3 = pool.getRecord();
00069 assert(release1 == rec3);
00070 assert(release2 == rec1);
00071 assert(release3 == rec);
00072 assert(pool.getRecord() == NULL);
00073
00074
00075
00076
00077 pool.setMaxAllocatedRecs(4);
00078 pool.setMaxAllocatedRecs(0);
00079 pool.releaseRecord(release3);
00080 pool.releaseRecord(release1);
00081 pool.releaseRecord(release2);
00082 rec1 = pool.getRecord();
00083 rec2 = pool.getRecord();
00084 rec3 = pool.getRecord();
00085 assert(rec1 == release3);
00086 assert(rec2 == release1);
00087 assert(rec3 == release2);
00088 assert(pool.getRecord() == NULL);
00089
00090
00091
00092 pool.setMaxAllocatedRecs(4);
00093 rec = pool.getRecord();
00094 assert(rec != NULL);
00095 assert(rec != rec1);
00096 assert(rec != rec2);
00097 assert(rec != rec3);
00098 assert(pool.getRecord() == NULL);
00099 }