|
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 "CTcpClientTestUPnP7.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:Body1></s:Envelope>" ); |
|
40 |
|
41 CTcpClientTestUPnP7* CTcpClientTestUPnP7::NewL ( CProxyProvd* aProvd ) |
|
42 { |
|
43 CTcpClientTestUPnP7* ret = new ( ELeave ) CTcpClientTestUPnP7 ( aProvd ); |
|
44 CleanupStack::PushL ( ret ); |
|
45 ret->ConstructL (); |
|
46 CleanupStack::Pop ( ret ); |
|
47 return ret; |
|
48 } |
|
49 |
|
50 CTcpClientTestUPnP7::CTcpClientTestUPnP7 ( CProxyProvd* aProvd ) : |
|
51 CTcpClientTestBase(aProvd), iTestServer(NULL) |
|
52 { |
|
53 } |
|
54 |
|
55 CTcpClientTestUPnP7::~CTcpClientTestUPnP7 () |
|
56 { |
|
57 iTimer.Close (); |
|
58 } |
|
59 |
|
60 void CTcpClientTestUPnP7::ConstructL() |
|
61 { |
|
62 iTimer.CreateLocal (); |
|
63 } |
|
64 |
|
65 TVerdict CTcpClientTestUPnP7::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 //////Panic in this case--Defect |
|
118 /* |
|
119 RMBufChain bodyBuf1; |
|
120 bodyBuf1.CreateL(KNullDesC8()); |
|
121 iSSPData->Write(bodyBuf1, 0, NULL); |
|
122 */ |
|
123 |
|
124 delete iTestServer; |
|
125 |
|
126 // cleanup tcp client flow |
|
127 delete reinterpret_cast<CHttpClientFlow*> ( iClientId.Ptr () ); |
|
128 iTimer.After ( iStatus, 60000000 ); //10 secs |
|
129 iState = EComplete; |
|
130 iStatus = KRequestPending; |
|
131 Reschedule (); |
|
132 return EPass; |
|
133 } |
|
134 case EComplete: |
|
135 { |
|
136 iLogger.WriteFormat(_L("<i>TestCase: Complete..... </i>")); |
|
137 return EPass; |
|
138 } |
|
139 |
|
140 default: |
|
141 iLogger.WriteFormat(_L("<i> Failed: TestCase:..... </i>")); |
|
142 ASSERT(0); |
|
143 return EFail; |
|
144 } |
|
145 } |
|
146 |
|
147 void CTcpClientTestUPnP7::OnTestServerEventL ( TInt aError ) |
|
148 { |
|
149 CompleteSelf ( aError ); |
|
150 } |
|
151 |
|
152 MTcpClientTestCase* CTcpClientTestUPnP7::GetTestCase () |
|
153 { |
|
154 return this; |
|
155 } |
|
156 |
|
157 CTestExecuteLogger& CTcpClientTestUPnP7::GetLogger ( ) |
|
158 { |
|
159 return iLogger; |
|
160 } |
|
161 |
|
162 |
|
163 void CTcpClientTestUPnP7::ReceivedL ( const TRuntimeCtxId& /*aSender*/, const TNodeId& /*aRecipient*/, TSignatureBase& aMessage ) |
|
164 { |
|
165 if ( aMessage.IsMessage<TCFFactory::TPeerFoundOrCreated> () ) |
|
166 { |
|
167 const TCFFactory::TPeerFoundOrCreated& msg = message_cast < const TCFFactory::TPeerFoundOrCreated > ( aMessage ); |
|
168 iClientId = msg.iNodeId; |
|
169 |
|
170 |
|
171 iFlow = mcfnode_cast<CSubConnectionFlowBase>( |
|
172 reinterpret_cast<Messages::ANode*>( iClientId.Ptr())); |
|
173 |
|
174 |
|
175 // Perform the binding to the flow below |
|
176 iFlowBinder = iFlow->GetBinderControlL(); |
|
177 iSSP = iFlowBinder->GetControlL(KSockStream, *this); |
|
178 iSSPData = iFlowBinder->BindL(*this); |
|
179 |
|
180 |
|
181 CompleteSelf ( KErrNone ); |
|
182 } |
|
183 else if ( aMessage.IsMessage<TUpnpMessage::TResponse > () ) |
|
184 { |
|
185 |
|
186 CompleteSelf(EPass); |
|
187 } |
|
188 else if ( aMessage.IsMessage<TEBase::TError > () ) |
|
189 { |
|
190 iLogger.WriteFormat(_L("<i>TEBase::TError..... </i>")); |
|
191 CompleteSelf(EFail); |
|
192 } |
|
193 |
|
194 } |
|
195 |
|
196 const TDesC& CTcpClientTestUPnP7::TestCaseName () const |
|
197 { |
|
198 _LIT ( KTxtTitle, "Defect Fix CINC077703More" ); |
|
199 return KTxtTitle (); |
|
200 } |
|
201 |
|
202 TInt CTcpClientTestUPnP7::TotalTransactionCount () const |
|
203 { |
|
204 return KTransactionCount; |
|
205 } |
|
206 |
|
207 const TDesC8& CTcpClientTestUPnP7::GetRawRequest ( TInt aTransIndex ) |
|
208 { |
|
209 __ASSERT_ALWAYS ( aTransIndex < KTransactionCount, User::Invariant () ); |
|
210 return KTxtRawRequest (); |
|
211 } |
|
212 |
|
213 const TDesC8& CTcpClientTestUPnP7::GetRawResponse ( TInt aTransIndex ) |
|
214 { |
|
215 __ASSERT_ALWAYS( aTransIndex < KTransactionCount, User::Invariant () ); |
|
216 return KTxtRawResponse1 (); |
|
217 } |
|
218 |
|
219 TInt CTcpClientTestUPnP7::TransactionCount () const |
|
220 { |
|
221 return KTransactionCount; |
|
222 } |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |