bluetoothapitest/bluetoothsvs/T_BTUserAPI/src/T_SEIDData.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     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 "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <bluetoothav.h>
       
    19 //	User Includes
       
    20 #include "T_SEIDData.h"
       
    21 
       
    22 /*@{*/
       
    23 //Parameters
       
    24 
       
    25 //Fields
       
    26 _LIT(KFldExpected,						"expected");
       
    27 _LIT(KFldSeid,							"seid");
       
    28 _LIT(KFldIsLocal,						"islocal");
       
    29 _LIT(KFldValue,							"value");
       
    30 
       
    31 //Commands
       
    32 _LIT(KCmdnew,							"new");
       
    33 _LIT(KCmdSEID,							"SEID");
       
    34 _LIT(KCmdPacketValue,					"PacketValue");
       
    35 _LIT(KCmdIsValid,						"IsValid");
       
    36 _LIT(KCmdSet,							"Set");
       
    37 _LIT(KCmdCompare,						"==");
       
    38 _LIT(KCmdNegativeCompare,				"!=");
       
    39 _LIT(KCmd_Spare,						"_Spare");
       
    40 _LIT(KCmdFromPacketL,					"FromPacketL");
       
    41 _LIT(KCmdReset,							"Reset");
       
    42 _LIT(KCmdIsLocal,						"IsLocal");
       
    43 _LIT(KCmdValue,							"Value"); 
       
    44 _LIT(KCmdDestructor,					"~"); 
       
    45 //Log
       
    46 _LIT(KLogError,							"Error=%d");
       
    47 _LIT(KLogMissingParameter,				"Missing parameter '%S'");
       
    48 _LIT(KLogNotExpectedValue,				"Not expected value");
       
    49 /*@}*/
       
    50 
       
    51 //////////////////////////////////////////////////////////////////////
       
    52 // Construction/Destruction
       
    53 //////////////////////////////////////////////////////////////////////
       
    54 
       
    55 CT_SEIDData* CT_SEIDData::NewL()
       
    56 	{
       
    57 	CT_SEIDData*	ret=new (ELeave) CT_SEIDData();
       
    58 	CleanupStack::PushL(ret);
       
    59 	ret->ConstructL();
       
    60 	CleanupStack::Pop(ret);
       
    61 	return ret;
       
    62 	}
       
    63 
       
    64 CT_SEIDData::CT_SEIDData()
       
    65 :	iData(NULL)
       
    66 	{
       
    67 	}
       
    68 
       
    69 void CT_SEIDData::ConstructL()
       
    70 	{
       
    71 	}
       
    72 
       
    73 CT_SEIDData::~CT_SEIDData()
       
    74 	{
       
    75 	DestroyData();
       
    76 	}
       
    77 
       
    78 TAny* CT_SEIDData::GetObject()
       
    79 	{
       
    80 	return iData;
       
    81 	}
       
    82 
       
    83 
       
    84 void CT_SEIDData::SetObjectL(TAny* aAny)
       
    85 	{
       
    86 	DestroyData();
       
    87 	iData = static_cast<TSEID*> (aAny);
       
    88 	}
       
    89 
       
    90 void CT_SEIDData::DisownObjectL()
       
    91 	{
       
    92 	iData = NULL;
       
    93 	}
       
    94 
       
    95 void CT_SEIDData::DestroyData()
       
    96 	{
       
    97 	delete iData;
       
    98 	iData=NULL;	
       
    99 	}
       
   100 
       
   101 inline TCleanupOperation CT_SEIDData::CleanupOperation()
       
   102 	{
       
   103 	return CleanupOperation;
       
   104 	}
       
   105 
       
   106 void CT_SEIDData::CleanupOperation(TAny* aAny)
       
   107 	{
       
   108 	//may be unnecessary
       
   109 	TSEID* arg=static_cast<TSEID*>(aAny);
       
   110 	delete arg;
       
   111 	}
       
   112 
       
   113 
       
   114 TBool CT_SEIDData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
   115 	{
       
   116 	TBool	ret = ETrue;
       
   117 	
       
   118 	if ( aCommand==KCmdnew )
       
   119 		{
       
   120 		DoCmdnewL(aSection);
       
   121 		}
       
   122 	else if ( aCommand==KCmdSEID )
       
   123 		{
       
   124 		DoCmdSEID(aSection);
       
   125 		}
       
   126 	else if ( aCommand==KCmdPacketValue )
       
   127 		{
       
   128 		DoCmdPacketValue(aSection);
       
   129 		}
       
   130 	else if ( aCommand==KCmdIsValid )
       
   131 		{
       
   132 		DoCmdIsValid(aSection);
       
   133 		}
       
   134 	else if ( aCommand==KCmdSet )
       
   135 		{
       
   136 		DoCmdSet(aSection);
       
   137 		}
       
   138 	else if ( aCommand==KCmdCompare )
       
   139 		{
       
   140 		DoCmdCompareL(aSection);
       
   141 		}
       
   142 	else if ( aCommand==KCmdNegativeCompare )
       
   143 		{
       
   144 		DoCmdNegativeCompareL(aSection);
       
   145 		}
       
   146 	else if ( aCommand==KCmd_Spare )
       
   147 		{
       
   148 		DoCmd_Spare(aSection);
       
   149 		}
       
   150 	else if ( aCommand==KCmdFromPacketL )
       
   151 		{
       
   152 		DoCmdFromPacketL(aSection);
       
   153 		}
       
   154 	else if ( aCommand==KCmdReset )
       
   155 		{
       
   156 		DoCmdReset(aSection);
       
   157 		}
       
   158 	else if ( aCommand==KCmdIsLocal )
       
   159 		{
       
   160 		DoCmdIsLocal(aSection);
       
   161 		}
       
   162 	else if ( aCommand==KCmdValue )
       
   163 		{
       
   164 		DoCmdValue(aSection);
       
   165 		}
       
   166 	else if ( aCommand==KCmdDestructor )
       
   167 		{
       
   168 		DestroyData();
       
   169 		}
       
   170 	else
       
   171 		{
       
   172 		ret=EFalse;
       
   173 		}
       
   174 
       
   175 	return ret;
       
   176 	}
       
   177 
       
   178 /**
       
   179 Test TSEID()
       
   180 */
       
   181 void CT_SEIDData::DoCmdnewL(const TDesC& aSection)
       
   182 	{
       
   183 	INFO_PRINTF1(_L("TSEID Constructor Call"));
       
   184 	DestroyData();
       
   185 	
       
   186 	
       
   187 	TBool	isTwoParameters=EFalse;
       
   188 	TBool	isOneParameter=EFalse;
       
   189 	
       
   190 	TInt	seid=0;
       
   191 	TBool	islocal=EFalse;
       
   192 	
       
   193 	TInt	value=0;
       
   194 	TInt 	dataOK = ETrue;
       
   195 	
       
   196 	if( GetIntFromConfig(aSection, KFldSeid(), seid) )
       
   197 		{
       
   198 		if(GetBoolFromConfig(aSection, KFldIsLocal(), islocal) )
       
   199 			{
       
   200 			INFO_PRINTF1(_L("Constructor got 2 parameters.)"));
       
   201 			isTwoParameters = ETrue;
       
   202 			}
       
   203 		else
       
   204 			{
       
   205 			ERR_PRINTF2(KLogMissingParameter, &KFldIsLocal);
       
   206 			dataOK = EFalse;
       
   207 			SetBlockResult(EFail);
       
   208 			}
       
   209 		}
       
   210 	else
       
   211 		{
       
   212 		if( GetIntFromConfig(aSection, KFldValue(), value) )
       
   213 			{
       
   214 			INFO_PRINTF1(_L("Constructor got parameter as value"));
       
   215 			isOneParameter = ETrue;
       
   216 			}
       
   217 		}
       
   218 	
       
   219 	if(dataOK)
       
   220 		{
       
   221 		TInt err = KErrNone;
       
   222 		if(isTwoParameters)
       
   223 			{
       
   224 			INFO_PRINTF1(_L("Constructor called is TSEID(TUint, TBool)"));
       
   225 			TRAP( err, iData = new (ELeave) TSEID(seid,islocal));
       
   226 			}
       
   227 		else if(isOneParameter)
       
   228 			{
       
   229 			INFO_PRINTF1(_L("Constructor called is TSEID(TUint)."));
       
   230 			TRAP( err, iData = new (ELeave) TSEID(value));
       
   231 			}
       
   232 		else
       
   233 			{
       
   234 			INFO_PRINTF1(_L("Constructor called is TSEID()."));
       
   235 			TRAP( err, iData = new (ELeave) TSEID());
       
   236 			}
       
   237 		
       
   238 		if ( err!=KErrNone )
       
   239 			{
       
   240 			ERR_PRINTF2(KLogError, err);
       
   241 			SetError(err);
       
   242 			}
       
   243 		}
       
   244 	
       
   245 	}
       
   246 
       
   247 /**
       
   248 Test SEID()
       
   249 */
       
   250 void CT_SEIDData::DoCmdSEID(const TDesC& aSection)
       
   251 	{
       
   252 	INFO_PRINTF1(_L("TSEID SEID() Call."));
       
   253 	TInt actual = iData->SEID();
       
   254 	INFO_PRINTF2(_L("SEID()=%d"), actual);
       
   255 	
       
   256 	TInt expected=0;
       
   257 	if( !GetIntFromConfig(aSection, KFldExpected(), expected) )
       
   258 		{
       
   259 		ERR_PRINTF2(KLogMissingParameter, &KFldExpected);
       
   260 		SetBlockResult(EFail);
       
   261 		}
       
   262 	else
       
   263 		{
       
   264 		if ( actual!=expected )
       
   265 			{
       
   266 			ERR_PRINTF1(KLogNotExpectedValue);
       
   267 			SetBlockResult(EFail);
       
   268 			}
       
   269 		}
       
   270 	}
       
   271 
       
   272 /**
       
   273 Test PacketValue()
       
   274 */
       
   275 void CT_SEIDData::DoCmdPacketValue(const TDesC& aSection)
       
   276 	{
       
   277 	INFO_PRINTF1(_L("TSEID PacketValue() Call."));
       
   278 	TInt actual = iData->PacketValue();
       
   279 	INFO_PRINTF2(_L("PacketValue()=%d"), actual);
       
   280 	
       
   281 	TInt expected=0;
       
   282 	if( !GetIntFromConfig(aSection, KFldExpected(), expected) )
       
   283 		{
       
   284 		ERR_PRINTF2(KLogMissingParameter, &KFldExpected);
       
   285 		SetBlockResult(EFail);
       
   286 		}
       
   287 	else
       
   288 		{
       
   289 		if ( actual!=expected )
       
   290 			{
       
   291 			ERR_PRINTF1(KLogNotExpectedValue);
       
   292 			SetBlockResult(EFail);
       
   293 			}
       
   294 		}
       
   295 	}
       
   296 
       
   297 /**
       
   298 Test IsValid()
       
   299 */
       
   300 void CT_SEIDData::DoCmdIsValid(const TDesC& aSection)
       
   301 	{
       
   302 	INFO_PRINTF1(_L("TSEID IsValid() Call."));
       
   303 	TBool actual = iData->IsValid();
       
   304 	INFO_PRINTF2(_L("IsValid()=%d"), actual);
       
   305 	
       
   306 	TBool expected = EFalse;
       
   307 	if( !GetBoolFromConfig(aSection, KFldExpected(), expected) )
       
   308 		{
       
   309 		ERR_PRINTF2(KLogMissingParameter, &KFldExpected);
       
   310 		SetBlockResult(EFail);
       
   311 		}
       
   312 	else
       
   313 		{
       
   314 		if ( actual!=expected )
       
   315 			{
       
   316 			ERR_PRINTF1(KLogNotExpectedValue);
       
   317 			SetBlockResult(EFail);
       
   318 			}
       
   319 		}
       
   320 	}
       
   321 
       
   322 /**
       
   323 Test Set()
       
   324 */
       
   325 void CT_SEIDData::DoCmdSet(const TDesC& aSection)
       
   326 	{	
       
   327 	INFO_PRINTF1(_L("TSEID Set() Call."));
       
   328 	TInt value=0;
       
   329 	if( !GetIntFromConfig(aSection, KFldValue(), value) )
       
   330 		{
       
   331 		ERR_PRINTF2(KLogMissingParameter, &KFldValue);
       
   332 		SetBlockResult(EFail);
       
   333 		}
       
   334 	else
       
   335 		{
       
   336 		INFO_PRINTF2(_L("Execute Set(TUint), value = %d"), value);
       
   337 		iData->Set(value);
       
   338 		}
       
   339 	}
       
   340 
       
   341 /**
       
   342 Test operator==()
       
   343 */
       
   344 void CT_SEIDData::DoCmdCompareL(const TDesC& aSection)
       
   345 	{
       
   346 	INFO_PRINTF1(_L("TSEID == Call."));
       
   347 	TSEID*	seid=NULL;
       
   348 	TPtrC	seidName;
       
   349 	if ( !GetStringFromConfig(aSection, KFldSeid, seidName) )
       
   350 		{
       
   351 		ERR_PRINTF2(KLogMissingParameter, &KFldSeid);
       
   352 		SetBlockResult(EFail);
       
   353 		}
       
   354 	else
       
   355 		{
       
   356 		seid = static_cast<TSEID*>(GetDataObjectL(seidName));
       
   357 		}	
       
   358 	
       
   359 	if(seid)
       
   360 		{
       
   361 		TBool actual = iData->operator ==(*seid);
       
   362 		INFO_PRINTF2(_L("execute operator==(TSEID) = %d"), actual);
       
   363 		
       
   364 		TBool expected=EFalse;
       
   365 		if( !GetBoolFromConfig(aSection, KFldExpected(), expected) )
       
   366 			{
       
   367 			ERR_PRINTF2(KLogMissingParameter, &KFldExpected);
       
   368 			SetBlockResult(EFail);
       
   369 			}
       
   370 		else
       
   371 			{
       
   372 			if ( actual!=expected )
       
   373 				{
       
   374 				ERR_PRINTF1(KLogNotExpectedValue);
       
   375 				SetBlockResult(EFail);
       
   376 				}
       
   377 			}
       
   378 		}
       
   379 	else
       
   380 		{
       
   381 		ERR_PRINTF1(_L("seid is NULL"));
       
   382 		SetBlockResult(EFail);
       
   383 		}
       
   384 	}
       
   385 
       
   386 /**
       
   387 Test operator!=()
       
   388 */
       
   389 void CT_SEIDData::DoCmdNegativeCompareL(const TDesC& aSection)
       
   390 	{
       
   391 	INFO_PRINTF1(_L("TSEID != Call."));
       
   392 	TSEID*	seid=NULL;
       
   393 	TPtrC	seidName;
       
   394 	if ( !GetStringFromConfig(aSection, KFldSeid, seidName) )
       
   395 		{
       
   396 		ERR_PRINTF2(KLogMissingParameter, &KFldSeid);
       
   397 		SetBlockResult(EFail);
       
   398 		}
       
   399 	else
       
   400 		{
       
   401 		seid = static_cast<TSEID*>(GetDataObjectL(seidName));
       
   402 		}	
       
   403 	
       
   404 	if(seid)
       
   405 		{
       
   406 		TBool actual = iData->operator !=(*seid);
       
   407 		INFO_PRINTF2(_L("execuete operator !=(TSEID) = %d"), actual);
       
   408 		
       
   409 		TBool expected=EFalse;
       
   410 		if( !GetBoolFromConfig(aSection, KFldExpected(), expected) )
       
   411 			{
       
   412 			ERR_PRINTF2(KLogMissingParameter, &KFldExpected);
       
   413 			SetBlockResult(EFail);
       
   414 			}
       
   415 		else
       
   416 			{
       
   417 			if ( actual!=expected )
       
   418 				{
       
   419 				ERR_PRINTF1(KLogNotExpectedValue);
       
   420 				SetBlockResult(EFail);
       
   421 				}
       
   422 			}
       
   423 		}
       
   424 	else
       
   425 		{
       
   426 		ERR_PRINTF1(_L("seid is NULL"));
       
   427 		SetBlockResult(EFail);
       
   428 		}
       
   429 	}
       
   430 
       
   431 /**
       
   432 Test _Spare()
       
   433 */
       
   434 void CT_SEIDData::DoCmd_Spare(const TDesC& /*aSection*/)
       
   435 	{
       
   436 	//Not implemented!
       
   437 	}
       
   438 
       
   439 /**
       
   440 Test FromPacketL()
       
   441 */
       
   442 void CT_SEIDData::DoCmdFromPacketL(const TDesC& /*aSection*/)
       
   443 	{
       
   444 	//Not implemented!
       
   445 	}
       
   446 
       
   447 /**
       
   448 Test Reset()
       
   449 */
       
   450 void CT_SEIDData::DoCmdReset(const TDesC& /*aSection*/)
       
   451 	{
       
   452 	INFO_PRINTF1(_L("TSEID Reset() Call."));
       
   453 	iData->Reset();
       
   454 	}
       
   455 
       
   456 /**
       
   457 Test IsLocal()
       
   458 */
       
   459 void CT_SEIDData::DoCmdIsLocal(const TDesC& aSection)
       
   460 	{
       
   461 	INFO_PRINTF1(_L("TSEID IsLocal() Call."));
       
   462 	TBool actual = iData->IsLocal();
       
   463 	INFO_PRINTF2(_L("IsLocal()=%d"), actual);
       
   464 	
       
   465 	TBool expected = EFalse;
       
   466 	if( !GetBoolFromConfig(aSection, KFldExpected(), expected) )
       
   467 		{
       
   468 		ERR_PRINTF2(KLogMissingParameter, &KFldExpected);
       
   469 		SetBlockResult(EFail);
       
   470 		}
       
   471 	else
       
   472 		{
       
   473 		if ( actual!=expected )
       
   474 			{
       
   475 			ERR_PRINTF1(KLogNotExpectedValue);
       
   476 			SetBlockResult(EFail);
       
   477 			}
       
   478 		}
       
   479 	}
       
   480 
       
   481 /**
       
   482 Test Value()
       
   483 */
       
   484 void CT_SEIDData::DoCmdValue(const TDesC& aSection)
       
   485 	{
       
   486 	INFO_PRINTF1(_L("TSEID Value() Call."));
       
   487 	TInt actual = iData->Value();
       
   488 	INFO_PRINTF2(_L("Value()=%d"), actual);
       
   489 	
       
   490 	TInt expected=0;
       
   491 	if( !GetIntFromConfig(aSection, KFldExpected(), expected) )
       
   492 		{
       
   493 		ERR_PRINTF2(KLogMissingParameter, &KFldExpected);
       
   494 		SetBlockResult(EFail);
       
   495 		}
       
   496 	else
       
   497 		{
       
   498 		if ( actual!=expected )
       
   499 			{
       
   500 			ERR_PRINTF1(KLogNotExpectedValue);
       
   501 			SetBlockResult(EFail);
       
   502 			}
       
   503 		}
       
   504 	}