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