sl@0
|
1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\system\t_ctrap.cpp
|
sl@0
|
15 |
// Overview:
|
sl@0
|
16 |
// Test the CCleanup, CTrapCleanup and TAutoClose classes
|
sl@0
|
17 |
// API Information:
|
sl@0
|
18 |
// CCleanup, CTrapCleanup, TAutoClose
|
sl@0
|
19 |
// Details:
|
sl@0
|
20 |
// - Test cleanup stack reallocation during cleanup.
|
sl@0
|
21 |
// - Test cleanup stack modifications during the cleanup operation
|
sl@0
|
22 |
// will cause a panic.
|
sl@0
|
23 |
// - Test single-level cleanup of cells, objects, items and a mix:
|
sl@0
|
24 |
// Create a CCleanup object, call a combination of methods, verify
|
sl@0
|
25 |
// the results are as expected and verify the heap has not been
|
sl@0
|
26 |
// corrupted.
|
sl@0
|
27 |
// - Test multi-level cleanup of cells, objects, items and a mix:
|
sl@0
|
28 |
// Create a CCleanup object, call a combination of methods, verify
|
sl@0
|
29 |
// the results are as expected and verify the heap has not been
|
sl@0
|
30 |
// corrupted.
|
sl@0
|
31 |
// - Test a variety of special case cleanup tasks. Verify that the
|
sl@0
|
32 |
// results are as expected.
|
sl@0
|
33 |
// - Test CTrapCleanup cleanup of objects that either exit normally
|
sl@0
|
34 |
// or leave. Also test the cleanup of multiple objects that leave.
|
sl@0
|
35 |
// Verify results are as expected.
|
sl@0
|
36 |
// - Test TAutoClose: create a TAutoClose object, verify that it is
|
sl@0
|
37 |
// closed when it goes out of scope, push it on the cleanup stack,
|
sl@0
|
38 |
// verify cleanup results are as expected.
|
sl@0
|
39 |
// - Test that the Cleanup stack can go re-entrant.
|
sl@0
|
40 |
// - Ensure that the stack is properly balanced with and without
|
sl@0
|
41 |
// leaving.
|
sl@0
|
42 |
// Platforms/Drives/Compatibility:
|
sl@0
|
43 |
// All.
|
sl@0
|
44 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
45 |
// Failures and causes:
|
sl@0
|
46 |
// Base Port information:
|
sl@0
|
47 |
//
|
sl@0
|
48 |
//
|
sl@0
|
49 |
|
sl@0
|
50 |
#define __E32TEST_EXTENSION__
|
sl@0
|
51 |
|
sl@0
|
52 |
#include <e32test.h>
|
sl@0
|
53 |
#include <e32panic.h>
|
sl@0
|
54 |
#include <e32debug.h>
|
sl@0
|
55 |
#include <e32def.h>
|
sl@0
|
56 |
#include <e32def_private.h>
|
sl@0
|
57 |
|
sl@0
|
58 |
|
sl@0
|
59 |
const TInt KInitialCount=2;
|
sl@0
|
60 |
const TInt KInitialCountAll=3;
|
sl@0
|
61 |
const TInt KLeaveValue=0x12345678;
|
sl@0
|
62 |
const TInt KMaxAlloc=6;
|
sl@0
|
63 |
|
sl@0
|
64 |
static const TInt KHeapSize = 0x2000;
|
sl@0
|
65 |
|
sl@0
|
66 |
enum TWhat {EPop,EPopAndDestroy,EMulti,ENull};
|
sl@0
|
67 |
|
sl@0
|
68 |
class CTest : public CBase
|
sl@0
|
69 |
{
|
sl@0
|
70 |
public:
|
sl@0
|
71 |
void ConstructL();
|
sl@0
|
72 |
private:
|
sl@0
|
73 |
TInt iData;
|
sl@0
|
74 |
};
|
sl@0
|
75 |
|
sl@0
|
76 |
class CTest2: public CBase
|
sl@0
|
77 |
{
|
sl@0
|
78 |
public:
|
sl@0
|
79 |
~CTest2();
|
sl@0
|
80 |
};
|
sl@0
|
81 |
|
sl@0
|
82 |
class CTest3: public CBase
|
sl@0
|
83 |
{
|
sl@0
|
84 |
public:
|
sl@0
|
85 |
~CTest3();
|
sl@0
|
86 |
};
|
sl@0
|
87 |
|
sl@0
|
88 |
class RItem
|
sl@0
|
89 |
{
|
sl@0
|
90 |
public:
|
sl@0
|
91 |
RItem() : iOpen(EFalse) {}
|
sl@0
|
92 |
void Open() {iOpen=ETrue;}
|
sl@0
|
93 |
void Close() {iOpen=EFalse;}
|
sl@0
|
94 |
operator TCleanupItem() {return TCleanupItem(Cleanup,this);}
|
sl@0
|
95 |
TBool IsOpen() const {return(iOpen);}
|
sl@0
|
96 |
private:
|
sl@0
|
97 |
static void Cleanup(TAny* aPtr);
|
sl@0
|
98 |
private:
|
sl@0
|
99 |
TBool iOpen;
|
sl@0
|
100 |
};
|
sl@0
|
101 |
|
sl@0
|
102 |
LOCAL_D RTest test(_L("T_CTRAP"));
|
sl@0
|
103 |
LOCAL_D TAny* gP1;
|
sl@0
|
104 |
LOCAL_D CBufFlat* gP2;
|
sl@0
|
105 |
|
sl@0
|
106 |
|
sl@0
|
107 |
LOCAL_C void ReallocateStackL()
|
sl@0
|
108 |
{
|
sl@0
|
109 |
TInt n = 0;
|
sl@0
|
110 |
for(TInt i = 0; i < KMaxAlloc; ++i)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
HBufC *p1 = HBufC::NewLC(4); //Stack re-allocation will be performed due to the additional objects pushed
|
sl@0
|
113 |
//into the cleanup stack
|
sl@0
|
114 |
n = p1->Length(); //include this line to avoid warnigs for unused "p1" variable
|
sl@0
|
115 |
}
|
sl@0
|
116 |
test.Printf(_L("ReallocateStackL(): PopAndDestroy KMaxAlloc pointers\n"));
|
sl@0
|
117 |
CleanupStack::PopAndDestroy(KMaxAlloc);
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
CTest2::~CTest2()
|
sl@0
|
121 |
{
|
sl@0
|
122 |
TInt err = KErrNoMemory;
|
sl@0
|
123 |
|
sl@0
|
124 |
test.Printf(_L("~CTest2(): call ReallocateStackL()\n"));
|
sl@0
|
125 |
|
sl@0
|
126 |
TRAP(err, ReallocateStackL() );
|
sl@0
|
127 |
}
|
sl@0
|
128 |
|
sl@0
|
129 |
CTest3::~CTest3()
|
sl@0
|
130 |
{
|
sl@0
|
131 |
RDebug::Printf("~CTest3(): Modify Cleanup stack by pushing items");
|
sl@0
|
132 |
|
sl@0
|
133 |
TInt n = 0;
|
sl@0
|
134 |
for(TInt i = 0; i < KMaxAlloc; ++i)
|
sl@0
|
135 |
{
|
sl@0
|
136 |
HBufC *p1 = HBufC::NewLC(4); //Stack re-allocation will be performed due to the additional objects pushed
|
sl@0
|
137 |
//into the cleanup stack
|
sl@0
|
138 |
n = p1->Length(); //include this line to avoid warnigs for unused "p1" variable
|
sl@0
|
139 |
}
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
LOCAL_C void ModifyStack()
|
sl@0
|
143 |
{
|
sl@0
|
144 |
CTest3* ptr6 = new(ELeave)CTest3;
|
sl@0
|
145 |
CleanupStack::PushL(ptr6);
|
sl@0
|
146 |
|
sl@0
|
147 |
RDebug::Printf("ModifyStack(): PopAndDestroy ptr6");
|
sl@0
|
148 |
CleanupStack::PopAndDestroy();
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
LOCAL_C TInt PanicStackModifiedFn(TAny* aNopFn)
|
sl@0
|
152 |
{
|
sl@0
|
153 |
__UHEAP_MARK;
|
sl@0
|
154 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
sl@0
|
155 |
|
sl@0
|
156 |
aNopFn = NULL; //avoid warnings for unused "aNopFn" variable
|
sl@0
|
157 |
|
sl@0
|
158 |
TInt err = KErrNoMemory;
|
sl@0
|
159 |
|
sl@0
|
160 |
RDebug::Printf("PanicStackModifiedFn(): call TRAP(err, ModifyStack())");
|
sl@0
|
161 |
|
sl@0
|
162 |
if(NULL != cleanup)
|
sl@0
|
163 |
{
|
sl@0
|
164 |
TRAP(err, ModifyStack());
|
sl@0
|
165 |
delete cleanup;
|
sl@0
|
166 |
}
|
sl@0
|
167 |
__UHEAP_MARKEND;
|
sl@0
|
168 |
return err;
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
LOCAL_C void PushAndCleanupL()
|
sl@0
|
172 |
{
|
sl@0
|
173 |
CTest2* ptr1 = new(ELeave)CTest2;
|
sl@0
|
174 |
CleanupStack::PushL(ptr1);
|
sl@0
|
175 |
|
sl@0
|
176 |
CTest2* ptr2 = new(ELeave)CTest2;
|
sl@0
|
177 |
CleanupStack::PushL(ptr2);
|
sl@0
|
178 |
|
sl@0
|
179 |
CTest2* ptr3 = new(ELeave)CTest2;
|
sl@0
|
180 |
CleanupStack::PushL(ptr3);
|
sl@0
|
181 |
|
sl@0
|
182 |
test.Printf(_L("PushAndCleanupL(): PopAndDestroy ptr3, ptr2 and ptr1\n"));
|
sl@0
|
183 |
CleanupStack::PopAndDestroy(3);
|
sl@0
|
184 |
|
sl@0
|
185 |
CTest2* ptr4 = new(ELeave)CTest2;
|
sl@0
|
186 |
CleanupStack::PushL(ptr4);
|
sl@0
|
187 |
|
sl@0
|
188 |
CTest2* ptr5 = new(ELeave)CTest2;
|
sl@0
|
189 |
CleanupStack::PushL(ptr5);
|
sl@0
|
190 |
|
sl@0
|
191 |
test.Printf(_L("PushAndCleanupL(): PopAndDestroy ptr5 and ptr4\n"));
|
sl@0
|
192 |
CleanupStack::PopAndDestroy();
|
sl@0
|
193 |
CleanupStack::PopAndDestroy();
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
LOCAL_C void testDestructorStackReallocation()
|
sl@0
|
197 |
{
|
sl@0
|
198 |
__UHEAP_MARK;
|
sl@0
|
199 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
sl@0
|
200 |
|
sl@0
|
201 |
TInt err = KErrNoMemory;
|
sl@0
|
202 |
|
sl@0
|
203 |
if(NULL != cleanup)
|
sl@0
|
204 |
{
|
sl@0
|
205 |
TRAP(err, PushAndCleanupL());
|
sl@0
|
206 |
delete cleanup;
|
sl@0
|
207 |
}
|
sl@0
|
208 |
__UHEAP_MARKEND;
|
sl@0
|
209 |
|
sl@0
|
210 |
test_KErrNone(err);
|
sl@0
|
211 |
|
sl@0
|
212 |
test.Printf(_L("Verify cleanup stack modification during cleanup operation causes EClnStackModified panic\n"));
|
sl@0
|
213 |
|
sl@0
|
214 |
//
|
sl@0
|
215 |
//To verify the above case a new thread is created which does modify the cleanup stack during cleanup.
|
sl@0
|
216 |
//The exit reason is then checked for the appropriate value(EClnStackModified)
|
sl@0
|
217 |
//
|
sl@0
|
218 |
|
sl@0
|
219 |
RThread panicThread;
|
sl@0
|
220 |
|
sl@0
|
221 |
TInt r = panicThread.Create(_L("Panic EClnStackModified Thread"), PanicStackModifiedFn, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
|
sl@0
|
222 |
|
sl@0
|
223 |
test_KErrNone(r);
|
sl@0
|
224 |
|
sl@0
|
225 |
TRequestStatus panicThreadStatus;
|
sl@0
|
226 |
panicThread.Logon(panicThreadStatus);
|
sl@0
|
227 |
|
sl@0
|
228 |
//don't want just in time debugging as we trap panics
|
sl@0
|
229 |
TBool justInTime=User::JustInTime();
|
sl@0
|
230 |
User::SetJustInTime(EFalse);
|
sl@0
|
231 |
|
sl@0
|
232 |
panicThread.Resume();
|
sl@0
|
233 |
|
sl@0
|
234 |
User::WaitForRequest(panicThreadStatus);
|
sl@0
|
235 |
|
sl@0
|
236 |
test_Equal(EExitPanic, panicThread.ExitType());
|
sl@0
|
237 |
test_Equal(EClnStackModified, panicThread.ExitReason());
|
sl@0
|
238 |
|
sl@0
|
239 |
User::SetJustInTime(justInTime);
|
sl@0
|
240 |
|
sl@0
|
241 |
CLOSE_AND_WAIT(panicThread);
|
sl@0
|
242 |
}
|
sl@0
|
243 |
|
sl@0
|
244 |
LOCAL_C void createMultiL()
|
sl@0
|
245 |
//
|
sl@0
|
246 |
// Create an object on the cleanup list and leave
|
sl@0
|
247 |
//
|
sl@0
|
248 |
{
|
sl@0
|
249 |
|
sl@0
|
250 |
CBufFlat* pT=CBufFlat::NewL(8);
|
sl@0
|
251 |
User::LeaveIfNull(pT);
|
sl@0
|
252 |
CleanupStack::PushL(pT);
|
sl@0
|
253 |
__UHEAP_CHECK(3);
|
sl@0
|
254 |
User::Leave(KLeaveValue+1);
|
sl@0
|
255 |
}
|
sl@0
|
256 |
|
sl@0
|
257 |
LOCAL_C void createL(TWhat aWhat,TBool aLeave)
|
sl@0
|
258 |
//
|
sl@0
|
259 |
// Create objects and then either leave or return.
|
sl@0
|
260 |
// Optionally pop them again.
|
sl@0
|
261 |
//
|
sl@0
|
262 |
{
|
sl@0
|
263 |
|
sl@0
|
264 |
gP1=User::AllocL(0x10);
|
sl@0
|
265 |
test.Printf(_L("createL 1"));
|
sl@0
|
266 |
CleanupStack::PushL(gP1);
|
sl@0
|
267 |
test.Printf(_L("createL 2"));
|
sl@0
|
268 |
__UHEAP_CHECK(1);
|
sl@0
|
269 |
test.Printf(_L("createL 3"));
|
sl@0
|
270 |
gP2=CBufFlat::NewL(8);
|
sl@0
|
271 |
test.Printf(_L("createL 4"));
|
sl@0
|
272 |
User::LeaveIfNull(gP2);
|
sl@0
|
273 |
test.Printf(_L("createL 5"));
|
sl@0
|
274 |
CleanupStack::PushL(gP2);
|
sl@0
|
275 |
test.Printf(_L("createL 6"));
|
sl@0
|
276 |
__UHEAP_CHECK(2);
|
sl@0
|
277 |
test.Printf(_L("createL 7"));
|
sl@0
|
278 |
if (aWhat==EPop)
|
sl@0
|
279 |
{
|
sl@0
|
280 |
test.Printf(_L("createL 8"));
|
sl@0
|
281 |
CleanupStack::Pop();
|
sl@0
|
282 |
test.Printf(_L("createL 9"));
|
sl@0
|
283 |
CleanupStack::Pop(1);
|
sl@0
|
284 |
test.Printf(_L("createL 10"));
|
sl@0
|
285 |
}
|
sl@0
|
286 |
if (aWhat==EPopAndDestroy)
|
sl@0
|
287 |
{
|
sl@0
|
288 |
test.Printf(_L("createL 11"));
|
sl@0
|
289 |
CleanupStack::PopAndDestroy();
|
sl@0
|
290 |
test.Printf(_L("createL 12"));
|
sl@0
|
291 |
CleanupStack::PopAndDestroy(1);
|
sl@0
|
292 |
test.Printf(_L("createL 13"));
|
sl@0
|
293 |
}
|
sl@0
|
294 |
if (aWhat==EMulti)
|
sl@0
|
295 |
{
|
sl@0
|
296 |
test.Printf(_L("createL 14"));
|
sl@0
|
297 |
TRAPD(r,createMultiL())
|
sl@0
|
298 |
test.Printf(_L("createL 15"));
|
sl@0
|
299 |
test(r==(KLeaveValue+1));
|
sl@0
|
300 |
test.Printf(_L("createL 16"));
|
sl@0
|
301 |
__UHEAP_CHECK(2);
|
sl@0
|
302 |
test.Printf(_L("createL 17"));
|
sl@0
|
303 |
}
|
sl@0
|
304 |
if (aLeave)
|
sl@0
|
305 |
{
|
sl@0
|
306 |
test.Printf(_L("createL 18"));
|
sl@0
|
307 |
User::Leave(KLeaveValue);
|
sl@0
|
308 |
}
|
sl@0
|
309 |
test.Printf(_L("createL 19"));
|
sl@0
|
310 |
}
|
sl@0
|
311 |
|
sl@0
|
312 |
LOCAL_C void createAllL(TBool aLeave)
|
sl@0
|
313 |
//
|
sl@0
|
314 |
// Call all functions which autmatically put objects on the cleanup list.
|
sl@0
|
315 |
//
|
sl@0
|
316 |
{
|
sl@0
|
317 |
|
sl@0
|
318 |
__UHEAP_CHECK(KInitialCountAll);
|
sl@0
|
319 |
TLex* pL=new(ELeave) TLex; // ::new, 1 cell
|
sl@0
|
320 |
CleanupStack::PushL(pL); // Push
|
sl@0
|
321 |
__UHEAP_CHECK(KInitialCountAll+1);
|
sl@0
|
322 |
CTest* pT=new(ELeave) CTest; // CBase::new, 1 cell
|
sl@0
|
323 |
CleanupStack::PushL(pT); // Push
|
sl@0
|
324 |
__UHEAP_CHECK(KInitialCountAll+2);
|
sl@0
|
325 |
pT->ConstructL(); // 1 more cell // Push
|
sl@0
|
326 |
__UHEAP_CHECK(KInitialCountAll+3);
|
sl@0
|
327 |
User::AllocLC(0x10); // Test RHeap::AllocLC as well // Push
|
sl@0
|
328 |
__UHEAP_CHECK(KInitialCountAll+4);
|
sl@0
|
329 |
_L("Hello").AllocLC(); // Test HBufC::NewLC() as well // Push
|
sl@0
|
330 |
__UHEAP_CHECK(KInitialCountAll+5);
|
sl@0
|
331 |
HBufC* pH=HBufC::NewMaxLC(8); // Push
|
sl@0
|
332 |
test(pH->Length()==8);
|
sl@0
|
333 |
__UHEAP_CHECK(KInitialCountAll+6);
|
sl@0
|
334 |
if (aLeave)
|
sl@0
|
335 |
User::Leave(KLeaveValue);
|
sl@0
|
336 |
// new behavior for TCleanupTrapHander requires Pushes to the
|
sl@0
|
337 |
// cleanup stack to be balanced by Pops
|
sl@0
|
338 |
CleanupStack::PopAndDestroy(6);
|
sl@0
|
339 |
}
|
sl@0
|
340 |
|
sl@0
|
341 |
LOCAL_C void testSingleLevelCellsCleanup()
|
sl@0
|
342 |
//
|
sl@0
|
343 |
// Test single level cells cleanup
|
sl@0
|
344 |
//
|
sl@0
|
345 |
{
|
sl@0
|
346 |
|
sl@0
|
347 |
test.Start(_L("Creating"));
|
sl@0
|
348 |
//
|
sl@0
|
349 |
__UHEAP_MARK;
|
sl@0
|
350 |
CCleanup* pC=CCleanup::New();
|
sl@0
|
351 |
test(pC!=NULL);
|
sl@0
|
352 |
//
|
sl@0
|
353 |
__UHEAP_MARK;
|
sl@0
|
354 |
//
|
sl@0
|
355 |
test.Next(_L("PopAll when empty"));
|
sl@0
|
356 |
pC->NextLevel();
|
sl@0
|
357 |
pC->PopAll();
|
sl@0
|
358 |
pC->NextLevel();
|
sl@0
|
359 |
pC->PopAndDestroyAll();
|
sl@0
|
360 |
__UHEAP_CHECK(0);
|
sl@0
|
361 |
//
|
sl@0
|
362 |
test.Next(_L("Push and pop"));
|
sl@0
|
363 |
TAny* p=User::Alloc(0x10);
|
sl@0
|
364 |
test(p!=NULL);
|
sl@0
|
365 |
__UHEAP_CHECK(1);
|
sl@0
|
366 |
pC->NextLevel();
|
sl@0
|
367 |
pC->PushL(p);
|
sl@0
|
368 |
pC->Pop();
|
sl@0
|
369 |
__UHEAP_CHECK(1);
|
sl@0
|
370 |
User::Free(p);
|
sl@0
|
371 |
__UHEAP_CHECK(0);
|
sl@0
|
372 |
pC->PopAll();
|
sl@0
|
373 |
__UHEAP_CHECK(0);
|
sl@0
|
374 |
//
|
sl@0
|
375 |
test.Next(_L("Push and pop N"));
|
sl@0
|
376 |
TAny* p1=User::Alloc(0x10);
|
sl@0
|
377 |
test(p1!=NULL);
|
sl@0
|
378 |
__UHEAP_CHECK(1);
|
sl@0
|
379 |
TAny* p2=User::Alloc(0x10);
|
sl@0
|
380 |
test(p2!=NULL);
|
sl@0
|
381 |
__UHEAP_CHECK(2);
|
sl@0
|
382 |
pC->NextLevel();
|
sl@0
|
383 |
pC->PushL(p1);
|
sl@0
|
384 |
pC->PushL(p2);
|
sl@0
|
385 |
pC->Pop(2);
|
sl@0
|
386 |
__UHEAP_CHECK(2);
|
sl@0
|
387 |
User::Free(p1);
|
sl@0
|
388 |
User::Free(p2);
|
sl@0
|
389 |
__UHEAP_CHECK(0);
|
sl@0
|
390 |
pC->PopAll();
|
sl@0
|
391 |
__UHEAP_CHECK(0);
|
sl@0
|
392 |
//
|
sl@0
|
393 |
test.Next(_L("Push and pop all"));
|
sl@0
|
394 |
p1=User::Alloc(0x10);
|
sl@0
|
395 |
test(p1!=NULL);
|
sl@0
|
396 |
__UHEAP_CHECK(1);
|
sl@0
|
397 |
p2=User::Alloc(0x10);
|
sl@0
|
398 |
test(p2!=NULL);
|
sl@0
|
399 |
__UHEAP_CHECK(2);
|
sl@0
|
400 |
TAny* p3=User::Alloc(0x10);
|
sl@0
|
401 |
test(p3!=NULL);
|
sl@0
|
402 |
__UHEAP_CHECK(3);
|
sl@0
|
403 |
pC->NextLevel();
|
sl@0
|
404 |
pC->PushL(p1);
|
sl@0
|
405 |
pC->PushL(p2);
|
sl@0
|
406 |
pC->PushL(p3);
|
sl@0
|
407 |
pC->PopAll();
|
sl@0
|
408 |
__UHEAP_CHECK(3);
|
sl@0
|
409 |
User::Free(p1);
|
sl@0
|
410 |
User::Free(p2);
|
sl@0
|
411 |
User::Free(p3);
|
sl@0
|
412 |
__UHEAP_CHECK(0);
|
sl@0
|
413 |
//
|
sl@0
|
414 |
test.Next(_L("Push and pop and destroy"));
|
sl@0
|
415 |
p=User::Alloc(0x10);
|
sl@0
|
416 |
test(p!=NULL);
|
sl@0
|
417 |
__UHEAP_CHECK(1);
|
sl@0
|
418 |
pC->NextLevel();
|
sl@0
|
419 |
pC->PushL(p);
|
sl@0
|
420 |
pC->PopAndDestroy();
|
sl@0
|
421 |
__UHEAP_CHECK(0);
|
sl@0
|
422 |
pC->PopAll();
|
sl@0
|
423 |
//
|
sl@0
|
424 |
test.Next(_L("Push and pop and destroy N"));
|
sl@0
|
425 |
p1=User::Alloc(0x10);
|
sl@0
|
426 |
test(p1!=NULL);
|
sl@0
|
427 |
__UHEAP_CHECK(1);
|
sl@0
|
428 |
p2=User::Alloc(0x10);
|
sl@0
|
429 |
test(p2!=NULL);
|
sl@0
|
430 |
__UHEAP_CHECK(2);
|
sl@0
|
431 |
pC->NextLevel();
|
sl@0
|
432 |
pC->PushL(p1);
|
sl@0
|
433 |
pC->PushL(p2);
|
sl@0
|
434 |
pC->PopAndDestroy(2);
|
sl@0
|
435 |
__UHEAP_CHECK(0);
|
sl@0
|
436 |
pC->PopAll();
|
sl@0
|
437 |
__UHEAP_CHECK(0);
|
sl@0
|
438 |
//
|
sl@0
|
439 |
test.Next(_L("Push and pop and destroy all"));
|
sl@0
|
440 |
p1=User::Alloc(0x10);
|
sl@0
|
441 |
test(p1!=NULL);
|
sl@0
|
442 |
__UHEAP_CHECK(1);
|
sl@0
|
443 |
p2=User::Alloc(0x10);
|
sl@0
|
444 |
test(p2!=NULL);
|
sl@0
|
445 |
__UHEAP_CHECK(2);
|
sl@0
|
446 |
p3=User::Alloc(0x10);
|
sl@0
|
447 |
test(p3!=NULL);
|
sl@0
|
448 |
__UHEAP_CHECK(3);
|
sl@0
|
449 |
pC->NextLevel();
|
sl@0
|
450 |
pC->PushL(p1);
|
sl@0
|
451 |
pC->PushL(p2);
|
sl@0
|
452 |
pC->PushL(p3);
|
sl@0
|
453 |
pC->PopAndDestroyAll();
|
sl@0
|
454 |
__UHEAP_CHECK(0);
|
sl@0
|
455 |
//
|
sl@0
|
456 |
__UHEAP_MARKEND;
|
sl@0
|
457 |
//
|
sl@0
|
458 |
delete pC;
|
sl@0
|
459 |
__UHEAP_MARKEND;
|
sl@0
|
460 |
//
|
sl@0
|
461 |
test.End();
|
sl@0
|
462 |
}
|
sl@0
|
463 |
|
sl@0
|
464 |
LOCAL_C void testSingleLevelObjCleanup()
|
sl@0
|
465 |
//
|
sl@0
|
466 |
// Test single level object cleanup
|
sl@0
|
467 |
//
|
sl@0
|
468 |
{
|
sl@0
|
469 |
|
sl@0
|
470 |
test.Start(_L("Creating"));
|
sl@0
|
471 |
//
|
sl@0
|
472 |
__UHEAP_MARK;
|
sl@0
|
473 |
CCleanup* pC=CCleanup::New();
|
sl@0
|
474 |
test(pC!=NULL);
|
sl@0
|
475 |
//
|
sl@0
|
476 |
__UHEAP_MARK;
|
sl@0
|
477 |
//
|
sl@0
|
478 |
test.Next(_L("Push and pop"));
|
sl@0
|
479 |
CBufFlat* p=CBufFlat::NewL(8);
|
sl@0
|
480 |
test(p!=NULL);
|
sl@0
|
481 |
__UHEAP_CHECK(1);
|
sl@0
|
482 |
pC->NextLevel();
|
sl@0
|
483 |
pC->PushL(p);
|
sl@0
|
484 |
pC->Pop();
|
sl@0
|
485 |
__UHEAP_CHECK(1);
|
sl@0
|
486 |
User::Free(p);
|
sl@0
|
487 |
__UHEAP_CHECK(0);
|
sl@0
|
488 |
pC->PopAll();
|
sl@0
|
489 |
__UHEAP_CHECK(0);
|
sl@0
|
490 |
//
|
sl@0
|
491 |
test.Next(_L("Push and pop N"));
|
sl@0
|
492 |
CBufFlat* p1=CBufFlat::NewL(8);
|
sl@0
|
493 |
test(p1!=NULL);
|
sl@0
|
494 |
__UHEAP_CHECK(1);
|
sl@0
|
495 |
CBufFlat* p2=CBufFlat::NewL(8);
|
sl@0
|
496 |
test(p2!=NULL);
|
sl@0
|
497 |
__UHEAP_CHECK(2);
|
sl@0
|
498 |
pC->NextLevel();
|
sl@0
|
499 |
pC->PushL(p1);
|
sl@0
|
500 |
pC->PushL(p2);
|
sl@0
|
501 |
pC->Pop(2);
|
sl@0
|
502 |
__UHEAP_CHECK(2);
|
sl@0
|
503 |
User::Free(p1);
|
sl@0
|
504 |
User::Free(p2);
|
sl@0
|
505 |
__UHEAP_CHECK(0);
|
sl@0
|
506 |
pC->PopAll();
|
sl@0
|
507 |
__UHEAP_CHECK(0);
|
sl@0
|
508 |
//
|
sl@0
|
509 |
test.Next(_L("Push and pop all"));
|
sl@0
|
510 |
p1=CBufFlat::NewL(8);
|
sl@0
|
511 |
test(p1!=NULL);
|
sl@0
|
512 |
__UHEAP_CHECK(1);
|
sl@0
|
513 |
p2=CBufFlat::NewL(8);
|
sl@0
|
514 |
test(p2!=NULL);
|
sl@0
|
515 |
__UHEAP_CHECK(2);
|
sl@0
|
516 |
CBufFlat* p3=CBufFlat::NewL(8);
|
sl@0
|
517 |
test(p3!=NULL);
|
sl@0
|
518 |
__UHEAP_CHECK(3);
|
sl@0
|
519 |
pC->NextLevel();
|
sl@0
|
520 |
pC->PushL(p1);
|
sl@0
|
521 |
pC->PushL(p2);
|
sl@0
|
522 |
pC->PushL(p3);
|
sl@0
|
523 |
pC->PopAll();
|
sl@0
|
524 |
__UHEAP_CHECK(3);
|
sl@0
|
525 |
User::Free(p1);
|
sl@0
|
526 |
User::Free(p2);
|
sl@0
|
527 |
User::Free(p3);
|
sl@0
|
528 |
__UHEAP_CHECK(0);
|
sl@0
|
529 |
//
|
sl@0
|
530 |
test.Next(_L("Push and pop and destroy"));
|
sl@0
|
531 |
p=CBufFlat::NewL(8);
|
sl@0
|
532 |
test(p!=NULL);
|
sl@0
|
533 |
__UHEAP_CHECK(1);
|
sl@0
|
534 |
pC->NextLevel();
|
sl@0
|
535 |
pC->PushL(p);
|
sl@0
|
536 |
pC->PopAndDestroy();
|
sl@0
|
537 |
__UHEAP_CHECK(0);
|
sl@0
|
538 |
pC->PopAll();
|
sl@0
|
539 |
//
|
sl@0
|
540 |
test.Next(_L("Push and pop and destroy N"));
|
sl@0
|
541 |
p1=CBufFlat::NewL(8);
|
sl@0
|
542 |
test(p1!=NULL);
|
sl@0
|
543 |
__UHEAP_CHECK(1);
|
sl@0
|
544 |
p2=CBufFlat::NewL(8);
|
sl@0
|
545 |
test(p2!=NULL);
|
sl@0
|
546 |
__UHEAP_CHECK(2);
|
sl@0
|
547 |
pC->NextLevel();
|
sl@0
|
548 |
pC->PushL(p1);
|
sl@0
|
549 |
pC->PushL(p2);
|
sl@0
|
550 |
pC->PopAndDestroy(2);
|
sl@0
|
551 |
__UHEAP_CHECK(0);
|
sl@0
|
552 |
pC->PopAll();
|
sl@0
|
553 |
__UHEAP_CHECK(0);
|
sl@0
|
554 |
//
|
sl@0
|
555 |
test.Next(_L("Push and pop and destroy all"));
|
sl@0
|
556 |
p1=CBufFlat::NewL(8);
|
sl@0
|
557 |
test(p1!=NULL);
|
sl@0
|
558 |
__UHEAP_CHECK(1);
|
sl@0
|
559 |
p2=CBufFlat::NewL(8);
|
sl@0
|
560 |
test(p2!=NULL);
|
sl@0
|
561 |
__UHEAP_CHECK(2);
|
sl@0
|
562 |
p3=CBufFlat::NewL(8);
|
sl@0
|
563 |
test(p3!=NULL);
|
sl@0
|
564 |
__UHEAP_CHECK(3);
|
sl@0
|
565 |
pC->NextLevel();
|
sl@0
|
566 |
pC->PushL(p1);
|
sl@0
|
567 |
pC->PushL(p2);
|
sl@0
|
568 |
pC->PushL(p3);
|
sl@0
|
569 |
pC->PopAndDestroyAll();
|
sl@0
|
570 |
__UHEAP_CHECK(0);
|
sl@0
|
571 |
//
|
sl@0
|
572 |
__UHEAP_MARKEND;
|
sl@0
|
573 |
//
|
sl@0
|
574 |
delete pC;
|
sl@0
|
575 |
__UHEAP_MARKEND;
|
sl@0
|
576 |
//
|
sl@0
|
577 |
test.End();
|
sl@0
|
578 |
}
|
sl@0
|
579 |
|
sl@0
|
580 |
LOCAL_C void testSingleLevelItemCleanup()
|
sl@0
|
581 |
//
|
sl@0
|
582 |
// Test single level object cleanup
|
sl@0
|
583 |
//
|
sl@0
|
584 |
{
|
sl@0
|
585 |
|
sl@0
|
586 |
test.Start(_L("Creating"));
|
sl@0
|
587 |
//
|
sl@0
|
588 |
__UHEAP_MARK;
|
sl@0
|
589 |
CCleanup* pC=CCleanup::New();
|
sl@0
|
590 |
test(pC!=NULL);
|
sl@0
|
591 |
//
|
sl@0
|
592 |
__UHEAP_MARK;
|
sl@0
|
593 |
//
|
sl@0
|
594 |
test.Next(_L("Push and pop"));
|
sl@0
|
595 |
RItem r;
|
sl@0
|
596 |
r.Open();
|
sl@0
|
597 |
test(r.IsOpen());
|
sl@0
|
598 |
pC->NextLevel();
|
sl@0
|
599 |
pC->PushL(r);
|
sl@0
|
600 |
pC->Pop();
|
sl@0
|
601 |
test(r.IsOpen());
|
sl@0
|
602 |
r.Close();
|
sl@0
|
603 |
test(!r.IsOpen());
|
sl@0
|
604 |
pC->PopAll();
|
sl@0
|
605 |
//
|
sl@0
|
606 |
test.Next(_L("Push and pop N"));
|
sl@0
|
607 |
RItem r1;
|
sl@0
|
608 |
r1.Open();
|
sl@0
|
609 |
RItem r2;
|
sl@0
|
610 |
r2.Open();
|
sl@0
|
611 |
pC->NextLevel();
|
sl@0
|
612 |
pC->PushL(r1);
|
sl@0
|
613 |
pC->PushL(r2);
|
sl@0
|
614 |
pC->Pop(2);
|
sl@0
|
615 |
test(r1.IsOpen());
|
sl@0
|
616 |
test(r2.IsOpen());
|
sl@0
|
617 |
r1.Close();
|
sl@0
|
618 |
r2.Close();
|
sl@0
|
619 |
pC->PopAll();
|
sl@0
|
620 |
//
|
sl@0
|
621 |
test.Next(_L("Push and pop all"));
|
sl@0
|
622 |
r1.Open();
|
sl@0
|
623 |
r2.Open();
|
sl@0
|
624 |
RItem r3;
|
sl@0
|
625 |
r3.Open();
|
sl@0
|
626 |
pC->NextLevel();
|
sl@0
|
627 |
pC->PushL(r1);
|
sl@0
|
628 |
pC->PushL(r2);
|
sl@0
|
629 |
pC->PushL(r3);
|
sl@0
|
630 |
pC->PopAll();
|
sl@0
|
631 |
test(r1.IsOpen());
|
sl@0
|
632 |
test(r2.IsOpen());
|
sl@0
|
633 |
test(r3.IsOpen());
|
sl@0
|
634 |
r1.Close();
|
sl@0
|
635 |
r2.Close();
|
sl@0
|
636 |
r3.Close();
|
sl@0
|
637 |
//
|
sl@0
|
638 |
test.Next(_L("Push and pop and destroy"));
|
sl@0
|
639 |
r.Open();
|
sl@0
|
640 |
pC->NextLevel();
|
sl@0
|
641 |
pC->PushL(r);
|
sl@0
|
642 |
pC->PopAndDestroy();
|
sl@0
|
643 |
test(!r.IsOpen());
|
sl@0
|
644 |
pC->PopAll();
|
sl@0
|
645 |
//
|
sl@0
|
646 |
test.Next(_L("Push and pop and destroy N"));
|
sl@0
|
647 |
r1.Open();
|
sl@0
|
648 |
r2.Open();
|
sl@0
|
649 |
pC->NextLevel();
|
sl@0
|
650 |
pC->PushL(r1);
|
sl@0
|
651 |
pC->PushL(r2);
|
sl@0
|
652 |
pC->PopAndDestroy(2);
|
sl@0
|
653 |
test(!r1.IsOpen());
|
sl@0
|
654 |
test(!r2.IsOpen());
|
sl@0
|
655 |
pC->PopAll();
|
sl@0
|
656 |
//
|
sl@0
|
657 |
test.Next(_L("Push and pop and destroy all"));
|
sl@0
|
658 |
r1.Open();
|
sl@0
|
659 |
r2.Open();
|
sl@0
|
660 |
r3.Open();
|
sl@0
|
661 |
pC->NextLevel();
|
sl@0
|
662 |
pC->PushL(r1);
|
sl@0
|
663 |
pC->PushL(r2);
|
sl@0
|
664 |
pC->PushL(r3);
|
sl@0
|
665 |
pC->PopAndDestroyAll();
|
sl@0
|
666 |
test(!r1.IsOpen());
|
sl@0
|
667 |
test(!r2.IsOpen());
|
sl@0
|
668 |
test(!r3.IsOpen());
|
sl@0
|
669 |
//
|
sl@0
|
670 |
__UHEAP_MARKEND;
|
sl@0
|
671 |
//
|
sl@0
|
672 |
delete pC;
|
sl@0
|
673 |
__UHEAP_MARKEND;
|
sl@0
|
674 |
//
|
sl@0
|
675 |
test.End();
|
sl@0
|
676 |
}
|
sl@0
|
677 |
|
sl@0
|
678 |
LOCAL_C void testSingleLevelMixCleanup()
|
sl@0
|
679 |
//
|
sl@0
|
680 |
// Test single level mixed cleanup
|
sl@0
|
681 |
//
|
sl@0
|
682 |
{
|
sl@0
|
683 |
|
sl@0
|
684 |
test.Start(_L("Creating"));
|
sl@0
|
685 |
//
|
sl@0
|
686 |
__UHEAP_MARK;
|
sl@0
|
687 |
CCleanup* pC=CCleanup::New();
|
sl@0
|
688 |
test(pC!=NULL);
|
sl@0
|
689 |
//
|
sl@0
|
690 |
__UHEAP_MARK;
|
sl@0
|
691 |
//
|
sl@0
|
692 |
test.Next(_L("PushO PushC PushI and pop N"));
|
sl@0
|
693 |
CBufFlat* p1=CBufFlat::NewL(8);
|
sl@0
|
694 |
test(p1!=NULL);
|
sl@0
|
695 |
__UHEAP_CHECK(1);
|
sl@0
|
696 |
TAny* p2=User::Alloc(0x10);
|
sl@0
|
697 |
test(p2!=NULL);
|
sl@0
|
698 |
__UHEAP_CHECK(2);
|
sl@0
|
699 |
RItem r;
|
sl@0
|
700 |
r.Open();
|
sl@0
|
701 |
pC->NextLevel();
|
sl@0
|
702 |
pC->PushL(p1);
|
sl@0
|
703 |
pC->PushL(p2);
|
sl@0
|
704 |
pC->PushL(r);
|
sl@0
|
705 |
pC->Pop(3);
|
sl@0
|
706 |
__UHEAP_CHECK(2);
|
sl@0
|
707 |
test(r.IsOpen());
|
sl@0
|
708 |
User::Free(p1);
|
sl@0
|
709 |
User::Free(p2);
|
sl@0
|
710 |
r.Close();
|
sl@0
|
711 |
__UHEAP_CHECK(0);
|
sl@0
|
712 |
pC->PopAll();
|
sl@0
|
713 |
__UHEAP_CHECK(0);
|
sl@0
|
714 |
//
|
sl@0
|
715 |
test.Next(_L("PushO PushI PushC PushO and pop all"));
|
sl@0
|
716 |
p1=CBufFlat::NewL(8);
|
sl@0
|
717 |
test(p1!=NULL);
|
sl@0
|
718 |
__UHEAP_CHECK(1);
|
sl@0
|
719 |
r.Open();
|
sl@0
|
720 |
p2=User::Alloc(0x10);
|
sl@0
|
721 |
test(p2!=NULL);
|
sl@0
|
722 |
__UHEAP_CHECK(2);
|
sl@0
|
723 |
CBufFlat* p3=CBufFlat::NewL(8);
|
sl@0
|
724 |
test(p3!=NULL);
|
sl@0
|
725 |
__UHEAP_CHECK(3);
|
sl@0
|
726 |
pC->NextLevel();
|
sl@0
|
727 |
pC->PushL(p1);
|
sl@0
|
728 |
pC->PushL(r);
|
sl@0
|
729 |
pC->PushL(p2);
|
sl@0
|
730 |
pC->PushL(p3);
|
sl@0
|
731 |
pC->PopAll();
|
sl@0
|
732 |
__UHEAP_CHECK(3);
|
sl@0
|
733 |
test(r.IsOpen());
|
sl@0
|
734 |
User::Free(p1);
|
sl@0
|
735 |
User::Free(p2);
|
sl@0
|
736 |
User::Free(p3);
|
sl@0
|
737 |
r.Close();
|
sl@0
|
738 |
__UHEAP_CHECK(0);
|
sl@0
|
739 |
//
|
sl@0
|
740 |
test.Next(_L("PushO PushC PushI and pop and destroy N"));
|
sl@0
|
741 |
p1=CBufFlat::NewL(8);
|
sl@0
|
742 |
test(p1!=NULL);
|
sl@0
|
743 |
__UHEAP_CHECK(1);
|
sl@0
|
744 |
p2=User::Alloc(0x10);
|
sl@0
|
745 |
test(p2!=NULL);
|
sl@0
|
746 |
__UHEAP_CHECK(2);
|
sl@0
|
747 |
r.Open();
|
sl@0
|
748 |
pC->NextLevel();
|
sl@0
|
749 |
pC->PushL(p1);
|
sl@0
|
750 |
pC->PushL(p2);
|
sl@0
|
751 |
pC->PushL(r);
|
sl@0
|
752 |
pC->PopAndDestroy(3);
|
sl@0
|
753 |
test(!r.IsOpen());
|
sl@0
|
754 |
__UHEAP_CHECK(0);
|
sl@0
|
755 |
pC->PopAll();
|
sl@0
|
756 |
__UHEAP_CHECK(0);
|
sl@0
|
757 |
//
|
sl@0
|
758 |
test.Next(_L("PushO PushI PushC PushO and pop and destroy all"));
|
sl@0
|
759 |
p1=CBufFlat::NewL(8);
|
sl@0
|
760 |
test(p1!=NULL);
|
sl@0
|
761 |
__UHEAP_CHECK(1);
|
sl@0
|
762 |
r.Open();
|
sl@0
|
763 |
p2=User::Alloc(0x10);
|
sl@0
|
764 |
test(p2!=NULL);
|
sl@0
|
765 |
__UHEAP_CHECK(2);
|
sl@0
|
766 |
p3=CBufFlat::NewL(8);
|
sl@0
|
767 |
test(p3!=NULL);
|
sl@0
|
768 |
__UHEAP_CHECK(3);
|
sl@0
|
769 |
pC->NextLevel();
|
sl@0
|
770 |
pC->PushL(p1);
|
sl@0
|
771 |
pC->PushL(r);
|
sl@0
|
772 |
pC->PushL(p2);
|
sl@0
|
773 |
pC->PushL(p3);
|
sl@0
|
774 |
pC->PopAndDestroyAll();
|
sl@0
|
775 |
test(!r.IsOpen());
|
sl@0
|
776 |
__UHEAP_CHECK(0);
|
sl@0
|
777 |
//
|
sl@0
|
778 |
__UHEAP_MARKEND;
|
sl@0
|
779 |
//
|
sl@0
|
780 |
delete pC;
|
sl@0
|
781 |
__UHEAP_MARKEND;
|
sl@0
|
782 |
//
|
sl@0
|
783 |
test.End();
|
sl@0
|
784 |
}
|
sl@0
|
785 |
|
sl@0
|
786 |
LOCAL_C void testMultiLevelCellsCleanup()
|
sl@0
|
787 |
//
|
sl@0
|
788 |
// Test multi level cells cleanup
|
sl@0
|
789 |
//
|
sl@0
|
790 |
{
|
sl@0
|
791 |
|
sl@0
|
792 |
test.Start(_L("Creating"));
|
sl@0
|
793 |
//
|
sl@0
|
794 |
__UHEAP_MARK;
|
sl@0
|
795 |
CCleanup* pC=CCleanup::New();
|
sl@0
|
796 |
test(pC!=NULL);
|
sl@0
|
797 |
//
|
sl@0
|
798 |
__UHEAP_MARK;
|
sl@0
|
799 |
//
|
sl@0
|
800 |
test.Next(_L("Nest push push nest push popall popall"));
|
sl@0
|
801 |
TAny* p1=User::Alloc(0x10);
|
sl@0
|
802 |
test(p1!=NULL);
|
sl@0
|
803 |
__UHEAP_CHECK(1);
|
sl@0
|
804 |
TAny* p2=User::Alloc(0x10);
|
sl@0
|
805 |
test(p2!=NULL);
|
sl@0
|
806 |
__UHEAP_CHECK(2);
|
sl@0
|
807 |
TAny* p3=User::Alloc(0x10);
|
sl@0
|
808 |
test(p3!=NULL);
|
sl@0
|
809 |
__UHEAP_CHECK(3);
|
sl@0
|
810 |
pC->NextLevel();
|
sl@0
|
811 |
pC->PushL(p1);
|
sl@0
|
812 |
pC->PushL(p2);
|
sl@0
|
813 |
pC->NextLevel();
|
sl@0
|
814 |
pC->PushL(p3);
|
sl@0
|
815 |
pC->PopAll();
|
sl@0
|
816 |
__UHEAP_CHECK(3);
|
sl@0
|
817 |
pC->PopAll();
|
sl@0
|
818 |
__UHEAP_CHECK(3);
|
sl@0
|
819 |
User::Free(p1);
|
sl@0
|
820 |
User::Free(p2);
|
sl@0
|
821 |
User::Free(p3);
|
sl@0
|
822 |
__UHEAP_CHECK(0);
|
sl@0
|
823 |
//
|
sl@0
|
824 |
test.Next(_L("Nest push push nest push popallD popallD"));
|
sl@0
|
825 |
p1=User::Alloc(0x10);
|
sl@0
|
826 |
test(p1!=NULL);
|
sl@0
|
827 |
__UHEAP_CHECK(1);
|
sl@0
|
828 |
p2=User::Alloc(0x10);
|
sl@0
|
829 |
test(p2!=NULL);
|
sl@0
|
830 |
__UHEAP_CHECK(2);
|
sl@0
|
831 |
p3=User::Alloc(0x10);
|
sl@0
|
832 |
test(p3!=NULL);
|
sl@0
|
833 |
__UHEAP_CHECK(3);
|
sl@0
|
834 |
pC->NextLevel();
|
sl@0
|
835 |
pC->PushL(p1);
|
sl@0
|
836 |
pC->PushL(p2);
|
sl@0
|
837 |
pC->NextLevel();
|
sl@0
|
838 |
pC->PushL(p3);
|
sl@0
|
839 |
pC->PopAndDestroyAll();
|
sl@0
|
840 |
__UHEAP_CHECK(2);
|
sl@0
|
841 |
pC->PopAndDestroyAll();
|
sl@0
|
842 |
__UHEAP_CHECK(0);
|
sl@0
|
843 |
//
|
sl@0
|
844 |
__UHEAP_MARKEND;
|
sl@0
|
845 |
//
|
sl@0
|
846 |
delete pC;
|
sl@0
|
847 |
__UHEAP_MARKEND;
|
sl@0
|
848 |
//
|
sl@0
|
849 |
test.End();
|
sl@0
|
850 |
}
|
sl@0
|
851 |
|
sl@0
|
852 |
LOCAL_C void testMultiLevelObjCleanup()
|
sl@0
|
853 |
//
|
sl@0
|
854 |
// Test multi level object cleanup
|
sl@0
|
855 |
//
|
sl@0
|
856 |
{
|
sl@0
|
857 |
|
sl@0
|
858 |
test.Start(_L("Creating"));
|
sl@0
|
859 |
//
|
sl@0
|
860 |
__UHEAP_MARK;
|
sl@0
|
861 |
CCleanup* pC=CCleanup::New();
|
sl@0
|
862 |
test(pC!=NULL);
|
sl@0
|
863 |
//
|
sl@0
|
864 |
__UHEAP_MARK;
|
sl@0
|
865 |
//
|
sl@0
|
866 |
test.Next(_L("Nest push push nest push popall popall"));
|
sl@0
|
867 |
CBufFlat* p1=CBufFlat::NewL(8);
|
sl@0
|
868 |
test(p1!=NULL);
|
sl@0
|
869 |
__UHEAP_CHECK(1);
|
sl@0
|
870 |
CBufFlat* p2=CBufFlat::NewL(8);
|
sl@0
|
871 |
test(p2!=NULL);
|
sl@0
|
872 |
__UHEAP_CHECK(2);
|
sl@0
|
873 |
CBufFlat* p3=CBufFlat::NewL(8);
|
sl@0
|
874 |
test(p3!=NULL);
|
sl@0
|
875 |
__UHEAP_CHECK(3);
|
sl@0
|
876 |
pC->NextLevel();
|
sl@0
|
877 |
pC->PushL(p1);
|
sl@0
|
878 |
pC->PushL(p2);
|
sl@0
|
879 |
pC->NextLevel();
|
sl@0
|
880 |
pC->PushL(p3);
|
sl@0
|
881 |
pC->PopAll();
|
sl@0
|
882 |
__UHEAP_CHECK(3);
|
sl@0
|
883 |
pC->PopAll();
|
sl@0
|
884 |
__UHEAP_CHECK(3);
|
sl@0
|
885 |
User::Free(p1);
|
sl@0
|
886 |
User::Free(p2);
|
sl@0
|
887 |
User::Free(p3);
|
sl@0
|
888 |
__UHEAP_CHECK(0);
|
sl@0
|
889 |
//
|
sl@0
|
890 |
test.Next(_L("Nest push push nest push popallD popallD"));
|
sl@0
|
891 |
p1=CBufFlat::NewL(8);
|
sl@0
|
892 |
test(p1!=NULL);
|
sl@0
|
893 |
__UHEAP_CHECK(1);
|
sl@0
|
894 |
p2=CBufFlat::NewL(8);
|
sl@0
|
895 |
test(p2!=NULL);
|
sl@0
|
896 |
__UHEAP_CHECK(2);
|
sl@0
|
897 |
p3=CBufFlat::NewL(8);
|
sl@0
|
898 |
test(p3!=NULL);
|
sl@0
|
899 |
__UHEAP_CHECK(3);
|
sl@0
|
900 |
pC->NextLevel();
|
sl@0
|
901 |
pC->PushL(p1);
|
sl@0
|
902 |
pC->PushL(p2);
|
sl@0
|
903 |
pC->NextLevel();
|
sl@0
|
904 |
pC->PushL(p3);
|
sl@0
|
905 |
pC->PopAndDestroyAll();
|
sl@0
|
906 |
__UHEAP_CHECK(2);
|
sl@0
|
907 |
pC->PopAndDestroyAll();
|
sl@0
|
908 |
__UHEAP_CHECK(0);
|
sl@0
|
909 |
//
|
sl@0
|
910 |
__UHEAP_MARKEND;
|
sl@0
|
911 |
//
|
sl@0
|
912 |
delete pC;
|
sl@0
|
913 |
__UHEAP_MARKEND;
|
sl@0
|
914 |
//
|
sl@0
|
915 |
test.End();
|
sl@0
|
916 |
}
|
sl@0
|
917 |
|
sl@0
|
918 |
LOCAL_C void testMultiLevelItemCleanup()
|
sl@0
|
919 |
//
|
sl@0
|
920 |
// Test multi level item cleanup
|
sl@0
|
921 |
//
|
sl@0
|
922 |
{
|
sl@0
|
923 |
|
sl@0
|
924 |
test.Start(_L("Creating"));
|
sl@0
|
925 |
//
|
sl@0
|
926 |
__UHEAP_MARK;
|
sl@0
|
927 |
CCleanup* pC=CCleanup::New();
|
sl@0
|
928 |
test(pC!=NULL);
|
sl@0
|
929 |
//
|
sl@0
|
930 |
__UHEAP_MARK;
|
sl@0
|
931 |
//
|
sl@0
|
932 |
test.Next(_L("Nest push push nest push popall popall"));
|
sl@0
|
933 |
RItem r1;
|
sl@0
|
934 |
r1.Open();
|
sl@0
|
935 |
RItem r2;
|
sl@0
|
936 |
r2.Open();
|
sl@0
|
937 |
RItem r3;
|
sl@0
|
938 |
r3.Open();
|
sl@0
|
939 |
pC->NextLevel();
|
sl@0
|
940 |
pC->PushL(r1);
|
sl@0
|
941 |
pC->PushL(r2);
|
sl@0
|
942 |
pC->NextLevel();
|
sl@0
|
943 |
pC->PushL(r3);
|
sl@0
|
944 |
pC->PopAll();
|
sl@0
|
945 |
test(r1.IsOpen());
|
sl@0
|
946 |
test(r2.IsOpen());
|
sl@0
|
947 |
test(r3.IsOpen());
|
sl@0
|
948 |
pC->PopAll();
|
sl@0
|
949 |
test(r1.IsOpen());
|
sl@0
|
950 |
test(r2.IsOpen());
|
sl@0
|
951 |
test(r3.IsOpen());
|
sl@0
|
952 |
r1.Close();
|
sl@0
|
953 |
r2.Close();
|
sl@0
|
954 |
r3.Close();
|
sl@0
|
955 |
//
|
sl@0
|
956 |
test.Next(_L("Nest push push nest push popallD popallD"));
|
sl@0
|
957 |
r1.Open();
|
sl@0
|
958 |
r2.Open();
|
sl@0
|
959 |
r3.Open();
|
sl@0
|
960 |
pC->NextLevel();
|
sl@0
|
961 |
pC->PushL(r1);
|
sl@0
|
962 |
pC->PushL(r2);
|
sl@0
|
963 |
pC->NextLevel();
|
sl@0
|
964 |
pC->PushL(r3);
|
sl@0
|
965 |
pC->PopAndDestroyAll();
|
sl@0
|
966 |
test(r1.IsOpen());
|
sl@0
|
967 |
test(r2.IsOpen());
|
sl@0
|
968 |
test(!r3.IsOpen());
|
sl@0
|
969 |
pC->PopAndDestroyAll();
|
sl@0
|
970 |
test(!r1.IsOpen());
|
sl@0
|
971 |
test(!r2.IsOpen());
|
sl@0
|
972 |
test(!r3.IsOpen());
|
sl@0
|
973 |
//
|
sl@0
|
974 |
__UHEAP_MARKEND;
|
sl@0
|
975 |
//
|
sl@0
|
976 |
delete pC;
|
sl@0
|
977 |
__UHEAP_MARKEND;
|
sl@0
|
978 |
//
|
sl@0
|
979 |
test.End();
|
sl@0
|
980 |
}
|
sl@0
|
981 |
|
sl@0
|
982 |
LOCAL_C void testMultiLevelMixCleanup()
|
sl@0
|
983 |
//
|
sl@0
|
984 |
// Test multi level mixed cleanup
|
sl@0
|
985 |
//
|
sl@0
|
986 |
{
|
sl@0
|
987 |
|
sl@0
|
988 |
test.Start(_L("Creating"));
|
sl@0
|
989 |
//
|
sl@0
|
990 |
__UHEAP_MARK;
|
sl@0
|
991 |
CCleanup* pC=CCleanup::New();
|
sl@0
|
992 |
test(pC!=NULL);
|
sl@0
|
993 |
//
|
sl@0
|
994 |
__UHEAP_MARK;
|
sl@0
|
995 |
//
|
sl@0
|
996 |
test.Next(_L("Nest pushO pushC nest pushI popall popall"));
|
sl@0
|
997 |
CBufFlat* p1=CBufFlat::NewL(8);
|
sl@0
|
998 |
test(p1!=NULL);
|
sl@0
|
999 |
__UHEAP_CHECK(1);
|
sl@0
|
1000 |
TAny* p2=User::Alloc(0x10);
|
sl@0
|
1001 |
test(p2!=NULL);
|
sl@0
|
1002 |
__UHEAP_CHECK(2);
|
sl@0
|
1003 |
RItem r3;
|
sl@0
|
1004 |
r3.Open();
|
sl@0
|
1005 |
pC->NextLevel();
|
sl@0
|
1006 |
pC->PushL(p1);
|
sl@0
|
1007 |
pC->PushL(p2);
|
sl@0
|
1008 |
pC->NextLevel();
|
sl@0
|
1009 |
pC->PushL(r3);
|
sl@0
|
1010 |
pC->PopAll();
|
sl@0
|
1011 |
__UHEAP_CHECK(2);
|
sl@0
|
1012 |
test(r3.IsOpen());
|
sl@0
|
1013 |
pC->PopAll();
|
sl@0
|
1014 |
__UHEAP_CHECK(2);
|
sl@0
|
1015 |
test(r3.IsOpen());
|
sl@0
|
1016 |
User::Free(p1);
|
sl@0
|
1017 |
User::Free(p2);
|
sl@0
|
1018 |
r3.Close();
|
sl@0
|
1019 |
__UHEAP_CHECK(0);
|
sl@0
|
1020 |
//
|
sl@0
|
1021 |
test.Next(_L("Nest pushO pushC nest pushI popallD popallD"));
|
sl@0
|
1022 |
p1=CBufFlat::NewL(8);
|
sl@0
|
1023 |
test(p1!=NULL);
|
sl@0
|
1024 |
__UHEAP_CHECK(1);
|
sl@0
|
1025 |
p2=User::Alloc(0x10);
|
sl@0
|
1026 |
test(p2!=NULL);
|
sl@0
|
1027 |
__UHEAP_CHECK(2);
|
sl@0
|
1028 |
r3.Open();
|
sl@0
|
1029 |
pC->NextLevel();
|
sl@0
|
1030 |
pC->PushL(p1);
|
sl@0
|
1031 |
pC->PushL(p2);
|
sl@0
|
1032 |
pC->NextLevel();
|
sl@0
|
1033 |
pC->PushL(r3);
|
sl@0
|
1034 |
pC->PopAndDestroyAll();
|
sl@0
|
1035 |
__UHEAP_CHECK(2);
|
sl@0
|
1036 |
test(!r3.IsOpen());
|
sl@0
|
1037 |
pC->PopAndDestroyAll();
|
sl@0
|
1038 |
test(!r3.IsOpen());
|
sl@0
|
1039 |
__UHEAP_CHECK(0);
|
sl@0
|
1040 |
//
|
sl@0
|
1041 |
__UHEAP_MARKEND;
|
sl@0
|
1042 |
//
|
sl@0
|
1043 |
delete pC;
|
sl@0
|
1044 |
__UHEAP_MARKEND;
|
sl@0
|
1045 |
//
|
sl@0
|
1046 |
test.End();
|
sl@0
|
1047 |
}
|
sl@0
|
1048 |
|
sl@0
|
1049 |
LOCAL_C void testSpecialCaseCleanup()
|
sl@0
|
1050 |
//
|
sl@0
|
1051 |
// Test special case cleanup
|
sl@0
|
1052 |
//
|
sl@0
|
1053 |
{
|
sl@0
|
1054 |
|
sl@0
|
1055 |
test.Start(_L("Creating"));
|
sl@0
|
1056 |
//
|
sl@0
|
1057 |
__UHEAP_MARK;
|
sl@0
|
1058 |
CCleanup* pC=CCleanup::New();
|
sl@0
|
1059 |
test(pC!=NULL);
|
sl@0
|
1060 |
__UHEAP_CHECK(KInitialCount);
|
sl@0
|
1061 |
//
|
sl@0
|
1062 |
test.Next(_L("Nest push push push fail"));
|
sl@0
|
1063 |
CBufFlat* p1=CBufFlat::NewL(8);
|
sl@0
|
1064 |
test(p1!=NULL);
|
sl@0
|
1065 |
__UHEAP_CHECK(KInitialCount+1);
|
sl@0
|
1066 |
CBufFlat* p2=CBufFlat::NewL(8);
|
sl@0
|
1067 |
test(p2!=NULL);
|
sl@0
|
1068 |
__UHEAP_CHECK(KInitialCount+2);
|
sl@0
|
1069 |
CBufFlat* p3=CBufFlat::NewL(8);
|
sl@0
|
1070 |
test(p3!=NULL);
|
sl@0
|
1071 |
__UHEAP_CHECK(KInitialCount+3);
|
sl@0
|
1072 |
CBufFlat* p4=CBufFlat::NewL(8);
|
sl@0
|
1073 |
test(p4!=NULL);
|
sl@0
|
1074 |
__UHEAP_CHECK(KInitialCount+4);
|
sl@0
|
1075 |
CBufFlat* p5=CBufFlat::NewL(8);
|
sl@0
|
1076 |
test(p5!=NULL);
|
sl@0
|
1077 |
__UHEAP_CHECK(KInitialCount+5);
|
sl@0
|
1078 |
CBufFlat* p6=CBufFlat::NewL(8);
|
sl@0
|
1079 |
test(p6!=NULL);
|
sl@0
|
1080 |
__UHEAP_CHECK(KInitialCount+6);
|
sl@0
|
1081 |
pC->NextLevel();
|
sl@0
|
1082 |
pC->PushL(p1);
|
sl@0
|
1083 |
pC->PushL(p2);
|
sl@0
|
1084 |
pC->PushL(p3);
|
sl@0
|
1085 |
pC->PushL(p4);
|
sl@0
|
1086 |
pC->PushL(p5);
|
sl@0
|
1087 |
//
|
sl@0
|
1088 |
// The granularity is 4 so this should try and grow the array
|
sl@0
|
1089 |
// since room is always made for a free slot. We set the allocator
|
sl@0
|
1090 |
// to fail so that we can test that the free slot is re-established
|
sl@0
|
1091 |
// when we do the cleanup. This test only works in debug mode.
|
sl@0
|
1092 |
//
|
sl@0
|
1093 |
__UHEAP_FAILNEXT(1);
|
sl@0
|
1094 |
TRAPD(r,pC->PushL(p6));
|
sl@0
|
1095 |
#if defined(_DEBUG)
|
sl@0
|
1096 |
test(r==KErrNoMemory);
|
sl@0
|
1097 |
#endif
|
sl@0
|
1098 |
__UHEAP_CHECK(KInitialCount+6);
|
sl@0
|
1099 |
pC->PopAndDestroyAll();
|
sl@0
|
1100 |
__UHEAP_CHECK(KInitialCount);
|
sl@0
|
1101 |
//
|
sl@0
|
1102 |
test.Next(_L("Nest push push push push popallD"));
|
sl@0
|
1103 |
p1=CBufFlat::NewL(8);
|
sl@0
|
1104 |
test(p1!=NULL);
|
sl@0
|
1105 |
__UHEAP_CHECK(KInitialCount+1);
|
sl@0
|
1106 |
p2=CBufFlat::NewL(8);
|
sl@0
|
1107 |
test(p2!=NULL);
|
sl@0
|
1108 |
__UHEAP_CHECK(KInitialCount+2);
|
sl@0
|
1109 |
p3=CBufFlat::NewL(8);
|
sl@0
|
1110 |
test(p3!=NULL);
|
sl@0
|
1111 |
__UHEAP_CHECK(KInitialCount+3);
|
sl@0
|
1112 |
p4=CBufFlat::NewL(8);
|
sl@0
|
1113 |
test(p4!=NULL);
|
sl@0
|
1114 |
__UHEAP_CHECK(KInitialCount+4);
|
sl@0
|
1115 |
pC->NextLevel();
|
sl@0
|
1116 |
pC->PushL(p1);
|
sl@0
|
1117 |
pC->NextLevel();
|
sl@0
|
1118 |
pC->PushL(p2);
|
sl@0
|
1119 |
pC->PushL(p3);
|
sl@0
|
1120 |
pC->PushL(p4);
|
sl@0
|
1121 |
pC->PopAndDestroyAll();
|
sl@0
|
1122 |
__UHEAP_CHECK(KInitialCount+1);
|
sl@0
|
1123 |
pC->PopAndDestroyAll();
|
sl@0
|
1124 |
__UHEAP_CHECK(KInitialCount);
|
sl@0
|
1125 |
//
|
sl@0
|
1126 |
test.Next(_L("Destroy cleanup object"));
|
sl@0
|
1127 |
//
|
sl@0
|
1128 |
p1=CBufFlat::NewL(8);
|
sl@0
|
1129 |
test(p1!=NULL);
|
sl@0
|
1130 |
__UHEAP_CHECK(KInitialCount+1);
|
sl@0
|
1131 |
p2=CBufFlat::NewL(8);
|
sl@0
|
1132 |
test(p2!=NULL);
|
sl@0
|
1133 |
__UHEAP_CHECK(KInitialCount+2);
|
sl@0
|
1134 |
p3=CBufFlat::NewL(8);
|
sl@0
|
1135 |
test(p3!=NULL);
|
sl@0
|
1136 |
__UHEAP_CHECK(KInitialCount+3);
|
sl@0
|
1137 |
p4=CBufFlat::NewL(8);
|
sl@0
|
1138 |
test(p4!=NULL);
|
sl@0
|
1139 |
__UHEAP_CHECK(KInitialCount+4);
|
sl@0
|
1140 |
pC->NextLevel();
|
sl@0
|
1141 |
pC->PushL(p1);
|
sl@0
|
1142 |
pC->NextLevel();
|
sl@0
|
1143 |
pC->PushL(p2);
|
sl@0
|
1144 |
pC->PushL(p3);
|
sl@0
|
1145 |
pC->PushL(p4);
|
sl@0
|
1146 |
delete pC;
|
sl@0
|
1147 |
__UHEAP_CHECK(0);
|
sl@0
|
1148 |
//
|
sl@0
|
1149 |
__UHEAP_MARKEND;
|
sl@0
|
1150 |
//
|
sl@0
|
1151 |
test.End();
|
sl@0
|
1152 |
}
|
sl@0
|
1153 |
|
sl@0
|
1154 |
LOCAL_C void testUnTrap()
|
sl@0
|
1155 |
//
|
sl@0
|
1156 |
// Test cleanup with normal exits
|
sl@0
|
1157 |
//
|
sl@0
|
1158 |
{
|
sl@0
|
1159 |
|
sl@0
|
1160 |
test.Start(_L("Creating"));
|
sl@0
|
1161 |
//
|
sl@0
|
1162 |
__UHEAP_MARK;
|
sl@0
|
1163 |
CTrapCleanup* pT=CTrapCleanup::New();
|
sl@0
|
1164 |
test(pT!=NULL);
|
sl@0
|
1165 |
__UHEAP_CHECK(KInitialCountAll);
|
sl@0
|
1166 |
//
|
sl@0
|
1167 |
__UHEAP_MARK;
|
sl@0
|
1168 |
//
|
sl@0
|
1169 |
test.Next(_L("PushC PushO EPop cleanup empty"));
|
sl@0
|
1170 |
TRAPD(r,createL(EPop,EFalse))
|
sl@0
|
1171 |
test.Next(_L("PushC PushO EPop cleanup empty 1"));
|
sl@0
|
1172 |
test(r==KErrNone);
|
sl@0
|
1173 |
test.Next(_L("PushC PushO EPop cleanup empty 2"));
|
sl@0
|
1174 |
__UHEAP_CHECK(2);
|
sl@0
|
1175 |
test.Next(_L("PushC PushO EPop cleanup empty 3"));
|
sl@0
|
1176 |
User::Free(gP1);
|
sl@0
|
1177 |
test.Next(_L("PushC PushO EPop cleanup empty 4"));
|
sl@0
|
1178 |
delete gP2;
|
sl@0
|
1179 |
test.Next(_L("PushC PushO EPop cleanup empty 5"));
|
sl@0
|
1180 |
__UHEAP_CHECK(0);
|
sl@0
|
1181 |
//
|
sl@0
|
1182 |
test.Next(_L("PushC PushO EPopAndDestroy cleanup empty"));
|
sl@0
|
1183 |
TRAP(r,createL(EPopAndDestroy,EFalse))
|
sl@0
|
1184 |
test(r==KErrNone);
|
sl@0
|
1185 |
__UHEAP_CHECK(0);
|
sl@0
|
1186 |
//
|
sl@0
|
1187 |
/*
|
sl@0
|
1188 |
// Change of behavior for TCleanupTrapHandler means that the current
|
sl@0
|
1189 |
// cleanup stack must be empty when UnTrap is called. IE. calls to
|
sl@0
|
1190 |
// Push should be balanced with a Pop within the same function.
|
sl@0
|
1191 |
test.Next(_L("PushC PushO ENull cleanup 2 objects"));
|
sl@0
|
1192 |
TRAP(r,createL(ENull,EFalse))
|
sl@0
|
1193 |
test(r==KErrNone);
|
sl@0
|
1194 |
__UHEAP_CHECK(0);
|
sl@0
|
1195 |
*/
|
sl@0
|
1196 |
__UHEAP_MARKEND;
|
sl@0
|
1197 |
//
|
sl@0
|
1198 |
test.Next(_L("Test all LC functions"));
|
sl@0
|
1199 |
TRAP(r,createAllL(EFalse))
|
sl@0
|
1200 |
test(r==KErrNone);
|
sl@0
|
1201 |
__UHEAP_CHECK(KInitialCountAll);
|
sl@0
|
1202 |
//
|
sl@0
|
1203 |
delete pT;
|
sl@0
|
1204 |
__UHEAP_MARKEND;
|
sl@0
|
1205 |
//
|
sl@0
|
1206 |
test.End();
|
sl@0
|
1207 |
}
|
sl@0
|
1208 |
|
sl@0
|
1209 |
LOCAL_C void testLeave()
|
sl@0
|
1210 |
//
|
sl@0
|
1211 |
// Test cleanup with leave exits
|
sl@0
|
1212 |
//
|
sl@0
|
1213 |
{
|
sl@0
|
1214 |
|
sl@0
|
1215 |
test.Start(_L("Creating"));
|
sl@0
|
1216 |
//
|
sl@0
|
1217 |
__UHEAP_MARK;
|
sl@0
|
1218 |
CTrapCleanup* pT=CTrapCleanup::New();
|
sl@0
|
1219 |
test(pT!=NULL);
|
sl@0
|
1220 |
__UHEAP_CHECK(KInitialCountAll);
|
sl@0
|
1221 |
//
|
sl@0
|
1222 |
__UHEAP_MARK;
|
sl@0
|
1223 |
//
|
sl@0
|
1224 |
test.Next(_L("PushC PushO EPop cleanup empty and leave"));
|
sl@0
|
1225 |
TRAPD(r,createL(EPop,ETrue))
|
sl@0
|
1226 |
test(r==KLeaveValue);
|
sl@0
|
1227 |
__UHEAP_CHECK(2);
|
sl@0
|
1228 |
User::Free(gP1);
|
sl@0
|
1229 |
delete gP2;
|
sl@0
|
1230 |
__UHEAP_CHECK(0);
|
sl@0
|
1231 |
//
|
sl@0
|
1232 |
test.Next(_L("PushC PushO EPopAndDestroy cleanup empty and leave"));
|
sl@0
|
1233 |
TRAP(r,createL(EPopAndDestroy,ETrue))
|
sl@0
|
1234 |
test(r==KLeaveValue);
|
sl@0
|
1235 |
__UHEAP_CHECK(0);
|
sl@0
|
1236 |
//
|
sl@0
|
1237 |
test.Next(_L("PushC PushO ENull cleanup 2 objects and leave"));
|
sl@0
|
1238 |
TRAP(r,createL(ENull,ETrue))
|
sl@0
|
1239 |
test(r==KLeaveValue);
|
sl@0
|
1240 |
__UHEAP_CHECK(0);
|
sl@0
|
1241 |
__UHEAP_MARKEND;
|
sl@0
|
1242 |
//
|
sl@0
|
1243 |
test.Next(_L("Test all LC functions and leave"));
|
sl@0
|
1244 |
TRAP(r,createAllL(ETrue))
|
sl@0
|
1245 |
test(r==KLeaveValue);
|
sl@0
|
1246 |
__UHEAP_CHECK(KInitialCountAll);
|
sl@0
|
1247 |
//
|
sl@0
|
1248 |
delete pT;
|
sl@0
|
1249 |
__UHEAP_MARKEND;
|
sl@0
|
1250 |
//
|
sl@0
|
1251 |
test.End();
|
sl@0
|
1252 |
}
|
sl@0
|
1253 |
|
sl@0
|
1254 |
LOCAL_C void testMultiLeave()
|
sl@0
|
1255 |
//
|
sl@0
|
1256 |
// Test cleanup with multiple leave exits
|
sl@0
|
1257 |
//
|
sl@0
|
1258 |
{
|
sl@0
|
1259 |
|
sl@0
|
1260 |
test.Start(_L("Creating"));
|
sl@0
|
1261 |
//
|
sl@0
|
1262 |
__UHEAP_MARK;
|
sl@0
|
1263 |
CTrapCleanup* pT=CTrapCleanup::New();
|
sl@0
|
1264 |
test(pT!=NULL);
|
sl@0
|
1265 |
//
|
sl@0
|
1266 |
__UHEAP_MARK;
|
sl@0
|
1267 |
//
|
sl@0
|
1268 |
test.Next(_L("PushC PushO nest PushO cleanup leave leave"));
|
sl@0
|
1269 |
TRAPD(r,createL(EMulti,ETrue))
|
sl@0
|
1270 |
test(r==KLeaveValue);
|
sl@0
|
1271 |
__UHEAP_CHECK(0);
|
sl@0
|
1272 |
__UHEAP_MARKEND;
|
sl@0
|
1273 |
//
|
sl@0
|
1274 |
delete pT;
|
sl@0
|
1275 |
__UHEAP_MARKEND;
|
sl@0
|
1276 |
//
|
sl@0
|
1277 |
test.End();
|
sl@0
|
1278 |
}
|
sl@0
|
1279 |
|
sl@0
|
1280 |
LOCAL_C void addNullItemL()
|
sl@0
|
1281 |
{
|
sl@0
|
1282 |
CleanupStack::PushL((TAny*)0);
|
sl@0
|
1283 |
}
|
sl@0
|
1284 |
|
sl@0
|
1285 |
LOCAL_C void addCellL()
|
sl@0
|
1286 |
{
|
sl@0
|
1287 |
User::AllocLC(4);
|
sl@0
|
1288 |
}
|
sl@0
|
1289 |
|
sl@0
|
1290 |
LOCAL_C void useCleanupStackL()
|
sl@0
|
1291 |
{
|
sl@0
|
1292 |
addNullItemL();
|
sl@0
|
1293 |
addCellL();
|
sl@0
|
1294 |
CleanupStack::PopAndDestroy();
|
sl@0
|
1295 |
CleanupStack::Pop();
|
sl@0
|
1296 |
}
|
sl@0
|
1297 |
|
sl@0
|
1298 |
LOCAL_C void reentrantCleanup(TAny*)
|
sl@0
|
1299 |
//
|
sl@0
|
1300 |
// A cleanup operation which uses a trap harness and the cleanup stack
|
sl@0
|
1301 |
//
|
sl@0
|
1302 |
{
|
sl@0
|
1303 |
TRAPD(ignore,useCleanupStackL())
|
sl@0
|
1304 |
}
|
sl@0
|
1305 |
|
sl@0
|
1306 |
LOCAL_C void addReentrantItemL()
|
sl@0
|
1307 |
{
|
sl@0
|
1308 |
CleanupStack::PushL(TCleanupItem(reentrantCleanup));
|
sl@0
|
1309 |
}
|
sl@0
|
1310 |
|
sl@0
|
1311 |
LOCAL_C void addItemsL(TInt aCount)
|
sl@0
|
1312 |
//
|
sl@0
|
1313 |
// add number of reentrant items to make stack fail
|
sl@0
|
1314 |
//
|
sl@0
|
1315 |
{
|
sl@0
|
1316 |
while (--aCount>=0)
|
sl@0
|
1317 |
addReentrantItemL();
|
sl@0
|
1318 |
#if !defined(_DEBUG)
|
sl@0
|
1319 |
User::Leave(KErrNoMemory); // heap failure not available
|
sl@0
|
1320 |
#endif
|
sl@0
|
1321 |
}
|
sl@0
|
1322 |
|
sl@0
|
1323 |
const TInt KInitialStackSize=8; // from UC_CLN.CPP
|
sl@0
|
1324 |
const TInt KGrowItems=KInitialStackSize-3;
|
sl@0
|
1325 |
|
sl@0
|
1326 |
LOCAL_C void testReentrancyL()
|
sl@0
|
1327 |
//
|
sl@0
|
1328 |
// Test the Cleanup stack can go re-entrant
|
sl@0
|
1329 |
//
|
sl@0
|
1330 |
{
|
sl@0
|
1331 |
|
sl@0
|
1332 |
test.Next(_L("PopAndDestroy()"));
|
sl@0
|
1333 |
__UHEAP_MARK;
|
sl@0
|
1334 |
addNullItemL();
|
sl@0
|
1335 |
addCellL();
|
sl@0
|
1336 |
addReentrantItemL();
|
sl@0
|
1337 |
CleanupStack::PopAndDestroy(2);
|
sl@0
|
1338 |
CleanupStack::Pop();
|
sl@0
|
1339 |
__UHEAP_MARKEND;
|
sl@0
|
1340 |
//
|
sl@0
|
1341 |
test.Next(_L("cleanup after a leave"));
|
sl@0
|
1342 |
addNullItemL();
|
sl@0
|
1343 |
TRAPD(r,addReentrantItemL();User::Leave(KLeaveValue);)
|
sl@0
|
1344 |
test(r==KLeaveValue);
|
sl@0
|
1345 |
CleanupStack::Pop();
|
sl@0
|
1346 |
//
|
sl@0
|
1347 |
test.Next(_L("cleanup after stack failure"));
|
sl@0
|
1348 |
// Ensuring stack reallocate fails by placing following cell
|
sl@0
|
1349 |
TInt* forceAlloc=(TInt*)User::AllocL(4);
|
sl@0
|
1350 |
for (TInt i=0;i<KGrowItems;++i)
|
sl@0
|
1351 |
addNullItemL();
|
sl@0
|
1352 |
__UHEAP_SETFAIL(RHeap::EDeterministic,1); // fail everything
|
sl@0
|
1353 |
TRAP(r,addItemsL(1);) // will leave as stack full and cannot grow
|
sl@0
|
1354 |
test(r==KErrNoMemory);
|
sl@0
|
1355 |
__UHEAP_RESET;
|
sl@0
|
1356 |
CleanupStack::Pop(KGrowItems);
|
sl@0
|
1357 |
//
|
sl@0
|
1358 |
test.Next(_L("multiple re-entrancy & stack failure"));
|
sl@0
|
1359 |
__UHEAP_SETFAIL(RHeap::EDeterministic,1); // fail everything
|
sl@0
|
1360 |
TRAP(r,addItemsL(KGrowItems+1););
|
sl@0
|
1361 |
test(r==KErrNoMemory);
|
sl@0
|
1362 |
__UHEAP_RESET;
|
sl@0
|
1363 |
User::Free(forceAlloc);
|
sl@0
|
1364 |
}
|
sl@0
|
1365 |
|
sl@0
|
1366 |
LOCAL_C void testReentrancy()
|
sl@0
|
1367 |
//
|
sl@0
|
1368 |
// Test the Cleanup stack can go re-entrant
|
sl@0
|
1369 |
//
|
sl@0
|
1370 |
{
|
sl@0
|
1371 |
|
sl@0
|
1372 |
test.Start(_L("Creating"));
|
sl@0
|
1373 |
//
|
sl@0
|
1374 |
__UHEAP_MARK;
|
sl@0
|
1375 |
CTrapCleanup* pT=CTrapCleanup::New();
|
sl@0
|
1376 |
test(pT!=NULL);
|
sl@0
|
1377 |
//
|
sl@0
|
1378 |
TRAPD(r,testReentrancyL());
|
sl@0
|
1379 |
test(r==KErrNone);
|
sl@0
|
1380 |
//
|
sl@0
|
1381 |
delete pT;
|
sl@0
|
1382 |
__UHEAP_MARKEND;
|
sl@0
|
1383 |
//
|
sl@0
|
1384 |
test.End();
|
sl@0
|
1385 |
}
|
sl@0
|
1386 |
|
sl@0
|
1387 |
LOCAL_C void testAutoCloseL()
|
sl@0
|
1388 |
//
|
sl@0
|
1389 |
// A leaving function for testAutoClose()
|
sl@0
|
1390 |
//
|
sl@0
|
1391 |
{
|
sl@0
|
1392 |
test.Next(_L("Create a TAutoClose object"));
|
sl@0
|
1393 |
TAutoClose<RTimer> tim;
|
sl@0
|
1394 |
tim.iObj.CreateLocal();
|
sl@0
|
1395 |
test.Next(_L("Push it on the cleanup stack"));
|
sl@0
|
1396 |
tim.PushL();
|
sl@0
|
1397 |
test.Next(_L("Leave before object goes out of scope"));
|
sl@0
|
1398 |
User::Leave(KErrGeneral);
|
sl@0
|
1399 |
tim.Pop();
|
sl@0
|
1400 |
}
|
sl@0
|
1401 |
|
sl@0
|
1402 |
LOCAL_C void testAutoClose()
|
sl@0
|
1403 |
//
|
sl@0
|
1404 |
// Test the TAutoClose class
|
sl@0
|
1405 |
//
|
sl@0
|
1406 |
{
|
sl@0
|
1407 |
|
sl@0
|
1408 |
// Kill the granules
|
sl@0
|
1409 |
RTimer s[20];
|
sl@0
|
1410 |
TInt i;
|
sl@0
|
1411 |
for (i=0; i<20; i++)
|
sl@0
|
1412 |
s[i].CreateLocal();
|
sl@0
|
1413 |
for (i=0; i<20; i++)
|
sl@0
|
1414 |
s[i].Close();
|
sl@0
|
1415 |
|
sl@0
|
1416 |
__KHEAP_MARK;
|
sl@0
|
1417 |
test.Start(_L("Make a TAutoClose object"));
|
sl@0
|
1418 |
{
|
sl@0
|
1419 |
TAutoClose<RTimer> tim;
|
sl@0
|
1420 |
tim.iObj.CreateLocal();
|
sl@0
|
1421 |
|
sl@0
|
1422 |
test.Next(_L("Let it fall out of scope"));
|
sl@0
|
1423 |
}
|
sl@0
|
1424 |
test.Next(_L("Check the object has closed"));
|
sl@0
|
1425 |
__KHEAP_CHECK(0);
|
sl@0
|
1426 |
|
sl@0
|
1427 |
TRAPD(r, testAutoCloseL());
|
sl@0
|
1428 |
test.Next(_L("Check object has been closed and cleaned up after leave"));
|
sl@0
|
1429 |
__KHEAP_MARKEND;
|
sl@0
|
1430 |
test.End();
|
sl@0
|
1431 |
}
|
sl@0
|
1432 |
|
sl@0
|
1433 |
void CTest::ConstructL()
|
sl@0
|
1434 |
//
|
sl@0
|
1435 |
// Allocate a cell with CBase::new
|
sl@0
|
1436 |
//
|
sl@0
|
1437 |
{
|
sl@0
|
1438 |
|
sl@0
|
1439 |
TLex* pL=new(ELeave) TLex;
|
sl@0
|
1440 |
CleanupStack::PushL(pL);
|
sl@0
|
1441 |
}
|
sl@0
|
1442 |
|
sl@0
|
1443 |
void RItem::Cleanup(TAny* aPtr)
|
sl@0
|
1444 |
//
|
sl@0
|
1445 |
// Invoke the Close member on the RItem at aPtr
|
sl@0
|
1446 |
//
|
sl@0
|
1447 |
{
|
sl@0
|
1448 |
|
sl@0
|
1449 |
((RItem*)aPtr)->Close();
|
sl@0
|
1450 |
}
|
sl@0
|
1451 |
|
sl@0
|
1452 |
LOCAL_C TInt getStackPointer()
|
sl@0
|
1453 |
{
|
sl@0
|
1454 |
static TUint8 there;
|
sl@0
|
1455 |
TUint8 here;
|
sl@0
|
1456 |
return &here-&there;
|
sl@0
|
1457 |
}
|
sl@0
|
1458 |
LOCAL_C void sheLeavesMeL(TBool sheLeavesMeNot)
|
sl@0
|
1459 |
{
|
sl@0
|
1460 |
if (!sheLeavesMeNot)
|
sl@0
|
1461 |
User::Leave(KErrBadName); // Montague
|
sl@0
|
1462 |
}
|
sl@0
|
1463 |
|
sl@0
|
1464 |
// Variables for stack balance test need to be global or clever compiler optimisations
|
sl@0
|
1465 |
// Can interfere with stack balance calculations.
|
sl@0
|
1466 |
TInt StackBalanceLoopCounter;
|
sl@0
|
1467 |
TInt StackBalanceResult=KErrNone;
|
sl@0
|
1468 |
TInt StackBalanceBefore;
|
sl@0
|
1469 |
TInt StackBalanceAfter;
|
sl@0
|
1470 |
|
sl@0
|
1471 |
// Split into two functions because x86gcc makes a local stack optimisation for the second
|
sl@0
|
1472 |
// loop which unbalances the stack frame of the first loop.
|
sl@0
|
1473 |
LOCAL_C TInt StackBalanceNotLeaving()
|
sl@0
|
1474 |
{
|
sl@0
|
1475 |
StackBalanceBefore=getStackPointer();
|
sl@0
|
1476 |
for (StackBalanceLoopCounter=0; StackBalanceLoopCounter<20;StackBalanceLoopCounter++)
|
sl@0
|
1477 |
{
|
sl@0
|
1478 |
TRAP(StackBalanceResult,sheLeavesMeL(ETrue));
|
sl@0
|
1479 |
}
|
sl@0
|
1480 |
StackBalanceAfter=getStackPointer();
|
sl@0
|
1481 |
return StackBalanceAfter-StackBalanceBefore;
|
sl@0
|
1482 |
}
|
sl@0
|
1483 |
LOCAL_C TInt StackBalanceLeaving()
|
sl@0
|
1484 |
{
|
sl@0
|
1485 |
StackBalanceBefore=getStackPointer();
|
sl@0
|
1486 |
for (StackBalanceLoopCounter=0; StackBalanceLoopCounter<20;StackBalanceLoopCounter++)
|
sl@0
|
1487 |
{
|
sl@0
|
1488 |
TRAP(StackBalanceResult,sheLeavesMeL(EFalse));
|
sl@0
|
1489 |
}
|
sl@0
|
1490 |
StackBalanceAfter=getStackPointer();
|
sl@0
|
1491 |
return StackBalanceAfter-StackBalanceBefore;
|
sl@0
|
1492 |
}
|
sl@0
|
1493 |
|
sl@0
|
1494 |
LOCAL_C void testStackBalance()
|
sl@0
|
1495 |
//
|
sl@0
|
1496 |
// Ensure that we get the stack properly balanced
|
sl@0
|
1497 |
//
|
sl@0
|
1498 |
{
|
sl@0
|
1499 |
// Not leaving case
|
sl@0
|
1500 |
test.Start(_L("Stack balance without Leaving"));
|
sl@0
|
1501 |
TInt balance = StackBalanceNotLeaving();
|
sl@0
|
1502 |
test.Printf(_L("Stack balance: %d bytes\n"), balance);
|
sl@0
|
1503 |
test(balance == 0);
|
sl@0
|
1504 |
|
sl@0
|
1505 |
// Leaving case
|
sl@0
|
1506 |
test.Next(_L("Stack balance after Leave"));
|
sl@0
|
1507 |
balance = StackBalanceLeaving();
|
sl@0
|
1508 |
test.Printf(_L("Stack balance: %d bytes\n"), balance);
|
sl@0
|
1509 |
test(balance == 0);
|
sl@0
|
1510 |
test.End();
|
sl@0
|
1511 |
}
|
sl@0
|
1512 |
|
sl@0
|
1513 |
void Inc(TAny* aPtr)
|
sl@0
|
1514 |
{
|
sl@0
|
1515 |
++(*(TInt*)aPtr);
|
sl@0
|
1516 |
}
|
sl@0
|
1517 |
|
sl@0
|
1518 |
void testTrapIgnore()
|
sl@0
|
1519 |
{
|
sl@0
|
1520 |
test.Start(_L("Create cleanup"));
|
sl@0
|
1521 |
CCleanup* pC=CCleanup::New();
|
sl@0
|
1522 |
test(pC!=NULL);
|
sl@0
|
1523 |
TInt count = 0;
|
sl@0
|
1524 |
|
sl@0
|
1525 |
test.Next(_L("TRAP_IGNORE with no leave"));
|
sl@0
|
1526 |
TRAP_IGNORE(
|
sl@0
|
1527 |
CleanupStack::PushL(TCleanupItem(Inc,&count));
|
sl@0
|
1528 |
CleanupStack::Pop();
|
sl@0
|
1529 |
);
|
sl@0
|
1530 |
test(count==0);
|
sl@0
|
1531 |
|
sl@0
|
1532 |
test.Next(_L("TRAP_IGNORE with leave"));
|
sl@0
|
1533 |
TRAP_IGNORE(
|
sl@0
|
1534 |
CleanupStack::PushL(TCleanupItem(Inc,&count));
|
sl@0
|
1535 |
User::Leave(KErrGeneral);
|
sl@0
|
1536 |
);
|
sl@0
|
1537 |
test(count==1);
|
sl@0
|
1538 |
|
sl@0
|
1539 |
delete pC;
|
sl@0
|
1540 |
test.End();
|
sl@0
|
1541 |
}
|
sl@0
|
1542 |
|
sl@0
|
1543 |
GLDEF_C TInt E32Main()
|
sl@0
|
1544 |
{
|
sl@0
|
1545 |
test.Title();
|
sl@0
|
1546 |
|
sl@0
|
1547 |
test.Start(_L("Test destructor causing stack reallocation"));
|
sl@0
|
1548 |
testDestructorStackReallocation();
|
sl@0
|
1549 |
|
sl@0
|
1550 |
test.Next(_L("CCleanup single level tests just alloc cells"));
|
sl@0
|
1551 |
testSingleLevelCellsCleanup();
|
sl@0
|
1552 |
|
sl@0
|
1553 |
test.Next(_L("CCleanup single level tests just objects"));
|
sl@0
|
1554 |
testSingleLevelObjCleanup();
|
sl@0
|
1555 |
|
sl@0
|
1556 |
test.Next(_L("CCleanup single level tests just items"));
|
sl@0
|
1557 |
testSingleLevelItemCleanup();
|
sl@0
|
1558 |
|
sl@0
|
1559 |
test.Next(_L("CCleanup single level tests mixed"));
|
sl@0
|
1560 |
testSingleLevelMixCleanup();
|
sl@0
|
1561 |
|
sl@0
|
1562 |
test.Next(_L("CCleanup multi level tests just alloc cells"));
|
sl@0
|
1563 |
testMultiLevelCellsCleanup();
|
sl@0
|
1564 |
|
sl@0
|
1565 |
test.Next(_L("CCleanup multi level tests just objects"));
|
sl@0
|
1566 |
testMultiLevelObjCleanup();
|
sl@0
|
1567 |
|
sl@0
|
1568 |
test.Next(_L("CCleanup multi level tests just items"));
|
sl@0
|
1569 |
testMultiLevelItemCleanup();
|
sl@0
|
1570 |
|
sl@0
|
1571 |
test.Next(_L("CCleanup multi level tests mixed"));
|
sl@0
|
1572 |
testMultiLevelMixCleanup();
|
sl@0
|
1573 |
|
sl@0
|
1574 |
test.Next(_L("CCleanup special case test"));
|
sl@0
|
1575 |
testSpecialCaseCleanup();
|
sl@0
|
1576 |
|
sl@0
|
1577 |
test.Next(_L("Install trap handler"));
|
sl@0
|
1578 |
CTrapCleanup* pT=CTrapCleanup::New();
|
sl@0
|
1579 |
test(pT!=NULL);
|
sl@0
|
1580 |
|
sl@0
|
1581 |
test.Next(_L("Untrap handling tests"));
|
sl@0
|
1582 |
testUnTrap();
|
sl@0
|
1583 |
|
sl@0
|
1584 |
test.Next(_L("Leave handling tests"));
|
sl@0
|
1585 |
testLeave();
|
sl@0
|
1586 |
|
sl@0
|
1587 |
test.Next(_L("Multi level leave handling tests"));
|
sl@0
|
1588 |
testMultiLeave();
|
sl@0
|
1589 |
|
sl@0
|
1590 |
test.Next(_L("Test TAutoClose"));
|
sl@0
|
1591 |
testAutoClose();
|
sl@0
|
1592 |
|
sl@0
|
1593 |
test.Next(_L("Test Re-entrancy of cleanup stack"));
|
sl@0
|
1594 |
testReentrancy();
|
sl@0
|
1595 |
|
sl@0
|
1596 |
test.Next(_L("Test stack safety of TRAP and Leave"));
|
sl@0
|
1597 |
testStackBalance();
|
sl@0
|
1598 |
|
sl@0
|
1599 |
test.Next(_L("Test TRAP_IGNORE"));
|
sl@0
|
1600 |
testTrapIgnore();
|
sl@0
|
1601 |
|
sl@0
|
1602 |
test.End();
|
sl@0
|
1603 |
return(0);
|
sl@0
|
1604 |
}
|
sl@0
|
1605 |
|