applayerprotocols/httptransportfw/Test/T_HttpPipeliningTest/CTestCase18.cpp
changeset 0 b16258d2340f
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 "CTestCase18.h"
       
    17 #include "httptestutils.h"
       
    18 
       
    19 const TInt KConn1TransCount = 3;
       
    20 const TInt KConn2TransCount = 2;
       
    21 const TInt KConnectionCount = 2;
       
    22 const TInt KBufferSize = 10; // Batching buffer size in bytes
       
    23 _LIT8(KTxtRawRequest, "GET / HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n");
       
    24 _LIT8(KTxtRawRequestWithClose, "GET / HTTP/1.1\r\nConnection: Close\r\nHost: 127.0.0.1\r\n\r\n");
       
    25 _LIT8(KTxtRawResponse, "HTTP/1.1 200 Ok\r\nContent-Length: 6\r\n\r\nhello!");
       
    26 
       
    27 
       
    28 CTestCase18* CTestCase18::NewL(CHTTPTestUtils& aTestUtils)
       
    29 	{
       
    30 	CTestCase18* self = new (ELeave) CTestCase18(aTestUtils);
       
    31 	CleanupStack::PushL(self);
       
    32 	self->ConstructL();
       
    33 	CleanupStack::Pop(self);
       
    34 	return self;
       
    35 	}
       
    36 
       
    37 CTestCase18::CTestCase18(CHTTPTestUtils& aTestUtils)
       
    38 : CBatchingTestCase(), iTestUtils(aTestUtils)
       
    39 	{
       
    40 	}
       
    41 
       
    42 void CTestCase18::ConstructL()
       
    43 	{
       
    44 	}
       
    45 
       
    46 CTestCase18::~CTestCase18()
       
    47 	{
       
    48 	}
       
    49 
       
    50 const TDesC& CTestCase18::TestCaseName() const
       
    51 	{
       
    52 	_LIT(KTxtTitle, "Test Case 18");
       
    53 	return KTxtTitle();
       
    54 	}
       
    55 
       
    56 TInt CTestCase18::TransactionCount(TInt aConnectionIndex) const
       
    57 	{
       
    58 	TInt transCount = 0;
       
    59 	switch(aConnectionIndex)
       
    60 		{
       
    61 		case 0:
       
    62 			{
       
    63 			transCount = KConn1TransCount;
       
    64 			} break;
       
    65 		case 1:
       
    66 			{
       
    67 			transCount = KConn2TransCount;
       
    68 			} break;
       
    69 		default:
       
    70 			User::Invariant();
       
    71 		}
       
    72 
       
    73 	return transCount;
       
    74 	}
       
    75 
       
    76 TInt CTestCase18::TotalTransactionCount() const
       
    77 	{
       
    78 	return KConn1TransCount+KConn2TransCount;
       
    79 	}
       
    80 
       
    81 TInt CTestCase18::ConnectionCount() const
       
    82 	{
       
    83 	return KConnectionCount;
       
    84 	}
       
    85 	
       
    86 RHTTPTransaction CTestCase18::GetTransactionL(TInt aIndex, RHTTPSession aSession, MHTTPTransactionCallback& aClient)
       
    87 	{
       
    88 	__ASSERT_ALWAYS(aIndex<TotalTransactionCount(), User::Invariant());
       
    89 	
       
    90 	RStringF method = aSession.StringPool().StringF(HTTP::EGET,RHTTPSession::GetTable());
       
    91 	_LIT8(KTxtUri, "http://127.0.0.1");
       
    92 	TUriParser8 uri; 
       
    93 	uri.Parse(KTxtUri());
       
    94 
       
    95 	// Buffer size needs to be reduced in the session property before the first transaction.
       
    96 	if( aIndex == 0 )
       
    97 		{
       
    98 		RHTTPConnectionInfo connInfo = aSession.ConnectionInfo();
       
    99 		connInfo.SetPropertyL(aSession.StringPool().StringF(HTTP::EBatchingBufferSize,RHTTPSession::GetTable()), KBufferSize);
       
   100 		}
       
   101 		
       
   102 	if( aIndex==2 )
       
   103 		{
       
   104 		RHTTPTransaction trans = aSession.OpenTransactionL(uri, aClient, method);
       
   105 		AddConnectionCloseHeaderL(trans);
       
   106 		return trans;
       
   107 		}
       
   108 
       
   109 	return aSession.OpenTransactionL(uri, aClient, method);
       
   110 	}
       
   111 
       
   112 const TDesC8& CTestCase18::GetRawRequest(TInt aConnectionIndex, TInt aTransIndex)
       
   113 	{
       
   114 	__ASSERT_ALWAYS(aTransIndex<TransactionCount(aConnectionIndex), User::Invariant());
       
   115 	
       
   116 	if( aConnectionIndex==0 && aTransIndex==2 )
       
   117 		return KTxtRawRequestWithClose();
       
   118 
       
   119 	return KTxtRawRequest();
       
   120 	}
       
   121 	
       
   122 const TDesC8& CTestCase18::GetRawResponse(TInt aConnectionIndex, TInt aTransIndex)
       
   123 	{
       
   124 	__ASSERT_ALWAYS(aTransIndex<TransactionCount(aConnectionIndex), User::Invariant());
       
   125 	
       
   126 	return KTxtRawResponse();
       
   127 	}
       
   128 	
       
   129 void CTestCase18::AddConnectionCloseHeaderL(RHTTPTransaction aTransaction)
       
   130 	{
       
   131 	RStringF name = aTransaction.Session().StringPool().StringF(HTTP::EConnection, RHTTPSession::GetTable());
       
   132 	THTTPHdrVal value = aTransaction.Session().StringPool().StringF(HTTP::EClose, RHTTPSession::GetTable());
       
   133 
       
   134 	aTransaction.Request().GetHeaderCollection().SetFieldL(name, value);
       
   135 	}