applayerprotocols/httptransportfw/Test/T_HttpOnline/T_MultiTransConcurrent.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 // defines test class: CTextModeTestMultiTransConcurrent
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "T_MultiTransConcurrent.h"
       
    19 #include "csrvaddrval.h"
       
    20 
       
    21 // Constants used in CTextModeTestMultiTransConcurrent test
       
    22 _LIT8(KHttpMultiTransUrlFormat, "http://%S/http_tests/prothnd/conc/");
       
    23 _LIT8(KHttpMultiTransUrlExtn, ".txt");
       
    24 const TInt KMultiTransFailed = -7399; 
       
    25 const TInt KErrMultipleTransNotConcurrent = -7399;
       
    26 // CTextModeTestMultiTransConcurrent-----------------------------------
       
    27 
       
    28 CTextModeTestMultiTransConcurrent* CTextModeTestMultiTransConcurrent::NewL(const TDesC& aHostName, TInt aMaxNumTrans)
       
    29 	{
       
    30 	CTextModeTestMultiTransConcurrent* me = new(ELeave)CTextModeTestMultiTransConcurrent(aMaxNumTrans);
       
    31 	CleanupStack::PushL(me);
       
    32 	me->ConstructL(aHostName);
       
    33 	CleanupStack::Pop();
       
    34 	return me;
       
    35 	}
       
    36 
       
    37 CTextModeTestMultiTransConcurrent::~CTextModeTestMultiTransConcurrent()
       
    38 	{
       
    39 	delete iHostName;
       
    40 	iTransArray.Close();
       
    41 	}
       
    42 
       
    43 CTextModeTestMultiTransConcurrent::CTextModeTestMultiTransConcurrent(TInt aMaxNumTrans)
       
    44 	: iMaxNumTransactions(aMaxNumTrans)
       
    45 	{
       
    46 	// does nothing
       
    47 	}
       
    48 
       
    49 void CTextModeTestMultiTransConcurrent::ConstructL(const TDesC& aHostName)
       
    50 	{
       
    51 	iHostName = HBufC8::NewL(aHostName.Length());
       
    52 	iHostName->Des().Copy(aHostName);
       
    53 	}
       
    54 
       
    55 void CTextModeTestMultiTransConcurrent::DoRunL()
       
    56 	{
       
    57 	// Open the HTTP session
       
    58 	iSession.OpenL();
       
    59 	CleanupClosePushL(iSession);
       
    60 
       
    61 	// Set the protocol to use
       
    62 /*	if (iUseWsp)
       
    63 		{
       
    64 		RHTTPConnectionInfo ci = iSession.ConnectionInfo();
       
    65 		ci.SetPropertyL(iSession.StringPool().StringF(HTTP::EProtocol,RHTTPSession::GetTable()), THTTPHdrVal(iSession.StringPool().StringF(HTTP::EWSP,RHTTPSession::GetTable())));
       
    66 		}*/
       
    67 
       
    68 	// Create the array of transactions
       
    69 	CreateTransArrayL();
       
    70 
       
    71 	// Go!
       
    72 	iFailureError = KErrNone;
       
    73 	CActiveScheduler::Start();
       
    74 
       
    75 	// No particular status code is required for success in this test
       
    76 	iExpectedStatusCode = 0;
       
    77 
       
    78 	// Close anything opened
       
    79 	CleanupStack::PopAndDestroy(); //close iSession
       
    80 
       
    81 	// If any transaction failed then fail the test
       
    82 	User::LeaveIfError(iFailureError);
       
    83 	}
       
    84 	
       
    85 TInt CTextModeTestMultiTransConcurrent::RunError(TInt aErr)
       
    86 	{
       
    87 	iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr);
       
    88 	return KErrNone;
       
    89 	}
       
    90 
       
    91 void CTextModeTestMultiTransConcurrent::DoCancel()
       
    92 	{
       
    93 	}
       
    94 
       
    95 const TDesC& CTextModeTestMultiTransConcurrent::TestName()
       
    96 	{
       
    97 	_LIT(KHeaderTestName,"CTextModeTestMultiTransConcurrent");
       
    98 	return KHeaderTestName;
       
    99 	}
       
   100 
       
   101 
       
   102 TInt CTextModeTestMultiTransConcurrent::MHFRunError(TInt aError, 
       
   103 										RHTTPTransaction aTransaction,
       
   104 										const THTTPEvent& /*aEvent*/)
       
   105 	{
       
   106 	iEngine->Utils().LogIt(_L("\nTest failed with error code %d on transaction ID=%d\n"), aError, aTransaction.Id());
       
   107 	iFailureError = aError;
       
   108 	CActiveScheduler::Stop();
       
   109 	return KErrNone;
       
   110 	}
       
   111 
       
   112 void CTextModeTestMultiTransConcurrent::MHFRunL(RHTTPTransaction aTransaction,
       
   113 						 const THTTPEvent& aEvent)
       
   114 	{
       
   115 	switch (aEvent.iStatus)
       
   116 		{
       
   117 	case THTTPEvent::EGotResponseHeaders:
       
   118 		{
       
   119 		// HTTP response headers have been received
       
   120 		iEngine->Utils().LogIt(_L("<Got response headers>"));
       
   121 		iGotHeadersCount[aTransaction.Id()-1]++;
       
   122 		} break;
       
   123 	case THTTPEvent::ESubmit:
       
   124 		{
       
   125 		} break;
       
   126 	case THTTPEvent::EGotResponseBodyData:
       
   127 		{
       
   128 		// Some (more) body data has been received (in the HTTP response)
       
   129 		iEngine->Utils().LogIt(_L("<Got a chunk of data>"));
       
   130 		ValidateBodyL(aTransaction);
       
   131 		} break;
       
   132 	case THTTPEvent::EResponseComplete:
       
   133 		{
       
   134 		// The transaction's response is complete
       
   135 		iEngine->Utils().LogIt(_L("<Transaction Complete>"));
       
   136 		// Test that when transaction 1 completes, headers of other transaction have been received
       
   137 		// this provesthat the transactions occur concurrently.
       
   138 		// for this purpose transaction 1 must be slow i.e ask for a much bigger amount of data that the others transactions
       
   139 		TInt curentTransId = aTransaction.Id();
       
   140 		if (curentTransId == 1)
       
   141 			{
       
   142 			//Leave  if the transactions are not made concurrently
       
   143 			if(!TestConcurrentTrans())
       
   144 				User::Leave(KErrMultipleTransNotConcurrent);
       
   145 			}
       
   146 
       
   147 		} break;
       
   148 	case THTTPEvent::ESucceeded:
       
   149 		{
       
   150 		iEngine->Utils().LogIt(_L("<Transaction validated successfully>"));
       
   151 		aTransaction.Close();
       
   152 		if (--iOpenTransactionCount == 0)
       
   153 			CActiveScheduler::Stop();
       
   154 		} break;
       
   155 	case THTTPEvent::EFailed:
       
   156 		{
       
   157 		iEngine->Utils().LogIt(_L("<Transaction NOT validated successfully>"));
       
   158 		aTransaction.Close();
       
   159 		if (--iOpenTransactionCount == 0)
       
   160 			{
       
   161 			CActiveScheduler::Stop();
       
   162 			}
       
   163 		iFailureError = KErrTestFailed;
       
   164 		} break;
       
   165 	default:
       
   166 		{
       
   167 		iEngine->Utils().LogIt(_L("<unrecognised event> %d"),aEvent.iStatus);
       
   168 		if (aEvent.iStatus < 0)
       
   169 			{
       
   170 			iFailureError = aEvent.iStatus;
       
   171 			CActiveScheduler::Stop();
       
   172 			}
       
   173 		} 
       
   174 		break;
       
   175 		}
       
   176 	}
       
   177 
       
   178 TBool CTextModeTestMultiTransConcurrent::TestConcurrentTrans()
       
   179 	{
       
   180 	TInt remainingTrans = iTransArray.Count()-1;
       
   181 	for(TInt count=1; count<=remainingTrans ; ++count) 
       
   182 		{
       
   183 		// check that at least one other transaction at this point has already received a header
       
   184 		if(iGotHeadersCount[count-1] > 0 )
       
   185 			return ETrue;
       
   186 		}
       
   187 	return EFalse;
       
   188 	}
       
   189 
       
   190 void CTextModeTestMultiTransConcurrent::ValidateBodyL(RHTTPTransaction aTransaction)
       
   191 	{
       
   192 	// In this test, the test URLs point to resources that contain just characters from the test number
       
   193 	// i.e. http:/xxx/1.txt will contain only the char 1, CR or LF.
       
   194 	// These numbers should also align with the transaction ID, since they were created in order
       
   195 	RHTTPResponse resp = aTransaction.Response();
       
   196 	MHTTPDataSupplier* body = resp.Body();
       
   197 	TPtrC8 data;
       
   198 	body->GetNextDataPart(data);
       
   199 	TChar reqdCh = (TChar)(aTransaction.Id() + 48);
       
   200 	for (TInt ii = 0; ii < data.Length(); ii++)
       
   201 		{
       
   202 		TChar ch = data[ii];
       
   203 		if ((ch != reqdCh) && (ch != (TChar)0x0d) && (ch != (TChar)0x0a))
       
   204 			User::Leave(KMultiTransFailed);
       
   205 		}
       
   206 
       
   207 	// OK - release the block
       
   208 	body->ReleaseData();
       
   209 	}
       
   210 
       
   211 void CTextModeTestMultiTransConcurrent::CreateTransArrayL()
       
   212 	{
       
   213 	// As the transport framework enables pipelining by default, we need to disable pipelining
       
   214 	// for the concurrent tests to work
       
   215 	RStringF pipeliningProperty = iSession.StringPool().StringF(HTTP::EHttpPipelining, iSession.GetTable());
       
   216 	THTTPHdrVal pipeliningValue = iSession.StringPool().StringF(HTTP::EDisablePipelining, iSession.GetTable());
       
   217 
       
   218 	// Open several transactions, all with a URL of the form http://xxx/y.txt where y is from 1 to iMaxNumTransactions
       
   219 	TBuf8<KMaxUrlBufSize> url;
       
   220 	RStringF get = iSession.StringPool().StringF(HTTP::EGET,RHTTPSession::GetTable());
       
   221 	iOpenTransactionCount = 0;
       
   222 	for (TInt ii = 1; ii <= iMaxNumTransactions; ii++)
       
   223 		{
       
   224 		// create the transaction and submit
       
   225 		url.Zero();
       
   226 		url.Format(KHttpMultiTransUrlFormat(), iHostName);
       
   227 		url.Append(TChar(ii + 48));
       
   228 		url.Append(KHttpMultiTransUrlExtn());
       
   229 		TUriParser8 urlParser;
       
   230 		urlParser.Parse(url);
       
   231 		RHTTPTransaction tr = iSession.OpenTransactionL(urlParser, *this, get);
       
   232 		CleanupClosePushL(tr);
       
   233 		User::LeaveIfError(iTransArray.Append(tr));
       
   234 		CleanupStack::Pop(&tr);
       
   235 		// Disable pipelining
       
   236 		tr.PropertySet().SetPropertyL(pipeliningProperty, pipeliningValue);	
       
   237 		tr.SubmitL();
       
   238 		iOpenTransactionCount++;
       
   239 		}
       
   240 	}
       
   241