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