1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/OpenFileByHandle7905.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,217 @@
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 <mmf/plugin/mmfcontrollerimplementationuids.hrh>
1.20 +#include <caf/caf.h>
1.21 +#include "TestPlayerUtils.h"
1.22 +#include "OpenFileByHandle7905.h"
1.23 +
1.24 +/**
1.25 + * Constructor
1.26 + */
1.27 +CTestMmfAclntOpenFile7905::CTestMmfAclntOpenFile7905(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 +CTestMmfAclntOpenFile7905* CTestMmfAclntOpenFile7905::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
1.42 + {
1.43 + CTestMmfAclntOpenFile7905* self = new (ELeave) CTestMmfAclntOpenFile7905(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
1.44 + return self;
1.45 + }
1.46 +
1.47 +CTestMmfAclntOpenFile7905* CTestMmfAclntOpenFile7905::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
1.48 + {
1.49 + CTestMmfAclntOpenFile7905* self = CTestMmfAclntOpenFile7905::NewLC(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
1.50 + CleanupStack::PushL(self);
1.51 + return self;
1.52 + }
1.53 +
1.54 +void CTestMmfAclntOpenFile7905::MoscoStateChangeEvent(CBase* /*aObject*/, TInt /*aPreviousState*/, TInt /*aCurrentState*/, TInt aErrorCode)
1.55 + {
1.56 + iError = aErrorCode;
1.57 + INFO_PRINTF1( _L("CTestMmfAclntOpenFile7905 : MMdaObjectStateChangeObserver Callback for CMdaAudioRecorderUtility complete"));
1.58 + INFO_PRINTF2( _L("iError %d "), iError);
1.59 +
1.60 + CActiveScheduler::Stop();
1.61 + }
1.62 +
1.63 +// Audio utility callbacks
1.64 +void CTestMmfAclntOpenFile7905::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
1.65 + {
1.66 + iError = aError;
1.67 + CActiveScheduler::Stop();
1.68 + }
1.69 +
1.70 +void CTestMmfAclntOpenFile7905::MapcPlayComplete(TInt aError)
1.71 + {
1.72 + iError = aError;
1.73 + CActiveScheduler::Stop();
1.74 + }
1.75 +
1.76 +// Audio output stream callbacks
1.77 +void CTestMmfAclntOpenFile7905::MaoscOpenComplete(TInt aError)
1.78 + {
1.79 + iError = aError;
1.80 + CActiveScheduler::Stop();
1.81 + }
1.82 +
1.83 +void CTestMmfAclntOpenFile7905::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/)
1.84 + {
1.85 + iError = aError;
1.86 + CActiveScheduler::Stop();
1.87 + }
1.88 +
1.89 +void CTestMmfAclntOpenFile7905::MaoscPlayComplete(TInt aError)
1.90 + {
1.91 + iError = aError;
1.92 + CActiveScheduler::Stop();
1.93 + }
1.94 +
1.95 +
1.96 +TVerdict CTestMmfAclntOpenFile7905::DoTestStepPreambleL()
1.97 + {
1.98 + TVerdict ret = EPass;
1.99 +
1.100 + SetupFormatL(iTestFormat);
1.101 +
1.102 + if((ret == EInconclusive) || (ret == EFail))
1.103 + return ret;
1.104 +
1.105 + return CTestMmfAclntStep::DoTestStepPreambleL();
1.106 + }
1.107 +
1.108 +/**
1.109 + * Open a file based clip and record
1.110 + */
1.111 +#define KInvalidAudioController 0xA0A0A0A0
1.112 +
1.113 +TVerdict CTestMmfAclntOpenFile7905::DoTestStepL()
1.114 + {
1.115 + INFO_PRINTF1( _L("TestRecorder : Record File"));
1.116 + TVerdict ret = EFail;
1.117 + iError = KErrTimedOut;
1.118 +
1.119 + RFs fs;
1.120 + RFile file;
1.121 +
1.122 + User::LeaveIfError(fs.Connect());
1.123 + CleanupClosePushL(fs);
1.124 + User::LeaveIfError(fs.ShareProtected());
1.125 +
1.126 + TPtrC filename;
1.127 + if(!GetStringFromConfig(iSectName, iKeyName, filename))
1.128 + {
1.129 + return EInconclusive;
1.130 + }
1.131 +
1.132 + CMdaAudioRecorderUtility* recUtil = CMdaAudioRecorderUtility::NewL(*this);
1.133 + CleanupStack::PushL(recUtil);
1.134 +
1.135 + TUid invalidAudioController;
1.136 + invalidAudioController.iUid = KInvalidAudioController;
1.137 +
1.138 + User::LeaveIfError(file.Replace(fs,filename,EFileWrite));
1.139 + CleanupClosePushL(file);
1.140 +
1.141 + recUtil->OpenFileL(file, invalidAudioController, KNullUid, KNullUid, KFourCCNULL);
1.142 +
1.143 + INFO_PRINTF1( _L("Initialise CMdaAudioRecorderUtility"));
1.144 + CActiveScheduler::Start();
1.145 +
1.146 + if( iError == KErrNotFound )
1.147 + {
1.148 + ret = EPass;
1.149 + }
1.150 +
1.151 + if(iError == KErrNone)
1.152 + {
1.153 + iError = KErrTimedOut;
1.154 + recUtil->RecordL();
1.155 + INFO_PRINTF1( _L("Record CMdaAudioRecorderUtility"));
1.156 + CActiveScheduler::Start(); // open -> record
1.157 +
1.158 + User::After(KFiveSeconds);
1.159 + recUtil->Stop();
1.160 + }
1.161 +
1.162 + CleanupStack::PopAndDestroy(2, recUtil);
1.163 + recUtil = NULL;
1.164 +
1.165 + // Playback the file
1.166 + if (iError == KErrNone)
1.167 + {
1.168 + if (filename.Right(4).Compare(_L(".wav"))==0)
1.169 + {
1.170 + // Wav file playback
1.171 + CMdaAudioPlayerUtility* playUtil = CMdaAudioPlayerUtility::NewL(*this);
1.172 + CleanupStack::PushL(playUtil);
1.173 + TRAPD(err, playUtil->OpenFileL(filename));
1.174 + if (err != KErrNone)
1.175 + {
1.176 + INFO_PRINTF2(_L("Error opening file for playback err = %d"), err);
1.177 + ret = EFail;
1.178 + }
1.179 + CActiveScheduler::Start();
1.180 + if (iError != KErrNone)
1.181 + {
1.182 + INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError);
1.183 + ret = EFail;
1.184 + }
1.185 +
1.186 + playUtil->Play();
1.187 + CActiveScheduler::Start();
1.188 +
1.189 + CleanupStack::PopAndDestroy(playUtil);
1.190 +
1.191 + if (iError != KErrNone)
1.192 + {
1.193 + INFO_PRINTF2(_L("Error during playback of recorded file iError=%d"), iError);
1.194 + ret = EFail;
1.195 + }
1.196 + }
1.197 + }
1.198 +
1.199 + if( iError == KErrNone )
1.200 + {
1.201 + RFile file;
1.202 + TInt size = 0;
1.203 + User::LeaveIfError(file.Open(fs,filename,EFileRead));
1.204 + CleanupClosePushL(file);
1.205 + User::LeaveIfError(file.Size(size));
1.206 +
1.207 + if(size > 0)
1.208 + {
1.209 + ret = EPass;
1.210 + }
1.211 + CleanupStack::PopAndDestroy(); //file
1.212 + }
1.213 +
1.214 + CleanupStack::PopAndDestroy(); // fs
1.215 +
1.216 + ERR_PRINTF2( _L("CMdaAudioRecorderUtility completed with error %d"),iError );
1.217 + User::After(KOneSecond);
1.218 +
1.219 + return ret;
1.220 + }