os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0491.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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-0491.cpp
    15 // @internalComponent
    16 // 
    17 //
    18 
    19 #include "PBASE-T_USBDI-0491.h"
    20 #include "testpolicy.h"
    21 #include "modelleddevices.h"
    22 #include "testliterals.h"
    23 
    24 
    25  
    26 
    27 namespace NUnitTesting_USBDI
    28 	{
    29 
    30 const TUint KBulkTransferSize = 210; 
    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-0491");
    39 const TFunctorTestCase<CUT_PBASE_T_USBDI_0491,TBool> CUT_PBASE_T_USBDI_0491::iFunctor(KTestCaseId);	
    40 
    41 CUT_PBASE_T_USBDI_0491* CUT_PBASE_T_USBDI_0491::NewL(TBool aHostRole)
    42 	{
    43 	CUT_PBASE_T_USBDI_0491* self = new (ELeave) CUT_PBASE_T_USBDI_0491(aHostRole);
    44 	CleanupStack::PushL(self);
    45 	self->ConstructL();
    46 	CleanupStack::Pop(self);
    47 	return self;
    48 	}
    49 	
    50 
    51 CUT_PBASE_T_USBDI_0491::CUT_PBASE_T_USBDI_0491(TBool aHostRole)
    52 :	CBaseBulkTestCase(KTestCaseId,aHostRole),
    53 	iCaseStep(EInProgress)
    54 	{
    55 	} 
    56 
    57 
    58 void CUT_PBASE_T_USBDI_0491::ConstructL()
    59 	{
    60 	BaseBulkConstructL();
    61 	}
    62 
    63 
    64 CUT_PBASE_T_USBDI_0491::~CUT_PBASE_T_USBDI_0491()
    65 	{
    66 	LOG_FUNC
    67 	}
    68 
    69 void CUT_PBASE_T_USBDI_0491::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(KLiteralEnglish2(), KBulkTransferSize);
   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_0491::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(), KLiteralEnglish2(), 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_0491::DeviceInsertedL(TUint aDeviceHandle)
   205 	{
   206 	LOG_FUNC
   207 	Cancel();
   208 	RDebug::Printf("****** Father William Pattern Length is %d bytes! *********", KLiteralEnglish2().Length());
   209 	
   210 	if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
   211 		// Prepare for response from control transfer to client
   212 		{
   213 		iCaseStep = EFailed;
   214 		}
   215 	
   216 	// Create the bulk transfers	
   217 	iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferInId);
   218 	iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId);
   219 	
   220 	// Initialise the descriptors for transfer		
   221 	RDebug::Printf("Initialising the transfer descriptors");
   222 	TInt err = iUsbInterface1.InitialiseTransferDescriptors();
   223 	if(err != KErrNone)
   224 		{
   225 		TBuf<256> msg;
   226 		msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
   227 		RDebug::Print(msg);
   228 		iCaseStep = EFailed;
   229 		TTestCaseFailed request(err,msg);
   230 		iControlEp0->SendRequest(request,this);
   231 		return;
   232 		}
   233 
   234 	iCaseStep = ETransferOut;	
   235 	TEndpointReadUntilShortRequest request(1,1,KBulkTransferSize);// EP1 because 1st reader EP
   236 	iControlEp0->SendRequest(request,this);
   237 	}
   238 	
   239 	} //end namespace