applayerprotocols/httptransportfw/Test/T_HttpPipeliningTest/CPREQ1805.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2007-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 "CPREQ1805.h"
       
    17 #include "httptestutils.h"
       
    18 
       
    19 const TInt KTransactionCount = 5;
       
    20 const TInt KConnectionCount = 1;
       
    21 _LIT8(KTxtRawRequest, "GET / HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n");
       
    22 _LIT8(KTxtRawResponse, "HTTP/1.1 200 Ok\r\nContent-Length: 6\r\n\r\nhello!");
       
    23 
       
    24 CPREQ1805* CPREQ1805::NewL(CHTTPTestUtils& aTestUtils)
       
    25 	{
       
    26 	CPREQ1805* self = new (ELeave) CPREQ1805(aTestUtils);
       
    27 	CleanupStack::PushL(self);
       
    28 	self->ConstructL();
       
    29 	CleanupStack::Pop(self);
       
    30 	return self;
       
    31 	}
       
    32 
       
    33 CPREQ1805::CPREQ1805(CHTTPTestUtils& aTestUtils)
       
    34 : CPipeliningTestCase(), iTestUtils(aTestUtils)
       
    35 	{
       
    36 	}
       
    37 
       
    38 void CPREQ1805::ConstructL()
       
    39 	{
       
    40 	}
       
    41 
       
    42 CPREQ1805::~CPREQ1805()
       
    43 	{
       
    44 	}
       
    45 
       
    46 const TDesC& CPREQ1805::TestCaseName() const
       
    47 	{
       
    48 	_LIT(KTxtTitle, "Pipelining test for PREQ1805");
       
    49 	return KTxtTitle();
       
    50 	}
       
    51 
       
    52 TInt CPREQ1805::TotalTransactionCount() const
       
    53 	{
       
    54 	return KTransactionCount;
       
    55 	}
       
    56 
       
    57 TInt CPREQ1805::ConnectionCount() const
       
    58 	{
       
    59 	return KConnectionCount;
       
    60 	}
       
    61 	
       
    62 RHTTPTransaction CPREQ1805::GetTransactionL(TInt aIndex, RHTTPSession aSession, MHTTPTransactionCallback& aClient)
       
    63 	{
       
    64 	__ASSERT_ALWAYS(aIndex<KTransactionCount, User::Invariant());
       
    65 	
       
    66 	// Stting HttpDataOptimiser to session 
       
    67 	aSession.SetupHttpDataOptimiser(*this);
       
    68 	
       
    69 	RStringF method = aSession.StringPool().StringF(HTTP::EGET,RHTTPSession::GetTable());
       
    70 	_LIT8(KTxtUri, "http://127.0.0.1");
       
    71 	TUriParser8 uri; 
       
    72 	uri.Parse(KTxtUri());
       
    73 	return aSession.OpenTransactionL(uri, aClient, method);
       
    74 	}
       
    75 
       
    76 const TDesC8& CPREQ1805::GetRawRequest(TInt aConnectionIndex, TInt aTransIndex)
       
    77 	{
       
    78 	__ASSERT_ALWAYS( (aTransIndex<KTransactionCount) && (aConnectionIndex-1 < KConnectionCount), User::Invariant());
       
    79 	
       
    80 	return KTxtRawRequest();
       
    81 	}
       
    82 	
       
    83 const TDesC8& CPREQ1805::GetRawResponse(TInt aConnectionIndex, TInt aTransIndex)
       
    84 	{
       
    85 	__ASSERT_ALWAYS( (aTransIndex<KTransactionCount) && (aConnectionIndex-1 < KConnectionCount), User::Invariant());
       
    86 
       
    87 	return KTxtRawResponse();
       
    88 	}
       
    89 	
       
    90 void CPREQ1805::EncodeL (const TDesC8& aHttpData, HBufC8* &aEncodedData)
       
    91 	{
       
    92 	
       
    93 	_LIT(KTxtMessage, "######## CPREQ1805::Encode ########\n");
       
    94 	iTestUtils.LogIt(KTxtMessage);
       
    95 
       
    96 	// Encoding: copying the same request data from aHttpData to aEncodedData
       
    97  	TRAPD(err,
       
    98 		{
       
    99 		aEncodedData=  aHttpData.AllocLC();
       
   100 		CleanupStack::Pop();
       
   101 		});	
       
   102 	if(err != KErrNone)
       
   103 		{
       
   104 		_LIT(KTxtErrMsg, "CPREQ1805 - Leave in CPREQ1805::Encode: %D\n");
       
   105 		iTestUtils.LogIt(KTxtErrMsg(),err);
       
   106 		}
       
   107 	}
       
   108 
       
   109 void CPREQ1805::DecodeL (const TDesC8& aData, HBufC8*& aHttpData, TBool& aTransFail)
       
   110 	{
       
   111 	
       
   112 	_LIT(KTxtMessage, "######## CPREQ1805::Decode ########\n");
       
   113 	iTestUtils.LogIt(KTxtMessage);
       
   114 	
       
   115 	static int count = 0;
       
   116 	TRAPD(err, 
       
   117 		{
       
   118 		aHttpData = aData.AllocLC();
       
   119 		CleanupStack::Pop();	
       
   120 		});
       
   121 	if(err != KErrNone)
       
   122 		{
       
   123 		_LIT(KTxtErrMsg, "CPREQ1805 - Leave in CPREQ1805::Decode: %D\n");
       
   124 		iTestUtils.LogIt(KTxtErrMsg(),err);
       
   125 		}
       
   126 		
       
   127 	// Checking to fail the transaction.
       
   128 	if(count == 2)
       
   129 		aTransFail = ETrue;	
       
   130 	else
       
   131 		aTransFail = EFalse;
       
   132 			
       
   133 	count++;
       
   134 	}
       
   135 	
       
   136