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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 #include <e32std_private.h>
20 #include <u32std.h> // unicode builds
22 #include <e32base_private.h>
23 #include <e32Test.h> // RTest headder
24 #include "testcaseroot.h"
25 #include "b2bwatchers.h"
26 #include "testcase0679.h"
28 #define _REPEATS (oOpenIterations*3)
31 /* **************************************************************************************
32 * the name below is used to add a pointer to our construction method to a pointer MAP in
35 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0679");
36 const TTestCaseFactoryReceipt<CTestCase0679> CTestCase0679::iFactoryReceipt(KTestCaseId);
38 CTestCase0679* CTestCase0679::NewL(TBool aHost)
41 CTestCase0679* self = new (ELeave) CTestCase0679(aHost);
42 CleanupStack::PushL(self);
44 CleanupStack::Pop(self);
49 CTestCase0679::CTestCase0679(TBool aHost)
50 : CTestCaseB2BRoot(KTestCaseId, aHost, iStatus)
60 void CTestCase0679::ConstructL()
64 iDualRoleCase = ETrue; // another back-back
70 CTestCase0679::~CTestCase0679()
73 iCollector.DestroyObservers();
78 void CTestCase0679::ExecuteTestCaseL()
81 iCaseStep = EPreconditions;
82 CActiveScheduler::Add(this);
87 void CTestCase0679::DoCancel()
95 // handle event completion
96 void CTestCase0679::RunStepL()
99 // Obtain the completion code for this CActive obj.
100 TInt completionCode(iStatus.Int());
101 TBuf<MAX_DSTRLEN> aDescription;
108 LOG_STEPNAME(_L("EPreconditions"))
109 iCaseStep = ELoadLdd;
110 StepB2BPreconditions();
114 // 1. Load the Client LDD
117 LOG_STEPNAME(_L("ELoadLdd"))
118 if (!StepLoadClient(0xF679, EFalse /*no HNP support!*/))
120 return TestFailed(KErrAbort, _L("Client Load Failure"));
122 // load OTG ldd and init.
125 return TestFailed(KErrAbort, _L("OTG Load Failure"));
128 if(otgActivateFdfActor()!=KErrNone)
130 return TestFailed(KErrAbort, _L("Couldn't load FDF Actor"));
133 // test that the right cable is in
134 CheckRoleConnections();
136 // subscribe to OTG states,events and messages now that it has loaded OK
137 TRAPD(result, iCollector.CreateObserversL(*this));
138 if (KErrNone != result)
139 return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
140 iCollector.ClearAllEvents();
141 iCaseStep = EReadyToRaiseVBus;
146 case EReadyToRaiseVBus:
150 // wait for Vbus to be raised
151 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
152 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
153 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
157 // Raise VBus, then wait for default role
158 err = otgBusRequest(); // ok to turn on VBus now
161 return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
164 // we might also wait for and EStateAIdle
165 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
166 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
167 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
170 const TInt KTestCase0679VBusRaiseTimeout = 2000; // 2 seconds, should be plenty of time for this test
171 iCollector.AddStepTimeout(KTestCase0679VBusRaiseTimeout);
173 iCaseStep = EDefaultRoles;
180 test.Printf(_L("Into EDefaultRoles step...\n"));
181 LOG_STEPNAME(_L("EWaitEnumeration"));
185 // B-Device should now wait until it is configured
186 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
188 const TInt KTestCase0679BTimeout = 5000; // 5 seconds, should be plenty of time for overall test
189 iCollector.AddStepTimeout(KTestCase0679BTimeout);
191 iCaseStep = EBConfigured;
195 // A-Device should expect nothing more (role swap won't happen
196 // because the B-Device doesn't indicate support for OTG in its
197 // OTG descriptor, so the host won't have sent SetFeature(b_hnp_enable))
198 // Instead, just rely on the test timeout and display a request for the user
199 // to observe the B-Device test code for the pass/fail
200 const TInt KTestCase0679ATimeout = 4000; // 4 seconds before A-Device drops VBus (before B test times out at 5 seconds)
201 iCollector.AddStepTimeout(KTestCase0679ATimeout); // NB. In this test on the A-Device, we expect to timeout
202 // so a timeout isn't treated as a failure
203 test.Printf(_L("NOTE : Please observe test result on B-Device...\n"));
204 iCaseStep = EDropVBus; // This is the step the A-Device will go to
205 // when the timer (set up in previous test) fires
212 case EBConfigured: // A B-Device only step!
214 test.Printf(_L("Into EBConfigured step...\n"));
215 if (KTestCaseWatchdogTO == iStatus.Int())
217 iCollector.DestroyObservers();
218 return TestFailed(KErrAbort, _L("Timeout"));
220 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
221 iCaseStep = EBSuspended;
228 test.Printf(_L("Into EBSuspended step...\n"));
229 if (KTestCaseWatchdogTO == iStatus.Int())
231 iCollector.DestroyObservers();
232 return TestFailed(KErrAbort, _L("Timeout"));
236 test.Printf(_L("Attempting a swap on a non-HNP enabled link...\n"));
237 iCollector.AddRequiredNotification(EWatcherMessage, RUsbOtgDriver::EMessageHnpNotEnabled);
239 err = otgBusRequest(); // Request the host role
243 test.Printf(_L("BusRequest returned %d)"),err);
244 //DS Temp! return TestFailed(KErrAbort, _L("BusRequest() failed!"));
247 iCaseStep = EBErrorReceived;
252 case EBErrorReceived:
254 test.Printf(_L("Into EBErrorReceived step...\n"));
255 if (KTestCaseWatchdogTO == iStatus.Int())
257 iCollector.DestroyObservers();
258 return TestFailed(KErrAbort, _L("Timeout"));
260 iCaseStep = EDropVBus; // Test has pretty much passed now. Just wait for A-Device to drop VBus.
266 LOG_STEPNAME(_L("EDropVBus"))
268 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
269 if ( gTestRoleMaster)
271 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
275 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
278 iCaseStep = EVBusDropped;
283 LOG_STEPNAME(_L("EVBusDropped"))
284 if (KTestCaseWatchdogTO == iStatus.Int() && gTestRoleMaster)
286 // Remember, a timeout is only a failure for the B-Device in this test,
287 // we're expecting and relying on a timeout on the A-Device to conclude
288 // the test and bring VBus down.
289 return TestFailed(KErrAbort, _L("Timeout"));
292 if (otgVbusPresent())
294 return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
296 iCaseStep = EUnloadLdd;
301 LOG_STEPNAME(_L("EUnloadLdd"))
302 iCollector.DestroyObservers();
303 otgDeactivateFdfActor();
304 if (EFalse == StepUnloadLDD())
305 return TestFailed(KErrAbort,_L("unload Ldd failure"));
306 if (!StepUnloadClient())
307 return TestFailed(KErrAbort,_L("Client Unload Failure"));
309 iCaseStep = ELastStep;
314 LOG_STEPNAME(_L("ELastStep"))
319 test.Printf(_L("<Error> unknown test step"));
321 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));