equal
deleted
inserted
replaced
53 #include <e32panic.h> |
53 #include <e32panic.h> |
54 #include <e32debug.h> |
54 #include <e32debug.h> |
55 #include <e32def.h> |
55 #include <e32def.h> |
56 #include <e32def_private.h> |
56 #include <e32def_private.h> |
57 |
57 |
58 |
58 #if defined(_DEBUG) |
59 const TInt KInitialCount=2; |
59 const TInt KInitialCount=2; |
60 const TInt KInitialCountAll=3; |
60 const TInt KInitialCountAll=3; |
|
61 #endif |
|
62 |
61 const TInt KLeaveValue=0x12345678; |
63 const TInt KLeaveValue=0x12345678; |
62 const TInt KMaxAlloc=6; |
64 const TInt KMaxAlloc=6; |
63 |
65 |
64 static const TInt KHeapSize = 0x2000; |
66 static const TInt KHeapSize = 0x2000; |
65 |
67 |
104 LOCAL_D CBufFlat* gP2; |
106 LOCAL_D CBufFlat* gP2; |
105 |
107 |
106 |
108 |
107 LOCAL_C void ReallocateStackL() |
109 LOCAL_C void ReallocateStackL() |
108 { |
110 { |
109 TInt n = 0; |
|
110 for(TInt i = 0; i < KMaxAlloc; ++i) |
111 for(TInt i = 0; i < KMaxAlloc; ++i) |
111 { |
112 { |
112 HBufC *p1 = HBufC::NewLC(4); //Stack re-allocation will be performed due to the additional objects pushed |
113 (void)HBufC::NewLC(4); //Stack re-allocation will be performed due to the additional objects pushed |
113 //into the cleanup stack |
114 //into the cleanup stack |
114 n = p1->Length(); //include this line to avoid warnigs for unused "p1" variable |
|
115 } |
115 } |
116 test.Printf(_L("ReallocateStackL(): PopAndDestroy KMaxAlloc pointers\n")); |
116 test.Printf(_L("ReallocateStackL(): PopAndDestroy KMaxAlloc pointers\n")); |
117 CleanupStack::PopAndDestroy(KMaxAlloc); |
117 CleanupStack::PopAndDestroy(KMaxAlloc); |
118 } |
118 } |
119 |
119 |
128 |
128 |
129 CTest3::~CTest3() |
129 CTest3::~CTest3() |
130 { |
130 { |
131 RDebug::Printf("~CTest3(): Modify Cleanup stack by pushing items"); |
131 RDebug::Printf("~CTest3(): Modify Cleanup stack by pushing items"); |
132 |
132 |
133 TInt n = 0; |
|
134 for(TInt i = 0; i < KMaxAlloc; ++i) |
133 for(TInt i = 0; i < KMaxAlloc; ++i) |
135 { |
134 { |
136 HBufC *p1 = HBufC::NewLC(4); //Stack re-allocation will be performed due to the additional objects pushed |
135 HBufC::NewLC(4); //Stack re-allocation will be performed due to the additional objects pushed |
137 //into the cleanup stack |
136 //into the cleanup stack |
138 n = p1->Length(); //include this line to avoid warnigs for unused "p1" variable |
|
139 } |
137 } |
140 } |
138 } |
141 |
139 |
142 LOCAL_C void ModifyStack() |
140 LOCAL_C void ModifyStack() |
143 { |
141 { |
146 |
144 |
147 RDebug::Printf("ModifyStack(): PopAndDestroy ptr6"); |
145 RDebug::Printf("ModifyStack(): PopAndDestroy ptr6"); |
148 CleanupStack::PopAndDestroy(); |
146 CleanupStack::PopAndDestroy(); |
149 } |
147 } |
150 |
148 |
151 LOCAL_C TInt PanicStackModifiedFn(TAny* aNopFn) |
149 LOCAL_C TInt PanicStackModifiedFn(TAny* /*aNopFn*/) |
152 { |
150 { |
153 __UHEAP_MARK; |
151 __UHEAP_MARK; |
154 CTrapCleanup* cleanup = CTrapCleanup::New(); |
152 CTrapCleanup* cleanup = CTrapCleanup::New(); |
155 |
|
156 aNopFn = NULL; //avoid warnings for unused "aNopFn" variable |
|
157 |
153 |
158 TInt err = KErrNoMemory; |
154 TInt err = KErrNoMemory; |
159 |
155 |
160 RDebug::Printf("PanicStackModifiedFn(): call TRAP(err, ModifyStack())"); |
156 RDebug::Printf("PanicStackModifiedFn(): call TRAP(err, ModifyStack())"); |
161 |
157 |
1089 // since room is always made for a free slot. We set the allocator |
1085 // since room is always made for a free slot. We set the allocator |
1090 // to fail so that we can test that the free slot is re-established |
1086 // to fail so that we can test that the free slot is re-established |
1091 // when we do the cleanup. This test only works in debug mode. |
1087 // when we do the cleanup. This test only works in debug mode. |
1092 // |
1088 // |
1093 __UHEAP_FAILNEXT(1); |
1089 __UHEAP_FAILNEXT(1); |
|
1090 #if defined(_DEBUG) |
1094 TRAPD(r,pC->PushL(p6)); |
1091 TRAPD(r,pC->PushL(p6)); |
1095 #if defined(_DEBUG) |
|
1096 test(r==KErrNoMemory); |
1092 test(r==KErrNoMemory); |
|
1093 #else |
|
1094 TRAP_IGNORE(pC->PushL(p6)); |
1097 #endif |
1095 #endif |
1098 __UHEAP_CHECK(KInitialCount+6); |
1096 __UHEAP_CHECK(KInitialCount+6); |
1099 pC->PopAndDestroyAll(); |
1097 pC->PopAndDestroyAll(); |
1100 __UHEAP_CHECK(KInitialCount); |
1098 __UHEAP_CHECK(KInitialCount); |
1101 // |
1099 // |
1298 LOCAL_C void reentrantCleanup(TAny*) |
1296 LOCAL_C void reentrantCleanup(TAny*) |
1299 // |
1297 // |
1300 // A cleanup operation which uses a trap harness and the cleanup stack |
1298 // A cleanup operation which uses a trap harness and the cleanup stack |
1301 // |
1299 // |
1302 { |
1300 { |
1303 TRAPD(ignore,useCleanupStackL()) |
1301 TRAP_IGNORE(useCleanupStackL()); |
1304 } |
1302 } |
1305 |
1303 |
1306 LOCAL_C void addReentrantItemL() |
1304 LOCAL_C void addReentrantItemL() |
1307 { |
1305 { |
1308 CleanupStack::PushL(TCleanupItem(reentrantCleanup)); |
1306 CleanupStack::PushL(TCleanupItem(reentrantCleanup)); |
1422 test.Next(_L("Let it fall out of scope")); |
1420 test.Next(_L("Let it fall out of scope")); |
1423 } |
1421 } |
1424 test.Next(_L("Check the object has closed")); |
1422 test.Next(_L("Check the object has closed")); |
1425 __KHEAP_CHECK(0); |
1423 __KHEAP_CHECK(0); |
1426 |
1424 |
1427 TRAPD(r, testAutoCloseL()); |
1425 TRAP_IGNORE(testAutoCloseL()); |
1428 test.Next(_L("Check object has been closed and cleaned up after leave")); |
1426 test.Next(_L("Check object has been closed and cleaned up after leave")); |
1429 __KHEAP_MARKEND; |
1427 __KHEAP_MARKEND; |
1430 test.End(); |
1428 test.End(); |
1431 } |
1429 } |
1432 |
1430 |