applayerprotocols/httptransportfw/Test/Acceptance/CHttpTestChunkedBase.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 "CHttpTestChunkedBase.h"
       
    17 #include <http.h>
       
    18 #include "csrvaddrval.h"
       
    19 
       
    20 void CHttpTestChunkedBase::OpenTestSessionL()
       
    21 	{
       
    22 	//open  a Session
       
    23 	
       
    24 	iSession.OpenL();
       
    25 	iEngine->Utils().LogIt(_L("Session Created(Iteration 3 Post xx)"));
       
    26 	iEngine->Utils().LogIt(_L("Session parameters: Default"));
       
    27 
       
    28 	InstallAuthenticationL(iSession);
       
    29 
       
    30 	//Get the iSession'string pool handle;
       
    31 	iMyStrP = iSession.StringPool();
       
    32 	//open string this testcase needs
       
    33 
       
    34 	// Literals used in the function
       
    35 	_LIT8(KWapTestNameUrl, "http://scooby:doo@WapTestName/upload/testchunked");
       
    36 	// Replace the host name in the URL
       
    37 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestNameUrl(), iIniSettingsFile);
       
    38 	CleanupStack::PushL(newUrl8);
       
    39 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
    40 
       
    41 	TUriParser8 testURI; 
       
    42 	testURI.Parse(newUrlPtr8);
       
    43 	
       
    44 	iTransaction = iSession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EPUT,RHTTPSession::GetTable()));
       
    45 	iOpenTransactionCount++;
       
    46 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
    47 
       
    48 	//Get a handle of the request in iTransaction
       
    49 	RHTTPRequest myRequest = iTransaction.Request();
       
    50 	RHTTPHeaders myHeaders = myRequest.GetHeaderCollection();
       
    51 	//provide  some headers 
       
    52 
       
    53 	THTTPHdrVal contentTypeHdr(iMyStrP.StringF(HTTP::EApplicationXWwwFormUrlEncoded,RHTTPSession::GetTable()));
       
    54 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentType,RHTTPSession::GetTable()),contentTypeHdr);
       
    55 	
       
    56 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
    57 	iEngine->Utils().LogIt(_L("Method:Post"));
       
    58 	iEngine->Utils().LogIt(_L("Content-Type:application/x-www-form-urlencoded "));
       
    59 	CleanupStack::PopAndDestroy(newUrl8);
       
    60 	myRequest.SetBody(*this);
       
    61 	} 
       
    62 
       
    63 void CHttpTestChunkedBase::CloseTestSession()
       
    64 	{
       
    65 	// Close strings used in this session before closing the session
       
    66 	//close Transaction and session
       
    67 	iTransaction.Close();
       
    68 	iEngine->Utils().LogIt(_L("Transaction terminated\n"));
       
    69 	iSession.Close();
       
    70 	iEngine->Utils().LogIt(_L("Session terminated"));
       
    71 	}
       
    72 
       
    73 TBool CHttpTestChunkedBase::GetCredentialsL(const TUriC8& /*aURI*/, RString /*aRealm*/, RStringF /*aAuthenticationType*/, RString& /*aUsername*/,RString& /*aPassword*/)
       
    74 	{
       
    75 	return 0;
       
    76 	}
       
    77 
       
    78 void CHttpTestChunkedBase::ReleaseData() 
       
    79 	{	
       
    80 	++iReqBodyChunkCount;
       
    81 	// As we only have 3 chunks do not tell the transaction that there is more 
       
    82 	// data after we have released the last chunk!
       
    83 	if(!iLastChunk)
       
    84 		{
       
    85 		TRAPD(err, iTransaction.NotifyNewRequestBodyPartL());
       
    86 		if(err!=KErrNone)
       
    87 			iTransaction.Fail();
       
    88 		}
       
    89 	}
       
    90 
       
    91 TBool CHttpTestChunkedBase::GetNextDataPart(TPtrC8& aDataChunk)
       
    92 	{
       
    93 	_LIT8(KHttpPostBodyChunk1,"ABC");
       
    94 	_LIT8(KHttpPostBodyChunk2,"DEF");
       
    95 	_LIT8(KHttpPostBodyChunk3,"GHJ");
       
    96 
       
    97 	TBool retVal = EFalse;
       
    98 	switch (iReqBodyChunkCount)
       
    99 		{
       
   100 	case 0:
       
   101 		{
       
   102 		aDataChunk.Set(KHttpPostBodyChunk1());
       
   103 		} break;
       
   104 	case 1:
       
   105 		{
       
   106 		aDataChunk.Set(KHttpPostBodyChunk2());
       
   107 		} break;
       
   108 	case 2:
       
   109 		{
       
   110 		aDataChunk.Set(KHttpPostBodyChunk3());
       
   111 		iLastChunk = ETrue;
       
   112 		retVal = ETrue;
       
   113 		} break;
       
   114 		}
       
   115 	return retVal;
       
   116 	}