00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <spl/Debug.h>
00018 #include <spl/Log.h>
00019 #include <spl/RefCountPtr.h>
00020 #include <spl/String.h>
00021
00022 #ifdef DEBUG
00023
00024 static void _TestRefCountPtr1()
00025 {
00026 RefCountPtr<int> pi(new int[1]);
00027
00028 DEBUG_CLEAR_MEM_CHECK_POINTS();
00029 pi.CheckMem();
00030 DEBUG_DUMP_MEM_LEAKS();
00031 UNIT_ASSERT_MEM_NOTED("RefCountPtr test 1.0");
00032
00033 UNIT_ASSERT("1", pi.ReferenceCount() == 1);
00034
00035 {
00036 RefCountPtr<int> pi2 = pi;
00037 pi2.ValidateMem();
00038 pi.ValidateMem();
00039 UNIT_ASSERT("assign", pi2.ReferenceCount() == 2);
00040 UNIT_ASSERT("assign", pi.ReferenceCount() == 2);
00041
00042 *pi2 = 6;
00043 }
00044
00045 UNIT_ASSERT("1", pi.ReferenceCount() == 1);
00046 UNIT_ASSERT("6", *pi == 6);
00047
00048 DEBUG_CLEAR_MEM_CHECK_POINTS();
00049 pi.CheckMem();
00050 DEBUG_DUMP_MEM_LEAKS();
00051 UNIT_ASSERT_MEM_NOTED("RefCountPtr test 1.1");
00052
00053 Log::SWriteOkFail( "RefCountPtr test" );
00054 }
00055
00056 static StringPtr _TestReturnStringPtrNull()
00057 {
00058 return StringPtr();
00059 }
00060
00061 void _TestRefCountPtrRegression1()
00062 {
00063 {
00064 StringPtr ptr = _TestReturnStringPtrNull();
00065 UNIT_ASSERT("Should be null", ptr.IsNull());
00066 UNIT_ASSERT("Should be not notnull", ! ptr.IsNotNull());
00067 }
00068
00069 DEBUG_CLEAR_MEM_CHECK_POINTS();
00070 DEBUG_DUMP_MEM_LEAKS();
00071 UNIT_ASSERT_MEM_NOTED("RefCountPtr regression 1.1");
00072
00073 Log::SWriteOkFail( "RefCountPtr StringPtr() NULL regression" );
00074 }
00075
00076 void _TestRefCountPtr()
00077 {
00078 _TestRefCountPtr1();
00079 DEBUG_CLEAR_MEM_CHECK_POINTS();
00080 UNIT_ASSERT_MEM_NOTED("_TestRefCountPtr");
00081
00082 _TestRefCountPtrRegression1();
00083 DEBUG_CLEAR_MEM_CHECK_POINTS();
00084 UNIT_ASSERT_MEM_NOTED("_TestRefCountPtrRegression1");
00085 }
00086
00087 #endif