sl@0
|
1 |
// Copyright (c) 2006-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 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
|
sl@0
|
17 |
#include "TestMidiClientSharedHeap.h"
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
const TInt KMaxPlayers = 24; // easily enough to overflow the chunk if there were one
|
sl@0
|
21 |
|
sl@0
|
22 |
const TInt KNoSharedPlayer = 2;
|
sl@0
|
23 |
// which of the created players should be given its own heap on mixed style tests
|
sl@0
|
24 |
// This must always be true: KNoSharedPlayer < KMaxPlayers
|
sl@0
|
25 |
|
sl@0
|
26 |
|
sl@0
|
27 |
const TInt KRepeatAmount = 16;
|
sl@0
|
28 |
// how often CTestStepPlayerSharedHeapRepeatMultiFilePlayer should create and delete players
|
sl@0
|
29 |
|
sl@0
|
30 |
|
sl@0
|
31 |
CTestMidiClntMultiSharedHeap::CTestMidiClntMultiSharedHeap(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle )
|
sl@0
|
32 |
: CTestMmfMidiClntStep(aTestName, ETestValid)
|
sl@0
|
33 |
, iMixHeapStyle( aMixHeapStyle )
|
sl@0
|
34 |
{
|
sl@0
|
35 |
iSectName = aSectName;
|
sl@0
|
36 |
iKeyName = aKeyName;
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
CTestMidiClntMultiSharedHeap* CTestMidiClntMultiSharedHeap::NewL(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle )
|
sl@0
|
40 |
{
|
sl@0
|
41 |
CTestMidiClntMultiSharedHeap* self = new(ELeave) CTestMidiClntMultiSharedHeap(aTestName, aSectName, aKeyName, aMixHeapStyle );
|
sl@0
|
42 |
return self;
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
TVerdict CTestMidiClntMultiSharedHeap::DoTestStepL()
|
sl@0
|
46 |
{
|
sl@0
|
47 |
TPtrC filename;
|
sl@0
|
48 |
if(!GetStringFromConfig(iSectName,iKeyName,filename))
|
sl@0
|
49 |
return EInconclusive;
|
sl@0
|
50 |
|
sl@0
|
51 |
INFO_PRINTF2(_L("Check we can create lots of clients - creating %d clients"), KMaxPlayers );
|
sl@0
|
52 |
|
sl@0
|
53 |
// create lots of players
|
sl@0
|
54 |
RPointerArray<CMidiClientUtility> players;
|
sl@0
|
55 |
|
sl@0
|
56 |
TVerdict ret = EPass;
|
sl@0
|
57 |
|
sl@0
|
58 |
__MM_HEAP_MARK;
|
sl@0
|
59 |
|
sl@0
|
60 |
for( TInt i = 0; i < KMaxPlayers; ++i )
|
sl@0
|
61 |
{
|
sl@0
|
62 |
CMidiClientUtility* player = NULL;
|
sl@0
|
63 |
// create player with shared heap
|
sl@0
|
64 |
|
sl@0
|
65 |
TBool useSharedHeap = ETrue;
|
sl@0
|
66 |
if( i == KNoSharedPlayer && iMixHeapStyle )
|
sl@0
|
67 |
{
|
sl@0
|
68 |
INFO_PRINTF2(_L("MIDI client on iteration %d has own heap."), i );
|
sl@0
|
69 |
useSharedHeap = EFalse;
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
TRAPD( err, player = CMidiClientUtility::NewL(*this, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality, useSharedHeap ) );
|
sl@0
|
73 |
if( err )
|
sl@0
|
74 |
{
|
sl@0
|
75 |
if( err == KErrNoMemory )
|
sl@0
|
76 |
{
|
sl@0
|
77 |
INFO_PRINTF2(_L("Could not create player #%d due to lack of memory."), i );
|
sl@0
|
78 |
ret = EFail;
|
sl@0
|
79 |
}
|
sl@0
|
80 |
else
|
sl@0
|
81 |
{
|
sl@0
|
82 |
INFO_PRINTF3(_L("Error %d. Could not create player #%d."), err, i );
|
sl@0
|
83 |
ret = EFail;
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
delete player;
|
sl@0
|
87 |
player = NULL;
|
sl@0
|
88 |
break;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
else
|
sl@0
|
91 |
{
|
sl@0
|
92 |
if( players.Append( player ) )
|
sl@0
|
93 |
{
|
sl@0
|
94 |
// could not add to array
|
sl@0
|
95 |
delete player;
|
sl@0
|
96 |
player = NULL;
|
sl@0
|
97 |
ret = EInconclusive;
|
sl@0
|
98 |
break;
|
sl@0
|
99 |
}
|
sl@0
|
100 |
}
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
if( (ret == EPass) && (players.Count() > 0) ) // no errors so far
|
sl@0
|
104 |
{
|
sl@0
|
105 |
// do fake play
|
sl@0
|
106 |
TMMFMessageDestinationPckg dummyPckg;
|
sl@0
|
107 |
TInt dummyFunc = 0; //EDevMidiOff;
|
sl@0
|
108 |
TBuf8<8> dummyBuff;
|
sl@0
|
109 |
(players[0])->CustomCommandSyncL(dummyPckg, dummyFunc, dummyBuff, dummyBuff, dummyBuff);
|
sl@0
|
110 |
(players[0])->OpenFile(filename);
|
sl@0
|
111 |
|
sl@0
|
112 |
// Wait for initialisation callback
|
sl@0
|
113 |
INFO_PRINTF1(_L("CMidiClientUtility: Opening file"));
|
sl@0
|
114 |
CActiveScheduler::Start();
|
sl@0
|
115 |
|
sl@0
|
116 |
(players[0])->Play();
|
sl@0
|
117 |
// wait for playback callback
|
sl@0
|
118 |
CActiveScheduler::Start();
|
sl@0
|
119 |
|
sl@0
|
120 |
if( iError )
|
sl@0
|
121 |
{
|
sl@0
|
122 |
// something went wrong
|
sl@0
|
123 |
INFO_PRINTF2(_L("Error %d during playback."), iError );
|
sl@0
|
124 |
ret = EFail;
|
sl@0
|
125 |
}
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
|
sl@0
|
129 |
// cleanup
|
sl@0
|
130 |
for( TInt i = 0; i < players.Count(); ++i )
|
sl@0
|
131 |
{
|
sl@0
|
132 |
delete players[i];
|
sl@0
|
133 |
players[i] = NULL;
|
sl@0
|
134 |
}
|
sl@0
|
135 |
players.Close();
|
sl@0
|
136 |
|
sl@0
|
137 |
__MM_HEAP_MARKEND;
|
sl@0
|
138 |
|
sl@0
|
139 |
|
sl@0
|
140 |
return ret;
|
sl@0
|
141 |
}
|
sl@0
|
142 |
|
sl@0
|
143 |
|
sl@0
|
144 |
// =======================================================================
|
sl@0
|
145 |
|
sl@0
|
146 |
|
sl@0
|
147 |
CTestMidiClntRepeatMultiSharedHeap::CTestMidiClntRepeatMultiSharedHeap(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle )
|
sl@0
|
148 |
: CTestMmfMidiClntStep(aTestName, ETestValid)
|
sl@0
|
149 |
, iMixHeapStyle( aMixHeapStyle )
|
sl@0
|
150 |
{
|
sl@0
|
151 |
iSectName = aSectName;
|
sl@0
|
152 |
iKeyName = aKeyName;
|
sl@0
|
153 |
iHeapSize = 512 * 1024; // 512k rather than the usual 64k to avoid KErrNoMemory
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
CTestMidiClntRepeatMultiSharedHeap* CTestMidiClntRepeatMultiSharedHeap::NewL(const TDesC& aTestName,const TDesC& aSectName,const TDesC& aKeyName, TBool aMixHeapStyle )
|
sl@0
|
157 |
{
|
sl@0
|
158 |
CTestMidiClntRepeatMultiSharedHeap* self = new(ELeave) CTestMidiClntRepeatMultiSharedHeap(aTestName, aSectName, aKeyName, aMixHeapStyle );
|
sl@0
|
159 |
return self;
|
sl@0
|
160 |
}
|
sl@0
|
161 |
|
sl@0
|
162 |
TVerdict CTestMidiClntRepeatMultiSharedHeap::DoTestStepL()
|
sl@0
|
163 |
{
|
sl@0
|
164 |
TPtrC filename;
|
sl@0
|
165 |
if(!GetStringFromConfig(iSectName,iKeyName,filename))
|
sl@0
|
166 |
return EInconclusive;
|
sl@0
|
167 |
|
sl@0
|
168 |
INFO_PRINTF3(_L("Create and delete %d players %d times"), KMaxPlayers, KRepeatAmount );
|
sl@0
|
169 |
|
sl@0
|
170 |
TVerdict ret = EPass;
|
sl@0
|
171 |
|
sl@0
|
172 |
__MM_HEAP_MARK;
|
sl@0
|
173 |
|
sl@0
|
174 |
for( TInt j = 0; j < KRepeatAmount; ++j )
|
sl@0
|
175 |
{
|
sl@0
|
176 |
INFO_PRINTF2(_L("** Starting outter iteration %d."), j );
|
sl@0
|
177 |
|
sl@0
|
178 |
// create lots of players
|
sl@0
|
179 |
RPointerArray<CMidiClientUtility> players;
|
sl@0
|
180 |
|
sl@0
|
181 |
for( TInt i = 0; i < KMaxPlayers; ++i )
|
sl@0
|
182 |
{
|
sl@0
|
183 |
CMidiClientUtility* player = NULL;
|
sl@0
|
184 |
// create player with shared heap
|
sl@0
|
185 |
|
sl@0
|
186 |
TBool useSharedHeap = ETrue;
|
sl@0
|
187 |
if( (i == KNoSharedPlayer) && iMixHeapStyle )
|
sl@0
|
188 |
{
|
sl@0
|
189 |
INFO_PRINTF2(_L("MIDI client on iteration %d has own heap."), i );
|
sl@0
|
190 |
useSharedHeap = EFalse;
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
TRAPD( err, player = CMidiClientUtility::NewL(*this, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality, useSharedHeap ) );
|
sl@0
|
194 |
if( err )
|
sl@0
|
195 |
{
|
sl@0
|
196 |
if( err == KErrNoMemory )
|
sl@0
|
197 |
{
|
sl@0
|
198 |
INFO_PRINTF2(_L("Could not create player #%d due to lack of memory."), i );
|
sl@0
|
199 |
ret = EFail;
|
sl@0
|
200 |
}
|
sl@0
|
201 |
else
|
sl@0
|
202 |
{
|
sl@0
|
203 |
INFO_PRINTF3(_L("Error %d. Could not create player #%d."), err, i );
|
sl@0
|
204 |
ret = EFail;
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
delete player;
|
sl@0
|
208 |
player = NULL;
|
sl@0
|
209 |
break;
|
sl@0
|
210 |
}
|
sl@0
|
211 |
else
|
sl@0
|
212 |
{
|
sl@0
|
213 |
if( players.Append( player ) )
|
sl@0
|
214 |
{
|
sl@0
|
215 |
// could not add to array
|
sl@0
|
216 |
delete player;
|
sl@0
|
217 |
player = NULL;
|
sl@0
|
218 |
ret = EInconclusive;
|
sl@0
|
219 |
break;
|
sl@0
|
220 |
}
|
sl@0
|
221 |
}
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
if( (ret == EPass) && (players.Count() > 0) ) // no errors so far
|
sl@0
|
225 |
{
|
sl@0
|
226 |
// do fake play
|
sl@0
|
227 |
TMMFMessageDestinationPckg dummyPckg;
|
sl@0
|
228 |
TInt dummyFunc = 0; //EDevMidiOff;
|
sl@0
|
229 |
TBuf8<8> dummyBuff;
|
sl@0
|
230 |
(players[0])->CustomCommandSyncL(dummyPckg, dummyFunc, dummyBuff, dummyBuff, dummyBuff);
|
sl@0
|
231 |
(players[0])->OpenFile(filename);
|
sl@0
|
232 |
|
sl@0
|
233 |
// Wait for initialisation callback
|
sl@0
|
234 |
INFO_PRINTF1(_L("CMidiClientUtility: Opening file"));
|
sl@0
|
235 |
CActiveScheduler::Start();
|
sl@0
|
236 |
|
sl@0
|
237 |
(players[0])->Play();
|
sl@0
|
238 |
// wait for playback callback
|
sl@0
|
239 |
CActiveScheduler::Start();
|
sl@0
|
240 |
|
sl@0
|
241 |
if( iError )
|
sl@0
|
242 |
{
|
sl@0
|
243 |
// something went wrong
|
sl@0
|
244 |
INFO_PRINTF2(_L("Error %d during playback."), iError );
|
sl@0
|
245 |
ret = EFail;
|
sl@0
|
246 |
}
|
sl@0
|
247 |
}
|
sl@0
|
248 |
|
sl@0
|
249 |
// cleanup
|
sl@0
|
250 |
for( TInt i = 0; i < players.Count(); ++i )
|
sl@0
|
251 |
{
|
sl@0
|
252 |
delete players[i];
|
sl@0
|
253 |
players[i] = NULL;
|
sl@0
|
254 |
}
|
sl@0
|
255 |
players.Close();
|
sl@0
|
256 |
|
sl@0
|
257 |
if( ret != EPass )
|
sl@0
|
258 |
{
|
sl@0
|
259 |
INFO_PRINTF2(_L("Outter iteration %d failed. Stopping."), j);
|
sl@0
|
260 |
break;
|
sl@0
|
261 |
}
|
sl@0
|
262 |
|
sl@0
|
263 |
}// end outter loop
|
sl@0
|
264 |
|
sl@0
|
265 |
__MM_HEAP_MARKEND;
|
sl@0
|
266 |
|
sl@0
|
267 |
return ret;
|
sl@0
|
268 |
}
|