landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp163.cpp
changeset 39 3efc7a0e8755
parent 35 1a92308afc46
equal deleted inserted replaced
37:e175e2ba2fb0 39:3efc7a0e8755
    24 #include <EPos_CPosLmDatabaseManager.h>
    24 #include <EPos_CPosLmDatabaseManager.h>
    25 #include <EPos_CPosLandmarkParser.h>
    25 #include <EPos_CPosLandmarkParser.h>
    26            
    26            
    27 // ================= CONSTANTS =======================
    27 // ================= CONSTANTS =======================
    28 
    28 
    29   
    29   _LIT(KTp163DbFile, "TP163Test.ldb");
    30     _LIT(KKMZFile, "c:\\system\\test\\testdata\\Tp163KMZ.kmz");
    30     _LIT(KKMZFile, "c:\\system\\test\\testdata\\Tp163KMZ.kmz");
    31 
    31 
    32     
    32     
    33     _LIT(KEmpty, "");
    33     _LIT(KEmpty, "");
    34 
    34 
    62 // (other items were commented in a header).
    62 // (other items were commented in a header).
    63 // ---------------------------------------------------------
    63 // ---------------------------------------------------------
    64 //
    64 //
    65 void CPosTp163::CloseTest()
    65 void CPosTp163::CloseTest()
    66     {
    66     {
       
    67     delete iLandmarkParser;
       
    68             iLandmarkParser = NULL;
       
    69             
       
    70             delete iDatabase;
       
    71             iDatabase = NULL;
    67     // Release ECOM stuff
    72     // Release ECOM stuff
    68     ReleaseLandmarkResources();
    73     ReleaseLandmarkResources();
    69     
    74     
    70     delete iOperation;iOperation=NULL;
    75     delete iOperation;iOperation=NULL;
    71     }
    76     }
   204 // (other items were commented in a header).
   209 // (other items were commented in a header).
   205 // ---------------------------------------------------------
   210 // ---------------------------------------------------------
   206 //
   211 //
   207 void CPosTp163::TestImportL(const TDesC& aFile, const TDesC8& aMime)
   212 void CPosTp163::TestImportL(const TDesC& aFile, const TDesC8& aMime)
   208     {
   213     {
   209     iLog->Log(_L("----- TestImportL -----"));    
   214     iLog->Log(_L("----- TestImport1L ------"));
   210     iLog->Log(_L("FILE: %S"), &aFile);
   215     iLog->Log(_L("FILE: %S"), &aFile);
   211 
       
   212     RemoveAllLmDatabasesL();
   216     RemoveAllLmDatabasesL();
   213 
   217     CopyTestDbFileL(KTp163DbFile);
   214     const TDesC* categoryNames[KNrOfLandmarks][4] = {{&KEmpty, &KEmpty, &KEmpty, &KEmpty},
   218     iLandmarkParser = CPosLandmarkParser::NewL(aMime);
   215                                         {&K1, &KEmpty, &KEmpty, &KEmpty},
   219     iLandmarkParser->SetInputFileL(aFile);
   216                                         {&K2, &K3, &K4, &K5},
   220     
   217                                         {&KEmpty, &KEmpty, &KEmpty, &KEmpty},
   221     TRAPD( err,iDatabase = CPosLandmarkDatabase::OpenL(KTp163DbFile));
   218                                         {&K6, &KEmpty, &KEmpty, &KEmpty},
   222     iLog->Log(_L("Error after CPosLandmarkDatabase::OpenL = %d"),err);
   219                                         {&K7, &K8, &K9, &K10},
       
   220                                         {&K11, &K12, &K13, &KEmpty},
       
   221                                         {&K14, &K15_1, &KEmpty, &KEmpty}};
       
   222     
       
   223     CPosLandmarkDatabase* database = OpenDatabaseLC();
       
   224    
   223    
   225     CPosLandmarkParser* parser = CPosLandmarkParser::NewL(aMime);
   224     if (iDatabase->IsInitializingNeeded())
   226     CleanupStack::PushL(parser);
   225         {
   227     
   226         ExecuteAndDeleteLD(iDatabase->InitializeL());
   228     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*database);
   227         }
       
   228     
       
   229     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
   229     CleanupStack::PushL(categoryManager);
   230     CleanupStack::PushL(categoryManager);
   230     
   231     // Create two local categories, "Dagis" and "BurgerKing" belongs to landmark "asdf"
   231     RFile file; 
   232     CPosLandmarkCategory* category1 = CPosLandmarkCategory::NewLC();
   232     TInt err = file.Open(iFileSession, aFile, EFileRead);
   233     category1->SetCategoryNameL(_L("Dagis"));
   233     if (err != KErrNone) 
   234     TPosLmItemId id1 = categoryManager->AddCategoryL(*category1);
   234     {
   235     CleanupStack::PopAndDestroy(category1);
   235     	iLog->Log(_L("Error when opening file"));
   236     
   236         User::Leave(err);
   237     CPosLandmarkCategory* category2 = CPosLandmarkCategory::NewLC();
   237     }
   238     category2->SetCategoryNameL(_L("BurgerKing"));
   238     CleanupClosePushL(file);
   239     TPosLmItemId id2 = categoryManager->AddCategoryL(*category2);
   239     
   240     CleanupStack::PopAndDestroy(category2);
   240     parser->SetInputFileHandleL(file);
   241     
   241     iOperation = database->ImportLandmarksL(*parser, CPosLandmarkDatabase::EIncludeCategories);
   242     // Create "Frisör" belongs to landmark "TE, Lund"
   242     
   243     CPosLandmarkCategory* category3 = CPosLandmarkCategory::NewLC();
   243     ExecuteAndDeleteLD(iOperation);
   244     category3->SetCategoryNameL(_L("Frisör"));
   244     iOperation=NULL;
   245     TPosLmItemId id3 = categoryManager->AddCategoryL(*category3);
   245     
   246     CleanupStack::PopAndDestroy(category3);
   246     CPosLmItemIterator* iter = database->LandmarkIteratorL();
   247     
   247     CleanupStack::PushL(iter);
   248     // Remove global category  with global id 1
   248     
   249     // Belongs to "Kalles Hundgård"
   249     CDesCArrayFlat* landmarkNames = new (ELeave) CDesCArrayFlat(KNrOfLandmarks);
   250     TPosLmItemId globalId = categoryManager->GetGlobalCategoryL(3000);
   250     landmarkNames->AppendL(_L("Billigt"));
   251     ExecuteAndDeleteLD(categoryManager->RemoveCategoryL(globalId));
   251     landmarkNames->AppendL(_L("LOG9"));
   252     
   252     landmarkNames->AppendL(_L("Kalles Hundgård"));
   253     CPosLmItemIterator* catIter = categoryManager->CategoryIteratorL();
   253     landmarkNames->AppendL(_L("MLFW"));
   254     CleanupStack::PushL(catIter);
   254     landmarkNames->AppendL(_L("TE, Lund"));
   255     TInt nrOfcategoriesBefore = catIter->NumOfItemsL();
   255     landmarkNames->AppendL(_L("asdf"));
   256     CleanupStack::PopAndDestroy(catIter);   
   256     landmarkNames->AppendL(_L("TP48LandmarkWithAllXMLFields"));
   257     
   257     landmarkNames->AppendL(_L("TP48Landmark With Empty XML Fields"));
   258     iLog->Log(_L("iDatabase->ImportLandmarksL"));
   258     
   259 
   259     TPosLmItemId id = iter->NextL();
   260     ExecuteAndDeleteLD(iDatabase->ImportLandmarksL(*iLandmarkParser, CPosLandmarkDatabase::EIncludeGlobalCategoryNames | CPosLandmarkDatabase::ESupressCategoryCreation| CPosLandmarkDatabase::EIncludeCategories));
   260     TInt counter = 0;
   261     
   261     while (id != KPosLmNullItemId)
   262 
   262         {
   263     catIter = categoryManager->CategoryIteratorL();
   263         CPosLandmark* lm = database->ReadLandmarkLC(id);
   264     CleanupStack::PushL(catIter);
   264         RArray<TPosLmItemId> arr;
   265     TInt nrOfcategoriesAfter = catIter->NumOfItemsL();
   265         CleanupClosePushL(arr);
   266     CleanupStack::PopAndDestroy(catIter);
   266         
   267     if (nrOfcategoriesAfter != nrOfcategoriesBefore) 
   267         TPtrC name;
   268     {
   268         lm->GetLandmarkName(name);
   269         iLog->Log(_L("ERROR: Three categories should have been added"));
   269         TPtrC expName(landmarkNames->MdcaPoint(counter));
   270         iErrorsFound++;
   270         iLog->Log(_L("Landmark %d, Actual name '%S', Expected '%S'"), counter, &name, &expName);
   271     }
   271         if (expName.CompareC(name) != KErrNone)
   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)
   272             {
   342             {
   273             iLog->Log(_L("ERROR: Wrong Landmark Name"));
   343             iLog->Log(_L("Found"));
       
   344             }
       
   345         else 
       
   346             {
       
   347             iLog->Log(_L("ERROR: Category '%S' was not found"));
   274             iErrorsFound++;
   348             iErrorsFound++;
   275             }
   349             }
   276         
   350         }
   277         lm->GetCategoriesL(arr);
   351     
   278         if (arr.Count() == 0) iLog->Log(_L("NOLL"));
       
   279         else
       
   280             {
       
   281             TBuf<100> buf;
       
   282             buf.Format(_L("nr of categories %d"), arr.Count());
       
   283             iLog->Log(buf);
       
   284             }
       
   285             
       
   286         for (TInt i=0;i<arr.Count();i++)
       
   287             {
       
   288             CPosLandmarkCategory* cat = categoryManager->ReadCategoryLC(arr[i]);
       
   289             TPtrC catName;
       
   290             cat->GetCategoryName(catName);
       
   291             iLog->Log(_L("Category %d, Actual '%S', Expected '%S'"), i, &catName, categoryNames[counter][i]);
       
   292             if (catName.CompareC(*categoryNames[counter][i]) != KErrNone) 
       
   293                 {
       
   294                 iLog->Log(_L("ERROR: Wrong Category Name"));
       
   295                 iErrorsFound++;
       
   296                 }
       
   297             CleanupStack::PopAndDestroy(cat);
       
   298             }
       
   299 
       
   300         CleanupStack::PopAndDestroy(&arr);
       
   301         CleanupStack::PopAndDestroy(lm);
       
   302         id = iter->NextL();
       
   303         counter++;
       
   304         }
       
   305     TUint32 nr = parser->NumOfParsedLandmarks();
       
   306     if (nr != KNrOfLandmarks)
       
   307     {
       
   308     	iLog->Log(_L("ERROR: Wrong number of landmarks parsed"));
       
   309         iErrorsFound++;
       
   310     }
       
   311     
       
   312     CleanupStack::PopAndDestroy(iter);
       
   313     landmarkNames->Reset();
       
   314     delete landmarkNames;
       
   315     landmarkNames = NULL;  
       
   316     
       
   317     iLog->Log(_L("-------------------\n"));
       
   318 
       
   319     CleanupStack::PopAndDestroy(&file);
       
   320     CleanupStack::PopAndDestroy(categoryManager);
   352     CleanupStack::PopAndDestroy(categoryManager);
   321     CleanupStack::PopAndDestroy(parser);
   353 
   322     CleanupStack::PopAndDestroy(database);
   354     CleanupStack::PopAndDestroy(&categories);
   323     }
   355     CleanupStack::PopAndDestroy(lm1);
       
   356     }
       
   357     
   324 	
   358 	
   325 //  End of File
   359 //  End of File