servicediscoveryandcontrol/pnp/test/upnp/unittests/tcpclient/src/ctcpclienttestupnp2.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 #include "CTcpClientTestUPnP2.h"
       
    29 
       
    30 const TUint16 KActivityNull = 0;
       
    31 const TUint KHttpDefaultPort = 80;
       
    32 
       
    33 
       
    34 const TUint KTransactionCount = 1;
       
    35 _LIT8 ( KTxtRawRequest, "GET / HTTP/1.1\r\nHost: [0:0:0:0:0:0:0:1]\r\nContent-Length: 0\r\n\r\n" );
       
    36 _LIT8 ( KTxtRawResponse1, "HTTP/2.2 200 OK\r\nContent-Length: 0\r\n\r\n" );
       
    37 
       
    38 
       
    39 CTcpClientTestUPnP2* CTcpClientTestUPnP2::NewL ( CProxyProvd* aProvd )
       
    40 	{
       
    41 	CTcpClientTestUPnP2* ret = new ( ELeave ) CTcpClientTestUPnP2 ( aProvd );
       
    42 	CleanupStack::PushL ( ret );
       
    43 	ret->ConstructL ();
       
    44 	CleanupStack::Pop ( ret );
       
    45 	return ret;
       
    46 	}
       
    47 
       
    48 CTcpClientTestUPnP2::CTcpClientTestUPnP2 ( CProxyProvd* aProvd ) :
       
    49 	CTcpClientTestBase(aProvd), iTestServer(NULL)
       
    50 	{
       
    51 	}
       
    52 
       
    53 CTcpClientTestUPnP2::~CTcpClientTestUPnP2 ()
       
    54 	{	
       
    55 	iTimer.Close ();
       
    56 	}
       
    57 
       
    58 void CTcpClientTestUPnP2::ConstructL()
       
    59 	{	
       
    60 	iTimer.CreateLocal ();
       
    61 	}
       
    62 
       
    63 TVerdict CTcpClientTestUPnP2::RunTestL()
       
    64 	{
       
    65 	switch ( iState )
       
    66 		{
       
    67 		case ECreateTestServer:
       
    68 			{
       
    69 			iLogger.WriteFormat(_L("<i>Creating TestServer..... </i>"));
       
    70 			
       
    71 			iTestServer = CTestTcpServer::NewL ( *this );
       
    72 			
       
    73 			iState  = ECreateTestClient;
       
    74 			iStatus = KRequestPending;			
       
    75 			Reschedule();
       
    76 			return EPass;
       
    77 			}
       
    78 		
       
    79 		case ECreateTestClient:
       
    80 			{
       
    81 			iLogger.WriteFormat(_L("<i>TestServer is created..... </i>"));			
       
    82 			iLogger.WriteFormat(_L("<i>Creating TestClient..... </i>"));
       
    83 			
       
    84 			THttpClientFlowQuery flowQuery ( TAppProtAddr ( KInetAddrLoop, KHttpDefaultPort ), Id (), EHttpClientFlow, THttpClientFlowQuery::ECreateNew, iChunkManager );
       
    85 			const TUid requestedUid = { CUPnPFlowFactory::iUid };
       
    86 			
       
    87 			TNodeId factoryContainer = SockManGlobals::Get( )->GetPlaneFC( TCFPlayerRole ( TCFPlayerRole::EDataPlane ) );
       
    88 			
       
    89 			RClientInterface::OpenPostMessageClose ( NodeId (), TNodeCtxId ( KActivityNull, factoryContainer ), TCFFactory::TFindOrCreatePeer ( TCFPlayerRole::EDataPlane, requestedUid, &flowQuery ).CRef () );
       
    90 			
       
    91 			iState  = ESendRequestData;
       
    92 			iStatus = KRequestPending;
       
    93 			Reschedule();
       
    94 			return EPass;
       
    95 			}
       
    96 		
       
    97 		case ESendRequestData:
       
    98 			{
       
    99 			iLogger.WriteFormat(_L("<i>Client is Created</i>"));
       
   100 			iLogger.WriteFormat(_L("<i>Send data..... </i>"));
       
   101 			
       
   102 			RMemChunk bodyBuf;
       
   103 			RMemChunk uriBuf;
       
   104 			//uriBuf.CreateL ( _L8 ("http://127.0.0.1:9999") );
       
   105 			uriBuf.CreateL ( _L8 ("http://[0:0:0:0:0:0:0:1]"), iAllocator );
       
   106 			TUpnpMessage::TUPnPClientRequestInfo msg ( HTTP::EGET, uriBuf, bodyBuf, NULL );
       
   107 			iClientId.Node ().ReceivedL ( TNodeCtxId ( KActivityNull, Id () ), TNodeCtxId ( KActivityNull, iClientId ), msg );
       
   108 			
       
   109 			iState = ECleanup;
       
   110 			iStatus = KRequestPending;
       
   111 			Reschedule ();
       
   112 			return EPass;
       
   113 			}
       
   114 
       
   115 		case ECleanup:
       
   116 			{
       
   117 			delete iTestServer;
       
   118 			// cleanup tcp client flow
       
   119 			delete reinterpret_cast<CHttpClientFlow*> ( iClientId.Ptr () );
       
   120 			iTimer.After ( iStatus, 60000000 ); //10 secs
       
   121 			iState = EComplete;
       
   122 			iStatus = KRequestPending;
       
   123 			Reschedule ();
       
   124 			return EPass;
       
   125 			}
       
   126 		case EComplete:
       
   127 			{
       
   128 			iLogger.WriteFormat(_L("<i>TestCase: Complete..... </i>"));
       
   129 			return EPass;
       
   130 			}
       
   131 			
       
   132 		default:
       
   133 			iLogger.WriteFormat(_L("<i> Failed: TestCase:..... </i>"));
       
   134 			ASSERT(0);
       
   135 			return EFail;
       
   136 		}
       
   137 	}
       
   138 	
       
   139 void CTcpClientTestUPnP2::OnTestServerEventL ( TInt aError )
       
   140 	{
       
   141 	CompleteSelf ( aError );
       
   142 	}
       
   143 
       
   144 MTcpClientTestCase* CTcpClientTestUPnP2::GetTestCase ()
       
   145 	{
       
   146 	return this;
       
   147 	}
       
   148 	
       
   149 CTestExecuteLogger& CTcpClientTestUPnP2::GetLogger ( )
       
   150 	{
       
   151 	return iLogger;
       
   152 	}
       
   153 
       
   154 
       
   155 void CTcpClientTestUPnP2::ReceivedL ( const TRuntimeCtxId& /*aSender*/, const TNodeId& /*aRecipient*/, TSignatureBase& aMessage )
       
   156 	{
       
   157 	if ( aMessage.IsMessage<TCFFactory::TPeerFoundOrCreated> () )
       
   158 		{
       
   159 		const TCFFactory::TPeerFoundOrCreated& msg = message_cast < const TCFFactory::TPeerFoundOrCreated > ( aMessage );
       
   160 		iClientId = msg.iNodeId;
       
   161 		CompleteSelf ( KErrNone );
       
   162 		}
       
   163 	else if ( aMessage.IsMessage<TUpnpMessage::TResponse > () )
       
   164 		{
       
   165 		
       
   166 		CompleteSelf(EPass);
       
   167 		}
       
   168 	else if ( aMessage.IsMessage<TEBase::TError > () )
       
   169 		{
       
   170 		iLogger.WriteFormat(_L("<i>TEBase::TError..... </i>"));
       
   171 		CompleteSelf(EFail);
       
   172 		}
       
   173 
       
   174 	}
       
   175 	
       
   176 const TDesC& CTcpClientTestUPnP2::TestCaseName () const
       
   177 	{
       
   178 	_LIT ( KTxtTitle, "Defect Fix CINC077703More" );
       
   179 	return KTxtTitle ();
       
   180 	}
       
   181 	
       
   182 TInt CTcpClientTestUPnP2::TotalTransactionCount () const
       
   183 	{
       
   184 	return KTransactionCount;
       
   185 	}
       
   186 
       
   187 const TDesC8& CTcpClientTestUPnP2::GetRawRequest ( TInt aTransIndex )
       
   188 	{
       
   189 	__ASSERT_ALWAYS ( aTransIndex < KTransactionCount, User::Invariant () );
       
   190 	return KTxtRawRequest ();
       
   191 	}
       
   192 	
       
   193 const TDesC8& CTcpClientTestUPnP2::GetRawResponse ( TInt aTransIndex )
       
   194 	{
       
   195 	__ASSERT_ALWAYS( aTransIndex < KTransactionCount, User::Invariant () );
       
   196 	return KTxtRawResponse1 ();
       
   197 	}
       
   198 
       
   199 TInt CTcpClientTestUPnP2::TransactionCount () const
       
   200 	{ 
       
   201 	return KTransactionCount; 
       
   202 	}
       
   203 
       
   204 
       
   205