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