servicediscoveryandcontrol/pnp/test/upnp/unittests/tcpclient/src/ctcpclienttestupnp11.cpp
changeset 0 f5a58ecadc66
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/servicediscoveryandcontrol/pnp/test/upnp/unittests/tcpclient/src/ctcpclienttestupnp11.cpp	Tue Feb 02 01:12:20 2010 +0200
@@ -0,0 +1,204 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+#include <ss_glob.h>
+#include <comms-infras/ss_nodemessages_factory.h>
+#include <comms-infras/ss_nodemessages_dataclient.h>
+#include <httpstringconstants.h>
+
+#include "ptcpclienttests.h"	
+#include "upnp_cf_msgs.h"
+#include "upnpflowbase.h"
+#include "httpclientflow.h"
+#include "upnpflowfactory.h"
+#include "CTcpClientTestUPnP11.h"
+
+const TUint16 KActivityNull = 0;
+const TUint KHttpDefaultPort = 80;
+
+
+const TUint KTransactionCount = 1;
+_LIT8 ( KTxtRawRequest, "GET / HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 0\r\n\r\n" );
+_LIT8 ( KTxtRawResponse1, "HTTP/1.2 200 OK\r\nConnection: kept-alive\r\nContent-Length: 0\r\n\r\n" );
+
+
+CTcpClientTestUPnP11* CTcpClientTestUPnP11::NewL ( CProxyProvd* aProvd )
+	{
+	CTcpClientTestUPnP11* ret = new ( ELeave ) CTcpClientTestUPnP11 ( aProvd );
+	CleanupStack::PushL ( ret );
+	ret->ConstructL ();
+	CleanupStack::Pop ( ret );
+	return ret;
+	}
+
+CTcpClientTestUPnP11::CTcpClientTestUPnP11 ( CProxyProvd* aProvd ) :
+	CTcpClientTestBase(aProvd), iTestServer(NULL)
+	{
+	}
+
+CTcpClientTestUPnP11::~CTcpClientTestUPnP11 ()
+	{	
+	iTimer.Close ();
+	}
+
+void CTcpClientTestUPnP11::ConstructL()
+	{	
+	iTimer.CreateLocal ();
+	}
+
+TVerdict CTcpClientTestUPnP11::RunTestL()
+	{
+	switch ( iState )
+		{
+		case ECreateTestServer:
+			{
+			iLogger.WriteFormat(_L("<i>Creating TestServer..... </i>"));
+			
+			iTestServer = CTestTcpServer::NewL ( *this );
+			
+			iState  = ECreateTestClient;
+			iStatus = KRequestPending;			
+			Reschedule();
+			return EPass;
+			}
+		
+		case ECreateTestClient:
+			{
+			iLogger.WriteFormat(_L("<i>TestServer is created..... </i>"));			
+			iLogger.WriteFormat(_L("<i>Creating TestClient..... </i>"));
+			
+			THttpClientFlowQuery flowQuery ( TAppProtAddr ( KInetAddrLoop, KHttpDefaultPort ), Id (), EHttpClientFlow, THttpClientFlowQuery::ECreateNew, iChunkManager );
+			const TUid requestedUid = { CUPnPFlowFactory::iUid };
+			
+			TNodeId factoryContainer = SockManGlobals::Get( )->GetPlaneFC( TCFPlayerRole ( TCFPlayerRole::EDataPlane ) );
+			
+			RClientInterface::OpenPostMessageClose ( NodeId (), TNodeCtxId ( KActivityNull, factoryContainer ), TCFFactory::TFindOrCreatePeer ( TCFPlayerRole::EDataPlane, requestedUid, &flowQuery ).CRef () );
+			
+			iState  = ESendRequestData;
+			iStatus = KRequestPending;
+			Reschedule();
+			return EPass;
+			}
+		
+		case ESendRequestData:
+			{
+			iLogger.WriteFormat(_L("<i>Client is Created</i>"));
+			iLogger.WriteFormat(_L("<i>Send data..... </i>"));
+			
+			RMemChunk bodyBuf;
+			RMemChunk uriBuf;
+			uriBuf.CreateL ( _L8 ("http://127.0.0.1:9999"), iAllocator );
+			TUpnpMessage::TUPnPClientRequestInfo msg ( HTTP::EGET, uriBuf, bodyBuf, NULL );
+			iClientId.Node ().ReceivedL ( TNodeCtxId ( KActivityNull, Id () ), TNodeCtxId ( KActivityNull, iClientId ), msg );
+			
+			iState = ECleanup;
+			iStatus = KRequestPending;
+			Reschedule ();
+			return EPass;
+			}
+
+		case ECleanup:
+			{
+			delete iTestServer;
+			// cleanup tcp client flow
+			delete reinterpret_cast<CHttpClientFlow*> ( iClientId.Ptr () );
+			iTimer.After ( iStatus, 60000000 ); //10 secs
+			iState = EComplete;
+			iStatus = KRequestPending;
+			Reschedule ();
+			return EPass;
+			}
+		case EComplete:
+			{
+			iLogger.WriteFormat(_L("<i>TestCase: Complete..... </i>"));
+			return EPass;
+			}
+			
+		default:
+			iLogger.WriteFormat(_L("<i> Failed: TestCase:..... </i>"));
+			ASSERT(0);
+			return EFail;
+		}
+	}
+	
+void CTcpClientTestUPnP11::OnTestServerEventL ( TInt aError )
+	{
+	CompleteSelf ( aError );
+	}
+
+MTcpClientTestCase* CTcpClientTestUPnP11::GetTestCase ()
+	{
+	return this;
+	}
+	
+CTestExecuteLogger& CTcpClientTestUPnP11::GetLogger ( )
+	{
+	return iLogger;
+	}
+
+
+void CTcpClientTestUPnP11::ReceivedL ( const TRuntimeCtxId& /*aSender*/, const TNodeId& /*aRecipient*/, TSignatureBase& aMessage )
+	{
+	if ( aMessage.IsMessage<TCFFactory::TPeerFoundOrCreated> () )
+		{
+		const TCFFactory::TPeerFoundOrCreated& msg = message_cast < const TCFFactory::TPeerFoundOrCreated > ( aMessage );
+		iClientId = msg.iNodeId;
+		CompleteSelf ( KErrNone );
+		}
+	else if ( aMessage.IsMessage<TUpnpMessage::TResponse > () )
+		{
+		
+		CompleteSelf(EPass);
+		}
+	else if ( aMessage.IsMessage<TEBase::TError > () )
+		{
+		iLogger.WriteFormat(_L("<i>TEBase::TError..... </i>"));
+		CompleteSelf(EFail);
+		}
+
+	}
+	
+const TDesC& CTcpClientTestUPnP11::TestCaseName () const
+	{
+	_LIT ( KTxtTitle, "Defect Fix CINC077703More" );
+	return KTxtTitle ();
+	}
+	
+TInt CTcpClientTestUPnP11::TotalTransactionCount () const
+	{
+	return KTransactionCount;
+	}
+
+const TDesC8& CTcpClientTestUPnP11::GetRawRequest ( TInt aTransIndex )
+	{
+	__ASSERT_ALWAYS ( aTransIndex < KTransactionCount, User::Invariant () );
+	return KTxtRawRequest ();
+	}
+	
+const TDesC8& CTcpClientTestUPnP11::GetRawResponse ( TInt aTransIndex )
+	{
+	__ASSERT_ALWAYS( aTransIndex < KTransactionCount, User::Invariant () );
+	return KTxtRawResponse1 ();
+	}
+
+TInt CTcpClientTestUPnP11::TransactionCount () const
+	{ 
+	return KTransactionCount; 
+	}
+
+
+