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