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