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