kerneltest/e32test/usbho/t_otgdi/src/testcase0682.cpp
changeset 253 d37db4dcc88d
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
252:0a40b8675b23 253:d37db4dcc88d
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    22 #include <e32base_private.h>
    22 #include <e32base_private.h>
    23 #include <e32Test.h>	// RTest headder
    23 #include <e32Test.h>	// RTest headder
    24 #include "testcaseroot.h"
    24 #include "testcaseroot.h"
    25 #include "b2bwatchers.h"
    25 #include "b2bwatchers.h"
    26 #include "testcase0682.h"
    26 #include "testcase0682.h"
       
    27 #include "OstTraceDefinitions.h"
       
    28 #ifdef OST_TRACE_COMPILER_IN_USE
       
    29 #include "testcase0682Traces.h"
       
    30 #endif
    27 
    31 
    28 #define _REPEATS (oOpenIterations*3)
    32 #define _REPEATS (oOpenIterations*3)
    29 
    33 
    30 /* **************************************************************************************
    34 /* **************************************************************************************
    31  * the name below is used to add a pointer to our construction method to a pointer MAP in 
    35  * the name below is used to add a pointer to our construction method to a pointer MAP in 
    34 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0682");
    38 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0682");
    35 const TTestCaseFactoryReceipt<CTestCase0682> CTestCase0682::iFactoryReceipt(KTestCaseId);	
    39 const TTestCaseFactoryReceipt<CTestCase0682> CTestCase0682::iFactoryReceipt(KTestCaseId);	
    36 
    40 
    37 CTestCase0682* CTestCase0682::NewL(TBool aHost)
    41 CTestCase0682* CTestCase0682::NewL(TBool aHost)
    38 	{
    42 	{
    39 	LOG_FUNC
    43 	if(gVerboseOutput)
       
    44 	    {
       
    45 	    OstTraceFunctionEntry0(CTESTCASE0682_NEWL);
       
    46 	    }
    40 	CTestCase0682* self = new (ELeave) CTestCase0682(aHost);
    47 	CTestCase0682* self = new (ELeave) CTestCase0682(aHost);
    41 	CleanupStack::PushL(self);
    48 	CleanupStack::PushL(self);
    42 	self->ConstructL();
    49 	self->ConstructL();
    43 	CleanupStack::Pop(self);
    50 	CleanupStack::Pop(self);
    44 	return self;
    51 	return self;
    47 
    54 
    48 CTestCase0682::CTestCase0682(TBool aHost)
    55 CTestCase0682::CTestCase0682(TBool aHost)
    49 : 	CTestCaseB2BRoot(KTestCaseId, aHost, iStatus),
    56 : 	CTestCaseB2BRoot(KTestCaseId, aHost, iStatus),
    50 	iFirstRoleSwap(ETrue)
    57 	iFirstRoleSwap(ETrue)
    51 	{
    58 	{
    52 	LOG_FUNC
    59 	if(gVerboseOutput)
       
    60 	    {
       
    61 	    OstTraceFunctionEntry0(CTESTCASE0682_CTESTCASE0682);
       
    62 	    }
    53 		
    63 		
    54 	} 
    64 	} 
    55 
    65 
    56 
    66 
    57 /**
    67 /**
    58  ConstructL
    68  ConstructL
    59 */
    69 */
    60 void CTestCase0682::ConstructL()
    70 void CTestCase0682::ConstructL()
    61 	{
    71 	{
    62 	LOG_FUNC
    72 	if(gVerboseOutput)
       
    73 	    {
       
    74 	    OstTraceFunctionEntry0(CTESTCASE0682_CONSTRUCTL);
       
    75 	    }
    63 
    76 
    64 	iDualRoleCase = ETrue;	// another back-back
    77 	iDualRoleCase = ETrue;	// another back-back
    65 		
    78 		
    66 	BaseConstructL();
    79 	BaseConstructL();
    67 	}
    80 	}
    68 
    81 
    69 
    82 
    70 CTestCase0682::~CTestCase0682()
    83 CTestCase0682::~CTestCase0682()
    71 	{
    84 	{
    72 	LOG_FUNC
    85 	if(gVerboseOutput)
       
    86 	    {
       
    87 	    OstTraceFunctionEntry0(CTESTCASE0682_DCTESTCASE0682);
       
    88 	    }
    73 	iCollector.DestroyObservers();
    89 	iCollector.DestroyObservers();
    74 	Cancel();
    90 	Cancel();
    75 	}
    91 	}
    76 
    92 
    77 
    93 
    78 void CTestCase0682::ExecuteTestCaseL()
    94 void CTestCase0682::ExecuteTestCaseL()
    79 	{
    95 	{
    80 	LOG_FUNC
    96 	if(gVerboseOutput)
       
    97 	    {
       
    98 	    OstTraceFunctionEntry0(CTESTCASE0682_EXECUTETESTCASEL);
       
    99 	    }
    81 	iCaseStep = EPreconditions;
   100 	iCaseStep = EPreconditions;
    82 	iHNPCounter = 3;	//	To be decremented to govern the number of times we do HNP.
   101 	iHNPCounter = 3;	//	To be decremented to govern the number of times we do HNP.
    83 	CActiveScheduler::Add(this);
   102 	CActiveScheduler::Add(this);
    84 	SelfComplete();
   103 	SelfComplete();
    85 	}
   104 	}
    86 
   105 
    87 	
   106 	
    88 void CTestCase0682::DoCancel()
   107 void CTestCase0682::DoCancel()
    89 	{
   108 	{
    90 	LOG_FUNC
   109 	if(gVerboseOutput)
       
   110 	    {
       
   111 	    OstTraceFunctionEntry0(CTESTCASE0682_DOCANCEL);
       
   112 	    }
    91 	// cancel our timer
   113 	// cancel our timer
    92 	iTimer.Cancel();
   114 	iTimer.Cancel();
    93 	}
   115 	}
    94 
   116 
    95 void CTestCase0682::StepB2BPreconditions()
   117 void CTestCase0682::StepB2BPreconditions()
    96 	{
   118 	{
    97 	// prompt to insert connector and activate A-end first...
   119 	// prompt to insert connector and activate A-end first...
    98 	if (gTestRoleMaster)
   120 	if (gTestRoleMaster)
    99 		{ // "B" device
   121 		{ // "B" device
   100 		test.Printf(_L("***** Important note *****\n"));
   122 		test.Printf(_L("***** Important note *****\n"));
       
   123 		OstTrace0(TRACE_NORMAL, CTESTCASE0682_STEPB2BPRECONDITIONS, "***** Important note *****\n");
   101 		test.Printf(_L("Before commencing test, please\n"));
   124 		test.Printf(_L("Before commencing test, please\n"));
       
   125 		OstTrace0(TRACE_NORMAL, CTESTCASE0682_STEPB2BPRECONDITIONS_DUP01, "Before commencing test, please\n");
   102 		test.Printf(_L("insert 'B'-cable end and activate\n"));
   126 		test.Printf(_L("insert 'B'-cable end and activate\n"));
       
   127 		OstTrace0(TRACE_NORMAL, CTESTCASE0682_STEPB2BPRECONDITIONS_DUP02, "insert 'B'-cable end and activate\n");
   103 		test.Printf(_L("the test on the 'A' device.\n"));
   128 		test.Printf(_L("the test on the 'A' device.\n"));
       
   129 		OstTrace0(TRACE_NORMAL, CTESTCASE0682_STEPB2BPRECONDITIONS_DUP03, "the test on the 'A' device.\n");
   104 		test.Printf(_L("Then, press any key to continue.\n"));
   130 		test.Printf(_L("Then, press any key to continue.\n"));
       
   131 		OstTrace0(TRACE_NORMAL, CTESTCASE0682_STEPB2BPRECONDITIONS_DUP04, "Then, press any key to continue.\n");
   105 		test.Printf(_L("**************************\n"));
   132 		test.Printf(_L("**************************\n"));
       
   133 		OstTrace0(TRACE_NORMAL, CTESTCASE0682_STEPB2BPRECONDITIONS_DUP05, "**************************\n");
   106 		}
   134 		}
   107 	else
   135 	else
   108 		{
   136 		{
   109 		test.Printf(KInsertACablePrompt);
   137 		test.Printf(KInsertACablePrompt);
       
   138 		OstTrace0(TRACE_NORMAL, CTESTCASE0682_STEPB2BPRECONDITIONS_DUP06, KInsertACablePrompt);
   110 		test.Printf(KPressAnyKeyToContinue);
   139 		test.Printf(KPressAnyKeyToContinue);
       
   140 		OstTrace0(TRACE_NORMAL, CTESTCASE0682_STEPB2BPRECONDITIONS_DUP07, KPressAnyKeyToContinue);
   111 		}
   141 		}
   112 
   142 
   113 	RequestCharacter();	
   143 	RequestCharacter();	
   114 	}
   144 	}
   115 
   145 
   116 // handle event completion	
   146 // handle event completion	
   117 void CTestCase0682::RunStepL()
   147 void CTestCase0682::RunStepL()
   118 	{
   148 	{
   119 	LOG_FUNC
   149 	if(gVerboseOutput)
       
   150 	    {
       
   151 	    OstTraceFunctionEntry0(CTESTCASE0682_RUNSTEPL);
       
   152 	    }
   120 	// Obtain the completion code for this CActive obj.
   153 	// Obtain the completion code for this CActive obj.
   121 	TInt completionCode(iStatus.Int()); 
   154 	TInt completionCode(iStatus.Int()); 
   122 	TBuf<MAX_DSTRLEN> aDescription;
   155 	TBuf<MAX_DSTRLEN> aDescription;
   123 	TInt err(0);
   156 	TInt err(0);
   124 
   157 
   165 			}
   198 			}
   166 			
   199 			
   167 		case EPerformSrp:
   200 		case EPerformSrp:
   168 			{
   201 			{
   169 			test.Printf(_L("Into EPerformSrp step...\n"));
   202 			test.Printf(_L("Into EPerformSrp step...\n"));
       
   203 			OstTrace0(TRACE_NORMAL, CTESTCASE0682_RUNSTEPL_DUP01, "Into EPerformSrp step...\n");
   170 
   204 
   171 			if (gTestRoleMaster)
   205 			if (gTestRoleMaster)
   172 				{
   206 				{
   173 				// Trigger SRP
   207 				// Trigger SRP
   174 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
   208 				iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
   198 			}
   232 			}
   199 
   233 
   200 		case EAReceivedSrp:		//	A-Device step only!
   234 		case EAReceivedSrp:		//	A-Device step only!
   201 			{
   235 			{
   202 			test.Printf(_L("Into EAReceivedSrp step...\n"));
   236 			test.Printf(_L("Into EAReceivedSrp step...\n"));
       
   237 			OstTrace0(TRACE_NORMAL, CTESTCASE0682_RUNSTEPL_DUP02, "Into EAReceivedSrp step...\n");
   203 
   238 
   204 			if (KTestCaseWatchdogTO == iStatus.Int())
   239 			if (KTestCaseWatchdogTO == iStatus.Int())
   205 				{
   240 				{
   206 				iCollector.DestroyObservers();
   241 				iCollector.DestroyObservers();
   207 				return TestFailed(KErrAbort, _L("Timeout"));
   242 				return TestFailed(KErrAbort, _L("Timeout"));
   226 			}
   261 			}
   227 			
   262 			
   228 		case EDefaultRoles:
   263 		case EDefaultRoles:
   229 			{
   264 			{
   230 			test.Printf(_L("Into EDefaultRoles step...\n"));
   265 			test.Printf(_L("Into EDefaultRoles step...\n"));
       
   266 			OstTrace0(TRACE_NORMAL, CTESTCASE0682_RUNSTEPL_DUP03, "Into EDefaultRoles step...\n");
   231 			
   267 			
   232 			if ( --iHNPCounter >= 0)
   268 			if ( --iHNPCounter >= 0)
   233 				{
   269 				{
   234 				//	We want to do further role swapping
   270 				//	We want to do further role swapping
   235 				if (gTestRoleMaster)
   271 				if (gTestRoleMaster)
   258 
   294 
   259 			
   295 			
   260 		case EBConfigured:	//	A B-Device only step!
   296 		case EBConfigured:	//	A B-Device only step!
   261 			{
   297 			{
   262 			test.Printf(_L("Into EBConfigured step...\n"));
   298 			test.Printf(_L("Into EBConfigured step...\n"));
       
   299 			OstTrace0(TRACE_NORMAL, CTESTCASE0682_RUNSTEPL_DUP04, "Into EBConfigured step...\n");
   263 			if (KTestCaseWatchdogTO == iStatus.Int())
   300 			if (KTestCaseWatchdogTO == iStatus.Int())
   264 				{
   301 				{
   265 				iCollector.DestroyObservers();
   302 				iCollector.DestroyObservers();
   266 				return TestFailed(KErrAbort, _L("Timeout"));
   303 				return TestFailed(KErrAbort, _L("Timeout"));
   267 				}
   304 				}
   272 			}
   309 			}
   273 			
   310 			
   274 		case EBSuspended:	
   311 		case EBSuspended:	
   275 			{
   312 			{
   276 			test.Printf(_L("Into EBSuspended step...\n"));
   313 			test.Printf(_L("Into EBSuspended step...\n"));
       
   314 			OstTrace0(TRACE_NORMAL, CTESTCASE0682_RUNSTEPL_DUP05, "Into EBSuspended step...\n");
   277 			if (KTestCaseWatchdogTO == iStatus.Int())
   315 			if (KTestCaseWatchdogTO == iStatus.Int())
   278 				{
   316 				{
   279 				iCollector.DestroyObservers();
   317 				iCollector.DestroyObservers();
   280 				return TestFailed(KErrAbort, _L("Timeout"));
   318 				return TestFailed(KErrAbort, _L("Timeout"));
   281 				}			
   319 				}			
   290 				{
   328 				{
   291 				err = otgBusRequest();	//	Request the host role
   329 				err = otgBusRequest();	//	Request the host role
   292 				if (KErrNone != err)
   330 				if (KErrNone != err)
   293 					{
   331 					{
   294 					test.Printf(_L("BusRequest returned %d\n"),err);
   332 					test.Printf(_L("BusRequest returned %d\n"),err);
       
   333 					OstTrace1(TRACE_NORMAL, CTESTCASE0682_RUNSTEPL_DUP06, "BusRequest returned %d\n",err);
   295 					return TestFailed(KErrAbort, _L("BusRequest() failed!"));
   334 					return TestFailed(KErrAbort, _L("BusRequest() failed!"));
   296 					}
   335 					}
   297 				}
   336 				}
   298 			else
   337 			else
   299 				{
   338 				{
   307 			}
   346 			}
   308 			
   347 			
   309 		case ESwappedRoles:
   348 		case ESwappedRoles:
   310 			{
   349 			{
   311 			test.Printf(_L("Into ESwappedRoles step...\n"));
   350 			test.Printf(_L("Into ESwappedRoles step...\n"));
       
   351 			OstTrace0(TRACE_NORMAL, CTESTCASE0682_RUNSTEPL_DUP07, "Into ESwappedRoles step...\n");
   312 			if (KTestCaseWatchdogTO == iStatus.Int())
   352 			if (KTestCaseWatchdogTO == iStatus.Int())
   313 				{
   353 				{
   314 				iCollector.DestroyObservers();
   354 				iCollector.DestroyObservers();
   315 				return TestFailed(KErrAbort, _L("Timeout"));
   355 				return TestFailed(KErrAbort, _L("Timeout"));
   316 				}			
   356 				}			
   332 			}
   372 			}
   333 			
   373 			
   334 		case EAConfigured:	//	A-Device only step
   374 		case EAConfigured:	//	A-Device only step
   335 			{
   375 			{
   336 			test.Printf(_L("Into EWaitTillAConfigured step...\n"));
   376 			test.Printf(_L("Into EWaitTillAConfigured step...\n"));
       
   377 			OstTrace0(TRACE_NORMAL, CTESTCASE0682_RUNSTEPL_DUP08, "Into EWaitTillAConfigured step...\n");
   337 			if (KTestCaseWatchdogTO == iStatus.Int())
   378 			if (KTestCaseWatchdogTO == iStatus.Int())
   338 				{
   379 				{
   339 				iCollector.DestroyObservers();
   380 				iCollector.DestroyObservers();
   340 				return TestFailed(KErrAbort, _L("Timeout"));
   381 				return TestFailed(KErrAbort, _L("Timeout"));
   341 				}			
   382 				}			
   347 			}
   388 			}
   348 		
   389 		
   349 		case EASuspended:	//	A-Device only step
   390 		case EASuspended:	//	A-Device only step
   350 			{
   391 			{
   351 			test.Printf(_L("Into EWaitTillASuspended step...\n"));
   392 			test.Printf(_L("Into EWaitTillASuspended step...\n"));
       
   393 			OstTrace0(TRACE_NORMAL, CTESTCASE0682_RUNSTEPL_DUP09, "Into EWaitTillASuspended step...\n");
   352 			if (KTestCaseWatchdogTO == iStatus.Int())
   394 			if (KTestCaseWatchdogTO == iStatus.Int())
   353 				{
   395 				{
   354 				iCollector.DestroyObservers();
   396 				iCollector.DestroyObservers();
   355 				return TestFailed(KErrAbort, _L("Timeout"));
   397 				return TestFailed(KErrAbort, _L("Timeout"));
   356 				}			
   398 				}			
   414 			TestPassed();
   456 			TestPassed();
   415 			break;
   457 			break;
   416 			
   458 			
   417 		default:
   459 		default:
   418 			test.Printf(_L("<Error> unknown test step"));
   460 			test.Printf(_L("<Error> unknown test step"));
       
   461 			OstTrace0(TRACE_NORMAL, CTESTCASE0682_RUNSTEPL_DUP10, "<Error> unknown test step");
   419 			Cancel();
   462 			Cancel();
   420 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   463 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   421 		}
   464 		}
   422 	}
   465 	}