|
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 07 for TrimStart() 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 "Test07TrimStart.h" |
|
32 #include <comms-infras/commsbufpond.h> |
|
33 // constructor |
|
34 CTest07TrimStart::CTest07TrimStart() |
|
35 { |
|
36 SetTestStepName(_L("MBufMgrTest07"));// Store the name of this test case |
|
37 } |
|
38 |
|
39 // destructor |
|
40 CTest07TrimStart::~CTest07TrimStart() |
|
41 { |
|
42 } |
|
43 |
|
44 // |
|
45 enum TVerdict CTest07TrimStart::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("MBufMgrTest07"), _L("Length"), aLength); |
|
53 if (!bRet) |
|
54 { |
|
55 SetTestStepResult(EFail); |
|
56 |
|
57 return TestStepResult(); |
|
58 } |
|
59 bRet = GetIntFromConfig(_L("MBufMgrTest07"), _L("Offset"), aOffset); |
|
60 if (!bRet) |
|
61 { |
|
62 SetTestStepResult(EFail); |
|
63 |
|
64 return TestStepResult(); |
|
65 } |
|
66 INFO_PRINTF2(_L(" ------- Chain LENGTH = %d --"), aLength); |
|
67 INFO_PRINTF2(_L(" ------- OFFSET where to TrimStart = %d --"), aOffset); |
|
68 if ( (aLength > 1000) ||(aLength <0) || |
|
69 (aOffset > aLength) || (aOffset <0) ) |
|
70 { |
|
71 INFO_PRINTF1(_L("ERROR: Wrong input parameter(s)")); |
|
72 SetTestStepResult(EFail); |
|
73 |
|
74 return TestStepResult(); |
|
75 } |
|
76 |
|
77 //-------------- substep 1 -------------------- |
|
78 INFO_PRINTF1(_L(" 01 Creating CMBufManager and installing active scheduler:")); |
|
79 CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler ); |
|
80 CActiveScheduler::Install(iActSch); |
|
81 CreateInstanceMBufMgrL(KMBufDefaultHeapSize); |
|
82 CleanupClosePushL(iBufPond); |
|
83 |
|
84 //-------------- substep 2 -------------------- |
|
85 INFO_PRINTF1(_L(" 02 Allocate two desc. of Length:LENGTH(Des1) & (LENGTH-OFFSET)(Des2):")); |
|
86 TBuf8<1000> *aDes1, *aDes2; |
|
87 CleanupStack::PushL( aDes1 = new(ELeave) TBuf8<1000> ); |
|
88 CleanupStack::PushL( aDes2 = new(ELeave) TBuf8<1000> ); |
|
89 aDes1->SetLength(aLength); |
|
90 aDes2->SetLength(aLength-aOffset); |
|
91 |
|
92 //-------------- substep 3 -------------------- |
|
93 INFO_PRINTF1(_L(" 03 Fill in Des1 with a pattern:")); |
|
94 StripeDes(*aDes1, 0, aLength, '@', 'Z'); |
|
95 |
|
96 //-------------- substep 4 -------------------- |
|
97 INFO_PRINTF1(_L(" 04 Fill in Des2 with zeros:")); |
|
98 StripeDes(*aDes2, 0, aLength-aOffset, 0, 0); |
|
99 |
|
100 //-------------- substep 5 -------------------- |
|
101 INFO_PRINTF1(_L(" 05 Allocate Chain:")); |
|
102 RMBufChain aChain; |
|
103 TRAPD(ret,aChain.AllocL(aLength)); |
|
104 if (ret != KErrNone) |
|
105 { |
|
106 INFO_PRINTF1(_L("Error: Couldn't allocate RMBuf:")); |
|
107 User::Leave(EFail); |
|
108 } |
|
109 |
|
110 //-------------- substep 6 -------------------- |
|
111 INFO_PRINTF1(_L(" 06 Copy in Des1 into Chain1:")); |
|
112 aChain.CopyIn(*aDes1); |
|
113 |
|
114 //-------------- substep 7 -------------------- |
|
115 INFO_PRINTF1(_L(" 07 TrimStart Chain1 at OFFSET position (actually, remove the 1st OFFSET bytes:")); |
|
116 aChain.TrimStart(aOffset); |
|
117 |
|
118 //-------------- substep 8 -------------------- |
|
119 INFO_PRINTF1(_L(" 08 Check the length of the chain. It should be (LENGTH - OFFSET):")); |
|
120 TInt temp; |
|
121 if ( (temp = aChain.Length()) != aLength-aOffset) |
|
122 { |
|
123 INFO_PRINTF3(_L("Error: Chain length is %d instead of %d"), temp, aLength-aOffset); |
|
124 aChain.Free(); |
|
125 User::Leave(EFail); |
|
126 } |
|
127 |
|
128 //-------------- substep 09 -------------------- |
|
129 INFO_PRINTF1(_L(" 09 Copy the last (LENGTH-OFFSET) bytes of Des1 into the start of Des1:")); |
|
130 (void)Mem::Copy((TUint8 *)aDes1->Ptr(), (TUint8 *)aDes1->Ptr()+aOffset, aLength-aOffset); |
|
131 |
|
132 //-------------- substep 10 -------------------- |
|
133 INFO_PRINTF1(_L(" 10 Set the length of Des1 to value LENGTH-OFFSET")); |
|
134 aDes1->SetLength(aLength-aOffset); |
|
135 |
|
136 //-------------- substep 11 -------------------- |
|
137 INFO_PRINTF1(_L(" 11 Copy out Chain into Des2:")); |
|
138 aChain.CopyOut(*aDes2); |
|
139 |
|
140 //-------------- substep 12 -------------------- |
|
141 INFO_PRINTF1(_L(" 12 Compare the content of Des1 & Des2:")); |
|
142 if(aDes1->Compare(*aDes2)) |
|
143 { |
|
144 aChain.Free(); |
|
145 INFO_PRINTF1(_L("Error: The content is not the same")); |
|
146 User::Leave(EFail); |
|
147 } |
|
148 |
|
149 //-------------- substep 13 -------------------- |
|
150 INFO_PRINTF1(_L(" 13 Free the chains. Clean up stack:")); |
|
151 aChain.Free(); |
|
152 CleanupStack::PopAndDestroy(aDes2); |
|
153 CleanupStack::PopAndDestroy(aDes1); |
|
154 CleanupStack::PopAndDestroy(); |
|
155 CActiveScheduler::Install(NULL); |
|
156 CleanupStack::PopAndDestroy(iActSch); |
|
157 SetTestStepResult(EPass); |
|
158 |
|
159 return TestStepResult(); |
|
160 } |