|
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 "Test11AsyncAlloc.h" |
|
31 |
|
32 #include <comms-infras/commsbufpond.h> |
|
33 // constructor |
|
34 CTest11AsyncAlloc::CTest11AsyncAlloc() |
|
35 { |
|
36 SetTestStepName(_L("MBufMgrTest11"));// Store the name of this test case |
|
37 } |
|
38 |
|
39 // destructor |
|
40 CTest11AsyncAlloc::~CTest11AsyncAlloc() |
|
41 { |
|
42 } |
|
43 |
|
44 class CMBufAsyncReq : public CActive |
|
45 { |
|
46 public: |
|
47 CMBufAsyncReq(RMBufAsyncRequest &aMBufAsyncReq) |
|
48 :CActive(EPriorityStandard) |
|
49 ,iMBufAsyncReq(aMBufAsyncReq) { } |
|
50 |
|
51 ~CMBufAsyncReq() { Cancel(); } |
|
52 |
|
53 void RunL() { CActiveScheduler::Stop(); } |
|
54 |
|
55 void DoCancel() { iMBufAsyncReq.Cancel(); } |
|
56 |
|
57 TInt DoAsyncRequest(RMBufChain& aChain, TInt aSize) |
|
58 { |
|
59 iMBufAsyncReq.Alloc(aChain, aSize, iStatus); |
|
60 SetActive(); |
|
61 CActiveScheduler::Start(); |
|
62 return iStatus.Int(); |
|
63 } |
|
64 private: |
|
65 RMBufAsyncRequest& iMBufAsyncReq; |
|
66 }; |
|
67 |
|
68 enum TVerdict CTest11AsyncAlloc::doTestStepL(void) |
|
69 { |
|
70 SetTestStepResult(EFail); |
|
71 //-------------- substep 1 -------------------- |
|
72 INFO_PRINTF1(_L(" 01 Create CMBufManager and install active scheduler:")); |
|
73 CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler ); |
|
74 CActiveScheduler::Install(iActSch); |
|
75 CreateInstanceMBufMgrL(KMBufDefaultHeapSize); |
|
76 CleanupClosePushL(iBufPond); |
|
77 |
|
78 //-------------- substep 2 -------------------- |
|
79 INFO_PRINTF1(_L(" 02 Create and install active object that will do async. alloc on request:")); |
|
80 RMBufAsyncRequest async; |
|
81 CMBufAsyncReq* testAsync; |
|
82 CleanupStack::PushL(testAsync = new(ELeave) CMBufAsyncReq(async)); |
|
83 CActiveScheduler::Add(testAsync); |
|
84 |
|
85 //-------------- substep 3 -------------------- |
|
86 INFO_PRINTF1(_L(" 03 Async. alloce 5000-bytes long RMBuf:")); |
|
87 RMBufChain aChain; |
|
88 TInt ret = testAsync->DoAsyncRequest(aChain, 5000); |
|
89 if (ret != KErrNone) |
|
90 { |
|
91 INFO_PRINTF1(_L("Error: Couldn't allocate Chain:")); |
|
92 User::Leave(EFail); |
|
93 } |
|
94 |
|
95 //-------------- substep 4 -------------------- |
|
96 INFO_PRINTF1(_L(" 04 Free the chain. Clean up stack:")); |
|
97 aChain.Free(); |
|
98 CleanupStack::PopAndDestroy(testAsync); |
|
99 CleanupStack::PopAndDestroy(); |
|
100 CActiveScheduler::Install(NULL); |
|
101 CleanupStack::PopAndDestroy(iActSch); |
|
102 SetTestStepResult(EPass); |
|
103 |
|
104 return TestStepResult(); |
|
105 } |