os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/OpenFileByHandle7904.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/OpenFileByHandle7904.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,207 @@
     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 <mmf/plugin/mmfcontrollerimplementationuids.hrh>
    1.22 +#include "TestPlayerUtils.h"
    1.23 +#include "OpenFileByHandle7904.h"
    1.24 +
    1.25 +/**
    1.26 + * Constructor
    1.27 + */
    1.28 +CTestMmfAclntOpenFile7904::CTestMmfAclntOpenFile7904(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
    1.29 +
    1.30 +	{
    1.31 +	// store the name of this test case
    1.32 +	// this is the name that is used by the script file
    1.33 +	// Each test step initialises it's own name
    1.34 +	iTestStepName = aTestName;
    1.35 +	iHeapSize = 200000;		// playback part of test loads whole sound file into buffer, so need large heap
    1.36 +	iSectName = aSectName;
    1.37 +	iKeyName = aKeyName;
    1.38 +	iTestFormat = aFormat;
    1.39 +	iCreateFile = aCreateFile;
    1.40 +	}
    1.41 +
    1.42 +CTestMmfAclntOpenFile7904* CTestMmfAclntOpenFile7904::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
    1.43 +	{
    1.44 +	CTestMmfAclntOpenFile7904* self = new (ELeave) CTestMmfAclntOpenFile7904(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
    1.45 +	return self;
    1.46 +	}
    1.47 +
    1.48 +CTestMmfAclntOpenFile7904* CTestMmfAclntOpenFile7904::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
    1.49 +	{
    1.50 +	CTestMmfAclntOpenFile7904* self = CTestMmfAclntOpenFile7904::NewLC(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
    1.51 +	CleanupStack::PushL(self);
    1.52 +	return self;
    1.53 +	}
    1.54 +
    1.55 +void CTestMmfAclntOpenFile7904::MoscoStateChangeEvent(CBase* /*aObject*/, TInt /*aPreviousState*/, TInt /*aCurrentState*/, TInt aErrorCode)
    1.56 +	{
    1.57 +	iError = aErrorCode;
    1.58 +	INFO_PRINTF1( _L("CTestMmfAclntOpenFile7904 : MMdaObjectStateChangeObserver Callback for CMdaAudioRecorderUtility complete"));
    1.59 +	INFO_PRINTF2( _L("iError %d "), iError);
    1.60 +
    1.61 +	CActiveScheduler::Stop();
    1.62 +	}
    1.63 +
    1.64 +// Audio utility callbacks
    1.65 +void CTestMmfAclntOpenFile7904::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
    1.66 +	{
    1.67 +	iError = aError;
    1.68 +	CActiveScheduler::Stop();
    1.69 +	}
    1.70 +
    1.71 +void CTestMmfAclntOpenFile7904::MapcPlayComplete(TInt aError)
    1.72 +	{
    1.73 +	iError = aError;
    1.74 +	CActiveScheduler::Stop();
    1.75 +	}
    1.76 +
    1.77 +// Audio output stream callbacks
    1.78 +void CTestMmfAclntOpenFile7904::MaoscOpenComplete(TInt aError)
    1.79 +	{
    1.80 +	iError = aError;
    1.81 +	CActiveScheduler::Stop();
    1.82 +	}
    1.83 +
    1.84 +void CTestMmfAclntOpenFile7904::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/)
    1.85 +	{
    1.86 +	iError = aError;
    1.87 +	CActiveScheduler::Stop();
    1.88 +	}
    1.89 +
    1.90 +void CTestMmfAclntOpenFile7904::MaoscPlayComplete(TInt aError)
    1.91 +	{
    1.92 +	iError = aError;
    1.93 +	CActiveScheduler::Stop();
    1.94 +	}
    1.95 +
    1.96 +
    1.97 +TVerdict CTestMmfAclntOpenFile7904::DoTestStepPreambleL()
    1.98 +	{
    1.99 +	TVerdict ret = EPass;
   1.100 +
   1.101 +	SetupFormatL(iTestFormat);
   1.102 +
   1.103 +	if((ret == EInconclusive) || (ret == EFail))
   1.104 +		return ret;	
   1.105 +	
   1.106 +	return CTestMmfAclntStep::DoTestStepPreambleL();
   1.107 +	}
   1.108 +
   1.109 +/**
   1.110 + * Open a file based clip and record
   1.111 + */
   1.112 +TVerdict CTestMmfAclntOpenFile7904::DoTestStepL()
   1.113 +	{
   1.114 +	INFO_PRINTF1( _L("TestRecorder : Record File"));
   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 +		return EInconclusive;
   1.129 +		}
   1.130 +
   1.131 +	CMdaAudioRecorderUtility* recUtil = CMdaAudioRecorderUtility::NewL(*this);
   1.132 +	CleanupStack::PushL(recUtil);
   1.133 +
   1.134 +	TUid audioController = TUid::Uid(KMmfUidControllerAudio);
   1.135 +	
   1.136 +	User::LeaveIfError(file.Replace(fs,filename,EFileWrite));
   1.137 +	CleanupClosePushL(file);
   1.138 +
   1.139 +	recUtil->OpenFileL(file, audioController, KNullUid, KNullUid, KFourCCNULL);
   1.140 +
   1.141 +	INFO_PRINTF1( _L("Initialise CMdaAudioRecorderUtility"));
   1.142 +	CActiveScheduler::Start();
   1.143 +
   1.144 +	if(iError == KErrNone)
   1.145 +		{
   1.146 +		iError = KErrTimedOut;
   1.147 +		recUtil->RecordL();
   1.148 +		INFO_PRINTF1( _L("Record CMdaAudioRecorderUtility"));
   1.149 +		CActiveScheduler::Start(); // open -> record
   1.150 +
   1.151 +		User::After(500000);
   1.152 +		recUtil->Stop();
   1.153 +		}
   1.154 +
   1.155 +	CleanupStack::PopAndDestroy(2, recUtil);	// file, recUtil
   1.156 +	recUtil = NULL;
   1.157 +
   1.158 +	// Playback the file
   1.159 +	if (iError == KErrNone)
   1.160 +		{
   1.161 +		if (filename.Right(4).Compare(_L(".wav"))==0)
   1.162 +			{
   1.163 +			// Wav file playback
   1.164 +			CMdaAudioPlayerUtility* playUtil = CMdaAudioPlayerUtility::NewL(*this);
   1.165 +			CleanupStack::PushL(playUtil);
   1.166 +			TRAPD(err, playUtil->OpenFileL(filename));
   1.167 +			if (err != KErrNone)
   1.168 +				{
   1.169 +				INFO_PRINTF2(_L("Error opening file for playback err = %d"), err);
   1.170 +				ret = EFail;
   1.171 +				}
   1.172 +			CActiveScheduler::Start();
   1.173 +			if (iError != KErrNone)
   1.174 +				{
   1.175 +				INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError);
   1.176 +				ret = EFail;
   1.177 +				}
   1.178 +			playUtil->Play();
   1.179 +			CActiveScheduler::Start();
   1.180 +			CleanupStack::PopAndDestroy(playUtil);
   1.181 +			if (iError != KErrNone)
   1.182 +				{
   1.183 +				INFO_PRINTF2(_L("Error during playback of recorded file iError=%d"), iError);
   1.184 +				ret = EFail;
   1.185 +				}
   1.186 +			}
   1.187 +		}
   1.188 +
   1.189 +	if( iError == KErrNone ) 
   1.190 +		{
   1.191 +		RFile file;
   1.192 +		TInt size = 0;
   1.193 +		User::LeaveIfError(file.Open(fs,filename,EFileRead));
   1.194 +		CleanupClosePushL(file);
   1.195 +		User::LeaveIfError(file.Size(size));
   1.196 +
   1.197 +		if(size > 0)
   1.198 +			{
   1.199 +			ret = EPass;
   1.200 +			}
   1.201 +		CleanupStack::PopAndDestroy(); //file
   1.202 +		}
   1.203 +
   1.204 +	CleanupStack::PopAndDestroy(&fs);	// fs
   1.205 +
   1.206 +	ERR_PRINTF2( _L("CMdaAudioRecorderUtility completed with error %d"),iError );
   1.207 +	User::After(KOneSecond);
   1.208 +
   1.209 +	return	ret;
   1.210 +	}