os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0474.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-0474.cpp
    15 // @internalComponent
    16 // 
    17 //
    18 
    19 #include "PBASE-T_USBDI-0474.h"
    20 #include "testpolicy.h"
    21 #include "modelleddevices.h"
    22 
    23 
    24 namespace NUnitTesting_USBDI
    25 	{
    26 	
    27 _LIT(KTestCaseId,"PBASE-T_USBDI-0474");
    28 const TFunctorTestCase<CUT_PBASE_T_USBDI_0474,TBool> CUT_PBASE_T_USBDI_0474::iFunctor(KTestCaseId);	
    29 
    30 CUT_PBASE_T_USBDI_0474* CUT_PBASE_T_USBDI_0474::NewL(TBool aHostRole)
    31 	{
    32 	CUT_PBASE_T_USBDI_0474* self = new (ELeave) CUT_PBASE_T_USBDI_0474(aHostRole);
    33 	CleanupStack::PushL(self);
    34 	self->ConstructL();
    35 	CleanupStack::Pop(self);
    36 	return self;
    37 	}
    38 	
    39 
    40 CUT_PBASE_T_USBDI_0474::CUT_PBASE_T_USBDI_0474(TBool aHostRole)
    41 :	CBaseTestCase(KTestCaseId,aHostRole),
    42 	iCaseStep(EInProgress)
    43 	{
    44 	} 
    45 
    46 
    47 void CUT_PBASE_T_USBDI_0474::ConstructL()
    48 	{
    49 	iTestDevice = new RUsbDeviceB(this);
    50 	BaseConstructL();
    51 	}
    52 
    53 
    54 CUT_PBASE_T_USBDI_0474::~CUT_PBASE_T_USBDI_0474()
    55 	{
    56 	LOG_FUNC
    57 	Cancel();
    58 	
    59 	iUsbInterface0.Close();
    60 
    61 	delete iClientAction;
    62 	delete iActorFDF;
    63 	if(!IsHost() && iTestDevice)
    64 		{
    65 		iTestDevice->Close();
    66 		}		
    67 	delete iTestDevice;
    68 	}
    69 	
    70 	
    71 void CUT_PBASE_T_USBDI_0474::ExecuteHostTestCaseL()
    72 	{
    73 	LOG_FUNC
    74 	
    75 	iActorFDF = CActorFDF::NewL(*this);
    76 	iClientAction = new (ELeave) CEp0Transfer(iUsbInterface0);
    77 	iActorFDF->Monitor();
    78 	TimeoutIn(30);
    79 	}
    80 
    81 	
    82 void CUT_PBASE_T_USBDI_0474::ExecuteDeviceTestCaseL()
    83 	{
    84 	LOG_FUNC
    85 	
    86 	iTestDevice->OpenL(TestCaseId());
    87 	iTestDevice->SubscribeToReports(iStatus);
    88 	SetActive();
    89 	iTestDevice->SoftwareConnect();
    90 	} 
    91 	
    92 	
    93 void CUT_PBASE_T_USBDI_0474::HostDoCancel()
    94 	{
    95 	LOG_FUNC
    96 	
    97 	// Cancel the test step timeout
    98 	
    99 	CancelTimeout();
   100 	}
   101 
   102 
   103 void CUT_PBASE_T_USBDI_0474::DeviceDoCancel()
   104 	{
   105 	LOG_FUNC
   106 	
   107 	// Cancel the device
   108 	
   109 	iTestDevice->CancelSubscriptionToReports();
   110 	}
   111 			
   112 void CUT_PBASE_T_USBDI_0474::DeviceInsertedL(TUint aDeviceHandle)
   113 	{
   114 	LOG_FUNC
   115 	Cancel();
   116 	TInt err(KErrNone); 
   117 	
   118 	// Validate that device is as expected
   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 	// Check tree now
   134 	TUsbGenericDescriptor deviceDesc = testDevice.DeviceDescriptor();
   135 	TUsbGenericDescriptor configDesc = testDevice.ConfigurationDescriptor();
   136 
   137 	// Check tree now	
   138 	CHECK(CheckTreeAfterDeviceInsertion(testDevice, _L("RDeviceB")) == KErrNone);
   139 		
   140 	// Inform client device test case successful
   141 	TUint32 token0;
   142 	err = testDevice.Device().GetTokenForInterface(0,token0);
   143 	if(err != KErrNone)
   144 		{
   145 		RDebug::Printf("<Error %d> Token for interface 0 could not be retrieved",err);
   146 		return TestFailed(err);
   147 		}
   148 	err = iUsbInterface0.Open(token0); // Default interface setting 0
   149 	if(err != KErrNone)
   150 		{
   151 		RDebug::Printf("<Error %d> Unable to open interface 1 using token %d",err,token0);
   152 		return TestFailed(err);
   153 		} 
   154 	 	
   155 	iCaseStep = EPassed;
   156 	TTestCasePassed request;
   157 	iClientAction->SendRequest(request,this);
   158 	}
   159 	
   160 	
   161 void CUT_PBASE_T_USBDI_0474::DeviceRemovedL(TUint aDeviceHandle)
   162 	{
   163 	LOG_FUNC
   164 
   165 	// The test device should not be removed until the test case has passed
   166 	// so this test case has not completed, and state this event as an error
   167 
   168 	TestFailed(KErrDisconnected);
   169 	}
   170 	
   171 	
   172 void CUT_PBASE_T_USBDI_0474::BusErrorL(TInt aError)
   173 	{
   174 	LOG_FUNC
   175 
   176 	// This test case handles no failiures on the bus
   177 	
   178 	TestFailed(aError);
   179 	}
   180 	
   181 	
   182 void CUT_PBASE_T_USBDI_0474::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
   183 	RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
   184 	{
   185 	LOG_FUNC
   186 	Cancel();
   187 	}
   188 
   189 void CUT_PBASE_T_USBDI_0474::Ep0TransferCompleteL(TInt aCompletionCode)
   190 	{
   191 	LOG_FUNC
   192 	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
   193 	
   194 	if(iCaseStep == EPassed)
   195 		{
   196 		TestPassed();
   197 		}
   198 		
   199 	if(iCaseStep == EFailed)
   200 		{
   201 		TestFailed(KErrCompletion);
   202 		}
   203 	}
   204 	
   205 	
   206 void CUT_PBASE_T_USBDI_0474::HostRunL()
   207 	{
   208 	LOG_FUNC
   209 
   210 	// Obtain the completion code
   211 	TInt completionCode(iStatus.Int());
   212 	
   213 	if(completionCode == KErrNone)
   214 		{
   215 		// Action timeout
   216 		RDebug::Printf("<Error> Action timeout");
   217 		TestFailed(KErrTimedOut);
   218 		}
   219 	else
   220 		{
   221 		RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
   222 		TestFailed(completionCode);
   223 		}
   224 	}
   225 
   226 void CUT_PBASE_T_USBDI_0474::DeviceRunL()
   227 	{
   228 	LOG_FUNC
   229 	
   230 	// Disconnect the device
   231 	
   232 	iTestDevice->SoftwareDisconnect();
   233 	
   234 	// Complete the test case request
   235 	
   236 	TestPolicy().SignalTestComplete(iStatus.Int());
   237 	}
   238 	
   239 	
   240 	}
   241