os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0490.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2008-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 the License "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 // @file PBASE-T_USBDI-0490.cpp
    15 // @internalComponent
    16 // 
    17 //
    18 
    19 #include "PBASE-T_USBDI-0490.h"
    20 #include "testpolicy.h"
    21 #include "modelleddevices.h"
    22 
    23 
    24  
    25 
    26 namespace NUnitTesting_USBDI
    27 	{
    28 _LIT8(KPayloadPattern,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); // 52bytes
    29 
    30 const TUint KBulkTransferSize = 52;
    31 const TInt KBulkTransferInId = 1<<0;
    32 const TInt KBulkTransferOutId = 1<<1;
    33 
    34 const TInt KUnexpectedTransferID = -101;
    35 const TInt KUndefinedStep	 = -102;
    36 
    37 
    38 _LIT(KTestCaseId,"PBASE-T_USBDI-0490");
    39 const TFunctorTestCase<CUT_PBASE_T_USBDI_0490,TBool> CUT_PBASE_T_USBDI_0490::iFunctor(KTestCaseId);	
    40 
    41 CUT_PBASE_T_USBDI_0490* CUT_PBASE_T_USBDI_0490::NewL(TBool aHostRole)
    42 	{
    43 	CUT_PBASE_T_USBDI_0490* self = new (ELeave) CUT_PBASE_T_USBDI_0490(aHostRole);
    44 	CleanupStack::PushL(self);
    45 	self->ConstructL();
    46 	CleanupStack::Pop(self);
    47 	return self;
    48 	}
    49 	
    50 
    51 CUT_PBASE_T_USBDI_0490::CUT_PBASE_T_USBDI_0490(TBool aHostRole)
    52 :	CBaseBulkTestCase(KTestCaseId,aHostRole),
    53 	iCaseStep(EInProgress)
    54 	{
    55 	} 
    56 
    57 
    58 void CUT_PBASE_T_USBDI_0490::ConstructL()
    59 	{
    60 	BaseBulkConstructL();
    61 	}
    62 
    63 
    64 CUT_PBASE_T_USBDI_0490::~CUT_PBASE_T_USBDI_0490()
    65 	{
    66 	LOG_FUNC
    67 	}
    68 	
    69 void CUT_PBASE_T_USBDI_0490::Ep0TransferCompleteL(TInt aCompletionCode)
    70 	{
    71 	LOG_FUNC
    72 	
    73 	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
    74 	
    75 	if(aCompletionCode != KErrNone)
    76 		{
    77 		if(iCaseStep == EFailed)
    78 			{// ignore error, nad catch the TestFailed method called further down.
    79 			RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***");
    80 			}
    81 		else
    82 			{
    83 			TBuf<256> msg;
    84 			msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
    85 			RDebug::Print(msg);
    86 			iCaseStep = EFailed;
    87 			TTestCaseFailed request(aCompletionCode,msg);
    88 			iControlEp0->SendRequest(request,this);
    89 			return;
    90 			}
    91 		}
    92 	
    93 	switch(iCaseStep)
    94 		{
    95 		// Test case passed
    96 		case EPassed:
    97 			TestPassed();
    98 			break;
    99 		
   100 		// Test case failed	
   101 		case EFailed:
   102 			TestFailed(KErrCompletion);
   103 			break;
   104 			
   105 		case ETransferOut:
   106 			RDebug::Printf("Try to send data");
   107 			iOutTransfer[0]->TransferOut(KPayloadPattern);
   108 			break;
   109 		
   110 		case ETransferIn:
   111 			RDebug::Printf("Try to receive data");
   112 			iInTransfer[0]->TransferIn(KBulkTransferSize);
   113 			break;
   114 	
   115 		default:
   116 			RDebug::Printf("<Error> Unknown test step");
   117 			TestFailed(KErrUnknown);
   118 			break;
   119 		}
   120 	}
   121 	
   122 void CUT_PBASE_T_USBDI_0490::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
   123 	{
   124 	LOG_FUNC
   125 	Cancel();
   126 	
   127 	TInt err(KErrNone);
   128 	TBuf<256> msg;
   129 	RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
   130 
   131 	switch(iCaseStep)
   132 		{
   133 		case ETransferOut:
   134 			{
   135 			if(aCompletionCode != KErrNone)
   136 				{
   137 				err = KErrCorrupt;
   138 				msg.Format(_L("<Error %d> No data sent on bulk OUT request"),aCompletionCode);
   139 				break;
   140 				}
   141 			if(aTransferId != KBulkTransferOutId)
   142 				{
   143 				err = KUnexpectedTransferID;
   144 				msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d, got %d"),
   145 						       err, KBulkTransferOutId, aTransferId);
   146 				break;
   147 				}
   148 			RDebug::Printf("Try to receive back sent data");
   149 			iCaseStep = ETransferIn;
   150 			TWriteSynchronousCachedReadDataRequest request(1,1,1); //Use first read EP and first write EP (on interface 1)
   151 			iControlEp0->SendRequest(request,this);	
   152 			}
   153 			break;
   154 			
   155 		case ETransferIn:
   156 			{
   157 			if(aCompletionCode != KErrNone)
   158 				{
   159 				err = KErrCorrupt;
   160 				msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode);
   161 				break;
   162 				}
   163 			if(aTransferId != KBulkTransferInId)
   164 				{
   165 				err = KUnexpectedTransferID;
   166 				msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d, got %d"),
   167 						       err, KBulkTransferInId, aTransferId);
   168 				break;
   169 				}
   170 			// Compare the data to what is expected
   171 			if(ValidateData(iInTransfer[0]->DataPolled(), KPayloadPattern, KBulkTransferSize) == EFalse)
   172 				{
   173 				err = KErrCompletion; //indicates data validation failure
   174 				msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
   175 				break;
   176 				}
   177 			if(err == KErrNone)
   178 				{
   179 				// Comparison is a match
   180 				RDebug::Printf("Comparison for IN transfer is a match");
   181 				iCaseStep = EPassed;
   182 				TTestCasePassed request;
   183 				iControlEp0->SendRequest(request,this);
   184 				break;
   185 				}
   186 			}
   187 			break;
   188 
   189 		default:
   190 			err = KUndefinedStep;
   191 			msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep);
   192 			break;
   193 		}
   194 	
   195 	if(err!=KErrNone)
   196 		{	
   197 		RDebug::Print(msg);
   198 		iCaseStep = EFailed;
   199 		TTestCaseFailed request(err,msg);
   200 		return iControlEp0->SendRequest(request,this);
   201 		}	
   202 	}
   203 	
   204 void CUT_PBASE_T_USBDI_0490::DeviceInsertedL(TUint aDeviceHandle)
   205 	{
   206 	LOG_FUNC
   207 	Cancel();
   208 	
   209 	if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
   210 		// Prepare for response from control transfer to client
   211 		{
   212 		iCaseStep = EFailed;
   213 		}
   214 	
   215 	// Create the bulk transfers	
   216 	iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferInId);
   217 	iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId);
   218 	
   219 	// Initialise the descriptors for transfer		
   220 	RDebug::Printf("Initialising the transfer descriptors");
   221 	TInt err = iUsbInterface1.InitialiseTransferDescriptors();
   222 	if(err != KErrNone)
   223 		{
   224 		TBuf<256> msg;
   225 		msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
   226 		RDebug::Print(msg);
   227 		iCaseStep = EFailed;
   228 		TTestCaseFailed request(err,msg);
   229 		iControlEp0->SendRequest(request,this);
   230 		return;
   231 		}
   232 
   233 	iCaseStep = ETransferOut;
   234 	TEndpointReadUntilShortRequest request(1,1,KBulkTransferSize);// EP1 because 1st reader EP
   235 	iControlEp0->SendRequest(request,this);
   236 	}
   237 	
   238 	} //end namespace