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