os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0485.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0485.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,301 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// @file PBASE-T_USBDI-0485.cpp
    1.18 +// @internalComponent
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#include "PBASE-T_USBDI-0485.h"
    1.23 +#include "testpolicy.h"
    1.24 +#include "testdebug.h"
    1.25 +#include "modelleddevices.h"
    1.26 +
    1.27 +namespace NUnitTesting_USBDI
    1.28 +	{
    1.29 +	
    1.30 +_LIT(KTestCaseId,"PBASE-T_USBDI-0485");
    1.31 +const TFunctorTestCase<CUT_PBASE_T_USBDI_0485,TBool> CUT_PBASE_T_USBDI_0485::iFunctor(KTestCaseId);	
    1.32 +
    1.33 +CUT_PBASE_T_USBDI_0485* CUT_PBASE_T_USBDI_0485::NewL(TBool aHostRole)
    1.34 +	{
    1.35 +	CUT_PBASE_T_USBDI_0485* self = new (ELeave) CUT_PBASE_T_USBDI_0485(aHostRole);
    1.36 +	CleanupStack::PushL(self);
    1.37 +	self->ConstructL();
    1.38 +	CleanupStack::Pop(self);
    1.39 +	return self;
    1.40 +	} 
    1.41 +	
    1.42 +
    1.43 +CUT_PBASE_T_USBDI_0485::CUT_PBASE_T_USBDI_0485(TBool aHostRole)
    1.44 +:	CBaseTestCase(KTestCaseId,aHostRole),
    1.45 +	iCaseStep(EInProgress)
    1.46 +	{
    1.47 +	} 
    1.48 +
    1.49 +
    1.50 +void CUT_PBASE_T_USBDI_0485::ConstructL()
    1.51 +	{
    1.52 +	iTestDevice = new RUsbDeviceVendor(this);
    1.53 +	BaseConstructL();
    1.54 +	}
    1.55 +
    1.56 +
    1.57 +CUT_PBASE_T_USBDI_0485::~CUT_PBASE_T_USBDI_0485()
    1.58 +	{
    1.59 +	LOG_FUNC
    1.60 +	
    1.61 +	Cancel();
    1.62 +	
    1.63 +	// Close the interface
    1.64 +	iUsbInterface0.Close();
    1.65 +	
    1.66 +	delete iControlEp0;
    1.67 +	delete iActorFDF;
    1.68 +	if(!IsHost() && iTestDevice)
    1.69 +		{
    1.70 +		iTestDevice->Close();
    1.71 +		}		
    1.72 +	delete iTestDevice;
    1.73 +	}
    1.74 +	
    1.75 +void CUT_PBASE_T_USBDI_0485::ExecuteHostTestCaseL()	
    1.76 +	{
    1.77 +	LOG_FUNC
    1.78 +
    1.79 +	// Create the actor for the Function Driver Framework 
    1.80 +	
    1.81 +	iActorFDF = CActorFDF::NewL(*this);
    1.82 +
    1.83 +	// Create the control transfer for requests
    1.84 +
    1.85 +	iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
    1.86 +	
    1.87 +	// Monitor for devices
    1.88 +
    1.89 +	iActorFDF->Monitor();
    1.90 +	
    1.91 +	// Start the connection timeout timer
    1.92 +
    1.93 +	TimeoutIn(30);
    1.94 +	}
    1.95 +
    1.96 +
    1.97 +void CUT_PBASE_T_USBDI_0485::ExecuteDeviceTestCaseL()	
    1.98 +	{
    1.99 +	LOG_FUNC
   1.100 +	
   1.101 +	// Create the test device
   1.102 +	
   1.103 +	iTestDevice->OpenL(TestCaseId());
   1.104 +	iTestDevice->SubscribeToReports(iStatus);
   1.105 +	SetActive();
   1.106 +	
   1.107 +	// Connect the device to the host
   1.108 +	
   1.109 +	iTestDevice->SoftwareConnect();
   1.110 +	}
   1.111 +
   1.112 +
   1.113 +void CUT_PBASE_T_USBDI_0485::HostDoCancel()
   1.114 +	{
   1.115 +	LOG_FUNC
   1.116 +	
   1.117 +	// Cancel the test step action timeout timer
   1.118 +	
   1.119 +	CancelTimeout();
   1.120 +	}
   1.121 +
   1.122 +	
   1.123 +void CUT_PBASE_T_USBDI_0485::DeviceDoCancel()
   1.124 +	{
   1.125 +	LOG_FUNC
   1.126 +	
   1.127 +	// Cancel the device (the activity timer and the error reporting)
   1.128 +	
   1.129 +	iTestDevice->CancelSubscriptionToReports();
   1.130 +	}
   1.131 +	
   1.132 +	
   1.133 +void CUT_PBASE_T_USBDI_0485::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
   1.134 +		RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
   1.135 +	{
   1.136 +	LOG_FUNC
   1.137 +	
   1.138 +	}
   1.139 +	
   1.140 +	
   1.141 +void CUT_PBASE_T_USBDI_0485::DeviceInsertedL(TUint aDeviceHandle)
   1.142 +	{
   1.143 +	LOG_FUNC
   1.144 +
   1.145 +	// Cancel the timeout timer
   1.146 +	
   1.147 +	Cancel();
   1.148 +	
   1.149 +	TInt err(KErrNone);
   1.150 +	
   1.151 +	// Validate that device is as expected
   1.152 +	
   1.153 +	CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
   1.154 +	if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
   1.155 +		{
   1.156 +		// Incorrect device for this test case	
   1.157 +
   1.158 +		RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
   1.159 +			KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
   1.160 +
   1.161 +		// Start the connection timeout again
   1.162 +
   1.163 +		TimeoutIn(30);
   1.164 +		return;
   1.165 +		}	
   1.166 +	
   1.167 +	// Get the token for the interface
   1.168 +	
   1.169 +	err = testDevice.Device().GetTokenForInterface(0,iToken0);
   1.170 +	if(err != KErrNone)
   1.171 +		{
   1.172 +		RDebug::Printf("<Error %d> Unable to retrieve token for interface 0",err);
   1.173 +		TestFailed(err);
   1.174 +		}
   1.175 +	
   1.176 +	// Open the interface	
   1.177 +	err = iUsbInterface0.Open(iToken0);
   1.178 +	if(err != KErrNone)
   1.179 +		{
   1.180 +		RDebug::Printf("<Error %d> Unable to open interface 0");
   1.181 +		TestFailed(err);
   1.182 +		}
   1.183 +	
   1.184 +
   1.185 +	// Send a request to control endpoint 0 to continuously NAK the request
   1.186 +	
   1.187 +	iCaseStep = EInProgress;
   1.188 +	TNakRequest request(0);
   1.189 +	iControlEp0->SendRequest(request,this);
   1.190 +	
   1.191 +	// Wait 1 second then close the interface	
   1.192 +	User::After(1000000);
   1.193 +	RDebug::Printf("Closing interface 0");
   1.194 +	iUsbInterface0.Close();
   1.195 +	}
   1.196 +	
   1.197 +void CUT_PBASE_T_USBDI_0485::Ep0TransferCompleteL(TInt aCompletionCode)
   1.198 +	{
   1.199 +	LOG_FUNC
   1.200 +	
   1.201 +	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
   1.202 +		
   1.203 +	switch(iCaseStep)
   1.204 +		{
   1.205 +		case EInProgress:
   1.206 +			{
   1.207 +			if(aCompletionCode != KErrCancel)
   1.208 +				{
   1.209 +				RDebug::Printf("<Error %d> Nakking request was not cancelled by stack",aCompletionCode);
   1.210 +				return TestFailed(aCompletionCode);
   1.211 +				}
   1.212 +		
   1.213 +			// No panic or leave so passed
   1.214 +			
   1.215 +			RDebug::Printf("No leave or panic occured so open interface again and send test passed");
   1.216 +			
   1.217 +			// Open the interface
   1.218 +			
   1.219 +			TInt err(iUsbInterface0.Open(iToken0));
   1.220 +			if(err != KErrNone)
   1.221 +				{
   1.222 +				RDebug::Printf("<Error %d> Unable to open interface 0");
   1.223 +				return TestFailed(err);
   1.224 +				}
   1.225 +			
   1.226 +			RDebug::Printf("Interface 0 re-opened");
   1.227 +			
   1.228 +			iCaseStep = EPassed;
   1.229 +			TTestCasePassed request;
   1.230 +			iControlEp0->SendRequest(request,this);			
   1.231 +			}
   1.232 +			break;
   1.233 +			
   1.234 +		case EPassed:
   1.235 +			TestPassed();
   1.236 +			break;
   1.237 +			
   1.238 +		case EFailed:
   1.239 +		default:
   1.240 +			TestFailed(KErrCompletion);
   1.241 +			break;
   1.242 +		}
   1.243 +	}
   1.244 +	
   1.245 +void CUT_PBASE_T_USBDI_0485::DeviceRemovedL(TUint aDeviceHandle)
   1.246 +	{
   1.247 +	LOG_FUNC
   1.248 +
   1.249 +	// The test device should not be removed until the test case has passed
   1.250 +	// so this test case has not completed, and state this event as an error
   1.251 +
   1.252 +	TestFailed(KErrDisconnected);
   1.253 +	}
   1.254 +	
   1.255 +	
   1.256 +void CUT_PBASE_T_USBDI_0485::BusErrorL(TInt aError)
   1.257 +	{
   1.258 +	LOG_FUNC
   1.259 +
   1.260 +	// This test case handles no failiures on the bus
   1.261 +
   1.262 +	TestFailed(aError);
   1.263 +	}
   1.264 +
   1.265 +
   1.266 +void CUT_PBASE_T_USBDI_0485::HostRunL()
   1.267 +	{
   1.268 +	LOG_FUNC
   1.269 +	
   1.270 +	// Obtain the completion code
   1.271 +	TInt completionCode(iStatus.Int());
   1.272 +	
   1.273 +	if(completionCode == KErrNone)
   1.274 +		{
   1.275 +		// Action timeout
   1.276 +		RDebug::Printf("<Error> Action timeout");
   1.277 +		TestFailed(KErrTimedOut);
   1.278 +		}
   1.279 +	else
   1.280 +		{
   1.281 +		RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
   1.282 +		TestFailed(completionCode);
   1.283 +		}
   1.284 +	}
   1.285 +
   1.286 +/**
   1.287 +Called when the device has reported any kind of error in its opertaion
   1.288 +or when the device has been informed by the host to report success
   1.289 +*/
   1.290 +void CUT_PBASE_T_USBDI_0485::DeviceRunL()
   1.291 +	{
   1.292 +	LOG_FUNC
   1.293 +	
   1.294 +	// Disconnect the device
   1.295 +	
   1.296 +	iTestDevice->SoftwareDisconnect();
   1.297 +	
   1.298 +	// Complete the test case request
   1.299 +	
   1.300 +	TestPolicy().SignalTestComplete(iStatus.Int());
   1.301 +	}
   1.302 +
   1.303 +	
   1.304 +	}