applayerprotocols/httptransportfw/Test/T_HttpOnline/DEF079378.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2006-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: CDEF079378
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "DEF079378.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://10.29.23.12/jar/kFire004.jar");
       
    27 
       
    28 
       
    29 /**
       
    30 	This function is called to create a new instance of the class 
       
    31 	CDEF079378
       
    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 CDEF079378* CDEF079378::NewL(TInt aTestNumber, CScriptFile* aIniSettingsFile)
       
    39 	{
       
    40 	CDEF079378* self = new(ELeave)CDEF079378(aTestNumber, aIniSettingsFile);
       
    41 	CleanupStack::PushL(self);
       
    42 	CleanupStack::Pop(self);
       
    43 	return self;
       
    44 	}
       
    45 
       
    46 /**
       
    47 	Destructor
       
    48 */
       
    49 CDEF079378::~CDEF079378()
       
    50 	{
       
    51 //	delete iCookieManager;
       
    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 CDEF079378::CDEF079378(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 CDEF079378::DoRunL()
       
    76 	{
       
    77 	TUriParser8 up;
       
    78 	up.Parse(KHttpAuthenticationUrl);
       
    79 
       
    80 	// Open the HTTP session
       
    81 	iSession.OpenL();
       
    82 	CleanupClosePushL(iSession);
       
    83 
       
    84 	// Install this class as the callback for authentication requests
       
    85 	InstallAuthenticationL(iSession);
       
    86 	RStringPool strP = iSession.StringPool();
       
    87 
       
    88 	// Open a GET transactions, specifying this object as the request body data supplier
       
    89 	iTransaction = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable()));
       
    90 	
       
    91 	iTransaction.SubmitL();
       
    92 	CActiveScheduler::Start();
       
    93 	
       
    94 	CleanupStack::PopAndDestroy(&iSession); //close iSession
       
    95 
       
    96 	}
       
    97 
       
    98 /**
       
    99 	If a test is failed then is function is executed to log the error code
       
   100 	with which the test failed
       
   101 
       
   102 	@param	aErr	The error code with which the test failed.
       
   103 */
       
   104 TInt CDEF079378::RunError(TInt aErr)
       
   105 	{
       
   106 	iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr);
       
   107 	return KErrNone;
       
   108 	}
       
   109 
       
   110 void CDEF079378::DoCancel()
       
   111 	{
       
   112 	}
       
   113 
       
   114 const TDesC& CDEF079378::TestName()
       
   115 	{
       
   116 	_LIT(KHeaderTestName,"CDEF079378");
       
   117 	return KHeaderTestName;
       
   118 	}
       
   119 
       
   120 TInt CDEF079378::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/)
       
   121 	{
       
   122 	_LIT(KLogDescription, "\nTest failed with error code %d on transaction ID=%d\n");
       
   123 	iEngine->Utils().LogIt(KLogDescription, aError, aTransaction.Id());
       
   124 	iFailureError = aError;
       
   125 	CActiveScheduler::Stop();
       
   126 	return KErrNone;
       
   127 	}
       
   128 
       
   129 void CDEF079378::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
       
   130 	{
       
   131 	switch (aEvent.iStatus)
       
   132 		{
       
   133 		case THTTPEvent::EGotResponseHeaders:
       
   134 			{
       
   135 			// HTTP response headers have been received
       
   136 			iEngine->Utils().LogIt(_L("<Got response headers>"));
       
   137 			} break;
       
   138 		case THTTPEvent::ESubmit:
       
   139 			{
       
   140 			} break;
       
   141 		case THTTPEvent::EGotResponseBodyData:
       
   142 			{
       
   143 			// Some (more) body data has been received (in the HTTP response)
       
   144 			iEngine->Utils().LogIt(_L("<Got a chunk of data>"));
       
   145 			} break;
       
   146 		case THTTPEvent::EResponseComplete:
       
   147 			{
       
   148 			// The transaction's response is complete
       
   149 			iEngine->Utils().LogIt(_L("<Transaction Complete>"));
       
   150 			} break;
       
   151 		case THTTPEvent::ESucceeded:
       
   152 			{
       
   153 			// The transaction succeeded
       
   154 			iEngine->Utils().LogIt(_L("<Transaction succeeded>"));
       
   155 			aTransaction.Close();
       
   156 			CActiveScheduler::Stop();
       
   157 			}
       
   158 			break;
       
   159 		case THTTPEvent::EFailed:
       
   160 			{
       
   161 			// The transaction failed so fail the test
       
   162 			iEngine->Utils().LogIt(_L("<Transaction failed>"));
       
   163 			aTransaction.Close();
       
   164 			CActiveScheduler::Stop();
       
   165 			} break;
       
   166 		default:
       
   167 			{
       
   168 			_LIT(KLogDescription, "<unrecognised event> %d");
       
   169 			iEngine->Utils().LogIt(KLogDescription,aEvent.iStatus);
       
   170 			if (aEvent.iStatus < 0)
       
   171 				{
       
   172 				iFailureError = aEvent.iStatus;
       
   173 				CActiveScheduler::Stop();
       
   174 				}
       
   175 			} 
       
   176 			break;
       
   177 		}
       
   178 	
       
   179 	return;
       
   180 	}
       
   181 
       
   182 
       
   183 void CDEF079378::ConfigureSessionFiltersL(TFilterConfigurationIterator* /*aFilterConfigIter*/)
       
   184 	{
       
   185 	if (iTestNumber == 11)
       
   186 		{
       
   187 		User::Leave(KErrNone);
       
   188 		}
       
   189 
       
   190 	iCookieManager = CExampleCookieManager::NewL(iSession.StringPool());
       
   191 
       
   192 	CCookieFilterInterface::InstallFilterL(iSession, iCookieManager);
       
   193 	}
       
   194 
       
   195 TBool CDEF079378::GetCredentialsL(const TUriC8& /*aURI*/, RString /*aRealm*/, 
       
   196 								   RStringF /*aAuthenticationType*/,
       
   197 								   RString& /*aUsername*/, 
       
   198 								   RString& /*aPassword*/)
       
   199 
       
   200 	{
       
   201 	User::Leave(KErrGeneral);
       
   202 	return EFalse;
       
   203 	}