os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0472.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-0472.cpp
    15 // @internalComponent
    16 // 
    17 //
    18 
    19 #include "PBASE-T_USBDI-0472.h"
    20 #include <e32test.h>
    21 #include <d32usbc.h>
    22 #include <e32debug.h>
    23 #include "UsbDescriptorOffsets.h"
    24 #include "TestPolicy.h"
    25 
    26 namespace NUnitTesting_USBDI
    27 	{
    28 	
    29 _LIT(KTestCaseId,"PBASE-T_USBDI-0472");
    30 const TFunctorTestCase<CUT_PBASE_T_USBDI_0472,TBool> CUT_PBASE_T_USBDI_0472::iFunctor(KTestCaseId);	
    31 
    32 CUT_PBASE_T_USBDI_0472* CUT_PBASE_T_USBDI_0472::NewL(TBool aHostRole)
    33 	{
    34 	CUT_PBASE_T_USBDI_0472* self = new (ELeave) CUT_PBASE_T_USBDI_0472(aHostRole);
    35 	CleanupStack::PushL(self);
    36 	self->ConstructL();
    37 	CleanupStack::Pop(self);
    38 	return self;
    39 	}
    40 	
    41 
    42 CUT_PBASE_T_USBDI_0472::CUT_PBASE_T_USBDI_0472(TBool aHostRole)
    43 :	CBaseTestCase(KTestCaseId,aHostRole)
    44 	{
    45 	} 
    46 
    47 
    48 void CUT_PBASE_T_USBDI_0472::ConstructL()
    49 	{
    50 	iTestDevice = new RUsbDeviceVendor(this);
    51 	BaseConstructL();
    52 	}
    53 
    54 
    55 CUT_PBASE_T_USBDI_0472::~CUT_PBASE_T_USBDI_0472()
    56 	{
    57 	LOG_FUNC
    58 	Cancel();
    59 
    60 	delete iClientAction;
    61 	delete iActorFDF;
    62 	if(!IsHost() && iTestDevice)
    63 		{
    64 		iTestDevice->Close();
    65 		}		
    66 	delete iTestDevice;
    67 	}
    68 
    69 
    70 void CUT_PBASE_T_USBDI_0472::ExecuteHostTestCaseL()
    71 	{
    72 	LOG_FUNC
    73 	iActorFDF = CActorFDF::NewL(*this);
    74 	iClientAction = new (ELeave) CEp0Transfer(iInterface0);
    75 	iCaseStep = EConnectDevice;
    76 	iActorFDF->Monitor();
    77 	TimeoutIn(30);
    78 	}
    79 
    80 void CUT_PBASE_T_USBDI_0472::ExecuteDeviceTestCaseL()
    81 	{
    82 	LOG_FUNC
    83 	
    84 	iTestDevice->OpenL(TestCaseId());
    85 	iTestDevice->SubscribeToReports(iStatus);	
    86 	SetActive();
    87 	iTestDevice->SoftwareConnect();
    88 	}
    89 	
    90 void CUT_PBASE_T_USBDI_0472::HostDoCancel()
    91 	{
    92 	LOG_FUNC
    93 	
    94 	// Cancel the test step action timeout timer
    95 	
    96 	CancelTimeout();
    97 	}
    98 
    99 
   100 void CUT_PBASE_T_USBDI_0472::DeviceDoCancel()
   101 	{
   102 	LOG_FUNC
   103 	
   104 	// Cancel the test device
   105 	
   106 	iTestDevice->CancelSubscriptionToReports();
   107 	}
   108 	
   109 	
   110 void CUT_PBASE_T_USBDI_0472::DeviceInsertedL(TUint aDeviceHandle)
   111 	{
   112 	LOG_FUNC
   113 
   114 	Cancel();
   115 	TInt err(KErrNone);
   116 	
   117 	// Validate that device is as expected
   118 	
   119 	CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
   120 	if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
   121 		{
   122 		// Incorrect device for this test case	
   123 
   124 		RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
   125 			KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
   126 
   127 		// Start the connection timeout again
   128 
   129 		TimeoutIn(30);
   130 		return;
   131 		}	
   132 		
   133 	// Perform the correct test step
   134 		
   135 	switch(iCaseStep)
   136 		{
   137 		case EConnectDevice:
   138 			{
   139 			// Validate vendor identity
   140 			RDebug::Printf("Vendor identity: 0x%04x",testDevice.VendorId());
   141 			if(testDevice.VendorId() != 0x0E22)
   142 				{
   143 				RDebug::Printf("<Error> Vendor identity is not 0x0E22");
   144 				return TestFailed(KErrCorrupt);
   145 				}
   146 				
   147 			// Validate product information
   148 			RDebug::Printf("Usb device supported specification: 0x%04x",testDevice.DeviceSpec());
   149 			if(testDevice.DeviceSpec() != 0x0200)
   150 				{
   151 				RDebug::Printf("<Error> Usb device supported specification is not 2.0");
   152 				return TestFailed(KErrCorrupt);
   153 				}
   154 			RDebug::Printf("Usb product identity: 0x%04x",testDevice.ProductId());
   155 			if(testDevice.ProductId() != 0x0040)
   156 				{
   157 				RDebug::Printf("<Error> Usb product idenity is not 0x0040");
   158 				return TestFailed(KErrCorrupt);
   159 				}
   160 		
   161 			RDebug::Printf("testDevice.ConfigurationString() = %S",&testDevice.ConfigurationString());		
   162 			gtest(KErrNone == testDevice.ConfigurationString().Compare(KConfigurationString()));		
   163 					
   164 			RDebug::Printf("testDevice.Manufacturer() = %S",&testDevice.Manufacturer());
   165 			gtest(KErrNone == testDevice.Manufacturer().Compare(KManufacturer()));
   166 			
   167 			RDebug::Printf("testDevice.SerialNumber = %s",&testDevice.SerialNumber());	
   168 			gtest(KErrNone == testDevice.SerialNumber().Compare(KTestCaseId()));
   169 		
   170 			RDebug::Printf("Waiting for device removal");
   171 			iCaseStep = ERemoveDevice;
   172 			
   173 			TUint32 token;
   174 			err = testDevice.Device().GetTokenForInterface(0,token);
   175 			if(err != KErrNone)
   176 				{
   177 				RDebug::Printf("<Error %d> Unable to get token for interface 0",err);
   178 				return TestFailed(err);
   179 				}
   180 			err = iInterface0.Open(token);
   181 			if(err != KErrNone)
   182 				{
   183 				RDebug::Printf("<Error %d> Unable to open interface 0",err);
   184 				return TestFailed(err);
   185 				}
   186 			
   187 			// Send request to client to reconnect in 3 seconds
   188 			
   189 			TReconnectRequest request(3);
   190 			iClientAction->SendRequest(request,this);
   191 			
   192 			// Monitor for the reconnection from the client
   193 			
   194 			iActorFDF->Monitor();
   195 			TimeoutIn(30);
   196 			}
   197 			break;
   198 			
   199 		case EConnectCancelled:
   200 			RDebug::Printf("<Error> Bus event cancellation not successful");
   201 			TestFailed(KErrCorrupt);
   202 			break;
   203 			
   204 		case EPassed:	// Test case has been successfully concluded
   205 			{
   206 			TUint32 token;
   207 			err = testDevice.Device().GetTokenForInterface(0,token);
   208 			if(err != KErrNone)
   209 				{
   210 				RDebug::Printf("<Error %d> Unable to get token for interface 0",err);
   211 				return TestFailed(err);
   212 				}
   213 			err = iInterface0.Open(token);
   214 			if(err != KErrNone)
   215 				{
   216 				RDebug::Printf("<Error %d> Unable to open interface 0",err);
   217 				return TestFailed(err);
   218 				}
   219 	
   220 			// Send test case passed request to client
   221 			TTestCasePassed request;
   222 			iClientAction->SendRequest(request,this);
   223 			}
   224 			break;
   225 			
   226 		default:
   227 			RDebug::Printf("<Error> Test case actions out of sync");
   228 			TestFailed(KErrCorrupt);
   229 			break;
   230 		}
   231 	}
   232 
   233 
   234 void CUT_PBASE_T_USBDI_0472::Ep0TransferCompleteL(TInt aCompletionCode)
   235 	{
   236 	LOG_FUNC
   237 	
   238 	switch(iCaseStep)
   239 		{
   240 		case EPassed:
   241 			{
   242 			TestPassed();
   243 			}
   244 			break;
   245 			
   246 		case EFailed:
   247 			{
   248 			TestFailed(KErrCompletion);
   249 			}
   250 			break;
   251 	
   252 		case ERemoveDevice:
   253 			{
   254 			// Doing nothing, client should be re-connecting
   255 			}
   256 			break;
   257 			
   258 		default:
   259 			RDebug::Printf("<Error %d> Unknown test step",KErrCorrupt);
   260 			TestFailed(KErrCorrupt);
   261 			break;
   262 		}
   263 	}
   264 	
   265 	
   266 void CUT_PBASE_T_USBDI_0472::DeviceRemovedL(TUint aDeviceHandle)
   267 	{
   268 	LOG_FUNC
   269 
   270 	Cancel();
   271 	
   272 	switch(iCaseStep)
   273 		{
   274 		case ERemoveDevice:
   275 			{
   276 			iCaseStep = EConnectCancelled;
   277 		
   278 			// start timer now
   279 			TimeoutIn(5);		
   280 			}
   281 			break;
   282 			
   283 		default:
   284 			RDebug::Printf("<Error> Test case actions out of sync");
   285 			TestFailed(KErrCorrupt);
   286 			break;
   287 		}
   288 	}
   289 	
   290 void CUT_PBASE_T_USBDI_0472::BusErrorL(TInt aError)
   291 	{
   292 	// This test case handles no failiures on the bus
   293 
   294 	TestFailed(aError);
   295 	}
   296 
   297 void CUT_PBASE_T_USBDI_0472::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
   298 	RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
   299 	{
   300 	LOG_FUNC
   301 	}
   302 	
   303 void CUT_PBASE_T_USBDI_0472::HostRunL()
   304 	{
   305 	LOG_FUNC
   306 	
   307 	// Obtain the completion code
   308 	TInt completionCode(iStatus.Int());
   309 	
   310 	if(completionCode == KErrNone)
   311 		{		
   312 		if(iCaseStep == EConnectCancelled)
   313 			{
   314 			// not a time-out 
   315 			RDebug::Printf("Timer elapsed, reactivating notifications now");
   316 			iCaseStep = EPassed;			
   317 			iActorFDF->Monitor();
   318 			}
   319 		else
   320 			{
   321 			// Action timeout
   322 			RDebug::Printf("<Error> Action timeout");
   323 			TestFailed(KErrTimedOut);
   324 			}	
   325 		}
   326 	else
   327 		{
   328 		RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
   329 		TestFailed(completionCode);
   330 		}
   331 	}
   332 	
   333 
   334 void CUT_PBASE_T_USBDI_0472::DeviceRunL()
   335 	{
   336 	LOG_FUNC
   337 	
   338 	// Disconnect the device
   339 	
   340 	iTestDevice->SoftwareDisconnect();
   341 	
   342 	// Complete the test case request
   343 	
   344 	TestPolicy().SignalTestComplete(iStatus.Int());
   345 	}	
   346 	
   347 
   348 	}
   349