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-0478.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,297 @@
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-0478.cpp
1.18 +// @internalComponent
1.19 +//
1.20 +//
1.21 +
1.22 +#include "PBASE-T_USBDI-0478.h"
1.23 +#include "testpolicy.h"
1.24 +#include "modelleddevices.h"
1.25 +
1.26 +
1.27 +namespace NUnitTesting_USBDI
1.28 + {
1.29 +
1.30 +_LIT(KTestCaseId,"PBASE-T_USBDI-0478");
1.31 +const TFunctorTestCase<CUT_PBASE_T_USBDI_0478,TBool> CUT_PBASE_T_USBDI_0478::iFunctor(KTestCaseId);
1.32 +
1.33 +CUT_PBASE_T_USBDI_0478* CUT_PBASE_T_USBDI_0478::NewL(TBool aHostRole)
1.34 + {
1.35 + CUT_PBASE_T_USBDI_0478* self = new (ELeave) CUT_PBASE_T_USBDI_0478(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_0478::CUT_PBASE_T_USBDI_0478(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_0478::ConstructL()
1.51 + {
1.52 + iTestDevice = new RUsbDeviceA(this);
1.53 + BaseConstructL();
1.54 + }
1.55 +
1.56 +
1.57 +CUT_PBASE_T_USBDI_0478::~CUT_PBASE_T_USBDI_0478()
1.58 + {
1.59 + LOG_FUNC
1.60 +
1.61 + Cancel();
1.62 +
1.63 + // Close the interfaces
1.64 +
1.65 + iDuplicateUsbInterface1.Close();
1.66 + iUsbInterface1.Close();
1.67 + iUsbInterface0.Close();
1.68 +
1.69 + delete iControlEp0;
1.70 + delete iActorFDF;
1.71 + if(!IsHost() && iTestDevice)
1.72 + {
1.73 + iTestDevice->Close();
1.74 + }
1.75 + delete iTestDevice;
1.76 + }
1.77 +
1.78 +void CUT_PBASE_T_USBDI_0478::ExecuteHostTestCaseL()
1.79 + {
1.80 + LOG_FUNC
1.81 +
1.82 + // Create the actor for the Function Driver Framework
1.83 +
1.84 + iActorFDF = CActorFDF::NewL(*this);
1.85 +
1.86 + // Create the control transfer for requests
1.87 +
1.88 + iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
1.89 +
1.90 + // Monitor for devices
1.91 +
1.92 + iActorFDF->Monitor();
1.93 +
1.94 + // Start the connection timeout timer
1.95 +
1.96 + TimeoutIn(30);
1.97 + }
1.98 +
1.99 +void CUT_PBASE_T_USBDI_0478::HostDoCancel()
1.100 + {
1.101 + LOG_FUNC
1.102 +
1.103 + // Cancel the timeout timer for activity
1.104 +
1.105 + CancelTimeout();
1.106 + }
1.107 +
1.108 +
1.109 +void CUT_PBASE_T_USBDI_0478::ExecuteDeviceTestCaseL()
1.110 + {
1.111 + LOG_FUNC
1.112 +
1.113 + // Create the test device for this test case
1.114 +
1.115 + iTestDevice->OpenL(TestCaseId());
1.116 + iTestDevice->SubscribeToReports(iStatus);
1.117 + SetActive();
1.118 +
1.119 + // Connect the test device to the host
1.120 +
1.121 + iTestDevice->SoftwareConnect();
1.122 + }
1.123 +
1.124 +void CUT_PBASE_T_USBDI_0478::DeviceDoCancel()
1.125 + {
1.126 + LOG_FUNC
1.127 +
1.128 + // Cancel the test device
1.129 +
1.130 + iTestDevice->CancelSubscriptionToReports();
1.131 + }
1.132 +
1.133 +
1.134 +void CUT_PBASE_T_USBDI_0478::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
1.135 + RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
1.136 + {
1.137 + LOG_FUNC
1.138 +
1.139 + Cancel();
1.140 + }
1.141 +
1.142 +
1.143 +void CUT_PBASE_T_USBDI_0478::DeviceInsertedL(TUint aDeviceHandle)
1.144 + {
1.145 + LOG_FUNC
1.146 +
1.147 + Cancel();
1.148 + TInt err(KErrNone);
1.149 +
1.150 + // Validate that device is as expected
1.151 + CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
1.152 + if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
1.153 + {
1.154 + // Incorrect device for this test case
1.155 +
1.156 + RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
1.157 + KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
1.158 +
1.159 + // Start the connection timeout again
1.160 +
1.161 + TimeoutIn(30);
1.162 + return;
1.163 + }
1.164 +
1.165 + TUint32 token0,token1;
1.166 + err = testDevice.Device().GetTokenForInterface(0,token0);
1.167 + if(err != KErrNone)
1.168 + {
1.169 + RDebug::Printf("<Error %d> Token for interface 0 could not be retrieved",err);
1.170 + return TestFailed(err);
1.171 + }
1.172 + err = iUsbInterface0.Open(token0); // Default interface setting 0
1.173 + if(err != KErrNone)
1.174 + {
1.175 + RDebug::Printf("<Error %d> Unable to open interface 0 using token %d",err,token0);
1.176 + return TestFailed(err);
1.177 + }
1.178 +
1.179 + err = testDevice.Device().GetTokenForInterface(1,token1);
1.180 + if(err != KErrNone)
1.181 + {
1.182 + RDebug::Printf("<Error %d> Token for interface 1 could not be retrieved",err);
1.183 + return TestFailed(err);
1.184 + }
1.185 +
1.186 + err = iUsbInterface1.Open(token1);
1.187 + if(err != KErrNone)
1.188 + {
1.189 + RDebug::Printf("<Error %d> Unable to open interface using token %d",err,token1);
1.190 + return TestFailed(err);
1.191 + }
1.192 +
1.193 + // Acting as another FD open the interface
1.194 +
1.195 + err = iDuplicateUsbInterface1.Open(token1);
1.196 + if(err == KErrNone)
1.197 + {
1.198 + TBuf<64> msg;
1.199 + msg.Format(_L("<Error> Able to open a concurrent hande to an interface"));
1.200 + RDebug::Print(msg);
1.201 + iCaseStep = EFailed;
1.202 + TTestCaseFailed request(KErrCompletion,msg);
1.203 + iControlEp0->SendRequest(request,this);
1.204 + return;
1.205 + }
1.206 + RDebug::Printf("Attempt to open concurrent interface handle failed with: %d",err);
1.207 +
1.208 + // Inform client device test case successful
1.209 + User::After(1000000);
1.210 + iCaseStep = EPassed;
1.211 + TTestCasePassed request;
1.212 + iControlEp0->SendRequest(request,this);
1.213 + }
1.214 +
1.215 +
1.216 +void CUT_PBASE_T_USBDI_0478::Ep0TransferCompleteL(TInt aCompletionCode)
1.217 + {
1.218 + LOG_FUNC
1.219 +
1.220 + RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
1.221 +
1.222 + if(aCompletionCode != KErrNone)
1.223 + {
1.224 + TBuf<256> msg;
1.225 + msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
1.226 + RDebug::Print(msg);
1.227 + }
1.228 +
1.229 + if(iCaseStep == EPassed)
1.230 + {
1.231 + if(aCompletionCode == KErrNone)
1.232 + {
1.233 + return TestPassed();
1.234 + }
1.235 + // else error
1.236 + iCaseStep = EFailed;
1.237 + }
1.238 +
1.239 + if(iCaseStep == EFailed)
1.240 + {
1.241 + return TestFailed(KErrCompletion);
1.242 + }
1.243 + }
1.244 +
1.245 +
1.246 +void CUT_PBASE_T_USBDI_0478::DeviceRemovedL(TUint aDeviceHandle)
1.247 + {
1.248 + LOG_FUNC
1.249 +
1.250 + // The test device should not be removed until the test case has passed
1.251 + // so this test case has not completed, and state this event as an error
1.252 +
1.253 + TestFailed(KErrDisconnected);
1.254 + }
1.255 +
1.256 +
1.257 +void CUT_PBASE_T_USBDI_0478::BusErrorL(TInt aError)
1.258 + {
1.259 + LOG_FUNC
1.260 +
1.261 + // This test case handles no failiures on the bus
1.262 +
1.263 + TestFailed(aError);
1.264 + }
1.265 +
1.266 +void CUT_PBASE_T_USBDI_0478::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 +void CUT_PBASE_T_USBDI_0478::DeviceRunL()
1.287 + {
1.288 + LOG_FUNC
1.289 +
1.290 + // Disconnect the device
1.291 +
1.292 + iTestDevice->SoftwareDisconnect();
1.293 +
1.294 + // Complete the test case request
1.295 +
1.296 + TestPolicy().SignalTestComplete(iStatus.Int());
1.297 + }
1.298 +
1.299 +
1.300 + }