os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/OpenFileByHandle7906.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/OpenFileByHandle7906.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 "TestPlayerUtils.h"
    1.21 +#include "OpenFileByHandle7906.h"
    1.22 +
    1.23 +#include <caf/caf.h>
    1.24 +
    1.25 +/**
    1.26 + * Constructor
    1.27 + */
    1.28 +CTestMmfAclntOpenFile7906::CTestMmfAclntOpenFile7906(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 +CTestMmfAclntOpenFile7906* CTestMmfAclntOpenFile7906::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
    1.43 +	{
    1.44 +	CTestMmfAclntOpenFile7906* self = new (ELeave) CTestMmfAclntOpenFile7906(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
    1.45 +	return self;
    1.46 +	}
    1.47 +
    1.48 +CTestMmfAclntOpenFile7906* CTestMmfAclntOpenFile7906::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
    1.49 +	{
    1.50 +	CTestMmfAclntOpenFile7906* self = CTestMmfAclntOpenFile7906::NewLC(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
    1.51 +	CleanupStack::PushL(self);
    1.52 +	return self;
    1.53 +	}
    1.54 +
    1.55 +void CTestMmfAclntOpenFile7906::MoscoStateChangeEvent(CBase* /*aObject*/, TInt /*aPreviousState*/, TInt /*aCurrentState*/, TInt aErrorCode)
    1.56 +	{
    1.57 +	iError = aErrorCode;
    1.58 +	INFO_PRINTF1( _L("CTestMmfAclntOpenFile7906 : 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 CTestMmfAclntOpenFile7906::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
    1.66 +	{
    1.67 +	iError = aError;
    1.68 +	CActiveScheduler::Stop();
    1.69 +	}
    1.70 +
    1.71 +void CTestMmfAclntOpenFile7906::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 CTestMmfAclntOpenFile7906::MaoscOpenComplete(TInt aError)
    1.79 +	{
    1.80 +	iError = aError;
    1.81 +	CActiveScheduler::Stop();
    1.82 +	}
    1.83 +
    1.84 +void CTestMmfAclntOpenFile7906::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/)
    1.85 +	{
    1.86 +	iError = aError;
    1.87 +	CActiveScheduler::Stop();
    1.88 +	}
    1.89 +
    1.90 +void CTestMmfAclntOpenFile7906::MaoscPlayComplete(TInt aError)
    1.91 +	{
    1.92 +	iError = aError;
    1.93 +	CActiveScheduler::Stop();
    1.94 +	}
    1.95 +
    1.96 +
    1.97 +TVerdict CTestMmfAclntOpenFile7906::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 +		{
   1.105 +		return ret;
   1.106 +		}
   1.107 +	
   1.108 +	return CTestMmfAclntStep::DoTestStepPreambleL();
   1.109 +	}
   1.110 +
   1.111 +/**
   1.112 + * Open a file based clip and record
   1.113 + */
   1.114 +TVerdict CTestMmfAclntOpenFile7906::DoTestStepL()
   1.115 +	{
   1.116 +	INFO_PRINTF1( _L("TestRecorder : Record File"));
   1.117 +	TVerdict ret = EFail;
   1.118 +	iError = KErrTimedOut;
   1.119 +
   1.120 +	RFs fs;
   1.121 +	RFile file;
   1.122 +
   1.123 +	User::LeaveIfError(fs.Connect());
   1.124 +	CleanupClosePushL(fs);
   1.125 +	User::LeaveIfError(fs.ShareProtected());
   1.126 +
   1.127 +	TPtrC			filename; 
   1.128 +	if(!GetStringFromConfig(iSectName, iKeyName, filename))
   1.129 +		{
   1.130 +		return EInconclusive;
   1.131 +		}
   1.132 +
   1.133 +	CMdaAudioRecorderUtility* recUtil = CMdaAudioRecorderUtility::NewL(*this);
   1.134 +	CleanupStack::PushL(recUtil);
   1.135 +
   1.136 +	TUid audioController = TUid::Uid(KMmfUidControllerAudio);
   1.137 +
   1.138 +	TFourCC invalidDataType(0xAA, 0xAA, 0xAA, 0xAA);
   1.139 +
   1.140 +	User::LeaveIfError(file.Replace(fs,filename,EFileWrite));
   1.141 +	CleanupClosePushL(file);
   1.142 +
   1.143 +	recUtil->OpenFileL(file, audioController, KNullUid, KNullUid, invalidDataType);
   1.144 +
   1.145 +	INFO_PRINTF1( _L("Initialise CMdaAudioRecorderUtility"));
   1.146 +	CActiveScheduler::Start();
   1.147 +
   1.148 +	if( iError == KErrNotSupported )
   1.149 +		{
   1.150 +		ret = EPass;
   1.151 +		}
   1.152 +
   1.153 +	if(iError == KErrNone)
   1.154 +		{
   1.155 +		iError = KErrTimedOut;
   1.156 +		recUtil->RecordL();
   1.157 +		INFO_PRINTF1( _L("Record CMdaAudioRecorderUtility"));
   1.158 +		CActiveScheduler::Start(); // open -> record
   1.159 +
   1.160 +		User::After(500000);
   1.161 +
   1.162 +		recUtil->Stop();
   1.163 +		}
   1.164 +
   1.165 +	CleanupStack::PopAndDestroy(2, recUtil);	// file, recUtil
   1.166 +	recUtil = NULL;
   1.167 +
   1.168 +	// Playback the file
   1.169 +	if (iError == KErrNone)
   1.170 +		{
   1.171 +		if (filename.Right(4).Compare(_L(".wav"))==0)
   1.172 +			{
   1.173 +			// Wav file playback
   1.174 +			CMdaAudioPlayerUtility* playUtil = CMdaAudioPlayerUtility::NewL(*this);
   1.175 +			CleanupStack::PushL(playUtil);
   1.176 +			TRAPD(err, playUtil->OpenFileL(filename));
   1.177 +			if (err != KErrNone)
   1.178 +				{
   1.179 +				INFO_PRINTF2(_L("Error opening file for playback err = %d"), err);
   1.180 +				ret = EFail;
   1.181 +				}
   1.182 +			CActiveScheduler::Start();
   1.183 +			if (iError != KErrNone)
   1.184 +				{
   1.185 +				INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError);
   1.186 +				ret = EFail;
   1.187 +				}
   1.188 +			playUtil->Play();
   1.189 +			CActiveScheduler::Start();
   1.190 +			CleanupStack::PopAndDestroy(playUtil);
   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 +	}