applayerprotocols/httptransportfw/Test/Acceptance/Iter1/Tc10.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 // Author: Franco.Bellu@symbian.com
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 #include "Tc10.h"
       
    20 #include <http.h>
       
    21 #include "testservers.h"
       
    22 
       
    23 _LIT8(KWapTestUrl,			"http://WapTestIP");
       
    24 
       
    25 CHttpTestCase10::CHttpTestCase10(CScriptFile* aIniSettingsFile) : 
       
    26 	CHttpTestTransBase(),
       
    27 	iIniSettingsFile(aIniSettingsFile)
       
    28 	{
       
    29 	}
       
    30 
       
    31 void CHttpTestCase10::DoRunL()
       
    32 	{
       
    33 	iSession.OpenL();
       
    34 	iEngine->Utils().LogIt(_L("Session Created(10) (Default parameters)"));	
       
    35 	iMyStrP = iSession.StringPool();
       
    36 	
       
    37 	OpenTestTransaction1L();
       
    38 	iTransaction.SubmitL();
       
    39 	CActiveScheduler::Start();
       
    40 	CloseTestTransaction1();
       
    41 
       
    42 	OpenTestTransaction2L();
       
    43 	iTransaction.SubmitL();
       
    44 	CActiveScheduler::Start();
       
    45 	CloseTestTransaction2();
       
    46 
       
    47 	iSession.Close();
       
    48 	if (iTestFail==1)
       
    49 		{
       
    50 		User::Leave(-1);
       
    51 		}
       
    52 	iEngine->Utils().LogIt(_L("Session terminated"));
       
    53 	}
       
    54 	
       
    55 TInt CHttpTestCase10::RunError(TInt aErr)
       
    56 	{
       
    57 	iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr);
       
    58 	return KErrNone;
       
    59 	}
       
    60 
       
    61 void CHttpTestCase10::DoCancel()
       
    62 	{
       
    63 	}
       
    64 
       
    65 CHttpTestCase10::~CHttpTestCase10()
       
    66 	{
       
    67 	}	
       
    68 
       
    69 /** increment the value of iState and set active to create call to RunL
       
    70 	with new state value 
       
    71 */
       
    72 
       
    73 /** set this object active */
       
    74 void CHttpTestCase10::CompleteOwnRequest()
       
    75 	{
       
    76 	TRequestStatus* stat = &iStatus;
       
    77 	User::RequestComplete(stat,KErrNone);	
       
    78 	if (!IsActive())
       
    79 		SetActive();
       
    80 	}
       
    81 
       
    82 /** sets base test name.
       
    83 	@param void
       
    84 	@return string - the test name 
       
    85 */
       
    86 const TDesC& CHttpTestCase10::TestName()
       
    87 	{
       
    88 	_LIT(KHeaderTestName,"Test Case 10 ");
       
    89 	return KHeaderTestName;
       
    90 	}
       
    91 
       
    92 
       
    93 TInt CHttpTestCase10::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/,
       
    94 								  const THTTPEvent& /*aEvent*/)
       
    95 	{
       
    96 	iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aError);
       
    97 	return KErrNone;
       
    98 	}
       
    99 
       
   100 void CHttpTestCase10::MHFRunL(RHTTPTransaction aTransaction,
       
   101 							  const THTTPEvent& aEvent)
       
   102 	{
       
   103 	if(aEvent.iUID!=KHTTPUid)
       
   104 		{
       
   105 		iEngine->Utils().LogIt(_L("\nTHTTPEvent::iUID =%d"),aEvent.iUID);
       
   106 		}
       
   107 
       
   108 	switch (aEvent.iStatus)
       
   109 			{
       
   110 	case THTTPEvent::EGotResponseHeaders:
       
   111 		{
       
   112 		// HTTP response headers have been received
       
   113 		iEngine->Utils().LogIt(_L("<EGotResponseHeaders>\n"));
       
   114 		TInt  statusCode = aTransaction.Response().StatusCode();
       
   115 		iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode);
       
   116 		DumpRespHeaders(aTransaction);
       
   117 		iEngine->SetCurrentStatusCode(statusCode);
       
   118 		} break;
       
   119 
       
   120 	case THTTPEvent::EGotResponseBodyData:
       
   121 		{
       
   122 		// Some (more) body data has been received (in the HTTP response)
       
   123 		iEngine->Utils().LogIt(_L("<EGotResponseBodyData received>\n"));
       
   124 		// for each chunk of data received we have to empty the buffer before 
       
   125 		// to be able to receive 
       
   126 		MHTTPDataSupplier* body = aTransaction.Response().Body();
       
   127 		body->ReleaseData();
       
   128 		} break;
       
   129 	case THTTPEvent::EResponseComplete:
       
   130 		{
       
   131 		// The transaction's response is complete
       
   132 		iEngine->Utils().LogIt(_L("<EResponseComplete received >\n"));
       
   133 		} break;
       
   134 	case THTTPEvent::ESucceeded:
       
   135 		{
       
   136 		iEngine->Utils().LogIt(_L("<ESucceeded received>\n"));
       
   137 		CActiveScheduler::Stop();
       
   138 		} break;
       
   139 	case THTTPEvent::EFailed:
       
   140 		{
       
   141 		iEngine->Utils().LogIt(_L("<EFailed received>\n"));
       
   142 		CActiveScheduler::Stop();
       
   143 		} break;
       
   144 	default:
       
   145 		{
       
   146 		iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus);
       
   147 		if (aEvent.iStatus < THTTPEvent::ERedirectedPermanently)
       
   148 			{
       
   149 			iTestFail=1;
       
   150 			iEngine->Utils().LogIt(_L("Test Failed: The event received was not expected and it's not just a warning\n"));
       
   151 			iEngine->PressAnyKey();
       
   152 			CActiveScheduler::Stop();
       
   153 			}
       
   154 		} 
       
   155 		break;
       
   156 		}
       
   157 	}
       
   158 
       
   159 void CHttpTestCase10::OpenTestTransaction1L()
       
   160 	{
       
   161 	// Literals used in the function
       
   162 	_LIT8(KUrlPath,				"/perl/dumpform.pl");
       
   163 
       
   164 	// Replace the host name in the URL
       
   165 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
       
   166 	CleanupStack::PushL(newUrl8);
       
   167 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
   168 	newUrlPtr8.Append(KUrlPath());
       
   169 
       
   170 	TUriParser8 testURI;
       
   171 	testURI.Parse(newUrlPtr8);
       
   172 
       
   173 	//get the string handles this testcase needs
       
   174 	RStringF textPlain = iMyStrP.StringF(HTTP::ETextPlain, RHTTPSession::GetTable());
       
   175 	RStringF textHtml = iMyStrP.StringF(HTTP::ETextHtml, RHTTPSession::GetTable());
       
   176 	RStringF mimeType = iMyStrP.StringF(HTTP::EApplicationXWwwFormUrlEncoded, RHTTPSession::GetTable());
       
   177 	iUnknownHeader = iMyStrP.OpenFStringL(_L8("UnknownHeader:"));
       
   178 
       
   179 	//open  a Transaction in iSession 
       
   180 	iTransaction = iSession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EPOST,RHTTPSession::GetTable()));
       
   181 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
   182 
       
   183 	//Get a handle of the request in iTransaction
       
   184 	RHTTPRequest myRequest = iTransaction.Request();
       
   185 	RHTTPHeaders myHeaders = myRequest.GetHeaderCollection();
       
   186 	//provide  some headers 
       
   187 	THTTPHdrVal v2(textPlain);
       
   188 	THTTPHdrVal v3(textHtml);
       
   189 	THTTPHdrVal v4(6);
       
   190 	THTTPHdrVal v5(mimeType);
       
   191 	THTTPHdrVal v6(iUnknownHeader);
       
   192 
       
   193 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),v2);
       
   194 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),v3);
       
   195 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentLength, RHTTPSession::GetTable()),v4);
       
   196 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentType, RHTTPSession::GetTable()), v5);
       
   197 	myHeaders.SetFieldL(iMyStrP.StringF(iUnknownHeader), v6);
       
   198 
       
   199 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
   200 	iEngine->Utils().LogIt(_L("Method:Post"));
       
   201 	iEngine->Utils().LogIt(_L("Accept:test/plain,text/html"));
       
   202 	iEngine->Utils().LogIt(_L("Content-Type: application/x-www-form-urlencoded"));
       
   203 	iEngine->Utils().LogIt(_L("Content-Length: 6"));
       
   204 	iEngine->Utils().LogIt(_L("UnknownHeader:UnknownHeader:"));
       
   205 	myRequest.SetBody(*this);
       
   206 	CleanupStack::PopAndDestroy(newUrl8);
       
   207 	}
       
   208 
       
   209 void CHttpTestCase10::CloseTestTransaction1()
       
   210 	{
       
   211 	iUnknownHeader.Close();
       
   212 	//close Transaction 
       
   213 	iTransaction.Close();
       
   214 	iEngine->Utils().LogIt(_L("Transaction terminated\n"));
       
   215 	}
       
   216 
       
   217 void CHttpTestCase10::OpenTestTransaction2L()
       
   218 	{
       
   219 	// Literals used in the function
       
   220 	_LIT8(KUrlPath,				"/perl/dumpform.pl");
       
   221 
       
   222 	// Replace the host name in the URL
       
   223 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
       
   224 	CleanupStack::PushL(newUrl8);
       
   225 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
   226 	newUrlPtr8.Append(KUrlPath());
       
   227 
       
   228 	TUriParser8 testURI;
       
   229 	testURI.Parse(newUrlPtr8);
       
   230 
       
   231 	//get the string handles this testcase needs
       
   232 	RStringF textPlain = iMyStrP.StringF(HTTP::ETextPlain, RHTTPSession::GetTable());
       
   233 	RStringF textHtml = iMyStrP.StringF(HTTP::ETextHtml, RHTTPSession::GetTable());
       
   234 	RStringF mimeType = iMyStrP.StringF(HTTP::EApplicationXWwwFormUrlEncoded, RHTTPSession::GetTable());
       
   235 
       
   236 	//open  a Transaction in iSession 
       
   237 	iTransaction = iSession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EPOST,RHTTPSession::GetTable()));
       
   238 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
   239 
       
   240 	//Get a handle of the request in iTransaction
       
   241 	RHTTPRequest myRequest = iTransaction.Request();
       
   242 	RHTTPHeaders myHeaders = myRequest.GetHeaderCollection();
       
   243 
       
   244 	//provide  some headers 
       
   245 	THTTPHdrVal v2(textPlain);
       
   246 	THTTPHdrVal v3(textHtml);
       
   247 	THTTPHdrVal v4(6);
       
   248 	THTTPHdrVal v5(mimeType);
       
   249 
       
   250 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),v2);
       
   251 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),v3);
       
   252 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentLength, RHTTPSession::GetTable()),v4);
       
   253 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentType, RHTTPSession::GetTable()), v5);
       
   254 
       
   255  	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
   256 	iEngine->Utils().LogIt(_L("Method:Post"));
       
   257 	iEngine->Utils().LogIt(_L("Accept:test/plain,text/html"));
       
   258 	iEngine->Utils().LogIt(_L("Content-Type: application/x-www-form-urlencoded"));
       
   259 	iEngine->Utils().LogIt(_L("Content-Length: 6"));
       
   260 	myRequest.SetBody(*this);
       
   261 	CleanupStack::PopAndDestroy(newUrl8);
       
   262 
       
   263 	//this event should be ignored by the VF
       
   264 	iTransaction.SendEventL(THTTPEvent(0,0x1000A440),THTTPEvent::EIncoming, THTTPFilterHandle::EClient );
       
   265 	}
       
   266 
       
   267 void CHttpTestCase10::CloseTestTransaction2()
       
   268 	{
       
   269 	//close Transaction 
       
   270 	iTransaction.Close();
       
   271 	iEngine->Utils().LogIt(_L("Transaction terminated\n"));
       
   272 	}