os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/SDevSound/SDSCapTestServer/src/CapTestStep0010.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/SDevSound/SDSCapTestServer/src/CapTestStep0010.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,303 @@
     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 +// CapTestStep0010.h
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "CapTestStep0010.h"
    1.22 +
    1.23 +CSecDevSndTS0010* CSecDevSndTS0010::NewL()
    1.24 +	{
    1.25 +	CSecDevSndTS0010* self = new (ELeave) CSecDevSndTS0010;
    1.26 +	CleanupStack::PushL(self);
    1.27 +	self->ConstructL();
    1.28 +	CleanupStack::Pop();
    1.29 +	return self;
    1.30 +	}
    1.31 +	
    1.32 +void CSecDevSndTS0010::ConstructL()
    1.33 +	{
    1.34 +	}
    1.35 +	
    1.36 +
    1.37 +void CSecDevSndTS0010::StartProcessing(TRequestStatus& aStatus)
    1.38 +	{
    1.39 +	iStatus = &aStatus;
    1.40 +	if ( (iVerdict = DoTestStepPreambleL() ) == EPass)
    1.41 +		{
    1.42 +		// only do this when DoTestStepPreambleL() pass, if it fails, it means 
    1.43 +		// devsound is not ready for play data yet.
    1.44 +		iVerdict = DoRecordData();
    1.45 +		}
    1.46 +	}
    1.47 +		
    1.48 +CSecDevSndTS0010::~CSecDevSndTS0010()
    1.49 +	{
    1.50 +	}
    1.51 +
    1.52 +/******************************************************************************
    1.53 + *
    1.54 + * DevSound methods
    1.55 + *
    1.56 + *****************************************************************************/
    1.57 + 
    1.58 +/**
    1.59 + *
    1.60 + * DoTestStepL
    1.61 + * @result TVerdict
    1.62 + *
    1.63 + */
    1.64 +
    1.65 +TVerdict CSecDevSndTS0010::DoRecordData()
    1.66 +	{
    1.67 +	//Initialize
    1.68 +	TVerdict initOK = TestInitialize(EMMFStateRecording);
    1.69 +	if (initOK != EPass)
    1.70 +		{
    1.71 +		return EInconclusive;
    1.72 +		}
    1.73 +
    1.74 +	TestSetPriority(KDevSoundPriorityHigh);
    1.75 +
    1.76 +	initOK = TestRecordInit();
    1.77 +	if (initOK != EPass)
    1.78 +		{
    1.79 +		return EInconclusive;
    1.80 +		}
    1.81 +
    1.82 +	User::RequestComplete(iStatus, KErrNone);
    1.83 +
    1.84 +	TestSetVolume(iMMFDevSound->MaxVolume() / 2);
    1.85 +
    1.86 +	TFileName	aFilename = _L("C:\\rectest1.wav");
    1.87 +
    1.88 +	return RecordDataFile(aFilename);
    1.89 +	}
    1.90 +
    1.91 +/**
    1.92 + *
    1.93 + * TestDigitalPlayback
    1.94 + * @param aNumSamples
    1.95 + * @param aFilename
    1.96 + * @param aDataType
    1.97 + * @result TVerdict
    1.98 + *
    1.99 + */
   1.100 +TVerdict CSecDevSndTS0010::RecordDataFile(TDesC& aFilename)
   1.101 +	{
   1.102 +	TInt		initOK = KErrNone;
   1.103 +	TInt		aNumSamples = 1;
   1.104 +
   1.105 +	//open file
   1.106 +	RFs fs;
   1.107 +	RFile file;
   1.108 +	TInt err = fs.Connect();
   1.109 +	if (err != KErrNone)
   1.110 +		{
   1.111 +		// Could not connect to Filesystem.
   1.112 +		return EInconclusive;
   1.113 +		}
   1.114 +
   1.115 +	//Create output directory if it doesn't already exist
   1.116 +//	fs.MkDir(_L("C:\\TSU_MMF_DEVSOUND_SUITE\\Output\\"));
   1.117 +
   1.118 +	err = file.Replace(fs, aFilename, EFileWrite);
   1.119 +	if (err != KErrNone)
   1.120 +		{
   1.121 +		file.Close();
   1.122 +		fs.Close();
   1.123 +		return EInconclusive;
   1.124 +		}
   1.125 +
   1.126 +	//SetGain
   1.127 +	TInt vol = iMMFDevSound->MaxVolume();	// Hacked... Fix this...
   1.128 +	TestSetGain(vol);
   1.129 +
   1.130 +	TInt bufferCount = 0;
   1.131 +	while (bufferCount < aNumSamples && initOK == KErrNone && iCallbackError == KErrNone)
   1.132 +		{
   1.133 +		//DevSound Record
   1.134 +		initOK = TestRecordData();
   1.135 +
   1.136 +		//Write buffer to file
   1.137 +		CMMFDataBuffer* buffer = STATIC_CAST (CMMFDataBuffer*, iBuffer);
   1.138 +		file.Write(buffer->Data());
   1.139 +
   1.140 +		bufferCount ++;
   1.141 +		}
   1.142 +
   1.143 +	file.Close();
   1.144 +	fs.Close();
   1.145 +
   1.146 +	if (initOK != KErrNone)
   1.147 +		{
   1.148 +		return EFail;
   1.149 +		}
   1.150 +
   1.151 +	if (aNumSamples >= 0 && bufferCount != aNumSamples)
   1.152 +		{
   1.153 +		return EFail;
   1.154 +		}
   1.155 +
   1.156 +	return EPass;
   1.157 +	}
   1.158 +
   1.159 +/**
   1.160 + *
   1.161 + * TestInitialize
   1.162 + * @param aDataType
   1.163 + * @param aMode
   1.164 + * @result TVerdict
   1.165 + *
   1.166 + */
   1.167 +TVerdict CSecDevSndTS0010::TestInitialize(TMMFState aMode)
   1.168 +	{
   1.169 +	TFourCC pcm16(KMMFFourCCCodePCM16); //default to pcm16 data type
   1.170 +
   1.171 +	iCallbackError = KErrNone;
   1.172 +	iExpectedValue = KErrNone;
   1.173 +
   1.174 +	// Initialize
   1.175 +	TRAPD(err, iMMFDevSound->InitializeL(*this, pcm16, aMode));
   1.176 +	if (err)
   1.177 +		{
   1.178 +		return EInconclusive;
   1.179 +		}
   1.180 +	else
   1.181 +		{
   1.182 +		CActiveScheduler::Start();
   1.183 +		
   1.184 +		if (iCallbackError != iExpectedValue)
   1.185 +			{
   1.186 +			return EFail;
   1.187 +			}
   1.188 +		if (iCallbackArray[EInitComplete] != 1)
   1.189 +			{
   1.190 +			return EFail;
   1.191 +			}
   1.192 +		}
   1.193 +	return EPass;
   1.194 +	}
   1.195 +
   1.196 +/**
   1.197 + *
   1.198 + * TestRecordInit
   1.199 + * @result TVerdict
   1.200 + *
   1.201 + */
   1.202 +TVerdict CSecDevSndTS0010::TestRecordInit()
   1.203 +	{
   1.204 +	ResetCallbacks();
   1.205 +
   1.206 +	//get buffer from devsound
   1.207 +	TRAPD(err, iMMFDevSound->RecordInitL());
   1.208 +	// Start the active scheduler and catch the callback
   1.209 + 	CActiveScheduler::Start();
   1.210 +	if (err)
   1.211 +		{
   1.212 +		return EFail;
   1.213 +		}
   1.214 +	else
   1.215 +		{
   1.216 +		if (iCallbackArray[EBuffToEmpty] != 1)
   1.217 +			{
   1.218 +			return EFail;
   1.219 +			}
   1.220 +		TInt tot = GetCallbackTotal();
   1.221 +		if (tot > 1)
   1.222 +			{
   1.223 +			return EFail;
   1.224 +			}
   1.225 +		}
   1.226 +	return EPass;
   1.227 +	}
   1.228 +
   1.229 +/**
   1.230 + *
   1.231 + * TestRecordData
   1.232 + * @result TVerdict
   1.233 + *
   1.234 + */
   1.235 +TVerdict CSecDevSndTS0010::TestRecordData()
   1.236 +	{
   1.237 +	ResetCallbacks();
   1.238 +
   1.239 +	iMMFDevSound->RecordData();
   1.240 +	// Start the active scheduler and catch the callback
   1.241 + 	CActiveScheduler::Start();
   1.242 +
   1.243 +	if (iCallbackArray[EBuffToEmpty] != 1)
   1.244 +		{
   1.245 +		if (iCallbackArray[EBuffToEmpty] == 0 && iCallbackArray[ERecError] == 1)
   1.246 +			{
   1.247 +			// DevSound RecordError was called 1 time.
   1.248 +			}
   1.249 +		else
   1.250 +			{
   1.251 +			return EFail;
   1.252 +			}
   1.253 +		}
   1.254 +
   1.255 +	TInt tot = GetCallbackTotal();
   1.256 +	if (tot > 1)
   1.257 +		{
   1.258 +		return EFail;
   1.259 +		}
   1.260 +	return EPass;
   1.261 +	}
   1.262 +
   1.263 +/******************************************************************************
   1.264 + *
   1.265 + * DevSound mixin methods
   1.266 + *
   1.267 + *****************************************************************************/
   1.268 + 
   1.269 +/**
   1.270 + * 
   1.271 + * BufferToBeEmptied
   1.272 + * @param aBuffer
   1.273 + *
   1.274 + */
   1.275 +void CSecDevSndTS0010::BufferToBeEmptied (CMMFBuffer* aBuffer)
   1.276 +	{
   1.277 +	iBuffer = aBuffer;
   1.278 +	if (aBuffer != NULL)
   1.279 +		{
   1.280 +		iCallbackError = KErrNone;
   1.281 +		}
   1.282 +	else
   1.283 +		{
   1.284 +		iCallbackError = KErrNotFound;
   1.285 +		}
   1.286 +	iCallbackArray[EBuffToEmpty] ++;
   1.287 +	CActiveScheduler::Stop();
   1.288 +	}
   1.289 +
   1.290 +/**
   1.291 + *
   1.292 + * RecordError
   1.293 + * @param aError
   1.294 + *
   1.295 + */
   1.296 +void CSecDevSndTS0010::RecordError (TInt aError)
   1.297 +	{
   1.298 +	if( aError != KErrInUse )
   1.299 +		{
   1.300 +		// should get interrupted by client
   1.301 +		iVerdict = EFail;
   1.302 +		}
   1.303 +	iCallbackError = aError;
   1.304 +	iCallbackArray[ERecError] ++;
   1.305 +	CActiveScheduler::Stop();
   1.306 +	}