landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp119.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_CPosTp119.h"
       
    22 #include "FT_LandmarkConstants.h"
       
    23 #include <EPos_CPosLmMultiDbSearch.h>
       
    24 #include <EPos_CPosLmTextCriteria.h>
       
    25 #include <EPos_CPosLmDatabaseManager.h>
       
    26 #include <EPos_TPosLmSortPref.h>
       
    27 #include "badesca.h"
       
    28 
       
    29 //  CONSTANTS
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 
       
    34 // ---------------------------------------------------------
       
    35 // CPosTp119::StartL
       
    36 //
       
    37 // (other items were commented in a header).
       
    38 // ---------------------------------------------------------
       
    39 //
       
    40 void CPosTp119::StartL()
       
    41     {  
       
    42     // PrepareDatabases
       
    43     const TInt KNrOfDatabases = 5;
       
    44     RemoveAllLmDatabasesL();
       
    45     CopyTestDbFileL(KDb20);
       
    46     CopyTestDbFileL(KDb40);
       
    47     CopyTestDbFileL(KDb60);
       
    48     CopyTestDbFileL(KDb80);
       
    49     CopyTestDbFileL(KDb105);
       
    50     
       
    51     // List databases
       
    52     // TBool searchRefined = ETrue;
       
    53     CPosLmDatabaseManager* dbMan = CPosLmDatabaseManager::NewL();
       
    54     CleanupStack::PushL(dbMan);
       
    55     CDesCArray* dbUris = dbMan->ListDatabasesLC();
       
    56     CleanupStack::Pop(dbUris);
       
    57     AssertTrueSecL(dbUris->Count() == KNrOfDatabases, _L("Wrong number of test databases!"));
       
    58     CleanupStack::PopAndDestroy(dbMan);
       
    59     CleanupStack::PushL(dbUris);
       
    60     
       
    61     // 1-2. Search in all databases
       
    62     SearchAllDbsL(dbUris, ENoSort);
       
    63     
       
    64     // 3-4. Remove one of the databases and re-search
       
    65     RemoveDatabaseL(_L("c:\\private\\100012a5\\DBS_101FE978_EPOSLM_080.LDB"));
       
    66     SearchAllButOneL(dbUris);
       
    67     
       
    68     // 5-6. Restore all ofthe databases but one and re-search
       
    69     RemoveDatabaseL(_L("c:\\private\\100012a5\\DBS_101FE978_EPOSLM_105.LDB"));
       
    70     RemoveDatabaseL(_L("c:\\private\\100012a5\\DBS_101FE978_EPOSLM_040.LDB"));
       
    71     RemoveDatabaseL(_L("c:\\private\\100012a5\\DBS_101FE978_EPOSLM_020.LDB"));
       
    72     SearchOneDbL(dbUris);    
       
    73     
       
    74     // 7-8. Restore all ofthe databases and re-search
       
    75     CopyTestDbFileL(KDb20);
       
    76     CopyTestDbFileL(KDb40);
       
    77     CopyTestDbFileL(KDb80);
       
    78     CopyTestDbFileL(KDb105);
       
    79     SearchAllDbsL(dbUris, EAsc);
       
    80     
       
    81     // 9. Test SetMaxNumOfMatches
       
    82     TestMaxNrOfMatchesL(dbUris);
       
    83    
       
    84     // 10. Test MatchIteratorL
       
    85     TestMatchIteratorL(dbUris);
       
    86     
       
    87     // 11-12. Search all + one non-existing
       
    88     SearchNonExistingDbL(dbUris);
       
    89     
       
    90     // 13. Search database multiple times
       
    91     SearchDbMultipleTimesL(dbUris);
       
    92     
       
    93     // 14-15. Search all + one non-existing + one with invalid URI
       
    94     SearchInvalidURIDbL(dbUris);
       
    95     
       
    96     CleanupStack::PopAndDestroy(dbUris);
       
    97 	}
       
    98 
       
    99 // ---------------------------------------------------------
       
   100 // CPosTp119::SearchAllDbsL
       
   101 //
       
   102 // (other items were commented in a header).
       
   103 // ---------------------------------------------------------
       
   104 //
       
   105 void CPosTp119::SearchAllDbsL(CDesCArray* aDbUris, TTp119SortOrder aSortOrder)
       
   106     {
       
   107     CPosLmMultiDbSearch* multiSearcher = CPosLmMultiDbSearch::NewL(*aDbUris);
       
   108     CleanupStack::PushL(multiSearcher);
       
   109     VerifyDbsToSearchL(multiSearcher, aDbUris);
       
   110     
       
   111     TBool searchRefined = ETrue;
       
   112     SearchForLandmarksL(multiSearcher, aSortOrder, !searchRefined);
       
   113     
       
   114     // Verify Result - no errors should have occurred and all databases should return matches
       
   115     TUint searchErrors = VerifyResultL(multiSearcher, *aDbUris, aSortOrder);
       
   116     AssertTrueSecL(searchErrors == 0, _L("Found %d search errors"), searchErrors);
       
   117     for (TInt i = 0; i < aDbUris->Count(); i++)
       
   118         {
       
   119         AssertTrueSecL(multiSearcher->NumOfMatches(i) > 0, _L("Found no matches"));
       
   120         }
       
   121         
       
   122     CleanupStack::PopAndDestroy(multiSearcher);    
       
   123     }
       
   124        
       
   125 // ---------------------------------------------------------
       
   126 // CPosTp119::SearchAllButOneL
       
   127 //
       
   128 // (other items were commented in a header).
       
   129 // ---------------------------------------------------------
       
   130 //
       
   131 void CPosTp119::SearchAllButOneL(CDesCArray* aDbUris)
       
   132     {
       
   133     CPosLmMultiDbSearch* multiSearcher = CPosLmMultiDbSearch::NewL(*aDbUris);
       
   134     CleanupStack::PushL(multiSearcher);
       
   135     VerifyDbsToSearchL(multiSearcher, aDbUris);
       
   136     
       
   137     TBool searchRefined = ETrue;
       
   138     SearchForLandmarksL(multiSearcher, EAsc, !searchRefined);
       
   139     
       
   140     // Verify Result - KErrNotFound for the removed database (eposlm_80.ldb) - Matches from all but this.
       
   141     TUint searchErrors = VerifyResultL(multiSearcher, *aDbUris, EAsc);
       
   142     AssertTrueSecL(searchErrors == 1, _L("Found %d search errors"), searchErrors);
       
   143     CPosLmMultiDbSearch::TSearchError searchErr;
       
   144     multiSearcher->GetSearchError(0, searchErr);
       
   145     AssertTrueSecL(searchErr.iErrorCode == KErrNotFound, _L("Expected KErrNotFound but got %d"), searchErr.iErrorCode);
       
   146     TBuf<64> uriWithError((*aDbUris)[searchErr.iDatabaseIndex]);
       
   147     uriWithError.LowerCase();
       
   148     AssertTrueSecL(uriWithError == _L("file://c:eposlm_080.ldb"), _L("Error from wrong database"));
       
   149     for (TInt i = 0; i < aDbUris->Count(); i++)
       
   150         {
       
   151         if (i != searchErr.iDatabaseIndex)
       
   152             {
       
   153             AssertTrueSecL(multiSearcher->NumOfMatches(i) > 0, _L("Found no matches"));
       
   154             }
       
   155         }
       
   156         
       
   157     CleanupStack::PopAndDestroy(multiSearcher);
       
   158     }
       
   159     
       
   160 // ---------------------------------------------------------
       
   161 // CPosTp119::SearchOneDbL
       
   162 //
       
   163 // (other items were commented in a header).
       
   164 // ---------------------------------------------------------
       
   165 //
       
   166 void CPosTp119::SearchOneDbL(CDesCArray* aDbUris)
       
   167     {
       
   168     CPosLmMultiDbSearch* multiSearcher = CPosLmMultiDbSearch::NewL(*aDbUris);
       
   169     CleanupStack::PushL(multiSearcher);
       
   170     VerifyDbsToSearchL(multiSearcher, aDbUris);
       
   171     
       
   172     TBool searchRefined = ETrue;
       
   173     SearchForLandmarksL(multiSearcher, EAsc, !searchRefined);
       
   174     
       
   175     // Verify Result - Only matches from the one (eposlm_60.ldb) remaining. KErrNotFound from the others
       
   176     TUint searchErrors = VerifyResultL(multiSearcher, *aDbUris, EAsc);
       
   177     AssertTrueSecL(searchErrors == 4, _L("Found %d search errors"), searchErrors);
       
   178     for (TInt i = 0; i < searchErrors; i++)
       
   179         {
       
   180         CPosLmMultiDbSearch::TSearchError searchErr;
       
   181         multiSearcher->GetSearchError(i, searchErr);
       
   182         AssertTrueSecL(searchErr.iErrorCode == KErrNotFound, _L("Expected KErrNotFound but got %d"), searchErr.iErrorCode);
       
   183         TBuf<64> uriWithError((*aDbUris)[searchErr.iDatabaseIndex]);
       
   184         uriWithError.LowerCase();
       
   185         AssertTrueSecL(uriWithError != _L("file://c:eposlm_60.ldb"), _L("Eror from wong database"));
       
   186         }
       
   187         
       
   188     CleanupStack::PopAndDestroy(multiSearcher);
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------
       
   192 // CPosTp119::SearchNonExistingDbL
       
   193 //
       
   194 // (other items were commented in a header).
       
   195 // ---------------------------------------------------------
       
   196 //
       
   197 void CPosTp119::SearchNonExistingDbL(CDesCArray* aDbUris)
       
   198     {    
       
   199     CPosLmMultiDbSearch* multiSearcher = CPosLmMultiDbSearch::NewL(*aDbUris);
       
   200     CleanupStack::PushL(multiSearcher);    
       
   201     VerifyDbsToSearchL(multiSearcher, aDbUris);
       
   202   
       
   203     _LIT(KNonExistingDb, "file://pellefant.ldb");
       
   204     aDbUris->AppendL(KNonExistingDb);
       
   205     multiSearcher->SetDatabasesToSearchL(*aDbUris);
       
   206     VerifyDbsToSearchL(multiSearcher, aDbUris);
       
   207     
       
   208     TBool searchRefined = ETrue;
       
   209     SearchForLandmarksL(multiSearcher, EAsc, !searchRefined);
       
   210     
       
   211     // Verify Result - one error from the non-existing should have been returned. 
       
   212     TUint searchErrors = VerifyResultL(multiSearcher, *aDbUris, EAsc);
       
   213     AssertTrueSecL(searchErrors == 1, _L("Found %d search errors"), searchErrors);
       
   214     CPosLmMultiDbSearch::TSearchError searchErr;
       
   215     multiSearcher->GetSearchError(0, searchErr);
       
   216     AssertTrueSecL(searchErr.iErrorCode == KErrNotFound, _L("Expected KErrNotFound but got %d"), searchErr.iErrorCode);
       
   217     TBuf<64> uriWithError = (*aDbUris)[searchErr.iDatabaseIndex];
       
   218     uriWithError.LowerCase();
       
   219     AssertTrueSecL(uriWithError == KNonExistingDb, _L("Error from wrong database"));
       
   220     for (TInt i = 0; i < aDbUris->Count(); i++)
       
   221         {
       
   222         if (i != searchErr.iDatabaseIndex)
       
   223             {
       
   224             AssertTrueSecL(multiSearcher->NumOfMatches(i) > 0, _L("Found no matches"));
       
   225             }
       
   226         }
       
   227         
       
   228     CleanupStack::PopAndDestroy(multiSearcher);
       
   229     }
       
   230     
       
   231 // ---------------------------------------------------------
       
   232 // CPosTp119::SearchInvalidURIDbL
       
   233 //
       
   234 // (other items were commented in a header).
       
   235 // ---------------------------------------------------------
       
   236 //
       
   237 void CPosTp119::SearchInvalidURIDbL(CDesCArray* aDbUris)
       
   238     {
       
   239     iLog->Log(_L("SearchInvalidURIDbL"));
       
   240     CPosLmMultiDbSearch* multiSearcher = CPosLmMultiDbSearch::NewL(*aDbUris);
       
   241     CleanupStack::PushL(multiSearcher);    
       
   242     VerifyDbsToSearchL(multiSearcher, aDbUris);
       
   243   
       
   244     _LIT(KNonExistingDb, "file://pellefant.ldb");
       
   245     aDbUris->AppendL(KNonExistingDb);
       
   246     _LIT(KRemoteURI, "http://kallekanin.ldb");
       
   247     aDbUris->AppendL(KRemoteURI);
       
   248     _LIT(KInvalidDrive, "file://r:nonexistingdrive.ldb");
       
   249     aDbUris->AppendL(KInvalidDrive);
       
   250     
       
   251     multiSearcher->SetDatabasesToSearchL(*aDbUris);
       
   252     VerifyDbsToSearchL(multiSearcher, aDbUris);
       
   253     
       
   254     TBool searchRefined = ETrue;
       
   255     SearchForLandmarksL(multiSearcher, EAsc, !searchRefined);
       
   256     
       
   257     // Verify Result - three errors should be returned
       
   258     iLog->Log(_L("Verify Result - three errors should be returned"));
       
   259     TUint searchErrors = VerifyResultL(multiSearcher, *aDbUris, EAsc);
       
   260     AssertTrueSecL(searchErrors == 3, _L("Found %d search errors"), searchErrors);
       
   261     CPosLmMultiDbSearch::TSearchError searchErr;
       
   262     TInt id1;
       
   263     TInt id2;
       
   264     TInt id3;
       
   265     
       
   266     multiSearcher->GetSearchError(0, searchErr);
       
   267     AssertTrueSecL(searchErr.iErrorCode == KErrNotFound, _L("Expected KErrNotFound but got %d"), searchErr.iErrorCode);
       
   268     
       
   269     TBuf<64> uriWithError = (*aDbUris)[searchErr.iDatabaseIndex];
       
   270     uriWithError.LowerCase();
       
   271     AssertTrueSecL(uriWithError == KNonExistingDb, _L("Error from wrong database1"));
       
   272     id1 = searchErr.iDatabaseIndex;
       
   273     
       
   274     multiSearcher->GetSearchError(1, searchErr);
       
   275     AssertTrueSecL(searchErr.iErrorCode == KErrNotSupported, _L("Expected KErrNotSupported but got %d"), searchErr.iErrorCode);
       
   276     uriWithError.Zero();
       
   277     uriWithError = (*aDbUris)[searchErr.iDatabaseIndex];
       
   278     uriWithError.LowerCase();
       
   279     AssertTrueSecL(uriWithError == KRemoteURI, _L("Error from wrong database2"));
       
   280     id2 = searchErr.iDatabaseIndex;
       
   281     
       
   282     // KErrNotReady from dbs on non existing drives
       
   283     multiSearcher->GetSearchError(2, searchErr);
       
   284     AssertTrueSecL(searchErr.iErrorCode == KErrNotReady, _L("Expected KErrNotReady but got %d"), searchErr.iErrorCode);
       
   285     uriWithError.Zero();
       
   286     uriWithError = (*aDbUris)[searchErr.iDatabaseIndex];
       
   287     uriWithError.LowerCase();
       
   288     AssertTrueSecL(uriWithError == KInvalidDrive, _L("Error from wrong database3"));
       
   289     id3 = searchErr.iDatabaseIndex;
       
   290     
       
   291     for (TInt i=0; i < aDbUris->Count(); i++)
       
   292         {
       
   293         if (i != id1 && i != id2 && i != id3)
       
   294             {
       
   295             AssertTrueSecL(multiSearcher->NumOfMatches(i) > 0, _L("Found no matches"));
       
   296             }
       
   297         }
       
   298         
       
   299     CleanupStack::PopAndDestroy(multiSearcher);
       
   300     }
       
   301     
       
   302 // ---------------------------------------------------------
       
   303 // CPosTp119::SearchDbMultipleTimesL
       
   304 //
       
   305 // (other items were commented in a header).
       
   306 // ---------------------------------------------------------
       
   307 //
       
   308 void CPosTp119::SearchDbMultipleTimesL(CDesCArray* aDbUris)
       
   309     {    
       
   310     // Remove all dbs but the first
       
   311     aDbUris->Delete(1, aDbUris->Count() - 1);
       
   312     
       
   313     // 13. Repeat the same database multiple times (3 in this case)
       
   314     aDbUris->AppendL((*aDbUris)[0]);
       
   315     aDbUris->AppendL((*aDbUris)[0]);
       
   316     
       
   317     CPosLmMultiDbSearch* multiSearcher = CPosLmMultiDbSearch::NewL(*aDbUris);
       
   318     CleanupStack::PushL(multiSearcher);    
       
   319     VerifyDbsToSearchL(multiSearcher, aDbUris);
       
   320   
       
   321     TBool searchRefined = ETrue;
       
   322     SearchForLandmarksL(multiSearcher, EAsc, !searchRefined);
       
   323     
       
   324     // Verify Result - doubles should have been found 
       
   325     TUint searchErrors = VerifyResultL(multiSearcher, *aDbUris, EAsc);
       
   326     AssertTrueSecL(searchErrors == 0, _L("Found %d search errors"), searchErrors);
       
   327     for (TInt i = 0; i < aDbUris->Count(); i++)
       
   328         {
       
   329         AssertTrueSecL(multiSearcher->NumOfMatches(i) > 0, _L("Found no matches"));
       
   330         }
       
   331     for (TInt i = 0; i < aDbUris->Count(); i++)
       
   332         {
       
   333         // Log landmark names to identify doublets
       
   334         CPosLmItemIterator* iter = multiSearcher->MatchIteratorL(i);
       
   335         if (iter)
       
   336             {
       
   337             CleanupStack::PushL(iter);
       
   338             _LIT(KFormat, "Printing landmark names from db %S");
       
   339             TBuf<100> buf;
       
   340             TPtrC dbName = (*aDbUris)[i];
       
   341             buf.Format(KFormat, &dbName);
       
   342             iLog->Log(buf);
       
   343             TPosLmItemId id = iter->NextL();
       
   344             CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL((*aDbUris)[i]);
       
   345             CleanupStack::PushL(db);
       
   346             while (id != KPosLmNullItemId)
       
   347                 {
       
   348                 CPosLandmark* lm = db->ReadLandmarkLC(id);
       
   349                 TPtrC name;
       
   350                 lm->GetLandmarkName(name);
       
   351                 iLog->Log(name);
       
   352                 CleanupStack::PopAndDestroy(lm);
       
   353                 id = iter->NextL();
       
   354                 }
       
   355             CleanupStack::PopAndDestroy(2, iter);
       
   356             }
       
   357         }
       
   358         
       
   359     CleanupStack::PopAndDestroy(multiSearcher);
       
   360     } 
       
   361        
       
   362 // ---------------------------------------------------------
       
   363 // CPosTp119::TestMaxNrOfMatchesL
       
   364 //
       
   365 // (other items were commented in a header).
       
   366 // ---------------------------------------------------------
       
   367 //
       
   368 void CPosTp119::TestMaxNrOfMatchesL(CDesCArray* aDbUris)
       
   369     {
       
   370     CPosLmMultiDbSearch* multiSearcher = CPosLmMultiDbSearch::NewL(*aDbUris);
       
   371     CleanupStack::PushL(multiSearcher);
       
   372     TInt nrOfDbs = aDbUris->Count();
       
   373     TInt maxNrOfMatches = 4;
       
   374     TBool searchRefined = ETrue;
       
   375     TInt fetchedMaxNrOfMatches = multiSearcher->MaxNumOfMatches();
       
   376     AssertTrueSecL(fetchedMaxNrOfMatches == KPosLmMaxNumOfMatchesUnlimited, _L("Not unlimited number of matches by default."));
       
   377     multiSearcher->SetMaxNumOfMatches(maxNrOfMatches);
       
   378     fetchedMaxNrOfMatches = multiSearcher->MaxNumOfMatches();
       
   379     AssertTrueSecL(fetchedMaxNrOfMatches == maxNrOfMatches, _L("Unexpected maxNrOfMatches"));
       
   380     
       
   381     // Test normal flow
       
   382     SearchForLandmarksL(multiSearcher, ENoSort, !searchRefined);
       
   383     TUint searchErrors = VerifyResultL(multiSearcher, *aDbUris, ENoSort);
       
   384     AssertTrueSecL(searchErrors == 0, _L("Found %d search errors"), searchErrors);
       
   385     for (TInt i = 0; i < nrOfDbs; i++)
       
   386         {
       
   387         CPosLmItemIterator* iter = multiSearcher->MatchIteratorL(i);
       
   388         CleanupStack::PushL(iter);
       
   389         AssertTrueSecL(iter->NumOfItemsL() == maxNrOfMatches, _L("Wrong number of matches"));
       
   390         CleanupStack::PopAndDestroy(iter);
       
   391         }
       
   392     AssertTrueSecL(multiSearcher->TotalNumOfMatches() == nrOfDbs * maxNrOfMatches, _L("Wrong number of total matches"));
       
   393     
       
   394     // Test resetting of max nr of matches during search - should not affect ongoing search
       
   395     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   396     textCriteria->SetTextL(_L("*e*"));
       
   397     textCriteria->SetAttributesToSearch(CPosLandmark::ELandmarkName);
       
   398     CPosLmOperation* operation = multiSearcher->StartLandmarkSearchL(*textCriteria, searchRefined);        
       
   399     CleanupStack::PushL(operation);
       
   400     
       
   401     // Update maxNrOfMatches twice
       
   402     TInt oldMaxNrOfMatches = maxNrOfMatches;
       
   403     maxNrOfMatches--;
       
   404     multiSearcher->SetMaxNumOfMatches(maxNrOfMatches);
       
   405     maxNrOfMatches--;
       
   406     multiSearcher->SetMaxNumOfMatches(maxNrOfMatches);
       
   407     fetchedMaxNrOfMatches = multiSearcher->MaxNumOfMatches();
       
   408     AssertTrueSecL(fetchedMaxNrOfMatches == maxNrOfMatches, _L("Unexpected maxNrOfMatches"));
       
   409     
       
   410     operation->ExecuteL();
       
   411     CleanupStack::PopAndDestroy(operation);
       
   412     CleanupStack::PopAndDestroy(textCriteria);
       
   413     
       
   414     searchErrors = VerifyResultL(multiSearcher, *aDbUris, ENoSort);
       
   415     AssertTrueSecL(searchErrors == 0, _L("Found %d search errors"), searchErrors);
       
   416     for (TInt i = 0; i < nrOfDbs; i++)
       
   417         {
       
   418         CPosLmItemIterator* iter = multiSearcher->MatchIteratorL(i);
       
   419         CleanupStack::PushL(iter);
       
   420         AssertTrueSecL(iter->NumOfItemsL() == oldMaxNrOfMatches, _L("Wrong number of matches"));
       
   421         CleanupStack::PopAndDestroy(iter);
       
   422         }
       
   423     AssertTrueSecL(multiSearcher->TotalNumOfMatches() == nrOfDbs * oldMaxNrOfMatches, _L("Wrong number of total matches"));
       
   424     
       
   425     // Test new search - the new maxNrOfMatches should have effect
       
   426     SearchForLandmarksL(multiSearcher, ENoSort, !searchRefined);
       
   427     searchErrors = VerifyResultL(multiSearcher, *aDbUris, ENoSort);
       
   428     AssertTrueSecL(searchErrors == 0, _L("Found %d search errors"), searchErrors);
       
   429     fetchedMaxNrOfMatches = multiSearcher->MaxNumOfMatches();
       
   430     AssertTrueSecL(fetchedMaxNrOfMatches == maxNrOfMatches, _L("Unexpected maxNrOfMatches"));
       
   431     for (TInt i = 0; i < nrOfDbs; i++)
       
   432         {
       
   433         CPosLmItemIterator* iter = multiSearcher->MatchIteratorL(i);
       
   434         CleanupStack::PushL(iter);
       
   435         AssertTrueSecL(iter->NumOfItemsL() == maxNrOfMatches, _L("Wrong number of matches"));
       
   436         CleanupStack::PopAndDestroy(iter);
       
   437         }
       
   438     AssertTrueSecL(multiSearcher->TotalNumOfMatches() == nrOfDbs * maxNrOfMatches, _L("Wrong number of total matches"));
       
   439         
       
   440     CleanupStack::PopAndDestroy(multiSearcher);
       
   441     }
       
   442 
       
   443 // ---------------------------------------------------------
       
   444 // CPosTp119::TestMatchIteratorL
       
   445 //
       
   446 // (other items were commented in a header).
       
   447 // ---------------------------------------------------------
       
   448 //
       
   449 void CPosTp119::TestMatchIteratorL(CDesCArray* /*aDbUris*/)
       
   450     {
       
   451     // Moved to TP130
       
   452     }
       
   453     
       
   454 // ---------------------------------------------------------
       
   455 // CPosTp119::SearchForLandmarksL
       
   456 //
       
   457 // (other items were commented in a header).
       
   458 // ---------------------------------------------------------
       
   459 //
       
   460 void CPosTp119::SearchForLandmarksL(
       
   461     CPosLmMultiDbSearch* aSearcher, 
       
   462     TTp119SortOrder aSortOrder,
       
   463     TBool aRefined)
       
   464     {
       
   465     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   466     textCriteria->SetTextL(_L("*e*"));
       
   467     textCriteria->SetAttributesToSearch(CPosLandmark::ELandmarkName);
       
   468     
       
   469     CPosLmOperation* operation = NULL;
       
   470     if (aSortOrder == ENoSort)
       
   471         {
       
   472         operation = aSearcher->StartLandmarkSearchL(*textCriteria, aRefined);
       
   473         }
       
   474     else
       
   475         {
       
   476         TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   477         if (aSortOrder == EDesc)
       
   478             {
       
   479             sortPref = TPosLmSortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending);
       
   480             }
       
   481         operation = aSearcher->StartLandmarkSearchL(*textCriteria, sortPref, aRefined);
       
   482         }
       
   483         
       
   484     CleanupStack::PushL(operation);
       
   485     operation->ExecuteL();
       
   486     CleanupStack::PopAndDestroy(operation);
       
   487     CleanupStack::PopAndDestroy(textCriteria);
       
   488     }
       
   489     
       
   490 // ---------------------------------------------------------
       
   491 // CPosTp119::VerifyResultL
       
   492 //
       
   493 // (other items were commented in a header).
       
   494 // ---------------------------------------------------------
       
   495 //
       
   496 TUint CPosTp119::VerifyResultL(
       
   497     CPosLmMultiDbSearch* aSearcher, 
       
   498     CDesCArray& aDbUris,
       
   499     TTp119SortOrder aSortOrder)
       
   500     {
       
   501     TUint searchErrors = aSearcher->NumOfSearchErrors();
       
   502     for (TUint j = 0; j < searchErrors; j++)
       
   503         {
       
   504         CPosLmMultiDbSearch::TSearchError searchErr;
       
   505         aSearcher->GetSearchError(j, searchErr);
       
   506         TBuf<100> buf;
       
   507         _LIT(KFormat, "Got error code %d from database nr%d : %S");
       
   508         TPtrC uri = aDbUris[searchErr.iDatabaseIndex];
       
   509         buf.Format(KFormat, searchErr.iErrorCode,searchErr.iDatabaseIndex, &uri);
       
   510         iLog->Log(buf);
       
   511         }
       
   512         
       
   513     // Verify sort order
       
   514     if (aSortOrder != ENoSort)
       
   515         {        
       
   516         for (TInt i = 0; i < aDbUris.Count(); i++)
       
   517             {
       
   518             CPosLmItemIterator* iterator = aSearcher->MatchIteratorL(i);
       
   519             CleanupStack::PushL(iterator);
       
   520             if (iterator && iterator->NumOfItemsL() > 0)
       
   521                 {
       
   522                 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(aDbUris[i]);
       
   523                 CleanupStack::PushL(db);
       
   524                 TPosLmItemId currentId = iterator->NextL();
       
   525                 while (currentId != KPosLmNullItemId)
       
   526                     {
       
   527                     TPosLmItemId nextId = iterator->NextL();
       
   528                     if (nextId != KPosLmNullItemId)
       
   529                         {
       
   530                         CPosLandmark* currentLM = db->ReadLandmarkLC(currentId);
       
   531                         CPosLandmark* nextLM = db->ReadLandmarkLC(nextId);
       
   532                         TPtrC currentName, nextName;
       
   533                         currentLM->GetLandmarkName(currentName);
       
   534                         nextLM->GetLandmarkName(nextName);
       
   535                         TInt order = nextName.CompareC(currentName);
       
   536                         if (aSortOrder == EAsc)
       
   537                             {                        
       
   538                             AssertTrueSecL(order >= 0, _L("Wrong sort order (not ascending)"));
       
   539                             }
       
   540                         else // aSortOrder == EDesc
       
   541                             {
       
   542                             AssertTrueSecL(order <= 0, _L("Wrong sort order (not descending)"));
       
   543                             }
       
   544                         CleanupStack::PopAndDestroy(2, currentLM);
       
   545                         }
       
   546                     currentId = nextId;
       
   547                     }
       
   548                 CleanupStack::PopAndDestroy(db);
       
   549                 }
       
   550             CleanupStack::PopAndDestroy(iterator);
       
   551             }
       
   552         }
       
   553         
       
   554     return searchErrors;
       
   555     }
       
   556     
       
   557 // ---------------------------------------------------------
       
   558 // CPosTp119::RemoveDatabaseL
       
   559 //
       
   560 // (other items were commented in a header).
       
   561 // ---------------------------------------------------------
       
   562 //
       
   563 void CPosTp119::RemoveDatabaseL(const TDesC& aFile)
       
   564     {    
       
   565     RFs fileServer;
       
   566     User::LeaveIfError(fileServer.Connect());
       
   567     CleanupClosePushL(fileServer);
       
   568     CFileMan* fileMan = CFileMan::NewL(fileServer);
       
   569     CleanupStack::PushL(fileMan);
       
   570     User::LeaveIfError(fileMan->Delete(aFile));
       
   571     CleanupStack::PopAndDestroy(2, &fileServer);
       
   572     }
       
   573     
       
   574 // ---------------------------------------------------------
       
   575 // CPosTp119::VerifyDbsToSearchL
       
   576 //
       
   577 // (other items were commented in a header).
       
   578 // ---------------------------------------------------------
       
   579 //
       
   580 void CPosTp119::VerifyDbsToSearchL(
       
   581     CPosLmMultiDbSearch* aMultiSearcher, 
       
   582     CDesCArray* aDbUris)
       
   583     {
       
   584     CDesCArray* dbToSearch = aMultiSearcher->DatabasesToSearchL();
       
   585     CleanupStack::PushL(dbToSearch);
       
   586     
       
   587     // Verify that lengths of specified array and retrived array match
       
   588     AssertTrueSecL(aDbUris->Count() == dbToSearch->Count(), _L("aDbUris->Count() != dbToSearch->Count()"));
       
   589     
       
   590     // Verify that length of specified array equals retrived length
       
   591     AssertTrueSecL(aDbUris->Count() == aMultiSearcher->NumOfDatabasesToSearch(), _L("aDbUris->Count() != aMultiSearcher->NumOfDatabasesToSearch()"));
       
   592     
       
   593     for (TInt i = 0; i < aDbUris->Count(); i++)
       
   594         {
       
   595         TInt pos, pos2;
       
   596         
       
   597         // Verify that specified db can be found in retrieved list.
       
   598         TInt err = dbToSearch->Find((*aDbUris)[i], pos);
       
   599         
       
   600         // Verify that retrieved db URI can be found in specified list
       
   601         TInt err2 = aDbUris->Find(aMultiSearcher->DatabaseUriPtr(i), pos2);
       
   602         
       
   603         // Error handling
       
   604         if (err != KErrNone || err2 != KErrNone)
       
   605             {
       
   606             // No match found
       
   607             iLog->Log(_L("Didn't find expected db in db list"));
       
   608             User::Leave(err);
       
   609             }
       
   610         else
       
   611             {
       
   612             dbToSearch->Delete(pos);
       
   613             }
       
   614         }
       
   615         
       
   616     // Verify that no more db exist in search list
       
   617     AssertTrueSecL(dbToSearch->Count() == 0, _L("More dbs to search than expected"));
       
   618     
       
   619     CleanupStack::PopAndDestroy(dbToSearch);
       
   620     }
       
   621     
       
   622 //  End of File