|
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 09 for Align() 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 "Test09Align.h" |
|
33 #include <comms-infras/commsbufpond.h> |
|
34 |
|
35 // constructor |
|
36 CTest09Align::CTest09Align() |
|
37 { |
|
38 iTestStepName = _L("MBufMgrTest09");// Store the name of this test case |
|
39 } |
|
40 |
|
41 // destructor |
|
42 CTest09Align::~CTest09Align() |
|
43 { |
|
44 } |
|
45 |
|
46 // |
|
47 enum TVerdict CTest09Align::doTestStepL(void) |
|
48 { |
|
49 __UHEAP_MARK; |
|
50 |
|
51 //-------------- substep 0 -------------------- |
|
52 Log(_L(" 00 Read parameters from the script:")); |
|
53 CScriptInput* aInput; |
|
54 CleanupStack::PushL( aInput= new (ELeave) CScriptInput ); |
|
55 TInt i; |
|
56 TBuf<20> aBuf; |
|
57 TInt bRet; |
|
58 aInput->aBufsBefore=0; |
|
59 for (i = 0;i<50;i++) |
|
60 { |
|
61 aBuf.Format(_L("Length%02d"),i+1); |
|
62 bRet = GetIntFromConfig(_L("MBufMgrTest09"), aBuf, aInput->aBuf[i].aLength); |
|
63 if (!bRet) |
|
64 { |
|
65 return EFail; |
|
66 } |
|
67 if (aInput->aBuf[i].aLength == -1) break; |
|
68 |
|
69 aBuf.Format(_L("Offset%02d"),i+1); |
|
70 bRet = GetIntFromConfig(_L("MBufMgrTest09"), aBuf, aInput->aBuf[i].aOffset); |
|
71 if (!bRet) |
|
72 { |
|
73 return EFail; |
|
74 } |
|
75 aInput->aBufsBefore++; |
|
76 } |
|
77 bRet = GetIntFromConfig(_L("MBufMgrTest09"),_L("BuffsAfter") , aInput->aBufsAfter); |
|
78 |
|
79 Log(_L(" The following has been read from the script:")); |
|
80 Log(_L(" Number of RMBufs in chain before align= %2d"),aInput->aBufsBefore); |
|
81 Log(_L(" Number of RMBufs in chain after align = %2d"),aInput->aBufsAfter); |
|
82 |
|
83 for (i = 0; i < aInput->aBufsBefore ; i++ ) |
|
84 { |
|
85 Log(_L(" Chain #%2d: Offset=%3d Length=%3d"), |
|
86 i+1, aInput->aBuf[i].aOffset, aInput->aBuf[i].aLength); |
|
87 } |
|
88 |
|
89 #ifdef __CFLOG_ACTIVE |
|
90 __CFLOG_CREATEL; |
|
91 __CFLOG_OPEN; |
|
92 #endif |
|
93 |
|
94 //-------------- substep 1 -------------------- |
|
95 Log(_L(" 01 Create CMBufManager and install active scheduler:")); |
|
96 CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler ); |
|
97 CActiveScheduler::Install(iActSch); |
|
98 |
|
99 CreateInstanceMBufMgrL(KMBufDefaultHeapSize); |
|
100 CleanupClosePushL(iBufPond); |
|
101 |
|
102 //-------------- substep 2 -------------------- |
|
103 Log(_L(" 02 Create TestStr structure and fill it with data:")); |
|
104 CTestStr* aTestStr1; |
|
105 CleanupStack::PushL( aTestStr1 = new (ELeave) CTestStr ); |
|
106 |
|
107 aTestStr1->iSrcAddr = 0x01234567; |
|
108 aTestStr1->iDstAddr = 0x89abcdef; |
|
109 aTestStr1->iSrcPort = 0x0246; |
|
110 aTestStr1->iDstPort = 0x8ace; |
|
111 aTestStr1->iLength = sizeof(CTestStr); |
|
112 aTestStr1->iOptions = 0x1359; |
|
113 StripeMem(aTestStr1->iData, 0, sizeof(aTestStr1->iData), '@', 'Z'); |
|
114 |
|
115 //-------------- substep 3 -------------------- |
|
116 Log(_L(" 03 Create a chain containing RMBufs as specified in the script:")); |
|
117 RMBufChain aChain; |
|
118 RMBuf *buf=0; |
|
119 for (i = aInput->aBufsBefore-1; i >= 0 ; i-- ) |
|
120 { |
|
121 buf = static_cast<RMBuf*>(iBufPond.Alloc(KMBufSmallSize, 0, KMaxTInt)); |
|
122 if (buf==NULL) |
|
123 { |
|
124 Log(_L("Error:Could not allocate buffer")); |
|
125 aChain.Free(); |
|
126 |
|
127 #ifdef __CFLOG_ACTIVE |
|
128 __CFLOG_CLOSE; |
|
129 __CFLOG_DELETE; |
|
130 #endif |
|
131 User::Leave(EFail); |
|
132 } |
|
133 buf->SetData(aInput->aBuf[i].aOffset,aInput->aBuf[i].aLength); |
|
134 aChain.Prepend(buf); |
|
135 } |
|
136 |
|
137 //-------------- substep 4 -------------------- |
|
138 Log(_L(" 04 Copy in TestStr into Chain:")); |
|
139 aChain.CopyIn(TPtrC8((TUint8 *)aTestStr1, sizeof(CTestStr))); |
|
140 |
|
141 CTestStr* aTestStr3 = (CTestStr*)(aChain.First()->Ptr()); |
|
142 |
|
143 //-------------- substep 5 -------------------- |
|
144 Log(_L(" 05 Allign Chain for the size of TestStr:")); |
|
145 aChain.Align(sizeof(CTestStr)); |
|
146 |
|
147 //-------------- substep 6 -------------------- |
|
148 Log(_L(" 06 Check the number of RMBufs in chain after allign:")); |
|
149 if (aChain.NumBufs() != aInput->aBufsAfter) |
|
150 { |
|
151 Log(_L("ERROR: Number of bufs is %d instead of %d"),aChain.NumBufs(),aInput->aBufsAfter); |
|
152 aChain.Free(); |
|
153 |
|
154 #ifdef __CFLOG_ACTIVE |
|
155 __CFLOG_CLOSE; |
|
156 __CFLOG_DELETE; |
|
157 #endif |
|
158 User::Leave(EFail); |
|
159 } |
|
160 |
|
161 //-------------- substep 7 -------------------- |
|
162 Log(_L(" 07 Create the pointer of TestStr type and point to the 1st RMBuf in chain:")); |
|
163 CTestStr* aTestStr2 = (CTestStr*)(aChain.First()->Ptr()); |
|
164 |
|
165 //-------------- substep 8 -------------------- |
|
166 Log(_L(" 08 Compare TestStr1 and TestData2. They should be the same:")); |
|
167 if ( (aTestStr1->iSrcAddr != aTestStr2->iSrcAddr) || |
|
168 (aTestStr1->iDstAddr != aTestStr2->iDstAddr) || |
|
169 (aTestStr1->iSrcPort != aTestStr2->iSrcPort) || |
|
170 (aTestStr1->iDstPort != aTestStr2->iDstPort) || |
|
171 (aTestStr1->iLength != aTestStr2->iLength) || |
|
172 (aTestStr1->iOptions != aTestStr2->iOptions) || |
|
173 (Mem::Compare(aTestStr1->iData, sizeof(aTestStr1->iData), |
|
174 aTestStr2->iData, sizeof(aTestStr2->iData))) ) |
|
175 { |
|
176 Log(_L("ERROR: They are not the same")); |
|
177 aChain.Free(); |
|
178 |
|
179 #ifdef __CFLOG_ACTIVE |
|
180 __CFLOG_CLOSE; |
|
181 __CFLOG_DELETE; |
|
182 #endif |
|
183 User::Leave(EFail); |
|
184 } |
|
185 |
|
186 //-------------- substep 9 -------------------- |
|
187 Log(_L(" 09 Free the chain. Clean up stack:")); |
|
188 aChain.Free(); |
|
189 CleanupStack::PopAndDestroy(aTestStr1); |
|
190 CleanupStack::PopAndDestroy(); |
|
191 CActiveScheduler::Install(NULL); |
|
192 CleanupStack::PopAndDestroy(iActSch); |
|
193 CleanupStack::PopAndDestroy(aInput); |
|
194 |
|
195 #ifdef __CFLOG_ACTIVE |
|
196 __CFLOG_CLOSE; |
|
197 __CFLOG_DELETE; |
|
198 #endif |
|
199 __UHEAP_MARKEND; |
|
200 return EPass; |
|
201 } |