sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: sl@0: #include "TestMidiClientSharedHeap.h" sl@0: sl@0: sl@0: const TInt KMaxPlayers = 24; // easily enough to overflow the chunk if there were one sl@0: sl@0: const TInt KNoSharedPlayer = 2; sl@0: // which of the created players should be given its own heap on mixed style tests sl@0: // This must always be true: KNoSharedPlayer < KMaxPlayers sl@0: sl@0: sl@0: const TInt KRepeatAmount = 16; sl@0: // how often CTestStepPlayerSharedHeapRepeatMultiFilePlayer should create and delete players sl@0: sl@0: sl@0: CTestMidiClntMultiSharedHeap::CTestMidiClntMultiSharedHeap(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle ) sl@0: : CTestMmfMidiClntStep(aTestName, ETestValid) sl@0: , iMixHeapStyle( aMixHeapStyle ) sl@0: { sl@0: iSectName = aSectName; sl@0: iKeyName = aKeyName; sl@0: } sl@0: sl@0: CTestMidiClntMultiSharedHeap* CTestMidiClntMultiSharedHeap::NewL(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle ) sl@0: { sl@0: CTestMidiClntMultiSharedHeap* self = new(ELeave) CTestMidiClntMultiSharedHeap(aTestName, aSectName, aKeyName, aMixHeapStyle ); sl@0: return self; sl@0: } sl@0: sl@0: TVerdict CTestMidiClntMultiSharedHeap::DoTestStepL() sl@0: { sl@0: TPtrC filename; sl@0: if(!GetStringFromConfig(iSectName,iKeyName,filename)) sl@0: return EInconclusive; sl@0: sl@0: INFO_PRINTF2(_L("Check we can create lots of clients - creating %d clients"), KMaxPlayers ); sl@0: sl@0: // create lots of players sl@0: RPointerArray players; sl@0: sl@0: TVerdict ret = EPass; sl@0: sl@0: __MM_HEAP_MARK; sl@0: sl@0: for( TInt i = 0; i < KMaxPlayers; ++i ) sl@0: { sl@0: CMidiClientUtility* player = NULL; sl@0: // create player with shared heap sl@0: sl@0: TBool useSharedHeap = ETrue; sl@0: if( i == KNoSharedPlayer && iMixHeapStyle ) sl@0: { sl@0: INFO_PRINTF2(_L("MIDI client on iteration %d has own heap."), i ); sl@0: useSharedHeap = EFalse; sl@0: } sl@0: sl@0: TRAPD( err, player = CMidiClientUtility::NewL(*this, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality, useSharedHeap ) ); sl@0: if( err ) sl@0: { sl@0: if( err == KErrNoMemory ) sl@0: { sl@0: INFO_PRINTF2(_L("Could not create player #%d due to lack of memory."), i ); sl@0: ret = EFail; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("Error %d. Could not create player #%d."), err, i ); sl@0: ret = EFail; sl@0: } sl@0: sl@0: delete player; sl@0: player = NULL; sl@0: break; sl@0: } sl@0: else sl@0: { sl@0: if( players.Append( player ) ) sl@0: { sl@0: // could not add to array sl@0: delete player; sl@0: player = NULL; sl@0: ret = EInconclusive; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: if( (ret == EPass) && (players.Count() > 0) ) // no errors so far sl@0: { sl@0: // do fake play sl@0: TMMFMessageDestinationPckg dummyPckg; sl@0: TInt dummyFunc = 0; //EDevMidiOff; sl@0: TBuf8<8> dummyBuff; sl@0: (players[0])->CustomCommandSyncL(dummyPckg, dummyFunc, dummyBuff, dummyBuff, dummyBuff); sl@0: (players[0])->OpenFile(filename); sl@0: sl@0: // Wait for initialisation callback sl@0: INFO_PRINTF1(_L("CMidiClientUtility: Opening file")); sl@0: CActiveScheduler::Start(); sl@0: sl@0: (players[0])->Play(); sl@0: // wait for playback callback sl@0: CActiveScheduler::Start(); sl@0: sl@0: if( iError ) sl@0: { sl@0: // something went wrong sl@0: INFO_PRINTF2(_L("Error %d during playback."), iError ); sl@0: ret = EFail; sl@0: } sl@0: } sl@0: sl@0: sl@0: // cleanup sl@0: for( TInt i = 0; i < players.Count(); ++i ) sl@0: { sl@0: delete players[i]; sl@0: players[i] = NULL; sl@0: } sl@0: players.Close(); sl@0: sl@0: __MM_HEAP_MARKEND; sl@0: sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: // ======================================================================= sl@0: sl@0: sl@0: CTestMidiClntRepeatMultiSharedHeap::CTestMidiClntRepeatMultiSharedHeap(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle ) sl@0: : CTestMmfMidiClntStep(aTestName, ETestValid) sl@0: , iMixHeapStyle( aMixHeapStyle ) sl@0: { sl@0: iSectName = aSectName; sl@0: iKeyName = aKeyName; sl@0: iHeapSize = 512 * 1024; // 512k rather than the usual 64k to avoid KErrNoMemory sl@0: } sl@0: sl@0: CTestMidiClntRepeatMultiSharedHeap* CTestMidiClntRepeatMultiSharedHeap::NewL(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle ) sl@0: { sl@0: CTestMidiClntRepeatMultiSharedHeap* self = new(ELeave) CTestMidiClntRepeatMultiSharedHeap(aTestName, aSectName, aKeyName, aMixHeapStyle ); sl@0: return self; sl@0: } sl@0: sl@0: TVerdict CTestMidiClntRepeatMultiSharedHeap::DoTestStepL() sl@0: { sl@0: TPtrC filename; sl@0: if(!GetStringFromConfig(iSectName,iKeyName,filename)) sl@0: return EInconclusive; sl@0: sl@0: INFO_PRINTF3(_L("Create and delete %d players %d times"), KMaxPlayers, KRepeatAmount ); sl@0: sl@0: TVerdict ret = EPass; sl@0: sl@0: __MM_HEAP_MARK; sl@0: sl@0: for( TInt j = 0; j < KRepeatAmount; ++j ) sl@0: { sl@0: INFO_PRINTF2(_L("** Starting outter iteration %d."), j ); sl@0: sl@0: // create lots of players sl@0: RPointerArray players; sl@0: sl@0: for( TInt i = 0; i < KMaxPlayers; ++i ) sl@0: { sl@0: CMidiClientUtility* player = NULL; sl@0: // create player with shared heap sl@0: sl@0: TBool useSharedHeap = ETrue; sl@0: if( (i == KNoSharedPlayer) && iMixHeapStyle ) sl@0: { sl@0: INFO_PRINTF2(_L("MIDI client on iteration %d has own heap."), i ); sl@0: useSharedHeap = EFalse; sl@0: } sl@0: sl@0: TRAPD( err, player = CMidiClientUtility::NewL(*this, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality, useSharedHeap ) ); sl@0: if( err ) sl@0: { sl@0: if( err == KErrNoMemory ) sl@0: { sl@0: INFO_PRINTF2(_L("Could not create player #%d due to lack of memory."), i ); sl@0: ret = EFail; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("Error %d. Could not create player #%d."), err, i ); sl@0: ret = EFail; sl@0: } sl@0: sl@0: delete player; sl@0: player = NULL; sl@0: break; sl@0: } sl@0: else sl@0: { sl@0: if( players.Append( player ) ) sl@0: { sl@0: // could not add to array sl@0: delete player; sl@0: player = NULL; sl@0: ret = EInconclusive; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: if( (ret == EPass) && (players.Count() > 0) ) // no errors so far sl@0: { sl@0: // do fake play sl@0: TMMFMessageDestinationPckg dummyPckg; sl@0: TInt dummyFunc = 0; //EDevMidiOff; sl@0: TBuf8<8> dummyBuff; sl@0: (players[0])->CustomCommandSyncL(dummyPckg, dummyFunc, dummyBuff, dummyBuff, dummyBuff); sl@0: (players[0])->OpenFile(filename); sl@0: sl@0: // Wait for initialisation callback sl@0: INFO_PRINTF1(_L("CMidiClientUtility: Opening file")); sl@0: CActiveScheduler::Start(); sl@0: sl@0: (players[0])->Play(); sl@0: // wait for playback callback sl@0: CActiveScheduler::Start(); sl@0: sl@0: if( iError ) sl@0: { sl@0: // something went wrong sl@0: INFO_PRINTF2(_L("Error %d during playback."), iError ); sl@0: ret = EFail; sl@0: } sl@0: } sl@0: sl@0: // cleanup sl@0: for( TInt i = 0; i < players.Count(); ++i ) sl@0: { sl@0: delete players[i]; sl@0: players[i] = NULL; sl@0: } sl@0: players.Close(); sl@0: sl@0: if( ret != EPass ) sl@0: { sl@0: INFO_PRINTF2(_L("Outter iteration %d failed. Stopping."), j); sl@0: break; sl@0: } sl@0: sl@0: }// end outter loop sl@0: sl@0: __MM_HEAP_MARKEND; sl@0: sl@0: return ret; sl@0: }