sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "TestPlayerUtils.h" sl@0: #include "OpenFileByHandle7908.h" sl@0: sl@0: #include sl@0: sl@0: /** sl@0: * Constructor sl@0: */ sl@0: CTestMmfAclntOpenFile7908::CTestMmfAclntOpenFile7908(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile) sl@0: : CTestMmfAclntOpenFile7902(aTestName, aSectName, aKeyName, aFormat, aCreateFile), iRecUtil(NULL),iPlayUtil(NULL) sl@0: { sl@0: } sl@0: sl@0: CTestMmfAclntOpenFile7908* CTestMmfAclntOpenFile7908::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile) sl@0: { sl@0: CTestMmfAclntOpenFile7908* self = new (ELeave) CTestMmfAclntOpenFile7908(aTestName,aSectName,aKeyName,aFormat,aCreateFile); sl@0: return self; sl@0: } sl@0: sl@0: CTestMmfAclntOpenFile7908* CTestMmfAclntOpenFile7908::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile) sl@0: { sl@0: CTestMmfAclntOpenFile7908* self = CTestMmfAclntOpenFile7908::NewL(aTestName,aSectName,aKeyName,aFormat,aCreateFile); sl@0: CleanupStack::PushL(self); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: * Open a file based clip and record, and then playback sl@0: * Performs alloc tests separately for each step in this test case sl@0: * The 4 steps in this case are : sl@0: * 1> Create CMdaAudioRecorderUtility sl@0: * 2> Open CMdaAudioRecorderUtility and record a clip sl@0: * 3> Create CMdaAudioPlayerUtility sl@0: * 4> Open CMdaAudioRecorderUtility and playback the clip sl@0: */ sl@0: TVerdict CTestMmfAclntOpenFile7908::DoTestStepL() sl@0: { sl@0: INFO_PRINTF1( _L("TestRecorder : Record File")); sl@0: TInt err = KErrNone; sl@0: sl@0: //>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<< sl@0: if( PerformTestStepL() != EPass ) sl@0: { sl@0: err = iError; sl@0: } sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: INFO_PRINTF2(_L("Test error, returned error code = %d"), err); sl@0: User::Leave(err); sl@0: } sl@0: sl@0: TInt failCount = 0;//total fail count for all the steps = sum of fail counts in each step sl@0: TInt stepFailCount; //fail count in each step sl@0: TVerdict iAllocTestStepResult = EPass; // XXX check?? assume pass sl@0: sl@0: err = PerformTestStep(1, stepFailCount); sl@0: failCount += stepFailCount; sl@0: if (err != KErrNone) sl@0: { sl@0: iAllocTestStepResult = EFail; sl@0: TBuf<80> format; sl@0: format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount); sl@0: Log(format); sl@0: return iAllocTestStepResult; sl@0: } sl@0: sl@0: TRAP(err, ExecuteStep1L());//Till step1 alloc tests are done, now keep the conditions ready sl@0: //for performing alloc tests on step 2 i,e keep the iRecUtil sl@0: //created and open for recording in this step sl@0: if (err != KErrNone) sl@0: { sl@0: iAllocTestStepResult = EFail; sl@0: TBuf<80> format; sl@0: format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount); sl@0: Log(format); sl@0: return iAllocTestStepResult; sl@0: } sl@0: err = PerformTestStep(2, stepFailCount); sl@0: failCount += stepFailCount; sl@0: delete iRecUtil;// Was created in ExecuteStep1L to be used for performing alloc tests in step 2 sl@0: if (err != KErrNone) sl@0: { sl@0: iAllocTestStepResult = EFail; sl@0: TBuf<80> format; sl@0: format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount); sl@0: Log(format); sl@0: return iAllocTestStepResult; sl@0: } sl@0: sl@0: err = PerformTestStep(3, stepFailCount); sl@0: failCount += stepFailCount; sl@0: if (err != KErrNone) sl@0: { sl@0: iAllocTestStepResult = EFail; sl@0: TBuf<80> format; sl@0: format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount); sl@0: Log(format); sl@0: return iAllocTestStepResult; sl@0: } sl@0: sl@0: TRAP(err, ExecuteStep3L());//Till step3 alloc tests are done, now keep the conditions ready sl@0: //for performing alloc tests on step 4 i,e keep the iPlayUtil sl@0: //created and open for playback in this step sl@0: if(err != KErrNone) sl@0: { sl@0: iAllocTestStepResult = EFail; sl@0: TBuf<80> format; sl@0: format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount); sl@0: Log(format); sl@0: return iAllocTestStepResult; sl@0: } sl@0: err = PerformTestStep(4, stepFailCount); sl@0: failCount += stepFailCount; sl@0: delete iPlayUtil; // Was created in ExecuteStep3L to be used for performing alloc tests in step 4 sl@0: sl@0: stepFailCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: iAllocTestStepResult = EFail; sl@0: TBuf<80> format; sl@0: format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount); sl@0: Log(format); sl@0: } sl@0: else sl@0: { sl@0: TBuf<80> format; sl@0: format.Format(_L(" Completed OK with %d memory allocations tested\n"), failCount); sl@0: Log(format); sl@0: } sl@0: sl@0: return iAllocTestStepResult; sl@0: } sl@0: /* sl@0: * TVerdict CTestMmfAclntOpenFile7908::PerformTestStep(TInt aStepNo, TInt& aStepFailCount) sl@0: * Performs alloc tests on the step aStepNo in this test case sl@0: */ sl@0: TInt CTestMmfAclntOpenFile7908::PerformTestStep(TInt aStepNo, TInt& aStepFailCount) sl@0: { sl@0: TBool completed; sl@0: TInt err; sl@0: for(aStepFailCount = 1;;) sl@0: { sl@0: __UHEAP_SETFAIL(RHeap::EFailNext, aStepFailCount); sl@0: __MM_HEAP_MARK; sl@0: sl@0: // INFO_PRINTF2(_L("CAudioRecorderUtility: Alloc Test Loop: %d"), failCount); sl@0: //>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<< sl@0: TVerdict verdict = EFail; sl@0: sl@0: switch( aStepNo ) sl@0: { sl@0: case 1: sl@0: TRAP(err, verdict = ExecuteStep1L()); sl@0: if(err == KErrNone) sl@0: { sl@0: delete iRecUtil; //Created in ExecuteStep1L. We dont need it open anymore sl@0: } sl@0: break; sl@0: case 2: sl@0: TRAP(err, verdict = ExecuteStep2L()); sl@0: break; sl@0: case 3: sl@0: TRAP(err, verdict = ExecuteStep3L()); sl@0: if(err == KErrNone) sl@0: { sl@0: delete iPlayUtil; //Created in ExecuteStep3L. We dont need it open anymore sl@0: } sl@0: break; sl@0: case 4: sl@0: TRAP(err, verdict = ExecuteStep4L()); sl@0: break; sl@0: } sl@0: sl@0: if (err == KErrNone && verdict != EPass) sl@0: { sl@0: err = iError; sl@0: } sl@0: sl@0: completed = EFalse; sl@0: if (err == KErrNone) sl@0: { sl@0: TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test sl@0: if (testAlloc == NULL) sl@0: { sl@0: completed = ETrue; sl@0: aStepFailCount -= 1; sl@0: } sl@0: else sl@0: { sl@0: User::Free(testAlloc); sl@0: } sl@0: sl@0: } sl@0: else if (err != KErrNoMemory) // bad error code sl@0: { sl@0: completed = ETrue; sl@0: } sl@0: sl@0: __MM_HEAP_MARKEND; sl@0: __UHEAP_SETFAIL(RHeap::ENone, 0); sl@0: sl@0: if (completed) sl@0: { sl@0: break; // exit loop sl@0: } sl@0: sl@0: aStepFailCount++; sl@0: }//for sl@0: return err; sl@0: } sl@0: /* sl@0: * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep1L() sl@0: * Executes the statements for step 1 of this test case sl@0: */ sl@0: TVerdict CTestMmfAclntOpenFile7908::ExecuteStep1L() sl@0: { sl@0: iError = KErrTimedOut; sl@0: sl@0: iRecUtil = CMdaAudioRecorderUtility::NewL(*this); sl@0: iError = KErrNone; sl@0: return EPass; sl@0: } sl@0: sl@0: /* sl@0: * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep2L() sl@0: * Executes the statements for step 2 of this test case sl@0: */ sl@0: TVerdict CTestMmfAclntOpenFile7908::ExecuteStep2L() sl@0: { sl@0: TVerdict ret = EFail; sl@0: iError = KErrTimedOut; sl@0: sl@0: User::LeaveIfError(iFs.Connect()); sl@0: CleanupClosePushL(iFs); sl@0: User::LeaveIfError(iFs.ShareProtected()); sl@0: sl@0: if(!GetStringFromConfig(iSectName, iKeyName, iFilename)) sl@0: { sl@0: ret = EInconclusive; sl@0: } sl@0: sl@0: User::LeaveIfError(iFile.Replace(iFs,iFilename,EFileWrite)); sl@0: CleanupClosePushL(iFile); sl@0: iRecUtil->OpenFileL(iFile); sl@0: CleanupClosePushL(*iRecUtil); sl@0: CActiveScheduler::Start(); sl@0: sl@0: if(iError == KErrNone) sl@0: { sl@0: iError = KErrTimedOut; sl@0: iRecUtil->RecordL(); sl@0: CActiveScheduler::Start(); // open -> record sl@0: sl@0: User::After(500000); // 0.5 sec sl@0: iRecUtil->Stop(); sl@0: } sl@0: CleanupStack::PopAndDestroy(3, &iFs); //iFs, iFile, iRecUtil sl@0: if(iError == KErrNone) sl@0: { sl@0: ret = EPass; sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: /* sl@0: * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep3L() sl@0: * Executes the statements for step 3 of this test case sl@0: */ sl@0: TVerdict CTestMmfAclntOpenFile7908::ExecuteStep3L() sl@0: { sl@0: TVerdict ret = EFail; sl@0: iError = KErrTimedOut; sl@0: sl@0: iPlayUtil = CMdaAudioPlayerUtility::NewL(*this); sl@0: iError = KErrNone; sl@0: ret = EPass; sl@0: return ret; sl@0: } sl@0: sl@0: /* sl@0: * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep4L() sl@0: * Executes the statements for step 4 of this test case sl@0: */ sl@0: TVerdict CTestMmfAclntOpenFile7908::ExecuteStep4L() sl@0: { sl@0: TVerdict ret = EFail; sl@0: iError = KErrTimedOut; sl@0: sl@0: TRAPD(err, iPlayUtil->OpenFileL(iFilename)); sl@0: if (err != KErrNone) sl@0: { sl@0: INFO_PRINTF2(_L("Error opening file for playback err = %d"), err); sl@0: ret = EFail; sl@0: } sl@0: CActiveScheduler::Start(); sl@0: if (iError != KErrNone) sl@0: { sl@0: INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError); sl@0: ret = EFail; sl@0: } sl@0: if( iError == KErrNone ) sl@0: { sl@0: iPlayUtil->Play(); sl@0: CActiveScheduler::Start(); sl@0: } sl@0: iPlayUtil->Close(); sl@0: if (iError != KErrNone) sl@0: { sl@0: INFO_PRINTF2(_L("Error during playback of recorded file iError=%d"), iError); sl@0: ret = EFail; sl@0: } sl@0: if( iError == KErrNone ) sl@0: { sl@0: RFile file; sl@0: TInt size = 0; sl@0: sl@0: User::LeaveIfError(iFs.Connect()); sl@0: CleanupClosePushL(iFs); sl@0: User::LeaveIfError(iFs.ShareProtected()); sl@0: User::LeaveIfError(file.Open(iFs,iFilename,EFileRead)); sl@0: CleanupClosePushL(file); sl@0: User::LeaveIfError(file.Size(size)); sl@0: sl@0: if(size > 0) sl@0: { sl@0: ret = EPass; sl@0: } sl@0: CleanupStack::PopAndDestroy(2, &iFs); //iFile, iFs sl@0: } sl@0: sl@0: ERR_PRINTF2( _L("CMdaAudioRecorderUtility completed with error %d"),iError ); sl@0: if(iError == KErrNone) sl@0: { sl@0: User::After(500000); sl@0: } sl@0: sl@0: return ret; sl@0: }