os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/Ctlfrm/TSI_MmfCtlfrm.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // TSIMmfCtlfrm.cpp
    15 // 
    16 //
    17 
    18 // EPOC includes
    19 #include <e32base.h>
    20 
    21 // Test system includes
    22 #include <testframework.h>
    23 #include "TSI_MmfCtlfrm.h"
    24 #include "TSI_MmfCtlfrmStep.h"
    25 #include "TSI_MmfCtlfrmSuite.h"
    26 #include "TSI_MmfCodes.h"
    27 #include "TSI_MmfEventIds.h"
    28 #include "ActrlTestUids.h"
    29 
    30 #include <mmf/common/mmfcontroller.h>
    31 #include <mmf/common/mmfstandardcustomcommands.h>
    32 #include <mmf/plugin/mmfcontrollerimplementationuids.hrh>
    33 
    34 const TUid KTestControllerUid = {KTSIMmfControllerUid};
    35 const TUid KTestDataSourceUid = {KTSIMmfDataSourceUid};
    36 const TUid KTestDataSinkUid   = {KTSIMmfDataSinkUid};
    37 
    38 // audio controllers, from mmfControllerImplementationUIDs.hrh
    39 const TUid KTestAudioControllerUid = {KMmfUidControllerAudio};
    40 
    41 // pause length for repeat calls to GetPosition
    42 // NB this can't be a const - global uninitialised data in ARM
    43 #define KGetPositionIntervalLength 500000
    44 
    45 // ---------------------------
    46 // RTestMmfCtlfrmI0001
    47 //
    48 // Load each controller plugin into its own thread
    49 //
    50 // REQ172.3.1
    51 
    52 RTestMmfCtlfrmI0001* RTestMmfCtlfrmI0001::NewL()
    53 	{
    54 	RTestMmfCtlfrmI0001* self = new(ELeave) RTestMmfCtlfrmI0001;
    55 	return self;
    56 	}
    57 
    58 RTestMmfCtlfrmI0001::RTestMmfCtlfrmI0001()
    59 	{
    60 	iTestStepName = _L("MM-MMF-CTLFRM-I-0001");
    61 	}
    62 
    63 
    64 TVerdict RTestMmfCtlfrmI0001::DoTestStepL()
    65 	{
    66 
    67 	TMMFPrioritySettings settings;
    68 	TInt error = KErrNone;
    69 	RMMFController controller, controller2;
    70 
    71 	settings.iPriority = ETSIMmfPriorityLow;
    72 	settings.iPref = EMdaPriorityPreferenceTime;
    73 	settings.iState = EMMFStateIdle;
    74 
    75 	// Open a controller
    76 	error = controller.Open(KTestControllerUid, settings);
    77 	if (error)
    78 		{
    79 		ERR_PRINTF2(_L("controller1 failed to open, error %d"), error);
    80 		return iTestStepResult = EInconclusive;
    81 		}
    82 
    83 	// Open another controller 
    84 	// (it is valid for this test to open two instances of the same controller)
    85 	error = controller2.Open(KTestControllerUid, settings);
    86 		if (error)
    87 		{
    88 		ERR_PRINTF2(_L("controller2 failed to open, error %d"), error);
    89 		controller.Close();
    90 		return iTestStepResult = EInconclusive;
    91 		}
    92 
    93 	TBuf8<KTextBufLen> memFunctionText;
    94 	TUid uid = {KTSIMmfControllerUid};
    95 	TMMFMessageDestination handleInfo(uid);
    96 	TMMFMessageDestinationPckg messageDest(handleInfo);
    97 	TBuf<KTextBufLen> memFunctionText16;
    98 	TBuf<KTextBufLen> memFunction2Text16;
    99 
   100 	// get thread addresses
   101 	error = controller.CustomCommandSync(messageDest, KThreadIdFunction, KNullDesC8, KNullDesC8, memFunctionText);
   102 	if (error)
   103 		{
   104 		ERR_PRINTF2(_L("controller1 CustomCommandSync failed with error %d"), error);
   105 		controller2.Close();
   106 		controller.Close();
   107 		return iTestStepResult = EInconclusive;
   108 		}
   109 
   110 	// memFunctionText comes back as hex string
   111 	memFunctionText16.SetMax();
   112 	memFunctionText16.Fill(0x0);
   113 	memFunctionText16.Copy(memFunctionText);
   114 	INFO_PRINTF2(_L("Controller1 thread ID : 0x%S"), &memFunctionText16);
   115 
   116 	error = controller2.CustomCommandSync(messageDest, KThreadIdFunction, KNullDesC8, KNullDesC8, memFunctionText);
   117 	if (error)
   118 		{
   119 		ERR_PRINTF2(_L("controller2 CustomCommandSync failed with error %d"), error);
   120 		controller2.Close();
   121 		controller.Close();
   122 		return iTestStepResult = EInconclusive;
   123 		}
   124 
   125 	// memFunctionText comes back as hex string
   126 	memFunction2Text16.SetMax();
   127 	memFunction2Text16.Fill(0x0);
   128 	memFunction2Text16.Copy(memFunctionText);
   129 	INFO_PRINTF2(_L("Controller2 thread ID : 0x%S"), &memFunction2Text16);
   130 
   131 	// compare thread addresses; they must not match
   132 	if(!memFunctionText16.Compare(memFunction2Text16))
   133 		{
   134 		ERR_PRINTF1(_L("Error - thread IDs match"));
   135 		controller2.Close();
   136 		controller.Close();
   137 		return iTestStepResult = EFail;
   138 		}
   139 	
   140 	controller2.Close();
   141 	controller.Close();
   142 	return iTestStepResult = EPass;
   143 	}
   144 
   145 // ---------------------------
   146 // RTestMmfCtlfrmI0002
   147 //
   148 // Give each controller thread its own heap
   149 //
   150 // REQ172.3.2
   151 
   152 RTestMmfCtlfrmI0002* RTestMmfCtlfrmI0002::NewL()
   153 	{
   154 	RTestMmfCtlfrmI0002* self = new(ELeave) RTestMmfCtlfrmI0002;
   155 	return self;
   156 	}
   157 
   158 RTestMmfCtlfrmI0002::RTestMmfCtlfrmI0002()
   159 	{
   160 	iTestStepName = _L("MM-MMF-CTLFRM-I-0002");
   161 	}
   162 
   163 
   164 TVerdict RTestMmfCtlfrmI0002::DoTestStepL()
   165 	{
   166 	TMMFPrioritySettings settings;
   167 	TInt error = KErrNone;
   168 	RMMFController controller, controller2;
   169 
   170 	settings.iPriority = ETSIMmfPriorityLow;
   171 	settings.iPref = EMdaPriorityPreferenceTime;
   172 	settings.iState = EMMFStateIdle;
   173 
   174 	// Open a controller
   175 	error = controller.Open(KTestControllerUid, settings);
   176 	if (error)
   177 		{
   178 		ERR_PRINTF2(_L("controller1 failed to open, error %d"), error);
   179 		return iTestStepResult = EInconclusive;
   180 		}
   181 
   182 	// Open another controller 
   183 	// (it is valid for this test to open two instances of the same controller)
   184 	error = controller2.Open(KTestControllerUid, settings);
   185 		if (error)
   186 		{
   187 		ERR_PRINTF2(_L("controller2 failed to open, error %d"), error);
   188 		controller.Close();
   189 		return iTestStepResult = EInconclusive;
   190 		}
   191 
   192 	TBuf8<KTextBufLen> memFunctionText;
   193 	TUid uid = {KTSIMmfControllerUid};
   194 	TMMFMessageDestination handleInfo(uid);
   195 	TMMFMessageDestinationPckg messageDest(handleInfo);
   196 	TBuf<KTextBufLen> memFunctionText16;
   197 	TBuf<KTextBufLen> memFunction2Text16;
   198 
   199 	// get heap addresses
   200 	error = controller.CustomCommandSync(messageDest, KHeapAddressFunction, KNullDesC8, KNullDesC8, memFunctionText);
   201 	if (error)
   202 		{
   203 		ERR_PRINTF2(_L("controller1 CustomCommandSync failed with error %d"), error);
   204 		controller2.Close();
   205 		controller.Close();
   206 		return iTestStepResult = EInconclusive;
   207 		}
   208 
   209 	// memFunctionText comes back as hex string
   210 	memFunctionText16.SetMax();
   211 	memFunctionText16.Fill(0x0);
   212 	memFunctionText16.Copy(memFunctionText);
   213 	INFO_PRINTF2(_L("Controller1 heap address : 0x%S"), &memFunctionText16);
   214 
   215 	error = controller2.CustomCommandSync(messageDest, KHeapAddressFunction, KNullDesC8, KNullDesC8, memFunctionText);
   216 	if (error)
   217 		{
   218 		ERR_PRINTF2(_L("controller2 CustomCommandSync failed with error %d"), error);
   219 		controller2.Close();
   220 		controller.Close();
   221 		return iTestStepResult = EInconclusive;
   222 		}
   223 
   224 	// memFunctionText comes back as hex string
   225 	memFunction2Text16.SetMax();
   226 	memFunction2Text16.Fill(0x0);
   227 	memFunction2Text16.Copy(memFunctionText);
   228 	INFO_PRINTF2(_L("Controller2 heap address : 0x%S"), &memFunction2Text16);
   229 
   230 	// compare heap addresses; they must not match
   231 	if(!memFunctionText16.Compare(memFunction2Text16))
   232 		{
   233 		ERR_PRINTF1(_L("Error - heap addresses match"));
   234 		controller2.Close();
   235 		controller.Close();
   236 		return iTestStepResult = EFail;
   237 		}
   238 
   239 	// cleanup
   240 	controller2.Close();
   241 	controller.Close();
   242 
   243 	return iTestStepResult = EPass;
   244 	}
   245 
   246 // ---------------------------
   247 // RTestMmfCtlfrmI0003
   248 //
   249 // Provide inter-thread access from client to controller plugin
   250 //
   251 // REQ172.3.3
   252 
   253 RTestMmfCtlfrmI0003* RTestMmfCtlfrmI0003::NewL()
   254 	{
   255 	RTestMmfCtlfrmI0003* self = new(ELeave) RTestMmfCtlfrmI0003;
   256 	return self;
   257 	}
   258 
   259 RTestMmfCtlfrmI0003::RTestMmfCtlfrmI0003()
   260 	{
   261 	iTestStepName = _L("MM-MMF-CTLFRM-I-0003");
   262 	}
   263 
   264 TVerdict RTestMmfCtlfrmI0003::DoTestStepL()
   265 	{
   266 	TMMFPrioritySettings settings;
   267 	TInt error = KErrNone;
   268 	RMMFController controller;
   269 
   270 	settings.iPriority = ETSIMmfPriorityLow;
   271 	settings.iPref = EMdaPriorityPreferenceTime;
   272 	settings.iState = EMMFStateIdle;
   273 
   274 	// Open a controller
   275 	
   276 	error = controller.Open(KTestControllerUid, settings);
   277 	if (error)
   278 		{
   279 		ERR_PRINTF2(_L("controller failed to open, error %d"), error);
   280 		return iTestStepResult = EInconclusive;
   281 		}
   282 
   283 	TUid uid = {KTSIMmfControllerUid};
   284 	TMMFMessageDestination handleInfo(uid);
   285 	TMMFMessageDestinationPckg messageDest(handleInfo);
   286 
   287 	// send dummy messages, to verify that return values are correct
   288 	error = controller.CustomCommandSync(messageDest, KDummyFunc1, KNullDesC8, KNullDesC8);
   289 	if(error == KDummyFunc1Return)
   290 		error = KErrNone;
   291 	else
   292 		{
   293 		ERR_PRINTF2(_L("CustomCommandSync KDummyFunc1 returned unexpected value %d"), error);
   294 		controller.Close();
   295 		return iTestStepResult = EFail;
   296 		}
   297 
   298 
   299 	error = controller.CustomCommandSync(messageDest, KDummyFunc2, KNullDesC8, KNullDesC8);
   300 	if(error == KDummyFunc2Return)
   301 		error = KErrNone;
   302 	else
   303 		{
   304 		ERR_PRINTF2(_L("CustomCommandSync KDummyFunc2 returned unexpected value %d"), error);
   305 		controller.Close();
   306 		return iTestStepResult = EFail;
   307 		}
   308 
   309 	INFO_PRINTF1(_L("CustomCommandSync returned expected values"));
   310 
   311 	// cleanup
   312 	controller.Close();
   313 	return iTestStepResult = EPass;
   314 	}
   315 
   316 // ---------------------------
   317 // RTestMmfCtlfrmI0102
   318 //
   319 // Load a controller plugin by UID
   320 //
   321 // REQ172.5.1
   322 
   323 RTestMmfCtlfrmI0102* RTestMmfCtlfrmI0102::NewL()
   324 	{
   325 	RTestMmfCtlfrmI0102* self = new(ELeave) RTestMmfCtlfrmI0102;
   326 	return self;
   327 	}
   328 
   329 RTestMmfCtlfrmI0102::RTestMmfCtlfrmI0102()
   330 	{
   331 	iTestStepName = _L("MM-MMF-CTLFRM-I-0102");
   332 	}
   333 
   334 TVerdict RTestMmfCtlfrmI0102::DoTestStepL()
   335 	{
   336 	TMMFPrioritySettings settings;
   337 	TInt error = KErrNone;
   338 	RMMFController controller;
   339 
   340 	settings.iPriority = ETSIMmfPriorityLow;
   341 	settings.iPref = EMdaPriorityPreferenceTime;
   342 	settings.iState = EMMFStateIdle;
   343 
   344 	// Open a controller
   345 	error = controller.Open(KTestControllerUid, settings);
   346 	if (error)
   347 		{
   348 		ERR_PRINTF2(_L("controller failed to open, error %d"), error);
   349 		return iTestStepResult = EInconclusive;
   350 		}
   351 
   352 	TUid uid = {KTSIMmfControllerUid};
   353 	TMMFMessageDestination handleInfo(uid);
   354 	TMMFMessageDestinationPckg messageDest(handleInfo);
   355 	TBuf8<KTextBufLen> memFunctionText;
   356 	TBuf<KTextBufLen> memFunctionText16;
   357 
   358 	// verify that we've loaded the plugin requested
   359 	// the return we expect to be the string KPluginUIDSubstitute
   360 	// we'd like to use the UID itself, but it's private in CMMFController, so this will have to do
   361 	error = controller.CustomCommandSync(messageDest, KPluginUidFunction, KNullDesC8, KNullDesC8, memFunctionText);
   362 	if(error)
   363 		{
   364 		// could be we haven't got this function in the loaded plugin 
   365 		ERR_PRINTF2(_L("CustomCommandSync KPluginUidFunction failed, error code %d"), error);
   366 		controller.Close();
   367 		return iTestStepResult = EFail;
   368 		}
   369 
   370 	// this string must match that specified in TSIMmfController.cpp
   371 	_LIT8(KPluginUIDSubstitute, "TSI_MMFController");
   372 
   373 	// memFunctionText comes back as hex string
   374 	memFunctionText16.SetMax();
   375 	memFunctionText16.Fill(0x0);
   376 	memFunctionText16.Copy(memFunctionText);
   377 	INFO_PRINTF2(_L("Controller returned : %S"), &memFunctionText16);
   378 
   379 	// check return string is expected value
   380 	if(memFunctionText.Compare(KPluginUIDSubstitute))	// returns 0 if equal
   381 		{
   382 		ERR_PRINTF1(_L("Error - string does not match expected value"));
   383 		controller.Close();
   384 		return iTestStepResult = EFail;
   385 		}
   386 	
   387 	// cleanup
   388 	controller.Close();
   389 	return iTestStepResult = EPass;
   390 	}
   391 
   392 // ---------------------------
   393 // RTestMmfCtlfrmI0105
   394 //
   395 // Load a controller plugin by filename / extension
   396 //
   397 // REQ172.5.3, REQ172.5.4
   398 
   399 RTestMmfCtlfrmI0105* RTestMmfCtlfrmI0105::NewL()
   400 	{
   401 	RTestMmfCtlfrmI0105* self = new(ELeave) RTestMmfCtlfrmI0105;
   402 	return self;
   403 	}
   404 
   405 RTestMmfCtlfrmI0105::RTestMmfCtlfrmI0105()
   406 	{
   407 	iTestStepName = _L("MM-MMF-CTLFRM-I-0105");
   408 	}
   409 
   410 TVerdict RTestMmfCtlfrmI0105::DoTestStepL()
   411 	{
   412 	// open controller by filename / extension
   413 
   414 	INFO_PRINTF1(_L("open controller by filename / extension"));
   415 
   416 	TMMFPrioritySettings settings;
   417 	TInt error = KErrNone;
   418 	RMMFController controller;
   419 
   420 	settings.iPriority = ETSIMmfPriorityLow;
   421 	settings.iPref = EMdaPriorityPreferenceTime;
   422 	settings.iState = EMMFStateIdle;
   423 
   424 	CMMFControllerPluginSelectionParameters* cSelect = CMMFControllerPluginSelectionParameters::NewLC();
   425 	CMMFFormatSelectionParameters* fSelect = CMMFFormatSelectionParameters::NewLC();
   426 
   427 	// Set the format match data
   428 	fSelect->SetMatchToFileNameL(_L("test.wav"));
   429 	// Set the controller plugin play format match data
   430 	cSelect->SetRequiredPlayFormatSupportL(*fSelect); 
   431 
   432 	RMMFControllerImplInfoArray controllers; // Array to hold all the controllers support the match data
   433 	CleanupResetAndDestroyPushL(controllers);
   434 	cSelect->ListImplementationsL(controllers);  // Populates the array with all the suitable controllers
   435 	TInt numControllers = controllers.Count();
   436 	if(!numControllers)
   437 		{
   438 		ERR_PRINTF1(_L("Could not find any controllers"));
   439 		CleanupStack::PopAndDestroy(3);//controllers, fSelect, cSelect
   440 		return iTestStepResult = EFail;
   441 		}
   442 	INFO_PRINTF2(_L("Found %d controllers"), numControllers);
   443 	CMMFControllerImplementationInformation* implInfo = controllers[0];
   444 	TUid theControllerImplUid = implInfo->Uid();
   445 	error = controller.Open(theControllerImplUid, settings); // instantiate the controller
   446 	if(error)
   447 		{
   448 		ERR_PRINTF2(_L("Could not open controller, error %d"), error);
   449 		CleanupStack::PopAndDestroy(3);//controllers, fSelect, cSelect
   450 		return iTestStepResult = EFail;
   451 		}
   452 
   453 	INFO_PRINTF2(_L("Opened controller with UID 0x%8x"), theControllerImplUid);
   454 	if(theControllerImplUid != KTestAudioControllerUid)	// check it's the right one
   455 		{
   456 		ERR_PRINTF1(_L("Error: this is not the Audio Controller"));
   457 		return iTestStepResult = EFail;
   458 		}
   459 
   460 	INFO_PRINTF1(_L("This is the Audio Controller"));
   461 	controller.Close();
   462 	CleanupStack::PopAndDestroy(3);//controllers, fSelect, cSelect
   463 	return iTestStepResult = EPass;
   464 	}
   465 
   466 // ---------------------------
   467 // RTestMmfCtlfrmI0106
   468 //
   469 // Load a controller plugin from a preferred supplier by filename / extension
   470 //
   471 // REQ172.5.3, REQ172.5.4
   472 
   473 RTestMmfCtlfrmI0106* RTestMmfCtlfrmI0106::NewL()
   474 	{
   475 	RTestMmfCtlfrmI0106* self = new(ELeave) RTestMmfCtlfrmI0106;
   476 	return self;
   477 	}
   478 
   479 RTestMmfCtlfrmI0106::RTestMmfCtlfrmI0106()
   480 	{
   481 	iTestStepName = _L("MM-MMF-CTLFRM-I-0106");
   482 	}
   483 
   484 TVerdict RTestMmfCtlfrmI0106::DoTestStepL()
   485 	{
   486 	// open controller by filename / extension and preferred supplier
   487 
   488 	INFO_PRINTF1(_L("open controller by filename / extension and preferred supplier"));
   489 
   490 	TMMFPrioritySettings settings;
   491 	TInt error = KErrNone;
   492 	RMMFController controller;
   493 
   494 	settings.iPriority = ETSIMmfPriorityLow;
   495 	settings.iPref = EMdaPriorityPreferenceTime;
   496 	settings.iState = EMMFStateIdle;
   497 
   498 	CMMFControllerPluginSelectionParameters* cSelect = CMMFControllerPluginSelectionParameters::NewLC();
   499 	CMMFFormatSelectionParameters* fSelect = CMMFFormatSelectionParameters::NewLC();
   500 
   501 	// Set the format match data
   502 	fSelect->SetMatchToFileNameL(_L("test.wav"));
   503 	// Set the controller plugin play format match data
   504 	cSelect->SetRequiredPlayFormatSupportL(*fSelect); 
   505 
   506 	// Set for only those plugins supplied by "Symbian"
   507 	_LIT(KPrefSupplierSymbian, "Symbian");
   508 	cSelect->SetPreferredSupplierL(KPrefSupplierSymbian, CMMFPluginSelectionParameters::EOnlyPreferredSupplierPluginsReturned);
   509 
   510 	RMMFControllerImplInfoArray controllers; // Array to hold all the controllers support the match data
   511 	CleanupResetAndDestroyPushL(controllers);
   512 	cSelect->ListImplementationsL(controllers);  // Populates the array with all the suitable controllers
   513 	TInt numControllers = controllers.Count();
   514 	if(!numControllers)
   515 		{
   516 		ERR_PRINTF1(_L("Could not find any controllers"));
   517 		CleanupStack::PopAndDestroy(3);//controllers, fSelect, cSelect
   518 		return iTestStepResult = EFail;
   519 		}
   520 	INFO_PRINTF2(_L("Found %d controllers"), numControllers);
   521 	CMMFControllerImplementationInformation* implInfo = controllers[0];
   522 	TUid theControllerImplUid = implInfo->Uid();
   523 	error = controller.Open(theControllerImplUid, settings); // instantiate the controller
   524 	if(error)
   525 		{
   526 		ERR_PRINTF2(_L("Could not open controller, error %d"), error);
   527 		CleanupStack::PopAndDestroy(3);//controllers, fSelect, cSelect
   528 		return iTestStepResult = EFail;
   529 		}
   530 
   531 	INFO_PRINTF2(_L("Opened controller with UID 0x%8x"), theControllerImplUid);
   532 	if(theControllerImplUid != KTestAudioControllerUid)	// check it's the right one
   533 		{
   534 		ERR_PRINTF1(_L("Error: this is not the requested controller"));
   535 		controller.Close();
   536 		CleanupStack::PopAndDestroy(3);//controllers, fSelect, cSelect
   537 		return iTestStepResult = EFail;
   538 		}
   539 
   540 	INFO_PRINTF1(_L("This is the Audio Controller"));
   541 	if(implInfo->Supplier() != KPrefSupplierSymbian)	// check supplier
   542 		{
   543 		ERR_PRINTF1(_L("Error: this controller is not from the requested supplier"));
   544 		controller.Close();
   545 		CleanupStack::PopAndDestroy(3);//controllers, fSelect, cSelect
   546 		return iTestStepResult = EFail;
   547 		}
   548 
   549 	INFO_PRINTF1(_L("This controller is from the requested supplier"));
   550 	controller.Close();
   551 	CleanupStack::PopAndDestroy(3);//controllers, fSelect, cSelect
   552 	return iTestStepResult = EPass;
   553 	}
   554 
   555 // ---------------------------
   556 // RTestMmfCtlfrmI0107
   557 //
   558 // Add a second instance of a controller which already exists
   559 //
   560 // REQ172.5.1
   561 
   562 RTestMmfCtlfrmI0107* RTestMmfCtlfrmI0107::NewL()
   563 	{
   564 	RTestMmfCtlfrmI0107* self = new(ELeave) RTestMmfCtlfrmI0107;
   565 	return self;
   566 	}
   567 
   568 RTestMmfCtlfrmI0107::RTestMmfCtlfrmI0107()
   569 	{
   570 	iTestStepName = _L("MM-MMF-CTLFRM-I-0107");
   571 	}
   572 
   573 TVerdict RTestMmfCtlfrmI0107::DoTestStepL()
   574 	{
   575 	// add a second instance of an already loaded controller
   576 	// essentially a duplicate of test 0001/0002 - simply to verify that we are running
   577 	// two instances of the same controller
   578 
   579 	INFO_PRINTF1(_L("add a second instance of an already loaded controller"));
   580 
   581 	TMMFPrioritySettings settings;
   582 	TInt error = KErrNone;
   583 	RMMFController controller, controller2;
   584 
   585 	settings.iPriority = ETSIMmfPriorityLow;
   586 	settings.iPref = EMdaPriorityPreferenceTime;
   587 	settings.iState = EMMFStateIdle;
   588 
   589 	// Open a controller
   590 	error = controller.Open(KTestControllerUid, settings);
   591 	if (error)
   592 		{
   593 		ERR_PRINTF2(_L("controller1 failed to open, error %d"), error);
   594 		return iTestStepResult = EInconclusive;
   595 		}
   596 
   597 	// Open another controller 
   598 	// (it is valid for this test to open two instances of the same controller)
   599 	error = controller2.Open(KTestControllerUid, settings);
   600 		if (error)
   601 		{
   602 		ERR_PRINTF2(_L("controller2 failed to open, error %d"), error);
   603 		controller.Close();
   604 		return iTestStepResult = EInconclusive;
   605 		}
   606 
   607 	TBuf8<KTextBufLen> memFunctionText;
   608 	TUid uid = {KTSIMmfControllerUid};
   609 	TMMFMessageDestination handleInfo(uid);
   610 	TMMFMessageDestinationPckg messageDest(handleInfo);
   611 	TBuf<KTextBufLen> memFunctionText16;
   612 	TBuf<KTextBufLen> memFunction2Text16;
   613 
   614 	// get thread addresses
   615 	error = controller.CustomCommandSync(messageDest, KThreadIdFunction, KNullDesC8, KNullDesC8, memFunctionText);
   616 	if (error)
   617 		{
   618 		ERR_PRINTF2(_L("controller1 CustomCommandSync failed with error %d"), error);
   619 		controller2.Close();
   620 		controller.Close();
   621 		return iTestStepResult = EInconclusive;
   622 		}
   623 
   624 	// memFunctionText comes back as hex string
   625 	memFunctionText16.SetMax();
   626 	memFunctionText16.Fill(0x0);
   627 	memFunctionText16.Copy(memFunctionText);
   628 	INFO_PRINTF2(_L("Controller1 thread ID : 0x%S"), &memFunctionText16);
   629 
   630 	error = controller2.CustomCommandSync(messageDest, KThreadIdFunction, KNullDesC8, KNullDesC8, memFunctionText);
   631 	if (error)
   632 		{
   633 		ERR_PRINTF2(_L("controller2 CustomCommandSync failed with error %d"), error);
   634 		controller2.Close();
   635 		controller.Close();
   636 		return iTestStepResult = EInconclusive;
   637 		}
   638 
   639 	// memFunctionText comes back as hex string
   640 	memFunction2Text16.SetMax();
   641 	memFunction2Text16.Fill(0x0);
   642 	memFunction2Text16.Copy(memFunctionText);
   643 	INFO_PRINTF2(_L("Controller2 thread ID : 0x%S"), &memFunction2Text16);
   644 
   645 	// compare thread addresses; they must not match
   646 	if(!memFunctionText16.Compare(memFunction2Text16))
   647 		{
   648 		ERR_PRINTF1(_L("Error - thread IDs match"));
   649 		controller2.Close();
   650 		controller.Close();
   651 		return iTestStepResult = EFail;
   652 		}
   653 
   654 	// get heap addresses
   655 	error = controller.CustomCommandSync(messageDest, KHeapAddressFunction, KNullDesC8, KNullDesC8, memFunctionText);
   656 	if (error)
   657 		{
   658 		ERR_PRINTF2(_L("controller1 CustomCommandSync failed with error %d"), error);
   659 		controller2.Close();
   660 		controller.Close();
   661 		return iTestStepResult = EInconclusive;
   662 		}
   663 
   664 	// memFunctionText comes back as hex string
   665 	memFunctionText16.SetMax();
   666 	memFunctionText16.Fill(0x0);
   667 	memFunctionText16.Copy(memFunctionText);
   668 	INFO_PRINTF2(_L("Controller1 heap address : 0x%S"), &memFunctionText16);
   669 
   670 	error = controller2.CustomCommandSync(messageDest, KHeapAddressFunction, KNullDesC8, KNullDesC8, memFunctionText);
   671 	if (error)
   672 		{
   673 		ERR_PRINTF2(_L("controller2 CustomCommandSync failed with error %d"), error);
   674 		controller2.Close();
   675 		controller.Close();
   676 		return iTestStepResult = EInconclusive;
   677 		}
   678 
   679 	// memFunctionText comes back as hex string
   680 	memFunction2Text16.SetMax();
   681 	memFunction2Text16.Fill(0x0);
   682 	memFunction2Text16.Copy(memFunctionText);
   683 	INFO_PRINTF2(_L("Controller2 heap address : 0x%S"), &memFunction2Text16);
   684 
   685 	// compare heap addresses; they must not match
   686 	if(!memFunctionText16.Compare(memFunction2Text16))
   687 		{
   688 		ERR_PRINTF1(_L("Error - heap addresses match"));
   689 		controller2.Close();
   690 		controller.Close();
   691 		return iTestStepResult = EFail;
   692 		}
   693 
   694 	// success if we've got here
   695 	INFO_PRINTF1(_L("Two instances of the same controller loaded successfully"));
   696 
   697 	// cleanup
   698 	controller2.Close();
   699 	controller.Close();
   700 
   701 	return iTestStepResult = EPass;
   702 	}
   703 
   704 // ---------------------------
   705 // RTestMmfCtlfrmI0108
   706 //
   707 // Load a controller plugin using ambiguous or insufficient information
   708 //
   709 // REQ172.5.3
   710 
   711 RTestMmfCtlfrmI0108* RTestMmfCtlfrmI0108::NewL()
   712 	{
   713 	RTestMmfCtlfrmI0108* self = new(ELeave) RTestMmfCtlfrmI0108;
   714 	return self;
   715 	}
   716 
   717 RTestMmfCtlfrmI0108::RTestMmfCtlfrmI0108()
   718 	{
   719 	iTestStepName = _L("MM-MMF-CTLFRM-I-0108");
   720 	}
   721 
   722 TVerdict RTestMmfCtlfrmI0108::DoTestStepL()
   723 	{
   724 	// load a controller with ambiguous information
   725 
   726 	INFO_PRINTF1(_L("load a controller with insufficient information"));
   727 
   728 	// we'll basically give no information at all. if we get a controller back at all,
   729 	// we've passed.
   730 	TMMFPrioritySettings settings;
   731 	TInt error = KErrNone;
   732 	RMMFController controller;
   733 
   734 	settings.iPriority = ETSIMmfPriorityLow;
   735 	settings.iPref = EMdaPriorityPreferenceTime;
   736 	settings.iState = EMMFStateIdle;
   737 
   738 	CMMFControllerPluginSelectionParameters* cSelect = CMMFControllerPluginSelectionParameters::NewLC();
   739 
   740 	RMMFControllerImplInfoArray controllers; // Array to hold all the controllers support the match data
   741 	CleanupResetAndDestroyPushL(controllers);
   742 	cSelect->ListImplementationsL(controllers);  // Populates the array with all the suitable controllers
   743 	TInt numControllers = controllers.Count();
   744 	if(!numControllers)
   745 		{
   746 		ERR_PRINTF1(_L("Could not find any controllers"));
   747 		CleanupStack::PopAndDestroy(2);//controllers, cSelect
   748 		return iTestStepResult = EFail;
   749 		}
   750 	INFO_PRINTF2(_L("Found %d controllers"), numControllers);
   751 	TBool controllerLoaded = EFalse;
   752 	CMMFControllerImplementationInformation* implInfo = NULL;
   753 	TUid theControllerImplUid = TUid::Uid(0);
   754 	for(TInt i = 0; i < numControllers; i++)
   755 		{
   756 		implInfo = controllers[i];
   757 		theControllerImplUid = implInfo->Uid();
   758 		error = controller.Open(theControllerImplUid, settings); // instantiate the controller
   759 		if(error)
   760 			{
   761 			if(error != KErrNoMemory)
   762 				{
   763 				ERR_PRINTF2(_L("Could not open controller, error %d"), error);
   764 				break;
   765 				}
   766 			}
   767 		else
   768 			{
   769 			controllerLoaded = ETrue;
   770 			break;
   771 			}
   772 		}
   773 	if(!controllerLoaded)
   774 		{
   775 		INFO_PRINTF1(_L("No controller loaded"));
   776 		CleanupStack::PopAndDestroy(2);//controllers, cSelect
   777 		return iTestStepResult = EFail;
   778 		}
   779 
   780 	const TDesC& theControllerImplName = implInfo->DisplayName();
   781 	const TDesC& theControllerImplSupplier = implInfo->Supplier();
   782 	INFO_PRINTF2(_L("Opened controller with UID 0x%8x"), theControllerImplUid);
   783 	INFO_PRINTF3(_L("This is the %S, supplied by %S"), &theControllerImplName, &theControllerImplSupplier);
   784 	controller.Close();
   785 	CleanupStack::PopAndDestroy(2);//controllers, cSelect
   786 	return iTestStepResult = EPass;
   787 	
   788 	}
   789 
   790 // ---------------------------
   791 // RTestMmfCtlfrmI0109
   792 //
   793 // Call overloaded constructors for parameters
   794 //
   795 // REQ: none
   796 
   797 RTestMmfCtlfrmI0109* RTestMmfCtlfrmI0109::NewL()
   798 	{
   799 	RTestMmfCtlfrmI0109* self = new(ELeave) RTestMmfCtlfrmI0109;
   800 	return self;
   801 	}
   802 
   803 RTestMmfCtlfrmI0109::RTestMmfCtlfrmI0109()
   804 	{
   805 	iTestStepName = _L("MM-MMF-CTLFRM-I-0109");
   806 	}
   807 
   808 TVerdict RTestMmfCtlfrmI0109::DoTestStepL()
   809 	{
   810 	// open controller by filename / extension
   811 
   812 	INFO_PRINTF1(_L("call overloaded constructors for parameters"));
   813 
   814 	CMMFControllerPluginSelectionParameters* cSelect = CMMFControllerPluginSelectionParameters::NewL();
   815 	CleanupStack::PushL(cSelect);
   816 	INFO_PRINTF1(_L("CMMFControllerPluginSelectionParameters constructed ok"));
   817 
   818 	CMMFFormatSelectionParameters* fSelect = CMMFFormatSelectionParameters::NewL();
   819 	CleanupStack::PushL(fSelect);
   820 	INFO_PRINTF1(_L("CMMFFormatSelectionParameters constructed ok"));
   821 
   822 	CMMFFormatDecodePluginSelectionParameters* dSelect = CMMFFormatDecodePluginSelectionParameters::NewL();
   823 	CleanupStack::PushL(dSelect);
   824 	INFO_PRINTF1(_L("CMMFFormatDecodePluginSelectionParameters constructed ok"));
   825 
   826 	CMMFFormatEncodePluginSelectionParameters* eSelect = CMMFFormatEncodePluginSelectionParameters::NewL();
   827 	CleanupStack::PushL(eSelect);
   828 	INFO_PRINTF1(_L("CMMFFormatEncodePluginSelectionParameters constructed ok"));
   829 
   830 	// if we get here without leaving, we've passed
   831 	CleanupStack::PopAndDestroy(4);//eSelect, dSelect, fSelect, cSelect
   832 	return iTestStepResult = EPass;
   833 	}
   834 
   835 // ---------------------------
   836 // RTestMmfCtlfrmI0111
   837 //
   838 // Add a data source
   839 //
   840 // REQ172.5.5.1
   841 
   842 RTestMmfCtlfrmI0111* RTestMmfCtlfrmI0111::NewL()
   843 	{
   844 	RTestMmfCtlfrmI0111* self = new(ELeave) RTestMmfCtlfrmI0111;
   845 	return self;
   846 	}
   847 
   848 RTestMmfCtlfrmI0111::RTestMmfCtlfrmI0111()
   849 	{
   850 	iTestStepName = _L("MM-MMF-CTLFRM-I-0111");
   851 	}
   852 
   853 TVerdict RTestMmfCtlfrmI0111::DoTestStepL()
   854 	{
   855 	INFO_PRINTF1(_L("(a) add a data source"));
   856 
   857 	TInt error = KErrNone;
   858 
   859 	_LIT8(KInitData,"TEST");
   860 
   861 	// first : add a data source without a handle
   862 	error = iController.AddDataSource(KTestDataSourceUid, KInitData);
   863 	if (error)
   864 		{
   865 		ERR_PRINTF2(_L("AddDataSource failed, error %d"), error);
   866 		return iTestStepResult = EInconclusive;
   867 		}
   868 
   869 	// Get log info - we expect "AddDataSourceL Called"
   870 	_LIT8(KExpectedResult, "AddDataSourceL Called");
   871 	TBuf8<KTextBufLen> memFunctionText;
   872 
   873 	TUid uid = {KTSIMmfControllerUid};
   874 	TMMFMessageDestination handleInfo(uid);
   875 	TMMFMessageDestinationPckg messageDest(handleInfo);
   876 
   877 	error = iController.CustomCommandSync(messageDest, KLogFunction, KNullDesC8, KNullDesC8, memFunctionText);
   878 	if (error)
   879 		{
   880 		ERR_PRINTF2(_L("controller CustomCommandSync failed with error %d"), error);
   881 		return iTestStepResult = EInconclusive;
   882 		}
   883 		
   884 	TBuf<KTextBufLen> memFunctionText16;
   885 	memFunctionText16.SetMax();
   886 	memFunctionText16.Fill(0x0);
   887 	memFunctionText16.Copy(memFunctionText);
   888 	INFO_PRINTF2(_L("Log : %S"), &memFunctionText16);
   889 
   890 	if (memFunctionText != KExpectedResult)
   891 		{
   892 		ERR_PRINTF1(_L("Return value did not match expected"));
   893 		return iTestStepResult = EFail;
   894 		}
   895 
   896 	// second : add a data source with a handle
   897 	INFO_PRINTF1(_L("(b) add a data source with handle"));
   898 	TMMFMessageDestination* sourceHandlePtr = new (ELeave) TMMFMessageDestination();
   899 	TMMFMessageDestination& sourceHandle = *sourceHandlePtr;
   900 
   901 	error = iController.AddDataSource(KTestDataSourceUid, KInitData, sourceHandle);
   902 	if (error)
   903 		{
   904 		ERR_PRINTF2(_L("AddDataSource failed, error %d"), error);
   905 		delete sourceHandlePtr;
   906 		return iTestStepResult = EInconclusive;
   907 		}
   908 
   909 	// Get log info - we expect "AddDataSourceL Called" again
   910 	error = iController.CustomCommandSync(messageDest, KLogFunction, KNullDesC8, KNullDesC8, memFunctionText);
   911 	if (error)
   912 		{
   913 		ERR_PRINTF2(_L("controller CustomCommandSync failed with error %d"), error);
   914 		delete sourceHandlePtr;
   915 		return iTestStepResult = EInconclusive;
   916 		}
   917 		
   918 	memFunctionText16.SetMax();
   919 	memFunctionText16.Fill(0x0);
   920 	memFunctionText16.Copy(memFunctionText);
   921 	INFO_PRINTF2(_L("Log : %S"), &memFunctionText16);
   922 
   923 	if (memFunctionText != KExpectedResult)
   924 		{
   925 		ERR_PRINTF1(_L("Return value did not match expected"));
   926 		delete sourceHandlePtr;
   927 		return iTestStepResult = EFail;
   928 		}
   929 
   930 	INFO_PRINTF2(_L("Data source handle is %d"), sourceHandle.DestinationHandle());
   931 
   932 	// call a custom source command. doesn't matter what it is, we'd expect it to return KErrNotSupported
   933 	// anyway - the point is to ensure CMMFDataSourceHolder::HandleRequest() is called.
   934 	// a return of 0 or -5 indicates it has been.
   935 	error = iController.CustomCommandSync(sourceHandle, KLogFunction, KNullDesC8, KNullDesC8, memFunctionText);
   936 	INFO_PRINTF2(_L("CustomCommandSync on sourceHandle returned %d"), error);
   937 	if (error && error != KErrNotSupported)
   938 		{
   939 		ERR_PRINTF1(_L("Unexpected error code returned"));
   940 		delete sourceHandlePtr;
   941 		return iTestStepResult = EFail;
   942 		}
   943 	
   944 	// cleanup 
   945 	delete sourceHandlePtr;
   946 	return iTestStepResult = EPass;
   947 	}
   948 
   949 // ---------------------------
   950 // RTestMmfCtlfrmI0112
   951 //
   952 // Remove a data source
   953 //
   954 // REQ172.5.5.2
   955 
   956 RTestMmfCtlfrmI0112* RTestMmfCtlfrmI0112::NewL()
   957 	{
   958 	RTestMmfCtlfrmI0112* self = new(ELeave) RTestMmfCtlfrmI0112;
   959 	return self;
   960 	}
   961 
   962 RTestMmfCtlfrmI0112::RTestMmfCtlfrmI0112()
   963 	{
   964 	iTestStepName = _L("MM-MMF-CTLFRM-I-0112");
   965 	}
   966 
   967 TVerdict RTestMmfCtlfrmI0112::DoTestStepL()
   968 	{
   969 	INFO_PRINTF1(_L("remove a data source"));
   970 
   971 	TInt error = KErrNone;
   972 
   973 	_LIT8(KInitData,"TEST");
   974 
   975 	// add a data source with a handle
   976 	TMMFMessageDestination* sourceHandlePtr = new (ELeave) TMMFMessageDestination();
   977 	TMMFMessageDestination& sourceHandle = *sourceHandlePtr;
   978 
   979 	error = iController.AddDataSource(KTestDataSourceUid, KInitData, sourceHandle);
   980 	if (error)
   981 		{
   982 		ERR_PRINTF2(_L("AddDataSource failed, error %d"), error);
   983 		delete sourceHandlePtr;
   984 		return iTestStepResult = EInconclusive;
   985 		}
   986 
   987 	// Get log info - we expect "AddDataSourceL Called"
   988 	_LIT8(KExpectedResult, "AddDataSourceL Called");
   989 	TBuf8<KTextBufLen> memFunctionText;
   990 
   991 	TUid uid = {KTSIMmfControllerUid};
   992 	TMMFMessageDestination handleInfo(uid);
   993 	TMMFMessageDestinationPckg messageDest(handleInfo);
   994 
   995 	error = iController.CustomCommandSync(messageDest, KLogFunction, KNullDesC8, KNullDesC8, memFunctionText);
   996 	if (error)
   997 		{
   998 		ERR_PRINTF2(_L("controller CustomCommandSync failed with error %d"), error);
   999 		delete sourceHandlePtr;
  1000 		return iTestStepResult = EInconclusive;
  1001 		}
  1002 		
  1003 	if (memFunctionText != KExpectedResult)
  1004 		{
  1005 		ERR_PRINTF1(_L("Return value did not match expected"));
  1006 		delete sourceHandlePtr;
  1007 		return iTestStepResult = EInconclusive;
  1008 		}
  1009 
  1010 	// now, delete the data source we just added
  1011 	error = iController.RemoveDataSource(sourceHandle);
  1012 	if (error)
  1013 		{
  1014 		ERR_PRINTF2(_L("RemoveDataSource failed with error %d"), error);
  1015 		delete sourceHandlePtr;
  1016 		return iTestStepResult = EInconclusive;
  1017 		}
  1018 	
  1019 	// verify that the data source is no longer there. try and remove it again, this should
  1020 	// return an error
  1021 	error = iController.RemoveDataSource(sourceHandle);
  1022 	if (!error)
  1023 		{
  1024 		ERR_PRINTF1(_L("Error : data source was not removed at first attempt"));
  1025 		delete sourceHandlePtr;
  1026 		return iTestStepResult = EInconclusive;
  1027 		}
  1028 
  1029 	INFO_PRINTF2(_L("Data source removed (second attempt failed with error %d)"), error);
  1030 
  1031 	// cleanup 
  1032 	delete sourceHandlePtr;
  1033 	return iTestStepResult = EPass;
  1034 	}
  1035 
  1036 // ---------------------------
  1037 // RTestMmfCtlfrmI0113
  1038 //
  1039 // Add a data sink
  1040 //
  1041 // REQ172.5.5.3
  1042 
  1043 RTestMmfCtlfrmI0113* RTestMmfCtlfrmI0113::NewL()
  1044 	{
  1045 	RTestMmfCtlfrmI0113* self = new(ELeave) RTestMmfCtlfrmI0113;
  1046 	return self;
  1047 	}
  1048 
  1049 RTestMmfCtlfrmI0113::RTestMmfCtlfrmI0113()
  1050 	{
  1051 	iTestStepName = _L("MM-MMF-CTLFRM-I-0113");
  1052 	}
  1053 
  1054 TVerdict RTestMmfCtlfrmI0113::DoTestStepL()
  1055 	{
  1056 	INFO_PRINTF1(_L("(a) add a data sink"));
  1057 
  1058 	TInt error = KErrNone;
  1059 
  1060 	_LIT8(KInitData,"TEST");
  1061 
  1062 	// first : add a data sink without a handle
  1063 	error = iController.AddDataSink(KTestDataSinkUid, KInitData);
  1064 	if (error)
  1065 		{
  1066 		ERR_PRINTF2(_L("AddDataSink failed, error %d"), error);
  1067 		return iTestStepResult = EInconclusive;
  1068 		}
  1069 
  1070 	// Get log info - we expect "AddDataSinkL Called"
  1071 	_LIT8(KExpectedResult, "AddDataSinkL Called");
  1072 	TBuf8<KTextBufLen> memFunctionText;
  1073 
  1074 	TUid uid = {KTSIMmfControllerUid};
  1075 	TMMFMessageDestination handleInfo(uid);
  1076 	TMMFMessageDestinationPckg messageDest(handleInfo);
  1077 
  1078 	error = iController.CustomCommandSync(messageDest, KLogFunction, KNullDesC8, KNullDesC8, memFunctionText);
  1079 	if (error)
  1080 		{
  1081 		ERR_PRINTF2(_L("controller CustomCommandSync failed with error %d"), error);
  1082 		return iTestStepResult = EInconclusive;
  1083 		}
  1084 		
  1085 	TBuf<KTextBufLen> memFunctionText16;
  1086 	memFunctionText16.SetMax();
  1087 	memFunctionText16.Fill(0x0);
  1088 	memFunctionText16.Copy(memFunctionText);
  1089 	INFO_PRINTF2(_L("Log : %S"), &memFunctionText16);
  1090 
  1091 	if (memFunctionText != KExpectedResult)
  1092 		{
  1093 		ERR_PRINTF1(_L("Return value did not match expected"));
  1094 		return iTestStepResult = EFail;
  1095 		}
  1096 
  1097 	// second : add a data sink with a handle
  1098 	INFO_PRINTF1(_L("(b) add a data sink with handle"));
  1099 	TMMFMessageDestination* sinkHandlePtr = new (ELeave) TMMFMessageDestination();
  1100 	TMMFMessageDestination& sinkHandle = *sinkHandlePtr;
  1101 
  1102 	error = iController.AddDataSink(KTestDataSinkUid, KInitData, sinkHandle);
  1103 	if (error)
  1104 		{
  1105 		ERR_PRINTF2(_L("AddDataSink failed, error %d"), error);
  1106 		delete sinkHandlePtr;
  1107 		return iTestStepResult = EInconclusive;
  1108 		}
  1109 
  1110 	// Get log info - we expect "AddDataSinkL Called" again
  1111 	error = iController.CustomCommandSync(messageDest, KLogFunction, KNullDesC8, KNullDesC8, memFunctionText);
  1112 	if (error)
  1113 		{
  1114 		ERR_PRINTF2(_L("controller CustomCommandSync failed with error %d"), error);
  1115 		delete sinkHandlePtr;
  1116 		return iTestStepResult = EInconclusive;
  1117 		}
  1118 		
  1119 	memFunctionText16.SetMax();
  1120 	memFunctionText16.Fill(0x0);
  1121 	memFunctionText16.Copy(memFunctionText);
  1122 	INFO_PRINTF2(_L("Log : %S"), &memFunctionText16);
  1123 
  1124 	if (memFunctionText != KExpectedResult)
  1125 		{
  1126 		ERR_PRINTF1(_L("Return value did not match expected"));
  1127 		delete sinkHandlePtr;
  1128 		return iTestStepResult = EFail;
  1129 		}
  1130 
  1131 	INFO_PRINTF2(_L("Data sink handle is %d"), sinkHandle.DestinationHandle());
  1132 
  1133 	// call a custom sink command. doesn't matter what it is, we'd expect it to return KErrNotSupported
  1134 	// anyway - the point is to ensure CMMFDataSinkHolder::HandleRequest() is called.
  1135 	// a return of 0 or -5 indicates it has been.
  1136 	error = iController.CustomCommandSync(sinkHandle, KLogFunction, KNullDesC8, KNullDesC8, memFunctionText);
  1137 	INFO_PRINTF2(_L("CustomCommandSync on sinkHandle returned %d"), error);
  1138 	if (error && error != KErrNotSupported)
  1139 		{
  1140 		ERR_PRINTF1(_L("Unexpected error code returned"));
  1141 		delete sinkHandlePtr;
  1142 		return iTestStepResult = EFail;
  1143 		}
  1144 	
  1145 	// cleanup 
  1146 	delete sinkHandlePtr;
  1147 	return iTestStepResult = EPass;
  1148 	}
  1149 
  1150 // ---------------------------
  1151 // RTestMmfCtlfrmI0114
  1152 //
  1153 // Remove a data sink
  1154 //
  1155 // REQ172.5.5.4
  1156 
  1157 RTestMmfCtlfrmI0114* RTestMmfCtlfrmI0114::NewL()
  1158 	{
  1159 	RTestMmfCtlfrmI0114* self = new(ELeave) RTestMmfCtlfrmI0114;
  1160 	return self;
  1161 	}
  1162 
  1163 RTestMmfCtlfrmI0114::RTestMmfCtlfrmI0114()
  1164 	{
  1165 	iTestStepName = _L("MM-MMF-CTLFRM-I-0114");
  1166 	}
  1167 
  1168 TVerdict RTestMmfCtlfrmI0114::DoTestStepL()
  1169 	{
  1170 	INFO_PRINTF1(_L("remove a data sink"));
  1171 
  1172 	TInt error = KErrNone;
  1173 
  1174 	_LIT8(KInitData,"TEST");
  1175 
  1176 	// add a data sink with a handle
  1177 	TMMFMessageDestination* sinkHandlePtr = new (ELeave) TMMFMessageDestination();
  1178 	TMMFMessageDestination& sinkHandle = *sinkHandlePtr;
  1179 
  1180 	error = iController.AddDataSink(KTestDataSinkUid, KInitData, sinkHandle);
  1181 	if (error)
  1182 		{
  1183 		ERR_PRINTF2(_L("AddDataSink failed, error %d"), error);
  1184 		delete sinkHandlePtr;
  1185 		return iTestStepResult = EInconclusive;
  1186 		}
  1187 
  1188 	// Get log info - we expect "AddDataSinkL Called"
  1189 	_LIT8(KExpectedResult, "AddDataSinkL Called");
  1190 	TBuf8<KTextBufLen> memFunctionText;
  1191 
  1192 	TUid uid = {KTSIMmfControllerUid};
  1193 	TMMFMessageDestination handleInfo(uid);
  1194 	TMMFMessageDestinationPckg messageDest(handleInfo);
  1195 
  1196 	error = iController.CustomCommandSync(messageDest, KLogFunction, KNullDesC8, KNullDesC8, memFunctionText);
  1197 	if (error)
  1198 		{
  1199 		ERR_PRINTF2(_L("controller CustomCommandSync failed with error %d"), error);
  1200 		delete sinkHandlePtr;
  1201 		return iTestStepResult = EInconclusive;
  1202 		}
  1203 		
  1204 	if (memFunctionText != KExpectedResult)
  1205 		{
  1206 		ERR_PRINTF1(_L("Return value did not match expected"));
  1207 		delete sinkHandlePtr;
  1208 		return iTestStepResult = EInconclusive;
  1209 		}
  1210 
  1211 	// now, delete the data sink we just added
  1212 	error = iController.RemoveDataSink(sinkHandle);
  1213 	if (error)
  1214 		{
  1215 		ERR_PRINTF2(_L("RemoveDataSink failed with error %d"), error);
  1216 		delete sinkHandlePtr;
  1217 		return iTestStepResult = EInconclusive;
  1218 		}
  1219 	
  1220 	// verify that the data sink is no longer there. try and remove it again, this should
  1221 	// return an error
  1222 	error = iController.RemoveDataSink(sinkHandle);
  1223 	if (!error)
  1224 		{
  1225 		ERR_PRINTF1(_L("Error : data sink was not removed at first attempt"));
  1226 		delete sinkHandlePtr;
  1227 		return iTestStepResult = EInconclusive;
  1228 		}
  1229 
  1230 	INFO_PRINTF2(_L("Data sink removed (second attempt failed with error %d)"), error);
  1231 
  1232 	// cleanup 
  1233 	delete sinkHandlePtr;
  1234 	return iTestStepResult = EPass;
  1235 	}
  1236 
  1237 // ---------------------------
  1238 // RTestMmfCtlfrmI0117
  1239 //
  1240 // Set / get source config parameters
  1241 //
  1242 // REQ: none
  1243 
  1244 RTestMmfCtlfrmI0117* RTestMmfCtlfrmI0117::NewL()
  1245 	{
  1246 	RTestMmfCtlfrmI0117* self = new(ELeave) RTestMmfCtlfrmI0117;
  1247 	return self;
  1248 	}
  1249 
  1250 RTestMmfCtlfrmI0117::RTestMmfCtlfrmI0117()
  1251 	{
  1252 	iTestStepName = _L("MM-MMF-CTLFRM-I-0117");
  1253 	}
  1254 
  1255 TVerdict RTestMmfCtlfrmI0117::DoTestStepL( void )
  1256 	{
  1257 	INFO_PRINTF1(_L("Set / get source config parameters"));
  1258 
  1259 	TInt error = KErrNone;
  1260 	
  1261 	RMMFAudioControllerCustomCommands customCommands(iController);
  1262 
  1263 	RArray<TUint> supportedSampleRates;
  1264 	TRAP(error, customCommands.GetSupportedSourceSampleRatesL(supportedSampleRates));
  1265 	if (error)
  1266 		{
  1267 		ERR_PRINTF2(_L("GetSupportedSourceSampleRatesL left, error %d"), error);
  1268 		return iTestStepResult = EFail;
  1269 		}
  1270 	INFO_PRINTF2(_L("GetSupportedSourceSampleRatesL returned %d entries"), supportedSampleRates.Count());
  1271 
  1272 	RArray<TUint> supportedBitRates;
  1273 	// we expect this to be Not Supported
  1274 	TRAP(error, customCommands.GetSupportedSourceBitRatesL(supportedBitRates));
  1275 	if (error)
  1276 		{
  1277 		ERR_PRINTF2(_L("GetSupportedSourceBitRatesL left, error %d"), error);
  1278 		if(error != KErrNotSupported)
  1279 			return iTestStepResult = EFail;
  1280 		}
  1281 	else
  1282 		{
  1283 		INFO_PRINTF2(_L("GetSupportedSourceBitRatesL returned %d entries"), supportedBitRates.Count());
  1284 		}
  1285 
  1286 	RArray<TUint> supportedNumChannels;
  1287 	TRAP(error, customCommands.GetSupportedSourceNumChannelsL(supportedNumChannels));
  1288 	if (error)
  1289 		{
  1290 		ERR_PRINTF2(_L("GetSupportedSourceNumChannelsL left, error %d"), error);
  1291 		return iTestStepResult = EFail;
  1292 		}
  1293 	INFO_PRINTF2(_L("GetSupportedSourceNumChannelsL returned %d entries"), supportedNumChannels.Count());
  1294 
  1295 	TUint bitRate = 1000; // 1 Khz
  1296 	error = customCommands.SetSourceBitRate(bitRate);
  1297 	INFO_PRINTF2(_L("SetSourceBitRate returned %d"), error);
  1298 	if (error && error != KErrNotSupported)
  1299 		{
  1300 		ERR_PRINTF2(_L("SetSourceBitRate failed, error %d"), error);
  1301 		return iTestStepResult = EFail;
  1302 		}
  1303 
  1304 	TUint sampleRate = 5;
  1305 	error = customCommands.SetSourceSampleRate(sampleRate);
  1306 	INFO_PRINTF2(_L("SetSourceSampleRate returned %d"), error);
  1307 	// Setting source sample rate to a different value 
  1308 	// is tolerated (INC038043) to preserve BC with 6.1
  1309 	if (error != KErrNone)
  1310 		{
  1311 		ERR_PRINTF3(_L("SetSourceSampleRate failed, error %d, expected %d"), error, KErrAlreadyExists);
  1312 		return iTestStepResult = EFail;
  1313 		}
  1314 	
  1315 	TUint numChannels = 1;
  1316 	error = customCommands.SetSourceNumChannels(numChannels);
  1317 	INFO_PRINTF2(_L("SetSourceNumChannels returned %d"), error);
  1318 	// Setting number of channels to a different value 
  1319 	// is tolerated (INC038043) to preserve BC with 6.1
  1320 	if (error && error != KErrNone)
  1321 		{
  1322 		ERR_PRINTF2(_L("SetSourceNumChannels failed, error %d"), error);
  1323 		return iTestStepResult = EFail;
  1324 		}
  1325 
  1326 	// EPass if we got here
  1327 	return iTestStepResult = EPass;
  1328 	}
  1329 
  1330 // ---------------------------
  1331 // RTestMmfCtlfrmI0118
  1332 //
  1333 // Set / get sink config parameters
  1334 //
  1335 // REQ: none
  1336 
  1337 RTestMmfCtlfrmI0118* RTestMmfCtlfrmI0118::NewL()
  1338 	{
  1339 	RTestMmfCtlfrmI0118* self = new(ELeave) RTestMmfCtlfrmI0118;
  1340 	return self;
  1341 	}
  1342 
  1343 RTestMmfCtlfrmI0118::RTestMmfCtlfrmI0118()
  1344 	{
  1345 	iTestStepName = _L("MM-MMF-CTLFRM-I-0118");
  1346 	}
  1347 
  1348 TVerdict RTestMmfCtlfrmI0118::DoTestStepL( void )
  1349 	{
  1350 	INFO_PRINTF1(_L("Set / get sink config parameters"));
  1351 
  1352 	TInt error = KErrNone;
  1353 	
  1354 	RMMFAudioControllerCustomCommands customCommands(iController);
  1355 
  1356 	RArray<TUint> supportedSampleRates;
  1357 	TRAP(error, customCommands.GetSupportedSinkSampleRatesL(supportedSampleRates));
  1358 	if (error != KErrNotSupported)
  1359 		{
  1360 		ERR_PRINTF2(_L("GetSupportedSinkSampleRatesL left with error %d but expected is KErrNotSupported"), error);
  1361 		return iTestStepResult = EFail;
  1362 		}
  1363 	INFO_PRINTF2(_L("GetSupportedSinkSampleRatesL returned %d entries"), supportedSampleRates.Count());
  1364 
  1365 	RArray<TUint> supportedBitRates;
  1366 	// we expect this to be Not Supported
  1367 	TRAP(error, customCommands.GetSupportedSinkBitRatesL(supportedBitRates));
  1368 	if (error)
  1369 		{
  1370 		ERR_PRINTF2(_L("GetSupportedSinkBitRatesL left, error %d"), error);
  1371 		if(error != KErrNotSupported)
  1372 			return iTestStepResult = EFail;
  1373 		}
  1374 	else
  1375 		{
  1376 		INFO_PRINTF2(_L("GetSupportedSinkBitRatesL returned %d entries"), supportedBitRates.Count());
  1377 		}
  1378 
  1379 	RArray<TUint> supportedNumChannels;
  1380 	TRAP(error, customCommands.GetSupportedSinkNumChannelsL(supportedNumChannels));
  1381 	if (error != KErrNotSupported)
  1382 		{
  1383 		ERR_PRINTF2(_L("GetSupportedSinkNumChannelsL left with error %d but expected is KErrNotSupported"), error);
  1384 		return iTestStepResult = EFail;
  1385 		}
  1386 	INFO_PRINTF2(_L("GetSupportedSinkNumChannelsL returned %d entries"), supportedNumChannels.Count());
  1387 
  1388 	TUint bitRate = 1000; // 1 Khz
  1389 	error = customCommands.SetSinkBitRate(bitRate);
  1390 	INFO_PRINTF2(_L("SetSinkBitRate returned %d"), error);
  1391 	if (error && error != KErrNotSupported)
  1392 		{
  1393 		ERR_PRINTF2(_L("SetSinkBitRate failed, error %d"), error);
  1394 		return iTestStepResult = EFail;
  1395 		}
  1396 
  1397 	TUint sampleRate = 5;
  1398 	error = customCommands.SetSinkSampleRate(sampleRate);
  1399 	INFO_PRINTF2(_L("SetSinkSampleRate returned %d"), error);
  1400 	if (error && error != KErrNotSupported)
  1401 		{
  1402 		ERR_PRINTF2(_L("SetSinkSampleRate failed, error %d"), error);
  1403 		return iTestStepResult = EFail;
  1404 		}
  1405 	
  1406 	TUint numChannels = 1;
  1407 	error = customCommands.SetSinkNumChannels(numChannels);
  1408 	INFO_PRINTF2(_L("SetSinkNumChannels returned %d"), error);
  1409 	if (error && error != KErrNotSupported)
  1410 		{
  1411 		ERR_PRINTF2(_L("SetSinkNumChannels failed, error %d"), error);
  1412 		return iTestStepResult = EFail;
  1413 		}
  1414 
  1415 	// EPass if we got here
  1416 	return iTestStepResult = EPass;
  1417 	}
  1418 
  1419 // ---------------------------
  1420 // RTestMmfCtlfrmI0119
  1421 //
  1422 // Get supported source/sink video types
  1423 //
  1424 // REQ: none
  1425 
  1426 RTestMmfCtlfrmI0119* RTestMmfCtlfrmI0119::NewL()
  1427 	{
  1428 	RTestMmfCtlfrmI0119* self = new(ELeave) RTestMmfCtlfrmI0119;
  1429 	return self;
  1430 	}
  1431 
  1432 RTestMmfCtlfrmI0119::RTestMmfCtlfrmI0119()
  1433 	{
  1434 	iTestStepName = _L("MM-MMF-CTLFRM-I-0119");
  1435 	}
  1436 
  1437 TVerdict RTestMmfCtlfrmI0119::DoTestStepL( void )
  1438 	{
  1439 	// NB this is implemented purely for code coverage purposes
  1440 	INFO_PRINTF1(_L("Get supported source/sink audio/video types"));
  1441 
  1442 	// GetSupportedSinkAudioTypes no longer in base class
  1443 	INFO_PRINTF1(_L("GetSupportedSinkAudioTypes no longer in video controller base class"));
  1444 
  1445 	// GetSupportedSinkVideoTypes no longer in base class
  1446 	INFO_PRINTF1(_L("GetSupportedSinkVideoTypes no longer in video controller base class"));
  1447 
  1448 	// GetSupportedSourceAudioTypes no longer supported
  1449 	INFO_PRINTF1(_L("GetSupportedSourceAudioTypes no longer supported"));
  1450 
  1451 	// GetSupportedSourceVideoTypes no longer supported
  1452 	INFO_PRINTF1(_L("GetSupportedSourceVideoTypes no longer supported"));
  1453 
  1454 	// EPass if we got here
  1455 	return iTestStepResult = EPass;
  1456 	}
  1457 
  1458 // ---------------------------
  1459 // RTestMmfCtlfrmI0120
  1460 //
  1461 // Call display window related methods for video play controller
  1462 //
  1463 // REQ: none
  1464 
  1465 RTestMmfCtlfrmI0120* RTestMmfCtlfrmI0120::NewL()
  1466 	{
  1467 	RTestMmfCtlfrmI0120* self = new(ELeave) RTestMmfCtlfrmI0120;
  1468 	return self;
  1469 	}
  1470 
  1471 RTestMmfCtlfrmI0120::RTestMmfCtlfrmI0120()
  1472 	{
  1473 	iTestStepName = _L("MM-MMF-CTLFRM-I-0120");
  1474 	}
  1475 
  1476 TVerdict RTestMmfCtlfrmI0120::DoTestStepL( void )
  1477 	{
  1478 	// NB this is implemented purely for code coverage purposes
  1479 	INFO_PRINTF1(_L("Call display window related methods for video play controller"));
  1480 
  1481 	TInt error = KErrNone;
  1482 	
  1483 	RMMFVideoPlayControllerCustomCommands playCustomCommands(iController);
  1484 
  1485 	TRect r(0,0,0,0);
  1486 	error = playCustomCommands.SetDisplayWindow(r, r);
  1487 	INFO_PRINTF2(_L("SetDisplayWindow returned %d"), error);
  1488 	if (error)
  1489 		{
  1490 		if(error != KErrNotSupported)
  1491 			return iTestStepResult = EFail;
  1492 		}
  1493 
  1494 	RRegion rg;
  1495 	error = playCustomCommands.UpdateDisplayRegion(rg);
  1496 	INFO_PRINTF2(_L("UpdateDisplayRegion returned %d"), error);
  1497 	if (error)
  1498 		{
  1499 		if(error != KErrNotSupported)
  1500 			return iTestStepResult = EFail;
  1501 		}
  1502 
  1503 	// EPass if we got here
  1504 	return iTestStepResult = EPass;
  1505 	}
  1506 
  1507 // ---------------------------
  1508 // RTestMmfCtlfrmI0121
  1509 //
  1510 // Prime (prepare data flow)
  1511 //
  1512 // REQ172.5.5.5
  1513 
  1514 RTestMmfCtlfrmI0121* RTestMmfCtlfrmI0121::NewL()
  1515 	{
  1516 	RTestMmfCtlfrmI0121* self = new(ELeave) RTestMmfCtlfrmI0121;
  1517 	return self;
  1518 	}
  1519 
  1520 RTestMmfCtlfrmI0121::RTestMmfCtlfrmI0121()
  1521 	{
  1522 	iTestStepName = _L("MM-MMF-CTLFRM-I-0121");
  1523 	}
  1524 
  1525 TVerdict RTestMmfCtlfrmI0121::DoTestStepL()
  1526 	{
  1527 	INFO_PRINTF1(_L("Prime a controller"));
  1528 
  1529 	TInt error = KErrNone;
  1530 	TVerdict result = EPass;
  1531 	
  1532 	error = iController.Prime();
  1533 	if(error)
  1534 		{
  1535 		ERR_PRINTF2(_L("Prime failed, error %d"), error);
  1536 		return iTestStepResult = EFail;
  1537 		}
  1538 	
  1539 	// [ wait for and process the return event from the Custom audio controller ]
  1540 	TMMFEvent primeEvent( KPrimeTestId, KErrNone);
  1541 	result = SearchForEvent( primeEvent );
  1542 	if( result == EFail )
  1543 		{
  1544 		ERR_PRINTF1(_L("Custom audio controller did not return a prime event"));
  1545 		return iTestStepResult = EFail;
  1546 		}
  1547 	
  1548 	// EPass if we got here
  1549 	return iTestStepResult = EPass;
  1550 	}
  1551 
  1552 // ---------------------------
  1553 // RTestMmfCtlfrmI0122
  1554 //
  1555 // Play
  1556 //
  1557 // REQ172.5.5.6
  1558 
  1559 RTestMmfCtlfrmI0122* RTestMmfCtlfrmI0122::NewL()
  1560 	{
  1561 	RTestMmfCtlfrmI0122* self = new(ELeave) RTestMmfCtlfrmI0122;
  1562 	return self;
  1563 	}
  1564 
  1565 RTestMmfCtlfrmI0122::RTestMmfCtlfrmI0122()
  1566 	{
  1567 	iTestStepName = _L("MM-MMF-CTLFRM-I-0122");
  1568 	}
  1569 
  1570 TVerdict RTestMmfCtlfrmI0122::DoTestStepL()
  1571 	{
  1572 	// Play a controller. Must be primed first
  1573 	INFO_PRINTF1(_L("Play a controller"));
  1574 
  1575 	TInt error = KErrNone;
  1576 	TVerdict result = EPass;
  1577 	
  1578 	error = iController.Prime();
  1579 	if(error)
  1580 		{
  1581 		ERR_PRINTF2(_L("Prime failed, error %d"), error);
  1582 		return iTestStepResult = EInconclusive;
  1583 		}
  1584 	
  1585 	// [ wait for and process the return event from the Custom audio controller ]
  1586 	TMMFEvent primeEvent( KPrimeTestId, KErrNone);
  1587 	result = SearchForEvent( primeEvent );
  1588 	if( result == EFail )
  1589 		{
  1590 		ERR_PRINTF1(_L("Custom audio controller did not return a prime event"));
  1591 		return iTestStepResult = EInconclusive;
  1592 		}
  1593 	
  1594     error = iController.Play();
  1595 	if(error)
  1596 		{
  1597 		ERR_PRINTF2(_L("Play failed, error %d"), error);
  1598 		return iTestStepResult = EFail;
  1599 		}
  1600 
  1601 	// wait for an event from the Custom audio controller
  1602 	TMMFEvent playEvent( KPlayTestId, KErrNone);
  1603 	result = SearchForEvent( playEvent );
  1604 	if( result == EFail )
  1605 		{
  1606 		ERR_PRINTF1(_L("Custom audio controller did not return a play event"));
  1607 		return iTestStepResult = EFail;
  1608 		}
  1609 	
  1610 	// verify that clip is playing : get the position a couple of times
  1611 	// NB the clip must be at least 1 second long for this to work
  1612 
  1613 	TTimeIntervalMicroSeconds clipPos1, clipPos2, clipPos3;
  1614 	User::After(KGetPositionIntervalLength);
  1615 	error = iController.GetPosition(clipPos1);
  1616 	User::After(KGetPositionIntervalLength);
  1617 	error += iController.GetPosition(clipPos2);
  1618 	User::After(KGetPositionIntervalLength);
  1619 	error += iController.GetPosition(clipPos3);
  1620 
  1621 	if(error)
  1622 		{
  1623 		// NB it's cumulative so don't give return value
  1624 		ERR_PRINTF1(_L("Error : GetPosition failed"));	
  1625 		return iTestStepResult = EInconclusive;
  1626 		}
  1627 
  1628 	INFO_PRINTF4(_L("Clip positions : %ld %ld %ld"), I64LOW(clipPos1.Int64()), I64LOW(clipPos2.Int64()), I64LOW(clipPos3.Int64()));
  1629 
  1630 	if((clipPos1 == clipPos2) && (clipPos2 == clipPos3))
  1631 		{
  1632 		ERR_PRINTF1(_L("Error : clip position not changing"));
  1633 		return iTestStepResult = EFail;
  1634 		}
  1635 
  1636 	// EPass if we got here
  1637 	return iTestStepResult = EPass;
  1638 	}
  1639 
  1640 // ---------------------------
  1641 // RTestMmfCtlfrmI0123
  1642 //
  1643 // Stop
  1644 //
  1645 // REQ172.5.5.7
  1646 
  1647 RTestMmfCtlfrmI0123* RTestMmfCtlfrmI0123::NewL()
  1648 	{
  1649 	RTestMmfCtlfrmI0123* self = new(ELeave) RTestMmfCtlfrmI0123;
  1650 	return self;
  1651 	}
  1652 
  1653 RTestMmfCtlfrmI0123::RTestMmfCtlfrmI0123()
  1654 	{
  1655 	iTestStepName = _L("MM-MMF-CTLFRM-I-0123");
  1656 	}
  1657 
  1658 TVerdict RTestMmfCtlfrmI0123::DoTestStepL()
  1659 	{
  1660 	// Stop a controller. Must be playing first
  1661 	INFO_PRINTF1(_L("Stop a controller"));
  1662 
  1663 	TInt error = KErrNone;
  1664 	TVerdict result = EPass;
  1665 	
  1666 	error = iController.Prime();
  1667 	if(error)
  1668 		{
  1669 		ERR_PRINTF2(_L("Prime failed, error %d"), error);
  1670 		return iTestStepResult = EInconclusive;
  1671 		}
  1672 	
  1673 	// [ wait for and process the return event from the Custom audio controller ]
  1674 	TMMFEvent primeEvent( KPrimeTestId, KErrNone);
  1675 	result = SearchForEvent( primeEvent );
  1676 	if( result == EFail )
  1677 		{
  1678 		ERR_PRINTF1(_L("Custom audio controller did not return a prime event"));
  1679 		return iTestStepResult = EInconclusive;
  1680 		}
  1681 	
  1682     error = iController.Play();
  1683 	if(error)
  1684 		{
  1685 		ERR_PRINTF2(_L("Play failed, error %d"), error);
  1686 		return iTestStepResult = EInconclusive;
  1687 		}
  1688 
  1689 	// get an event from the controller
  1690 	TMMFEvent playEvent( KPlayTestId, KErrNone);
  1691 	result = SearchForEvent( playEvent );
  1692 	if( result == EFail )
  1693 		{
  1694 		ERR_PRINTF1(_L("Custom audio controller did not return a play event"));
  1695 		return iTestStepResult = EFail;
  1696 		}
  1697 	
  1698 	// verify that clip is playing : get the position a couple of times
  1699 	// NB the clip must be at least 1.5 seconds long for this to work
  1700 
  1701 	TTimeIntervalMicroSeconds clipPos1, clipPos2, clipPos3;
  1702 	User::After(KGetPositionIntervalLength);
  1703 	error = iController.GetPosition(clipPos1);
  1704 	User::After(KGetPositionIntervalLength);
  1705 	error += iController.GetPosition(clipPos2);
  1706 	User::After(KGetPositionIntervalLength);
  1707 	error += iController.GetPosition(clipPos3);
  1708 
  1709 	if(error)
  1710 		{
  1711 		// NB it's cumulative so don't give return value
  1712 		ERR_PRINTF1(_L("Error : GetPosition failed"));	
  1713 		return iTestStepResult = EInconclusive;
  1714 		}
  1715 
  1716 	INFO_PRINTF4(_L("Clip positions : %ld %ld %ld"), I64LOW(clipPos1.Int64()), I64LOW(clipPos2.Int64()), I64LOW(clipPos3.Int64()));
  1717 
  1718 	if((clipPos1 == clipPos2) && (clipPos2 == clipPos3))
  1719 		{
  1720 		ERR_PRINTF1(_L("Error : clip position not changing"));
  1721 		return iTestStepResult = EInconclusive;
  1722 		}
  1723 
  1724 	// now stop the clip. verify that the position is 0 and not changing.
  1725 	error = iController.Stop();
  1726 	if(error)
  1727 		{
  1728 		ERR_PRINTF2(_L("Stop failed, error %d"), error);
  1729 		return iTestStepResult = EFail;
  1730 		}
  1731 		
  1732  	// verify that clip is stopped : get the position a couple of times
  1733 	// NB we have to re-prime it first for this to work. If it is still playing,
  1734 	// the prime will fail
  1735 	error = iController.Prime();
  1736 	if(error)
  1737 		{
  1738 		ERR_PRINTF2(_L("Prime failed, error %d"), error);
  1739 		return iTestStepResult = EInconclusive;
  1740 		}
  1741 	
  1742 	User::After(KGetPositionIntervalLength);
  1743 	error = iController.GetPosition(clipPos1);
  1744 	User::After(KGetPositionIntervalLength);
  1745 	error += iController.GetPosition(clipPos2);
  1746 	User::After(KGetPositionIntervalLength);
  1747 	error += iController.GetPosition(clipPos3);
  1748 
  1749 	if(error)
  1750 		{
  1751 		// NB it's cumulative so don't give return value
  1752 		ERR_PRINTF1(_L("Error : GetPosition failed"));	
  1753 		return iTestStepResult = EInconclusive;
  1754 		}
  1755 
  1756 	INFO_PRINTF4(_L("Clip positions : %ld %ld %ld"), I64LOW(clipPos1.Int64()), I64LOW(clipPos2.Int64()), I64LOW(clipPos3.Int64()));
  1757 
  1758 	if((clipPos1 != clipPos2) && (clipPos2 != clipPos3))
  1759 		{
  1760 		ERR_PRINTF1(_L("Error : clip position still changing"));
  1761 		return iTestStepResult = EFail;
  1762 		}
  1763 
  1764 	if(clipPos3.Int64() != 0)
  1765 		{
  1766 		ERR_PRINTF1(_L("Error : clip position not at start"));
  1767 		return iTestStepResult = EFail;
  1768 		}
  1769 
  1770 	// EPass if we got here
  1771 	return iTestStepResult = EPass;
  1772 	}
  1773 
  1774 // ---------------------------
  1775 // RTestMmfCtlfrmI0124
  1776 //
  1777 // Pause
  1778 //
  1779 // REQ172.5.5.8
  1780 
  1781 RTestMmfCtlfrmI0124* RTestMmfCtlfrmI0124::NewL()
  1782 	{
  1783 	RTestMmfCtlfrmI0124* self = new(ELeave) RTestMmfCtlfrmI0124;
  1784 	return self;
  1785 	}
  1786 
  1787 RTestMmfCtlfrmI0124::RTestMmfCtlfrmI0124()
  1788 	{
  1789 	iTestStepName = _L("MM-MMF-CTLFRM-I-0124");
  1790 	}
  1791 
  1792 TVerdict RTestMmfCtlfrmI0124::DoTestStepL()
  1793 	{
  1794 	// Pause a controller. Must be playing first
  1795 	INFO_PRINTF1(_L("Pause a controller"));
  1796 
  1797 	TInt error = KErrNone;
  1798 	TVerdict result = EPass;
  1799 	
  1800 	error = iController.Prime();
  1801 	if(error)
  1802 		{
  1803 		ERR_PRINTF2(_L("Prime failed, error %d"), error);
  1804 		return iTestStepResult = EInconclusive;
  1805 		}
  1806 	
  1807 	// [ wait for and process the return event from the Custom audio controller ]
  1808 	TMMFEvent primeEvent( KPrimeTestId, KErrNone);
  1809 	result = SearchForEvent( primeEvent );
  1810 	if( result == EFail )
  1811 		{
  1812 		ERR_PRINTF1(_L("Custom audio controller did not return a prime event"));
  1813 		return iTestStepResult = EInconclusive;
  1814 		}
  1815 	
  1816     error = iController.Play();
  1817 	if(error)
  1818 		{
  1819 		ERR_PRINTF2(_L("Play failed, error %d"), error);
  1820 		return iTestStepResult = EInconclusive;
  1821 		}
  1822 
  1823 	// get an event from the Custom audio controller
  1824 	TMMFEvent playEvent( KPlayTestId, KErrNone);
  1825 	result = SearchForEvent( playEvent );
  1826 	if( result == EFail )
  1827 		{
  1828 		ERR_PRINTF1(_L("Custom audio controller did not return a play event"));
  1829 		return iTestStepResult = EFail;
  1830 		}
  1831 	
  1832 	// verify that clip is playing : get the position a couple of times
  1833 	// NB the clip must be at least 1 second long for this to work
  1834 
  1835 	TTimeIntervalMicroSeconds clipPos1, clipPos2, clipPos3;
  1836 	User::After(KGetPositionIntervalLength);
  1837 	error = iController.GetPosition(clipPos1);
  1838 	User::After(KGetPositionIntervalLength);
  1839 	error += iController.GetPosition(clipPos2);
  1840 	User::After(KGetPositionIntervalLength);
  1841 	error += iController.GetPosition(clipPos3);
  1842 
  1843 	if(error)
  1844 		{
  1845 		// NB it's cumulative so don't give return value
  1846 		ERR_PRINTF1(_L("Error : GetPosition failed"));	
  1847 		return iTestStepResult = EInconclusive;
  1848 		}
  1849 
  1850 	INFO_PRINTF4(_L("Clip positions : %ld %ld %ld"), I64LOW(clipPos1.Int64()), I64LOW(clipPos2.Int64()), I64LOW(clipPos3.Int64()));
  1851 
  1852 	if((clipPos1 == clipPos2) || (clipPos2 == clipPos3))
  1853 		{
  1854 		ERR_PRINTF1(_L("Error : clip position not changing"));
  1855 		return iTestStepResult = EInconclusive;
  1856 		}
  1857 
  1858 	// now pause the clip. verify that the position is not 0 and not changing.
  1859 	error = iController.Pause();
  1860 	if(error)
  1861 		{
  1862 		ERR_PRINTF2(_L("Pause failed, error %d"), error);
  1863 		return iTestStepResult = EFail;
  1864 		}
  1865 	
  1866 	// [ wait for and process the return event from the Custom audio controller ]
  1867 	TMMFEvent pauseEvent( KPauseTestId, KErrNone);
  1868 	result = SearchForEvent( pauseEvent );
  1869 	if( result == EFail )
  1870 		{
  1871 		ERR_PRINTF1(_L("Custom audio controller did not return a pause event"));
  1872 		return iTestStepResult = EFail;
  1873 		}
  1874 	
  1875  	// verify that clip is paused : get the position a couple of times
  1876 	User::After(KGetPositionIntervalLength);
  1877 	error = iController.GetPosition(clipPos1);
  1878 	User::After(KGetPositionIntervalLength);
  1879 	error += iController.GetPosition(clipPos2);
  1880 	User::After(KGetPositionIntervalLength);
  1881 	error += iController.GetPosition(clipPos3);
  1882 
  1883 	if(error)
  1884 		{
  1885 		// NB it's cumulative so don't give return value
  1886 		ERR_PRINTF1(_L("Error : GetPosition failed"));	
  1887 		return iTestStepResult = EInconclusive;
  1888 		}
  1889 
  1890 	INFO_PRINTF4(_L("Clip positions : %ld %ld %ld"), I64LOW(clipPos1.Int64()), I64LOW(clipPos2.Int64()), I64LOW(clipPos3.Int64()));
  1891 
  1892 	if((clipPos1 != clipPos2) || (clipPos2 != clipPos3))
  1893 		{
  1894 		ERR_PRINTF1(_L("Error : clip position still changing"));
  1895 		return iTestStepResult = EFail;
  1896 		}
  1897 
  1898 	if(clipPos2.Int64() == 0)
  1899 		{
  1900 		ERR_PRINTF1(_L("Error : clip position is zero"));
  1901 		return iTestStepResult = EFail;
  1902 		}
  1903 
  1904 	// EPass if we got here
  1905 	return iTestStepResult = EPass;
  1906 	}
  1907 
  1908 // ---------------------------
  1909 // RTestMmfCtlfrmI0125
  1910 //
  1911 // Assign priority to controller
  1912 //
  1913 // REQ172.5.5.9
  1914 
  1915 RTestMmfCtlfrmI0125* RTestMmfCtlfrmI0125::NewL()
  1916 	{
  1917 	RTestMmfCtlfrmI0125* self = new(ELeave) RTestMmfCtlfrmI0125;
  1918 	return self;
  1919 	}
  1920 
  1921 RTestMmfCtlfrmI0125::RTestMmfCtlfrmI0125()
  1922 	{
  1923 	iTestStepName = _L("MM-MMF-CTLFRM-I-0125");
  1924 	}
  1925 
  1926 TVerdict RTestMmfCtlfrmI0125::DoTestStepL()
  1927 	{
  1928 	INFO_PRINTF1(_L("Assign priority to controller"));
  1929 	TInt error = KErrNone;
  1930 
  1931 	// set priorities - 1 higher than 2
  1932 	iSettings.iPriority = 10;
  1933 	error = iController1.SetPrioritySettings(iSettings);
  1934 	if(error)
  1935 		{
  1936 		ERR_PRINTF2(_L("controller1 SetPrioritySettings failed, error %d"), error);
  1937 		return iTestStepResult = EInconclusive;
  1938 		}
  1939 
  1940 	iSettings.iPriority = -10;
  1941 	error = iController2.SetPrioritySettings(iSettings);
  1942 	if(error)
  1943 		{
  1944 		ERR_PRINTF2(_L("controller2 SetPrioritySettings failed, error %d"), error);
  1945 		return iTestStepResult = EInconclusive;
  1946 		}
  1947 
  1948 	// prime them
  1949 	error = iController1.Prime();
  1950 	if(error)
  1951 		{
  1952 		ERR_PRINTF2(_L("controller1 prime failed, error %d"), error);
  1953 		return iTestStepResult = EInconclusive;
  1954 		}
  1955 	error = iController2.Prime();
  1956 	if(error)
  1957 		{
  1958 		ERR_PRINTF2(_L("controller2 prime failed, error %d"), error);
  1959 		return iTestStepResult = EInconclusive;
  1960 		}
  1961 
  1962 	// at last we are ready to do the test...
  1963 	// play both controllers. give the first time to start before playing the second.
  1964 	// we should get an error.
  1965 	error = iController1.Play();
  1966 	if(error)
  1967 		{
  1968 		ERR_PRINTF2(_L("iController1 play failed, error %d"), error);
  1969 		return iTestStepResult = EInconclusive;
  1970 		}
  1971 	// wait a while, to give it chance to play
  1972 	const TTimeIntervalMicroSeconds32 KPlayPosition32 = 500000L;
  1973 	INFO_PRINTF2(_L("Waiting %d mcs..."), KPlayPosition32.Int());
  1974 	User::After(KPlayPosition32);
  1975 	error = iController2.Play();
  1976 	if(error)
  1977 		{
  1978 		ERR_PRINTF2(_L("iController2 play failed, error %d"), error);
  1979 		return iTestStepResult = EInconclusive;
  1980 		}
  1981 
  1982 	// search for a KErrInUse from anywhere on controller 2
  1983 	// this is from Audio Policy
  1984 	TMMFEvent inUseEvent( KMMFEventCategoryPlaybackComplete, KErrInUse );
  1985 	TVerdict result;
  1986 	result = SearchForEvent( inUseEvent, 2 );
  1987 	if( result == EFail )
  1988 		{
  1989 		ERR_PRINTF1(_L("Audio Policy did not return a KErrInUse event"));
  1990 		return iTestStepResult = EFail;
  1991 		}
  1992 	INFO_PRINTF1(_L("Audio Policy returned a KErrInUse event"));
  1993 
  1994 	// check that the position on controller1 is actually changing
  1995 	// and that the position on controller2 isn't
  1996 
  1997 	// NB this may fail - if iController2 is actually stopped. in that case
  1998 	// we just have to check that GetPosition returns an error
  1999 	TTimeIntervalMicroSeconds clipPos1a, clipPos1b, clipPos1c;
  2000 	TTimeIntervalMicroSeconds clipPos2a, clipPos2b, clipPos2c;
  2001 	User::After(KGetPositionIntervalLength);
  2002 	error = iController1.GetPosition(clipPos1a);
  2003 
  2004 	TInt ctrl2Error=KErrNone;
  2005 	ctrl2Error = iController2.GetPosition(clipPos2a);
  2006 	if(ctrl2Error)
  2007 		{
  2008 		ERR_PRINTF1(_L("Controller 2 GetPosition returned an Error"));
  2009 		return iTestStepResult = EFail;
  2010 		}
  2011 	
  2012 	User::After(KGetPositionIntervalLength);
  2013 	error += iController1.GetPosition(clipPos1b);
  2014 	ctrl2Error = iController2.GetPosition(clipPos2b);
  2015 	if(ctrl2Error)
  2016 		{
  2017 		ERR_PRINTF1(_L("Controller 2 GetPosition returned an Error"));
  2018 		return iTestStepResult = EFail;
  2019 		}
  2020 
  2021 	User::After(KGetPositionIntervalLength);
  2022 	error += iController1.GetPosition(clipPos1c);
  2023 	ctrl2Error = iController2.GetPosition(clipPos2c);
  2024 	if(ctrl2Error)
  2025 		{
  2026 		ERR_PRINTF1(_L("Controller 2 GetPosition returned an Error"));
  2027 		return iTestStepResult = EFail;
  2028 		}
  2029 	if(error)
  2030 		{
  2031 		// NB it's cumulative so don't give return value
  2032 		ERR_PRINTF1(_L("Error : GetPosition failed"));	
  2033 		return iTestStepResult = EInconclusive;
  2034 		}
  2035 
  2036 	INFO_PRINTF4(_L("Clip positions 1 : %d %d %d"), I64LOW(clipPos1a.Int64()), I64LOW(clipPos1b.Int64()), I64LOW(clipPos1c.Int64()));
  2037 	INFO_PRINTF4(_L("Clip positions 2 : %d %d %d"), I64LOW(clipPos2a.Int64()), I64LOW(clipPos2b.Int64()), I64LOW(clipPos2c.Int64()));
  2038 
  2039 	if((clipPos1a == clipPos1b) || (clipPos1b == clipPos1c))
  2040 		{
  2041 		ERR_PRINTF1(_L("Error : clip position 1 not changing"));
  2042 		return iTestStepResult = EFail;
  2043 		}
  2044     if(clipPos2a != clipPos2b || clipPos2b != clipPos2c)
  2045         {
  2046         ERR_PRINTF1(_L("Controller 2 position changed"));
  2047         return iTestStepResult = EFail;
  2048         }
  2049 	// ok - now do the same the other way up - set controller 2 priority higher than 
  2050 	// controller 1
  2051 	iController1.Stop();
  2052 	iController2.Stop();
  2053 
  2054 
  2055 	iSettings.iPriority = -10;
  2056 	error = iController1.SetPrioritySettings(iSettings);
  2057 	if(error)
  2058 		{
  2059 		ERR_PRINTF2(_L("controller1 SetPrioritySettings failed, error %d"), error);
  2060 		return iTestStepResult = EInconclusive;
  2061 		}
  2062 
  2063 	iSettings.iPriority = 10;
  2064 	error = iController2.SetPrioritySettings(iSettings);
  2065 	if(error)
  2066 		{
  2067 		ERR_PRINTF2(_L("controller2 SetPrioritySettings failed, error %d"), error);
  2068 		return iTestStepResult = EInconclusive;
  2069 		}
  2070 
  2071 	// prime them
  2072 	error = iController1.Prime();
  2073 	if(error)
  2074 		{
  2075 		ERR_PRINTF2(_L("controller1 prime failed, error %d"), error);
  2076 		return iTestStepResult = EInconclusive;
  2077 		}
  2078 	error = iController2.Prime();
  2079 	if(error)
  2080 		{
  2081 		ERR_PRINTF2(_L("controller2 prime failed, error %d"), error);
  2082 		return iTestStepResult = EInconclusive;
  2083 		}
  2084 
  2085 	// play both controllers. give the first time to start before playing the second.
  2086 	// we should get an error.
  2087 	error = iController1.Play();
  2088 	if(error)
  2089 		{
  2090 		ERR_PRINTF2(_L("iController1 play failed, error %d"), error);
  2091 		return iTestStepResult = EInconclusive;
  2092 		}
  2093 	// wait a while, to give it chance to play
  2094 	INFO_PRINTF2(_L("Waiting %d mcs..."), KPlayPosition32.Int());
  2095 	User::After(KPlayPosition32);
  2096 	error = iController2.Play();
  2097 	if(error)
  2098 		{
  2099 		ERR_PRINTF2(_L("iController2 play failed, error %d"), error);
  2100 		return iTestStepResult = EInconclusive;
  2101 		}
  2102 
  2103 	// *** Test Changed - originally searched for a KErrAccessDenied
  2104 	// from anywhere on controller 1
  2105 	// BUT since controller 1 is already playing, this isn't appropriate
  2106 	// Instead we search for a KErrCancel event from controller 1;
  2107 	// this should be passed through the Custom Audio Controller and arrive
  2108 	// with uid KMMFEventCategoryPlaybackComplete
  2109 
  2110 
  2111 	// Search for the event caused by playing the higher priority controller
  2112 	inUseEvent.iEventType = KMMFEventCategoryPlaybackComplete;
  2113 	result = SearchForEvent( inUseEvent, 1 );
  2114 	if( result == EFail )
  2115 		{
  2116 		ERR_PRINTF1(_L("Audio Policy did not return a KErrInUse event"));
  2117 		return iTestStepResult = EFail;
  2118 		}
  2119 	INFO_PRINTF1(_L("Audio Policy returned a KErrInUse event"));
  2120 
  2121 
  2122 	// check that the position on controller2 is actually changing
  2123 	// and that the position on controller1 isn't
  2124 	User::After(KGetPositionIntervalLength);
  2125 
  2126 	TInt ctrlError1=KErrNone;
  2127 	ctrlError1 = iController1.GetPosition(clipPos1a);
  2128 	if(ctrlError1)
  2129 		{
  2130 		ERR_PRINTF1(_L("Controller 1 GetPosition returned an Error"));
  2131 		return iTestStepResult = EFail;
  2132 		}
  2133 
  2134 	error = iController2.GetPosition(clipPos2a);
  2135 	User::After(KGetPositionIntervalLength);
  2136 	ctrlError1 = iController1.GetPosition(clipPos1b);
  2137 	if(ctrlError1)
  2138 		{
  2139 		ERR_PRINTF1(_L("Controller 1 GetPosition returned an Error"));
  2140 		return iTestStepResult = EFail;
  2141 		}
  2142 
  2143 	error += iController2.GetPosition(clipPos2b);
  2144 	User::After(KGetPositionIntervalLength);
  2145 	ctrlError1 = iController1.GetPosition(clipPos1c);
  2146 	if(ctrlError1)
  2147 		{
  2148 		ERR_PRINTF1(_L("Controller 1 GetPosition returned an Error"));
  2149 		return iTestStepResult = EFail;
  2150 		}
  2151 
  2152 	error += iController2.GetPosition(clipPos2c);
  2153 
  2154 	if(error)
  2155 		{
  2156 		// NB it's cumulative so don't give return value
  2157 		ERR_PRINTF1(_L("Error : GetPosition failed"));	
  2158 		return iTestStepResult = EInconclusive;
  2159 		}
  2160 
  2161 	INFO_PRINTF4(_L("Clip positions 1 : %d %d %d"), I64LOW(clipPos1a.Int64()), I64LOW(clipPos1b.Int64()), I64LOW(clipPos1c.Int64()));
  2162 	INFO_PRINTF4(_L("Clip positions 2 : %d %d %d"), I64LOW(clipPos2a.Int64()), I64LOW(clipPos2b.Int64()), I64LOW(clipPos2c.Int64()));
  2163 
  2164 	if((clipPos2a == clipPos2b) || (clipPos2b == clipPos2c))
  2165 		{
  2166 		ERR_PRINTF1(_L("Error : clip position 2 not changing"));
  2167 		return iTestStepResult = EFail;
  2168 		}
  2169     if(clipPos1a != clipPos1b || clipPos1b != clipPos1c)
  2170         {
  2171         ERR_PRINTF1(_L("Controller 1 position changed"));
  2172         return iTestStepResult = EFail;
  2173         }
  2174 	return iTestStepResult = EPass;
  2175 	}
  2176 
  2177 
  2178 // ---------------------------
  2179 // RTestMmfCtlfrmI0128
  2180 //
  2181 // Get position
  2182 //
  2183 // REQ172.5.5.10
  2184 
  2185 RTestMmfCtlfrmI0128* RTestMmfCtlfrmI0128::NewL()
  2186 	{
  2187 	RTestMmfCtlfrmI0128* self = new(ELeave) RTestMmfCtlfrmI0128;
  2188 	return self;
  2189 	}
  2190 
  2191 RTestMmfCtlfrmI0128::RTestMmfCtlfrmI0128()
  2192 	{
  2193 	iTestStepName = _L("MM-MMF-CTLFRM-I-0128");
  2194 	}
  2195 
  2196 TVerdict RTestMmfCtlfrmI0128::DoTestStepL()
  2197 	{
  2198  	// Get position
  2199 	INFO_PRINTF1(_L("Get Position"));
  2200 
  2201 	TInt error = KErrNone;
  2202 	TVerdict result = EPass;
  2203 	
  2204 	// 1. before playing, verify that GetPosition returns start
  2205 	// 2. set to known position, verify that GetPosition returns correct position
  2206 	// 3. set to start, play for N seconds, check position is approx as expected
  2207 
  2208 	error = iController.Prime();
  2209 	if(error)
  2210 		{
  2211 		ERR_PRINTF2(_L("Prime failed, error %d"), error);
  2212 		return iTestStepResult = EInconclusive;
  2213 		}
  2214 	
  2215 	// [ wait for and process the return event from the Custom audio controller ]
  2216 	TMMFEvent primeEvent( KPrimeTestId, KErrNone);
  2217 	result = SearchForEvent( primeEvent );
  2218 	if( result == EFail )
  2219 		{
  2220 		ERR_PRINTF1(_L("Custom audio controller did not return a prime event"));
  2221 		return iTestStepResult = EInconclusive;
  2222 		}
  2223 	
  2224  	// 1. verify that clip is at position 0
  2225 	TTimeIntervalMicroSeconds clipPos;
  2226 	error = iController.GetPosition(clipPos);
  2227 
  2228 	if(error)
  2229 		{
  2230 		ERR_PRINTF2(_L("Error : GetPosition failed, error %d"), error);	
  2231 		return iTestStepResult = EFail;
  2232 		}
  2233 
  2234 	INFO_PRINTF2(_L("Clip position : %ld"), I64LOW(clipPos.Int64()));
  2235 	if(clipPos.Int64() != 0)
  2236 		{
  2237 		ERR_PRINTF1(_L("Error : clip position not at start"));
  2238 		return iTestStepResult = EFail;
  2239 		}
  2240 
  2241  	// 2. set position and verify that clip is there
  2242 	// NB allow for resolution of the controller itself
  2243 	const TTimeIntervalMicroSeconds KPlayPosition(2000000);
  2244 	const TTimeIntervalMicroSeconds KPlayPositionPlusError(3000000);
  2245 	const TTimeIntervalMicroSeconds KPlayPositionMinusError(1000000); // allow +/1 sec
  2246 	const TTimeIntervalMicroSeconds32 KPlayPosition32 = 2000000L; // for User::After
  2247 	error = iController.SetPosition(KPlayPosition);
  2248 	if(error)
  2249 		{
  2250 		ERR_PRINTF2(_L("SetPosition failed, error %d"), error);
  2251 		return iTestStepResult = EInconclusive;
  2252 		}
  2253 
  2254 	error = iController.GetPosition(clipPos);
  2255 	if(error)
  2256 		{
  2257 		ERR_PRINTF2(_L("Error : GetPosition failed, error %d"), error);	
  2258 		return iTestStepResult = EFail;
  2259 		}
  2260 
  2261 	INFO_PRINTF3(_L("Clip position : %ld Expected : %ld"), I64LOW(clipPos.Int64()), I64LOW(KPlayPosition.Int64()));
  2262 	if( (clipPos < (KPlayPositionMinusError)) || (clipPos > (KPlayPositionPlusError)) )
  2263 		{
  2264 		ERR_PRINTF1(_L("Error : clip position not set correctly"));
  2265 		return iTestStepResult = EFail;
  2266 		}
  2267 
  2268 	// 3. set position to start, play clip for a time span, and verify that its position is approx. correct
  2269 	const TTimeIntervalMicroSeconds KStartPosition(0);
  2270     error = iController.SetPosition(KStartPosition);
  2271 	if(error)
  2272 		{
  2273 		ERR_PRINTF2(_L("SetPosition failed, error %d"), error);
  2274 		return iTestStepResult = EInconclusive;
  2275 		}
  2276 
  2277 	error = iController.GetPosition(clipPos);
  2278 	if(error)
  2279 		{
  2280 		ERR_PRINTF2(_L("Error : GetPosition failed, error %d"), error);	
  2281 		return iTestStepResult = EFail;
  2282 		}
  2283 
  2284 	INFO_PRINTF2(_L("Clip position : %ld"), I64LOW(clipPos.Int64()));
  2285 	if(clipPos != KStartPosition)
  2286 		{
  2287 		ERR_PRINTF1(_L("Error : clip position not at start"));
  2288 		return iTestStepResult = EFail;
  2289 		}
  2290 
  2291 	error = iController.Play();
  2292 	if(error)
  2293 		{
  2294 		ERR_PRINTF2(_L("Play failed, error %d"), error);
  2295 		return iTestStepResult = EInconclusive;
  2296 		}
  2297 	TMMFEvent playEvent( KPlayTestId, KErrNone);
  2298 	result = SearchForEvent( playEvent );
  2299 	if( result == EFail )
  2300 		{
  2301 		ERR_PRINTF1(_L("Custom audio controller did not return a play event"));
  2302 		return iTestStepResult = EInconclusive;
  2303 		}
  2304 	
  2305 	TTimeIntervalMicroSeconds clipPosStart;
  2306 	error = iController.GetPosition(clipPosStart);
  2307 	if(error)
  2308 		{
  2309 		ERR_PRINTF2(_L("Error : GetPosition failed, error %d"), error);	
  2310 		return iTestStepResult = EInconclusive;
  2311 		}
  2312 
  2313 	INFO_PRINTF2(_L("Clip position : %ld"), I64LOW(clipPosStart.Int64()));
  2314 
  2315 	// wait, then get pos again
  2316 	User::After(KPlayPosition32);
  2317 
  2318 	error = iController.GetPosition(clipPos);
  2319 	if(error)
  2320 		{
  2321 		ERR_PRINTF2(_L("Error : GetPosition failed, error %d"), error);	
  2322 		return iTestStepResult = EFail;
  2323 		}
  2324 
  2325 	TTimeIntervalMicroSeconds clipPosPlayedFor = clipPos;
  2326 	clipPosPlayedFor = clipPosPlayedFor.Int64() - clipPosStart.Int64();
  2327 
  2328 	TTimeIntervalMicroSeconds clipPosExpected = KPlayPosition;
  2329 	clipPosExpected = clipPosExpected.Int64() + clipPosStart.Int64();
  2330 
  2331 	INFO_PRINTF3(_L("Clip position : %ld Expected : %ld"), I64LOW(clipPos.Int64()), I64LOW(clipPosExpected.Int64()));
  2332 	if( (clipPosPlayedFor < (KPlayPositionMinusError)) || (clipPosPlayedFor > (KPlayPositionPlusError)) )
  2333 		{
  2334 		ERR_PRINTF1(_L("Error : clip position not correct"));
  2335 		return iTestStepResult = EFail;
  2336 		}
  2337 
  2338 	// EPass if we got here
  2339 	return iTestStepResult = EPass;
  2340 	}
  2341 
  2342 // ---------------------------
  2343 // RTestMmfCtlfrmI0129
  2344 //
  2345 // Set position
  2346 //
  2347 // REQ172.5.5.11
  2348 
  2349 RTestMmfCtlfrmI0129* RTestMmfCtlfrmI0129::NewL()
  2350 	{
  2351 	RTestMmfCtlfrmI0129* self = new(ELeave) RTestMmfCtlfrmI0129;
  2352 	return self;
  2353 	}
  2354 
  2355 RTestMmfCtlfrmI0129::RTestMmfCtlfrmI0129()
  2356 	{
  2357 	iTestStepName = _L("MM-MMF-CTLFRM-I-0129");
  2358 	}
  2359 
  2360 TVerdict RTestMmfCtlfrmI0129::DoTestStepL()
  2361 	{
  2362 	// Set position
  2363 	INFO_PRINTF1(_L("Set Position"));
  2364 
  2365 	TInt error = KErrNone;
  2366 	TVerdict result = EPass;
  2367 	
  2368 	// set to known position, verify that GetPosition returns correct position
  2369 
  2370 	error = iController.Prime();
  2371 	if(error)
  2372 		{
  2373 		ERR_PRINTF2(_L("Prime failed, error %d"), error);
  2374 		return iTestStepResult = EInconclusive;
  2375 		}
  2376 	
  2377 	// [ wait for and process the return event from the Custom audio controller ]
  2378 	TMMFEvent primeEvent( KPrimeTestId, KErrNone);
  2379 	result = SearchForEvent( primeEvent );
  2380 	if( result == EFail )
  2381 		{
  2382 		ERR_PRINTF1(_L("Custom audio controller did not return a prime event"));
  2383 		return iTestStepResult = EInconclusive;
  2384 		}
  2385 	
  2386  	// 2. set position and verify that clip is there
  2387 	// NB allow for resolution of the controller itself
  2388 	const TTimeIntervalMicroSeconds KPlayPosition(2000000);
  2389 	const TTimeIntervalMicroSeconds KPlayPositionPlusError(2500000);
  2390 	const TTimeIntervalMicroSeconds KPlayPositionMinusError(1500000); // allow +/-0.5 sec
  2391 	error = iController.SetPosition(KPlayPosition);
  2392 	if(error)
  2393 		{
  2394 		ERR_PRINTF2(_L("SetPosition failed, error %d"), error);
  2395 		return iTestStepResult = EFail;
  2396 		}
  2397 
  2398 	TTimeIntervalMicroSeconds clipPos;
  2399 	error = iController.GetPosition(clipPos);
  2400 	if(error)
  2401 		{
  2402 		ERR_PRINTF2(_L("Error : GetPosition failed, error %d"), error);	
  2403 		return iTestStepResult = EInconclusive;
  2404 		}
  2405 
  2406 	INFO_PRINTF3(_L("Clip position : %ld Expected : %ld"), I64LOW(clipPos.Int64()), I64LOW(KPlayPosition.Int64()));
  2407 	if( (clipPos < (KPlayPositionMinusError)) || (clipPos > (KPlayPositionPlusError)) )
  2408 		{
  2409 		ERR_PRINTF1(_L("Error : clip position not set correctly"));
  2410 		return iTestStepResult = EFail;
  2411 		}
  2412 	   
  2413 	// EPass if we got here
  2414 	return iTestStepResult = EPass;
  2415 	}
  2416 
  2417 // ---------------------------
  2418 // RTestMmfCtlfrmI0131
  2419 //
  2420 // Reset controller
  2421 //
  2422 // REQ172.5.5.12
  2423 
  2424 RTestMmfCtlfrmI0131* RTestMmfCtlfrmI0131::NewL()
  2425 	{
  2426 	RTestMmfCtlfrmI0131* self = new(ELeave) RTestMmfCtlfrmI0131;
  2427 	return self;
  2428 	}
  2429 
  2430 RTestMmfCtlfrmI0131::RTestMmfCtlfrmI0131()
  2431 	{
  2432 	iTestStepName = _L("MM-MMF-CTLFRM-I-0131");
  2433 	}
  2434 
  2435 TVerdict RTestMmfCtlfrmI0131::DoTestStepL()
  2436 	{
  2437 	INFO_PRINTF1(_L("Reset"));
  2438 
  2439 	TInt error = KErrNone;
  2440 	
  2441 	// reset the controller; verify that source and sink are no longer present, and that
  2442 	// it is not primed.
  2443 
  2444 	error = iController.Reset();
  2445 	if(error)
  2446 		{
  2447 		ERR_PRINTF2(_L("Error : Reset failed, error %d"), error);	
  2448 		return iTestStepResult = EFail;
  2449 		}
  2450 
  2451 	// try and play : we should get an error KErrNotReady
  2452 	error = iController.Play();
  2453 	if(error != KErrNotReady)
  2454 		{
  2455 		ERR_PRINTF2(_L("Error : play returned unexpected code %d"), error);	
  2456 		return iTestStepResult = EFail;
  2457 		}
  2458 	INFO_PRINTF1(_L("Attempt to play controller failed with KErrNotReady"));	
  2459 
  2460 	// try and remove data source : we should get an error KErrNotFound
  2461 	TMMFMessageDestination& sourceHandle = *iSourceHandlePtr;
  2462 	error = iController.RemoveDataSource(sourceHandle);
  2463 	if(error != KErrNotFound)
  2464 		{
  2465 		ERR_PRINTF2(_L("Error : remove data source returned unexpected code %d"), error);	
  2466 		return iTestStepResult = EFail;
  2467 		}
  2468 	INFO_PRINTF1(_L("Attempt to remove data source failed with KErrNotFound"));	
  2469 
  2470 	// try and remove data sink : we should get an error KErrNotFound
  2471 	TMMFMessageDestination& sinkHandle = *iSinkHandlePtr;
  2472 	error = iController.RemoveDataSink(sinkHandle);
  2473 	if(error != KErrNotFound)
  2474 		{
  2475 		ERR_PRINTF2(_L("Error : remove data sink returned unexpected code %d"), error);	
  2476 		return iTestStepResult = EFail;
  2477 		}
  2478 	INFO_PRINTF1(_L("Attempt to remove data sink failed with KErrNotFound"));	
  2479 
  2480 	// EPass if we got here
  2481 	return iTestStepResult = EPass;
  2482 	}
  2483 
  2484 // ---------------------------
  2485 // RTestMmfCtlfrmI0132
  2486 //
  2487 // Close controller
  2488 //
  2489 // REQ172.5.5.12
  2490 
  2491 RTestMmfCtlfrmI0132* RTestMmfCtlfrmI0132::NewL()
  2492 	{
  2493 	RTestMmfCtlfrmI0132* self = new(ELeave) RTestMmfCtlfrmI0132;
  2494 	return self;
  2495 	}
  2496 
  2497 RTestMmfCtlfrmI0132::RTestMmfCtlfrmI0132()
  2498 	{
  2499 	iTestStepName = _L("MM-MMF-CTLFRM-I-0132");
  2500 	}
  2501 
  2502 TVerdict RTestMmfCtlfrmI0132::DoTestStepL()
  2503 	{
  2504 	// Reset
  2505 	INFO_PRINTF1(_L("Close"));
  2506 
  2507 	TInt error = KErrNone;
  2508 	
  2509 	// close the controller; verify that source and sink are no longer present, and that
  2510 	// it is not primed.
  2511 
  2512 	iController.Close();
  2513 	// returns no error
  2514 
  2515 	// try and prime : we should get an error KErrNotReady
  2516 	error = iController.Prime();
  2517 	if(error != KErrNotReady)
  2518 		{
  2519 		ERR_PRINTF2(_L("Error : prime returned unexpected code %d"), error);	
  2520 		return iTestStepResult = EFail;
  2521 		}
  2522 	INFO_PRINTF1(_L("Attempt to prime controller failed with KErrNotReady"));	
  2523 	// try and play : we should get an error KErrNotReady
  2524 	error = iController.Play();
  2525 	if(error != KErrNotReady)
  2526 		{
  2527 		ERR_PRINTF2(_L("Error : play returned unexpected code %d"), error);	
  2528 		return iTestStepResult = EFail;
  2529 		}
  2530 	INFO_PRINTF1(_L("Attempt to play controller failed with KErrNotReady"));	
  2531 
  2532 	// try and remove data source : we should get an error KErrNotReady
  2533 	TMMFMessageDestination& sourceHandle = *iSourceHandlePtr;
  2534 	error = iController.RemoveDataSource(sourceHandle);
  2535 	if(error != KErrNotReady)
  2536 		{
  2537 		ERR_PRINTF2(_L("Error : remove data source returned unexpected code %d"), error);	
  2538 		return iTestStepResult = EFail;
  2539 		}
  2540 	INFO_PRINTF1(_L("Attempt to remove data source failed with KErrNotReady"));	
  2541 
  2542 	// try and remove data sink : we should get an error KErrNotReady
  2543 	TMMFMessageDestination& sinkHandle = *iSinkHandlePtr;
  2544 	error = iController.RemoveDataSink(sinkHandle);
  2545 	if(error != KErrNotReady)
  2546 		{
  2547 		ERR_PRINTF2(_L("Error : remove data sink returned unexpected code %d"), error);	
  2548 		return iTestStepResult = EFail;
  2549 		}
  2550 	INFO_PRINTF1(_L("Attempt to remove data sink failed with KErrNotReady"));	
  2551 
  2552 	// EPass if we got here
  2553 	return iTestStepResult = EPass;
  2554 	}
  2555 
  2556 // ---------------------------
  2557 // RTestMmfCtlfrmI0141
  2558 //
  2559 // Event notification
  2560 //
  2561 // REQ172.5.5.13
  2562 
  2563 RTestMmfCtlfrmI0141* RTestMmfCtlfrmI0141::NewL()
  2564 	{
  2565 	RTestMmfCtlfrmI0141* self = new(ELeave) RTestMmfCtlfrmI0141;
  2566 	return self;
  2567 	}
  2568 
  2569 RTestMmfCtlfrmI0141::RTestMmfCtlfrmI0141()
  2570 	{
  2571 	iTestStepName = _L("MM-MMF-CTLFRM-I-0141");
  2572 	}
  2573 
  2574 TVerdict RTestMmfCtlfrmI0141::DoTestStepL()
  2575 	{
  2576 	// NB : if event search is disabled, we can't run this test - but unlike other
  2577 	// tests which can pass without SearchForEvent being called, this one can't.
  2578 #ifdef EVENT_SEARCH_DISABLED
  2579 	ERR_PRINTF1(_L("SearchForEvent disabled, we can't run this test"));
  2580 	return iTestStepResult = EInconclusive;
  2581 
  2582 #else
  2583 	INFO_PRINTF1(_L("Receive Events"));
  2584 
  2585 	TInt error = KErrNone;
  2586 	TVerdict result = EPass;
  2587 	
  2588 	error = iController.Prime();
  2589 	if(error)
  2590 		{
  2591 		ERR_PRINTF2(_L("Prime failed, error %d"), error);
  2592 		return iTestStepResult = EFail;
  2593 		}
  2594 
  2595 	// SearchForEvent() calls ReceiveEvents() and waits until the event is received
  2596 	// or times out.
  2597 	TMMFEvent primeEvent( KPrimeTestId, KErrNone);
  2598 	result = SearchForEvent( primeEvent );
  2599 	if( result != EPass )
  2600 		{
  2601 		ERR_PRINTF1(_L("Event request did not find the event"));
  2602 		return iTestStepResult = result;
  2603 		}
  2604 
  2605 	// we pass if we receive the event
  2606 	INFO_PRINTF1(_L("Event request succeeded"));
  2607 	
  2608 	// EPass if we got here
  2609 	return iTestStepResult = EPass;
  2610 
  2611 #endif // EVENT_SEARCH_DISABLED
  2612 	}
  2613 
  2614 // ---------------------------
  2615 // RTestMmfCtlfrmI0142
  2616 //
  2617 // Cancel event notification
  2618 //
  2619 // REQ172.5.5.13
  2620 
  2621 RTestMmfCtlfrmI0142* RTestMmfCtlfrmI0142::NewL()
  2622 	{
  2623 	RTestMmfCtlfrmI0142* self = new(ELeave) RTestMmfCtlfrmI0142;
  2624 	return self;
  2625 	}
  2626 
  2627 RTestMmfCtlfrmI0142::RTestMmfCtlfrmI0142()
  2628 	{
  2629 	iTestStepName = _L("MM-MMF-CTLFRM-I-0142");
  2630 	}
  2631 
  2632 // SearchForEventWithCancel() is a modified version of SearchForEvent() which
  2633 // calls ReceiveEvents() but then calls CancelReceiveEvents() before waiting for the request.
  2634 // It will return EPass if, and only if, the request times out.
  2635 TVerdict RTestMmfCtlfrmI0142::SearchForEventWithCancel( TMMFEvent& aEvent )
  2636 	{
  2637 	TVerdict result = EPass;
  2638 	
  2639 	TRequestStatus timerStatus;
  2640 	TRequestStatus eventStatus;
  2641 
  2642 	RTimer  myTimer;
  2643 	TInt err = myTimer.CreateLocal();
  2644 	if(err)
  2645 		{
  2646 		ERR_PRINTF1(_L("Error : could not create local timer in SearchForEventWithCancel"));
  2647 		return EFail;
  2648 		}
  2649 	
  2650 	// NOTE. This test is somewhat spurious - we cannot call ReceiveEvents() without getting
  2651 	// an event back even if we call ReceiveEvents() straight afterwards. 
  2652 	
  2653 	// Therefore we don't call ReceiveEvents() here. Instead we call
  2654 	// CancelEvents() straight away, and set eventStatus to KRequestPending to ensure we get
  2655 	// a timeout from the 'request'.
  2656 
  2657 	// This is still a valid test as long as we precede it in DoTestStepL() with a call to
  2658 	// SearchForEvent() to show that the event mechanism is working.
  2659 
  2660     TMMFEventPckg receivedEvent;
  2661 	
  2662 	// event values for audio controller testing
  2663 	const TInt KDelay            = 1000000;
  2664 	const TInt KMaxRetries       = 1;
  2665 
  2666 	// for KMaxRetries attempt to find the event
  2667 	for( TInt retries = 0; retries < KMaxRetries; retries++ )
  2668 		{
  2669 		eventStatus = KRequestPending;
  2670 		// now cancel receive events before we have a chance to receive any!
  2671 		CancelReceivedEvents();
  2672 		
  2673 		// start breakout timer to escape
  2674 		myTimer.After( timerStatus, KDelay );
  2675 		// wait for an event to mature
  2676 		User::WaitForRequest( eventStatus, timerStatus );
  2677 		
  2678 		// fail if we get an event. pass if we timeout
  2679         if( IsTimeOut( eventStatus ))
  2680 			{
  2681 			CancelReceivedEvents();
  2682 			}
  2683 		else 
  2684 			{
  2685 			if( IsSoughtEvent( aEvent, receivedEvent ) )
  2686 				{
  2687 				User::Check();
  2688 				myTimer.Cancel();
  2689 				// set status to FAIL since we have found the event
  2690 				return EFail;
  2691 				}
  2692 			else
  2693 				{
  2694 				// we've received an event other than the one expected.
  2695 				// we aren't expecting to receive events at all, so this too is a fail
  2696 				myTimer.Cancel();
  2697 				return EFail;
  2698 				}
  2699 			}
  2700 		}
  2701     return result;
  2702 	}
  2703 
  2704 TVerdict RTestMmfCtlfrmI0142::DoTestStepL()
  2705 	{
  2706 	// NB : if event search is disabled, we can't run this test - but unlike other
  2707 	// tests which can pass without SearchForEvent being called, this one can't.
  2708 #ifdef EVENT_SEARCH_DISABLED
  2709 	ERR_PRINTF1(_L("SearchForEvent disabled, we can't run this test"));
  2710 	return iTestStepResult = EInconclusive;
  2711 
  2712 #else
  2713 	INFO_PRINTF1(_L("Cancel receive events"));
  2714 
  2715 	TInt error = KErrNone;
  2716 	TVerdict result = EPass;
  2717 	
  2718 	error = iController.Prime();
  2719 	if(error)
  2720 		{
  2721 		ERR_PRINTF2(_L("Prime failed, error %d"), error);
  2722 		return iTestStepResult = EFail;
  2723 		}
  2724 	
  2725 	// Get an event first, to ensure that the mechanism is working.
  2726 	TMMFEvent primeEvent( KPrimeTestId, KErrNone);
  2727 	result = SearchForEvent( primeEvent );
  2728 	if( result != EPass )
  2729 		{
  2730 		ERR_PRINTF1(_L("First event request timed out"));
  2731 		return iTestStepResult = result;
  2732 		}
  2733 	INFO_PRINTF1(_L("First event request succeeded"));
  2734 
  2735 	// SearchForEventWithCancel() is an override which doesn't actually get an event at all.
  2736 	TMMFEvent primeEvent2( KPrimeTestId, KErrNone);
  2737 	result = SearchForEventWithCancel( primeEvent2 );
  2738 	if( result != EPass )
  2739 		{
  2740 		ERR_PRINTF1(_L("Second event request did NOT timeout"));
  2741 		return iTestStepResult = result;
  2742 		}
  2743 
  2744 	// we pass if we don't receive an event
  2745 	INFO_PRINTF1(_L("Second event request timed out"));
  2746 	
  2747 	// EPass if we got here
  2748 	return iTestStepResult = EPass;
  2749 
  2750 #endif // EVENT_SEARCH_DISABLED
  2751 	}
  2752 
  2753 // ---------------------------
  2754 // RTestMmfCtlfrmI0143
  2755 //
  2756 // Custom commands (synchronous)
  2757 //
  2758 // REQ172.5.5.14
  2759 
  2760 RTestMmfCtlfrmI0143* RTestMmfCtlfrmI0143::NewL()
  2761 	{
  2762 	RTestMmfCtlfrmI0143* self = new(ELeave) RTestMmfCtlfrmI0143;
  2763 	return self;
  2764 	}
  2765 
  2766 RTestMmfCtlfrmI0143::RTestMmfCtlfrmI0143()
  2767 	{
  2768 	iTestStepName = _L("MM-MMF-CTLFRM-I-0143");
  2769 	}
  2770 
  2771 TVerdict RTestMmfCtlfrmI0143::DoTestStepL()
  2772 	{
  2773 	INFO_PRINTF1(_L("Custom Command (sync)"));
  2774 
  2775 	TInt error = KErrNone;
  2776 
  2777 	TUid uid = {KTSIMmfControllerUid};
  2778 	TMMFMessageDestination handleInfo(uid);
  2779 	TMMFMessageDestinationPckg messageDest(handleInfo);
  2780 
  2781 	// call CustomCommandSync
  2782 	error = iController.CustomCommandSync(messageDest, KDummyFunc1, KNullDesC8, KNullDesC8);
  2783 	if(error == KDummyFunc1Return)
  2784 		error = KErrNone;
  2785 	else
  2786 		{
  2787 		ERR_PRINTF2(_L("CustomCommandSync KDummyFunc1 returned unexpected value %d"), error);
  2788 		return iTestStepResult = EFail;
  2789 		}
  2790 	INFO_PRINTF2(_L("CustomCommandSync KDummyFunc1 returned expected value %d"), KDummyFunc1Return);
  2791 
  2792 	// now call the log - to test CustomCommandSync with aDataFrom
  2793 	_LIT8(KExpectedResult, "DummyFunc1 Called");
  2794 	TBuf8<KTextBufLen> memFunctionText;
  2795 
  2796 	error = iController.CustomCommandSync(messageDest, KLogFunction, KNullDesC8, KNullDesC8, memFunctionText);
  2797 	if (error)
  2798 		{
  2799 		ERR_PRINTF2(_L("CustomCommandSync failed with error %d"), error);
  2800 		return iTestStepResult = EFail;
  2801 		}
  2802 		
  2803 	TBuf<KTextBufLen> memFunctionText16;
  2804 	memFunctionText16.SetMax();
  2805 	memFunctionText16.Fill(0x0);
  2806 	memFunctionText16.Copy(memFunctionText);
  2807 	INFO_PRINTF2(_L("Log : %S"), &memFunctionText16);
  2808 
  2809 	if (memFunctionText != KExpectedResult)
  2810 		{
  2811 		ERR_PRINTF1(_L("Return value did not match expected"));
  2812 		return iTestStepResult = EFail;
  2813 		}
  2814 
  2815 	// this is simply to ensure that all variations of ReadDataNFromClient*() are called
  2816 	// SetControllerMode() in TSI_MmfController does this.
  2817 	error = iController.CustomCommandSync(messageDest, KModeFunction, KNullDesC8, KNullDesC8, memFunctionText);
  2818 	if (error)
  2819 		{
  2820 		ERR_PRINTF2(_L("CustomCommandSync failed with error %d"), error);
  2821 		return iTestStepResult = EFail;
  2822 		}
  2823 		// now call the log - to test CustomCommandSync with aDataFrom
  2824 	_LIT8(KExpectedResultModePass, "SetControllerMode completed successfully");
  2825 	error = iController.CustomCommandSync(messageDest, KLogFunction, KNullDesC8, KNullDesC8, memFunctionText);
  2826 	if (error)
  2827 		{
  2828 		ERR_PRINTF2(_L("CustomCommandSync failed with error %d"), error);
  2829 		return iTestStepResult = EFail;
  2830 		}
  2831 	memFunctionText16.SetMax();
  2832 	memFunctionText16.Fill(0x0);
  2833 	memFunctionText16.Copy(memFunctionText);
  2834 	INFO_PRINTF2(_L("Log : %S"), &memFunctionText16);
  2835 
  2836 	if (memFunctionText != KExpectedResultModePass)
  2837 		return iTestStepResult = EFail;
  2838 
  2839 	return iTestStepResult = EPass;
  2840 	}
  2841 
  2842 // ---------------------------
  2843 // RTestMmfCtlfrmI0144
  2844 //
  2845 // Custom commands (asynchronous)
  2846 //
  2847 // REQ172.5.5.1
  2848 
  2849 RTestMmfCtlfrmI0144* RTestMmfCtlfrmI0144::NewL()
  2850 	{
  2851 	RTestMmfCtlfrmI0144* self = new(ELeave) RTestMmfCtlfrmI0144;
  2852 	return self;
  2853 	}
  2854 
  2855 RTestMmfCtlfrmI0144::RTestMmfCtlfrmI0144()
  2856 	{
  2857 	iTestStepName = _L("MM-MMF-CTLFRM-I-0144");
  2858 	}
  2859 
  2860 TVerdict RTestMmfCtlfrmI0144::DoTestStepL()
  2861 	{
  2862 	INFO_PRINTF1(_L("Custom Command (async)"));
  2863 
  2864 	TInt error = KErrNone;
  2865 
  2866 	TUid uid = {KTSIMmfControllerUid};
  2867 	TMMFMessageDestination handleInfo(uid);
  2868 	TMMFMessageDestinationPckg messageDest(handleInfo);
  2869 
  2870 	// call CustomCommandAsync
  2871 	const TInt KGuardTimerValue = 5000000; // give it 5 sec timeout
  2872 	RTimer guardTimer;
  2873 	TRequestStatus timerStatus;
  2874 	TRequestStatus controllerStatus;
  2875 	guardTimer.CreateLocal();
  2876 
  2877 	iController.CustomCommandAsync(messageDest, KDummyFunc1, KNullDesC8, KNullDesC8, controllerStatus);
  2878 	guardTimer.After(timerStatus, KGuardTimerValue);
  2879 	User::WaitForRequest(controllerStatus, timerStatus);
  2880 	guardTimer.Cancel();
  2881 	guardTimer.Close();
  2882 
  2883 	if(controllerStatus == KRequestPending)
  2884 		{ 
  2885 		// request timed out
  2886 		ERR_PRINTF1(_L("CustomCommandAsync : request timed out"));
  2887 		return iTestStepResult = EFail;
  2888 		}
  2889 		
  2890 	error = controllerStatus.Int();
  2891 	if(error == KDummyFunc1Return)
  2892 		error = KErrNone;
  2893 	else
  2894 		{
  2895 		ERR_PRINTF2(_L("CustomCommandAsync KDummyFunc1 returned unexpected value %d"), error);
  2896 		return iTestStepResult = EFail;
  2897 		}
  2898 	INFO_PRINTF2(_L("CustomCommandAsync KDummyFunc1 returned expected value %d"), KDummyFunc1Return);
  2899 
  2900 	// now call the log - to test CustomCommandAsync with aDataFrom
  2901 	_LIT8(KExpectedResult, "DummyFunc1 Called");
  2902 	TBuf8<KTextBufLen> memFunctionText;
  2903 
  2904 	guardTimer.CreateLocal();
  2905 	iController.CustomCommandAsync(messageDest, KLogFunction, KNullDesC8, KNullDesC8, 
  2906 								   memFunctionText, controllerStatus);
  2907 	guardTimer.After(timerStatus, KGuardTimerValue);
  2908 	User::WaitForRequest(controllerStatus, timerStatus);
  2909 	guardTimer.Cancel();
  2910 	guardTimer.Close();
  2911 
  2912 	if(controllerStatus == KRequestPending)
  2913 		{ 
  2914 		// request timed out
  2915 		ERR_PRINTF1(_L("CustomCommandAsync : request timed out"));
  2916 		return iTestStepResult = EFail;
  2917 		}
  2918 		
  2919 	error = controllerStatus.Int();
  2920 	if (error)
  2921 		{
  2922 		ERR_PRINTF2(_L("CustomCommandAsync failed with error %d"), error);
  2923 		return iTestStepResult = EFail;
  2924 		}
  2925 		
  2926 	TBuf<KTextBufLen> memFunctionText16;
  2927 	memFunctionText16.SetMax();
  2928 	memFunctionText16.Fill(0x0);
  2929 	memFunctionText16.Copy(memFunctionText);
  2930 	INFO_PRINTF2(_L("Log : %S"), &memFunctionText16);
  2931 
  2932 	if (memFunctionText != KExpectedResult)
  2933 		{
  2934 		ERR_PRINTF1(_L("Return value did not match expected"));
  2935 		return iTestStepResult = EFail;
  2936 		}
  2937 
  2938 	return iTestStepResult = EPass;
  2939 	}
  2940 
  2941 // ---------------------------
  2942 // RTestMmfCtlfrmI0151
  2943 //
  2944 // Get duration
  2945 //
  2946 // (no REQ)
  2947 
  2948 RTestMmfCtlfrmI0151* RTestMmfCtlfrmI0151::NewL()
  2949 	{
  2950 	RTestMmfCtlfrmI0151* self = new(ELeave) RTestMmfCtlfrmI0151;
  2951 	return self;
  2952 	}
  2953 
  2954 RTestMmfCtlfrmI0151::RTestMmfCtlfrmI0151()
  2955 	{
  2956 	iTestStepName = _L("MM-MMF-CTLFRM-I-0151");
  2957 	}
  2958 
  2959 TVerdict RTestMmfCtlfrmI0151::DoTestStepL()
  2960 	{
  2961 	INFO_PRINTF1(_L("Get Duration"));
  2962 
  2963 	TInt error = KErrNone;
  2964 	TTimeIntervalMicroSeconds duration;
  2965 
  2966 	error = iController.GetDuration(duration);
  2967 	if (error)
  2968 		{
  2969 		ERR_PRINTF2(_L("GetDuration failed with error %d"), error);
  2970 		return iTestStepResult = EFail;
  2971 		}
  2972 	INFO_PRINTF2(_L("Clip duration: %d"), I64LOW(duration.Int64()));
  2973 
  2974 	// we just happen to know that this clip is 5.33 seconds long
  2975 	// currently assuming resolution 1/100 of a sec, rounding up
  2976 	const TTimeIntervalMicroSeconds expectedDuration(5330000);
  2977 	const TInt expectedDurationMilliSeconds = 533;
  2978 	TInt64 duration64 = duration.Int64();
  2979 	TInt64 durationMod;
  2980 	I64DIVMOD(duration64, 10000, durationMod);
  2981 	if (durationMod >= 5000)
  2982 		duration64++;
  2983 
  2984 	if(duration64 != expectedDurationMilliSeconds)
  2985 		{
  2986 		ERR_PRINTF2(_L("Expected duration was %d"), I64LOW(expectedDuration.Int64()));
  2987 		return iTestStepResult = EFail;
  2988 		}
  2989 
  2990 	return iTestStepResult = EPass;
  2991 	}
  2992 
  2993 // ---------------------------
  2994 // RTestMmfCtlfrmI0152
  2995 //
  2996 // Get metadata entries
  2997 //
  2998 // (no REQ)
  2999 
  3000 RTestMmfCtlfrmI0152* RTestMmfCtlfrmI0152::NewL()
  3001 	{
  3002 	RTestMmfCtlfrmI0152* self = new(ELeave) RTestMmfCtlfrmI0152;
  3003 	return self;
  3004 	}
  3005 
  3006 RTestMmfCtlfrmI0152::RTestMmfCtlfrmI0152()
  3007 	{
  3008 	iTestStepName = _L("MM-MMF-CTLFRM-I-0152");
  3009 	}
  3010 
  3011 TVerdict RTestMmfCtlfrmI0152::DoTestStepL()
  3012 	{
  3013 	INFO_PRINTF1(_L("Get Metadata Entries"));
  3014 
  3015 	TInt error = KErrNone;
  3016 
  3017 	// expected values from our test controller
  3018 	const TInt KExpectedNumberOfMetaDataEntries = 4;
  3019 	// NB : these are 8-bit strings
  3020 	_LIT(KExpectedMetaDataEntryName1, "AudioLevel");
  3021 	_LIT(KExpectedMetaDataEntryValue1, "HIGH");
  3022 	_LIT(KExpectedMetaDataEntryName2, "AudioQuality");
  3023 	_LIT(KExpectedMetaDataEntryValue2, "LOW");
  3024 
  3025 	TInt numEntries;
  3026 	error = iController.GetNumberOfMetaDataEntries(numEntries);
  3027 	if (error)
  3028 		{
  3029 		ERR_PRINTF2(_L("GetNumberOfMetaDataEntries failed, error %d"), error);
  3030 		return iTestStepResult = EFail;
  3031 		}
  3032 	INFO_PRINTF2(_L("Number of metadata entries : %d"), numEntries);
  3033 	if (numEntries != KExpectedNumberOfMetaDataEntries)
  3034 		{
  3035 		ERR_PRINTF2(_L("GetNumberOfMetaDataEntries returned unexpected value %d"), numEntries);
  3036 		return iTestStepResult = EFail;
  3037 		}
  3038 
  3039 	CMMFMetaDataEntry* metaEntry1 = NULL;
  3040 	TRAPD(err1, metaEntry1 = iController.GetMetaDataEntryL(1))
  3041 	if(err1)
  3042 		{
  3043 		ERR_PRINTF2(_L("GetMetaDataEntryL left with error %d"), err1);
  3044 		return iTestStepResult = EFail;
  3045 		}
  3046 	CleanupStack::PushL(metaEntry1);
  3047 	TPtrC entry1Name = metaEntry1->Name();
  3048 	TPtrC entry1Value = metaEntry1->Value();
  3049 	INFO_PRINTF3(_L("Metadata entry 1 = %S:%S"), &entry1Name, &entry1Value);
  3050 
  3051 	if((entry1Name != KExpectedMetaDataEntryName1) || (entry1Value != KExpectedMetaDataEntryValue1))
  3052 		{
  3053 		ERR_PRINTF1(_L("Metadata entries did not match expected"));
  3054 		CleanupStack::PopAndDestroy(metaEntry1);
  3055 		return iTestStepResult = EFail;
  3056 		}
  3057 
  3058 	CMMFMetaDataEntry* metaEntry2 = NULL;
  3059 	TRAPD(err2, metaEntry2 = iController.GetMetaDataEntryL(2))
  3060 	if(err2)
  3061 		{
  3062 		ERR_PRINTF2(_L("GetMetaDataEntryL left with error %d"), err2);
  3063 		CleanupStack::PopAndDestroy(metaEntry1);
  3064 		return iTestStepResult = EFail;
  3065 		}
  3066 	CleanupStack::PushL(metaEntry2);
  3067 	TPtrC entry2Name = metaEntry2->Name();
  3068 	TPtrC entry2Value = metaEntry2->Value();
  3069 	INFO_PRINTF3(_L("Metadata entry 2 = %S:%S"), &entry2Name, &entry2Value);
  3070 
  3071 	if((entry2Name != KExpectedMetaDataEntryName2) || (entry2Value != KExpectedMetaDataEntryValue2))
  3072 		{
  3073 		ERR_PRINTF1(_L("Metadata entries did not match expected"));
  3074 		CleanupStack::PopAndDestroy(2); // metaEntry2, metaEntry1
  3075 		return iTestStepResult = EFail;
  3076 		}
  3077 
  3078 	// test the copy constructor
  3079 	CMMFMetaDataEntry* metaEntry3 = CMMFMetaDataEntry::NewL(*metaEntry2);
  3080 	CleanupStack::PushL(metaEntry3);
  3081 	TPtrC entry3Name = metaEntry3->Name();
  3082 	TPtrC entry3Value = metaEntry3->Value();
  3083 	INFO_PRINTF3(_L("Copy-constructed metadata entry = %S:%S"), &entry3Name, &entry3Value);
  3084 
  3085 	if((entry3Name != KExpectedMetaDataEntryName2) || (entry3Value != KExpectedMetaDataEntryValue2))
  3086 		{
  3087 		ERR_PRINTF1(_L("Copy-constructed metadata entries did not match expected"));
  3088 		CleanupStack::PopAndDestroy(3); // metaEntry3, metaEntry2, metaEntry1
  3089 		return iTestStepResult = EFail;
  3090 		}
  3091 
  3092 	// test setters
  3093 	TRAPD(err3, metaEntry3->SetNameL(KExpectedMetaDataEntryName1));
  3094 	if(err3)
  3095 		{
  3096 		ERR_PRINTF2(_L("SetNameL left with error %d"), err3);
  3097 		CleanupStack::PopAndDestroy(3); // metaEntry3, metaEntry2, metaEntry1
  3098 		return iTestStepResult = EFail;
  3099 		}
  3100 
  3101 	TRAP(err3, metaEntry3->SetValueL(KExpectedMetaDataEntryValue1));
  3102 	if(err3)
  3103 		{
  3104 		ERR_PRINTF2(_L("SetValueL left with error %d"), err3);
  3105 		CleanupStack::PopAndDestroy(3); // metaEntry3, metaEntry2, metaEntry1
  3106 		return iTestStepResult = EFail;
  3107 		}
  3108 
  3109 	TPtrC entry3NewName = metaEntry3->Name();
  3110 	TPtrC entry3NewValue = metaEntry3->Value();
  3111 	INFO_PRINTF3(_L("Copy-constructed metadata entry now = %S:%S"), &entry3NewName, &entry3NewValue);
  3112 
  3113 	if((entry3NewName != KExpectedMetaDataEntryName1) || (entry3NewValue != KExpectedMetaDataEntryValue1))
  3114 		{
  3115 		ERR_PRINTF1(_L("Copy-constructed metadata entries did not match after Set()"));
  3116 		CleanupStack::PopAndDestroy(3); // metaEntry3, metaEntry2, metaEntry1
  3117 		return iTestStepResult = EFail;
  3118 		}
  3119 
  3120 
  3121 	CleanupStack::PopAndDestroy(3); // metaEntry3, metaEntry2, metaEntry1
  3122 	return iTestStepResult = EPass;
  3123 	}