os/mm/mmlibs/mmfw/tsrc/mmfunittest/Actrl/TestStepActrlPlay.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // TestStepActrlPlay
    15 //
    16 
    17 #include <e32std.h>
    18 #include <e32base.h>
    19 #include <mmf/common/mmfcontroller.h>
    20 #include <mmf/server/mmffile.h>
    21 #include <mmf/server/mmfdes.h>
    22 #include <mmf/plugin/mmfcontrollerimplementationuids.hrh>
    23 #include <mmf/common/mmfstandardcustomcommands.h>
    24 
    25 #include "ActrlTestUids.h"
    26 
    27 // Test system includes
    28 #include <testframework.h>
    29 
    30 // Specific includes for this test suite
    31 #include "TS_MMF_ACTRL_TestStep.h"
    32 #include "TS_MMF_ACTRL_TestSuite.h"
    33 
    34 // Specific includes for these test steps
    35 #include "TestStepActrlPlay.h"
    36 
    37 // CONSTANTS
    38 //const TInt KPlayDelayNewMail = 100000000; //arbitrary delay	// EABI warning removal
    39 
    40 const TUint KSampleRate8000Hz  = 8000;
    41 const TUint KSampleRate11025Hz = 11025;
    42 const TUint KSampleRate22050Hz = 22050;
    43 const TUint KSampleRate44100Hz = 44100;
    44 
    45 const TUint KNone	= 0;
    46 const TUint KMono	= 1;
    47 const TUint KStereo = 2;
    48 
    49 //const TUint KFormatWAV = 0;
    50 //const TUint KFormatAU  = 1;
    51 //const TUint KFormatRAW = 2;
    52 
    53 // parameter structure for conversion tests
    54 class TConvParameters
    55 	{	
    56 public:
    57 	const TText* iTestName;
    58 	TUid	iSrcFormat;
    59 	TUid	iDestFormat;
    60 	TUint32 iSrcEncoding;
    61 	TUint32 iDestEncoding;
    62 	TUint	iSrcSampleRate;
    63 	TUint	iDestSampleRate;
    64 	TUint	iSrcChannels;
    65 	TUint	iDestChannels;
    66 	const TText* iFromFilename;
    67 	const TText* iRefFilename;
    68 	TInt	iExpectedResult;
    69 	};
    70 
    71 
    72 // constant table of parameters for tests
    73 const TConvParameters KTestParameters[] =
    74 {	
    75 	// straight encode test
    76 	{ _S("MM-MMF-ACTRL-U-0040-HP"), {KMmfUidFormatWAVRead},	{KMmfUidFormatAUWrite},		KMMFFourCCCodePCM16,	KMMFFourCCCodePCM16B,	KSampleRate44100Hz,		KSampleRate8000Hz,	KStereo,	KMono,		_S("44KHzPCM16Stereo1KHzTone.wav"),	_S("44KHzPCM16StereoWAVTo8KHzPCM16Mono.au"),	KErrNone },
    77 	{ _S("MM-MMF-ACTRL-U-0041-HP"), {KMmfUidFormatWAVRead},	{KMmfUidFormatWAVWrite},	KMMFFourCCCodePCMU8,	KMMFFourCCCodePCM16,	KSampleRate22050Hz,		KSampleRate11025Hz,	KMono,		KStereo,	_S("22KHzPCM8Mono1KHzTone.wav"),	_S("22KHzPCM8MonoWAVTo11KHzPCM16Stereo.wav"),	KErrNone },
    78 	{ _S("MM-MMF-ACTRL-U-0042-HP"), {KMmfUidFormatWAVRead},	{KMmfUidFormatRAWWrite},	KMMFFourCCCodeIMAD,		KMMFFourCCCodePCM16,	KSampleRate11025Hz,		KSampleRate8000Hz,	KMono,		KMono,		_S("11KHzADPCMMono1KHzTone.wav"),	_S("11KHzADPCMMonoWAVTo8KHzPCM16Mono.raw"),		KErrNone },
    79 	{ _S("MM-MMF-ACTRL-U-0043-HP"), {KMmfUidFormatAURead},	{KMmfUidFormatAUWrite},		KMMFFourCCCodePCM16B,	KMMFFourCCCodePCM16B,	KSampleRate8000Hz,		KSampleRate8000Hz,	KMono,		KMono,		_S("8KHzPCM16Mono1KHzTone.au"),		_S("8KHzPCM16MonoAUTo8KHzPCM16Mono.au"),		KErrNone },
    80 	{ _S("MM-MMF-ACTRL-U-0044-HP"), {KMmfUidFormatAURead},	{KMmfUidFormatRAWWrite},	KMMFFourCCCodePCM16B,	KMMFFourCCCodePCM16,	KSampleRate44100Hz,		KSampleRate22050Hz,	KStereo,	KMono,		_S("44KHzPCM16Stereo1KHzTone.au"),	_S("44KHzPCM16StereoAUTo22KHzPCM16Mono.raw"),	KErrNone },
    81 	{ _S("MM-MMF-ACTRL-U-0045-HP"), {KMmfUidFormatAURead},	{KMmfUidFormatWAVWrite},	KMMFFourCCCodePCM16B,	KMMFFourCCCodePCM16,	KSampleRate22050Hz,		KSampleRate8000Hz,	KMono,		KMono,		_S("22KHzPCM16Mono1KHzTone.au"),	_S("22KHzPCM16MonoAUTo8KhzPCM16Mono.wav"),		KErrNone },
    82 	{ _S("MM-MMF-ACTRL-U-0046-HP"), {KMmfUidFormatRAWRead},	{KMmfUidFormatWAVWrite},	KMMFFourCCCodeGSM610,	KMMFFourCCCodePCM16,	KSampleRate8000Hz,		KSampleRate8000Hz,	KMono,		KMono,		_S("8KHzGSM610Mono1KHzTone.raw"),	_S("8KHzGSM610MonoRAWTo8KHzPCM16Mono.wav"),		KErrNone },
    83 	{ _S("MM-MMF-ACTRL-U-0047-HP"), {KMmfUidFormatRAWRead},	{KMmfUidFormatRAWWrite},	KMMFFourCCCodeALAW,		KMMFFourCCCodePCM16,	KSampleRate22050Hz,		KSampleRate11025Hz,	KStereo,	KMono,		_S("22KHzALAWStereo1KHzTone.raw"),	_S("22KHzALAWStereoRAWTo11KHzPCM16Mono.raw"),	KErrNone },
    84 	{ _S("MM-MMF-ACTRL-U-0048-HP"), {KMmfUidFormatRAWRead},	{KMmfUidFormatWAVWrite},	KMMFFourCCCodePCM16,	KMMFFourCCCodeGSM610,	KSampleRate11025Hz,		KSampleRate8000Hz,	KMono,		KMono,		_S("11KHzPCM16Mono1KHzTone.raw"),	_S("11KHzPCM16MonoRAWTo8KHzGSM610Mono.wav"),	KErrNone },
    85 	{ _S("MM-MMF-ACTRL-U-0049-HP"), {KMmfUidFormatWAVRead},	{KMmfUidFormatWAVWrite},	KMMFFourCCCodeALAW,		KMMFFourCCCodePCM16,	KSampleRate22050Hz,		KSampleRate8000Hz,	KMono,		KMono,		_S("22KHzALAWMono1KHzTone.wav"),	_S("22KHzALAWMonoWAVTo8KHzPCM16Mono.wav"),		KErrNone },
    86 	{ _S("MM-MMF-ACTRL-U-0050-HP"), {KMmfUidFormatWAVRead},	{KMmfUidFormatWAVWrite},	KMMFFourCCCodePCM16,	KMMFFourCCCodeMuLAW,	KSampleRate11025Hz,		KSampleRate8000Hz,	KStereo,	KMono,		_S("11KHzPCM16Stereo1KHzTone.wav"), _S("11KHzPCM16StereoWAVTo8KHzMuLAWMono.wav"),	KErrNone },
    87 	{ _S("MM-MMF-ACTRL-U-0051-HP"), {KMmfUidFormatWAVRead},	{KMmfUidFormatWAVWrite},	KMMFFourCCCodePCM16,	KMMFFourCCCodeGSM610,	KSampleRate8000Hz,		KSampleRate8000Hz,	KStereo,	KMono,		_S("8KHzPCM16Stereo1KHzTone.wav"),	_S("8KHzPCM16StereoWAVTo8KHzGSM610Mono.wav"),	KErrNone },
    88 	
    89 	// test 52 not currently supported - should return -5
    90 	{ _S("MM-MMF-ACTRL-U-0052-HP"), {KMmfUidFormatAURead},	{KMmfUidFormatAUWrite},		KMMFFourCCCodePCM16B,	KMMFFourCCCodeIMAD,		KSampleRate22050Hz,		KSampleRate8000Hz,	KMono,		KMono,		_S("22KHzPCM16Mono1KHzTone.au"),	_S("NoReferenceFile"),	KErrNotSupported },
    91 	
    92 	{ _S("MM-MMF-ACTRL-U-0053-HP"), {KMmfUidFormatRAWRead},	{KMmfUidFormatAUWrite},		KMMFFourCCCodePCM16,	KMMFFourCCCodePCM16B,	KSampleRate44100Hz,		KSampleRate8000Hz,	KStereo,	KStereo,	_S("44KHzPCM16Stereo1KHzTone.raw"),	_S("44KHzPCM16StereoRAWTo8KHzPCM16Stereo.au"),	KErrNone },
    93 	
    94 	// test below will return -5
    95 	{ _S("MM-MMF-ACTRL-U-0054-HP"),	{KMmfUidFormatWAVRead},	{KMmfUidFormatWAVWrite},	KMMFFourCCCodePCM16,	KMMFFourCCCodePCM16,	KSampleRate11025Hz,		KSampleRate44100Hz,	KStereo,	KStereo,	_S("11KHzPCM16Stereo1KHzTone.wav"),	_S("NoReferenceFile"),	KErrNotSupported },
    96 	{ _S("MM-MMF-ACTRL-U-0055-HP"),	{KMmfUidFormatWAVRead},	{KMmfUidFormatAUWrite},		KMMFFourCCCodePCM16,	KMMFFourCCCodeIMAD,		KSampleRate22050Hz,		KSampleRate22050Hz,	KStereo,	KStereo,	_S("22KHzPCM16Stereo1KHzTone.wav"), _S("NoReferenceFile"),	KErrNotSupported },
    97 
    98 	// replacement for test 039 - see DEF017344
    99 	{ _S("MM-MMF-ACTRL-U-0039-HP"),	{KMmfUidFormatAURead},	{KMmfUidFormatWAVWrite},	KMMFFourCCCodePCM8,		KMMFFourCCCodePCM16,	KSampleRate11025Hz,		KSampleRate8000Hz,	KMono,		KMono,		_S("NewMail.au"),					_S("11KHzPCMU8MonoAUTo8KHzPCM16Mono.wav"),		KErrNone },
   100 
   101 	//DEF025783 - Convert Stereo PCM16 to IMA ADPCM
   102 	//Sink channels are not configured, we are testing if negotiation will do this
   103 	{ _S("MM-MMF-ACTRL-U-0056-HP"),	{KMmfUidFormatWAVRead},	{KMmfUidFormatWAVWrite},	KMMFFourCCCodePCM16,	KMMFFourCCCodeIMAD,		KSampleRate11025Hz,		KSampleRate11025Hz,	KStereo,	KNone,		_S("11KHzPCM16Stereo1KHzTone.wav"),	_S("11KHzPCM16StereoWAVTo11KHzADPCMMono.wav"),	KErrNone },
   104 	{ _S("MM-MMF-ACTRL-U-0057-HP"),	{KMmfUidFormatWAVRead},	{KMmfUidFormatRAWWrite},	KMMFFourCCCodePCM16,	KMMFFourCCCodeIMAD,		KSampleRate11025Hz,		KSampleRate11025Hz,	KStereo,	KNone,		_S("11KHzPCM16Stereo1KHzTone.wav"),	_S("11KHzPCM16StereoWAVTo11KHzADPCMMono.raw"),	KErrNone },
   105 	//Configure sink channels to stereo expect KErrNotSupported
   106 	{ _S("MM-MMF-ACTRL-U-0058-HP"),	{KMmfUidFormatWAVRead},	{KMmfUidFormatWAVWrite},	KMMFFourCCCodePCM16,	KMMFFourCCCodeIMAD,		KSampleRate11025Hz,		KSampleRate11025Hz,	KStereo,	KStereo,	_S("11KHzPCM16Stereo1KHzTone.wav"),	_S("11KHzPCM16StereoWAVTo11KHzADPCMMono.wav"),	KErrNotSupported },
   107 	{ _S("MM-MMF-ACTRL-U-0059-HP"),	{KMmfUidFormatWAVRead},	{KMmfUidFormatRAWWrite},	KMMFFourCCCodePCM16,	KMMFFourCCCodeIMAD,		KSampleRate11025Hz,		KSampleRate11025Hz,	KStereo,	KStereo,	_S("11KHzPCM16Stereo1KHzTone.wav"),	_S("11KHzPCM16StereoWAVTo11KHzADPCMMono.raw"),	KErrNotSupported }
   108 
   109 };
   110 
   111 
   112 /**
   113 *
   114 * Test step constructor.
   115 * Each test step initialises its own name.
   116 *
   117 */
   118 CTestStepActrlPlay::CTestStepActrlPlay()
   119 	{
   120 	// store the name of this test case
   121 	// this is the name that is used by the script file
   122 	iTestStepName = _L("MM-MMF-ACTRL-U-0018-HP");
   123 	}
   124 
   125 /**
   126 *
   127 * Test step destructor.
   128 * 
   129 */
   130 CTestStepActrlPlay::~CTestStepActrlPlay()
   131 	{
   132 	}
   133 
   134 
   135 /**
   136 * @xxxx
   137 * Do the test step.
   138 * @return	"TVerdict" the status of the test
   139 *			The result of the test step 
   140 */
   141 TVerdict CTestStepActrlPlay::DoTestStepL( void )
   142 	{
   143 	TVerdict result = EPass;
   144 	
   145 	_LIT( KTestPlay, "Play Test");
   146 	Log( KTestPlay );
   147 	
   148 	_LIT( KTestStepPlay, "This test checks playing an audio clip");
   149 	Log( KTestStepPlay );
   150 	
   151 	// [ audio file to play ]
   152 	_LIT(KTestWavFile, "newmail.wav");
   153 		//[ configure the filename ]
   154 	SetReadFileNameL( KTestWavFile );
   155    	
   156 	TInt errorCode = iController.Open(KUidCustomTestAudioPlugin, iPriority);
   157 	User::LeaveIfError( errorCode );
   158 	
   159 	//[ add data source and sink and prime the controller ]
   160     errorCode = iController.AddDataSource(KUidMmfFileSource, ReadFileConfig());
   161 	User::LeaveIfError( errorCode );
   162 	
   163 	errorCode =	iController.AddDataSink(KUidMmfAudioOutput, KNullDesC8);
   164     User::LeaveIfError( errorCode );
   165 	
   166 	errorCode =	iController.Prime();
   167 	User::LeaveIfError( errorCode );
   168 	
   169 	// [ wait for and process the return event from the audio output ]
   170 	
   171 	TMMFEvent primeEvent( KPrimeTestId, KErrNone);
   172 	result = SearchForEvent( primeEvent );
   173 	if( result == EFail )
   174 		{
   175 		return result;
   176 		}
   177 	
   178     User::LeaveIfError( iController.Play() );
   179 	
   180 	// note this test does not wait around 
   181 	// to detect that the audio has been played
   182 	// [ now process the confirmation event that play has reached audio output
   183 	//   this is the raison detre of the test ]
   184 	TMMFEvent playEvent( KPlayTestId, KErrNone );
   185 	
   186 	result = SearchForEvent( playEvent );
   187 	
   188 	//[ ensure the controller is unloaded so that it does 
   189 	// not interfere with the following test ]
   190 	// There is error in this code and the stop followed by reset
   191 	// ensure the controller resources are released.
   192 	iController.Stop();
   193 	iController.Reset();
   194 	iController.Close();  
   195 
   196 	// test steps return a result
   197 	return result;
   198 	}
   199 
   200 /**
   201 *
   202 * CTestStepPlayT
   203 * @param aTimesToPlay
   204 *
   205 */
   206 CTestStepPlayT::CTestStepPlayT( TInt aTimesToPlay )
   207 : iTimesToPlay( aTimesToPlay )
   208 	{
   209 	// store the name of this test case
   210 	// this is the name that is used by the script file
   211 	iTestStepName = _L("MM-MMF-ACTRL-U-0004-HP");
   212 	}
   213 
   214 /**
   215 * 
   216 * ~CTestStepPlayT
   217 */
   218 CTestStepPlayT::~CTestStepPlayT()
   219 	{
   220 	}
   221 
   222 /**
   223 * Do the test step.
   224 * Each test step must supply an implementation for DoTestStepL.
   225 * This Test step will play an audio clip n 
   226 * times
   227 * @return	"TVerdict" the status of the test
   228 *			The result of the test step 
   229 */
   230 TVerdict CTestStepPlayT::DoTestStepL()
   231 	{
   232 	__MM_HEAP_MARK;
   233 	TVerdict result = EPass;
   234 	
   235 	_LIT( KTestPlay, "Play Test");
   236 	Log( KTestPlay );
   237 	
   238 	_LIT( KTestStepPlay, "This test checks playing an audio clip n times");
   239 	Log( KTestStepPlay );
   240 	
   241 	// [ audio file to play ]
   242 	_LIT(KTestWavFile, "newmail.wav");
   243 	SetReadFileNameL( KTestWavFile );
   244    	
   245 	TInt errorCode = iController.Open(KUidCustomTestAudioPlugin, iPriority);
   246 	User::LeaveIfError( errorCode );
   247 
   248 	//[ add data source and sink and prime the controller ]
   249     errorCode = iController.AddDataSource(KUidMmfFileSource, ReadFileConfig());
   250 	User::LeaveIfError( errorCode );
   251 	
   252 	errorCode =	iController.AddDataSink(KUidMmfAudioOutput, KNullDesC8);
   253     User::LeaveIfError( errorCode );
   254 
   255 	
   256 	for( TInt iTimes = 0; iTimes < iTimesToPlay; iTimes++)
   257 		{
   258 		errorCode =	iController.Prime();
   259 		User::LeaveIfError( errorCode );
   260 		
   261 		// [ wait for and process the return event from the audio output ]
   262 		
   263 		TMMFEvent primeEvent( KPrimeTestId, KErrNone);
   264 		TVerdict primeResult = SearchForEvent( primeEvent );
   265 		if( primeResult == EFail )
   266 			{
   267 			return primeResult;
   268 			}
   269 		
   270 		User::LeaveIfError( iController.Play() );
   271 		
   272 		// note this test does not wait around 
   273 		// to detect that the audio has been played
   274 		// [ now process the confirmation event that play has reached audio output
   275 		//   this is the raison detre of the test ]
   276 		TMMFEvent playEvent( KPlayTestId, KErrNone );
   277 		
   278 		TVerdict playResult = SearchForEvent( playEvent );
   279 		if( playResult == EFail )
   280 			{
   281 			return playResult ;
   282 			}
   283 		
   284 		// [ lets ensure we are stopped ]
   285 		User::LeaveIfError( iController.Stop() );
   286 		}
   287 	
   288 	//[ ensure the controller is unloaded so that it does 
   289 	// not interfere with the following test ]
   290 	// There is error in this code and the stop followed by reset
   291 	// ensure the controller resources are released.
   292 	iController.Stop();
   293 	iController.Reset();
   294 	iController.Close();  
   295 
   296 	__MM_HEAP_MARKEND;  
   297 	// test steps return a result
   298 	return result;
   299 	}
   300 
   301 /*
   302 *
   303 * CTestStepPause
   304 *
   305 */
   306 CTestStepPause::CTestStepPause()
   307 	{
   308 	iTestStepName = _L("MM-MMF-ACTRL-U-0011-HP");
   309 	}
   310 
   311 /*
   312 *
   313 * ~CTestStepPause
   314 *
   315 */
   316 CTestStepPause::~CTestStepPause()
   317 	{
   318 	}
   319 
   320 /*
   321 *
   322 * DoTestStepL
   323 * This test checks the pause function
   324 *
   325 */
   326 TVerdict CTestStepPause::DoTestStepL()
   327 	{
   328 	__MM_HEAP_MARK;
   329 	
   330 	TVerdict result = EFail;
   331 	
   332 	_LIT( KTestPlay, "Pause Test");
   333 	Log( KTestPlay );
   334 	
   335 	_LIT( KTestStepPlay, "This test checks the pause function");
   336 	Log( KTestStepPlay );
   337 	
   338 	// [ audio file to play ]
   339 	_LIT(KTestWavFile, "newmail.wav");
   340 	SetReadFileNameL( KTestWavFile );
   341 	   	
   342 	TInt errorCode = iController.Open(KUidCustomTestAudioPlugin, iPriority);
   343 	User::LeaveIfError( errorCode );
   344 		
   345 	//[ add data source and sink and prime the controller ]
   346     errorCode = iController.AddDataSource(KUidMmfFileSource, ReadFileConfig());
   347 	User::LeaveIfError( errorCode );
   348 	
   349 	errorCode =	iController.AddDataSink(KUidMmfAudioOutput, KNullDesC8);
   350     User::LeaveIfError( errorCode );
   351 
   352     // [ The controller is in the stopped state 
   353 	//   and should return an error if pause is called ]
   354 		
   355 	TInt pauseError = iController.Pause();
   356 	if( pauseError == KErrNone )
   357 		{
   358 		// [ we should not be able to call pause while stopped ]
   359 		result = EFail;
   360 		return result ;
   361 		}
   362 
   363 	TMMFEvent pauseFailEvent( KPauseTestId, pauseError );
   364 	result = SearchForEvent( pauseFailEvent );
   365 	if( result == EFail )
   366 		{
   367 		return result;
   368 		}
   369 	
   370 	// [ move the contoller to the primed state ]
   371 	errorCode =	iController.Prime();
   372 	User::LeaveIfError( errorCode );
   373 
   374 	//[ call pause in the paused state
   375     // should return no error ]
   376 	pauseError = iController.Pause();
   377 	if( pauseError == KErrNone )
   378 		{
   379 		//[calling paused while paused returns an error]
   380 		result = EFail;
   381 		return result ;
   382 		}
   383 	
   384 	// [ wait for and process the return event from the audio output ]	
   385 	TMMFEvent primeEvent( KPrimeTestId, KErrNone );
   386 	result = SearchForEvent( primeEvent );
   387 	if( result == EFail )
   388 		{
   389 		return result;
   390 		}
   391 
   392 	result = SearchForEvent( pauseFailEvent );
   393 	if( result == EFail )
   394 		{
   395 		return result;
   396 		}
   397 	
   398     User::LeaveIfError( iController.Play() );
   399 
   400 	// [ process the play event ]
   401 	TMMFEvent playEvent( KPlayTestId, KErrNone );
   402 	result = SearchForEvent( playEvent );
   403 	if( result == EFail )
   404 		{
   405 		return result;
   406 		}
   407 
   408 	// [ now call pause when playing ]
   409 	TMMFEvent pausePassEvent( KPauseTestId, KErrNone );
   410 	pauseError = iController.Pause();
   411 	if( pauseError != KErrNone )
   412 		{
   413 		//[calling paused while paused returns an error]
   414 		result = EFail;
   415 		return result ;
   416 		}
   417 
   418 	// note this test does not wait around 
   419 	// to detect that the audio has been played
   420 	// [ now process the confirmation event that play has reached audio output
   421 	//   this is the raison detre of the test ]
   422 	result = SearchForEvent( pausePassEvent );
   423 	if( result == EFail )
   424 		{
   425 		return result;
   426 		}
   427 
   428 	// [ we should now be in the paused state 
   429 	//   try playing ]
   430 	User::LeaveIfError( iController.Play() );
   431 	result = SearchForEvent( playEvent );
   432 	if( result == EFail )
   433 		{
   434 		return result;
   435 		}
   436 
   437 	//[ ensure the controller is unloaded so that it does 
   438 	// not interfere with the following test ]
   439 	// There is error in this code and the stop followed by reset
   440 	// ensure the controller resources are released.
   441 	iController.Stop();
   442 	iController.Reset();
   443 	iController.Close();  
   444 	
   445 	__MM_HEAP_MARKEND;    
   446 
   447 	return result;
   448 	}
   449 
   450 /**
   451 *
   452 * CTestStepStop
   453 *
   454 */
   455 CTestStepStop::CTestStepStop()
   456 	{
   457 	iTestStepName = _L("MM-MMF-ACTRL-U-0012-HP");
   458 	}
   459 
   460 /**
   461 *
   462 * ~CTestStepStop
   463 *
   464 */
   465 CTestStepStop::~CTestStepStop()
   466 	{
   467 	}
   468 
   469 /*
   470 *
   471 * DoTestStepL
   472 * This test checks the stop function on the controller
   473 *
   474 */
   475 TVerdict CTestStepStop::DoTestStepL()
   476 	{
   477 	__MM_HEAP_MARK;
   478 	
   479 	TVerdict result = EFail;
   480 	
   481 	_LIT( KTestPlay, "Stop Test");
   482 	Log( KTestPlay );
   483 	
   484 	_LIT( KTestStepPlay, "This test checks the stop function");
   485 	Log( KTestStepPlay );
   486 	
   487 	// [ audio file to play ]
   488 	_LIT(KTestWavFile, "newmail.wav");
   489 	SetReadFileNameL( KTestWavFile );
   490 	   	
   491 	TInt errorCode = iController.Open(KUidCustomTestAudioPlugin, iPriority);
   492 	User::LeaveIfError( errorCode );
   493 
   494 	//[ add data source and sink and prime the controller ]
   495     errorCode = iController.AddDataSource(KUidMmfFileSource, ReadFileConfig());
   496 	User::LeaveIfError( errorCode );
   497 	
   498 	errorCode =	iController.AddDataSink(KUidMmfAudioOutput, KNullDesC8);
   499     User::LeaveIfError( errorCode );
   500 
   501 	//[ call stop while stopped ]
   502 	User::LeaveIfError( iController.Stop() );
   503 
   504 
   505 	// [ go to primed and call stop ]
   506 	errorCode =	iController.Prime();
   507 	User::LeaveIfError( errorCode );
   508 	
   509 	// [ wait for and process the return event from the audio output ]
   510 	
   511 	TMMFEvent primeEvent( KPrimeTestId, KErrNone);
   512 	result = SearchForEvent( primeEvent );
   513 	if( result == EFail )
   514 		{
   515 		return result;
   516 		}	
   517 
   518 	User::LeaveIfError( iController.Stop() );
   519 
   520 	// [ go to play and call stop ]
   521 	errorCode =	iController.Prime();
   522 	User::LeaveIfError( errorCode );
   523 	
   524 	// [ wait for and process the return event from the audio output ]
   525 	
   526 	result = SearchForEvent( primeEvent );
   527 	if( result == EFail )
   528 		{
   529 		return result;
   530 		}	
   531 
   532 	User::LeaveIfError( iController.Play() );
   533 	
   534 	// note this test does not wait around 
   535 	// to detect that the audio has been played
   536 	// [ now process the confirmation event that play has reached audio output
   537 	//   this is the raison detre of the test ]
   538 	TMMFEvent playEvent( KPlayTestId, KErrNone );
   539 	result = SearchForEvent( playEvent );
   540 	if( result == EFail )
   541 		{
   542 		return result;
   543 		}
   544 
   545 	User::LeaveIfError( iController.Stop() );
   546 
   547 
   548 	// [ go to prime from stopped via playing ]
   549 	// [ stopped ]
   550     // [ prime   ]
   551 	// [ play    ]
   552 	// [ pause   ]
   553 	// [ stop    ]
   554 
   555 	errorCode =	iController.Prime();
   556 	User::LeaveIfError( errorCode );
   557 	
   558 	// [ wait for and process the return event from the audio output ]
   559 	
   560 	result = SearchForEvent( primeEvent );
   561 	if( result == EFail )
   562 		{
   563 		return result;
   564 		}	
   565 
   566 	User::LeaveIfError( iController.Play() );
   567 	
   568 	// note this test does not wait around 
   569 	// to detect that the audio has been played
   570 	// [ now process the confirmation event that play has reached audio output
   571 	//   this is the raison detre of the test ]
   572 	result = SearchForEvent( playEvent );
   573 	if( result == EFail )
   574 		{
   575 		return result;
   576 		}
   577 
   578 	// [ now call pause when playing ]
   579 	TMMFEvent pausePassEvent( KPauseTestId, KErrNone );
   580 	TInt pauseError = iController.Pause();
   581 	if( pauseError != KErrNone )
   582 		{
   583 		//[calling paused while paused returns an error]
   584 		result = EFail;
   585 		return result ;
   586 		}
   587 
   588 	// note this test does not wait around 
   589 	// to detect that the audio has been played
   590 	// [ now process the confirmation event that play has reached audio output
   591 	//   this is the raison detre of the test ]
   592 	result = SearchForEvent( pausePassEvent );
   593 	if( result == EFail )
   594 		{
   595 		return result;
   596 		}
   597 
   598 	// [ now stop from paused ]
   599 	User::LeaveIfError( iController.Stop() );
   600 	
   601 	//[ ensure the controller is unloaded so that it does 
   602 	// not interfere with the following test ]
   603 	// There is error in this code and the stop followed by reset
   604 	// ensure the controller resources are released.
   605 	iController.Stop();
   606 	iController.Reset();
   607 	iController.Close();  
   608 
   609 	return result;
   610 	}
   611 
   612 
   613 /*
   614 *
   615 * CTestStepConvertFormat
   616 *
   617 */
   618 CTestStepConvertFormat::CTestStepConvertFormat( TUint aTestIndex )
   619 	{
   620 	// store a pointer to the test parameters
   621 	iTestParameters = &(KTestParameters[aTestIndex]);
   622 
   623 	// store the name of this test case
   624 	// this is the name that is used by the script file
   625 	iTestStepName = iTestParameters->iTestName;
   626 	}
   627 
   628 /*
   629 *
   630 * ~CTestStepConvertFormat
   631 *
   632 */
   633 CTestStepConvertFormat::~CTestStepConvertFormat()
   634 	{
   635 
   636 
   637 	}
   638 
   639 
   640 // test preamble
   641 TVerdict CTestStepConvertFormat::DoTestStepPreambleL(void)
   642 	{
   643 	// connect to the file server
   644 	User::LeaveIfError(iFs.Connect());
   645 
   646 	// call the superclass
   647 	return CTestStepActrl::DoTestStepPreambleL();
   648 	}
   649 
   650 //test postamble
   651 TVerdict CTestStepConvertFormat::DoTestStepPostambleL(void)
   652 	{
   653 	// close connection with the file server
   654 	iFs.Close();
   655 
   656 	// call the superclass
   657 	return CTestStepActrl::DoTestStepPostambleL();
   658 	}
   659 /**
   660  *
   661  * Compare two binary files
   662  *
   663  * @param "const TDesC& aFile1"
   664  *		  The first file to compare
   665  * @param "const TDesC& aFile2"
   666  *		  The second file to compare
   667  * @leave "" 
   668  *		  Will leave with appropriate system codes if a problem is encountered reading either file 	
   669  * @return "TVerdict"
   670  *		  EPass if the files are identical
   671  *		  EFail otherwise
   672  * @xxxx
   673  *
   674  */
   675 TVerdict CTestStepConvertFormat::CompareFilesL(const TDesC& aFile1,const TDesC& aFile2) 
   676 	{
   677 	RFile file1, file2;
   678 
   679 	User::LeaveIfError(file1.Open(iFs, aFile1, EFileShareAny | EFileStream | EFileRead));
   680 	CleanupClosePushL(file1);
   681 
   682 	User::LeaveIfError(file2.Open(iFs, aFile2, EFileShareAny | EFileStream | EFileRead));
   683 	CleanupClosePushL(file2);
   684 
   685 	TInt fileSize1, fileSize2;
   686 
   687 	TVerdict result = EPass;
   688 	TInt blockSize = 1024;
   689 	
   690 	User::LeaveIfError(file1.Size(fileSize1));
   691 	User::LeaveIfError(file2.Size(fileSize2));
   692 
   693 	if (fileSize1 == fileSize2) 
   694 		{
   695 		HBufC8* buf1 = HBufC8::NewMaxLC(blockSize);
   696 		TPtr8 buf1Ptr(buf1->Des());
   697 		HBufC8* buf2 = HBufC8::NewMaxLC(blockSize);
   698 		TPtr8 buf2Ptr(buf2->Des());
   699 
   700 		TInt length = 0;
   701 
   702 		while (length<fileSize1 && result == EPass)
   703 			{
   704 			TInt copySize;
   705 
   706 			if (fileSize1 - length > blockSize)
   707 				copySize = blockSize;
   708 			else
   709 				copySize = fileSize1 - length;
   710 			User::LeaveIfError(file1.Read(buf1Ptr,copySize));
   711 			User::LeaveIfError(file2.Read(buf2Ptr,copySize));
   712 
   713 			TInt comp_res = Mem::Compare(buf1Ptr.Ptr(),copySize,buf2Ptr.Ptr(),copySize);
   714 			    
   715 			if (comp_res!=0)
   716 			    {
   717 			    INFO_PRINTF5(_L("Comparison Failed, comparison failed (%S, %S), result=%d at offset %d"),
   718 			            &aFile1, &aFile2, comp_res, length);
   719 				result = EFail;
   720 				break;
   721 			    }
   722 
   723 			length += copySize;
   724 			}
   725 		CleanupStack::PopAndDestroy(2); // buf1, buf2
   726 		}
   727 	else
   728 	    {
   729         INFO_PRINTF5(_L("Comparison Failed, files are different sizes (%S, %S), (%d,%d)"),
   730                 &aFile1, &aFile2, fileSize1, fileSize2);
   731 		result = EFail;
   732 	    }
   733 
   734 	file1.Close();
   735 	file2.Close();
   736 
   737 	CleanupStack::PopAndDestroy(2); //file1, file2
   738 
   739 	return result;
   740 	}
   741 /*
   742 *
   743 * DoTestStepL
   744 * This test checks the stop function on the controller
   745 *
   746 */
   747 TVerdict CTestStepConvertFormat::DoTestStepL( void )
   748 	{
   749 	TVerdict result = EPass;
   750 	TInt	error;
   751 
   752 	// do the conversion step
   753 	TRAP(error, result = DoConvertStepL( ));
   754 
   755 	if (error != iTestParameters->iExpectedResult )
   756 		{
   757 		INFO_PRINTF2(_L("Error - Test step returned %d"), error);
   758 		result = EFail;
   759 		}
   760 
   761 	//[ delete output file after comparison]
   762 	//[ here because DoTestStepL() can leave ]
   763 	 TInt ret = iFs.Delete( WriteFileConfig()().iPath );
   764 	 if (ret != KErrNone && ret != KErrNotFound)
   765 		{
   766 		INFO_PRINTF2(_L("Error deleting file - Delete returned %d"), ret);
   767 		}
   768 		
   769 	//[ ensure the controller is unloaded so that it does 
   770 	// not interfere with the following test ]
   771 	// There is error in this code and the stop followed by reset
   772 	// ensure the controller resources are released.
   773 	iController.Stop();
   774 	iController.Reset();
   775 	iController.Close();  
   776 
   777 	return result;
   778 	}
   779 
   780 /*
   781 * DoConvertL( void )
   782 * Do the conversion of the files
   783 * @return	"TVerdict" the result of the convert operation
   784 */
   785 TVerdict CTestStepConvertFormat::DoConvertStepL( void )
   786 	{
   787 	 TVerdict result = EPass;
   788 	
   789 	 _LIT( KTestConvertFormat, "Convert Formats Test");
   790 	 Log( KTestConvertFormat );
   791 	
   792 	 _LIT( KTestStepPlay, "This test checks converting an audio clip");
   793 	 Log( KTestStepPlay );
   794 	
   795 	 // get filename of input file
   796 	 TInt strLen = User::StringLength(iTestParameters->iFromFilename);
   797 	 TPtrC ptr( iTestParameters->iFromFilename, strLen );
   798 	
   799 	 //[ configure the filename ]
   800 	 SetReadFileNameL( ptr );
   801 	 
   802 	 //[ configure reference filename ]
   803 	 strLen = User::StringLength(iTestParameters->iRefFilename);
   804 	 ptr.Set( iTestParameters->iRefFilename, strLen );
   805 
   806 	 SetRefFileNameL( ptr );
   807 
   808 	 // [ converted audio file name ]
   809 	 //_LIT(KTestOutFile, "ConvertedOutput");
   810 	 TBuf<32> testFileName = _L("ConvertedOutput");
   811 
   812 	 switch ( iTestParameters->iDestFormat.iUid )
   813 		{
   814 		case KMmfUidFormatRAWWrite:
   815 			testFileName.Append( _L(".raw") );
   816 			break;
   817 
   818 		case KMmfUidFormatWAVWrite:
   819 			testFileName.Append( _L(".wav") );
   820 			break;
   821 
   822 		case KMmfUidFormatAUWrite:
   823 			testFileName.Append( _L(".au") );
   824 			break;
   825 
   826 		default:
   827 			// not a recognised output format - use .tmp
   828 			testFileName.Append( _L(".tmp") );
   829 			break;
   830 		}	
   831 
   832 	 //[ configure the filename ]
   833 	 SetWriteFileNameL( testFileName );
   834 
   835 	 // open the audio controller
   836 	 TInt errorCode = iController.Open(KUidCustomTestAudioPlugin, iPriority);
   837 	 User::LeaveIfError( errorCode );
   838 	
   839 	 //[ add data source and sink and prime the controller ]
   840      errorCode = iController.AddDataSource(KUidMmfFileSource, ReadFileConfig());
   841 	 User::LeaveIfError( errorCode );
   842 	
   843 	 errorCode = iController.AddDataSink(KUidMmfFileSink, WriteFileConfig());
   844      User::LeaveIfError( errorCode );
   845 
   846 	//[ attempt to get the sink num channels ]
   847     RMMFAudioControllerCustomCommands theCommander( iController );
   848 	
   849 	 // if source data is RAW then need to complete the source format
   850 	 if ( iTestParameters->iSrcFormat.iUid == KMmfUidFormatRAWRead )
   851 		{
   852 		
   853 		errorCode = theCommander.SetSourceFormat( iTestParameters->iSrcFormat );
   854 		User::LeaveIfError( errorCode );
   855 
   856 		errorCode = theCommander.SetSourceDataType( iTestParameters->iSrcEncoding );
   857 		User::LeaveIfError( errorCode );
   858 		 
   859 		errorCode = theCommander.SetSourceSampleRate( iTestParameters->iSrcSampleRate );
   860 		User::LeaveIfError( errorCode );
   861 
   862 		errorCode = theCommander.SetSourceNumChannels( iTestParameters->iSrcChannels );
   863 		User::LeaveIfError( errorCode );
   864 		}	
   865 
   866 	 // set sink sample rate
   867 	 errorCode = theCommander.SetSinkSampleRate( iTestParameters->iDestSampleRate );
   868 	 User::LeaveIfError( errorCode );
   869 
   870 	 // set sink number of channels
   871 	 if(iTestParameters->iDestChannels != KNone)
   872 		 {
   873 		 errorCode = theCommander.SetSinkNumChannels( iTestParameters->iDestChannels );
   874 		 User::LeaveIfError( errorCode );
   875 		 }
   876 
   877 	 //[ ok lets try to set the sink format ]
   878 	 errorCode = theCommander.SetSinkFormat( iTestParameters->iDestFormat );
   879 	 User::LeaveIfError( errorCode );
   880 
   881 	 //[ set the sink data type ]
   882 	 errorCode = theCommander.SetSinkDataType( iTestParameters->iDestEncoding );
   883 	 User::LeaveIfError( errorCode );
   884 
   885  	 errorCode = iController.Prime();
   886 	 User::LeaveIfError( errorCode );
   887 	
   888 	 // [ wait for and process the return event from the audio output ]
   889 	 TMMFEvent primeEvent( KPrimeTestId, KErrNone);
   890 	 result = SearchForEvent( primeEvent );
   891 	 if( result == EFail )
   892 		{
   893 		return result;
   894 		}
   895 	
   896 	 errorCode = iController.Play();
   897      User::LeaveIfError( errorCode );
   898 	
   899 	 // note this test does not wait around 
   900 	 // to detect that the audio has been played
   901 	 // [ now process the confirmation event that play has reached audio output
   902 	 //   this is the raison detre of the test ]
   903 	 TMMFEvent playEvent( KPlayTestId, KErrNone );
   904 	
   905 	 result = SearchForEvent( playEvent );
   906 	 if( result == EFail )
   907 		 {
   908 		 return result;
   909 		 }
   910 
   911 	 //[ now wait for play complete event]
   912 	 TMMFEvent playCompleteEvent( KPlayCompleteTestId, KErrNone);
   913 	 result = SearchForEvent( playCompleteEvent );
   914 	 if( result == EFail )
   915 		{
   916 		return result;
   917 		}
   918 
   919 	 //[ now compare the file produced with a reference file ]
   920 	 INFO_PRINTF1(_L("Comparing file to reference..."));
   921 	 result = CompareFilesL( RefFileName()().iPath, WriteFileConfig()().iPath);
   922 	 
   923 	 if (result == EFail)
   924 		 {
   925 		 INFO_PRINTF1(_L("Comparison Failed - Files are not identical !"));
   926 		 }
   927 	
   928 
   929 	 return result;
   930 	}
   931 
   932 /*
   933 *
   934 * SetRefFileNameL
   935 *
   936 */
   937 void CTestStepConvertFormat::SetRefFileNameL( const TDesC& aPathNameAndExtn )
   938 	{
   939 	//[ append the filename relative to the default path ]
   940 	TFileName fileName = GetSuite()->DefaultPath();
   941 	fileName.Append(aPathNameAndExtn);
   942 	iFileConfigRef().iPath = fileName ;
   943 	}
   944 /*
   945 *
   946 * RefFileName
   947 *
   948 */
   949 TMMFFileConfig& CTestStepConvertFormat::RefFileName()
   950 	{
   951 	return iFileConfigRef;
   952 	}
   953 
   954 /*
   955 *
   956 * CTestStepRampVolume
   957 */
   958 CTestStepRampVolume::CTestStepRampVolume()
   959 	{
   960 	iTestStepName = _L("MM-MMF-ACTRL-U-0064-HP");
   961 	}
   962 
   963 /*
   964 *
   965 * ~CTestStepRampVolume
   966 */
   967 CTestStepRampVolume::~CTestStepRampVolume()
   968 	{
   969 	}
   970 
   971 /*
   972 *
   973 * CTestStepRampVolume
   974 */
   975 TVerdict CTestStepRampVolume::DoTestStepL()
   976 	{
   977 	TVerdict result = EPass;
   978 	
   979 	_LIT( KTestVolumeRamp, "Volume Ramp Test");
   980 	Log( KTestVolumeRamp );
   981 	
   982 	_LIT( KTestStepPlay, "This test checks volume ramp");
   983 	Log( KTestStepPlay );
   984 	
   985 	// [ audio file to play ]
   986 	_LIT(KTestWavFile, "RampVolume.wav");
   987 		//[ configure the filename ]
   988 	SetReadFileNameL( KTestWavFile );
   989    	
   990 	TInt errorCode = iController.Open(KUidCustomTestAudioPlugin, iPriority);
   991 	User::LeaveIfError( errorCode );
   992 	
   993 	//[ add data source and sink and prime the controller ]
   994     errorCode = iController.AddDataSource(KUidMmfFileSource, ReadFileConfig());
   995 	User::LeaveIfError( errorCode );
   996 	
   997 	errorCode =	iController.AddDataSink(KUidMmfAudioOutput, KNullDesC8);
   998     User::LeaveIfError( errorCode );
   999 	
  1000 	errorCode =	iController.Prime();
  1001 	User::LeaveIfError( errorCode );
  1002 	
  1003 	// [ wait for and process the return event from the audio output ]
  1004 	//[ attempt to get the sink num channels ]
  1005     RMMFAudioPlayDeviceCustomCommands theCommander( iController );
  1006 	//[lets say 2 seconds for now ]
  1007 	TTimeIntervalMicroSeconds aRampDuration( 2000000);
  1008 	errorCode = theCommander.SetVolumeRamp( aRampDuration);
  1009 	User::LeaveIfError( errorCode );
  1010 	
  1011 	TMMFEvent primeEvent( KPrimeTestId, KErrNone);
  1012 	result = SearchForEvent( primeEvent );
  1013 	if( result == EFail )
  1014 		{
  1015 		return result;
  1016 		}
  1017 
  1018 	//[ lets set the volume ramp before we play ]
  1019     
  1020 	
  1021     User::LeaveIfError( iController.Play() );
  1022 	
  1023 	// note this test does not wait around 
  1024 	// to detect that the audio has been played
  1025 	// [ now process the confirmation event that play has reached audio output
  1026 	//   this is the raison detre of the test ]
  1027 	TMMFEvent playEvent( KPlayTestId, KErrNone );
  1028 	result = SearchForEvent( playEvent );
  1029 	if( result == EFail )
  1030 		{
  1031 		return EFail;
  1032 		}
  1033 
  1034 	//[ now wait for play complete event]
  1035 	 TMMFEvent playCompleteEvent( KPlayCompleteTestId, KErrNone);
  1036 	 result = SearchForEvent( playCompleteEvent );
  1037 	 if( result == EFail )
  1038 		{
  1039 		return EFail;
  1040 		}
  1041 		
  1042 	//[ ensure the controller is unloaded so that it does 
  1043 	// not interfere with the following test ]
  1044 	// There is error in this code and the stop followed by reset
  1045 	// ensure the controller resources are released.
  1046 	iController.Stop();
  1047 	iController.Reset();
  1048 	iController.Close();  
  1049 
  1050 	// test steps return a result
  1051 	return result;
  1052 	}
  1053 
  1054 /*
  1055 *
  1056 * CTestStepRampVolume
  1057 */
  1058 TVerdict CTestStepRampVolume::DoTestStepPreambleL(void)
  1059 	{
  1060 	return EPass;
  1061 	}
  1062 
  1063 /*
  1064 *
  1065 * CTestStepRampVolume
  1066 */
  1067 TVerdict CTestStepRampVolume::DoTestStepPostambleL(void)
  1068 	{
  1069 	return CTestStepActrl::DoTestStepPostambleL();
  1070 	}
  1071