|
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_thread.h> |
|
20 #include <comms-infras/ss_nodemessages_factory.h> |
|
21 #include <comms-infras/ss_nodemessages_dataclient.h> |
|
22 #include "ptcpservertests.h" |
|
23 #include "upnp_cf_msgs.h" |
|
24 #include "upnpflowbase.h" |
|
25 #include "upnpflowfactory.h" |
|
26 |
|
27 #include "CTcpServerTestUPnP9.h" |
|
28 |
|
29 using namespace Messages; |
|
30 const TUint16 KActivityNull = 0; |
|
31 const TUint KHttpDefaultPort = 80; |
|
32 |
|
33 //------------------------------------------------------------// |
|
34 /////////////////// CTcpServerTestUPnP9 ///////////////////////// |
|
35 ////// Testcase: Send the test data from the test client///////// |
|
36 //------------------------------------------------------------// |
|
37 |
|
38 _LIT8 ( KTestUPnPServiceUri,"http://127.0.0.1:80/testserviceuri1" ); |
|
39 //ASSERT - Defect to be fixed. |
|
40 _LIT8 ( KConnect, "POST /testserviceuri1 HTTP/1.1\r\nHOST: 127.0.0.1:80\r\nContent-Length: 5\r\n\r\nABCDE"); |
|
41 _LIT8 ( KExpectedResponse, "HTTP/1.1 415 Unsupported Media Type"); |
|
42 |
|
43 CTcpServerTestUPnP9* CTcpServerTestUPnP9::NewL ( CProxyProvd* aProvd ) |
|
44 { |
|
45 CTcpServerTestUPnP9* ret = new ( ELeave ) CTcpServerTestUPnP9 ( aProvd ); |
|
46 CleanupStack::PushL ( ret ); |
|
47 ret->ConstructL (); |
|
48 CleanupStack::Pop ( ret ); |
|
49 return ret; |
|
50 } |
|
51 |
|
52 CTcpServerTestUPnP9::CTcpServerTestUPnP9 ( CProxyProvd* aProvd ) : |
|
53 CTcpServerTestBase ( aProvd ), iSocketHandler ( *this ), iHostAddr ( KInetAddrLoop, KHttpDefaultPort ), iState ( ECreateServer ) |
|
54 { |
|
55 } |
|
56 |
|
57 CTcpServerTestUPnP9::~CTcpServerTestUPnP9 () |
|
58 { |
|
59 iServiceUri.Close (); |
|
60 |
|
61 iSocketHandler.CancelAll (); |
|
62 iClientSocket.Close (); |
|
63 delete iSocketOpener; |
|
64 |
|
65 iTimer.Close (); |
|
66 |
|
67 TUpnpMessage::DeRegister (); |
|
68 } |
|
69 |
|
70 void CTcpServerTestUPnP9::ConstructL () |
|
71 { |
|
72 TUpnpMessage::RegisterL ( SockManGlobals::Get ()->SelfWorker ()); |
|
73 |
|
74 iServiceUri.CreateL ( KTestUPnPServiceUri ); |
|
75 |
|
76 iTimer.CreateLocal (); |
|
77 TRAPD ( err, iSocketOpener = CSocketOpener::NewL ( *this ) ); |
|
78 |
|
79 User::LeaveIfError ( err ); |
|
80 } |
|
81 |
|
82 TVerdict CTcpServerTestUPnP9::RunTestL () |
|
83 { |
|
84 switch ( iState ) |
|
85 { |
|
86 case ECreateServer: |
|
87 { |
|
88 const TUint8* uriPtr = NULL; |
|
89 uriPtr = iServiceUri.Ptr (); |
|
90 |
|
91 const TUid reqUid = { CUPnPFlowFactory::iUid }; |
|
92 THttpServerFlowQuery flowQuery ( uriPtr, |
|
93 iServiceUri.Size (), |
|
94 Id (), |
|
95 EHttpServerFlow, iChunkManager ); |
|
96 TCFPlayerRole playerRole ( TCFPlayerRole::EDataPlane ); |
|
97 |
|
98 TCFFactory::TFindOrCreatePeer msg ( TCFPlayerRole::EDataPlane, reqUid, &flowQuery ); |
|
99 TNodeId factoryContainer = SockManGlobals::Get()->GetPlaneFC( playerRole ); |
|
100 |
|
101 RClientInterface::OpenPostMessageClose ( Id (), TNodeCtxId ( KActivityNull, factoryContainer ), TCFFactory::TFindOrCreatePeer ( TCFPlayerRole::EDataPlane, reqUid, &flowQuery ).CRef () ); |
|
102 |
|
103 iState = EStartServer; |
|
104 iStatus = KRequestPending; |
|
105 Reschedule (); |
|
106 return EPass; |
|
107 } |
|
108 |
|
109 case EStartServer: |
|
110 { |
|
111 RClientInterface::OpenPostMessageClose ( TNodeCtxId ( KActivityNull, Id () ), TNodeCtxId ( KActivityNull, iTcpServer ), TCFDataClient::TStart ().CRef () ); |
|
112 |
|
113 iState = EOpenClientSocketAndConnect; |
|
114 iStatus = KRequestPending; |
|
115 Reschedule (); |
|
116 return EPass; |
|
117 } |
|
118 |
|
119 case EOpenClientSocketAndConnect: |
|
120 { |
|
121 iSocketOpener->MakeSocket ( KAfInet, KSockStream, KProtocolInetTcp ); |
|
122 |
|
123 iState = ESendData; |
|
124 iStatus = KRequestPending; |
|
125 Reschedule (); |
|
126 return EPass; |
|
127 } |
|
128 |
|
129 case ESendData: |
|
130 { |
|
131 iSendChain.CreateL ( KConnect ); |
|
132 iSocketHandler.Send ( iSendChain ); |
|
133 |
|
134 iState = ESendStopServer; |
|
135 iStatus = KRequestPending; |
|
136 Reschedule (); |
|
137 return EPass; |
|
138 } |
|
139 |
|
140 // just to make sure production objects are cleaned-up properly. |
|
141 case ESendStopServer: |
|
142 { |
|
143 // cleanup tcp server flow |
|
144 RClientInterface::OpenPostMessageClose ( TNodeCtxId ( KActivityNull, Id () ), TNodeCtxId ( KActivityNull, iTcpServer ), TCFDataClient::TStop ( KErrNone ).CRef () ); |
|
145 |
|
146 iState = EServerStopped; |
|
147 iStatus = KRequestPending; |
|
148 Reschedule (); |
|
149 return EPass; |
|
150 } |
|
151 |
|
152 case EServerStopped: |
|
153 { |
|
154 // cleanup udp server flow |
|
155 RClientInterface::OpenPostMessageClose ( TNodeCtxId ( KActivityNull, Id () ), TNodeCtxId ( KActivityNull, iTcpServer ), TEChild::TDestroy ().CRef () ); |
|
156 |
|
157 iTimer.After ( iStatus, 1000000 ); //1secs |
|
158 iState = ECleanup; |
|
159 iStatus = KRequestPending; |
|
160 Reschedule (); |
|
161 return EPass; |
|
162 } |
|
163 |
|
164 case ECleanup: |
|
165 { |
|
166 return iResponse; // Here the final test case is passed back to the RSocket::Ioctl |
|
167 } |
|
168 |
|
169 default: |
|
170 { |
|
171 iLogger.WriteFormat(_L("<i> Failed: TestCase:..... </i>")); |
|
172 ASSERT(0); |
|
173 return EFail; |
|
174 } |
|
175 } |
|
176 } |
|
177 |
|
178 void CTcpServerTestUPnP9::OpenComplete ( RInternalSocket& aSocket ) |
|
179 { |
|
180 iClientSocket = aSocket; |
|
181 iSocketHandler.Attach ( aSocket ); |
|
182 |
|
183 iSocketHandler.Connect ( iHostAddr ); |
|
184 } |
|
185 |
|
186 void CTcpServerTestUPnP9::ConnectComplete () |
|
187 { |
|
188 CompleteSelf ( KErrNone ); |
|
189 } |
|
190 |
|
191 void CTcpServerTestUPnP9::SendComplete ( TInt /*aLength*/ ) |
|
192 { |
|
193 iSendChain.Init (); |
|
194 iSocketHandler.Recv (); |
|
195 } |
|
196 |
|
197 void CTcpServerTestUPnP9::RecvComplete ( RMBufChain& aData ) |
|
198 { |
|
199 RBuf8 responseBuf; |
|
200 responseBuf.CreateMax ( aData.Length () ); |
|
201 aData.CopyOut ( responseBuf ); |
|
202 aData.Free (); |
|
203 |
|
204 if ( responseBuf.FindF ( KExpectedResponse ) == KErrNotFound ) |
|
205 { |
|
206 iResponse = EFail; // test case failed |
|
207 } |
|
208 else |
|
209 { |
|
210 iResponse = EPass; // test case passed |
|
211 } |
|
212 |
|
213 responseBuf.Close (); |
|
214 CompleteSelf ( KErrNone ); |
|
215 } |
|
216 |
|
217 void CTcpServerTestUPnP9::ReceivedL ( const TRuntimeCtxId& /*aSender*/, const TNodeId& /*aRecipient*/, TSignatureBase& aMessage ) |
|
218 { |
|
219 if ( aMessage.IsMessage<TCFFactory::TPeerFoundOrCreated> () ) |
|
220 { |
|
221 const TCFFactory::TPeerFoundOrCreated& msg = message_cast < const TCFFactory::TPeerFoundOrCreated > ( aMessage ); |
|
222 iTcpServer = msg.iNodeId; |
|
223 CompleteSelf ( KErrNone ); |
|
224 } |
|
225 else if ( aMessage.IsMessage<TCFDataClient::TStarted> () |
|
226 || aMessage.IsMessage<TCFDataClient::TStopped> () ) |
|
227 { |
|
228 CompleteSelf ( KErrNone ); |
|
229 } |
|
230 } |
|
231 |