diff -r 000000000000 -r f5a58ecadc66 servicediscoveryandcontrol/pnp/test/upnp/unittests/tcpclient/src/ctcpclienttestupnp14.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servicediscoveryandcontrol/pnp/test/upnp/unittests/tcpclient/src/ctcpclienttestupnp14.cpp Tue Feb 02 01:12:20 2010 +0200 @@ -0,0 +1,298 @@ +/* +* 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 +#include +#include +#include + +#include "ptcpclienttests.h" +#include "upnp_cf_msgs.h" +#include "upnpflowbase.h" +#include "httpclientflow.h" +#include "upnpflowfactory.h" + +#include "CTcpClientTestUPnP14.h" +#include "upnpserverconstants.h" + +const TUint16 KActivityNull = 0; +const TUint KHttpDefaultPort = 80; + + +const TUint KTransactionCount = 1; +_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" ); +_LIT8 ( KTxtRawResponse1, "HTTP/1.1 200 OK\r\nContent-Length: 330\r\n\r\nQuery return value\r\n\r\n" ); +_LIT8 ( KData1, ""); +_LIT8 ( KData3, "Query return value"); + +CTcpClientTestUPnP14* CTcpClientTestUPnP14::NewL ( CProxyProvd* aProvd ) + { + CTcpClientTestUPnP14* ret = new ( ELeave ) CTcpClientTestUPnP14 ( aProvd ); + CleanupStack::PushL ( ret ); + ret->ConstructL (); + CleanupStack::Pop ( ret ); + return ret; + } + +CTcpClientTestUPnP14::CTcpClientTestUPnP14 ( CProxyProvd* aProvd ) : + CTcpClientTestBase(aProvd), iTestServer(NULL), iTimerstart(EFalse) + { + } + +CTcpClientTestUPnP14::~CTcpClientTestUPnP14 () + { + iTimer.Close (); + } + +void CTcpClientTestUPnP14::ConstructL() + { + iTimer.CreateLocal (); + } + +TVerdict CTcpClientTestUPnP14::RunTestL() + { + switch ( iState ) + { + case ECreateTestServer: + { + iLogger.WriteFormat(_L("Creating TestServer..... ")); + + iTestServer = CTestTcpServer::NewL ( *this ); + + iState = ECreateTestClient; + iStatus = KRequestPending; + Reschedule(); + return EPass; + } + + case ECreateTestClient: + { + iLogger.WriteFormat(_L("TestServer is created..... ")); + iLogger.WriteFormat(_L("Creating TestClient..... ")); + + 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("Client is Created")); + iLogger.WriteFormat(_L("Send data..... ")); + + TPtrC8 data(KData1); + TPtrC8 data2(KData2); + TPtrC8 data3(KData3); + + if(!iTimerstart) + { + iSSP->SetOption(KCHOptionLevel, KCHAbsoluteUri, _L8 ("http://127.0.0.1")); + + TCHMessageOption option ( 1, data.Length()+data2.Length()+data3.Length() ); + + TPckg < TCHMessageOption > optionBuf ( option ); + + iSSP->SetOption(KCHOptionLevel, KCHMaxLength, optionBuf); + + + RMBufChain bodyBuf; + bodyBuf.CreateL(KData1); + iSSPData->Write(bodyBuf, 0, NULL); + + /* + + TCHMessageOption option2 ( 1, data2.Length() ); + TPckg < TCHMessageOption > optionBuf2 ( option2 ); + + iSSP->SetOption(KCHOptionLevel, KCHMaxLength, optionBuf2); + */ + + RMBufChain bodyBuf1; + bodyBuf1.CreateL(KData2); + iSSPData->Write(bodyBuf1, 0, NULL); + + iState = ESendRequestData; + + iTimerstart = ETrue; + iTimer.After ( iStatus, 1000000 ); + /* + + TCHMessageOption option3 ( 1, data3.Length() ); + TPckg < TCHMessageOption > optionBuf3 ( option3 ); + + iSSP->SetOption(KCHOptionLevel, KCHMaxLength, optionBuf3); + */ + } + else + { + RMBufChain bodyBuf2; + bodyBuf2.CreateL(KData3); + iSSPData->Write(bodyBuf2, 0, NULL); + iState = ECleanup; + } + + iStatus = KRequestPending; + Reschedule (); + return EPass; + } + + case ECleanup: + { + delete iTestServer; + + // cleanup tcp client flow + delete reinterpret_cast ( iClientId.Ptr () ); + iTimer.After ( iStatus, 60000000 ); //10 secs + iState = EComplete; + iStatus = KRequestPending; + Reschedule (); + return EPass; + } + case EComplete: + { + iLogger.WriteFormat(_L("TestCase: Complete..... ")); + return EPass; + } + + default: + iLogger.WriteFormat(_L(" Failed: TestCase:..... ")); + ASSERT(0); + return EFail; + } + } + +void CTcpClientTestUPnP14::OnTestServerEventL ( TInt aError ) + { + CompleteSelf ( aError ); + } + +MTcpClientTestCase* CTcpClientTestUPnP14::GetTestCase () + { + return this; + } + +CTestExecuteLogger& CTcpClientTestUPnP14::GetLogger ( ) + { + return iLogger; + } + + +void CTcpClientTestUPnP14::ReceivedL ( const TRuntimeCtxId& /*aSender*/, const TNodeId& /*aRecipient*/, TSignatureBase& aMessage ) + { + if ( aMessage.IsMessage () ) + { + const TCFFactory::TPeerFoundOrCreated& msg = message_cast < const TCFFactory::TPeerFoundOrCreated > ( aMessage ); + iClientId = msg.iNodeId; + + + iFlow = mcfnode_cast( + reinterpret_cast( iClientId.Ptr())); + + + // Perform the binding to the flow below + iFlowBinder = iFlow->GetBinderControlL(); + iSSP = iFlowBinder->GetControlL(KSockStream, *this); + iSSPData = iFlowBinder->BindL(*this); + + + CompleteSelf ( KErrNone ); + } + else if ( aMessage.IsMessage () ) + { + + CompleteSelf(EPass); + } + else if ( aMessage.IsMessage () ) + { + iLogger.WriteFormat(_L("TEBase::TError..... ")); + CompleteSelf(EFail); + } + + } + +const TDesC& CTcpClientTestUPnP14::TestCaseName () const + { + _LIT ( KTxtTitle, "CTcpClientTestMWrites" ); + return KTxtTitle (); + } + +TInt CTcpClientTestUPnP14::TotalTransactionCount () const + { + return KTransactionCount; + } + +const TDesC8& CTcpClientTestUPnP14::GetRawRequest ( TInt /*aTransIndex*/ ) + { + //__ASSERT_ALWAYS ( aTransIndex < KTransactionCount, User::Invariant () ); + return KTxtRawRequest (); + } + +const TDesC8& CTcpClientTestUPnP14::GetRawResponse ( TInt /*aTransIndex*/ ) + { + //__ASSERT_ALWAYS( aTransIndex < KTransactionCount, User::Invariant () ); + return KTxtRawResponse1 (); + } + +TInt CTcpClientTestUPnP14::TransactionCount () const + { + return KTransactionCount; + } + +void CTcpClientTestUPnP14::NewData(TUint aCount) + { + RMBufChain data; + RBuf8 resData; + + iLogger.WriteFormat(_L("NewData..... ")); + iSSP->GetOption(1,KCHMaxLength,resData); + resData.Create( aCount ); + iSSP->GetOption(KCHOptionLevel,KCHMaxLength,resData); + TInt len = *(TUint*) resData.Ptr(); + resData.Close(); + + iSSPData->GetData(data,len,0); + resData.Create( len ); + data.CopyOut(resData); + resData.Close(); + resData.Create( aCount ); + iSSP->GetOption(KCHOptionLevel,KCHLastMessage,resData); + TBool isLastMsg = *(TUint*) resData.Ptr(); + resData.Close(); + data.Init(); + + if(isLastMsg) + { + iLogger.WriteFormat(_L("NewData.LastMsg.... ")); + CompleteSelf ( KErrNone ); + } + } + + + + + + +