applayerprotocols/httptransportfw/Test/TestScriptTest/CPipeliningTestServer.cpp
changeset 0 b16258d2340f
child 37 5f1cd966e0d9
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <chttptransportlayer.h>
       
    17 
       
    18 #include "CPipeliningTestServer.h"
       
    19 #include "httptestutils.h"
       
    20 #include "MPipeliningTestCase.h"
       
    21 #include "MPipeliningTestObserver.h"
       
    22 #include "CTestServerStreamManager.h"
       
    23 
       
    24 const TUint16 KListeningPort = 80;
       
    25 
       
    26 CPipeliningTestServer* CPipeliningTestServer::NewL(CHTTPTestUtils& aTestUtils, MPipeliningTestObserver& aObserver)
       
    27 	{
       
    28 	CPipeliningTestServer* self = new (ELeave) CPipeliningTestServer(aTestUtils, aObserver);
       
    29 	CleanupStack::PushL(self);
       
    30 	self->ConstructL();
       
    31 	CleanupStack::Pop(self);
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 CPipeliningTestServer::CPipeliningTestServer(CHTTPTestUtils& aTestUtils, MPipeliningTestObserver& aObserver)
       
    36 : iTestUtils(aTestUtils), iObserver(aObserver)
       
    37 	{
       
    38 	}
       
    39 	
       
    40 void CPipeliningTestServer::ConstructL()
       
    41 	{
       
    42 	_LIT8(KTxtTCP, "TCP");
       
    43 	THttpTransportConstructionParams params(*this); 
       
    44 	iTCPLayer = CHttpTransportLayer::NewL(KTxtTCP(), params);
       
    45 	}
       
    46 
       
    47 CPipeliningTestServer::~CPipeliningTestServer()
       
    48 	{
       
    49 	StopServer();
       
    50 	iStreamManager.ResetAndDestroy();
       
    51 	iStreamManager.Close();
       
    52 	delete iTCPLayer;
       
    53 	}
       
    54 
       
    55 void CPipeliningTestServer::StartServerL()
       
    56 	{
       
    57 	iTCPLayer->ListenL(*this, KListeningPort);
       
    58 	}
       
    59 
       
    60 void CPipeliningTestServer::StopServer()
       
    61 	{
       
    62 	if( iTCPLayer != NULL )
       
    63 		{
       
    64 		iTCPLayer->StopListen();
       
    65 		}
       
    66 	}
       
    67 
       
    68 void CPipeliningTestServer::ResetServer()
       
    69 	{
       
    70 	iStreamManager.ResetAndDestroy();
       
    71 	}
       
    72 	
       
    73 void CPipeliningTestServer::SetTestCase(MPipeliningTestCase* aTestCase)
       
    74 	{
       
    75 	iTestCase = aTestCase;
       
    76 	
       
    77 	_LIT(KTxtTransCount, "Total transaction in test case = %d");
       
    78 	iTestUtils.LogIt(KTxtTransCount(), iTestCase->TotalTransactionCount());
       
    79 
       
    80 	_LIT(KTxtConnectionCount, "Total connections in test case = %d");
       
    81 	iTestUtils.LogIt(KTxtConnectionCount(), iTestCase->ConnectionCount());
       
    82 	}
       
    83 
       
    84 TInt CPipeliningTestServer::ConnectionCount() const
       
    85 	{
       
    86 	return iStreamManager.Count();
       
    87 	}
       
    88 	
       
    89 // From MSocketListenObserver
       
    90 void CPipeliningTestServer::ConnectionReceivedL(MInputStream& aInputStream, MOutputStream& aOutputStream)
       
    91 	{
       
    92     _LIT(KTestCaseLocalAndRemoteHost, "TSWDEFECT1 JKUN-7VVGB6");
       
    93     if(iTestCase->TestCaseName().CompareF(KTestCaseLocalAndRemoteHost) == 0)
       
    94         {
       
    95         ResetServer();
       
    96         }
       
    97 	// New connection received, create a new stream manager to manage the requests and responses
       
    98 	const TInt connectionCount = iStreamManager.Count();
       
    99 	
       
   100 	CTestServerStreamManager* newStreamMgr = CTestServerStreamManager::NewL(iTestUtils, connectionCount, iTestCase, &aInputStream, &aOutputStream);
       
   101 	CleanupStack::PushL(newStreamMgr);
       
   102 	User::LeaveIfError(iStreamManager.Append(newStreamMgr));
       
   103 	CleanupStack::Pop(newStreamMgr);
       
   104 
       
   105 	_LIT(KTxtConnection, "Server - Client connection received and connected.");
       
   106 	iTestUtils.LogIt(KTxtConnection());
       
   107 	}
       
   108 	
       
   109 TInt CPipeliningTestServer::HandleListenError(TInt aError)
       
   110 	{
       
   111 	_LIT(KTxtListenError, "Server listening error: Error code = %d");
       
   112 	iTestUtils.LogIt(KTxtListenError(), aError);
       
   113 
       
   114 	iObserver.EndTest(aError);
       
   115 	return KErrNone;
       
   116 	}
       
   117 	
       
   118 void CPipeliningTestServer::MSocketListenObserver_Reserved()
       
   119 	{
       
   120 	}
       
   121 
       
   122 // From MConnectionPrefsProvider
       
   123 TBool CPipeliningTestServer::SupplyCommsConnection(RConnection*& /*aConnectionPtr*/)
       
   124 	{
       
   125 	return EFalse;
       
   126 	}
       
   127 	
       
   128 
       
   129 void CPipeliningTestServer::SetCommsConnectionL(RConnection* /*aConnectionPtr*/)
       
   130 	{
       
   131 	//do nothing
       
   132 	}
       
   133 	
       
   134 void CPipeliningTestServer::GetSecurityPrefs(TBool& aDialogPrompt, MSecurityPolicy*& aSecurityPolicy)
       
   135 	{
       
   136 	aDialogPrompt = EFalse;
       
   137 	aSecurityPolicy = NULL;
       
   138 	}
       
   139 
       
   140 TBool CPipeliningTestServer::ImmediateSocketShutdown()
       
   141 	{
       
   142 	return EFalse;
       
   143 	}
       
   144 
       
   145 TInt CPipeliningTestServer::SessionId()
       
   146 	{
       
   147 	return KErrNotSupported;
       
   148 	}
       
   149 
       
   150 TBool CPipeliningTestServer::SupplySocketServerHandle ( TInt& /*aSocketServerHandle*/ )
       
   151   	{
       
   152   	return 0;
       
   153   	}
       
   154   	
       
   155 void CPipeliningTestServer::SetSocketServerHandleL ( TInt /*aSocketServerHandle*/ )	
       
   156   	{	
       
   157   	// do nothing
       
   158   	}
       
   159 
       
   160 TInt CPipeliningTestServer::GetRecvBufferSize()
       
   161 	{
       
   162 	return KDefaultBufferSize;
       
   163 	}
       
   164