landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp21.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 <EPos_CPosLandmarkDatabase.h>
       
    22 #include <EPos_CPosLandmarkSearch.h> 
       
    23 #include <EPos_CPosLmCategoryCriteria.h>
       
    24 #include <EPos_CPosLMItemIterator.h>    
       
    25 
       
    26 #include "FT_CPosTp21.h"
       
    27 #include "FT_CCategoryLandmarkSearchResult.h"
       
    28 #include <EPos_CPosLmCatNameCriteria.h>
       
    29 
       
    30 //CONSTANTS
       
    31 const TInt KNoCategoriesTp21  = 40;
       
    32 const TInt KNoLandmarksTp21 = 40; 
       
    33 
       
    34 // ================= MEMBER FUNCTIONS =======================
       
    35 
       
    36 // ---------------------------------------------------------
       
    37 // CPosTp29::CloseTest
       
    38 //
       
    39 // (other items were commented in a header).
       
    40 // ---------------------------------------------------------
       
    41 //
       
    42 void CPosTp21::CloseTest()
       
    43     {       
       
    44     iCategories.ResetAndDestroy();
       
    45     iCategories.Close();        
       
    46     iReferencedCategories.Close();    
       
    47     iLandmarks.ResetAndDestroy();
       
    48     iLandmarks.Close();         
       
    49     
       
    50     delete iCategoryManager; 
       
    51     iCategoryManager = NULL;  
       
    52     delete iLandmarkSearch;
       
    53     iLandmarkSearch = NULL;    
       
    54     delete iDatabase;
       
    55     iDatabase = NULL;    
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // CPosTp21::StartL
       
    60 //
       
    61 // (other items were commented in a header).
       
    62 // ---------------------------------------------------------
       
    63 //
       
    64 void CPosTp21::StartL()
       
    65     {        
       
    66     
       
    67     iLog->Log(_L("***Testing CPosLandmarkSearch:: ( LM Search Category Criteria) *** "));
       
    68     
       
    69     iDatabase = CPosLandmarkDatabase::OpenL();  
       
    70         
       
    71     if (iDatabase->IsInitializingNeeded())
       
    72        {
       
    73        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
    74        }   
       
    75        
       
    76     iCategoryManager = CPosLmCategoryManager::NewL(*iDatabase);    
       
    77     iLog->Log(_L("Default database initialized"));
       
    78     
       
    79     
       
    80     // Remove all the categories and landmarks from database to make it empty
       
    81     MakeEmptyLmDatabaseL( *iDatabase, *iCategoryManager);    
       
    82     
       
    83     // Add some landmarks to db
       
    84     // Add some categories to db
       
    85     // Add categories to lms in the database    
       
    86     AddCategoriesL();
       
    87     AddLandmarksL();    
       
    88     
       
    89     iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase);
       
    90     
       
    91     // Test some leave codes
       
    92     iLog->Log(_L("Check that StartLandmarkSearchL leaves with correct codes "));
       
    93     SearchWithSortOrderL();   
       
    94   
       
    95 	// Search synchronously
       
    96     iLog->Log(_L("Testing search with criterias read from LmDbSearchResult.txt syncronously, \
       
    97 using CategoryName"));
       
    98 
       
    99     SearchL(iCategoryLandmarkSearchResults, ETrue);
       
   100  
       
   101     iLog->Log(_L("Testing search with criterias read from LmDbSearchResult.txt syncronously, \
       
   102 using CategoryId"));
       
   103     SearchL(iCategoryLandmarkSearchResults);
       
   104 
       
   105     iLog->Log(_L("Searching fon nonexisting entries synchronously"));
       
   106     SearchNonExistingL(ESynchronous);    
       
   107 
       
   108 	// Search asynchronously
       
   109     iLog->Log(_L("Testing search with criterias read from LmDbSearchResult.txt asynchronously, \
       
   110 using CategoryName"));
       
   111     SearchL(iCategoryLandmarkSearchResults, ETrue, EAsynchronous);
       
   112 
       
   113     iLog->Log(_L("Testing search with criterias read from LmDbSearchResult.txt asynchronously, \
       
   114 using Categoryid"));
       
   115     SearchL(iCategoryLandmarkSearchResults, EFalse, EAsynchronous);
       
   116 
       
   117     iLog->Log(_L("Searching for nonexisting entries asynchronously"));
       
   118     SearchNonExistingL(EAsynchronous);   
       
   119 
       
   120 	// Search asynchronously using User::WaitForRequest()
       
   121     iLog->Log(_L("Testing search with criterias read from LmDbSearchResult.txt asynchronously, \
       
   122 with User::WaitForRequest() using CategoryName"));
       
   123     SearchL(iCategoryLandmarkSearchResults, ETrue, EWaitForRequest);
       
   124 
       
   125     iLog->Log(_L("Testing search with criterias read from LmDbSearchResult.txt asynchronously, \
       
   126 with User::WaitForRequest() using Categoryid"));
       
   127     SearchL(iCategoryLandmarkSearchResults, EFalse, EWaitForRequest);
       
   128 
       
   129     iLog->Log(_L("Searching for nonexisting entries asynchronously"));
       
   130     SearchNonExistingL(EWaitForRequest);
       
   131 
       
   132 
       
   133 	// Test cancel
       
   134     iLog->Log(_L("Search and cancels the search"));
       
   135     SearchAndCancelL();
       
   136 
       
   137     iLog->Log(_L("Search and cancels the search in a callback"));
       
   138     SearchAndCancelL(ETrue);
       
   139 
       
   140 	// Search in global categories
       
   141     iLog->Log(_L("SearchForLandmarksInGlobalCategoriesL asynchronously"));
       
   142     SearchForLandmarksInGlobalCategoriesL(EAsynchronous);
       
   143 
       
   144     iLog->Log(_L("SearchForLandmarksInGlobalCategoriesL synchronously"));
       
   145     SearchForLandmarksInGlobalCategoriesL(ESynchronous);
       
   146     
       
   147     iLog->Log(_L("SearchForLandmarksInGlobalCategoriesL synchronously"));
       
   148     SearchForLandmarksInGlobalCategoriesL(EWaitForRequest);   
       
   149    
       
   150     iLog->Log(_L("Check maximum length of search pattern"));
       
   151     TestSearchPatternLengthL();
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------
       
   155 // CPosTp21::SearchL
       
   156 //
       
   157 // (other items were commented in a header).
       
   158 // ---------------------------------------------------------
       
   159 // 
       
   160 void CPosTp21::SearchL(
       
   161     const RPointerArray<CCategoryLandmarkSearchResult>& /* aSearchResults */, 
       
   162     TBool aNameOrId, 
       
   163     TExecutionMode aExecutionMode)
       
   164     {
       
   165     /*
       
   166      * Positive test cases 
       
   167      * Test for referenced category search
       
   168      */
       
   169          
       
   170     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed");
       
   171 
       
   172     //Test SetMaxNumOfMatches, first set to one and then back to unlimited
       
   173     iLandmarkSearch->SetMaxNumOfMatches(1);
       
   174     iLandmarkSearch->SetMaxNumOfMatches();    
       
   175         
       
   176     TPtrC refCatName;
       
   177     TPosLmItemId refCatId(0);
       
   178     
       
   179     for ( TInt i = 0; i < iReferencedCategories.Count(); i++ )    
       
   180         {
       
   181         CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC();
       
   182         // Perform search with either name or id
       
   183         if (aNameOrId)
       
   184             {
       
   185             // Set cearch criteria based on category name             
       
   186             TInt retErr = iReferencedCategories[i]->GetCategoryName( refCatName );
       
   187             if ( retErr == KErrNone)
       
   188                 {
       
   189                 catSearchCriteria->SetCategoryNameL( refCatName );
       
   190                 //iLog->Log( refCatName );
       
   191                 }   
       
   192             }            
       
   193         else
       
   194             {
       
   195             refCatId = iReferencedCategories[i]->CategoryId();
       
   196             catSearchCriteria->SetCategoryItemId( refCatId );
       
   197             }   
       
   198                     
       
   199         //aSearchOnlyPreviousMatches is set to false by default    
       
   200         iOperation = iLandmarkSearch->StartLandmarkSearchL( *catSearchCriteria );         
       
   201 
       
   202         switch (aExecutionMode)
       
   203             {
       
   204             case ESynchronous:
       
   205                 ExecuteAndDeleteLD(iOperation);
       
   206                 break;
       
   207             case EAsynchronous:
       
   208                 RunAsyncOperationLD(iOperation);
       
   209                 break;
       
   210             case EWaitForRequest:
       
   211                 RunAsyncOperationByWaitForReqL(iOperation);
       
   212                 delete iOperation;
       
   213             break;
       
   214             }
       
   215 
       
   216         CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   217         CleanupStack::PushL(iter);
       
   218         
       
   219         /* iter->NumOfItems() contains the number of items that are contained in this search 
       
   220          *  iteration
       
   221          */  
       
   222 
       
   223         TPosLmItemId id = iter->NextL(); // First item from the search results
       
   224 
       
   225         if ( iLandmarkSearch->NumOfMatches() != iter->NumOfItemsL() )
       
   226             {
       
   227             _LIT(KExpected, "Expected no. of matches: %d");
       
   228             _LIT(KReturned, "Returned no. of matches: %d");
       
   229             TBuf<100> info;
       
   230             info.Format( KExpected, iter->NumOfItemsL() );
       
   231             iLog->Log( info );
       
   232             info.Format( KReturned, iLandmarkSearch->NumOfMatches() );
       
   233             iLog->Log(info);                        
       
   234             iLog->Log(KNumOfMatchesErr);            
       
   235             CleanupStack::PopAndDestroy( 2 ); // Iter,catSearchCriteria                
       
   236             User::Leave(-1);
       
   237             }
       
   238             
       
   239         CleanupStack::PopAndDestroy( iter );
       
   240             
       
   241         // Test by setting Max num of matches and also set aSearchOnlyPreviousMatches to true        
       
   242         
       
   243         iLandmarkSearch->SetMaxNumOfMatches(1);
       
   244 
       
   245         if ( aNameOrId )
       
   246             {            
       
   247             refCatId = iReferencedCategories[i]->CategoryId();
       
   248             catSearchCriteria->SetCategoryItemId( refCatId );
       
   249             }            
       
   250         else
       
   251             {
       
   252             // Set cearch criteria based on category name             
       
   253             TInt retErr = iReferencedCategories[i]->GetCategoryName( refCatName );
       
   254             if ( retErr == KErrNone)
       
   255                 {
       
   256                 catSearchCriteria->SetCategoryNameL( refCatName );
       
   257                 //iLog->Log( refCatName );
       
   258                 }                
       
   259             } 
       
   260         iOperation = iLandmarkSearch->StartLandmarkSearchL(*catSearchCriteria, ETrue);
       
   261         switch (aExecutionMode)
       
   262             {
       
   263             case ESynchronous:
       
   264                 ExecuteAndDeleteLD(iOperation);
       
   265                 break;
       
   266             case EAsynchronous:
       
   267                 RunAsyncOperationLD(iOperation);
       
   268                 break;
       
   269             case EWaitForRequest:
       
   270                 RunAsyncOperationByWaitForReqL(iOperation);
       
   271                 delete iOperation;
       
   272             break;
       
   273             }
       
   274             
       
   275         iter = iLandmarkSearch->MatchIteratorL();
       
   276         CleanupStack::PushL(iter);
       
   277         id = iter->NextL();
       
   278 
       
   279         if (iLandmarkSearch->NumOfMatches() != 1)
       
   280             {
       
   281             _LIT(KExpected, "Expected no. of matches: %d");
       
   282             _LIT(KReturned, "Returned no. of matches: %d");
       
   283             TBuf<100> info;
       
   284             info.Format(KExpected, 1);
       
   285             iLog->Log(info);
       
   286             info.Format(KReturned, iLandmarkSearch->NumOfMatches());
       
   287             iLog->Log(info);
       
   288             iLog->Log(_L("Search criteria: "));
       
   289             iLog->Log(catSearchCriteria->CategoryName());            
       
   290             iLog->Log(KNumOfMatchesErr);
       
   291             CleanupStack::PopAndDestroy( 2 ); // Iter,catSearchCriteria                
       
   292             User::Leave(-1);
       
   293             }   
       
   294     
       
   295         // Set back to unlimited
       
   296         iLandmarkSearch->SetMaxNumOfMatches();     
       
   297         CleanupStack::PopAndDestroy( 2 ); // Iter,catSearchCriteria                           
       
   298         }                 
       
   299     }
       
   300     
       
   301 // ---------------------------------------------------------
       
   302 // CPosTp21::SearchForLandmarksInGlobalCategoriesL
       
   303 //
       
   304 // (other items were commented in a header).
       
   305 // ---------------------------------------------------------
       
   306 //
       
   307 void CPosTp21::SearchForLandmarksInGlobalCategoriesL(
       
   308     TExecutionMode aExecutionMode)
       
   309     {        
       
   310     iLog->Log(_L("SearchForGlobalCategoriesL"));
       
   311     TBuf<150> buf; // Buffer used for log messages
       
   312     buf.Zero(); 
       
   313     
       
   314     /*  
       
   315      *Default db is open in the beginning of the test procedure anyway
       
   316      *Use it for global categories related testing
       
   317      */      
       
   318     
       
   319     delete iLandmarkSearch;
       
   320     iLandmarkSearch = NULL;
       
   321     
       
   322     iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase);
       
   323 
       
   324     // Using default database with global cateegories initialized    
       
   325     // Add some more landmarks
       
   326     AddLandmarksToGlobalCategoriesL();     
       
   327 
       
   328     CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC();
       
   329     
       
   330     // Set the criteria for global category search     
       
   331     catSearchCriteria->SetGlobalCategory( KAccommodation );    
       
   332     if ( catSearchCriteria->GlobalCategory() == KPosLmNullGlobalCategory ) // Error in setting category search criteria
       
   333         {
       
   334         iLog->Log(_L("Error in setting Search criteria for global category search"));
       
   335         buf.Format(_L("What should be set : global cat id %d, "), KAccommodation);
       
   336         buf.Format(_L("What is set now    : global cat id %d, "), catSearchCriteria->GlobalCategory() );         
       
   337         iLog->Log( buf );
       
   338         buf.Zero();
       
   339         CleanupStack::PopAndDestroy( catSearchCriteria );
       
   340         User::Leave(-1);    
       
   341         }
       
   342                    
       
   343     iOperation = iLandmarkSearch->StartLandmarkSearchL( *catSearchCriteria );
       
   344      switch (aExecutionMode)
       
   345         {
       
   346         case ESynchronous:
       
   347             ExecuteAndDeleteLD(iOperation);
       
   348             break;
       
   349         case EAsynchronous:
       
   350             RunAsyncOperationLD(iOperation);
       
   351             break;
       
   352         case EWaitForRequest:
       
   353             RunAsyncOperationByWaitForReqL(iOperation);
       
   354             delete iOperation;
       
   355             break;
       
   356         }
       
   357             
       
   358     CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   359     CleanupStack::PushL(iter);
       
   360 
       
   361     /*
       
   362      * Verify the search result
       
   363      * iter->NumOfItems holds the total number of searched items in this iteration
       
   364      */
       
   365      
       
   366     if ( iLandmarkSearch->NumOfMatches() != iter->NumOfItemsL() )     
       
   367         {
       
   368         iLog->Log(_L("Wrong number of landmarks returned global category search (Accomodation)"));    
       
   369         buf.Format(_L("Expected : Num %d, "), iter->NumOfItemsL());
       
   370         buf.Format(_L("Found    : Num %d, "), iLandmarkSearch->NumOfMatches() );
       
   371         buf.Zero();
       
   372         CleanupStack::PopAndDestroy(iter);
       
   373         CleanupStack::PopAndDestroy(catSearchCriteria);
       
   374         User::Leave( -1 );  
       
   375         }
       
   376         
       
   377     CleanupStack::PopAndDestroy(iter);
       
   378     CleanupStack::PopAndDestroy(catSearchCriteria);   
       
   379     }
       
   380 
       
   381 // ---------------------------------------------------------
       
   382 // CPosTp21::AddLandmarksToGlobalCategoriesL
       
   383 //
       
   384 // (other items were commented in a header).
       
   385 // ---------------------------------------------------------
       
   386 //
       
   387 void CPosTp21::AddLandmarksToGlobalCategoriesL()
       
   388     {      
       
   389     iLog->Log(_L("AddLandmarksToGlobalCategoriesL"));
       
   390     ExecuteAndDeleteLD(iDatabase->CompactL());    
       
   391     CPosLandmark* lm = NULL;
       
   392     
       
   393     // Add some new landmarks to the db, associate some with global categories
       
   394     
       
   395     // lm1
       
   396     lm = CPosLandmark::NewLC();
       
   397     lm->SetLandmarkNameL(_L("LandmarkName1"));
       
   398     lm->SetLandmarkDescriptionL(_L("SomeLandmarkDescription"));    
       
   399     lm->AddCategoryL( KAccommodation );
       
   400     lm->AddCategoryL( KBusiness );
       
   401 
       
   402     TPosLmItemId id = iDatabase->AddLandmarkL(*lm);
       
   403     iRestaurantId1 = id;    
       
   404     CleanupStack::PopAndDestroy(lm);
       
   405     
       
   406     // lm2
       
   407     lm = CPosLandmark::NewLC();
       
   408     lm->SetLandmarkNameL(_L("LandmarkName2"));
       
   409     lm->SetLandmarkDescriptionL(_L("SomeLandmarkDescription2"));    
       
   410     lm->AddCategoryL(KAccommodation );
       
   411     lm->AddCategoryL( KBusiness );
       
   412     id = iDatabase->AddLandmarkL(*lm);
       
   413     CleanupStack::PopAndDestroy(lm);
       
   414        
       
   415     // lm3 
       
   416     lm = CPosLandmark::NewLC();
       
   417     lm->SetLandmarkNameL(_L("LandmarkName3"));
       
   418     lm->SetLandmarkDescriptionL(_L("SomeLandmarkDescription3"));    
       
   419     lm->AddCategoryL( KAccommodation );
       
   420     lm->AddCategoryL( KBusiness );
       
   421     lm->AddCategoryL( KEducational );
       
   422     id = iDatabase->AddLandmarkL(*lm);
       
   423     CleanupStack::PopAndDestroy(lm);
       
   424     }
       
   425 
       
   426 // ---------------------------------------------------------
       
   427 // CPosTp21::SearchNonExistingL
       
   428 //
       
   429 // (other items were commented in a header).
       
   430 // ---------------------------------------------------------
       
   431 //
       
   432 void CPosTp21::SearchNonExistingL(TExecutionMode aExecutionMode)
       
   433     {
       
   434     iLog->Log(_L("SearchNonExistingL"));
       
   435 
       
   436     CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC();
       
   437     catSearchCriteria->SetCategoryNameL(_L("NonExistingLandmark"));
       
   438 
       
   439     iOperation = iLandmarkSearch->StartLandmarkSearchL(*catSearchCriteria);        
       
   440     switch (aExecutionMode)
       
   441         {
       
   442         case ESynchronous:
       
   443             ExecuteAndDeleteLD(iOperation);
       
   444             break;
       
   445         case EAsynchronous:
       
   446             RunAsyncOperationLD(iOperation);
       
   447             break;
       
   448         case EWaitForRequest:
       
   449             RunAsyncOperationByWaitForReqL(iOperation);
       
   450             delete iOperation;
       
   451             break;
       
   452         }
       
   453 
       
   454     CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   455     CleanupStack::PushL(iter);
       
   456             
       
   457     TPosLmItemId id = iter->NextL();
       
   458     if (id != KPosLmNullItemId)
       
   459         {
       
   460         //LogErrorAndLeave(_L("Should return KPosLmNullItemId"));
       
   461         iLog->Log(_L("Should return KPosLmNullItemId"));
       
   462         User::Leave(-1);
       
   463         }
       
   464     CleanupStack::PopAndDestroy(iter);
       
   465 
       
   466     TPosLmItemId nonExistingId = 56789; 
       
   467     catSearchCriteria->SetCategoryItemId(nonExistingId);
       
   468 
       
   469     iOperation = iLandmarkSearch->StartLandmarkSearchL(*catSearchCriteria);
       
   470     switch (aExecutionMode)
       
   471         {
       
   472         case ESynchronous:
       
   473             ExecuteAndDeleteLD(iOperation);
       
   474             break;
       
   475         case EAsynchronous:
       
   476             RunAsyncOperationLD(iOperation);
       
   477             break;
       
   478         case EWaitForRequest:
       
   479             RunAsyncOperationByWaitForReqL(iOperation);
       
   480             delete iOperation;
       
   481             break;
       
   482         }
       
   483     
       
   484     iter = iLandmarkSearch->MatchIteratorL();
       
   485     CleanupStack::PushL(iter);
       
   486             
       
   487     id = iter->NextL();
       
   488     if (id != KPosLmNullItemId)
       
   489         {
       
   490         //LogErrorAndLeave(_L("Should return KPosLmNullItemId"));
       
   491         iLog->Log(_L("Should return KPosLmNullItemId"));
       
   492         User::Leave(-1);
       
   493         }
       
   494 
       
   495     CleanupStack::PopAndDestroy(iter);
       
   496     
       
   497     //Test with invalid id as global category id
       
   498     catSearchCriteria->SetGlobalCategory((TPosLmGlobalCategory)nonExistingId);
       
   499 
       
   500     iOperation = iLandmarkSearch->StartLandmarkSearchL(*catSearchCriteria);
       
   501     ExecuteAndDeleteLD(iOperation);
       
   502     
       
   503     iter = iLandmarkSearch->MatchIteratorL();
       
   504     CleanupStack::PushL(iter);
       
   505             
       
   506     id = iter->NextL();
       
   507     if (id != KPosLmNullItemId)
       
   508         {
       
   509         //LogErrorAndLeave(_L("Should return KPosLmNullItemId"));
       
   510         iLog->Log(_L("Should return KPosLmNullItemId"));
       
   511         User::Leave(-1);
       
   512         }
       
   513 
       
   514     CleanupStack::PopAndDestroy(iter);
       
   515     CleanupStack::PopAndDestroy(catSearchCriteria);
       
   516     }
       
   517         
       
   518 // ---------------------------------------------------------
       
   519 // CPosTp21::SearchWithSortOrderL
       
   520 //
       
   521 // (other items were commented in a header).
       
   522 // ---------------------------------------------------------
       
   523 //
       
   524 void CPosTp21::SearchWithSortOrderL()
       
   525     {
       
   526     iLog->Log(_L("SearchWithSortOrderL"));
       
   527     
       
   528     TPosLmSortPref sortPref(CPosLandmark::ECategoryInfo, TPosLmSortPref::EAscending);
       
   529     CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC();
       
   530 
       
   531     // Only ECategoryName is supported,all other leave with KErrNotSupported
       
   532     TRAPD(err, iLandmarkSearch->StartLandmarkSearchL(*catSearchCriteria, sortPref));
       
   533     if (err != KErrNotSupported)     //LogErrorAndLeave(_L("Should leave with KErrNotSupported1"));
       
   534         {
       
   535         iLog->Log(_L("Should leave with KErrNotSupported1"));
       
   536         User::Leave(err);
       
   537         }
       
   538     
       
   539     // Only ECategoryName is supported,all other leave with KErrNotSupported
       
   540     catSearchCriteria->SetCategoryNameL(_L("SomeCategory"));
       
   541     TRAP(err, iLandmarkSearch->StartLandmarkSearchL(*catSearchCriteria, sortPref));
       
   542     if (err != KErrNotSupported)     //LogErrorAndLeave(_L("Should leave with KErrNotSupported2"));
       
   543         {
       
   544         iLog->Log(_L("Should leave with KErrNotSupported2"));
       
   545         User::Leave(err);	
       
   546         }
       
   547        
       
   548     // Only ECategoryName is supported,all other leave with KErrNotSupported
       
   549     sortPref.SetSortByLandmarkAttribute(CPosLandmark::EDescription, TPosLmSortPref::EDescending);
       
   550     TRAP(err, iLandmarkSearch->StartLandmarkSearchL(*catSearchCriteria, sortPref));
       
   551     if (err != KErrNotSupported)// LogErrorAndLeave(_L("Should leave with KErrNotSupported3"));
       
   552         {
       
   553         iLog->Log(_L("Should leave with KErrNotSupported3"));
       
   554         User::Leave(err);	
       
   555         }
       
   556     CleanupStack::PopAndDestroy(catSearchCriteria);
       
   557 
       
   558     // Also test with a category criteria into a landmarksearch operation
       
   559     sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending);
       
   560     CPosLmCatNameCriteria* nameCriteria = CPosLmCatNameCriteria::NewLC();
       
   561     nameCriteria->SetSearchPatternL(_L("SomeCategoryPattern"));
       
   562     TRAP(err, iLandmarkSearch->StartLandmarkSearchL(*nameCriteria, sortPref));
       
   563     if (err != KErrArgument) //LogErrorAndLeave(_L("Should leave with KErrNotSupported4"), err);
       
   564         {
       
   565         iLog->Log(_L("Should leave with KErrNotSupported4"));
       
   566         User::Leave(err);	
       
   567         }
       
   568     CleanupStack::PopAndDestroy(nameCriteria);
       
   569     }
       
   570 
       
   571 //---------------------------------------------------------
       
   572 // CPosTp21::SearchAndCancelL
       
   573 //
       
   574 // (other items were commented in a header).
       
   575 // ---------------------------------------------------------
       
   576 //
       
   577 void CPosTp21::SearchAndCancelL(const TBool& aInCallback)
       
   578     {            
       
   579     _LIT(KNumOfMatchesErr, "No. of matches is incorrect when the search is performed");
       
   580     _LIT(KCancelErr, "The search is canceled after progress has increased but no search result is found");
       
   581 
       
   582     // Test search with one criteria
       
   583     
       
   584     const TInt KIndex = 10;    // Try testing with referenced category at index 10
       
   585     TPtrC refCatName;
       
   586 
       
   587     CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC();
       
   588     
       
   589     TInt err = iReferencedCategories[KIndex]->GetCategoryName( refCatName );
       
   590     if (err == KErrNone) // Got the category name
       
   591         {
       
   592         catSearchCriteria->SetCategoryNameL( refCatName );    
       
   593         }
       
   594     else 
       
   595         {
       
   596         iLog->Log(_L("Error in setting category search criteria"));   
       
   597         CleanupStack::PopAndDestroy(); // catSearchCriteria   
       
   598         User::Leave(-1);    
       
   599         }    
       
   600     
       
   601     if (aInCallback)
       
   602         {
       
   603         RunAsyncOperationAndCancelInCallbackLD(
       
   604                          iLandmarkSearch->StartLandmarkSearchL(*catSearchCriteria));
       
   605         }
       
   606     else
       
   607         {
       
   608         RunAsyncOperationAndCancelLD( 
       
   609               iLandmarkSearch->StartLandmarkSearchL(
       
   610                                *catSearchCriteria));
       
   611         }
       
   612 
       
   613     CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   614     CleanupStack::PushL(iter);
       
   615  
       
   616     if (aInCallback)
       
   617         {
       
   618         if (iter->NumOfItemsL() != iLandmarkSearch->NumOfMatches())
       
   619             {
       
   620             iLog->Log(_L("Iterators no. of items is not equal to LandmarksSearch no. matches"));
       
   621             _LIT( KExpected, "Iter. of matches: %d" );
       
   622             _LIT( KReturned, "LandmarksSearch no. of matches: %d" );
       
   623             TBuf<100> info;
       
   624             info.Format( KExpected, iter->NumOfItemsL() );            
       
   625             info.Format( KReturned, iLandmarkSearch->NumOfMatches());
       
   626             iLog->Log( info );            
       
   627             iLog->Log( KNumOfMatchesErr  );
       
   628             CleanupStack::PopAndDestroy ( 2 );
       
   629        		User::Leave(-1);
       
   630             }
       
   631             
       
   632         TBuf<100> info2;
       
   633         _LIT(KNof, "No. of matches found before cancel = %d");
       
   634         info2.Format(KNof, iter->NumOfItemsL());
       
   635         iLog->Log(info2);
       
   636 
       
   637         AssertTrueSecL(iter->NumOfItemsL() != 0, KCancelErr);
       
   638         }
       
   639         
       
   640     CleanupStack::PopAndDestroy( 2 );// Iter, catSearchCriteria    
       
   641     
       
   642     
       
   643     
       
   644     }
       
   645 
       
   646 // ---------------------------------------------------------
       
   647 // CPosTp21::TestSearchPatternLengthL
       
   648 //
       
   649 // (other items were commented in a header).
       
   650 // ---------------------------------------------------------
       
   651 //
       
   652 void CPosTp21::TestSearchPatternLengthL()
       
   653     {
       
   654     iLog->Log(_L("TestSearchPatternLengthL"));
       
   655     
       
   656     CPosLmCategoryCriteria* catSearchCriteria = CPosLmCategoryCriteria::NewLC();
       
   657     
       
   658     //Test with maximum size of search pattern
       
   659     //KPosLmMaxCategoryNameLength is 124 (from EPos_Landmarks.h)
       
   660     HBufC* hbuf = HBufC::NewLC(KPosLmMaxCategoryNameLength+1);
       
   661     while(hbuf->Des().Length() < KPosLmMaxCategoryNameLength)
       
   662         {
       
   663         hbuf->Des().Append(_L("*"));
       
   664         }
       
   665     catSearchCriteria->SetCategoryNameL(*hbuf);
       
   666         
       
   667     hbuf->Des().Append(_L("*"));
       
   668     
       
   669     TRAPD(err, catSearchCriteria->SetCategoryNameL(*hbuf));
       
   670 
       
   671     AssertTrueSecL(err == KErrArgument, _L("It should not be possible to set search pattern"));
       
   672     CleanupStack::PopAndDestroy(hbuf);
       
   673     CleanupStack::PopAndDestroy(catSearchCriteria);
       
   674     }
       
   675 
       
   676 
       
   677 /*
       
   678  * Added for BC testing 
       
   679  */
       
   680 
       
   681     
       
   682 // ---------------------------------------------------------
       
   683 // CPosTp11::AddCategoriesL
       
   684 //
       
   685 // (other items were commented in a header).
       
   686 // ---------------------------------------------------------
       
   687 //
       
   688 void CPosTp21::AddCategoriesL()
       
   689     {
       
   690     _LIT(KName, "CategoryTP21 - %d");
       
   691     TInt err=KErrLocked;
       
   692     for (TInt i=0; i<KNoCategoriesTp21; i++)
       
   693         {
       
   694         TBuf<100> categoryName;
       
   695         categoryName.Format(KName,i);
       
   696        
       
   697         CPosLandmarkCategory* lmc = CPosLandmarkCategory::NewLC();
       
   698         lmc->SetCategoryNameL(categoryName);
       
   699         err = KErrLocked;
       
   700         while (err == KErrLocked)
       
   701             {
       
   702             TRAP(err, iCategoryManager->AddCategoryL(*lmc));
       
   703             }
       
   704     
       
   705         iCategories.Append(lmc);  
       
   706         //TPosLmItemId catId = iCategories [i]->CategoryId();     
       
   707         CleanupStack::Pop(lmc);
       
   708         }    
       
   709     }
       
   710 
       
   711 // ---------------------------------------------------------
       
   712 // CPosTp11::AddLandmarksL
       
   713 //
       
   714 // (other items were commented in a header).
       
   715 // ---------------------------------------------------------
       
   716 //
       
   717 void CPosTp21::AddLandmarksL()
       
   718     {
       
   719     _LIT(KLmName, "LmTP21 - %d");
       
   720     TInt err = KErrLocked;
       
   721     TPosLmItemId catId(0);
       
   722     for (TInt i=0; i<KNoLandmarksTp21; i++)
       
   723         {
       
   724         TBuf<100> lmName;
       
   725         lmName.Format(KLmName,i);
       
   726        
       
   727         CPosLandmark* landmark = CPosLandmark::NewLC();
       
   728         landmark->SetLandmarkNameL(lmName); 
       
   729 
       
   730         if (i % 2)
       
   731             {
       
   732             catId = iCategories[i]->CategoryId();
       
   733             landmark->AddCategoryL( catId );
       
   734             iReferencedCategories.Append(iCategories[i]);
       
   735             }
       
   736 
       
   737         err = KErrLocked;
       
   738         while (err == KErrLocked)
       
   739             {
       
   740             TRAP(err, iDatabase->AddLandmarkL(*landmark));
       
   741             }
       
   742         iLandmarks.Append(landmark);
       
   743         CleanupStack::Pop(landmark);
       
   744         }
       
   745     }
       
   746     
       
   747 // ---------------------------------------------------------
       
   748 // CPosTp21::MakeEmptyLmDatabaseL()
       
   749 // ---------------------------------------------------------
       
   750 //
       
   751 void CPosTp21::MakeEmptyLmDatabaseL( CPosLandmarkDatabase& aLdb,
       
   752                                      CPosLmCategoryManager& aCatMgr )    
       
   753     {
       
   754     CPosLmOperation* operation1 = aLdb.RemoveAllLandmarksL();
       
   755     
       
   756     //Remove all landmarks from default db : Sync call     
       
   757     ExecuteAndDeleteLD( operation1 ); 
       
   758 
       
   759     RArray<TPosLmItemId> catArray;
       
   760     CleanupClosePushL( catArray );
       
   761     
       
   762     // Get all the categories from the database and delete them if necessary 
       
   763     CPosLmItemIterator* iter = aCatMgr.CategoryIteratorL();
       
   764     CleanupStack::PushL( iter );
       
   765 
       
   766     TUint count = iter->NumOfItemsL();
       
   767     if ( count > 0 )
       
   768         { // can only be called if there are some items
       
   769         iter->GetItemIdsL( catArray, 0, count );
       
   770         }
       
   771         
       
   772     // Remove all the categories here Sync call     
       
   773     ExecuteAndDeleteLD(aCatMgr.RemoveCategoriesL( catArray ));
       
   774     
       
   775     CleanupStack::PopAndDestroy( 2 ); // catArray, iter
       
   776     }
       
   777         
       
   778     
       
   779 
       
   780 //  End of File