|
1 // Copyright (c) 2001-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 // |
|
15 |
|
16 #include "get21.h" |
|
17 #include <http.h> |
|
18 #include <commdbconnpref.h> |
|
19 |
|
20 const TDesC& CHttpTestCaseGet21::TestName() |
|
21 { |
|
22 _LIT(KHeaderTestName,"Iteration 2 Get Test 21 "); |
|
23 return KHeaderTestName; |
|
24 } |
|
25 |
|
26 CHttpTestCaseGet21::CHttpTestCaseGet21() |
|
27 { |
|
28 iTransNum=0; |
|
29 iTransSucceeded=0; |
|
30 } |
|
31 |
|
32 void CHttpTestCaseGet21::OpenTestSessionL() |
|
33 { |
|
34 //open sessions |
|
35 iSession1.OpenL(); |
|
36 CleanupClosePushL(iSession1); |
|
37 iSession2.OpenL(); |
|
38 CleanupClosePushL(iSession2); |
|
39 |
|
40 iEngine->Utils().LogIt(_L("Sessions Created(Iteration 2 Get Test 21)")); |
|
41 iEngine->Utils().LogIt(_L("Session1 parameters: Default")); |
|
42 |
|
43 //Connect to Socket server |
|
44 User::LeaveIfError(iSockServ.Connect()); |
|
45 |
|
46 //Define preferences for connection1 |
|
47 TCommDbConnPref prefs1; |
|
48 prefs1.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); |
|
49 //Start Connection1 |
|
50 User::LeaveIfError(iConnection1.Open(iSockServ)); |
|
51 User::LeaveIfError(iConnection1.Start(prefs1)); |
|
52 //Set properties for session1 |
|
53 RStringPool strP1 = iSession1.StringPool(); |
|
54 RHTTPConnectionInfo connInfo1 = iSession1.ConnectionInfo(); |
|
55 connInfo1.SetPropertyL ( strP1.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable() ), THTTPHdrVal (iSockServ.Handle()) ); |
|
56 TInt connPtr1 = REINTERPRET_CAST(TInt, &iConnection1); |
|
57 connInfo1.SetPropertyL ( strP1.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ), THTTPHdrVal (connPtr1) ); |
|
58 |
|
59 |
|
60 //Define preferences for connection2 |
|
61 TCommDbConnPref prefs2; |
|
62 prefs2.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); |
|
63 //Start Connection2 |
|
64 User::LeaveIfError(iConnection2.Open(iSockServ)); |
|
65 User::LeaveIfError(iConnection2.Start(prefs2)); |
|
66 //Set properties for session2 |
|
67 RStringPool strP2 = iSession2.StringPool(); |
|
68 RHTTPConnectionInfo connInfo2 = iSession2.ConnectionInfo(); |
|
69 connInfo2.SetPropertyL ( strP2.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable() ), THTTPHdrVal (iSockServ.Handle()) ); |
|
70 TInt connPtr2 = REINTERPRET_CAST(TInt, &iConnection2); |
|
71 connInfo2.SetPropertyL ( strP2.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ), THTTPHdrVal (connPtr2) ); |
|
72 |
|
73 iEngine->Utils().LogIt(_L("Session2 parameters: Specified")); |
|
74 |
|
75 } |
|
76 |
|
77 void CHttpTestCaseGet21::CloseTestSession() |
|
78 { |
|
79 iTransaction1.Close(); |
|
80 iEngine->Utils().LogIt(_L("Transaction1 terminated\n")); |
|
81 iTransaction2.Close(); |
|
82 iEngine->Utils().LogIt(_L("Transaction2 terminated\n")); |
|
83 iTransaction3.Close(); |
|
84 iEngine->Utils().LogIt(_L("Transaction3 terminated\n")); |
|
85 iSession1.Close(); |
|
86 iEngine->Utils().LogIt(_L("Session1 terminated")); |
|
87 iSession2.Close(); |
|
88 iEngine->Utils().LogIt(_L("Session2 terminated")); |
|
89 } |
|
90 |
|
91 void CHttpTestCaseGet21::DoRunL() |
|
92 { |
|
93 OpenTestSessionL(); |
|
94 |
|
95 //Trans1 in Session1 |
|
96 OpenTestTrans1L(); |
|
97 iTransaction1.SubmitL(); |
|
98 iTransNum++; |
|
99 //Trans2 in Session2 |
|
100 OpenTestTrans2L(); |
|
101 iTransaction2.SubmitL(); |
|
102 iTransNum++; |
|
103 //Trans3 in Session1 |
|
104 OpenTestTrans3L(); |
|
105 iTransaction3.SubmitL(); |
|
106 iTransNum++; |
|
107 |
|
108 CActiveScheduler::Start(); |
|
109 |
|
110 CloseTestSession(); |
|
111 if (iTestFail==1) |
|
112 { |
|
113 User::Leave(-1); |
|
114 } |
|
115 |
|
116 CleanupStack::PopAndDestroy(2); //session1 & session2 |
|
117 } |
|
118 |
|
119 void CHttpTestCaseGet21::OpenTestTrans1L() |
|
120 { |
|
121 _LIT8(KTestURIDes,"http://www.google.com/"); |
|
122 TUriParser8 testURI1; |
|
123 testURI1.Parse(KTestURIDes); |
|
124 |
|
125 //Get the session's string pool handle; |
|
126 RStringPool strP = iSession1.StringPool(); |
|
127 |
|
128 //open a GET transaction and log it |
|
129 iTransaction1 = iSession1.OpenTransactionL(testURI1, *this,strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
130 iEngine->Utils().LogIt(_L("Transaction Created in Session")); |
|
131 |
|
132 //Get a handle of each request and of its header |
|
133 RHTTPRequest iMyRequest1 = iTransaction1.Request(); |
|
134 RHTTPHeaders iMyHeaders1 = iMyRequest1.GetHeaderCollection(); |
|
135 |
|
136 //get string from the string pool |
|
137 RStringF accept= strP.StringF(HTTP::EAnyAny,RHTTPSession::GetTable()); |
|
138 |
|
139 //provide some headers |
|
140 THTTPHdrVal acceptHdr(accept); |
|
141 |
|
142 iMyHeaders1.SetFieldL(strP.StringF(HTTP::EAccept,RHTTPSession::GetTable()),acceptHdr); |
|
143 |
|
144 // Log the Request parameters |
|
145 iEngine->Utils().LogIt(_L("URI: http://www.google.com/")); |
|
146 iEngine->Utils().LogIt(_L("Method:GET")); |
|
147 iEngine->Utils().LogIt(_L("Accept: */*")); |
|
148 } |
|
149 |
|
150 void CHttpTestCaseGet21::OpenTestTrans2L() |
|
151 { |
|
152 _LIT8(KTestURIDes,"http://www.lonelyplanet.com//"); |
|
153 TUriParser8 testURI2; |
|
154 testURI2.Parse(KTestURIDes); |
|
155 |
|
156 //Get the session's string pool handle |
|
157 RStringPool strP = iSession2.StringPool(); |
|
158 |
|
159 //open a GET transaction and log it |
|
160 iTransaction2 = iSession2.OpenTransactionL(testURI2, *this,strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
161 iEngine->Utils().LogIt(_L("Transaction Created in Session")); |
|
162 |
|
163 //Get a handle of each request and of its header |
|
164 RHTTPRequest iMyRequest2 = iTransaction2.Request(); |
|
165 RHTTPHeaders iMyHeaders2 = iMyRequest2.GetHeaderCollection(); |
|
166 |
|
167 //get string from the string pool |
|
168 RStringF accept= strP.StringF(HTTP::EAnyAny,RHTTPSession::GetTable()); |
|
169 |
|
170 //provide some headers |
|
171 THTTPHdrVal acceptHdr(accept); |
|
172 iMyHeaders2.SetFieldL(strP.StringF(HTTP::EAccept,RHTTPSession::GetTable()),acceptHdr); |
|
173 |
|
174 // Log the Request parameters |
|
175 iEngine->Utils().LogIt(_L("URI: http://www.lonelyplanet.com//")); |
|
176 iEngine->Utils().LogIt(_L("Method:GET")); |
|
177 iEngine->Utils().LogIt(_L("Accept: */*")); |
|
178 } |
|
179 |
|
180 void CHttpTestCaseGet21::OpenTestTrans3L() |
|
181 { |
|
182 _LIT8(KTestURIDes,"http://www.yahoo.com/"); |
|
183 TUriParser8 testURI3; |
|
184 testURI3.Parse(KTestURIDes); |
|
185 |
|
186 //Get the session's string pool handle |
|
187 RStringPool strP = iSession1.StringPool(); |
|
188 |
|
189 //open a GET transaction and log it |
|
190 iTransaction3 = iSession1.OpenTransactionL(testURI3, *this,strP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
191 iEngine->Utils().LogIt(_L("Transaction Created in Session")); |
|
192 |
|
193 //Get a handle of each request and of its header |
|
194 RHTTPRequest iMyRequest3 = iTransaction3.Request(); |
|
195 RHTTPHeaders iMyHeaders3 = iMyRequest3.GetHeaderCollection(); |
|
196 |
|
197 //get string from the string pool |
|
198 RStringF accept= strP.StringF(HTTP::EAnyAny,RHTTPSession::GetTable()); |
|
199 |
|
200 //provide some headers |
|
201 THTTPHdrVal acceptHdr(accept); |
|
202 iMyHeaders3.SetFieldL(strP.StringF(HTTP::EAccept,RHTTPSession::GetTable()),acceptHdr); |
|
203 |
|
204 // Log the Request parameters |
|
205 iEngine->Utils().LogIt(_L("URI: http://www.yahoo.com/")); |
|
206 iEngine->Utils().LogIt(_L("Method:GET")); |
|
207 iEngine->Utils().LogIt(_L("Accept: */*")); |
|
208 |
|
209 } |
|
210 |
|
211 |
|
212 |
|
213 TInt CHttpTestCaseGet21::MHFRunError(TInt aError, |
|
214 RHTTPTransaction /*aTransaction*/, |
|
215 const THTTPEvent& /*aEvent*/) |
|
216 { |
|
217 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aError); |
|
218 return KErrNone; |
|
219 } |
|
220 |
|
221 |
|
222 void CHttpTestCaseGet21::MHFRunL(RHTTPTransaction aTransaction, |
|
223 const THTTPEvent& aEvent) |
|
224 { |
|
225 switch (aEvent.iStatus) |
|
226 { |
|
227 case THTTPEvent::EGotResponseHeaders: |
|
228 { |
|
229 // HTTP response headers have been received |
|
230 iEngine->Utils().LogIt(_L("<EGotResponseHeaders for TR %d>\n"),transCount+1); |
|
231 TInt statusCode = aTransaction.Response().StatusCode(); |
|
232 iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode); |
|
233 DumpRespHeaders(aTransaction); |
|
234 iEngine->SetCurrentStatusCode(statusCode); |
|
235 } break; |
|
236 case THTTPEvent::EGotResponseBodyData: |
|
237 { |
|
238 // Some (more) body data has been received (in the HTTP response) |
|
239 iEngine->Utils().LogIt(_L("<EGotResponseBodyData received for TR %d>\n"),transCount+1); |
|
240 // for each chunk of data received we have to empty the buffer before to be able to receive |
|
241 MHTTPDataSupplier* body = aTransaction.Response().Body(); |
|
242 body->ReleaseData(); |
|
243 } break; |
|
244 case THTTPEvent::EResponseComplete: |
|
245 { |
|
246 // The transaction's response is complete |
|
247 iEngine->Utils().LogIt(_L("<EResponseComplete received for TR %d>\n"),transCount+1); |
|
248 |
|
249 } break; |
|
250 case THTTPEvent::ESucceeded: |
|
251 { |
|
252 transCount++; |
|
253 iTransSucceeded++; |
|
254 iEngine->Utils().LogIt(_L("<ESucceeded received %d>\n"),transCount); |
|
255 if (transCount<=iTransNum) |
|
256 { |
|
257 if(iTransSucceeded==iTransNum) |
|
258 { |
|
259 iEngine->Utils().LogIt(_L("The test has PASSED")); |
|
260 CActiveScheduler::Stop(); |
|
261 } |
|
262 } |
|
263 else |
|
264 { |
|
265 iTestFail=1; |
|
266 iEngine->Utils().LogIt(_L("<The Test will fail:less than %d ESucceeded have been received>\n"),iTransNum); |
|
267 } |
|
268 } break; |
|
269 case THTTPEvent::EFailed: |
|
270 { |
|
271 transCount++; |
|
272 iTestFail=1; |
|
273 iEngine->Utils().LogIt(_L("<The Test will fail:1 Transaction has failed")); |
|
274 iEngine->Utils().LogIt(_L("<EFailed received from the VF>\nThe Test has FAILED")); |
|
275 CActiveScheduler::Stop(); |
|
276 } break; |
|
277 default: |
|
278 { |
|
279 iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus); |
|
280 iEngine->PressAnyKey(); |
|
281 CActiveScheduler::Stop(); |
|
282 } |
|
283 break; |
|
284 } |
|
285 } |