landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp23.cpp
branchRCL_3
changeset 44 2b4ea9893b66
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
       
     1 /*
       
     2 * Copyright (c) 2005 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 *   ?description_line
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 //  INCLUDES
       
    21 #include "FT_CPosTp23.h"
       
    22 #include <EPos_CPosLandmarkDatabase.h>
       
    23 #include <EPos_CPosLandmarkSearch.h>
       
    24 #include <EPos_CPosLmTextCriteria.h>
       
    25 #include <EPos_CPosLMItemIterator.h>
       
    26 #include <EPos_CPosLmDisplayData.h>
       
    27 #include <EPos_CPosLmDisplayItem.h>
       
    28 #include <EPos_TPosLMSortPref.h>
       
    29 #include "FT_CSearchResult.h"
       
    30      
       
    31 // CONSTANTS
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 
       
    35 
       
    36 // ---------------------------------------------------------
       
    37 // CPosTp23::CloseTest
       
    38 //
       
    39 // (other items were commented in a header).
       
    40 // ---------------------------------------------------------
       
    41 //
       
    42 void CPosTp23::CloseTest()
       
    43     {
       
    44     //CHECK TR   Delete of landmarks search - ESLI-5WNG9N
       
    45     delete iDatabase;
       
    46     iDatabase = NULL;
       
    47 
       
    48     delete iLandmarkSearch;
       
    49     iLandmarkSearch = NULL;
       
    50     
       
    51     iSearchResults.ResetAndDestroy();
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------
       
    55 // CPosTp23::StartL
       
    56 //
       
    57 // (other items were commented in a header).
       
    58 // ---------------------------------------------------------
       
    59 //
       
    60 void CPosTp23::StartL()
       
    61     {
       
    62     _LIT(KEmptyTextCriteriaErr, "An empty string as text criteria should not be allowed");
       
    63 
       
    64     iDatabase = UseGeneratedDbFileL();
       
    65     
       
    66     if (iDatabase->IsInitializingNeeded())
       
    67        {
       
    68        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
    69        }
       
    70 
       
    71     iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase);
       
    72         
       
    73     TestInvalidPositionFieldsL();
       
    74         
       
    75     // Check iterator before search has started (in multidb search all iterators are empty thus NOT NULL)
       
    76     CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
    77     if (iter)
       
    78     	{
       
    79     	CleanupStack::PushL(iter);
       
    80     	AssertTrueSecL(iter->NumOfItemsL() == 0, _L("Iterator should be empty"));
       
    81     	CleanupStack::PopAndDestroy(iter);
       
    82     	}
       
    83     else
       
    84     	{
       
    85     	
       
    86     	iLog->Log(_L("Iterator should NOT be NULL"));
       
    87     	User::Leave(-1);	
       
    88     	}
       
    89     
       
    90     TUint attr = CPosLandmark::ELandmarkName | CPosLandmark::EDescription;
       
    91     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
    92     textCriteria->SetAttributesToSearch(attr);
       
    93     textCriteria->SetTextL(_L(""));
       
    94     
       
    95     TRAPD(err, iLandmarkSearch->StartLandmarkSearchL(*textCriteria));
       
    96     AssertTrueSecL(err == KErrArgument, KEmptyTextCriteriaErr);
       
    97     CleanupStack::PopAndDestroy(textCriteria);
       
    98     
       
    99     AppendSearchResultsL();
       
   100     
       
   101     iLog->Log(_L("Testing search with criterias read from LmDbSearchResult.txt syncronously"));
       
   102     SearchL(iSearchResults, ESynchronous);
       
   103 
       
   104     iLog->Log(_L("Testing search with criterias read from LmDbSearchResult.txt asyncronously"));
       
   105     SearchL(SearchResults(), EAsynchronous);
       
   106 
       
   107     iLog->Log(_L("Testing search with criterias read from LmDbSearchResult.txt asyncronously using User::WaitForRequest"));
       
   108     SearchL(SearchResults(), EWaitForRequest);
       
   109 
       
   110     iLog->Log(_L("Testing search with a defined sortorder"));
       
   111     SearchWithSortOrderL(iSearchResults);   
       
   112 
       
   113     iLog->Log(_L("Testing search anc cancel"));
       
   114     SearchAndCancelL();
       
   115     
       
   116     iLog->Log(_L("Testing search and cancel in callback"));
       
   117     SearchAndCancelL(ETrue);
       
   118 
       
   119     iLog->Log(_L("Testing a redefined search after a landmark has been removed"));
       
   120     SearchAndDeleteL(iSearchResults);
       
   121 
       
   122     iLog->Log(_L("Testing a redefined search after landmarks have been renamed"));
       
   123     SearchAndRenameL(iSearchResults);
       
   124     
       
   125     iLog->Log(_L("Test max length for SetTextL"));
       
   126     TestMaxLengthL();
       
   127     
       
   128     // Verify error report "ESLI-62DBXR Landmarks - Sort order is not correctly implemented"
       
   129     // Check that CPosLandmarkSearch::MatchIteratorL are CPosLandmarkDatabase::LandmarkIteratorL
       
   130     // are sorted correctly (should be identically sorted)
       
   131 	VerifySortOrderL();
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------
       
   135 // CPosTp23::SearchL
       
   136 //
       
   137 // (other items were commented in a header).
       
   138 // ---------------------------------------------------------
       
   139 //
       
   140 void CPosTp23::SearchL(
       
   141     const RPointerArray<CSearchResult>& aSearchResults, 
       
   142     TExecutionMode aExecutionMode)
       
   143     {
       
   144     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed");
       
   145     _LIT(KNotFoundErr, "Id %d not found in parsed Lm search results when the search is performed syncronously");
       
   146 
       
   147     // Set DisplayData
       
   148 	CPosLmDisplayData* displayData = CPosLmDisplayData::NewL();
       
   149 	CleanupStack::PushL(displayData);
       
   150 	iLandmarkSearch->SetDisplayData(*displayData);
       
   151     	
       
   152     for(TInt i=0; i<aSearchResults.Count(); i++)
       
   153         {
       
   154         CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   155         
       
   156         textCriteria->SetTextL(aSearchResults[i]->TextCriteria());
       
   157         textCriteria->SetAttributesToSearch(aSearchResults[i]->Attributes());
       
   158         
       
   159         textCriteria->SetPositionFieldsToSearchL(aSearchResults[i]->PositionFields()); 
       
   160 
       
   161         CPosLmOperation* operation = 
       
   162             iLandmarkSearch->StartLandmarkSearchL(*textCriteria, aSearchResults[i]->Redefined());
       
   163         CleanupStack::PushL(operation);
       
   164          switch (aExecutionMode)
       
   165             {
       
   166             case ESynchronous:
       
   167                 ExecuteAndDeleteLD(operation);
       
   168                 CleanupStack::Pop(operation);
       
   169                 break;
       
   170             case EAsynchronous:
       
   171                 RunAsyncOperationLD(operation);
       
   172                 CleanupStack::Pop(operation);
       
   173                 break;
       
   174             case EWaitForRequest:
       
   175                 RunAsyncOperationByWaitForReqL(operation);
       
   176                 CleanupStack::PopAndDestroy(operation);                
       
   177                 break;
       
   178             }
       
   179 
       
   180         CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   181         CleanupStack::PushL(iter);
       
   182 		       
       
   183         if ((TUint)(aSearchResults[i]->SearchResult()).Count() != iLandmarkSearch->NumOfMatches())
       
   184             {
       
   185             _LIT(KExpected, "Expected no. of matches: %d");
       
   186             _LIT(KReturned, "Returned no. of matches: %d");
       
   187             TBuf<100> info;
       
   188             info.Format(KExpected, (aSearchResults[i]->SearchResult()).Count());
       
   189             iLog->Log(info);
       
   190             info.Format(KReturned, iLandmarkSearch->NumOfMatches());
       
   191             iLog->Log(info);
       
   192             iLog->Log(_L("Search criteria: "));
       
   193             iLog->Log(textCriteria->Text());
       
   194             iLog->Log(KNumOfMatchesErr);
       
   195             User::Leave(-1);
       
   196             
       
   197             }
       
   198 
       
   199 		//Check displaydata        
       
   200         AssertTrueSecL(iter->NumOfItemsL() == displayData->Count(), _L("Wrong number of DisplayData matches"));
       
   201         
       
   202        	TInt itemId = displayData->NewItemIndex();
       
   203         while (itemId != KPosLmNoNewItems)
       
   204             {
       
   205             CPosLmDisplayItem& item = displayData->DisplayItem(itemId);
       
   206                        
       
   207             if (item.DisplayItemType() != CPosLmDisplayItem::ELandmarkItem)
       
   208             	{
       
   209             	iLog->Log(_L("ERROR :::::"));
       
   210                 iLog->Log(_L("Wrong item returned, only ELandmarkItem should be returned"));
       
   211             	User::Leave(-1);
       
   212             	}
       
   213             
       
   214             if (item.DatabaseIndex() != 0)
       
   215             	{
       
   216             	// When single search, index should always be 0
       
   217                 iLog->Log(_L("Wrong DatabaseIndex, should be 0"));
       
   218             	User::Leave(-1);
       
   219             	
       
   220             	}
       
   221             
       
   222 			
       
   223 				TInt lmId = item.Landmark().LandmarkId();
       
   224 				
       
   225         	AssertTrueSecL(aSearchResults[i]->FindSearchResult(lmId), KNotFoundErr, lmId);
       
   226             itemId = displayData->NewItemIndex();
       
   227            	}
       
   228             	
       
   229         TPosLmItemId id = iter->NextL();
       
   230         while (id != KPosLmNullItemId)
       
   231             {
       
   232             AssertTrueSecL(aSearchResults[i]->FindSearchResult(id), KNotFoundErr, id);
       
   233                  	
       
   234             id = iter->NextL();
       
   235             }
       
   236         
       
   237         CleanupStack::PopAndDestroy(iter);
       
   238         CleanupStack::PopAndDestroy(textCriteria);
       
   239         }
       
   240         iLandmarkSearch->UnsetDisplayData();
       
   241         CleanupStack::PopAndDestroy(displayData);
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------
       
   245 // CPosTp23::VerifySortOrderL
       
   246 //
       
   247 // (other items were commented in a header).
       
   248 // ---------------------------------------------------------
       
   249 //
       
   250 void CPosTp23::VerifySortOrderL()
       
   251     {
       
   252     iLog->Log(_L("VerifySortOrderL"));
       
   253     _LIT(KNumOfMatchesErr, "No. of matches is incorrect");
       
   254     _LIT(KNumOfMatchesErr2, "No. of matches in DisplayData is incorrect");
       
   255     _LIT(KSortorderErr, "The sortorder is incorrect");
       
   256     _LIT(KNameMatchError, "The landmark names does not match");
       
   257     _LIT(KNameMatchError2, "The landmark name in DisplayData does not match");
       
   258     
       
   259     // Just in case, add some landmarks
       
   260     CPosLandmark* landmark = CPosLandmark::NewLC();
       
   261     landmark->SetLandmarkNameL(_L("CategoryA")); 
       
   262     TPosLmItemId id1 = iDatabase->AddLandmarkL(*landmark);
       
   263 
       
   264     CleanupStack::PopAndDestroy(landmark);
       
   265 
       
   266     landmark = CPosLandmark::NewLC();
       
   267     landmark->SetLandmarkNameL(_L("Categorya")); 
       
   268     TPosLmItemId id2 = iDatabase->AddLandmarkL(*landmark);
       
   269     CleanupStack::PopAndDestroy(landmark);
       
   270 
       
   271     landmark = CPosLandmark::NewLC();
       
   272     landmark->SetLandmarkNameL(_L("AA")); 
       
   273     TPosLmItemId id3 = iDatabase->AddLandmarkL(*landmark);
       
   274     CleanupStack::PopAndDestroy(landmark);
       
   275 
       
   276     landmark = CPosLandmark::NewLC();
       
   277     landmark->SetLandmarkNameL(_L("aa")); 
       
   278     TPosLmItemId id4 = iDatabase->AddLandmarkL(*landmark);
       
   279     CleanupStack::PopAndDestroy(landmark);
       
   280    
       
   281     TPosLmSortPref sortDesc(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending);
       
   282     TPosLmSortPref sortAsc(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   283 
       
   284     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   285     // Search pattern "*" should match all existing landmarks -> it is possible to compare
       
   286     // sort order of CPosLandmarkSearch::MatchIteratorL with CPosLandmarkDatabase::LandmarkIteratorL
       
   287     textCriteria->SetTextL(_L("*"));
       
   288     
       
   289     // Set DisplayData
       
   290     CPosLmDisplayData* displayData = CPosLmDisplayData::NewL();
       
   291 	CleanupStack::PushL(displayData);
       
   292     iLandmarkSearch->SetDisplayData(*displayData);
       
   293 
       
   294     CPosLmItemIterator* lmDbIter = NULL;
       
   295 
       
   296     for (TInt i=0; i<6; i++)
       
   297         {
       
   298         if(i==0)
       
   299             {
       
   300             // Sorted ascending
       
   301             lmDbIter = iDatabase->LandmarkIteratorL(sortAsc);
       
   302             CleanupStack::PushL(lmDbIter);
       
   303             ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL(
       
   304                 *textCriteria, sortAsc, EFalse));
       
   305             }
       
   306         else if (i==1)
       
   307             {
       
   308             // Sorted descending
       
   309             lmDbIter = iDatabase->LandmarkIteratorL(sortDesc);
       
   310             CleanupStack::PushL(lmDbIter);
       
   311             ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL(
       
   312                 *textCriteria, sortDesc, EFalse));
       
   313             }
       
   314         else if (i==2)
       
   315             {
       
   316             //**** Async search, sorted ascending
       
   317             lmDbIter = iDatabase->LandmarkIteratorL(sortAsc);
       
   318             CleanupStack::PushL(lmDbIter);
       
   319             RunAsyncOperationLD(iLandmarkSearch->StartLandmarkSearchL(
       
   320                 *textCriteria, sortAsc, EFalse));
       
   321             }
       
   322         else if (i==3)
       
   323             {
       
   324             //**** Async search, sorted descending
       
   325             lmDbIter = iDatabase->LandmarkIteratorL(sortDesc);
       
   326             CleanupStack::PushL(lmDbIter);
       
   327             RunAsyncOperationLD(iLandmarkSearch->StartLandmarkSearchL(
       
   328                 *textCriteria, sortDesc, EFalse));
       
   329             }
       
   330         else if (i==4)
       
   331             {
       
   332             //**** Async search with User::WaitForRequest(), sorted ascending
       
   333             lmDbIter = iDatabase->LandmarkIteratorL(sortAsc);
       
   334             CleanupStack::PushL(lmDbIter);
       
   335             CPosLmOperation* op = iLandmarkSearch->StartLandmarkSearchL(
       
   336                 *textCriteria, sortAsc, EFalse);
       
   337             CleanupStack::PushL(op);
       
   338             RunAsyncOperationByWaitForReqL(op);
       
   339             CleanupStack::PopAndDestroy(op);
       
   340             }
       
   341         else if (i==5)
       
   342             {
       
   343             //**** Async search with User::WaitForRequest(), sorted descending
       
   344             lmDbIter = iDatabase->LandmarkIteratorL(sortDesc);
       
   345             CleanupStack::PushL(lmDbIter);
       
   346             CPosLmOperation* op = iLandmarkSearch->StartLandmarkSearchL(
       
   347                 *textCriteria, sortDesc, EFalse);
       
   348             CleanupStack::PushL(op);
       
   349             RunAsyncOperationByWaitForReqL(op);
       
   350             CleanupStack::PopAndDestroy(op);
       
   351             }
       
   352 
       
   353         CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   354         CleanupStack::PushL(iter);
       
   355 
       
   356         AssertTrueSecL(iter->NumOfItemsL() == lmDbIter->NumOfItemsL(), KNumOfMatchesErr);
       
   357         // Check correct displayData
       
   358         AssertTrueSecL(iter->NumOfItemsL() == displayData->Count(), KNumOfMatchesErr2);
       
   359 
       
   360 		TInt itemId = displayData->NewItemIndex();
       
   361 
       
   362         TPosLmItemId id = iter->NextL();
       
   363         TPosLmItemId lmDbId = lmDbIter->NextL();
       
   364         // check that the two iterators are sorted identically
       
   365         while (id != KPosLmNullItemId)
       
   366             {
       
   367             CPosLandmark* source = iDatabase->ReadLandmarkLC(id);
       
   368             CPosLandmark* target = iDatabase->ReadLandmarkLC(lmDbId);
       
   369                    	
       
   370         	CPosLmDisplayItem& item = displayData->DisplayItem(itemId);
       
   371 			TPtrC lmName;
       
   372 			item.Landmark().GetLandmarkName(lmName);
       
   373             
       
   374             TPtrC sourceName, targetName;
       
   375             source->GetLandmarkName(sourceName);
       
   376             target->GetLandmarkName(targetName);
       
   377     		
       
   378             // For debugging purposes
       
   379             TBuf<150> buf;
       
   380             buf.Append(_L("Name:"));
       
   381             buf.Append(sourceName);
       
   382             buf.Append(_L("<->"));
       
   383             buf.Append(targetName);
       
   384             buf.Append(_L("<->"));
       
   385             buf.Append(lmName);
       
   386             //iLog->Log(buf);
       
   387             
       
   388            
       
   389             if (id != lmDbId) iLog->Log(_L("ids are not identical, therefore check name"));
       
   390             // Should always be the same
       
   391             AssertTrueSecL(sourceName.Compare(targetName) == KErrNone, KNameMatchError);
       
   392             AssertTrueSecL(sourceName.Compare(lmName) == KErrNone, KNameMatchError2);
       
   393             
       
   394             CleanupStack::PopAndDestroy(target);
       
   395             CleanupStack::PopAndDestroy(source);
       
   396             id = iter->NextL();
       
   397             lmDbId = lmDbIter->NextL();
       
   398             itemId = displayData->NewItemIndex();
       
   399             }
       
   400         CleanupStack::PopAndDestroy(iter);
       
   401         CleanupStack::PopAndDestroy(lmDbIter);
       
   402         }
       
   403     // Unset displayData before deleting
       
   404     iLandmarkSearch->UnsetDisplayData();
       
   405 	CleanupStack::PopAndDestroy(displayData);
       
   406     CleanupStack::PopAndDestroy(textCriteria);
       
   407 
       
   408     //Remove landmarks created in this part
       
   409     iDatabase->RemoveLandmarkL(id1);
       
   410     iDatabase->RemoveLandmarkL(id2);
       
   411     iDatabase->RemoveLandmarkL(id3);
       
   412     iDatabase->RemoveLandmarkL(id4);
       
   413 
       
   414     iLog->Log(_L("VerifySortOrderL Done"));
       
   415     }
       
   416 
       
   417 // ---------------------------------------------------------
       
   418 // CPosTp23::SearchWithSortOrderL
       
   419 //
       
   420 // (other items were commented in a header).
       
   421 // ---------------------------------------------------------
       
   422 //
       
   423 void CPosTp23::SearchWithSortOrderL(const RPointerArray<CSearchResult>& aSearchResults)
       
   424     {
       
   425     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed syncronously");
       
   426     _LIT(KSortorderErr, "The sortorder is incorrect");
       
   427    
       
   428     TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);  
       
   429     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   430        
       
   431     for(TInt j=0; j<aSearchResults.Count(); j++)
       
   432         {   
       
   433         textCriteria->SetTextL(aSearchResults[j]->TextCriteria());
       
   434         textCriteria->SetAttributesToSearch(aSearchResults[j]->Attributes());
       
   435         textCriteria->SetPositionFieldsToSearchL(aSearchResults[j]->PositionFields()); 
       
   436 
       
   437         //iLog->Log(aSearchResults[j]->TextCriteria());
       
   438         
       
   439         for (TInt i=0; i<6; i++)
       
   440             {
       
   441             switch (i)
       
   442                 {
       
   443                 //**** sync
       
   444                 case 0:
       
   445                     ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL(
       
   446                         *textCriteria, 
       
   447                         sortPref, 
       
   448                         aSearchResults[j]->Redefined()));
       
   449                     break;
       
   450                 case 1:
       
   451                     sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending);
       
   452                     ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL(
       
   453                         *textCriteria, 
       
   454                         sortPref, 
       
   455                         aSearchResults[j]->Redefined()));
       
   456                     break;
       
   457                 case 2:
       
   458                 //**** async
       
   459                     RunAsyncOperationLD(iLandmarkSearch->StartLandmarkSearchL(
       
   460                         *textCriteria, 
       
   461                         sortPref, 
       
   462                         aSearchResults[j]->Redefined()));
       
   463                     break;
       
   464                 case 3:
       
   465                     sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   466                     RunAsyncOperationLD(iLandmarkSearch->StartLandmarkSearchL(
       
   467                         *textCriteria, 
       
   468                         sortPref, 
       
   469                         aSearchResults[j]->Redefined()));
       
   470                     break;
       
   471                 //**** asych with User::WaitForRequest()
       
   472                 case 4:
       
   473                     {
       
   474                     CPosLmOperation* op = iLandmarkSearch->StartLandmarkSearchL(
       
   475                         *textCriteria, 
       
   476                         sortPref, 
       
   477                         aSearchResults[j]->Redefined());
       
   478                     CleanupStack::PushL(op);
       
   479                     RunAsyncOperationByWaitForReqL(op);
       
   480                     CleanupStack::PopAndDestroy(op);
       
   481                     }
       
   482                     break;
       
   483                 case 5:
       
   484                     {
       
   485                     sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   486                     CPosLmOperation* op = iLandmarkSearch->StartLandmarkSearchL(
       
   487                         *textCriteria, 
       
   488                         sortPref, 
       
   489                         aSearchResults[j]->Redefined());
       
   490                     CleanupStack::PushL(op);
       
   491                     RunAsyncOperationByWaitForReqL(op);
       
   492                     CleanupStack::PopAndDestroy(op);
       
   493                     }
       
   494                     break;
       
   495                 }
       
   496            
       
   497         CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   498         CleanupStack::PushL(iter);
       
   499         
       
   500         RArray<TPosLmItemId>* searchResults = &aSearchResults[j]->SearchResult();
       
   501         if ((TUint)searchResults->Count() != iLandmarkSearch->NumOfMatches())
       
   502             {
       
   503             TBuf<50> buf;
       
   504             buf.Append(_L("KNumOfMatchesError when searching for "));
       
   505             buf.Append(aSearchResults[j]->TextCriteria());
       
   506             iLog->Log(buf);
       
   507             
       
   508             iLog->Log(KNumOfMatchesErr);
       
   509             User::Leave(-1);
       
   510             }
       
   511         
       
   512         LandmarksSortL(*searchResults, sortPref);
       
   513         
       
   514         TInt ii=0;
       
   515         TPosLmItemId id = iter->NextL();
       
   516         
       
   517         while (id != KPosLmNullItemId)
       
   518             {  
       
   519             if (id != (*searchResults)[ii])
       
   520                 {
       
   521                 //Check if same name then don't Leave
       
   522                 CPosLandmark* source = iDatabase->ReadLandmarkLC(id);
       
   523                 CPosLandmark* target = iDatabase->ReadLandmarkLC((*searchResults)[ii]);
       
   524                 TPtrC sourceName, targetName;
       
   525                 source->GetLandmarkName(sourceName);
       
   526                 target->GetLandmarkName(targetName);
       
   527 
       
   528                 AssertTrueSecL(!sourceName.CompareC(targetName),KSortorderErr, id);
       
   529                 CleanupStack::PopAndDestroy(2, source);
       
   530                 }
       
   531             id = iter->NextL();
       
   532             ++ii;
       
   533             }
       
   534         CleanupStack::PopAndDestroy(iter);
       
   535         } // for (TInt i=0; i<6; i++)
       
   536         } // for(TInt j=0; j<aSearchResults.Count(); j++)
       
   537     CleanupStack::PopAndDestroy(textCriteria);
       
   538     }
       
   539 
       
   540 // ---------------------------------------------------------
       
   541 // CPosTp23::SearchAndDeleteL
       
   542 //
       
   543 // (other items were commented in a header).
       
   544 // ---------------------------------------------------------
       
   545 //
       
   546 void CPosTp23::SearchAndDeleteL(const RPointerArray<CSearchResult>& aSearchResults)
       
   547     {
       
   548     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when a redefined search is performed"); 
       
   549     _LIT(KSortorderErr, "The sortorder is incorrect after a delete when a redefined search is performed");
       
   550     
       
   551     TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   552     
       
   553     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   554         
       
   555     textCriteria->SetTextL(aSearchResults[11]->TextCriteria());
       
   556     textCriteria->SetAttributesToSearch(aSearchResults[11]->Attributes());
       
   557     textCriteria->SetPositionFieldsToSearchL(aSearchResults[11]->PositionFields()); 
       
   558     
       
   559     ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL(*textCriteria, sortPref));
       
   560     
       
   561     RArray<TPosLmItemId>* searchResults = &aSearchResults[11]->SearchResult();
       
   562     
       
   563     iDatabase->RemoveLandmarkL((*searchResults)[0]); 
       
   564     searchResults->Remove(0);
       
   565     searchResults->Compress();
       
   566 
       
   567     ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL(*textCriteria, sortPref, ETrue));
       
   568     
       
   569     CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   570     CleanupStack::PushL(iter);
       
   571 
       
   572     AssertTrueSecL((TUint)searchResults->Count() == iLandmarkSearch->NumOfMatches(), KNumOfMatchesErr);    
       
   573              
       
   574     LandmarksSortL(*searchResults, sortPref);
       
   575         
       
   576     TInt ii=0;
       
   577     TPosLmItemId id = iter->NextL();
       
   578     while (id != KPosLmNullItemId)
       
   579         {  
       
   580         AssertTrueSecL(id == (*searchResults)[ii], KSortorderErr, id);
       
   581             
       
   582         id = iter->NextL();
       
   583         ++ii;
       
   584         }
       
   585        
       
   586     CleanupStack::PopAndDestroy(2, textCriteria);
       
   587     }
       
   588 
       
   589 // ---------------------------------------------------------
       
   590 // CPosTp23::SearchAndRenameL
       
   591 //
       
   592 // (other items were commented in a header).
       
   593 // ---------------------------------------------------------
       
   594 //
       
   595 void CPosTp23::SearchAndRenameL(const RPointerArray<CSearchResult>& aSearchResults)
       
   596     {
       
   597     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when a redefined search is performed"); 
       
   598     const TInt KTestIndex=4;
       
   599 
       
   600     TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   601     
       
   602     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   603         
       
   604     textCriteria->SetTextL(aSearchResults[KTestIndex]->TextCriteria());
       
   605     textCriteria->SetAttributesToSearch(aSearchResults[KTestIndex]->Attributes());
       
   606     textCriteria->SetPositionFieldsToSearchL(aSearchResults[KTestIndex]->PositionFields()); 
       
   607     
       
   608     ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL(*textCriteria, sortPref));
       
   609     
       
   610     RArray<TPosLmItemId>* searchResults = &aSearchResults[KTestIndex]->SearchResult();
       
   611     
       
   612     _LIT(KLmName, "LmTP23-%d");
       
   613     for (TInt i=0; i<searchResults->Count(); i++)
       
   614         {
       
   615         CPosLandmark* lm =iDatabase->ReadLandmarkLC((*searchResults)[i]);
       
   616         
       
   617         TBuf<100> lmName;
       
   618         lmName.Format(KLmName,i);
       
   619 
       
   620         lm->SetLandmarkNameL(lmName);
       
   621         iDatabase->UpdateLandmarkL(*lm);
       
   622         CleanupStack::PopAndDestroy(lm);   
       
   623         }
       
   624     
       
   625     ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL(*textCriteria, sortPref, ETrue));
       
   626     
       
   627     CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   628     CleanupStack::PushL(iter);
       
   629 
       
   630    
       
   631              
       
   632     AssertTrueSecL(iLandmarkSearch->NumOfMatches()==0, KNumOfMatchesErr);    
       
   633 
       
   634     CleanupStack::PopAndDestroy(2, textCriteria);
       
   635    
       
   636     }
       
   637 
       
   638 // ---------------------------------------------------------
       
   639 // CPosTp23::SearchAndCancelL
       
   640 //
       
   641 // (other items were commented in a header).
       
   642 // ---------------------------------------------------------
       
   643 //
       
   644 void CPosTp23::SearchAndCancelL(const TBool& aInCallback)
       
   645     {
       
   646     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed");
       
   647     _LIT(KCancelErr, "The search is canceled after progress has increased but no search result is found");
       
   648 
       
   649     // Test search with one criteria
       
   650     const TInt KIndex=0;
       
   651 
       
   652     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   653         
       
   654     textCriteria->SetTextL(iSearchResults[KIndex]->TextCriteria());
       
   655     textCriteria->SetAttributesToSearch(iSearchResults[KIndex]->Attributes());
       
   656         
       
   657     textCriteria->SetPositionFieldsToSearchL(iSearchResults[KIndex]->PositionFields()); 
       
   658 
       
   659     if (aInCallback)
       
   660         {
       
   661         RunAsyncOperationAndCancelInCallbackLD(iLandmarkSearch->StartLandmarkSearchL(
       
   662                 *textCriteria, iSearchResults[KIndex]->Redefined()));
       
   663         }
       
   664     else
       
   665         {
       
   666         RunAsyncOperationAndCancelLD(iLandmarkSearch->StartLandmarkSearchL(
       
   667                 *textCriteria, iSearchResults[KIndex]->Redefined()));
       
   668         }
       
   669 
       
   670     CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   671     CleanupStack::PushL(iter);
       
   672  
       
   673     if (aInCallback)
       
   674         {
       
   675         if (iter->NumOfItemsL() != iLandmarkSearch->NumOfMatches())
       
   676             {
       
   677             iLog->Log(_L("Iterators no. of items is not equal to LandmarksSearch no. matches"));
       
   678             _LIT(KExpected, "Iter. of matches: %d");
       
   679             _LIT(KReturned, "LandmarksSearch no. of matches: %d");
       
   680             TBuf<100> info;
       
   681             info.Format(KExpected, iter->NumOfItemsL());
       
   682             iLog->Log(info);
       
   683             info.Format(KReturned, iLandmarkSearch->NumOfMatches());
       
   684             iLog->Log(info);
       
   685             iLog->Log(_L("Search criteria: "));
       
   686             iLog->Log(textCriteria->Text());
       
   687             
       
   688             iLog->Log(KNumOfMatchesErr);
       
   689             User::Leave(-1);
       
   690             }
       
   691         TBuf<100> info2;
       
   692         _LIT(KNof, "No. of matches found before cancel = %d");
       
   693         info2.Format(KNof, iter->NumOfItemsL());
       
   694         iLog->Log(info2);
       
   695 
       
   696         AssertTrueSecL(iter->NumOfItemsL() != 0, KCancelErr);
       
   697         }
       
   698         
       
   699     CleanupStack::PopAndDestroy(2, textCriteria);
       
   700        
       
   701     }
       
   702     
       
   703 // ---------------------------------------------------------
       
   704 // CPosTp23::TestMaxLengthL
       
   705 //
       
   706 // (other items were commented in a header).
       
   707 // ---------------------------------------------------------
       
   708 //
       
   709 void CPosTp23::TestMaxLengthL()
       
   710 	{
       
   711 	CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   712 	_LIT(K255Error, "Exceeding limit should leave with KErrArgument");
       
   713     
       
   714 	_LIT(K255CHAR, "ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ12345");
       
   715 	_LIT(K256CHAR, "ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ123456");
       
   716 
       
   717 	textCriteria->SetTextL(K255CHAR);
       
   718 	
       
   719 	TRAPD(err, textCriteria->SetTextL(K256CHAR););
       
   720 	AssertTrueSecL(err == KErrArgument, K255Error);
       
   721 
       
   722     iOperation = iLandmarkSearch->StartLandmarkSearchL(*textCriteria);
       
   723     ExecuteAndDeleteLD(iOperation);
       
   724     
       
   725     TInt nr = iLandmarkSearch->NumOfMatches();
       
   726     TBuf<100> buf;
       
   727     buf.Format(_L("Found %d nr of matches"), nr);
       
   728     iLog->Log(buf);
       
   729 
       
   730 	AssertTrueSecL(nr == 0, _L("We should not find any matches"));	
       
   731     CleanupStack::PopAndDestroy(textCriteria);	    
       
   732 	}
       
   733 
       
   734 // ---------------------------------------------------------
       
   735 // CPosTp23::TestInvalidPositionFieldsL
       
   736 //
       
   737 // (other items were commented in a header).
       
   738 // ---------------------------------------------------------
       
   739 //
       
   740 void CPosTp23::TestInvalidPositionFieldsL()
       
   741 	{
       
   742 	CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   743 	RArray<TUint> arr;
       
   744 	CleanupClosePushL(arr);
       
   745 		
       
   746 	textCriteria->SetTextL(_L("*"));
       
   747 	textCriteria->SetPositionFieldsToSearchL(arr);
       
   748 
       
   749 	// Search with empty positionfields list, should find all landmarks
       
   750 	iOperation = iLandmarkSearch->StartLandmarkSearchL(*textCriteria);
       
   751     ExecuteAndDeleteLD(iOperation);
       
   752     TInt nr = iLandmarkSearch->NumOfMatches();
       
   753     TBuf<100> buf;
       
   754     buf.Format(_L("Found %d nr of matches when searching in empty position fields list"), nr);
       
   755     iLog->Log(buf);
       
   756     
       
   757     	
       
   758 		
       
   759 	User::LeaveIfError(arr.Append(0));
       
   760 	User::LeaveIfError(arr.Append(50));
       
   761 	User::LeaveIfError(arr.Append(500));
       
   762 	textCriteria->SetPositionFieldsToSearchL(arr);
       
   763 
       
   764 	// Search with invalid positionfields list, should NOT find any landmarks
       
   765 	iOperation = iLandmarkSearch->StartLandmarkSearchL(*textCriteria);
       
   766     ExecuteAndDeleteLD(iOperation);
       
   767     nr = iLandmarkSearch->NumOfMatches();
       
   768 
       
   769     buf.Format(_L("Found %d nr of matches when searching in invalid position fields"), nr);
       
   770     iLog->Log(buf);
       
   771     
       
   772     AssertTrueSecL(nr == 0, _L("We should not find any matches"));
       
   773     
       
   774     CleanupStack::PopAndDestroy(&arr);
       
   775     CleanupStack::PopAndDestroy(textCriteria);
       
   776 	}
       
   777 
       
   778 //  End of File