applayerprotocols/httptransportfw/Test/Acceptance/Iter2/EofTransactionResubmission.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2004-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 "EofTransactionResubmission.h"
       
    17 #include <http.h>
       
    18 #include "csrvaddrval.h"
       
    19 
       
    20 // Literals used in the file
       
    21 _LIT8(KWapTestUrl,			"http://WapTestName");
       
    22 
       
    23 /**
       
    24 	This function returns the name of the test.
       
    25 */
       
    26 const TDesC& CEofTransactionResubmission::TestName()
       
    27 	{
       
    28 	_LIT(KHeaderTestName,"Resubmission due to EOF error returned from socket");
       
    29 	return KHeaderTestName;
       
    30 	}
       
    31 
       
    32 CEofTransactionResubmission::CEofTransactionResubmission(CScriptFile* aIniSettingsFile) 
       
    33 	:	iIniSettingsFile(aIniSettingsFile)
       
    34 	{
       
    35 	iTransNum=0;
       
    36 	iTransSucceeded=0;
       
    37 	iExpectedStatusCode=200;
       
    38 	}
       
    39 
       
    40 /**
       
    41 	This function is opens a session for the test being executed.
       
    42 
       
    43 	@leave		Leaves with a standard error.
       
    44 */
       
    45 void CEofTransactionResubmission::OpenTestSessionL()
       
    46 	{
       
    47 	//open a default Session
       
    48 	iSession.OpenL();
       
    49 	iSetCredentials=ETrue;
       
    50 
       
    51 	//Logs 
       
    52 	iEngine->Utils().LogIt(_L("Session Created(Iteration 2 Get Test 17)"));
       
    53 	iEngine->Utils().LogIt(_L("Session parameters: Default"));
       
    54 	
       
    55 	//Get the iSession'string pool handle;
       
    56 	iMyStrP = iSession.StringPool();
       
    57 	}
       
    58 
       
    59 /**
       
    60 	This function closes all the transactions and sessions opened.
       
    61 */
       
    62 void CEofTransactionResubmission::CloseTestSession()
       
    63 	{
       
    64 	//Close all the 8 Transactions opened in the DoRunL()
       
    65 	iTransaction1.Close();
       
    66 	iEngine->Utils().LogIt(_L("Transaction1 terminated\n"));
       
    67 	iTransaction2.Close();
       
    68 	iEngine->Utils().LogIt(_L("Transaction2 terminated\n"));
       
    69 	//and close the session
       
    70 	iSession.Close();
       
    71 	iEngine->Utils().LogIt(_L("Session terminated"));
       
    72 	}
       
    73 
       
    74 /**
       
    75 	3 Digest authentication transactions are executed from this function.
       
    76 
       
    77 	@leave		Leaves with a standard error.
       
    78 */
       
    79 void CEofTransactionResubmission::DoRunL()
       
    80 	{
       
    81 	OpenTestSessionL(); 
       
    82 
       
    83 	//Trans1
       
    84 	OpenTestTrans1L();
       
    85 	iTransaction1.SubmitL();
       
    86 	iTransNum++;
       
    87 	i2ndTrans=EFalse;
       
    88 
       
    89 	CActiveScheduler::Start();
       
    90 
       
    91 	CloseTestSession();
       
    92 	if (iTestFail==1)
       
    93 		{
       
    94 		User::Leave(-1);
       
    95 		}
       
    96 	}
       
    97 
       
    98 void CEofTransactionResubmission::OpenTestTrans1L()
       
    99 	{
       
   100 	// Literals used in the function
       
   101 	_LIT8(KUrlPath,				"/stats.html");
       
   102 
       
   103 	// Replace the host name in the URL
       
   104 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
       
   105 	CleanupStack::PushL(newUrl8);
       
   106 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
   107 	newUrlPtr8.Append(KUrlPath());
       
   108 
       
   109 	TUriParser8 testURI1; 
       
   110 	testURI1.Parse(newUrlPtr8);
       
   111 	
       
   112 	//open a GET transaction and log it
       
   113 	iTransaction1 = iSession.OpenTransactionL(testURI1, *this, iMyStrP.StringF(HTTP::EGET,RHTTPSession::GetTable()));
       
   114 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
   115 	DisablePipeliningL(iTransaction1);
       
   116 
       
   117 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
   118 	iEngine->Utils().LogIt(_L("Method:GET"));
       
   119 	CleanupStack::PopAndDestroy(newUrl8);
       
   120 	}
       
   121 
       
   122 void CEofTransactionResubmission::OpenTestTrans2L()
       
   123 	{
       
   124 	// Literals used in the function
       
   125 	_LIT8(KUrlPath,				"/manual/windows.html");
       
   126 
       
   127 	// Replace the host name in the URL
       
   128 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
       
   129 	CleanupStack::PushL(newUrl8);
       
   130 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
   131 	newUrlPtr8.Append(KUrlPath());
       
   132 
       
   133 	TUriParser8 testURI1; 
       
   134 	testURI1.Parse(newUrlPtr8);
       
   135 	
       
   136 	//open a GET transaction and log it
       
   137 	iTransaction2 = iSession.OpenTransactionL(testURI1, *this, iMyStrP.StringF(HTTP::EGET,RHTTPSession::GetTable()));
       
   138 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
   139 	DisablePipeliningL(iTransaction2);
       
   140 
       
   141 	// Log the Request parameters
       
   142 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
   143 	iEngine->Utils().LogIt(_L("Method:GET"));
       
   144 	CleanupStack::PopAndDestroy(newUrl8);
       
   145 	}
       
   146 
       
   147 TInt CEofTransactionResubmission::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/,
       
   148 											  const THTTPEvent& /*aEvent*/)
       
   149 	{
       
   150 	iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aError);
       
   151 	return KErrNone;
       
   152 	}
       
   153 
       
   154 void CEofTransactionResubmission::MHFRunL(RHTTPTransaction aTransaction,
       
   155 										  const THTTPEvent& aEvent)
       
   156 	{
       
   157 	switch (aEvent.iStatus)
       
   158 		{
       
   159 	case THTTPEvent::EGotResponseHeaders:
       
   160 		{
       
   161 		// HTTP response headers have been received
       
   162 		iEngine->Utils().LogIt(_L("<EGotResponseHeaders>\n"));
       
   163 		TInt  statusCode = aTransaction.Response().StatusCode();
       
   164 		iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode);
       
   165 		DumpRespHeaders(aTransaction);
       
   166 		iEngine->SetCurrentStatusCode(statusCode);
       
   167 		if (iExpectedStatusCode != statusCode)
       
   168 			{
       
   169 			iTestFail=1;
       
   170 			iEngine->Utils().LogIt(_L("<The Test will fail :The expected status code doesn't match the actual status code received>\n"));
       
   171 			}
       
   172 		} break;
       
   173 	case THTTPEvent::EGotResponseBodyData:
       
   174 		{
       
   175 		// Some (more) body data has been received (in the HTTP response)
       
   176 		iEngine->Utils().LogIt(_L("<EGotResponseBodyData received>\n"));
       
   177 		// for each chunk of data received we have to empty the buffer 
       
   178 		// before to be able to receive 
       
   179 		MHTTPDataSupplier* body = aTransaction.Response().Body();
       
   180 		body->ReleaseData();
       
   181 		} break;
       
   182 	case THTTPEvent::EResponseComplete:
       
   183 		{
       
   184 		// The transaction's response is complete
       
   185 		iEngine->Utils().LogIt(_L("<EResponseComplete received >\n"));
       
   186 		
       
   187 		} break;
       
   188 	case THTTPEvent::ESucceeded:
       
   189 		{
       
   190 		transCount++;
       
   191 		iTransSucceeded++;
       
   192 		iEngine->Utils().LogIt(_L("<ESucceeded received >\n"));
       
   193 
       
   194 		if (!i2ndTrans)
       
   195 			{
       
   196 			User::After(20*1000000);
       
   197 			OpenTestTrans2L();
       
   198 			iTransaction2.SubmitL();
       
   199 			iTransNum++;
       
   200 			i2ndTrans=ETrue;
       
   201 			}
       
   202 
       
   203 	if (transCount<=iTransNum)
       
   204 			{
       
   205 			if(iTransSucceeded==iTransNum)
       
   206 				{
       
   207 				iEngine->Utils().LogIt(_L("The test has PASSED"));
       
   208 				CActiveScheduler::Stop();
       
   209 				} 
       
   210 			}
       
   211 		else 
       
   212 			{
       
   213 			iTestFail=1;
       
   214 			iEngine->Utils().LogIt(_L("<The Test will fail:less than %d ESucceeded have been received>\n"),iTransNum);		
       
   215 			}
       
   216 		} break;
       
   217 	case THTTPEvent::EFailed:
       
   218 		{
       
   219 		TInt  statusCode = aTransaction.Response().StatusCode();
       
   220 		iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode);
       
   221 		} break;
       
   222 	default:
       
   223 		{
       
   224 		iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus);
       
   225 		iEngine->Utils().LogIt(_L("Test Failed\n"));
       
   226 		iEngine->PressAnyKey();
       
   227 		CActiveScheduler::Stop();
       
   228 		} 
       
   229 		break;
       
   230 		}
       
   231 	}
       
   232 
       
   233 
       
   234 void CEofTransactionResubmission::DisablePipeliningL(RHTTPTransaction trans)
       
   235 	{
       
   236 	RStringPool strPool = iSession.StringPool();
       
   237 
       
   238 	RHTTPTransactionPropertySet transactionPropertySet = trans.PropertySet();
       
   239 	RStringF name = strPool.StringF(HTTP::EHttpPipelining, RHTTPSession::GetTable());
       
   240 	RStringF value = strPool.StringF(HTTP::EDisablePipelining, RHTTPSession::GetTable());
       
   241 	transactionPropertySet.SetPropertyL(name,value);
       
   242 	}