|
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 |
|
29 #include "CTcpClientTestUPnP6.h" |
|
30 #include "upnpserverconstants.h" |
|
31 |
|
32 const TUint16 KActivityNull = 0; |
|
33 const TUint KHttpDefaultPort = 80; |
|
34 |
|
35 |
|
36 const TUint KTransactionCount = 1; |
|
37 _LIT8 ( KTxtRawRequest, "POST / HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 330\r\nContent-Type: text/xml; charset=utf-8\r\nSoapAction: :urn:shemas-upnp-org:control-1-0#QueryStateVariableResponse:\r\n\r\n" ); |
|
38 _LIT8 ( KTxtRawResponse1, "HTTP/1.1 200 OK\r\nContent-Length: 330\r\n\r\n<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:QueryStateVariableResponse xmlns:u=\"urn:shemas-upnp-org:control-1-0\"><return>Query return value</return></u:QueryStateVariableResponse></s:Body></s:Envelope>\r\n\r\n" ); |
|
39 _LIT8 ( KData1, "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:QueryStateVariableResponse xmlns:u=\"urn:shemas-upnp-org:control-1-0\"><return>Query return value</return></u:QueryStateVariableResponse></s:Body></s:Envelope>" ); |
|
40 |
|
41 CTcpClientTestUPnP6* CTcpClientTestUPnP6::NewL ( CProxyProvd* aProvd ) |
|
42 { |
|
43 CTcpClientTestUPnP6* ret = new ( ELeave ) CTcpClientTestUPnP6 ( aProvd ); |
|
44 CleanupStack::PushL ( ret ); |
|
45 ret->ConstructL (); |
|
46 CleanupStack::Pop ( ret ); |
|
47 return ret; |
|
48 } |
|
49 |
|
50 CTcpClientTestUPnP6::CTcpClientTestUPnP6 ( CProxyProvd* aProvd ) : |
|
51 CTcpClientTestBase(aProvd), iTestServer(NULL) |
|
52 { |
|
53 } |
|
54 |
|
55 CTcpClientTestUPnP6::~CTcpClientTestUPnP6 () |
|
56 { |
|
57 iTimer.Close (); |
|
58 } |
|
59 |
|
60 void CTcpClientTestUPnP6::ConstructL() |
|
61 { |
|
62 iTimer.CreateLocal (); |
|
63 } |
|
64 |
|
65 TVerdict CTcpClientTestUPnP6::RunTestL() |
|
66 { |
|
67 switch ( iState ) |
|
68 { |
|
69 case ECreateTestServer: |
|
70 { |
|
71 iLogger.WriteFormat(_L("<i>Creating TestServer..... </i>")); |
|
72 |
|
73 iTestServer = CTestTcpServer::NewL ( *this ); |
|
74 |
|
75 iState = ECreateTestClient; |
|
76 iStatus = KRequestPending; |
|
77 Reschedule(); |
|
78 return EPass; |
|
79 } |
|
80 |
|
81 case ECreateTestClient: |
|
82 { |
|
83 iLogger.WriteFormat(_L("<i>TestServer is created..... </i>")); |
|
84 iLogger.WriteFormat(_L("<i>Creating TestClient..... </i>")); |
|
85 |
|
86 THttpClientFlowQuery flowQuery ( TAppProtAddr ( KInetAddrLoop, KHttpDefaultPort ), Id (), EHttpClientFlow, THttpClientFlowQuery::ECreateNew, iChunkManager ); |
|
87 const TUid requestedUid = { CUPnPFlowFactory::iUid }; |
|
88 |
|
89 TNodeId factoryContainer = SockManGlobals::Get( )->GetPlaneFC( TCFPlayerRole ( TCFPlayerRole::EDataPlane ) ); |
|
90 |
|
91 RClientInterface::OpenPostMessageClose ( NodeId (), TNodeCtxId ( KActivityNull, factoryContainer ), TCFFactory::TFindOrCreatePeer ( TCFPlayerRole::EDataPlane, requestedUid, &flowQuery ).CRef () ); |
|
92 |
|
93 iState = ESendRequestData; |
|
94 iStatus = KRequestPending; |
|
95 Reschedule(); |
|
96 return EPass; |
|
97 } |
|
98 |
|
99 case ESendRequestData: |
|
100 { |
|
101 iLogger.WriteFormat(_L("<i>Client is Created</i>")); |
|
102 iLogger.WriteFormat(_L("<i>Send data..... </i>")); |
|
103 |
|
104 TPtrC8 data(KData1); |
|
105 |
|
106 iSSP->SetOption(KCHOptionLevel, KCHAbsoluteUri, _L8 ("http://127.0.0.1")); |
|
107 |
|
108 TCHMessageOption option ( 1, data.Length() ); |
|
109 TPckg < TCHMessageOption > optionBuf ( option ); |
|
110 |
|
111 iSSP->SetOption(KCHOptionLevel, KCHMaxLength, optionBuf); |
|
112 |
|
113 RMBufChain bodyBuf; |
|
114 bodyBuf.CreateL(KData1); |
|
115 iSSPData->Write(bodyBuf, 0, NULL); |
|
116 /* |
|
117 RMBufChain bodyBuf1; |
|
118 bodyBuf1.CreateL(KData1); |
|
119 iSSPData->Write(bodyBuf1, 0, NULL); |
|
120 */ |
|
121 iState = ECleanup; |
|
122 iStatus = KRequestPending; |
|
123 Reschedule (); |
|
124 return EPass; |
|
125 } |
|
126 |
|
127 case ECleanup: |
|
128 { |
|
129 delete iTestServer; |
|
130 |
|
131 // cleanup tcp client flow |
|
132 delete reinterpret_cast<CHttpClientFlow*> ( iClientId.Ptr () ); |
|
133 iTimer.After ( iStatus, 60000000 ); //10 secs |
|
134 iState = EComplete; |
|
135 iStatus = KRequestPending; |
|
136 Reschedule (); |
|
137 return EPass; |
|
138 } |
|
139 case EComplete: |
|
140 { |
|
141 iLogger.WriteFormat(_L("<i>TestCase: Complete..... </i>")); |
|
142 return EPass; |
|
143 } |
|
144 |
|
145 default: |
|
146 iLogger.WriteFormat(_L("<i> Failed: TestCase:..... </i>")); |
|
147 ASSERT(0); |
|
148 return EFail; |
|
149 } |
|
150 } |
|
151 |
|
152 void CTcpClientTestUPnP6::OnTestServerEventL ( TInt aError ) |
|
153 { |
|
154 CompleteSelf ( aError ); |
|
155 } |
|
156 |
|
157 MTcpClientTestCase* CTcpClientTestUPnP6::GetTestCase () |
|
158 { |
|
159 return this; |
|
160 } |
|
161 |
|
162 CTestExecuteLogger& CTcpClientTestUPnP6::GetLogger ( ) |
|
163 { |
|
164 return iLogger; |
|
165 } |
|
166 |
|
167 |
|
168 void CTcpClientTestUPnP6::ReceivedL ( const TRuntimeCtxId& /*aSender*/, const TNodeId& /*aRecipient*/, TSignatureBase& aMessage ) |
|
169 { |
|
170 if ( aMessage.IsMessage<TCFFactory::TPeerFoundOrCreated> () ) |
|
171 { |
|
172 const TCFFactory::TPeerFoundOrCreated& msg = message_cast < const TCFFactory::TPeerFoundOrCreated > ( aMessage ); |
|
173 iClientId = msg.iNodeId; |
|
174 |
|
175 |
|
176 iFlow = mcfnode_cast<CSubConnectionFlowBase>( |
|
177 reinterpret_cast<Messages::ANode*>( iClientId.Ptr())); |
|
178 |
|
179 |
|
180 // Perform the binding to the flow below |
|
181 iFlowBinder = iFlow->GetBinderControlL(); |
|
182 iSSP = iFlowBinder->GetControlL(KSockStream, *this); |
|
183 iSSPData = iFlowBinder->BindL(*this); |
|
184 |
|
185 |
|
186 CompleteSelf ( KErrNone ); |
|
187 } |
|
188 else if ( aMessage.IsMessage<TUpnpMessage::TResponse > () ) |
|
189 { |
|
190 |
|
191 CompleteSelf(EPass); |
|
192 } |
|
193 else if ( aMessage.IsMessage<TEBase::TError > () ) |
|
194 { |
|
195 iLogger.WriteFormat(_L("<i>TEBase::TError..... </i>")); |
|
196 CompleteSelf(EFail); |
|
197 } |
|
198 |
|
199 } |
|
200 |
|
201 const TDesC& CTcpClientTestUPnP6::TestCaseName () const |
|
202 { |
|
203 _LIT ( KTxtTitle, "Defect Fix CINC077703More" ); |
|
204 return KTxtTitle (); |
|
205 } |
|
206 |
|
207 TInt CTcpClientTestUPnP6::TotalTransactionCount () const |
|
208 { |
|
209 return KTransactionCount; |
|
210 } |
|
211 |
|
212 const TDesC8& CTcpClientTestUPnP6::GetRawRequest ( TInt aTransIndex ) |
|
213 { |
|
214 __ASSERT_ALWAYS ( aTransIndex < KTransactionCount, User::Invariant () ); |
|
215 return KTxtRawRequest (); |
|
216 } |
|
217 |
|
218 const TDesC8& CTcpClientTestUPnP6::GetRawResponse ( TInt aTransIndex ) |
|
219 { |
|
220 __ASSERT_ALWAYS( aTransIndex < KTransactionCount, User::Invariant () ); |
|
221 return KTxtRawResponse1 (); |
|
222 } |
|
223 |
|
224 TInt CTcpClientTestUPnP6::TransactionCount () const |
|
225 { |
|
226 return KTransactionCount; |
|
227 } |
|
228 |
|
229 void CTcpClientTestUPnP6::NewData(TUint aCount) |
|
230 { |
|
231 RMBufChain data; |
|
232 RBuf8 resData; |
|
233 |
|
234 iLogger.WriteFormat(_L("<i>NewData..... </i>")); |
|
235 iSSP->GetOption(1,KCHMaxLength,resData); |
|
236 resData.Create( aCount ); |
|
237 iSSP->GetOption(KCHOptionLevel,KCHMaxLength,resData); |
|
238 TInt len = *(TUint*) resData.Ptr(); |
|
239 resData.Close(); |
|
240 |
|
241 iSSPData->GetData(data,len,0); |
|
242 resData.Create( len ); |
|
243 data.CopyOut(resData); |
|
244 resData.Close(); |
|
245 resData.Create( aCount ); |
|
246 iSSP->GetOption(KCHOptionLevel,KCHLastMessage,resData); |
|
247 TBool isLastMsg = *(TUint*) resData.Ptr(); |
|
248 resData.Close(); |
|
249 data.Init(); |
|
250 |
|
251 if(isLastMsg) |
|
252 { |
|
253 iLogger.WriteFormat(_L("<i>NewData...Last Msg.. </i>")); |
|
254 CompleteSelf ( KErrNone ); |
|
255 } |
|
256 } |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |