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