os/mm/mmlibs/mmfw/tsrc/mmfunittest/MidiClnt/TestStepMidiClntAllocFailNew.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfunittest/MidiClnt/TestStepMidiClntAllocFailNew.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,208 @@
     1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// This file contains an example Test step implementation 
    1.18 +// This demonstrates the various functions provided
    1.19 +// by the CTestStep base class which are available within
    1.20 +// a test step 
    1.21 +// 
    1.22 +//
    1.23 +
    1.24 +// EPOC includes
    1.25 +#include <e32base.h>
    1.26 +#include <e32test.h>
    1.27 +#include <e32keys.h>
    1.28 +#include <c32comm.h>
    1.29 +#include <f32file.h>
    1.30 +#include <etel.h>
    1.31 +#include <etelmm.h>
    1.32 +#include <testframework.h>
    1.33 +
    1.34 +// Test system includes
    1.35 +#include <testframework.h>
    1.36 +
    1.37 +#include "TSU_MMFMIDICLNT.h"
    1.38 +#include "TS_MMFMIDICLNTsuite.h"
    1.39 +
    1.40 +#include "TestStepMidiClntAllocFailNew.h"
    1.41 +
    1.42 +
    1.43 +
    1.44 +// --------------------------------------------
    1.45 +
    1.46 +/**
    1.47 + *
    1.48 + * Static constructor for CTestStepMidiClntAllocFailNew.
    1.49 + *
    1.50 + *
    1.51 + * @return	"CTestStepMidiClntAllocFailNew*"
    1.52 + *			The constructed CTestStepMidiClntAllocFailNew
    1.53 + *
    1.54 + * @xxxx
    1.55 + * 
    1.56 + */
    1.57 +CTestStepMidiClntAllocFailNew* CTestStepMidiClntAllocFailNew::NewL()
    1.58 +	{
    1.59 +	CTestStepMidiClntAllocFailNew* self = new(ELeave) CTestStepMidiClntAllocFailNew;
    1.60 +	return self;
    1.61 +	}
    1.62 +
    1.63 +/**
    1.64 + *
    1.65 + * Test step constructor.
    1.66 + * Each test step initialises its own name.
    1.67 + *
    1.68 + * @xxxx
    1.69 + * 
    1.70 + */
    1.71 +CTestStepMidiClntAllocFailNew::CTestStepMidiClntAllocFailNew()
    1.72 +	{
    1.73 +	// store the name of this test case
    1.74 +	// this is the name that is used by the script file
    1.75 +	iTestStepName = _L("MM-MMF-MIDICLNT-U-0100-CP");
    1.76 +	}
    1.77 +
    1.78 +/**
    1.79 + *
    1.80 + * Test step destructor.
    1.81 + *
    1.82 + * @xxxx
    1.83 + * 
    1.84 + */
    1.85 +CTestStepMidiClntAllocFailNew::~CTestStepMidiClntAllocFailNew()
    1.86 +	{
    1.87 +	}
    1.88 +
    1.89 +	// from MMidiClientUtilityObserver
    1.90 +void CTestStepMidiClntAllocFailNew::MmcuoStateChanged(TMidiState /*aOldState*/,TMidiState /*aNewState*/,const TTimeIntervalMicroSeconds& /*aTime*/,TInt /*aError*/)
    1.91 +	{
    1.92 +	}
    1.93 +void CTestStepMidiClntAllocFailNew::MmcuoTempoChanged(TInt /*aMicroBeatsPerMinute*/)
    1.94 +	{
    1.95 +	}
    1.96 +void CTestStepMidiClntAllocFailNew::MmcuoVolumeChanged(TInt /*aChannel*/,TReal32 /*aVolumeInDecibels*/)
    1.97 +	{
    1.98 +	}
    1.99 +void CTestStepMidiClntAllocFailNew::MmcuoMuteChanged(TInt /*aChannel*/,TBool /*aMuted*/)
   1.100 +	{
   1.101 +	}
   1.102 +void CTestStepMidiClntAllocFailNew::MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& /*aMicroSeconds*/,TInt64 /*aMicroBeats*/)
   1.103 +	{
   1.104 +	}
   1.105 +void CTestStepMidiClntAllocFailNew::MmcuoMetaDataEntryFound(const TInt /*aMetaDataEntryId*/,const TTimeIntervalMicroSeconds& /*aPosition*/)
   1.106 +	{
   1.107 +	}
   1.108 +void CTestStepMidiClntAllocFailNew::MmcuoMipMessageReceived(const RArray<TMipMessageEntry>& /*aEntry*/)
   1.109 +	{
   1.110 +	}
   1.111 +void CTestStepMidiClntAllocFailNew::MmcuoPolyphonyChanged(TInt /*aNewPolyphony*/)
   1.112 +	{
   1.113 +	}
   1.114 +void CTestStepMidiClntAllocFailNew::MmcuoInstrumentChanged(TInt /*aChannel*/,TInt /*aBankId*/,TInt /*aInstrumentId*/)
   1.115 +	{
   1.116 +	}
   1.117 +
   1.118 +/**
   1.119 + *
   1.120 + * Do the test step.
   1.121 + * Each test step must supply an implementation for DoTestStepL.
   1.122 + *
   1.123 + * @return	"TVerdict"
   1.124 + *			The result of the test step
   1.125 + *
   1.126 + * @xxxx
   1.127 + * 
   1.128 + */
   1.129 +TVerdict CTestStepMidiClntAllocFailNew::DoTestStepL()
   1.130 +	{
   1.131 +	iTestStepResult = EPass;
   1.132 +    TInt err       = KErrNone;
   1.133 +
   1.134 +	// Printing to the console and log file
   1.135 +	INFO_PRINTF1(_L("MM-MMF-MIDICLNT-U-0100-CP"));
   1.136 +	INFO_PRINTF1(_L("this is Alloc Failure test of initialising a CMidiClientUtility object with NewL()"));
   1.137 +
   1.138 +	//__MM_HEAP_MARK;
   1.139 +	TRAP( err, iMidiClnt = CMidiClientUtility::NewL(*this) );
   1.140 +	delete iMidiClnt;
   1.141 +	iMidiClnt = NULL;
   1.142 +	//__MM_HEAP_MARKEND;
   1.143 +
   1.144 +	if (err != KErrNone)
   1.145 +		return EFail;
   1.146 +
   1.147 +	TInt failCount = 1;
   1.148 +	TBool completed = EFalse;
   1.149 +	TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
   1.150 +	for(;;)	
   1.151 +		{
   1.152 +		__UHEAP_SETFAIL(RHeap::EFailNext ,failCount);
   1.153 +		//__MM_HEAP_MARK;
   1.154 +
   1.155 +		TRAP( err, (iMidiClnt = CMidiClientUtility::NewL(*this)) );
   1.156 +
   1.157 + 		completed = EFalse;
   1.158 +		if (err == KErrNone)
   1.159 +			{
   1.160 +			TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
   1.161 +			if (testAlloc==NULL)
   1.162 +				{
   1.163 +				reachedEnd = ETrue;
   1.164 +				failCount--; // -= 1;
   1.165 +				}
   1.166 +			else
   1.167 +				User::Free(testAlloc);
   1.168 +			// see if valid result and break if wrong - might be premature result
   1.169 +			if (iMidiClnt != NULL)
   1.170 +				{
   1.171 +				delete iMidiClnt;
   1.172 +				iMidiClnt = NULL;
   1.173 +				}
   1.174 +			completed = reachedEnd;
   1.175 +			}
   1.176 +		else if (err != KErrNoMemory) // bad error code
   1.177 +			completed = ETrue;
   1.178 +
   1.179 +		//__MM_HEAP_MARKEND;
   1.180 +		__UHEAP_SETFAIL(RHeap::ENone ,0);
   1.181 +
   1.182 +		if (completed)
   1.183 +			break; // exit loop
   1.184 +
   1.185 +		failCount++;
   1.186 +		}
   1.187 +
   1.188 +	//failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc.
   1.189 +
   1.190 +	if (err != KErrNone)
   1.191 +		{
   1.192 +		INFO_PRINTF3(_L("  Error(%d) with %d memory allocations tested"), err, failCount);
   1.193 +		iTestStepResult = EFail;
   1.194 +		}
   1.195 +	else 
   1.196 +		{
   1.197 +		INFO_PRINTF2(_L("  Completed OK with %d memory allocations tested"), failCount);
   1.198 +		iTestStepResult = EPass;
   1.199 +		}
   1.200 +
   1.201 +	if (iMidiClnt != NULL)
   1.202 +		{
   1.203 +		delete iMidiClnt;
   1.204 +		iMidiClnt = NULL;
   1.205 +		}
   1.206 +
   1.207 +	INFO_PRINTF1(_L("finished with this test step"));
   1.208 +	// test steps return a result
   1.209 +	return iTestStepResult;
   1.210 +	}
   1.211 +