os/mm/mmlibs/mmfw/tsrc/mmfunittest/MidiClnt/TestStepMidiClntAllocFailNew.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2003-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 "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 // This file contains an example Test step implementation 
    15 // This demonstrates the various functions provided
    16 // by the CTestStep base class which are available within
    17 // a test step 
    18 // 
    19 //
    20 
    21 // EPOC includes
    22 #include <e32base.h>
    23 #include <e32test.h>
    24 #include <e32keys.h>
    25 #include <c32comm.h>
    26 #include <f32file.h>
    27 #include <etel.h>
    28 #include <etelmm.h>
    29 #include <testframework.h>
    30 
    31 // Test system includes
    32 #include <testframework.h>
    33 
    34 #include "TSU_MMFMIDICLNT.h"
    35 #include "TS_MMFMIDICLNTsuite.h"
    36 
    37 #include "TestStepMidiClntAllocFailNew.h"
    38 
    39 
    40 
    41 // --------------------------------------------
    42 
    43 /**
    44  *
    45  * Static constructor for CTestStepMidiClntAllocFailNew.
    46  *
    47  *
    48  * @return	"CTestStepMidiClntAllocFailNew*"
    49  *			The constructed CTestStepMidiClntAllocFailNew
    50  *
    51  * @xxxx
    52  * 
    53  */
    54 CTestStepMidiClntAllocFailNew* CTestStepMidiClntAllocFailNew::NewL()
    55 	{
    56 	CTestStepMidiClntAllocFailNew* self = new(ELeave) CTestStepMidiClntAllocFailNew;
    57 	return self;
    58 	}
    59 
    60 /**
    61  *
    62  * Test step constructor.
    63  * Each test step initialises its own name.
    64  *
    65  * @xxxx
    66  * 
    67  */
    68 CTestStepMidiClntAllocFailNew::CTestStepMidiClntAllocFailNew()
    69 	{
    70 	// store the name of this test case
    71 	// this is the name that is used by the script file
    72 	iTestStepName = _L("MM-MMF-MIDICLNT-U-0100-CP");
    73 	}
    74 
    75 /**
    76  *
    77  * Test step destructor.
    78  *
    79  * @xxxx
    80  * 
    81  */
    82 CTestStepMidiClntAllocFailNew::~CTestStepMidiClntAllocFailNew()
    83 	{
    84 	}
    85 
    86 	// from MMidiClientUtilityObserver
    87 void CTestStepMidiClntAllocFailNew::MmcuoStateChanged(TMidiState /*aOldState*/,TMidiState /*aNewState*/,const TTimeIntervalMicroSeconds& /*aTime*/,TInt /*aError*/)
    88 	{
    89 	}
    90 void CTestStepMidiClntAllocFailNew::MmcuoTempoChanged(TInt /*aMicroBeatsPerMinute*/)
    91 	{
    92 	}
    93 void CTestStepMidiClntAllocFailNew::MmcuoVolumeChanged(TInt /*aChannel*/,TReal32 /*aVolumeInDecibels*/)
    94 	{
    95 	}
    96 void CTestStepMidiClntAllocFailNew::MmcuoMuteChanged(TInt /*aChannel*/,TBool /*aMuted*/)
    97 	{
    98 	}
    99 void CTestStepMidiClntAllocFailNew::MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& /*aMicroSeconds*/,TInt64 /*aMicroBeats*/)
   100 	{
   101 	}
   102 void CTestStepMidiClntAllocFailNew::MmcuoMetaDataEntryFound(const TInt /*aMetaDataEntryId*/,const TTimeIntervalMicroSeconds& /*aPosition*/)
   103 	{
   104 	}
   105 void CTestStepMidiClntAllocFailNew::MmcuoMipMessageReceived(const RArray<TMipMessageEntry>& /*aEntry*/)
   106 	{
   107 	}
   108 void CTestStepMidiClntAllocFailNew::MmcuoPolyphonyChanged(TInt /*aNewPolyphony*/)
   109 	{
   110 	}
   111 void CTestStepMidiClntAllocFailNew::MmcuoInstrumentChanged(TInt /*aChannel*/,TInt /*aBankId*/,TInt /*aInstrumentId*/)
   112 	{
   113 	}
   114 
   115 /**
   116  *
   117  * Do the test step.
   118  * Each test step must supply an implementation for DoTestStepL.
   119  *
   120  * @return	"TVerdict"
   121  *			The result of the test step
   122  *
   123  * @xxxx
   124  * 
   125  */
   126 TVerdict CTestStepMidiClntAllocFailNew::DoTestStepL()
   127 	{
   128 	iTestStepResult = EPass;
   129     TInt err       = KErrNone;
   130 
   131 	// Printing to the console and log file
   132 	INFO_PRINTF1(_L("MM-MMF-MIDICLNT-U-0100-CP"));
   133 	INFO_PRINTF1(_L("this is Alloc Failure test of initialising a CMidiClientUtility object with NewL()"));
   134 
   135 	//__MM_HEAP_MARK;
   136 	TRAP( err, iMidiClnt = CMidiClientUtility::NewL(*this) );
   137 	delete iMidiClnt;
   138 	iMidiClnt = NULL;
   139 	//__MM_HEAP_MARKEND;
   140 
   141 	if (err != KErrNone)
   142 		return EFail;
   143 
   144 	TInt failCount = 1;
   145 	TBool completed = EFalse;
   146 	TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
   147 	for(;;)	
   148 		{
   149 		__UHEAP_SETFAIL(RHeap::EFailNext ,failCount);
   150 		//__MM_HEAP_MARK;
   151 
   152 		TRAP( err, (iMidiClnt = CMidiClientUtility::NewL(*this)) );
   153 
   154  		completed = EFalse;
   155 		if (err == KErrNone)
   156 			{
   157 			TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
   158 			if (testAlloc==NULL)
   159 				{
   160 				reachedEnd = ETrue;
   161 				failCount--; // -= 1;
   162 				}
   163 			else
   164 				User::Free(testAlloc);
   165 			// see if valid result and break if wrong - might be premature result
   166 			if (iMidiClnt != NULL)
   167 				{
   168 				delete iMidiClnt;
   169 				iMidiClnt = NULL;
   170 				}
   171 			completed = reachedEnd;
   172 			}
   173 		else if (err != KErrNoMemory) // bad error code
   174 			completed = ETrue;
   175 
   176 		//__MM_HEAP_MARKEND;
   177 		__UHEAP_SETFAIL(RHeap::ENone ,0);
   178 
   179 		if (completed)
   180 			break; // exit loop
   181 
   182 		failCount++;
   183 		}
   184 
   185 	//failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
   186 
   187 	if (err != KErrNone)
   188 		{
   189 		INFO_PRINTF3(_L("  Error(%d) with %d memory allocations tested"), err, failCount);
   190 		iTestStepResult = EFail;
   191 		}
   192 	else 
   193 		{
   194 		INFO_PRINTF2(_L("  Completed OK with %d memory allocations tested"), failCount);
   195 		iTestStepResult = EPass;
   196 		}
   197 
   198 	if (iMidiClnt != NULL)
   199 		{
   200 		delete iMidiClnt;
   201 		iMidiClnt = NULL;
   202 		}
   203 
   204 	INFO_PRINTF1(_L("finished with this test step"));
   205 	// test steps return a result
   206 	return iTestStepResult;
   207 	}
   208