common/tools/ats/smoketest/graphics/wserv/src/T_DataSoundPlugIn.cpp
changeset 833 6ffc235847d0
child 872 17498133d9ad
equal deleted inserted replaced
832:9b2bf01d4d36 833:6ffc235847d0
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Symbian Foundation License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 /**
       
    19 @test
       
    20 @internalComponent
       
    21 
       
    22 This contains CT_DataSoundPlugIn
       
    23 */
       
    24 
       
    25 #include "T_DataSoundPlugIn.h"
       
    26 
       
    27 /*@{*/
       
    28 ///	Parameters
       
    29 _LIT(KExpectedBool,							"expected_bool");
       
    30 _LIT(KEnabled,								"enabled");
       
    31 _LIT(KPlugInFileName,						"filename");
       
    32 _LIT(KOpcode,                               "opcode");
       
    33 _LIT(KPackagedArgs,                         "args");
       
    34 _LIT(KUid,                                  "uid");
       
    35 _LIT(KChangableBool, 						"isChangeable");
       
    36 
       
    37 /// Commands
       
    38 _LIT(KCmdNew,								"new");
       
    39 _LIT(KCmdConstruct,							"Construct");
       
    40 _LIT(KCmdClose,								"Close");
       
    41 _LIT(KCmdDestroy,							"Destroy");
       
    42 _LIT(KCmdIsLoaded,							"IsLoaded");
       
    43 _LIT(KCmdUnload,							"Unload");
       
    44 _LIT(KCmdLoad,								"Load");
       
    45 _LIT(KCmdSetKeyClick,						"SetKeyClick");
       
    46 _LIT(KCmdKeyClickEnabled,					"KeyClickEnabled");
       
    47 _LIT(KCmdSetPenClick,						"SetPenClick");
       
    48 _LIT(KCmdPenClickEnabled,					"PenClickEnabled");
       
    49 _LIT(KCmdCommandReply,						"CommandReply");
       
    50 
       
    51 // Fields
       
    52 _LIT(KFldWs,								"ws");
       
    53 
       
    54 // Log
       
    55 _LIT(KLogMissingParameter, 					"Missing parameter '%S'");
       
    56 
       
    57 /*@}*/
       
    58 
       
    59 /**
       
    60 * Two phase constructor
       
    61 */
       
    62 CT_DataSoundPlugIn* CT_DataSoundPlugIn::NewL()
       
    63 	{
       
    64 	CT_DataSoundPlugIn*	ret = new (ELeave) CT_DataSoundPlugIn();
       
    65 	CleanupStack::PushL(ret);
       
    66 	ret->ConstructL();
       
    67 	CleanupStack::Pop(ret);
       
    68 	return ret;
       
    69 	}
       
    70 
       
    71 /**
       
    72 * Protected constructor. First phase construction
       
    73 */
       
    74 CT_DataSoundPlugIn::CT_DataSoundPlugIn()
       
    75 :	iSoundPlugIn(NULL)
       
    76 	{
       
    77 	}
       
    78 
       
    79 /**
       
    80 * Second phase construction
       
    81 */
       
    82 void CT_DataSoundPlugIn::ConstructL()
       
    83 	{
       
    84 	}
       
    85 
       
    86 /**
       
    87 * Protected destructor.
       
    88 */
       
    89 CT_DataSoundPlugIn::~CT_DataSoundPlugIn()
       
    90 	{
       
    91 	Cleanup();
       
    92 	}
       
    93 
       
    94 void CT_DataSoundPlugIn::Cleanup()
       
    95 	{
       
    96 	delete iSoundPlugIn;
       
    97 	iSoundPlugIn = NULL;
       
    98 	}
       
    99 /**
       
   100  * Return a pointer to the object that the data wraps. Not implemented, returns NULL.
       
   101  *
       
   102  * @return pointer to the object that the data wraps. Not implemented, returns NULL.
       
   103  */
       
   104  TAny* CT_DataSoundPlugIn::GetObject()
       
   105  	{
       
   106  	return NULL;
       
   107  	}
       
   108  
       
   109  MWsClientClass* CT_DataSoundPlugIn::GetClientClass() const
       
   110  	{
       
   111  	return iSoundPlugIn;
       
   112  	}
       
   113  
       
   114 /**
       
   115 * Process a command read from the ini file
       
   116 *
       
   117 * @param aDataWrapper	test step requiring command to be processed
       
   118 * @param aCommand	the command to process
       
   119 * @param aSection		the entry in the ini file requiring the command to be processed
       
   120 *
       
   121 * @return ETrue if the command is processed
       
   122 */
       
   123 TBool CT_DataSoundPlugIn::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
   124 	{
       
   125 	TBool	retVal=ETrue;
       
   126 
       
   127 	if(aCommand == KCmdNew)
       
   128 		{
       
   129 		DoCmdNewL(aSection);
       
   130 		}
       
   131 	else if(aCommand == KCmdConstruct)
       
   132 		{
       
   133 		DoCmdConstruct(aSection);
       
   134 		}
       
   135 	else if(aCommand == KCmdClose)
       
   136 		{
       
   137 		DoCmdClose();
       
   138 		}
       
   139 	else if(aCommand == KCmdDestroy)
       
   140 		{
       
   141 		DoCmdDestroy();
       
   142 		}
       
   143 	else if(aCommand == KCmdIsLoaded)
       
   144 		{
       
   145 		DoCmdIsLoaded(aSection);
       
   146 		}
       
   147 	else if(aCommand == KCmdUnload)
       
   148 		{
       
   149 		DoCmdUnload();
       
   150 		}
       
   151 	else if(aCommand == KCmdLoad)
       
   152 		{
       
   153 		DoCmdLoad(aSection);
       
   154 		}
       
   155 	else if(aCommand == KCmdSetKeyClick)
       
   156 		{
       
   157 		DoCmdSetKeyClick(aSection);
       
   158 		}
       
   159 	else if(aCommand == KCmdKeyClickEnabled)
       
   160 		{
       
   161 		DoCmdKeyClickEnabled(aSection);
       
   162 		}
       
   163 	else if(aCommand == KCmdSetPenClick)
       
   164 		{
       
   165 		DoCmdSetPenClick(aSection);
       
   166 		}
       
   167 	else if(aCommand == KCmdPenClickEnabled)
       
   168 		{
       
   169 		DoCmdPenClickEnabled(aSection);
       
   170 		}
       
   171 	else if(aCommand == KCmdCommandReply)
       
   172 		{
       
   173 		DoCmdCommandReply(aSection);
       
   174 		}
       
   175 	else
       
   176 		{
       
   177 		retVal = EFalse;
       
   178 		}
       
   179 
       
   180 	return retVal;
       
   181 	}
       
   182 
       
   183 /** RSoundPlugIn::RSoundPlugIn() Call */
       
   184 void CT_DataSoundPlugIn::DoCmdNewL(const TDesC& aSection)
       
   185 	{
       
   186 	// Cleanup if already created
       
   187 	Cleanup();
       
   188 	
       
   189 	TPtrC wsName;
       
   190 	RWsSession* ws = NULL;
       
   191 	if(GetStringFromConfig(aSection, KFldWs, wsName))
       
   192 		{
       
   193 		ws = static_cast<RWsSession*>(GetDataObjectL(wsName));
       
   194 		}
       
   195 	
       
   196 
       
   197 	TInt err = KErrNone;
       
   198 	
       
   199 	if(ws == NULL)
       
   200 		{
       
   201 		// Execute command and log parameters
       
   202 		INFO_PRINTF1(_L("execute new RSoundPlugIn()"));
       
   203 		TRAP(err, iSoundPlugIn = new (ELeave) RSoundPlugIn);
       
   204 		}
       
   205 	else
       
   206 		{
       
   207 		// Execute command and log parameters
       
   208 		INFO_PRINTF1(_L("execute new RSoundPlugIn(RWsSession)"));
       
   209 		TRAP(err, iSoundPlugIn = new (ELeave) RSoundPlugIn(*ws));
       
   210 		}
       
   211 	
       
   212 	// Check error code
       
   213 	if(err != KErrNone)
       
   214 		{
       
   215 		ERR_PRINTF2(_L("Error creation instance: %d"), err);
       
   216 		SetError(err);
       
   217 		}
       
   218 	}
       
   219 
       
   220 /** RSoundPlugIn::Construct() Call */
       
   221 void CT_DataSoundPlugIn::DoCmdConstruct(const TDesC& aSection)
       
   222 	{
       
   223 	TInt err = KErrNone;
       
   224 	
       
   225 	if(0 == aSection.Length())
       
   226 		{
       
   227 		INFO_PRINTF1(_L("Calls RSoundPlugIn::Construct() with TUid::Null()"));
       
   228 		
       
   229 		// Call Construct()
       
   230 		err = iSoundPlugIn->Construct();
       
   231 		}
       
   232 	else
       
   233 		{
       
   234 		INFO_PRINTF1(_L("Calls RSoundPlugIn::Construct() with a plug-in DLL's third UID"));
       
   235 		
       
   236 		// Get UID from parameters
       
   237 		TInt uid;
       
   238 		if(!GetIntFromConfig(aSection, KUid(), uid))
       
   239 			{
       
   240 			ERR_PRINTF2(KLogMissingParameter, &KUid());
       
   241 			SetBlockResult(EFail);
       
   242 			}
       
   243 		else
       
   244 			{
       
   245 			//Call Construct()
       
   246 			err = iSoundPlugIn->Construct(TUid::Uid(uid));
       
   247 			}
       
   248 		}
       
   249 	
       
   250 	// Check error code
       
   251 	if(err != KErrNone)
       
   252 		{
       
   253 		ERR_PRINTF2(_L("Calls Construct() error %d"), err);
       
   254 		SetError(err);
       
   255 		}
       
   256 	}
       
   257 
       
   258 
       
   259 /** RSoundPlugIn::Close() Call */
       
   260 void CT_DataSoundPlugIn::DoCmdClose()
       
   261 	{
       
   262 	INFO_PRINTF1(_L("Calls RSoundPlugIn::Close()"));
       
   263 	
       
   264 	// Call Close()
       
   265 	iSoundPlugIn->Close();
       
   266 	}
       
   267 
       
   268 /** RSoundPlugIn::Destroy() Call */
       
   269 void CT_DataSoundPlugIn::DoCmdDestroy()
       
   270 	{
       
   271 	INFO_PRINTF1(_L("Calls RSoundPlugIn::Destroy()"));
       
   272 	
       
   273 	// Call Destroy()
       
   274 	iSoundPlugIn->Destroy();
       
   275 	iSoundPlugIn = NULL;
       
   276 	}
       
   277 
       
   278 /** RSoundPlugIn::IsLoaded() Call */
       
   279 void CT_DataSoundPlugIn::DoCmdIsLoaded(const TDesC& aSection)
       
   280 	{
       
   281 	TBool actualValue,actualChangeable;
       
   282 	TBool setChangable = EFalse;
       
   283 	TBool expectedValue = EFalse;
       
   284 
       
   285 	if ( !GetBoolFromConfig(aSection, KExpectedBool(), expectedValue))
       
   286 		{
       
   287 		ERR_PRINTF2(KLogMissingParameter, &KExpectedBool());
       
   288 		SetBlockResult (EFail);
       
   289 		}		
       
   290 	else
       
   291 		{
       
   292 		actualValue = iSoundPlugIn->IsLoaded (actualChangeable);
       
   293 		INFO_PRINTF2(_L("Calls RSoundPlugIn::IsLoaded() %d"), actualValue);
       
   294 
       
   295 		if ( expectedValue != actualValue)
       
   296 			{
       
   297 			ERR_PRINTF3(_L("The returned value is not as expected, expected: %d, actual: %d"), expectedValue, actualValue);
       
   298 			SetBlockResult (EFail);
       
   299 			}
       
   300 		else if (actualValue)
       
   301 			{
       
   302 			if ( !GetBoolFromConfig(aSection, KChangableBool(), setChangable))
       
   303 				{
       
   304 				ERR_PRINTF2(KLogMissingParameter, &KChangableBool());
       
   305 				SetBlockResult (EFail);
       
   306 				}
       
   307 			else
       
   308 			{
       
   309 			if (actualChangeable)
       
   310 				actualChangeable=ETrue;
       
   311 			if (actualChangeable != setChangable)
       
   312 				{
       
   313 				ERR_PRINTF3(_L("The IsChangeable is not as expected, expected: %d, actual: %d"), setChangable, actualChangeable);
       
   314 				SetBlockResult (EFail);
       
   315 				}
       
   316 			}
       
   317 			}		 
       
   318 		}
       
   319 	}
       
   320 
       
   321 /** RSoundPlugIn::Unload() Call */
       
   322 void CT_DataSoundPlugIn::DoCmdUnload()
       
   323 	{
       
   324 	INFO_PRINTF1(_L("Calls RSoundPlugIn::Unload()"));
       
   325 
       
   326 	// Call Unload to get actual return value
       
   327 	TInt err = iSoundPlugIn->Unload();
       
   328 	if(err != KErrNone)
       
   329 		{
       
   330 		ERR_PRINTF2(_L("Call Unload() error %d"), err);
       
   331 		SetError(err);
       
   332 		}
       
   333 	}
       
   334 
       
   335 /** RSoundPlugIn::Load() Call */
       
   336 void CT_DataSoundPlugIn::DoCmdLoad(const TDesC& aSection)
       
   337 	{
       
   338 	INFO_PRINTF1(_L("Calls RSoundPlugIn::Load()"));
       
   339 	
       
   340 	// Get file name from parameters
       
   341 	TPtrC fileName;
       
   342 	if(!GetStringFromConfig(aSection, KPlugInFileName(), fileName))
       
   343 		{
       
   344 		ERR_PRINTF2(KLogMissingParameter, &KPlugInFileName());
       
   345 		SetBlockResult(EFail);
       
   346 		}
       
   347 	else
       
   348 		{	
       
   349 		// Call Load()
       
   350 		TInt err = iSoundPlugIn->Load(fileName);
       
   351 		
       
   352 		// Check error code
       
   353 		if(err != KErrNone)
       
   354 			{
       
   355 			ERR_PRINTF3(_L("Load file error %d. File name: %S"), err, &fileName);
       
   356 			SetError(err);
       
   357 			}
       
   358 		}
       
   359 	}
       
   360 
       
   361 /** RSoundPlugIn::SetKeyClick() Call */
       
   362 void CT_DataSoundPlugIn::DoCmdSetKeyClick(const TDesC& aSection)
       
   363 	{
       
   364 	INFO_PRINTF1(_L("Calls RSoundPlugIn::SetKeyClick()"));
       
   365 	
       
   366 	// Get bool value from parameters
       
   367 	TBool keyClickEnabled = ETrue;
       
   368 	if(!GetBoolFromConfig(aSection, KEnabled(), keyClickEnabled))
       
   369 		{
       
   370 		ERR_PRINTF2(KLogMissingParameter, &KEnabled());
       
   371 		SetBlockResult(EFail);
       
   372 		}
       
   373 	else
       
   374 		{	
       
   375 		// Call SetKeyClick()
       
   376 		iSoundPlugIn->SetKeyClick(keyClickEnabled);
       
   377 		}
       
   378 	}
       
   379 
       
   380 /** RSoundPlugIn::KeyClickEnabled() Call */
       
   381 void CT_DataSoundPlugIn::DoCmdKeyClickEnabled(const TDesC& aSection)
       
   382 	{
       
   383 	// Call KeyClickEnabled() to get actual value
       
   384 	TBool actualValue = iSoundPlugIn->KeyClickEnabled();
       
   385 	INFO_PRINTF2(_L("Calls RSoundPlugIn::KeyClickEnabled() %d"), actualValue);
       
   386 	
       
   387 	// Get expected value from parameters
       
   388 	TBool expectedValue = EFalse;
       
   389 	if(GetBoolFromConfig(aSection, KExpectedBool(), expectedValue))
       
   390 		{
       
   391 		if(expectedValue != actualValue)
       
   392 			{
       
   393 			ERR_PRINTF3(_L("The returned value is not as expected, expected: %d, actual: %d"), expectedValue, actualValue);
       
   394 			SetBlockResult(EFail);
       
   395 			}
       
   396 		}
       
   397 	}
       
   398 
       
   399 /** RSoundPlugIn::SetPenClick() Call */
       
   400 void CT_DataSoundPlugIn::DoCmdSetPenClick(const TDesC& aSection)
       
   401 	{
       
   402 	INFO_PRINTF1(_L("Calls RSoundPlugIn::SetPenClick()"));
       
   403 	
       
   404 	// Get bool value from parameters
       
   405 	TBool penClickEnabled = ETrue;
       
   406 	if(!GetBoolFromConfig(aSection, KEnabled(), penClickEnabled))
       
   407 		{
       
   408 		ERR_PRINTF2(KLogMissingParameter, &KEnabled());
       
   409 		SetBlockResult(EFail);
       
   410 		}
       
   411 	else
       
   412 		{
       
   413 		// Call SetPenClick()
       
   414 		iSoundPlugIn->SetPenClick(penClickEnabled);
       
   415 		}
       
   416 	}
       
   417 
       
   418 /** RSoundPlugIn::PenClickEnabled() Call */
       
   419 void CT_DataSoundPlugIn::DoCmdPenClickEnabled(const TDesC& aSection)
       
   420 	{
       
   421 	// Call PenClickEnabled() to get actual value
       
   422 	TBool actualValue = iSoundPlugIn->PenClickEnabled();
       
   423 	INFO_PRINTF2(_L("Calls RSoundPlugIn::PenClickEnabled() %d"), actualValue);
       
   424 	
       
   425 	// Get expected value from parameters
       
   426 	TBool expectedValue = EFalse;
       
   427 	if(GetBoolFromConfig(aSection, KExpectedBool(), expectedValue))
       
   428 		{
       
   429 		if(expectedValue != actualValue)
       
   430 			{
       
   431 			ERR_PRINTF3(_L("The returned value is not as expected, expected: %d, actual: %d"), expectedValue, actualValue);
       
   432 			SetBlockResult(EFail);
       
   433 			}
       
   434 		}
       
   435 	}
       
   436 
       
   437 /** RSoundPlugIn::DoCmdCommandReply() Call */
       
   438 void CT_DataSoundPlugIn::DoCmdCommandReply(const TDesC& aSection)
       
   439 	{
       
   440 	INFO_PRINTF1(_L("Calls RSoundPlugIn::DoCmdCommandReply()"));
       
   441 	
       
   442 	TBool dataOK = ETrue;
       
   443 	
       
   444 	// Get Opcode from parameters
       
   445 	TInt opcode = 0;
       
   446 	if(!GetIntFromConfig(aSection, KOpcode(), opcode))
       
   447 		{
       
   448 		ERR_PRINTF2(KLogMissingParameter, &KOpcode());
       
   449 		SetBlockResult(EFail);
       
   450 		dataOK = EFalse;
       
   451 		}
       
   452 	
       
   453 	// Get packeaged args from parameters
       
   454 	TPtrC theString;
       
   455 	if(!GetStringFromConfig(aSection, KPackagedArgs(), theString))
       
   456 		{
       
   457 		ERR_PRINTF2(KLogMissingParameter, &KPackagedArgs());
       
   458 		SetBlockResult(EFail);
       
   459 		dataOK = EFalse;
       
   460 		}
       
   461 	
       
   462 	if(dataOK)
       
   463 		{
       
   464 		// Call CommandReply()
       
   465 		TInt err = iSoundPlugIn->CommandReply(opcode, TPckgC<TDesC>(theString));
       
   466 		
       
   467 		// Check error code
       
   468 		if ( err!=KErrNone )
       
   469 			{
       
   470 			ERR_PRINTF2(_L("CommandReply failed with error %d"), err);
       
   471 			SetError(err);
       
   472 			}
       
   473 		}
       
   474 	}