landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp120.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_CPosTp120.h"
       
    22 #include "FT_LandmarkConstants.h"
       
    23 #include <EPos_CPosLandmarkDatabase.h>
       
    24 #include <EPos_CPosLmCategoryManager.h>
       
    25 #include <EPos_CPosLmAreaCriteria.h>
       
    26 #include <EPos_CPosLMItemIterator.h>    
       
    27 #include <EPos_TPosLMSortPref.h>
       
    28      
       
    29 // CONSTANTS  
       
    30 const TInt KNrOfDbs = 5;
       
    31 const TInt KLmPerDb = 20;
       
    32 const TInt KTotLms = 105;
       
    33 
       
    34 // ================= MEMBER FUNCTIONS =======================
       
    35 
       
    36 
       
    37 // ---------------------------------------------------------
       
    38 // CPosTp120::CloseTest
       
    39 //
       
    40 // (other items were commented in a header).
       
    41 // ---------------------------------------------------------
       
    42 //
       
    43 void CPosTp120::CloseTest()
       
    44     {
       
    45     delete iDatabase;
       
    46     iDatabase = NULL;
       
    47     
       
    48     delete iDbArray;
       
    49 
       
    50     delete iLmMultiSearch;
       
    51     iLmMultiSearch = NULL;
       
    52     
       
    53     iAreaSearchResults.ResetAndDestroy();
       
    54     
       
    55     REComSession::FinalClose();
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // CPosTp120::StartL
       
    60 //
       
    61 // (other items were commented in a header).
       
    62 // ---------------------------------------------------------
       
    63 //
       
    64 void CPosTp120::StartL()
       
    65     {
       
    66     // Split databases, NrOfDBs db, LmPerDb lm in each, TotLms is last lm id from original db.
       
    67     // Last param is to enable/disable debug
       
    68     iDbArray = CreateDatabasesL(KNrOfDbs, KLmPerDb, KTotLms); //, ETrue);    
       
    69        
       
    70     // Constructing a lm multi search 
       
    71     iLmMultiSearch = CPosLmMultiDbSearch::NewL(*iDbArray);
       
    72 
       
    73     AppendAreaSearchResultsL();
       
    74             
       
    75     iLog->Log(_L("Testing search with criterias read from LmDbAreaSearchResult.txt syncronously"));
       
    76     SearchL(iAreaSearchResults, ESynchronous);
       
    77 
       
    78     iLog->Log(_L("Testing search with criterias read from LmDbAreaSearchResult.txt asyncronously"));
       
    79     SearchL(iAreaSearchResults, EAsynchronous);
       
    80 
       
    81     
       
    82     iLog->Log(_L("Testing search with a defined sortorder"));
       
    83     SearchWithSortOrderL(iAreaSearchResults);   
       
    84 
       
    85     iLog->Log(_L("Testing search and cancel"));
       
    86     SearchAndCancelL();
       
    87     
       
    88 
       
    89     iLog->Log(_L("Testing maximum number of matches"));
       
    90     SearchWithMaximumL();
       
    91     
       
    92     iLog->Log(_L("Testing searching on the fly"));
       
    93     OnTheFlySearchL();  
       
    94     
       
    95     iLog->Log(_L("Testing a redefined search after landmarks have been renamed"));
       
    96     SearchAndRenameL();
       
    97 
       
    98     iLog->Log(_L("Testing a redefined search after a landmark has been removed"));
       
    99     SearchAndDeleteL();
       
   100 
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------
       
   104 // CPosTp120::AreaCriteriaL
       
   105 //
       
   106 // (other items were commented in a header).
       
   107 // ---------------------------------------------------------
       
   108 //
       
   109 CPosLmAreaCriteria* CPosTp120::AreaCriteriaL(const TReal64 &aSouthLat, 
       
   110                                              const TReal64 &aNorthLat,
       
   111                                              const TReal64 &aWestLong, 
       
   112                                              const TReal64 &aEastLong) 
       
   113     {
       
   114     CPosLmAreaCriteria* areaCriteria = CPosLmAreaCriteria::NewLC(aSouthLat, 
       
   115                                                                 aNorthLat, 
       
   116                                                                 aWestLong, 
       
   117                                                                 aEastLong);
       
   118     CleanupStack::Pop();
       
   119     return areaCriteria;
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------
       
   123 // CPosTp120::CheckDatabasesL
       
   124 //
       
   125 // (other items were commented in a header).
       
   126 // ---------------------------------------------------------
       
   127 //
       
   128 void CPosTp120::CheckDatabasesL(
       
   129     CDesCArray* aExpectedLmUris,
       
   130     TUint aExpectedMaxMatches)
       
   131     {
       
   132     CDesCArray* dbToSearch = iLmMultiSearch->DatabasesToSearchL();
       
   133     CleanupStack::PushL(dbToSearch);
       
   134     
       
   135     _LIT(KWrongNrDatabases, "Wrong number of databases to search!");
       
   136     AssertTrueSecL(aExpectedLmUris != dbToSearch, KWrongNrDatabases);
       
   137     AssertTrueSecL(aExpectedLmUris->Count() == dbToSearch->Count(), KWrongNrDatabases);
       
   138     CleanupStack::PopAndDestroy(dbToSearch);
       
   139     
       
   140     AssertTrueSecL(aExpectedLmUris->Count() == iLmMultiSearch->NumOfDatabasesToSearch(), 
       
   141         KWrongNrDatabases);
       
   142     for (TInt i=0; i<aExpectedLmUris->Count(); i++)
       
   143         {
       
   144         AssertTrueSecL(aExpectedLmUris->MdcaPoint(i) == iLmMultiSearch->DatabaseUriPtr(i), 
       
   145             KWrongNrDatabases);        
       
   146         }
       
   147     
       
   148     _LIT(KWrongNrMatches, "Wrong number of max matches!");
       
   149     AssertTrueSecL(iLmMultiSearch->MaxNumOfMatches() == aExpectedMaxMatches, 
       
   150         KWrongNrMatches);        
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------
       
   154 // CPosTp120::GetLmIdsL
       
   155 //
       
   156 // (other items were commented in a header).
       
   157 // ---------------------------------------------------------
       
   158 //
       
   159 void CPosTp120::GetLmIdsL(
       
   160     TInt aDbId, 
       
   161     RArray<TPosLmItemId> aSearchResults,
       
   162     RArray<TPosLmItemId>& aLmIdForADb)
       
   163     {
       
   164     TInt startId = aDbId * KLmPerDb + 1;
       
   165     TInt stopId = 0;
       
   166     
       
   167     if (aDbId == KNrOfDbs - 1)
       
   168         {
       
   169         stopId = KTotLms;            
       
   170         }
       
   171     else 
       
   172         {
       
   173         stopId = (aDbId+1) * KLmPerDb;            
       
   174         }
       
   175     
       
   176     for (TInt i=0; i<aSearchResults.Count(); i++)
       
   177         {
       
   178         if (aSearchResults[i] >= startId && aSearchResults[i] <= stopId)
       
   179             {
       
   180             User::LeaveIfError(aLmIdForADb.Append(aSearchResults[i]));
       
   181             }
       
   182         }
       
   183     }
       
   184     
       
   185 // ---------------------------------------------------------
       
   186 // CPosTp120::CheckEqualsLmsL
       
   187 //
       
   188 // (other items were commented in a header).
       
   189 // ---------------------------------------------------------
       
   190 //
       
   191 void CPosTp120::CheckEqualsLmsL(
       
   192     TPosLmItemId aSource, 
       
   193     TPosLmItemId aTarget)
       
   194     {
       
   195     _LIT(KSortorderErr, "The sortorder is incorrect");
       
   196 
       
   197     if (aSource != aTarget)
       
   198         {                
       
   199         // Check if same name then don't Leave
       
   200         CPosLandmark* source = iDatabase->ReadLandmarkLC(aSource);
       
   201         CPosLandmark* target = iDatabase->ReadLandmarkLC(aTarget);
       
   202         TPtrC sourceName, targetName;
       
   203         source->GetLandmarkName(sourceName);
       
   204         target->GetLandmarkName(targetName);
       
   205 
       
   206         if (EFalse)
       
   207             {
       
   208             // For debugging purposes
       
   209             TBuf<100> buf;
       
   210             buf.Append(_L("Name:"));
       
   211             buf.Append(sourceName);
       
   212             buf.Append(targetName);
       
   213             iLog->Log(buf);
       
   214             }
       
   215 
       
   216         AssertTrueSecL(!sourceName.CompareC(targetName), KSortorderErr, aSource);
       
   217         CleanupStack::PopAndDestroy(2, source); // target, source
       
   218         }
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------
       
   222 // CPosTp120::SearchL
       
   223 //
       
   224 // (other items were commented in a header).
       
   225 // ---------------------------------------------------------
       
   226 //
       
   227 void CPosTp120::SearchL(
       
   228     const RPointerArray<CAreaSearchResult>& aSearchResults, 
       
   229     TExecutionMode aExecutionMode)
       
   230     {
       
   231     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed");
       
   232     _LIT(KNotFoundErr, "Id %d not found in parsed Lm search results when the search is performed syncronously");
       
   233     TBuf<255> info;
       
   234 
       
   235     for(TInt i=0; i<aSearchResults.Count(); i++)
       
   236         {   
       
   237         CPosLmAreaCriteria* areaCriteria = NULL;
       
   238         TRAPD(err, areaCriteria = CPosTp120::AreaCriteriaL(aSearchResults[i]->SouthLat(),
       
   239                                                 aSearchResults[i]->NorthLat(),
       
   240                                                 aSearchResults[i]->WestLong(),
       
   241                                                 aSearchResults[i]->EastLong()));
       
   242         CleanupStack::PushL(areaCriteria);
       
   243         
       
   244         if (err != aSearchResults[i]->ErrorCode())
       
   245             {
       
   246             iLog->Log(_L("Unexpected error code returned"));    
       
   247             iLog->Log(_L("Area Search result read from file:"));
       
   248             
       
   249             aSearchResults[i]->Print(info);
       
   250             iLog->Log(info);
       
   251 
       
   252             _LIT(KReturned, "Search returned errorCode = %d");
       
   253             info.Format(KReturned, err);
       
   254             iLog->Log(info);
       
   255             User::Leave(KErrGeneral);
       
   256             }
       
   257             
       
   258         if (!err)
       
   259             {
       
   260             CPosLmOperation* operation = 
       
   261                 iLmMultiSearch->StartLandmarkSearchL(*areaCriteria, aSearchResults[i]->Redefined());
       
   262             CleanupStack::PushL(operation);
       
   263              switch (aExecutionMode)
       
   264                 {
       
   265                 case ESynchronous:
       
   266                     ExecuteAndDeleteLD(operation);
       
   267                     CleanupStack::Pop(operation);
       
   268                     break;
       
   269                 case EAsynchronous:
       
   270                     RunAsyncOperationLD(operation);
       
   271                     CleanupStack::Pop(operation);
       
   272                     break;
       
   273                 case EWaitForRequest:
       
   274                     RunAsyncOperationByWaitForReqL(operation);
       
   275                     CleanupStack::PopAndDestroy(operation);                
       
   276                     break;
       
   277                 }
       
   278 
       
   279             // Check database array
       
   280             CheckDatabasesL(iDbArray);
       
   281 
       
   282             // Check for errors        
       
   283             AssertTrueSecL(iLmMultiSearch->NumOfSearchErrors() == 0, 
       
   284                 _L("Error(s) found during multi search."));
       
   285 
       
   286             // Check total number of matches       
       
   287             if ((TUint)(aSearchResults[i]->SearchResult()).Count() != 
       
   288                 iLmMultiSearch->TotalNumOfMatches())
       
   289                 {
       
   290                 _LIT(KExpected, "Expected no. of matches: %d");
       
   291                 _LIT(KReturned, "Returned no. of matches: %d");
       
   292                 TBuf<100> info;
       
   293                 info.Format(KExpected, (aSearchResults[i]->SearchResult()).Count());
       
   294                 iLog->Log(info);
       
   295                 info.Format(KReturned, iLmMultiSearch->TotalNumOfMatches());
       
   296                 iLog->Log(info);
       
   297                
       
   298                 iLog->Log(KNumOfMatchesErr);
       
   299                 User::Leave(-1);
       
   300                 }
       
   301 
       
   302             RArray<TPosLmItemId> lmids;
       
   303             CleanupClosePushL(lmids);
       
   304 
       
   305             for (TInt j=0; j<iLmMultiSearch->NumOfDatabasesToSearch(); j++) 
       
   306                 {
       
   307                 CPosLmItemIterator* iter = iLmMultiSearch->MatchIteratorL(j);
       
   308                 // Check if there are any matches = iteration exists.
       
   309                 if (iter) 
       
   310                     {
       
   311                     CleanupStack::PushL(iter);
       
   312                     TPosLmItemId id = iter->NextL();    
       
   313                     while (id != KPosLmNullItemId)
       
   314                         {
       
   315                         // Check that found id is expected
       
   316                         AssertTrueSecL(aSearchResults[i]->FindSearchResult(id), KNotFoundErr);
       
   317                         User::LeaveIfError(lmids.Append(id));                              
       
   318                         id = iter->NextL();
       
   319                         }
       
   320                     CleanupStack::PopAndDestroy(iter);                
       
   321                     }
       
   322                 else 
       
   323                     {
       
   324                     _LIT(KIterNull, "MatchIterator returned null for a db");
       
   325                     iLog->Log(KIterNull);
       
   326                     }
       
   327                 }
       
   328 
       
   329             AssertTrueSecL(aSearchResults[i]->SearchResult().Count() == lmids.Count(), 
       
   330                 _L("Expected number of hits and found hits don't match"));
       
   331 
       
   332             for (TInt k=0; k<lmids.Count(); k++)
       
   333                 {
       
   334                 // Check that found id is expected from all ids
       
   335                 AssertTrueSecL(aSearchResults[i]->FindSearchResult(lmids[k]), KNotFoundErr);
       
   336                 }
       
   337 
       
   338             CleanupStack::PopAndDestroy(&lmids); // lmids
       
   339             }
       
   340             
       
   341         CleanupStack::PopAndDestroy(areaCriteria);
       
   342 
       
   343         _LIT(KSearchNr, "Multi search test index #%d executed ok.");
       
   344         TBuf<100> buf;
       
   345         buf.Format(KSearchNr, i);        
       
   346         iLog->Log(buf);
       
   347         }
       
   348     }
       
   349 
       
   350 // ---------------------------------------------------------
       
   351 // CPosTp120::SearchWithSortOrderL
       
   352 //
       
   353 // (other items were commented in a header).
       
   354 // ---------------------------------------------------------
       
   355 //
       
   356 void CPosTp120::SearchWithSortOrderL(const RPointerArray<CAreaSearchResult>& aSearchResults)
       
   357     {
       
   358     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed syncronously");
       
   359    
       
   360     TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);  
       
   361  
       
   362     for (TInt j=0; j<aSearchResults.Count(); j++)
       
   363         {   
       
   364         CPosLmAreaCriteria* areaCriteria = NULL;
       
   365         TRAPD(err, areaCriteria = AreaCriteriaL(
       
   366                     iAreaSearchResults[j]->SouthLat(),
       
   367                     iAreaSearchResults[j]->NorthLat(),
       
   368                     iAreaSearchResults[j]->WestLong(),
       
   369                     iAreaSearchResults[j]->EastLong()));
       
   370         
       
   371         CleanupStack::PushL(areaCriteria);
       
   372         
       
   373         if (err != KErrNone)
       
   374             {
       
   375             CleanupStack::PopAndDestroy(areaCriteria);
       
   376             continue;
       
   377             }
       
   378             
       
   379                
       
   380         // 5 and 6 is using WaitForRequest
       
   381         for (TInt i=0; i<4; i++)
       
   382             {
       
   383             switch (i)
       
   384                 {
       
   385                 //**** sync
       
   386                 case 0:
       
   387                     ExecuteAndDeleteLD(iLmMultiSearch->StartLandmarkSearchL(
       
   388                         *areaCriteria, 
       
   389                         sortPref, 
       
   390                         aSearchResults[j]->Redefined()));
       
   391                     break;
       
   392                 case 1:
       
   393                     sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending);
       
   394                     ExecuteAndDeleteLD(iLmMultiSearch->StartLandmarkSearchL(
       
   395                         *areaCriteria, 
       
   396                         sortPref, 
       
   397                         aSearchResults[j]->Redefined()));
       
   398                     break;
       
   399                 case 2:
       
   400                 //**** async
       
   401                     RunAsyncOperationLD(iLmMultiSearch->StartLandmarkSearchL(
       
   402                         *areaCriteria, 
       
   403                         sortPref, 
       
   404                         aSearchResults[j]->Redefined()));
       
   405                     break;
       
   406                 case 3:
       
   407                     sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   408                     RunAsyncOperationLD(iLmMultiSearch->StartLandmarkSearchL(
       
   409                         *areaCriteria, 
       
   410                         sortPref, 
       
   411                         aSearchResults[j]->Redefined()));
       
   412                     break;
       
   413                 //**** asych with User::WaitForRequest()
       
   414                 case 4:
       
   415                     {
       
   416                     CPosLmOperation* op = iLmMultiSearch->StartLandmarkSearchL(
       
   417                         *areaCriteria, 
       
   418                         sortPref, 
       
   419                         aSearchResults[j]->Redefined());
       
   420                     CleanupStack::PushL(op);
       
   421                     RunAsyncOperationByWaitForReqL(op);
       
   422                     CleanupStack::PopAndDestroy(op);
       
   423                     }
       
   424                     break;
       
   425                 case 5:
       
   426                     {
       
   427                     sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   428                     CPosLmOperation* op = iLmMultiSearch->StartLandmarkSearchL(
       
   429                         *areaCriteria, 
       
   430                         sortPref, 
       
   431                         aSearchResults[j]->Redefined());
       
   432                     CleanupStack::PushL(op);
       
   433                     RunAsyncOperationByWaitForReqL(op);
       
   434                     CleanupStack::PopAndDestroy(op);
       
   435                     }
       
   436                     break;
       
   437                 }
       
   438             }
       
   439            
       
   440         // Check database array
       
   441         CheckDatabasesL(iDbArray);
       
   442 
       
   443         // Check for errors        
       
   444         AssertTrueSecL(iLmMultiSearch->NumOfSearchErrors() == 0, 
       
   445             _L("Error(s) found during multi search."));
       
   446 
       
   447         // Check total number of matches       
       
   448         if ((TUint)(aSearchResults[j]->SearchResult()).Count() != 
       
   449             iLmMultiSearch->TotalNumOfMatches())
       
   450             {
       
   451             _LIT(KExpected, "Expected no. of matches: %d");
       
   452             _LIT(KReturned, "Returned no. of matches: %d");
       
   453             TBuf<100> info;
       
   454             info.Format(KExpected, (aSearchResults[j]->SearchResult()).Count());
       
   455             iLog->Log(info);
       
   456             info.Format(KReturned, iLmMultiSearch->TotalNumOfMatches());
       
   457             iLog->Log(info);
       
   458             
       
   459             iLog->Log(KNumOfMatchesErr);
       
   460             User::Leave(-1);
       
   461             }
       
   462         
       
   463         RArray<TPosLmItemId>* searchResults = &aSearchResults[j]->SearchResult();        
       
   464         for (TInt n=0; n<iLmMultiSearch->NumOfDatabasesToSearch(); n++) 
       
   465             {
       
   466             RArray<TPosLmItemId> lmids;
       
   467             CleanupClosePushL(lmids);
       
   468             GetLmIdsL(n, *searchResults, lmids);            
       
   469 
       
   470             iDatabase = CPosLandmarkDatabase::OpenL(iLmMultiSearch->DatabaseUriPtr(n));
       
   471             if (iDatabase->IsInitializingNeeded())
       
   472            {
       
   473            ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   474            }
       
   475 
       
   476             LandmarksSortL(lmids, sortPref);
       
   477         
       
   478             CPosLmItemIterator* iter = iLmMultiSearch->MatchIteratorL(n);
       
   479             // Check if there are any matches = iteration exists.
       
   480             if (iter) 
       
   481                 {
       
   482                 CleanupStack::PushL(iter);
       
   483                 TInt lmid = 0;
       
   484                 TPosLmItemId id = iter->NextL();
       
   485         
       
   486                 while (id != KPosLmNullItemId)
       
   487                     {
       
   488                     CheckEqualsLmsL(id, lmids[lmid]);
       
   489                     
       
   490                     id = iter->NextL();
       
   491                     ++lmid;
       
   492                     }
       
   493                 CleanupStack::PopAndDestroy(iter);
       
   494                 }
       
   495             else 
       
   496                 {
       
   497                 _LIT(KIterNull, "MatchIterator returned null for a db");
       
   498                 iLog->Log(KIterNull);
       
   499                 }
       
   500                 
       
   501             delete iDatabase;
       
   502             iDatabase = NULL;
       
   503             
       
   504             CleanupStack::PopAndDestroy(&lmids);
       
   505             }
       
   506                    
       
   507         CleanupStack::PopAndDestroy(areaCriteria);
       
   508         
       
   509         _LIT(KSearchNr, "Multi search test index #%d executed ok.");
       
   510         TBuf<100> buf;
       
   511         buf.Format(KSearchNr, j);        
       
   512         iLog->Log(buf);
       
   513         }
       
   514     }
       
   515 
       
   516 // ---------------------------------------------------------
       
   517 // CPosTp120::OnTheFlySearchL
       
   518 //
       
   519 // (other items were commented in a header).
       
   520 // ---------------------------------------------------------
       
   521 //
       
   522 void CPosTp120::OnTheFlySearchL()
       
   523     {
       
   524     const TInt KTestIndex = 4;
       
   525 
       
   526    _LIT(KTestNr, "Multi search test, using test index %d.");
       
   527     TBuf<100> buf;
       
   528     buf.Format(KTestNr, KTestIndex);
       
   529     iLog->Log(buf);
       
   530 
       
   531            
       
   532     CPosLmAreaCriteria* areaCriteria = CPosLmAreaCriteria::NewLC(
       
   533                     iAreaSearchResults[KTestIndex]->SouthLat(),
       
   534                     iAreaSearchResults[KTestIndex]->NorthLat(),
       
   535                     iAreaSearchResults[KTestIndex]->WestLong(),
       
   536                     iAreaSearchResults[KTestIndex]->EastLong());
       
   537                         
       
   538     COnTheFlyTester* onTheFlyTester = COnTheFlyTester::NewLC();
       
   539     onTheFlyTester->StartSearchCampaignL(iLmMultiSearch, 
       
   540         iAreaSearchResults[KTestIndex]->SearchResult(), 
       
   541         areaCriteria);
       
   542 
       
   543     TInt result = onTheFlyTester->Err();
       
   544     if (result != KErrNone)
       
   545         {
       
   546         TPtrC msg;
       
   547         onTheFlyTester->GetErrMsg(msg);
       
   548         iLog->Log(msg);
       
   549         User::Leave(result);
       
   550         }
       
   551         
       
   552     CleanupStack::PopAndDestroy(2, areaCriteria);
       
   553     
       
   554     iLmMultiSearch->UnsetDisplayData();
       
   555     }
       
   556 
       
   557 // ---------------------------------------------------------
       
   558 // CPosTp120::SearchAndDeleteL
       
   559 //
       
   560 // (other items were commented in a header).
       
   561 // ---------------------------------------------------------
       
   562 //
       
   563 void CPosTp120::SearchAndDeleteL()
       
   564     {
       
   565     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when a redefined search is performed"); 
       
   566     const TInt KTestIndex = 4;
       
   567     
       
   568    _LIT(KTestNr, "Multi search test, using test index %d.");
       
   569     TBuf<100> buf;
       
   570     buf.Format(KTestNr, KTestIndex);
       
   571     iLog->Log(buf);
       
   572 
       
   573     TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   574     
       
   575     CPosLmAreaCriteria* areaCriteria=CPosLmAreaCriteria::NewLC(
       
   576                     iAreaSearchResults[KTestIndex]->SouthLat(),
       
   577                     iAreaSearchResults[KTestIndex]->NorthLat(),
       
   578                     iAreaSearchResults[KTestIndex]->WestLong(),
       
   579                     iAreaSearchResults[KTestIndex]->EastLong());
       
   580         
       
   581     // Search #1
       
   582     ExecuteAndDeleteLD(iLmMultiSearch->StartLandmarkSearchL(*areaCriteria, sortPref));
       
   583     
       
   584     RArray<TPosLmItemId>* searchResults = &iAreaSearchResults[KTestIndex]->SearchResult();
       
   585 
       
   586     // Check for errors        
       
   587     AssertTrueSecL(iLmMultiSearch->NumOfSearchErrors() == 0, 
       
   588         _L("Error(s) found during multi search."));
       
   589 
       
   590     AssertTrueSecL((TUint)searchResults->Count() == iLmMultiSearch->TotalNumOfMatches(), 
       
   591         KNumOfMatchesErr);    
       
   592     
       
   593     TPosLmItemId lmid = (*searchResults)[0];
       
   594     iDatabase = CPosLandmarkDatabase::OpenL();   
       
   595     if (iDatabase->IsInitializingNeeded())
       
   596    {
       
   597    ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   598    }
       
   599 
       
   600     iDatabase->RemoveLandmarkL(lmid); 
       
   601     searchResults->Remove(0);
       
   602     searchResults->Compress();
       
   603     delete iDatabase;
       
   604     iDatabase = NULL;
       
   605 
       
   606     // Search #2
       
   607     ExecuteAndDeleteLD(iLmMultiSearch->StartLandmarkSearchL(*areaCriteria, sortPref, ETrue));
       
   608 
       
   609     // Check result
       
   610     // Check database array
       
   611     CheckDatabasesL(iDbArray);
       
   612 
       
   613     // Check for errors        
       
   614     AssertTrueSecL(iLmMultiSearch->NumOfSearchErrors() == 0, 
       
   615         _L("Error(s) found during multi search."));
       
   616 
       
   617     AssertTrueSecL((TUint)searchResults->Count() == iLmMultiSearch->TotalNumOfMatches(), 
       
   618         KNumOfMatchesErr);    
       
   619 
       
   620     RArray<TPosLmItemId> lmids;
       
   621     CleanupClosePushL(lmids);
       
   622     _LIT(KNotFoundErr, "Id %d not found in parsed Lm search results");
       
   623 
       
   624     for (TInt j=0; j<iLmMultiSearch->NumOfDatabasesToSearch(); j++) 
       
   625         {
       
   626         CPosLmItemIterator* iter = iLmMultiSearch->MatchIteratorL(j);
       
   627         // Check if there are any matches = iteration exists.
       
   628         if (iter) 
       
   629             {
       
   630             CleanupStack::PushL(iter);
       
   631             TPosLmItemId id = iter->NextL();    
       
   632             while (id != KPosLmNullItemId)
       
   633                 {
       
   634                 // Check that found id is expected
       
   635                 AssertTrueSecL(iAreaSearchResults[KTestIndex]->FindSearchResult(id), KNotFoundErr);
       
   636                 User::LeaveIfError(lmids.Append(id));                              
       
   637                 id = iter->NextL();
       
   638                 }
       
   639             CleanupStack::PopAndDestroy(iter);                
       
   640             }
       
   641         else 
       
   642             {
       
   643             _LIT(KIterNull, "MatchIterator returned null for a db");
       
   644             iLog->Log(KIterNull);
       
   645             }
       
   646         }
       
   647 
       
   648     AssertTrueSecL(iAreaSearchResults[KTestIndex]->SearchResult().Count() == lmids.Count(), 
       
   649         _L("Expected number of hits and found hits don't match"));
       
   650 
       
   651     for (TInt k=0; k<lmids.Count(); k++)
       
   652         {
       
   653         // Check that found id is expected from all ids
       
   654         AssertTrueSecL(iAreaSearchResults[KTestIndex]->FindSearchResult(lmids[k]), KNotFoundErr);
       
   655         }
       
   656 
       
   657     CleanupStack::PopAndDestroy(&lmids); // lmids
       
   658 
       
   659     CleanupStack::PopAndDestroy(areaCriteria);
       
   660 
       
   661     // Prepare for another search with different criteria
       
   662     TInt otherTestIndex = KTestIndex + 1;
       
   663 
       
   664     buf.Format(KTestNr, otherTestIndex);
       
   665     iLog->Log(buf);
       
   666     
       
   667     areaCriteria = CPosLmAreaCriteria::NewLC(
       
   668                     iAreaSearchResults[otherTestIndex]->SouthLat(),
       
   669                     iAreaSearchResults[otherTestIndex]->NorthLat(),
       
   670                     iAreaSearchResults[otherTestIndex]->WestLong(),
       
   671                     iAreaSearchResults[otherTestIndex]->EastLong());
       
   672 
       
   673     // Search #3
       
   674     ExecuteAndDeleteLD(iLmMultiSearch->StartLandmarkSearchL(*areaCriteria, sortPref, ETrue));
       
   675 
       
   676     // Check result
       
   677     // Check database array
       
   678     CheckDatabasesL(iDbArray);
       
   679 
       
   680     // Check for errors        
       
   681     AssertTrueSecL(iLmMultiSearch->NumOfSearchErrors() == 0, 
       
   682         _L("Error(s) found during multi search."));
       
   683 
       
   684     AssertTrueSecL(iLmMultiSearch->TotalNumOfMatches() != searchResults->Count(), 
       
   685         KNumOfMatchesErr);    
       
   686 
       
   687     AssertTrueSecL(iLmMultiSearch->TotalNumOfMatches() == 0, KNumOfMatchesErr);    
       
   688 
       
   689     CleanupStack::PopAndDestroy(areaCriteria);
       
   690     }
       
   691 
       
   692 // ---------------------------------------------------------
       
   693 // CPosTp120::SearchAndRenameL
       
   694 //
       
   695 // (other items were commented in a header).
       
   696 // ---------------------------------------------------------
       
   697 //
       
   698 void CPosTp120::SearchAndRenameL()
       
   699     {
       
   700     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when a redefined search is performed"); 
       
   701     const TInt KTestIndex = 4;
       
   702 
       
   703     _LIT(KTestNr, "Multi search test, using test index %d.");
       
   704     TBuf<100> buf;
       
   705     buf.Format(KTestNr, KTestIndex);
       
   706     iLog->Log(buf);
       
   707 
       
   708     TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   709     
       
   710     CPosLmAreaCriteria* areaCriteria = CPosLmAreaCriteria::NewLC(
       
   711                     iAreaSearchResults[KTestIndex]->SouthLat(),
       
   712                     iAreaSearchResults[KTestIndex]->NorthLat(),
       
   713                     iAreaSearchResults[KTestIndex]->WestLong(),
       
   714                     iAreaSearchResults[KTestIndex]->EastLong());
       
   715 
       
   716     ExecuteAndDeleteLD(iLmMultiSearch->StartLandmarkSearchL(*areaCriteria, sortPref));
       
   717     
       
   718     RArray<TPosLmItemId>* searchResults = &iAreaSearchResults[KTestIndex]->SearchResult();
       
   719     
       
   720     _LIT(KNotFoundErr, "Id %d not found in parsed Lm search results");
       
   721     _LIT(KLmName, "LmTP120");
       
   722    
       
   723     for (TInt j=0; j<iLmMultiSearch->NumOfDatabasesToSearch(); j++) 
       
   724         {
       
   725         CPosLmItemIterator* iter = iLmMultiSearch->MatchIteratorL(j);
       
   726         iDatabase = 
       
   727             CPosLandmarkDatabase::OpenL(iLmMultiSearch->DatabaseUriPtr(j));
       
   728         if (iDatabase->IsInitializingNeeded())
       
   729        {
       
   730        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   731        }
       
   732 
       
   733             
       
   734         // Check if there are any matches = iteration exists.
       
   735         if (iter)
       
   736             {
       
   737             CleanupStack::PushL(iter);
       
   738             TPosLmItemId id = iter->NextL();    
       
   739             while (id != KPosLmNullItemId)
       
   740                 {
       
   741                 // Check that found id is expected
       
   742                 AssertTrueSecL(iAreaSearchResults[KTestIndex]->FindSearchResult(id), 
       
   743                     KNotFoundErr);
       
   744               
       
   745                 CPosLandmark* lm = iDatabase->ReadLandmarkLC(id);
       
   746         
       
   747                 TBuf<30> lmName;
       
   748                 lmName = KLmName;
       
   749                 lm->SetLandmarkNameL(lmName);
       
   750                 iDatabase->UpdateLandmarkL(*lm);
       
   751                 CleanupStack::PopAndDestroy(lm);   
       
   752                                 
       
   753                 id = iter->NextL();
       
   754                 }
       
   755             CleanupStack::PopAndDestroy(iter);                
       
   756             }
       
   757         else 
       
   758             {
       
   759             _LIT(KIterNull, "MatchIterator returned null for a db");
       
   760             iLog->Log(KIterNull);
       
   761             }
       
   762             
       
   763         delete iDatabase;
       
   764         iDatabase = NULL;
       
   765         }
       
   766     
       
   767     ExecuteAndDeleteLD(iLmMultiSearch->StartLandmarkSearchL(*areaCriteria, sortPref, ETrue));
       
   768     
       
   769     // Check database array
       
   770     CheckDatabasesL(iDbArray);
       
   771 
       
   772     // Check for errors        
       
   773     AssertTrueSecL(iLmMultiSearch->NumOfSearchErrors() == 0, 
       
   774         _L("Error(s) found during multi search."));
       
   775         
       
   776     AssertTrueSecL((TUint) searchResults->Count() == 
       
   777         iLmMultiSearch->TotalNumOfMatches(), KNumOfMatchesErr);
       
   778 
       
   779     for (TInt j=0; j<iLmMultiSearch->NumOfDatabasesToSearch(); j++) 
       
   780         {
       
   781         iDatabase = 
       
   782             CPosLandmarkDatabase::OpenL(iLmMultiSearch->DatabaseUriPtr(j));
       
   783         if (iDatabase->IsInitializingNeeded())
       
   784        {
       
   785        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   786        }
       
   787 
       
   788         CPosLmItemIterator* iter = iLmMultiSearch->MatchIteratorL(j);
       
   789             
       
   790         // Check if there are any matches = iteration exists.
       
   791         if (iter)
       
   792             {
       
   793             CleanupStack::PushL(iter);
       
   794             TPosLmItemId id = iter->NextL();    
       
   795             while (id != KPosLmNullItemId)
       
   796                 {
       
   797                 // Check that found id is expected
       
   798                 AssertTrueSecL(iAreaSearchResults[KTestIndex]->FindSearchResult(id), 
       
   799                     KNotFoundErr);
       
   800    
       
   801                 CPosLandmark* lm = iDatabase->ReadLandmarkLC(id);
       
   802         
       
   803                 TPtrC16 lmName;
       
   804                 lm->GetLandmarkName(lmName);
       
   805                 AssertTrueSecL(!lmName.CompareC(KLmName), _L("Wrong landmark name"));
       
   806                 
       
   807                 CleanupStack::PopAndDestroy(lm);   
       
   808                  
       
   809                 id = iter->NextL();
       
   810                 }
       
   811             CleanupStack::PopAndDestroy(iter);                
       
   812             }
       
   813         else 
       
   814             {
       
   815             _LIT(KIterNull, "MatchIterator returned null for a db");
       
   816             iLog->Log(KIterNull);
       
   817             }   
       
   818             
       
   819         delete iDatabase;
       
   820         iDatabase = NULL;
       
   821         }
       
   822 
       
   823     CleanupStack::PopAndDestroy(areaCriteria);   
       
   824     }
       
   825 
       
   826 // ---------------------------------------------------------
       
   827 // CPosTp120::SearchAndCancelL
       
   828 //
       
   829 // (other items were commented in a header).
       
   830 // ---------------------------------------------------------
       
   831 //
       
   832 void CPosTp120::SearchAndCancelL(const TBool& aInCallback)
       
   833     {
       
   834     // Test search with one criteria
       
   835     const TInt KTestIndex = 0;
       
   836 
       
   837     _LIT(KTestNr, "Multi search test, using test index %d.");
       
   838     TBuf<100> buf;
       
   839     buf.Format(KTestNr, KTestIndex);
       
   840     iLog->Log(buf);
       
   841 
       
   842     CPosLmAreaCriteria* areaCriteria = CPosLmAreaCriteria::NewLC(
       
   843                     iAreaSearchResults[KTestIndex]->SouthLat(),
       
   844                     iAreaSearchResults[KTestIndex]->NorthLat(),
       
   845                     iAreaSearchResults[KTestIndex]->WestLong(),
       
   846                     iAreaSearchResults[KTestIndex]->EastLong());
       
   847     
       
   848     if (aInCallback)
       
   849         {
       
   850         TReal threshold = 3;
       
   851         for (TReal i=0; i<100; i+=10) 
       
   852             {
       
   853             threshold = i/100;
       
   854             RunAsyncOperationAndCancelInCallbackLD(iLmMultiSearch->StartLandmarkSearchL(
       
   855                 *areaCriteria, iAreaSearchResults[KTestIndex]->Redefined()), threshold);
       
   856 
       
   857             _LIT(KCancelNr, "Multi search test, cancel after progress %f, canceled ok.");
       
   858             TBuf<100> buf;
       
   859             buf.Format(KCancelNr, threshold);
       
   860             iLog->Log(buf);
       
   861             }
       
   862         }
       
   863     else
       
   864         {
       
   865         RunAsyncOperationAndCancelLD(iLmMultiSearch->StartLandmarkSearchL(
       
   866                 *areaCriteria, iAreaSearchResults[KTestIndex]->Redefined()));
       
   867         }
       
   868 
       
   869     CleanupStack::PopAndDestroy(areaCriteria);       
       
   870     }
       
   871 
       
   872 // ---------------------------------------------------------
       
   873 // CPosTp120::SearchWithMaximumL
       
   874 //
       
   875 // (other items were commented in a header).
       
   876 // ---------------------------------------------------------
       
   877 //
       
   878 void CPosTp120::SearchWithMaximumL()
       
   879     {
       
   880     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when SearchWithMaximumL is performed");
       
   881 
       
   882     // Test search with one criteria
       
   883     const TInt KTestIndex = 8;
       
   884     
       
   885     _LIT(KTestNr, "Multi search test, using test index %d.");
       
   886     TBuf<100> buf;
       
   887     buf.Format(KTestNr, KTestIndex);
       
   888     iLog->Log(buf);
       
   889 
       
   890     CPosLmAreaCriteria* areaCriteria = CPosLmAreaCriteria::NewLC(
       
   891                     iAreaSearchResults[KTestIndex]->SouthLat(),
       
   892                     iAreaSearchResults[KTestIndex]->NorthLat(),
       
   893                     iAreaSearchResults[KTestIndex]->WestLong(),
       
   894                     iAreaSearchResults[KTestIndex]->EastLong());
       
   895    
       
   896     TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending);
       
   897 
       
   898     // First get the maximum number of matches
       
   899     TInt maxMatches = KNrOfDbs;  
       
   900     iLmMultiSearch->SetMaxNumOfMatches(maxMatches);
       
   901     _LIT(KErrNrOfMatches, "Number of matches is incorrect");
       
   902     AssertTrueSecL(iLmMultiSearch->MaxNumOfMatches() == maxMatches, KErrNrOfMatches);
       
   903     
       
   904     ExecuteAndDeleteLD(iLmMultiSearch->StartLandmarkSearchL(*areaCriteria, sortPref)); 
       
   905 
       
   906     AssertTrueSecL(iLmMultiSearch->MaxNumOfMatches() == maxMatches, KErrNrOfMatches);
       
   907     RArray<TPosLmItemId>* searchResults = &iAreaSearchResults[KTestIndex]->SearchResult();    
       
   908     TInt totalMatches = iLmMultiSearch->TotalNumOfMatches();
       
   909     
       
   910     // Check database array
       
   911     CheckDatabasesL(iDbArray, maxMatches);
       
   912     // Check for errors        
       
   913     AssertTrueSecL(iLmMultiSearch->NumOfSearchErrors() == 0, 
       
   914         _L("Error(s) found during multi search."));
       
   915     // Check that nr is not expected number of results
       
   916     AssertTrueSecL((TUint) searchResults->Count() != 
       
   917         totalMatches, KNumOfMatchesErr);    
       
   918 
       
   919     for (TInt n=0; n<iLmMultiSearch->NumOfDatabasesToSearch(); n++) 
       
   920         {
       
   921         RArray<TPosLmItemId> lmids;
       
   922         CleanupClosePushL(lmids);
       
   923         GetLmIdsL(n, *searchResults, lmids);            
       
   924     
       
   925         iDatabase = CPosLandmarkDatabase::OpenL(iLmMultiSearch->DatabaseUriPtr(n));
       
   926         if (iDatabase->IsInitializingNeeded())
       
   927        {
       
   928        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   929        }
       
   930 
       
   931         LandmarksSortL(lmids, sortPref);
       
   932     
       
   933         CPosLmItemIterator* iter = iLmMultiSearch->MatchIteratorL(n);
       
   934         // Check if there are any matches = iteration exists.
       
   935         if (iter) 
       
   936             {
       
   937             CleanupStack::PushL(iter);
       
   938             AssertTrueSecL(iter->NumOfItemsL() == iLmMultiSearch->NumOfMatches(n), 
       
   939                 KNumOfMatchesErr);
       
   940     
       
   941             TInt lmid = 0;
       
   942             TPosLmItemId id = iter->NextL();
       
   943     
       
   944             while (id != KPosLmNullItemId)
       
   945                 {
       
   946                 CheckEqualsLmsL(id, lmids[lmid]);
       
   947                 
       
   948                 id = iter->NextL();
       
   949                 ++lmid;
       
   950                 }
       
   951             CleanupStack::PopAndDestroy(iter);
       
   952             }
       
   953         else 
       
   954             {
       
   955             _LIT(KIterNull, "MatchIterator returned null for a db");
       
   956             iLog->Log(KIterNull);
       
   957             }
       
   958             
       
   959         delete iDatabase;
       
   960         iDatabase = NULL;
       
   961         
       
   962         CleanupStack::PopAndDestroy(&lmids);
       
   963         }
       
   964 
       
   965     // Test max matches again
       
   966     TInt incMatches = 2;
       
   967     maxMatches = maxMatches + incMatches;  
       
   968     iLmMultiSearch->SetMaxNumOfMatches(maxMatches);
       
   969     AssertTrueSecL(iLmMultiSearch->MaxNumOfMatches() == maxMatches, KErrNrOfMatches);
       
   970     
       
   971     ExecuteAndDeleteLD(iLmMultiSearch->StartLandmarkSearchL(*areaCriteria)); 
       
   972 
       
   973     AssertTrueSecL(iLmMultiSearch->MaxNumOfMatches() == maxMatches, KErrNrOfMatches);
       
   974     TInt reTotalMatches = iLmMultiSearch->TotalNumOfMatches();
       
   975     
       
   976     AssertTrueSecL(reTotalMatches != totalMatches, 
       
   977         _L("Total number of matches should not be that same."));
       
   978     
       
   979     // Check database array
       
   980     CheckDatabasesL(iDbArray, maxMatches);
       
   981     // Check for errors        
       
   982     AssertTrueSecL(iLmMultiSearch->NumOfSearchErrors() == 0, 
       
   983         _L("Error(s) found during multi search."));
       
   984     // Check that nr is not expected number of results
       
   985     AssertTrueSecL((TUint) searchResults->Count() != 
       
   986         reTotalMatches, KNumOfMatchesErr); 
       
   987 
       
   988     CleanupStack::PopAndDestroy(areaCriteria);
       
   989 
       
   990     // Unset max number of matches to normal/unlimited again
       
   991     iLmMultiSearch->SetMaxNumOfMatches();
       
   992     }
       
   993 
       
   994 // ---------------------------------------------------------
       
   995 // CPosTp120::CreateDatabasesL
       
   996 //
       
   997 // (other items were commented in a header).
       
   998 // ---------------------------------------------------------
       
   999 //
       
  1000 CDesCArray* CPosTp120::CreateDatabasesL(TInt aNrOfLmDbs, TInt aLmPerDb, 
       
  1001     TInt aLastId, TBool aDebug)
       
  1002     {
       
  1003     
       
  1004     CDesCArray* iDbArray = new (ELeave) CDesCArrayFlat(aNrOfLmDbs); 
       
  1005     CleanupStack::PushL(iDbArray);     
       
  1006          
       
  1007     RemoveDefaultDbL();
       
  1008     
       
  1009     // Populate default db
       
  1010     iDatabase = UseGeneratedDbFileL();
       
  1011     if (iDatabase->IsInitializingNeeded())
       
  1012        {
       
  1013        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
  1014        }
       
  1015     delete iDatabase;
       
  1016     iDatabase = NULL;  
       
  1017       
       
  1018     CFileMan* fileMan = CFileMan::NewL(iFileSession);
       
  1019     CleanupStack::PushL(fileMan);
       
  1020 
       
  1021     // Create databases
       
  1022     TInt i=0;
       
  1023     for (i=1; i < aNrOfLmDbs; i++)
       
  1024         {
       
  1025         TBuf<100> db;
       
  1026         db.Format(KDbNamePath, i * aLmPerDb);
       
  1027         
       
  1028         iFileSession.Delete(db);
       
  1029         User::LeaveIfError(fileMan->Copy(KLmFullDefaultDbPath, db, CFileMan::EOverWrite));    
       
  1030         }
       
  1031     CleanupStack::PopAndDestroy(fileMan);               
       
  1032 
       
  1033     for (TInt db=0; db < aNrOfLmDbs; db++)
       
  1034         {
       
  1035         TInt dbform = db;
       
  1036         if (db == aNrOfLmDbs)
       
  1037             {
       
  1038             dbform = aNrOfLmDbs - 1;
       
  1039             }
       
  1040             
       
  1041         CPosLandmarkDatabase* lmd = NULL;
       
  1042         TBuf<100> name;
       
  1043         if (db == 0)
       
  1044             {
       
  1045             _LIT(KDefLmDb, "eposlm.ldb");
       
  1046             name = KDefLmDb;
       
  1047             lmd = CPosLandmarkDatabase::OpenL();
       
  1048             if (lmd->IsInitializingNeeded())
       
  1049            {
       
  1050            ExecuteAndDeleteLD(lmd->InitializeL());
       
  1051            }
       
  1052 
       
  1053             }
       
  1054         else 
       
  1055             {
       
  1056             name.Format(KDbName, dbform * aLmPerDb);        
       
  1057             lmd = CPosLandmarkDatabase::OpenL(name);
       
  1058             if (lmd->IsInitializingNeeded())
       
  1059            {
       
  1060            ExecuteAndDeleteLD(lmd->InitializeL());
       
  1061            }
       
  1062 
       
  1063             }
       
  1064         CleanupStack::PushL(lmd);
       
  1065         // Append db name to array
       
  1066         iDbArray->AppendL(name);
       
  1067 
       
  1068         if (aDebug)
       
  1069             {
       
  1070             iLog->Log(name);
       
  1071             }
       
  1072         
       
  1073         TInt startItemid = dbform * aLmPerDb + 1;
       
  1074         TInt stopItemid = dbform * aLmPerDb + aLmPerDb;            
       
  1075         if (dbform == aNrOfLmDbs - 1)
       
  1076             {
       
  1077             stopItemid = aLastId;
       
  1078             }
       
  1079         
       
  1080         for (TInt lmid=1; lmid <= aLastId; lmid++) 
       
  1081             {
       
  1082             TBuf<100> lmidbuf;
       
  1083                 
       
  1084             if (aDebug)
       
  1085                 {
       
  1086                 _LIT(KLmId, "Landmark with LmId: %d");
       
  1087                 lmidbuf.Format(KLmId, lmid);
       
  1088                 iLog->Log(lmidbuf);                                
       
  1089                 }
       
  1090 
       
  1091             if (lmid < startItemid || lmid > stopItemid)
       
  1092                 {
       
  1093                 if (aDebug)
       
  1094                     {
       
  1095                     _LIT(KDelLmId, "Removing LmId: %d");
       
  1096                     lmidbuf.Format(KDelLmId, lmid);
       
  1097                     iLog->Log(lmidbuf);                                
       
  1098                     }
       
  1099                 
       
  1100                 TInt err = KErrLocked;
       
  1101                 while (err == KErrLocked)
       
  1102                     {
       
  1103                     TRAP(err, lmd->RemoveLandmarkL(lmid));
       
  1104                     }
       
  1105                 }
       
  1106             }
       
  1107 
       
  1108         // Compact database
       
  1109         ExecuteAndDeleteLD(lmd->CompactL());
       
  1110         CleanupStack::PopAndDestroy(lmd);  
       
  1111         }
       
  1112         
       
  1113     // Log/print landmark databases.
       
  1114     if (aDebug)
       
  1115         {
       
  1116         // DEBUG 
       
  1117         for (i=0; i < aNrOfLmDbs; i++)
       
  1118             {
       
  1119             TBuf<100> dbNo;
       
  1120             dbNo.Format(_L(" -------- Printing Db %d --------------"), i);
       
  1121             iLog->Log(dbNo);
       
  1122                 
       
  1123             CPosLandmarkDatabase* lmd = NULL;
       
  1124             if (i == 0) 
       
  1125                 {
       
  1126                 _LIT(KDbDefName, "Default Lm DB");
       
  1127                 iLog->Log(KDbDefName);
       
  1128                 lmd = CPosLandmarkDatabase::OpenL();
       
  1129                 if (lmd->IsInitializingNeeded())
       
  1130                {
       
  1131                ExecuteAndDeleteLD(lmd->InitializeL());
       
  1132                }
       
  1133 
       
  1134                 }
       
  1135             else 
       
  1136                 {            
       
  1137                 TInt dbform = i;
       
  1138                 if (i == 5)
       
  1139                     {
       
  1140                     dbform = 4;
       
  1141                     }
       
  1142                     
       
  1143                 TBuf<100> db;
       
  1144                 db.Format(KDbName, dbform * aLmPerDb);
       
  1145                 iLog->Log(db);
       
  1146                 
       
  1147                 lmd = CPosLandmarkDatabase::OpenL(db);  
       
  1148                 if (lmd->IsInitializingNeeded())
       
  1149                {
       
  1150                ExecuteAndDeleteLD(lmd->InitializeL());
       
  1151                }
       
  1152 
       
  1153                 }
       
  1154             CleanupStack::PushL(lmd);
       
  1155             CPosLmCategoryManager* lmcat = CPosLmCategoryManager::NewL(*lmd);
       
  1156             CleanupStack::PushL(lmcat);
       
  1157             
       
  1158             CPosLmItemIterator* iter = lmd->LandmarkIteratorL();
       
  1159             CleanupStack::PushL(iter);
       
  1160 
       
  1161             _LIT(KNrLms, "Nr of Lms: %d");
       
  1162             TBuf<20> lms;
       
  1163             lms.Format(KNrLms, iter->NumOfItemsL());
       
  1164             iLog->Log(lms);
       
  1165            
       
  1166             TPosLmItemId id = iter->NextL(); 
       
  1167             while (id != KPosLmNullItemId)
       
  1168                 {
       
  1169                 CPosLandmark* lm = lmd->ReadLandmarkLC(id);
       
  1170             
       
  1171                 TBuf<255> info;
       
  1172                 PrintLandmark(*lm, info);
       
  1173                 iLog->Log(info);
       
  1174                 CleanupStack::PopAndDestroy(lm); 
       
  1175                 
       
  1176                 id = iter->NextL();
       
  1177                 }    
       
  1178 
       
  1179             CleanupStack::PopAndDestroy(iter);
       
  1180 
       
  1181             CPosLmItemIterator* catiter = lmcat->CategoryIteratorL();
       
  1182             CleanupStack::PushL(catiter);
       
  1183 
       
  1184             _LIT(KNrLmCats, "Nr of Lm Cats: %d");
       
  1185             TBuf<20> lmcats;
       
  1186             lmcats.Format(KNrLmCats, catiter->NumOfItemsL());
       
  1187             iLog->Log(lmcats);
       
  1188            
       
  1189             id = catiter->NextL(); 
       
  1190             while (id != KPosLmNullItemId)
       
  1191                 {
       
  1192                 CPosLandmarkCategory* cat = lmcat->ReadCategoryLC(id);
       
  1193             
       
  1194                 TBuf<255> info;
       
  1195                 // PrintLandmark(*lm, info);
       
  1196                 _LIT(KCatId, "Category id: %d");
       
  1197                 _LIT(KCatGlobalId, "Global Category id: %d");
       
  1198                 _LIT(KCatName, "Category name: %S");
       
  1199                 
       
  1200                 info.Format(KCatId, cat->CategoryId());                
       
  1201                 iLog->Log(info);
       
  1202                 
       
  1203                 info.Format(KCatGlobalId, cat->GlobalCategory());                
       
  1204                 iLog->Log(info);
       
  1205                 
       
  1206                 TPtrC catname;
       
  1207                 TInt err = cat->GetCategoryName(catname);
       
  1208                 info.Format(KCatName, &catname);                
       
  1209                 iLog->Log(info);
       
  1210                 
       
  1211                 CleanupStack::PopAndDestroy(cat); 
       
  1212                 
       
  1213                 id = catiter->NextL();
       
  1214                 }    
       
  1215            
       
  1216            
       
  1217             CleanupStack::PopAndDestroy(3, lmd); // catiter, lmcat
       
  1218             }        
       
  1219         }
       
  1220         
       
  1221     CleanupStack::Pop(iDbArray);
       
  1222     return iDbArray;
       
  1223     }
       
  1224 
       
  1225 //  End of File