|
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 10 for CopyL() methods |
|
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 |
|
31 #include "Test10CopyL.h" |
|
32 #include <comms-infras/commsbufpond.h> |
|
33 |
|
34 // constructor |
|
35 CTest10Copy::CTest10Copy() |
|
36 { |
|
37 SetTestStepName(_L("MBufMgrTest10"));// Store the name of this test case |
|
38 } |
|
39 |
|
40 // destructor |
|
41 CTest10Copy::~CTest10Copy() |
|
42 { |
|
43 } |
|
44 |
|
45 // |
|
46 enum TVerdict CTest10Copy::doTestStepL(void) |
|
47 { |
|
48 SetTestStepResult(EFail); |
|
49 //-------------- substep 0 -------------------- |
|
50 INFO_PRINTF1(_L(" 00 Read parameters from the script:")); |
|
51 CScriptInput* aInput;//It will hold input |
|
52 CleanupStack::PushL( aInput= new (ELeave) CScriptInput ); |
|
53 TInt i; |
|
54 TBuf<20> aBuf; |
|
55 TInt bRet; |
|
56 aInput->aBufs=0; |
|
57 aInput->aChainLen=0; |
|
58 for (i = 0;i<50;i++) |
|
59 { |
|
60 aBuf.Format(_L("Length%02d"),i+1); |
|
61 bRet = GetIntFromConfig(_L("MBufMgrTest10"), aBuf, aInput->aBuf[i].aLength); |
|
62 |
|
63 if (!bRet) return TestStepResult(); |
|
64 if (aInput->aBuf[i].aLength == -1) break; |
|
65 |
|
66 aBuf.Format(_L("Offset%02d"),i+1); |
|
67 bRet = GetIntFromConfig(_L("MBufMgrTest10"), aBuf, aInput->aBuf[i].aOffset); |
|
68 |
|
69 if (!bRet) return TestStepResult(); |
|
70 |
|
71 aInput->aBufs++; |
|
72 aInput->aChainLen += aInput->aBuf[i].aLength; |
|
73 } |
|
74 bRet = GetIntFromConfig(_L("MBufMgrTest10"),_L("CopyOffset") , aInput->aCopyOffset); |
|
75 bRet = GetIntFromConfig(_L("MBufMgrTest10"),_L("CopyLen") , aInput->aCopyLen); |
|
76 |
|
77 INFO_PRINTF1(_L(" The following has been read from the script:")); |
|
78 INFO_PRINTF3(_L(" Number of RMBufs in chain = %2d, with overall length CHAINLEN=%d"),aInput->aBufs,aInput->aChainLen); |
|
79 |
|
80 for (i = 0; i < aInput->aBufs ; i++ ) |
|
81 { |
|
82 INFO_PRINTF4(_L(" RMBuf #%2d: Offset=%3d Length=%3d"), |
|
83 i+1, aInput->aBuf[i].aOffset, aInput->aBuf[i].aLength); |
|
84 } |
|
85 INFO_PRINTF3(_L(" CopyL() parameters: COPYOFFSET=%d COPYLEN=%d"),aInput->aCopyOffset, aInput->aCopyLen); |
|
86 |
|
87 //-------------- substep 1 -------------------- |
|
88 INFO_PRINTF1(_L(" 01 Create CMBufManager and install active scheduler:")); |
|
89 CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler ); |
|
90 CActiveScheduler::Install(iActSch); |
|
91 CreateInstanceMBufMgrL(KMBufDefaultHeapSize); |
|
92 CleanupClosePushL(iBufPond); |
|
93 |
|
94 //-------------- substep 2 -------------------- |
|
95 INFO_PRINTF1(_L(" 02 Allocate two descriptors (Des1 & Des2) of length = Min(COPYLEN, CHAINLEN - COPYOFFSET):")); |
|
96 TBuf8<5000> *aDes1, *aDes2; |
|
97 TInt aDesLength; |
|
98 CleanupStack::PushL( aDes1 = new(ELeave) TBuf8<5000> ); |
|
99 CleanupStack::PushL( aDes2 = new(ELeave) TBuf8<5000> ); |
|
100 aDesLength = Min(aInput->aCopyLen, aInput->aChainLen-aInput->aCopyOffset); |
|
101 aDes1->SetLength(aDesLength); |
|
102 aDes2->SetLength(aDesLength); |
|
103 |
|
104 //-------------- substep 3 -------------------- |
|
105 INFO_PRINTF1(_L(" 03 Fill in Des1 with a pattern:")); |
|
106 StripeDes(*aDes1, 0, aDesLength, '@', 'Z'); |
|
107 |
|
108 //-------------- substep 4 -------------------- |
|
109 INFO_PRINTF1(_L(" 04 Create Chain1 containing RMBufs as specified in the script:")); |
|
110 RMBufChain aChain1; |
|
111 RMBuf *buf=0; |
|
112 for (i = aInput->aBufs-1; i >= 0 ; i-- ) |
|
113 { |
|
114 buf = static_cast<RMBuf*>(iBufPond.Alloc(KMBufSmallSize,0, KMaxTInt)); |
|
115 if (buf==NULL) |
|
116 { |
|
117 INFO_PRINTF1(_L("Error:Could not allocate buffer")); |
|
118 aChain1.Free(); |
|
119 User::Leave(EFail); |
|
120 } |
|
121 buf->SetData(aInput->aBuf[i].aOffset,aInput->aBuf[i].aLength); |
|
122 aChain1.Prepend(buf); |
|
123 } |
|
124 |
|
125 //-------------- substep 5 -------------------- |
|
126 INFO_PRINTF1(_L(" 05 Copy in Des1 into Chain1 at offset=COPYOFFSET:")); |
|
127 TBuf8<5000> *aDesTemp; |
|
128 CleanupStack::PushL( aDesTemp = new(ELeave) TBuf8<5000> ); |
|
129 aDesTemp->SetLength(aDesLength+aInput->aCopyOffset); |
|
130 Mem::Copy ((TAny*)(aDesTemp->Ptr()+aInput->aCopyOffset), aDes1->Ptr(), aDesLength); |
|
131 aChain1.CopyIn(*aDesTemp); |
|
132 CleanupStack::PopAndDestroy(aDesTemp); |
|
133 |
|
134 //-------------- substep 6 -------------------- |
|
135 INFO_PRINTF1(_L(" 06 Copy Chain1 into Chain2:")); |
|
136 RMBufChain aChain2; |
|
137 aChain1.CopyL(aChain2,aInput->aCopyOffset, aInput->aCopyLen); |
|
138 |
|
139 //-------------- substep 7 -------------------- |
|
140 INFO_PRINTF1(_L(" 07 Copy out Chain2 into Des2:")); |
|
141 aChain2.CopyOut(*aDes2); |
|
142 |
|
143 //-------------- substep 8 -------------------- |
|
144 INFO_PRINTF1(_L(" 08 Compare the content of Des1 & Des2:")); |
|
145 if(aDes1->Compare(*aDes2)) |
|
146 { |
|
147 INFO_PRINTF1(_L("Error: The content is not the same")); |
|
148 aChain1.Free(); |
|
149 aChain2.Free(); |
|
150 User::Leave(EFail); |
|
151 } |
|
152 |
|
153 //-------------- substep 9 -------------------- |
|
154 INFO_PRINTF1(_L(" 09 Free chain. Clean up stack:")); |
|
155 aChain1.Free(); |
|
156 aChain2.Free(); |
|
157 CleanupStack::PopAndDestroy(aDes2); |
|
158 CleanupStack::PopAndDestroy(aDes1); |
|
159 CleanupStack::PopAndDestroy(); |
|
160 CActiveScheduler::Install(NULL); |
|
161 CleanupStack::PopAndDestroy(iActSch); |
|
162 CleanupStack::PopAndDestroy(aInput); |
|
163 SetTestStepResult(EPass); |
|
164 |
|
165 return TestStepResult(); |
|
166 } |