|
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 "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 // defines test class: CINC097492 |
|
15 // |
|
16 // |
|
17 |
|
18 #include "CINC097492.h" |
|
19 #include "examplecookiemanager.h" |
|
20 #include <http/ccookiefilterinterface.h> |
|
21 |
|
22 // User include |
|
23 #include "csrvaddrval.h" |
|
24 |
|
25 // Literals used in the file |
|
26 _LIT8(KHttpUrl1, "http://10.29.23.12/manual/index.html"); |
|
27 _LIT8(KHttpUrl2, "http://10.29.23.12/manual/new_features_1_3.html"); |
|
28 _LIT8(KHttpUrl3, "http://10.29.23.12/manual/images/index.gif"); |
|
29 _LIT8(KHttpUrl4, "http://10.29.23.12/manual/install.html"); |
|
30 _LIT8(KHttpUrl5, "http://10.29.23.12/manual/invoking.html"); |
|
31 _LIT8(KHttpUrl6, "http://10.29.23.12/manual/stopping.html"); |
|
32 _LIT8(KHttpUrl7, "http://10.29.23.12/manual/mod/directives.html"); |
|
33 _LIT8(KHttpUrl8, "http://10.29.23.12/manual/images/custom_errordocs.gif"); |
|
34 _LIT8(KHttpUrl9, "http://10.29.23.12/manual/images/home.gif"); |
|
35 _LIT8(KHttpUrl10, "http://10.29.23.12/manual/images/home.gif"); |
|
36 |
|
37 /** |
|
38 This function is called to create a new instance of the class |
|
39 CINC097492 |
|
40 |
|
41 @param aTestNumber The test number that has to be executed |
|
42 @param aIniSettingsFile The script file that holds the sections |
|
43 from which the value has to be retrieved |
|
44 @leave Leaves with a standard error |
|
45 */ |
|
46 CINC097492* CINC097492::NewL(TInt aTestNumber, CScriptFile* aIniSettingsFile) |
|
47 { |
|
48 CINC097492* self = new(ELeave)CINC097492(aTestNumber, aIniSettingsFile); |
|
49 CleanupStack::PushL(self); |
|
50 CleanupStack::Pop(self); |
|
51 return self; |
|
52 } |
|
53 |
|
54 /** |
|
55 Destructor |
|
56 */ |
|
57 CINC097492::~CINC097492() |
|
58 { |
|
59 iTransArray.Close(); |
|
60 } |
|
61 |
|
62 /** |
|
63 This C++ constructor is called in the NewL function and is used to |
|
64 instantiate iTestNumber and iIniSettingsFile |
|
65 |
|
66 @param aTestNumber - The test number that has to be executed |
|
67 @param aIniSettingsFile - The script file that holds the sections |
|
68 from which the value has to be retrieved |
|
69 */ |
|
70 CINC097492::CINC097492(TInt aTestNumber, CScriptFile* aIniSettingsFile) : |
|
71 iIniSettingsFile(aIniSettingsFile), |
|
72 iTestNumber(aTestNumber) |
|
73 { |
|
74 } |
|
75 |
|
76 /** |
|
77 This function is called to initiate the tests. |
|
78 |
|
79 @leave Leaves with a standard error. |
|
80 */ |
|
81 void CINC097492::DoRunL() |
|
82 { |
|
83 // Open the HTTP session |
|
84 iSession.OpenL(); |
|
85 CleanupClosePushL(iSession); |
|
86 |
|
87 CreateTransArrayL(); |
|
88 |
|
89 CActiveScheduler::Start(); |
|
90 |
|
91 CleanupStack::PopAndDestroy(&iSession); //close iSession |
|
92 } |
|
93 |
|
94 /** |
|
95 If a test is failed then is function is executed to log the error code |
|
96 with which the test failed |
|
97 |
|
98 @param aErr The error code with which the test failed. |
|
99 */ |
|
100 TInt CINC097492::RunError(TInt aErr) |
|
101 { |
|
102 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr); |
|
103 return KErrNone; |
|
104 } |
|
105 |
|
106 void CINC097492::DoCancel() |
|
107 { |
|
108 } |
|
109 |
|
110 const TDesC& CINC097492::TestName() |
|
111 { |
|
112 _LIT(KHeaderTestName,"CINC097492"); |
|
113 return KHeaderTestName; |
|
114 } |
|
115 |
|
116 TInt CINC097492::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/) |
|
117 { |
|
118 _LIT(KLogDescription, "\nTest failed with error code %d on transaction ID=%d\n"); |
|
119 iEngine->Utils().LogIt(KLogDescription, aError, aTransaction.Id()); |
|
120 iFailureError = aError; |
|
121 CActiveScheduler::Stop(); |
|
122 return KErrNone; |
|
123 } |
|
124 |
|
125 void CINC097492::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) |
|
126 { |
|
127 switch (aEvent.iStatus) |
|
128 { |
|
129 case THTTPEvent::EGotResponseHeaders: |
|
130 { |
|
131 // HTTP response headers have been received |
|
132 iEngine->Utils().LogIt(_L("<Got response headers>")); |
|
133 MHTTPDataSupplier* body = aTransaction.Response().Body (); |
|
134 if ( body ) |
|
135 { |
|
136 body->ReleaseData (); |
|
137 } |
|
138 } break; |
|
139 case THTTPEvent::ESubmit: |
|
140 { |
|
141 } break; |
|
142 case THTTPEvent::EGotResponseBodyData: |
|
143 { |
|
144 // Some (more) body data has been received (in the HTTP response) |
|
145 iEngine->Utils().LogIt(_L("<Got a chunk of data>")); |
|
146 // Get the body data supplier |
|
147 MHTTPDataSupplier* iRespBody = aTransaction.Response().Body(); |
|
148 // Append to the output file. |
|
149 TPtrC8 bodyData; |
|
150 TBool lastChunk = iRespBody->GetNextDataPart( bodyData ); |
|
151 iRespBody->ReleaseData(); |
|
152 } break; |
|
153 case THTTPEvent::EResponseComplete: |
|
154 { |
|
155 if(aTransaction.Request().URI().UriDes().Compare(KHttpUrl7) == 0) |
|
156 { |
|
157 iTransArray[8].Cancel(); |
|
158 iOpenTransCount--; |
|
159 } |
|
160 |
|
161 // The transaction's response is complete |
|
162 iEngine->Utils().LogIt(_L("<Transaction Complete>")); |
|
163 } break; |
|
164 case THTTPEvent::ESucceeded: |
|
165 { |
|
166 if(aTransaction.Request().URI().UriDes().Compare(KHttpUrl4) == 0) |
|
167 { |
|
168 iTransArray[5].Cancel(); |
|
169 iOpenTransCount--; |
|
170 } |
|
171 |
|
172 // The transaction succeeded |
|
173 iEngine->Utils().LogIt(_L("<Transaction succeeded>")); |
|
174 aTransaction.Close(); |
|
175 if(--iOpenTransCount == 0) |
|
176 { |
|
177 CActiveScheduler::Stop(); |
|
178 } |
|
179 } |
|
180 break; |
|
181 case THTTPEvent::EFailed: |
|
182 { |
|
183 // The transaction failed so fail the test |
|
184 iEngine->Utils().LogIt(_L("<Transaction failed>")); |
|
185 aTransaction.Close(); |
|
186 if(--iOpenTransCount == 0) |
|
187 { |
|
188 CActiveScheduler::Stop(); |
|
189 } |
|
190 } break; |
|
191 default: |
|
192 { |
|
193 _LIT(KLogDescription, "<unrecognised event> %d"); |
|
194 iEngine->Utils().LogIt(KLogDescription,aEvent.iStatus); |
|
195 if (aEvent.iStatus < 0) |
|
196 { |
|
197 iFailureError = aEvent.iStatus; |
|
198 CActiveScheduler::Stop(); |
|
199 } |
|
200 } |
|
201 break; |
|
202 } |
|
203 |
|
204 return; |
|
205 } |
|
206 |
|
207 |
|
208 void CINC097492::ConfigureSessionFiltersL(TFilterConfigurationIterator* /*aFilterConfigIter*/) |
|
209 { |
|
210 if (iTestNumber == 11) |
|
211 { |
|
212 User::Leave(KErrNone); |
|
213 } |
|
214 |
|
215 iCookieManager = CExampleCookieManager::NewL(iSession.StringPool()); |
|
216 |
|
217 CCookieFilterInterface::InstallFilterL(iSession, iCookieManager); |
|
218 } |
|
219 |
|
220 void CINC097492::CreateTransArrayL() |
|
221 { |
|
222 RStringPool strP = iSession.StringPool(); |
|
223 TUriParser8 up; |
|
224 |
|
225 up.Parse(KHttpUrl1); |
|
226 RHTTPTransaction trans1 = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
227 CleanupClosePushL(trans1); |
|
228 iTransArray.Append(trans1); |
|
229 CleanupStack::Pop(&trans1); |
|
230 |
|
231 up.Parse(KHttpUrl2); |
|
232 RHTTPTransaction trans2 = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
233 CleanupClosePushL(trans2); |
|
234 iTransArray.Append(trans2); |
|
235 CleanupStack::Pop(&trans2); |
|
236 |
|
237 up.Parse(KHttpUrl3); |
|
238 RHTTPTransaction trans3 = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
239 CleanupClosePushL(trans3); |
|
240 iTransArray.Append(trans3); |
|
241 CleanupStack::Pop(&trans3); |
|
242 |
|
243 up.Parse(KHttpUrl4); |
|
244 RHTTPTransaction trans4 = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
245 CleanupClosePushL(trans4); |
|
246 iTransArray.Append(trans4); |
|
247 CleanupStack::Pop(&trans4); |
|
248 |
|
249 up.Parse(KHttpUrl5); |
|
250 RHTTPTransaction trans5 = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
251 CleanupClosePushL(trans5); |
|
252 iTransArray.Append(trans5); |
|
253 CleanupStack::Pop(&trans5); |
|
254 |
|
255 up.Parse(KHttpUrl6); |
|
256 RHTTPTransaction trans6 = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
257 CleanupClosePushL(trans6); |
|
258 iTransArray.Append(trans6); |
|
259 CleanupStack::Pop(&trans6); |
|
260 |
|
261 up.Parse(KHttpUrl7); |
|
262 RHTTPTransaction trans7 = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
263 CleanupClosePushL(trans7); |
|
264 iTransArray.Append(trans7); |
|
265 CleanupStack::Pop(&trans7); |
|
266 |
|
267 up.Parse(KHttpUrl8); |
|
268 RHTTPTransaction trans8 = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
269 CleanupClosePushL(trans8); |
|
270 iTransArray.Append(trans8); |
|
271 CleanupStack::Pop(&trans8); |
|
272 |
|
273 up.Parse(KHttpUrl9); |
|
274 RHTTPTransaction trans9 = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
275 CleanupClosePushL(trans9); |
|
276 iTransArray.Append(trans9); |
|
277 CleanupStack::Pop(&trans9); |
|
278 |
|
279 up.Parse(KHttpUrl10); |
|
280 RHTTPTransaction trans10 = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
281 CleanupClosePushL(trans10); |
|
282 iTransArray.Append(trans10); |
|
283 CleanupStack::Pop(&trans10); |
|
284 |
|
285 for(TInt i=0; i<iTransArray.Count(); i++) |
|
286 { |
|
287 iTransArray[i].SubmitL(); |
|
288 iOpenTransCount++; |
|
289 } |
|
290 } |
|
291 |
|
292 |