landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp163.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_CPosTp163.h"
       
    23 #include <EPos_CPosLandmarkDatabase.h>
       
    24 #include <EPos_CPosLmDatabaseManager.h>
       
    25 #include <EPos_CPosLandmarkParser.h>
       
    26            
       
    27 // ================= CONSTANTS =======================
       
    28 
       
    29   _LIT(KTp163DbFile, "TP163Test.ldb");
       
    30     _LIT(KKMZFile, "c:\\system\\test\\testdata\\Tp163KMZ.kmz");
       
    31 
       
    32     
       
    33     _LIT(KEmpty, "");
       
    34 
       
    35     _LIT(K1, "Category nr1 added in TP48");
       
    36         
       
    37     _LIT(K2, "Läkare");
       
    38     _LIT(K3, "Sjukhus");
       
    39     _LIT(K4, "Restaurant");
       
    40     _LIT(K5, "Shop");
       
    41     
       
    42     _LIT(K6, "Frisör");
       
    43     
       
    44     _LIT(K7, "Dagis");
       
    45     _LIT(K8, "BurgerKing");
       
    46     _LIT(K9, "Hotel");
       
    47     _LIT(K10, "Car park");
       
    48     
       
    49     _LIT(K11, "Garage");
       
    50     _LIT(K12, "Bus stop");
       
    51     _LIT(K13, "BurgerKing");
       
    52     
       
    53     _LIT(K14, "Category nr2 added in TP48");
       
    54     _LIT(K15_1, "OutSight");
       
    55     const TInt KNrOfLandmarks = 8;
       
    56                                                     
       
    57 // ================= MEMBER FUNCTIONS =======================
       
    58 
       
    59 // ---------------------------------------------------------
       
    60 // CPosTp163::CloseTest
       
    61 //
       
    62 // (other items were commented in a header).
       
    63 // ---------------------------------------------------------
       
    64 //
       
    65 void CPosTp163::CloseTest()
       
    66     {
       
    67     delete iLandmarkParser;
       
    68             iLandmarkParser = NULL;
       
    69             
       
    70             delete iDatabase;
       
    71             iDatabase = NULL;
       
    72     // Release ECOM stuff
       
    73     ReleaseLandmarkResources();
       
    74     
       
    75     delete iOperation;iOperation=NULL;
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------
       
    79 // CPosTp163::StartL
       
    80 //
       
    81 // (other items were commented in a header).
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 void CPosTp163::StartL()
       
    85     {
       
    86     iErrorsFound = 0;
       
    87     
       
    88        
       
    89     // KML
       
    90     TestParseL(KKMZFile, KKmzMimeType);
       
    91    TestImportL(KKMZFile, KKmzMimeType);
       
    92     
       
    93     if (iErrorsFound != KErrNone)
       
    94         {
       
    95         iLog->Log(_L("Errors found in Tp163"));
       
    96         User::Leave(-1);
       
    97         }
       
    98 	}
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CPosTp163::TestParseL
       
   102 //
       
   103 // (other items were commented in a header).
       
   104 // ---------------------------------------------------------
       
   105 //
       
   106 void CPosTp163::TestParseL(const TDesC& aFile, const TDesC8& aMime)
       
   107     {
       
   108     iLog->Log(_L("----- TestParseL -----"));
       
   109     iLog->Log(_L("FILE: %S"), &aFile);
       
   110     
       
   111     RemoveAllLmDatabasesL();
       
   112     
       
   113         const TDesC* categoryNames[KNrOfLandmarks][4] = {{&KEmpty, &KEmpty, &KEmpty, &KEmpty},
       
   114                                             {&K1, &KEmpty, &KEmpty, &KEmpty},
       
   115                                             {&K2, &K3, &K4, &K5},
       
   116                                             {&KEmpty, &KEmpty, &KEmpty, &KEmpty},
       
   117                                             {&K6, &KEmpty, &KEmpty, &KEmpty},
       
   118                                             {&K7, &K8, &K9, &K10},
       
   119                                             {&K11, &K12, &K13, &KEmpty},
       
   120                                             {&K14, &K15_1, &KEmpty, &KEmpty}};
       
   121 
       
   122     CPosLandmarkParser* parser = CPosLandmarkParser::NewL(aMime);
       
   123     CleanupStack::PushL(parser);
       
   124     
       
   125     RFile file; 
       
   126     TInt err = file.Open(iFileSession, aFile, EFileRead);
       
   127     if (err != KErrNone) 
       
   128     {
       
   129     	iLog->Log(_L("Error when opening file"));
       
   130         User::Leave(err);
       
   131     }
       
   132     CleanupClosePushL(file);
       
   133     parser->SetInputFileHandleL(file);
       
   134     iOperation = parser->ParseContentL();
       
   135     TRequestStatus status = KPosLmOperationNotComplete;
       
   136     TReal32 progress=0;
       
   137     
       
   138     CDesCArrayFlat* landmarkNames = new (ELeave) CDesCArrayFlat(KNrOfLandmarks);
       
   139     landmarkNames->AppendL(_L("Billigt"));
       
   140     landmarkNames->AppendL(_L("LOG9"));
       
   141     landmarkNames->AppendL(_L("Kalles Hundgård"));
       
   142     landmarkNames->AppendL(_L("MLFW"));
       
   143     landmarkNames->AppendL(_L("TE, Lund"));
       
   144     landmarkNames->AppendL(_L("asdf"));
       
   145     landmarkNames->AppendL(_L("TP48LandmarkWithAllXMLFields"));
       
   146     landmarkNames->AppendL(_L("TP48Landmark With Empty XML Fields"));
       
   147     
       
   148     TInt counter=0;
       
   149     while (progress != 1)
       
   150         {
       
   151         iOperation->NextStep(status, progress);
       
   152         // Wait for NextStep to complete
       
   153         User::WaitForRequest(status);
       
   154         CPosLandmark* lm = parser->LandmarkLC();
       
   155         TPtrC name;
       
   156         lm->GetLandmarkName(name);
       
   157         TPtrC expName(landmarkNames->MdcaPoint(counter));
       
   158         iLog->Log(_L("Landmark %d, Actual name '%S', Expected '%S'"), counter, &name, &expName);
       
   159         if (expName.CompareC(name) != KErrNone)
       
   160             {
       
   161             iLog->Log(_L("ERROR: Wrong Landmark Name"));
       
   162         	iErrorsFound++;
       
   163             }
       
   164         
       
   165         RArray<TPosLmItemId> arr;
       
   166         CleanupClosePushL(arr);
       
   167         
       
   168         lm->GetCategoriesL(arr);
       
   169         for (TInt i=0;i<arr.Count();i++)
       
   170             {
       
   171             CPosLandmarkCategory* cat = parser->LandmarkCategoryLC(arr[i]);
       
   172             TPtrC catName;
       
   173             cat->GetCategoryName(catName);
       
   174             iLog->Log(_L("Category %d, Actual '%S', Expected '%S'"), i, &catName, categoryNames[counter][i]);
       
   175             if (catName.CompareC(*categoryNames[counter][i]) != KErrNone)
       
   176             	{
       
   177             	iLog->Log(_L("ERROR: Wrong Category Name when comparing"));
       
   178                 iErrorsFound++;
       
   179             	}
       
   180             CleanupStack::PopAndDestroy(cat);
       
   181             }
       
   182         
       
   183         CleanupStack::PopAndDestroy(&arr);
       
   184         CleanupStack::PopAndDestroy(lm);
       
   185         counter++;
       
   186         }
       
   187         
       
   188     TUint32 nr = parser->NumOfParsedLandmarks();
       
   189     if (nr != KNrOfLandmarks) 
       
   190     {
       
   191     	iLog->Log(_L("ERROR: Wrong number of landmarks parsed"));
       
   192         iErrorsFound++;
       
   193     }
       
   194     
       
   195     iLog->Log(_L("-------------------\n"));
       
   196     delete iOperation;iOperation=NULL;
       
   197        
       
   198     CleanupStack::PopAndDestroy(&file);
       
   199     
       
   200     landmarkNames->Reset();
       
   201     delete landmarkNames;
       
   202     landmarkNames = NULL;   
       
   203     CleanupStack::PopAndDestroy(parser);    
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------
       
   207 // CPosTp163::TestImportL
       
   208 //
       
   209 // (other items were commented in a header).
       
   210 // ---------------------------------------------------------
       
   211 //
       
   212 void CPosTp163::TestImportL(const TDesC& aFile, const TDesC8& aMime)
       
   213     {
       
   214     iLog->Log(_L("----- TestImport1L ------"));
       
   215     iLog->Log(_L("FILE: %S"), &aFile);
       
   216     RemoveAllLmDatabasesL();
       
   217     CopyTestDbFileL(KTp163DbFile);
       
   218     iLandmarkParser = CPosLandmarkParser::NewL(aMime);
       
   219     iLandmarkParser->SetInputFileL(aFile);
       
   220     
       
   221     TRAPD( err,iDatabase = CPosLandmarkDatabase::OpenL(KTp163DbFile));
       
   222     iLog->Log(_L("Error after CPosLandmarkDatabase::OpenL = %d"),err);
       
   223    
       
   224     if (iDatabase->IsInitializingNeeded())
       
   225         {
       
   226         ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   227         }
       
   228     
       
   229     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   230     CleanupStack::PushL(categoryManager);
       
   231     // Create two local categories, "Dagis" and "BurgerKing" belongs to landmark "asdf"
       
   232     CPosLandmarkCategory* category1 = CPosLandmarkCategory::NewLC();
       
   233     category1->SetCategoryNameL(_L("Dagis"));
       
   234     TPosLmItemId id1 = categoryManager->AddCategoryL(*category1);
       
   235     CleanupStack::PopAndDestroy(category1);
       
   236     
       
   237     CPosLandmarkCategory* category2 = CPosLandmarkCategory::NewLC();
       
   238     category2->SetCategoryNameL(_L("BurgerKing"));
       
   239     TPosLmItemId id2 = categoryManager->AddCategoryL(*category2);
       
   240     CleanupStack::PopAndDestroy(category2);
       
   241     
       
   242     // Create "Frisör" belongs to landmark "TE, Lund"
       
   243     CPosLandmarkCategory* category3 = CPosLandmarkCategory::NewLC();
       
   244     category3->SetCategoryNameL(_L("Frisör"));
       
   245     TPosLmItemId id3 = categoryManager->AddCategoryL(*category3);
       
   246     CleanupStack::PopAndDestroy(category3);
       
   247     
       
   248     // Remove global category  with global id 1
       
   249     // Belongs to "Kalles Hundgård"
       
   250     TPosLmItemId globalId = categoryManager->GetGlobalCategoryL(3000);
       
   251     ExecuteAndDeleteLD(categoryManager->RemoveCategoryL(globalId));
       
   252     
       
   253     CPosLmItemIterator* catIter = categoryManager->CategoryIteratorL();
       
   254     CleanupStack::PushL(catIter);
       
   255     TInt nrOfcategoriesBefore = catIter->NumOfItemsL();
       
   256     CleanupStack::PopAndDestroy(catIter);   
       
   257     
       
   258     iLog->Log(_L("iDatabase->ImportLandmarksL"));
       
   259 
       
   260     ExecuteAndDeleteLD(iDatabase->ImportLandmarksL(*iLandmarkParser, CPosLandmarkDatabase::EIncludeGlobalCategoryNames | CPosLandmarkDatabase::ESupressCategoryCreation| CPosLandmarkDatabase::EIncludeCategories));
       
   261     
       
   262 
       
   263     catIter = categoryManager->CategoryIteratorL();
       
   264     CleanupStack::PushL(catIter);
       
   265     TInt nrOfcategoriesAfter = catIter->NumOfItemsL();
       
   266     CleanupStack::PopAndDestroy(catIter);
       
   267     if (nrOfcategoriesAfter != nrOfcategoriesBefore) 
       
   268     {
       
   269         iLog->Log(_L("ERROR: Three categories should have been added"));
       
   270         iErrorsFound++;
       
   271     }
       
   272     
       
   273     // Check that landmark "TE, Lund" has "Frisör" and
       
   274     // landmark "asdf" has "Dagis" and "BurgerKing" (and also already existing global categories 
       
   275     
       
   276     TBuf<100> buf;
       
   277     
       
   278     RArray<TPosLmItemId> categories;
       
   279     CleanupClosePushL(categories);    
       
   280     
       
   281     TPosLmItemId idde1;
       
   282    
       
   283     // Check id=5 Te, Lund
       
   284     idde1 = categoryManager->GetCategoryL(_L("Frisör"));    
       
   285     categories.Append(idde1);
       
   286     CheckLandmarkL(5, categories);
       
   287     categories.Reset();
       
   288     
       
   289     // Check id=6 asdf
       
   290     idde1 = categoryManager->GetCategoryL(_L("Dagis"));
       
   291     
       
   292     categories.Append(idde1);
       
   293     
       
   294     CheckLandmarkL(6, categories);
       
   295     categories.Reset();
       
   296     
       
   297     CleanupStack::PopAndDestroy(&categories);
       
   298     CleanupStack::PopAndDestroy(categoryManager);
       
   299     
       
   300     delete iLandmarkParser;
       
   301     iLandmarkParser = NULL;
       
   302     
       
   303     delete iDatabase;
       
   304     iDatabase = NULL;
       
   305     iLog->Log(_L("-------------------\n"));
       
   306     }
       
   307 
       
   308 // ---------------------------------------------------------
       
   309 // CPosTp163::CheckLandmarkL
       
   310 //
       
   311 // (other items were commented in a header).
       
   312 // ---------------------------------------------------------
       
   313 //
       
   314 void CPosTp163::CheckLandmarkL(TPosLmItemId aLandmarkId, RArray<TPosLmItemId> aCategoriesList)
       
   315     {
       
   316     iLog->Log(_L("CheckLandmarkL"));
       
   317     
       
   318     // Get landmark
       
   319     CPosLandmark* lm1 = iDatabase->ReadLandmarkLC(aLandmarkId);
       
   320     TPtrC name1;
       
   321     lm1->GetLandmarkName(name1);
       
   322     iLog->Log(name1);
       
   323     
       
   324     RArray<TPosLmItemId> categories;
       
   325     CleanupClosePushL(categories);
       
   326     // Get all categories attached to this landmark
       
   327     lm1->GetCategoriesL(categories);
       
   328    
       
   329     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   330     CleanupStack::PushL(categoryManager);
       
   331     
       
   332     if ( aCategoriesList.Count() != categories.Count() )
       
   333         {
       
   334         iLog->Log(_L("ERROR: Wrong number of categories, actual %d, expected %d"),
       
   335             categories.Count(), aCategoriesList.Count() );
       
   336         iErrorsFound++;
       
   337         }
       
   338     
       
   339     for (TInt i=0;i<categories.Count();i++)
       
   340         {
       
   341         if (aCategoriesList.Find(categories[i]) != KErrNotFound)
       
   342             {
       
   343             iLog->Log(_L("Found"));
       
   344             }
       
   345         else 
       
   346             {
       
   347             iLog->Log(_L("ERROR: Category '%S' was not found"));
       
   348             iErrorsFound++;
       
   349             }
       
   350         }
       
   351     
       
   352     CleanupStack::PopAndDestroy(categoryManager);
       
   353 
       
   354     CleanupStack::PopAndDestroy(&categories);
       
   355     CleanupStack::PopAndDestroy(lm1);
       
   356     }
       
   357     
       
   358 	
       
   359 //  End of File