|
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 06 for SplitL method |
|
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 "Test06SplitL.h" |
|
32 #include <comms-infras/commsbufpond.h> |
|
33 // constructor |
|
34 CTest06Split::CTest06Split() |
|
35 { |
|
36 SetTestStepName(_L("MBufMgrTest06"));// Store the name of this test case |
|
37 } |
|
38 |
|
39 // destructor |
|
40 CTest06Split::~CTest06Split() |
|
41 { |
|
42 } |
|
43 |
|
44 // |
|
45 enum TVerdict CTest06Split::doTestStepL(void) |
|
46 { |
|
47 SetTestStepResult(EFail); |
|
48 //-------------- substep 0 -------------------- |
|
49 INFO_PRINTF1(_L(" 00 Read parameters from the script:")); |
|
50 TInt aOffset;// Will contain the position in chain where split action will be done |
|
51 TInt aLength;// Will contain the length of desc & chains in the test |
|
52 TInt bRet = GetIntFromConfig(_L("MBufMgrTest06"), _L("Length"), aLength); |
|
53 if (!bRet) |
|
54 { |
|
55 SetTestStepResult(EFail); |
|
56 |
|
57 return TestStepResult(); |
|
58 } |
|
59 bRet = GetIntFromConfig(_L("MBufMgrTest06"), _L("Offset"), aOffset); |
|
60 if (!bRet) |
|
61 { |
|
62 SetTestStepResult(EFail); |
|
63 |
|
64 return TestStepResult(); |
|
65 } |
|
66 TBool forceSmallBuf = EFalse; |
|
67 bRet = GetIntFromConfig(_L("MBufMgrTest06"), _L("ForceSmallBuf"), forceSmallBuf); |
|
68 INFO_PRINTF2(_L(" ------- Chain & Desc LENGTH = %d --"), aLength); |
|
69 INFO_PRINTF2(_L(" ------- OFFSET where to Split = %d --"), aOffset); |
|
70 if ( (aLength > 1000) ||(aLength <0) || |
|
71 (aOffset > aLength) || (aOffset <0) ) |
|
72 { |
|
73 INFO_PRINTF1(_L("ERROR: Wrong input parameter(s)")); |
|
74 SetTestStepResult(EFail); |
|
75 |
|
76 return TestStepResult(); |
|
77 } |
|
78 |
|
79 //-------------- substep 1 -------------------- |
|
80 INFO_PRINTF1(_L(" 01 Creating CMBufManager and installing active scheduler:")); |
|
81 CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler ); |
|
82 CActiveScheduler::Install(iActSch); |
|
83 |
|
84 enum { KBigBuf = 256, KSmallBuf = 128 }; |
|
85 if(forceSmallBuf) |
|
86 { |
|
87 RArray<TCommsBufPoolCreateInfo> createInfoArray; |
|
88 |
|
89 TCommsBufPoolCreateInfo createInfo; |
|
90 createInfo.iBufSize = KSmallBuf; |
|
91 createInfo.iInitialBufs = 128; |
|
92 createInfo.iGrowByBufs = 64; |
|
93 createInfo.iMinFreeBufs = 40; |
|
94 createInfo.iCeiling = 410; |
|
95 createInfoArray.AppendL(createInfo); |
|
96 |
|
97 createInfo.iBufSize = KBigBuf; |
|
98 createInfo.iInitialBufs = 3; |
|
99 createInfo.iGrowByBufs = 1; |
|
100 createInfo.iMinFreeBufs = 1; |
|
101 createInfo.iCeiling = 3; |
|
102 createInfoArray.AppendL(createInfo); |
|
103 |
|
104 CreateInstanceMBufMgrL(createInfoArray); |
|
105 |
|
106 createInfoArray.Close(); |
|
107 } |
|
108 else |
|
109 { |
|
110 CreateInstanceMBufMgrL(KMBufDefaultHeapSize); |
|
111 } |
|
112 |
|
113 CleanupClosePushL(iBufPond); |
|
114 |
|
115 //-------------- substep 2 -------------------- |
|
116 INFO_PRINTF1(_L(" 02 Allocating two descriptors (Des1 & Des2):")); |
|
117 TBuf8<1000> *aDes1, *aDes2; |
|
118 CleanupStack::PushL( aDes1 = new(ELeave) TBuf8<1000> ); |
|
119 CleanupStack::PushL( aDes2 = new(ELeave) TBuf8<1000> ); |
|
120 aDes1->SetLength(aLength); |
|
121 aDes2->SetLength(aLength); |
|
122 |
|
123 //-------------- substep 3 -------------------- |
|
124 INFO_PRINTF1(_L(" 03 Fill in Des1 with a pattern:")); |
|
125 StripeDes(*aDes1, 0, aLength, '@', 'Z'); |
|
126 |
|
127 //-------------- substep 4 -------------------- |
|
128 INFO_PRINTF1(_L(" 04 Fill in Des2 with zeros:")); |
|
129 StripeDes(*aDes1, 0, aLength, 0, 0); |
|
130 |
|
131 //-------------- substep 5 -------------------- |
|
132 INFO_PRINTF1(_L(" 05 Allocate Chain1:")); |
|
133 RMBufChain aChain1; |
|
134 TRAPD(ret,aChain1.AllocL(aLength)); |
|
135 if (ret != KErrNone) |
|
136 { |
|
137 INFO_PRINTF1(_L("Error: Couldn't allocate Chain1:")); |
|
138 User::Leave(EFail); |
|
139 } |
|
140 |
|
141 if(forceSmallBuf) |
|
142 { |
|
143 for(RMBuf* buf = aChain1.First(); buf; buf = buf->Next()) |
|
144 { |
|
145 if(buf->Size() != KBigBuf) |
|
146 { |
|
147 INFO_PRINTF3(_L("-- initial chain should be composed of %d buf, found %d buf"), KBigBuf, buf->Size()); |
|
148 User::Leave(EFail); |
|
149 } |
|
150 } |
|
151 } |
|
152 |
|
153 //-------------- substep 6 -------------------- |
|
154 INFO_PRINTF1(_L(" 06 Copy in Des1 into Chain1:")); |
|
155 aChain1.CopyIn(*aDes1); |
|
156 |
|
157 //-------------- substep 7 -------------------- |
|
158 INFO_PRINTF1(_L(" 07 Split Chain1. The 2nd part goes to Chain2:")); |
|
159 RMBufChain aChain2; |
|
160 TRAP(ret,aChain1.SplitL(aOffset, aChain2)); |
|
161 if (ret != KErrNone) |
|
162 { |
|
163 INFO_PRINTF1(_L("Error: Couldn't Split")); |
|
164 aChain1.Free(); |
|
165 aChain2.Free(); |
|
166 User::Leave(EFail); |
|
167 } |
|
168 |
|
169 //-------------- substep 8 -------------------- |
|
170 INFO_PRINTF1(_L(" 08 Check the length of the chains. They should be OFFSET and (LENGTH - OFFSET):")); |
|
171 TInt temp; |
|
172 if ( (temp = aChain1.Length()) != aOffset) |
|
173 { |
|
174 INFO_PRINTF3(_L("Error: Chain1 length is %d instead of %d"), temp, aOffset); |
|
175 aChain1.Free(); |
|
176 aChain2.Free(); |
|
177 User::Leave(EFail); |
|
178 } |
|
179 |
|
180 if ( (temp = aChain2.Length()) != aLength - aOffset) |
|
181 { |
|
182 INFO_PRINTF3(_L("Error: Chain2 length is %d instead of %d"), temp, aLength - aOffset); |
|
183 aChain1.Free(); |
|
184 aChain2.Free(); |
|
185 User::Leave(EFail); |
|
186 } |
|
187 |
|
188 if(forceSmallBuf) |
|
189 { |
|
190 if(!aChain2.First() || aChain2.First()->Size() != KSmallBuf || |
|
191 !aChain2.First()->Next() || aChain2.First()->Next()->Size() != KSmallBuf) |
|
192 { |
|
193 INFO_PRINTF2(_L("-- split chain should start with two %d buf"), KSmallBuf); |
|
194 User::Leave(EFail); |
|
195 } |
|
196 } |
|
197 |
|
198 //-------------- substep 9 -------------------- |
|
199 INFO_PRINTF1(_L(" 09 Copy out Chain1 into Des2:")); |
|
200 aChain1.CopyOut(*aDes2); |
|
201 |
|
202 //-------------- substep 10 -------------------- |
|
203 INFO_PRINTF1(_L(" 10 Check the length of Des2. It should be OFFSET ")); |
|
204 if ( (temp = aDes2->Length()) != aOffset) |
|
205 { |
|
206 INFO_PRINTF3(_L("Error: Des2 length is %d instead of %d"), temp, aOffset); |
|
207 aChain1.Free(); |
|
208 aChain2.Free(); |
|
209 User::Leave(EFail); |
|
210 } |
|
211 |
|
212 //-------------- substep 11 -------------------- |
|
213 INFO_PRINTF1(_L(" 11 Set the length of Des2 to LENGTH value")); |
|
214 aDes2->SetLength(aLength); |
|
215 |
|
216 //-------------- substep 12 -------------------- |
|
217 INFO_PRINTF1(_L(" 12 Copy out the whole Chain2 into Des2 at offset = OFFSET")); |
|
218 TPtr8 dest((TUint8*)aDes2->Ptr() + aOffset, aLength-aOffset, aLength - aOffset); |
|
219 aChain2.CopyOut(dest); |
|
220 |
|
221 //-------------- substep 13 -------------------- |
|
222 INFO_PRINTF1(_L(" 13 Compare the content of Des1 & Des2:")); |
|
223 if(aDes1->Compare(*aDes2)) |
|
224 { |
|
225 aChain1.Free(); |
|
226 aChain2.Free(); |
|
227 INFO_PRINTF1(_L("Error: The content is not the same")); |
|
228 User::Leave(EFail); |
|
229 } |
|
230 |
|
231 //-------------- substep 14 -------------------- |
|
232 INFO_PRINTF1(_L(" 14 Free the chains. Clean up stack:")); |
|
233 aChain1.Free(); |
|
234 aChain2.Free(); |
|
235 CleanupStack::PopAndDestroy(aDes2); |
|
236 CleanupStack::PopAndDestroy(aDes1); |
|
237 CleanupStack::PopAndDestroy(); // iBufPond |
|
238 CActiveScheduler::Install(NULL); |
|
239 CleanupStack::PopAndDestroy(iActSch); |
|
240 SetTestStepResult(EPass); |
|
241 |
|
242 return TestStepResult(); |
|
243 } |