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