|
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 "CTcpClientTestUPnP4.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/2.2 200 OK\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n" ); |
|
37 |
|
38 |
|
39 CTcpClientTestUPnP4* CTcpClientTestUPnP4::NewL ( CProxyProvd* aProvd ) |
|
40 { |
|
41 CTcpClientTestUPnP4* ret = new ( ELeave ) CTcpClientTestUPnP4 ( aProvd ); |
|
42 CleanupStack::PushL ( ret ); |
|
43 ret->ConstructL (); |
|
44 CleanupStack::Pop ( ret ); |
|
45 return ret; |
|
46 } |
|
47 |
|
48 CTcpClientTestUPnP4::CTcpClientTestUPnP4 ( CProxyProvd* aProvd ) : |
|
49 CTcpClientTestBase(aProvd), iTestServer(NULL) |
|
50 { |
|
51 } |
|
52 |
|
53 CTcpClientTestUPnP4::~CTcpClientTestUPnP4 () |
|
54 { |
|
55 iTimer.Close (); |
|
56 } |
|
57 |
|
58 void CTcpClientTestUPnP4::ConstructL() |
|
59 { |
|
60 iTimer.CreateLocal (); |
|
61 } |
|
62 |
|
63 TVerdict CTcpClientTestUPnP4::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 CTcpClientTestUPnP4::OnTestServerEventL ( TInt aError ) |
|
139 { |
|
140 CompleteSelf ( aError ); |
|
141 } |
|
142 |
|
143 MTcpClientTestCase* CTcpClientTestUPnP4::GetTestCase () |
|
144 { |
|
145 return this; |
|
146 } |
|
147 |
|
148 CTestExecuteLogger& CTcpClientTestUPnP4::GetLogger ( ) |
|
149 { |
|
150 return iLogger; |
|
151 } |
|
152 |
|
153 |
|
154 void CTcpClientTestUPnP4::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& CTcpClientTestUPnP4::TestCaseName () const |
|
176 { |
|
177 _LIT ( KTxtTitle, "Defect Fix CINC077703More" ); |
|
178 return KTxtTitle (); |
|
179 } |
|
180 |
|
181 TInt CTcpClientTestUPnP4::TotalTransactionCount () const |
|
182 { |
|
183 return KTransactionCount; |
|
184 } |
|
185 |
|
186 const TDesC8& CTcpClientTestUPnP4::GetRawRequest ( TInt aTransIndex ) |
|
187 { |
|
188 __ASSERT_ALWAYS ( aTransIndex < KTransactionCount, User::Invariant () ); |
|
189 return KTxtRawRequest (); |
|
190 } |
|
191 |
|
192 const TDesC8& CTcpClientTestUPnP4::GetRawResponse ( TInt aTransIndex ) |
|
193 { |
|
194 __ASSERT_ALWAYS( aTransIndex < KTransactionCount, User::Invariant () ); |
|
195 return KTxtRawResponse1 (); |
|
196 } |
|
197 |
|
198 TInt CTcpClientTestUPnP4::TransactionCount () const |
|
199 { |
|
200 return KTransactionCount; |
|
201 } |
|
202 |
|
203 |
|
204 |