|
1 // Copyright (c) 2003-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 "cpipeliningtestclient.h" |
|
17 #include "httptestutils.h" |
|
18 #include "MPipeliningTestCase.h" |
|
19 #include "MPipeliningTestObserver.h" |
|
20 |
|
21 CPipeliningTestClient* CPipeliningTestClient::NewL(CHTTPTestUtils& aTestUtils, MPipeliningTestObserver& aObserver) |
|
22 { |
|
23 CPipeliningTestClient* self = new (ELeave) CPipeliningTestClient(aTestUtils, aObserver); |
|
24 CleanupStack::PushL(self); |
|
25 self->ConstructL(); |
|
26 CleanupStack::Pop(self); |
|
27 return self; |
|
28 } |
|
29 |
|
30 CPipeliningTestClient::CPipeliningTestClient(CHTTPTestUtils& aTestUtils, MPipeliningTestObserver& aObserver) |
|
31 : iTestUtils(aTestUtils), iObserver(aObserver) |
|
32 { |
|
33 } |
|
34 |
|
35 void CPipeliningTestClient::ConstructL() |
|
36 { |
|
37 iSession.OpenL(); |
|
38 iHttpTimer = new(ELeave) CHttpTimer1(*this); |
|
39 iASW = new(ELeave) CActiveSchedulerWait(); |
|
40 } |
|
41 |
|
42 CPipeliningTestClient::~CPipeliningTestClient() |
|
43 { |
|
44 iTransArray.Reset(); |
|
45 iTransArray.Close(); |
|
46 iSession.Close(); |
|
47 delete iHttpTimer; |
|
48 delete iASW; |
|
49 } |
|
50 |
|
51 RHTTPSession& CPipeliningTestClient::GetSession() |
|
52 { |
|
53 return iSession; |
|
54 } |
|
55 |
|
56 // From MHTTPTransactionCallback |
|
57 void CPipeliningTestClient::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) |
|
58 { |
|
59 TInt expectedError = iTestCase->ExpectedError(aTransaction); |
|
60 TInt tranID = aTransaction.Id(); |
|
61 switch (aEvent.iStatus) |
|
62 { |
|
63 case THTTPEvent::EGotResponseHeaders: |
|
64 { |
|
65 iTestCase->ProcessHeadersL(aTransaction); |
|
66 } break; |
|
67 case THTTPEvent::EGotResponseBodyData: |
|
68 { |
|
69 // Done with that bit of body data |
|
70 aTransaction.Response().Body()->ReleaseData(); |
|
71 } break; |
|
72 case THTTPEvent::EResponseComplete: |
|
73 { |
|
74 } break; |
|
75 case KErrHttpOptimiserFailsTrans: |
|
76 { |
|
77 _LIT(KTxtMessage, "Cancelling/Failing Transaction\n"); |
|
78 iTestUtils.LogIt(KTxtMessage); |
|
79 aTransaction.Fail(THTTPFilterHandle::EProtocolHandler); |
|
80 } break; |
|
81 case THTTPEvent::ESucceeded: |
|
82 { |
|
83 ++iCurrentTrans; |
|
84 aTransaction.Close(); |
|
85 _LIT(KTxtSuccessful, "Client - Transaction %d, completed successfully."); |
|
86 iTestUtils.LogIt(KTxtSuccessful, tranID); |
|
87 if ((iTestCase->TestCaseName().Match(_L("Test Case 5")) == 0)||(iTestCase->TestCaseName().Match(_L("Test Case 6")) == 0)||(iTestCase->TestCaseName().Match(_L("Test Case 25")) == 0)) |
|
88 { |
|
89 TTimeIntervalMicroSeconds32 time(1000000); |
|
90 iHttpTimer->After(time); |
|
91 iASW->Start(); |
|
92 } |
|
93 if( expectedError != KErrNone ) |
|
94 { |
|
95 _LIT(KTxtErrorExpected, "Client - Expected error code %d"); |
|
96 iTestUtils.LogIt(KTxtErrorExpected, expectedError); |
|
97 |
|
98 EndTestL(KErrNotFound); |
|
99 } |
|
100 |
|
101 if( iTestCase->TotalTransactionCount() == iCurrentTrans ) |
|
102 EndTestL(KErrNone); |
|
103 } break; |
|
104 case THTTPEvent::EFailed: |
|
105 { |
|
106 ++iCurrentTrans; |
|
107 aTransaction.Close(); |
|
108 if( expectedError == iLastError ) |
|
109 { |
|
110 _LIT(KTxtExpectedError, "Client - Transaction %d Failed, Expected: %d, Actual: %d"); |
|
111 iTestUtils.LogIt(KTxtExpectedError(), tranID, expectedError, iLastError); |
|
112 if( iTestCase->TotalTransactionCount() == iCurrentTrans ) |
|
113 EndTestL(KErrNone); |
|
114 } |
|
115 else |
|
116 { |
|
117 _LIT(KTxtErrorUnexpected, "Client - Error code mismatch."); |
|
118 iTestUtils.LogIt(KTxtErrorUnexpected()); |
|
119 EndTestL(KErrNotFound); |
|
120 } |
|
121 } break; |
|
122 case THTTPEvent::ERedirectedPermanently: |
|
123 { |
|
124 } break; |
|
125 case THTTPEvent::ERedirectedTemporarily: |
|
126 { |
|
127 } break; |
|
128 case THTTPEvent::ERedirectRequiresConfirmation: |
|
129 { |
|
130 aTransaction.SubmitL(); |
|
131 } break; |
|
132 case THTTPEvent::EReceiveTimeOut: |
|
133 { |
|
134 iTestUtils.Test().Printf(_L("Receive TimeOut\n")); |
|
135 _LIT(KTxtErrRecvTimeout, "Client - Receive Timeout."); |
|
136 iTestUtils.LogIt(KTxtErrRecvTimeout()); |
|
137 }break; |
|
138 case THTTPEvent::ESendTimeOut: |
|
139 { |
|
140 iTestUtils.Test().Printf(_L("Send TimeOut\n")); |
|
141 _LIT(KTxtErrSendTimeout, "Client - Send Timeout."); |
|
142 iTestUtils.LogIt(KTxtErrSendTimeout()); |
|
143 }break; |
|
144 default: |
|
145 { |
|
146 if (aEvent.iStatus < 0) |
|
147 { |
|
148 iLastError = aEvent.iStatus; |
|
149 |
|
150 _LIT(KTxtClientError, "Client - Transaction %d, received error code %d"); |
|
151 iTestUtils.LogIt(KTxtClientError, tranID, iLastError); |
|
152 } |
|
153 } break; |
|
154 } |
|
155 } |
|
156 |
|
157 |
|
158 void CPipeliningTestClient::EndTestL(TInt aErrorCode) |
|
159 { |
|
160 #if defined (_DEBUG) |
|
161 _LIT(KTxtClientError, "Error - Code %d"); |
|
162 iTestUtils.LogIt(KTxtClientError, aErrorCode); |
|
163 if (aErrorCode == KErrNone) |
|
164 { |
|
165 TInt expectedConnections = iTestCase->RealExpectedConnectionCount(); |
|
166 RStringPool stringPool = iSession.StringPool(); |
|
167 _LIT8(KNumberConnectionManagers, "__NumConnectionManagers"); |
|
168 RStringF numberConnectionsString = stringPool.OpenFStringL(KNumberConnectionManagers); |
|
169 CleanupClosePushL(numberConnectionsString); |
|
170 RHTTPConnectionInfo connInfo = iSession.ConnectionInfo(); |
|
171 TInt numberConnections =0; |
|
172 _LIT(KTxtTitle, "Test Case Pipeline Fallback"); |
|
173 THTTPHdrVal numberConnectionsVal; |
|
174 if (connInfo.Property(numberConnectionsString, numberConnectionsVal)) |
|
175 { |
|
176 numberConnections = numberConnectionsVal.Int(); |
|
177 connInfo.RemoveProperty(numberConnectionsString); |
|
178 |
|
179 if ((numberConnections > expectedConnections) && iTestCase->TestCaseName().Match(KTxtTitle) != 0) |
|
180 { |
|
181 |
|
182 _LIT(KTxtClientError, "Client - Connections %d, Expected: %d"); |
|
183 iTestUtils.LogIt(KTxtClientError, numberConnections, expectedConnections); |
|
184 aErrorCode = KErrNotFound; |
|
185 } |
|
186 |
|
187 } |
|
188 |
|
189 CleanupStack::PopAndDestroy(&numberConnectionsString); |
|
190 } |
|
191 #endif |
|
192 |
|
193 iObserver.EndTest(aErrorCode); |
|
194 } |
|
195 |
|
196 |
|
197 TInt CPipeliningTestClient::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/) |
|
198 { |
|
199 _LIT(KTxtRunError, "Client - MHFRunError - Transaction %d with error code %d."); |
|
200 iTestUtils.LogIt(KTxtRunError(), aTransaction.Id(), aError); |
|
201 |
|
202 return KErrNone; |
|
203 } |
|
204 |
|
205 void CPipeliningTestClient::AddTransactionL(RHTTPTransaction aTransaction) |
|
206 { |
|
207 User::LeaveIfError(iTransArray.Append(aTransaction)); |
|
208 } |
|
209 |
|
210 void CPipeliningTestClient::StartClientL() |
|
211 { |
|
212 __ASSERT_DEBUG(iTestCase!=NULL, User::Invariant()); |
|
213 |
|
214 if( iTestCase->EnableBatching() ) |
|
215 { |
|
216 // @todo we need to add the session property for enabling batching |
|
217 RHTTPConnectionInfo connInfo = GetSession().ConnectionInfo(); |
|
218 THTTPHdrVal batchingSupport(iSession.StringPool().StringF(HTTP::EEnableBatching,RHTTPSession::GetTable())); |
|
219 connInfo.SetPropertyL(iSession.StringPool().StringF(HTTP::EHttpBatching,RHTTPSession::GetTable()), batchingSupport); |
|
220 } |
|
221 |
|
222 if( iTestCase->TransportHandlerPriority() ) |
|
223 { |
|
224 RHTTPConnectionInfo connInfo = iSession.ConnectionInfo(); |
|
225 THTTPHdrVal enableTranspHndlrPriority(iSession.StringPool().StringF(HTTP::EEnableTranspHndlrPriority, RHTTPSession::GetTable())); |
|
226 connInfo.SetPropertyL(iSession.StringPool().StringF(HTTP::ETranspHndlrPriority, RHTTPSession::GetTable()), enableTranspHndlrPriority); |
|
227 } |
|
228 |
|
229 TBool batchTrans = iTestCase->BatchTransactions(); |
|
230 |
|
231 // Create transactions |
|
232 for( TInt ii=0; ii < iTestCase->TotalTransactionCount(); ++ii ) |
|
233 { |
|
234 RHTTPTransaction trans = iTestCase->GetTransactionL(ii, GetSession(), *this); |
|
235 CleanupClosePushL(trans); |
|
236 AddTransactionL(trans); |
|
237 if(!batchTrans) |
|
238 trans.SubmitL(); |
|
239 CleanupStack::Pop(&trans); |
|
240 } |
|
241 |
|
242 if(batchTrans) |
|
243 { |
|
244 for( TInt jj=0; jj < iTransArray.Count(); ++jj ) |
|
245 { |
|
246 iTransArray[jj].SubmitL(); |
|
247 } |
|
248 } |
|
249 } |
|
250 |
|
251 void CPipeliningTestClient::SetTestCase(MPipeliningTestCase* aTestCase) |
|
252 { |
|
253 iTestCase = aTestCase; |
|
254 } |
|
255 |
|
256 void CPipeliningTestClient::TimeOut() |
|
257 { |
|
258 iASW->AsyncStop(); |
|
259 } |
|
260 |
|
261 CHttpTimer1::CHttpTimer1(MTimerClient1& aClient) |
|
262 :CActive(EPriorityStandard), iClient(aClient) |
|
263 { |
|
264 CActiveScheduler::Add(this); |
|
265 iTimer.CreateLocal(); |
|
266 } |
|
267 |
|
268 CHttpTimer1::~CHttpTimer1() |
|
269 { |
|
270 Cancel(); |
|
271 iTimer.Close(); |
|
272 } |
|
273 |
|
274 void CHttpTimer1::After(TTimeIntervalMicroSeconds32 anInterval) |
|
275 { |
|
276 iTimer.After(iStatus, anInterval); |
|
277 SetActive(); |
|
278 } |
|
279 |
|
280 void CHttpTimer1::DoCancel() |
|
281 { |
|
282 |
|
283 } |
|
284 |
|
285 void CHttpTimer1::RunL() |
|
286 { |
|
287 iClient.TimeOut(); |
|
288 } |
|
289 |