applayerprotocols/httptransportfw/Test/Acceptance/Iter2/get13.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 "get13.h"
       
    17 #include <http.h>
       
    18 
       
    19 #include "csrvaddrval.h"
       
    20 
       
    21 _LIT8(KWapTestUrl,			"http://WapTestIP");
       
    22 
       
    23 CHttpTestCaseGet13::CHttpTestCaseGet13(CScriptFile* aIniSettingsFile) 
       
    24 	:	iIniSettingsFile(aIniSettingsFile)
       
    25 	{
       
    26 	iExpectedStatusCode=401;
       
    27 	iAttempt=0;
       
    28 	}
       
    29 
       
    30 const TDesC& CHttpTestCaseGet13::TestName()
       
    31 	{
       
    32 	_LIT(KHeaderTestName,"Iteration 2 Get Test 13 ");
       
    33 	return KHeaderTestName;
       
    34 	}
       
    35 
       
    36 void CHttpTestCaseGet13::OpenTestSessionL()
       
    37 	{
       
    38 	iAttempt++;
       
    39 	iSession.OpenL();
       
    40 	iEngine->Utils().LogIt(_L("Session Created(Iteration 2 Post Test 13)"));
       
    41 	iEngine->Utils().LogIt(_L("Session parameters: Default"));
       
    42 	InstallAuthenticationL(iSession);
       
    43 	iMyStrP = iSession.StringPool();
       
    44 
       
    45 	// Literals used in the function
       
    46 	_LIT8(KUrlPath,				"/http_tests/rc/401/private/index.html");
       
    47 
       
    48 	// Replace the host name in the URL
       
    49 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
       
    50 	CleanupStack::PushL(newUrl8);
       
    51 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
    52 	newUrlPtr8.Append(KUrlPath());
       
    53 
       
    54 	TUriParser8 testURI;
       
    55 	testURI.Parse(newUrlPtr8);
       
    56 	
       
    57 	iTransaction = iSession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EGET,RHTTPSession::GetTable()));
       
    58 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
    59 	iOpenTransactionCount++;
       
    60 
       
    61 	//Get a handle of the request in iTransaction
       
    62 	RHTTPRequest myRequest = iTransaction.Request();
       
    63 	RHTTPHeaders myHeaders = myRequest.GetHeaderCollection();
       
    64 	//provide  some headers 
       
    65 
       
    66 	THTTPHdrVal acceptHdr(iMyStrP.StringF(HTTP::EAnyAny, RHTTPSession::GetTable()));
       
    67 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),acceptHdr);
       
    68 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
    69 	iEngine->Utils().LogIt(_L("Method:Get"));
       
    70 	iEngine->Utils().LogIt(_L("Accept:*/*"));
       
    71 	CleanupStack::PopAndDestroy(newUrl8);
       
    72 	}
       
    73 
       
    74 
       
    75 void CHttpTestCaseGet13::CloseTestSession()
       
    76 	{
       
    77 	// Close strings used in this session before closing the session
       
    78 	//close Transaction and session
       
    79 	iTransaction.Close();
       
    80 	iEngine->Utils().LogIt(_L("Transaction terminated\n"));
       
    81 	iSession.Close();
       
    82 	iEngine->Utils().LogIt(_L("Session terminated"));
       
    83 	}
       
    84 
       
    85 
       
    86 TBool CHttpTestCaseGet13::GetCredentialsL(const TUriC8& aURI, RString aRealm, RStringF aAuthenticationType, RString& aUsername, RString& aPassword)
       
    87 	{
       
    88 	iAttempt++;
       
    89 	if(iAttempt<=2)
       
    90 		{
       
    91 		iEngine->Utils().LogIt(_L("Supplying credentials"));
       
    92 		iEngine->Utils().DumpData(aURI.UriDes());
       
    93 		iEngine->Utils().DumpData(aRealm.DesC());	
       
    94 		iEngine->Utils().DumpData(aAuthenticationType.DesC());	
       
    95 		_LIT8(KUser, "invalid");
       
    96 		_LIT8(KPass, "forgot");
       
    97 		RStringPool p = aRealm.Pool();
       
    98 		aUsername = p.OpenStringL(KUser);
       
    99 		aPassword = p.OpenStringL(KPass);
       
   100 		return ETrue;
       
   101 		}
       
   102 	else return EFalse;
       
   103 	}