applayerprotocols/httptransportfw/Test/Acceptance/Iter2/Get17.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 "Get17.h"
       
    17 #include <http.h>
       
    18 #include "csrvaddrval.h"
       
    19 
       
    20 _LIT8(KWapTestUrl,			"http://WapTestIP:9002/");
       
    21 
       
    22 const TDesC& CHttpTestCaseGet17::TestName()
       
    23 	{
       
    24 	_LIT(KHeaderTestName,"Iteration 2 Get Test 17 ");
       
    25 	return KHeaderTestName;
       
    26 	}
       
    27 
       
    28 CHttpTestCaseGet17::CHttpTestCaseGet17(CScriptFile* aIniSettingsFile)
       
    29 	:	iIniSettingsFile(aIniSettingsFile)
       
    30 	{
       
    31 	iTransNum=0;
       
    32 	iTransSucceeded=0;
       
    33 	}
       
    34 
       
    35 void CHttpTestCaseGet17::OpenTestSessionL()
       
    36 	{
       
    37 	//open a default Session
       
    38 	iSession.OpenL();
       
    39 
       
    40 	//Logs 
       
    41 	iEngine->Utils().LogIt(_L("Session Created(Iteration 2 Get Test 17)"));
       
    42 	iEngine->Utils().LogIt(_L("Session parameters: Default"));
       
    43 	
       
    44 	//Get the iSession'string pool handle;
       
    45 	iMyStrP = iSession.StringPool();
       
    46 	}
       
    47 
       
    48 void CHttpTestCaseGet17::CloseTestSession()
       
    49 	{
       
    50 	//Close all the 8 Transactions opened in the DoRunL()
       
    51 	iTransaction1.Close();
       
    52 	iEngine->Utils().LogIt(_L("Transaction1 terminated\n"));
       
    53 	iTransaction2.Close();
       
    54 	iEngine->Utils().LogIt(_L("Transaction2 terminated\n"));
       
    55 	iTransaction3.Close();
       
    56 	iEngine->Utils().LogIt(_L("Transaction3 terminated\n"));
       
    57 	iTransaction4.Close();
       
    58 	iEngine->Utils().LogIt(_L("Transaction4 terminated\n"));
       
    59 	iTransaction5.Close();
       
    60 	iEngine->Utils().LogIt(_L("Transaction5 terminated\n"));
       
    61 	iTransaction6.Close();
       
    62 	iEngine->Utils().LogIt(_L("Transaction6 terminated\n"));
       
    63 	iTransaction7.Close();
       
    64 	iEngine->Utils().LogIt(_L("Transaction7 terminated\n"));
       
    65 	iTransaction8.Close();
       
    66 	iEngine->Utils().LogIt(_L("Transaction8 terminated\n"));
       
    67 	//and close the session
       
    68 	iSession.Close();
       
    69 	iEngine->Utils().LogIt(_L("Session terminated"));
       
    70 	}
       
    71 
       
    72 void CHttpTestCaseGet17::DoRunL()
       
    73 	{
       
    74 	OpenTestSessionL(); 
       
    75 
       
    76 	//Trans1
       
    77 	OpenTestTrans1L();
       
    78 	iTransaction1.SubmitL();
       
    79 	iTransNum++;
       
    80 	//Trans2
       
    81 	OpenTestTrans2L();
       
    82 	iTransaction2.SubmitL();
       
    83 	iTransNum++;
       
    84 
       
    85 	//Trans3
       
    86 	OpenTestTrans3L();
       
    87 	iTransaction3.SubmitL();
       
    88 	iTransNum++;
       
    89 
       
    90 	//Trans4
       
    91 	OpenTestTrans4L();
       
    92 	iTransaction4.SubmitL();
       
    93 	iTransNum++;
       
    94 	//Trans5
       
    95 	OpenTestTrans5L();
       
    96 	iTransaction5.SubmitL();
       
    97 	iTransNum++;
       
    98 
       
    99 	//Trans6
       
   100 	OpenTestTrans6L();
       
   101 	iTransaction6.SubmitL();
       
   102 	iTransNum++;
       
   103 
       
   104 	//Trans7
       
   105 	OpenTestTrans7L();
       
   106 	iTransaction7.SubmitL();
       
   107 	iTransNum++;
       
   108 
       
   109 	//Trans8
       
   110 	OpenTestTrans8L();
       
   111 	iTransaction8.SubmitL();
       
   112 	iTransNum++;
       
   113 
       
   114 	CActiveScheduler::Start();
       
   115 	
       
   116 	CloseTestSession();
       
   117 	if (iTestFail==1)
       
   118 		{
       
   119 		User::Leave(-1);
       
   120 		}
       
   121 	}
       
   122 
       
   123 void CHttpTestCaseGet17::OpenTestTrans1L()
       
   124 	{
       
   125 	// Replace the host name in the URL
       
   126 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
       
   127 	CleanupStack::PushL(newUrl8);
       
   128 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
   129 
       
   130 	TUriParser8 testURI1; 
       
   131 	testURI1.Parse(newUrlPtr8);
       
   132 	
       
   133 	//open a GET transaction and log it
       
   134 	iTransaction1 = iSession.OpenTransactionL(testURI1, *this, iMyStrP.StringF(HTTP::EGET,RHTTPSession::GetTable()));
       
   135 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
   136 
       
   137 	// Log the Request parameters
       
   138 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
   139 	iEngine->Utils().LogIt(_L("Method:GET"));
       
   140 	CleanupStack::PopAndDestroy(newUrl8);
       
   141 	}
       
   142 
       
   143 void CHttpTestCaseGet17::OpenTestTrans2L()
       
   144 	{
       
   145 	// Replace the host name in the URL
       
   146 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
       
   147 	CleanupStack::PushL(newUrl8);
       
   148 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
   149 
       
   150 	TUriParser8 testURI1; 
       
   151 	testURI1.Parse(newUrlPtr8);
       
   152 	
       
   153 	//open a GET transaction and log it
       
   154 	iTransaction2 = iSession.OpenTransactionL(testURI1, *this, iMyStrP.StringF(HTTP::EGET,RHTTPSession::GetTable()));
       
   155 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
   156 
       
   157 	// Log the Request parameters
       
   158 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
   159 	iEngine->Utils().LogIt(_L("Method:GET"));
       
   160 	CleanupStack::PopAndDestroy(newUrl8);
       
   161 	}
       
   162 
       
   163 void CHttpTestCaseGet17::OpenTestTrans3L()
       
   164 	{
       
   165 	// Replace the host name in the URL
       
   166 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
       
   167 	CleanupStack::PushL(newUrl8);
       
   168 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
   169 
       
   170 	TUriParser8 testURI1; 
       
   171 	testURI1.Parse(newUrlPtr8);
       
   172 	
       
   173 	//open a GET transaction and log it
       
   174 	iTransaction3 = iSession.OpenTransactionL(testURI1, *this, iMyStrP.StringF(HTTP::EGET,RHTTPSession::GetTable()));
       
   175 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
   176 
       
   177 	// Log the Request parameters
       
   178 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
   179 	iEngine->Utils().LogIt(_L("Method:GET"));
       
   180 	CleanupStack::PopAndDestroy(newUrl8);
       
   181 	}
       
   182 
       
   183 void CHttpTestCaseGet17::OpenTestTrans4L()
       
   184 	{
       
   185 	// Replace the host name in the URL
       
   186 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
       
   187 	CleanupStack::PushL(newUrl8);
       
   188 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
   189 
       
   190 	TUriParser8 testURI1; 
       
   191 	testURI1.Parse(newUrlPtr8);
       
   192 	
       
   193 	//open a GET transaction and log it
       
   194 	iTransaction4 = iSession.OpenTransactionL(testURI1, *this, iMyStrP.StringF(HTTP::EGET,RHTTPSession::GetTable()));
       
   195 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
   196 
       
   197 	// Log the Request parameters
       
   198 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
   199 	iEngine->Utils().LogIt(_L("Method:GET"));
       
   200 	CleanupStack::PopAndDestroy(newUrl8);
       
   201 	}
       
   202 
       
   203 void CHttpTestCaseGet17::OpenTestTrans5L()
       
   204 	{
       
   205 	// Replace the host name in the URL
       
   206 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
       
   207 	CleanupStack::PushL(newUrl8);
       
   208 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
   209 
       
   210 	TUriParser8 testURI1; 
       
   211 	testURI1.Parse(newUrlPtr8);
       
   212 	
       
   213 	//open a GET transaction and log it
       
   214 	iTransaction5 = iSession.OpenTransactionL(testURI1, *this, iMyStrP.StringF(HTTP::EGET,RHTTPSession::GetTable()));
       
   215 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
   216 
       
   217 	// Log the Request parameters
       
   218 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
   219 	iEngine->Utils().LogIt(_L("Method:GET"));
       
   220 	CleanupStack::PopAndDestroy(newUrl8);
       
   221 	}
       
   222 
       
   223 void CHttpTestCaseGet17::OpenTestTrans6L()
       
   224 	{
       
   225 	// Replace the host name in the URL
       
   226 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
       
   227 	CleanupStack::PushL(newUrl8);
       
   228 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
   229 
       
   230 	TUriParser8 testURI1; 
       
   231 	testURI1.Parse(newUrlPtr8);
       
   232 	
       
   233 	//open a GET transaction and log it
       
   234 	iTransaction6 = iSession.OpenTransactionL(testURI1, *this, iMyStrP.StringF(HTTP::EGET,RHTTPSession::GetTable()));
       
   235 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
   236 
       
   237 	// Log the Request parameters
       
   238 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
   239 	iEngine->Utils().LogIt(_L("Method:GET"));
       
   240 	CleanupStack::PopAndDestroy(newUrl8);
       
   241 	}
       
   242 
       
   243 void CHttpTestCaseGet17::OpenTestTrans7L()
       
   244 	{
       
   245 	// Replace the host name in the URL
       
   246 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
       
   247 	CleanupStack::PushL(newUrl8);
       
   248 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
   249 
       
   250 	TUriParser8 testURI1; 
       
   251 	testURI1.Parse(newUrlPtr8);
       
   252 	
       
   253 	//open a GET transaction and log it
       
   254 	iTransaction7 = iSession.OpenTransactionL(testURI1, *this, iMyStrP.StringF(HTTP::EGET,RHTTPSession::GetTable()));
       
   255 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
   256 
       
   257 	// Log the Request parameters
       
   258 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
   259 	iEngine->Utils().LogIt(_L("Method:GET"));
       
   260 	CleanupStack::PopAndDestroy(newUrl8);
       
   261 	}
       
   262 
       
   263 void CHttpTestCaseGet17::OpenTestTrans8L()
       
   264 	{
       
   265 	// Replace the host name in the URL
       
   266 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
       
   267 	CleanupStack::PushL(newUrl8);
       
   268 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
   269 
       
   270 	TUriParser8 testURI1; 
       
   271 	testURI1.Parse(newUrlPtr8);
       
   272 	
       
   273 	//open a GET transaction and log it
       
   274 	iTransaction8 = iSession.OpenTransactionL(testURI1, *this, iMyStrP.StringF(HTTP::EGET,RHTTPSession::GetTable()));
       
   275 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
   276 
       
   277 	// Log the Request parameters
       
   278 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
   279 	iEngine->Utils().LogIt(_L("Method:GET"));
       
   280 	CleanupStack::PopAndDestroy(newUrl8);
       
   281 	}
       
   282 
       
   283 TInt CHttpTestCaseGet17::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/,
       
   284 									 const THTTPEvent& /*aEvent*/)
       
   285 	{
       
   286 	iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aError);
       
   287 	return KErrNone;
       
   288 	}
       
   289 
       
   290 void CHttpTestCaseGet17::MHFRunL(RHTTPTransaction aTransaction,
       
   291 								 const THTTPEvent& aEvent)
       
   292 	{
       
   293 	switch (aEvent.iStatus)
       
   294 		{
       
   295 	case THTTPEvent::EGotResponseHeaders:
       
   296 		{
       
   297 		// HTTP response headers have been received
       
   298 		iEngine->Utils().LogIt(_L("<EGotResponseHeaders>\n"));
       
   299 		TInt  statusCode = aTransaction.Response().StatusCode();
       
   300 		iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode);
       
   301 		DumpRespHeaders(aTransaction);
       
   302 		iEngine->SetCurrentStatusCode(statusCode);
       
   303 		THTTPHdrVal headerValue;
       
   304 		RStringF xTransactionCount=iMyStrP.OpenFStringL(_L8("X-Transaction-Count"));
       
   305 		RStringF headerValueStr;
       
   306 		TBool headerValueExists=aTransaction.Response().GetHeaderCollection().GetField(xTransactionCount,0,headerValue);
       
   307 		if(headerValueExists)
       
   308 			{
       
   309 			iTestFail=-1;
       
   310 			iEngine->Utils().LogIt(_L("<the test will fail:'X-Transaction-Count'header not present in the response headers collection No %d>\n"),testHdrReceived);
       
   311 			// The test fails here so close the xTransactionCount and break here.
       
   312 			xTransactionCount.Close();
       
   313 			break;
       
   314 			}
       
   315 		else
       
   316 			{
       
   317 			testHdrReceived++;
       
   318 			}
       
   319 		headerValueStr= headerValue;
       
   320 		TDesC8 headerValueDes=headerValueStr.DesC();
       
   321 		_LIT8(KTwo,"2");
       
   322 		if (testHdrReceived>=5)
       
   323 			if( headerValueDes!=KTwo)
       
   324 				{
       
   325 				iEngine->Utils().LogIt(_L("<X-Transaction-Count header  No:%d  received == 2 >\n"),testHdrReceived);
       
   326 				} 
       
   327 			else{
       
   328 				iEngine->Utils().LogIt(_L("<the test will fail:X-Transaction-Count header  No:%d  received but  != 2 >\n"),testHdrReceived);
       
   329 				iTestFail=-1;
       
   330 				}
       
   331 		xTransactionCount.Close();
       
   332 		}break;
       
   333 	case THTTPEvent::EGotResponseBodyData:
       
   334 		{
       
   335 		// Some (more) body data has been received (in the HTTP response)
       
   336 		iEngine->Utils().LogIt(_L("<EGotResponseBodyData received>\n"));
       
   337 		// for each chunk of data received we have to empty the buffer before 
       
   338 		// to be able to receive 
       
   339 		MHTTPDataSupplier* body = aTransaction.Response().Body();
       
   340 		body->ReleaseData();
       
   341 		} break;
       
   342 	case THTTPEvent::EResponseComplete:
       
   343 		{
       
   344 		// The transaction's response is complete
       
   345 		iEngine->Utils().LogIt(_L("<EResponseComplete received >\n"));
       
   346 		
       
   347 		} break;
       
   348 	case THTTPEvent::ESucceeded:
       
   349 		{
       
   350 		transCount++;
       
   351 		iTransSucceeded++;
       
   352 		iEngine->Utils().LogIt(_L("<ESucceeded received >\n"));
       
   353 		if (transCount<=iTransNum)
       
   354 			{
       
   355 			if(iTransSucceeded==iTransNum)
       
   356 				{
       
   357 				iEngine->Utils().LogIt(_L("The test has PASSED"));
       
   358 				CActiveScheduler::Stop();
       
   359 				} 
       
   360 			}
       
   361 		else 
       
   362 			{
       
   363 			iTestFail=1;
       
   364 			iEngine->Utils().LogIt(_L("<The Test will fail:less than %d ESucceeded have been received>\n"),iTransNum);
       
   365 			}
       
   366 		} break;
       
   367 	case THTTPEvent::EFailed:
       
   368 		{
       
   369 		transCount++;
       
   370 		iTestFail=1;
       
   371 		iEngine->Utils().LogIt(_L("<The Test will fail:1 Transaction  has failed"));
       
   372 		iEngine->Utils().LogIt(_L("<EFailed received from the VF>\nThe Test has FAILED"));
       
   373 		CActiveScheduler::Stop();
       
   374 		} break;
       
   375 	default:
       
   376 		{
       
   377 		iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus);
       
   378 		iEngine->Utils().LogIt(_L("Test Failed\n"));
       
   379 		iEngine->PressAnyKey();
       
   380 		CActiveScheduler::Stop();
       
   381 		} 
       
   382 		break;
       
   383 		}
       
   384 	}