os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0473.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// @file PBASE-T_USBDI-0473.cpp
sl@0
    15
// @internalComponent
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include "PBASE-T_USBDI-0473.h"
sl@0
    20
#include <d32usbc.h>
sl@0
    21
#include "testdebug.h"
sl@0
    22
#include "modelleddevices.h"
sl@0
    23
#include "TestPolicy.h"
sl@0
    24
sl@0
    25
namespace NUnitTesting_USBDI
sl@0
    26
	{
sl@0
    27
	
sl@0
    28
_LIT(KTestCaseId,"PBASE-T_USBDI-0473");
sl@0
    29
const TFunctorTestCase<CUT_PBASE_T_USBDI_0473,TBool> CUT_PBASE_T_USBDI_0473::iFunctor(KTestCaseId);	
sl@0
    30
sl@0
    31
CUT_PBASE_T_USBDI_0473* CUT_PBASE_T_USBDI_0473::NewL(TBool aHostRole)
sl@0
    32
	{
sl@0
    33
	CUT_PBASE_T_USBDI_0473* self = new (ELeave) CUT_PBASE_T_USBDI_0473(aHostRole);
sl@0
    34
	CleanupStack::PushL(self);
sl@0
    35
	self->ConstructL();
sl@0
    36
	CleanupStack::Pop(self);
sl@0
    37
	return self; 
sl@0
    38
	}
sl@0
    39
	   
sl@0
    40
sl@0
    41
CUT_PBASE_T_USBDI_0473::CUT_PBASE_T_USBDI_0473(TBool aHostRole)
sl@0
    42
:	CBaseTestCase(KTestCaseId,aHostRole),
sl@0
    43
	iSuspendedI0(EFalse),
sl@0
    44
	iSuspendedI1(EFalse),
sl@0
    45
	iDeviceNotificationPending(ETrue)
sl@0
    46
	{
sl@0
    47
	} 
sl@0
    48
sl@0
    49
sl@0
    50
void CUT_PBASE_T_USBDI_0473::ConstructL()
sl@0
    51
	{
sl@0
    52
	iTestDevice = new RUsbDeviceA(this);
sl@0
    53
	BaseConstructL();
sl@0
    54
	}
sl@0
    55
sl@0
    56
sl@0
    57
CUT_PBASE_T_USBDI_0473::~CUT_PBASE_T_USBDI_0473()
sl@0
    58
	{
sl@0
    59
	LOG_FUNC
sl@0
    60
	
sl@0
    61
	// Cancel any async operations
sl@0
    62
	
sl@0
    63
	Cancel(); // Cancel host timer
sl@0
    64
	
sl@0
    65
	// Destroy the watchers
sl@0
    66
	// they still use opened interfaces to cancel the suspend if active
sl@0
    67
	delete iInterface1Watcher;
sl@0
    68
	delete iInterface0Watcher;
sl@0
    69
sl@0
    70
	// Close the interfaces
sl@0
    71
	iUsbInterface1.Close();
sl@0
    72
	iUsbInterface0.Close();
sl@0
    73
	
sl@0
    74
	delete iControlEp0;
sl@0
    75
	delete iActorFDF;
sl@0
    76
	if(!IsHost() && iTestDevice)
sl@0
    77
		{
sl@0
    78
		iTestDevice->Close();
sl@0
    79
		}		
sl@0
    80
	delete iTestDevice;
sl@0
    81
	}
sl@0
    82
sl@0
    83
sl@0
    84
void CUT_PBASE_T_USBDI_0473::ExecuteHostTestCaseL()
sl@0
    85
	{
sl@0
    86
	LOG_FUNC
sl@0
    87
	iCaseStep = EStepSuspend;
sl@0
    88
	iActorFDF = CActorFDF::NewL(*this);
sl@0
    89
	iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
sl@0
    90
	iInterface0Watcher = new (ELeave) CInterfaceWatcher(iUsbInterface0,TCallBack(CUT_PBASE_T_USBDI_0473::Interface0ResumedL,this));
sl@0
    91
	iInterface1Watcher = new (ELeave) CInterfaceWatcher(iUsbInterface1,TCallBack(CUT_PBASE_T_USBDI_0473::Interface1ResumedL,this));
sl@0
    92
	
sl@0
    93
	// Monitor for device connections
sl@0
    94
	iActorFDF->Monitor();
sl@0
    95
sl@0
    96
	// Start the connection timeout	
sl@0
    97
	TimeoutIn(30);
sl@0
    98
	}
sl@0
    99
sl@0
   100
void CUT_PBASE_T_USBDI_0473::ExecuteDeviceTestCaseL()
sl@0
   101
	{
sl@0
   102
	LOG_FUNC
sl@0
   103
sl@0
   104
	// Construct the device for the test case
sl@0
   105
	iTestDevice->OpenL(TestCaseId());
sl@0
   106
	iTestDevice->SubscribeToReports(iStatus);
sl@0
   107
	SetActive();
sl@0
   108
sl@0
   109
	// Connect the test device	
sl@0
   110
	iTestDevice->SoftwareConnect();
sl@0
   111
	}
sl@0
   112
	
sl@0
   113
	
sl@0
   114
void CUT_PBASE_T_USBDI_0473::HostDoCancel()
sl@0
   115
	{
sl@0
   116
	LOG_FUNC
sl@0
   117
sl@0
   118
	// Cancel the timeout timer
sl@0
   119
	CancelTimeout();
sl@0
   120
	}
sl@0
   121
sl@0
   122
sl@0
   123
void CUT_PBASE_T_USBDI_0473::DeviceDoCancel()
sl@0
   124
	{
sl@0
   125
	LOG_FUNC
sl@0
   126
	
sl@0
   127
	// Cancel the device	
sl@0
   128
	iTestDevice->CancelSubscriptionToReports();
sl@0
   129
	}
sl@0
   130
	
sl@0
   131
void CUT_PBASE_T_USBDI_0473::DeviceInsertedL(TUint aDeviceHandle)
sl@0
   132
	{
sl@0
   133
	LOG_FUNC
sl@0
   134
sl@0
   135
	Cancel(); // Cancel the timer
sl@0
   136
	TInt err(KErrNone);
sl@0
   137
	iDeviceHandle = aDeviceHandle;
sl@0
   138
	iActorFDF->Monitor();
sl@0
   139
	
sl@0
   140
	// Validate that device is as expected
sl@0
   141
	CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
sl@0
   142
	if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
sl@0
   143
		{
sl@0
   144
		// Incorrect device for this test case
sl@0
   145
sl@0
   146
		RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
sl@0
   147
			KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
sl@0
   148
sl@0
   149
		// Start the connection timeout again
sl@0
   150
		TimeoutIn(30);
sl@0
   151
		return;
sl@0
   152
		}	
sl@0
   153
	// Check tree now	
sl@0
   154
	CHECK(CheckTreeAfterDeviceInsertion(testDevice, _L("RDeviceA")) == KErrNone);
sl@0
   155
		
sl@0
   156
	// Perform the correct test step				
sl@0
   157
	switch(iCaseStep)
sl@0
   158
		{
sl@0
   159
		case EStepSuspend:
sl@0
   160
			{
sl@0
   161
			TUint32 token1(0);
sl@0
   162
			TUint32 token2(0);
sl@0
   163
	
sl@0
   164
			RDebug::Printf("Obtaining token for interface 0");
sl@0
   165
			err = testDevice.Device().GetTokenForInterface(0,token1);
sl@0
   166
			if(err != KErrNone)
sl@0
   167
				{
sl@0
   168
				RDebug::Printf("<Error %d> Token for interface 0 could not be retrieved",err);
sl@0
   169
				return TestFailed(err);
sl@0
   170
				}
sl@0
   171
			RDebug::Printf("Token 1 (%d) retrieved",token1);
sl@0
   172
			RDebug::Printf("Opening interface 0");
sl@0
   173
			err = iUsbInterface0.Open(token1); // Alternate interface setting 0
sl@0
   174
			if(err != KErrNone)
sl@0
   175
				{
sl@0
   176
				RDebug::Printf("<Error %d> Interface 0 could not be opened",err);
sl@0
   177
				return TestFailed(err);
sl@0
   178
				}
sl@0
   179
			RDebug::Printf("Interface 0 opened");
sl@0
   180
		
sl@0
   181
																
sl@0
   182
			RDebug::Printf("Obtaining token for interface 1");
sl@0
   183
			err = testDevice.Device().GetTokenForInterface(1,token2);
sl@0
   184
			if(err != KErrNone)
sl@0
   185
				{
sl@0
   186
				RDebug::Printf("<Error %d> Token for interface 1 could not be retrieved",err);
sl@0
   187
				return TestFailed(err);			
sl@0
   188
				}	
sl@0
   189
			RDebug::Printf("Opening interface 1");
sl@0
   190
			err = iUsbInterface1.Open(token2); // Alternate interface setting 0
sl@0
   191
			if(err != KErrNone)
sl@0
   192
				{
sl@0
   193
				RDebug::Printf("<Error %d> Interface 1 could not be opened",err);
sl@0
   194
				return TestFailed(err);
sl@0
   195
				}
sl@0
   196
			RDebug::Printf("Interface 1 opened");
sl@0
   197
	
sl@0
   198
			// close it
sl@0
   199
			iUsbInterface1.Close();		
sl@0
   200
			RDebug::Printf("Interface 1 closed");
sl@0
   201
	
sl@0
   202
			//re-open now
sl@0
   203
			err = iUsbInterface1.Open(token2); // Alternate interface setting 0
sl@0
   204
			if(err != KErrNone)
sl@0
   205
				{
sl@0
   206
				RDebug::Printf("<Error %d> Interface 1 could not be re-opened",err);
sl@0
   207
				return TestFailed(err);
sl@0
   208
				}
sl@0
   209
			RDebug::Printf("Interface 1 re-opened");
sl@0
   210
			
sl@0
   211
			
sl@0
   212
			// Suspend interface 0
sl@0
   213
			RDebug::Printf("Suspending interface 0");
sl@0
   214
			iInterface0Watcher->SuspendAndWatch();
sl@0
   215
			iSuspendedI0 = ETrue;
sl@0
   216
			
sl@0
   217
			// Suspend interface 1
sl@0
   218
			RDebug::Printf("Suspending interface 1");
sl@0
   219
			iInterface1Watcher->SuspendAndWatch();
sl@0
   220
			iSuspendedI1 = ETrue;
sl@0
   221
			
sl@0
   222
			iCaseStep = EValidateSuspendingInterfaces;
sl@0
   223
			TimeoutIn(10); // Give 10 seconds for device to suspend
sl@0
   224
			}
sl@0
   225
			break;
sl@0
   226
			
sl@0
   227
		default:
sl@0
   228
			TestFailed(KErrCorrupt);
sl@0
   229
			break;
sl@0
   230
		}	
sl@0
   231
	}
sl@0
   232
sl@0
   233
sl@0
   234
TInt CUT_PBASE_T_USBDI_0473::Interface0ResumedL(TAny* aPtr)
sl@0
   235
	{
sl@0
   236
	LOG_CFUNC
sl@0
   237
	RDebug::Printf("Interface 0 resumed");
sl@0
   238
	CUT_PBASE_T_USBDI_0473* self = reinterpret_cast<CUT_PBASE_T_USBDI_0473*>(aPtr);
sl@0
   239
	RDebug::Printf("watcher 0 iStatus=%d",self->iInterface0Watcher->CompletionCode());
sl@0
   240
	self->iSuspendedI0 = EFalse;
sl@0
   241
	return self->CheckForAllResumedNotificationsAndContinueFSM();
sl@0
   242
	}
sl@0
   243
	
sl@0
   244
	
sl@0
   245
TInt CUT_PBASE_T_USBDI_0473::Interface1ResumedL(TAny* aPtr)
sl@0
   246
	{
sl@0
   247
	LOG_CFUNC
sl@0
   248
	RDebug::Printf("Interface 1 resumed");
sl@0
   249
	CUT_PBASE_T_USBDI_0473* self = reinterpret_cast<CUT_PBASE_T_USBDI_0473*>(aPtr);
sl@0
   250
	RDebug::Printf("watcher 1 iStatus=%d",self->iInterface1Watcher->CompletionCode());
sl@0
   251
	self->iSuspendedI1 = EFalse;
sl@0
   252
	return self->CheckForAllResumedNotificationsAndContinueFSM();
sl@0
   253
	}
sl@0
   254
	
sl@0
   255
	
sl@0
   256
void CUT_PBASE_T_USBDI_0473::DeviceRemovedL(TUint aDeviceHandle)
sl@0
   257
	{
sl@0
   258
	LOG_FUNC
sl@0
   259
sl@0
   260
	// The test device should not be removed until the test case has passed
sl@0
   261
	// so this test case has not completed, and state this event as an error
sl@0
   262
sl@0
   263
	TestFailed(KErrDisconnected);
sl@0
   264
	}
sl@0
   265
	
sl@0
   266
	
sl@0
   267
void CUT_PBASE_T_USBDI_0473::BusErrorL(TInt aError)
sl@0
   268
	{
sl@0
   269
	LOG_FUNC
sl@0
   270
sl@0
   271
	// This test case handles no failiures on the bus
sl@0
   272
sl@0
   273
	TestFailed(aError);
sl@0
   274
	}
sl@0
   275
sl@0
   276
TInt CUT_PBASE_T_USBDI_0473::CheckForAllResumedNotificationsAndContinueFSM()
sl@0
   277
	{
sl@0
   278
	LOG_FUNC
sl@0
   279
	TBool readyToContinueFSM= ETrue;
sl@0
   280
	if( iInterface0Watcher->IsActive()
sl@0
   281
	||  iInterface0Watcher->iStatus == KRequestPending)
sl@0
   282
		{
sl@0
   283
		RDebug::Printf("Interface 0 watcher still pending");
sl@0
   284
		readyToContinueFSM= EFalse;
sl@0
   285
		}
sl@0
   286
sl@0
   287
	if( iInterface1Watcher->IsActive()
sl@0
   288
	||  iInterface1Watcher->iStatus == KRequestPending)
sl@0
   289
		{
sl@0
   290
		RDebug::Printf("Interface 1 watcher still pending");
sl@0
   291
		readyToContinueFSM= EFalse;
sl@0
   292
		}
sl@0
   293
sl@0
   294
	if( iDeviceNotificationPending)
sl@0
   295
		{
sl@0
   296
		readyToContinueFSM= EFalse;
sl@0
   297
		}
sl@0
   298
sl@0
   299
	if( readyToContinueFSM)
sl@0
   300
		{
sl@0
   301
		return ContinueFSMAfterAllResumedNotifications();
sl@0
   302
		}
sl@0
   303
	else
sl@0
   304
		{
sl@0
   305
		return KErrNone;
sl@0
   306
		}
sl@0
   307
	}
sl@0
   308
sl@0
   309
TInt CUT_PBASE_T_USBDI_0473::ContinueFSMAfterAllResumedNotifications()
sl@0
   310
	{
sl@0
   311
	LOG_FUNC
sl@0
   312
	iDeviceNotificationPending= ETrue;
sl@0
   313
	if(iSuspendedI0)
sl@0
   314
		{
sl@0
   315
		RDebug::Printf("<Error %d> Interface 0 still suspended",KErrCompletion);
sl@0
   316
		TestFailed(KErrCompletion);
sl@0
   317
		return KErrCompletion;
sl@0
   318
		}
sl@0
   319
sl@0
   320
	if(iSuspendedI1)
sl@0
   321
		{
sl@0
   322
		RDebug::Printf("<Error %d> Interface 1 still suspended",KErrCompletion);
sl@0
   323
		TestFailed(KErrCompletion);
sl@0
   324
		return KErrCompletion;
sl@0
   325
		}
sl@0
   326
sl@0
   327
	switch(iCaseStep)
sl@0
   328
		{
sl@0
   329
		case EValidateResumptionAfterInterfaceSuspension:
sl@0
   330
			{
sl@0
   331
			// Device is resumed, send request to client: Remote wake up in 6 secs
sl@0
   332
			TInt err= iUsbInterface1.PermitRemoteWakeup(ETrue);
sl@0
   333
			
sl@0
   334
			if(err != KErrNone)
sl@0
   335
				{
sl@0
   336
				RDebug::Printf("<Error %d> Unable to permit remote device wakeup",err);
sl@0
   337
				iCaseStep = EFailed;
sl@0
   338
				TTestCaseFailed request(err,_L8("Unable to permit remote device wakeup"));
sl@0
   339
				iControlEp0->SendRequest(request,this);
sl@0
   340
				}
sl@0
   341
			else
sl@0
   342
				{
sl@0
   343
				RDebug::Printf("Device is resumed, send request to client: Remote wake up in 6 secs");
sl@0
   344
				
sl@0
   345
				TRemoteWakeupRequest request(6);
sl@0
   346
				iControlEp0->SendRequest(request,this);			
sl@0
   347
				iCaseStep = ESuspendForRemoteWakeup;		
sl@0
   348
				}
sl@0
   349
			}
sl@0
   350
			break;
sl@0
   351
sl@0
   352
		case EValidateResumptionAfterWakeup:
sl@0
   353
			{
sl@0
   354
			if(iStoredNewState == RUsbDevice::EDeviceActive)
sl@0
   355
				{
sl@0
   356
				// Now suspend the device again after resumption from remote wakeup
sl@0
   357
			
sl@0
   358
				RDebug::Printf("Suspending interface 0");
sl@0
   359
				iInterface0Watcher->SuspendAndWatch();
sl@0
   360
				iSuspendedI0 = ETrue;
sl@0
   361
				
sl@0
   362
				RDebug::Printf("Suspending interface 1");
sl@0
   363
				iInterface1Watcher->SuspendAndWatch();
sl@0
   364
				iSuspendedI1 = ETrue;
sl@0
   365
				
sl@0
   366
				iCaseStep = EValidateSuspendAfterWakeup;
sl@0
   367
				}
sl@0
   368
			else
sl@0
   369
				{
sl@0
   370
				RDebug::Printf("<Error %d> Device is still suspended",KErrCompletion);
sl@0
   371
				TestFailed(KErrCompletion);
sl@0
   372
				return KErrCompletion;
sl@0
   373
				}
sl@0
   374
			}
sl@0
   375
			break;
sl@0
   376
sl@0
   377
		default:
sl@0
   378
			RDebug::Printf("CUT_PBASE_T_USBDI_0473::ContinueFSMAfterAllResumedNotifications: Invalid state %d", iCaseStep);
sl@0
   379
			TestFailed(KErrCompletion);
sl@0
   380
			return KErrCompletion;
sl@0
   381
		}
sl@0
   382
sl@0
   383
	return KErrNone;
sl@0
   384
	}
sl@0
   385
sl@0
   386
void CUT_PBASE_T_USBDI_0473::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
sl@0
   387
	{
sl@0
   388
	LOG_FUNC
sl@0
   389
	Cancel();
sl@0
   390
	
sl@0
   391
	RDebug::Printf("Device State change from %d to %d err=%d",aPreviousState,aNewState,aCompletionCode);
sl@0
   392
sl@0
   393
	switch(iCaseStep)
sl@0
   394
		{
sl@0
   395
	
sl@0
   396
		// Validate that the device was suspended by individual interface suspension
sl@0
   397
	
sl@0
   398
		case EValidateSuspendingInterfaces:
sl@0
   399
			{
sl@0
   400
			if(aNewState == RUsbDevice::EDeviceSuspended)
sl@0
   401
				{
sl@0
   402
				// Device state is suspended now resume it by resuming one of the interfaces
sl@0
   403
				
sl@0
   404
				RDebug::Printf("Device is suspended now resume device by resuming one of the interfaces");
sl@0
   405
				iUsbInterface0.CancelPermitSuspend();
sl@0
   406
				iCaseStep = EValidateResumptionAfterInterfaceSuspension;
sl@0
   407
				}
sl@0
   408
			else
sl@0
   409
				{
sl@0
   410
				RDebug::Printf("<Error %d> State was not suspended",KErrCompletion);
sl@0
   411
				
sl@0
   412
				// Since the device is not suspended, send test case failed to the device
sl@0
   413
	
sl@0
   414
				iCaseStep = EFailed;
sl@0
   415
				TTestCaseFailed request(KErrCompletion,_L8("The device was not in the expected suspend state"));
sl@0
   416
				iControlEp0->SendRequest(request,this);
sl@0
   417
				}
sl@0
   418
			}
sl@0
   419
			break;
sl@0
   420
			
sl@0
   421
		// Validate that device is now active after resuming one of the interfaces
sl@0
   422
	
sl@0
   423
		case EValidateResumptionAfterInterfaceSuspension:
sl@0
   424
			{
sl@0
   425
			iDeviceNotificationPending= EFalse;
sl@0
   426
sl@0
   427
			if(aNewState == RUsbDevice::EDeviceActive)
sl@0
   428
				{
sl@0
   429
				CheckForAllResumedNotificationsAndContinueFSM();
sl@0
   430
				}
sl@0
   431
			else
sl@0
   432
				{
sl@0
   433
				RDebug::Printf("<Error %d> Device is still suspended",KErrCompletion);
sl@0
   434
				return TestFailed(KErrCompletion);
sl@0
   435
				}
sl@0
   436
			}
sl@0
   437
			break;
sl@0
   438
			
sl@0
   439
		// Validate that the device is now suspended for the device to remote-wakeup
sl@0
   440
		case EValidateSuspendForRemoteWakeup:
sl@0
   441
			{
sl@0
   442
			if(aNewState == RUsbDevice::EDeviceSuspended)
sl@0
   443
				{
sl@0
   444
				// Now awaiting a remote wake up state change notification
sl@0
   445
				
sl@0
   446
				RDebug::Printf("Now awaiting a remote wake up state change notification");
sl@0
   447
				
sl@0
   448
				CancelTimeout();
sl@0
   449
				iTimer.After(iStatus,10000000); // Give 10 seconds for device to signal remote wake-up
sl@0
   450
				iCaseStep = EValidateResumptionAfterWakeup;
sl@0
   451
				SetActive();
sl@0
   452
				}
sl@0
   453
			else
sl@0
   454
				{
sl@0
   455
				RDebug::Printf("<Error %d> State was not suspended",KErrCompletion);
sl@0
   456
				
sl@0
   457
				// Since the device is not suspended, send test case failed to the device
sl@0
   458
	
sl@0
   459
				iCaseStep = EFailed;
sl@0
   460
				TTestCaseFailed request(KErrCompletion,_L8("State was not suspended"));
sl@0
   461
				iControlEp0->SendRequest(request,this);
sl@0
   462
				}
sl@0
   463
			}
sl@0
   464
			break;
sl@0
   465
			
sl@0
   466
		// This step should never be reached as ep0 complete traps this step, but if it does test fails.
sl@0
   467
		case ESuspendForRemoteWakeup:
sl@0
   468
			{
sl@0
   469
			RDebug::Printf("Resumed before suspended");	    
sl@0
   470
		    iCaseStep = EFailed;
sl@0
   471
		    TTestCaseFailed request(KErrCompletion,_L8("State was not suspended"));
sl@0
   472
		    iControlEp0->SendRequest(request,this);
sl@0
   473
		    break;	
sl@0
   474
			}	    
sl@0
   475
				
sl@0
   476
		// Validate that the device is now active from a remote wakeup
sl@0
   477
		case EValidateResumptionAfterWakeup:
sl@0
   478
			{
sl@0
   479
			iDeviceNotificationPending= EFalse;
sl@0
   480
			iStoredNewState= aNewState;
sl@0
   481
			CheckForAllResumedNotificationsAndContinueFSM();
sl@0
   482
			}
sl@0
   483
			break;
sl@0
   484
			
sl@0
   485
		// Validate that the device can be suspended after a remote wakeup
sl@0
   486
	
sl@0
   487
		case EValidateSuspendAfterWakeup:
sl@0
   488
			{
sl@0
   489
			// Successfully suspended after a remote wake up event
sl@0
   490
			if(aNewState == RUsbDevice::EDeviceSuspended)
sl@0
   491
				{
sl@0
   492
				// Device is now suspended, now activate the device again to send test case
sl@0
   493
				// completed request to device
sl@0
   494
	
sl@0
   495
				RDebug::Printf("Device is now suspended, now activate the device again to send test case completed request to device");
sl@0
   496
	
sl@0
   497
				CUsbTestDevice& testDevice = iActorFDF->DeviceL(iDeviceHandle);
sl@0
   498
	
sl@0
   499
				RDebug::Printf("Resuming at device level");
sl@0
   500
				TInt err(testDevice.Device().Resume());
sl@0
   501
				if(err != KErrNone)
sl@0
   502
					{
sl@0
   503
					RDebug::Printf("<Error %d> Unable to suspend the device",err);
sl@0
   504
					iCaseStep = EFailed;
sl@0
   505
					TTestCaseFailed request(err,_L8("Unable to suspend the device"));
sl@0
   506
					iControlEp0->SendRequest(request,this);
sl@0
   507
					}
sl@0
   508
				
sl@0
   509
				iCaseStep = EPassed;
sl@0
   510
				}
sl@0
   511
			else
sl@0
   512
				{
sl@0
   513
				RDebug::Printf("<Error %d> State was not suspended",KErrCompletion);
sl@0
   514
				
sl@0
   515
				// Since the device is not suspended, send test case failed to the device
sl@0
   516
	
sl@0
   517
				iCaseStep = EFailed;
sl@0
   518
				TTestCaseFailed request(KErrCompletion,_L8("State was not suspended"));
sl@0
   519
				iControlEp0->SendRequest(request,this);
sl@0
   520
				}
sl@0
   521
			}
sl@0
   522
			break;
sl@0
   523
	
sl@0
   524
		// Validate that the device is now active again 
sl@0
   525
	
sl@0
   526
		case EPassed:
sl@0
   527
			{
sl@0
   528
			if(aNewState == RUsbDevice::EDeviceActive)
sl@0
   529
				{
sl@0
   530
				RDebug::Printf("Device is active again, test case passed");
sl@0
   531
				TTestCasePassed request;
sl@0
   532
				iControlEp0->SendRequest(request,this);
sl@0
   533
				}
sl@0
   534
			else
sl@0
   535
				{
sl@0
   536
				RDebug::Printf("<Error %d> Device is still suspended",KErrCompletion);
sl@0
   537
				return TestFailed(KErrCompletion);
sl@0
   538
				}
sl@0
   539
			}
sl@0
   540
			break;
sl@0
   541
			
sl@0
   542
		default:
sl@0
   543
			break;
sl@0
   544
		}
sl@0
   545
	}
sl@0
   546
sl@0
   547
sl@0
   548
void CUT_PBASE_T_USBDI_0473::Ep0TransferCompleteL(TInt aCompletionCode)
sl@0
   549
	{
sl@0
   550
	LOG_FUNC
sl@0
   551
	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
sl@0
   552
	switch(iCaseStep)
sl@0
   553
		{
sl@0
   554
		case ESuspendForRemoteWakeup:
sl@0
   555
			{
sl@0
   556
			// Suspend device again so a remote wakeup can be achieved
sl@0
   557
			RDebug::Printf("Suspend device again so a remote wakeup can be achieved");
sl@0
   558
	
sl@0
   559
			// Suspend interface 0
sl@0
   560
			RDebug::Printf("Suspending interface 0");
sl@0
   561
			iInterface0Watcher->SuspendAndWatch();
sl@0
   562
			iSuspendedI0 = ETrue;
sl@0
   563
			
sl@0
   564
			// Suspend interface 1
sl@0
   565
			RDebug::Printf("Suspending interface 1");
sl@0
   566
			iInterface1Watcher->SuspendAndWatch();
sl@0
   567
			iSuspendedI1 = ETrue;
sl@0
   568
			
sl@0
   569
			iCaseStep = EValidateSuspendForRemoteWakeup;
sl@0
   570
			TimeoutIn(10); // Give 10 seconds for device to suspend	
sl@0
   571
			}
sl@0
   572
			break;
sl@0
   573
	
sl@0
   574
		// Fail the test case
sl@0
   575
	
sl@0
   576
		default:
sl@0
   577
		case EFailed:
sl@0
   578
			TestFailed(KErrCompletion);
sl@0
   579
			break;
sl@0
   580
	
sl@0
   581
		// Pass the test case
sl@0
   582
	
sl@0
   583
		case EPassed:
sl@0
   584
			TestPassed();
sl@0
   585
			break;
sl@0
   586
			}
sl@0
   587
	}
sl@0
   588
sl@0
   589
sl@0
   590
void CUT_PBASE_T_USBDI_0473::HostRunL()
sl@0
   591
	{
sl@0
   592
	LOG_FUNC
sl@0
   593
	
sl@0
   594
	// Obtain the completion code
sl@0
   595
	TInt completionCode(iStatus.Int());
sl@0
   596
	
sl@0
   597
	if(completionCode == KErrNone)
sl@0
   598
		{
sl@0
   599
		// Action timeout
sl@0
   600
		RDebug::Printf("<Error> Action timeout");
sl@0
   601
		TestFailed(KErrTimedOut);
sl@0
   602
		}
sl@0
   603
	else
sl@0
   604
		{
sl@0
   605
		RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
sl@0
   606
		TestFailed(completionCode);
sl@0
   607
		}
sl@0
   608
	}
sl@0
   609
	
sl@0
   610
sl@0
   611
void CUT_PBASE_T_USBDI_0473::DeviceRunL()
sl@0
   612
	{
sl@0
   613
	LOG_FUNC
sl@0
   614
	
sl@0
   615
	// Disconnect the device
sl@0
   616
	
sl@0
   617
	iTestDevice->SoftwareDisconnect();
sl@0
   618
	
sl@0
   619
	// Complete the test case request
sl@0
   620
	
sl@0
   621
	TestPolicy().SignalTestComplete(iStatus.Int());
sl@0
   622
	}
sl@0
   623
	
sl@0
   624
	
sl@0
   625
	}