contacts_plat/predictivesearch_utils_api/tsrc/PsUtilsTestSuite/src/TestSuiteInputData.cpp
branchRCL_3
changeset 39 a6539d1e8e43
parent 0 e686773b3f54
child 64 c1e8ba0c2b16
equal deleted inserted replaced
35:4ae315f230bc 39:a6539d1e8e43
    41 // ----------------------------------------------------------------------------
    41 // ----------------------------------------------------------------------------
    42 CTestSuiteInputData::CTestSuiteInputData()
    42 CTestSuiteInputData::CTestSuiteInputData()
    43 {
    43 {
    44 }
    44 }
    45 
    45 
    46 
       
    47 // ----------------------------------------------------------------------------
    46 // ----------------------------------------------------------------------------
    48 // Destructor
    47 // Destructor
    49 // ----------------------------------------------------------------------------
    48 // ----------------------------------------------------------------------------
    50 CTestSuiteInputData::~CTestSuiteInputData()
    49 CTestSuiteInputData::~CTestSuiteInputData()
    51 {    	
    50 {    	
    52     	
       
    53     if(iQueryBuf)
    51     if(iQueryBuf)
    54     {
    52     {
    55     	delete iQueryBuf;
    53     	delete iQueryBuf;
    56 		iQueryBuf = NULL;    
    54 		iQueryBuf = NULL;    
    57     }	
    55     }	
    59     {
    57     {
    60     	delete iKeyboardModeBuf;
    58     	delete iKeyboardModeBuf;
    61     	iKeyboardModeBuf = NULL;
    59     	iKeyboardModeBuf = NULL;
    62     }
    60     }
    63 
    61 
    64 	
    62     iCacheUris.ResetAndDestroy();
    65 	iCacheUris.ResetAndDestroy();
       
    66 	
       
    67 
    63 
    68 	iDisplayFields.Close();
    64 	iDisplayFields.Close();
    69 
       
    70 }
    65 }
    71 
    66 
    72 // ----------------------------------------------------------------------------
    67 // ----------------------------------------------------------------------------
    73 // Destructor
    68 // Destructor
    74 // ----------------------------------------------------------------------------
    69 // ----------------------------------------------------------------------------
    85 	return iId;
    80 	return iId;
    86 }
    81 }
    87 
    82 
    88 void CTestSuiteInputData::Data(RPointerArray<TDesC> & aDataArray)
    83 void CTestSuiteInputData::Data(RPointerArray<TDesC> & aDataArray)
    89 {
    84 {
    90 	for(TInt i = 0 ; i < iDataArray.Count(); i++)
    85 	for(TInt i = 0; i < iDataArray.Count(); i++)
    91 	{
    86 	{
    92 		aDataArray.Append(iDataArray[i]->AllocL());
    87 		aDataArray.Append(iDataArray[i]->AllocL());
    93 	}
    88 	}
    94 
    89 }
    95 }
    90 
    96 // ----------------------------------------------------------------------------
    91 // ----------------------------------------------------------------------------
    97 // Sets the keyboard mode
    92 // Sets the keyboard mode
    98 // ----------------------------------------------------------------------------
    93 // ----------------------------------------------------------------------------
    99 void CTestSuiteInputData::SetKeyboardModeL(const TDesC& aKeyboardMode)
    94 void CTestSuiteInputData::SetKeyboardModeL(const TDesC& aKeyboardMode)
   100 {
    95 {
   125 // ----------------------------------------------------------------------------
   120 // ----------------------------------------------------------------------------
   126 void CTestSuiteInputData::SetQueryL(const TDesC& aQuery)
   121 void CTestSuiteInputData::SetQueryL(const TDesC& aQuery)
   127 {
   122 {
   128 	iQueryBuf = aQuery.AllocL();
   123 	iQueryBuf = aQuery.AllocL();
   129 }
   124 }
   130 
       
   131 
   125 
   132 // ----------------------------------------------------------------------------
   126 // ----------------------------------------------------------------------------
   133 // Return the cache uri at given index 
   127 // Return the cache uri at given index 
   134 // ----------------------------------------------------------------------------
   128 // ----------------------------------------------------------------------------
   135 TDesC& CTestSuiteInputData::CacheUriAt(TInt aIndex) const
   129 TDesC& CTestSuiteInputData::CacheUriAt(TInt aIndex) const
   143 	}
   137 	}
   144          
   138          
   145     return *(iCacheUris[aIndex]);
   139     return *(iCacheUris[aIndex]);
   146 }
   140 }
   147 
   141 
   148 
       
   149 // ----------------------------------------------------------------------------
   142 // ----------------------------------------------------------------------------
   150 // Return the cache uri 
   143 // Return the cache uri 
   151 // ----------------------------------------------------------------------------
   144 // ----------------------------------------------------------------------------
   152 void CTestSuiteInputData::CacheUris(RPointerArray<TDesC> & aUriArray)
   145 void CTestSuiteInputData::CacheUris(RPointerArray<TDesC> & aUriArray)
   153 {
   146 {
   154 	for(TInt i = 0 ; i < iCacheUris.Count(); i++)
   147 	for(TInt i = 0; i < iCacheUris.Count(); i++)
   155 	{
   148 	{
   156 		aUriArray.Append(iCacheUris[i]->AllocL());
   149 		aUriArray.Append(iCacheUris[i]->AllocL());
   157 	}
   150 	}
   158 }
   151 }
   159 
   152 
   160 // ----------------------------------------------------------------------------
   153 // ----------------------------------------------------------------------------
   161 // Sets the cache uris
   154 // Sets the cache uris
   162 // ----------------------------------------------------------------------------
   155 // ----------------------------------------------------------------------------
   163 void CTestSuiteInputData::ApendCacheUrisL(RPointerArray<TDesC>& aCacheUriArray)
   156 void CTestSuiteInputData::ApendCacheUrisL(RPointerArray<TDesC>& aCacheUriArray)
   164 {   iCacheUris.ResetAndDestroy();
   157 {
       
   158     iCacheUris.ResetAndDestroy();
   165 	for(TInt i =0; i <aCacheUriArray.Count(); i++ ) 
   159 	for(TInt i =0; i <aCacheUriArray.Count(); i++ ) 
   166     	iCacheUris.Append(aCacheUriArray[i]);
   160     	iCacheUris.Append(aCacheUriArray[i]);
   167 }
   161 }
   168 
   162 
   169 
   163 
   191 // ----------------------------------------------------------------------------
   185 // ----------------------------------------------------------------------------
   192 // Second phase construction
   186 // Second phase construction
   193 // ----------------------------------------------------------------------------
   187 // ----------------------------------------------------------------------------
   194 void CTestSuiteInputData::ConstructL(CStifItemParser& /*aItem*/)
   188 void CTestSuiteInputData::ConstructL(CStifItemParser& /*aItem*/)
   195 {
   189 {
   196 
       
   197 }
   190 }
   198 
   191 
   199 // -----------------------------------------------------------------------------
   192 // -----------------------------------------------------------------------------
   200 // This function parses the input parameters
   193 // This function parses the input parameters
   201 // -----------------------------------------------------------------------------
   194 // -----------------------------------------------------------------------------
   223 				
   216 				
   224 			TPtrC16 dataPtr = string.Mid(sqBracketStartPos + 1,sqBracketEndPos - sqBracketStartPos - 1 );	
   217 			TPtrC16 dataPtr = string.Mid(sqBracketStartPos + 1,sqBracketEndPos - sqBracketStartPos - 1 );	
   225 			
   218 			
   226 			
   219 			
   227 			// Check the type of tag, then do the corresponding parsing
   220 			// Check the type of tag, then do the corresponding parsing
   228 		   if(optionPtr.Compare(KSearchQueryTag) == 0)
   221 		    if(optionPtr.Compare(KSearchQueryTag) == 0)
   229 		    {
   222 		    {
   230 		    	// Search query
   223 		    	// Search query
   231 		    	ParseInputForSearchQueryL(dataPtr);
   224 		    	ParseInputForSearchQueryL(dataPtr);
   232 		    
   225 		    
   233 		    }
   226 		    }
   266 		}
   259 		}
   267 		else
   260 		else
   268 		{
   261 		{
   269 			// Wrong Input..
   262 			// Wrong Input..
   270 			User::Leave(KErrGeneral);
   263 			User::Leave(KErrGeneral);
   271 		
       
   272 		}
   264 		}
   273 		
   265 	}
   274 	}
   266 }
   275 }
       
   276 
       
   277 
   267 
   278 // -----------------------------------------------------------------------------
   268 // -----------------------------------------------------------------------------
   279 // This function parses input for number id
   269 // This function parses input for number id
   280 // -----------------------------------------------------------------------------
   270 // -----------------------------------------------------------------------------
   281 void CTestSuiteInputData::ParseInputForIdL(TDesC& aInput)
   271 void CTestSuiteInputData::ParseInputForIdL(TDesC& aInput)
   282 {
   272 {
   283 
   273     TInt fieldId = 0;
   284 		TInt fieldId = 0;
   274     TLex num(aInput);
   285 		TLex num(aInput);
   275     
   286 		
   276     TInt err = num.Val(fieldId);
   287 		TInt err = num.Val(fieldId);
   277     if(err == KErrNone)
   288 		if(err == KErrNone)
   278     {
   289 		{
   279         iId = fieldId;
   290 			iId = fieldId;
   280     }
   291 		}
   281     else
   292 		else
   282     {
   293 		{
   283         User::Leave(KErrArgument);
   294 			User::Leave(KErrArgument);
   284     }
   295 		}
       
   296 
       
   297 }
   285 }
   298 
   286 
   299 // -----------------------------------------------------------------------------
   287 // -----------------------------------------------------------------------------
   300 // This function parses input for sort type
   288 // This function parses input for sort type
   301 // -----------------------------------------------------------------------------
   289 // -----------------------------------------------------------------------------
   328 	
   316 	
   329 	// Get the uris which are separated by commas
   317 	// Get the uris which are separated by commas
   330 	GetCharacterSeparatedDataL( aInput,separator, data);
   318 	GetCharacterSeparatedDataL( aInput,separator, data);
   331 	for(TInt i = 0; i< data.Count(); i++)
   319 	for(TInt i = 0; i< data.Count(); i++)
   332 	{
   320 	{
   333 	        HBufC *temp =  data[i]->AllocL();
   321         HBufC *temp =  data[i]->AllocL();
   334 			iDataArray.Append(data[i]);
   322         iDataArray.Append(data[i]);
   335 	
       
   336 	}
   323 	}
   337 }
   324 }
   338 
   325 
   339 // -----------------------------------------------------------------------------
   326 // -----------------------------------------------------------------------------
   340 // This function parses input for cache uris
   327 // This function parses input for cache uris
   346 	
   333 	
   347 	// Get the uris which are separated by commas
   334 	// Get the uris which are separated by commas
   348 	GetCharacterSeparatedDataL( aInput,separator, Uris);
   335 	GetCharacterSeparatedDataL( aInput,separator, Uris);
   349 	for(TInt i = 0; i< Uris.Count(); i++)
   336 	for(TInt i = 0; i< Uris.Count(); i++)
   350 	{
   337 	{
   351 	        HBufC *temp =  Uris[i]->AllocL();
   338         HBufC *temp =  Uris[i]->AllocL();
   352 			iCacheUris.Append(Uris[i]);
   339         iCacheUris.Append(Uris[i]);
   353 	
   340 	}
   354 	}
   341 }
   355 }
       
   356 
       
   357 
   342 
   358 // -----------------------------------------------------------------------------
   343 // -----------------------------------------------------------------------------
   359 // This function parses the input for display fields
   344 // This function parses the input for display fields
   360 // -----------------------------------------------------------------------------
   345 // -----------------------------------------------------------------------------
   361 void CTestSuiteInputData::ParseInputForDisplayFieldsL(TDesC& aInput)
   346 void CTestSuiteInputData::ParseInputForDisplayFieldsL(TDesC& aInput)
   367 	for(TInt i = 0; i< dispFieldsBuf.Count(); i++)
   352 	for(TInt i = 0; i< dispFieldsBuf.Count(); i++)
   368 	{
   353 	{
   369 		TInt fieldId = 0;
   354 		TInt fieldId = 0;
   370 		TLex num(*(dispFieldsBuf[i]));
   355 		TLex num(*(dispFieldsBuf[i]));
   371 		
   356 		
   372 		    TInt err = num.Val(fieldId);  // parse the string to extract integer value
   357         TInt err = num.Val(fieldId);  // parse the string to extract integer value
   373 			if(err != KErrNone)
   358         if(err != KErrNone)
   374 			{
   359         {
   375 				User::Leave(KErrGeneral);
   360             User::Leave(KErrGeneral);
   376 			}
   361         }
   377 			else
   362         else
   378 			{
   363         {
   379 			    iDisplayFields.Append(fieldId);
   364             iDisplayFields.Append(fieldId);
   380 			}
   365         }
   381 	}
   366 	}
   382 }
   367 }
   383 
   368 
   384 // -----------------------------------------------------------------------------
   369 // -----------------------------------------------------------------------------
   385 // This function parses the input for expected group ids
   370 // This function parses the input for expected group ids
   393 	for(TInt i = 0; i< grpIdsBuf.Count(); i++)
   378 	for(TInt i = 0; i< grpIdsBuf.Count(); i++)
   394 	{
   379 	{
   395 		TInt groupId = 0;
   380 		TInt groupId = 0;
   396 		TLex num(*(grpIdsBuf[i]));
   381 		TLex num(*(grpIdsBuf[i]));
   397 		
   382 		
   398 		    TInt err = num.Val(groupId);  // parse the string to extract integer value
   383         TInt err = num.Val(groupId);  // parse the string to extract integer value
   399 			if(err != KErrNone)
   384         if(err != KErrNone)
   400 			{
   385         {
   401 				User::Leave(KErrGeneral);
   386             User::Leave(KErrGeneral);
   402 			}
   387         }
   403 			else
   388         else
   404 			{
   389         {
   405 			    iGroupIds.Append(groupId);
   390             iGroupIds.Append(groupId);
   406 			}
   391         }
   407 	}
   392 	}
   408 }
   393 }
   409 
   394 
   410 // -----------------------------------------------------------------------------
   395 // -----------------------------------------------------------------------------
   411 // This function splits the the input separated by particular character
   396 // This function splits the the input separated by particular character
   412 // -----------------------------------------------------------------------------
   397 // -----------------------------------------------------------------------------
   413 void CTestSuiteInputData::GetCharacterSeparatedDataL(TDesC& aInput,TChar aSeparator, RPointerArray<TDesC> &aSeparatedData)
   398 void CTestSuiteInputData::GetCharacterSeparatedDataL(TDesC& aInput,TChar aSeparator, RPointerArray<TDesC> &aSeparatedData)
   414 {
   399 {
   415 	
       
   416 	TInt SeparatorPos = -1 ;
   400 	TInt SeparatorPos = -1 ;
   417     for (TInt j = 0 ; j< aInput.Length();)
   401     for (TInt j = 0 ; j< aInput.Length();)
   418 	{
   402 	{
   419 			
   403         TInt Startpos = SeparatorPos + 1;
   420 	        TInt Startpos = SeparatorPos + 1;
       
   421 		// Get the data for each contact
   404 		// Get the data for each contact
   422 			while((aInput[j] != aSeparator) && (j < ( aInput.Length()-1) ) )
   405         while((aInput[j] != aSeparator) && (j < ( aInput.Length()-1) ) )
   423 			     j++;
   406             j++;
   424 			if(j == (aInput.Length() - 1))
   407 		if(j == (aInput.Length() - 1))
   425 			 j++; 
   408 			j++; 
   426 			      
   409 
   427 			TPtrC16 dataPtr = aInput.Mid(Startpos ,j - Startpos);	
   410         TPtrC16 dataPtr = aInput.Mid(Startpos ,j - Startpos);	
   428 			
   411 
   429 			
   412         // Add data to the output
   430 			// Add data to the output
   413         HBufC* tempData = dataPtr.AllocL();
   431 			HBufC* tempData = dataPtr.AllocL();
   414         aSeparatedData.Append(tempData);
   432 			aSeparatedData.Append(tempData);
   415         SeparatorPos = j ;  
   433 			SeparatorPos = j ;  
   416         j++;   
   434 			j++;   
   417     }
   435 			
       
   436 		}
       
   437 
       
   438 }
   418 }
   439 
   419 
   440 // -----------------------------------------------------------------------------
   420 // -----------------------------------------------------------------------------
   441 // This function parses the input for search query
   421 // This function parses the input for search query
   442 // -----------------------------------------------------------------------------
   422 // -----------------------------------------------------------------------------
   443 void CTestSuiteInputData::ParseInputForSearchQueryL(TDesC& aInput)
   423 void CTestSuiteInputData::ParseInputForSearchQueryL(TDesC& aInput)
   444 {
   424 {
   445 
       
   446 	RPointerArray<TDesC> queryData;
   425 	RPointerArray<TDesC> queryData;
   447 	TChar separator = ',';
   426 	TChar separator = ',';
   448 	GetCharacterSeparatedDataL( aInput,separator, queryData);
   427 	GetCharacterSeparatedDataL( aInput,separator, queryData);
   449 
   428 
   450     // If there are more than 2 field, then it is an error
   429     // If there are more than 2 field, then it is an error
   457     else
   436     else
   458     {
   437     {
   459     	queryData.ResetAndDestroy();
   438     	queryData.ResetAndDestroy();
   460      	User::Leave(KErrArgument);
   439      	User::Leave(KErrArgument);
   461     }
   440     }
   462 	
   441 }
   463 
       
   464 }
       
   465 
       
   466 
       
   467 
   442 
   468 // -----------------------------------------------------------------------------
   443 // -----------------------------------------------------------------------------
   469 // This function creates the search query from the input buffer
   444 // This function creates the search query from the input buffer
   470 // -----------------------------------------------------------------------------
   445 // -----------------------------------------------------------------------------
   471 void CTestSuiteInputData::CreateSearchQueryL(CPsQuery& aPsQuery,TDesC& aQueryBuf)
   446 void CTestSuiteInputData::CreateSearchQueryL(CPsQuery& aPsQuery,TDesC& aQueryBuf)
   516 	    item1->SetMode(keyboardMode);
   491 	    item1->SetMode(keyboardMode);
   517 	    aPsQuery.AppendL(*item1);
   492 	    aPsQuery.AppendL(*item1);
   518 	}
   493 	}
   519 }
   494 }
   520 
   495 
   521 
       
   522 // -----------------------------------------------------------------------------
   496 // -----------------------------------------------------------------------------
   523 // Perform the search settings
   497 // Perform the search settings
   524 // -----------------------------------------------------------------------------
   498 // -----------------------------------------------------------------------------
   525 
   499 
   526 void CTestSuiteInputData::PerformSearchSettingsL(CPsSettings& aSettings)
   500 void CTestSuiteInputData::PerformSearchSettingsL(CPsSettings& aSettings)
   527 {
   501 {
   528 
       
   529 	RPointerArray<TDesC> databases; // list of databases
   502 	RPointerArray<TDesC> databases; // list of databases
   530 	RArray<TInt> displayFields;     // list of display fields
   503 	RArray<TInt> displayFields;     // list of display fields
   531 	TInt maxResults = 100;
   504 	TInt maxResults = 100;
   532 
   505 
   533 	// add the display fields
   506 	// add the display fields
   534     if(iDisplayFields.Count())
   507     if(iDisplayFields.Count())
   535     {
   508     {
   536 		for(TInt i =0; i<iDisplayFields.Count();i++)
   509 		for(TInt i =0; i<iDisplayFields.Count();i++)
   537 		    displayFields.Append(iDisplayFields[i]);
   510 		    displayFields.Append(iDisplayFields[i]);
   538     
       
   539     }
   511     }
   540     else
   512     else
   541     {
   513     {
   542 	    displayFields.Append(6); // Firstname
   514 	    displayFields.Append(6); // Firstname
   543 	    displayFields.Append(4); // Lastname
   515 	    displayFields.Append(4); // Lastname
   544 	    displayFields.Append(27); // Company name
   516 	    displayFields.Append(27); // Company name
   545     }
   517     }
   546     
       
   547      
   518      
   548     // Set the databases to be searched 
   519     // Set the databases to be searched 
   549 	for(TInt i =0; i <iCacheUris.Count(); i++ )
   520 	for(TInt i =0; i <iCacheUris.Count(); i++ )
   550 	{
   521 	{
   551 		databases.Append(iCacheUris[i]->AllocL());
   522 		databases.Append(iCacheUris[i]->AllocL());
   552 	
       
   553 	}
   523 	}
   554 	
   524 	
   555 	// Perform the settings
   525 	// Perform the settings
   556 	aSettings.SetSearchUrisL(databases);
   526 	aSettings.SetSearchUrisL(databases);
   557     aSettings.SetDisplayFieldsL(displayFields);
   527     aSettings.SetDisplayFieldsL(displayFields);
   558     aSettings.SetMaxResults(maxResults);
   528     aSettings.SetMaxResults(maxResults);
   559 	
       
   560 
   529 
   561 	// cleanup
   530 	// cleanup
   562 	displayFields.Close();
   531 	displayFields.Close();
   563 	databases.Reset(); 
   532 	databases.Reset(); 
   564 	databases.Close(); 
   533 	databases.Close(); 
   565 
       
   566 
       
   567 }
   534 }
   568 
   535 
   569 TInt CTestSuiteInputData::CompareByDataL ( const CPsClientData& aObject1, const CPsClientData& aObject2 )
   536 TInt CTestSuiteInputData::CompareByDataL ( const CPsClientData& aObject1, const CPsClientData& aObject2 )
   570 {
   537 {
   571 	TBuf<KBufferMaxLen> data1;
   538 	TBuf<KBufferMaxLen> data1;
   572      TBuf<255> data2;
   539     TBuf<255> data2;
   573      
   540      
   574      _LIT(KSpace, " ");
   541     _LIT(KSpace, " ");
   575      
   542      
   576      data1 = KNullDesC;
   543     data1 = KNullDesC;
   577      for ( int i = 0; i < aObject1.DataElementCount(); i++ )
   544     for ( int i = 0; i < aObject1.DataElementCount(); i++ )
   578      {
   545     {
   579      	 if ( aObject1.Data(i) )
   546         if ( aObject1.Data(i) )
   580 	     {
   547         {
   581 	     	data1 += aObject1.Data(i)->Des();
   548             data1 += aObject1.Data(i)->Des();
   582 	     	data1 += KSpace;
   549             data1 += KSpace;
   583 	     }	     
   550         }	     
   584      }
   551     }
   585      
   552     
   586      // Trim the unnecessary white spaces before we compare
   553     // Trim the unnecessary white spaces before we compare
   587      data1.TrimAll();
   554     data1.TrimAll();
   588      
   555     
   589      data2 = KNullDesC;
   556     data2 = KNullDesC;
   590      for ( int i = 0; i < aObject2.DataElementCount(); i++ )
   557     for ( int i = 0; i < aObject2.DataElementCount(); i++ )
   591      {
   558     {
   592      	 if ( aObject2.Data(i) )
   559         if ( aObject2.Data(i) )
   593 	     {
   560         {
   594 	     	data2 += aObject2.Data(i)->Des();
   561             data2 += aObject2.Data(i)->Des();
   595 	     	data2 += KSpace;
   562             data2 += KSpace;
   596 	     }	     
   563         }	     
   597      }   
   564     }   
   598      
   565     
   599      // Trim the unnecessary white spaces before we compare 
   566     // Trim the unnecessary white spaces before we compare 
   600      data2.TrimAll();   
   567     data2.TrimAll();   
   601      
   568     
   602 	 // Get the standard method
   569     // Get the standard method
   603 	 TCollationMethod meth = *Mem::CollationMethodByIndex( 0 );
   570     TCollationMethod meth = *Mem::CollationMethodByIndex( 0 );
   604   	 meth.iFlags |= TCollationMethod::EIgnoreNone;
   571     meth.iFlags |= TCollationMethod::EIgnoreNone;
   605   	 meth.iFlags |= TCollationMethod::EFoldCase;
   572     meth.iFlags |= TCollationMethod::EFoldCase;
   606 
   573     
   607 	 // Magic: Collation level 3 is used
   574     // Magic: Collation level 3 is used
   608 	 TInt comparison(data1.CompareC( data2, 3, &meth ));
   575     TInt comparison(data1.CompareC( data2, 3, &meth ));
   609 	 return comparison;
   576     return comparison;
   610 }
   577 }
       
   578 
   611 // End of file
   579 // End of file