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