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