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