os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/TestMultiClientARN.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2005-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 // CPP file: Audio Resource Notification tests for Multiple Audio Clients.
    15 // 
    16 //
    17 
    18 /**
    19  @file TestMultiClientARN.cpp
    20 */
    21 
    22 #include "TestAudioClientUtilitiesARN.h"
    23 
    24 //------------------------------------------------------------------------------
    25 //********************PREQ 797 - Audio Resource Notification********************
    26 //------------------------------------------------------------------------------
    27 
    28 //
    29 //CTestMdaAudioMultiClientCallbackSupport
    30 //
    31 
    32 /**
    33  * NewL
    34  */
    35 CTestMdaAudioMultiClientCallbackSupport* CTestMdaAudioMultiClientCallbackSupport::NewL(MTestAudioResourceNotificationCallback& aCallback)
    36 	{
    37 	return new(ELeave) CTestMdaAudioMultiClientCallbackSupport(aCallback);
    38 	}
    39 
    40 /**
    41  * MarncResourceAvailable
    42  */
    43 void CTestMdaAudioMultiClientCallbackSupport::MarncResourceAvailable(TUid aNotificationEventId, const TDesC8& aNotificationData)
    44 	{
    45 	iCallback.MarncResourceAvailableTest(aNotificationEventId, aNotificationData, *this);
    46 	}
    47 
    48 /**
    49  * Constructor
    50  */
    51 CTestMdaAudioMultiClientCallbackSupport::CTestMdaAudioMultiClientCallbackSupport(MTestAudioResourceNotificationCallback& aCallback):iCallback(aCallback)
    52 	{
    53 
    54 	}
    55 
    56 //
    57 //CTestMmfAclntMultiClientARN
    58 //
    59 
    60 /**
    61  * Constructor
    62  */
    63 CTestMmfAclntMultiClientARN::CTestMmfAclntMultiClientARN(const TDesC& aTestName, const TDesC& aSectName)
    64 	{
    65 	// store the name of this test case
    66 	// this is the name that is used by the script file
    67 	// Each test step initialises it's own name
    68 	iTestStepName=aTestName;
    69 	iHeapSize = 800000;
    70 	iSectName = aSectName;
    71 	}
    72 
    73 /**
    74  * MarncResourceAvailableTest
    75  */
    76 void CTestMmfAclntMultiClientARN::MarncResourceAvailableTest(TUid aNotificationEventId, const TDesC8& aNotificationData, CTestMdaAudioMultiClientCallbackSupport& aMdaAudioMultiClientCallbackSupport)
    77 	{
    78 	if (aNotificationEventId == KMMFEventCategoryAudioResourceAvailable)
    79 		{
    80 		INFO_PRINTF1(_L("iAudioOutputStream::MMMFAudioResourceNotificationCallback -> KMMFEventCategoryAudioResourceAvailable"));
    81 
    82 		//Convert TDesc8 to TInt64
    83 		TMMFTimeIntervalMicroSecondsPckg timeIntvbuf;
    84 		timeIntvbuf.Copy(aNotificationData);
    85 		TTimeIntervalMicroSeconds intPos = timeIntvbuf();
    86 		iPosition = intPos;
    87 
    88 		if (&aMdaAudioMultiClientCallbackSupport == iMdaAudioPlayerCallbackSupport)
    89 			{
    90 			INFO_PRINTF1(_L("iAudioPlayer -> MMMFAudioResourceNotificationCallback NotificationReceived"));
    91 			TRAP(iError, FsmL(EMarncResourceAvailablePlayer));
    92 			}
    93 		else if (&aMdaAudioMultiClientCallbackSupport == iMdaAudioRecorderCallbackSupport)
    94 			{
    95 			INFO_PRINTF1(_L("iAudioRecorder -> MMMFAudioResourceNotificationCallback NotificationReceived"));
    96 			TRAP(iError, FsmL(EMarncResourceAvailableRecorder));
    97 			}
    98 		else if (&aMdaAudioMultiClientCallbackSupport == iMdaAudioOutputStreamCallbackSupport)
    99 			{
   100 			INFO_PRINTF1(_L("iAudioOutputStream -> MMMFAudioResourceNotificationCallback NotificationReceived"));
   101 			TRAP(iError, FsmL(EMarncResourceAvailableOS));
   102 			}
   103 		}
   104 	else
   105 		{
   106 		INFO_PRINTF1(_L("MMMFAudioResourceNotificationCallback, but NOT KMMFEventCategoryAudioResourceAvailable"));
   107 		}
   108 	}
   109 
   110 /**
   111  * MapcInitCompleteTest
   112  */
   113 void CTestMmfAclntMultiClientARN::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration)
   114 	{
   115 	iDuration = aDuration;
   116 	INFO_PRINTF2(_L("iAudioPlayer -> MMdaAudioPlayerCallback InitComplete (%d)"),aError);
   117 	TRAP(iError, FsmL(EMapcInitComplete, aError));
   118 	}
   119 
   120 /**
   121  * MapcPlayCompleteTest
   122  */
   123 void CTestMmfAclntMultiClientARN::MapcPlayComplete(TInt aError)
   124 	{
   125 	INFO_PRINTF2(_L("iAudioPlayer -> MMdaAudioPlayerCallback PlayComplete (%d)"), aError);
   126 	TRAP(iError, FsmL(EMapcPlayComplete, aError));
   127 	}
   128 
   129 /**
   130  * MoscoStateChangeEventTest
   131  */
   132 void CTestMmfAclntMultiClientARN::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
   133 	{
   134 	INFO_PRINTF1(_L("iAudioRecorder -> MMdaObjectStateChangeObserver StateChanged"));
   135 	INFO_PRINTF4(_L("iTestAudioRecorder -> aErrorCode : %d, aPreviousState : %d, aCurrentState : %d"), aErrorCode, aPreviousState, aCurrentState);
   136 	TRAP(iError, FsmL(EMoscoStateChangeEvent, aErrorCode, iTestAudioRecorder->State()));
   137 	}
   138 
   139 /**
   140  * MMdaAudioOutputStreamCallback->MaoscOpenComplete
   141  */
   142 void CTestMmfAclntMultiClientARN::MaoscOpenComplete(TInt aError)
   143 	{
   144 	INFO_PRINTF2(_L("iAudioOutputStream -> MMdaAudioOutputStreamCallback : MaoscOpenComplete (%d)"),aError);
   145 	TRAP(iError, FsmL(EMaoscOpenComplete, aError));
   146 	}
   147 
   148 /**
   149  * MMdaAudioOutputStreamCallback->MaoscBufferCopied
   150  */
   151 void CTestMmfAclntMultiClientARN::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/)
   152 	{
   153 	INFO_PRINTF2(_L("iAudioOutputStream -> MMdaAudioOutputStreamCallback : MaoscBufferCopied  (%d)"), aError);
   154 	TRAP(iError, FsmL(EMaoscBufferCopied, aError));
   155 	}
   156 
   157 /**
   158  * MMdaAudioOutputStreamCallback->MaoscPlayComplete
   159  */
   160 void CTestMmfAclntMultiClientARN::MaoscPlayComplete(TInt aError)
   161 	{
   162 	INFO_PRINTF2(_L("iAudioOutputStream -> MMdaAudioOutputStreamCallback : MaoscPlayComplete  (%d)"), aError);
   163 	TRAP(iError, FsmL(EMaoscPlayComplete, aError));
   164 	}
   165 
   166 /**
   167  * DoTestStepPreambleL
   168  */
   169 TVerdict CTestMmfAclntMultiClientARN::DoTestStepPreambleL()
   170 	{
   171 	iError = KErrTimedOut;
   172 	TPtrC filename;
   173 	TVerdict verdict;
   174 	
   175 	// Install the scheduler - Call base DoTestStepPreambleL()
   176 	verdict = CTestMmfAclntStep::DoTestStepPreambleL();
   177 	if (verdict == EFail)
   178 		{
   179 		return verdict;
   180 		}
   181 	
   182 	iEventChecker = CMultiEventChecker::NewL();
   183 	//************** Initialise CMdaAudioPlayerUtility***************
   184 	INFO_PRINTF1(_L("Initialise CMdaAudioPlayerUtility : EMdaPriorityNormal"));
   185 	// Get file name
   186 	if(!GetStringFromConfig(iSectName, _L("playerAudioFile1"), filename))
   187 		{
   188 		return EInconclusive;
   189 		}
   190 	GetDriveName(iFilenamePlayer);
   191 	iFilenamePlayer.Append(filename);
   192 	
   193 	// Callback Handler
   194 	iMdaAudioPlayerCallbackSupport = CTestMdaAudioMultiClientCallbackSupport::NewL(*this);
   195 	
   196 	// Initialise Audio Player
   197 	iTestAudioPlayer = CMdaAudioPlayerUtility::NewL(*this, EMdaPriorityNormal);
   198 	
   199 	//************** Initialise CMdaAudioRecorderUtility*************
   200 	INFO_PRINTF1(_L("Initialise CMdaAudioRecorderUtility : EMdaPriorityMax"));
   201 	// Get file name
   202 	if(!GetStringFromConfig(iSectName, _L("playerAudioFile2"), filename))
   203 		{
   204 		return EInconclusive;
   205 		}
   206 	GetDriveName(iFilenameRecorder);
   207 	iFilenameRecorder.Append(filename);
   208 	
   209 	// Callback Handler
   210 	iMdaAudioRecorderCallbackSupport = CTestMdaAudioMultiClientCallbackSupport::NewL(*this);
   211 	
   212 	// Initialise Audio Recorder
   213 	iTestAudioRecorder = CMdaAudioRecorderUtility::NewL(*this, NULL, EMdaPriorityMax);
   214 	
   215 	//************** Initialise CMdaAudioOutputStream****************
   216 	INFO_PRINTF1(_L("Initialise CMdaAudioOutputStream  : EMdaPriorityMin"));
   217 	// Connect RFs session
   218 	TInt err = iFs.Connect();
   219 	if (err != KErrNone)
   220 		{
   221 		INFO_PRINTF2(_L("Error connecting to File session (RFs) = %d"), err);
   222 		return EFail;
   223 		}
   224 	// Callback Handler
   225 	iMdaAudioOutputStreamCallbackSupport = CTestMdaAudioMultiClientCallbackSupport::NewL(*this);
   226 	
   227 	// Initialise iTestAudioOutputStream
   228 	TRAP(err, iTestAudioOutputStream = CMdaAudioOutputStream::NewL(*this, EMdaPriorityMin, EMdaPriorityPreferenceTimeAndQuality));
   229 	if (err != KErrNone || iTestAudioOutputStream == NULL )
   230 		{
   231 		INFO_PRINTF2(_L("Error Creating iTestAudioOutputStream = %d"), err);
   232 		return EInconclusive;
   233 		}
   234 	// Open RFile
   235 	err = iFile.Open(iFs, KStreamRawFile1, EFileRead);
   236 	if (err != KErrNone)
   237 		{
   238 		INFO_PRINTF2(_L("Error opening iFile = %d"), err);
   239 		return EFail;
   240 		}
   241 	// Get size of iFile
   242 	err = iFile.Size(iFileSize);
   243 	if (err != KErrNone)
   244 		{
   245 		INFO_PRINTF2(_L("Error getting size of iFile = %d"), err);
   246 		return EFail;
   247 		}
   248 	// Initialise iBuf
   249 	iBuf.CreateMaxL(iFileSize);
   250 	
   251 	// Initialise the CCallBackTimer.
   252 	iCallBackTimer = CCallBackTimer::NewL(TCallBack(stopActiveScheduler));
   253 	
   254 	return verdict;
   255 	}
   256 
   257 /**
   258  * DoTestStepPostambleL
   259  */
   260 TVerdict CTestMmfAclntMultiClientARN::DoTestStepPostambleL()
   261 	{
   262 	// Delete all the Audio Client utilities.
   263 	if (iTestAudioPlayer)
   264 		iTestAudioPlayer->Close();
   265 	delete iTestAudioPlayer;
   266 	iTestAudioPlayer = NULL;
   267 	iTestAudioRecorder->Close();
   268 	delete iTestAudioRecorder;
   269 	iTestAudioRecorder = NULL;
   270 	delete iTestAudioOutputStream;
   271 	iTestAudioOutputStream = NULL;
   272 	// Delete CTestMdaAudioRecorderCallbackSupport
   273 	delete iMdaAudioPlayerCallbackSupport;
   274 	delete iMdaAudioRecorderCallbackSupport;
   275 	delete iMdaAudioOutputStreamCallbackSupport;
   276 	// Close RBuf8
   277 	iBuf.Close();
   278 	// Delete the CCallBackTimer.
   279 	delete iCallBackTimer;
   280 	iCallBackTimer=NULL;
   281 	// Close the File Handles
   282 	iFile.Close();
   283 	iFs.Close();
   284 	delete iEventChecker;
   285 	
   286 	return CTestMmfAclntStep::DoTestStepPostambleL();
   287 	}
   288 
   289 /**
   290  * DoTestStepL
   291  */
   292 TVerdict CTestMmfAclntMultiClientARN::DoTestStepL()
   293 	{
   294 	return( DoTestL() );
   295 	}
   296 
   297 /**
   298  * StateInit
   299  */
   300 void CTestMmfAclntMultiClientARN::StateInit()
   301 	{
   302 	iExpectedEvent=EIdleMulti;
   303 	iExpectedRecorderState=CMdaAudioClipUtility::ENotReady;
   304 	iExpectedError=KErrNone;
   305 	iState=0;
   306 	}
   307 
   308 /**
   309  * StateChange
   310  */
   311 void CTestMmfAclntMultiClientARN::StateChange(TMmfAudioMultiClientEvents aExpectedEvent, TInt aExpectedError, CMdaAudioClipUtility::TState aExpectedRecorderState)
   312 	{
   313 	iExpectedEvent=aExpectedEvent;
   314 	iExpectedRecorderState=aExpectedRecorderState;
   315 	iExpectedError=aExpectedError;
   316 	iState++;
   317 	}
   318 
   319 /**
   320  * FsmCheck
   321  */
   322 TBool CTestMmfAclntMultiClientARN::FsmCheck(TMmfAudioMultiClientEvents aEventCode, TInt aError, CMdaAudioClipUtility::TState aRecorderState)
   323 	{
   324 	TBool retFsmCheck = EFalse;
   325 	if ((iExpectedError !=KErrUnderflow) && (aError == KErrUnderflow))
   326 		{
   327 		INFO_PRINTF1(_L("Underflow !"));
   328 		}
   329 	else if (iExpectedEvent != aEventCode)
   330 		{
   331 		ERR_PRINTF3(_L("ExpectedEvent : %d, ActualEvent : %d"), iExpectedEvent, aEventCode);
   332 		iTestStepResult = EFail;
   333 		CActiveScheduler::Stop();
   334 		}
   335 	else if (iExpectedError != aError)
   336 		{
   337 		ERR_PRINTF3(_L("ExpectedError : %d, ActualError : %d"), iExpectedError, aError);
   338 		iTestStepResult = EFail;
   339 		CActiveScheduler::Stop();
   340 		}
   341 	else if (iExpectedRecorderState != aRecorderState)
   342 		{
   343 		ERR_PRINTF3(_L("ExpectedRecorderState : %d, ActualRecorderState : %d"), iExpectedRecorderState, aRecorderState);
   344 		iTestStepResult = EFail;
   345 		CActiveScheduler::Stop();
   346 		}
   347 	else
   348 		{
   349 		retFsmCheck = ETrue;
   350 		}
   351 	return retFsmCheck;
   352 	}
   353 
   354 //
   355 //CTestMmfAclntARN9001
   356 //
   357 
   358 /**
   359  * Constructor
   360  */
   361 CTestMmfAclntARN9001::CTestMmfAclntARN9001(const TDesC& aTestName, const TDesC& aSectName)
   362 	: CTestMmfAclntMultiClientARN(aTestName, aSectName)
   363 	{}
   364 
   365 /**
   366  * NewL
   367  */
   368 CTestMmfAclntARN9001* CTestMmfAclntARN9001::NewL(const TDesC& aTestName, const TDesC& aSectName)
   369 	{
   370 	CTestMmfAclntARN9001* self = new (ELeave) CTestMmfAclntARN9001(aTestName, aSectName);
   371 	return self;
   372 	}
   373 
   374 /**
   375  * DoTestL
   376  */
   377 TVerdict CTestMmfAclntARN9001::DoTestL()
   378 	{
   379 	return( PerformTestL() );
   380 	}
   381 
   382 /**
   383  * FsmCheck
   384  */
   385 TBool CTestMmfAclntARN9001::FsmCheck(TMmfAudioMultiClientEvents aEventCode, TInt aError, CMdaAudioClipUtility::TState aRecorderState)
   386 	{
   387 	TBool retFsmCheck = EFalse;
   388 	if ((iExpectedError !=KErrUnderflow) && (aError == KErrUnderflow))
   389 		{
   390 		INFO_PRINTF1(_L("Underflow !"));
   391 		}
   392 	else if (iExpectedEvent != aEventCode)
   393 		{
   394         if ((aEventCode == EMoscoStateChangeEvent))
   395 	        {
   396 	        retFsmCheck = ETrue;
   397 	        if (iEventOccured == EMarncResourceAvailableOS)
   398 	            {
   399 	            return retFsmCheck;
   400 	            }
   401             else
   402                 {
   403                 iEventOccured = EMoscoStateChangeEvent;
   404                 }
   405 	        }
   406         else if (aEventCode == EMarncResourceAvailableOS)
   407             {
   408             retFsmCheck = ETrue;
   409             if (iEventOccured == EMoscoStateChangeEvent)
   410                 {
   411                 return retFsmCheck;
   412                 }
   413             else
   414                 {
   415                 iEventOccured = EMarncResourceAvailableOS;
   416                 }
   417             }
   418         else
   419             {
   420     		ERR_PRINTF3(_L("ExpectedEvent : %d, ActualEvent : %d"), iExpectedEvent, aEventCode);
   421     		iTestStepResult = EFail;
   422     		CActiveScheduler::Stop();
   423             }
   424 		}
   425 	else if (iExpectedError != aError)
   426 		{
   427 		ERR_PRINTF3(_L("ExpectedError : %d, ActualError : %d"), iExpectedError, aError);
   428 		iTestStepResult = EFail;
   429 		CActiveScheduler::Stop();
   430 		}
   431 	else if (iExpectedRecorderState != aRecorderState)
   432 		{
   433 		ERR_PRINTF3(_L("ExpectedRecorderState : %d, ActualRecorderState : %d"), iExpectedRecorderState, aRecorderState);
   434 		iTestStepResult = EFail;
   435 		CActiveScheduler::Stop();
   436 		}
   437 	else
   438 		{
   439 		retFsmCheck = ETrue;
   440 		}
   441 	return retFsmCheck;
   442 	}
   443 
   444 /**
   445  * FsmL
   446  */
   447 void CTestMmfAclntARN9001::FsmL(TMmfAudioMultiClientEvents aEventCode, TInt aError, CMdaAudioClipUtility::TState aRecorderState)
   448 	{
   449 	if (FsmCheck(aEventCode, aError, aRecorderState))
   450 		{
   451 		TInt err = KErrNone;
   452 		switch (iState)
   453 			{
   454 			case 0:
   455 				// Open iTestAudioPlayer
   456 				iTestAudioPlayer->OpenFileL(iFilenamePlayer);
   457 				INFO_PRINTF1(_L("iTestAudioPlayer->OpenFileL()"));
   458 				// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
   459 				StateChange(EMapcInitComplete);
   460 				break;
   461 			case 1:
   462 				// Play iTestAudioPlayer
   463 				iTestAudioPlayer->Play();
   464 				INFO_PRINTF1(_L("iTestAudioPlayer->Play()"));
   465 				// Open iTestAudioRecorder
   466 				iTestAudioRecorder->OpenFileL(iFilenameRecorder);
   467 				INFO_PRINTF1(_L("iTestAudioRecorder->OpenFileL()"));
   468 				// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
   469 				StateChange(EMoscoStateChangeEvent, KErrNone, CMdaAudioClipUtility::EOpen);
   470 				break;
   471 			case 2:
   472 				// Play iTestAudioRecorder
   473 				iTestAudioRecorder->PlayL();
   474 				INFO_PRINTF1(_L("iTestAudioRecorder->PlayL()"));
   475 				// Set ExpectedEvent and change the State
   476 				StateChange(EMoscoStateChangeEvent, KErrNone, CMdaAudioClipUtility::EPlaying);
   477 				break;
   478 			case 3:
   479 				// iTestAudioPlayer gets PlayError.
   480 				StateChange(EMapcPlayComplete, KErrInUse);
   481 				break;
   482 			case 4:
   483 				// Register iTestAudioPlayer for Notification
   484 				err = iTestAudioPlayer->RegisterAudioResourceNotification(*iMdaAudioPlayerCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
   485 				INFO_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification : Status - %d "), err);
   486 				if( err != KErrNone )
   487 					{
   488 					ERR_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification - Failed with Error : %d"), err);
   489 					iTestStepResult = EFail;
   490 					CActiveScheduler::Stop();
   491 					break;
   492 					}
   493 				// Register iTestAudioOutputStream for Notification
   494 				err = iTestAudioOutputStream->RegisterAudioResourceNotification(*iMdaAudioOutputStreamCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
   495 				INFO_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification : Status - %d "), err);
   496 				if( err != KErrNone )
   497 					{
   498 					ERR_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification - Failed with Error : %d"), err);
   499 					iTestStepResult = EFail;
   500 					CActiveScheduler::Stop();
   501 					break;
   502 					}
   503 				// Open iTestAudioOutputStream
   504 				iTestAudioOutputStream->Open(NULL);
   505 				INFO_PRINTF1(_L("iTestAudioOutputStream->Open()"));
   506 				// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
   507 				StateChange(EMaoscOpenComplete);
   508 				break;
   509 			case 5:
   510 				// iFile->Read()
   511 				err = iFile.Read(iBuf); //-synchronous
   512 				if (err != KErrNone)
   513 					{
   514 					INFO_PRINTF2(_L("Error reading iFile %d"), err);
   515 					User::Leave(err);
   516 					}
   517 				// iTestAudioOutputStream->WriteL()
   518 				INFO_PRINTF1(_L("iTestAudioOutputStream->WriteL()"));
   519 				iTestAudioOutputStream->WriteL(iBuf); //-Should get Play Error.
   520 				// Set ExpectedEvent & ExpectedError and change the State
   521 				StateChange(EMaoscBufferCopied, KErrInUse);
   522 				break;
   523 			case 6:
   524 				// Set ExpectedEvent & ExpectedError and change the State
   525 				StateChange(EMaoscPlayComplete, KErrInUse);
   526 				break;
   527 			case 7:
   528 				// Delete the instance iTestAudioPlayer
   529 				delete iTestAudioPlayer;
   530 				iTestAudioPlayer = NULL;
   531 				INFO_PRINTF1(_L("delete iTestAudioPlayer"));
   532 				User::After(100000);
   533 				// Wait for iTestAudioRecorder to complete playing
   534 				// Set ExpectedEvent and change the State
   535 				StateChange(EMoscoStateChangeEvent, KErrNone, CMdaAudioClipUtility::EOpen);
   536 				break;
   537 			case 8:
   538 				// Timer to check if Notification Event Occurs.
   539 				iCallBackTimer->After(2000000);
   540 				// Set ExpectedEvent and change the State
   541 				StateChange(EMarncResourceAvailableOS, KErrNone);
   542 				break;
   543 			case 9:
   544 				iCallBackTimer->Cancel(); // in case something else stopped the AS
   545 				INFO_PRINTF1(_L("iTestAudioOutputStream->NotificationReceived"));
   546 				iTestStepResult = EPass;
   547 				CActiveScheduler::Stop();
   548 				break;
   549 			}
   550 		}
   551 	}
   552 
   553 /**
   554  * PerformTestL
   555  */
   556 TVerdict CTestMmfAclntARN9001::PerformTestL()
   557 	{
   558 	INFO_PRINTF1(_L("Receipt of Notification (on deleting the Audio Play Client instance of a Notified Client) of a Resource Available Event."));
   559 	iTestStepResult = EFail;
   560 	
   561 	// Initialise the state variables
   562 	StateInit();
   563 	
   564 	// Begin the process
   565 	FsmL(EIdleMulti, CMdaAudioClipUtility::ENotReady);
   566 	
   567 	// Start the scheduler - Done only once !
   568 	CActiveScheduler::Start();
   569 	
   570 	return iTestStepResult;
   571 	}
   572 
   573 
   574 //
   575 //CTestMmfAclntARN9002
   576 //
   577 
   578 /**
   579  * Constructor
   580  */
   581 CTestMmfAclntARN9002::CTestMmfAclntARN9002(const TDesC& aTestName, const TDesC& aSectName)
   582 	: CTestMmfAclntMultiClientARN(aTestName, aSectName)
   583 	{}
   584 
   585 /**
   586  * NewL
   587  */
   588 CTestMmfAclntARN9002* CTestMmfAclntARN9002::NewL(const TDesC& aTestName, const TDesC& aSectName)
   589 	{
   590 	CTestMmfAclntARN9002* self = new (ELeave) CTestMmfAclntARN9002(aTestName, aSectName);
   591 	return self;
   592 	}
   593 
   594 /**
   595  * DoTestL
   596  */
   597 TVerdict CTestMmfAclntARN9002::DoTestL()
   598 	{
   599 	return( PerformTestL() );
   600 	}
   601 
   602 void CTestMmfAclntARN9002::InitTest()
   603 	{
   604 	iEventChecker = CMultiEventChecker::NewL();
   605 	//Keep adding handlers
   606 	iStateHandlers[EStateApInitComplete] = &CTestMmfAclntARN9002::HandleStateApInitComplete;
   607 	iStateHandlers[EStateRecoderOpen] = &CTestMmfAclntARN9002::HandleStateRecorderOpen;
   608 	iStateHandlers[EStateRecoderPlaying] = &CTestMmfAclntARN9002::HandleStateRecorderPlaying;
   609 	iStateHandlers[EStateApPlayCompleteKErrInUse] = &CTestMmfAclntARN9002::HandleApPlayCompleteKErrInUse;
   610 	iStateHandlers[EStateAosOpenComplete] = &CTestMmfAclntARN9002::HandleStateAosOpenComplete;
   611 	iStateHandlers[EStateAosBufferCopiedKErrInUse] = &CTestMmfAclntARN9002::HandleStateAosBufferCopiedKErrInUse;
   612 	iStateHandlers[EStateAosPlayCompleteKErrInUse] = &CTestMmfAclntARN9002::HandleStateAosPlayCompleteKErrInUse;
   613 	iStateHandlers[EStateRecorderrelease] = &CTestMmfAclntARN9002::HandleStateRecorderrelease;
   614 	iStateHandlers[EStateApResourceAvailable] = &CTestMmfAclntARN9002::HandleStateApResourceAvailable;
   615 	iStateHandlers[EStateApPlayComplete] = &CTestMmfAclntARN9002::HandleStateApPlayComplete;
   616 	iStateHandlers[EStateAosResourceAvailable] = &CTestMmfAclntARN9002::HandleStateAosResourceAvailable;
   617 	}
   618 	
   619 void CTestMmfAclntARN9002::StartTestL()
   620 	{
   621 	// Open iTestAudioPlayer
   622 	iTestAudioPlayer->OpenFileL(iFilenamePlayer);
   623 	INFO_PRINTF1(_L("iTestAudioPlayer->OpenFileL()"));
   624 	iEventChecker->SetExpectedEvent(0,EMapcInitComplete,KErrNone);
   625 	iEventChecker->SetExpectedState(EStateApInitComplete);
   626 	}
   627 	
   628 TVerdict CTestMmfAclntARN9002::HandleStateApInitComplete()
   629 	{
   630 	iTestAudioPlayer->Play();
   631 	INFO_PRINTF1(_L("iTestAudioPlayer->Play()"));
   632 	// Open iTestAudioRecorder
   633 	iTestAudioRecorder->OpenFileL(iFilenameRecorder);
   634 	INFO_PRINTF1(_L("iTestAudioRecorder->OpenFileL()"));
   635 	iEventChecker->SetExpectedEvent(1,EMoscoStateChangeEvent, KErrNone,CMdaAudioClipUtility::EOpen);
   636 	iEventChecker->SetExpectedState(EStateRecoderOpen);
   637 	return EPass;
   638 	}
   639 	
   640 TVerdict CTestMmfAclntARN9002::HandleStateRecorderOpen()
   641 	{
   642 	iTestAudioRecorder->PlayL();
   643 	INFO_PRINTF1(_L("iTestAudioRecorder->PlayL()"));
   644 	// Set ExpectedEvent and change the State
   645 	iEventChecker->SetExpectedEvent(1,EMoscoStateChangeEvent,KErrNone,CMdaAudioClipUtility::EPlaying);
   646 	iEventChecker->SetExpectedState(EStateRecoderPlaying);
   647 	return EPass;
   648 	}
   649 
   650 TVerdict CTestMmfAclntARN9002::HandleStateRecorderPlaying()
   651 	{
   652 	iEventChecker->SetExpectedEvent(0,EMapcPlayComplete,KErrInUse);
   653 	iEventChecker->SetExpectedState(EStateApPlayCompleteKErrInUse);
   654 	return EPass;
   655 	}
   656 	
   657 TVerdict CTestMmfAclntARN9002::HandleApPlayCompleteKErrInUse()
   658 	{
   659 	TInt err = iTestAudioPlayer->RegisterAudioResourceNotification(*iMdaAudioPlayerCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
   660 	INFO_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification : Status - %d "), err);
   661 	if( err != KErrNone )
   662 		{
   663 		ERR_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification - Failed with Error : %d"), err);
   664 		iTestStepResult = EFail;
   665 		CActiveScheduler::Stop();
   666 		}
   667 	// Register iTestAudioOutputStream for Notification
   668 	err = iTestAudioOutputStream->RegisterAudioResourceNotification(*iMdaAudioOutputStreamCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
   669 	INFO_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification : Status - %d "), err);
   670 	if( err != KErrNone )
   671 		{
   672 		ERR_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification - Failed with Error : %d"), err);
   673 		iTestStepResult = EFail;
   674 		CActiveScheduler::Stop();
   675 		}
   676 	// Open iTestAudioOutputStream
   677 	iTestAudioOutputStream->Open(NULL);
   678 	INFO_PRINTF1(_L("iTestAudioOutputStream->Open()"));
   679 	// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
   680 	iEventChecker->SetExpectedEvent(2,EMaoscOpenComplete,KErrNone);
   681 	iEventChecker->SetExpectedState(EStateAosOpenComplete);
   682 	return EPass;
   683 	}
   684 
   685 TVerdict CTestMmfAclntARN9002::HandleStateAosOpenComplete()
   686 	{
   687 	// iFile->Read()
   688 	TInt err = iFile.Read(iBuf); //-synchronous
   689 	if (err != KErrNone)
   690 		{
   691 		INFO_PRINTF2(_L("Error reading iFile %d"), err);
   692 		User::Leave(err);
   693 		}
   694 	// iTestAudioOutputStream->WriteL()
   695 	INFO_PRINTF1(_L("iTestAudioOutputStream->WriteL()"));
   696 	iTestAudioOutputStream->WriteL(iBuf); //-Should get Play Error.
   697 	// Set ExpectedEvent & ExpectedError and change the State
   698 	iEventChecker->SetExpectedEvent(2,EMaoscBufferCopied,KErrInUse);
   699 	iEventChecker->SetExpectedState(EStateAosBufferCopiedKErrInUse);
   700 	return EPass;	
   701 	}
   702 
   703 TVerdict CTestMmfAclntARN9002::HandleStateAosBufferCopiedKErrInUse()
   704 	{
   705 	iEventChecker->SetExpectedEvent(2,EMaoscPlayComplete,KErrInUse);
   706 	iEventChecker->SetExpectedState(EStateAosPlayCompleteKErrInUse);
   707 	return EPass;
   708 	}
   709 
   710 TVerdict CTestMmfAclntARN9002::HandleStateAosPlayCompleteKErrInUse()
   711 	{
   712 	iEventChecker->SetExpectedEvent(1,EMoscoStateChangeEvent,KErrNone,CMdaAudioClipUtility::EOpen);
   713 	iEventChecker->SetExpectedState(EStateRecorderrelease);
   714 	return EPass;
   715 	}
   716 	
   717 TVerdict CTestMmfAclntARN9002::HandleStateRecorderrelease()
   718 	{
   719 	// Timer to check if Notification Event Occurs.
   720 	iCallBackTimer->After(2000000);
   721 	// Set ExpectedEvent and change the State
   722 	iEventChecker->SetExpectedEvent(0,EMarncResourceAvailablePlayer,KErrNone);
   723 	iEventChecker->SetExpectedState(EStateApResourceAvailable);
   724 	return EPass;
   725 	}
   726 	
   727 TVerdict CTestMmfAclntARN9002::HandleStateApResourceAvailable()
   728 	{
   729 	iCallBackTimer->Cancel(); // in case something else stopped the AS
   730 	INFO_PRINTF1(_L("iTestAudioPlayer->NotificationReceived"));
   731 	TInt err = iTestAudioPlayer->WillResumePlay();
   732 	INFO_PRINTF1(_L("iTestAudioPlayer->WillResumePlay()"));
   733 	if( err != KErrNone )
   734 		{
   735 		ERR_PRINTF2(_L("iTestAudioPlayer->WillResumePlay() - Failed with Error : %d"), err);
   736 		iTestStepResult = EFail;
   737 		CActiveScheduler::Stop();
   738 		}
   739 	iTestAudioPlayer->SetPosition(iPosition);
   740 	INFO_PRINTF1(_L("iTestAudioPlayer->SetPosition()"));
   741 	// Play iTestAudioPlayer
   742 	iTestAudioPlayer->Play();
   743 	// Set ExpectedEvent & ExpectedError and change the State
   744 	iEventChecker->RegisterClientEventToMonitor(0,EMapcPlayComplete,KErrNone,EStateApPlayComplete);
   745 	iEventChecker->RegisterClientEventToMonitor(2,EMarncResourceAvailableOS,KErrNone,EStateAosResourceAvailable);
   746 	iEventChecker->EnableMultipleEventMonitor();
   747 	return EPass;
   748 	}
   749 	
   750 TVerdict CTestMmfAclntARN9002::HandleStateApPlayComplete()
   751 	{
   752 	INFO_PRINTF1(_L("AudioPlayer->PlayComplete"));
   753 	if(iEventChecker->IsMonitoringFinished())
   754 		{
   755 		iTestStepResult = EPass;
   756 		iCallBackTimer->Cancel();
   757 		iEventChecker->StopTest();
   758 		}
   759 	else
   760 		{
   761 		iEventChecker->EnableMultipleEventMonitor();
   762 		}
   763 	return EPass;		
   764 	}
   765 	
   766 TVerdict CTestMmfAclntARN9002::HandleStateAosResourceAvailable()
   767 	{
   768 	INFO_PRINTF1(_L("iTestAudioOutputStream->NotificationReceived"));
   769 	if(iEventChecker->IsMonitoringFinished())
   770 		{
   771 		iCallBackTimer->Cancel();
   772 		iTestStepResult = EPass;
   773 		iEventChecker->StopTest();
   774 		}
   775 	else
   776 		{
   777 		iEventChecker->EnableMultipleEventMonitor();
   778 		}
   779 	return EPass;	
   780 	}
   781 	
   782 void CTestMmfAclntARN9002::DecideFsmState(TInt aClientNumber,CMultiEventChecker::TClientUtilityType aClientType, TInt aEventCode, TInt aError,CMdaAudioClipUtility::TState aRecorderState)
   783 	{
   784 	if (iEventChecker->CheckFsm(aClientNumber, aClientType, aEventCode, aError,aRecorderState))
   785 		{
   786 		iTestStepResult = (this->*(iStateHandlers[iEventChecker->NextState()]))();
   787  		if(iTestStepResult != EPass)
   788  			{
   789  			iEventChecker->StopTest();
   790  			}
   791 		}
   792 	}
   793 
   794 void CTestMmfAclntARN9002::FsmL(TMmfAudioMultiClientEvents aEventCode, TInt aError, CMdaAudioClipUtility::TState aRecorderState)
   795 	{
   796 	if (aEventCode == EMapcInitComplete || aEventCode == EMapcPlayComplete || aEventCode == EMarncResourceAvailablePlayer)
   797 		{
   798 			DecideFsmState(0,CMultiEventChecker::EAudioPlayer,aEventCode,aError);
   799 		}
   800 	if (aEventCode == EMoscoStateChangeEvent || aEventCode == EMarncResourceAvailableRecorder)
   801 		{
   802 			DecideFsmState(1,CMultiEventChecker::EAudioRecorder,aEventCode,aError,aRecorderState);
   803 		}
   804 	if (aEventCode == EMaoscOpenComplete || aEventCode == EMaoscBufferCopied || aEventCode == EMaoscPlayComplete || aEventCode == EMarncResourceAvailableOS)
   805 		{
   806 			DecideFsmState(2,CMultiEventChecker::EAudioStream,aEventCode,aError);
   807 		}
   808 	}
   809 
   810 TVerdict CTestMmfAclntARN9002::PerformTestL()
   811 	{
   812 	INFO_PRINTF1(_L("Receipt of Notification (on completion of play of a Notifed Client) of a Resource Available Event."));
   813 	iTestStepResult = EFail;
   814 	
   815 	// Initialise the handler functions
   816 	InitTest();
   817 	
   818 	// Initiate the process
   819 	StartTestL();
   820 	
   821 	// Start the scheduler - Done only once !
   822 	CActiveScheduler::Start();
   823 	
   824 	return iTestStepResult;
   825 	}
   826 
   827 
   828 //
   829 //CTestMmfAclntARN9003
   830 //
   831 
   832 /**
   833  * Constructor
   834  */
   835 CTestMmfAclntARN9003::CTestMmfAclntARN9003(const TDesC& aTestName, const TDesC& aSectName)
   836 	: CTestMmfAclntMultiClientARN(aTestName, aSectName)
   837 	{}
   838 
   839 /**
   840  * NewL
   841  */
   842 CTestMmfAclntARN9003* CTestMmfAclntARN9003::NewL(const TDesC& aTestName, const TDesC& aSectName)
   843 	{
   844 	CTestMmfAclntARN9003* self = new (ELeave) CTestMmfAclntARN9003(aTestName, aSectName);
   845 	return self;
   846 	}
   847 
   848 /**
   849  * DoTestL
   850  */
   851 TVerdict CTestMmfAclntARN9003::DoTestL()
   852 	{
   853 	return( PerformTestL() );
   854 	}
   855 
   856 /**
   857  * FsmL
   858  */
   859 void CTestMmfAclntARN9003::FsmL(TMmfAudioMultiClientEvents aEventCode, TInt aError, CMdaAudioClipUtility::TState aRecorderState)
   860 	{
   861 	if (FsmCheck(aEventCode, aError, aRecorderState))
   862 		{
   863 		TInt err = KErrNone;
   864 		switch (iState)
   865 			{
   866 			case 0:
   867 				// Open iTestAudioPlayer
   868 				iTestAudioPlayer->OpenFileL(iFilenamePlayer);
   869 				INFO_PRINTF1(_L("iTestAudioPlayer->OpenFileL()"));
   870 				// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
   871 				StateChange(EMapcInitComplete);
   872 				break;
   873 			case 1:
   874 				// Play iTestAudioPlayer
   875 				iTestAudioPlayer->Play();
   876 				INFO_PRINTF1(_L("iTestAudioPlayer->Play()"));
   877 				// Open iTestAudioRecorder
   878 				iTestAudioRecorder->OpenFileL(iFilenameRecorder);
   879 				INFO_PRINTF1(_L("iTestAudioRecorder->OpenFileL()"));
   880 				// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
   881 				StateChange(EMoscoStateChangeEvent, KErrNone, CMdaAudioClipUtility::EOpen);
   882 				break;
   883 			case 2:
   884 				// Play iTestAudioRecorder
   885 				iTestAudioRecorder->PlayL();
   886 				INFO_PRINTF1(_L("iTestAudioRecorder->PlayL()"));
   887 				// Set ExpectedEvent and change the State
   888 				StateChange(EMoscoStateChangeEvent, KErrNone, CMdaAudioClipUtility::EPlaying);
   889 				break;
   890 			case 3:
   891 				// iTestAudioPlayer gets PlayError.
   892 				StateChange(EMapcPlayComplete, KErrInUse);
   893 				break;
   894 			case 4:
   895 				// Register iTestAudioPlayer for Notification
   896 				err = iTestAudioPlayer->RegisterAudioResourceNotification(*iMdaAudioPlayerCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
   897 				INFO_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification : Status - %d "), err);
   898 				if( err != KErrNone )
   899 					{
   900 					ERR_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification - Failed with Error : %d"), err);
   901 					iTestStepResult = EFail;
   902 					CActiveScheduler::Stop();
   903 					break;
   904 					}
   905 				// Register iTestAudioOutputStream for Notification
   906 				err = iTestAudioOutputStream->RegisterAudioResourceNotification(*iMdaAudioOutputStreamCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
   907 				INFO_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification : Status - %d "), err);
   908 				if( err != KErrNone )
   909 					{
   910 					ERR_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification - Failed with Error : %d"), err);
   911 					iTestStepResult = EFail;
   912 					CActiveScheduler::Stop();
   913 					break;
   914 					}
   915 				// Open iTestAudioOutputStream
   916 				iTestAudioOutputStream->Open(NULL);
   917 				INFO_PRINTF1(_L("iTestAudioOutputStream->Open()"));
   918 				// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
   919 				StateChange(EMaoscOpenComplete);
   920 				break;
   921 			case 5:
   922 				// iFile->Read()
   923 				err = iFile.Read(iBuf); //-synchronous
   924 				if (err != KErrNone)
   925 					{
   926 					INFO_PRINTF2(_L("Error reading iFile %d"), err);
   927 					User::Leave(err);
   928 					}
   929 				// iTestAudioOutputStream->WriteL()
   930 				INFO_PRINTF1(_L("iTestAudioOutputStream->WriteL()"));
   931 				iTestAudioOutputStream->WriteL(iBuf); //-Should get Play Error.
   932 				// Set ExpectedEvent & ExpectedError and change the State
   933 				StateChange(EMaoscBufferCopied, KErrInUse);
   934 				break;
   935 			case 6:
   936 				// Set ExpectedEvent & ExpectedError and change the State
   937 				StateChange(EMaoscPlayComplete, KErrInUse);
   938 				break;			
   939 			case 7:
   940 				// Wait for iTestAudioRecorder to complete playing
   941 				// Set ExpectedEvent and change the State
   942 				StateChange(EMoscoStateChangeEvent, KErrNone, CMdaAudioClipUtility::EOpen);
   943 				break;
   944 			case 8:
   945 				// Timer to check if Notification Event Occurs.
   946 				iCallBackTimer->After(2000000);
   947 				// Set ExpectedEvent and change the State
   948 				StateChange(EMarncResourceAvailablePlayer, KErrNone);
   949 				break;
   950 			case 9:
   951 				iCallBackTimer->Cancel(); // in case something else stopped the AS
   952 				INFO_PRINTF1(_L("iTestAudioPlayer->NotificationReceived"));
   953 				err = iTestAudioPlayer->WillResumePlay();
   954 				INFO_PRINTF1(_L("iTestAudioPlayer->WillResumePlay()"));
   955 				if( err != KErrNone )
   956 					{
   957 					ERR_PRINTF2(_L("iTestAudioPlayer->WillResumePlay() - Failed with Error : %d"), err);
   958 					iTestStepResult = EFail;
   959 					CActiveScheduler::Stop();
   960 					break;
   961 					}
   962 				iTestAudioPlayer->SetPosition(iPosition);
   963 				INFO_PRINTF1(_L("iTestAudioPlayer->SetPosition()"));
   964 				// Play iTestAudioPlayer
   965 				iTestAudioPlayer->Play();
   966 				// Stop & Close iTestAudioPlayer
   967 				WaitWithTimeout(iRequestStatus,1000000);
   968 				iTestAudioPlayer->Stop();
   969 				INFO_PRINTF1(_L("iTestAudioPlayer->Stop()"));
   970 				iTestAudioPlayer->Close();
   971 				INFO_PRINTF1(_L("iTestAudioPlayer->Close()"));
   972 				// Timer to check if Notification Event Occurs.
   973 				iCallBackTimer->After(2000000);
   974 				// Set ExpectedEvent and change the State
   975 				StateChange(EMarncResourceAvailableOS);
   976 				break;
   977 			case 10:
   978 				iCallBackTimer->Cancel(); // in case something else stopped the AS
   979 				INFO_PRINTF1(_L("iTestAudioOutputStream->NotificationReceived"));
   980 				iTestStepResult = EPass;
   981 				CActiveScheduler::Stop();
   982 				break;
   983 			}
   984 		}
   985 	}
   986 
   987 /**
   988  * PerformTestL
   989  */
   990 TVerdict CTestMmfAclntARN9003::PerformTestL()
   991 	{
   992 	INFO_PRINTF1(_L("Receipt of Notification (on stopping play of a Notitifed Client) of a Resource Available Event."));
   993 	iTestStepResult = EFail;
   994 	
   995 	// Initialise the state variables
   996 	StateInit();
   997 	
   998 	// Begin the process
   999 	FsmL(EIdleMulti, CMdaAudioClipUtility::ENotReady);
  1000 	
  1001 	// Start the scheduler - Done only once !
  1002 	CActiveScheduler::Start();
  1003 	
  1004 	return iTestStepResult;
  1005 	}
  1006 
  1007 //
  1008 //CTestMmfAclntARN9004
  1009 //
  1010 
  1011 /**
  1012  * Constructor
  1013  */
  1014 CTestMmfAclntARN9004::CTestMmfAclntARN9004(const TDesC& aTestName, const TDesC& aSectName)
  1015 	: CTestMmfAclntMultiClientARN(aTestName, aSectName)
  1016 	{}
  1017 
  1018 /**
  1019  * NewL
  1020  */
  1021 CTestMmfAclntARN9004* CTestMmfAclntARN9004::NewL(const TDesC& aTestName, const TDesC& aSectName)
  1022 	{
  1023 	CTestMmfAclntARN9004* self = new (ELeave) CTestMmfAclntARN9004(aTestName, aSectName);
  1024 	return self;
  1025 	}
  1026 
  1027 /**
  1028  * DoTestL
  1029  */
  1030 TVerdict CTestMmfAclntARN9004::DoTestL()
  1031 	{
  1032 	return( PerformTestL() );
  1033 	}
  1034 
  1035 /**
  1036  * FsmCheck
  1037  */
  1038 TBool CTestMmfAclntARN9004::FsmCheck(TMmfAudioMultiClientEvents aEventCode, TInt aError, CMdaAudioClipUtility::TState aRecorderState)
  1039 	{
  1040 	TBool retFsmCheck = EFalse;
  1041 	if ((iExpectedError !=KErrUnderflow) && (aError == KErrUnderflow))
  1042 		{
  1043 		INFO_PRINTF1(_L("Underflow !"));
  1044 		}
  1045 	else if (iExpectedEvent != aEventCode)
  1046 		{
  1047         if ((aEventCode == EMoscoStateChangeEvent))
  1048 	        {
  1049 	        retFsmCheck = ETrue;
  1050 #ifdef SYMBIAN_MULTIMEDIA_A3FDEVSOUND
  1051 	        if (iEventOccured == EMarncResourceAvailablePlayer)
  1052 #else
  1053    	        if (iEventOccured == EMarncResourceAvailableOS)
  1054 #endif
  1055 	            {
  1056 	            return retFsmCheck;
  1057 	            }
  1058             else
  1059                 {
  1060                 iEventOccured = EMoscoStateChangeEvent;
  1061                 }
  1062 	        }
  1063 #ifdef SYMBIAN_MULTIMEDIA_A3FDEVSOUND
  1064         else if (aEventCode == EMarncResourceAvailablePlayer)
  1065 #else
  1066         else if (aEventCode == EMarncResourceAvailableOS)
  1067 #endif
  1068             {
  1069             retFsmCheck = ETrue;
  1070             if (iEventOccured == EMoscoStateChangeEvent)
  1071                 {
  1072                 return retFsmCheck;
  1073                 }
  1074             else
  1075                 {
  1076 #ifdef SYMBIAN_MULTIMEDIA_A3FDEVSOUND
  1077                 iEventOccured = EMarncResourceAvailablePlayer;
  1078 #else
  1079 				iEventOccured = EMarncResourceAvailableOS;
  1080 #endif
  1081 		       }
  1082             }
  1083         else
  1084             {
  1085     		ERR_PRINTF3(_L("ExpectedEvent : %d, ActualEvent : %d"), iExpectedEvent, aEventCode);
  1086     		iTestStepResult = EFail;
  1087     		CActiveScheduler::Stop();
  1088             }
  1089 		}
  1090 	else if (iExpectedError != aError)
  1091 		{
  1092 		ERR_PRINTF3(_L("ExpectedError : %d, ActualError : %d"), iExpectedError, aError);
  1093 		iTestStepResult = EFail;
  1094 		CActiveScheduler::Stop();
  1095 		}
  1096 	else if (iExpectedRecorderState != aRecorderState)
  1097 		{
  1098 		ERR_PRINTF3(_L("ExpectedRecorderState : %d, ActualRecorderState : %d"), iExpectedRecorderState, aRecorderState);
  1099 		iTestStepResult = EFail;
  1100 		CActiveScheduler::Stop();
  1101 		}
  1102 	else
  1103 		{
  1104 		retFsmCheck = ETrue;
  1105 		}
  1106 	return retFsmCheck;
  1107 	}
  1108 
  1109 /**
  1110  * FsmL
  1111  */
  1112 void CTestMmfAclntARN9004::FsmL(TMmfAudioMultiClientEvents aEventCode, TInt aError, CMdaAudioClipUtility::TState aRecorderState)
  1113 	{
  1114 	if (FsmCheck(aEventCode, aError, aRecorderState))
  1115 		{
  1116 		TInt err = KErrNone;
  1117 		switch (iState)
  1118 			{
  1119 			case 0:
  1120 				// Open iTestAudioPlayer
  1121 				iTestAudioPlayer->OpenFileL(iFilenamePlayer);
  1122 				INFO_PRINTF1(_L("iTestAudioPlayer->OpenFileL()"));
  1123 				// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
  1124 				StateChange(EMapcInitComplete);
  1125 				break;
  1126 			case 1:
  1127 				// Play iTestAudioPlayer
  1128 				iTestAudioPlayer->Play();
  1129 				INFO_PRINTF1(_L("iTestAudioPlayer->Play()"));
  1130 				// Open iTestAudioRecorder
  1131 				iTestAudioRecorder->OpenFileL(iFilenameRecorder);
  1132 				INFO_PRINTF1(_L("iTestAudioRecorder->OpenFileL()"));
  1133 				// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
  1134 				StateChange(EMoscoStateChangeEvent, KErrNone, CMdaAudioClipUtility::EOpen);
  1135 				break;
  1136 			case 2:
  1137 				// Play iTestAudioRecorder
  1138 				iTestAudioRecorder->PlayL();
  1139 				INFO_PRINTF1(_L("iTestAudioRecorder->PlayL()"));
  1140 				// Set ExpectedEvent and change the State
  1141 				StateChange(EMoscoStateChangeEvent, KErrNone, CMdaAudioClipUtility::EPlaying);
  1142 				break;
  1143 			case 3:
  1144 				// iTestAudioPlayer gets PlayError.
  1145 				StateChange(EMapcPlayComplete, KErrInUse);
  1146 				break;
  1147 			case 4:
  1148 				// Register iTestAudioOutputStream for Notification
  1149 				err = iTestAudioOutputStream->RegisterAudioResourceNotification(*iMdaAudioOutputStreamCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
  1150 				INFO_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification : Status - %d "), err);
  1151 				if( err != KErrNone )
  1152 					{
  1153 					ERR_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification - Failed with Error : %d"), err);
  1154 					iTestStepResult = EFail;
  1155 					CActiveScheduler::Stop();
  1156 					break;
  1157 					}
  1158 				// Register iTestAudioPlayer for Notification
  1159 				err = iTestAudioPlayer->RegisterAudioResourceNotification(*iMdaAudioPlayerCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
  1160 				INFO_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification : Status - %d "), err);
  1161 				if( err != KErrNone )
  1162 					{
  1163 					ERR_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification - Failed with Error : %d"), err);
  1164 					iTestStepResult = EFail;
  1165 					CActiveScheduler::Stop();
  1166 					break;
  1167 					}
  1168 				// Open iTestAudioOutputStream
  1169 				iTestAudioOutputStream->Open(NULL);
  1170 				INFO_PRINTF1(_L("iTestAudioOutputStream->Open()"));
  1171 				// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
  1172 				StateChange(EMaoscOpenComplete);
  1173 				break;
  1174 			case 5:
  1175 				// iFile->Read()
  1176 				err = iFile.Read(iBuf); //-synchronous
  1177 				if (err != KErrNone)
  1178 					{
  1179 					INFO_PRINTF2(_L("Error reading iFile %d"), err);
  1180 					User::Leave(err);
  1181 					}
  1182 				// iTestAudioOutputStream->WriteL()
  1183 				INFO_PRINTF1(_L("iTestAudioOutputStream->WriteL()"));
  1184 				iTestAudioOutputStream->WriteL(iBuf); //-Should get Play Error.
  1185 				// Set ExpectedEvent & ExpectedError and change the State
  1186 				StateChange(EMaoscBufferCopied, KErrInUse);
  1187 				break;
  1188 			case 6:
  1189 				// Set ExpectedEvent & ExpectedError and change the State
  1190 				StateChange(EMaoscPlayComplete, KErrInUse);
  1191 				break;			
  1192 			case 7:
  1193 				// Wait for iTestAudioRecorder to complete playing
  1194 				// Set ExpectedEvent and change the State
  1195 				StateChange(EMoscoStateChangeEvent, KErrNone, CMdaAudioClipUtility::EOpen);
  1196 				break;
  1197 			case 8:
  1198 				// Timer to check if Notification Event Occurs.
  1199 				iCallBackTimer->After(2000000);
  1200 				// Set ExpectedEvent and change the State
  1201 				StateChange(EMarncResourceAvailableOS);
  1202 				break;
  1203 			case 9:
  1204 				iCallBackTimer->Cancel(); // in case something else stopped the AS
  1205 				INFO_PRINTF1(_L("iTestAudioOutputStream->NotificationReceived"));
  1206 #ifdef SYMBIAN_MULTIMEDIA_A3FDEVSOUND
  1207 				StateChange(EMarncResourceAvailablePlayer);
  1208 #else
  1209 				iTestStepResult = EPass;
  1210 				CActiveScheduler::Stop();
  1211 #endif
  1212 				break;
  1213 #ifdef SYMBIAN_MULTIMEDIA_A3FDEVSOUND
  1214 			case 10:
  1215 				INFO_PRINTF1(_L("iTestAudioPlayer->NotificationReceived"));
  1216 				err = iTestAudioPlayer->WillResumePlay();
  1217 				INFO_PRINTF1(_L("iTestAudioPlayer->WillResumePlay()"));
  1218 				if( err != KErrNone )
  1219 					{
  1220 					ERR_PRINTF2(_L("iTestAudioPlayer->WillResumePlay() - Failed with Error : %d"), err);
  1221 					iTestStepResult = EFail;
  1222 					CActiveScheduler::Stop();
  1223 					break;
  1224 					}
  1225 				iTestStepResult = EPass;
  1226 				CActiveScheduler::Stop();
  1227 				break;
  1228 #endif
  1229 			}
  1230 		}
  1231 	}
  1232 
  1233 /**
  1234  * PerformTestL
  1235  */
  1236 TVerdict CTestMmfAclntARN9004::PerformTestL()
  1237 	{
  1238 	INFO_PRINTF1(_L("Receipt of Notification (chronological order for equal priority clients) of a Resource Available Event."));
  1239 	iTestStepResult = EFail;
  1240 	
  1241 	// Initialise the state variables
  1242 	StateInit();
  1243 	
  1244 	// Set the priorities
  1245 	iTestAudioPlayer->SetPriority(EMdaPriorityMin, EMdaPriorityPreferenceTimeAndQuality);
  1246 	INFO_PRINTF1(_L("Reset Priority for CMdaAudioPlayerUtility  : EMdaPriorityMin"));
  1247 	iTestAudioOutputStream->SetPriority(EMdaPriorityMin, EMdaPriorityPreferenceTimeAndQuality);
  1248 	INFO_PRINTF1(_L("Reset Priority for CMdaAudioOutputStream   : EMdaPriorityMin"));
  1249 	
  1250 	// Begin the process
  1251 	FsmL(EIdleMulti, CMdaAudioClipUtility::ENotReady);
  1252 	
  1253 	// Start the scheduler - Done only once !
  1254 	CActiveScheduler::Start();
  1255 	
  1256 	return iTestStepResult;
  1257 	}
  1258 
  1259 //
  1260 //CTestMmfAclntARN9005
  1261 //
  1262 
  1263 /**
  1264  * Constructor
  1265  */
  1266 CTestMmfAclntARN9005::CTestMmfAclntARN9005(const TDesC& aTestName, const TDesC& aSectName)
  1267 	: CTestMmfAclntMultiClientARN(aTestName, aSectName)
  1268 	{}
  1269 
  1270 /**
  1271  * NewL
  1272  */
  1273 CTestMmfAclntARN9005* CTestMmfAclntARN9005::NewL(const TDesC& aTestName, const TDesC& aSectName)
  1274 	{
  1275 	CTestMmfAclntARN9005* self = new (ELeave) CTestMmfAclntARN9005(aTestName, aSectName);
  1276 	return self;
  1277 	}
  1278 
  1279 /**
  1280  * DoTestL
  1281  */
  1282 TVerdict CTestMmfAclntARN9005::DoTestL()
  1283 	{
  1284 	return( PerformTestL() );
  1285 	}
  1286 
  1287 void CTestMmfAclntARN9005::InitTest()
  1288 	{
  1289 	//Keep adding handlers
  1290 	iStateHandlers[EStateApInitComplete] = &CTestMmfAclntARN9005::HandleStateApInitComplete;
  1291 	iStateHandlers[EStateRecoderOpen] = &CTestMmfAclntARN9005::HandleStateRecorderOpen;
  1292 	iStateHandlers[EStateRecoderPlaying] = &CTestMmfAclntARN9005::HandleStateRecorderPlaying;
  1293 	iStateHandlers[EStateApPlayCompleteKErrInUse] = &CTestMmfAclntARN9005::HandleApPlayCompleteKErrInUse;
  1294 	iStateHandlers[EStateAosOpenComplete] = &CTestMmfAclntARN9005::HandleStateAosOpenComplete;
  1295 	iStateHandlers[EStateAosBufferCopiedKErrInUse] = &CTestMmfAclntARN9005::HandleStateAosBufferCopiedKErrInUse;
  1296 	iStateHandlers[EStateAosPlayCompleteKErrInUse] = &CTestMmfAclntARN9005::HandleStateAosPlayCompleteKErrInUse;
  1297 	iStateHandlers[EStateRecorderrelease] = &CTestMmfAclntARN9005::HandleStateRecorderrelease;
  1298 	iStateHandlers[EStateApResourceAvailable] = &CTestMmfAclntARN9005::HandleStateApResourceAvailable;
  1299 	iStateHandlers[EStateApPlayComplete] = &CTestMmfAclntARN9005::HandleStateApPlayComplete;
  1300 	iStateHandlers[EStateAosResourceAvailable] = &CTestMmfAclntARN9005::HandleStateAosResourceAvailable;
  1301 	}
  1302 
  1303 void CTestMmfAclntARN9005::DecideFsmState(TInt aClientNumber,CMultiEventChecker::TClientUtilityType aClientType, TInt aEventCode, TInt aError,CMdaAudioClipUtility::TState aRecorderState)
  1304 	{
  1305 	if (iEventChecker->CheckFsm(aClientNumber, aClientType, aEventCode, aError,aRecorderState))
  1306 		{
  1307 		iTestStepResult = (this->*(iStateHandlers[iEventChecker->NextState()]))();
  1308  		if(iTestStepResult != EPass)
  1309  			{
  1310  			iEventChecker->StopTest();
  1311  			}
  1312 		}
  1313 	}
  1314 
  1315 void CTestMmfAclntARN9005::FsmL(TMmfAudioMultiClientEvents aEventCode, TInt aError, CMdaAudioClipUtility::TState aRecorderState)
  1316 	{
  1317 	if (aEventCode == EMapcInitComplete || aEventCode == EMapcPlayComplete || aEventCode == EMarncResourceAvailablePlayer)
  1318 		{
  1319 			DecideFsmState(0,CMultiEventChecker::EAudioPlayer,aEventCode,aError);
  1320 		}
  1321 	if (aEventCode == EMoscoStateChangeEvent || aEventCode == EMarncResourceAvailableRecorder)
  1322 		{
  1323 			DecideFsmState(1,CMultiEventChecker::EAudioRecorder,aEventCode,aError,aRecorderState);
  1324 		}
  1325 	if (aEventCode == EMaoscOpenComplete || aEventCode == EMaoscBufferCopied || aEventCode == EMaoscPlayComplete || aEventCode == EMarncResourceAvailableOS)
  1326 		{
  1327 			DecideFsmState(2,CMultiEventChecker::EAudioStream,aEventCode,aError);
  1328 		}
  1329 	}
  1330 
  1331 void CTestMmfAclntARN9005::StartTestL()
  1332 	{
  1333 	// Open iTestAudioPlayer
  1334 	iTestAudioPlayer->OpenFileL(iFilenamePlayer);
  1335 	INFO_PRINTF1(_L("iTestAudioPlayer->OpenFileL()"));
  1336 	iEventChecker->SetExpectedEvent(0,EMapcInitComplete,KErrNone);
  1337 	iEventChecker->SetExpectedState(EStateApInitComplete);
  1338 	}
  1339 	
  1340 TVerdict CTestMmfAclntARN9005::HandleStateApInitComplete()
  1341 	{
  1342 	iTestAudioPlayer->Play();
  1343 	INFO_PRINTF1(_L("iTestAudioPlayer->Play()"));
  1344 	// Open iTestAudioRecorder
  1345 	iTestAudioRecorder->OpenFileL(iFilenameRecorder);
  1346 	INFO_PRINTF1(_L("iTestAudioRecorder->OpenFileL()"));
  1347 	iEventChecker->SetExpectedEvent(1,EMoscoStateChangeEvent, KErrNone,CMdaAudioClipUtility::EOpen);
  1348 	iEventChecker->SetExpectedState(EStateRecoderOpen);
  1349 	return EPass;
  1350 	}	
  1351 
  1352 TVerdict CTestMmfAclntARN9005::HandleStateRecorderOpen()
  1353 	{
  1354 	iTestAudioRecorder->PlayL();
  1355 	INFO_PRINTF1(_L("iTestAudioRecorder->PlayL()"));
  1356 	// Set ExpectedEvent and change the State
  1357 	iEventChecker->SetExpectedEvent(1,EMoscoStateChangeEvent,KErrNone,CMdaAudioClipUtility::EPlaying);
  1358 	iEventChecker->SetExpectedState(EStateRecoderPlaying);
  1359 	return EPass;
  1360 	}
  1361 
  1362 TVerdict CTestMmfAclntARN9005::HandleStateRecorderPlaying()
  1363 	{
  1364 	iEventChecker->SetExpectedEvent(0,EMapcPlayComplete,KErrInUse);
  1365 	iEventChecker->SetExpectedState(EStateApPlayCompleteKErrInUse);
  1366 	return EPass;
  1367 	}
  1368 	
  1369 TVerdict CTestMmfAclntARN9005::HandleApPlayCompleteKErrInUse()
  1370 	{
  1371 	TInt err = iTestAudioPlayer->RegisterAudioResourceNotification(*iMdaAudioPlayerCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
  1372 	INFO_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification : Status - %d "), err);
  1373 	if( err != KErrNone )
  1374 		{
  1375 		ERR_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification - Failed with Error : %d"), err);
  1376 		iTestStepResult = EFail;
  1377 		CActiveScheduler::Stop();
  1378 		}
  1379 	// Register iTestAudioOutputStream for Notification
  1380 	err = iTestAudioOutputStream->RegisterAudioResourceNotification(*iMdaAudioOutputStreamCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
  1381 	INFO_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification : Status - %d "), err);
  1382 	if( err != KErrNone )
  1383 		{
  1384 		ERR_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification - Failed with Error : %d"), err);
  1385 		iTestStepResult = EFail;
  1386 		CActiveScheduler::Stop();
  1387 		}
  1388 	// Open iTestAudioOutputStream
  1389 	iTestAudioOutputStream->Open(NULL);
  1390 	INFO_PRINTF1(_L("iTestAudioOutputStream->Open()"));
  1391 	// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
  1392 	iEventChecker->SetExpectedEvent(2,EMaoscOpenComplete,KErrNone);
  1393 	iEventChecker->SetExpectedState(EStateAosOpenComplete);
  1394 	return EPass;
  1395 	}
  1396 
  1397 TVerdict CTestMmfAclntARN9005::HandleStateAosOpenComplete()
  1398 	{
  1399 	// iFile->Read()
  1400 	TInt err = iFile.Read(iBuf); //-synchronous
  1401 	if (err != KErrNone)
  1402 		{
  1403 		INFO_PRINTF2(_L("Error reading iFile %d"), err);
  1404 		User::Leave(err);
  1405 		}
  1406 	// iTestAudioOutputStream->WriteL()
  1407 	INFO_PRINTF1(_L("iTestAudioOutputStream->WriteL()"));
  1408 	iTestAudioOutputStream->WriteL(iBuf); //-Should get Play Error.
  1409 	// Set ExpectedEvent & ExpectedError and change the State
  1410 	iEventChecker->SetExpectedEvent(2,EMaoscBufferCopied,KErrInUse);
  1411 	iEventChecker->SetExpectedState(EStateAosBufferCopiedKErrInUse);
  1412 	return EPass;	
  1413 	}
  1414 
  1415 TVerdict CTestMmfAclntARN9005::HandleStateAosBufferCopiedKErrInUse()
  1416 	{
  1417 	iEventChecker->SetExpectedEvent(2,EMaoscPlayComplete,KErrInUse);
  1418 	iEventChecker->SetExpectedState(EStateAosPlayCompleteKErrInUse);
  1419 	return EPass;
  1420 	}
  1421 
  1422 TVerdict CTestMmfAclntARN9005::HandleStateAosPlayCompleteKErrInUse()
  1423 	{
  1424 	iEventChecker->SetExpectedEvent(1,EMoscoStateChangeEvent,KErrNone,CMdaAudioClipUtility::EOpen);
  1425 	iEventChecker->SetExpectedState(EStateRecorderrelease);
  1426 	return EPass;
  1427 	}
  1428 
  1429 TVerdict CTestMmfAclntARN9005::HandleStateRecorderrelease()
  1430 	{
  1431 	// Timer to check if Notification Event Occurs.
  1432 	iCallBackTimer->After(2000000);
  1433 	// Set ExpectedEvent and change the State
  1434 	iEventChecker->SetExpectedEvent(0,EMarncResourceAvailablePlayer,KErrNone);
  1435 	iEventChecker->SetExpectedState(EStateApResourceAvailable);
  1436 	return EPass;
  1437 	}	
  1438 	
  1439 TVerdict CTestMmfAclntARN9005::HandleStateApResourceAvailable()
  1440 	{
  1441 	iCallBackTimer->Cancel(); // in case something else stopped the AS
  1442 	INFO_PRINTF1(_L("iTestAudioPlayer->NotificationReceived"));
  1443 	TInt err = iTestAudioPlayer->WillResumePlay();
  1444 	INFO_PRINTF1(_L("iTestAudioPlayer->WillResumePlay()"));
  1445 	if( err != KErrNone )
  1446 		{
  1447 		ERR_PRINTF2(_L("iTestAudioPlayer->WillResumePlay() - Failed with Error : %d"), err);
  1448 		iTestStepResult = EFail;
  1449 		CActiveScheduler::Stop();
  1450 		return EFail;
  1451 		}
  1452 	iTestAudioPlayer->SetPosition(iPosition);
  1453 	INFO_PRINTF1(_L("iTestAudioPlayer->SetPosition()"));
  1454 	// Play iTestAudioPlayer
  1455 	iTestAudioPlayer->Play();
  1456 	// Set ExpectedEvent & ExpectedError and change the State
  1457 	iEventChecker->RegisterClientEventToMonitor(0,EMapcPlayComplete,KErrNone,EStateApPlayComplete);
  1458 	iEventChecker->RegisterClientEventToMonitor(2,EMarncResourceAvailableOS,KErrNone,EStateAosResourceAvailable);
  1459 	iEventChecker->EnableMultipleEventMonitor();
  1460 	return EPass;
  1461 	}
  1462 
  1463 TVerdict CTestMmfAclntARN9005::HandleStateApPlayComplete()
  1464 	{
  1465 	INFO_PRINTF1(_L("AudioPlayer->PlayComplete"));
  1466 	if(iEventChecker->IsMonitoringFinished())
  1467 		{
  1468 		iTestStepResult = EPass;
  1469 		iCallBackTimer->Cancel();
  1470 		iEventChecker->StopTest();
  1471 		}
  1472 	else
  1473 		{
  1474 		iEventChecker->EnableMultipleEventMonitor();
  1475 		}
  1476 	return EPass;		
  1477 	}
  1478 	
  1479 TVerdict CTestMmfAclntARN9005::HandleStateAosResourceAvailable()
  1480 	{
  1481 	INFO_PRINTF1(_L("iTestAudioOutputStream->NotificationReceived"));
  1482 	if(iEventChecker->IsMonitoringFinished())
  1483 		{
  1484 		iCallBackTimer->Cancel();
  1485 		iTestStepResult = EPass;
  1486 		iEventChecker->StopTest();
  1487 		}
  1488 	else
  1489 		{
  1490 		iEventChecker->EnableMultipleEventMonitor();
  1491 		}
  1492 	return EPass;	
  1493 	}	
  1494 	
  1495 /**
  1496  * PerformTestL
  1497  */
  1498 TVerdict CTestMmfAclntARN9005::PerformTestL()
  1499 	{
  1500 	INFO_PRINTF1(_L("Non Receipt of Notification (on calling WillResumePlay() of a notified client) of a Resource Available Event."));
  1501 	iTestStepResult = EFail;
  1502 	
  1503 	// Initialise the state variables
  1504 	InitTest();
  1505 	
  1506 	// Begin the process
  1507 	StartTestL();
  1508 	
  1509 	// Start the scheduler - Done only once !
  1510 	CActiveScheduler::Start();
  1511 	
  1512 	return iTestStepResult;
  1513 	}
  1514 
  1515 //
  1516 //CTestMmfAclntARN9006
  1517 //
  1518 
  1519 /**
  1520  * Constructor
  1521  */
  1522 CTestMmfAclntARN9006::CTestMmfAclntARN9006(const TDesC& aTestName, const TDesC& aSectName)
  1523 	: CTestMmfAclntMultiClientARN(aTestName, aSectName)
  1524 	{}
  1525 
  1526 /**
  1527  * NewL
  1528  */
  1529 CTestMmfAclntARN9006* CTestMmfAclntARN9006::NewL(const TDesC& aTestName, const TDesC& aSectName)
  1530 	{
  1531 	CTestMmfAclntARN9006* self = new (ELeave) CTestMmfAclntARN9006(aTestName, aSectName);
  1532 	return self;
  1533 	}
  1534 
  1535 /**
  1536  * DoTestL
  1537  */
  1538 TVerdict CTestMmfAclntARN9006::DoTestL()
  1539 	{
  1540 	return( PerformTestL() );
  1541 	}
  1542 
  1543 void CTestMmfAclntARN9006::DecideFsmState(TInt aClientNumber,CMultiEventChecker::TClientUtilityType aClientType, TInt aEventCode, TInt aError,CMdaAudioClipUtility::TState aRecorderState)
  1544 	{
  1545 	if (iEventChecker->CheckFsm(aClientNumber, aClientType, aEventCode, aError,aRecorderState))
  1546 		{
  1547 		iTestStepResult = (this->*(iStateHandlers[iEventChecker->NextState()]))();
  1548  		if(iTestStepResult != EPass)
  1549  			{
  1550  			iEventChecker->StopTest();
  1551  			}
  1552 		}
  1553 	}
  1554 
  1555 void CTestMmfAclntARN9006::FsmL(TMmfAudioMultiClientEvents aEventCode, TInt aError, CMdaAudioClipUtility::TState aRecorderState)
  1556 	{
  1557 	if (aEventCode == EMapcInitComplete || aEventCode == EMapcPlayComplete || aEventCode == EMarncResourceAvailablePlayer)
  1558 		{
  1559 			DecideFsmState(0,CMultiEventChecker::EAudioPlayer,aEventCode,aError);
  1560 		}
  1561 	if (aEventCode == EMoscoStateChangeEvent || aEventCode == EMarncResourceAvailableRecorder)
  1562 		{
  1563 			DecideFsmState(1,CMultiEventChecker::EAudioRecorder,aEventCode,aError,aRecorderState);
  1564 		}
  1565 	if (aEventCode == EMaoscOpenComplete || aEventCode == EMaoscBufferCopied || aEventCode == EMaoscPlayComplete || aEventCode == EMarncResourceAvailableOS)
  1566 		{
  1567 			DecideFsmState(2,CMultiEventChecker::EAudioStream,aEventCode,aError);
  1568 		}
  1569 	}
  1570 
  1571 void CTestMmfAclntARN9006::InitTest()
  1572 	{
  1573 	//Keep adding handlers
  1574 	iStateHandlers[EStateApInitComplete] = &CTestMmfAclntARN9006::HandleStateApInitComplete;
  1575 	iStateHandlers[EStateRecoderOpen] = &CTestMmfAclntARN9006::HandleStateRecorderOpen;
  1576 	iStateHandlers[EStateRecoderPlaying] = &CTestMmfAclntARN9006::HandleStateRecorderPlaying;
  1577 	iStateHandlers[EStateApPlayCompleteKErrInUse] = &CTestMmfAclntARN9006::HandleApPlayCompleteKErrInUse;
  1578 	iStateHandlers[EStateAosOpenComplete] = &CTestMmfAclntARN9006::HandleStateAosOpenComplete;
  1579 	iStateHandlers[EStateAosBufferCopiedKErrInUse] = &CTestMmfAclntARN9006::HandleStateAosBufferCopiedKErrInUse;
  1580 	iStateHandlers[EStateAosPlayCompleteKErrInUse] = &CTestMmfAclntARN9006::HandleStateAosPlayCompleteKErrInUse;
  1581 	iStateHandlers[EStateRecorderrelease] = &CTestMmfAclntARN9006::HandleStateRecorderrelease;
  1582 	iStateHandlers[EStateApResourceAvailable] = &CTestMmfAclntARN9006::HandleStateApResourceAvailable;
  1583 	iStateHandlers[EStateAosResourceAvailable] = &CTestMmfAclntARN9006::HandleStateAosResourceAvailable;
  1584 	}
  1585 	
  1586 void CTestMmfAclntARN9006::StartTestL()
  1587 	{
  1588 	// Open iTestAudioPlayer
  1589 	iTestAudioPlayer->OpenFileL(iFilenamePlayer);
  1590 	INFO_PRINTF1(_L("iTestAudioPlayer->OpenFileL()"));
  1591 	iEventChecker->SetExpectedEvent(0,EMapcInitComplete,KErrNone);
  1592 	iEventChecker->SetExpectedState(EStateApInitComplete);
  1593 	}
  1594 
  1595 TVerdict CTestMmfAclntARN9006::HandleStateApInitComplete()
  1596 	{
  1597 	iTestAudioPlayer->Play();
  1598 	INFO_PRINTF1(_L("iTestAudioPlayer->Play()"));
  1599 	// Open iTestAudioRecorder
  1600 	iTestAudioRecorder->OpenFileL(iFilenameRecorder);
  1601 	INFO_PRINTF1(_L("iTestAudioRecorder->OpenFileL()"));
  1602 	iEventChecker->SetExpectedEvent(1,EMoscoStateChangeEvent, KErrNone,CMdaAudioClipUtility::EOpen);
  1603 	iEventChecker->SetExpectedState(EStateRecoderOpen);
  1604 	return EPass;
  1605 	}
  1606 
  1607 TVerdict CTestMmfAclntARN9006::HandleStateRecorderOpen()
  1608 	{
  1609 	iTestAudioRecorder->PlayL();
  1610 	INFO_PRINTF1(_L("iTestAudioRecorder->PlayL()"));
  1611 	// Set ExpectedEvent and change the State
  1612 	iEventChecker->SetExpectedEvent(1,EMoscoStateChangeEvent,KErrNone,CMdaAudioClipUtility::EPlaying);
  1613 	iEventChecker->SetExpectedState(EStateRecoderPlaying);
  1614 	return EPass;
  1615 	}
  1616 
  1617 TVerdict CTestMmfAclntARN9006::HandleStateRecorderPlaying()
  1618 	{
  1619 	iEventChecker->SetExpectedEvent(0,EMapcPlayComplete,KErrInUse);
  1620 	iEventChecker->SetExpectedState(EStateApPlayCompleteKErrInUse);
  1621 	return EPass;
  1622 	}
  1623 
  1624 TVerdict CTestMmfAclntARN9006::HandleApPlayCompleteKErrInUse()
  1625 	{
  1626 	TInt err = iTestAudioPlayer->RegisterAudioResourceNotification(*iMdaAudioPlayerCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
  1627 	INFO_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification : Status - %d "), err);
  1628 	if( err != KErrNone )
  1629 		{
  1630 		ERR_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification - Failed with Error : %d"), err);
  1631 		iTestStepResult = EFail;
  1632 		CActiveScheduler::Stop();
  1633 		return EFail;
  1634 		}
  1635 	// Register iTestAudioOutputStream for Notification
  1636 	err = iTestAudioOutputStream->RegisterAudioResourceNotification(*iMdaAudioOutputStreamCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
  1637 	INFO_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification : Status - %d "), err);
  1638 	if( err != KErrNone )
  1639 		{
  1640 		ERR_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification - Failed with Error : %d"), err);
  1641 		iTestStepResult = EFail;
  1642 		CActiveScheduler::Stop();
  1643 		return EFail;
  1644 		}
  1645 	// Open iTestAudioOutputStream
  1646 	iTestAudioOutputStream->Open(NULL);
  1647 	INFO_PRINTF1(_L("iTestAudioOutputStream->Open()"));
  1648 	// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
  1649 	iEventChecker->SetExpectedEvent(2,EMaoscOpenComplete,KErrNone);
  1650 	iEventChecker->SetExpectedState(EStateAosOpenComplete);
  1651 	return EPass;
  1652 	}
  1653 
  1654 TVerdict CTestMmfAclntARN9006::HandleStateAosOpenComplete()
  1655 	{
  1656 	// iFile->Read()
  1657 	TInt err = iFile.Read(iBuf); //-synchronous
  1658 	if (err != KErrNone)
  1659 		{
  1660 		INFO_PRINTF2(_L("Error reading iFile %d"), err);
  1661 		User::Leave(err);
  1662 		}
  1663 	// iTestAudioOutputStream->WriteL()
  1664 	INFO_PRINTF1(_L("iTestAudioOutputStream->WriteL()"));
  1665 	iTestAudioOutputStream->WriteL(iBuf); //-Should get Play Error.
  1666 	// Set ExpectedEvent & ExpectedError and change the State
  1667 	iEventChecker->SetExpectedEvent(2,EMaoscBufferCopied,KErrInUse);
  1668 	iEventChecker->SetExpectedState(EStateAosBufferCopiedKErrInUse);
  1669 	return EPass;	
  1670 	}
  1671 
  1672 TVerdict CTestMmfAclntARN9006::HandleStateAosBufferCopiedKErrInUse()
  1673 	{
  1674 	iEventChecker->SetExpectedEvent(2,EMaoscPlayComplete,KErrInUse);
  1675 	iEventChecker->SetExpectedState(EStateAosPlayCompleteKErrInUse);
  1676 	return EPass;
  1677 	}
  1678 
  1679 TVerdict CTestMmfAclntARN9006::HandleStateAosPlayCompleteKErrInUse()
  1680 	{
  1681 	iEventChecker->SetExpectedEvent(1,EMoscoStateChangeEvent,KErrNone,CMdaAudioClipUtility::EOpen);
  1682 	iEventChecker->SetExpectedState(EStateRecorderrelease);
  1683 	return EPass;
  1684 	}
  1685 
  1686 TVerdict CTestMmfAclntARN9006::HandleStateRecorderrelease()
  1687 	{
  1688 	// Timer to check if Notification Event Occurs.
  1689 	iCallBackTimer->After(2000000);
  1690 	// Set ExpectedEvent and change the State
  1691 	iEventChecker->SetExpectedEvent(0,EMarncResourceAvailablePlayer,KErrNone);
  1692 	iEventChecker->SetExpectedState(EStateApResourceAvailable);
  1693 	return EPass;
  1694 	}
  1695 
  1696 TVerdict CTestMmfAclntARN9006::HandleStateApResourceAvailable()
  1697 	{
  1698 	iCallBackTimer->Cancel(); // in case something else stopped the AS
  1699 	INFO_PRINTF1(_L("iTestAudioPlayer->NotificationReceived"));
  1700 	TInt err = iTestAudioPlayer->WillResumePlay();
  1701 	INFO_PRINTF1(_L("iTestAudioPlayer->WillResumePlay()"));
  1702 	if( err != KErrNone )
  1703 		{
  1704 		ERR_PRINTF2(_L("iTestAudioPlayer->WillResumePlay() - Failed with Error : %d"), err);
  1705 		iTestStepResult = EFail;
  1706 		CActiveScheduler::Stop();
  1707 		return EFail;
  1708 		}
  1709 	iCallBackTimer->After(10000000);
  1710 	// Set ExpectedEvent & ExpectedError and change the State
  1711 	iEventChecker->SetExpectedEvent(2,EMarncResourceAvailableOS,KErrNone);
  1712 	iEventChecker->SetExpectedState(EStateAosResourceAvailable);
  1713 	return EPass;
  1714 	}
  1715 
  1716 TVerdict CTestMmfAclntARN9006::HandleStateAosResourceAvailable()
  1717 	{
  1718 	INFO_PRINTF1(_L("iTestAudioOutputStream->NotificationReceived"));
  1719 	iCallBackTimer->Cancel();
  1720 	iTestStepResult = EPass;
  1721 	iEventChecker->StopTest();
  1722 	return EPass;
  1723 	}
  1724 
  1725 /**
  1726  * PerformTestL
  1727  */
  1728 TVerdict CTestMmfAclntARN9006::PerformTestL()
  1729 	{
  1730 	INFO_PRINTF1(_L("Receipt of Notification (on timeout of a notified client, 1 sec assumed, call WillResumePlay() after 1 second) of a Resource Available Event."));
  1731 	iTestStepResult = EFail;
  1732 	
  1733 	// Initialise the handler functions
  1734 	InitTest();
  1735 	
  1736 	// Initiate the process
  1737 	StartTestL();
  1738 	
  1739 	// Start the scheduler - Done only once !
  1740 	CActiveScheduler::Start();
  1741 	
  1742 	return iTestStepResult;
  1743 	}
  1744 
  1745 //
  1746 //CTestMmfAclntARN9007
  1747 //
  1748 
  1749 /**
  1750  * Constructor
  1751  */
  1752 CTestMmfAclntARN9007::CTestMmfAclntARN9007(const TDesC& aTestName, const TDesC& aSectName)
  1753 	: CTestMmfAclntMultiClientARN(aTestName, aSectName)
  1754 	{}
  1755 
  1756 /**
  1757  * NewL
  1758  */
  1759 CTestMmfAclntARN9007* CTestMmfAclntARN9007::NewL(const TDesC& aTestName, const TDesC& aSectName)
  1760 	{
  1761 	CTestMmfAclntARN9007* self = new (ELeave) CTestMmfAclntARN9007(aTestName, aSectName);
  1762 	return self;
  1763 	}
  1764 
  1765 /**
  1766  * DoTestL
  1767  */
  1768 TVerdict CTestMmfAclntARN9007::DoTestL()
  1769 	{
  1770 	return( PerformTestL() );
  1771 	}
  1772 
  1773 /**
  1774  * FsmCheck
  1775  */
  1776 TBool CTestMmfAclntARN9007::FsmCheck(TMmfAudioMultiClientEvents aEventCode, TInt aError, CMdaAudioClipUtility::TState aRecorderState)
  1777 	{
  1778 	TBool retFsmCheck = EFalse;
  1779 	if ((iExpectedError !=KErrUnderflow) && (aError == KErrUnderflow))
  1780 		{
  1781 		INFO_PRINTF1(_L("Underflow !"));
  1782 		}
  1783 	else if (iExpectedEvent != aEventCode)
  1784 		{
  1785         if ((aEventCode == EMoscoStateChangeEvent))
  1786 	        {
  1787 	        retFsmCheck = ETrue;
  1788 	        if (iEventOccured == EMarncResourceAvailableOS)
  1789 	            {
  1790 	            return retFsmCheck;
  1791 	            }
  1792             else
  1793                 {
  1794                 iEventOccured = EMoscoStateChangeEvent;
  1795                 }
  1796 	        }
  1797         else if (aEventCode == EMarncResourceAvailableOS)
  1798             {
  1799             retFsmCheck = ETrue;
  1800             if (iEventOccured == EMoscoStateChangeEvent)
  1801                 {
  1802                 return retFsmCheck;
  1803                 }
  1804             else
  1805                 {
  1806                 iEventOccured = EMarncResourceAvailableOS;
  1807                 }
  1808             }
  1809         else
  1810             {
  1811     		ERR_PRINTF3(_L("ExpectedEvent : %d, ActualEvent : %d"), iExpectedEvent, aEventCode);
  1812     		iTestStepResult = EFail;
  1813     		CActiveScheduler::Stop();
  1814             }
  1815 		}
  1816 	else if (iExpectedError != aError)
  1817 		{
  1818 		ERR_PRINTF3(_L("ExpectedError : %d, ActualError : %d"), iExpectedError, aError);
  1819 		iTestStepResult = EFail;
  1820 		CActiveScheduler::Stop();
  1821 		}
  1822 	else if (iExpectedRecorderState != aRecorderState)
  1823 		{
  1824 		ERR_PRINTF3(_L("ExpectedRecorderState : %d, ActualRecorderState : %d"), iExpectedRecorderState, aRecorderState);
  1825 		iTestStepResult = EFail;
  1826 		CActiveScheduler::Stop();
  1827 		}
  1828 	else
  1829 		{
  1830 		retFsmCheck = ETrue;
  1831 		}
  1832 	return retFsmCheck;
  1833 	}
  1834 
  1835 /**
  1836  * FsmL
  1837  */
  1838 void CTestMmfAclntARN9007::FsmL(TMmfAudioMultiClientEvents aEventCode, TInt aError, CMdaAudioClipUtility::TState aRecorderState)
  1839 	{
  1840 	if (FsmCheck(aEventCode, aError, aRecorderState))
  1841 		{
  1842 		TInt err = KErrNone;
  1843 		switch (iState)
  1844 			{
  1845 			case 0:
  1846 				// Open iTestAudioPlayer
  1847 				iTestAudioPlayer->OpenFileL(iFilenamePlayer);
  1848 				INFO_PRINTF1(_L("iTestAudioPlayer->OpenFileL()"));
  1849 				// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
  1850 				StateChange(EMapcInitComplete);
  1851 				break;
  1852 			case 1:
  1853 				// Play iTestAudioPlayer
  1854 				iTestAudioPlayer->Play();
  1855 				INFO_PRINTF1(_L("iTestAudioPlayer->Play()"));
  1856 				// Open iTestAudioRecorder
  1857 				iTestAudioRecorder->OpenFileL(iFilenameRecorder);
  1858 				INFO_PRINTF1(_L("iTestAudioRecorder->OpenFileL()"));
  1859 				// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
  1860 				StateChange(EMoscoStateChangeEvent, KErrNone, CMdaAudioClipUtility::EOpen);
  1861 				break;
  1862 			case 2:
  1863 				// Play iTestAudioRecorder
  1864 				iTestAudioRecorder->PlayL();
  1865 				INFO_PRINTF1(_L("iTestAudioRecorder->PlayL()"));
  1866 				// Set ExpectedEvent and change the State
  1867 				StateChange(EMoscoStateChangeEvent, KErrNone, CMdaAudioClipUtility::EPlaying);
  1868 				break;
  1869 			case 3:
  1870 				// iTestAudioPlayer gets PlayError.
  1871 				StateChange(EMapcPlayComplete, KErrInUse);
  1872 				break;
  1873 			case 4:
  1874 				// Register iTestAudioPlayer for Notification
  1875 				err = iTestAudioPlayer->RegisterAudioResourceNotification(*iMdaAudioPlayerCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
  1876 				INFO_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification : Status - %d "), err);
  1877 				if( err != KErrNone )
  1878 					{
  1879 					ERR_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification - Failed with Error : %d"), err);
  1880 					iTestStepResult = EFail;
  1881 					CActiveScheduler::Stop();
  1882 					break;
  1883 					}
  1884 				// Register iTestAudioOutputStream for Notification
  1885 				err = iTestAudioOutputStream->RegisterAudioResourceNotification(*iMdaAudioOutputStreamCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
  1886 				INFO_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification : Status - %d "), err);
  1887 				if( err != KErrNone )
  1888 					{
  1889 					ERR_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification - Failed with Error : %d"), err);
  1890 					iTestStepResult = EFail;
  1891 					CActiveScheduler::Stop();
  1892 					break;
  1893 					}
  1894 				// Open iTestAudioOutputStream
  1895 				iTestAudioOutputStream->Open(NULL);
  1896 				INFO_PRINTF1(_L("iTestAudioOutputStream->Open()"));
  1897 				// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
  1898 				StateChange(EMaoscOpenComplete);
  1899 				break;
  1900 			case 5:
  1901 				// iFile->Read()
  1902 				err = iFile.Read(iBuf); //-synchronous
  1903 				if (err != KErrNone)
  1904 					{
  1905 					INFO_PRINTF2(_L("Error reading iFile %d"), err);
  1906 					User::Leave(err);
  1907 					}
  1908 				// iTestAudioOutputStream->WriteL()
  1909 				INFO_PRINTF1(_L("iTestAudioOutputStream->WriteL()"));
  1910 				iTestAudioOutputStream->WriteL(iBuf); //-Should get Play Error.
  1911 				// Set ExpectedEvent & ExpectedError and change the State
  1912 				StateChange(EMaoscBufferCopied, KErrInUse);
  1913 				break;
  1914 			case 6:
  1915 				// Set ExpectedEvent & ExpectedError and change the State
  1916 				StateChange(EMaoscPlayComplete, KErrInUse);
  1917 				break;
  1918 			case 7:
  1919 				// Cancel the Notification request for iTestAudioPlayer
  1920 				err = iTestAudioPlayer->CancelRegisterAudioResourceNotification(KMMFEventCategoryAudioResourceAvailable);
  1921 				INFO_PRINTF2(_L("iTestAudioPlayer->CancelRegisterAudioResourceNotification : Return Code = %d"), err);
  1922 				if( err != KErrNone )
  1923 					{
  1924 					ERR_PRINTF2(_L("iTestAudioPlayer->CancelRegisterAudioResourceNotification - Failed with Error : %d"), err);
  1925 					iTestStepResult = EFail;
  1926 					CActiveScheduler::Stop();
  1927 					break;
  1928 					}
  1929 				// Wait for iTestAudioRecorder to complete playing
  1930 				// Set ExpectedEvent and change the State
  1931 				StateChange(EMoscoStateChangeEvent, KErrNone, CMdaAudioClipUtility::EOpen);
  1932 				break;
  1933 			case 8:
  1934 				// Timer to check if Notification Event Occurs.
  1935 				iCallBackTimer->After(2000000);
  1936 				// Set ExpectedEvent and change the State
  1937 				StateChange(EMarncResourceAvailableOS);
  1938 				break;
  1939 			case 9:
  1940 				iCallBackTimer->Cancel(); // in case something else stopped the AS
  1941 				INFO_PRINTF1(_L("iTestAudioOutputStream->NotificationReceived"));
  1942 				iTestStepResult = EPass;
  1943 				CActiveScheduler::Stop();
  1944 				break;
  1945 			}
  1946 		}
  1947 	}
  1948 
  1949 /**
  1950  * PerformTestL
  1951  */
  1952 TVerdict CTestMmfAclntARN9007::PerformTestL()
  1953 	{
  1954 	INFO_PRINTF1(_L("Receipt of Notification (on cancellation of the notification of a client that has requested for notification) of a Resource Available Event."));
  1955 	INFO_PRINTF1(_L("[Cancel before receipt of Notification]"));
  1956 	iTestStepResult = EFail;
  1957 	
  1958 	// Initialise the state variables
  1959 	StateInit();
  1960 	
  1961 	// Begin the process
  1962 	FsmL(EIdleMulti, CMdaAudioClipUtility::ENotReady);
  1963 	
  1964 	// Start the scheduler - Done only once !
  1965 	CActiveScheduler::Start();
  1966 	
  1967 	return iTestStepResult;
  1968 	}
  1969 
  1970 //
  1971 //CTestMmfAclntARN9008
  1972 //
  1973 
  1974 /**
  1975  * Constructor
  1976  */
  1977 CTestMmfAclntARN9008::CTestMmfAclntARN9008(const TDesC& aTestName, const TDesC& aSectName)
  1978 	: CTestMmfAclntMultiClientARN(aTestName, aSectName)
  1979 	{}
  1980 
  1981 /**
  1982  * NewL
  1983  */
  1984 CTestMmfAclntARN9008* CTestMmfAclntARN9008::NewL(const TDesC& aTestName, const TDesC& aSectName)
  1985 	{
  1986 	CTestMmfAclntARN9008* self = new (ELeave) CTestMmfAclntARN9008(aTestName, aSectName);
  1987 	return self;
  1988 	}
  1989 
  1990 /**
  1991  * DoTestL
  1992  */
  1993 TVerdict CTestMmfAclntARN9008::DoTestL()
  1994 	{
  1995 	return( PerformTestL() );
  1996 	}
  1997 
  1998 void CTestMmfAclntARN9008::DecideFsmState(TInt aClientNumber,CMultiEventChecker::TClientUtilityType aClientType, TInt aEventCode, TInt aError,CMdaAudioClipUtility::TState aRecorderState)
  1999 	{
  2000 	if (iEventChecker->CheckFsm(aClientNumber, aClientType, aEventCode, aError,aRecorderState))
  2001 		{
  2002 		iTestStepResult = (this->*(iStateHandlers[iEventChecker->NextState()]))();
  2003  		if(iTestStepResult != EPass)
  2004  			{
  2005  			iEventChecker->StopTest();
  2006  			}
  2007 		}
  2008 	}
  2009 
  2010 void CTestMmfAclntARN9008::FsmL(TMmfAudioMultiClientEvents aEventCode, TInt aError, CMdaAudioClipUtility::TState aRecorderState)
  2011 	{
  2012 	if (aEventCode == EMapcInitComplete || aEventCode == EMapcPlayComplete || aEventCode == EMarncResourceAvailablePlayer)
  2013 		{
  2014 			DecideFsmState(0,CMultiEventChecker::EAudioPlayer,aEventCode,aError);
  2015 		}
  2016 	if (aEventCode == EMoscoStateChangeEvent || aEventCode == EMarncResourceAvailableRecorder)
  2017 		{
  2018 			DecideFsmState(1,CMultiEventChecker::EAudioRecorder,aEventCode,aError,aRecorderState);
  2019 		}
  2020 	if (aEventCode == EMaoscOpenComplete || aEventCode == EMaoscBufferCopied || aEventCode == EMaoscPlayComplete || aEventCode == EMarncResourceAvailableOS)
  2021 		{
  2022 			DecideFsmState(2,CMultiEventChecker::EAudioStream,aEventCode,aError);
  2023 		}
  2024 	}
  2025 
  2026 void CTestMmfAclntARN9008::InitTest()
  2027 	{
  2028 	//Keep adding handlers
  2029 	iStateHandlers[EStateApInitComplete] = &CTestMmfAclntARN9008::HandleStateApInitComplete;
  2030 	iStateHandlers[EStateRecoderOpen] = &CTestMmfAclntARN9008::HandleStateRecorderOpen;
  2031 	iStateHandlers[EStateRecoderPlaying] = &CTestMmfAclntARN9008::HandleStateRecorderPlaying;
  2032 	iStateHandlers[EStateApPlayCompleteKErrInUse] = &CTestMmfAclntARN9008::HandleApPlayCompleteKErrInUse;
  2033 	iStateHandlers[EStateAosOpenComplete] = &CTestMmfAclntARN9008::HandleStateAosOpenComplete;
  2034 	iStateHandlers[EStateAosBufferCopiedKErrInUse] = &CTestMmfAclntARN9008::HandleStateAosBufferCopiedKErrInUse;
  2035 	iStateHandlers[EStateAosPlayCompleteKErrInUse] = &CTestMmfAclntARN9008::HandleStateAosPlayCompleteKErrInUse;
  2036 	iStateHandlers[EStateRecorderrelease] = &CTestMmfAclntARN9008::HandleStateRecorderrelease;
  2037 	iStateHandlers[EStateApResourceAvailable] = &CTestMmfAclntARN9008::HandleStateApResourceAvailable;
  2038 	iStateHandlers[EStateApPlayComplete] = &CTestMmfAclntARN9008::HandleStateApPlayComplete;
  2039 	iStateHandlers[EStateAosResourceAvailable] = &CTestMmfAclntARN9008::HandleStateAosResourceAvailable;
  2040 	iStateHandlers[EStateRecorderResumePlay] = &CTestMmfAclntARN9008::HandleStateRecorderResumePlay;
  2041 	iStateHandlers[EStateRecorderPlayComplete]= &CTestMmfAclntARN9008::HandleStateRecorderPlayComplete;
  2042 	}
  2043 	
  2044 void CTestMmfAclntARN9008::StartTestL()
  2045 	{
  2046 	// Open iTestAudioPlayer
  2047 	iTestAudioPlayer->OpenFileL(iFilenamePlayer);
  2048 	INFO_PRINTF1(_L("iTestAudioPlayer->OpenFileL()"));
  2049 	iEventChecker->SetExpectedEvent(0,EMapcInitComplete,KErrNone);
  2050 	iEventChecker->SetExpectedState(EStateApInitComplete);
  2051 	}
  2052 	
  2053 TVerdict CTestMmfAclntARN9008::HandleStateApInitComplete()
  2054 	{
  2055 	iTestAudioPlayer->Play();
  2056 	INFO_PRINTF1(_L("iTestAudioPlayer->Play()"));
  2057 	// Open iTestAudioRecorder
  2058 	iTestAudioRecorder->OpenFileL(iFilenameRecorder);
  2059 	INFO_PRINTF1(_L("iTestAudioRecorder->OpenFileL()"));
  2060 	iEventChecker->SetExpectedEvent(1,EMoscoStateChangeEvent, KErrNone,CMdaAudioClipUtility::EOpen);
  2061 	iEventChecker->SetExpectedState(EStateRecoderOpen);
  2062 	return EPass;
  2063 	}
  2064 
  2065 TVerdict CTestMmfAclntARN9008::HandleStateRecorderOpen()
  2066 	{
  2067 	iTestAudioRecorder->PlayL();
  2068 	INFO_PRINTF1(_L("iTestAudioRecorder->PlayL()"));
  2069 	// Set ExpectedEvent and change the State
  2070 	iEventChecker->SetExpectedEvent(1,EMoscoStateChangeEvent,KErrNone,CMdaAudioClipUtility::EPlaying);
  2071 	iEventChecker->SetExpectedState(EStateRecoderPlaying);
  2072 	return EPass;
  2073 	}
  2074 
  2075 TVerdict CTestMmfAclntARN9008::HandleStateRecorderPlaying()
  2076 	{
  2077 	iEventChecker->SetExpectedEvent(0,EMapcPlayComplete,KErrInUse);
  2078 	iEventChecker->SetExpectedState(EStateApPlayCompleteKErrInUse);
  2079 	return EPass;
  2080 	}
  2081 
  2082 TVerdict CTestMmfAclntARN9008::HandleApPlayCompleteKErrInUse()
  2083 	{
  2084 	TInt err = iTestAudioPlayer->RegisterAudioResourceNotification(*iMdaAudioPlayerCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
  2085 	INFO_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification : Status - %d "), err);
  2086 	if( err != KErrNone )
  2087 		{
  2088 		ERR_PRINTF2(_L("iTestAudioPlayer->RegisterAudioResourceNotification - Failed with Error : %d"), err);
  2089 		iTestStepResult = EFail;
  2090 		CActiveScheduler::Stop();
  2091 		}
  2092 	// Register iTestAudioOutputStream for Notification
  2093 	err = iTestAudioOutputStream->RegisterAudioResourceNotification(*iMdaAudioOutputStreamCallbackSupport, KMMFEventCategoryAudioResourceAvailable);
  2094 	INFO_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification : Status - %d "), err);
  2095 	if( err != KErrNone )
  2096 		{
  2097 		ERR_PRINTF2(_L("iTestAudioOutputStream->RegisterAudioResourceNotification - Failed with Error : %d"), err);
  2098 		iTestStepResult = EFail;
  2099 		CActiveScheduler::Stop();
  2100 		}
  2101 	// Open iTestAudioOutputStream
  2102 	iTestAudioOutputStream->Open(NULL);
  2103 	INFO_PRINTF1(_L("iTestAudioOutputStream->Open()"));
  2104 	// Set ExpectedEvent, ExpectedError, ExpectedRecorderState and change the State
  2105 	iEventChecker->SetExpectedEvent(2,EMaoscOpenComplete,KErrNone);
  2106 	iEventChecker->SetExpectedState(EStateAosOpenComplete);
  2107 	return EPass;
  2108 	}
  2109 	
  2110 TVerdict CTestMmfAclntARN9008::HandleStateAosOpenComplete()
  2111 	{
  2112 	// iFile->Read()
  2113 	TInt err = iFile.Read(iBuf); //-synchronous
  2114 	if (err != KErrNone)
  2115 		{
  2116 		INFO_PRINTF2(_L("Error reading iFile %d"), err);
  2117 		User::Leave(err);
  2118 		}
  2119 	// iTestAudioOutputStream->WriteL()
  2120 	INFO_PRINTF1(_L("iTestAudioOutputStream->WriteL()"));
  2121 	iTestAudioOutputStream->WriteL(iBuf); //-Should get Play Error.
  2122 	// Set ExpectedEvent & ExpectedError and change the State
  2123 	iEventChecker->SetExpectedEvent(2,EMaoscBufferCopied,KErrInUse);
  2124 	iEventChecker->SetExpectedState(EStateAosBufferCopiedKErrInUse);
  2125 	return EPass;	
  2126 	}
  2127 
  2128 TVerdict CTestMmfAclntARN9008::HandleStateAosBufferCopiedKErrInUse()
  2129 	{
  2130 	iEventChecker->SetExpectedEvent(2,EMaoscPlayComplete,KErrInUse);
  2131 	iEventChecker->SetExpectedState(EStateAosPlayCompleteKErrInUse);
  2132 	return EPass;
  2133 	}
  2134 	
  2135 TVerdict CTestMmfAclntARN9008::HandleStateAosPlayCompleteKErrInUse()
  2136 	{
  2137 	iEventChecker->SetExpectedEvent(1,EMoscoStateChangeEvent,KErrNone,CMdaAudioClipUtility::EOpen);
  2138 	iEventChecker->SetExpectedState(EStateRecorderrelease);
  2139 	return EPass;
  2140 	}
  2141 
  2142 TVerdict CTestMmfAclntARN9008::HandleStateRecorderrelease()
  2143 	{
  2144 	// Set ExpectedEvent and change the State
  2145 	iEventChecker->SetExpectedEvent(0,EMarncResourceAvailablePlayer,KErrNone);
  2146 	iEventChecker->SetExpectedState(EStateApResourceAvailable);
  2147 	return EPass;
  2148 	}
  2149 
  2150 TVerdict CTestMmfAclntARN9008::HandleStateApResourceAvailable()
  2151 	{
  2152 	// iTestAudioPlayer resumes the playback.
  2153 	iTestAudioPlayer->SetPosition(iPosition);
  2154 	INFO_PRINTF1(_L("iTestAudioPlayer->SetPosition()"));
  2155 	iTestAudioPlayer->Play();
  2156 	INFO_PRINTF1(_L("iTestAudioPlayer->Play()"));
  2157 	// Cancel the Notification request for iTestAudioPlayer
  2158 	TInt err = iTestAudioPlayer->CancelRegisterAudioResourceNotification(KMMFEventCategoryAudioResourceAvailable);
  2159 	INFO_PRINTF2(_L("iTestAudioPlayer->CancelRegisterAudioResourceNotification : Return Code = %d"), err);
  2160 	if( err != KErrNone )
  2161 		{
  2162 		ERR_PRINTF2(_L("iTestAudioPlayer->CancelRegisterAudioResourceNotification - Failed with Error : %d"), err);
  2163 		iTestStepResult = EFail;
  2164 		CActiveScheduler::Stop();
  2165 		return EFail;
  2166 		}
  2167 	// Play iTestAudioRecorder
  2168 	iTestAudioRecorder->PlayL();
  2169 	INFO_PRINTF1(_L("iTestAudioRecorder->PlayL()"));
  2170 	// Set ExpectedEvent and change the State
  2171 	iEventChecker->SetExpectedEvent(1,EMoscoStateChangeEvent,KErrNone,CMdaAudioClipUtility::EPlaying);
  2172 	iEventChecker->SetExpectedState(EStateRecorderResumePlay);
  2173 	return EPass;
  2174 	}
  2175 TVerdict CTestMmfAclntARN9008::HandleStateRecorderResumePlay()
  2176 	{
  2177 	iEventChecker->RegisterClientEventToMonitor(0,EMapcPlayComplete,KErrInUse,EStateApPlayComplete);
  2178 	iEventChecker->RegisterClientEventToMonitor(2,EMarncResourceAvailableOS,KErrNone,EStateAosResourceAvailable);
  2179 	iEventChecker->EnableMultipleEventMonitor();
  2180 	return EPass;
  2181 	}
  2182 TVerdict CTestMmfAclntARN9008::HandleStateApPlayComplete()
  2183 	{
  2184 	INFO_PRINTF1(_L("AudioPlayer->PlayComplete"));
  2185 	if(iEventChecker->IsMonitoringFinished())
  2186 		{
  2187 		iEventChecker->SetExpectedEvent(1,EMoscoStateChangeEvent, KErrNone, CMdaAudioClipUtility::EOpen);
  2188 		iEventChecker->SetExpectedState(EStateRecorderPlayComplete);
  2189 		}
  2190 	else
  2191 		{
  2192 		iEventChecker->EnableMultipleEventMonitor();
  2193 		}
  2194 	return EPass;		
  2195 	}
  2196 
  2197 TVerdict CTestMmfAclntARN9008::HandleStateAosResourceAvailable()
  2198 	{
  2199 	INFO_PRINTF1(_L("AudioPlayer->PlayComplete"));
  2200 	if(iEventChecker->IsMonitoringFinished())
  2201 		{
  2202 		iEventChecker->SetExpectedEvent(1,EMoscoStateChangeEvent, KErrNone, CMdaAudioClipUtility::EOpen);
  2203 		iEventChecker->SetExpectedState(EStateRecorderPlayComplete);
  2204 		}
  2205 	else
  2206 		{
  2207 		iEventChecker->EnableMultipleEventMonitor();
  2208 		}
  2209 	return EPass;	
  2210 	}
  2211 
  2212 TVerdict CTestMmfAclntARN9008::HandleStateRecorderPlayComplete()
  2213 	{
  2214 	INFO_PRINTF1(_L("AudioRecorder->Complete"));
  2215 	iEventChecker->StopTest();
  2216 	return EPass;
  2217 	}
  2218 
  2219 TVerdict CTestMmfAclntARN9008::PerformTestL()
  2220 	{
  2221 	INFO_PRINTF1(_L("Receipt of Notification (on cancellation of notification of a client that has just received notification) of a Resource Available Event."));
  2222 	INFO_PRINTF1(_L("[Cancel after receipt of Notification]"));
  2223 	iTestStepResult = EFail;
  2224 		
  2225 	// Initialise the handler functions
  2226 	InitTest();
  2227 	
  2228 	// Initiate the process
  2229 	StartTestL();
  2230 	
  2231 	// Start the scheduler - Done only once !
  2232 	CActiveScheduler::Start();
  2233 	
  2234 	return iTestStepResult;
  2235 	}
  2236 
  2237 CMultiEventChecker* CMultiEventChecker::NewL()
  2238 	{
  2239 	CMultiEventChecker* s = new(ELeave) CMultiEventChecker();
  2240 	CleanupStack::PushL(s);
  2241 	s->ConstructL();
  2242 	CleanupStack::Pop();
  2243 	return s;
  2244 	}
  2245 
  2246 CMultiEventChecker::CMultiEventChecker()
  2247 	{		
  2248 	}
  2249 	
  2250 void CMultiEventChecker::ConstructL()
  2251 	{
  2252 	iExpectedRecorderState = CMdaAudioClipUtility::ENotReady;	
  2253 	iMonitorMultipleEvents = EFalse;
  2254 	}
  2255 
  2256 void CMultiEventChecker::SetExpectedState(TInt aState)
  2257 	{
  2258 	iNextState = aState;
  2259 	}
  2260 	
  2261 void CMultiEventChecker::StopTest()
  2262 	{ 
  2263 	CActiveScheduler::Stop();
  2264 	}
  2265 
  2266 void CMultiEventChecker::SetExpectedEvent(TInt aClientNumber, TInt aExpectedEvent, TInt aExpectedError,CMdaAudioClipUtility::TState aRecorderState)
  2267 	{
  2268 	iClientEventsToMonitor[aClientNumber]= aExpectedEvent;
  2269 	iClientError[aClientNumber] = aExpectedError;
  2270 	iExpectedRecorderState = aRecorderState;
  2271 	}
  2272 	
  2273 void CMultiEventChecker::RegisterClientEventToMonitor(TInt aClientNumber, TInt aEventCode, TInt aError, TInt aFsmState,CMdaAudioClipUtility::TState aRecorderState)
  2274 	{
  2275 	iClientsRegistered++;
  2276 	iClientEventsToMonitor[aClientNumber] = aEventCode;
  2277 	iClientError[aClientNumber] = aError;
  2278 	iFsmStateforClient[aClientNumber] = aFsmState;
  2279 	iExpectedRecorderState = aRecorderState;
  2280 	}
  2281 
  2282 TBool CMultiEventChecker::IsMonitoringFinished()
  2283 	{
  2284 	 if(iClientsRegistered == 0)
  2285 	 	{
  2286 	 	return ETrue;
  2287 	 	}
  2288 	 else
  2289 	 	{
  2290 	 	return EFalse;
  2291 	 	}
  2292 	}
  2293 	
  2294 TBool CMultiEventChecker::CheckFsm(TInt aClientNumber,TClientUtilityType aClientType, TInt aEventCode, TInt aError,CMdaAudioClipUtility::TState aRecorderState)
  2295 	{
  2296 	TBool retFsmCheck = ETrue;
  2297 	if (iMonitorMultipleEvents)
  2298 		{
  2299 		if(iClientEventsToMonitor[aClientNumber] == aEventCode && iClientError[aClientNumber] == aError )
  2300 			{
  2301 			SetExpectedState(iFsmStateforClient[aClientNumber]);
  2302 			}
  2303 		else
  2304 			{
  2305 			retFsmCheck = EFalse;
  2306 			}
  2307 		
  2308 		if(retFsmCheck)
  2309 			{
  2310 			//Client event has finished
  2311 			iClientsRegistered--;
  2312 			}
  2313 		iMonitorMultipleEvents = EFalse;
  2314 		}
  2315 	else
  2316 		{
  2317 		if(iClientEventsToMonitor[aClientNumber] != aEventCode)
  2318 			{
  2319 			retFsmCheck = EFalse;
  2320 			}
  2321 		else if(iClientError[aClientNumber] != aError)
  2322 			{
  2323 			retFsmCheck = EFalse;
  2324 			} 
  2325 		else if (aClientType == EAudioRecorder)
  2326 			{
  2327 			if (iExpectedRecorderState != aRecorderState)
  2328 				{
  2329 				retFsmCheck = EFalse;		
  2330 				}
  2331 			}
  2332 		}
  2333 	return retFsmCheck;
  2334 	}