bluetoothapitest/bluetoothsvs/T_BTSdpAPI/src/T_DataCSdpSearchPattern.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 "T_DataCSdpSearchPattern.h"
       
    19 #include "T_BTUtil.h"
       
    20 
       
    21 /*@{*/
       
    22 
       
    23 //Commands
       
    24 _LIT(KCmdNewL, 												"NewL");
       
    25 _LIT(KCmdConstructL, 										"ConstructL");
       
    26 _LIT(KCmdAddL,												"AddL");
       
    27 _LIT(KCmdRemove,		 									"Remove");
       
    28 _LIT(KCmdFind,	 											"Find");
       
    29 _LIT(KCmdCount,	 											"Count");
       
    30 _LIT(KCmdAt,	 											"At");
       
    31 _LIT(KCmdReset,	 											"Reset");
       
    32 _LIT(KCmdIsEmpty,	 										"IsEmpty");
       
    33 _LIT(KCmdDestructor, 										"~");
       
    34 
       
    35 
       
    36 //Parameters
       
    37 _LIT(KUUID, 												"uuid");
       
    38 _LIT(KExpected, 											"expected");
       
    39 _LIT(KPosition, 											"position");
       
    40 _LIT(KIndex, 												"index");
       
    41 
       
    42 /*@}*/
       
    43 
       
    44 //////////////////////////////////////////////////////////////////////
       
    45 // Construction/Destruction
       
    46 //////////////////////////////////////////////////////////////////////
       
    47 
       
    48 CT_DataCSdpSearchPattern* CT_DataCSdpSearchPattern::NewL()
       
    49 	{
       
    50 	CT_DataCSdpSearchPattern*	ret=new (ELeave) CT_DataCSdpSearchPattern();
       
    51 	CleanupStack::PushL(ret);
       
    52 	ret->ConstructL();
       
    53 	CleanupStack::Pop(ret);
       
    54 	return ret;
       
    55 	}
       
    56 
       
    57 CT_DataCSdpSearchPattern::CT_DataCSdpSearchPattern()
       
    58 :	iSearchPattern(NULL)
       
    59 ,	iElementBuilder(NULL)
       
    60 	{
       
    61 	}
       
    62 
       
    63 void CT_DataCSdpSearchPattern::ConstructL()
       
    64 	{
       
    65 	iElementBuilder = new (ELeave) CT_DataSdpElementBuilder(*this);
       
    66 	}
       
    67 
       
    68 CT_DataCSdpSearchPattern::~CT_DataCSdpSearchPattern()
       
    69 	{
       
    70 	DestroyData();
       
    71 	delete iElementBuilder;
       
    72 	iElementBuilder=NULL;
       
    73 	}
       
    74 
       
    75 void CT_DataCSdpSearchPattern::SetObjectL(TAny* aAny)
       
    76 	{
       
    77 	DestroyData();
       
    78 	iSearchPattern = static_cast<CSdpSearchPattern*> (aAny);
       
    79 	}
       
    80 
       
    81 void CT_DataCSdpSearchPattern::DisownObjectL()
       
    82 	{
       
    83 	iSearchPattern = NULL;
       
    84 	}
       
    85 
       
    86 void CT_DataCSdpSearchPattern::DestroyData()
       
    87 	{
       
    88 	delete iSearchPattern;
       
    89 	iSearchPattern=NULL;
       
    90 	}
       
    91 
       
    92 inline TCleanupOperation CT_DataCSdpSearchPattern::CleanupOperation()
       
    93 	{
       
    94 	return CleanupOperation;
       
    95 	}
       
    96 
       
    97 void CT_DataCSdpSearchPattern::CleanupOperation(TAny* aAny)
       
    98 	{
       
    99 	CSdpSearchPattern* pattern=static_cast<CSdpSearchPattern*>(aAny);
       
   100 	delete pattern;
       
   101 	}
       
   102 
       
   103 /**
       
   104  * Process a command read from the ini file
       
   105  *
       
   106  * @param aCommand			The command to process
       
   107  * @param aSection			The section in the ini containing data for the command
       
   108  * @param aAsyncErrorIndex	Command index for async calls to return errors to
       
   109  *
       
   110  * @return					ETrue if the command is processed
       
   111  *
       
   112  * @leave					System wide error
       
   113  */
       
   114 TBool CT_DataCSdpSearchPattern::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
   115 	{
       
   116 	TBool	ret=ETrue;
       
   117 
       
   118 	if ( aCommand==KCmdNewL )
       
   119 		{
       
   120 		DoCmdNewL();
       
   121 		}
       
   122 	else if ( aCommand==KCmdConstructL )
       
   123 		{
       
   124 		DoCmdConstructL();
       
   125 		}
       
   126 	else if ( aCommand==KCmdAddL )
       
   127 		{
       
   128 		DoCmdAddL(aSection);
       
   129 		}
       
   130 	else if ( aCommand==KCmdRemove )
       
   131 		{
       
   132 		DoCmdRemove(aSection);
       
   133 		}
       
   134 	else if ( aCommand==KCmdFind )
       
   135 		{
       
   136 		DoCmdFind(aSection);
       
   137 		}
       
   138 	else if ( aCommand==KCmdCount )
       
   139 		{
       
   140 		DoCmdCount(aSection);
       
   141 		}
       
   142 	else if ( aCommand==KCmdAt )
       
   143 		{
       
   144 		DoCmdAt(aSection);
       
   145 		}
       
   146 	else if ( aCommand==KCmdReset )
       
   147 		{
       
   148 		DoCmdReset();
       
   149 		}
       
   150 	else if ( aCommand==KCmdIsEmpty )
       
   151 		{
       
   152 		DoCmdIsEmpty(aSection);
       
   153 		}
       
   154 	else if ( aCommand==KCmdDestructor )
       
   155 		{
       
   156 		DoCmdDestructor();
       
   157 		}
       
   158 	else
       
   159 		{
       
   160 		ret = EFalse;
       
   161 		}
       
   162 
       
   163 	if( !ret )
       
   164 		{
       
   165 		ret=iElementBuilder->DoCommandL(*iSearchPattern, aCommand, aSection, aAsyncErrorIndex);
       
   166 		}
       
   167 
       
   168 	return ret;
       
   169 	}
       
   170 
       
   171 
       
   172 /**
       
   173 Test NewL()
       
   174 */
       
   175 void CT_DataCSdpSearchPattern::DoCmdNewL()
       
   176 	{
       
   177 	DestroyData();
       
   178 	INFO_PRINTF1(_L("CSdpSearchPattern NewL call"));
       
   179 	TRAPD(err, iSearchPattern = CSdpSearchPattern::NewL());
       
   180 	if(err != KErrNone)
       
   181 		{
       
   182 		ERR_PRINTF2(_L("CSdpSearchPattern NewL failed with error %d"), err);
       
   183 		SetError(err);
       
   184 		}
       
   185 	}
       
   186 
       
   187 /**
       
   188 Test ConstructL()
       
   189 */
       
   190 void CT_DataCSdpSearchPattern::DoCmdConstructL()
       
   191 	{
       
   192 	INFO_PRINTF1(_L("CSdpSearchPattern ConstructL Call"));
       
   193 
       
   194 	TRAPD(err, iSearchPattern->ConstructL());
       
   195 	if(err != KErrNone)
       
   196 		{
       
   197 		ERR_PRINTF2(_L("CSdpSearchPattern NewL failed with error %d"), err);
       
   198 		SetError(err);
       
   199 		}
       
   200 	}
       
   201 
       
   202 /**
       
   203 Test AddL()
       
   204 */
       
   205 void CT_DataCSdpSearchPattern::DoCmdAddL(const TDesC& aSection)
       
   206 	{
       
   207 	INFO_PRINTF1(_L("CSdpSearchPattern AddL Call"));
       
   208 
       
   209 	TInt 								theValue = 0;
       
   210 	if( GetIntFromConfig(aSection, KUUID(), theValue) )
       
   211 		{
       
   212 		const TUUID theUUID(theValue);
       
   213 		TInt position = 0;
       
   214 		TRAPD(err, position = iSearchPattern->AddL(theUUID));
       
   215 		if(err != KErrNone)
       
   216 			{
       
   217 			ERR_PRINTF2(_L("CSdpSearchPattern AddL failed with error %d"), err);
       
   218 			SetError(err);
       
   219 			}
       
   220 		INFO_PRINTF2(_L("CSdpSearchPattern AddL Call result: actual = %d"), position);
       
   221 
       
   222 		TInt expected = 0;
       
   223 		if( GetIntFromConfig(aSection, KExpected(), expected) )
       
   224 			{
       
   225 			if( position != expected )
       
   226 				{
       
   227 				ERR_PRINTF1(_L("AddL not as expected!"));
       
   228 				SetBlockResult(EFail);
       
   229 				}
       
   230 			}
       
   231 		else
       
   232 			{
       
   233 			ERR_PRINTF2(_L("Missing expected value %S"), &KExpected());
       
   234 			SetBlockResult(EFail);			
       
   235 			}
       
   236 		}
       
   237 	else
       
   238 		{
       
   239 		ERR_PRINTF2(_L("Missing parameter %S"), &KExpected());
       
   240 		SetBlockResult(EFail);
       
   241 		}
       
   242 	}
       
   243 
       
   244 /**
       
   245 Test Remove()
       
   246 */
       
   247 void CT_DataCSdpSearchPattern::DoCmdRemove(const TDesC& aSection)
       
   248 	{
       
   249 	INFO_PRINTF1(_L("CSdpSearchPattern Remove Call"));
       
   250 
       
   251 	TInt 								theValue = 0;
       
   252 	if( GetIntFromConfig(aSection, KUUID(), theValue))
       
   253 		{
       
   254 		const TUUID theUUID(theValue);
       
   255 		TInt position = iSearchPattern->Remove(theUUID);
       
   256 		INFO_PRINTF2(_L("CSdpSearchPattern Remove Call result: actual = %d"), position);
       
   257 
       
   258 		TInt expected = 0;
       
   259 		if( GetIntFromConfig(aSection, KExpected(), expected) )
       
   260 			{
       
   261 			if( expected != position )
       
   262 				{
       
   263 				ERR_PRINTF1(_L("Remove not as expected!"));
       
   264 				SetBlockResult(EFail);
       
   265 				}
       
   266 			}
       
   267 		else
       
   268 			{
       
   269 			ERR_PRINTF2(_L("Missing expected value %S"), &KExpected());
       
   270 			SetBlockResult(EFail);		
       
   271 			}
       
   272 		}
       
   273 	else
       
   274 		{
       
   275 		ERR_PRINTF2(_L("Missing parameter %S"), &KExpected());
       
   276 		SetBlockResult(EFail);
       
   277 		}
       
   278 	}
       
   279 
       
   280 /**
       
   281 Test Find()
       
   282 */
       
   283 void CT_DataCSdpSearchPattern::DoCmdFind(const TDesC& aSection)
       
   284 	{
       
   285 	INFO_PRINTF1(_L("CSdpSearchPattern Find Call"));
       
   286 
       
   287 	TInt 								theValue = 0;
       
   288 	if( GetIntFromConfig(aSection, KUUID(), theValue))
       
   289 		{
       
   290 		const TUUID theUUID(theValue);
       
   291 		TInt position = 0;
       
   292 		TInt result = iSearchPattern->Find(theUUID, position);
       
   293 		INFO_PRINTF2(_L("CSdpSearchPattern Find Call return value: actual = %d"), result);
       
   294 		INFO_PRINTF2(_L("CSdpSearchPattern Find Call position: actual = %d"), position);
       
   295 
       
   296 		TInt expectedResult = 0;
       
   297 		if( GetIntFromConfig(aSection, KExpected(), expectedResult) )
       
   298 			{
       
   299 			if( expectedResult != result )
       
   300 				{
       
   301 				ERR_PRINTF1(_L("Find not as expected!"));
       
   302 				SetBlockResult(EFail);
       
   303 				}
       
   304 			}
       
   305 		else
       
   306 			{
       
   307 			ERR_PRINTF2(_L("Missing expected value %S"), &KExpected());
       
   308 			SetBlockResult(EFail);		
       
   309 			}
       
   310 
       
   311 		TInt expectedPosition = 0;
       
   312 		if( GetIntFromConfig(aSection, KPosition(), expectedPosition) )
       
   313 			{
       
   314 			if( expectedPosition != position )
       
   315 				{
       
   316 				ERR_PRINTF1(_L("Find not as expected!"));
       
   317 				SetBlockResult(EFail);
       
   318 				}
       
   319 			}
       
   320 		else
       
   321 			{
       
   322 			ERR_PRINTF2(_L("Missing expected value %S"), &KPosition());
       
   323 			SetBlockResult(EFail);		
       
   324 			}
       
   325 		}
       
   326 	else
       
   327 		{
       
   328 		ERR_PRINTF2(_L("Missing parameter %S"), &KPosition());
       
   329 		SetBlockResult(EFail);
       
   330 		}
       
   331 	}
       
   332 
       
   333 /**
       
   334 Test Count()
       
   335 */
       
   336 void CT_DataCSdpSearchPattern::DoCmdCount(const TDesC& aSection)
       
   337 	{
       
   338 	INFO_PRINTF1(_L("CSdpSearchPattern Count Call"));
       
   339 
       
   340 	TInt	count = iSearchPattern->Count();
       
   341 	INFO_PRINTF2(_L("CSdpSearchPattern Count Call result: actual = %d"), count);
       
   342 
       
   343 	TInt								expected = 0;
       
   344 	if( GetIntFromConfig(aSection, KExpected(), expected) )
       
   345 		{
       
   346 		if( expected != count )
       
   347 			{
       
   348 			ERR_PRINTF1(_L("Count not as expected!"));
       
   349 			SetBlockResult(EFail);
       
   350 			}
       
   351 		}
       
   352 	else
       
   353 		{
       
   354 		ERR_PRINTF2(_L("Missing expected value %S"), &KExpected());
       
   355 		SetBlockResult(EFail);		
       
   356 		}
       
   357 	}
       
   358 
       
   359 /**
       
   360 Test At()
       
   361 */
       
   362 void CT_DataCSdpSearchPattern::DoCmdAt(const TDesC& aSection)
       
   363 	{
       
   364 	INFO_PRINTF1(_L("CSdpSearchPattern At Call"));
       
   365 
       
   366 	TInt 								theValue = 0;
       
   367 	if( GetIntFromConfig(aSection, KIndex(), theValue))
       
   368 		{
       
   369 		TUUID	theUUID = iSearchPattern->At(theValue);
       
   370 		TUint	intUUid= CT_BTUtil::ConvertUUID32toInt(theUUID);
       
   371 		INFO_PRINTF2(_L("CSdpSearchPattern At Call result: actual = %d"), intUUid);
       
   372 		
       
   373 		TInt expected = 0;
       
   374 		if( GetIntFromConfig(aSection, KExpected(), expected))
       
   375 			{
       
   376 			if( TUUID(expected) != theUUID)
       
   377 				{
       
   378 				ERR_PRINTF1(_L("At not as expected!"));
       
   379 				SetBlockResult(EFail);
       
   380 				}
       
   381 			}
       
   382 		else
       
   383 			{
       
   384 			ERR_PRINTF2(_L("Missing expected value %S"), &KExpected());
       
   385 			SetBlockResult(EFail);		
       
   386 			}
       
   387 		}
       
   388 	else
       
   389 		{
       
   390 		ERR_PRINTF2(_L("Missing parameter %S"), &KExpected());
       
   391 		SetBlockResult(EFail);
       
   392 		}
       
   393 	}
       
   394 
       
   395 /**
       
   396 Test Reset()
       
   397 */
       
   398 void CT_DataCSdpSearchPattern::DoCmdReset()
       
   399 	{
       
   400 	INFO_PRINTF1(_L("CSdpSearchPattern Reset Call"));
       
   401 
       
   402 	iSearchPattern->Reset();
       
   403 	}
       
   404 
       
   405 /**
       
   406 Test IsEmpty()
       
   407 */
       
   408 void CT_DataCSdpSearchPattern::DoCmdIsEmpty(const TDesC& aSection)
       
   409 	{
       
   410 	INFO_PRINTF1(_L("CSdpSearchPattern IsEmpty Call"));
       
   411 
       
   412 	TBool	result = iSearchPattern->IsEmpty();
       
   413 	INFO_PRINTF2(_L("CSdpSearchPattern IsEmpty Call result: actual = %d"), result);
       
   414 
       
   415 	TBool expected = EFalse;
       
   416 	if( GetBoolFromConfig(aSection, KExpected(), expected) )
       
   417 		{
       
   418 		if(result != expected)
       
   419 			{
       
   420 			ERR_PRINTF1(_L("IsEmpty not as expected!"));
       
   421 			SetBlockResult(EFail);
       
   422 			}
       
   423 		}
       
   424 	else
       
   425 		{
       
   426 		ERR_PRINTF2(_L("Missing expected value %S"), &KExpected());
       
   427 		SetBlockResult(EFail);		
       
   428 		}
       
   429 	}
       
   430 
       
   431 /**
       
   432 Test ~CSdpSearchPattern()
       
   433 */
       
   434 void CT_DataCSdpSearchPattern::DoCmdDestructor()
       
   435 	{
       
   436 	INFO_PRINTF1(_L("CSdpSearchPattern Destructor Call"));
       
   437 
       
   438 	DestroyData();
       
   439 	}