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