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