landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp25.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_CPosTp25.h"
       
    22 #include <EPos_CPosLandmarkDatabase.h>
       
    23 #include <EPos_CPosLandmarkSearch.h> 
       
    24 #include <EPos_CPosLmTextCriteria.h>
       
    25 #include <EPos_CPosLmCatNameCriteria.h>
       
    26 #include <EPos_CPosLMItemIterator.h>    
       
    27 #include <EPos_CPosLmDisplayData.h>
       
    28 #include <EPos_CPosLmDisplayItem.h>
       
    29 #include <EPos_TPosLMSortPref.h>
       
    30 #include "FT_CSearchResult.h"
       
    31 #include <EPos_Landmarks.h>
       
    32 #include "FT_LandmarkConstants.h"
       
    33 
       
    34 // CONSTANTS
       
    35 
       
    36 // ================= MEMBER FUNCTIONS =======================
       
    37 
       
    38 // ---------------------------------------------------------
       
    39 // CPosTp25::CloseTest
       
    40 //
       
    41 // (other items were commented in a header).
       
    42 // ---------------------------------------------------------
       
    43 //
       
    44 void CPosTp25::CloseTest()
       
    45     {
       
    46     iLog->Log(_L("CloseTest"));
       
    47     delete iLandmarkSearch;
       
    48     iLandmarkSearch = NULL;
       
    49     
       
    50     delete iDatabase;
       
    51     iDatabase=NULL;
       
    52 
       
    53     iCategorySearchResults.ResetAndDestroy();
       
    54 
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------
       
    58 // CPosTp25::StartL
       
    59 //
       
    60 // (other items were commented in a header).
       
    61 // ---------------------------------------------------------
       
    62 //
       
    63 void CPosTp25::StartL()
       
    64     {
       
    65     _LIT(KEmptyTextCriteriaErr, "An empty string as text criteria should not be allowed");
       
    66     _LIT(KEmptyTextCriteriaErr1, "An empty text criteria should not be allowed");
       
    67     // copy test db to the private path
       
    68     _LIT(KTestPath, "c:\\system\\test\\testdata\\");
       
    69 
       
    70     CFileMan* fileMan = CFileMan::NewL(iFileSession);
       
    71     CleanupStack::PushL(fileMan);
       
    72 
       
    73     TBuf<150> srcPath;
       
    74 
       
    75     srcPath.Append(KTestPath);
       
    76     srcPath.Append(KTp25TestDb);
       
    77 
       
    78     TInt er = fileMan->Copy(srcPath, KLmTp25DefaultDbPath,
       
    79             CFileMan::EOverWrite);
       
    80     if (er != KErrNone)
       
    81         iLog->Log(_L("Error when copying file"));
       
    82 
       
    83     CleanupStack::PopAndDestroy(fileMan);
       
    84     
       
    85     CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL();
       
    86     CleanupStack::PushL(manager);
       
    87 
       
    88     // This db must exist
       
    89     manager->SetDefaultDatabaseUriL(KTp25TestDb);
       
    90     CleanupStack::PopAndDestroy(manager);
       
    91 
       
    92     iDatabase = CPosLandmarkDatabase::OpenL(KTp25TestDb);
       
    93     if (iDatabase->IsInitializingNeeded())
       
    94         {
       
    95         TRAPD( err, ExecuteAndDeleteLD( iDatabase->InitializeL() ) );
       
    96         AssertTrueSecL(err == KErrNone, _L("Init db failed"));
       
    97         }
       
    98     
       
    99     
       
   100 
       
   101     iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase);
       
   102         
       
   103     TInt err = KErrNone;
       
   104     CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC();
       
   105        
       
   106     // Start by testing some error flows, returning KErrArgument
       
   107     TRAP(err, iLandmarkSearch->StartCategorySearchL(*nameCriteria, CPosLmCategoryManager::ECategorySortOrderNone)); 
       
   108     AssertTrueSecL(err == KErrArgument, KEmptyTextCriteriaErr1);
       
   109 
       
   110 
       
   111     // Test with a landmark search criteria into a category search operation
       
   112     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   113     textCriteria->SetTextL(_L("*"));
       
   114     TRAP(err, iLandmarkSearch->StartCategorySearchL(*textCriteria, CPosLmCategoryManager::ECategorySortOrderNone));
       
   115     AssertTrueSecL(err == KErrArgument, KEmptyTextCriteriaErr);
       
   116     CleanupStack::PopAndDestroy(textCriteria);
       
   117 
       
   118     // Test empty string
       
   119     nameCriteria->SetSearchPatternL(_L(""));   
       
   120     TRAP(err, iLandmarkSearch->StartCategorySearchL(*nameCriteria, CPosLmCategoryManager::ECategorySortOrderNone));
       
   121     AssertTrueSecL(err == KErrArgument, KEmptyTextCriteriaErr);
       
   122     CleanupStack::PopAndDestroy(nameCriteria);
       
   123     
       
   124     // test with maximum nr of characters in search pattern
       
   125     TestSearchPatternLengthL();
       
   126     
       
   127     AppendCategorySearchResultsL();
       
   128 
       
   129 	// Search synchronously
       
   130     iLog->Log(_L("Testing search with criterias read from LmDbSearchResult.txt syncronously"));
       
   131     SearchL(iCategorySearchResults, ESynchronous);
       
   132 
       
   133     iLog->Log(_L("Testing search with sort order"));
       
   134     SearchWithSortOrderL(iCategorySearchResults, ESynchronous);
       
   135 
       
   136     iLog->Log(_L("Testing search with maximum nr of matches"));
       
   137     SearchWithMaximumL(iCategorySearchResults, ESynchronous);
       
   138 
       
   139 	// Search asynchronously
       
   140     iLog->Log(_L("Testing search with criterias read from LmDbSearchResult.txt asyncronously"));
       
   141     SearchL(iCategorySearchResults, EAsynchronous);
       
   142 
       
   143     iLog->Log(_L("Testing search with sort order asynchronously"));
       
   144     SearchWithSortOrderL(iCategorySearchResults, EAsynchronous);
       
   145 
       
   146     iLog->Log(_L("Testing search with maximum nr of matches asynchronously"));
       
   147     SearchWithMaximumL(iCategorySearchResults, EAsynchronous);
       
   148 
       
   149 	// Search asynchronously with User::WaitForRequest()
       
   150     iLog->Log(_L("Testing search with criterias read from LmDbSearchResult.txt asyncronously using User::WaitForRequest()"));
       
   151     SearchL(iCategorySearchResults, EWaitForRequest);
       
   152 
       
   153     iLog->Log(_L("Testing search with sort order asynchronously using User::WaitForRequest()"));
       
   154     SearchWithSortOrderL(iCategorySearchResults, EWaitForRequest);
       
   155 
       
   156     iLog->Log(_L("Testing search with maximum nr of matches asynchronously using User::WaitForRequest()"));
       
   157     SearchWithMaximumL(iCategorySearchResults, EWaitForRequest);
       
   158 
       
   159 	// Search for added categories
       
   160     iLog->Log(_L("Testing search after category has been added"));
       
   161     SearchAfterAddedCategoryL();
       
   162 
       
   163 	// Cancel search test
       
   164     iLog->Log(_L("Testing category search and cancel"));    
       
   165     SearchAndCancelL();
       
   166 
       
   167     iLog->Log(_L("Testing category search and cancel in callback"));    
       
   168     SearchAndCancelL(ETrue);
       
   169 
       
   170     delete iDatabase;
       
   171     iDatabase = NULL;
       
   172     delete iLandmarkSearch;
       
   173     iLandmarkSearch = NULL;
       
   174     iDatabase = UseGlobalCategoriesL();
       
   175     
       
   176     if (iDatabase->IsInitializingNeeded())
       
   177        {
       
   178        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   179        }
       
   180        
       
   181     iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase);
       
   182 
       
   183     // Do reset so that global categories are included
       
   184     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   185     CleanupStack::PushL(categoryManager);   
       
   186     ExecuteAndDeleteLD(categoryManager->ResetGlobalCategoriesL());
       
   187     CleanupStack::PopAndDestroy(categoryManager);
       
   188 
       
   189     iLog->Log(_L("Testing search with global categories included, sync"));
       
   190     SearchGlobalL(iCategorySearchResults, ETrue);
       
   191 
       
   192     iLog->Log(_L("Testing search with global categories included, asyncronously"));
       
   193     SearchGlobalL(iCategorySearchResults, EFalse);
       
   194 
       
   195     // Verify error report "ESLI-62DBXR Landmarks - Sort order is not correctly implemented"
       
   196     // Check that CPosLandmarkSearch::MatchIteratorL are CPosLandmarkDatabase::LandmarkIteratorL
       
   197     // are sorted correctly (should be identically sorted)
       
   198     VerifySortOrderL();
       
   199 
       
   200     RemoveGlobalCategoriesL();
       
   201     
       
   202     delete iLandmarkSearch;
       
   203     iLandmarkSearch = NULL;
       
   204 
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------
       
   208 // CPosTp25::SearchL
       
   209 //
       
   210 // (other items were commented in a header).
       
   211 // ---------------------------------------------------------
       
   212 //
       
   213 void CPosTp25::SearchL(
       
   214     const RPointerArray<CCategorySearchResult>& aSearchResults, 
       
   215     TExecutionMode aExecutionMode)
       
   216     {
       
   217     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed");
       
   218     _LIT(KNotFoundErr, "Id %d not found in parsed Lm search results when the search is performed syncronously");
       
   219 
       
   220     for(TInt i=0; i<aSearchResults.Count(); i++)
       
   221         {   
       
   222         CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC();
       
   223         nameCriteria->SetSearchPatternL(aSearchResults[i]->TextCriteria());
       
   224         
       
   225         CPosLmDisplayData* displayData = CPosLmDisplayData::NewL();
       
   226 		    CleanupStack::PushL(displayData);
       
   227         iLandmarkSearch->SetDisplayData(*displayData);
       
   228 
       
   229         iOperation = iLandmarkSearch->StartCategorySearchL(*nameCriteria, CPosLmCategoryManager::ECategorySortOrderNone); 
       
   230 
       
   231         // The execution flow
       
   232         switch (aExecutionMode)
       
   233             {
       
   234             case ESynchronous:
       
   235                 ExecuteAndDeleteLD(iOperation);
       
   236                 break;
       
   237             case EAsynchronous:
       
   238                 RunAsyncOperationLD(iOperation);
       
   239                 break;
       
   240             case EWaitForRequest:
       
   241                 RunAsyncOperationByWaitForReqL(iOperation);
       
   242                 delete iOperation;
       
   243                 break;
       
   244             }
       
   245 
       
   246         CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   247         CleanupStack::PushL(iter);
       
   248         
       
   249         if ((TUint)(aSearchResults[i]->SearchResult()).Count() != iLandmarkSearch->NumOfMatches())
       
   250             {
       
   251             _LIT(KExpected, "Expected no. of matches: %d");
       
   252             _LIT(KReturned, "Returned no. of matches: %d");
       
   253             TBuf<100> info;
       
   254             info.Format(KExpected, (aSearchResults[i]->SearchResult()).Count());
       
   255             iLog->Log(info);
       
   256             info.Format(KReturned, iLandmarkSearch->NumOfMatches());
       
   257             iLog->Log(info);
       
   258             iLog->Log(_L("Name criteria: "));
       
   259             iLog->Log(nameCriteria->SearchPattern());
       
   260             iLog->Log(KNumOfMatchesErr);
       
   261             User::Leave(-1);
       
   262             }
       
   263 
       
   264         TPosLmItemId id = iter->NextL();
       
   265         while (id != KPosLmNullItemId)
       
   266             {
       
   267             AssertTrueSecL(aSearchResults[i]->FindSearchResult(id), KNotFoundErr, id);
       
   268 
       
   269             id = iter->NextL();
       
   270             }
       
   271 
       
   272 		// Check DisplayData below                
       
   273         TInt nrr = displayData->Count();
       
   274         
       
   275             if ((TUint)(aSearchResults[i]->SearchResult()).Count() != displayData->Count())
       
   276             {
       
   277             _LIT(KExpected, "Expected no. of displaydata matches: %d");
       
   278             _LIT(KReturned, "Returned no. of displaydata matches: %d");
       
   279             TBuf<100> info;
       
   280             info.Format(KExpected, (aSearchResults[i]->SearchResult()).Count());
       
   281             iLog->Log(info);
       
   282             info.Format(KReturned, displayData->Count());
       
   283             iLog->Log(info);
       
   284             iLog->Log(_L("Name criteria: "));
       
   285             iLog->Log(nameCriteria->SearchPattern());
       
   286                         
       
   287             iLog->Log(KNumOfMatchesErr);
       
   288             User::Leave(-1);
       
   289             }
       
   290 
       
   291         TInt itemId = displayData->NewItemIndex();
       
   292         while (itemId != KPosLmNoNewItems)
       
   293             {
       
   294             CPosLmDisplayItem& item = displayData->DisplayItem(itemId);
       
   295             
       
   296             if (item.DisplayItemType() != CPosLmDisplayItem::ECategoryItem)
       
   297             	{
       
   298             	iLog->Log(_L("ERROR :::::"));
       
   299             	iLog->Log(_L("Wrong item returned, only ECategoryItem should be returned"));
       
   300             	User::Leave(-1);
       
   301             	}
       
   302             
       
   303             if (item.DisplayItemType() == CPosLmDisplayItem::ELandmarkItem)
       
   304             	{
       
   305             	iLog->Log(_L("Is ELandmarkItem:::::"));
       
   306             	}
       
   307             
       
   308             if (item.DatabaseIndex() != 0)
       
   309             	{
       
   310             	// When single search, index should always be 0
       
   311             	iLog->Log(_L("Wrong DatabaseIndex, should be 0"));
       
   312             	User::Leave(-1);
       
   313             	
       
   314             	}
       
   315 			
       
   316 			      TInt categoryId = item.Category().CategoryId();
       
   317 
       
   318             if (!aSearchResults[i]->FindSearchResult(categoryId))
       
   319             	{
       
   320             	iLog->Log(_L("Not Found"));
       
   321             	TPtrC name;
       
   322 				      item.Category().GetCategoryName(name);
       
   323     			    iLog->Log(name);
       
   324             	iLog->Log(_L("Could not find LandmarkCategory"));
       
   325             	User::Leave(-1);
       
   326             	
       
   327             	}
       
   328             	itemId = displayData->NewItemIndex();
       
   329             }
       
   330         
       
   331         CleanupStack::PopAndDestroy(iter);
       
   332 				iLandmarkSearch->UnsetDisplayData();
       
   333 				CleanupStack::PopAndDestroy(displayData);
       
   334         CleanupStack::PopAndDestroy(nameCriteria);
       
   335         }
       
   336     }
       
   337 
       
   338 // ---------------------------------------------------------
       
   339 // CPosTp25::TestSearchPatternLengthL
       
   340 //
       
   341 // (other items were commented in a header).
       
   342 // ---------------------------------------------------------
       
   343 //
       
   344 void CPosTp25::TestSearchPatternLengthL()
       
   345     {
       
   346     iLog->Log(_L("TestSearchPatternLengthL"));
       
   347     
       
   348     CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC();  
       
   349     //Test with maximum size of search pattern
       
   350     //KPosLmMaxCategoryNameLength is 124 (from EPos_Landmarks.h)
       
   351     HBufC* hbuf = HBufC::NewLC(KPosLmMaxCategoryNameLength+1);
       
   352     while(hbuf->Des().Length() < KPosLmMaxCategoryNameLength)
       
   353         {
       
   354         hbuf->Des().Append(_L("*"));
       
   355         }
       
   356     nameCriteria->SetSearchPatternL(*hbuf);
       
   357         
       
   358     hbuf->Des().Append(_L("*"));
       
   359     TRAPD(err, nameCriteria->SetSearchPatternL(*hbuf));
       
   360 
       
   361     AssertTrueSecL(err == KErrArgument, _L("It should not be possible to set search pattern"));            
       
   362     
       
   363     CleanupStack::PopAndDestroy(hbuf);
       
   364     CleanupStack::PopAndDestroy(nameCriteria);
       
   365     }
       
   366 
       
   367 // ---------------------------------------------------------
       
   368 // CPosTp25::SearchWithSortOrderL
       
   369 //
       
   370 // (other items were commented in a header).
       
   371 // ---------------------------------------------------------
       
   372 //
       
   373 void CPosTp25::SearchWithSortOrderL(
       
   374     const RPointerArray<CCategorySearchResult>& aSearchResults, 
       
   375     TExecutionMode aExecutionMode)
       
   376     {
       
   377     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed");
       
   378     
       
   379     CPosLmCategoryManager::TCategorySortPref sortPref;
       
   380 
       
   381     for (TInt j=0;j<2;j++)
       
   382         {
       
   383         for(TInt i=0; i<aSearchResults.Count(); i++)
       
   384             {   
       
   385             CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC();
       
   386             nameCriteria->SetSearchPatternL(aSearchResults[i]->TextCriteria());
       
   387             
       
   388             if (j==0) 
       
   389                 {
       
   390                 sortPref = CPosLmCategoryManager::ECategorySortOrderNameAscending;
       
   391                 iOperation = iLandmarkSearch->StartCategorySearchL(*nameCriteria, sortPref);
       
   392                 }
       
   393             else 
       
   394                 {
       
   395                 sortPref = CPosLmCategoryManager::ECategorySortOrderNameDescending;
       
   396                 iOperation = iLandmarkSearch->StartCategorySearchL(*nameCriteria, sortPref);
       
   397                 }
       
   398             
       
   399             // The execution flow
       
   400             switch (aExecutionMode)
       
   401                 {
       
   402                 case ESynchronous:
       
   403                     ExecuteAndDeleteLD(iOperation);
       
   404                     break;
       
   405                 case EAsynchronous:
       
   406                     RunAsyncOperationLD(iOperation);
       
   407                     break;
       
   408                 case EWaitForRequest:
       
   409                     RunAsyncOperationByWaitForReqL(iOperation);
       
   410                     delete iOperation;
       
   411                     break;
       
   412                 }
       
   413             
       
   414             CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   415             CleanupStack::PushL(iter);
       
   416             
       
   417             // Create a sorted list out of the search result
       
   418             RArray<TPosLmItemId> searchResults = aSearchResults[i]->SearchResult();
       
   419             // To avoid User-44 create a copy of the aSearchResults[i]
       
   420             RArray<TPosLmItemId> searchResultsSorted;
       
   421             CleanupClosePushL(searchResultsSorted);
       
   422             
       
   423             for (TInt kk=0;kk<searchResults.Count();kk++)
       
   424                 {
       
   425                 searchResultsSorted.Append(searchResults[kk]);
       
   426                 }
       
   427 
       
   428             CategoriesSortL(searchResultsSorted, sortPref);
       
   429 
       
   430             if ((TUint)(aSearchResults[i]->SearchResult()).Count() != iLandmarkSearch->NumOfMatches())
       
   431                 {
       
   432                 _LIT(KExpected, "Expected no. of matches: %d");
       
   433                 _LIT(KReturned, "Returned no. of matches: %d");
       
   434                 TBuf<100> info;
       
   435                 info.Format(KExpected, (aSearchResults[i]->SearchResult()).Count());
       
   436                 iLog->Log(info);
       
   437                 info.Format(KReturned, iLandmarkSearch->NumOfMatches());
       
   438                 iLog->Log(info);
       
   439                 iLog->Log(_L("Name criteria: "));
       
   440                 iLog->Log(nameCriteria->SearchPattern());
       
   441                           
       
   442                 iLog->Log(KNumOfMatchesErr);
       
   443             		User::Leave(-1);
       
   444             	
       
   445                 }
       
   446             
       
   447             TPosLmItemId id = iter->NextL();
       
   448             TInt counter=0;
       
   449             while (id != KPosLmNullItemId)
       
   450                 {
       
   451                 // Check that sort order is correct
       
   452                 AssertTrueSecL(searchResultsSorted[counter] == id, _L("Error in sorting"));
       
   453                 id = iter->NextL();
       
   454                 counter++;
       
   455                 }
       
   456             CleanupStack::PopAndDestroy(&searchResultsSorted);
       
   457             CleanupStack::PopAndDestroy(2, nameCriteria);
       
   458             }
       
   459         }
       
   460     }
       
   461 
       
   462 // ---------------------------------------------------------
       
   463 // CPosTp25::SearchWithMaximumL
       
   464 //
       
   465 // (other items were commented in a header).
       
   466 // ---------------------------------------------------------
       
   467 //
       
   468 void CPosTp25::SearchWithMaximumL(
       
   469     const RPointerArray<CCategorySearchResult>& aSearchResults, 
       
   470     TExecutionMode aExecutionMode)
       
   471     {
       
   472     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when SearchWithMaximumL is performed");
       
   473     _LIT(KNotFoundErr, "Id %d not found in parsed Lm search results when the search is performed syncronously");
       
   474 
       
   475     CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC();
       
   476 
       
   477     // First get the maximum number of matches
       
   478     nameCriteria->SetSearchPatternL(_L("*"));  
       
   479     ExecuteAndDeleteLD(iLandmarkSearch->StartCategorySearchL(*nameCriteria, CPosLmCategoryManager::ECategorySortOrderNone)); 
       
   480     TInt max = iLandmarkSearch->NumOfMatches();
       
   481 
       
   482     for (TInt j=1;j<=max;j++)
       
   483         {
       
   484         nameCriteria->SetSearchPatternL(_L("*"));
       
   485         iLandmarkSearch->SetMaxNumOfMatches(j);
       
   486         iOperation = iLandmarkSearch->StartCategorySearchL(*nameCriteria, CPosLmCategoryManager::ECategorySortOrderNone); 
       
   487         
       
   488         // The execution flow
       
   489         switch (aExecutionMode)
       
   490             {
       
   491             case ESynchronous:
       
   492                 ExecuteAndDeleteLD(iOperation);
       
   493                 break;
       
   494             case EAsynchronous:
       
   495                 RunAsyncOperationLD(iOperation);
       
   496                 break;
       
   497             case EWaitForRequest:
       
   498                 RunAsyncOperationByWaitForReqL(iOperation);
       
   499                 delete iOperation;
       
   500                 break;
       
   501             }
       
   502 
       
   503         AssertTrueSecL((TUint)j == iLandmarkSearch->NumOfMatches(), KNumOfMatchesErr);
       
   504 
       
   505         CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   506         CleanupStack::PushL(iter);
       
   507 
       
   508         TPosLmItemId id = iter->NextL();
       
   509         while (id != KPosLmNullItemId)
       
   510             {
       
   511             // Use search result for position 0, should always be for *
       
   512             AssertTrueSecL(aSearchResults[0]->FindSearchResult(id), KNotFoundErr, id);
       
   513             id = iter->NextL();
       
   514             }
       
   515         CleanupStack::PopAndDestroy(iter);
       
   516         }
       
   517         
       
   518     CleanupStack::PopAndDestroy(nameCriteria);
       
   519     }
       
   520 
       
   521 // ---------------------------------------------------------
       
   522 // CPosTp25::SearchAfterAddedCategoryL
       
   523 //
       
   524 // (other items were commented in a header).
       
   525 // ---------------------------------------------------------
       
   526 //
       
   527 void CPosTp25::SearchAfterAddedCategoryL()
       
   528     {
       
   529     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when SearchAfterAddedCategoryL is performed");
       
   530     _LIT(KCategoryNotFound, "Added category could not be found");
       
   531     _LIT(KCategory, "StoraKoncernen");
       
   532 
       
   533     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   534     CleanupStack::PushL(categoryManager);
       
   535     CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC();
       
   536 
       
   537     CPosLandmarkCategory* cat1 = CPosLandmarkCategory::NewLC();
       
   538 
       
   539     // First do a search with wildcard
       
   540     nameCriteria->SetSearchPatternL(_L("S*"));  
       
   541     ExecuteAndDeleteLD(iLandmarkSearch->StartCategorySearchL(*nameCriteria, CPosLmCategoryManager::ECategorySortOrderNone)); 
       
   542 
       
   543     // Then add a new category with a name starting with S
       
   544     cat1->SetCategoryNameL(KCategory);
       
   545     TPosLmItemId categoryId = categoryManager->AddCategoryL(*cat1);
       
   546     CleanupStack::PopAndDestroy(cat1);
       
   547 
       
   548     // Then use do another search within the results of previous search
       
   549     // should return Stadsbibliotek and Stadspark
       
   550     nameCriteria->SetSearchPatternL(_L("St*"));
       
   551     ExecuteAndDeleteLD(iLandmarkSearch->StartCategorySearchL(*nameCriteria, CPosLmCategoryManager::ECategorySortOrderNone, ETrue)); 
       
   552     TInt max = iLandmarkSearch->NumOfMatches();
       
   553 
       
   554     if (max != 2) 
       
   555     	{
       
   556 				iLog->Log(KNumOfMatchesErr);
       
   557         User::Leave(-1);
       
   558 			}
       
   559     // Set a maximum number of matches, should return only one of Stadsbibliotek and Stadspark
       
   560     iLandmarkSearch->SetMaxNumOfMatches(1);
       
   561 
       
   562     // Do another search just to see that it is possible to find the added category
       
   563     nameCriteria->SetSearchPatternL(KCategory);
       
   564     ExecuteAndDeleteLD(iLandmarkSearch->StartCategorySearchL(*nameCriteria, CPosLmCategoryManager::ECategorySortOrderNone)); 
       
   565 
       
   566     CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   567     CleanupStack::PushL(iter);
       
   568     
       
   569     TPosLmItemId id = iter->NextL();
       
   570     max = iLandmarkSearch->NumOfMatches();
       
   571     
       
   572     if (max != 1)
       
   573     	{
       
   574     		iLog->Log(KNumOfMatchesErr);
       
   575         User::Leave(-1);
       
   576     	}
       
   577     if (categoryId != id) 
       
   578        {
       
   579     		iLog->Log(KCategoryNotFound);
       
   580         User::Leave(-1);
       
   581     	}
       
   582 
       
   583 
       
   584     // Remove added category
       
   585     ExecuteAndDeleteLD(categoryManager->RemoveCategoryL(categoryId));
       
   586 
       
   587     CleanupStack::PopAndDestroy(iter);
       
   588     CleanupStack::PopAndDestroy(nameCriteria);
       
   589     CleanupStack::PopAndDestroy(categoryManager);
       
   590     }
       
   591 
       
   592 // ---------------------------------------------------------
       
   593 // CPosTp25::SearchGlobalL
       
   594 //
       
   595 // (other items were commented in a header).
       
   596 // ---------------------------------------------------------
       
   597 //
       
   598 void CPosTp25::SearchGlobalL(const RPointerArray<CCategorySearchResult>& aSearchResults, const TBool& aSync)
       
   599     {
       
   600     iLog->Log(_L("SearchGlobalL"));
       
   601     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when SearchGlobalL is performed");
       
   602 
       
   603     // Nr of global categories, defined in resource file
       
   604     const TInt KNrOfGlobalCategories = 15;
       
   605 
       
   606     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   607     CleanupStack::PushL(categoryManager);
       
   608     CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC();
       
   609     CPosLmCategoryManager::TCategorySortPref sortPref = CPosLmCategoryManager::ECategorySortOrderNameAscending;
       
   610     
       
   611     for (TInt l=0;l<2;l++)
       
   612     {
       
   613         if (l==0) sortPref = CPosLmCategoryManager::ECategorySortOrderNameAscending;
       
   614         else if (l==1) sortPref = CPosLmCategoryManager::ECategorySortOrderNameDescending;
       
   615 
       
   616         // i=0 the first entry in aSearchResults should be wildcard "*"
       
   617         TInt i = 0;
       
   618         // First do a search with wildcard
       
   619         nameCriteria->SetSearchPatternL(aSearchResults[i]->TextCriteria());
       
   620         iOperation = iLandmarkSearch->StartCategorySearchL(*nameCriteria, sortPref);
       
   621         
       
   622         // The asynchronous flow
       
   623         if (aSync)
       
   624         {
       
   625             RunAsyncOperationLD(iOperation);
       
   626         }
       
   627         else
       
   628         {
       
   629             ExecuteAndDeleteLD(iOperation);
       
   630         }
       
   631         
       
   632         CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   633         CleanupStack::PushL(iter);
       
   634         
       
   635         // Create a sorted list out of the search result
       
   636         RArray<TPosLmItemId> searchResults = aSearchResults[i]->SearchResult();
       
   637         RArray<TPosLmItemId> searchResultsSorted;
       
   638         
       
   639         for (TInt kk=0;kk<searchResults.Count();kk++)
       
   640         {
       
   641             searchResultsSorted.Append(searchResults[kk]);
       
   642         }
       
   643         
       
   644 			        searchResultsSorted.Append(28);
       
   645 			        searchResultsSorted.Append(29);
       
   646 			        searchResultsSorted.Append(30);
       
   647 			        searchResultsSorted.Append(31);
       
   648 			        searchResultsSorted.Append(32);
       
   649 			        searchResultsSorted.Append(33);
       
   650 			        searchResultsSorted.Append(34);
       
   651 			        searchResultsSorted.Append(35);
       
   652 							searchResultsSorted.Append(36);
       
   653 							searchResultsSorted.Append(37);
       
   654 							searchResultsSorted.Append(38);
       
   655 							searchResultsSorted.Append(39);
       
   656 							searchResultsSorted.Append(40);
       
   657 							searchResultsSorted.Append(41);
       
   658 							searchResultsSorted.Append(42);
       
   659 
       
   660         // Sort list according to sortPref
       
   661         CategoriesSortL(searchResultsSorted, sortPref);
       
   662         TUint expNr = (aSearchResults[i]->SearchResult()).Count() + KNrOfGlobalCategories;
       
   663         TUint expNr2 = iLandmarkSearch->NumOfMatches();
       
   664         
       
   665         if (expNr != expNr2)
       
   666         {
       
   667             _LIT(KExpected, "Expected no. of matches: %d");
       
   668             _LIT(KReturned, "Returned no. of matches: %d");
       
   669             TBuf<100> info;
       
   670             info.Format(KExpected, expNr);
       
   671             iLog->Log(info);
       
   672             info.Format(KReturned, expNr2);
       
   673             iLog->Log(info);
       
   674             iLog->Log(_L("Name criteria: "));
       
   675             iLog->Log(nameCriteria->SearchPattern());
       
   676             
       
   677             iLog->Log(KNumOfMatchesErr);
       
   678        		  User::Leave(-1);
       
   679         }
       
   680         
       
   681         TPosLmItemId id = iter->NextL();
       
   682         TInt counter=0;
       
   683         while (id != KPosLmNullItemId)
       
   684         {
       
   685             // Check that sort order is correct
       
   686             AssertTrueSecL(searchResultsSorted[counter] == id, _L("Error in sorting"));
       
   687             id = iter->NextL();
       
   688             counter++;
       
   689         }
       
   690         
       
   691         CleanupStack::PopAndDestroy(iter);
       
   692         searchResultsSorted.Reset();
       
   693         searchResultsSorted.Close();
       
   694 
       
   695     } // end for (TInt l=0 ...)
       
   696     CleanupStack::PopAndDestroy(nameCriteria);
       
   697     CleanupStack::PopAndDestroy(categoryManager);
       
   698     iLog->Log(_L("SearchGlobalL Done"));
       
   699     }
       
   700 
       
   701 // ---------------------------------------------------------
       
   702 // CPosTp24::SearchAndCancelL
       
   703 //
       
   704 // (other items were commented in a header).
       
   705 // ---------------------------------------------------------
       
   706 //
       
   707 void CPosTp25::SearchAndCancelL(const TBool& aInCallback)
       
   708     {
       
   709     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed");
       
   710     _LIT(KCancelErr, "The search is canceled after progress has increased but no search result is found");
       
   711 
       
   712     // Test search with one criteria
       
   713     const TInt KIndex=0;
       
   714 
       
   715     CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC();
       
   716     nameCriteria->SetSearchPatternL(iCategorySearchResults[KIndex]->TextCriteria());
       
   717     iLandmarkSearch->SetMaxNumOfMatches();
       
   718 
       
   719     if (aInCallback)
       
   720         {
       
   721         RunAsyncOperationAndCancelInCallbackLD(iLandmarkSearch->StartCategorySearchL(
       
   722                 *nameCriteria, 
       
   723                 CPosLmCategoryManager::ECategorySortOrderNone, 
       
   724                 iCategorySearchResults[KIndex]->Redefined()));
       
   725         }
       
   726     else
       
   727         {
       
   728         RunAsyncOperationAndCancelLD(iLandmarkSearch->StartCategorySearchL(
       
   729                 *nameCriteria, 
       
   730                 CPosLmCategoryManager::ECategorySortOrderNone, 
       
   731                 iCategorySearchResults[KIndex]->Redefined()));
       
   732         }
       
   733 
       
   734     CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   735     CleanupStack::PushL(iter);
       
   736  
       
   737     if (aInCallback)
       
   738         {
       
   739         if (iter->NumOfItemsL() != iLandmarkSearch->NumOfMatches())
       
   740             {
       
   741 		           	iLog->Log(_L("Iterators no. of items is not equal to LandmarksSearch no. matches"));
       
   742 		            _LIT(KExpected, "Iter. of matches: %d");
       
   743 		            _LIT(KReturned, "LandmarksSearch no. of matches: %d");
       
   744 		            TBuf<100> info;
       
   745 		            info.Format(KExpected, iter->NumOfItemsL());
       
   746 		            iLog->Log(info);
       
   747 		            info.Format(KReturned, iLandmarkSearch->NumOfMatches());
       
   748 		            iLog->Log(info);
       
   749 		            iLog->Log(KNumOfMatchesErr);
       
   750 		       		  User::Leave(-1);
       
   751             }
       
   752         TBuf<100> info2;
       
   753         _LIT(KNof, "No. of matches found before cancel = %d");
       
   754         info2.Format(KNof, iter->NumOfItemsL());
       
   755         iLog->Log(info2);
       
   756 
       
   757         AssertTrueSecL(iter->NumOfItemsL() != 0, KCancelErr);
       
   758         }
       
   759         
       
   760     CleanupStack::PopAndDestroy(2, nameCriteria);   
       
   761     }
       
   762 
       
   763 // ---------------------------------------------------------
       
   764 // CPosTp25::VerifySortOrderL
       
   765 //
       
   766 // (other items were commented in a header).
       
   767 // ---------------------------------------------------------
       
   768 //
       
   769 void CPosTp25::VerifySortOrderL()
       
   770     {
       
   771     iLog->Log(_L("VerifySortOrderL"));
       
   772     // Search pattern "*" should match all existing landmarks -> it is possible to compare
       
   773     // sort order of CPosLandmarkSearch::MatchIteratorL with CPosLandmarkDatabase::LandmarkIteratorL
       
   774 
       
   775     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed");
       
   776     _LIT(KNumOfMatchesErr2, "No. of matches in DisplayData is incorrect when the search is performed");
       
   777     
       
   778     _LIT(KSortorderErr, "The sortorder is incorrect");
       
   779     _LIT(KNameMatchError, "The landmark category name does not match");
       
   780 
       
   781     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   782     CleanupStack::PushL(categoryManager);
       
   783 
       
   784     // Just in case, add some categories
       
   785     CPosLandmarkCategory* cat1 = CPosLandmarkCategory::NewLC();
       
   786     cat1->SetCategoryNameL(_L("CategoryA"));
       
   787     TPosLmItemId categoryId1 = categoryManager->AddCategoryL(*cat1);
       
   788     CleanupStack::PopAndDestroy(cat1);
       
   789 
       
   790     cat1 = CPosLandmarkCategory::NewLC();
       
   791     cat1->SetCategoryNameL(_L("Categorya"));
       
   792     TPosLmItemId categoryId2 = categoryManager->AddCategoryL(*cat1);
       
   793     CleanupStack::PopAndDestroy(cat1);
       
   794 
       
   795     cat1 = CPosLandmarkCategory::NewLC();
       
   796     cat1->SetCategoryNameL(_L("AA"));
       
   797     TPosLmItemId categoryId3 = categoryManager->AddCategoryL(*cat1);
       
   798     CleanupStack::PopAndDestroy(cat1);
       
   799 
       
   800     cat1 = CPosLandmarkCategory::NewLC();
       
   801     cat1->SetCategoryNameL(_L("aa"));
       
   802     TPosLmItemId categoryId4 = categoryManager->AddCategoryL(*cat1);
       
   803     CleanupStack::PopAndDestroy(cat1);
       
   804 
       
   805     CleanupStack::PopAndDestroy(categoryManager);
       
   806 
       
   807     CPosLmCategoryManager::TCategorySortPref sortPrefAsc = CPosLmCategoryManager::ECategorySortOrderNameAscending;;
       
   808     CPosLmCategoryManager::TCategorySortPref sortPrefDesc = CPosLmCategoryManager::ECategorySortOrderNameDescending;;
       
   809     CPosLmItemIterator* categoryDbIter = NULL;
       
   810 
       
   811     for (TInt j=0;j<6;j++)
       
   812         {
       
   813         categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   814         CleanupStack::PushL(categoryManager);
       
   815 
       
   816         CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC();
       
   817         nameCriteria->SetSearchPatternL(_L("*"));
       
   818         
       
   819         CPosLmDisplayData* displayData = CPosLmDisplayData::NewL();
       
   820 				CleanupStack::PushL(displayData);
       
   821         iLandmarkSearch->SetDisplayData(*displayData);
       
   822         
       
   823         if (j==0) 
       
   824             {
       
   825             // Sorted Ascending, sync
       
   826             iLog->Log(_L("Sorted Ascending, Sync"));
       
   827             categoryDbIter = categoryManager->CategoryIteratorL(sortPrefAsc);
       
   828             CleanupStack::PushL(categoryDbIter);
       
   829             iOperation = iLandmarkSearch->StartCategorySearchL(*nameCriteria, sortPrefAsc);
       
   830             ExecuteAndDeleteLD(iOperation);
       
   831             }
       
   832         else if (j==1)
       
   833             {
       
   834             // Sorted Descending, sync
       
   835             iLog->Log(_L("Sorted Descending, Sync"));
       
   836             categoryDbIter = categoryManager->CategoryIteratorL(sortPrefDesc);
       
   837             CleanupStack::PushL(categoryDbIter);
       
   838             iOperation = iLandmarkSearch->StartCategorySearchL(*nameCriteria, sortPrefDesc);
       
   839             ExecuteAndDeleteLD(iOperation);
       
   840             }
       
   841         else if (j==2)
       
   842             {
       
   843             // Sorted Ascending, async
       
   844             iLog->Log(_L("Sorted Ascending, Async"));
       
   845             categoryDbIter = categoryManager->CategoryIteratorL(sortPrefAsc);
       
   846             CleanupStack::PushL(categoryDbIter);
       
   847             iOperation = iLandmarkSearch->StartCategorySearchL(*nameCriteria, sortPrefAsc);
       
   848             RunAsyncOperationLD(iOperation);
       
   849             }
       
   850         else if (j==3)
       
   851             {
       
   852             // Sorted Descending, async
       
   853             iLog->Log(_L("Sorted Descending, Async"));
       
   854             categoryDbIter = categoryManager->CategoryIteratorL(sortPrefDesc);
       
   855             CleanupStack::PushL(categoryDbIter);
       
   856             iOperation = iLandmarkSearch->StartCategorySearchL(*nameCriteria, sortPrefDesc);
       
   857             RunAsyncOperationLD(iOperation);
       
   858             }
       
   859         else if (j==4)
       
   860             {
       
   861             iLog->Log(_L("Sorted Ascending, Async using User::WaitForRequest"));
       
   862             // Sorted Ascending, async using User::WaitForRequest()
       
   863             categoryDbIter = categoryManager->CategoryIteratorL(sortPrefAsc);
       
   864             CleanupStack::PushL(categoryDbIter);
       
   865             iOperation = iLandmarkSearch->StartCategorySearchL(*nameCriteria, sortPrefAsc);
       
   866             RunAsyncOperationByWaitForReqL(iOperation);
       
   867             delete iOperation;
       
   868             }
       
   869         else if (j==5)
       
   870             {
       
   871             iLog->Log(_L("Sorted Descending, Async using User::WaitForRequest"));
       
   872             // Sorted Descending, async using User::WaitForRequest()
       
   873             categoryDbIter = categoryManager->CategoryIteratorL(sortPrefDesc);
       
   874             CleanupStack::PushL(categoryDbIter);
       
   875             iOperation = iLandmarkSearch->StartCategorySearchL(*nameCriteria, sortPrefDesc);
       
   876             RunAsyncOperationByWaitForReqL(iOperation);
       
   877             delete iOperation;
       
   878             }
       
   879         
       
   880         CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   881         CleanupStack::PushL(iter);
       
   882         
       
   883         AssertTrueSecL(iter->NumOfItemsL() == categoryDbIter->NumOfItemsL(), KNumOfMatchesErr);
       
   884         
       
   885         // Check correct displayData
       
   886         AssertTrueSecL(iter->NumOfItemsL() == displayData->Count(), KNumOfMatchesErr2);
       
   887         
       
   888         TInt itemId = displayData->NewItemIndex();
       
   889            
       
   890         TPosLmItemId id = iter->NextL();
       
   891         TPosLmItemId categoryDbId = categoryDbIter->NextL();
       
   892         // check that the two iterators are sorted identically
       
   893         while (id != KPosLmNullItemId)
       
   894             {
       
   895             CPosLandmarkCategory* source = categoryManager->ReadCategoryLC(id);
       
   896             CPosLandmarkCategory* target = categoryManager->ReadCategoryLC(categoryDbId);
       
   897             
       
   898             CPosLmDisplayItem& item = displayData->DisplayItem(itemId);
       
   899         	TInt categoryId = item.Category().CategoryId();
       
   900 
       
   901         	// For debugging purposes
       
   902         		TPtrC sourceName, targetName;
       
   903             source->GetCategoryName(sourceName);
       
   904             target->GetCategoryName(targetName);
       
   905             TPtrC name;
       
   906 						item.Category().GetCategoryName(name);
       
   907             		
       
   908             TBuf<150> buf;
       
   909             buf.Append(_L("Name:"));
       
   910             buf.Append(sourceName);
       
   911             buf.Append(_L("<->"));
       
   912             buf.Append(targetName);
       
   913             buf.Append(_L("<->"));
       
   914             buf.Append(name);
       
   915             iLog->Log(buf);
       
   916             
       
   917             AssertTrueSecL(id == categoryDbId, KSortorderErr);
       
   918         		AssertTrueSecL(id == categoryId, _L("Wrong displaydata item when sorting"));
       
   919         		// Should always be the same, since we check that id are equal above
       
   920             AssertTrueSecL(sourceName.Compare(targetName) == KErrNone, KNameMatchError);
       
   921             AssertTrueSecL(sourceName.Compare(name) == KErrNone, _L("Wrong DisplayData item name when sorting"));
       
   922             
       
   923             CleanupStack::PopAndDestroy(target);
       
   924             CleanupStack::PopAndDestroy(source);
       
   925             
       
   926             id = iter->NextL();
       
   927             categoryDbId = categoryDbIter->NextL();
       
   928             itemId = displayData->NewItemIndex();
       
   929             }
       
   930         iLog->Log(_L("Done"));
       
   931         CleanupStack::PopAndDestroy(iter);
       
   932         CleanupStack::PopAndDestroy(categoryDbIter);
       
   933         
       
   934         iLandmarkSearch->UnsetDisplayData();
       
   935 		    CleanupStack::PopAndDestroy(displayData);
       
   936 		
       
   937         CleanupStack::PopAndDestroy(nameCriteria);
       
   938         CleanupStack::PopAndDestroy(categoryManager);
       
   939         }
       
   940 
       
   941     // Delete the categories added in the beginning
       
   942     categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   943     CleanupStack::PushL(categoryManager);
       
   944 
       
   945     iOperation = categoryManager->RemoveCategoryL(categoryId1);
       
   946     ExecuteAndDeleteLD(iOperation);
       
   947     iOperation = categoryManager->RemoveCategoryL(categoryId2);
       
   948     ExecuteAndDeleteLD(iOperation);
       
   949     iOperation = categoryManager->RemoveCategoryL(categoryId3);
       
   950     ExecuteAndDeleteLD(iOperation);
       
   951     iOperation = categoryManager->RemoveCategoryL(categoryId4);
       
   952     ExecuteAndDeleteLD(iOperation);
       
   953     
       
   954     CleanupStack::PopAndDestroy(categoryManager);
       
   955     iLog->Log(_L("VerifySortOrderL Done"));
       
   956     }
       
   957 
       
   958 //  End of File