applayerprotocols/httptransportfw/Test/Acceptance/Iter2/get12.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 "get12.h"
       
    17 #include <http.h>
       
    18 #include <es_sock.h>
       
    19 #include <commdbconnpref.h>
       
    20 #include <es_enum.h>
       
    21 #include "csrvaddrval.h"
       
    22 
       
    23 // Literals used in the file
       
    24 _LIT8(KWapTestIPSection, "http://WapTestIP");
       
    25 
       
    26 CHttpTestCaseGet12::CHttpTestCaseGet12(CScriptFile* aIniSettingsFile)
       
    27 	:	iIniSettingsFile(aIniSettingsFile)
       
    28 	{
       
    29 	iExpectedStatusCode=200;
       
    30 	}
       
    31 
       
    32 const TDesC& CHttpTestCaseGet12::TestName()
       
    33 	{
       
    34 	_LIT(KHeaderTestName,"Iteration 2 Get Test 12 ");
       
    35 	return KHeaderTestName;
       
    36 	}
       
    37 
       
    38 void CHttpTestCaseGet12::OpenTestSessionL()
       
    39 	{
       
    40 	iSession.OpenL();
       
    41 	iEngine->Utils().LogIt(_L("Session Created(Iteration 2 Get Test 12)"));
       
    42 	iEngine->Utils().LogIt(_L("Session parameters: Default"));
       
    43 	InstallAuthenticationL(iSession);
       
    44 	iMyStrP = iSession.StringPool();
       
    45 
       
    46 	// Literals used in the function
       
    47 	_LIT8(KUrlPath,				"/http_tests/rc/401/private/index.html");
       
    48 
       
    49 	// Replace the host name in the URL
       
    50 	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestIPSection(), iIniSettingsFile);
       
    51 	CleanupStack::PushL(newUrl8);
       
    52 	TPtr8 newUrlPtr8 = newUrl8->Des();
       
    53 	newUrlPtr8.Append(KUrlPath());
       
    54 
       
    55 	TUriParser8 testURI;
       
    56 	testURI.Parse(newUrlPtr8);
       
    57 	
       
    58 	iTransaction = iSession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EGET,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 
       
    66 	//provide  some headers 
       
    67 	THTTPHdrVal acceptHdr(iMyStrP.StringF(HTTP::EAnyAny, RHTTPSession::GetTable()));
       
    68 	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),acceptHdr);
       
    69 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
       
    70 	iEngine->Utils().LogIt(_L("Method:GET"));
       
    71 	CleanupStack::PopAndDestroy(newUrl8);
       
    72 	}
       
    73 
       
    74 void CHttpTestCaseGet12::LogConnectionProperties()
       
    75 	{
       
    76 	RHTTPConnectionInfo	connectionInfo = iSession.ConnectionInfo();
       
    77 	RStringPool stringPool = iSession.StringPool();
       
    78 	THTTPHdrVal value;
       
    79 	TBool hasValue = connectionInfo.Property (stringPool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), value);
       
    80 	if (hasValue)
       
    81 		{
       
    82 		RConnection* conn = REINTERPRET_CAST(RConnection*, value.Int());
       
    83 		TUint count;
       
    84 		//get the no of active connections
       
    85 		TInt err = conn->EnumerateConnections(count);
       
    86 		if(err==KErrNone)
       
    87 			{
       
    88 			for (TUint i=1; i<=count; ++i)
       
    89 				{
       
    90 				TPckgBuf<TConnectionInfo> connInfo;
       
    91 				conn->GetConnectionInfo(i, connInfo);
       
    92 				iEngine->Utils().LogIt(_L("Connection %d: IapId=%d, NetId=%d\n"),i, connInfo().iIapId, connInfo().iNetId);
       
    93 				}
       
    94 			}
       
    95 		else
       
    96 			{
       
    97 			iEngine->Utils().LogIt(_L("Unable to enumerate number of connections, Error: %d"), err);
       
    98 			}
       
    99 		}
       
   100 	}
       
   101 
       
   102 void CHttpTestCaseGet12::CloseTestSession()
       
   103 	{
       
   104 	//log connection properties before closing the session
       
   105 	LogConnectionProperties();
       
   106 	// Close strings used in this session before closing the session
       
   107 	//close Transaction and session
       
   108 	iTransaction.Close();
       
   109 	iEngine->Utils().LogIt(_L("Transaction terminated\n"));
       
   110 	iSession.Close();
       
   111 	iEngine->Utils().LogIt(_L("Session terminated"));
       
   112 	}
       
   113 
       
   114 
       
   115 TBool CHttpTestCaseGet12::GetCredentialsL(const TUriC8& aURI, RString aRealm, RStringF aAuthenticationType, RString& aUsername, RString& aPassword)
       
   116 	{
       
   117 	iEngine->Utils().LogIt(_L("Supplying credentials"));
       
   118 	iEngine->Utils().DumpData(aURI.UriDes());
       
   119 	iEngine->Utils().DumpData(aRealm.DesC());	
       
   120 	iEngine->Utils().DumpData(aAuthenticationType.DesC());	
       
   121 	_LIT8(KScooby, "scooby");
       
   122 	_LIT8(KDoo, "doo");
       
   123 	RStringPool p = aRealm.Pool();
       
   124 	aUsername = p.OpenStringL(KScooby);
       
   125 	aPassword = p.OpenStringL(KDoo);
       
   126 	return ETrue;
       
   127 	}