|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <ss_glob.h> |
|
19 #include <comms-infras/ss_nodemessages_factory.h> |
|
20 #include <comms-infras/ss_nodemessages_dataclient.h> |
|
21 #include <httpstringconstants.h> |
|
22 |
|
23 #include "ptcpclienttests.h" |
|
24 #include "upnp_cf_msgs.h" |
|
25 #include "upnpflowbase.h" |
|
26 #include "httpclientflow.h" |
|
27 #include "upnpflowfactory.h" |
|
28 #include "CTcpClientTestUPnP3.h" |
|
29 |
|
30 const TUint16 KActivityNull = 0; |
|
31 const TUint KHttpDefaultPort = 80; |
|
32 |
|
33 |
|
34 const TUint KTransactionCount = 1; |
|
35 _LIT8 ( KTxtRawRequest, "GET / HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 0\r\n\r\n" ); |
|
36 _LIT8 ( KTxtRawResponse1, "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 0\r\n\r\n" ); |
|
37 |
|
38 |
|
39 CTcpClientTestUPnP3* CTcpClientTestUPnP3::NewL ( CProxyProvd* aProvd ) |
|
40 { |
|
41 CTcpClientTestUPnP3* ret = new ( ELeave ) CTcpClientTestUPnP3 ( aProvd ); |
|
42 CleanupStack::PushL ( ret ); |
|
43 ret->ConstructL (); |
|
44 CleanupStack::Pop ( ret ); |
|
45 return ret; |
|
46 } |
|
47 |
|
48 CTcpClientTestUPnP3::CTcpClientTestUPnP3 ( CProxyProvd* aProvd ) : |
|
49 CTcpClientTestBase(aProvd), iTestServer(NULL) |
|
50 { |
|
51 } |
|
52 |
|
53 CTcpClientTestUPnP3::~CTcpClientTestUPnP3 () |
|
54 { |
|
55 iTimer.Close (); |
|
56 } |
|
57 |
|
58 void CTcpClientTestUPnP3::ConstructL() |
|
59 { |
|
60 iTimer.CreateLocal (); |
|
61 } |
|
62 |
|
63 TVerdict CTcpClientTestUPnP3::RunTestL() |
|
64 { |
|
65 switch ( iState ) |
|
66 { |
|
67 case ECreateTestServer: |
|
68 { |
|
69 iLogger.WriteFormat(_L("<i>Creating TestServer..... </i>")); |
|
70 |
|
71 iTestServer = CTestTcpServer::NewL ( *this ); |
|
72 |
|
73 iState = ECreateTestClient; |
|
74 iStatus = KRequestPending; |
|
75 Reschedule(); |
|
76 return EPass; |
|
77 } |
|
78 |
|
79 case ECreateTestClient: |
|
80 { |
|
81 iLogger.WriteFormat(_L("<i>TestServer is created..... </i>")); |
|
82 iLogger.WriteFormat(_L("<i>Creating TestClient..... </i>")); |
|
83 |
|
84 THttpClientFlowQuery flowQuery ( TAppProtAddr ( KInetAddrLoop, KHttpDefaultPort ), Id (), EHttpClientFlow, THttpClientFlowQuery::ECreateNew, iChunkManager ); |
|
85 const TUid requestedUid = { CUPnPFlowFactory::iUid }; |
|
86 |
|
87 TNodeId factoryContainer = SockManGlobals::Get( )->GetPlaneFC( TCFPlayerRole ( TCFPlayerRole::EDataPlane ) ); |
|
88 |
|
89 RClientInterface::OpenPostMessageClose ( NodeId (), TNodeCtxId ( KActivityNull, factoryContainer ), TCFFactory::TFindOrCreatePeer ( TCFPlayerRole::EDataPlane, requestedUid, &flowQuery ).CRef () ); |
|
90 |
|
91 iState = ESendRequestData; |
|
92 iStatus = KRequestPending; |
|
93 Reschedule(); |
|
94 return EPass; |
|
95 } |
|
96 |
|
97 case ESendRequestData: |
|
98 { |
|
99 iLogger.WriteFormat(_L("<i>Client is Created</i>")); |
|
100 iLogger.WriteFormat(_L("<i>Send data..... </i>")); |
|
101 |
|
102 RMemChunk bodyBuf; |
|
103 RMemChunk uriBuf; |
|
104 uriBuf.CreateL ( _L8 ("http://127.0.0.1:9999"), iAllocator ); |
|
105 TUpnpMessage::TUPnPClientRequestInfo msg ( HTTP::EGET, uriBuf, bodyBuf, NULL ); |
|
106 iClientId.Node ().ReceivedL ( TNodeCtxId ( KActivityNull, Id () ), TNodeCtxId ( KActivityNull, iClientId ), msg ); |
|
107 |
|
108 iState = ECleanup; |
|
109 iStatus = KRequestPending; |
|
110 Reschedule (); |
|
111 return EPass; |
|
112 } |
|
113 |
|
114 case ECleanup: |
|
115 { |
|
116 delete iTestServer; |
|
117 // cleanup tcp client flow |
|
118 delete reinterpret_cast<CHttpClientFlow*> ( iClientId.Ptr () ); |
|
119 iTimer.After ( iStatus, 60000000 ); //10 secs |
|
120 iState = EComplete; |
|
121 iStatus = KRequestPending; |
|
122 Reschedule (); |
|
123 return EPass; |
|
124 } |
|
125 case EComplete: |
|
126 { |
|
127 iLogger.WriteFormat(_L("<i>TestCase: Complete..... </i>")); |
|
128 return EPass; |
|
129 } |
|
130 |
|
131 default: |
|
132 iLogger.WriteFormat(_L("<i> Failed: TestCase:..... </i>")); |
|
133 ASSERT(0); |
|
134 return EFail; |
|
135 } |
|
136 } |
|
137 |
|
138 void CTcpClientTestUPnP3::OnTestServerEventL ( TInt aError ) |
|
139 { |
|
140 CompleteSelf ( aError ); |
|
141 } |
|
142 |
|
143 MTcpClientTestCase* CTcpClientTestUPnP3::GetTestCase () |
|
144 { |
|
145 return this; |
|
146 } |
|
147 |
|
148 CTestExecuteLogger& CTcpClientTestUPnP3::GetLogger ( ) |
|
149 { |
|
150 return iLogger; |
|
151 } |
|
152 |
|
153 |
|
154 void CTcpClientTestUPnP3::ReceivedL ( const TRuntimeCtxId& /*aSender*/, const TNodeId& /*aRecipient*/, TSignatureBase& aMessage ) |
|
155 { |
|
156 if ( aMessage.IsMessage<TCFFactory::TPeerFoundOrCreated> () ) |
|
157 { |
|
158 const TCFFactory::TPeerFoundOrCreated& msg = message_cast < const TCFFactory::TPeerFoundOrCreated > ( aMessage ); |
|
159 iClientId = msg.iNodeId; |
|
160 CompleteSelf ( KErrNone ); |
|
161 } |
|
162 else if ( aMessage.IsMessage<TUpnpMessage::TResponse > () ) |
|
163 { |
|
164 |
|
165 CompleteSelf(EPass); |
|
166 } |
|
167 else if ( aMessage.IsMessage<TEBase::TError > () ) |
|
168 { |
|
169 iLogger.WriteFormat(_L("<i>TEBase::TError..... </i>")); |
|
170 CompleteSelf(EFail); |
|
171 } |
|
172 |
|
173 } |
|
174 |
|
175 const TDesC& CTcpClientTestUPnP3::TestCaseName () const |
|
176 { |
|
177 _LIT ( KTxtTitle, "Defect Fix CINC077703More" ); |
|
178 return KTxtTitle (); |
|
179 } |
|
180 |
|
181 TInt CTcpClientTestUPnP3::TotalTransactionCount () const |
|
182 { |
|
183 return KTransactionCount; |
|
184 } |
|
185 |
|
186 const TDesC8& CTcpClientTestUPnP3::GetRawRequest ( TInt aTransIndex ) |
|
187 { |
|
188 __ASSERT_ALWAYS ( aTransIndex < KTransactionCount, User::Invariant () ); |
|
189 return KTxtRawRequest (); |
|
190 } |
|
191 |
|
192 const TDesC8& CTcpClientTestUPnP3::GetRawResponse ( TInt aTransIndex ) |
|
193 { |
|
194 __ASSERT_ALWAYS( aTransIndex < KTransactionCount, User::Invariant () ); |
|
195 return KTxtRawResponse1 (); |
|
196 } |
|
197 |
|
198 TInt CTcpClientTestUPnP3::TransactionCount () const |
|
199 { |
|
200 return KTransactionCount; |
|
201 } |
|
202 |
|
203 //////////////////////////////////////////////////////////////////////////////////////////// |
|
204 _LIT8 ( KTxtRawResponse2, "HTTP/1.1 200 OK\r\nConnection: close-close\r\nContent-Length: 0\r\n\r\n" ); |
|
205 |
|
206 CTcpClientTestUPnP15* CTcpClientTestUPnP15::NewL ( CProxyProvd* aProvd ) |
|
207 { |
|
208 CTcpClientTestUPnP15* ret = new ( ELeave ) CTcpClientTestUPnP15 ( aProvd ); |
|
209 CleanupStack::PushL ( ret ); |
|
210 ret->ConstructL (); |
|
211 CleanupStack::Pop ( ret ); |
|
212 return ret; |
|
213 } |
|
214 |
|
215 CTcpClientTestUPnP15::CTcpClientTestUPnP15 ( CProxyProvd* aProvd ) : |
|
216 CTcpClientTestBase(aProvd), iTestServer(NULL) |
|
217 { |
|
218 } |
|
219 |
|
220 CTcpClientTestUPnP15::~CTcpClientTestUPnP15 () |
|
221 { |
|
222 iTimer.Close (); |
|
223 } |
|
224 |
|
225 void CTcpClientTestUPnP15::ConstructL() |
|
226 { |
|
227 iTimer.CreateLocal (); |
|
228 } |
|
229 |
|
230 TVerdict CTcpClientTestUPnP15::RunTestL() |
|
231 { |
|
232 switch ( iState ) |
|
233 { |
|
234 case ECreateTestServer: |
|
235 { |
|
236 iLogger.WriteFormat(_L("<i>Creating TestServer..... </i>")); |
|
237 |
|
238 iTestServer = CTestTcpServer::NewL ( *this ); |
|
239 |
|
240 iState = ECreateTestClient; |
|
241 iStatus = KRequestPending; |
|
242 Reschedule(); |
|
243 return EPass; |
|
244 } |
|
245 |
|
246 case ECreateTestClient: |
|
247 { |
|
248 iLogger.WriteFormat(_L("<i>TestServer is created..... </i>")); |
|
249 iLogger.WriteFormat(_L("<i>Creating TestClient..... </i>")); |
|
250 |
|
251 THttpClientFlowQuery flowQuery ( TAppProtAddr ( KInetAddrLoop, KHttpDefaultPort ), Id (), EHttpClientFlow, THttpClientFlowQuery::ECreateNew, iChunkManager ); |
|
252 const TUid requestedUid = { CUPnPFlowFactory::iUid }; |
|
253 |
|
254 TNodeId factoryContainer = SockManGlobals::Get( )->GetPlaneFC( TCFPlayerRole ( TCFPlayerRole::EDataPlane ) ); |
|
255 |
|
256 RClientInterface::OpenPostMessageClose ( NodeId (), TNodeCtxId ( KActivityNull, factoryContainer ), TCFFactory::TFindOrCreatePeer ( TCFPlayerRole::EDataPlane, requestedUid, &flowQuery ).CRef () ); |
|
257 |
|
258 iState = ESendRequestData; |
|
259 iStatus = KRequestPending; |
|
260 Reschedule(); |
|
261 return EPass; |
|
262 } |
|
263 |
|
264 case ESendRequestData: |
|
265 { |
|
266 iLogger.WriteFormat(_L("<i>Client is Created</i>")); |
|
267 iLogger.WriteFormat(_L("<i>Send data..... </i>")); |
|
268 |
|
269 RMemChunk bodyBuf; |
|
270 RMemChunk uriBuf; |
|
271 uriBuf.CreateL ( _L8 ("http://127.0.0.1:9999"), iAllocator ); |
|
272 TUpnpMessage::TUPnPClientRequestInfo msg ( HTTP::EGET, uriBuf, bodyBuf, NULL ); |
|
273 iClientId.Node ().ReceivedL ( TNodeCtxId ( KActivityNull, Id () ), TNodeCtxId ( KActivityNull, iClientId ), msg ); |
|
274 |
|
275 iState = ECleanup; |
|
276 iStatus = KRequestPending; |
|
277 Reschedule (); |
|
278 return EPass; |
|
279 } |
|
280 |
|
281 case ECleanup: |
|
282 { |
|
283 delete iTestServer; |
|
284 // cleanup tcp client flow |
|
285 delete reinterpret_cast<CHttpClientFlow*> ( iClientId.Ptr () ); |
|
286 iTimer.After ( iStatus, 60000000 ); //10 secs |
|
287 iState = EComplete; |
|
288 iStatus = KRequestPending; |
|
289 Reschedule (); |
|
290 return EPass; |
|
291 } |
|
292 case EComplete: |
|
293 { |
|
294 iLogger.WriteFormat(_L("<i>TestCase: Complete..... </i>")); |
|
295 return EPass; |
|
296 } |
|
297 |
|
298 default: |
|
299 iLogger.WriteFormat(_L("<i> Failed: TestCase:..... </i>")); |
|
300 ASSERT(0); |
|
301 return EFail; |
|
302 } |
|
303 } |
|
304 |
|
305 void CTcpClientTestUPnP15::OnTestServerEventL ( TInt aError ) |
|
306 { |
|
307 CompleteSelf ( aError ); |
|
308 } |
|
309 |
|
310 MTcpClientTestCase* CTcpClientTestUPnP15::GetTestCase () |
|
311 { |
|
312 return this; |
|
313 } |
|
314 |
|
315 CTestExecuteLogger& CTcpClientTestUPnP15::GetLogger ( ) |
|
316 { |
|
317 return iLogger; |
|
318 } |
|
319 |
|
320 |
|
321 void CTcpClientTestUPnP15::ReceivedL ( const TRuntimeCtxId& /*aSender*/, const TNodeId& /*aRecipient*/, TSignatureBase& aMessage ) |
|
322 { |
|
323 if ( aMessage.IsMessage<TCFFactory::TPeerFoundOrCreated> () ) |
|
324 { |
|
325 const TCFFactory::TPeerFoundOrCreated& msg = message_cast < const TCFFactory::TPeerFoundOrCreated > ( aMessage ); |
|
326 iClientId = msg.iNodeId; |
|
327 CompleteSelf ( KErrNone ); |
|
328 } |
|
329 else if ( aMessage.IsMessage<TUpnpMessage::TResponse > () ) |
|
330 { |
|
331 |
|
332 CompleteSelf(EPass); |
|
333 } |
|
334 else if ( aMessage.IsMessage<TEBase::TError > () ) |
|
335 { |
|
336 iLogger.WriteFormat(_L("<i>TEBase::TError..... </i>")); |
|
337 CompleteSelf(EFail); |
|
338 } |
|
339 |
|
340 } |
|
341 |
|
342 const TDesC& CTcpClientTestUPnP15::TestCaseName () const |
|
343 { |
|
344 _LIT ( KTxtTitle, "Defect Fix CINC077703More" ); |
|
345 return KTxtTitle (); |
|
346 } |
|
347 |
|
348 TInt CTcpClientTestUPnP15::TotalTransactionCount () const |
|
349 { |
|
350 return KTransactionCount; |
|
351 } |
|
352 |
|
353 const TDesC8& CTcpClientTestUPnP15::GetRawRequest ( TInt aTransIndex ) |
|
354 { |
|
355 __ASSERT_ALWAYS ( aTransIndex < KTransactionCount, User::Invariant () ); |
|
356 return KTxtRawRequest (); |
|
357 } |
|
358 |
|
359 const TDesC8& CTcpClientTestUPnP15::GetRawResponse ( TInt aTransIndex ) |
|
360 { |
|
361 __ASSERT_ALWAYS( aTransIndex < KTransactionCount, User::Invariant () ); |
|
362 return KTxtRawResponse2 (); |
|
363 } |
|
364 |
|
365 TInt CTcpClientTestUPnP15::TransactionCount () const |
|
366 { |
|
367 return KTransactionCount; |
|
368 } |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |