mmlibs/mmfw/tsrc/mmfunittest/Actrl/TestStepController.cpp
changeset 0 b8ed18f6c07b
equal deleted inserted replaced
-1:000000000000 0:b8ed18f6c07b
       
     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 // TestStepContropller.cpp
       
    15 //
       
    16 
       
    17 #include <e32std.h>
       
    18 #include <e32base.h>
       
    19 #include <mmf/common/mmfcontroller.h>
       
    20 #include <mmf/server/mmffile.h>
       
    21 #include <mmf/server/mmfdes.h>
       
    22 #include <mmf/plugin/mmfcontrollerimplementationuids.hrh>
       
    23 #include <mmf/common/mmfstandardcustomcommands.h>
       
    24 
       
    25 // Test system includes
       
    26 #include <testframework.h>
       
    27 
       
    28 // Specific includes for this test suite
       
    29 #include "TS_MMF_ACTRL_TestStep.h"
       
    30 #include "TS_MMF_ACTRL_TestSuite.h"
       
    31 
       
    32 #include "ActrlTestUids.h"
       
    33 
       
    34 // Specific includes for these test steps
       
    35 #include "TestStepController.h"
       
    36 
       
    37 // constants destined for header file
       
    38 //const TInt KPlayDelayNewMail = 100000000 ;	// EABI warning removal
       
    39 const TInt KMemoryAllocCmd = 0xaaaaa;
       
    40 
       
    41 /**
       
    42 *
       
    43 * CTestStepResetController
       
    44 *
       
    45 */
       
    46 CTestStepResetController::CTestStepResetController()
       
    47 	{
       
    48 	iTestStepName = _L("MM-MMF-ACTRL-U-0016-HP");
       
    49 	}
       
    50 
       
    51 /**
       
    52 *
       
    53 * ~CTestStepResetController
       
    54 *
       
    55 */
       
    56 CTestStepResetController::~CTestStepResetController()
       
    57 	{
       
    58 	}
       
    59 
       
    60 /**
       
    61 *
       
    62 * DoTestStepL
       
    63 * This method tests the controllers reset function
       
    64 *
       
    65 */
       
    66 TVerdict CTestStepResetController::DoTestStepL( void )
       
    67 	{
       
    68 	__MM_HEAP_MARK;
       
    69 	
       
    70 	TVerdict result = EPass;
       
    71 	
       
    72 	_LIT( KTestPlay, "Reset Test");
       
    73 	Log( KTestPlay );
       
    74 	
       
    75 	_LIT( KTestStepReset, "This test checks a controller reset");
       
    76 	Log( KTestStepReset );
       
    77 	
       
    78 	// [ audio file to play ]
       
    79 	_LIT(KTestWavFile, "newmail.wav");
       
    80 	SetReadFileNameL( KTestWavFile );
       
    81 	
       
    82    	TInt errorCode = iController.Open(KUidCustomTestAudioPlugin, iPriority);
       
    83 	User::LeaveIfError( errorCode );
       
    84 	
       
    85 	//[ok lets reset the controller from it initial state]
       
    86 	errorCode = iController.Reset();
       
    87 	User::LeaveIfError( errorCode );
       
    88 	//[ search for reset event ]
       
    89 	TMMFEvent resetEvent( KResetTestId, KErrNone);
       
    90 	result = SearchForEvent( resetEvent );
       
    91 	if( result == EFail )
       
    92 		{
       
    93 		return result;
       
    94 		}
       
    95 	
       
    96 	//[ lets try a second reset ]
       
    97 	errorCode = iController.Reset();
       
    98 	User::LeaveIfError( errorCode );
       
    99 	//[ search for reset event ]
       
   100 	result = SearchForEvent( resetEvent );
       
   101 	if( result == EFail )
       
   102 		{
       
   103 		return result;
       
   104 		}
       
   105 	
       
   106 	//[ add data source and sink and prime the controller ]
       
   107     errorCode = iController.AddDataSource(KUidMmfFileSource, ReadFileConfig());
       
   108 	User::LeaveIfError( errorCode );
       
   109 	
       
   110 	errorCode =	iController.AddDataSink(KUidMmfAudioOutput, KNullDesC8);
       
   111     User::LeaveIfError( errorCode );
       
   112 	
       
   113 	//[ok lets reset the controller from it initial state]
       
   114 	errorCode = iController.Reset();
       
   115 	User::LeaveIfError( errorCode );
       
   116 	
       
   117 	//[ search for reset event ]
       
   118 	result = SearchForEvent( resetEvent );
       
   119 	if( result == EFail )
       
   120 		{
       
   121 		return result;
       
   122 		}
       
   123 	
       
   124 	//[ lets try a second reset ]
       
   125 	errorCode = iController.Reset();
       
   126 	User::LeaveIfError( errorCode );
       
   127 	//[ search for reset event ]
       
   128 	result = SearchForEvent( resetEvent );
       
   129 	if( result == EFail )
       
   130 		{
       
   131 		return result;
       
   132 		}
       
   133 
       
   134 	//[ add data source and sink and prime the controller ]
       
   135     errorCode = iController.AddDataSource(KUidMmfFileSource, ReadFileConfig());
       
   136 	User::LeaveIfError( errorCode );
       
   137 	
       
   138 	errorCode =	iController.AddDataSink(KUidMmfAudioOutput, KNullDesC8);
       
   139     User::LeaveIfError( errorCode );
       
   140 	
       
   141 	errorCode =	iController.Prime();
       
   142 	User::LeaveIfError( errorCode );
       
   143 	
       
   144 	// [ wait for and process the return event from the audio output ]
       
   145 	TMMFEvent primeEvent( KPrimeTestId, KErrNone);
       
   146 	result = SearchForEvent( primeEvent );
       
   147 	if( result == EFail )
       
   148 		{
       
   149 		return result;
       
   150 		}
       
   151 	
       
   152 	//[ lets reset again in the primed state ]
       
   153 	errorCode = iController.Reset();
       
   154 	User::LeaveIfError( errorCode );
       
   155 	
       
   156 	//[ search for reset event ]
       
   157 	result = SearchForEvent( resetEvent );
       
   158 	if( result == EFail )
       
   159 		{
       
   160 		return result;
       
   161 		}
       
   162 	
       
   163 	// [ get back to primed state ]
       
   164 	//[ add data source and sink and prime the controller ]
       
   165     errorCode = iController.AddDataSource(KUidMmfFileSource, ReadFileConfig());
       
   166 	User::LeaveIfError( errorCode );
       
   167 	
       
   168 	errorCode =	iController.AddDataSink(KUidMmfAudioOutput, KNullDesC8);
       
   169     User::LeaveIfError( errorCode );
       
   170 	
       
   171 	errorCode =	iController.Prime();
       
   172 	User::LeaveIfError( errorCode );
       
   173 	result = SearchForEvent( primeEvent );
       
   174 	if( result == EFail )
       
   175 		{
       
   176 		return result;
       
   177 		}
       
   178 
       
   179     User::LeaveIfError( iController.Play() );
       
   180 	
       
   181 	// note this test does not wait around 
       
   182 	// to detect that the audio has been played
       
   183 	// [ now process the confirmation event that play has reached audio output
       
   184 	//   this is the raison detre of the test ]
       
   185 	TMMFEvent playEvent( KPlayTestId, KErrNone );
       
   186 	result = SearchForEvent( playEvent );
       
   187 	if( result == EFail )
       
   188 		{
       
   189 		return result;
       
   190 		}
       
   191 	
       
   192 	//[ lets reset again in the primed state ]
       
   193 	errorCode = iController.Reset();
       
   194 	User::LeaveIfError( errorCode );
       
   195 	
       
   196 	//[ search for reset event ]
       
   197 	result = SearchForEvent( resetEvent );
       
   198 	if( result == EFail )
       
   199 		{
       
   200 		return result;
       
   201 		}
       
   202 
       
   203 	errorCode = iController.Reset();
       
   204 	User::LeaveIfError( errorCode );
       
   205 	
       
   206 	//[ search for reset event ]
       
   207 	result = SearchForEvent( resetEvent );
       
   208 	if( result == EFail )
       
   209 		{
       
   210 		return result;
       
   211 		}
       
   212 
       
   213 	//[ ensure the controller is unloaded so that it does 
       
   214 	// not interfere with the following test ]
       
   215 	// There is error in this code and the stop followed by reset
       
   216 	// ensure the controller resources are released.
       
   217 	iController.Stop();
       
   218 	iController.Reset();
       
   219 	iController.Close();  
       
   220 	
       
   221 	__MM_HEAP_MARKEND;
       
   222 	   
       
   223 	// [test steps return a result]
       
   224 	return result;
       
   225 	}
       
   226 
       
   227 /**
       
   228 *
       
   229 * CTestStepRemoveDataSink
       
   230 *
       
   231 */
       
   232 CTestStepRemoveDataSink::CTestStepRemoveDataSink()
       
   233 	{
       
   234 	iTestStepName = _L("MM-MMF-ACTRL-U-0017-HP");
       
   235 	}
       
   236 
       
   237 /**
       
   238 *
       
   239 * ~CTestStepPauseController
       
   240 *
       
   241 */ 
       
   242 CTestStepRemoveDataSink::~CTestStepRemoveDataSink()
       
   243 	{
       
   244 	}
       
   245 
       
   246 /**
       
   247 *
       
   248 * DoTestStepL
       
   249 *
       
   250 */
       
   251 TVerdict CTestStepRemoveDataSink::DoTestStepL( void )
       
   252 	{
       
   253 	 __MM_HEAP_MARK;
       
   254 	
       
   255 	TVerdict result = EPass;
       
   256 	
       
   257 	_LIT( KTestPlay, "Remove Data Sink Test");
       
   258 	Log( KTestPlay );
       
   259 	
       
   260 	_LIT( KTestStepPause, "This test checks removing a data sink");
       
   261 	Log( KTestStepPause );
       
   262 	
       
   263 	// [ audio file to play ]
       
   264 	_LIT(KTestWavFile, "newmail.wav");
       
   265 	SetReadFileNameL( KTestWavFile );
       
   266 	
       
   267    	TInt errorCode = iController.Open(KUidCustomTestAudioPlugin, iPriority);
       
   268 	User::LeaveIfError( errorCode );
       
   269 
       
   270 	//[ declare handles for removal of the data source and data sink]
       
   271 	TMMFMessageDestination aSourceHandleInfo;
       
   272 	TMMFMessageDestination aSinkHandleInfo  ;
       
   273 
       
   274 	//[ add data source and sink and prime the controller ]
       
   275     errorCode = iController.AddDataSource(KUidMmfFileSource, ReadFileConfig(), aSourceHandleInfo );
       
   276 	User::LeaveIfError( errorCode );
       
   277 	
       
   278 	errorCode =	iController.AddDataSink(KUidMmfAudioOutput, KNullDesC8, aSinkHandleInfo );
       
   279     User::LeaveIfError( errorCode );
       
   280 
       
   281 	//[ lets try removing the data sink with the soure handle ]
       
   282 	errorCode =	iController.RemoveDataSink( aSourceHandleInfo );
       
   283     if( errorCode == KErrNone )
       
   284 		{
       
   285 		result = EFail;
       
   286 		return result;
       
   287 		}
       
   288 
       
   289 	//[ lets remove the data sink ]
       
   290 	errorCode =	iController.RemoveDataSink( aSinkHandleInfo );
       
   291     User::LeaveIfError( errorCode );
       
   292 	
       
   293 	//[ search for remove event ]
       
   294 	TMMFEvent removeDataSinkEvent( KRemoveDataSinkTestId, KErrNone );
       
   295 	TVerdict removeResult = SearchForEvent( removeDataSinkEvent );
       
   296 	if( removeResult == EFail )
       
   297 		{
       
   298 		return removeResult ;
       
   299 		}
       
   300 	
       
   301 	//[ try removing the data sink a second time ]
       
   302 	errorCode =	iController.RemoveDataSink( aSinkHandleInfo );
       
   303 	if( errorCode == KErrNone )
       
   304 		{
       
   305 		result = EFail;
       
   306 		return result ;
       
   307 		}
       
   308 
       
   309 	//[ no need to remove event since the message does not reach the custom controller ]
       
   310 
       
   311 	errorCode =	iController.AddDataSink(KUidMmfAudioOutput, KNullDesC8, aSinkHandleInfo );
       
   312     User::LeaveIfError( errorCode );
       
   313     	
       
   314 	errorCode =	iController.Prime();
       
   315 	User::LeaveIfError( errorCode );
       
   316 	
       
   317 	// [ wait for and process the return event from the audio output ]
       
   318 	
       
   319 	TMMFEvent primeEvent( KPrimeTestId, KErrNone);
       
   320 	TVerdict primeResult = SearchForEvent( primeEvent );
       
   321 	if( primeResult == EFail )
       
   322 		{
       
   323 		return primeResult;
       
   324 		}
       
   325 
       
   326 	//[ try removing the data sink ]
       
   327 	errorCode =	iController.RemoveDataSink( aSinkHandleInfo );
       
   328 	if( errorCode == KErrNone )
       
   329 		{
       
   330 		result = EFail;
       
   331 		return result ;
       
   332 		}
       
   333 
       
   334 	// [ second event is not generated on failure ]
       
   335 	
       
   336 	User::LeaveIfError( iController.Play() );
       
   337 	
       
   338 	// note this test does not wait around 
       
   339 	// to detect that the audio has been played
       
   340 	// [ now process the confirmation event that play has reached audio output
       
   341 	//   this is the raison detre of the test ]
       
   342 	TMMFEvent playEvent( KPlayTestId, KErrNone );
       
   343 	
       
   344 	TVerdict playResult = SearchForEvent( playEvent );
       
   345 	if( playResult == EFail )
       
   346 		{
       
   347 		return playResult ;
       
   348 		}
       
   349 
       
   350 	//[ try removing the data sink  ]
       
   351 	errorCode =	iController.RemoveDataSink( aSinkHandleInfo );
       
   352 	if( errorCode == KErrNone )
       
   353 		{
       
   354 		result = EFail;
       
   355 		return result ;
       
   356 		}
       
   357 
       
   358 	//[ try removing the data sink  ]
       
   359 	errorCode =	iController.RemoveDataSink( aSinkHandleInfo );
       
   360 	if( errorCode == KErrNone )
       
   361 		{
       
   362 		result = EFail;
       
   363 		return result ;
       
   364 		}
       
   365 
       
   366 	result = EPass ;
       
   367 
       
   368 	//[ ensure the controller is unloaded so that it does 
       
   369 	// not interfere with the following test ]
       
   370 	// There is error in this code and the stop followed by reset
       
   371 	// ensure the controller resources are released.
       
   372 	iController.Stop();
       
   373 	iController.Reset();
       
   374 	iController.Close();  
       
   375 		
       
   376 	__MM_HEAP_MARKEND;
       
   377    
       
   378 	// test steps return a result
       
   379 	return result;
       
   380 	}
       
   381 
       
   382 /**
       
   383 *
       
   384 * CTestStepRemoveDataSource
       
   385 *
       
   386 */
       
   387 CTestStepRemoveDataSource::CTestStepRemoveDataSource()
       
   388 	{
       
   389 	iTestStepName = _L("MM-MMF-ACTRL-U-0019-HP");
       
   390 	}
       
   391 
       
   392 /**
       
   393 *
       
   394 * ~CTestStepRemoveDataSource
       
   395 *
       
   396 */
       
   397 CTestStepRemoveDataSource::~CTestStepRemoveDataSource()
       
   398 	{
       
   399 	}
       
   400 
       
   401 /**
       
   402 *
       
   403 * DoTestStepL
       
   404 * This method tests removing a Data Source
       
   405 */
       
   406 TVerdict CTestStepRemoveDataSource::DoTestStepL( void )
       
   407 	{
       
   408 	 __MM_HEAP_MARK;
       
   409 	
       
   410 	TVerdict result = EPass;
       
   411 	
       
   412 	_LIT( KTestPlay, "Remove Data Source Test");
       
   413 	Log( KTestPlay );
       
   414 	
       
   415 	_LIT( KTestStepSource, "This test checks removing a data source");
       
   416 	Log( KTestStepSource );
       
   417 	
       
   418 	// [ audio file to play ]
       
   419 	_LIT(KTestWavFile, "newmail.wav");
       
   420 	SetReadFileNameL( KTestWavFile );
       
   421 	
       
   422    	TInt errorCode = iController.Open(KUidCustomTestAudioPlugin, iPriority);
       
   423 	User::LeaveIfError( errorCode );
       
   424 	//iFileConfig().iPath = KTestWavFile;
       
   425 
       
   426 	//[ declare handles for removal of the data source and data sink]
       
   427 	TMMFMessageDestination aSourceHandleInfo;
       
   428 	TMMFMessageDestination aSinkHandleInfo  ;
       
   429 
       
   430 	//[ add data source and sink and prime the controller ]
       
   431     errorCode = iController.AddDataSource(KUidMmfFileSource, ReadFileConfig(), aSourceHandleInfo );
       
   432 	User::LeaveIfError( errorCode );
       
   433 	
       
   434 	errorCode =	iController.AddDataSink(KUidMmfAudioOutput, KNullDesC8, aSinkHandleInfo );
       
   435     User::LeaveIfError( errorCode );
       
   436 
       
   437 	//[ lets remove the data source using the sink handle !! ]
       
   438 	errorCode =	iController.RemoveDataSource( aSinkHandleInfo );
       
   439     if( errorCode == KErrNone )
       
   440 		{
       
   441 		result = EFail;
       
   442 		return result ;
       
   443 		}
       
   444 
       
   445 	//[ lets remove the data source ]
       
   446 	errorCode =	iController.RemoveDataSource( aSourceHandleInfo );
       
   447     User::LeaveIfError( errorCode );
       
   448 
       
   449 	//[ search for remove event ]
       
   450 	TMMFEvent removeDataSourceEvent( KRemoveDataSourceTestId, KErrNone );
       
   451 	TVerdict removeResult = SearchForEvent( removeDataSourceEvent );
       
   452 	if( removeResult == EFail )
       
   453 		{
       
   454 		return removeResult ;
       
   455 		}
       
   456 	
       
   457 	//[ try removing the data source a second time ]
       
   458 	errorCode =	iController.RemoveDataSource( aSourceHandleInfo );
       
   459 	if( errorCode == KErrNone )
       
   460 		{
       
   461 		result = EFail;
       
   462 		return result ;
       
   463 		}
       
   464 
       
   465 	//[ no need to remove event since the message does not reach the custom controller ]
       
   466 
       
   467 	//[ add data source and sink and prime the controller ]
       
   468     errorCode = iController.AddDataSource(KUidMmfFileSource, ReadFileConfig(), aSourceHandleInfo );
       
   469 	User::LeaveIfError( errorCode );
       
   470     
       
   471 	errorCode =	iController.Prime();
       
   472 	User::LeaveIfError( errorCode );
       
   473 	
       
   474 	// [ wait for and process the return event from the audio output ]
       
   475 	
       
   476 	TMMFEvent primeEvent( KPrimeTestId, KErrNone);
       
   477 	TVerdict primeResult = SearchForEvent( primeEvent );
       
   478 	if( primeResult == EFail )
       
   479 		{
       
   480 		return primeResult;
       
   481 		}
       
   482 
       
   483 	//[ try removing the data source ]
       
   484 	errorCode =	iController.RemoveDataSource( aSourceHandleInfo );
       
   485 	if( errorCode == KErrNone )
       
   486 		{
       
   487 		result = EFail;
       
   488 		return result ;
       
   489 		}
       
   490 
       
   491 	// [ second event is not generated on failure ]
       
   492 	
       
   493 	User::LeaveIfError( iController.Play() );
       
   494 	
       
   495 	// note this test does not wait around 
       
   496 	// to detect that the audio has been played
       
   497 	// [ now process the confirmation event that play has reached audio output
       
   498 	//   this is the raison detre of the test ]
       
   499 	TMMFEvent playEvent( KPlayTestId, KErrNone );
       
   500 	
       
   501 	TVerdict playResult = SearchForEvent( playEvent );
       
   502 	if( playResult == EFail )
       
   503 		{
       
   504 		return playResult ;
       
   505 		}
       
   506 
       
   507 	//[ try removing the data sink  ]
       
   508 	errorCode =	iController.RemoveDataSource( aSourceHandleInfo );
       
   509 	if( errorCode == KErrNone )
       
   510 		{
       
   511 		result = EFail;
       
   512 		return result ;
       
   513 		}
       
   514 
       
   515 	//[ try removing the data sink  ]
       
   516 	errorCode =	iController.RemoveDataSource( aSourceHandleInfo );
       
   517 	if( errorCode == KErrNone )
       
   518 		{
       
   519 		result = EFail;
       
   520 		return result ;
       
   521 		}
       
   522 
       
   523 	result = EPass ;
       
   524 
       
   525 	//[ ensure the controller is unloaded so that it does 
       
   526 	// not interfere with the following test ]
       
   527 	// There is error in this code and the stop followed by reset
       
   528 	// ensure the controller resources are released.
       
   529 	iController.Stop();
       
   530 	iController.Reset();
       
   531 	iController.Close();  
       
   532 		
       
   533 	__MM_HEAP_MARKEND;
       
   534 	   
       
   535 	// test steps return a result
       
   536 	return result;
       
   537 	}
       
   538 
       
   539 /**
       
   540 *
       
   541 * CTestStepMemoryAllocation
       
   542 */
       
   543 CTestStepMemoryAllocation::CTestStepMemoryAllocation()
       
   544 	{
       
   545 	iTestStepName = _L("MM-MMF-ACTRL-U-0020-HP");
       
   546 	}
       
   547 
       
   548 /**
       
   549 *
       
   550 * ~CTestStepMemoryAllocation
       
   551 */
       
   552 CTestStepMemoryAllocation::~CTestStepMemoryAllocation()
       
   553 	{
       
   554 	}
       
   555 
       
   556 /**
       
   557 *
       
   558 *DoTestStepL
       
   559 */
       
   560 TVerdict CTestStepMemoryAllocation::DoTestStepL( void )
       
   561 	{
       
   562 	__MM_HEAP_MARK;
       
   563 	
       
   564 	TVerdict result = EPass;
       
   565 	
       
   566 	_LIT( KTestPlay, "Memory Allocation Test");
       
   567 	Log( KTestPlay );
       
   568 	
       
   569 	_LIT( KTestStepSource, "This test checks memory allocation of the plugin");
       
   570 	Log( KTestStepSource );
       
   571 	
       
   572    	TInt errorCode = iController.Open(KUidCustomTestAudioPlugin, iPriority);
       
   573 	User::LeaveIfError( errorCode );
       
   574 	//[ send the custom command to the custom audio controller ]
       
   575 	TMMFMessageDestinationPckg destinationPckg(KMemoryAllocationTestId);
       
   576 	
       
   577 	//[ send memory alloc test to the custom plugin ]
       
   578 	//[ we have only ensured that the controller is loaded into memory
       
   579 	// and that all add sources etc will be don
       
   580 	errorCode = iController.CustomCommandSync(destinationPckg, 
       
   581 		KMemoryAllocCmd, 
       
   582 		KNullDesC8,
       
   583 		KNullDesC8);
       
   584 	User::LeaveIfError( errorCode );
       
   585 
       
   586 	//[ ensure the controller is unloaded so that it does 
       
   587 	// not interfere with the following test ]
       
   588 	// There is error in this code and the stop followed by reset
       
   589 	// ensure the controller resources are released.
       
   590 	iController.Stop();
       
   591 	iController.Reset();
       
   592 	iController.Close();  
       
   593 
       
   594 	return result ;
       
   595 	}