kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0490.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".
    17 //
    17 //
    18 
    18 
    19 #include "PBASE-T_USBDI-0490.h"
    19 #include "PBASE-T_USBDI-0490.h"
    20 #include "testpolicy.h"
    20 #include "testpolicy.h"
    21 #include "modelleddevices.h"
    21 #include "modelleddevices.h"
       
    22 #include "OstTraceDefinitions.h"
       
    23 #ifdef OST_TRACE_COMPILER_IN_USE
       
    24 #include "PBASE-T_USBDI-0490Traces.h"
       
    25 #endif
    22 
    26 
    23 
    27 
    24  
    28  
    25 
    29 
    26 namespace NUnitTesting_USBDI
    30 namespace NUnitTesting_USBDI
    38 _LIT(KTestCaseId,"PBASE-T_USBDI-0490");
    42 _LIT(KTestCaseId,"PBASE-T_USBDI-0490");
    39 const TFunctorTestCase<CUT_PBASE_T_USBDI_0490,TBool> CUT_PBASE_T_USBDI_0490::iFunctor(KTestCaseId);	
    43 const TFunctorTestCase<CUT_PBASE_T_USBDI_0490,TBool> CUT_PBASE_T_USBDI_0490::iFunctor(KTestCaseId);	
    40 
    44 
    41 CUT_PBASE_T_USBDI_0490* CUT_PBASE_T_USBDI_0490::NewL(TBool aHostRole)
    45 CUT_PBASE_T_USBDI_0490* CUT_PBASE_T_USBDI_0490::NewL(TBool aHostRole)
    42 	{
    46 	{
       
    47 	OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0490_NEWL_ENTRY, aHostRole );
    43 	CUT_PBASE_T_USBDI_0490* self = new (ELeave) CUT_PBASE_T_USBDI_0490(aHostRole);
    48 	CUT_PBASE_T_USBDI_0490* self = new (ELeave) CUT_PBASE_T_USBDI_0490(aHostRole);
    44 	CleanupStack::PushL(self);
    49 	CleanupStack::PushL(self);
    45 	self->ConstructL();
    50 	self->ConstructL();
    46 	CleanupStack::Pop(self);
    51 	CleanupStack::Pop(self);
       
    52 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_NEWL_EXIT, ( TUint )( self ) );
    47 	return self;
    53 	return self;
    48 	}
    54 	}
    49 	
    55 	
    50 
    56 
    51 CUT_PBASE_T_USBDI_0490::CUT_PBASE_T_USBDI_0490(TBool aHostRole)
    57 CUT_PBASE_T_USBDI_0490::CUT_PBASE_T_USBDI_0490(TBool aHostRole)
    52 :	CBaseBulkTestCase(KTestCaseId,aHostRole),
    58 :	CBaseBulkTestCase(KTestCaseId,aHostRole),
    53 	iCaseStep(EInProgress)
    59 	iCaseStep(EInProgress)
    54 	{
    60 	{
       
    61 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0490_CUT_PBASE_T_USBDI_0490_ENTRY, this );
       
    62 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_CUT_PBASE_T_USBDI_0490_EXIT, this );
    55 	} 
    63 	} 
    56 
    64 
    57 
    65 
    58 void CUT_PBASE_T_USBDI_0490::ConstructL()
    66 void CUT_PBASE_T_USBDI_0490::ConstructL()
    59 	{
    67 	{
       
    68 	OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0490_CONSTRUCTL_ENTRY, this );
    60 	BaseBulkConstructL();
    69 	BaseBulkConstructL();
       
    70 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_CONSTRUCTL_EXIT, this );
    61 	}
    71 	}
    62 
    72 
    63 
    73 
    64 CUT_PBASE_T_USBDI_0490::~CUT_PBASE_T_USBDI_0490()
    74 CUT_PBASE_T_USBDI_0490::~CUT_PBASE_T_USBDI_0490()
    65 	{
    75 	{
    66 	LOG_FUNC
    76 	OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0490_CUT_PBASE_T_USBDI_0490_ENTRY_DUP01, this );
       
    77 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_CUT_PBASE_T_USBDI_0490_EXIT_DUP01, this );
    67 	}
    78 	}
    68 	
    79 	
    69 void CUT_PBASE_T_USBDI_0490::Ep0TransferCompleteL(TInt aCompletionCode)
    80 void CUT_PBASE_T_USBDI_0490::Ep0TransferCompleteL(TInt aCompletionCode)
    70 	{
    81 	{
    71 	LOG_FUNC
    82 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_ENTRY, this );
    72 	
    83 	
    73 	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
    84 	OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL, "Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
    74 	
    85 	
    75 	if(aCompletionCode != KErrNone)
    86 	if(aCompletionCode != KErrNone)
    76 		{
    87 		{
    77 		if(iCaseStep == EFailed)
    88 		if(iCaseStep == EFailed)
    78 			{// ignore error, nad catch the TestFailed method called further down.
    89 			{// ignore error, nad catch the TestFailed method called further down.
    79 			RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***");
    90 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_DUP01, "***Failure sending FAIL message to client on endpoint 0***");
    80 			}
    91 			}
    81 		else
    92 		else
    82 			{
    93 			{
    83 			TBuf<256> msg;
    94 			TBuf<256> msg;
    84 			msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
    95 			msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
    85 			RDebug::Print(msg);
    96 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_DUP02, msg);
    86 			iCaseStep = EFailed;
    97 			iCaseStep = EFailed;
    87 			TTestCaseFailed request(aCompletionCode,msg);
    98 			TTestCaseFailed request(aCompletionCode,msg);
    88 			iControlEp0->SendRequest(request,this);
    99 			iControlEp0->SendRequest(request,this);
       
   100 			OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_EXIT, this );
    89 			return;
   101 			return;
    90 			}
   102 			}
    91 		}
   103 		}
    92 	
   104 	
    93 	switch(iCaseStep)
   105 	switch(iCaseStep)
   101 		case EFailed:
   113 		case EFailed:
   102 			TestFailed(KErrCompletion);
   114 			TestFailed(KErrCompletion);
   103 			break;
   115 			break;
   104 			
   116 			
   105 		case ETransferOut:
   117 		case ETransferOut:
   106 			RDebug::Printf("Try to send data");
   118 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_DUP03, "Try to send data");
   107 			iOutTransfer[0]->TransferOut(KPayloadPattern);
   119 			iOutTransfer[0]->TransferOut(KPayloadPattern);
   108 			break;
   120 			break;
   109 		
   121 		
   110 		case ETransferIn:
   122 		case ETransferIn:
   111 			RDebug::Printf("Try to receive data");
   123 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_DUP04, "Try to receive data");
   112 			iInTransfer[0]->TransferIn(KBulkTransferSize);
   124 			iInTransfer[0]->TransferIn(KBulkTransferSize);
   113 			break;
   125 			break;
   114 	
   126 	
   115 		default:
   127 		default:
   116 			RDebug::Printf("<Error> Unknown test step");
   128 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_DUP05, "<Error> Unknown test step");
   117 			TestFailed(KErrUnknown);
   129 			TestFailed(KErrUnknown);
   118 			break;
   130 			break;
   119 		}
   131 		}
       
   132 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_EP0TRANSFERCOMPLETEL_EXIT_DUP01, this );
   120 	}
   133 	}
   121 	
   134 	
   122 void CUT_PBASE_T_USBDI_0490::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
   135 void CUT_PBASE_T_USBDI_0490::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
   123 	{
   136 	{
   124 	LOG_FUNC
   137 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0490_TRANSFERCOMPLETEL_ENTRY, this );
   125 	Cancel();
   138 	Cancel();
   126 	
   139 	
   127 	TInt err(KErrNone);
   140 	TInt err(KErrNone);
   128 	TBuf<256> msg;
   141 	TBuf<256> msg;
   129 	RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
   142 	OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_TRANSFERCOMPLETEL, "Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
   130 
   143 
   131 	switch(iCaseStep)
   144 	switch(iCaseStep)
   132 		{
   145 		{
   133 		case ETransferOut:
   146 		case ETransferOut:
   134 			{
   147 			{
   143 				err = KUnexpectedTransferID;
   156 				err = KUnexpectedTransferID;
   144 				msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d, got %d"),
   157 				msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d, got %d"),
   145 						       err, KBulkTransferOutId, aTransferId);
   158 						       err, KBulkTransferOutId, aTransferId);
   146 				break;
   159 				break;
   147 				}
   160 				}
   148 			RDebug::Printf("Try to receive back sent data");
   161 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_TRANSFERCOMPLETEL_DUP01, "Try to receive back sent data");
   149 			iCaseStep = ETransferIn;
   162 			iCaseStep = ETransferIn;
   150 			TWriteSynchronousCachedReadDataRequest request(1,1,1); //Use first read EP and first write EP (on interface 1)
   163 			TWriteSynchronousCachedReadDataRequest request(1,1,1); //Use first read EP and first write EP (on interface 1)
   151 			iControlEp0->SendRequest(request,this);	
   164 			iControlEp0->SendRequest(request,this);	
   152 			}
   165 			}
   153 			break;
   166 			break;
   175 				break;
   188 				break;
   176 				}
   189 				}
   177 			if(err == KErrNone)
   190 			if(err == KErrNone)
   178 				{
   191 				{
   179 				// Comparison is a match
   192 				// Comparison is a match
   180 				RDebug::Printf("Comparison for IN transfer is a match");
   193 				OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_TRANSFERCOMPLETEL_DUP02, "Comparison for IN transfer is a match");
   181 				iCaseStep = EPassed;
   194 				iCaseStep = EPassed;
   182 				TTestCasePassed request;
   195 				TTestCasePassed request;
   183 				iControlEp0->SendRequest(request,this);
   196 				iControlEp0->SendRequest(request,this);
   184 				break;
   197 				break;
   185 				}
   198 				}
   192 			break;
   205 			break;
   193 		}
   206 		}
   194 	
   207 	
   195 	if(err!=KErrNone)
   208 	if(err!=KErrNone)
   196 		{	
   209 		{	
   197 		RDebug::Print(msg);
   210 		OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_TRANSFERCOMPLETEL_DUP03, msg);
   198 		iCaseStep = EFailed;
   211 		iCaseStep = EFailed;
   199 		TTestCaseFailed request(err,msg);
   212 		TTestCaseFailed request(err,msg);
   200 		return iControlEp0->SendRequest(request,this);
   213 		return iControlEp0->SendRequest(request,this);
   201 		}	
   214 		}	
       
   215 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_TRANSFERCOMPLETEL_EXIT, this );
   202 	}
   216 	}
   203 	
   217 	
   204 void CUT_PBASE_T_USBDI_0490::DeviceInsertedL(TUint aDeviceHandle)
   218 void CUT_PBASE_T_USBDI_0490::DeviceInsertedL(TUint aDeviceHandle)
   205 	{
   219 	{
   206 	LOG_FUNC
   220 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0490_DEVICEINSERTEDL_ENTRY, this );
   207 	Cancel();
   221 	Cancel();
   208 	
   222 	
   209 	if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
   223 	if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
   210 		// Prepare for response from control transfer to client
   224 		// Prepare for response from control transfer to client
   211 		{
   225 		{
   215 	// Create the bulk transfers	
   229 	// Create the bulk transfers	
   216 	iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferInId);
   230 	iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferInId);
   217 	iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId);
   231 	iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId);
   218 	
   232 	
   219 	// Initialise the descriptors for transfer		
   233 	// Initialise the descriptors for transfer		
   220 	RDebug::Printf("Initialising the transfer descriptors");
   234 	OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_DEVICEINSERTEDL, "Initialising the transfer descriptors");
   221 	TInt err = iUsbInterface1.InitialiseTransferDescriptors();
   235 	TInt err = iUsbInterface1.InitialiseTransferDescriptors();
   222 	if(err != KErrNone)
   236 	if(err != KErrNone)
   223 		{
   237 		{
   224 		TBuf<256> msg;
   238 		TBuf<256> msg;
   225 		msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
   239 		msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
   226 		RDebug::Print(msg);
   240 		OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0490_DEVICEINSERTEDL_DUP01, msg);
   227 		iCaseStep = EFailed;
   241 		iCaseStep = EFailed;
   228 		TTestCaseFailed request(err,msg);
   242 		TTestCaseFailed request(err,msg);
   229 		iControlEp0->SendRequest(request,this);
   243 		iControlEp0->SendRequest(request,this);
       
   244 		OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_DEVICEINSERTEDL_EXIT, this );
   230 		return;
   245 		return;
   231 		}
   246 		}
   232 
   247 
   233 	iCaseStep = ETransferOut;
   248 	iCaseStep = ETransferOut;
   234 	TEndpointReadUntilShortRequest request(1,1,KBulkTransferSize);// EP1 because 1st reader EP
   249 	TEndpointReadUntilShortRequest request(1,1,KBulkTransferSize);// EP1 because 1st reader EP
   235 	iControlEp0->SendRequest(request,this);
   250 	iControlEp0->SendRequest(request,this);
       
   251 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0490_DEVICEINSERTEDL_EXIT_DUP01, this );
   236 	}
   252 	}
   237 	
   253 	
   238 	} //end namespace
   254 	} //end namespace