1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/OpenFileByHandle7902.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,204 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "TestPlayerUtils.h"
1.20 +#include "OpenFileByHandle7902.h"
1.21 +
1.22 +#include <caf/caf.h>
1.23 +
1.24 +/**
1.25 + * Constructor
1.26 + */
1.27 +CTestMmfAclntOpenFile7902::CTestMmfAclntOpenFile7902(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
1.28 +
1.29 + {
1.30 + // store the name of this test case
1.31 + // this is the name that is used by the script file
1.32 + // Each test step initialises it's own name
1.33 + iTestStepName = aTestName;
1.34 + iHeapSize = 200000; // playback part of test loads whole sound file into buffer, so need large heap
1.35 + iSectName = aSectName;
1.36 + iKeyName = aKeyName;
1.37 + iTestFormat = aFormat;
1.38 + iCreateFile = aCreateFile;
1.39 + }
1.40 +
1.41 +CTestMmfAclntOpenFile7902* CTestMmfAclntOpenFile7902::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
1.42 + {
1.43 + CTestMmfAclntOpenFile7902* self = new (ELeave) CTestMmfAclntOpenFile7902(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
1.44 + return self;
1.45 + }
1.46 +
1.47 +CTestMmfAclntOpenFile7902* CTestMmfAclntOpenFile7902::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
1.48 + {
1.49 + CTestMmfAclntOpenFile7902* self = CTestMmfAclntOpenFile7902::NewLC(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
1.50 + CleanupStack::PushL(self);
1.51 + return self;
1.52 + }
1.53 +
1.54 +void CTestMmfAclntOpenFile7902::MoscoStateChangeEvent(CBase* /*aObject*/, TInt /*aPreviousState*/, TInt /*aCurrentState*/, TInt aErrorCode)
1.55 + {
1.56 + iError = aErrorCode;
1.57 + INFO_PRINTF2( _L("iError %d "), iError);
1.58 + CActiveScheduler::Stop();
1.59 + }
1.60 +
1.61 +// Audio utility callbacks
1.62 +void CTestMmfAclntOpenFile7902::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
1.63 + {
1.64 + iError = aError;
1.65 + CActiveScheduler::Stop();
1.66 + }
1.67 +
1.68 +void CTestMmfAclntOpenFile7902::MapcPlayComplete(TInt aError)
1.69 + {
1.70 + iError = aError;
1.71 + CActiveScheduler::Stop();
1.72 + }
1.73 +
1.74 +// Audio output stream callbacks
1.75 +void CTestMmfAclntOpenFile7902::MaoscOpenComplete(TInt aError)
1.76 + {
1.77 + iError = aError;
1.78 + CActiveScheduler::Stop();
1.79 + }
1.80 +
1.81 +void CTestMmfAclntOpenFile7902::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/)
1.82 + {
1.83 + iError = aError;
1.84 + CActiveScheduler::Stop();
1.85 + }
1.86 +
1.87 +void CTestMmfAclntOpenFile7902::MaoscPlayComplete(TInt aError)
1.88 + {
1.89 + iError = aError;
1.90 + CActiveScheduler::Stop();
1.91 + }
1.92 +
1.93 +
1.94 +TVerdict CTestMmfAclntOpenFile7902::DoTestStepPreambleL()
1.95 + {
1.96 + SetupFormatL(iTestFormat);
1.97 +
1.98 + return CTestMmfAclntStep::DoTestStepPreambleL();
1.99 + }
1.100 +
1.101 +/**
1.102 + * Open a file based clip and record
1.103 + */
1.104 +TVerdict CTestMmfAclntOpenFile7902::DoTestStepL()
1.105 + {
1.106 + return( PerformTestStepL() );
1.107 + }
1.108 +
1.109 +/*
1.110 + * TVerdict CTestMmfAclntOpenFile7902::PerformTestStepL()
1.111 + *
1.112 + */
1.113 +TVerdict CTestMmfAclntOpenFile7902::PerformTestStepL()
1.114 + {
1.115 + TVerdict ret = EFail;
1.116 + iError = KErrTimedOut;
1.117 +
1.118 + RFs fs;
1.119 + RFile file;
1.120 +
1.121 + User::LeaveIfError(fs.Connect());
1.122 + CleanupClosePushL(fs);
1.123 + User::LeaveIfError(fs.ShareProtected());
1.124 +
1.125 + TPtrC filename;
1.126 + if(!GetStringFromConfig(iSectName, iKeyName, filename))
1.127 + {
1.128 + ret = EInconclusive;
1.129 + }
1.130 +
1.131 + CMdaAudioRecorderUtility* recUtil = CMdaAudioRecorderUtility::NewL(*this);
1.132 + CleanupStack::PushL(recUtil);
1.133 +
1.134 + User::LeaveIfError(file.Replace(fs,filename,EFileWrite));
1.135 + CleanupClosePushL(file);
1.136 +
1.137 + recUtil->OpenFileL(file);
1.138 +
1.139 + CActiveScheduler::Start();
1.140 +
1.141 + if(iError == KErrNone)
1.142 + {
1.143 + iError = KErrTimedOut;
1.144 + recUtil->RecordL();
1.145 + CActiveScheduler::Start(); // open -> record
1.146 +
1.147 + User::After(500000); // 0.5 sec
1.148 + recUtil->Stop();
1.149 + }
1.150 +
1.151 + CleanupStack::PopAndDestroy(2, recUtil); // file, recUtil
1.152 + recUtil = NULL;
1.153 +
1.154 + // Playback the file
1.155 + if (iError == KErrNone)
1.156 + {
1.157 + // Wav file playback
1.158 + CMdaAudioPlayerUtility* playUtil = CMdaAudioPlayerUtility::NewL(*this);
1.159 + CleanupStack::PushL(playUtil);
1.160 + TRAPD(err, playUtil->OpenFileL(filename));
1.161 + if (err != KErrNone)
1.162 + {
1.163 + INFO_PRINTF2(_L("Error opening file for playback err = %d"), err);
1.164 + ret = EFail;
1.165 + }
1.166 + CActiveScheduler::Start();
1.167 + if (iError != KErrNone)
1.168 + {
1.169 + INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError);
1.170 + ret = EFail;
1.171 + }
1.172 +
1.173 + if( iError == KErrNone )
1.174 + {
1.175 + playUtil->Play();
1.176 + CActiveScheduler::Start();
1.177 + }
1.178 + CleanupStack::PopAndDestroy(playUtil);
1.179 + if (iError != KErrNone)
1.180 + {
1.181 + INFO_PRINTF2(_L("Error during playback of recorded file iError=%d"), iError);
1.182 + ret = EFail;
1.183 + }
1.184 + }
1.185 +
1.186 + if( iError == KErrNone )
1.187 + {
1.188 + RFile file;
1.189 + TInt size = 0;
1.190 + User::LeaveIfError(file.Open(fs,filename,EFileRead));
1.191 + CleanupClosePushL(file);
1.192 + User::LeaveIfError(file.Size(size));
1.193 +
1.194 + if(size > 0)
1.195 + {
1.196 + ret = EPass;
1.197 + }
1.198 + CleanupStack::PopAndDestroy(); //file
1.199 + }
1.200 +
1.201 + CleanupStack::PopAndDestroy(&fs); // fs
1.202 +
1.203 + ERR_PRINTF2( _L("CMdaAudioRecorderUtility completed with error %d"),iError );
1.204 + User::After(500000);
1.205 +
1.206 + return ret;
1.207 + }