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