First public contribution.
1 // Copyright (c) 2004-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.
16 #include "TestPlayerUtils.h"
17 #include "OpenFileByHandle7908.h"
24 CTestMmfAclntOpenFile7908::CTestMmfAclntOpenFile7908(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
25 : CTestMmfAclntOpenFile7902(aTestName, aSectName, aKeyName, aFormat, aCreateFile), iRecUtil(NULL),iPlayUtil(NULL)
29 CTestMmfAclntOpenFile7908* CTestMmfAclntOpenFile7908::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
31 CTestMmfAclntOpenFile7908* self = new (ELeave) CTestMmfAclntOpenFile7908(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
35 CTestMmfAclntOpenFile7908* CTestMmfAclntOpenFile7908::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
37 CTestMmfAclntOpenFile7908* self = CTestMmfAclntOpenFile7908::NewL(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
38 CleanupStack::PushL(self);
43 * Open a file based clip and record, and then playback
44 * Performs alloc tests separately for each step in this test case
45 * The 4 steps in this case are :
46 * 1> Create CMdaAudioRecorderUtility
47 * 2> Open CMdaAudioRecorderUtility and record a clip
48 * 3> Create CMdaAudioPlayerUtility
49 * 4> Open CMdaAudioRecorderUtility and playback the clip
51 TVerdict CTestMmfAclntOpenFile7908::DoTestStepL()
53 INFO_PRINTF1( _L("TestRecorder : Record File"));
56 //>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
57 if( PerformTestStepL() != EPass )
64 INFO_PRINTF2(_L("Test error, returned error code = %d"), err);
68 TInt failCount = 0;//total fail count for all the steps = sum of fail counts in each step
69 TInt stepFailCount; //fail count in each step
70 TVerdict iAllocTestStepResult = EPass; // XXX check?? assume pass
72 err = PerformTestStep(1, stepFailCount);
73 failCount += stepFailCount;
76 iAllocTestStepResult = EFail;
78 format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
80 return iAllocTestStepResult;
83 TRAP(err, ExecuteStep1L());//Till step1 alloc tests are done, now keep the conditions ready
84 //for performing alloc tests on step 2 i,e keep the iRecUtil
85 //created and open for recording in this step
88 iAllocTestStepResult = EFail;
90 format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
92 return iAllocTestStepResult;
94 err = PerformTestStep(2, stepFailCount);
95 failCount += stepFailCount;
96 delete iRecUtil;// Was created in ExecuteStep1L to be used for performing alloc tests in step 2
99 iAllocTestStepResult = EFail;
101 format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
103 return iAllocTestStepResult;
106 err = PerformTestStep(3, stepFailCount);
107 failCount += stepFailCount;
110 iAllocTestStepResult = EFail;
112 format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
114 return iAllocTestStepResult;
117 TRAP(err, ExecuteStep3L());//Till step3 alloc tests are done, now keep the conditions ready
118 //for performing alloc tests on step 4 i,e keep the iPlayUtil
119 //created and open for playback in this step
122 iAllocTestStepResult = EFail;
124 format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
126 return iAllocTestStepResult;
128 err = PerformTestStep(4, stepFailCount);
129 failCount += stepFailCount;
130 delete iPlayUtil; // Was created in ExecuteStep3L to be used for performing alloc tests in step 4
132 stepFailCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc
136 iAllocTestStepResult = EFail;
138 format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
144 format.Format(_L(" Completed OK with %d memory allocations tested\n"), failCount);
148 return iAllocTestStepResult;
151 * TVerdict CTestMmfAclntOpenFile7908::PerformTestStep(TInt aStepNo, TInt& aStepFailCount)
152 * Performs alloc tests on the step aStepNo in this test case
154 TInt CTestMmfAclntOpenFile7908::PerformTestStep(TInt aStepNo, TInt& aStepFailCount)
158 for(aStepFailCount = 1;;)
160 __UHEAP_SETFAIL(RHeap::EFailNext, aStepFailCount);
163 // INFO_PRINTF2(_L("CAudioRecorderUtility: Alloc Test Loop: %d"), failCount);
164 //>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
165 TVerdict verdict = EFail;
170 TRAP(err, verdict = ExecuteStep1L());
173 delete iRecUtil; //Created in ExecuteStep1L. We dont need it open anymore
177 TRAP(err, verdict = ExecuteStep2L());
180 TRAP(err, verdict = ExecuteStep3L());
183 delete iPlayUtil; //Created in ExecuteStep3L. We dont need it open anymore
187 TRAP(err, verdict = ExecuteStep4L());
191 if (err == KErrNone && verdict != EPass)
199 TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
200 if (testAlloc == NULL)
207 User::Free(testAlloc);
211 else if (err != KErrNoMemory) // bad error code
217 __UHEAP_SETFAIL(RHeap::ENone, 0);
229 * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep1L()
230 * Executes the statements for step 1 of this test case
232 TVerdict CTestMmfAclntOpenFile7908::ExecuteStep1L()
234 iError = KErrTimedOut;
236 iRecUtil = CMdaAudioRecorderUtility::NewL(*this);
242 * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep2L()
243 * Executes the statements for step 2 of this test case
245 TVerdict CTestMmfAclntOpenFile7908::ExecuteStep2L()
247 TVerdict ret = EFail;
248 iError = KErrTimedOut;
250 User::LeaveIfError(iFs.Connect());
251 CleanupClosePushL(iFs);
252 User::LeaveIfError(iFs.ShareProtected());
254 if(!GetStringFromConfig(iSectName, iKeyName, iFilename))
259 User::LeaveIfError(iFile.Replace(iFs,iFilename,EFileWrite));
260 CleanupClosePushL(iFile);
261 iRecUtil->OpenFileL(iFile);
262 CleanupClosePushL(*iRecUtil);
263 CActiveScheduler::Start();
265 if(iError == KErrNone)
267 iError = KErrTimedOut;
269 CActiveScheduler::Start(); // open -> record
271 User::After(500000); // 0.5 sec
274 CleanupStack::PopAndDestroy(3, &iFs); //iFs, iFile, iRecUtil
275 if(iError == KErrNone)
283 * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep3L()
284 * Executes the statements for step 3 of this test case
286 TVerdict CTestMmfAclntOpenFile7908::ExecuteStep3L()
288 TVerdict ret = EFail;
289 iError = KErrTimedOut;
291 iPlayUtil = CMdaAudioPlayerUtility::NewL(*this);
298 * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep4L()
299 * Executes the statements for step 4 of this test case
301 TVerdict CTestMmfAclntOpenFile7908::ExecuteStep4L()
303 TVerdict ret = EFail;
304 iError = KErrTimedOut;
306 TRAPD(err, iPlayUtil->OpenFileL(iFilename));
309 INFO_PRINTF2(_L("Error opening file for playback err = %d"), err);
312 CActiveScheduler::Start();
313 if (iError != KErrNone)
315 INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError);
318 if( iError == KErrNone )
321 CActiveScheduler::Start();
324 if (iError != KErrNone)
326 INFO_PRINTF2(_L("Error during playback of recorded file iError=%d"), iError);
329 if( iError == KErrNone )
334 User::LeaveIfError(iFs.Connect());
335 CleanupClosePushL(iFs);
336 User::LeaveIfError(iFs.ShareProtected());
337 User::LeaveIfError(file.Open(iFs,iFilename,EFileRead));
338 CleanupClosePushL(file);
339 User::LeaveIfError(file.Size(size));
345 CleanupStack::PopAndDestroy(2, &iFs); //iFile, iFs
348 ERR_PRINTF2( _L("CMdaAudioRecorderUtility completed with error %d"),iError );
349 if(iError == KErrNone)