kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0491.cpp
changeset 253 d37db4dcc88d
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
252:0a40b8675b23 253:d37db4dcc88d
     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-0491.h"
    19 #include "PBASE-T_USBDI-0491.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-0491Traces.h"
       
    26 #endif
    23 
    27 
    24 
    28 
    25  
    29  
    26 
    30 
    27 namespace NUnitTesting_USBDI
    31 namespace NUnitTesting_USBDI
    38 _LIT(KTestCaseId,"PBASE-T_USBDI-0491");
    42 _LIT(KTestCaseId,"PBASE-T_USBDI-0491");
    39 const TFunctorTestCase<CUT_PBASE_T_USBDI_0491,TBool> CUT_PBASE_T_USBDI_0491::iFunctor(KTestCaseId);	
    43 const TFunctorTestCase<CUT_PBASE_T_USBDI_0491,TBool> CUT_PBASE_T_USBDI_0491::iFunctor(KTestCaseId);	
    40 
    44 
    41 CUT_PBASE_T_USBDI_0491* CUT_PBASE_T_USBDI_0491::NewL(TBool aHostRole)
    45 CUT_PBASE_T_USBDI_0491* CUT_PBASE_T_USBDI_0491::NewL(TBool aHostRole)
    42 	{
    46 	{
       
    47 	OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0491_NEWL_ENTRY, aHostRole );
    43 	CUT_PBASE_T_USBDI_0491* self = new (ELeave) CUT_PBASE_T_USBDI_0491(aHostRole);
    48 	CUT_PBASE_T_USBDI_0491* self = new (ELeave) CUT_PBASE_T_USBDI_0491(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_0491_NEWL_EXIT, ( TUint )( self ) );
    47 	return self;
    53 	return self;
    48 	}
    54 	}
    49 	
    55 	
    50 
    56 
    51 CUT_PBASE_T_USBDI_0491::CUT_PBASE_T_USBDI_0491(TBool aHostRole)
    57 CUT_PBASE_T_USBDI_0491::CUT_PBASE_T_USBDI_0491(TBool aHostRole)
    52 :	CBaseBulkTestCase(KTestCaseId,aHostRole),
    58 :	CBaseBulkTestCase(KTestCaseId,aHostRole),
    53 	iCaseStep(EInProgress)
    59 	iCaseStep(EInProgress)
    54 	{
    60 	{
       
    61 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0491_CUT_PBASE_T_USBDI_0491_ENTRY, this );
       
    62 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0491_CUT_PBASE_T_USBDI_0491_EXIT, this );
    55 	} 
    63 	} 
    56 
    64 
    57 
    65 
    58 void CUT_PBASE_T_USBDI_0491::ConstructL()
    66 void CUT_PBASE_T_USBDI_0491::ConstructL()
    59 	{
    67 	{
       
    68 	OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0491_CONSTRUCTL_ENTRY, this );
    60 	BaseBulkConstructL();
    69 	BaseBulkConstructL();
       
    70 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0491_CONSTRUCTL_EXIT, this );
    61 	}
    71 	}
    62 
    72 
    63 
    73 
    64 CUT_PBASE_T_USBDI_0491::~CUT_PBASE_T_USBDI_0491()
    74 CUT_PBASE_T_USBDI_0491::~CUT_PBASE_T_USBDI_0491()
    65 	{
    75 	{
    66 	LOG_FUNC
    76 	OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0491_CUT_PBASE_T_USBDI_0491_ENTRY_DUP01, this );
       
    77 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0491_CUT_PBASE_T_USBDI_0491_EXIT_DUP01, this );
    67 	}
    78 	}
    68 
    79 
    69 void CUT_PBASE_T_USBDI_0491::Ep0TransferCompleteL(TInt aCompletionCode)
    80 void CUT_PBASE_T_USBDI_0491::Ep0TransferCompleteL(TInt aCompletionCode)
    70 	{
    81 	{
    71 	LOG_FUNC
    82 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0491_EP0TRANSFERCOMPLETEL_ENTRY, this );
    72 	
    83 	
    73 	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
    84 	OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0491_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_0491_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_0491_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_0491_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_0491_EP0TRANSFERCOMPLETEL_DUP03, "Try to send data");
   107 			iOutTransfer[0]->TransferOut(KLiteralEnglish2(), KBulkTransferSize);
   119 			iOutTransfer[0]->TransferOut(KLiteralEnglish2(), KBulkTransferSize);
   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_0491_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_0491_EP0TRANSFERCOMPLETEL_DUP05, "<Error> Unknown test step");
   117 			TestFailed(KErrUnknown);
   129 			TestFailed(KErrUnknown);
   118 			break;
   130 			break;
   119 		}
   131 		}
       
   132 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0491_EP0TRANSFERCOMPLETEL_EXIT_DUP01, this );
   120 	}
   133 	}
   121 	
   134 	
   122 void CUT_PBASE_T_USBDI_0491::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
   135 void CUT_PBASE_T_USBDI_0491::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
   123 	{
   136 	{
   124 	LOG_FUNC
   137 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0491_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_0491_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_0491_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_0491_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_0491_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_0491_TRANSFERCOMPLETEL_EXIT, this );
   202 	}
   216 	}
   203 	
   217 	
   204 void CUT_PBASE_T_USBDI_0491::DeviceInsertedL(TUint aDeviceHandle)
   218 void CUT_PBASE_T_USBDI_0491::DeviceInsertedL(TUint aDeviceHandle)
   205 	{
   219 	{
   206 	LOG_FUNC
   220 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0491_DEVICEINSERTEDL_ENTRY, this );
   207 	Cancel();
   221 	Cancel();
   208 	RDebug::Printf("****** Father William Pattern Length is %d bytes! *********", KLiteralEnglish2().Length());
   222 	OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0491_DEVICEINSERTEDL, "****** Father William Pattern Length is %d bytes! *********", KLiteralEnglish2().Length());
   209 	
   223 	
   210 	if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
   224 	if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
   211 		// Prepare for response from control transfer to client
   225 		// Prepare for response from control transfer to client
   212 		{
   226 		{
   213 		iCaseStep = EFailed;
   227 		iCaseStep = EFailed;
   216 	// Create the bulk transfers	
   230 	// Create the bulk transfers	
   217 	iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferInId);
   231 	iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferInId);
   218 	iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId);
   232 	iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId);
   219 	
   233 	
   220 	// Initialise the descriptors for transfer		
   234 	// Initialise the descriptors for transfer		
   221 	RDebug::Printf("Initialising the transfer descriptors");
   235 	OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0491_DEVICEINSERTEDL_DUP01, "Initialising the transfer descriptors");
   222 	TInt err = iUsbInterface1.InitialiseTransferDescriptors();
   236 	TInt err = iUsbInterface1.InitialiseTransferDescriptors();
   223 	if(err != KErrNone)
   237 	if(err != KErrNone)
   224 		{
   238 		{
   225 		TBuf<256> msg;
   239 		TBuf<256> msg;
   226 		msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
   240 		msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
   227 		RDebug::Print(msg);
   241 		OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0491_DEVICEINSERTEDL_DUP02, msg);
   228 		iCaseStep = EFailed;
   242 		iCaseStep = EFailed;
   229 		TTestCaseFailed request(err,msg);
   243 		TTestCaseFailed request(err,msg);
   230 		iControlEp0->SendRequest(request,this);
   244 		iControlEp0->SendRequest(request,this);
       
   245 		OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0491_DEVICEINSERTEDL_EXIT, this );
   231 		return;
   246 		return;
   232 		}
   247 		}
   233 
   248 
   234 	iCaseStep = ETransferOut;	
   249 	iCaseStep = ETransferOut;	
   235 	TEndpointReadUntilShortRequest request(1,1,KBulkTransferSize);// EP1 because 1st reader EP
   250 	TEndpointReadUntilShortRequest request(1,1,KBulkTransferSize);// EP1 because 1st reader EP
   236 	iControlEp0->SendRequest(request,this);
   251 	iControlEp0->SendRequest(request,this);
       
   252 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0491_DEVICEINSERTEDL_EXIT_DUP01, this );
   237 	}
   253 	}
   238 	
   254 	
   239 	} //end namespace
   255 	} //end namespace