os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/testoutputstreamtruepause.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2008-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 // Part of the TSI_MMFACLNT suite that tests CR1566 (TruePause) on AudioOutputStream
    15 // 
    16 //
    17 
    18 /**
    19  @file TestOutputStreamTruePause.cpp
    20 */
    21 
    22 #include "testoutputstreamtruepause.h"
    23 
    24 /*
    25  *
    26  * RMdaOutputStreamTestBase - Test step constructor
    27  *
    28  */
    29 RMdaOutputStreamTestBase::RMdaOutputStreamTestBase(const TDesC& aTestName, const TDesC& aSectName)
    30 	:	iAudioOutputStreamState(EStateAOSInitial), 
    31 		iAudioOutputStream(NULL),
    32 		iTimer(NULL),
    33 		iWait(EFalse),
    34 		iConfig(EFalse),
    35 		iInvalidConfig(EFalse),
    36 		iGetBytes(EFalse),
    37 		iCount(0),
    38 		iVolume(0),
    39 		iBalance(0),
    40 		iDuration(0),
    41 		iPause(0),
    42 		iBytes(0),
    43 		iPosition(0),
    44 		iFilename(KNullDesC)
    45 	{
    46 	iTestStepName = aTestName;
    47 	iSectName = aSectName;
    48 	}
    49 
    50 /*
    51  *
    52  * ~RMdaOutputStreamTestBase - Test step destructor
    53  *
    54  */
    55 RMdaOutputStreamTestBase::~RMdaOutputStreamTestBase()
    56 	{
    57 	if (iAudioOutputStream)
    58 		{
    59 		delete iAudioOutputStream;
    60 		}
    61 	if(iTimer)
    62 		{
    63 		delete iTimer;
    64 		}
    65 	iFile.Close();
    66 	iFs.Close();
    67 	iBuffer.Close();
    68 	}
    69 
    70 /*
    71  *
    72  * KickoffTestL - Starts the test
    73  *
    74  */
    75 void RMdaOutputStreamTestBase::KickoffTestL()
    76 	{
    77 	User::LeaveIfError(iFs.Connect());
    78 	INFO_PRINTF1(_L("__________  Creating AudioOutputStream object ___________"));
    79 
    80 	TRAPD(err,  iAudioOutputStream = CMdaAudioOutputStream::NewL(*this));
    81 	if (err != KErrNone)
    82 		{
    83 		ERR_PRINTF2(_L("Could not create Tone Utility object. Error = %d"), err);
    84 		StopTest(err);
    85 		return;
    86 		}
    87 	INFO_PRINTF1(_L("AudioOutputStream State: EStateCreated"));
    88 	iAudioOutputStreamState = EStateAOSCreated;
    89 	
    90 	DoKickoffTestL();
    91 	
    92 	INFO_PRINTF1(_L("AudioOutputStream: EEventInitialize"));
    93 	Fsm(EEventAOSInitialize, KErrNone);
    94 	}
    95 
    96 /*
    97  *
    98  * CloseTest
    99  *
   100  */
   101 void RMdaOutputStreamTestBase::CloseTest()
   102 	{
   103 	INFO_PRINTF1(_L("Deleting AudioOutputStream object"));
   104 	delete iAudioOutputStream;
   105 	delete iTimer;
   106 	}
   107 
   108 /*
   109  *
   110  * StartTimer - Starts timer and timer callback
   111  *
   112  */
   113 void RMdaOutputStreamTestBase::StartTimer(TTimeIntervalMicroSeconds32 aWaitTime)
   114 	{
   115 	TTimeIntervalMicroSeconds32 timeInterval;
   116 	
   117 	if(aWaitTime <= TTimeIntervalMicroSeconds32(0))
   118 		{
   119 		timeInterval = KOneSecond;
   120 		}
   121 	else
   122 		{
   123 		timeInterval = aWaitTime;
   124 		}
   125 	TCallBack callback (TimerCallback, this);
   126 	iTimer->Start(timeInterval, timeInterval, callback);
   127 	INFO_PRINTF1(_L("Timer has been started"));
   128 	}
   129 
   130 /*
   131  *
   132  * TimerCallback
   133  *
   134  */
   135 TInt RMdaOutputStreamTestBase::TimerCallback(TAny* aPtr)
   136 	{
   137 	static_cast<RMdaOutputStreamTestBase*>(aPtr)->DoTimerCallback();
   138 	return KErrNone;
   139 	}
   140 
   141 /*
   142  *
   143  * Fsm - Executes playing events of AudioToneUtility in sequence
   144  *
   145  */
   146 void RMdaOutputStreamTestBase::Fsm(TMdaAOSEvent aMdaAudioOutputStreamEvent, TInt aError)
   147 	{
   148 	TInt error = 0;
   149 	TTimeIntervalMicroSeconds resumeposition;
   150 	switch (iAudioOutputStreamState)
   151 		{
   152 		case EStateAOSCreated:
   153 			{
   154 			if (aMdaAudioOutputStreamEvent == EEventAOSInitialize)
   155 				{
   156 				TMdaAudioDataSettings settings;
   157 				//Default settings
   158 				settings.Query();
   159 				settings.iChannels = TMdaAudioDataSettings::EChannelsMono;
   160 				settings.iSampleRate = TMdaAudioDataSettings::ESampleRate8000Hz;
   161 				INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::Open"));
   162 				iAudioOutputStream->Open(&settings);
   163 				INFO_PRINTF1(_L("MdaAudioOutputStream State: EStateInitializing"));
   164 				iAudioOutputStreamState = EStateAOSInitializing;
   165 				}
   166 			else
   167 				{
   168 				ERR_PRINTF2(_L("MdaAudioOutputStream EEventInitialize not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
   169 				StopTest(aError, EFail);
   170 				}
   171 			break;
   172 			}
   173 		case EStateAOSInitializing:
   174 			{
   175 			if (aMdaAudioOutputStreamEvent == EEventAOSOpenComplete && aError == KErrNone)
   176 				{
   177 				INFO_PRINTF1(_L("Calling SetVolume using MaxVolume/2"));
   178 				iAudioOutputStream->SetVolume(iAudioOutputStream->MaxVolume()/2);
   179 				INFO_PRINTF1(_L("Starting playback"));
   180 				iAudioOutputStream->WriteL(iBuffer);
   181 				iAudioOutputStreamState = EStateAOSPlaying;
   182 				StartTimer(iPause*KOneSecond);
   183 				}
   184 			else if (aMdaAudioOutputStreamEvent == EEventAOSOpenComplete && aError != KErrNone)
   185 				{
   186 				ERR_PRINTF2(_L("MaoscOpenComplete returned with error = %d"), aError);
   187 				StopTest(aError);	
   188 				}
   189 			else
   190 				{
   191 				ERR_PRINTF2(_L("MdaAudioOutputStream EEventOpenComplete not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
   192 				StopTest(aError, EFail);
   193 				}
   194 			break;
   195 			}
   196 		case EStateAOSPlaying:
   197 			{
   198 			if(aMdaAudioOutputStreamEvent == EEventAOSTimerComplete)
   199 				{
   200 				if(!iGetBytes)
   201 					{
   202 					INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::Pause"));
   203 					error = iAudioOutputStream->Pause();
   204 					if(error == KErrNone)
   205 						{
   206 						INFO_PRINTF1(_L("Pause returned with KErrNone as expected"));
   207 						}
   208 					else
   209 						{
   210 						ERR_PRINTF2(_L("Pause returned with %d instead of KErrNone as expected"),error);
   211 						StopTest(error);
   212 						}
   213 					iPosition = iAudioOutputStream->Position();
   214 					INFO_PRINTF2(_L("Stream was paused at %Ld"),iPosition.Int64());
   215 					INFO_PRINTF1(_L("MdaAudioOutputStream State: EStatePause"));
   216 					iAudioOutputStreamState = EStateAOSPause;
   217 					iWait = EFalse;
   218 					}
   219 				if(iGetBytes)
   220 					{
   221 					INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::Pause"));
   222 					error = iAudioOutputStream->Pause();
   223 					if(error == KErrNone)
   224 						{
   225 						INFO_PRINTF1(_L("Pause returned with KErrNone as expected"));
   226 						}
   227 					else
   228 						{
   229 						ERR_PRINTF2(_L("Pause returned with %d instead of KErrNone as expected"),error);
   230 						StopTest(error);
   231 						}					
   232 					INFO_PRINTF1(_L("MdaAudioOutputStream State: EStatePause"));
   233 					iPosition = iAudioOutputStream->Position();
   234 					INFO_PRINTF2(_L("Stream was paused at %Ld"),iPosition.Int64());
   235 					INFO_PRINTF1(_L("MdaAudioOutputStream State: EStatePause"));
   236 					iAudioOutputStreamState = EStateAOSPause;
   237 					iWait = EFalse;
   238 					INFO_PRINTF1(_L("Calling GetBytes"));
   239 					iBytes = iAudioOutputStream->GetBytes();
   240 					}
   241 				}
   242 			else
   243 				{
   244 				ERR_PRINTF2(_L("DevSound EEventTimerComplete not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
   245 				StopTest(aError, EFail);
   246 				}
   247 			break;
   248 			}
   249 		case EStateAOSPause:
   250 			{
   251 			if (aMdaAudioOutputStreamEvent == EEventAOSTimerComplete)
   252 				{
   253 				if(!iWait && !iConfig && !iInvalidConfig && !iGetBytes)
   254 					{
   255 					if(iPosition == iAudioOutputStream->Position())
   256 						{
   257 						INFO_PRINTF2(_L("Paused position was maintained at %Ld"),iPosition.Int64());
   258 						}
   259 					else
   260 						{
   261 						ERR_PRINTF3(_L("Position was not maintained during pause. Expected %Ld Retrieved %Ld"),iPosition.Int64(),iAudioOutputStream->Position().Int64());
   262 						StopTest(KErrGeneral);
   263 						}
   264 					INFO_PRINTF1(_L("Resuming playback. Calling CMdaAudioOutputStream::Resume"));
   265 					error = iAudioOutputStream->Resume();
   266 					resumeposition = iAudioOutputStream->Position();
   267 					if(error == KErrNone)
   268 						{
   269 						INFO_PRINTF1(_L("Resume returned with KErrNone as expected"));
   270 						iAudioOutputStreamState = EStateAOSPlaying;
   271 						if(Abs(resumeposition.Int64() - iPosition.Int64()) <= KOneSecond/2)
   272 							{
   273 							INFO_PRINTF2(_L("Playback resumed from expected position %Ld"),iPosition.Int64());
   274 							}
   275 						else
   276 							{
   277 							ERR_PRINTF3(_L("Playback did not resume from expected position. Expected %Ld Retrieved %Ld"),iPosition.Int64(),resumeposition.Int64());
   278 							StopTest(KErrGeneral);
   279 							}
   280 						}
   281 					else
   282 						{
   283 						ERR_PRINTF2(_L("Resume returned with %d instead of KErrNone as expected"),error);
   284 						StopTest(error);
   285 						}
   286 					}
   287 				else if(!iWait && iConfig)
   288 					{
   289 					if(iPosition == iAudioOutputStream->Position())
   290 						{
   291 						INFO_PRINTF2(_L("Paused position was maintained at %Ld"),iPosition.Int64());
   292 						}
   293 					else
   294 						{
   295 						ERR_PRINTF3(_L("Position was not maintained during pause. Expected %Ld Retrieved %Ld"),iPosition.Int64(),iAudioOutputStream->Position().Int64());
   296 						StopTest(KErrGeneral);
   297 						}					
   298 					INFO_PRINTF2(_L("Playback paused for %d seconds"),iPause);
   299 					INFO_PRINTF3(_L("Changing Volume and Balance while paused to Volume = %d and Balance = %d"),iVolume,iBalance);
   300 					iAudioOutputStream->SetVolume(iVolume);
   301 					iAudioOutputStream->SetBalanceL(iBalance);
   302 					INFO_PRINTF1(_L("Resuming playback. Calling CMdaAudioOutputStream::Resume"));
   303 					error = iAudioOutputStream->Resume();
   304 					resumeposition = iAudioOutputStream->Position();
   305 					if(error == KErrNone)
   306 						{
   307 						INFO_PRINTF1(_L("Resume returned with KErrNone as expected"));
   308 						iAudioOutputStreamState = EStateAOSPlaying;
   309 						if(Abs(resumeposition.Int64() - iPosition.Int64()) <= KOneSecond/2)
   310 							{
   311 							INFO_PRINTF2(_L("Playback resumed from expected position %Ld"),iPosition.Int64());
   312 							}
   313 						else
   314 							{
   315 							ERR_PRINTF3(_L("Playback did not resume from expected position. Expected %Ld Retrieved %Ld"),iPosition.Int64(),resumeposition.Int64());
   316 							StopTest(KErrGeneral);
   317 							}
   318 						}
   319 					else
   320 						{
   321 						ERR_PRINTF2(_L("Resume returned with %d instead of KErrNone as expected"),error);
   322 						StopTest(error);
   323 						}
   324 					iConfig = EFalse;
   325 					}
   326 				else if(!iWait && iInvalidConfig)
   327 					{
   328 					if(iPosition == iAudioOutputStream->Position())
   329 						{
   330 						INFO_PRINTF2(_L("Paused position was maintained at %Ld"),iPosition.Int64());
   331 						}
   332 					else
   333 						{
   334 						ERR_PRINTF3(_L("Position was not maintained during pause. Expected %Ld Retrieved %Ld"),iPosition.Int64(),iAudioOutputStream->Position().Int64());
   335 						StopTest(KErrGeneral);
   336 						}					
   337 					INFO_PRINTF2(_L("Playback paused for %d seconds"),iPause);
   338 					INFO_PRINTF1(_L("Changing AudioProperties while paused"));
   339 					TRAPD(err,iAudioOutputStream->SetAudioPropertiesL(TMdaAudioDataSettings::ESampleRate48000Hz, TMdaAudioDataSettings::EChannelsStereo));
   340 					if(err == KErrNotReady)
   341 						{
   342 						INFO_PRINTF1(_L("SetAudioPropertiesL returned with KErrNotReady as expected"));
   343 						INFO_PRINTF1(_L("Resuming playback. Calling CMdaAudioOutputStream::Resume"));
   344 						error = iAudioOutputStream->Resume();
   345 						resumeposition = iAudioOutputStream->Position();
   346 						if(error == KErrNone)
   347 							{
   348 							INFO_PRINTF1(_L("Resume returned with KErrNone as expected"));
   349 							iAudioOutputStreamState = EStateAOSPlaying;
   350 							if(Abs(resumeposition.Int64() - iPosition.Int64()) <= KOneSecond/2)
   351 								{
   352 								INFO_PRINTF2(_L("Playback resumed from expected position %Ld"),iPosition.Int64());
   353 								}
   354 							else
   355 								{
   356 								ERR_PRINTF3(_L("Playback did not resume from expected position. Expected %Ld Retrieved %Ld"),iPosition.Int64(),resumeposition.Int64());
   357 								StopTest(KErrGeneral);
   358 								}							
   359 							}
   360 						else
   361 							{
   362 							ERR_PRINTF2(_L("Resume returned with %d instead of KErrNone as expected"),err);
   363 							StopTest(err);
   364 							}
   365 						iInvalidConfig = EFalse;
   366 						}
   367 					else
   368 						{
   369 						ERR_PRINTF2(_L("SetAudioPropertiesL did not return with KErrNotSupported as expected, returned with %d instead"), err);
   370 						StopTest(KErrGeneral);
   371 						}
   372 					}
   373 				else if(!iWait && iGetBytes)
   374 					{
   375 					if(iPosition == iAudioOutputStream->Position())
   376 						{
   377 						INFO_PRINTF2(_L("Paused position was maintained at %Ld"),iPosition.Int64());
   378 						}
   379 					else
   380 						{
   381 						ERR_PRINTF3(_L("Position was not maintained during pause. Expected %Ld Retrieved %Ld"),iPosition.Int64(),iAudioOutputStream->Position().Int64());
   382 						StopTest(KErrGeneral);
   383 						}					
   384 					INFO_PRINTF2(_L("Playback paused for %d seconds"),iPause);
   385 					INFO_PRINTF1(_L("Calling GetBytes to verify the value hasn't changed"));
   386 					TInt myBytes = iAudioOutputStream->GetBytes();
   387 					if(myBytes == iBytes)
   388 						{
   389 						INFO_PRINTF1(_L("GetBytes value did not change while in pause, this is expected."));
   390 						INFO_PRINTF1(_L("Resuming playback. Calling CMdaAudioOutputStream::Resume"));
   391 						error = iAudioOutputStream->Resume();
   392 						resumeposition = iAudioOutputStream->Position();
   393 						if(error == KErrNone)
   394 							{
   395 							INFO_PRINTF1(_L("Resume returned with KErrNone as expected"));
   396 							iAudioOutputStreamState = EStateAOSPlaying;
   397 							if(Abs(resumeposition.Int64() - iPosition.Int64()) <= KOneSecond/2)
   398 								{
   399 								INFO_PRINTF2(_L("Playback resumed from expected position %Ld"),iPosition.Int64());
   400 								}
   401 							else
   402 								{
   403 								ERR_PRINTF3(_L("Playback did not resume from expected position. Expected %Ld Retrieved %Ld"),iPosition.Int64(),resumeposition.Int64());
   404 								StopTest(KErrGeneral);
   405 								}							
   406 							}
   407 						else
   408 							{
   409 							ERR_PRINTF2(_L("Resume returned with %d instead of KErrNone as expected"),error);
   410 							StopTest(error);
   411 							}
   412 						iGetBytes = EFalse;
   413 						}
   414 					else
   415 						{
   416 						ERR_PRINTF3(_L("GetBytes value changed while in pause, this is unexpected. Expected = %d Retrieved = %d"),iBytes,myBytes);
   417 						StopTest(KErrGeneral);
   418 						}
   419 					}
   420 				}
   421 			else
   422 				{
   423 				ERR_PRINTF2(_L("EEventTimerComplete not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
   424 				StopTest(aError, EFail);
   425 				}
   426 			break;
   427 			}
   428 		default:
   429 			{
   430 			ERR_PRINTF2(_L("Invalid MdaAudioOutputStream state received: %d"), iAudioOutputStreamState);
   431 			StopTest(KErrGeneral);
   432 			}
   433 		}
   434 	}
   435 
   436 /*
   437  *
   438  * MaoscOpenComplete - From MMdaAudioOutputStreamObserver
   439  *
   440  */
   441 void RMdaOutputStreamTestBase::MaoscOpenComplete(TInt aError)
   442 	{
   443 	INFO_PRINTF1(_L("========== AudioOutputStream MaoscOpenComplete() callback =========="));
   444 	if(iAudioOutputStreamState == EStateAOSInitializing)
   445 		{
   446 		INFO_PRINTF1(_L("AudioOutputStream MaoscOpenComplete"));
   447 		Fsm(EEventAOSOpenComplete, aError);
   448 		}
   449 	}
   450 
   451 /*
   452  *
   453  * MaoscBufferCopied - From MMdaAudioOutputStreamObserver
   454  *
   455  */
   456 void RMdaOutputStreamTestBase::MaoscBufferCopied(TInt /*aError*/, const TDesC8& /*aBuffer*/)
   457 	{
   458 	INFO_PRINTF1(_L("========== AudioOutputStream MaoscBufferCopied() callback =========="));
   459 	INFO_PRINTF1(_L("Reading file"));
   460 	TInt err = iFile.Read(iBuffer);
   461 	if (err != KErrNone)
   462 		{
   463 		INFO_PRINTF2(_L("Error reading iFile %d"), err);
   464 		StopTest(err);
   465 		}
   466 	if (iBuffer != KNullDesC8 && iAudioOutputStreamState != EStateAOSStopped)
   467 		{
   468 		INFO_PRINTF1(_L("Writing to stream"));
   469 		iAudioOutputStream->WriteL(iBuffer);
   470 		}
   471 	if(iAudioOutputStreamState == EStateAOSPlaying)
   472 		{
   473 		INFO_PRINTF1(_L("AudioOutputStream MaoscBufferCopied"));
   474 		}
   475 	else if(iAudioOutputStreamState == EStateAOSPause)
   476 		{
   477 		ERR_PRINTF1(_L("AudioOutputStream MaoscBufferCopied in Paused. This is unexpected"));
   478 		StopTest(KErrGeneral);
   479 		}		
   480 	}
   481 
   482 /*
   483  *
   484  * MaoscPlayComplete - From MMdaAudioOutputStreamObserver
   485  *
   486  */
   487 void RMdaOutputStreamTestBase::MaoscPlayComplete(TInt aError)
   488 	{
   489 	INFO_PRINTF1(_L("========== AudioOutputStream MaoscPlayComplete() callback =========="));
   490 	if (aError == KErrUnderflow)
   491 		{
   492 		INFO_PRINTF2(_L("AudioOutputStream called MaoscPlayComplete with error = %d as expected"), aError);
   493 		StopTest(EPass);
   494 		}
   495 	else
   496 		{
   497 		ERR_PRINTF2(_L("AudioOutputStream called MaoscPlayComplete with error = %d"), aError);
   498 		ERR_PRINTF2(_L("Expected error = %d"), KErrUnderflow);
   499 		StopTest(aError);
   500 		}
   501 	}
   502 
   503 /*
   504  *========================================================================================================
   505  * MM-MMF-ACLNT-I-0175-HP
   506  *========================================================================================================
   507  */
   508 RMdaOutputStreamPauseResumeBeforeWriteTest::RMdaOutputStreamPauseResumeBeforeWriteTest(const TDesC& aTestName, const TDesC& aSectName)
   509 	:	RMdaOutputStreamTestBase(aTestName,aSectName)
   510 	{
   511 	}
   512 
   513 /*
   514  *
   515  * NewL
   516  *
   517  */
   518 RMdaOutputStreamPauseResumeBeforeWriteTest* RMdaOutputStreamPauseResumeBeforeWriteTest::NewL(const TDesC& aTestName, const TDesC& aSectName)
   519 	{
   520 	RMdaOutputStreamPauseResumeBeforeWriteTest * self = new(ELeave)RMdaOutputStreamPauseResumeBeforeWriteTest(aTestName,aSectName);
   521 	return self;
   522 	}
   523 
   524 /*
   525  *
   526  * DoKickoffTestL
   527  *
   528  */
   529 void RMdaOutputStreamPauseResumeBeforeWriteTest::DoKickoffTestL()
   530 	{
   531 	TPtrC filename;
   532 	// Get the filename of the audio file to play
   533 	if (!GetStringFromConfig(iSectName, KRawFile, filename))
   534 		{
   535 		ERR_PRINTF1(_L("Filename could not be retrieved from ini file"));
   536 		StopTest(KErrNotFound);
   537 		return;
   538 		}
   539 	// open using RFile for playback
   540 	iFilename.Copy(filename);
   541 	TInt err = iFile.Open(iFs, iFilename, EFileRead);
   542 	if (err != KErrNone)
   543 		{
   544 		ERR_PRINTF3(_L("Could not open input file %S. Error = %d"), &iFilename, err);
   545 		iFs.Close();
   546 		StopTest(err);
   547 		return;
   548 		}
   549 	// Get size of iFile
   550 	TInt filesize = 0;
   551 	err = iFile.Size(filesize);
   552 	if (err != KErrNone)
   553 		{
   554 		INFO_PRINTF2(_L("Error getting size of iFile = %d"), err);
   555 		StopTest(err);
   556 		return;
   557 		}
   558 	// Initialise iBuf
   559 	iBuffer.CreateMaxL(filesize/KFileDivision);
   560 	
   561 	//Read first half of the file
   562 	err = iFile.Read(iBuffer);
   563 	if (err != KErrNone)
   564 		{
   565 		INFO_PRINTF2(_L("Error reading iFile %d"), err);
   566 		StopTest(err);
   567 		}	
   568 			
   569 	iWait = ETrue;
   570 	iPause = KTimeout; //Set timeout to stop test if playback was paused
   571 	INFO_PRINTF2(_L("File under test  -> %S"), &iFilename);
   572 	iTimer = CPeriodic::NewL(CActive::EPriorityHigh);
   573 	}
   574 
   575 /*
   576  *
   577  * Fsm - Executes playing events of AudioToneUtility in sequence
   578  *
   579  */
   580 void RMdaOutputStreamPauseResumeBeforeWriteTest::Fsm(TMdaAOSEvent aMdaAudioOutputStreamEvent, TInt aError)
   581 	{
   582 	TInt error = 0;
   583 	TTimeIntervalMicroSeconds resumeposition;
   584 	switch (iAudioOutputStreamState)
   585 		{
   586 		case EStateAOSCreated:
   587 			{
   588 			if (aMdaAudioOutputStreamEvent == EEventAOSInitialize)
   589 				{
   590 				TMdaAudioDataSettings settings;
   591 				//Default settings
   592 				settings.Query();
   593 				settings.iChannels = TMdaAudioDataSettings::EChannelsMono;
   594 				settings.iSampleRate = TMdaAudioDataSettings::ESampleRate8000Hz;
   595 				INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::Pause before Open"));
   596 				error = iAudioOutputStream->Pause();
   597 				if(error == KErrNotReady)
   598 					{
   599 					INFO_PRINTF1(_L("Pause before open returned with KErrNotReady as expected"));
   600 					}
   601 				else
   602 					{
   603 					ERR_PRINTF2(_L("Pause before open returned with %d instead of KErrNotReady as expected"),error);
   604 					StopTest(error);
   605 					}
   606 				INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::Open"));
   607 				iAudioOutputStream->Open(&settings);
   608 				INFO_PRINTF1(_L("MdaAudioOutputStream State: EStateInitializing"));
   609 				iAudioOutputStreamState = EStateAOSInitializing;
   610 				}
   611 			else
   612 				{
   613 				ERR_PRINTF2(_L("MdaAudioOutputStream EEventInitialize not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
   614 				StopTest(aError, EFail);
   615 				}
   616 			break;
   617 			}
   618 		case EStateAOSInitializing:
   619 			{
   620 			if (aMdaAudioOutputStreamEvent == EEventAOSOpenComplete && aError == KErrNone)
   621 				{
   622 				INFO_PRINTF1(_L("Calling SetVolume using MaxVolume/2"));
   623 				iAudioOutputStream->SetVolume(iAudioOutputStream->MaxVolume()/2);
   624 				INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::Pause before first WriteL"));
   625 				error = iAudioOutputStream->Pause();
   626 				if(error == KErrNotReady)
   627 					{
   628 					INFO_PRINTF1(_L("Pause before first WriteL returned with KErrNotReady as expected"));
   629 					}
   630 				else
   631 					{
   632 					ERR_PRINTF2(_L("Pause before first WriteL returned with %d instead of KErrNotReady as expected"),error);
   633 					StopTest(error);
   634 					}
   635 				INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::Resume before first WriteL"));
   636 				error = iAudioOutputStream->Resume();
   637 				if(error == KErrNotReady)
   638 					{
   639 					INFO_PRINTF1(_L("Resume before first WriteL returned with KErrNotReady as expected"));
   640 					}
   641 				else
   642 					{
   643 					ERR_PRINTF2(_L("Resume before first WriteL returned with %d instead of KErrNotReady as expected"),error);
   644 					StopTest(error);
   645 					}						
   646 				INFO_PRINTF1(_L("Starting playback"));
   647 				iAudioOutputStream->WriteL(iBuffer);
   648 				iAudioOutputStreamState = EStateAOSPlaying;
   649 				StartTimer(iPause*KOneSecond);
   650 				}
   651 			else if (aMdaAudioOutputStreamEvent == EEventAOSOpenComplete && aError != KErrNone)
   652 				{
   653 				ERR_PRINTF2(_L("MaoscOpenComplete returned with error = %d"), aError);
   654 				StopTest(aError);	
   655 				}
   656 			else
   657 				{
   658 				ERR_PRINTF2(_L("MdaAudioOutputStream EEventOpenComplete not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
   659 				StopTest(aError, EFail);
   660 				}
   661 			break;
   662 			}
   663 		default:
   664 			{
   665 			ERR_PRINTF2(_L("Invalid MdaAudioOutputStream state received: %d"), iAudioOutputStreamState);
   666 			StopTest(KErrGeneral);
   667 			}
   668 		}
   669 	}
   670 
   671 /*
   672  *
   673  * DoTimerCallback
   674  *
   675  */
   676 void RMdaOutputStreamPauseResumeBeforeWriteTest::DoTimerCallback()
   677 	{
   678 	INFO_PRINTF1(_L("Cancelling timer"));
   679 	iTimer->Cancel();
   680 	ERR_PRINTF1(_L("Playback was paused when it shouldn't"));
   681 	StopTest(KErrGeneral);
   682 	}
   683 	
   684 /*
   685  *========================================================================================================
   686  * MM-MMF-ACLNT-I-0176-HP
   687  *========================================================================================================
   688  */
   689 RMdaOutputStreamResumeTest::RMdaOutputStreamResumeTest(const TDesC& aTestName, const TDesC& aSectName)
   690 	:	RMdaOutputStreamTestBase(aTestName,aSectName)
   691 	{
   692 	}
   693 
   694 /*
   695  *
   696  * NewL
   697  *
   698  */
   699 RMdaOutputStreamResumeTest* RMdaOutputStreamResumeTest::NewL(const TDesC& aTestName, const TDesC& aSectName)
   700 	{
   701 	RMdaOutputStreamResumeTest * self = new(ELeave)RMdaOutputStreamResumeTest(aTestName,aSectName);
   702 	return self;
   703 	}
   704 
   705 /*
   706  *
   707  * DoKickoffTestL
   708  *
   709  */
   710 void RMdaOutputStreamResumeTest::DoKickoffTestL()
   711 	{
   712 	TPtrC filename;
   713 	// Get the pause time
   714 	if (!GetIntFromConfig(iSectName, KPause, iPause))
   715 		{
   716 		ERR_PRINTF1(_L("Pause time could not be retrieved from ini file"));
   717 		StopTest(KErrNotFound);
   718 		return;
   719 		}
   720 	// Get the filename of the audio file to play
   721 	if (!GetStringFromConfig(iSectName, KRawFile, filename))
   722 		{
   723 		ERR_PRINTF1(_L("Filename could not be retrieved from ini file"));
   724 		StopTest(KErrNotFound);
   725 		return;
   726 		}
   727 	// open using RFile for playback
   728 	iFilename.Copy(filename);
   729 	TInt err = iFile.Open(iFs, iFilename, EFileRead);
   730 	if (err != KErrNone)
   731 		{
   732 		ERR_PRINTF3(_L("Could not open input file %S. Error = %d"), &iFilename, err);
   733 		iFs.Close();
   734 		StopTest(err);
   735 		return;
   736 		}
   737 	// Get size of iFile
   738 	TInt filesize = 0;
   739 	err = iFile.Size(filesize);
   740 	if (err != KErrNone)
   741 		{
   742 		INFO_PRINTF2(_L("Error getting size of iFile = %d"), err);
   743 		StopTest(err);
   744 		return;
   745 		}
   746 	// Initialise iBuf
   747 	iBuffer.CreateMaxL(filesize/KFileDivision);
   748 	
   749 	//Read first half of the file
   750 	err = iFile.Read(iBuffer);
   751 	if (err != KErrNone)
   752 		{
   753 		INFO_PRINTF2(_L("Error reading iFile %d"), err);
   754 		StopTest(err);
   755 		}	
   756 			
   757 	iWait = ETrue;
   758 	INFO_PRINTF2(_L("File under test  -> %S"), &iFilename);
   759 	iTimer = CPeriodic::NewL(CActive::EPriorityHigh);
   760 	}
   761 
   762 /*
   763  *
   764  * DoTimerCallback
   765  *
   766  */
   767 void RMdaOutputStreamResumeTest::DoTimerCallback()
   768 	{
   769 	if(!iWait)
   770 		{
   771 		INFO_PRINTF1(_L("Cancelling timer"));
   772 		iTimer->Cancel();
   773 		}
   774 	else
   775 		{
   776 		INFO_PRINTF1(_L("MdaAudioOutputStream Event: EEventTimerComplete"));
   777 		}
   778 	Fsm (EEventAOSTimerComplete, KErrNone);
   779 	}
   780 	
   781 /*
   782  *========================================================================================================
   783  * MM-MMF-ACLNT-I-0177-HP
   784  *========================================================================================================
   785  */
   786 RMdaOutputStreamResumeThriceTest::RMdaOutputStreamResumeThriceTest(const TDesC& aTestName, const TDesC& aSectName)
   787 	:	RMdaOutputStreamTestBase(aTestName,aSectName)
   788 	{
   789 	}
   790 
   791 /*
   792  *
   793  * NewL
   794  *
   795  */
   796 RMdaOutputStreamResumeThriceTest* RMdaOutputStreamResumeThriceTest::NewL(const TDesC& aTestName, const TDesC& aSectName)
   797 	{
   798 	RMdaOutputStreamResumeThriceTest * self = new(ELeave)RMdaOutputStreamResumeThriceTest(aTestName,aSectName);
   799 	return self;
   800 	}
   801 
   802 /*
   803  *
   804  * DoKickoffTestL
   805  *
   806  */
   807 void RMdaOutputStreamResumeThriceTest::DoKickoffTestL()
   808 	{
   809 	TPtrC filename;
   810 	// Get the pause time
   811 	if (!GetIntFromConfig(iSectName, KPause, iPause))
   812 		{
   813 		ERR_PRINTF1(_L("Pause time could not be retrieved from ini file"));
   814 		StopTest(KErrNotFound);
   815 		return;
   816 		}	
   817 	// Get the filename of the audio file to play
   818 	if (!GetStringFromConfig(iSectName, KRawFile, filename))
   819 		{
   820 		ERR_PRINTF1(_L("Filename could not be retrieved from ini file"));
   821 		StopTest(KErrNotFound);
   822 		return;
   823 		}
   824 	// open using RFile for playback
   825 	iFilename.Copy(filename);
   826 	TInt err = iFile.Open(iFs, iFilename, EFileRead);
   827 	if (err != KErrNone)
   828 		{
   829 		ERR_PRINTF3(_L("Could not open input file %S. Error = %d"), &iFilename, err);
   830 		iFs.Close();
   831 		StopTest(err);
   832 		return;
   833 		}
   834 	// Get size of iFile
   835 	TInt filesize = 0;
   836 	err = iFile.Size(filesize);
   837 	if (err != KErrNone)
   838 		{
   839 		INFO_PRINTF2(_L("Error getting size of iFile = %d"), err);
   840 		StopTest(err);
   841 		return;
   842 		}
   843 	// Initialise iBuf
   844 	iBuffer.CreateMaxL(filesize/KFileDivision);
   845 	
   846 	//Read first half of the file
   847 	err = iFile.Read(iBuffer);
   848 	if (err != KErrNone)
   849 		{
   850 		INFO_PRINTF2(_L("Error reading iFile %d"), err);
   851 		StopTest(err);
   852 		}	
   853 			
   854 	iWait = ETrue;
   855 	INFO_PRINTF2(_L("File under test  -> %S"), &iFilename);
   856 	iTimer = CPeriodic::NewL(CActive::EPriorityHigh);
   857 	}
   858 
   859 /*
   860  *
   861  * DoTimerCallback
   862  *
   863  */
   864 void RMdaOutputStreamResumeThriceTest::DoTimerCallback()
   865 	{
   866 	iCount++;
   867 	if(!iWait && iCount == 2*KRepeatThrice) //Repeating Pause-Resume cycle three times. Timer should be called 6 times
   868 		{
   869 		iTimer->Cancel();
   870 		Fsm (EEventAOSTimerComplete, KErrNone);
   871 		}
   872 	else
   873 		{
   874 		INFO_PRINTF1(_L("MdaToneUtility Event: EEventTimerComplete"));
   875 		Fsm (EEventAOSTimerComplete, KErrNone);
   876 		}
   877 	}
   878 
   879 /*
   880  *========================================================================================================
   881  * MM-MMF-ACLNT-I-0178-HP
   882  *========================================================================================================
   883  */
   884 RMdaOutputStreamConfigInPauseTest::RMdaOutputStreamConfigInPauseTest(const TDesC& aTestName, const TDesC& aSectName)
   885 	:	RMdaOutputStreamTestBase(aTestName,aSectName)
   886 	{
   887 	}
   888 
   889 /*
   890  *
   891  * NewL
   892  *
   893  */
   894 RMdaOutputStreamConfigInPauseTest* RMdaOutputStreamConfigInPauseTest::NewL(const TDesC& aTestName, const TDesC& aSectName)
   895 	{
   896 	RMdaOutputStreamConfigInPauseTest * self = new(ELeave)RMdaOutputStreamConfigInPauseTest(aTestName,aSectName);
   897 	return self;
   898 	}
   899 
   900 /*
   901  *
   902  * DoKickoffTestL
   903  *
   904  */
   905 void RMdaOutputStreamConfigInPauseTest::DoKickoffTestL()
   906 	{
   907 	TPtrC filename;
   908 	// Get the pause time
   909 	if (!GetIntFromConfig(iSectName, KPause, iPause))
   910 		{
   911 		ERR_PRINTF1(_L("Pause time could not be retrieved from ini file"));
   912 		StopTest(KErrNotFound);
   913 		return;
   914 		}
   915 	// Get the filename of the audio file to play
   916 	if (!GetStringFromConfig(iSectName, KRawFile, filename))
   917 		{
   918 		ERR_PRINTF1(_L("Filename could not be retrieved from ini file"));
   919 		StopTest(KErrNotFound);
   920 		return;
   921 		}
   922 	// Get the volume
   923 	if (!GetIntFromConfig(iSectName, KVolume, iVolume))
   924 		{
   925 		ERR_PRINTF1(_L("Volume could not be retrieved from ini file"));
   926 		StopTest(KErrNotFound);
   927 		return;
   928 		}
   929 	// Get the balance
   930 	if (!GetIntFromConfig(iSectName, KBalance, iBalance))
   931 		{
   932 		ERR_PRINTF1(_L("Balance could not be retrieved from ini file"));
   933 		StopTest(KErrNotFound);
   934 		return;
   935 		}		
   936 	// open using RFile for playback
   937 	iFilename.Copy(filename);
   938 	TInt err = iFile.Open(iFs, iFilename, EFileRead);
   939 	if (err != KErrNone)
   940 		{
   941 		ERR_PRINTF3(_L("Could not open input file %S. Error = %d"), &iFilename, err);
   942 		iFs.Close();
   943 		StopTest(err);
   944 		return;
   945 		}
   946 	// Get size of iFile
   947 	TInt filesize = 0;
   948 	err = iFile.Size(filesize);
   949 	if (err != KErrNone)
   950 		{
   951 		INFO_PRINTF2(_L("Error getting size of iFile = %d"), err);
   952 		StopTest(err);
   953 		return;
   954 		}
   955 	// Initialise iBuf
   956 	iBuffer.CreateMaxL(filesize/KFileDivision);
   957 	
   958 	//Read first half of the file
   959 	err = iFile.Read(iBuffer);
   960 	if (err != KErrNone)
   961 		{
   962 		INFO_PRINTF2(_L("Error reading iFile %d"), err);
   963 		StopTest(err);
   964 		}	
   965 			
   966 	iWait = ETrue;
   967 	iConfig = ETrue;
   968 	INFO_PRINTF2(_L("File under test  -> %S"), &iFilename);
   969 	iTimer = CPeriodic::NewL(CActive::EPriorityHigh);
   970 	}
   971 
   972 /*
   973  *
   974  * DoTimerCallback
   975  *
   976  */
   977 void RMdaOutputStreamConfigInPauseTest::DoTimerCallback()
   978 	{
   979 	if(!iWait && !iConfig)
   980 		{
   981 		iTimer->Cancel();
   982 		INFO_PRINTF1(_L("Comparing Volume and Balance with values set"));
   983 		if (iVolume == iAudioOutputStream->Volume() && Abs(iBalance - iAudioOutputStream->GetBalanceL())<KBalanceTolerance)
   984 			{
   985 			INFO_PRINTF3(_L("Volume = %d and Balance = %d as expected"),iVolume,iBalance);
   986 			}
   987 		else
   988 			{
   989 			ERR_PRINTF1(_L("Retrieved values are different than expected"));
   990 			ERR_PRINTF5(_L("Retrieved Volume = %d and Balance = %d. Expected Volume = %d and Balance = %d"),iAudioOutputStream->Volume(),iAudioOutputStream->GetBalanceL(),iVolume,iBalance);
   991 			StopTest(KErrGeneral);
   992 			}
   993 		}
   994 	else
   995 		{
   996 		INFO_PRINTF1(_L("MdaToneUtility Event: EEventTimerComplete"));
   997 		Fsm (EEventAOSTimerComplete, KErrNone);
   998 		}
   999 	}
  1000 
  1001 /*
  1002  *========================================================================================================
  1003  * MM-MMF-ACLNT-I-0179-HP
  1004  *========================================================================================================
  1005  */
  1006 RMdaOutputStreamInvalidConfigInPauseTest::RMdaOutputStreamInvalidConfigInPauseTest(const TDesC& aTestName, const TDesC& aSectName)
  1007 	:	RMdaOutputStreamTestBase(aTestName,aSectName)
  1008 	{
  1009 	}
  1010 
  1011 /*
  1012  *
  1013  * NewL
  1014  *
  1015  */
  1016 RMdaOutputStreamInvalidConfigInPauseTest* RMdaOutputStreamInvalidConfigInPauseTest::NewL(const TDesC& aTestName, const TDesC& aSectName)
  1017 	{
  1018 	RMdaOutputStreamInvalidConfigInPauseTest * self = new(ELeave)RMdaOutputStreamInvalidConfigInPauseTest(aTestName,aSectName);
  1019 	return self;
  1020 	}
  1021 
  1022 /*
  1023  *
  1024  * DoKickoffTestL
  1025  *
  1026  */
  1027 void RMdaOutputStreamInvalidConfigInPauseTest::DoKickoffTestL()
  1028 	{
  1029 	TPtrC filename;
  1030 	// Get the pause time
  1031 	if (!GetIntFromConfig(iSectName, KPause, iPause))
  1032 		{
  1033 		ERR_PRINTF1(_L("Pause time could not be retrieved from ini file"));
  1034 		StopTest(KErrNotFound);
  1035 		return;
  1036 		}
  1037 	// Get the filename of the audio file to play
  1038 	if (!GetStringFromConfig(iSectName, KRawFile, filename))
  1039 		{
  1040 		ERR_PRINTF1(_L("Filename could not be retrieved from ini file"));
  1041 		StopTest(KErrNotFound);
  1042 		return;
  1043 		}
  1044 	// open using RFile for playback
  1045 	iFilename.Copy(filename);
  1046 	TInt err = iFile.Open(iFs, iFilename, EFileRead);
  1047 	if (err != KErrNone)
  1048 		{
  1049 		ERR_PRINTF3(_L("Could not open input file %S. Error = %d"), &iFilename, err);
  1050 		iFs.Close();
  1051 		StopTest(err);
  1052 		return;
  1053 		}
  1054 	// Get size of iFile
  1055 	TInt filesize = 0;
  1056 	err = iFile.Size(filesize);
  1057 	if (err != KErrNone)
  1058 		{
  1059 		INFO_PRINTF2(_L("Error getting size of iFile = %d"), err);
  1060 		StopTest(err);
  1061 		return;
  1062 		}
  1063 	// Initialise iBuf
  1064 	iBuffer.CreateMaxL(filesize/KFileDivision);
  1065 	
  1066 	//Read first half of the file
  1067 	err = iFile.Read(iBuffer);
  1068 	if (err != KErrNone)
  1069 		{
  1070 		INFO_PRINTF2(_L("Error reading iFile %d"), err);
  1071 		StopTest(err);
  1072 		}	
  1073 			
  1074 	iWait = ETrue;
  1075 	iInvalidConfig = ETrue;
  1076 	INFO_PRINTF2(_L("File under test  -> %S"), &iFilename);
  1077 	iTimer = CPeriodic::NewL(CActive::EPriorityHigh);
  1078 	}
  1079 
  1080 /*
  1081  *
  1082  * DoTimerCallback
  1083  *
  1084  */
  1085 void RMdaOutputStreamInvalidConfigInPauseTest::DoTimerCallback()
  1086 	{
  1087 	if(!iWait)
  1088 		{
  1089 		INFO_PRINTF1(_L("Cancelling timer"));
  1090 		iTimer->Cancel();
  1091 		}
  1092 	else
  1093 		{
  1094 		INFO_PRINTF1(_L("MdaAudioOutputStream Event: EEventTimerComplete"));
  1095 		}
  1096 	Fsm (EEventAOSTimerComplete, KErrNone);
  1097 	}
  1098 
  1099 /*
  1100  *========================================================================================================
  1101  * MM-MMF-ACLNT-I-0180-HP
  1102  *========================================================================================================
  1103  */
  1104 RMdaOutputStreamGetBytesInPauseTest::RMdaOutputStreamGetBytesInPauseTest(const TDesC& aTestName, const TDesC& aSectName)
  1105 	:	RMdaOutputStreamTestBase(aTestName,aSectName)
  1106 	{
  1107 	}
  1108 
  1109 /*
  1110  *
  1111  * NewL
  1112  *
  1113  */
  1114 RMdaOutputStreamGetBytesInPauseTest* RMdaOutputStreamGetBytesInPauseTest::NewL(const TDesC& aTestName, const TDesC& aSectName)
  1115 	{
  1116 	RMdaOutputStreamGetBytesInPauseTest * self = new(ELeave)RMdaOutputStreamGetBytesInPauseTest(aTestName,aSectName);
  1117 	return self;
  1118 	}
  1119 
  1120 /*
  1121  *
  1122  * DoKickoffTestL
  1123  *
  1124  */
  1125 void RMdaOutputStreamGetBytesInPauseTest::DoKickoffTestL()
  1126 	{
  1127 	TPtrC filename;
  1128 	// Get the pause time
  1129 	if (!GetIntFromConfig(iSectName, KPause, iPause))
  1130 		{
  1131 		ERR_PRINTF1(_L("Pause time could not be retrieved from ini file"));
  1132 		StopTest(KErrNotFound);
  1133 		return;
  1134 		}
  1135 	// Get the filename of the audio file to play
  1136 	if (!GetStringFromConfig(iSectName, KRawFile, filename))
  1137 		{
  1138 		ERR_PRINTF1(_L("Filename could not be retrieved from ini file"));
  1139 		StopTest(KErrNotFound);
  1140 		return;
  1141 		}
  1142 	// open using RFile for playback
  1143 	iFilename.Copy(filename);
  1144 	TInt err = iFile.Open(iFs, iFilename, EFileRead);
  1145 	if (err != KErrNone)
  1146 		{
  1147 		ERR_PRINTF3(_L("Could not open input file %S. Error = %d"), &iFilename, err);
  1148 		iFs.Close();
  1149 		StopTest(err);
  1150 		return;
  1151 		}
  1152 	// Get size of iFile
  1153 	TInt filesize = 0;
  1154 	err = iFile.Size(filesize);
  1155 	if (err != KErrNone)
  1156 		{
  1157 		INFO_PRINTF2(_L("Error getting size of iFile = %d"), err);
  1158 		StopTest(err);
  1159 		return;
  1160 		}
  1161 	// Initialise iBuf
  1162 	iBuffer.CreateMaxL(filesize/KFileDivision);
  1163 	
  1164 	//Read first half of the file
  1165 	err = iFile.Read(iBuffer);
  1166 	if (err != KErrNone)
  1167 		{
  1168 		INFO_PRINTF2(_L("Error reading iFile %d"), err);
  1169 		StopTest(err);
  1170 		}	
  1171 			
  1172 	iWait = ETrue;
  1173 	iGetBytes = ETrue;
  1174 	INFO_PRINTF2(_L("File under test  -> %S"), &iFilename);
  1175 	iTimer = CPeriodic::NewL(CActive::EPriorityHigh);
  1176 	}
  1177 
  1178 /*
  1179  *
  1180  * DoTimerCallback
  1181  *
  1182  */
  1183 void RMdaOutputStreamGetBytesInPauseTest::DoTimerCallback()
  1184 	{
  1185 	if(!iWait)
  1186 		{
  1187 		INFO_PRINTF1(_L("Cancelling timer"));
  1188 		iTimer->Cancel();
  1189 		}
  1190 	else
  1191 		{
  1192 		INFO_PRINTF1(_L("MdaAudioOutputStream Event: EEventTimerComplete"));
  1193 		}
  1194 	Fsm (EEventAOSTimerComplete, KErrNone);
  1195 	}
  1196 
  1197 /*
  1198  *========================================================================================================
  1199  * MM-MMF-ACLNT-I-0181-HP
  1200  *========================================================================================================
  1201  */
  1202 RMdaOutputStreamPlayPauseStopPlayTest::RMdaOutputStreamPlayPauseStopPlayTest(const TDesC& aTestName, const TDesC& aSectName)
  1203 	:	RMdaOutputStreamTestBase(aTestName,aSectName)
  1204 	{
  1205 	}
  1206 
  1207 /*
  1208  *
  1209  * NewL
  1210  *
  1211  */
  1212 RMdaOutputStreamPlayPauseStopPlayTest* RMdaOutputStreamPlayPauseStopPlayTest::NewL(const TDesC& aTestName, const TDesC& aSectName)
  1213 	{
  1214 	RMdaOutputStreamPlayPauseStopPlayTest * self = new(ELeave)RMdaOutputStreamPlayPauseStopPlayTest(aTestName,aSectName);
  1215 	return self;
  1216 	}
  1217 
  1218 /*
  1219  *
  1220  * DoKickoffTestL
  1221  *
  1222  */
  1223 void RMdaOutputStreamPlayPauseStopPlayTest::DoKickoffTestL()
  1224 	{
  1225 	TPtrC filename;
  1226 	// Get the pause time
  1227 	if (!GetIntFromConfig(iSectName, KPause, iPause))
  1228 		{
  1229 		ERR_PRINTF1(_L("Pause time could not be retrieved from ini file"));
  1230 		StopTest(KErrNotFound);
  1231 		return;
  1232 		}
  1233 	// Get the filename of the audio file to play
  1234 	if (!GetStringFromConfig(iSectName, KRawFile, filename))
  1235 		{
  1236 		ERR_PRINTF1(_L("Filename could not be retrieved from ini file"));
  1237 		StopTest(KErrNotFound);
  1238 		return;
  1239 		}
  1240 	// open using RFile for playback
  1241 	iFilename.Copy(filename);
  1242 	TInt err = iFile.Open(iFs, iFilename, EFileRead);
  1243 	if (err != KErrNone)
  1244 		{
  1245 		ERR_PRINTF3(_L("Could not open input file %S. Error = %d"), &iFilename, err);
  1246 		iFs.Close();
  1247 		StopTest(err);
  1248 		return;
  1249 		}
  1250 	// Get size of iFile
  1251 	TInt filesize = 0;
  1252 	err = iFile.Size(filesize);
  1253 	if (err != KErrNone)
  1254 		{
  1255 		INFO_PRINTF2(_L("Error getting size of iFile = %d"), err);
  1256 		StopTest(err);
  1257 		return;
  1258 		}
  1259 	// Initialise iBuf
  1260 	iBuffer.CreateMaxL(filesize/KFileDivision);
  1261 	
  1262 	//Read first half of the file
  1263 	err = iFile.Read(iBuffer);
  1264 	if (err != KErrNone)
  1265 		{
  1266 		INFO_PRINTF2(_L("Error reading iFile %d"), err);
  1267 		StopTest(err);
  1268 		}	
  1269 			
  1270 	iWait = ETrue;
  1271 	iStop = ETrue;
  1272 	INFO_PRINTF2(_L("File under test  -> %S"), &iFilename);
  1273 	iTimer = CPeriodic::NewL(CActive::EPriorityHigh);
  1274 	}
  1275 
  1276 /*
  1277  *
  1278  * DoTimerCallback
  1279  *
  1280  */
  1281 void RMdaOutputStreamPlayPauseStopPlayTest::DoTimerCallback()
  1282 	{
  1283 	if(!iWait && iStop)
  1284 		{
  1285 		iAudioOutputStreamState = EStateAOSStopped;
  1286 		iStop = EFalse;
  1287 		iWait = ETrue;
  1288 		INFO_PRINTF1(_L("MAudioOutputStream Event: EEventTimerComplete"));
  1289 		Fsm (EEventAOSTimerComplete, KErrNone);
  1290 		}
  1291 	else if(!iWait && !iStop)
  1292 		{
  1293 		iTimer->Cancel();
  1294 		Fsm (EEventAOSTimerComplete, KErrNone);
  1295 		}
  1296 	else
  1297 		{
  1298 		INFO_PRINTF1(_L("MdaToneUtility Event: EEventTimerComplete"));
  1299 		Fsm (EEventAOSTimerComplete, KErrNone);
  1300 		}
  1301 	}
  1302 
  1303 /*
  1304  *
  1305  * Fsm - Executes playing events of AudioToneUtility in sequence
  1306  *
  1307  */
  1308 void RMdaOutputStreamPlayPauseStopPlayTest::Fsm(TMdaAOSEvent aMdaAudioOutputStreamEvent, TInt aError)
  1309 	{
  1310 	TInt error = 0;
  1311 	TTimeIntervalMicroSeconds resumeposition;
  1312 	switch (iAudioOutputStreamState)
  1313 		{
  1314 		case EStateAOSCreated:
  1315 			{
  1316 			if (aMdaAudioOutputStreamEvent == EEventAOSInitialize)
  1317 				{
  1318 				TMdaAudioDataSettings settings;
  1319 				//Default settings
  1320 				settings.Query();
  1321 				settings.iChannels = TMdaAudioDataSettings::EChannelsMono;
  1322 				settings.iSampleRate = TMdaAudioDataSettings::ESampleRate8000Hz;
  1323 				INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::Open"));
  1324 				iAudioOutputStream->Open(&settings);
  1325 				INFO_PRINTF1(_L("MdaAudioOutputStream State: EStateInitializing"));
  1326 				iAudioOutputStreamState = EStateAOSInitializing;
  1327 				}
  1328 			else
  1329 				{
  1330 				ERR_PRINTF2(_L("MdaAudioOutputStream EEventInitialize not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
  1331 				StopTest(aError, EFail);
  1332 				}
  1333 			break;
  1334 			}
  1335 		case EStateAOSInitializing:
  1336 			{
  1337 			if (aMdaAudioOutputStreamEvent == EEventAOSOpenComplete && aError == KErrNone)
  1338 				{
  1339 				INFO_PRINTF1(_L("Calling SetVolume using MaxVolume/2"));
  1340 				iAudioOutputStream->SetVolume(iAudioOutputStream->MaxVolume()/2);
  1341 				INFO_PRINTF1(_L("Starting playback"));
  1342 				iAudioOutputStream->WriteL(iBuffer);
  1343 				iAudioOutputStreamState = EStateAOSPlaying;
  1344 				StartTimer(iPause*KOneSecond);
  1345 				}
  1346 			else if (aMdaAudioOutputStreamEvent == EEventAOSOpenComplete && aError != KErrNone)
  1347 				{
  1348 				ERR_PRINTF2(_L("MaoscOpenComplete returned with error = %d"), aError);
  1349 				StopTest(aError);	
  1350 				}
  1351 			else
  1352 				{
  1353 				ERR_PRINTF2(_L("MdaAudioOutputStream EEventOpenComplete not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
  1354 				StopTest(aError, EFail);
  1355 				}
  1356 			break;
  1357 			}
  1358 		case EStateAOSPlaying:
  1359 			{
  1360 			if(aMdaAudioOutputStreamEvent == EEventAOSTimerComplete)
  1361 				{
  1362 				INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::Pause"));
  1363 				error = iAudioOutputStream->Pause();
  1364 				if(error == KErrNone)
  1365 					{
  1366 					INFO_PRINTF1(_L("Pause returned with KErrNone as expected"));
  1367 					}
  1368 				else
  1369 					{
  1370 					ERR_PRINTF2(_L("Pause returned with %d instead of KErrNone as expected"),error);
  1371 					StopTest(error);
  1372 					}
  1373 				iPosition = iAudioOutputStream->Position();
  1374 				INFO_PRINTF2(_L("Stream was paused at %Ld"),iPosition.Int64());
  1375 				INFO_PRINTF1(_L("MdaAudioOutputStream State: EStatePause"));
  1376 				iAudioOutputStreamState = EStateAOSPause;
  1377 				iWait = EFalse;
  1378 				}
  1379 			else
  1380 				{
  1381 				ERR_PRINTF2(_L("DevSound EEventTimerComplete not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
  1382 				StopTest(aError, EFail);
  1383 				}
  1384 			break;
  1385 			}
  1386 		case EStateAOSPause:
  1387 			{
  1388 			if (aMdaAudioOutputStreamEvent == EEventAOSTimerComplete)
  1389 				{
  1390 				if(iPosition == iAudioOutputStream->Position())
  1391 					{
  1392 					INFO_PRINTF2(_L("Paused position was maintained at %Ld"),iPosition.Int64());
  1393 					}
  1394 				else
  1395 					{
  1396 					ERR_PRINTF3(_L("Position was not maintained during pause. Expected %Ld Retrieved %Ld"),iPosition.Int64(),iAudioOutputStream->Position().Int64());
  1397 					StopTest(KErrGeneral);
  1398 					}
  1399 				INFO_PRINTF1(_L("Resuming playback. Calling CMdaAudioOutputStream::Resume"));
  1400 				error = iAudioOutputStream->Resume();
  1401 				resumeposition = iAudioOutputStream->Position();
  1402 				if(error == KErrNone)
  1403 					{
  1404 					INFO_PRINTF1(_L("Resume returned with KErrNone as expected"));
  1405 					iAudioOutputStreamState = EStateAOSPlaying;
  1406 					if(Abs(resumeposition.Int64() - iPosition.Int64()) <= KOneSecond/2)
  1407 						{
  1408 						INFO_PRINTF2(_L("Playback resumed from expected position %Ld"),iPosition.Int64());
  1409 						}
  1410 					else
  1411 						{
  1412 						ERR_PRINTF3(_L("Playback did not resume from expected position. Expected %Ld Retrieved %Ld"),iPosition.Int64(),resumeposition.Int64());
  1413 						StopTest(KErrGeneral);
  1414 						}
  1415 					}
  1416 				else
  1417 					{
  1418 					ERR_PRINTF2(_L("Resume returned with %d instead of KErrNone as expected"),error);
  1419 					StopTest(error);
  1420 					}				
  1421 				}
  1422 			else
  1423 				{
  1424 				ERR_PRINTF2(_L("EEventTimerComplete not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
  1425 				StopTest(aError, EFail);
  1426 				}
  1427 			break;
  1428 			}
  1429 		case EStateAOSStopped:
  1430 			{
  1431 			if (aMdaAudioOutputStreamEvent == EEventAOSTimerComplete)
  1432 				{
  1433 				if(iWait)
  1434 					{
  1435 					INFO_PRINTF1(_L("Stopping playback for 2 seconds"));
  1436 					iAudioOutputStream->Stop();
  1437 					iWait = EFalse;
  1438 					}
  1439 				else
  1440 					{
  1441 					INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::Resume while in Stop"));
  1442 					error = iAudioOutputStream->Resume();
  1443 					if(error == KErrNotReady)
  1444 						{
  1445 						INFO_PRINTF1(_L("Resume returned with KErrNotReady as expected"));
  1446 						}
  1447 					else
  1448 						{
  1449 						ERR_PRINTF2(_L("Resume returned with %d instead of KErrNotReady as expected"),error);
  1450 						StopTest(error);
  1451 						}
  1452 					TInt filepos = 0;
  1453 					INFO_PRINTF1(_L("Restarting file to start position"));
  1454 					error = iFile.Seek(ESeekStart, filepos);
  1455 					if (error != KErrNone)
  1456 						{
  1457 						INFO_PRINTF2(_L("Error restarting iFile %d"), error);
  1458 						StopTest(error);
  1459 						}
  1460 					error = iFile.Read(iBuffer);
  1461 					if (error != KErrNone)
  1462 						{
  1463 						INFO_PRINTF2(_L("Error reading iFile %d"), error);
  1464 						StopTest(error);
  1465 						}
  1466 					INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::WriteL while in Stop to restart playback"));
  1467 					iAudioOutputStream->WriteL(iBuffer);
  1468 					iAudioOutputStreamState = EStateAOSPlaying;
  1469 					}
  1470 				}
  1471 			else
  1472 				{
  1473 				ERR_PRINTF2(_L("EEventTimerComplete not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
  1474 				StopTest(aError, EFail);
  1475 				}
  1476 			break;
  1477 			}
  1478 		default:
  1479 			{
  1480 			ERR_PRINTF2(_L("Invalid MdaAudioOutputStream state received: %d"), iAudioOutputStreamState);
  1481 			StopTest(KErrGeneral);
  1482 			}
  1483 		}
  1484 	}
  1485 
  1486 /*
  1487  *
  1488  * MaoscPlayComplete - From MMdaAudioOutputStreamObserver
  1489  *
  1490  */
  1491 void RMdaOutputStreamPlayPauseStopPlayTest::MaoscPlayComplete(TInt aError)
  1492 	{
  1493 	INFO_PRINTF1(_L("========== AudioOutputStream MaoscPlayComplete() callback =========="));
  1494 	if(iAudioOutputStreamState == EStateAOSStopped)
  1495 		{
  1496 		if (aError == KErrCancel)
  1497 			{
  1498 			INFO_PRINTF2(_L("AudioOutputStream called MaoscPlayComplete with error = %d as expected"), aError);
  1499 			}
  1500 		else
  1501 			{
  1502 			ERR_PRINTF2(_L("AudioOutputStream called MaoscPlayComplete with error = %d"), aError);
  1503 			ERR_PRINTF2(_L("Expected error = %d"), KErrUnderflow);
  1504 			StopTest(aError);
  1505 			}
  1506 		}
  1507 	else if(iAudioOutputStreamState == EStateAOSPlaying)
  1508 		{
  1509 		if(aError == KErrUnderflow)
  1510 			{
  1511 			INFO_PRINTF2(_L("AudioOutputStream called MaoscPlayComplete with error = %d as expected"), aError);
  1512 			StopTest(EPass);
  1513 			}
  1514 		else
  1515 			{
  1516 			ERR_PRINTF2(_L("AudioOutputStream called MaoscPlayComplete with error = %d"), aError);
  1517 			ERR_PRINTF2(_L("Expected error = %d"), KErrUnderflow);
  1518 			StopTest(aError);
  1519 			}
  1520 		}
  1521 	else
  1522 		{
  1523 		ERR_PRINTF1(_L("AudioOutputStream called MaoscPlayComplete at invalid state"));
  1524 		StopTest(KErrGeneral);
  1525 		}
  1526 	}
  1527 
  1528 /*
  1529  *========================================================================================================
  1530  * MM-MMF-ACLNT-I-0182-HP
  1531  *========================================================================================================
  1532  */
  1533 RMdaOutputStreamInvalidFormatsTest::RMdaOutputStreamInvalidFormatsTest(const TDesC& aTestName, const TDesC& aSectName)
  1534 	:	RMdaOutputStreamTestBase(aTestName,aSectName)
  1535 	{
  1536 	}
  1537 
  1538 /*
  1539  *
  1540  * NewL
  1541  *
  1542  */
  1543 RMdaOutputStreamInvalidFormatsTest* RMdaOutputStreamInvalidFormatsTest::NewL(const TDesC& aTestName, const TDesC& aSectName)
  1544 	{
  1545 	RMdaOutputStreamInvalidFormatsTest * self = new(ELeave)RMdaOutputStreamInvalidFormatsTest(aTestName,aSectName);
  1546 	return self;
  1547 	}
  1548 
  1549 /*
  1550  *
  1551  * DoKickoffTestL
  1552  *
  1553  */
  1554 void RMdaOutputStreamInvalidFormatsTest::DoKickoffTestL()
  1555 	{
  1556 	TPtrC filename;
  1557 	// Get the pause time
  1558 	if (!GetIntFromConfig(iSectName, KPause, iPause))
  1559 		{
  1560 		ERR_PRINTF1(_L("Pause time could not be retrieved from ini file"));
  1561 		StopTest(KErrNotFound);
  1562 		return;
  1563 		}
  1564 	// Get the filename of the audio file to play
  1565 	if (!GetStringFromConfig(iSectName, KOggFile, filename))
  1566 		{
  1567 		ERR_PRINTF1(_L("Filename could not be retrieved from ini file"));
  1568 		StopTest(KErrNotFound);
  1569 		return;
  1570 		}
  1571 	// open using RFile for playback
  1572 	iFilename.Copy(filename);
  1573 	TInt err = iFile.Open(iFs, iFilename, EFileRead);
  1574 	if (err != KErrNone)
  1575 		{
  1576 		ERR_PRINTF3(_L("Could not open input file %S. Error = %d"), &iFilename, err);
  1577 		iFs.Close();
  1578 		StopTest(err);
  1579 		return;
  1580 		}
  1581 	// Get size of iFile
  1582 	TInt filesize = 0;
  1583 	err = iFile.Size(filesize);
  1584 	if (err != KErrNone)
  1585 		{
  1586 		INFO_PRINTF2(_L("Error getting size of iFile = %d"), err);
  1587 		StopTest(err);
  1588 		return;
  1589 		}
  1590 	// Initialise iBuf
  1591 	iBuffer.CreateMaxL(filesize/KFileDivision);
  1592 	
  1593 	//Read first half of the file
  1594 	err = iFile.Read(iBuffer);
  1595 	if (err != KErrNone)
  1596 		{
  1597 		INFO_PRINTF2(_L("Error reading iFile %d"), err);
  1598 		StopTest(err);
  1599 		}	
  1600 	
  1601 	iWait = ETrue;
  1602 	INFO_PRINTF2(_L("File under test  -> %S"), &iFilename);
  1603 	iTimer = CPeriodic::NewL(CActive::EPriorityHigh);
  1604 	}
  1605 
  1606 /*
  1607  *
  1608  * DoTimerCallback
  1609  *
  1610  */
  1611 void RMdaOutputStreamInvalidFormatsTest::DoTimerCallback()
  1612 	{
  1613 	INFO_PRINTF1(_L("Cancelling timer"));
  1614 	iTimer->Cancel();
  1615 	Fsm (EEventAOSTimerComplete, KErrNone);
  1616 	}
  1617 	
  1618 /*
  1619  *
  1620  * Fsm - Executes playing events of AudioToneUtility in sequence
  1621  *
  1622  */
  1623 void RMdaOutputStreamInvalidFormatsTest::Fsm(TMdaAOSEvent aMdaAudioOutputStreamEvent, TInt aError)
  1624 	{
  1625 	TInt error = 0;
  1626 	TTimeIntervalMicroSeconds resumeposition;
  1627 	switch (iAudioOutputStreamState)
  1628 		{
  1629 		case EStateAOSCreated:
  1630 			{
  1631 			if (aMdaAudioOutputStreamEvent == EEventAOSInitialize)
  1632 				{
  1633 				TMdaAudioDataSettings settings;
  1634 				//setting for OGG file
  1635 				settings.Query();
  1636 				settings.iChannels = TMdaAudioDataSettings::EChannelsStereo;
  1637 				settings.iSampleRate = TMdaAudioDataSettings::ESampleRate44100Hz;
  1638 				INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::Open"));
  1639 				iAudioOutputStream->Open(&settings);
  1640 				INFO_PRINTF1(_L("MdaAudioOutputStream State: EStateInitializing"));
  1641 				iAudioOutputStreamState = EStateAOSInitializing;
  1642 				}
  1643 			else
  1644 				{
  1645 				ERR_PRINTF2(_L("MdaAudioOutputStream EEventInitialize not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
  1646 				StopTest(aError, EFail);
  1647 				}
  1648 			break;
  1649 			}
  1650 		case EStateAOSInitializing:
  1651 			{
  1652 			if (aMdaAudioOutputStreamEvent == EEventAOSOpenComplete && aError == KErrNone)
  1653 				{
  1654 				TFourCC KVORBDataType('V', 'O', 'R', 'B');
  1655 				TRAPD(err,iAudioOutputStream->SetDataTypeL(KVORBDataType));
  1656 				if(err != KErrNone)
  1657 					{
  1658 					INFO_PRINTF1(_L("Failed to set non-PCM Format"));
  1659 					StopTest(err);
  1660 					}
  1661 				INFO_PRINTF1(_L("Calling SetVolume using MaxVolume/2"));
  1662 				iAudioOutputStream->SetVolume(iAudioOutputStream->MaxVolume()/2);
  1663 				INFO_PRINTF1(_L("Starting playback"));
  1664 				iAudioOutputStream->WriteL(iBuffer);
  1665 				iAudioOutputStreamState = EStateAOSPlaying;
  1666 				StartTimer(iPause*KOneSecond);
  1667 				}
  1668 			else if (aMdaAudioOutputStreamEvent == EEventAOSOpenComplete && aError != KErrNone)
  1669 				{
  1670 				ERR_PRINTF2(_L("MaoscOpenComplete returned with error = %d"), aError);
  1671 				StopTest(aError);	
  1672 				}
  1673 			else
  1674 				{
  1675 				ERR_PRINTF2(_L("MdaAudioOutputStream EEventOpenComplete not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
  1676 				StopTest(aError, EFail);
  1677 				}
  1678 			break;
  1679 			}
  1680 		case EStateAOSPlaying:
  1681 			{
  1682 			if(aMdaAudioOutputStreamEvent == EEventAOSTimerComplete)
  1683 				{
  1684 				INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::Pause while playing non-PCM format"));
  1685 				error = iAudioOutputStream->Pause();
  1686 				if(error == KErrNotSupported)
  1687 					{
  1688 					INFO_PRINTF1(_L("Pause while playing non-PCM format returned with KErrNotSupported as expected"));
  1689 					}
  1690 				else
  1691 					{
  1692 					ERR_PRINTF2(_L("Pause while playing non-PCM format returned with %d instead of KErrNotReady as expected"),error);
  1693 					StopTest(error);
  1694 					}
  1695 				}
  1696 			else
  1697 				{
  1698 				ERR_PRINTF2(_L("DevSound EEventTimerComplete not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
  1699 				StopTest(aError, EFail);
  1700 				}
  1701 			break;
  1702 			}
  1703 		default:
  1704 			{
  1705 			ERR_PRINTF2(_L("Invalid MdaAudioOutputStream state received: %d"), iAudioOutputStreamState);
  1706 			StopTest(KErrGeneral);
  1707 			}
  1708 		}
  1709 	}
  1710 
  1711 /*
  1712  *========================================================================================================
  1713  * MM-MMF-ACLNT-I-0184-HP
  1714  *========================================================================================================
  1715  */
  1716 RMdaOutputStreamPauseNonA3FTest::RMdaOutputStreamPauseNonA3FTest(const TDesC& aTestName, const TDesC& aSectName)
  1717 	:	RMdaOutputStreamTestBase(aTestName,aSectName)
  1718 	{
  1719 	}
  1720 
  1721 /*
  1722  *
  1723  * NewL
  1724  *
  1725  */
  1726 RMdaOutputStreamPauseNonA3FTest* RMdaOutputStreamPauseNonA3FTest::NewL(const TDesC& aTestName, const TDesC& aSectName)
  1727 	{
  1728 	RMdaOutputStreamPauseNonA3FTest * self = new(ELeave)RMdaOutputStreamPauseNonA3FTest(aTestName,aSectName);
  1729 	return self;
  1730 	}
  1731 
  1732 /*
  1733  *
  1734  * DoKickoffTestL
  1735  *
  1736  */
  1737 void RMdaOutputStreamPauseNonA3FTest::DoKickoffTestL()
  1738 	{
  1739 	TPtrC filename;
  1740 	// Get the pause time
  1741 	if (!GetIntFromConfig(iSectName, KPause, iPause))
  1742 		{
  1743 		ERR_PRINTF1(_L("Pause time could not be retrieved from ini file"));
  1744 		StopTest(KErrNotFound);
  1745 		return;
  1746 		}
  1747 	// Get the filename of the audio file to play
  1748 	if (!GetStringFromConfig(iSectName, KRawFile, filename))
  1749 		{
  1750 		ERR_PRINTF1(_L("Filename could not be retrieved from ini file"));
  1751 		StopTest(KErrNotFound);
  1752 		return;
  1753 		}
  1754 	// open using RFile for playback
  1755 	iFilename.Copy(filename);
  1756 	TInt err = iFile.Open(iFs, iFilename, EFileRead);
  1757 	if (err != KErrNone)
  1758 		{
  1759 		ERR_PRINTF3(_L("Could not open input file %S. Error = %d"), &iFilename, err);
  1760 		iFs.Close();
  1761 		StopTest(err);
  1762 		return;
  1763 		}
  1764 	// Get size of iFile
  1765 	TInt filesize = 0;
  1766 	err = iFile.Size(filesize);
  1767 	if (err != KErrNone)
  1768 		{
  1769 		INFO_PRINTF2(_L("Error getting size of iFile = %d"), err);
  1770 		StopTest(err);
  1771 		return;
  1772 		}
  1773 	// Initialise iBuf
  1774 	iBuffer.CreateMaxL(filesize/KFileDivision);
  1775 	
  1776 	//Read first half of the file
  1777 	err = iFile.Read(iBuffer);
  1778 	if (err != KErrNone)
  1779 		{
  1780 		INFO_PRINTF2(_L("Error reading iFile %d"), err);
  1781 		StopTest(err);
  1782 		}	
  1783 	
  1784 	iPause = KTimeout; //Set timeout to stop test if playback was paused
  1785 	iWait = ETrue;
  1786 	INFO_PRINTF2(_L("File under test  -> %S"), &iFilename);
  1787 	iTimer = CPeriodic::NewL(CActive::EPriorityHigh);
  1788 	}
  1789 
  1790 /*
  1791  *
  1792  * DoTimerCallback
  1793  *
  1794  */
  1795 void RMdaOutputStreamPauseNonA3FTest::DoTimerCallback()
  1796 	{
  1797 	INFO_PRINTF1(_L("Cancelling timer"));
  1798 	iTimer->Cancel();
  1799 	ERR_PRINTF1(_L("Playback was paused when it shouldn't"));
  1800 	StopTest(KErrGeneral);	
  1801 	}
  1802 
  1803 /*
  1804  *
  1805  * Fsm - Executes playing events of AudioToneUtility in sequence
  1806  *
  1807  */
  1808 void RMdaOutputStreamPauseNonA3FTest::Fsm(TMdaAOSEvent aMdaAudioOutputStreamEvent, TInt aError)
  1809 	{
  1810 	switch (iAudioOutputStreamState)
  1811 		{
  1812 		case EStateAOSCreated:
  1813 			{
  1814 			if (aMdaAudioOutputStreamEvent == EEventAOSInitialize)
  1815 				{
  1816 				TMdaAudioDataSettings settings;
  1817 				//Default settings
  1818 				settings.Query();
  1819 				settings.iChannels = TMdaAudioDataSettings::EChannelsMono;
  1820 				settings.iSampleRate = TMdaAudioDataSettings::ESampleRate8000Hz;
  1821 				INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::Open"));
  1822 				iAudioOutputStream->Open(&settings);
  1823 				INFO_PRINTF1(_L("MdaAudioOutputStream State: EStateInitializing"));
  1824 				iAudioOutputStreamState = EStateAOSInitializing;
  1825 				}
  1826 			else
  1827 				{
  1828 				ERR_PRINTF2(_L("MdaAudioOutputStream EEventInitialize not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
  1829 				StopTest(aError, EFail);
  1830 				}
  1831 			break;
  1832 			}
  1833 		case EStateAOSInitializing:
  1834 			{
  1835 			if (aMdaAudioOutputStreamEvent == EEventAOSOpenComplete && aError == KErrNone)
  1836 				{
  1837 				INFO_PRINTF1(_L("Calling SetVolume using MaxVolume/2"));
  1838 				iAudioOutputStream->SetVolume(iAudioOutputStream->MaxVolume()/2);
  1839 				INFO_PRINTF1(_L("Starting playback"));
  1840 				iAudioOutputStream->WriteL(iBuffer);
  1841 				StartTimer(iPause*KOneSecond);
  1842 				INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::Pause in non-a3f configuration"));
  1843 				TInt err = iAudioOutputStream->Pause();
  1844 				if(err == KErrNotSupported)
  1845 					{
  1846 					INFO_PRINTF1(_L("Pause in CMdaAudioOutputStream returned with KErrNotSupported as expected"));
  1847 					}
  1848 				else
  1849 					{
  1850 					ERR_PRINTF2(_L("Pause in CMdaAudioOutputStream returned with %d instead of KErrNotSupported as expected"),err);
  1851 					StopTest(err);
  1852 					}
  1853 				INFO_PRINTF1(_L("Calling CMdaAudioOutputStream::Resume in non-a3f configuration"));
  1854 				err = iAudioOutputStream->Resume();
  1855 				if(err == KErrNotReady)
  1856 					{
  1857 					INFO_PRINTF1(_L("Resume in CMdaAudioOutputStream returned with KErrNotReady as expected"));
  1858 					}
  1859 				else
  1860 					{
  1861 					ERR_PRINTF2(_L("Resume in CMdaAudioOutputStream returned with %d instead of KErrNotReady as expected"),err);
  1862 					StopTest(err);
  1863 					}					
  1864 				}
  1865 			else if (aMdaAudioOutputStreamEvent == EEventAOSOpenComplete && aError != KErrNone)
  1866 				{
  1867 				ERR_PRINTF2(_L("MaoscOpenComplete returned with error = %d"), aError);
  1868 				StopTest(aError);	
  1869 				}
  1870 			else
  1871 				{
  1872 				ERR_PRINTF2(_L("MdaAudioOutputStream EEventOpenComplete not received as expected. Received event: %d"), aMdaAudioOutputStreamEvent);
  1873 				StopTest(aError, EFail);
  1874 				}
  1875 			break;
  1876 			}
  1877 		default:
  1878 			{
  1879 			ERR_PRINTF2(_L("Invalid MdaAudioOutputStream state received: %d"), iAudioOutputStreamState);
  1880 			StopTest(KErrGeneral);
  1881 			}
  1882 		}
  1883 	}