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