kerneltest/e32test/usbho/t_otgdi/src/testcase0678.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".
    23 #include <e32Test.h>	// RTest headder
    23 #include <e32Test.h>	// RTest headder
    24 #include "testcaseroot.h"
    24 #include "testcaseroot.h"
    25 //#include "testcasewd.h"
    25 //#include "testcasewd.h"
    26 #include "b2bwatchers.h"
    26 #include "b2bwatchers.h"
    27 #include "testcase0678.h"
    27 #include "testcase0678.h"
    28 #include "OstTraceDefinitions.h"
       
    29 #ifdef OST_TRACE_COMPILER_IN_USE
       
    30 #include "testcase0678Traces.h"
       
    31 #endif
       
    32 
    28 
    33 #define _REPEATS (oOpenIterations*3)
    29 #define _REPEATS (oOpenIterations*3)
    34 
    30 
    35 
    31 
    36 /* **************************************************************************************
    32 /* **************************************************************************************
    40 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0678");
    36 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0678");
    41 const TTestCaseFactoryReceipt<CTestCase0678> CTestCase0678::iFactoryReceipt(KTestCaseId);	
    37 const TTestCaseFactoryReceipt<CTestCase0678> CTestCase0678::iFactoryReceipt(KTestCaseId);	
    42 
    38 
    43 CTestCase0678* CTestCase0678::NewL(TBool aHost)
    39 CTestCase0678* CTestCase0678::NewL(TBool aHost)
    44 	{
    40 	{
    45 	if(gVerboseOutput)
    41 	LOG_FUNC
    46 	    {
       
    47 	    OstTraceFunctionEntry0(CTESTCASE0678_NEWL);
       
    48 	    }
       
    49 	CTestCase0678* self = new (ELeave) CTestCase0678(aHost);
    42 	CTestCase0678* self = new (ELeave) CTestCase0678(aHost);
    50 	CleanupStack::PushL(self);
    43 	CleanupStack::PushL(self);
    51 	self->ConstructL();
    44 	self->ConstructL();
    52 	CleanupStack::Pop(self);
    45 	CleanupStack::Pop(self);
    53 	return self;
    46 	return self;
    55 	
    48 	
    56 
    49 
    57 CTestCase0678::CTestCase0678(TBool aHost)
    50 CTestCase0678::CTestCase0678(TBool aHost)
    58 	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
    51 	: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) 
    59 	{
    52 	{
    60 	if(gVerboseOutput)
    53 	LOG_FUNC
    61 	    {
       
    62 	    OstTraceFunctionEntry0(CTESTCASE0678_CTESTCASE0678);
       
    63 	    }
       
    64 		
    54 		
    65 	} 
    55 	} 
    66 
    56 
    67 
    57 
    68 /**
    58 /**
    69  ConstructL
    59  ConstructL
    70 */
    60 */
    71 void CTestCase0678::ConstructL()
    61 void CTestCase0678::ConstructL()
    72 	{
    62 	{
    73 	if(gVerboseOutput)
    63 	LOG_FUNC
    74 	    {
       
    75 	    OstTraceFunctionEntry0(CTESTCASE0678_CONSTRUCTL);
       
    76 	    }
       
    77 
    64 
    78 	iDualRoleCase = ETrue;	// another back-back
    65 	iDualRoleCase = ETrue;	// another back-back
    79 		
    66 		
    80 	BaseConstructL();
    67 	BaseConstructL();
    81 	}
    68 	}
    82 
    69 
    83 
    70 
    84 CTestCase0678::~CTestCase0678()
    71 CTestCase0678::~CTestCase0678()
    85 	{
    72 	{
    86 	if(gVerboseOutput)
    73 	LOG_FUNC
    87 	    {
       
    88 	    OstTraceFunctionEntry0(CTESTCASE0678_DCTESTCASE0678);
       
    89 	    }
       
    90 	iCollector.DestroyObservers();
    74 	iCollector.DestroyObservers();
    91 	Cancel();
    75 	Cancel();
    92 	}
    76 	}
    93 
    77 
    94 
    78 
    95 void CTestCase0678::ExecuteTestCaseL()
    79 void CTestCase0678::ExecuteTestCaseL()
    96 	{
    80 	{
    97 	if(gVerboseOutput)
    81 	LOG_FUNC
    98 	    {
       
    99 	    OstTraceFunctionEntry0(CTESTCASE0678_EXECUTETESTCASEL);
       
   100 	    }
       
   101 	iCaseStep = EPreconditions;
    82 	iCaseStep = EPreconditions;
   102 	iHNPCounter = 3;	//	To be decremented to govern the number of times we do HNP.
    83 	iHNPCounter = 3;	//	To be decremented to govern the number of times we do HNP.
   103 	CActiveScheduler::Add(this);
    84 	CActiveScheduler::Add(this);
   104 	SelfComplete();
    85 	SelfComplete();
   105 	}
    86 	}
   106 
    87 
   107 	
    88 	
   108 void CTestCase0678::DoCancel()
    89 void CTestCase0678::DoCancel()
   109 	{
    90 	{
   110 	if(gVerboseOutput)
    91 	LOG_FUNC
   111 	    {
       
   112 	    OstTraceFunctionEntry0(CTESTCASE0678_DOCANCEL);
       
   113 	    }
       
   114 	// cancel our timer
    92 	// cancel our timer
   115 	iTimer.Cancel();
    93 	iTimer.Cancel();
   116 	}
    94 	}
   117 
    95 
   118 
    96 
   119 // handle event completion	
    97 // handle event completion	
   120 void CTestCase0678::RunStepL()
    98 void CTestCase0678::RunStepL()
   121 	{
    99 	{
   122 	if(gVerboseOutput)
   100 	LOG_FUNC
   123 	    {
       
   124 	    OstTraceFunctionEntry0(CTESTCASE0678_RUNSTEPL);
       
   125 	    }
       
   126 	// Obtain the completion code for this CActive obj.
   101 	// Obtain the completion code for this CActive obj.
   127 	TInt completionCode(iStatus.Int()); 
   102 	TInt completionCode(iStatus.Int()); 
   128 	TBuf<MAX_DSTRLEN> aDescription;
   103 	TBuf<MAX_DSTRLEN> aDescription;
   129 	TInt err(0);
   104 	TInt err(0);
   130 
   105 
   201 			}
   176 			}
   202 			
   177 			
   203 		case EDefaultRoles:
   178 		case EDefaultRoles:
   204 			{
   179 			{
   205 			test.Printf(_L("Into EDefaultRoles step...\n"));
   180 			test.Printf(_L("Into EDefaultRoles step...\n"));
   206 			OstTrace0(TRACE_NORMAL, CTESTCASE0678_RUNSTEPL_DUP01, "Into EDefaultRoles step...\n");
       
   207 			
   181 			
   208 			if ( --iHNPCounter >= 0)
   182 			if ( --iHNPCounter >= 0)
   209 				{
   183 				{
   210 				//	We want to do further role swapping
   184 				//	We want to do further role swapping
   211 				if (gTestRoleMaster)
   185 				if (gTestRoleMaster)
   234 
   208 
   235 			
   209 			
   236 		case EBConfigured:	//	A B-Device only step!
   210 		case EBConfigured:	//	A B-Device only step!
   237 			{
   211 			{
   238 			test.Printf(_L("Into EBConfigured step...\n"));
   212 			test.Printf(_L("Into EBConfigured step...\n"));
   239 			OstTrace0(TRACE_NORMAL, CTESTCASE0678_RUNSTEPL_DUP02, "Into EBConfigured step...\n");
       
   240 			if (KTestCaseWatchdogTO == iStatus.Int())
   213 			if (KTestCaseWatchdogTO == iStatus.Int())
   241 				{
   214 				{
   242 				iCollector.DestroyObservers();
   215 				iCollector.DestroyObservers();
   243 				return TestFailed(KErrAbort, _L("Timeout"));
   216 				return TestFailed(KErrAbort, _L("Timeout"));
   244 				}
   217 				}
   249 			}
   222 			}
   250 			
   223 			
   251 		case EBSuspended:	
   224 		case EBSuspended:	
   252 			{
   225 			{
   253 			test.Printf(_L("Into EBSuspended step...\n"));
   226 			test.Printf(_L("Into EBSuspended step...\n"));
   254 			OstTrace0(TRACE_NORMAL, CTESTCASE0678_RUNSTEPL_DUP03, "Into EBSuspended step...\n");
       
   255 			if (KTestCaseWatchdogTO == iStatus.Int())
   227 			if (KTestCaseWatchdogTO == iStatus.Int())
   256 				{
   228 				{
   257 				iCollector.DestroyObservers();
   229 				iCollector.DestroyObservers();
   258 				return TestFailed(KErrAbort, _L("Timeout"));
   230 				return TestFailed(KErrAbort, _L("Timeout"));
   259 				}			
   231 				}			
   260 			
   232 			
   261 			// issue HNP
   233 			// issue HNP
   262 			test.Printf(_L("VBus present, attempting a swap.\n"));
   234 			test.Printf(_L("VBus present, attempting a swap.\n"));
   263 			OstTrace0(TRACE_NORMAL, CTESTCASE0678_RUNSTEPL_DUP04, "VBus present, attempting a swap.\n");
       
   264 			iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
   235 			iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
   265 
   236 
   266 			err = otgBusRequest();	//	Request the host role
   237 			err = otgBusRequest();	//	Request the host role
   267 
   238 
   268 			if (KErrNone != err)
   239 			if (KErrNone != err)
   269 				{
   240 				{
   270 				test.Printf(_L("BusRequest returned %d\n"),err);
   241 				test.Printf(_L("BusRequest returned %d\n"),err);
   271 				OstTrace1(TRACE_NORMAL, CTESTCASE0678_RUNSTEPL_DUP05, "BusRequest returned %d\n",err);
       
   272 				return TestFailed(KErrAbort, _L("BusRequest() failed!"));
   242 				return TestFailed(KErrAbort, _L("BusRequest() failed!"));
   273 				}
   243 				}
   274 		
   244 		
   275 			iCaseStep = ESwappedRoles;
   245 			iCaseStep = ESwappedRoles;
   276 			SetActive();
   246 			SetActive();
   278 			}
   248 			}
   279 			
   249 			
   280 		case ESwappedRoles:
   250 		case ESwappedRoles:
   281 			{
   251 			{
   282 			test.Printf(_L("Into ESwappedRoles step...\n"));
   252 			test.Printf(_L("Into ESwappedRoles step...\n"));
   283 			OstTrace0(TRACE_NORMAL, CTESTCASE0678_RUNSTEPL_DUP06, "Into ESwappedRoles step...\n");
       
   284 			if (KTestCaseWatchdogTO == iStatus.Int())
   253 			if (KTestCaseWatchdogTO == iStatus.Int())
   285 				{
   254 				{
   286 				iCollector.DestroyObservers();
   255 				iCollector.DestroyObservers();
   287 				return TestFailed(KErrAbort, _L("Timeout"));
   256 				return TestFailed(KErrAbort, _L("Timeout"));
   288 				}			
   257 				}			
   304 			}
   273 			}
   305 			
   274 			
   306 		case EAConfigured:	//	A-Device only step
   275 		case EAConfigured:	//	A-Device only step
   307 			{
   276 			{
   308 			test.Printf(_L("Into EWaitTillAConfigured step...\n"));
   277 			test.Printf(_L("Into EWaitTillAConfigured step...\n"));
   309 			OstTrace0(TRACE_NORMAL, CTESTCASE0678_RUNSTEPL_DUP07, "Into EWaitTillAConfigured step...\n");
       
   310 			if (KTestCaseWatchdogTO == iStatus.Int())
   278 			if (KTestCaseWatchdogTO == iStatus.Int())
   311 				{
   279 				{
   312 				iCollector.DestroyObservers();
   280 				iCollector.DestroyObservers();
   313 				return TestFailed(KErrAbort, _L("Timeout"));
   281 				return TestFailed(KErrAbort, _L("Timeout"));
   314 				}			
   282 				}			
   320 			}
   288 			}
   321 		
   289 		
   322 		case EASuspended:	//	A-Device only step
   290 		case EASuspended:	//	A-Device only step
   323 			{
   291 			{
   324 			test.Printf(_L("Into EWaitTillASuspended step...\n"));
   292 			test.Printf(_L("Into EWaitTillASuspended step...\n"));
   325 			OstTrace0(TRACE_NORMAL, CTESTCASE0678_RUNSTEPL_DUP08, "Into EWaitTillASuspended step...\n");
       
   326 			if (KTestCaseWatchdogTO == iStatus.Int())
   293 			if (KTestCaseWatchdogTO == iStatus.Int())
   327 				{
   294 				{
   328 				iCollector.DestroyObservers();
   295 				iCollector.DestroyObservers();
   329 				return TestFailed(KErrAbort, _L("Timeout"));
   296 				return TestFailed(KErrAbort, _L("Timeout"));
   330 				}			
   297 				}			
   388 			TestPassed();
   355 			TestPassed();
   389 			break;
   356 			break;
   390 			
   357 			
   391 		default:
   358 		default:
   392 			test.Printf(_L("<Error> unknown test step"));
   359 			test.Printf(_L("<Error> unknown test step"));
   393 			OstTrace0(TRACE_NORMAL, CTESTCASE0678_RUNSTEPL_DUP09, "<Error> unknown test step");
       
   394 			Cancel();
   360 			Cancel();
   395 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   361 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   396 		}
   362 		}
   397 	}
   363 	}
   398 
   364