|
1 // Copyright (c) 2008-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 // Test19Prepend.cpp |
|
15 // Contains MBufMgr Test Step 19 for Prepend() methods |
|
16 // |
|
17 // |
|
18 |
|
19 // EPOC includes |
|
20 #include <e32base.h> |
|
21 |
|
22 // Test system includes |
|
23 //#ifdef SYMBIAN_OLD_EXPORT_LOCATION |
|
24 //#include "networking/log.h" |
|
25 //#include "networking/teststep.h" |
|
26 //#else |
|
27 //#include <networking/log.h> |
|
28 //#include <networking/teststep.h> |
|
29 //#endif |
|
30 |
|
31 #include "TestStepCTMbufmgr.h" |
|
32 |
|
33 #include "Test19Prepend.h" |
|
34 |
|
35 // constructor |
|
36 CTest19Prepend::CTest19Prepend() |
|
37 { |
|
38 SetTestStepName( _L("MBufMgrTest19") ); // Store the name of this test case |
|
39 } |
|
40 |
|
41 // destructor |
|
42 CTest19Prepend::~CTest19Prepend() |
|
43 { |
|
44 } |
|
45 |
|
46 // |
|
47 enum TVerdict CTest19Prepend::doTestStepL(void) |
|
48 { |
|
49 //-------------- substep 1 -------------------- |
|
50 INFO_PRINTF1(_L(" 01 Create CMBufManager and install active scheduler:")); |
|
51 CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler ); |
|
52 CActiveScheduler::Install(iActSch); |
|
53 |
|
54 RArray<TCommsBufPoolCreateInfo> poolInfoArray; |
|
55 TCommsBufPoolCreateInfo createInfo; |
|
56 createInfo.iBufSize = 128; |
|
57 createInfo.iInitialBufs = 128; |
|
58 createInfo.iGrowByBufs = 64; |
|
59 createInfo.iMinFreeBufs = 40; |
|
60 createInfo.iCeiling = (KMBufDefaultHeapSize / 2)/createInfo.iBufSize; |
|
61 poolInfoArray.AppendL(createInfo); |
|
62 CreateInstanceMBufMgrL(poolInfoArray); |
|
63 CleanupClosePushL(iBufPond); |
|
64 poolInfoArray.Close (); |
|
65 |
|
66 TBool firstFail = EFalse; |
|
67 TBool secondFail = EFalse; |
|
68 TInt ret; |
|
69 RMBufChain chain,chain2; |
|
70 |
|
71 //-------------- substep 2 -------------------- |
|
72 INFO_PRINTF1(_L(" 02 Prepend 20 bytes to an empty chain")); |
|
73 ret = chain.Prepend(20); |
|
74 if (ret != KErrNone) |
|
75 { |
|
76 INFO_PRINTF1(_L("Error: Couldn't prepend:")); |
|
77 firstFail = ETrue; |
|
78 } |
|
79 else |
|
80 { |
|
81 if(chain.NumBufs() != 1) |
|
82 { |
|
83 INFO_PRINTF1(_L("Error: Wrong number of MBufs allocated:")); |
|
84 secondFail = ETrue; |
|
85 } |
|
86 if(chain.Length() != 20) |
|
87 { |
|
88 INFO_PRINTF1(_L("Error: Wrong number of bytes prepended:")); |
|
89 secondFail = ETrue; |
|
90 } |
|
91 //-------------- substep 3 -------------------- |
|
92 INFO_PRINTF1(_L(" 03 Deallocating RMBufChain")); |
|
93 chain.Free(); |
|
94 } |
|
95 |
|
96 //-------------- substep 4 -------------------- |
|
97 INFO_PRINTF1(_L(" 04 Prepend 200 bytes to an empty chain")); |
|
98 ret = chain.Prepend(200); |
|
99 if (ret != KErrNone) |
|
100 { |
|
101 INFO_PRINTF1(_L("Error: Couldn't prepend:")); |
|
102 firstFail = ETrue; |
|
103 } |
|
104 else |
|
105 { |
|
106 if(chain.NumBufs() != 2) |
|
107 { |
|
108 INFO_PRINTF1(_L("Error: Wrong number of MBufs allocated:")); |
|
109 secondFail = ETrue; |
|
110 } |
|
111 if(chain.Length() != 200) |
|
112 { |
|
113 INFO_PRINTF1(_L("Error: Wrong number of bytes prepended:")); |
|
114 secondFail = ETrue; |
|
115 } |
|
116 //-------------- substep 6 -------------------- |
|
117 INFO_PRINTF1(_L(" 05 Deallocating RMBufChain")); |
|
118 chain.Free(); |
|
119 } |
|
120 //-------------- substep 6 -------------------- |
|
121 INFO_PRINTF1(_L(" 06 Prepend 20 bytes to an existing chain")); |
|
122 ret = chain.Alloc(20); |
|
123 if (ret != KErrNone) |
|
124 { |
|
125 INFO_PRINTF1(_L("Error: Couldn't allocate initial chain:")); |
|
126 firstFail = ETrue; |
|
127 } |
|
128 else |
|
129 { |
|
130 ret = chain.Prepend(20); |
|
131 if (ret != KErrNone) |
|
132 { |
|
133 INFO_PRINTF1(_L("Error: Couldn't prepend:")); |
|
134 firstFail = ETrue; |
|
135 } |
|
136 else |
|
137 { |
|
138 if(chain.NumBufs() != 2) |
|
139 { |
|
140 INFO_PRINTF1(_L("Error: Wrong number of MBufs allocated:")); |
|
141 secondFail = ETrue; |
|
142 } |
|
143 if(chain.Length() != 40) |
|
144 { |
|
145 INFO_PRINTF1(_L("Error: Wrong number of bytes:")); |
|
146 secondFail = ETrue; |
|
147 } |
|
148 //-------------- substep 7 -------------------- |
|
149 INFO_PRINTF1(_L(" 07 Deallocating RMBufChain")); |
|
150 chain.Free(); |
|
151 } |
|
152 } |
|
153 //-------------- substep 8 -------------------- |
|
154 INFO_PRINTF1(_L(" 08 Prepend 200 bytes to an existing chain")); |
|
155 ret = chain.Alloc(20); |
|
156 if (ret != KErrNone) |
|
157 { |
|
158 INFO_PRINTF1(_L("Error: Couldn't allocate initial chain:")); |
|
159 firstFail = ETrue; |
|
160 } |
|
161 else |
|
162 { |
|
163 ret = chain.Prepend(200); |
|
164 if (ret != KErrNone) |
|
165 { |
|
166 INFO_PRINTF1(_L("Error: Couldn't prepend:")); |
|
167 firstFail = ETrue; |
|
168 } |
|
169 else |
|
170 { |
|
171 if(chain.NumBufs() != 3) |
|
172 { |
|
173 INFO_PRINTF1(_L("Error: Wrong number of MBufs allocated:")); |
|
174 secondFail = ETrue; |
|
175 } |
|
176 if(chain.Length() != 220) |
|
177 { |
|
178 INFO_PRINTF1(_L("Error: Wrong number of bytes:")); |
|
179 secondFail = ETrue; |
|
180 } |
|
181 //-------------- substep 7 -------------------- |
|
182 INFO_PRINTF1(_L(" 09 Deallocating RMBufChain")); |
|
183 chain.Free(); |
|
184 } |
|
185 } |
|
186 //-------------- substep 10 -------------------- |
|
187 INFO_PRINTF1(_L(" 10 Prepend one chain onto another chain")); |
|
188 ret = chain.Alloc(20); |
|
189 if (ret != KErrNone) |
|
190 { |
|
191 INFO_PRINTF1(_L("Error: Couldn't allocate initial chain:")); |
|
192 firstFail = ETrue; |
|
193 } |
|
194 else |
|
195 { |
|
196 ret = chain2.Alloc(200); |
|
197 if (ret != KErrNone) |
|
198 { |
|
199 INFO_PRINTF1(_L("Error: Couldn't allocate second chain:")); |
|
200 firstFail = ETrue; |
|
201 } |
|
202 else |
|
203 { |
|
204 RMBuf* first = chain2.First(); |
|
205 chain.Prepend(chain2); |
|
206 |
|
207 if(chain.NumBufs() != 3) |
|
208 { |
|
209 INFO_PRINTF1(_L("Error: Wrong number of MBufs in the chain:")); |
|
210 secondFail = ETrue; |
|
211 } |
|
212 if(chain.Length() != 220) |
|
213 { |
|
214 INFO_PRINTF1(_L("Error: Wrong number of bytes:")); |
|
215 secondFail = ETrue; |
|
216 } |
|
217 if(chain.First() != first) |
|
218 { |
|
219 INFO_PRINTF1(_L("Error: chain2 not prepended correctly:")); |
|
220 secondFail = ETrue; |
|
221 } |
|
222 //-------------- substep 11 -------------------- |
|
223 INFO_PRINTF1(_L(" 11 Deallocating RMBufChains")); |
|
224 chain2.Free(); |
|
225 } |
|
226 chain.Free(); |
|
227 } |
|
228 //-------------- substep 12 -------------------- |
|
229 INFO_PRINTF1(_L(" 12 Clean up stack:")); |
|
230 CleanupStack::PopAndDestroy(); // pond |
|
231 CActiveScheduler::Install(NULL); |
|
232 CleanupStack::PopAndDestroy(iActSch); |
|
233 |
|
234 if (firstFail || secondFail) |
|
235 { |
|
236 SetTestStepResult(EFail); |
|
237 } |
|
238 else |
|
239 { |
|
240 SetTestStepResult(EPass); |
|
241 } |
|
242 return TestStepResult(); |
|
243 } |