applayerprotocols/httptransportfw/Test/Acceptance/Iter2/post13.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 "post13.h"
       
    17 #include <http.h>
       
    18 
       
    19 #include "csrvaddrval.h"
       
    20 
       
    21 CHttpTestCasePost13::CHttpTestCasePost13(CScriptFile* aIniSettingsFile) :
       
    22 	iIniSettingsFile(aIniSettingsFile)
       
    23 	{
       
    24 	iExpectedStatusCode=401;
       
    25 	}
       
    26 
       
    27 const TDesC& CHttpTestCasePost13::TestName()
       
    28 	{
       
    29 	_LIT(KHeaderTestName,"Iteration 2 Post Test 13 ");
       
    30 	return KHeaderTestName;
       
    31 	}
       
    32 
       
    33 void CHttpTestCasePost13::OpenTestSessionL()
       
    34 	{
       
    35 	//open  a Session
       
    36 	
       
    37 	iSession.OpenL();
       
    38 	iEngine->Utils().LogIt(_L("Session Created(Iteration 2 Post Test 13)"));
       
    39 	iEngine->Utils().LogIt(_L("Session parameters: Default"));
       
    40 	
       
    41 	InstallAuthenticationL(iSession);
       
    42 
       
    43 	//Get the iSession'string pool handle;
       
    44 	iMyStrP = iSession.StringPool();
       
    45 	//open string this testcase needs
       
    46 
       
    47 	// Literals used in the function
       
    48 	_LIT8(KWapTestUrl,		"http://WapTestIP/perl/protected/dumpform.pl");
       
    49 	
       
    50 	// Replace the host name in the URL
       
    51 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
       
    52 	CleanupStack::PushL(newUrl8);
       
    53 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
    54 
       
    55 	TUriParser8 testURI;
       
    56 	testURI.Parse(newUrlPtr8);
       
    57 
       
    58 	iTransaction = iSession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EPOST,RHTTPSession::GetTable()));
       
    59 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
    60 	iOpenTransactionCount++;
       
    61 
       
    62 	//Get a handle of the request in iTransaction
       
    63 	RHTTPRequest myRequest = iTransaction.Request();
       
    64 	RHTTPHeaders myHeaders = myRequest.GetHeaderCollection();
       
    65 	//provide  some headers 
       
    66 
       
    67 	THTTPHdrVal contentTypeHdr(iMyStrP.StringF(HTTP::EApplicationXWwwFormUrlEncoded,RHTTPSession::GetTable()));
       
    68 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentType, RHTTPSession::GetTable()),contentTypeHdr);
       
    69 
       
    70 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
    71 	iEngine->Utils().LogIt(_L("Method:Post"));
       
    72 	iEngine->Utils().LogIt(_L("Content-Type:application/x-www-form-urlencoded "));
       
    73 	myRequest.SetBody(*this);
       
    74 
       
    75 	// for now we need to set the content length
       
    76 	THTTPHdrVal contentLengthHdr(OverallDataSize());
       
    77 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentLength, RHTTPSession::GetTable()), contentLengthHdr);
       
    78 	CleanupStack::PopAndDestroy(newUrl8);
       
    79 	} 
       
    80 
       
    81 void CHttpTestCasePost13::CloseTestSession()
       
    82 	{
       
    83 	// Close strings used in this session before closing the session
       
    84 	//close Transaction and session
       
    85 	iTransaction.Close();
       
    86 	iEngine->Utils().LogIt(_L("Transaction terminated\n"));
       
    87 	iSession.Close();
       
    88 	iEngine->Utils().LogIt(_L("Session terminated"));
       
    89 	}
       
    90 
       
    91 
       
    92 TBool CHttpTestCasePost13::GetCredentialsL(const TUriC8& aURI, RString aRealm, RStringF aAuthenticationType, RString& aUsername, RString& aPassword)
       
    93 	{
       
    94 	iAttempt++;
       
    95 	if(iAttempt<=2)
       
    96 		{
       
    97 		iEngine->Utils().LogIt(_L("Supplying credentials"));
       
    98 		// Can't log 8 bit data, so dump it.
       
    99 		iEngine->Utils().DumpData(aURI.UriDes());
       
   100 		iEngine->Utils().DumpData(aRealm.DesC());	
       
   101 		iEngine->Utils().DumpData(aAuthenticationType.DesC());	
       
   102 		_LIT8(KUser, "invalid");
       
   103 		_LIT8(KPass, "forgot");
       
   104 		RStringPool p = aRealm.Pool();
       
   105 		aUsername = p.OpenStringL(KUser);
       
   106 		aPassword = p.OpenStringL(KPass);
       
   107 		return ETrue;
       
   108 		}
       
   109 	else return EFalse;
       
   110 	}
       
   111 
       
   112 void CHttpTestCasePost13::MHFRunL(RHTTPTransaction aTransaction,
       
   113 								  THTTPEvent aEvent)
       
   114 	{
       
   115 	switch (aEvent.iStatus)
       
   116 		{
       
   117 	case THTTPEvent::EGotResponseHeaders:
       
   118 		{
       
   119 		// HTTP response headers have been received
       
   120 		iEngine->Utils().LogIt(_L("<EGotResponseHeaders>\n"));
       
   121 		TInt  statusCode = aTransaction.Response().StatusCode();
       
   122 		iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode);
       
   123 		DumpRespHeaders(aTransaction);
       
   124 		iEngine->SetCurrentStatusCode(statusCode);
       
   125 		if (iExpectedStatusCode != statusCode)
       
   126 			{
       
   127 			iTestFail=1;
       
   128 			iEngine->Utils().LogIt(_L("<The Test will fail :The expected status code doesn't match the actual status code received>\n"));
       
   129 			}
       
   130 		} break;
       
   131 	case THTTPEvent::EGotResponseBodyData:
       
   132 		{
       
   133 		// Some (more) body data has been received (in the HTTP response)
       
   134 		iEngine->Utils().LogIt(_L("<EGotResponseBodyData received>\n"));
       
   135 		// for each chunk of data received we have to empty the buffer before 
       
   136 		// to be able to receive 
       
   137 		MHTTPDataSupplier* body = aTransaction.Response().Body();
       
   138 		body->ReleaseData();
       
   139 		} break;
       
   140 	case THTTPEvent::EResponseComplete:
       
   141 		{
       
   142 		// The transaction's response is complete
       
   143 		iEngine->Utils().LogIt(_L("<EResponseComplete received >\n"));
       
   144 		} break;
       
   145 	case THTTPEvent::ESucceeded:
       
   146 		{
       
   147 		iEngine->Utils().LogIt(_L("<ESucceeded received from the VF>\n"));
       
   148 		CActiveScheduler::Stop();
       
   149 		} break;
       
   150 	case THTTPEvent::EFailed:
       
   151 		{
       
   152 		iEngine->Utils().LogIt(_L("<EFailed received from the VF( becouse status code is 4xx) but not a failure for the purpose ofthis test>\n"));
       
   153 		CActiveScheduler::Stop();
       
   154 		} break;
       
   155 	default:
       
   156 		{
       
   157 		iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus);
       
   158 		if (aEvent.iStatus < THTTPEvent::ERedirectedPermanently)
       
   159 			{
       
   160 			iTestFail=1;
       
   161 			iEngine->Utils().LogIt(_L("Test Failed: The event received was not expected and it's not just a warning\n"));
       
   162 			iEngine->PressAnyKey();
       
   163 			CActiveScheduler::Stop();
       
   164 			}
       
   165 		} 
       
   166 		break;
       
   167 		}
       
   168 	}