landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp161.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(KTp161DbFile, "TP161Test.ldb");
    30     _LIT(KKMLFile, "c:\\system\\test\\testdata\\Tp161KML.kml");
    30     _LIT(KKMLFile, "c:\\system\\test\\testdata\\Tp161KML.kml");
    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 CPosTp161::CloseTest()
    65 void CPosTp161::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     }
   196     delete landmarkNames;
   201     delete landmarkNames;
   197     landmarkNames = NULL;   
   202     landmarkNames = NULL;   
   198     CleanupStack::PopAndDestroy(parser);    
   203     CleanupStack::PopAndDestroy(parser);    
   199     }
   204     }
   200 
   205 
   201 // ---------------------------------------------------------
   206 
   202 // CPosTp161::TestImportL
   207 // ---------------------------------------------------------
       
   208 // CPosTp161::TestImport1L
   203 //
   209 //
   204 // (other items were commented in a header).
   210 // (other items were commented in a header).
   205 // ---------------------------------------------------------
   211 // ---------------------------------------------------------
   206 //
   212 //
   207 void CPosTp161::TestImportL(const TDesC& aFile, const TDesC8& aMime)
   213 void CPosTp161::TestImportL(const TDesC& aFile, const TDesC8& aMime)
   208     {
   214     {
   209     iLog->Log(_L("----- TestImportL -----"));    
   215     iLog->Log(_L("----- TestImport1L ------"));
   210     iLog->Log(_L("FILE: %S"), &aFile);
   216     iLog->Log(_L("FILE: %S"), &aFile);
   211 
       
   212     RemoveAllLmDatabasesL();
   217     RemoveAllLmDatabasesL();
   213 
   218     CopyTestDbFileL(KTp161DbFile);
   214     const TDesC* categoryNames[KNrOfLandmarks][4] = {{&KEmpty, &KEmpty, &KEmpty, &KEmpty},
   219     iLandmarkParser = CPosLandmarkParser::NewL(aMime);
   215                                         {&K1, &KEmpty, &KEmpty, &KEmpty},
   220     iLandmarkParser->SetInputFileL(aFile);
   216                                         {&K2, &K3, &K4, &K5},
   221     
   217                                         {&KEmpty, &KEmpty, &KEmpty, &KEmpty},
   222     TRAPD( err,iDatabase = CPosLandmarkDatabase::OpenL(KTp161DbFile));
   218                                         {&K6, &KEmpty, &KEmpty, &KEmpty},
   223     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    
   224    
   225     CPosLandmarkParser* parser = CPosLandmarkParser::NewL(aMime);
   225     if (iDatabase->IsInitializingNeeded())
   226     CleanupStack::PushL(parser);
   226         {
   227     
   227         ExecuteAndDeleteLD(iDatabase->InitializeL());
   228     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*database);
   228         }
       
   229     
       
   230     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
   229     CleanupStack::PushL(categoryManager);
   231     CleanupStack::PushL(categoryManager);
   230     
   232     // Create two local categories, "Dagis" and "BurgerKing" belongs to landmark "asdf"
   231     RFile file; 
   233     CPosLandmarkCategory* category1 = CPosLandmarkCategory::NewLC();
   232     TInt err = file.Open(iFileSession, aFile, EFileRead);
   234     category1->SetCategoryNameL(_L("Dagis"));
   233     if (err != KErrNone) 
   235     TPosLmItemId id1 = categoryManager->AddCategoryL(*category1);
   234     {
   236     CleanupStack::PopAndDestroy(category1);
   235     	iLog->Log(_L("Error when opening file"));
   237     
   236         User::Leave(err);
   238     CPosLandmarkCategory* category2 = CPosLandmarkCategory::NewLC();
   237     }
   239     category2->SetCategoryNameL(_L("BurgerKing"));
   238     CleanupClosePushL(file);
   240     TPosLmItemId id2 = categoryManager->AddCategoryL(*category2);
   239     
   241     CleanupStack::PopAndDestroy(category2);
   240     parser->SetInputFileHandleL(file);
   242     
   241     iOperation = database->ImportLandmarksL(*parser, CPosLandmarkDatabase::EIncludeCategories);
   243     // Create "Frisör" belongs to landmark "TE, Lund"
   242     
   244     CPosLandmarkCategory* category3 = CPosLandmarkCategory::NewLC();
   243     ExecuteAndDeleteLD(iOperation);
   245     category3->SetCategoryNameL(_L("Frisör"));
   244     iOperation=NULL;
   246     TPosLmItemId id3 = categoryManager->AddCategoryL(*category3);
   245     
   247     CleanupStack::PopAndDestroy(category3);
   246     CPosLmItemIterator* iter = database->LandmarkIteratorL();
   248     
   247     CleanupStack::PushL(iter);
   249     // Remove global category  with global id 1
   248     
   250     // Belongs to "Kalles Hundgård"
   249     CDesCArrayFlat* landmarkNames = new (ELeave) CDesCArrayFlat(KNrOfLandmarks);
   251     TPosLmItemId globalId = categoryManager->GetGlobalCategoryL(3000);
   250     landmarkNames->AppendL(_L("Billigt"));
   252     ExecuteAndDeleteLD(categoryManager->RemoveCategoryL(globalId));
   251     landmarkNames->AppendL(_L("LOG9"));
   253     
   252     landmarkNames->AppendL(_L("Kalles Hundgård"));
   254     CPosLmItemIterator* catIter = categoryManager->CategoryIteratorL();
   253     landmarkNames->AppendL(_L("MLFW"));
   255     CleanupStack::PushL(catIter);
   254     landmarkNames->AppendL(_L("TE, Lund"));
   256     TInt nrOfcategoriesBefore = catIter->NumOfItemsL();
   255     landmarkNames->AppendL(_L("asdf"));
   257     CleanupStack::PopAndDestroy(catIter);   
   256     landmarkNames->AppendL(_L("TP48LandmarkWithAllXMLFields"));
   258     
   257     landmarkNames->AppendL(_L("TP48Landmark With Empty XML Fields"));
   259     iLog->Log(_L("iDatabase->ImportLandmarksL"));
   258     
   260 
   259     TPosLmItemId id = iter->NextL();
   261     ExecuteAndDeleteLD(iDatabase->ImportLandmarksL(*iLandmarkParser, CPosLandmarkDatabase::EIncludeGlobalCategoryNames | CPosLandmarkDatabase::ESupressCategoryCreation| CPosLandmarkDatabase::EIncludeCategories));
   260     TInt counter = 0;
   262     
   261     while (id != KPosLmNullItemId)
   263 
   262         {
   264     catIter = categoryManager->CategoryIteratorL();
   263         CPosLandmark* lm = database->ReadLandmarkLC(id);
   265     CleanupStack::PushL(catIter);
   264         RArray<TPosLmItemId> arr;
   266     TInt nrOfcategoriesAfter = catIter->NumOfItemsL();
   265         CleanupClosePushL(arr);
   267     CleanupStack::PopAndDestroy(catIter);
   266         
   268     if (nrOfcategoriesAfter != nrOfcategoriesBefore) 
   267         TPtrC name;
   269     {
   268         lm->GetLandmarkName(name);
   270         iLog->Log(_L("ERROR: Three categories should have been added"));
   269         TPtrC expName(landmarkNames->MdcaPoint(counter));
   271         iErrorsFound++;
   270         iLog->Log(_L("Landmark %d, Actual name '%S', Expected '%S'"), counter, &name, &expName);
   272     }
   271         if (expName.CompareC(name) != KErrNone)
   273     
       
   274     // Check that landmark "TE, Lund" has "Frisör" and
       
   275     // landmark "asdf" has "Dagis" and "BurgerKing" (and also already existing global categories 
       
   276     
       
   277     TBuf<100> buf;
       
   278     
       
   279     RArray<TPosLmItemId> categories;
       
   280     CleanupClosePushL(categories);    
       
   281     
       
   282     TPosLmItemId idde1;
       
   283    
       
   284     // Check id=5 Te, Lund
       
   285     idde1 = categoryManager->GetCategoryL(_L("Frisör"));    
       
   286     categories.Append(idde1);
       
   287     CheckLandmarkL(5, categories);
       
   288     categories.Reset();
       
   289     
       
   290     // Check id=6 asdf
       
   291     idde1 = categoryManager->GetCategoryL(_L("Dagis"));
       
   292     
       
   293     categories.Append(idde1);
       
   294     
       
   295     CheckLandmarkL(6, categories);
       
   296     categories.Reset();
       
   297     
       
   298     CleanupStack::PopAndDestroy(&categories);
       
   299     CleanupStack::PopAndDestroy(categoryManager);
       
   300     
       
   301     delete iLandmarkParser;
       
   302     iLandmarkParser = NULL;
       
   303     
       
   304     delete iDatabase;
       
   305     iDatabase = NULL;
       
   306     iLog->Log(_L("-------------------\n"));
       
   307     }
       
   308 
       
   309 // ---------------------------------------------------------
       
   310 // CPosTp161::CheckLandmarkL
       
   311 //
       
   312 // (other items were commented in a header).
       
   313 // ---------------------------------------------------------
       
   314 //
       
   315 void CPosTp161::CheckLandmarkL(TPosLmItemId aLandmarkId, RArray<TPosLmItemId> aCategoriesList)
       
   316     {
       
   317     iLog->Log(_L("CheckLandmarkL"));
       
   318     
       
   319     // Get landmark
       
   320     CPosLandmark* lm1 = iDatabase->ReadLandmarkLC(aLandmarkId);
       
   321     TPtrC name1;
       
   322     lm1->GetLandmarkName(name1);
       
   323     iLog->Log(name1);
       
   324     
       
   325     RArray<TPosLmItemId> categories;
       
   326     CleanupClosePushL(categories);
       
   327     // Get all categories attached to this landmark
       
   328     lm1->GetCategoriesL(categories);
       
   329    
       
   330     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   331     CleanupStack::PushL(categoryManager);
       
   332     
       
   333     if ( aCategoriesList.Count() != categories.Count() )
       
   334         {
       
   335         iLog->Log(_L("ERROR: Wrong number of categories, actual %d, expected %d"),
       
   336             categories.Count(), aCategoriesList.Count() );
       
   337         iErrorsFound++;
       
   338         }
       
   339     
       
   340     for (TInt i=0;i<categories.Count();i++)
       
   341         {
       
   342         if (aCategoriesList.Find(categories[i]) != KErrNotFound)
   272             {
   343             {
   273             iLog->Log(_L("ERROR: Wrong Landmark Name"));
   344             iLog->Log(_L("Found"));
       
   345             }
       
   346         else 
       
   347             {
       
   348             iLog->Log(_L("ERROR: Category '%S' was not found"));
   274             iErrorsFound++;
   349             iErrorsFound++;
   275             }
   350             }
   276         
   351         }
   277         lm->GetCategoriesL(arr);
   352     
   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);
   353     CleanupStack::PopAndDestroy(categoryManager);
   321     CleanupStack::PopAndDestroy(parser);
   354 
   322     CleanupStack::PopAndDestroy(database);
   355     CleanupStack::PopAndDestroy(&categories);
   323     }
   356     CleanupStack::PopAndDestroy(lm1);
       
   357     }
       
   358     
   324 	
   359 	
   325 //  End of File
   360 //  End of File