os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0478.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-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-0478.cpp
    15 // @internalComponent
    16 // 
    17 //
    18 
    19 #include "PBASE-T_USBDI-0478.h"
    20 #include "testpolicy.h"
    21 #include "modelleddevices.h"
    22 
    23 
    24 namespace NUnitTesting_USBDI
    25 	{
    26 	
    27 _LIT(KTestCaseId,"PBASE-T_USBDI-0478");
    28 const TFunctorTestCase<CUT_PBASE_T_USBDI_0478,TBool> CUT_PBASE_T_USBDI_0478::iFunctor(KTestCaseId);	
    29 
    30 CUT_PBASE_T_USBDI_0478* CUT_PBASE_T_USBDI_0478::NewL(TBool aHostRole)
    31 	{
    32 	CUT_PBASE_T_USBDI_0478* self = new (ELeave) CUT_PBASE_T_USBDI_0478(aHostRole);
    33 	CleanupStack::PushL(self);
    34 	self->ConstructL();
    35 	CleanupStack::Pop(self);
    36 	return self;
    37 	}
    38 	
    39 
    40 CUT_PBASE_T_USBDI_0478::CUT_PBASE_T_USBDI_0478(TBool aHostRole)
    41 :	CBaseTestCase(KTestCaseId,aHostRole),
    42 	iCaseStep(EInProgress)
    43 	{
    44 	} 
    45 
    46 
    47 void CUT_PBASE_T_USBDI_0478::ConstructL()
    48 	{
    49 	iTestDevice = new RUsbDeviceA(this);
    50 	BaseConstructL();
    51 	}
    52 
    53 
    54 CUT_PBASE_T_USBDI_0478::~CUT_PBASE_T_USBDI_0478()
    55 	{
    56 	LOG_FUNC
    57 	
    58 	Cancel();
    59 
    60 	// Close the interfaces
    61 	
    62 	iDuplicateUsbInterface1.Close();
    63 	iUsbInterface1.Close();
    64 	iUsbInterface0.Close();
    65 	
    66 	delete iControlEp0;
    67 	delete iActorFDF;
    68 	if(!IsHost() && iTestDevice)
    69 		{
    70 		iTestDevice->Close();
    71 		}		
    72 	delete iTestDevice;
    73 	}
    74 	
    75 void CUT_PBASE_T_USBDI_0478::ExecuteHostTestCaseL()	
    76 	{
    77 	LOG_FUNC
    78 
    79 	// Create the actor for the Function Driver Framework 
    80 	
    81 	iActorFDF = CActorFDF::NewL(*this);
    82 
    83 	// Create the control transfer for requests
    84 
    85 	iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
    86 	
    87 	// Monitor for devices
    88 
    89 	iActorFDF->Monitor();
    90 	
    91 	// Start the connection timeout timer
    92 
    93 	TimeoutIn(30);
    94 	}
    95 	
    96 void CUT_PBASE_T_USBDI_0478::HostDoCancel()
    97 	{
    98 	LOG_FUNC
    99 
   100 	// Cancel the timeout timer for activity
   101 
   102 	CancelTimeout();
   103 	}
   104 	
   105 	
   106 void CUT_PBASE_T_USBDI_0478::ExecuteDeviceTestCaseL()	
   107 	{
   108 	LOG_FUNC
   109 
   110 	// Create the test device for this test case
   111 
   112 	iTestDevice->OpenL(TestCaseId());
   113 	iTestDevice->SubscribeToReports(iStatus);
   114 	SetActive();
   115 
   116 	// Connect the test device to the host
   117 
   118 	iTestDevice->SoftwareConnect();
   119 	}
   120 	
   121 void CUT_PBASE_T_USBDI_0478::DeviceDoCancel()
   122 	{
   123 	LOG_FUNC
   124 
   125 	// Cancel the test device
   126 	
   127 	iTestDevice->CancelSubscriptionToReports();
   128 	}
   129 	
   130 	
   131 void CUT_PBASE_T_USBDI_0478::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
   132 	RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
   133 	{
   134 	LOG_FUNC
   135 
   136 	Cancel();
   137 	}
   138 	
   139 	
   140 void CUT_PBASE_T_USBDI_0478::DeviceInsertedL(TUint aDeviceHandle)
   141 	{
   142 	LOG_FUNC
   143 
   144 	Cancel();
   145 	TInt err(KErrNone);
   146 	
   147 	// Validate that device is as expected
   148 	CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
   149 	if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
   150 		{
   151 		// Incorrect device for this test case	
   152 
   153 		RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
   154 			KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
   155 
   156 		// Start the connection timeout again
   157 
   158 		TimeoutIn(30);
   159 		return;
   160 		}
   161 	
   162 	TUint32 token0,token1;
   163 	err = testDevice.Device().GetTokenForInterface(0,token0);
   164 	if(err != KErrNone)
   165 		{
   166 		RDebug::Printf("<Error %d> Token for interface 0 could not be retrieved",err);
   167 		return TestFailed(err);
   168 		}
   169 	err = iUsbInterface0.Open(token0); // Default interface setting 0
   170 	if(err != KErrNone)
   171 		{
   172 		RDebug::Printf("<Error %d> Unable to open interface 0 using token %d",err,token0);
   173 		return TestFailed(err);
   174 		}
   175 
   176 	err = testDevice.Device().GetTokenForInterface(1,token1);
   177 	if(err != KErrNone)
   178 		{
   179 		RDebug::Printf("<Error %d> Token for interface 1 could not be retrieved",err);
   180 		return TestFailed(err);
   181 		}
   182 
   183 	err = iUsbInterface1.Open(token1);
   184 	if(err != KErrNone)
   185 		{
   186 		RDebug::Printf("<Error %d> Unable to open interface using token %d",err,token1);
   187 		return TestFailed(err);
   188 		}
   189 
   190 	// Acting as another FD open the interface
   191 	
   192 	err = iDuplicateUsbInterface1.Open(token1);
   193 	if(err == KErrNone)
   194 		{
   195 		TBuf<64> msg;
   196 		msg.Format(_L("<Error> Able to open a concurrent hande to an interface"));
   197 		RDebug::Print(msg);
   198 		iCaseStep = EFailed;
   199 		TTestCaseFailed request(KErrCompletion,msg);
   200 		iControlEp0->SendRequest(request,this);
   201 		return;
   202 		}
   203 	RDebug::Printf("Attempt to open concurrent interface handle failed with: %d",err);
   204 	
   205 	// Inform client device test case successful 
   206 	User::After(1000000);
   207 	iCaseStep = EPassed;
   208 	TTestCasePassed request;
   209 	iControlEp0->SendRequest(request,this);
   210 	}
   211 	
   212 	
   213 void CUT_PBASE_T_USBDI_0478::Ep0TransferCompleteL(TInt aCompletionCode)
   214 	{
   215 	LOG_FUNC
   216 	
   217 	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
   218 	
   219 	if(aCompletionCode != KErrNone)
   220 		{	
   221 		TBuf<256> msg;
   222 		msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
   223 		RDebug::Print(msg);
   224 		}
   225 
   226 	if(iCaseStep == EPassed)
   227 		{	
   228 		if(aCompletionCode == KErrNone)
   229 			{
   230 			return TestPassed();
   231 			}
   232 		// else error
   233 	    iCaseStep = EFailed;
   234 		}
   235 	
   236 	if(iCaseStep == EFailed)
   237 		{
   238 		return TestFailed(KErrCompletion);
   239 		}
   240 	}
   241 	
   242 	
   243 void CUT_PBASE_T_USBDI_0478::DeviceRemovedL(TUint aDeviceHandle)
   244 	{
   245 	LOG_FUNC
   246 
   247 	// The test device should not be removed until the test case has passed
   248 	// so this test case has not completed, and state this event as an error
   249 
   250 	TestFailed(KErrDisconnected);
   251 	}
   252 	
   253 	
   254 void CUT_PBASE_T_USBDI_0478::BusErrorL(TInt aError)
   255 	{
   256 	LOG_FUNC
   257 
   258 	// This test case handles no failiures on the bus
   259 	
   260 	TestFailed(aError);	
   261 	}
   262 
   263 void CUT_PBASE_T_USBDI_0478::HostRunL()
   264 	{
   265 	LOG_FUNC
   266 
   267 	// Obtain the completion code
   268 	TInt completionCode(iStatus.Int());
   269 	
   270 	if(completionCode == KErrNone)
   271 		{
   272 		// Action timeout
   273 		RDebug::Printf("<Error> Action timeout");
   274 		TestFailed(KErrTimedOut);
   275 		}
   276 	else
   277 		{
   278 		RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
   279 		TestFailed(completionCode);
   280 		}
   281 	}
   282 
   283 void CUT_PBASE_T_USBDI_0478::DeviceRunL()
   284 	{
   285 	LOG_FUNC
   286 	
   287 	// Disconnect the device
   288 	
   289 	iTestDevice->SoftwareDisconnect();
   290 	
   291 	// Complete the test case request
   292 	
   293 	TestPolicy().SignalTestComplete(iStatus.Int());
   294 	}
   295 
   296 	
   297 	}