00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <spl/Debug.h>
00018
00019 #ifdef DEBUG
00020 #include <spl/Log.h>
00021 #include <spl/collection/MemoryPool.h>
00022
00023 static void _TestMemoryPool1()
00024 {
00025 MemoryPool *mp = new MemoryPool(9);
00026
00027 DEBUG_CLEAR_MEM_CHECK_POINTS();
00028 DEBUG_NOTE_MEM(mp);
00029 mp->CheckMem();
00030 DEBUG_DUMP_MEM_LEAKS();
00031 UNIT_ASSERT_MEM_NOTED("MemoryPool test 1.0");
00032
00033 byte *onebyte = (byte *)mp->Malloc(1);
00034 ASSERT_PTR(onebyte);
00035 *onebyte = 'A';
00036 UNIT_ASSERT("onebyte ptr", mp->IsValidPointer(onebyte));
00037
00038 DEBUG_CLEAR_MEM_CHECK_POINTS();
00039 DEBUG_NOTE_MEM(mp);
00040 mp->CheckMem();
00041 DEBUG_DUMP_MEM_LEAKS();
00042 UNIT_ASSERT_MEM_NOTED("MemoryPool test 1.1");
00043
00044 byte *onebyte2 = (byte *)mp->Malloc(1);
00045 ASSERT_PTR(onebyte2);
00046 *onebyte2 = 'B';
00047
00048 UNIT_ASSERT("A", *onebyte == 'A');
00049 UNIT_ASSERT("B", *onebyte2 == 'B');
00050 ASSERT_PTR(onebyte);
00051 ASSERT_PTR(onebyte2);
00052 UNIT_ASSERT("onebyte ptr", mp->IsValidPointer(onebyte));
00053 UNIT_ASSERT("onebyte ptr2", mp->IsValidPointer(onebyte2));
00054
00055 mp->ValidateMem();
00056
00057 *onebyte = 'C';
00058 UNIT_ASSERT("A", *onebyte == 'C');
00059 UNIT_ASSERT("B", *onebyte2 == 'B');
00060 ASSERT_PTR(onebyte);
00061 ASSERT_PTR(onebyte2);
00062 UNIT_ASSERT("onebyte ptr", mp->IsValidPointer(onebyte));
00063 UNIT_ASSERT("onebyte ptr2", mp->IsValidPointer(onebyte2));
00064
00065 mp->Free(onebyte);
00066 UNIT_ASSERT("B", *onebyte2 == 'B');
00067 ASSERT_PTR(onebyte2);
00068 UNIT_ASSERT("onebyte ptr2", mp->IsValidPointer(onebyte2));
00069
00070 mp->Free(onebyte2);
00071 mp->ValidateMem();
00072
00073 DEBUG_CLEAR_MEM_CHECK_POINTS();
00074 DEBUG_NOTE_MEM(mp);
00075 mp->CheckMem();
00076 DEBUG_DUMP_MEM_LEAKS();
00077 UNIT_ASSERT_MEM_NOTED("MemoryPool test 1.2");
00078
00079 delete mp;
00080
00081 DEBUG_CLEAR_MEM_CHECK_POINTS();
00082 DEBUG_DUMP_MEM_LEAKS();
00083 UNIT_ASSERT_MEM_NOTED("MemoryPool test 1.3");
00084
00085 Log::SWriteOkFail( "MemoryPool test 1" );
00086 }
00087
00088 void _TestMemoryPool()
00089 {
00090 _TestMemoryPool1();
00091 DEBUG_CLEAR_MEM_CHECK_POINTS();
00092 DEBUG_DUMP_MEM_LEAKS();
00093 }
00094
00095 #endif