kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0494.cpp
changeset 259 57b9594f5772
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
247:d8d70de2bd36 259:57b9594f5772
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    18 
    18 
    19 #include "PBASE-T_USBDI-0494.h"
    19 #include "PBASE-T_USBDI-0494.h"
    20 #include "testpolicy.h"
    20 #include "testpolicy.h"
    21 #include "modelleddevices.h"
    21 #include "modelleddevices.h"
    22 #include "testliterals.h"
    22 #include "testliterals.h"
       
    23 #include "OstTraceDefinitions.h"
       
    24 #ifdef OST_TRACE_COMPILER_IN_USE
       
    25 #include "PBASE-T_USBDI-0494Traces.h"
       
    26 #endif
    23 
    27 
    24 
    28 
    25  
    29  
    26 
    30 
    27 namespace NUnitTesting_USBDI
    31 namespace NUnitTesting_USBDI
    39 _LIT(KTestCaseId,"PBASE-T_USBDI-0494");
    43 _LIT(KTestCaseId,"PBASE-T_USBDI-0494");
    40 const TFunctorTestCase<CUT_PBASE_T_USBDI_0494,TBool> CUT_PBASE_T_USBDI_0494::iFunctor(KTestCaseId);	
    44 const TFunctorTestCase<CUT_PBASE_T_USBDI_0494,TBool> CUT_PBASE_T_USBDI_0494::iFunctor(KTestCaseId);	
    41 
    45 
    42 CUT_PBASE_T_USBDI_0494* CUT_PBASE_T_USBDI_0494::NewL(TBool aHostRole)
    46 CUT_PBASE_T_USBDI_0494* CUT_PBASE_T_USBDI_0494::NewL(TBool aHostRole)
    43 	{
    47 	{
       
    48 	OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0494_NEWL_ENTRY, aHostRole );
    44 	CUT_PBASE_T_USBDI_0494* self = new (ELeave) CUT_PBASE_T_USBDI_0494(aHostRole);
    49 	CUT_PBASE_T_USBDI_0494* self = new (ELeave) CUT_PBASE_T_USBDI_0494(aHostRole);
    45 	CleanupStack::PushL(self);
    50 	CleanupStack::PushL(self);
    46 	self->ConstructL();
    51 	self->ConstructL();
    47 	CleanupStack::Pop(self);
    52 	CleanupStack::Pop(self);
       
    53 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_NEWL_EXIT, ( TUint )( self ) );
    48 	return self;
    54 	return self;
    49 	}
    55 	}
    50 	
    56 	
    51 
    57 
    52 CUT_PBASE_T_USBDI_0494::CUT_PBASE_T_USBDI_0494(TBool aHostRole)
    58 CUT_PBASE_T_USBDI_0494::CUT_PBASE_T_USBDI_0494(TBool aHostRole)
    53 :	CBaseBulkTestCase(KTestCaseId,aHostRole),
    59 :	CBaseBulkTestCase(KTestCaseId,aHostRole),
    54 	iCaseStep(EInProgress)
    60 	iCaseStep(EInProgress)
    55 	{
    61 	{
       
    62 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0494_CUT_PBASE_T_USBDI_0494_ENTRY, this );
       
    63 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_CUT_PBASE_T_USBDI_0494_EXIT, this );
    56 	} 
    64 	} 
    57 
    65 
    58 
    66 
    59 void CUT_PBASE_T_USBDI_0494::ConstructL()
    67 void CUT_PBASE_T_USBDI_0494::ConstructL()
    60 	{
    68 	{
       
    69 	OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0494_CONSTRUCTL_ENTRY, this );
    61 	BaseBulkConstructL();
    70 	BaseBulkConstructL();
       
    71 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_CONSTRUCTL_EXIT, this );
    62 	}
    72 	}
    63 
    73 
    64 
    74 
    65 CUT_PBASE_T_USBDI_0494::~CUT_PBASE_T_USBDI_0494()
    75 CUT_PBASE_T_USBDI_0494::~CUT_PBASE_T_USBDI_0494()
    66 	{
    76 	{
    67 	LOG_FUNC
    77 	OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0494_CUT_PBASE_T_USBDI_0494_ENTRY_DUP01, this );
       
    78 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_CUT_PBASE_T_USBDI_0494_EXIT_DUP01, this );
    68 	}
    79 	}
    69 
    80 
    70 void CUT_PBASE_T_USBDI_0494::Ep0TransferCompleteL(TInt aCompletionCode)
    81 void CUT_PBASE_T_USBDI_0494::Ep0TransferCompleteL(TInt aCompletionCode)
    71 	{
    82 	{
    72 	LOG_FUNC
    83 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_ENTRY, this );
    73 	
    84 	
    74 	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
    85 	OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL, "Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
    75 	
    86 	
    76 	if(aCompletionCode != KErrNone)
    87 	if(aCompletionCode != KErrNone)
    77 		{
    88 		{
    78 		if(iCaseStep == EFailed)
    89 		if(iCaseStep == EFailed)
    79 			{// ignore error, nad catch the TestFailed method called further down.
    90 			{// ignore error, nad catch the TestFailed method called further down.
    80 			RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***");
    91 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_DUP01, "***Failure sending FAIL message to client on endpoint 0***");
    81 			}
    92 			}
    82 		else
    93 		else
    83 			{
    94 			{
    84 			TBuf<256> msg;
    95 			TBuf<256> msg;
    85 			msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
    96 			msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
    86 			RDebug::Print(msg);
    97 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_DUP02, msg);
    87 			iCaseStep = EFailed;
    98 			iCaseStep = EFailed;
    88 			TTestCaseFailed request(aCompletionCode,msg);
    99 			TTestCaseFailed request(aCompletionCode,msg);
    89 			iControlEp0->SendRequest(request,this);
   100 			iControlEp0->SendRequest(request,this);
       
   101 			OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_EXIT, this );
    90 			return;
   102 			return;
    91 			}
   103 			}
    92 		}
   104 		}
    93 	
   105 	
    94 	switch(iCaseStep)
   106 	switch(iCaseStep)
   102 		case EFailed:
   114 		case EFailed:
   103 			TestFailed(KErrCompletion);
   115 			TestFailed(KErrCompletion);
   104 			break;
   116 			break;
   105 			
   117 			
   106 		case ETransferOut:
   118 		case ETransferOut:
   107 			RDebug::Printf("Try to send data");
   119 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_DUP03, "Try to send data");
   108 			iOutTransfer[0]->TransferOut(KLiteralEnglish8(), KBulkTransferSize, ETrue);
   120 			iOutTransfer[0]->TransferOut(KLiteralEnglish8(), KBulkTransferSize, ETrue);
   109 			break;
   121 			break;
   110 		
   122 		
   111 		case ETransferIn:
   123 		case ETransferIn:
   112 			RDebug::Printf("Try to receive data");
   124 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_DUP04, "Try to receive data");
   113 			iInTransfer[0]->TransferIn(KBulkNumReadBytes); //require completion using ZLP
   125 			iInTransfer[0]->TransferIn(KBulkNumReadBytes); //require completion using ZLP
   114 			break;
   126 			break;
   115 	
   127 	
   116 		default:
   128 		default:
   117 			RDebug::Printf("<Error> Unknown test step");
   129 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_DUP05, "<Error> Unknown test step");
   118 			TestFailed(KErrUnknown);
   130 			TestFailed(KErrUnknown);
   119 			break;
   131 			break;
   120 		}
   132 		}
       
   133 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_EP0TRANSFERCOMPLETEL_EXIT_DUP01, this );
   121 	}
   134 	}
   122 	
   135 	
   123 void CUT_PBASE_T_USBDI_0494::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
   136 void CUT_PBASE_T_USBDI_0494::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
   124 	{
   137 	{
   125 	LOG_FUNC
   138 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0494_TRANSFERCOMPLETEL_ENTRY, this );
   126 	Cancel();
   139 	Cancel();
   127 	
   140 	
   128 	TInt err(KErrNone);
   141 	TInt err(KErrNone);
   129 	TBuf<256> msg;
   142 	TBuf<256> msg;
   130 	RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
   143 	OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_TRANSFERCOMPLETEL, "Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
   131 
   144 
   132 	switch(iCaseStep)
   145 	switch(iCaseStep)
   133 		{
   146 		{
   134 		case ETransferOut:
   147 		case ETransferOut:
   135 			{
   148 			{
   146 				msg.Format(_L("<Error %d> Unexpected tranfer ID, wanted %d, got %d"),
   159 				msg.Format(_L("<Error %d> Unexpected tranfer ID, wanted %d, got %d"),
   147 						       err, KBulkTranferOutId, aTransferId);
   160 						       err, KBulkTranferOutId, aTransferId);
   148 				break;
   161 				break;
   149 				}
   162 				}
   150 
   163 
   151 			RDebug::Printf("Try to receive back sent data");
   164 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_TRANSFERCOMPLETEL_DUP01, "Try to receive back sent data");
   152 			iCaseStep = ETransferIn;
   165 			iCaseStep = ETransferIn;
   153 			TWriteSynchronousCachedReadDataRequest request(1,1,1);  //Use first read EP and first write EP (on interface 1)
   166 			TWriteSynchronousCachedReadDataRequest request(1,1,1);  //Use first read EP and first write EP (on interface 1)
   154 			iControlEp0->SendRequest(request,this);
   167 			iControlEp0->SendRequest(request,this);
   155 			}
   168 			}
   156 			break;
   169 			break;
   181 				}
   194 				}
   182 
   195 
   183 			if(err == KErrNone)
   196 			if(err == KErrNone)
   184 				{
   197 				{
   185 				// Comparison is a match
   198 				// Comparison is a match
   186 				RDebug::Printf("Comparison for IN transfer is a match");
   199 				OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_TRANSFERCOMPLETEL_DUP02, "Comparison for IN transfer is a match");
   187 				iCaseStep = EPassed;
   200 				iCaseStep = EPassed;
   188 				TTestCasePassed request;
   201 				TTestCasePassed request;
   189 				iControlEp0->SendRequest(request,this);
   202 				iControlEp0->SendRequest(request,this);
   190 				}
   203 				}
   191 			}
   204 			}
   197 			break;
   210 			break;
   198 		}
   211 		}
   199 	
   212 	
   200 	if(err!=KErrNone)
   213 	if(err!=KErrNone)
   201 		{	
   214 		{	
   202 		RDebug::Print(msg);
   215 		OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_TRANSFERCOMPLETEL_DUP03, msg);
   203 		iCaseStep = EFailed;
   216 		iCaseStep = EFailed;
   204 		TTestCaseFailed request(err,msg);
   217 		TTestCaseFailed request(err,msg);
   205 		return iControlEp0->SendRequest(request,this);
   218 		return iControlEp0->SendRequest(request,this);
   206 		}	
   219 		}	
       
   220 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_TRANSFERCOMPLETEL_EXIT, this );
   207 	}
   221 	}
   208 	
   222 	
   209 void CUT_PBASE_T_USBDI_0494::DeviceInsertedL(TUint aDeviceHandle)
   223 void CUT_PBASE_T_USBDI_0494::DeviceInsertedL(TUint aDeviceHandle)
   210 	{
   224 	{
   211 	LOG_FUNC
   225 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0494_DEVICEINSERTEDL_ENTRY, this );
   212 	Cancel();
   226 	Cancel();
   213 	
   227 	
   214 	if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
   228 	if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
   215 		// Prepare for response from control transfer to client
   229 		// Prepare for response from control transfer to client
   216 		{
   230 		{
   220 	// Create the bulk transfers	
   234 	// Create the bulk transfers	
   221 	iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTranferInId);
   235 	iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTranferInId);
   222 	iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTranferOutId);
   236 	iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTranferOutId);
   223 	
   237 	
   224 	// Initialise the descriptors for transfer		
   238 	// Initialise the descriptors for transfer		
   225 	RDebug::Printf("Initialising the transfer descriptors");
   239 	OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_DEVICEINSERTEDL, "Initialising the transfer descriptors");
   226 	TInt err = iUsbInterface1.InitialiseTransferDescriptors();
   240 	TInt err = iUsbInterface1.InitialiseTransferDescriptors();
   227 	if(err != KErrNone)
   241 	if(err != KErrNone)
   228 		{
   242 		{
   229 		TBuf<256> msg;
   243 		TBuf<256> msg;
   230 		msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
   244 		msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
   231 		RDebug::Print(msg);
   245 		OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0494_DEVICEINSERTEDL_DUP01, msg);
   232 		iCaseStep = EFailed;
   246 		iCaseStep = EFailed;
   233 		TTestCaseFailed request(err,msg);
   247 		TTestCaseFailed request(err,msg);
   234 		iControlEp0->SendRequest(request,this);
   248 		iControlEp0->SendRequest(request,this);
       
   249 		OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_DEVICEINSERTEDL_EXIT, this );
   235 		return;
   250 		return;
   236 		}
   251 		}
   237 
   252 
   238 	iCaseStep = ETransferOut;	
   253 	iCaseStep = ETransferOut;	
   239 	TEndpointReadUntilShortRequest request(1,1,KBulkTransferSize);// EP1 because 1st reader EP ??FIXME
   254 	TEndpointReadUntilShortRequest request(1,1,KBulkTransferSize);// EP1 because 1st reader EP ??FIXME
   240 	iControlEp0->SendRequest(request,this);
   255 	iControlEp0->SendRequest(request,this);
       
   256 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0494_DEVICEINSERTEDL_EXIT_DUP01, this );
   241 	}
   257 	}
   242 	
   258 	
   243 	} //end namespace
   259 	} //end namespace