|
1 // Copyright (c) 2008-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 "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 // @file |
|
15 // @internalComponent |
|
16 // |
|
17 // |
|
18 |
|
19 |
|
20 #include <e32base.h> |
|
21 #include <rmemchunk.h> |
|
22 |
|
23 #include "test03allocerror.h" |
|
24 |
|
25 TVerdict CTest03AllocError::doTestStepL(void) |
|
26 { |
|
27 __UHEAP_MARK; |
|
28 |
|
29 TVerdict verdict ( EFail ); |
|
30 |
|
31 // -------------- step 1: Create heap with 15K |
|
32 CleanupStack::PushL ( CreateChunkMgrL ( 65536 ) ); |
|
33 RMemoryAllocator allocator ( iChkMgr ); |
|
34 // -------------- step 2: Allocate 42000 bytes long memchunks |
|
35 RMemChunk memChunks[14]; |
|
36 TInt ret; |
|
37 for ( TInt i = 0; i < sizeof ( memChunks ) / sizeof ( memChunks[0] ); i++ ) |
|
38 { |
|
39 ret = memChunks[i].Alloc ( 3000, allocator ); |
|
40 if ( ret != KErrNone ) |
|
41 { |
|
42 User::Leave(EFail); |
|
43 } |
|
44 } |
|
45 // -------------- step 3: Allocate 16384-bytes long memchunk |
|
46 RMemChunk chunk; |
|
47 ret = chunk.Alloc ( 16384, allocator ); |
|
48 if ( ret != KErrNone ) |
|
49 { |
|
50 if ( ret == KErrNoMemory ) |
|
51 verdict = EPass; |
|
52 else |
|
53 { |
|
54 verdict = EFail; |
|
55 } |
|
56 } |
|
57 // -------------- step 4: Cleanup |
|
58 for ( TInt i = 0; i < sizeof ( memChunks ) / sizeof ( memChunks[0] ); i++ ) |
|
59 { |
|
60 memChunks[i].Free (); |
|
61 } |
|
62 chunk.Free (); |
|
63 |
|
64 CleanupStack::PopAndDestroy ( iChkMgr ); |
|
65 |
|
66 __UHEAP_MARKEND; |
|
67 return verdict; |
|
68 } |