landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp13.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 <StifParser.h>
       
    22 #include "FT_CPosTp13.h"
       
    23 #include <epos_cposlandmarkdatabase.h>
       
    24 #include <epos_cposlmcategorymanager.h>
       
    25 #include <epos_cposlmtextcriteria.h>
       
    26 #include <epos_cposlmcategorycriteria.h>
       
    27 #include <epos_cposlandmarksearch.h>
       
    28 #include <bautils.h>
       
    29 #include "EPos_Landmarks.h"
       
    30            
       
    31 //  CONSTANTS
       
    32 _LIT(KTP13Db, "eposlm_tp13.ldb");
       
    33 
       
    34 // ================= MEMBER FUNCTIONS =======================
       
    35 
       
    36 // ---------------------------------------------------------
       
    37 // CPosTp13::CloseTest
       
    38 //
       
    39 // (other items were commented in a header).
       
    40 // ---------------------------------------------------------
       
    41 //
       
    42 void CPosTp13::CloseTest()
       
    43     {
       
    44     iLog->Log(_L("CloseTest"));
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // CPosTp13::StartL
       
    49 //
       
    50 // (other items were commented in a header).
       
    51 // ---------------------------------------------------------
       
    52 //
       
    53 void CPosTp13::StartL(CStifItemParser& /*aItem*/)
       
    54     {
       
    55     _LIT( KTransportName, "Teleport" );
       
    56     _LIT( KPeopleName, "People" );
       
    57     _LIT( KLmAName, "A" );
       
    58     _LIT( KLmBName, "B" );
       
    59     
       
    60     const TInt KTransportGlobalId = 45000;
       
    61     const TInt KPeopleGlobalId = 27000;
       
    62    
       
    63 #undef TP13_PREP
       
    64 
       
    65 #ifdef TP13_PREP    
       
    66     // Preparation code, should be executed in Finnish (non-English) locale
       
    67     // Default database should be removed so that new database is created
       
    68 
       
    69     CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL();
       
    70     CleanupStack::PushL(db);
       
    71     
       
    72     CPosLmItemIterator* iter = NULL;
       
    73     if ( db->IsInitializingNeeded() )
       
    74         {
       
    75         ExecuteAndDeleteLD( db->InitializeL() );
       
    76         }
       
    77 
       
    78     CPosLmCategoryManager* catMan = CPosLmCategoryManager::NewL( *db );
       
    79     CleanupStack::PushL( catMan );
       
    80 
       
    81     // Rename global category
       
    82     TPosLmItemId id = catMan->GetGlobalCategoryL( KTransportGlobalId ); 
       
    83     CPosLandmarkCategory* cat = catMan->ReadCategoryLC( id );
       
    84     cat->SetCategoryNameL( KTransportName );
       
    85     catMan->UpdateCategoryL( *cat );
       
    86     CleanupStack::PopAndDestroy( cat );
       
    87 
       
    88     // Create user category
       
    89     cat = CPosLandmarkCategory::NewLC();
       
    90     cat->SetCategoryNameL( KPeopleName );
       
    91     TPosLmItemId idUserPeople = catMan->AddCategoryL( *cat );
       
    92     CleanupStack::PopAndDestroy( cat );
       
    93     
       
    94     // Find matching global category
       
    95     TPosLmItemId idPeople = catMan->GetGlobalCategoryL( KPeopleGlobalId );
       
    96     
       
    97     // Create landmark for user's People category
       
    98     CPosLandmark* lmA = CPosLandmark::NewLC();
       
    99     lmA->SetLandmarkNameL( KLmAName );
       
   100     lmA->AddCategoryL( idUserPeople );
       
   101     db->AddLandmarkL( *lmA );
       
   102     CleanupStack::PopAndDestroy( lmA );
       
   103 
       
   104     // Create landmark for global People category
       
   105     CPosLandmark* lmB = CPosLandmark::NewLC();
       
   106     lmA->SetLandmarkNameL( KLmBName );
       
   107     lmA->AddCategoryL( idPeople );
       
   108     db->AddLandmarkL( *lmB );
       
   109     CleanupStack::PopAndDestroy( lmB );
       
   110 
       
   111     CleanupStack::PopAndDestroy( catMan );
       
   112     CleanupStack::PopAndDestroy( db );
       
   113     
       
   114 #else
       
   115     
       
   116     // Test code, should be executed in English locale
       
   117     
       
   118     TInt lang = User::Language();
       
   119     iLog->Log(_L("Current language is %d"), lang);
       
   120 
       
   121     if ( lang != ELangEnglish )
       
   122         { 
       
   123         iLog->Log(_L("Wrong language, should be English (1)"));
       
   124         User::Leave( KErrGeneral );
       
   125         }
       
   126     
       
   127     CopyTestDbFileL( KTP13Db );
       
   128     
       
   129     // 1. Open database
       
   130     iLog->Log(_L("1. Open database"));
       
   131 
       
   132     CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL( KTP13Db );
       
   133     CleanupStack::PushL(db);
       
   134     
       
   135     // 2. Try to use it
       
   136     iLog->Log(_L("2. Try use it"));
       
   137 
       
   138     CPosLmItemIterator* iter = NULL;
       
   139     TRAPD( err, iter = db->LandmarkIteratorL() );
       
   140     if ( err != KErrPosLmNotInitialized )
       
   141         {
       
   142         iLog->Log(_L("Unexpected error on uninitialized database"));
       
   143         iErrorsFound++;
       
   144         }
       
   145 
       
   146     // 3. Initialize database
       
   147     iLog->Log(_L("3. Init database"));
       
   148 
       
   149     if ( db->IsInitializingNeeded() )
       
   150         {
       
   151         ExecuteAndDeleteLD( db->InitializeL() );
       
   152         }
       
   153     else
       
   154         {
       
   155         iLog->Log(_L("Intialization not requried"));
       
   156         iErrorsFound++;
       
   157         }
       
   158 
       
   159     // 4. Verify names of global categories
       
   160     iLog->Log(_L("4. Verify globals"));
       
   161 
       
   162     CPosLmCategoryManager* catMan = CPosLmCategoryManager::NewL( *db );
       
   163     CleanupStack::PushL( catMan );
       
   164 
       
   165     iter = catMan->CategoryIteratorL();
       
   166     CleanupStack::PushL( iter );
       
   167 
       
   168     TPosLmItemId id = iter->NextL();
       
   169     while ( id != KPosLmNullItemId )
       
   170         {
       
   171         CPosLandmarkCategory* cat = catMan->ReadCategoryLC( id );
       
   172         TPosLmGlobalCategory globalId = cat->GlobalCategory();
       
   173         
       
   174         TPtrC name;
       
   175         cat->GetCategoryName( name );
       
   176 
       
   177         if ( globalId != KTransportGlobalId )
       
   178             {
       
   179             HBufC* globalName = catMan->GlobalCategoryNameL( globalId );
       
   180             if ( name.Compare( *globalName ) != 0 )
       
   181                 {
       
   182                 iLog->Log( _L("Global category %d name mismatch: actual '%S', predefined '%S'"),
       
   183                     globalId, &name, globalName );
       
   184                 iErrorsFound++;
       
   185                 }
       
   186             delete globalName;
       
   187             }
       
   188         else // should retain user-defiend name
       
   189             {
       
   190             if ( name.Compare( KTransportName() ) != 0 )
       
   191                 {
       
   192                 iLog->Log( _L("Global category %d name mismatch: actual '%S', user-defined '%S'"),
       
   193                     globalId, &name, &KTransportName() );
       
   194                 iErrorsFound++;
       
   195                 }
       
   196             }
       
   197         
       
   198         CleanupStack::PopAndDestroy( cat );
       
   199         id = iter->NextL();
       
   200         }
       
   201     CleanupStack::PopAndDestroy( iter );
       
   202 
       
   203     // 5. Verify user-created category People, which now matches global category
       
   204     iLog->Log(_L("5. Verify user's"));
       
   205     TPosLmItemId idPeople = catMan->GetCategoryL( KPeopleName );
       
   206     CPosLandmarkCategory* cat = catMan->ReadCategoryLC( idPeople );
       
   207     TPosLmGlobalCategory idPeopleGlobal = cat->GlobalCategory();
       
   208     if ( idPeopleGlobal != KPeopleGlobalId )
       
   209         {
       
   210         iLog->Log( _L("Global category People ID mismatch: actual '%d', predefined '%d'"),
       
   211             idPeopleGlobal, KPeopleGlobalId );
       
   212         iErrorsFound++;
       
   213         }
       
   214 
       
   215     RArray<TPosLmItemId> lmIds;
       
   216     CleanupClosePushL( lmIds );
       
   217     FindLandmarksL( *db, idPeople, lmIds );
       
   218     if ( lmIds.Count() != 2 )
       
   219         {
       
   220         iLog->Log( _L("Global category People landmark list count mismatch: actual '%d', expected '%d'"),
       
   221             lmIds.Count(), 2 );
       
   222         iErrorsFound++;
       
   223         }
       
   224     CleanupStack::PopAndDestroy( &lmIds );
       
   225 
       
   226     // verify that those landmarks belong only to People
       
   227     RArray<TPosLmItemId> catIds;
       
   228 
       
   229     CPosLandmark* lmA = FindLandmarkLC( *db, KLmAName );
       
   230     lmA->GetCategoriesL( catIds );
       
   231     if ( catIds.Count() != 1 )
       
   232         {
       
   233         iLog->Log( _L("LmA: wrong category list count, actual '%d', expected '%d'"),
       
   234             catIds.Count(), 1 );
       
   235         iErrorsFound++;
       
   236         }
       
   237     if ( catIds.Count() && catIds[0] != idPeople )
       
   238         {
       
   239         iLog->Log( _L("LmB: wrong category in list, actual '%d', expected '%d'"),
       
   240             catIds[0], idPeople );
       
   241         iErrorsFound++;
       
   242         }
       
   243     catIds.Reset();
       
   244     CleanupStack::PopAndDestroy( lmA );
       
   245 
       
   246     CPosLandmark* lmB = FindLandmarkLC( *db, KLmBName );
       
   247     lmA->GetCategoriesL( catIds );
       
   248     if ( catIds.Count() != 1 )
       
   249         {
       
   250         iLog->Log( _L("LmB: wrong category list count, actual '%d', expected '%d'"),
       
   251             catIds.Count(), 1 );
       
   252         iErrorsFound++;
       
   253         }
       
   254     if ( catIds.Count() && catIds[0] != idPeople )
       
   255         {
       
   256         iLog->Log( _L("LmB: wrong category in list, actual '%d', expected '%d'"),
       
   257             catIds[0], idPeople );
       
   258         iErrorsFound++;
       
   259         }
       
   260     catIds.Reset();
       
   261     CleanupStack::PopAndDestroy( lmB );
       
   262     CleanupStack::PopAndDestroy( cat );
       
   263     
       
   264     // 6. Reset global categories and verify again
       
   265     iLog->Log(_L("6. Reset and verify globals"));
       
   266     ExecuteAndDeleteLD(catMan->ResetGlobalCategoriesL());
       
   267     
       
   268     iter = catMan->CategoryIteratorL();
       
   269     CleanupStack::PushL( iter );
       
   270 
       
   271     id = iter->NextL();
       
   272     while ( id != KPosLmNullItemId )
       
   273         {
       
   274         CPosLandmarkCategory* cat = catMan->ReadCategoryLC( id );
       
   275         TPosLmGlobalCategory globalId = cat->GlobalCategory();
       
   276         
       
   277         TPtrC name;
       
   278         cat->GetCategoryName( name );
       
   279 
       
   280         HBufC* globalName = catMan->GlobalCategoryNameL( globalId );
       
   281         if ( name.Compare( *globalName ) != 0 )
       
   282             {
       
   283             iLog->Log( _L("Global category %d name mismatch: actual '%S', predefined '%S'"),
       
   284                 globalId, &name, globalName );
       
   285             iErrorsFound++;
       
   286             }
       
   287         delete globalName;
       
   288         CleanupStack::PopAndDestroy( cat );
       
   289         id = iter->NextL();
       
   290         }
       
   291     CleanupStack::PopAndDestroy( iter );
       
   292 
       
   293     CleanupStack::PopAndDestroy( catMan );
       
   294     CleanupStack::PopAndDestroy( db );
       
   295     
       
   296     if ( iErrorsFound > 0 )
       
   297         {
       
   298         iLog->Log(_L("Errors found in TP13 = %d"), iErrorsFound );
       
   299         User::Leave( KErrGeneral );
       
   300         }
       
   301 #endif
       
   302 	}
       
   303 
       
   304 // ---------------------------------------------------------
       
   305 // ---------------------------------------------------------
       
   306 //
       
   307 CPosLandmark* CPosTp13::FindLandmarkLC( CPosLandmarkDatabase& aDb, const TDesC& aName )
       
   308     {
       
   309     CPosLmTextCriteria* crit = CPosLmTextCriteria::NewLC();
       
   310     crit->SetTextL( aName );
       
   311     crit->SetAttributesToSearch( CPosLandmark::ELandmarkName );
       
   312     
       
   313     CPosLandmarkSearch* search = CPosLandmarkSearch::NewL( aDb );
       
   314     CleanupStack::PushL( search );
       
   315     
       
   316     CPosLmOperation* op = search->StartLandmarkSearchL( *crit );
       
   317     CleanupStack::PushL( op );
       
   318     op->ExecuteL();
       
   319     
       
   320     CPosLmItemIterator* iter = search->MatchIteratorL();
       
   321     CleanupStack::PushL( iter );
       
   322     RArray<TPosLmItemId> lmIds;
       
   323     iter->GetItemIdsL( lmIds, 0, iter->NumOfItemsL() );
       
   324     CleanupClosePushL( lmIds );
       
   325     
       
   326     if ( lmIds.Count() < 1 )
       
   327         {
       
   328         iLog->Log(_L("Couldn't find landmarks, which match name '%S'"), &aName );
       
   329         User::Leave( KErrNotFound );
       
   330         }
       
   331     else
       
   332         {
       
   333         iLog->Log(_L("Found %d landmarks, which match name '%S'"), lmIds.Count(), &aName );
       
   334         }
       
   335     
       
   336     CPosLandmark* lm = aDb.ReadLandmarkLC( lmIds[0] );
       
   337     CleanupStack::Pop();
       
   338     
       
   339     CleanupStack::PopAndDestroy( &lmIds );
       
   340     CleanupStack::PopAndDestroy( iter );
       
   341     CleanupStack::PopAndDestroy( op );
       
   342     CleanupStack::PopAndDestroy( search );
       
   343     CleanupStack::PopAndDestroy( crit );
       
   344     
       
   345     CleanupStack::PushL( lm );
       
   346     return lm;
       
   347     }
       
   348 
       
   349 // ---------------------------------------------------------
       
   350 // ---------------------------------------------------------
       
   351 //
       
   352 void CPosTp13::FindLandmarksL( 
       
   353     CPosLandmarkDatabase& aDb, 
       
   354     TPosLmItemId aCategoryId,  
       
   355     RArray<TPosLmItemId>& aLmIds )
       
   356     {
       
   357     CPosLmCategoryCriteria* crit = CPosLmCategoryCriteria::NewLC();
       
   358     crit->SetCategoryItemId( aCategoryId );
       
   359     
       
   360     CPosLandmarkSearch* search = CPosLandmarkSearch::NewL( aDb );
       
   361     CleanupStack::PushL( search );
       
   362     
       
   363     CPosLmOperation* op = search->StartLandmarkSearchL( *crit );
       
   364     CleanupStack::PushL( op );
       
   365     op->ExecuteL();
       
   366     
       
   367     CPosLmItemIterator* iter = search->MatchIteratorL();
       
   368     CleanupStack::PushL( iter );
       
   369 
       
   370     iter->GetItemIdsL( aLmIds, 0, iter->NumOfItemsL() );
       
   371 
       
   372     CleanupStack::PopAndDestroy( iter );
       
   373     CleanupStack::PopAndDestroy( op );
       
   374     CleanupStack::PopAndDestroy( search );
       
   375     CleanupStack::PopAndDestroy( crit );
       
   376     }
       
   377 
       
   378 // ---------------------------------------------------------
       
   379 // ---------------------------------------------------------
       
   380 //
       
   381 void CPosTp13::ListCategoriesL( CPosLmCategoryManager& aCatMan )
       
   382     {
       
   383     iLog->Log(_L("--- Global Categories ---"));
       
   384 
       
   385     CPosLmItemIterator* iter = aCatMan.CategoryIteratorL();
       
   386     CleanupStack::PushL(iter);
       
   387 	TBuf<50> buffe;
       
   388 
       
   389     TPosLmItemId idde = iter->NextL();
       
   390     while (idde != KPosLmNullItemId)
       
   391         {       
       
   392         CPosLandmarkCategory* cat = aCatMan.ReadCategoryLC(idde);
       
   393 
       
   394         TPtrC name;
       
   395         cat->GetCategoryName(name);
       
   396 
       
   397         TPosLmGlobalCategory globalId = cat->GlobalCategory();
       
   398 
       
   399         TPtrC iconName;
       
   400         TInt iconNr;
       
   401         TInt iconMaskIndex;
       
   402         cat->GetIcon(iconName, iconNr, iconMaskIndex);
       
   403         
       
   404         iLog->Log(_L("Category %d, globalId %d, name '%S', icon {'%S',%d,%d}"),
       
   405             cat->CategoryId(), cat->GlobalCategory(), &name, &iconName, iconNr, iconMaskIndex );
       
   406 
       
   407         CleanupStack::PopAndDestroy(cat); 
       
   408 
       
   409         idde = iter->NextL();
       
   410         }
       
   411     CleanupStack::PopAndDestroy(iter);
       
   412 
       
   413 	iLog->Log(_L("------"));
       
   414     }
       
   415 
       
   416 
       
   417 //  End of File