|
1 // Copyright (c) 2007-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 the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Contains implementation of CTestHttpBufferSizeStep class |
|
15 // @internalAll |
|
16 // |
|
17 // |
|
18 |
|
19 // System Include |
|
20 // for StartC32() |
|
21 #include <c32comm.h> |
|
22 #include <e32base.h> |
|
23 #include <http.h> |
|
24 |
|
25 // User Include |
|
26 #include "testhttpbuffersizestep.h" |
|
27 |
|
28 // File system root |
|
29 _LIT(KFileSystemRoot,"C:\\"); |
|
30 |
|
31 // Standard headers used by default |
|
32 _LIT8(KUserAgent, "TestHttpBufferSize"); |
|
33 _LIT8(KAccept, "*/*"); |
|
34 |
|
35 |
|
36 /** |
|
37 Constructor: Sets the test step name. |
|
38 @internalTechnology |
|
39 @test |
|
40 */ |
|
41 CTestHttpBufferSizeStep::CTestHttpBufferSizeStep() |
|
42 { |
|
43 //Call base class method to set human readable name for test step |
|
44 SetTestStepName(KTestHttpBufferSizeStep); |
|
45 //Set the iChunkSize to the default buffer size of 6144 Bytes |
|
46 iChunkSize = 1024; |
|
47 } |
|
48 |
|
49 |
|
50 /** |
|
51 Destructor: Closes the iFileServ. |
|
52 @internalTechnology |
|
53 @test |
|
54 */ |
|
55 CTestHttpBufferSizeStep::~CTestHttpBufferSizeStep() |
|
56 { |
|
57 } |
|
58 |
|
59 |
|
60 /** |
|
61 Sets the proxy and HttpDataOptimiser implemetation to session |
|
62 based on the patameter values in ini file and calls InvokeHttpMethodL() |
|
63 @internalTechnology |
|
64 @test |
|
65 @param None |
|
66 @return None |
|
67 */ |
|
68 void CTestHttpBufferSizeStep::StartClientL() |
|
69 { |
|
70 TPtrC uri; |
|
71 |
|
72 if (!GetStringFromConfig(ConfigSection(), KIniUri, uri)) |
|
73 { |
|
74 ERR_PRINTF2(_L("Problem in reading values from ini. \ |
|
75 \nExpected fields are: \n%S\n" |
|
76 ),&KIniUri); |
|
77 SetTestStepResult(EFail); |
|
78 return; |
|
79 } |
|
80 |
|
81 THTTPHdrVal hdrVal ( 1024 ); |
|
82 RHTTPConnectionInfo httpConnInfo = iSess.ConnectionInfo(); |
|
83 httpConnInfo.SetPropertyL ( iSess.StringPool().StringF(HTTP::ERecvBufferSize,RHTTPSession::GetTable()), hdrVal ); |
|
84 INFO_PRINTF1(_L("Receive buffer size has been set to 1024 bytes\n")); |
|
85 |
|
86 RStringPool strP = iSess.StringPool(); |
|
87 RStringF method; |
|
88 |
|
89 // method |
|
90 method = strP.StringF(HTTP::EGET,RHTTPSession::GetTable()); |
|
91 TBuf8<256> url8; |
|
92 url8.Copy(uri); |
|
93 TRAPD(err,InvokeHttpMethodL(url8, method)); |
|
94 if (err != KErrNone) |
|
95 { |
|
96 ERR_PRINTF2(_L("Teststep Failed: Leave occured in CTestHttpBufferSizeStep::InvokeHttpMethodL: %D\n" |
|
97 ),err |
|
98 ); |
|
99 SetTestStepResult(EFail); |
|
100 } |
|
101 method.Close(); |
|
102 ValidateTest(); |
|
103 } |
|
104 |
|
105 |
|
106 /** |
|
107 Invoke the http method |
|
108 This actually creates the transaction, sets the headers and HttpDataOptimiser implemetation to transaction |
|
109 and then starts the transaction |
|
110 @internalTechnology |
|
111 @test |
|
112 @param aUri Requested uri |
|
113 @param aMethod Requested method |
|
114 @return None |
|
115 */ |
|
116 void CTestHttpBufferSizeStep::InvokeHttpMethodL(const TDesC8& aUri, RStringF aMethod) |
|
117 { |
|
118 |
|
119 TUriParser8 uri; |
|
120 uri.Parse( aUri ); |
|
121 |
|
122 // Opening a transaction |
|
123 iTrans = iSess.OpenTransactionL(uri, *this, aMethod); |
|
124 RHTTPHeaders hdr = iTrans.Request().GetHeaderCollection(); |
|
125 // Add headers appropriate to all methods |
|
126 SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent); |
|
127 SetHeaderL(hdr, HTTP::EAccept, KAccept); |
|
128 |
|
129 // submit the transaction |
|
130 iTrans.SubmitL(); |
|
131 // Start the scheduler, once the transaction completes or is cancelled on an error the scheduler will be |
|
132 // stopped in the event handler |
|
133 CActiveScheduler::Start(); |
|
134 } |
|
135 |
|
136 |
|
137 /** |
|
138 This is the implementation of interface method CTestHttpBufferSizeStep::MHFRunL |
|
139 If there is a reponse body it will be copied to a file. |
|
140 Just printing the fired events to the log file. |
|
141 @internalTechnology |
|
142 @test |
|
143 @param aTransaction Transaction which is being processed currently |
|
144 @param THTTPEvent Event for which it is called |
|
145 @return None |
|
146 */ |
|
147 void CTestHttpBufferSizeStep::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) |
|
148 { |
|
149 switch (aEvent.iStatus) |
|
150 { |
|
151 case THTTPEvent::EGotResponseHeaders: |
|
152 { |
|
153 // HTTP response headers have been received. We can determine now if there is |
|
154 // going to be a response body to save. |
|
155 RHTTPResponse resp = aTransaction.Response(); |
|
156 TInt status = resp.StatusCode(); |
|
157 RStringF statusStr = resp.StatusText(); |
|
158 TBuf<32> statusStr16; |
|
159 statusStr16.Copy(statusStr.DesC()); |
|
160 INFO_PRINTF3(_L("Status: %D (%S)\n"),status, &statusStr16); |
|
161 |
|
162 if (resp.HasBody() && (status >= 200) && (status < 300) && (status != 204)) |
|
163 { |
|
164 TInt dataSize = resp.Body()->OverallDataSize(); |
|
165 if (dataSize >= 0) |
|
166 INFO_PRINTF2(_L("Response body size is %d\n"), dataSize); |
|
167 else |
|
168 INFO_PRINTF1(_L("Response body size is unknown\n")); |
|
169 } |
|
170 } break; |
|
171 case THTTPEvent::EGotResponseBodyData: |
|
172 { |
|
173 // Get the body data supplier |
|
174 iRespBody = aTransaction.Response().Body(); |
|
175 INFO_PRINTF1(_L("Receiving response body...\n")); |
|
176 |
|
177 TPtrC8 bodyData; |
|
178 TBool lastChunk = iRespBody->GetNextDataPart(bodyData); |
|
179 if(bodyData.Size() > iChunkSize) |
|
180 { |
|
181 iChunkSize = bodyData.Size(); |
|
182 } |
|
183 iRespBody->ReleaseData(); |
|
184 } break; |
|
185 case THTTPEvent::EResponseComplete: |
|
186 { |
|
187 // The transaction's response is complete |
|
188 INFO_PRINTF1(_L("\nTransaction Complete\n")); |
|
189 } break; |
|
190 case THTTPEvent::ESucceeded: |
|
191 { |
|
192 INFO_PRINTF1(_L("Transaction Successful\n")); |
|
193 aTransaction.Close(); |
|
194 CActiveScheduler::Stop(); |
|
195 } break; |
|
196 case THTTPEvent::EFailed: |
|
197 { |
|
198 INFO_PRINTF1(_L("Transaction Failed\n")); |
|
199 aTransaction.Close(); |
|
200 CActiveScheduler::Stop(); |
|
201 } break; |
|
202 case THTTPEvent::ERedirectedPermanently: |
|
203 { |
|
204 INFO_PRINTF1(_L("Permanent Redirection\n")); |
|
205 } break; |
|
206 case THTTPEvent::ERedirectedTemporarily: |
|
207 { |
|
208 INFO_PRINTF1(_L("Temporary Redirection\n")); |
|
209 } break; |
|
210 case THTTPEvent::ERedirectRequiresConfirmation: |
|
211 { |
|
212 // 301(Moved Permanently), 302(Found) or 307(Temporary Redirect) status is received |
|
213 // from a transaction and hence ERedirectRequiresConfirmation is sent by filter |
|
214 // client has opted to close the transaction |
|
215 INFO_PRINTF1(_L("Redirect requires confirmation\n")); |
|
216 aTransaction.Close(); |
|
217 CActiveScheduler::Stop(); |
|
218 } break; |
|
219 default: |
|
220 { |
|
221 INFO_PRINTF2(_L("<unrecognised event: %D>\n"), aEvent.iStatus); |
|
222 // close off the transaction if it's an error |
|
223 if (aEvent.iStatus < 0) |
|
224 { |
|
225 aTransaction.Close(); |
|
226 CActiveScheduler::Stop(); |
|
227 } |
|
228 } break; |
|
229 } |
|
230 } |
|
231 |
|
232 |
|
233 /** |
|
234 This is the implementation of interface method CTestHttpBufferSizeStep::MHFRunError |
|
235 @internalTechnology |
|
236 @test |
|
237 @param aError Error which has been raised. |
|
238 @param aTransaction Transaction which is being processed currently |
|
239 @param THTTPEvent Event which it is being handled currently. |
|
240 @return None |
|
241 */ |
|
242 TInt CTestHttpBufferSizeStep::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, const THTTPEvent& /*aEvent*/) |
|
243 { |
|
244 INFO_PRINTF2(_L("MHFRunError fired with error code %D\n"), aError); |
|
245 return KErrNone; |
|
246 } |
|
247 |
|
248 void CTestHttpBufferSizeStep::ValidateTest() |
|
249 { |
|
250 if(iChunkSize <= 1024) |
|
251 { |
|
252 ERR_PRINTF1(_L("Teststep Passed: Buffer Size Feature is working\n")); |
|
253 } |
|
254 else |
|
255 { |
|
256 ERR_PRINTF2(_L("Received a chunk of size: %D\n"), iChunkSize); |
|
257 ERR_PRINTF1(_L("Received a chunk of size greater than the specified size of 1024 Bytes.\n")); |
|
258 ERR_PRINTF1(_L("Teststep Failed: Buffer Size Feature is not working\n")); |
|
259 SetTestStepResult(EFail); |
|
260 } |
|
261 } |