os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0469.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0469.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,219 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// @internalComponent
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32std.h>
    1.22 +#include <e32std_private.h>
    1.23 +#include <u32std.h> 	// unicode builds
    1.24 +#include <e32base.h>
    1.25 +#include <e32base_private.h>
    1.26 +#include <e32Test.h>	// RTest headder
    1.27 +#include "testcaseroot.h"
    1.28 +#include "testcasewd.h"
    1.29 +#include "testcase0469.h"
    1.30 +
    1.31 +#define _REPEATS (oOpenIterations*3)
    1.32 +
    1.33 +
    1.34 +
    1.35 +// the name below is used to add a pointer to our construction method to a pointer MAP in 
    1.36 +// the class factory
    1.37 +_LIT(KTestCaseId,"PBASE-USB_OTGDI-0469");
    1.38 +const TTestCaseFactoryReceipt<CTestCase0469> CTestCase0469::iFactoryReceipt(KTestCaseId);	
    1.39 +
    1.40 +CTestCase0469* CTestCase0469::NewL(TBool aHost)
    1.41 +	{
    1.42 +	LOG_FUNC
    1.43 +	CTestCase0469* self = new (ELeave) CTestCase0469(aHost);
    1.44 +	CleanupStack::PushL(self);
    1.45 +	self->ConstructL();
    1.46 +	CleanupStack::Pop(self);
    1.47 +	return self;
    1.48 +	}
    1.49 +	
    1.50 +CTestCase0469::CTestCase0469(TBool aHost)
    1.51 +	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
    1.52 +	{
    1.53 +	LOG_FUNC
    1.54 +		
    1.55 +	} 
    1.56 +
    1.57 +/**
    1.58 + ConstructL
    1.59 +*/
    1.60 +void CTestCase0469::ConstructL()
    1.61 +	{
    1.62 +	LOG_FUNC
    1.63 +    iDualRoleCase = EFalse; // Not back to back
    1.64 +	BaseConstructL();
    1.65 +	}
    1.66 +
    1.67 +
    1.68 +CTestCase0469::~CTestCase0469()
    1.69 +	{
    1.70 +	LOG_FUNC
    1.71 +    iCollector.DestroyObservers();
    1.72 +	Cancel();
    1.73 +	}
    1.74 +
    1.75 +
    1.76 +void CTestCase0469::ExecuteTestCaseL()
    1.77 +	{
    1.78 +	LOG_FUNC
    1.79 +	iCaseStep = EPreconditions;
    1.80 +	iRepeats = 3;
    1.81 +	
    1.82 +	CActiveScheduler::Add(this);
    1.83 +	SelfComplete();
    1.84 +	}
    1.85 +
    1.86 +	
    1.87 +void CTestCase0469::DoCancel()
    1.88 +	{
    1.89 +	LOG_FUNC
    1.90 +	// cancel our timer
    1.91 +	iTimer.Cancel();
    1.92 +	}
    1.93 +
    1.94 +// handle event completion	
    1.95 +void CTestCase0469::RunStepL()
    1.96 +	{
    1.97 +	LOG_FUNC
    1.98 +	// Obtain the completion code for this CActive obj.
    1.99 +	TInt completionCode(iStatus.Int()); 
   1.100 +	TBuf<MAX_DSTRLEN> aDescription;
   1.101 +    //	15 seconds, should be plenty of time for 3 cycles of plug pulling
   1.102 +    const TInt KTestCase0469Timeout = 15000;
   1.103 +
   1.104 +	switch(iCaseStep)
   1.105 +		{
   1.106 +    case EPreconditions:
   1.107 +        LOG_STEPNAME(_L("EPreconditions"))
   1.108 +        iCaseStep = ELoadLdd;
   1.109 +        // prompt to insert connectors
   1.110 +        test.Printf(KInsertBCablePrompt);
   1.111 +        test.Printf(KRemoveAFromPC);
   1.112 +        test.Printf(KPressAnyKeyToContinue);
   1.113 +        RequestCharacter();			
   1.114 +        break;
   1.115 +			
   1.116 +    case ELoadLdd:
   1.117 +        LOG_STEPNAME(_L("ELoadLdd"))
   1.118 +        if (!StepLoadClient(0xF678/*use default settings for SRP/HNP support*/))
   1.119 +            {
   1.120 +            return TestFailed(KErrAbort, _L("Client Load Failure"));
   1.121 +            }
   1.122 +
   1.123 +        if (!StepLoadLDD())
   1.124 +            {
   1.125 +            return TestFailed(KErrAbort, _L("OTG Load Failure"));
   1.126 +            }
   1.127 +
   1.128 +        // subscribe to OTG states,events and messages now that it has loaded OK
   1.129 +        TRAPD(result, iCollector.CreateObserversL(*this));
   1.130 +        if (KErrNone != result)
   1.131 +            {
   1.132 +            return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
   1.133 +            }
   1.134 +        iCollector.ClearAllEvents();
   1.135 +
   1.136 +        iCaseStep = ELoopControl;
   1.137 +
   1.138 +		iCollector.AddStepTimeout(KTestCase0469Timeout);
   1.139 +
   1.140 +        SelfComplete();
   1.141 +        break;
   1.142 +			
   1.143 +    case ELoopControl:
   1.144 +        LOG_STEPNAME(_L("ELoopControl"))
   1.145 +
   1.146 +        // Check for timeout
   1.147 +        if (KTestCaseWatchdogTO == iStatus.Int())
   1.148 +            {
   1.149 +            iCollector.DestroyObservers();
   1.150 +            return TestFailed(KErrAbort, _L("Timeout"));
   1.151 +            }
   1.152 +
   1.153 +        if (iRepeats--)
   1.154 +            {
   1.155 +            RDebug::Printf("ELoopControl around again %d", iRepeats);
   1.156 +            iCaseStep = ETestVbusRise;
   1.157 +            }
   1.158 +        else
   1.159 +            {
   1.160 +            RDebug::Printf("ELoopControl we're done");
   1.161 +            iCaseStep = EUnloadLdd;
   1.162 +            }
   1.163 +        SelfComplete();
   1.164 +        break;
   1.165 +
   1.166 +    case ETestVbusRise:
   1.167 +        LOG_STEPNAME(_L("ETestVbusRise"))
   1.168 +        // Check for timeout
   1.169 +        if (KTestCaseWatchdogTO == iStatus.Int())
   1.170 +            {
   1.171 +            iCollector.DestroyObservers();
   1.172 +            return TestFailed(KErrAbort, _L("Timeout"));
   1.173 +            }
   1.174 +
   1.175 +        iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
   1.176 +        iCaseStep = ETestVbusFall;
   1.177 +        test.Printf(KInsertAIntoPC);
   1.178 +        SetActive();
   1.179 +        break;
   1.180 +
   1.181 +    case ETestVbusFall:
   1.182 +        LOG_STEPNAME(_L("ETestVbusFall"))
   1.183 +        // Check for timeout
   1.184 +        if (KTestCaseWatchdogTO == iStatus.Int())
   1.185 +            {
   1.186 +            iCollector.DestroyObservers();
   1.187 +            return TestFailed(KErrAbort, _L("Timeout"));
   1.188 +            }
   1.189 +
   1.190 +        iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
   1.191 +        iCaseStep = ELoopControl;
   1.192 +        test.Printf(KRemoveAFromPC);
   1.193 +        SetActive();
   1.194 +        break;
   1.195 +
   1.196 +    case EUnloadLdd:
   1.197 +        LOG_STEPNAME(_L("EUnloadLdd"))
   1.198 +        iCollector.DestroyObservers();
   1.199 +        RDebug::Printf("Destroyed observers");
   1.200 +        if (EFalse == StepUnloadLDD())
   1.201 +            return TestFailed(KErrAbort,_L("unload Ldd failure"));	
   1.202 +        RDebug::Printf("unloaded ldd");
   1.203 +        if (!StepUnloadClient())
   1.204 +            return TestFailed(KErrAbort,_L("Client Unload Failure"));	
   1.205 +        RDebug::Printf("unloaded client");
   1.206 +
   1.207 +        iCaseStep = ELastStep;
   1.208 +        SelfComplete();
   1.209 +        break;
   1.210 +			
   1.211 +    case ELastStep:
   1.212 +        LOG_STEPNAME(_L("ELastStep"))
   1.213 +        TestPassed();
   1.214 +        break;
   1.215 +			
   1.216 +    default:
   1.217 +        test.Printf(_L("<Error> unknown test step"));
   1.218 +        Cancel();
   1.219 +        return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   1.220 +		}
   1.221 +	}
   1.222 +