|
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 #include "CTcpServerTestCase.h" |
|
27 |
|
28 #include <httperr.h> |
|
29 #include "CTcpServerTestUPnP26.h" |
|
30 |
|
31 using namespace Messages; |
|
32 |
|
33 //------------------------------------------------------------// |
|
34 /////////////////// CTcpServerTestUPnP26 ///////////////////////// |
|
35 ////// Testcase: Send the test data from the test client///////// |
|
36 //------------------------------------------------------------// |
|
37 |
|
38 _LIT8 ( KTestUPnPServiceUri,"http://127.0.0.1:80/testserviceuri1" ); |
|
39 _LIT8 ( KData, "GET /testserviceuri1 HTTP/1.1\r\nHOST: 127.0.0.1:80\r\nConnection:Close\r\n\r\n"); |
|
40 _LIT8 ( KExpectedResponse, "HTTP/1.1 200 OK"); |
|
41 _LIT8 ( KResponseData, "Test Server"); |
|
42 |
|
43 CTcpServerTestUPnP26* CTcpServerTestUPnP26::NewL ( CProxyProvd* aProvd ) |
|
44 { |
|
45 CTcpServerTestUPnP26* ret = new ( ELeave ) CTcpServerTestUPnP26 ( aProvd ); |
|
46 CleanupStack::PushL ( ret ); |
|
47 ret->ConstructL (); |
|
48 CleanupStack::Pop ( ret ); |
|
49 return ret; |
|
50 } |
|
51 |
|
52 CTcpServerTestUPnP26::CTcpServerTestUPnP26 ( CProxyProvd* aProvd ) : |
|
53 CTcpServerTestCase ( aProvd ) |
|
54 { |
|
55 } |
|
56 |
|
57 CTcpServerTestUPnP26::~CTcpServerTestUPnP26 () |
|
58 { |
|
59 |
|
60 } |
|
61 |
|
62 void CTcpServerTestUPnP26::ConstructL () |
|
63 { |
|
64 CTcpServerTestCase::ConstructL(KTestUPnPServiceUri); |
|
65 } |
|
66 |
|
67 TVerdict CTcpServerTestUPnP26::RunTestL () |
|
68 { |
|
69 switch ( iState ) |
|
70 { |
|
71 |
|
72 case ESendData: |
|
73 { |
|
74 iSendChain.CreateL ( KData ); |
|
75 iSocketHandler.Send ( iSendChain ); |
|
76 |
|
77 iState = ESendStopServer; |
|
78 iStatus = KRequestPending; |
|
79 Reschedule (); |
|
80 return EPass; |
|
81 } |
|
82 |
|
83 default: |
|
84 { |
|
85 return CTcpServerTestCase::RunTestL(); |
|
86 } |
|
87 } |
|
88 } |
|
89 |
|
90 |
|
91 void CTcpServerTestUPnP26::RecvComplete ( RMBufChain& aData ) |
|
92 { |
|
93 RBuf8 responseBuf; |
|
94 responseBuf.CreateMax ( aData.Length () ); |
|
95 aData.CopyOut ( responseBuf ); |
|
96 aData.Free (); |
|
97 |
|
98 if ( responseBuf.FindF ( KExpectedResponse ) != KErrNotFound ) |
|
99 { |
|
100 iSocketHandler.Recv (); |
|
101 responseBuf.Close (); |
|
102 return; |
|
103 } |
|
104 |
|
105 if ( responseBuf.FindF ( KResponseData ) == KErrNotFound ) |
|
106 { |
|
107 iResponse = EFail; // test case failed |
|
108 } |
|
109 else |
|
110 { |
|
111 iResponse = EPass; // test case passed |
|
112 } |
|
113 |
|
114 responseBuf.Close (); |
|
115 CompleteSelf ( KErrNone ); |
|
116 } |
|
117 |
|
118 void CTcpServerTestUPnP26::ReceivedL ( const TRuntimeCtxId& /*aSender*/, const TNodeId& /*aRecipient*/, TSignatureBase& aMessage ) |
|
119 { |
|
120 if ( aMessage.IsMessage<TCFFactory::TPeerFoundOrCreated> () ) |
|
121 { |
|
122 const TCFFactory::TPeerFoundOrCreated& msg = message_cast < const TCFFactory::TPeerFoundOrCreated > ( aMessage ); |
|
123 iTcpServer = msg.iNodeId; |
|
124 CompleteSelf ( KErrNone ); |
|
125 } |
|
126 else if ( aMessage.IsMessage<TCFDataClient::TStarted> () |
|
127 || aMessage.IsMessage<TCFDataClient::TStopped> () ) |
|
128 { |
|
129 CompleteSelf ( KErrNone ); |
|
130 } |
|
131 else if ( aMessage.IsMessage<TUpnpMessage::TUPnPRequestInfo> ()) |
|
132 { |
|
133 TUpnpMessage::TUPnPRequestInfo& requestMsg = message_cast< TUpnpMessage::TUPnPRequestInfo > ( aMessage ); |
|
134 CTransaction* trans = static_cast<CTransaction*> ( requestMsg.iPtr ); |
|
135 RMBufChain bufChain; |
|
136 bufChain.CreateL ( KResponseData ); |
|
137 trans->AddBodyPart ( bufChain ); |
|
138 |
|
139 TUpnpMessage::TUPnPResponseInfo msg ( trans, HTTPStatus::EOk, NULL ); |
|
140 RClientInterface::OpenPostMessageClose ( TNodeCtxId ( KActivityNull, Id () ), TNodeCtxId ( KActivityNull, iTcpServer ), msg ); |
|
141 } |
|
142 } |
|
143 |