landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp137.cpp
branchRCL_3
changeset 44 2b4ea9893b66
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp137.cpp	Tue Aug 31 15:37:04 2010 +0300
@@ -0,0 +1,295 @@
+/*
+* Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: 
+*   ?description_line
+*
+*/
+
+
+//  INCLUDES
+
+#include "FT_CPosTp137.h"
+#include <EPos_CPosLandmarkDatabase.h>
+#include <EPos_CPosLmDatabaseManager.h>
+#include <EPos_CPosLandmarkParser.h>
+
+#include <LbsPosition.h>
+#include <EPos_CPosLandmarkSearch.h>
+#include <EPos_CPosLmTextCriteria.h>
+#include <EPos_CPosLMItemIterator.h>
+           
+// ================= CONSTANTS =======================
+
+    _LIT(KLmxFile, "c:\\system\\test\\testdata\\Tp137.xml");
+    _LIT(KGpxFile, "c:\\system\\test\\testdata\\Tp137.gpx");
+
+#define DEBUG ETrue
+                                                    
+// ================= MEMBER FUNCTIONS =======================
+
+// ---------------------------------------------------------
+// CPosTp137::CloseTest
+//
+// (other items were commented in a header).
+// ---------------------------------------------------------
+//
+void CPosTp137::CloseTest()
+    {
+    iLog->Log(_L("CloseTest"));
+    
+    delete iLandmarkParser;
+    iLandmarkParser = NULL;
+    
+    delete iDatabase;
+    iDatabase = NULL;
+    }
+
+// ---------------------------------------------------------
+// CPosTp137::StartL
+//
+// (other items were commented in a header).
+// ---------------------------------------------------------
+//
+void CPosTp137::StartL()
+    {
+    iErrorsFound = 0;
+    
+    // LMX
+    TestImportEmptyDbL( KLmxFile, KLmxMimeType );
+    TestImport1L( KLmxFile, KLmxMimeType );
+
+    // GPX
+    TestImportEmptyDbL( KGpxFile, KGpxMimeType );
+    TestImport1L( KGpxFile, KGpxMimeType );
+
+    if (iErrorsFound != KErrNone)
+        {
+        iLog->Log(_L("Errors found in TP137"));
+        User::Leave(-1);
+        }
+    }
+
+// ---------------------------------------------------------
+// CPosTp137::TestImportEmptyDbL
+//
+// (other items were commented in a header).
+// ---------------------------------------------------------
+//
+void CPosTp137::TestImportEmptyDbL(const TDesC& aFile, const TDesC8& aMime)
+    {
+    iLog->Log(_L("----- TestImportEmptyDbL -----"));
+    iLog->Log(_L("FILE: %S"), &aFile);
+    RemoveAllLmDatabasesL();
+    
+    iLandmarkParser = CPosLandmarkParser::NewL(aMime);
+    iLandmarkParser->SetInputFileL(aFile);
+    
+    iDatabase = CPosLandmarkDatabase::OpenL();
+    if (iDatabase->IsInitializingNeeded())
+        {
+        ExecuteAndDeleteLD(iDatabase->InitializeL());
+        }
+        
+    CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
+    CleanupStack::PushL(categoryManager);
+    
+    CPosLmItemIterator* catIter = categoryManager->CategoryIteratorL();
+    CleanupStack::PushL(catIter);
+    TInt nrOfcategoriesBefore = catIter->NumOfItemsL();
+    CleanupStack::PopAndDestroy(catIter);
+    
+    iLog->Log(_L("iDatabase->ImportLandmarksL"));
+    // No categories should be imported, since ESupressCategoryCreation is used and the landmarks
+    // db is empty when starting
+    ExecuteAndDeleteLD(iDatabase->ImportLandmarksL(*iLandmarkParser, CPosLandmarkDatabase::ESupressCategoryCreation| CPosLandmarkDatabase::EIncludeCategories));
+
+    catIter = categoryManager->CategoryIteratorL();
+    CleanupStack::PushL(catIter);
+    TInt nrOfcategoriesAfter = catIter->NumOfItemsL();
+    CleanupStack::PopAndDestroy(catIter);
+    
+    CleanupStack::PopAndDestroy(categoryManager);
+    
+    delete iLandmarkParser;
+    iLandmarkParser = NULL;
+    
+    delete iDatabase;
+    iDatabase = NULL;
+    
+    if (nrOfcategoriesAfter != nrOfcategoriesBefore)
+    	{
+    	iLog->Log(_L("ERROR: No categories should have been imported"));
+        iErrorsFound++;
+    	}
+    iLog->Log(_L("-------------------\n"));
+    }
+    
+// ---------------------------------------------------------
+// CPosTp137::TestImport1L
+//
+// (other items were commented in a header).
+// ---------------------------------------------------------
+//
+void CPosTp137::TestImport1L(const TDesC& aFile, const TDesC8& aMime)
+    {
+    iLog->Log(_L("----- TestImport1L ------"));
+    iLog->Log(_L("FILE: %S"), &aFile);
+    RemoveAllLmDatabasesL();
+    
+    iLandmarkParser = CPosLandmarkParser::NewL(aMime);
+    iLandmarkParser->SetInputFileL(aFile);
+    
+    iDatabase = CPosLandmarkDatabase::OpenL();
+   
+    if (iDatabase->IsInitializingNeeded())
+        {
+        ExecuteAndDeleteLD(iDatabase->InitializeL());
+        }
+    
+    CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
+    CleanupStack::PushL(categoryManager);
+    // Create two local categories, "Dagis" and "BurgerKing" belongs to landmark "asdf"
+    CPosLandmarkCategory* category1 = CPosLandmarkCategory::NewLC();
+    category1->SetCategoryNameL(_L("Dagis"));
+    TPosLmItemId id1 = categoryManager->AddCategoryL(*category1);
+    CleanupStack::PopAndDestroy(category1);
+    
+    CPosLandmarkCategory* category2 = CPosLandmarkCategory::NewLC();
+    category2->SetCategoryNameL(_L("BurgerKing"));
+    TPosLmItemId id2 = categoryManager->AddCategoryL(*category2);
+    CleanupStack::PopAndDestroy(category2);
+    
+    // Create "Frisör" belongs to landmark "TE, Lund"
+    CPosLandmarkCategory* category3 = CPosLandmarkCategory::NewLC();
+    category3->SetCategoryNameL(_L("Frisör"));
+    TPosLmItemId id3 = categoryManager->AddCategoryL(*category3);
+    CleanupStack::PopAndDestroy(category3);
+    
+    // Remove global category  with global id 1
+    // Belongs to "Kalles Hundgård"
+    TPosLmItemId globalId = categoryManager->GetGlobalCategoryL(3000);
+    ExecuteAndDeleteLD(categoryManager->RemoveCategoryL(globalId));
+    
+    CPosLmItemIterator* catIter = categoryManager->CategoryIteratorL();
+    CleanupStack::PushL(catIter);
+    TInt nrOfcategoriesBefore = catIter->NumOfItemsL();
+    CleanupStack::PopAndDestroy(catIter);   
+    
+    iLog->Log(_L("iDatabase->ImportLandmarksL"));
+
+    ExecuteAndDeleteLD(iDatabase->ImportLandmarksL(*iLandmarkParser, CPosLandmarkDatabase::EIncludeGlobalCategoryNames | CPosLandmarkDatabase::ESupressCategoryCreation| CPosLandmarkDatabase::EIncludeCategories));
+    
+
+    catIter = categoryManager->CategoryIteratorL();
+    CleanupStack::PushL(catIter);
+    TInt nrOfcategoriesAfter = catIter->NumOfItemsL();
+    CleanupStack::PopAndDestroy(catIter);
+    if (nrOfcategoriesAfter != nrOfcategoriesBefore) 
+    {
+    	iLog->Log(_L("ERROR: Three categories should have been added"));
+        iErrorsFound++;
+    }
+    
+    // Check that landmark "TE, Lund" has "Frisör" and
+    // landmark "asdf" has "Dagis" and "BurgerKing" (and also already existing global categories 
+    
+    TBuf<100> buf;
+    
+    RArray<TPosLmItemId> categories;
+    CleanupClosePushL(categories);    
+    
+    TPosLmItemId idde1;
+   
+    // Check id=5 Te, Lund
+    idde1 = categoryManager->GetCategoryL(_L("Frisör"));    
+    categories.Append(idde1);
+    CheckLandmarkL(5, categories);
+    categories.Reset();
+    
+    // Check id=6 asdf
+    idde1 = categoryManager->GetCategoryL(_L("Dagis"));
+    TPosLmItemId idde2 = categoryManager->GetCategoryL(_L("BurgerKing"));
+    categories.Append(idde1);
+    if ( aMime != KGpxMimeType )
+        {
+        categories.Append(idde2);         
+        }
+    CheckLandmarkL(6, categories);
+    categories.Reset();
+    
+    CleanupStack::PopAndDestroy(&categories);
+    CleanupStack::PopAndDestroy(categoryManager);
+    
+    delete iLandmarkParser;
+    iLandmarkParser = NULL;
+    
+    delete iDatabase;
+    iDatabase = NULL;
+    iLog->Log(_L("-------------------\n"));
+    }
+
+// ---------------------------------------------------------
+// CPosTp137::CheckLandmarkL
+//
+// (other items were commented in a header).
+// ---------------------------------------------------------
+//
+void CPosTp137::CheckLandmarkL(TPosLmItemId aLandmarkId, RArray<TPosLmItemId> aCategoriesList)
+    {
+    iLog->Log(_L("CheckLandmarkL"));
+    
+    // Get landmark
+    CPosLandmark* lm1 = iDatabase->ReadLandmarkLC(aLandmarkId);
+    TPtrC name1;
+    lm1->GetLandmarkName(name1);
+    iLog->Log(name1);
+    
+    RArray<TPosLmItemId> categories;
+    CleanupClosePushL(categories);
+    // Get all categories attached to this landmark
+    lm1->GetCategoriesL(categories);
+   
+    CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
+    CleanupStack::PushL(categoryManager);
+    
+    if ( aCategoriesList.Count() != categories.Count() )
+        {
+        iLog->Log(_L("ERROR: Wrong number of categories, actual %d, expected %d"),
+            categories.Count(), aCategoriesList.Count() );
+        iErrorsFound++;
+        }
+    
+    for (TInt i=0;i<categories.Count();i++)
+        {
+        if (aCategoriesList.Find(categories[i]) != KErrNotFound)
+            {
+            iLog->Log(_L("Found"));
+            }
+        else 
+            {
+            iLog->Log(_L("ERROR: Category '%S' was not found"));
+            iErrorsFound++;
+            }
+        }
+    
+    CleanupStack::PopAndDestroy(categoryManager);
+
+    CleanupStack::PopAndDestroy(&categories);
+    CleanupStack::PopAndDestroy(lm1);
+    }
+    
+  
+
+	
+//  End of File