applayerprotocols/httptransportfw/Test/T_HttpOnline/T_MultiTransMalformedStatusLine.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2001-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 // defines test class: CTextModeTestMultiTransMalformedStatusLine
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "T_MultiTransMalformedStatusLine.h"
       
    19 
       
    20 
       
    21 // CTextModeTestMultiTrans-----------------------------------
       
    22 
       
    23 CTextModeTestMultiTransMalformedStatusLine* CTextModeTestMultiTransMalformedStatusLine::NewL(const TDesC& aHostName, TInt aMaxNumTrans)
       
    24 	{
       
    25 	CTextModeTestMultiTransMalformedStatusLine* me = new(ELeave)CTextModeTestMultiTransMalformedStatusLine(aMaxNumTrans);
       
    26 	CleanupStack::PushL(me);
       
    27 	me->ConstructL(aHostName);
       
    28 	CleanupStack::Pop();
       
    29 	return me;
       
    30 	}
       
    31 
       
    32 CTextModeTestMultiTransMalformedStatusLine::~CTextModeTestMultiTransMalformedStatusLine()
       
    33 	{
       
    34 	delete iHostName;
       
    35 	iTransArray.Close();
       
    36 	}
       
    37 
       
    38 CTextModeTestMultiTransMalformedStatusLine::CTextModeTestMultiTransMalformedStatusLine(TInt aMaxNumTrans)
       
    39 	: iMaxNumTransactions(aMaxNumTrans)
       
    40 	{
       
    41 	// does nothing
       
    42 	}
       
    43 
       
    44 void CTextModeTestMultiTransMalformedStatusLine::ConstructL(const TDesC& aHostName)
       
    45 	{
       
    46 	iHostName = HBufC8::NewL(aHostName.Length());
       
    47 	iHostName->Des().Copy(aHostName);
       
    48 	}
       
    49 
       
    50 void CTextModeTestMultiTransMalformedStatusLine::DoRunL()
       
    51 	{
       
    52 	// Open the HTTP session
       
    53 	iSession.OpenL();
       
    54 	CleanupClosePushL(iSession);
       
    55 
       
    56 	// Create the array of transactions
       
    57 	CreateTransArrayL();
       
    58 
       
    59 	// Go!
       
    60 	iFailureError = KErrNone;
       
    61 	CActiveScheduler::Start();
       
    62 
       
    63 	// No particular status code is required for success in this test
       
    64 	iExpectedStatusCode = 0;
       
    65 
       
    66 	// Close anything opened
       
    67 	CleanupStack::PopAndDestroy(); //close iSession
       
    68 
       
    69 	// If any transaction failed then fail the test
       
    70 	User::LeaveIfError(iFailureError);
       
    71 	}
       
    72 	
       
    73 TInt CTextModeTestMultiTransMalformedStatusLine::RunError(TInt aErr)
       
    74 	{
       
    75 	iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr);
       
    76 	return KErrNone;
       
    77 	}
       
    78 
       
    79 void CTextModeTestMultiTransMalformedStatusLine::DoCancel()
       
    80 	{
       
    81 	}
       
    82 
       
    83 const TDesC& CTextModeTestMultiTransMalformedStatusLine::TestName()
       
    84 	{
       
    85 	_LIT(KHeaderTestName,"CTextModeTestMultiTransMalformedStatusLine");
       
    86 	return KHeaderTestName;
       
    87 	}
       
    88 
       
    89 
       
    90 TInt CTextModeTestMultiTransMalformedStatusLine::MHFRunError(TInt aError, 
       
    91 										RHTTPTransaction aTransaction,
       
    92 										const THTTPEvent& /*aEvent*/)
       
    93 	{
       
    94 	iEngine->Utils().LogIt(_L("\nTest failed with error code %d on transaction ID=%d\n"), aError, aTransaction.Id());
       
    95 	iFailureError = aError;
       
    96 	CActiveScheduler::Stop();
       
    97 	return KErrNone;
       
    98 	}
       
    99 
       
   100 void CTextModeTestMultiTransMalformedStatusLine::MHFRunL(RHTTPTransaction aTransaction,
       
   101 						 const THTTPEvent& aEvent)
       
   102 	{
       
   103 	switch (aEvent.iStatus)
       
   104 		{
       
   105 	case THTTPEvent::EGotResponseHeaders:
       
   106 		{
       
   107 		// HTTP response headers have been received
       
   108 		iEngine->Utils().LogIt(_L("<Got response headers>"));
       
   109 		} break;
       
   110 	case THTTPEvent::ESubmit:
       
   111 		{
       
   112 		} break;
       
   113 	case THTTPEvent::EGotResponseBodyData:
       
   114 		{
       
   115 		// Some (more) body data has been received (in the HTTP response)
       
   116 		iEngine->Utils().LogIt(_L("<Got a chunk of data>"));
       
   117 		} break;
       
   118 	case THTTPEvent::EResponseComplete:
       
   119 		{
       
   120 		// The transaction's response is complete
       
   121 		iEngine->Utils().LogIt(_L("<Transaction Complete>"));
       
   122 		} break;
       
   123 	case THTTPEvent::ESucceeded:
       
   124 		{
       
   125 		iEngine->Utils().LogIt(_L("<Transaction validated successfully>"));
       
   126 		aTransaction.Close();
       
   127 		if (--iOpenTransactionCount == 0)
       
   128 			CActiveScheduler::Stop();
       
   129 		} break;
       
   130 	case THTTPEvent::EFailed:
       
   131 		{
       
   132 		iEngine->Utils().LogIt(_L("<Transaction NOT validated successfully>"));
       
   133 		aTransaction.Close();
       
   134 		if (--iOpenTransactionCount == 0)
       
   135 			{
       
   136 			CActiveScheduler::Stop();
       
   137 			}
       
   138 		iFailureError = KErrTestFailed;
       
   139 		} break;
       
   140 	default:
       
   141 		{
       
   142 		iEngine->Utils().LogIt(_L("<unrecognised event> %d"),aEvent.iStatus);
       
   143 		aTransaction.Close();
       
   144 		TInt status = aEvent.iStatus;
       
   145 		if ( status < 0)
       
   146 			{
       
   147 			if( status == KErrCouldNotConnect )
       
   148 				{
       
   149 				++iConnectFailureCount;
       
   150 				// If we get KErrCouldNotConnect create another transation to replace (it means the
       
   151 				// test server is too slow and was not ready for the next request)
       
   152 				RStringF get = iSession.StringPool().StringF(HTTP::EGET,RHTTPSession::GetTable());
       
   153 				CreateSingleTransactionL(get);
       
   154 				}
       
   155 			else if( status == KErrCorrupt )
       
   156 				iConnectFailureCount = 0;
       
   157             else
       
   158 				iFailureError = aEvent.iStatus;
       
   159 
       
   160 			if( --iOpenTransactionCount == 0 )
       
   161 				CActiveScheduler::Stop();
       
   162 
       
   163             if ( iConnectFailureCount == 10 )
       
   164 				{
       
   165 				iFailureError = KErrCouldNotConnect;
       
   166 				CActiveScheduler::Stop();
       
   167 				}
       
   168 			}
       
   169 		} 
       
   170 		break;
       
   171 		}
       
   172 	}
       
   173 
       
   174 void CTextModeTestMultiTransMalformedStatusLine::CreateTransArrayL()
       
   175 	{
       
   176 	// Open several transactions, all with a URL of the form http://xxx/y.txt where y is from 1 to iMaxNumTransactions
       
   177 	RStringF get = iSession.StringPool().StringF(HTTP::EGET,RHTTPSession::GetTable());
       
   178 	iOpenTransactionCount = 0;
       
   179 	for (TInt ii = 1; ii <= 6; ii++)
       
   180 		{
       
   181 		CreateSingleTransactionL(get);
       
   182 		}
       
   183 	}
       
   184 
       
   185 void CTextModeTestMultiTransMalformedStatusLine::CreateSingleTransactionL(RStringF aGet)
       
   186 	{
       
   187 	// create the transaction and submit
       
   188 	TUriParser8 urlParser;
       
   189 	urlParser.Parse(*iHostName);
       
   190 	RHTTPTransaction tr = iSession.OpenTransactionL(urlParser, *this, aGet);
       
   191 	CleanupClosePushL(tr);
       
   192 	User::LeaveIfError(iTransArray.Append(tr));
       
   193 	CleanupStack::Pop(&tr);
       
   194 	tr.SubmitL();
       
   195 	iOpenTransactionCount++;
       
   196 	}