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