kerneltest/e32test/usbho/t_otgdi/src/testcase0463.cpp
changeset 0 a41df078684a
child 253 d37db4dcc88d
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // @internalComponent
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <e32std_private.h>
       
    21 #include <u32std.h> 	// unicode builds
       
    22 #include <e32base.h>
       
    23 #include <e32base_private.h>
       
    24 #include <e32Test.h>	// RTest headder
       
    25 #include "testcaseroot.h"
       
    26 #include "testcase0463.h"
       
    27 
       
    28 
       
    29 
       
    30 
       
    31 // the name below is used to add a pointer to our construction method to a pointer MAP in 
       
    32 // the class factory
       
    33 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0463");
       
    34 const TTestCaseFactoryReceipt<CTestCase0463> CTestCase0463::iFactoryReceipt(KTestCaseId);	
       
    35 
       
    36 
       
    37 CTestCase0463* CTestCase0463::NewL(TBool aHost)
       
    38 	{
       
    39 	LOG_FUNC
       
    40 	CTestCase0463* self = new (ELeave) CTestCase0463(aHost);
       
    41 	CleanupStack::PushL(self);
       
    42 	self->ConstructL();
       
    43 	CleanupStack::Pop(self);
       
    44 	return self;
       
    45 	}
       
    46 	
       
    47 
       
    48 CTestCase0463::CTestCase0463(TBool aHost)
       
    49 :	CTestCaseRoot(KTestCaseId, aHost)
       
    50 	{	
       
    51 	LOG_FUNC
       
    52 	} 
       
    53 
       
    54 
       
    55 /**
       
    56  ConstructL
       
    57 */
       
    58 void CTestCase0463::ConstructL()
       
    59 	{
       
    60 	LOG_FUNC
       
    61 	iRepeats = OOMOPEN_REPEATS;
       
    62 	iAllocFailNumber = OOMOPEN_REPEATS + 1; // allocs 1..11 fail
       
    63 	
       
    64 	BaseConstructL();
       
    65 	}
       
    66 
       
    67 
       
    68 CTestCase0463::~CTestCase0463()
       
    69 	{
       
    70 	LOG_FUNC
       
    71 
       
    72 	Cancel();
       
    73 	}
       
    74 
       
    75 
       
    76 void CTestCase0463::ExecuteTestCaseL()
       
    77 	{
       
    78 	LOG_FUNC
       
    79 	iCaseStep = EMarkStack;
       
    80 	CActiveScheduler::Add(this);
       
    81 
       
    82 	SelfComplete();
       
    83 	
       
    84 	}
       
    85 
       
    86 void CTestCase0463::DescribePreconditions()
       
    87 	{
       
    88 	test.Printf(_L("Insert A connector beforehand.\n"));
       
    89 	}
       
    90 
       
    91 	
       
    92 void CTestCase0463::DoCancel()
       
    93 	{
       
    94 	LOG_FUNC
       
    95 
       
    96 	// cancel our timer
       
    97 	iTimer.Cancel();
       
    98 	}
       
    99 
       
   100 
       
   101 // handle event completion	
       
   102 void CTestCase0463::RunStepL()
       
   103 	{
       
   104 	LOG_FUNC
       
   105 
       
   106 	// Obtain the completion code for this CActive obj.
       
   107 	TInt completionCode(iStatus.Int()); 
       
   108 	
       
   109 	switch(iCaseStep)
       
   110 		{
       
   111 		case EMarkStack:
       
   112 			SelfComplete();
       
   113 			iCaseStep = ELoadLdd;
       
   114 			break;
       
   115 			
       
   116 		case ELoadLdd:
       
   117 			__UHEAP_SETFAIL(RHeap::EDeterministic, iAllocFailNumber);
       
   118 			__UHEAP_MARK;
       
   119 			test.Printf(_L("Load the LDD iteration %d/%d\n"), OOMOPEN_REPEATS-iRepeats+1, OOMOPEN_REPEATS);
       
   120 			aIntegerP = new TInt;
       
   121 			CleanupStack::PushL(aIntegerP);
       
   122 			if (!StepLoadLDD())
       
   123 				{
       
   124 				break;
       
   125 				}
       
   126 			// panic if the cleanupstack was messed
       
   127 			CleanupStack::PopAndDestroy(aIntegerP);
       
   128 
       
   129 			// SAMPLE : some code to test that the __HEAP macros did their stuff
       
   130 			// uncomment this to verify the test flow would fail
       
   131 			//	{
       
   132 			//	TInt *aInt = new TInt;
       
   133 			//	if (NULL ==aInt)
       
   134 			//		test.Printf(_L("Alloc failed!!!!!!\n"));
       
   135 			//	delete aInt;
       
   136 			//	}
       
   137 			iCaseStep = EUnloadLdd;
       
   138 			SelfComplete();
       
   139 			break;
       
   140 			
       
   141 		case EUnloadLdd:
       
   142 			if (EFalse == StepUnloadLDD())
       
   143 				return TestFailed(KErrAbort,_L("Unload Ldd failure"));	
       
   144 			__UHEAP_MARKEND;
       
   145 			test.Printf(_L("Heap intact: Asize %d\n"), iAllocFailNumber);
       
   146 			iCaseStep = ELoopDecrement;
       
   147 			SelfComplete();			
       
   148 			break;
       
   149 						
       
   150 		case ELoopDecrement:
       
   151 			test.Printf(_L("Repeat test\n"));
       
   152 			__UHEAP_RESET;
       
   153 			iAllocFailNumber--;
       
   154 			
       
   155 			if (iRepeats--)
       
   156 				iCaseStep = ELoadLdd;
       
   157 			else
       
   158 				iCaseStep = ELastStep;
       
   159 			SelfComplete();	
       
   160 		    break;
       
   161 		  
       
   162 		case ELastStep:
       
   163 
       
   164 			TestPolicy().SignalTestComplete(KErrNone);
       
   165 			break;
       
   166 			
       
   167 		default:
       
   168 			test.Printf(_L("<Error> unknown test step"));
       
   169 			Cancel();
       
   170 			TestPolicy().SignalTestComplete(KErrCorrupt);
       
   171 			break;
       
   172 		}
       
   173 	}
       
   174 
       
   175