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