sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // @file PBASE-T_USBDI-0500.cpp sl@0: // @internalComponent sl@0: // sl@0: // sl@0: sl@0: #include "PBASE-T_USBDI-0500.h" sl@0: #include "testpolicy.h" sl@0: #include "modelleddevices.h" sl@0: #include "testliterals.h" sl@0: sl@0: sl@0: sl@0: sl@0: namespace NUnitTesting_USBDI sl@0: { sl@0: const TInt KBulkMaxINTransferSize = 600; sl@0: const TInt KDeviceNumWriteBytesPreHalt = 256; sl@0: const TUint KHostNumReadBytesPreHalt1 = 512; sl@0: const TUint KHostNumReadBytesPreHalt2 = 512; sl@0: const TUint KHostNumReadBytesPostHalt1 = 256; sl@0: const TUint KHostNumReadBytesPostHalt2 = 257; sl@0: const TInt KDeviceNumWriteBytesPostHalt = 512; sl@0: sl@0: sl@0: //Make these single bit values ... sl@0: // ... so that their completion can be easily recorded in a bit mask! sl@0: const TInt KBulkTransferInId0 = 1<<0; sl@0: const TInt KBulkTransferInId1 = 1<<4; sl@0: sl@0: const TInt KUnexpectedTransferID = -101; sl@0: const TInt KUndefinedStep = -102; sl@0: sl@0: sl@0: _LIT(KTestCaseId,"PBASE-T_USBDI-0500"); sl@0: const TFunctorTestCase CUT_PBASE_T_USBDI_0500::iFunctor(KTestCaseId); sl@0: sl@0: CUT_PBASE_T_USBDI_0500* CUT_PBASE_T_USBDI_0500::NewL(TBool aHostRole) sl@0: { sl@0: CUT_PBASE_T_USBDI_0500* self = new (ELeave) CUT_PBASE_T_USBDI_0500(aHostRole); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: CUT_PBASE_T_USBDI_0500::CUT_PBASE_T_USBDI_0500(TBool aHostRole) sl@0: : CBaseBulkTestCase(KTestCaseId,aHostRole), sl@0: iCaseStep(EInProgress) sl@0: { sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0500::ConstructL() sl@0: { sl@0: BaseBulkConstructL(); sl@0: } sl@0: sl@0: sl@0: CUT_PBASE_T_USBDI_0500::~CUT_PBASE_T_USBDI_0500() sl@0: { sl@0: LOG_FUNC sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0500::Ep0TransferCompleteL(TInt aCompletionCode) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode); sl@0: sl@0: if(aCompletionCode != KErrNone) sl@0: { sl@0: if(iCaseStep == EFailed) sl@0: {// ignore error, nad catch the TestFailed method called further down. sl@0: RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***"); sl@0: } sl@0: else sl@0: { sl@0: TBuf<256> msg; sl@0: msg.Format(_L(" Transfer to control endpoint 0 was not successful"),aCompletionCode); sl@0: RDebug::Print(msg); sl@0: iCaseStep = EFailed; sl@0: TTestCaseFailed request(aCompletionCode,msg); sl@0: iControlEp0->SendRequest(request,this); sl@0: return; sl@0: } sl@0: } sl@0: sl@0: switch(iCaseStep) sl@0: { sl@0: // Test case passed sl@0: case EPassed: sl@0: TestPassed(); sl@0: break; sl@0: sl@0: // Test case failed sl@0: case EFailed: sl@0: TestFailed(KErrCompletion); sl@0: break; sl@0: sl@0: case ETransferInHalt: sl@0: RDebug::Printf("Try to receive data (pre halt)"); sl@0: iInTransfer[0]->TransferIn(KHostNumReadBytesPreHalt1); sl@0: iInTransfer[1]->TransferIn(KHostNumReadBytesPreHalt2); sl@0: break; sl@0: sl@0: case ETransferIn: sl@0: RDebug::Printf("Try to receive data"); sl@0: iInTransfer[0]->TransferIn(KHostNumReadBytesPostHalt1); sl@0: iInTransfer[1]->TransferIn(KHostNumReadBytesPostHalt2); sl@0: break; sl@0: sl@0: default: sl@0: RDebug::Printf(" Unknown test step"); sl@0: TestFailed(KErrUnknown); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CUT_PBASE_T_USBDI_0500::TransferCompleteL(TInt aTransferId,TInt aCompletionCode) sl@0: { sl@0: LOG_FUNC sl@0: Cancel(); sl@0: sl@0: TInt err(KErrNone); sl@0: TBuf<256> msg; sl@0: RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode); sl@0: sl@0: switch(iCaseStep) sl@0: { sl@0: case ETransferInHalt: sl@0: { sl@0: if(aCompletionCode != KErrUsbStalled) sl@0: { sl@0: iInTransfer[0]->Cancel(); sl@0: iInTransfer[1]->Cancel(); sl@0: err = KErrCorrupt; sl@0: msg.Format(_L(" The transfer completed with no errors but the endpoint should have halted"),aCompletionCode); sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: switch(aTransferId) sl@0: { sl@0: case KBulkTransferInId0: sl@0: case KBulkTransferInId1: sl@0: iTransferComplete |= aTransferId; sl@0: RDebug::Printf("Transfer %d completed", aTransferId); sl@0: break; //switch(aTransferId) sl@0: sl@0: default: sl@0: iTransferComplete = 0; //reset sl@0: err = KUnexpectedTransferID; sl@0: msg.Format(_L(" Unexpected transfer ID, wanted %d or %d, got %d"), sl@0: err, KBulkTransferInId0, KBulkTransferInId1, aTransferId); sl@0: break; //switch(aTransferId) sl@0: } sl@0: sl@0: if(err==KErrNone && iTransferComplete == (KBulkTransferInId0 | KBulkTransferInId1)) sl@0: { sl@0: RDebug::Printf("Clear halt and try to send data again. Transfers Completed %d", iTransferComplete); sl@0: iTransferComplete = 0; //reset sl@0: // Acknowledge the stall and clear sl@0: err = iTestPipeInterface1BulkIn.ClearRemoteStall(); sl@0: if(err != KErrNone) sl@0: { sl@0: msg.Format(_L(" The remote stall cannot be cleared"),err); sl@0: break; //switch(iCaseStep) sl@0: } sl@0: iCaseStep = ETransferIn; sl@0: TEndpointPatternSynchronousWriteRequest request(1,1, KLiteralEnglish8().Mid(0,KDeviceNumWriteBytesPostHalt), KDeviceNumWriteBytesPostHalt);// EP1 because 1st writter EP sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: } sl@0: break; //switch(iCaseStep) sl@0: sl@0: case ETransferIn: sl@0: { sl@0: if(aCompletionCode != KErrNone) sl@0: { sl@0: iInTransfer[0]->Cancel(); sl@0: iInTransfer[1]->Cancel(); sl@0: err = KErrCorrupt; sl@0: sl@0: msg.Format(_L(" No data sent on bulk IN request"),aCompletionCode); sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: switch(aTransferId) sl@0: { sl@0: case KBulkTransferInId0: sl@0: case KBulkTransferInId1: sl@0: iTransferComplete |= aTransferId; sl@0: RDebug::Printf("Transfer %d completed", aTransferId); sl@0: break; //switch(aTransferId) sl@0: sl@0: default: sl@0: iTransferComplete = 0; //reset sl@0: err = KUnexpectedTransferID; sl@0: msg.Format(_L(" Unexpected transfer ID, wanted %d or %d, got %d"), sl@0: err, KBulkTransferInId0, KBulkTransferInId1, aTransferId); sl@0: break; //switch(aTransferId) sl@0: } sl@0: sl@0: if(err==KErrNone && iTransferComplete == (KBulkTransferInId0 | KBulkTransferInId1)) sl@0: { sl@0: // ok, compare data rcvd now sl@0: iTransferComplete = 0; //reset sl@0: TPtrC8 data1(iInTransfer[0]->DataPolled()); sl@0: TPtrC8 data2(iInTransfer[1]->DataPolled()); sl@0: //Validate first transfer for number of bytes requested. sl@0: if(ValidateData(data1, KLiteralEnglish8(), KHostNumReadBytesPostHalt1) == EFalse) sl@0: { sl@0: err = KErrCompletion; //indicates data validation failure sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: //Validate second transfer for the remainder of bytes that the device should have written. sl@0: //NB The number of bytes requested is more than this remainder to accommodate the ZLP. sl@0: if(ValidateData(data2, KLiteralEnglish8(), KHostNumReadBytesPostHalt1, KDeviceNumWriteBytesPostHalt-KHostNumReadBytesPostHalt1) == EFalse) sl@0: { sl@0: err = KErrCompletion; //indicates data validation failure sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: // Comparison is a match sl@0: RDebug::Printf("Comparison for IN transfer is a match"); sl@0: iCaseStep = EPassed; sl@0: TTestCasePassed request; sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: } sl@0: break; //switch(iCaseStep) sl@0: sl@0: default: sl@0: err = KUndefinedStep; sl@0: msg.Format(_L(" Undefined case step %d reached"),KUndefinedStep, iCaseStep); sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: if(err == KErrCompletion) sl@0: //indicates data validation failure sl@0: { sl@0: msg.Format(_L(" Bulk transfer IN data received does not match Bulk Transfer OUT data"), err); sl@0: } sl@0: sl@0: if(err!=KErrNone) sl@0: { sl@0: RDebug::Print(msg); sl@0: iCaseStep = EFailed; sl@0: TTestCaseFailed request(err,msg); sl@0: return iControlEp0->SendRequest(request,this); sl@0: } sl@0: } sl@0: sl@0: void CUT_PBASE_T_USBDI_0500::DeviceInsertedL(TUint aDeviceHandle) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: Cancel(); sl@0: RDebug::Printf("this - %08x", this); sl@0: sl@0: TBuf<256> msg; sl@0: TInt err = KErrNone; sl@0: if(BaseBulkDeviceInsertedL(aDeviceHandle, EFalse) == EDeviceConfigurationError) sl@0: // Prepare for response from control transfer to client sl@0: { sl@0: err = KErrGeneral; sl@0: msg.Format(_L("Base class DeviceInsertedL failed")); sl@0: } sl@0: else sl@0: { sl@0: iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxINTransferSize,*this,KBulkTransferInId0); sl@0: iInTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxINTransferSize,*this,KBulkTransferInId1); sl@0: sl@0: // Initialise the descriptors for transfer sl@0: RDebug::Printf("Initialising the transfer descriptors"); sl@0: err = iUsbInterface1.InitialiseTransferDescriptors(); sl@0: if(err != KErrNone) sl@0: { sl@0: msg.Format(_L(" Unable to initialise transfer descriptors"),err); sl@0: } sl@0: } sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Print(msg); sl@0: iCaseStep = EFailed; sl@0: TTestCaseFailed request(err,msg); sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: else sl@0: { sl@0: RDebug::Printf("Asking client for 'Write' and 'Halt'"); sl@0: iCaseStep = ETransferInHalt; sl@0: TEndpointPatternSynchronousWriteAndHaltRequest request(1,1,KLiteralFrench4(),KDeviceNumWriteBytesPreHalt);// EP1 means endpoint index 1 not the actual endpoint number sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: } sl@0: sl@0: } //end namespace