os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0460.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
// @internalComponent
sl@0
    15
// 'A' connector removal test
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include <e32std.h>
sl@0
    20
#include <e32std_private.h>
sl@0
    21
#include <u32std.h> 	// unicode builds
sl@0
    22
#include <e32base.h>
sl@0
    23
#include <e32base_private.h>
sl@0
    24
#include <e32Test.h>	// RTest headder
sl@0
    25
#include "testcaseroot.h"
sl@0
    26
#include "testcasefactory.h"
sl@0
    27
#include "testcase0460.h"
sl@0
    28
sl@0
    29
sl@0
    30
sl@0
    31
sl@0
    32
// the name below is used to add a pointer to our construction method to a pointer MAP in 
sl@0
    33
// the class factory
sl@0
    34
_LIT(KTestCaseId,"PBASE-USB_OTGDI-0460");
sl@0
    35
const TTestCaseFactoryReceipt<CTestCase0460> CTestCase0460::iFactoryReceipt(KTestCaseId);	
sl@0
    36
sl@0
    37
CTestCase0460* CTestCase0460::NewL(TBool aHost)
sl@0
    38
	{
sl@0
    39
	LOG_FUNC
sl@0
    40
	CTestCase0460* self = new (ELeave) CTestCase0460(aHost);
sl@0
    41
	CleanupStack::PushL(self);
sl@0
    42
	self->ConstructL();
sl@0
    43
	CleanupStack::Pop(self);
sl@0
    44
	return self;
sl@0
    45
	}
sl@0
    46
	
sl@0
    47
sl@0
    48
CTestCase0460::CTestCase0460(TBool aHost)
sl@0
    49
:	CTestCaseRoot(KTestCaseId, aHost)
sl@0
    50
	{
sl@0
    51
	LOG_FUNC
sl@0
    52
		
sl@0
    53
	} 
sl@0
    54
sl@0
    55
sl@0
    56
/**
sl@0
    57
 ConstructL
sl@0
    58
*/
sl@0
    59
void CTestCase0460::ConstructL()
sl@0
    60
	{
sl@0
    61
	LOG_FUNC
sl@0
    62
	
sl@0
    63
	BaseConstructL();
sl@0
    64
	}
sl@0
    65
sl@0
    66
sl@0
    67
CTestCase0460::~CTestCase0460()
sl@0
    68
	{
sl@0
    69
	LOG_FUNC
sl@0
    70
sl@0
    71
	Cancel();
sl@0
    72
	}
sl@0
    73
sl@0
    74
sl@0
    75
void CTestCase0460::ExecuteTestCaseL()
sl@0
    76
	{
sl@0
    77
	LOG_FUNC
sl@0
    78
	iCaseStep = EPreconditions;
sl@0
    79
	
sl@0
    80
	CActiveScheduler::Add(this);
sl@0
    81
	SelfComplete();
sl@0
    82
sl@0
    83
	}
sl@0
    84
sl@0
    85
sl@0
    86
void CTestCase0460::DescribePreconditions()
sl@0
    87
	{
sl@0
    88
	test.Printf(_L("Insert 'A' connector beforehand.\n"));
sl@0
    89
	}
sl@0
    90
sl@0
    91
	
sl@0
    92
void CTestCase0460::DoCancel()
sl@0
    93
	{
sl@0
    94
	LOG_FUNC
sl@0
    95
sl@0
    96
	// cancel our timer
sl@0
    97
	iTimer.Cancel();
sl@0
    98
	}
sl@0
    99
	
sl@0
   100
sl@0
   101
// handle event completion	
sl@0
   102
void CTestCase0460::RunStepL()
sl@0
   103
	{
sl@0
   104
	LOG_FUNC
sl@0
   105
	// Obtain the completion code for this CActive obj.
sl@0
   106
	TInt completionCode(iStatus.Int()); 
sl@0
   107
	TBuf<MAX_DSTRLEN> aDescription;
sl@0
   108
		
sl@0
   109
	switch(iCaseStep)
sl@0
   110
		{
sl@0
   111
		case EPreconditions:
sl@0
   112
			iCaseStep = ELoadLdd;
sl@0
   113
			if (iAutomated)
sl@0
   114
				{
sl@0
   115
				iCaseStep = ELoadLdd;
sl@0
   116
				SelfComplete();
sl@0
   117
				break;
sl@0
   118
				}
sl@0
   119
			// prompt to remove connector
sl@0
   120
			test.Printf(KRemoveAConnectorPrompt);
sl@0
   121
			test.Printf(KPressAnyKeyToContinue);
sl@0
   122
			RequestCharacter();			
sl@0
   123
			break;
sl@0
   124
			
sl@0
   125
		case ELoadLdd:
sl@0
   126
			if (!StepLoadLDD())
sl@0
   127
				{
sl@0
   128
				break;
sl@0
   129
				}
sl@0
   130
sl@0
   131
			iCaseStep = ERegisterForEvents;
sl@0
   132
			iDequeAttempts = 0;	
sl@0
   133
sl@0
   134
			// prompt to insert connector
sl@0
   135
			test.Printf(KInsertAConnectorPrompt);
sl@0
   136
			test.Printf(KPressAnyKeyToContinue);
sl@0
   137
			RequestCharacter();			
sl@0
   138
			break;
sl@0
   139
			// wait on ID_PIN
sl@0
   140
		case ERegisterForEvents:
sl@0
   141
			if (iDequeAttempts > KOperationRetriesMax)
sl@0
   142
				{
sl@0
   143
				return (TestFailed(KErrCorrupt, _L("<Error> too many irrelevant/incorrect events")));
sl@0
   144
				}
sl@0
   145
			iCaseStep = ETestStateA;
sl@0
   146
sl@0
   147
			test.Printf(_L("Waiting for OTG Event\n"));
sl@0
   148
			otgQueueOtgEventRequest( iOTGEvent, iStatus);
sl@0
   149
sl@0
   150
			SetActive();
sl@0
   151
			break;
sl@0
   152
			
sl@0
   153
		case EDriveID_PIN:
sl@0
   154
			// API call for simulating ID_PIN is not implemented, so the user plugs in the cable, 
sl@0
   155
			// then test for A plug
sl@0
   156
			SetActive();
sl@0
   157
			break;
sl@0
   158
			
sl@0
   159
		case EWait5:
sl@0
   160
		case ETestStateA:
sl@0
   161
			OtgEventString(iOTGEvent, aDescription);
sl@0
   162
			test.Printf(_L("Received event %d '%S' status(%d)"), iOTGEvent, &aDescription, completionCode);
sl@0
   163
			if (RUsbOtgDriver::EEventAPlugInserted == iOTGEvent)
sl@0
   164
				{
sl@0
   165
				iCaseStep = EUnloadLdd;
sl@0
   166
				}
sl@0
   167
			else
sl@0
   168
				{
sl@0
   169
				// wrong event in the Q already, keep at it
sl@0
   170
				iCaseStep = ERegisterForEvents;	
sl@0
   171
				iDequeAttempts++;
sl@0
   172
				}
sl@0
   173
	
sl@0
   174
			SelfComplete();
sl@0
   175
			break;		
sl@0
   176
			
sl@0
   177
		case EUnloadLdd:
sl@0
   178
		case ELastStep:
sl@0
   179
			if (EFalse == StepUnloadLDD())
sl@0
   180
				return TestFailed(KErrAbort,_L("unload Ldd failure"));	
sl@0
   181
			
sl@0
   182
			return TestPassed();
sl@0
   183
sl@0
   184
		default:
sl@0
   185
			test.Printf(_L("<Error> unknown test step"));
sl@0
   186
			Cancel();
sl@0
   187
			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
sl@0
   188
sl@0
   189
		}
sl@0
   190
	}
sl@0
   191