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