applayerprotocols/httptransportfw/Test/Acceptance/Iter1/Tc3.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 "Tc3.h"
       
    20 #include <http.h>
       
    21 #include "testservers.h"
       
    22 
       
    23 #include "csrvaddrval.h"
       
    24 
       
    25 void CHttpTestCase3::DoRunL()
       
    26 	{
       
    27 	// Literals used in the function
       
    28 	_LIT(KWapTestUrl,			"http://WapTestIP/perl/dumpform.pl");
       
    29 
       
    30 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl());
       
    31 	CleanupStack::PushL(newUrl8);
       
    32 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
    33 
       
    34 	TUriParser8 testURI; 
       
    35 	testURI.Parse(newUrlPtr8);
       
    36 	
       
    37 	//open a Session
       
    38 	RHTTPSession mySession;
       
    39 	mySession.OpenL();
       
    40 	CleanupClosePushL(mySession);
       
    41 	iEngine->Utils().LogIt(_L("Session Created(TC3)"));
       
    42 	iEngine->Utils().LogIt(_L("Session parameters: Default"));
       
    43 
       
    44 	//Get the mySession'string pool handle;
       
    45 	iMyStrP = mySession.StringPool();
       
    46 
       
    47 	//get strings this testcase needs
       
    48 	RStringF textPlain = iMyStrP.StringF(HTTP::ETextPlain,RHTTPSession::GetTable());
       
    49 	RStringF textHtml = iMyStrP.StringF(HTTP::ETextHtml,RHTTPSession::GetTable());
       
    50 	RStringF mimeType = iMyStrP.StringF(HTTP::EApplicationXWwwFormUrlEncoded,RHTTPSession::GetTable());
       
    51 
       
    52 	//Open a Transaction in mySession 
       
    53 	RHTTPTransaction myTransaction;
       
    54 	myTransaction = mySession.OpenTransactionL(testURI, *this,iMyStrP.StringF(HTTP::EPOST,RHTTPSession::GetTable()));
       
    55 	CleanupClosePushL(myTransaction);
       
    56 	iEngine->Utils().LogIt(_L("Transaction Created in mySession"));
       
    57 	
       
    58 	//Get a handle of the request in myTransaction
       
    59 	RHTTPRequest myRequest = myTransaction.GetRequest();
       
    60 	RHTTPHeaders myHeaders = myRequest.GetHeaderCollection();	
       
    61 
       
    62 	//provide  some headers 
       
    63 	THTTPHdrVal v2(textPlain);
       
    64 	THTTPHdrVal v3(textHtml);
       
    65 	THTTPHdrVal v4(6);
       
    66 	THTTPHdrVal v5(mimeType);
       
    67 
       
    68 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept,RHTTPSession::GetTable()),v2);
       
    69 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept,RHTTPSession::GetTable()),v3);
       
    70 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentLength,RHTTPSession::GetTable()),v4);
       
    71 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentType,RHTTPSession::GetTable()), v5);
       
    72 
       
    73 	iEngine->Utils().LogIt(KWapTestUrl());
       
    74 	iEngine->Utils().LogIt(_L("Method:Post"));
       
    75 	iEngine->Utils().LogIt(_L("Accept:test/plain,text/html"));
       
    76 	iEngine->Utils().LogIt(_L("Content-Type: application/x-www-form-urlencoded"));
       
    77 	iEngine->Utils().LogIt(_L("Content-Length: 6"));
       
    78 		
       
    79 	myRequest.SetBody(*this);
       
    80 	myTransaction.SubmitL();
       
    81 	CActiveScheduler::Start();
       
    82 
       
    83 	//close transaction and session
       
    84 	myTransaction.Close();
       
    85 	iEngine->Utils().LogIt(_L("Transaction terminated\n"));
       
    86 	mySession.Close();
       
    87 	iEngine->Utils().LogIt(_L("Session terminated"));
       
    88 	CleanupStack::Pop(3, newUrl8); // mySession,myTansaction
       
    89 	}
       
    90 	
       
    91 TInt CHttpTestCase3::RunError(TInt aErr)
       
    92 	{
       
    93 	iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr);
       
    94 	return KErrNone;
       
    95 	}
       
    96 
       
    97 void CHttpTestCase3::DoCancel()
       
    98 	{
       
    99 	}
       
   100 
       
   101 CHttpTestCase3::~CHttpTestCase3()
       
   102 	{
       
   103 	}	
       
   104 
       
   105 /** set this object active */
       
   106 void CHttpTestCase3::CompleteOwnRequest()
       
   107 	{
       
   108 	TRequestStatus* stat = &iStatus;
       
   109 	User::RequestComplete(stat,KErrNone);	
       
   110 	if (!IsActive())
       
   111 		SetActive();
       
   112 	}
       
   113 
       
   114 
       
   115 /** sets base test name.
       
   116 	@param void
       
   117 	@return string - the test name 
       
   118 */
       
   119 const TDesC& CHttpTestCase3::TestName()
       
   120 	{
       
   121 	_LIT(KHeaderTestName,"Test Case 3 ");
       
   122 	return KHeaderTestName;
       
   123 	}
       
   124 
       
   125 TInt CHttpTestCase3::MHFRunError(TInt aError, 
       
   126 										RHTTPTransaction /*aTransaction*/,
       
   127 										const THTTPEvent& /*aEvent*/)
       
   128 	{
       
   129 	iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aError);
       
   130 	return KErrNone;
       
   131 	}
       
   132 
       
   133 void CHttpTestCase3::MHFRunL(RHTTPTransaction aTransaction,
       
   134 						 const THTTPEvent& aEvent)
       
   135 	{
       
   136 	switch (aEvent.iStatus)
       
   137 			{
       
   138 	case THTTPEvent::EGotResponseHeaders:
       
   139 		{
       
   140 		// HTTP response headers have been received
       
   141 		iEngine->Utils().LogIt(_L("<EGotResponseHeaders received>\n"));
       
   142 		DumpRespHeaders(aTransaction);
       
   143 		iEngine->SetCurrentStatusCode(aTransaction.GetResponse().Status());
       
   144 		} break;
       
   145 	case THTTPEvent::EGotResponseBodyData:
       
   146 		{
       
   147 		// Some (more) body data has been received (in the HTTP response)
       
   148 		iEngine->Utils().LogIt(_L("<EGotResponseBodyData received>\n"));
       
   149 		// for each chunk of data received we have to empty the buffer before to be able to receive 
       
   150 		MHTTPDataSupplier& body = aTransaction.GetResponse().GetBody();
       
   151 		body.ReleaseData();
       
   152 		} break;
       
   153 	case THTTPEvent::EResponseComplete:
       
   154 		{
       
   155 		// The transaction's response is complete
       
   156 		iEngine->Utils().LogIt(_L("<EResponseComplete received>\n"));
       
   157 		} break;
       
   158 	case THTTPEvent::ESucceeded:
       
   159 		{
       
   160 		iEngine->Utils().LogIt(_L("<ESucceeded received>\n"));
       
   161 		CActiveScheduler::Stop();
       
   162 		} break;
       
   163 	default:
       
   164 		{
       
   165 		iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus);
       
   166 		iEngine->Utils().LogIt(_L("Test Failed\n"));
       
   167 		iEngine->PressAnyKey();
       
   168 		CActiveScheduler::Stop();
       
   169 		} 
       
   170 		break;
       
   171 		}
       
   172 	}
       
   173