landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp164.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_CPosTp164.h"
       
    23 #include <EPos_CPosLandmarkDatabase.h>
       
    24 #include <EPos_CPosLmDatabaseManager.h>
       
    25 #include <EPos_CPosLandmarkParser.h>
       
    26 
       
    27 #include <LbsPosition.h>
       
    28 #include <EPos_CPosLandmarkSearch.h>
       
    29 #include <EPos_CPosLmTextCriteria.h>
       
    30 #include <EPos_CPosLMItemIterator.h>
       
    31            
       
    32 _LIT(KTp164DbFile, "TP164Test.ldb");
       
    33 
       
    34 
       
    35 // ================= CONSTANTS =======================
       
    36 
       
    37 
       
    38 	_LIT(KKMZFile, "c:\\system\\test\\testdata\\Tp164KMZ.kmz");
       
    39 
       
    40 
       
    41 #define DEBUG ETrue
       
    42                                                     
       
    43 // ================= MEMBER FUNCTIONS =======================
       
    44 
       
    45 // ---------------------------------------------------------
       
    46 // CPosTp164::CloseTest
       
    47 //
       
    48 // (other items were commented in a header).
       
    49 // ---------------------------------------------------------
       
    50 //
       
    51 void CPosTp164::CloseTest()
       
    52     {
       
    53     iLog->Log(_L("CloseTest"));
       
    54     
       
    55     delete iLandmarkParser;
       
    56     iLandmarkParser = NULL;
       
    57     
       
    58     delete iDatabase;
       
    59     iDatabase = NULL;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------
       
    63 // CPosTp164::StartL
       
    64 //
       
    65 // (other items were commented in a header).
       
    66 // ---------------------------------------------------------
       
    67 //
       
    68 void CPosTp164::StartL()
       
    69     {
       
    70     iErrorsFound = 0;
       
    71     
       
    72       
       
    73      // KML
       
    74     TestImportEmptyDbL( KKMZFile, KKmzMimeType );
       
    75     TestImport1L( KKMZFile, KKmzMimeType );
       
    76 
       
    77     if (iErrorsFound != KErrNone)
       
    78         {
       
    79         iLog->Log(_L("Errors found in TP164"));
       
    80         User::Leave(-1);
       
    81         }
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------
       
    85 // CPosTp164::TestImportEmptyDbL
       
    86 //
       
    87 // (other items were commented in a header).
       
    88 // ---------------------------------------------------------
       
    89 //
       
    90 void CPosTp164::TestImportEmptyDbL(const TDesC& aFile, const TDesC8& aMime)
       
    91     {
       
    92     iLog->Log(_L("----- TestImportEmptyDbL -----"));
       
    93     iLog->Log(_L("FILE: %S"), &aFile);
       
    94     RemoveAllLmDatabasesL();
       
    95     CopyTestDbFileL(KTp164DbFile);
       
    96     iLandmarkParser = CPosLandmarkParser::NewL(aMime);
       
    97     iLandmarkParser->SetInputFileL(aFile);
       
    98     
       
    99     iDatabase = CPosLandmarkDatabase::OpenL(KTp164DbFile);
       
   100     if (iDatabase->IsInitializingNeeded())
       
   101         {
       
   102         ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   103         }
       
   104         
       
   105     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   106     CleanupStack::PushL(categoryManager);
       
   107     
       
   108     CPosLmItemIterator* catIter = categoryManager->CategoryIteratorL();
       
   109     CleanupStack::PushL(catIter);
       
   110     TInt nrOfcategoriesBefore = catIter->NumOfItemsL();
       
   111     CleanupStack::PopAndDestroy(catIter);
       
   112     
       
   113     iLog->Log(_L("iDatabase->ImportLandmarksL"));
       
   114     // No categories should be imported, since ESupressCategoryCreation is used and the landmarks
       
   115     // db is empty when starting
       
   116     ExecuteAndDeleteLD(iDatabase->ImportLandmarksL(*iLandmarkParser, CPosLandmarkDatabase::ESupressCategoryCreation| CPosLandmarkDatabase::EIncludeCategories));
       
   117 
       
   118     catIter = categoryManager->CategoryIteratorL();
       
   119     CleanupStack::PushL(catIter);
       
   120     TInt nrOfcategoriesAfter = catIter->NumOfItemsL();
       
   121     CleanupStack::PopAndDestroy(catIter);
       
   122     
       
   123     CleanupStack::PopAndDestroy(categoryManager);
       
   124     
       
   125     delete iLandmarkParser;
       
   126     iLandmarkParser = NULL;
       
   127     
       
   128     delete iDatabase;
       
   129     iDatabase = NULL;
       
   130     
       
   131     if (nrOfcategoriesAfter != nrOfcategoriesBefore)
       
   132     	{
       
   133     	iLog->Log(_L("ERROR: No categories should have been imported"));
       
   134         iErrorsFound++;
       
   135     	}
       
   136     iLog->Log(_L("-------------------\n"));
       
   137     }
       
   138     
       
   139 // ---------------------------------------------------------
       
   140 // CPosTp164::TestImport1L
       
   141 //
       
   142 // (other items were commented in a header).
       
   143 // ---------------------------------------------------------
       
   144 //
       
   145 void CPosTp164::TestImport1L(const TDesC& aFile, const TDesC8& aMime)
       
   146     {
       
   147     iLog->Log(_L("----- TestImport1L ------"));
       
   148     iLog->Log(_L("FILE: %S"), &aFile);
       
   149     RemoveAllLmDatabasesL();
       
   150     CopyTestDbFileL(KTp164DbFile);
       
   151     iLandmarkParser = CPosLandmarkParser::NewL(aMime);
       
   152     iLandmarkParser->SetInputFileL(aFile);
       
   153     
       
   154     TRAPD( err,iDatabase = CPosLandmarkDatabase::OpenL(KTp164DbFile));
       
   155     iLog->Log(_L("Error after CPosLandmarkDatabase::OpenL = %d"),err);
       
   156    
       
   157     if (iDatabase->IsInitializingNeeded())
       
   158         {
       
   159         ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   160         }
       
   161     
       
   162     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   163     CleanupStack::PushL(categoryManager);
       
   164     // Create two local categories, "Dagis" and "BurgerKing" belongs to landmark "asdf"
       
   165     CPosLandmarkCategory* category1 = CPosLandmarkCategory::NewLC();
       
   166     category1->SetCategoryNameL(_L("Dagis"));
       
   167     TPosLmItemId id1 = categoryManager->AddCategoryL(*category1);
       
   168     CleanupStack::PopAndDestroy(category1);
       
   169     
       
   170     CPosLandmarkCategory* category2 = CPosLandmarkCategory::NewLC();
       
   171     category2->SetCategoryNameL(_L("BurgerKing"));
       
   172     TPosLmItemId id2 = categoryManager->AddCategoryL(*category2);
       
   173     CleanupStack::PopAndDestroy(category2);
       
   174     
       
   175     // Create "Frisör" belongs to landmark "TE, Lund"
       
   176     CPosLandmarkCategory* category3 = CPosLandmarkCategory::NewLC();
       
   177     category3->SetCategoryNameL(_L("Frisör"));
       
   178     TPosLmItemId id3 = categoryManager->AddCategoryL(*category3);
       
   179     CleanupStack::PopAndDestroy(category3);
       
   180     
       
   181     // Remove global category  with global id 1
       
   182     // Belongs to "Kalles Hundgård"
       
   183     TPosLmItemId globalId = categoryManager->GetGlobalCategoryL(3000);
       
   184     ExecuteAndDeleteLD(categoryManager->RemoveCategoryL(globalId));
       
   185     
       
   186     CPosLmItemIterator* catIter = categoryManager->CategoryIteratorL();
       
   187     CleanupStack::PushL(catIter);
       
   188     TInt nrOfcategoriesBefore = catIter->NumOfItemsL();
       
   189     CleanupStack::PopAndDestroy(catIter);   
       
   190     
       
   191     iLog->Log(_L("iDatabase->ImportLandmarksL"));
       
   192 
       
   193     ExecuteAndDeleteLD(iDatabase->ImportLandmarksL(*iLandmarkParser, CPosLandmarkDatabase::EIncludeGlobalCategoryNames | CPosLandmarkDatabase::ESupressCategoryCreation| CPosLandmarkDatabase::EIncludeCategories));
       
   194     
       
   195 
       
   196     catIter = categoryManager->CategoryIteratorL();
       
   197     CleanupStack::PushL(catIter);
       
   198     TInt nrOfcategoriesAfter = catIter->NumOfItemsL();
       
   199     CleanupStack::PopAndDestroy(catIter);
       
   200     if (nrOfcategoriesAfter != nrOfcategoriesBefore) 
       
   201     {
       
   202     	iLog->Log(_L("ERROR: Three categories should have been added"));
       
   203         iErrorsFound++;
       
   204     }
       
   205     
       
   206     // Check that landmark "TE, Lund" has "Frisör" and
       
   207     // landmark "asdf" has "Dagis" and "BurgerKing" (and also already existing global categories 
       
   208     
       
   209     TBuf<100> buf;
       
   210     
       
   211     RArray<TPosLmItemId> categories;
       
   212     CleanupClosePushL(categories);    
       
   213     
       
   214     TPosLmItemId idde1;
       
   215    
       
   216     // Check id=5 Te, Lund
       
   217     idde1 = categoryManager->GetCategoryL(_L("Frisör"));    
       
   218     categories.Append(idde1);
       
   219     CheckLandmarkL(5, categories);
       
   220     categories.Reset();
       
   221     
       
   222     // Check id=6 asdf
       
   223     idde1 = categoryManager->GetCategoryL(_L("Dagis"));
       
   224     
       
   225     categories.Append(idde1);
       
   226     
       
   227     CheckLandmarkL(6, categories);
       
   228     categories.Reset();
       
   229     
       
   230     CleanupStack::PopAndDestroy(&categories);
       
   231     CleanupStack::PopAndDestroy(categoryManager);
       
   232     
       
   233     delete iLandmarkParser;
       
   234     iLandmarkParser = NULL;
       
   235     
       
   236     delete iDatabase;
       
   237     iDatabase = NULL;
       
   238     iLog->Log(_L("-------------------\n"));
       
   239     }
       
   240 
       
   241 // ---------------------------------------------------------
       
   242 // CPosTp164::CheckLandmarkL
       
   243 //
       
   244 // (other items were commented in a header).
       
   245 // ---------------------------------------------------------
       
   246 //
       
   247 void CPosTp164::CheckLandmarkL(TPosLmItemId aLandmarkId, RArray<TPosLmItemId> aCategoriesList)
       
   248     {
       
   249     iLog->Log(_L("CheckLandmarkL"));
       
   250     
       
   251     // Get landmark
       
   252     CPosLandmark* lm1 = iDatabase->ReadLandmarkLC(aLandmarkId);
       
   253     TPtrC name1;
       
   254     lm1->GetLandmarkName(name1);
       
   255     iLog->Log(name1);
       
   256     
       
   257     RArray<TPosLmItemId> categories;
       
   258     CleanupClosePushL(categories);
       
   259     // Get all categories attached to this landmark
       
   260     lm1->GetCategoriesL(categories);
       
   261    
       
   262     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   263     CleanupStack::PushL(categoryManager);
       
   264     
       
   265     if ( aCategoriesList.Count() != categories.Count() )
       
   266         {
       
   267         iLog->Log(_L("ERROR: Wrong number of categories, actual %d, expected %d"),
       
   268             categories.Count(), aCategoriesList.Count() );
       
   269         iErrorsFound++;
       
   270         }
       
   271     
       
   272     for (TInt i=0;i<categories.Count();i++)
       
   273         {
       
   274         if (aCategoriesList.Find(categories[i]) != KErrNotFound)
       
   275             {
       
   276             iLog->Log(_L("Found"));
       
   277             }
       
   278         else 
       
   279             {
       
   280             iLog->Log(_L("ERROR: Category '%S' was not found"));
       
   281             iErrorsFound++;
       
   282             }
       
   283         }
       
   284     
       
   285     CleanupStack::PopAndDestroy(categoryManager);
       
   286 
       
   287     CleanupStack::PopAndDestroy(&categories);
       
   288     CleanupStack::PopAndDestroy(lm1);
       
   289     }
       
   290     
       
   291   
       
   292 
       
   293 	
       
   294 //  End of File