Update contrib.
1 // Copyright (c) 2006-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include "TestMidiClientSharedHeap.h"
20 const TInt KMaxPlayers = 24; // easily enough to overflow the chunk if there were one
22 const TInt KNoSharedPlayer = 2;
23 // which of the created players should be given its own heap on mixed style tests
24 // This must always be true: KNoSharedPlayer < KMaxPlayers
27 const TInt KRepeatAmount = 16;
28 // how often CTestStepPlayerSharedHeapRepeatMultiFilePlayer should create and delete players
31 CTestMidiClntMultiSharedHeap::CTestMidiClntMultiSharedHeap(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle )
32 : CTestMmfMidiClntStep(aTestName, ETestValid)
33 , iMixHeapStyle( aMixHeapStyle )
35 iSectName = aSectName;
39 CTestMidiClntMultiSharedHeap* CTestMidiClntMultiSharedHeap::NewL(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle )
41 CTestMidiClntMultiSharedHeap* self = new(ELeave) CTestMidiClntMultiSharedHeap(aTestName, aSectName, aKeyName, aMixHeapStyle );
45 TVerdict CTestMidiClntMultiSharedHeap::DoTestStepL()
48 if(!GetStringFromConfig(iSectName,iKeyName,filename))
51 INFO_PRINTF2(_L("Check we can create lots of clients - creating %d clients"), KMaxPlayers );
53 // create lots of players
54 RPointerArray<CMidiClientUtility> players;
60 for( TInt i = 0; i < KMaxPlayers; ++i )
62 CMidiClientUtility* player = NULL;
63 // create player with shared heap
65 TBool useSharedHeap = ETrue;
66 if( i == KNoSharedPlayer && iMixHeapStyle )
68 INFO_PRINTF2(_L("MIDI client on iteration %d has own heap."), i );
69 useSharedHeap = EFalse;
72 TRAPD( err, player = CMidiClientUtility::NewL(*this, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality, useSharedHeap ) );
75 if( err == KErrNoMemory )
77 INFO_PRINTF2(_L("Could not create player #%d due to lack of memory."), i );
82 INFO_PRINTF3(_L("Error %d. Could not create player #%d."), err, i );
92 if( players.Append( player ) )
94 // could not add to array
103 if( (ret == EPass) && (players.Count() > 0) ) // no errors so far
106 TMMFMessageDestinationPckg dummyPckg;
107 TInt dummyFunc = 0; //EDevMidiOff;
109 (players[0])->CustomCommandSyncL(dummyPckg, dummyFunc, dummyBuff, dummyBuff, dummyBuff);
110 (players[0])->OpenFile(filename);
112 // Wait for initialisation callback
113 INFO_PRINTF1(_L("CMidiClientUtility: Opening file"));
114 CActiveScheduler::Start();
116 (players[0])->Play();
117 // wait for playback callback
118 CActiveScheduler::Start();
122 // something went wrong
123 INFO_PRINTF2(_L("Error %d during playback."), iError );
130 for( TInt i = 0; i < players.Count(); ++i )
144 // =======================================================================
147 CTestMidiClntRepeatMultiSharedHeap::CTestMidiClntRepeatMultiSharedHeap(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle )
148 : CTestMmfMidiClntStep(aTestName, ETestValid)
149 , iMixHeapStyle( aMixHeapStyle )
151 iSectName = aSectName;
153 iHeapSize = 512 * 1024; // 512k rather than the usual 64k to avoid KErrNoMemory
156 CTestMidiClntRepeatMultiSharedHeap* CTestMidiClntRepeatMultiSharedHeap::NewL(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle )
158 CTestMidiClntRepeatMultiSharedHeap* self = new(ELeave) CTestMidiClntRepeatMultiSharedHeap(aTestName, aSectName, aKeyName, aMixHeapStyle );
162 TVerdict CTestMidiClntRepeatMultiSharedHeap::DoTestStepL()
165 if(!GetStringFromConfig(iSectName,iKeyName,filename))
166 return EInconclusive;
168 INFO_PRINTF3(_L("Create and delete %d players %d times"), KMaxPlayers, KRepeatAmount );
170 TVerdict ret = EPass;
174 for( TInt j = 0; j < KRepeatAmount; ++j )
176 INFO_PRINTF2(_L("** Starting outter iteration %d."), j );
178 // create lots of players
179 RPointerArray<CMidiClientUtility> players;
181 for( TInt i = 0; i < KMaxPlayers; ++i )
183 CMidiClientUtility* player = NULL;
184 // create player with shared heap
186 TBool useSharedHeap = ETrue;
187 if( (i == KNoSharedPlayer) && iMixHeapStyle )
189 INFO_PRINTF2(_L("MIDI client on iteration %d has own heap."), i );
190 useSharedHeap = EFalse;
193 TRAPD( err, player = CMidiClientUtility::NewL(*this, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality, useSharedHeap ) );
196 if( err == KErrNoMemory )
198 INFO_PRINTF2(_L("Could not create player #%d due to lack of memory."), i );
203 INFO_PRINTF3(_L("Error %d. Could not create player #%d."), err, i );
213 if( players.Append( player ) )
215 // could not add to array
224 if( (ret == EPass) && (players.Count() > 0) ) // no errors so far
227 TMMFMessageDestinationPckg dummyPckg;
228 TInt dummyFunc = 0; //EDevMidiOff;
230 (players[0])->CustomCommandSyncL(dummyPckg, dummyFunc, dummyBuff, dummyBuff, dummyBuff);
231 (players[0])->OpenFile(filename);
233 // Wait for initialisation callback
234 INFO_PRINTF1(_L("CMidiClientUtility: Opening file"));
235 CActiveScheduler::Start();
237 (players[0])->Play();
238 // wait for playback callback
239 CActiveScheduler::Start();
243 // something went wrong
244 INFO_PRINTF2(_L("Error %d during playback."), iError );
250 for( TInt i = 0; i < players.Count(); ++i )
259 INFO_PRINTF2(_L("Outter iteration %d failed. Stopping."), j);