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 "testcase1233.h"
30 #define LOG_INTO_STEP(a) test.Printf(_L("\nInto Step [%S]\n\n"), &a);
32 /* **************************************************************************************
33 * the name below is used to add a pointer to our construction method to a pointer MAP in
36 _LIT(KTestCaseId,"PBASE-USB_OTGDI-1233");
37 const TTestCaseFactoryReceipt<CTestCase1233> CTestCase1233::iFactoryReceipt(KTestCaseId);
39 CTestCase1233* CTestCase1233::NewL(TBool aHost)
42 CTestCase1233* self = new (ELeave) CTestCase1233(aHost);
43 CleanupStack::PushL(self);
45 CleanupStack::Pop(self);
50 CTestCase1233::CTestCase1233(TBool aHost)
51 : CTestCaseB2BRoot(KTestCaseId, aHost, iStatus)
61 void CTestCase1233::ConstructL()
65 iTestVID = 0x0E22; // Symbian
66 iTestPID = 0xF000 + 1233; // Test 1233
72 CTestCase1233::~CTestCase1233()
75 iCollector.DestroyObservers();
80 void CTestCase1233::ExecuteTestCaseL()
83 iCaseStep = EPreconditions;
84 CActiveScheduler::Add(this);
89 void CTestCase1233::DoCancel()
97 void CTestCase1233::RunStepL()
101 // Obtain the completion code for this CActive obj.
102 TInt completionCode(iStatus.Int());
103 TBuf<MAX_DSTRLEN> aDescription;
107 /*==================================================*/
108 /* Fixed 'pre' steps */
109 /*==================================================*/
112 LOG_INTO_STEP(_L("EPreconditions"))
114 iCaseStep = ELoadLdd;
115 StepB2BPreconditions();
121 LOG_INTO_STEP(_L("ELoadLdd"))
123 // Note we use here the hex equivalent of #1233 for the PID
125 if (!StepLoadClient(0xF4D1/*use default settings for SRP/HNP support*/))
127 return TestFailed(KErrAbort, _L("Client Load Failure"));
130 // load OTG ldd and init.
133 return TestFailed(KErrAbort, _L("OTG Load Failure"));
136 if(otgActivateFdfActor()!=KErrNone)
138 return TestFailed(KErrAbort, _L("Couldn't load FDF Actor"));
141 // test that the right cable is in
142 CheckRoleConnections();
144 // subscribe to OTG states,events and messages now that it has loaded OK
145 TRAPD(result, iCollector.CreateObserversL(*this));
146 if (KErrNone != result)
148 return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
151 // Allow enough time for 8 enumerations, say a second each, plus two of the
152 // tests require 15 seconds of SOF traffic
154 const TInt KTestCase1233Timeout = 45000;
155 iCollector.AddStepTimeout(KTestCase1233Timeout);
157 iCollector.ClearAllEvents();
158 iCaseStep = ERaiseVBus;
164 /*==================================================*/
165 /* Steps for this test case only */
166 /*==================================================*/
170 LOG_INTO_STEP(_L("ELoopToNextPID"));
172 if (KTestCaseWatchdogTO == iStatus.Int())
174 iCollector.DestroyObservers();
175 return TestFailed(KErrAbort, _L("Timeout"));
178 if ( iTestVID == 0x0E22 )
180 iTestVID = 0x1A0A; // OPT and test devices
181 iTestPID = 0x0100; // One *before* the first HS test ID
186 if ( iTestPID > 0x0108 )
188 test.Printf(_L("All VID/PID pairs done\n"));
190 iCaseStep = EUnloadLdd;
197 test.Printf(_L("Setting VID/PID of 0x%04x/0x%04x\n"),iTestVID,iTestPID);
199 if (!StepChangeVidPid(iTestVID,iTestPID))
201 return TestFailed(KErrAbort, _L("VID/PID Change Failure"));
207 test.Printf(_L("Expecting VID/PID of 0x%04x/0x%04x\n"),iTestVID,iTestPID);
210 iCollector.ClearAllEvents();
211 iCaseStep = ERaiseVBus;
220 LOG_INTO_STEP(_L("ERaiseVBus"));
222 if (KTestCaseWatchdogTO == iStatus.Int())
224 iCollector.DestroyObservers();
225 return TestFailed(KErrAbort, _L("Timeout"));
231 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
232 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
233 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateDefault);
234 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateAddress);
235 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventHnpEnabled);
236 iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
241 test.Printf(_L("Raising VBUS for VID/PID = 0x%04x/0x%04x\n"),iTestVID,iTestPID);
243 if ( otgBusRequest() != KErrNone )
245 return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
248 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
249 iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
250 iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost);
253 iCaseStep = EVBusRaised;
260 LOG_INTO_STEP(_L("EVBusRaised"));
262 if (KTestCaseWatchdogTO == iStatus.Int())
264 return TestFailed(KErrAbort, _L("Timeout"));
267 if ( otgVbusPresent() )
269 test.Printf(_L("...VBUS is UP\n"));
270 iCaseStep = EDropVBus;
274 test.Printf(_L("...VBUS is DOWN\n"));
275 return TestFailed(KErrAbort, _L("Vbus did not rise - FAILED!"));
287 // The default device (0x0E22/0xB4D1) is passed to the FDF, which will (eventually)
288 // suspend and enter connection idle state.
290 // The HS test devices (0x1A0A) will not be presented to FDF, so there will be no
291 // trailing connection idle to find.
293 if ( iTestVID == 0x0E22 )
295 iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
309 LOG_INTO_STEP(_L("EDropVBus"));
311 if (KTestCaseWatchdogTO == iStatus.Int())
313 iCollector.DestroyObservers();
314 return TestFailed(KErrAbort, _L("Timeout"));
317 if ( gTestRoleMaster)
320 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
327 iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
330 iCaseStep = EVBusDropped;
337 LOG_INTO_STEP(_L("EVBusDropped"));
339 if (KTestCaseWatchdogTO == iStatus.Int())
341 return TestFailed(KErrAbort, _L("Timeout"));
344 if ( otgVbusPresent() )
346 test.Printf(_L("...VBUS is UP\n"));
347 return TestFailed(KErrAbort, _L("Vbus did not rise - FAILED!"));
351 test.Printf(_L("...VBUS is DOWN\n"));
352 iCaseStep = ELoopToNextPID;
359 /*==================================================*/
360 /* Fixed 'post' steps */
361 /*==================================================*/
365 LOG_INTO_STEP(_L("EUnloadLdd"))
367 otgDeactivateFdfActor();
368 iCollector.DestroyObservers();
369 if (EFalse == StepUnloadLDD()){
370 return TestFailed(KErrAbort,_L("unload Ldd failure"));
372 if (!StepUnloadClient()){
373 return TestFailed(KErrAbort,_L("Client Unload Failure"));
376 iCaseStep = ELastStep;
383 LOG_INTO_STEP(_L("ELastStep"))
392 LOG_INTO_STEP(_L("DEFAULT! (unknown test step)"));
395 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));