applayerprotocols/httptransportfw/Test/T_HttpOnline/CR1130.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 // defines test class: CR1130
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "CR1130.h"
       
    19 #include "examplecookiemanager.h"
       
    20 #include <http/ccookiefilterinterface.h>
       
    21 
       
    22 // User include
       
    23 #include "csrvaddrval.h"
       
    24 
       
    25 // Literals used in the file
       
    26 _LIT8(KHttpUrl1,		"http://10.29.23.12/manual/images/index.gif");
       
    27 
       
    28 
       
    29 /**
       
    30 	This function is called to create a new instance of the class 
       
    31 	CR1130
       
    32 
       
    33 	@param aTestNumber			The test number that has to be executed
       
    34 	@param aIniSettingsFile		The script file that holds the sections
       
    35 								from which the value has to be retrieved
       
    36 	@leave 						Leaves with a standard error
       
    37 */
       
    38 CR1130* CR1130::NewL(TInt aTestNumber, CScriptFile* aIniSettingsFile)
       
    39 	{
       
    40 	CR1130* self = new(ELeave)CR1130(aTestNumber, aIniSettingsFile);
       
    41 	CleanupStack::PushL(self);
       
    42 	CleanupStack::Pop(self);
       
    43 	return self;
       
    44 	}
       
    45 
       
    46 /**
       
    47 	Destructor
       
    48 */
       
    49 CR1130::~CR1130()
       
    50 	{
       
    51 	iTransArray.Close();
       
    52 	}
       
    53 
       
    54 /**
       
    55 	This C++ constructor is called in the NewL function and is used to 
       
    56 	instantiate iTestNumber and iIniSettingsFile
       
    57 
       
    58 	@param aTestNumber		- The test number that has to be executed
       
    59 	@param aIniSettingsFile	- The script file that holds the sections
       
    60 							  from which the value has to be retrieved
       
    61 */
       
    62 CR1130::CR1130(TInt aTestNumber, CScriptFile* aIniSettingsFile) :
       
    63 	iIniSettingsFile(aIniSettingsFile),
       
    64 	iTestNumber(aTestNumber)
       
    65 	{
       
    66 	}
       
    67 
       
    68 /**
       
    69 	This function is called to initiate the tests.
       
    70 	
       
    71 	@leave	Leaves with a standard error.
       
    72 */
       
    73 void CR1130::DoRunL()
       
    74 	{
       
    75 	// Open the HTTP session
       
    76 	iSession.OpenL();
       
    77 	CleanupClosePushL(iSession);
       
    78 	
       
    79 	THTTPHdrVal hdrVal ( 10000 );
       
    80 	RHTTPConnectionInfo httpConnInfo = iSession.ConnectionInfo();
       
    81 	httpConnInfo.SetPropertyL ( iSession.StringPool().StringF(HTTP::ERecvBufferSize,RHTTPSession::GetTable()), hdrVal );
       
    82 
       
    83 	CreateTransArrayL();
       
    84 	
       
    85 	CActiveScheduler::Start();
       
    86 	
       
    87 	CleanupStack::PopAndDestroy(&iSession); //close iSession
       
    88 	}
       
    89 
       
    90 /**
       
    91 	If a test is failed then is function is executed to log the error code
       
    92 	with which the test failed
       
    93 
       
    94 	@param	aErr	The error code with which the test failed.
       
    95 */
       
    96 TInt CR1130::RunError(TInt aErr)
       
    97 	{
       
    98 	iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr);
       
    99 	return KErrNone;
       
   100 	}
       
   101 
       
   102 void CR1130::DoCancel()
       
   103 	{
       
   104 	}
       
   105 
       
   106 const TDesC& CR1130::TestName()
       
   107 	{
       
   108 	_LIT(KHeaderTestName,"CR1130");
       
   109 	return KHeaderTestName;
       
   110 	}
       
   111 
       
   112 TInt CR1130::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/)
       
   113 	{
       
   114 	_LIT(KLogDescription, "\nTest failed with error code %d on transaction ID=%d\n");
       
   115 	iEngine->Utils().LogIt(KLogDescription, aError, aTransaction.Id());
       
   116 	iFailureError = aError;
       
   117 	CActiveScheduler::Stop();
       
   118 	return KErrNone;
       
   119 	}
       
   120 
       
   121 void CR1130::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
       
   122 	{
       
   123 	switch (aEvent.iStatus)
       
   124 		{
       
   125 		case THTTPEvent::EGotResponseHeaders:
       
   126 			{
       
   127 			// HTTP response headers have been received
       
   128 			iEngine->Utils().LogIt(_L("<Got response headers>"));
       
   129 			MHTTPDataSupplier* body = aTransaction.Response().Body ();
       
   130 			if ( body )
       
   131 				{
       
   132 				body->ReleaseData ();
       
   133 				}
       
   134 			} break;
       
   135 		case THTTPEvent::ESubmit:
       
   136 			{
       
   137 			} break;
       
   138 		case THTTPEvent::EGotResponseBodyData:
       
   139 			{
       
   140 			// Some (more) body data has been received (in the HTTP response)
       
   141 			iEngine->Utils().LogIt(_L("<Got a chunk of data>"));
       
   142 			// Get the body data supplier
       
   143 			MHTTPDataSupplier* iRespBody = aTransaction.Response().Body();
       
   144 			// Append to the output file.
       
   145 			TPtrC8 bodyData;
       
   146 			TBool lastChunk = iRespBody->GetNextDataPart( bodyData );
       
   147 			iRespBody->ReleaseData();
       
   148 			} break;
       
   149 		case THTTPEvent::EResponseComplete:
       
   150 			{
       
   151 			// The transaction's response is complete
       
   152 			iEngine->Utils().LogIt(_L("<Transaction Complete>"));
       
   153 			} break;
       
   154 		case THTTPEvent::ESucceeded:
       
   155 			{
       
   156 			// The transaction succeeded
       
   157 			iEngine->Utils().LogIt(_L("<Transaction succeeded>"));
       
   158 			aTransaction.Close();
       
   159 			if(--iOpenTransCount == 0)
       
   160 				{
       
   161 				CActiveScheduler::Stop();
       
   162 				}
       
   163 			}
       
   164 			break;
       
   165 		case THTTPEvent::EFailed:
       
   166 			{
       
   167 			// The transaction failed so fail the test
       
   168 			iEngine->Utils().LogIt(_L("<Transaction failed>"));
       
   169 			aTransaction.Close();
       
   170 			if(--iOpenTransCount == 0)
       
   171 				{
       
   172 				CActiveScheduler::Stop();
       
   173 				}
       
   174 			} break;
       
   175 		default:
       
   176 			{
       
   177 			_LIT(KLogDescription, "<unrecognised event> %d");
       
   178 			iEngine->Utils().LogIt(KLogDescription,aEvent.iStatus);
       
   179 			if (aEvent.iStatus < 0)
       
   180 				{
       
   181 				iFailureError = aEvent.iStatus;
       
   182 				CActiveScheduler::Stop();
       
   183 				}
       
   184 			} 
       
   185 			break;
       
   186 		}
       
   187 	
       
   188 	return;
       
   189 	}
       
   190 
       
   191 
       
   192 void CR1130::ConfigureSessionFiltersL(TFilterConfigurationIterator* /*aFilterConfigIter*/)
       
   193 	{
       
   194 	if (iTestNumber == 11)
       
   195 		{
       
   196 		User::Leave(KErrNone);
       
   197 		}
       
   198 
       
   199 	iCookieManager = CExampleCookieManager::NewL(iSession.StringPool());
       
   200 
       
   201 	CCookieFilterInterface::InstallFilterL(iSession, iCookieManager);
       
   202 	}
       
   203 	
       
   204 void CR1130::CreateTransArrayL()
       
   205 	{
       
   206 	RStringPool strP = iSession.StringPool();
       
   207 	TUriParser8 up;
       
   208 
       
   209 	up.Parse(KHttpUrl1);
       
   210 	RHTTPTransaction trans1 = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable()));
       
   211 	CleanupClosePushL(trans1);
       
   212 	iTransArray.Append(trans1);
       
   213 	CleanupStack::Pop(&trans1);
       
   214 
       
   215 	for(TInt i=0; i<iTransArray.Count(); i++)
       
   216 		{
       
   217 		iTransArray[i].SubmitL();
       
   218 		iOpenTransCount++;
       
   219 		}
       
   220 	}
       
   221 
       
   222