applayerprotocols/httptransportfw/Test/T_HttpOnline/CINC110203.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2007-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 "CINC110203.h"
       
    17 
       
    18 // Literals used in the file
       
    19 _LIT8(KHttpUrl,		"http://www.google.co.in");
       
    20 _LIT8(KContentType,	"*/*");
       
    21 
       
    22 CINC110203* CINC110203::NewL(TInt aTestNumber, CScriptFile* aIniSettingsFile)
       
    23 	{
       
    24 	CINC110203* self = new(ELeave)CINC110203(aTestNumber, aIniSettingsFile);
       
    25 	CleanupStack::PushL(self);
       
    26 	CleanupStack::Pop(self);
       
    27 	return self;
       
    28 	}
       
    29 
       
    30 CINC110203::~CINC110203()
       
    31 	{
       
    32 	}
       
    33 
       
    34 CINC110203::CINC110203(TInt aTestNumber, CScriptFile* aIniSettingsFile) :
       
    35 	iIniSettingsFile(aIniSettingsFile),
       
    36 	iTestNumber(aTestNumber)
       
    37 	{
       
    38 	}
       
    39 
       
    40 void CINC110203::SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue)
       
    41 	{
       
    42 	RStringF valStr = iSession.StringPool().OpenFStringL(aHdrValue);
       
    43 	THTTPHdrVal val(valStr);
       
    44 	aHeaders.SetFieldL(iSession.StringPool().StringF(aHdrField,RHTTPSession::GetTable()), val);
       
    45 	valStr.Close();
       
    46 	}
       
    47 
       
    48 void CINC110203::DoRunL()
       
    49 	{
       
    50 	TUriParser8 up;
       
    51 	up.Parse(KHttpUrl);
       
    52 
       
    53 	// Open the HTTP session
       
    54 	iSession.OpenL();
       
    55 	CleanupClosePushL(iSession);
       
    56 
       
    57 	RStringPool strP = iSession.StringPool();
       
    58 
       
    59 	// Open a GET transactions, specifying this object as the request body data supplier
       
    60 	iTransaction = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EGET,RHTTPSession::GetTable()));
       
    61 
       
    62 	RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
       
    63 	SetHeaderL(hdr, HTTP::EContentType, KContentType);
       
    64 	
       
    65 	iTransaction.SubmitL();
       
    66 	CActiveScheduler::Start();
       
    67 	
       
    68 	CleanupStack::PopAndDestroy(&iSession); //close iSession
       
    69 
       
    70 	}
       
    71 
       
    72 TInt CINC110203::RunError(TInt aErr)
       
    73 	{
       
    74 	iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr);
       
    75 	return KErrNone;
       
    76 	}
       
    77 
       
    78 void CINC110203::DoCancel()
       
    79 	{
       
    80 	}
       
    81 
       
    82 const TDesC& CINC110203::TestName()
       
    83 	{
       
    84 	_LIT(KHeaderTestName,"CINC110203");
       
    85 	return KHeaderTestName;
       
    86 	}
       
    87 
       
    88 TInt CINC110203::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/)
       
    89 	{
       
    90 	_LIT(KLogDescription, "\nTest failed with error code %d on transaction ID=%d\n");
       
    91 	iEngine->Utils().LogIt(KLogDescription, aError, aTransaction.Id());
       
    92 	iFailureError = aError;
       
    93 	CActiveScheduler::Stop();
       
    94 	return KErrNone;
       
    95 	}
       
    96 
       
    97 void CINC110203::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
       
    98 	{
       
    99 	switch (aEvent.iStatus)
       
   100 		{
       
   101 		case THTTPEvent::EGotResponseHeaders:
       
   102 			{
       
   103 			// HTTP response headers have been received
       
   104 			iEngine->Utils().LogIt(_L("<Got response headers>"));
       
   105 			MHTTPDataSupplier* body = aTransaction.Response().Body ();
       
   106 			if ( body )
       
   107 				{
       
   108 				body->ReleaseData ();
       
   109 				}
       
   110 			} break;
       
   111 		case THTTPEvent::ESubmit:
       
   112 			{
       
   113 			} break;
       
   114 		case THTTPEvent::EGotResponseBodyData:
       
   115 			{
       
   116 			// Some (more) body data has been received (in the HTTP response)
       
   117 			iEngine->Utils().LogIt(_L("<Got a chunk of data>"));
       
   118 			// Get the body data supplier
       
   119 			MHTTPDataSupplier* iRespBody = aTransaction.Response().Body();
       
   120 			// Append to the output file.
       
   121 			TPtrC8 bodyData;
       
   122 			TBool lastChunk = iRespBody->GetNextDataPart( bodyData );
       
   123 			iRespBody->ReleaseData();
       
   124 			} break;
       
   125 		case THTTPEvent::EResponseComplete:
       
   126 			{
       
   127 			// The transaction's response is complete
       
   128 			iEngine->Utils().LogIt(_L("<Transaction Complete>"));
       
   129 			} break;
       
   130 		case THTTPEvent::ESucceeded:
       
   131 			{
       
   132 			// The transaction succeeded
       
   133 			iEngine->Utils().LogIt(_L("<Transaction succeeded>"));
       
   134 			aTransaction.Close();
       
   135 			CActiveScheduler::Stop();
       
   136 			}
       
   137 			break;
       
   138 		case THTTPEvent::EFailed:
       
   139 			{
       
   140 			// The transaction failed so fail the test
       
   141 			iEngine->Utils().LogIt(_L("<Transaction failed>"));
       
   142 			aTransaction.Close();
       
   143 			CActiveScheduler::Stop();
       
   144 			} break;
       
   145 		default:
       
   146 			{
       
   147 			_LIT(KLogDescription, "<unrecognised event> %d");
       
   148 			iEngine->Utils().LogIt(KLogDescription,aEvent.iStatus);
       
   149 			if (aEvent.iStatus < 0)
       
   150 				{
       
   151 				iFailureError = aEvent.iStatus;
       
   152 				CActiveScheduler::Stop();
       
   153 				}
       
   154 			} 
       
   155 			break;
       
   156 		}
       
   157 	
       
   158 	return;
       
   159 	}
       
   160