sl@0
|
1 |
// Copyright (c) 2004-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 |
#include "TestPlayerUtils.h"
|
sl@0
|
17 |
#include "OpenFileByHandle7908.h"
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <caf/caf.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
/**
|
sl@0
|
22 |
* Constructor
|
sl@0
|
23 |
*/
|
sl@0
|
24 |
CTestMmfAclntOpenFile7908::CTestMmfAclntOpenFile7908(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
|
sl@0
|
25 |
: CTestMmfAclntOpenFile7902(aTestName, aSectName, aKeyName, aFormat, aCreateFile), iRecUtil(NULL),iPlayUtil(NULL)
|
sl@0
|
26 |
{
|
sl@0
|
27 |
}
|
sl@0
|
28 |
|
sl@0
|
29 |
CTestMmfAclntOpenFile7908* CTestMmfAclntOpenFile7908::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
|
sl@0
|
30 |
{
|
sl@0
|
31 |
CTestMmfAclntOpenFile7908* self = new (ELeave) CTestMmfAclntOpenFile7908(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
|
sl@0
|
32 |
return self;
|
sl@0
|
33 |
}
|
sl@0
|
34 |
|
sl@0
|
35 |
CTestMmfAclntOpenFile7908* CTestMmfAclntOpenFile7908::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
CTestMmfAclntOpenFile7908* self = CTestMmfAclntOpenFile7908::NewL(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
|
sl@0
|
38 |
CleanupStack::PushL(self);
|
sl@0
|
39 |
return self;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
/**
|
sl@0
|
43 |
* Open a file based clip and record, and then playback
|
sl@0
|
44 |
* Performs alloc tests separately for each step in this test case
|
sl@0
|
45 |
* The 4 steps in this case are :
|
sl@0
|
46 |
* 1> Create CMdaAudioRecorderUtility
|
sl@0
|
47 |
* 2> Open CMdaAudioRecorderUtility and record a clip
|
sl@0
|
48 |
* 3> Create CMdaAudioPlayerUtility
|
sl@0
|
49 |
* 4> Open CMdaAudioRecorderUtility and playback the clip
|
sl@0
|
50 |
*/
|
sl@0
|
51 |
TVerdict CTestMmfAclntOpenFile7908::DoTestStepL()
|
sl@0
|
52 |
{
|
sl@0
|
53 |
INFO_PRINTF1( _L("TestRecorder : Record File"));
|
sl@0
|
54 |
TInt err = KErrNone;
|
sl@0
|
55 |
|
sl@0
|
56 |
//>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
|
sl@0
|
57 |
if( PerformTestStepL() != EPass )
|
sl@0
|
58 |
{
|
sl@0
|
59 |
err = iError;
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
if (err != KErrNone)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
INFO_PRINTF2(_L("Test error, returned error code = %d"), err);
|
sl@0
|
65 |
User::Leave(err);
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
TInt failCount = 0;//total fail count for all the steps = sum of fail counts in each step
|
sl@0
|
69 |
TInt stepFailCount; //fail count in each step
|
sl@0
|
70 |
TVerdict iAllocTestStepResult = EPass; // XXX check?? assume pass
|
sl@0
|
71 |
|
sl@0
|
72 |
err = PerformTestStep(1, stepFailCount);
|
sl@0
|
73 |
failCount += stepFailCount;
|
sl@0
|
74 |
if (err != KErrNone)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
iAllocTestStepResult = EFail;
|
sl@0
|
77 |
TBuf<80> format;
|
sl@0
|
78 |
format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
|
sl@0
|
79 |
Log(format);
|
sl@0
|
80 |
return iAllocTestStepResult;
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
TRAP(err, ExecuteStep1L());//Till step1 alloc tests are done, now keep the conditions ready
|
sl@0
|
84 |
//for performing alloc tests on step 2 i,e keep the iRecUtil
|
sl@0
|
85 |
//created and open for recording in this step
|
sl@0
|
86 |
if (err != KErrNone)
|
sl@0
|
87 |
{
|
sl@0
|
88 |
iAllocTestStepResult = EFail;
|
sl@0
|
89 |
TBuf<80> format;
|
sl@0
|
90 |
format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
|
sl@0
|
91 |
Log(format);
|
sl@0
|
92 |
return iAllocTestStepResult;
|
sl@0
|
93 |
}
|
sl@0
|
94 |
err = PerformTestStep(2, stepFailCount);
|
sl@0
|
95 |
failCount += stepFailCount;
|
sl@0
|
96 |
delete iRecUtil;// Was created in ExecuteStep1L to be used for performing alloc tests in step 2
|
sl@0
|
97 |
if (err != KErrNone)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
iAllocTestStepResult = EFail;
|
sl@0
|
100 |
TBuf<80> format;
|
sl@0
|
101 |
format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
|
sl@0
|
102 |
Log(format);
|
sl@0
|
103 |
return iAllocTestStepResult;
|
sl@0
|
104 |
}
|
sl@0
|
105 |
|
sl@0
|
106 |
err = PerformTestStep(3, stepFailCount);
|
sl@0
|
107 |
failCount += stepFailCount;
|
sl@0
|
108 |
if (err != KErrNone)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
iAllocTestStepResult = EFail;
|
sl@0
|
111 |
TBuf<80> format;
|
sl@0
|
112 |
format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
|
sl@0
|
113 |
Log(format);
|
sl@0
|
114 |
return iAllocTestStepResult;
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
TRAP(err, ExecuteStep3L());//Till step3 alloc tests are done, now keep the conditions ready
|
sl@0
|
118 |
//for performing alloc tests on step 4 i,e keep the iPlayUtil
|
sl@0
|
119 |
//created and open for playback in this step
|
sl@0
|
120 |
if(err != KErrNone)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
iAllocTestStepResult = EFail;
|
sl@0
|
123 |
TBuf<80> format;
|
sl@0
|
124 |
format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
|
sl@0
|
125 |
Log(format);
|
sl@0
|
126 |
return iAllocTestStepResult;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
err = PerformTestStep(4, stepFailCount);
|
sl@0
|
129 |
failCount += stepFailCount;
|
sl@0
|
130 |
delete iPlayUtil; // Was created in ExecuteStep3L to be used for performing alloc tests in step 4
|
sl@0
|
131 |
|
sl@0
|
132 |
stepFailCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc
|
sl@0
|
133 |
|
sl@0
|
134 |
if (err != KErrNone)
|
sl@0
|
135 |
{
|
sl@0
|
136 |
iAllocTestStepResult = EFail;
|
sl@0
|
137 |
TBuf<80> format;
|
sl@0
|
138 |
format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
|
sl@0
|
139 |
Log(format);
|
sl@0
|
140 |
}
|
sl@0
|
141 |
else
|
sl@0
|
142 |
{
|
sl@0
|
143 |
TBuf<80> format;
|
sl@0
|
144 |
format.Format(_L(" Completed OK with %d memory allocations tested\n"), failCount);
|
sl@0
|
145 |
Log(format);
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
return iAllocTestStepResult;
|
sl@0
|
149 |
}
|
sl@0
|
150 |
/*
|
sl@0
|
151 |
* TVerdict CTestMmfAclntOpenFile7908::PerformTestStep(TInt aStepNo, TInt& aStepFailCount)
|
sl@0
|
152 |
* Performs alloc tests on the step aStepNo in this test case
|
sl@0
|
153 |
*/
|
sl@0
|
154 |
TInt CTestMmfAclntOpenFile7908::PerformTestStep(TInt aStepNo, TInt& aStepFailCount)
|
sl@0
|
155 |
{
|
sl@0
|
156 |
TBool completed;
|
sl@0
|
157 |
TInt err;
|
sl@0
|
158 |
for(aStepFailCount = 1;;)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
__UHEAP_SETFAIL(RHeap::EFailNext, aStepFailCount);
|
sl@0
|
161 |
__MM_HEAP_MARK;
|
sl@0
|
162 |
|
sl@0
|
163 |
// INFO_PRINTF2(_L("CAudioRecorderUtility: Alloc Test Loop: %d"), failCount);
|
sl@0
|
164 |
//>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
|
sl@0
|
165 |
TVerdict verdict = EFail;
|
sl@0
|
166 |
|
sl@0
|
167 |
switch( aStepNo )
|
sl@0
|
168 |
{
|
sl@0
|
169 |
case 1:
|
sl@0
|
170 |
TRAP(err, verdict = ExecuteStep1L());
|
sl@0
|
171 |
if(err == KErrNone)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
delete iRecUtil; //Created in ExecuteStep1L. We dont need it open anymore
|
sl@0
|
174 |
}
|
sl@0
|
175 |
break;
|
sl@0
|
176 |
case 2:
|
sl@0
|
177 |
TRAP(err, verdict = ExecuteStep2L());
|
sl@0
|
178 |
break;
|
sl@0
|
179 |
case 3:
|
sl@0
|
180 |
TRAP(err, verdict = ExecuteStep3L());
|
sl@0
|
181 |
if(err == KErrNone)
|
sl@0
|
182 |
{
|
sl@0
|
183 |
delete iPlayUtil; //Created in ExecuteStep3L. We dont need it open anymore
|
sl@0
|
184 |
}
|
sl@0
|
185 |
break;
|
sl@0
|
186 |
case 4:
|
sl@0
|
187 |
TRAP(err, verdict = ExecuteStep4L());
|
sl@0
|
188 |
break;
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
if (err == KErrNone && verdict != EPass)
|
sl@0
|
192 |
{
|
sl@0
|
193 |
err = iError;
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
completed = EFalse;
|
sl@0
|
197 |
if (err == KErrNone)
|
sl@0
|
198 |
{
|
sl@0
|
199 |
TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
|
sl@0
|
200 |
if (testAlloc == NULL)
|
sl@0
|
201 |
{
|
sl@0
|
202 |
completed = ETrue;
|
sl@0
|
203 |
aStepFailCount -= 1;
|
sl@0
|
204 |
}
|
sl@0
|
205 |
else
|
sl@0
|
206 |
{
|
sl@0
|
207 |
User::Free(testAlloc);
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
}
|
sl@0
|
211 |
else if (err != KErrNoMemory) // bad error code
|
sl@0
|
212 |
{
|
sl@0
|
213 |
completed = ETrue;
|
sl@0
|
214 |
}
|
sl@0
|
215 |
|
sl@0
|
216 |
__MM_HEAP_MARKEND;
|
sl@0
|
217 |
__UHEAP_SETFAIL(RHeap::ENone, 0);
|
sl@0
|
218 |
|
sl@0
|
219 |
if (completed)
|
sl@0
|
220 |
{
|
sl@0
|
221 |
break; // exit loop
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
aStepFailCount++;
|
sl@0
|
225 |
}//for
|
sl@0
|
226 |
return err;
|
sl@0
|
227 |
}
|
sl@0
|
228 |
/*
|
sl@0
|
229 |
* TVerdict CTestMmfAclntOpenFile7908::ExecuteStep1L()
|
sl@0
|
230 |
* Executes the statements for step 1 of this test case
|
sl@0
|
231 |
*/
|
sl@0
|
232 |
TVerdict CTestMmfAclntOpenFile7908::ExecuteStep1L()
|
sl@0
|
233 |
{
|
sl@0
|
234 |
iError = KErrTimedOut;
|
sl@0
|
235 |
|
sl@0
|
236 |
iRecUtil = CMdaAudioRecorderUtility::NewL(*this);
|
sl@0
|
237 |
iError = KErrNone;
|
sl@0
|
238 |
return EPass;
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|
sl@0
|
241 |
/*
|
sl@0
|
242 |
* TVerdict CTestMmfAclntOpenFile7908::ExecuteStep2L()
|
sl@0
|
243 |
* Executes the statements for step 2 of this test case
|
sl@0
|
244 |
*/
|
sl@0
|
245 |
TVerdict CTestMmfAclntOpenFile7908::ExecuteStep2L()
|
sl@0
|
246 |
{
|
sl@0
|
247 |
TVerdict ret = EFail;
|
sl@0
|
248 |
iError = KErrTimedOut;
|
sl@0
|
249 |
|
sl@0
|
250 |
User::LeaveIfError(iFs.Connect());
|
sl@0
|
251 |
CleanupClosePushL(iFs);
|
sl@0
|
252 |
User::LeaveIfError(iFs.ShareProtected());
|
sl@0
|
253 |
|
sl@0
|
254 |
if(!GetStringFromConfig(iSectName, iKeyName, iFilename))
|
sl@0
|
255 |
{
|
sl@0
|
256 |
ret = EInconclusive;
|
sl@0
|
257 |
}
|
sl@0
|
258 |
|
sl@0
|
259 |
User::LeaveIfError(iFile.Replace(iFs,iFilename,EFileWrite));
|
sl@0
|
260 |
CleanupClosePushL(iFile);
|
sl@0
|
261 |
iRecUtil->OpenFileL(iFile);
|
sl@0
|
262 |
CleanupClosePushL(*iRecUtil);
|
sl@0
|
263 |
CActiveScheduler::Start();
|
sl@0
|
264 |
|
sl@0
|
265 |
if(iError == KErrNone)
|
sl@0
|
266 |
{
|
sl@0
|
267 |
iError = KErrTimedOut;
|
sl@0
|
268 |
iRecUtil->RecordL();
|
sl@0
|
269 |
CActiveScheduler::Start(); // open -> record
|
sl@0
|
270 |
|
sl@0
|
271 |
User::After(500000); // 0.5 sec
|
sl@0
|
272 |
iRecUtil->Stop();
|
sl@0
|
273 |
}
|
sl@0
|
274 |
CleanupStack::PopAndDestroy(3, &iFs); //iFs, iFile, iRecUtil
|
sl@0
|
275 |
if(iError == KErrNone)
|
sl@0
|
276 |
{
|
sl@0
|
277 |
ret = EPass;
|
sl@0
|
278 |
}
|
sl@0
|
279 |
return ret;
|
sl@0
|
280 |
}
|
sl@0
|
281 |
|
sl@0
|
282 |
/*
|
sl@0
|
283 |
* TVerdict CTestMmfAclntOpenFile7908::ExecuteStep3L()
|
sl@0
|
284 |
* Executes the statements for step 3 of this test case
|
sl@0
|
285 |
*/
|
sl@0
|
286 |
TVerdict CTestMmfAclntOpenFile7908::ExecuteStep3L()
|
sl@0
|
287 |
{
|
sl@0
|
288 |
TVerdict ret = EFail;
|
sl@0
|
289 |
iError = KErrTimedOut;
|
sl@0
|
290 |
|
sl@0
|
291 |
iPlayUtil = CMdaAudioPlayerUtility::NewL(*this);
|
sl@0
|
292 |
iError = KErrNone;
|
sl@0
|
293 |
ret = EPass;
|
sl@0
|
294 |
return ret;
|
sl@0
|
295 |
}
|
sl@0
|
296 |
|
sl@0
|
297 |
/*
|
sl@0
|
298 |
* TVerdict CTestMmfAclntOpenFile7908::ExecuteStep4L()
|
sl@0
|
299 |
* Executes the statements for step 4 of this test case
|
sl@0
|
300 |
*/
|
sl@0
|
301 |
TVerdict CTestMmfAclntOpenFile7908::ExecuteStep4L()
|
sl@0
|
302 |
{
|
sl@0
|
303 |
TVerdict ret = EFail;
|
sl@0
|
304 |
iError = KErrTimedOut;
|
sl@0
|
305 |
|
sl@0
|
306 |
TRAPD(err, iPlayUtil->OpenFileL(iFilename));
|
sl@0
|
307 |
if (err != KErrNone)
|
sl@0
|
308 |
{
|
sl@0
|
309 |
INFO_PRINTF2(_L("Error opening file for playback err = %d"), err);
|
sl@0
|
310 |
ret = EFail;
|
sl@0
|
311 |
}
|
sl@0
|
312 |
CActiveScheduler::Start();
|
sl@0
|
313 |
if (iError != KErrNone)
|
sl@0
|
314 |
{
|
sl@0
|
315 |
INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError);
|
sl@0
|
316 |
ret = EFail;
|
sl@0
|
317 |
}
|
sl@0
|
318 |
if( iError == KErrNone )
|
sl@0
|
319 |
{
|
sl@0
|
320 |
iPlayUtil->Play();
|
sl@0
|
321 |
CActiveScheduler::Start();
|
sl@0
|
322 |
}
|
sl@0
|
323 |
iPlayUtil->Close();
|
sl@0
|
324 |
if (iError != KErrNone)
|
sl@0
|
325 |
{
|
sl@0
|
326 |
INFO_PRINTF2(_L("Error during playback of recorded file iError=%d"), iError);
|
sl@0
|
327 |
ret = EFail;
|
sl@0
|
328 |
}
|
sl@0
|
329 |
if( iError == KErrNone )
|
sl@0
|
330 |
{
|
sl@0
|
331 |
RFile file;
|
sl@0
|
332 |
TInt size = 0;
|
sl@0
|
333 |
|
sl@0
|
334 |
User::LeaveIfError(iFs.Connect());
|
sl@0
|
335 |
CleanupClosePushL(iFs);
|
sl@0
|
336 |
User::LeaveIfError(iFs.ShareProtected());
|
sl@0
|
337 |
User::LeaveIfError(file.Open(iFs,iFilename,EFileRead));
|
sl@0
|
338 |
CleanupClosePushL(file);
|
sl@0
|
339 |
User::LeaveIfError(file.Size(size));
|
sl@0
|
340 |
|
sl@0
|
341 |
if(size > 0)
|
sl@0
|
342 |
{
|
sl@0
|
343 |
ret = EPass;
|
sl@0
|
344 |
}
|
sl@0
|
345 |
CleanupStack::PopAndDestroy(2, &iFs); //iFile, iFs
|
sl@0
|
346 |
}
|
sl@0
|
347 |
|
sl@0
|
348 |
ERR_PRINTF2( _L("CMdaAudioRecorderUtility completed with error %d"),iError );
|
sl@0
|
349 |
if(iError == KErrNone)
|
sl@0
|
350 |
{
|
sl@0
|
351 |
User::After(500000);
|
sl@0
|
352 |
}
|
sl@0
|
353 |
|
sl@0
|
354 |
return ret;
|
sl@0
|
355 |
}
|