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