os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/SDevSound/SDSCapTestServer/src/CapTestStep0008.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/CapTestStep0008.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,322 @@
     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 "CapTestStep0008.h"
    1.20 +
    1.21 +CSecDevSndTS0008* CSecDevSndTS0008::NewL()
    1.22 +	{
    1.23 +	CSecDevSndTS0008* self = new (ELeave) CSecDevSndTS0008;
    1.24 +	CleanupStack::PushL(self);
    1.25 +	self->ConstructL();
    1.26 +	CleanupStack::Pop();
    1.27 +	return self;
    1.28 +	}
    1.29 +	
    1.30 +void CSecDevSndTS0008::ConstructL()
    1.31 +	{
    1.32 +	iIsFirst = ETrue;
    1.33 +	}
    1.34 +	
    1.35 +
    1.36 +void CSecDevSndTS0008::StartProcessing(TRequestStatus& aStatus)
    1.37 +	{
    1.38 +	iStatus = &aStatus;
    1.39 +	if ( (iVerdict = DoTestStepPreambleL() ) == EPass)
    1.40 +		{
    1.41 +		// only do this when DoTestStepPreambleL() pass, if it fails, it means 
    1.42 +		// devsound is not ready for play data yet.
    1.43 +		iVerdict = DoPlayData();
    1.44 +		}
    1.45 +	}
    1.46 +		
    1.47 +CSecDevSndTS0008::~CSecDevSndTS0008()
    1.48 +	{
    1.49 +	}
    1.50 +
    1.51 +/******************************************************************************
    1.52 + *
    1.53 + * DevSound methods
    1.54 + *
    1.55 + *****************************************************************************/
    1.56 + 
    1.57 +/**
    1.58 + *
    1.59 + * DoTestStepL
    1.60 + * @result TVerdict
    1.61 + *
    1.62 + */
    1.63 +
    1.64 +TVerdict CSecDevSndTS0008::DoPlayData()
    1.65 +	{
    1.66 +	//Initialize
    1.67 +	TVerdict initOK = TestInitialize(EMMFStatePlaying);
    1.68 +	if (initOK != EPass)
    1.69 +		{
    1.70 +		return EInconclusive;
    1.71 +		}
    1.72 +
    1.73 +	TestSetPriority(KDevSoundPriorityHigh);
    1.74 +
    1.75 +	initOK = TestPlayInit();
    1.76 +	if (initOK != EPass)
    1.77 +		{
    1.78 +		return EInconclusive;
    1.79 +		}
    1.80 +
    1.81 +	User::RequestComplete(iStatus, KErrNone);
    1.82 +
    1.83 +	TestSetVolume(iMMFDevSound->MaxVolume() / 2);
    1.84 +
    1.85 +	_LIT(KTestFileName, "C:\\sdevsoundinttestdata\\mainTst.wav");
    1.86 +	TFileName aFilename(KTestFileName);
    1.87 +
    1.88 +	return PlayDataFile(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 CSecDevSndTS0008::PlayDataFile(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 +		return EInconclusive;
   1.112 +		}
   1.113 +
   1.114 +	err = file.Open(fs, aFilename, EFileRead);
   1.115 +	if (err != KErrNone)
   1.116 +		{
   1.117 +		fs.Close();
   1.118 +		return EInconclusive;
   1.119 +		}
   1.120 +
   1.121 +	TInt bufferCount = 0;
   1.122 +	if (aNumSamples < 0)
   1.123 +		{// Play to EOF
   1.124 +		while (initOK == KErrNone && iCallbackError == KErrNone)
   1.125 +			{
   1.126 +			//read sizeof buffer from file
   1.127 +			CMMFDataBuffer*  buffer = STATIC_CAST (CMMFDataBuffer*, iBuffer);
   1.128 +			file.Read(buffer->Data());
   1.129 +			if (buffer->Data().Length()!= buffer->RequestSize())
   1.130 +				{
   1.131 +				iBuffer->SetLastBuffer(ETrue);
   1.132 +				}
   1.133 +
   1.134 +			//DevSound Play
   1.135 +			initOK = TestPlayData();
   1.136 +			bufferCount ++;
   1.137 +			}
   1.138 +		}
   1.139 +	else
   1.140 +		{
   1.141 +		while (bufferCount < aNumSamples && initOK == KErrNone && iCallbackError == KErrNone)
   1.142 +			{
   1.143 +			//read sizeof buffer from file
   1.144 +			CMMFDataBuffer* buffer = STATIC_CAST (CMMFDataBuffer*, iBuffer);
   1.145 +			file.Read(buffer->Data());
   1.146 +			if (buffer->Data().Length()!= buffer->RequestSize())
   1.147 +				{
   1.148 +				iBuffer->SetLastBuffer(ETrue);
   1.149 +				}
   1.150 +
   1.151 +			//DevSound Play
   1.152 +			initOK = TestPlayData();
   1.153 +			bufferCount ++;
   1.154 +			}
   1.155 +		}
   1.156 +
   1.157 +	file.Close();
   1.158 +	fs.Close();
   1.159 +
   1.160 +	if (initOK != KErrNone)
   1.161 +		{
   1.162 +		return EFail;
   1.163 +		}
   1.164 +
   1.165 +	if (aNumSamples >= 0 && bufferCount != aNumSamples)
   1.166 +		{
   1.167 +		return EFail;
   1.168 +		}
   1.169 +
   1.170 +	return EPass;
   1.171 +	}
   1.172 +
   1.173 +/**
   1.174 + *
   1.175 + * TestInitialize
   1.176 + * @param aDataType
   1.177 + * @param aMode
   1.178 + * @result TVerdict
   1.179 + *
   1.180 + */
   1.181 +TVerdict CSecDevSndTS0008::TestInitialize(TMMFState aMode)
   1.182 +	{
   1.183 +	TFourCC pcm16(KMMFFourCCCodePCM16); //default to pcm16 data type
   1.184 +
   1.185 +	iCallbackError = KErrNone;
   1.186 +	iExpectedValue = KErrNone;
   1.187 +
   1.188 +	// Initialize
   1.189 +	TRAPD(err, iMMFDevSound->InitializeL(*this, pcm16, aMode));
   1.190 +	if (err)
   1.191 +		{
   1.192 +		return EInconclusive;
   1.193 +		}
   1.194 +	else
   1.195 +		{
   1.196 +		CActiveScheduler::Start();
   1.197 +
   1.198 +		if (iCallbackError != iExpectedValue)
   1.199 +			{
   1.200 +			return EFail;
   1.201 +			}
   1.202 +		if (iCallbackArray[EInitComplete] != 1)
   1.203 +			{
   1.204 +			return EFail;
   1.205 +			}
   1.206 +		}
   1.207 +	return EPass;
   1.208 +	}
   1.209 +
   1.210 +/**
   1.211 + *
   1.212 + * TestPlayInit
   1.213 + * @result TVerdict
   1.214 + *
   1.215 + */
   1.216 +TVerdict CSecDevSndTS0008::TestPlayInit()
   1.217 +	{
   1.218 +	ResetCallbacks();
   1.219 +
   1.220 +	//get buffer from devsound
   1.221 +	TRAPD(err, iMMFDevSound->PlayInitL());
   1.222 +	// Start the active scheduler and catch the callback
   1.223 + 	CActiveScheduler::Start();
   1.224 +	if (err)
   1.225 +		{
   1.226 +		return EFail;
   1.227 +		}
   1.228 +	else
   1.229 +		{
   1.230 +		if (iCallbackArray[EBuffToFill] != 1)
   1.231 +			{
   1.232 +			return EFail;
   1.233 +			}
   1.234 +		TInt tot = GetCallbackTotal();
   1.235 +		if (tot > 1)
   1.236 +			{
   1.237 +			return EFail;
   1.238 +			}
   1.239 +		}
   1.240 +	return EPass;
   1.241 +	}
   1.242 +
   1.243 +/**
   1.244 + *
   1.245 + * TestPlayData
   1.246 + * @result TVerdict
   1.247 + *
   1.248 + */
   1.249 +TVerdict CSecDevSndTS0008::TestPlayData()
   1.250 +	{
   1.251 +	ResetCallbacks();
   1.252 +
   1.253 +	iMMFDevSound->PlayData();
   1.254 +	// Start the active scheduler and catch the callback
   1.255 + 	CActiveScheduler::Start();
   1.256 +
   1.257 +	if (iCallbackArray[EBuffToFill] != 1)
   1.258 +		{
   1.259 +		if (iCallbackArray[EBuffToFill] == 0 && iCallbackArray[EPlayError] == 1)
   1.260 +			{
   1.261 +			// DevSound PlayError was called 1 time. Must be EOF.
   1.262 +			}
   1.263 +		else
   1.264 +			{
   1.265 +			return EFail;
   1.266 +			}
   1.267 +		}
   1.268 +
   1.269 +	TInt tot = GetCallbackTotal();
   1.270 +	if (tot > 2)
   1.271 +		{
   1.272 +		return EFail;
   1.273 +		}
   1.274 +	return EPass;
   1.275 +	}
   1.276 +
   1.277 +/******************************************************************************
   1.278 + *
   1.279 + * DevSound mixin methods
   1.280 + *
   1.281 + *****************************************************************************/
   1.282 + 
   1.283 +/**
   1.284 + *
   1.285 + * BufferToBeFilled
   1.286 + * @param aBuffer
   1.287 + *
   1.288 + */
   1.289 +void CSecDevSndTS0008::BufferToBeFilled (CMMFBuffer* aBuffer)
   1.290 +	{
   1.291 +	iBuffer = aBuffer;
   1.292 +	if (aBuffer != NULL) 
   1.293 +		{
   1.294 +		if( iIsFirst )
   1.295 +			{
   1.296 +			iIsFirst = EFalse;
   1.297 +			}
   1.298 +		iCallbackError = KErrNone;
   1.299 +		}
   1.300 +	else 
   1.301 +		{
   1.302 +		iCallbackError = KErrNotFound;
   1.303 +		}
   1.304 +	iCallbackArray[EBuffToFill] ++;
   1.305 +	CActiveScheduler::Stop();
   1.306 +	}
   1.307 +
   1.308 +/**
   1.309 + *
   1.310 + * PlayError
   1.311 + * @param aError
   1.312 + *
   1.313 + */
   1.314 +void CSecDevSndTS0008::PlayError (TInt aError)
   1.315 +	{
   1.316 +	if( aError != KErrInUse )
   1.317 +		{
   1.318 +		// should get interrupted by client
   1.319 +		iVerdict = EFail;
   1.320 +		}
   1.321 +
   1.322 +	iCallbackError = aError;
   1.323 +	iCallbackArray[EPlayError] ++;
   1.324 +	CActiveScheduler::Stop();
   1.325 +	}