|
1 // Copyright (c) 2002-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 // Contains MBufMgr Test Step 11 Async. Allocate |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 |
|
21 // Test system includes |
|
22 #ifdef SYMBIAN_OLD_EXPORT_LOCATION |
|
23 #include "networking/log.h" |
|
24 #include "networking/teststep.h" |
|
25 #else |
|
26 #include <networking/log.h> |
|
27 #include <networking/teststep.h> |
|
28 #endif |
|
29 #include "TestStepCTMbufmgr.h" |
|
30 #include "TestSuiteCTMbufmgr.h" |
|
31 #include "Test11AsyncAlloc.h" |
|
32 |
|
33 #include <comms-infras/commsbufpond.h> |
|
34 // constructor |
|
35 CTest11AsyncAlloc::CTest11AsyncAlloc() |
|
36 { |
|
37 iTestStepName = _L("MBufMgrTest11");// Store the name of this test case |
|
38 } |
|
39 |
|
40 // destructor |
|
41 CTest11AsyncAlloc::~CTest11AsyncAlloc() |
|
42 { |
|
43 } |
|
44 |
|
45 class CMBufAsyncReq : public CActive |
|
46 { |
|
47 public: |
|
48 CMBufAsyncReq(RMBufAsyncRequest &aMBufAsyncReq) |
|
49 :CActive(EPriorityStandard) |
|
50 ,iMBufAsyncReq(aMBufAsyncReq) { } |
|
51 |
|
52 ~CMBufAsyncReq() { Cancel(); } |
|
53 |
|
54 void RunL() { CActiveScheduler::Stop(); } |
|
55 |
|
56 void DoCancel() { iMBufAsyncReq.Cancel(); } |
|
57 |
|
58 TInt DoAsyncRequest(RMBufChain& aChain, TInt aSize) |
|
59 { |
|
60 iMBufAsyncReq.Alloc(aChain, aSize, iStatus); |
|
61 SetActive(); |
|
62 CActiveScheduler::Start(); |
|
63 return iStatus.Int(); |
|
64 } |
|
65 private: |
|
66 RMBufAsyncRequest& iMBufAsyncReq; |
|
67 }; |
|
68 |
|
69 enum TVerdict CTest11AsyncAlloc::doTestStepL(void) |
|
70 { |
|
71 __UHEAP_MARK; |
|
72 |
|
73 #ifdef __CFLOG_ACTIVE |
|
74 __CFLOG_CREATEL; |
|
75 __CFLOG_OPEN; |
|
76 #endif |
|
77 |
|
78 //-------------- substep 1 -------------------- |
|
79 Log(_L(" 01 Create CMBufManager and install active scheduler:")); |
|
80 CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler ); |
|
81 CActiveScheduler::Install(iActSch); |
|
82 CreateInstanceMBufMgrL(KMBufDefaultHeapSize); |
|
83 CleanupClosePushL(iBufPond); |
|
84 |
|
85 //-------------- substep 2 -------------------- |
|
86 Log(_L(" 02 Create and install active object that will do async. alloc on request:")); |
|
87 RMBufAsyncRequest async; |
|
88 CMBufAsyncReq* testAsync; |
|
89 CleanupStack::PushL(testAsync = new(ELeave) CMBufAsyncReq(async)); |
|
90 CActiveScheduler::Add(testAsync); |
|
91 |
|
92 //-------------- substep 3 -------------------- |
|
93 Log(_L(" 03 Async. alloce 5000-bytes long RMBuf:")); |
|
94 RMBufChain aChain; |
|
95 TInt ret = testAsync->DoAsyncRequest(aChain, 5000); |
|
96 if (ret != KErrNone) |
|
97 { |
|
98 Log(_L("Error: Couldn't allocate Chain:")); |
|
99 |
|
100 #ifdef __CFLOG_ACTIVE |
|
101 __CFLOG_CLOSE; |
|
102 __CFLOG_DELETE; |
|
103 #endif |
|
104 User::Leave(EFail); |
|
105 } |
|
106 |
|
107 //-------------- substep 4 -------------------- |
|
108 Log(_L(" 04 Free the chain. Clean up stack:")); |
|
109 aChain.Free(); |
|
110 CleanupStack::PopAndDestroy(testAsync); |
|
111 CleanupStack::PopAndDestroy(); |
|
112 CActiveScheduler::Install(NULL); |
|
113 CleanupStack::PopAndDestroy(iActSch); |
|
114 |
|
115 #ifdef __CFLOG_ACTIVE |
|
116 __CFLOG_CLOSE; |
|
117 __CFLOG_DELETE; |
|
118 #endif |
|
119 __UHEAP_MARKEND; |
|
120 return EPass; |
|
121 } |