landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp163.cpp
changeset 33 834e27cad510
child 35 1a92308afc46
child 40 16118e24b93b
equal deleted inserted replaced
32:b12ea03c50a3 33:834e27cad510
       
     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 the License "Symbian Foundation License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-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   
       
    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     // Release ECOM stuff
       
    68     ReleaseLandmarkResources();
       
    69     
       
    70     delete iOperation;iOperation=NULL;
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------
       
    74 // CPosTp163::StartL
       
    75 //
       
    76 // (other items were commented in a header).
       
    77 // ---------------------------------------------------------
       
    78 //
       
    79 void CPosTp163::StartL()
       
    80     {
       
    81     iErrorsFound = 0;
       
    82     
       
    83        
       
    84     // KML
       
    85     TestParseL(KKMZFile, KKmzMimeType);
       
    86    TestImportL(KKMZFile, KKmzMimeType);
       
    87     
       
    88     if (iErrorsFound != KErrNone)
       
    89         {
       
    90         iLog->Log(_L("Errors found in Tp163"));
       
    91         User::Leave(-1);
       
    92         }
       
    93 	}
       
    94 
       
    95 // ---------------------------------------------------------
       
    96 // CPosTp163::TestParseL
       
    97 //
       
    98 // (other items were commented in a header).
       
    99 // ---------------------------------------------------------
       
   100 //
       
   101 void CPosTp163::TestParseL(const TDesC& aFile, const TDesC8& aMime)
       
   102     {
       
   103     iLog->Log(_L("----- TestParseL -----"));
       
   104     iLog->Log(_L("FILE: %S"), &aFile);
       
   105     
       
   106     RemoveAllLmDatabasesL();
       
   107     
       
   108         const TDesC* categoryNames[KNrOfLandmarks][4] = {{&KEmpty, &KEmpty, &KEmpty, &KEmpty},
       
   109                                             {&K1, &KEmpty, &KEmpty, &KEmpty},
       
   110                                             {&K2, &K3, &K4, &K5},
       
   111                                             {&KEmpty, &KEmpty, &KEmpty, &KEmpty},
       
   112                                             {&K6, &KEmpty, &KEmpty, &KEmpty},
       
   113                                             {&K7, &K8, &K9, &K10},
       
   114                                             {&K11, &K12, &K13, &KEmpty},
       
   115                                             {&K14, &K15_1, &KEmpty, &KEmpty}};
       
   116 
       
   117     CPosLandmarkParser* parser = CPosLandmarkParser::NewL(aMime);
       
   118     CleanupStack::PushL(parser);
       
   119     
       
   120     RFile file; 
       
   121     TInt err = file.Open(iFileSession, aFile, EFileRead);
       
   122     if (err != KErrNone) 
       
   123     {
       
   124     	iLog->Log(_L("Error when opening file"));
       
   125         User::Leave(err);
       
   126     }
       
   127     CleanupClosePushL(file);
       
   128     parser->SetInputFileHandleL(file);
       
   129     iOperation = parser->ParseContentL();
       
   130     TRequestStatus status = KPosLmOperationNotComplete;
       
   131     TReal32 progress=0;
       
   132     
       
   133     CDesCArrayFlat* landmarkNames = new (ELeave) CDesCArrayFlat(KNrOfLandmarks);
       
   134     landmarkNames->AppendL(_L("Billigt"));
       
   135     landmarkNames->AppendL(_L("LOG9"));
       
   136     landmarkNames->AppendL(_L("Kalles Hundgård"));
       
   137     landmarkNames->AppendL(_L("MLFW"));
       
   138     landmarkNames->AppendL(_L("TE, Lund"));
       
   139     landmarkNames->AppendL(_L("asdf"));
       
   140     landmarkNames->AppendL(_L("TP48LandmarkWithAllXMLFields"));
       
   141     landmarkNames->AppendL(_L("TP48Landmark With Empty XML Fields"));
       
   142     
       
   143     TInt counter=0;
       
   144     while (progress != 1)
       
   145         {
       
   146         iOperation->NextStep(status, progress);
       
   147         // Wait for NextStep to complete
       
   148         User::WaitForRequest(status);
       
   149         CPosLandmark* lm = parser->LandmarkLC();
       
   150         TPtrC name;
       
   151         lm->GetLandmarkName(name);
       
   152         TPtrC expName(landmarkNames->MdcaPoint(counter));
       
   153         iLog->Log(_L("Landmark %d, Actual name '%S', Expected '%S'"), counter, &name, &expName);
       
   154         if (expName.CompareC(name) != KErrNone)
       
   155             {
       
   156             iLog->Log(_L("ERROR: Wrong Landmark Name"));
       
   157         	iErrorsFound++;
       
   158             }
       
   159         
       
   160         RArray<TPosLmItemId> arr;
       
   161         CleanupClosePushL(arr);
       
   162         
       
   163         lm->GetCategoriesL(arr);
       
   164         for (TInt i=0;i<arr.Count();i++)
       
   165             {
       
   166             CPosLandmarkCategory* cat = parser->LandmarkCategoryLC(arr[i]);
       
   167             TPtrC catName;
       
   168             cat->GetCategoryName(catName);
       
   169             iLog->Log(_L("Category %d, Actual '%S', Expected '%S'"), i, &catName, categoryNames[counter][i]);
       
   170             if (catName.CompareC(*categoryNames[counter][i]) != KErrNone)
       
   171             	{
       
   172             	iLog->Log(_L("ERROR: Wrong Category Name when comparing"));
       
   173                 iErrorsFound++;
       
   174             	}
       
   175             CleanupStack::PopAndDestroy(cat);
       
   176             }
       
   177         
       
   178         CleanupStack::PopAndDestroy(&arr);
       
   179         CleanupStack::PopAndDestroy(lm);
       
   180         counter++;
       
   181         }
       
   182         
       
   183     TUint32 nr = parser->NumOfParsedLandmarks();
       
   184     if (nr != KNrOfLandmarks) 
       
   185     {
       
   186     	iLog->Log(_L("ERROR: Wrong number of landmarks parsed"));
       
   187         iErrorsFound++;
       
   188     }
       
   189     
       
   190     iLog->Log(_L("-------------------\n"));
       
   191     delete iOperation;iOperation=NULL;
       
   192        
       
   193     CleanupStack::PopAndDestroy(&file);
       
   194     
       
   195     landmarkNames->Reset();
       
   196     delete landmarkNames;
       
   197     landmarkNames = NULL;   
       
   198     CleanupStack::PopAndDestroy(parser);    
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------
       
   202 // CPosTp163::TestImportL
       
   203 //
       
   204 // (other items were commented in a header).
       
   205 // ---------------------------------------------------------
       
   206 //
       
   207 void CPosTp163::TestImportL(const TDesC& aFile, const TDesC8& aMime)
       
   208     {
       
   209     iLog->Log(_L("----- TestImportL -----"));    
       
   210     iLog->Log(_L("FILE: %S"), &aFile);
       
   211 
       
   212     RemoveAllLmDatabasesL();
       
   213 
       
   214     const TDesC* categoryNames[KNrOfLandmarks][4] = {{&KEmpty, &KEmpty, &KEmpty, &KEmpty},
       
   215                                         {&K1, &KEmpty, &KEmpty, &KEmpty},
       
   216                                         {&K2, &K3, &K4, &K5},
       
   217                                         {&KEmpty, &KEmpty, &KEmpty, &KEmpty},
       
   218                                         {&K6, &KEmpty, &KEmpty, &KEmpty},
       
   219                                         {&K7, &K8, &K9, &K10},
       
   220                                         {&K11, &K12, &K13, &KEmpty},
       
   221                                         {&K14, &K15_1, &KEmpty, &KEmpty}};
       
   222     
       
   223     CPosLandmarkDatabase* database = OpenDatabaseLC();
       
   224    
       
   225     CPosLandmarkParser* parser = CPosLandmarkParser::NewL(aMime);
       
   226     CleanupStack::PushL(parser);
       
   227     
       
   228     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*database);
       
   229     CleanupStack::PushL(categoryManager);
       
   230     
       
   231     RFile file; 
       
   232     TInt err = file.Open(iFileSession, aFile, EFileRead);
       
   233     if (err != KErrNone) 
       
   234     {
       
   235     	iLog->Log(_L("Error when opening file"));
       
   236         User::Leave(err);
       
   237     }
       
   238     CleanupClosePushL(file);
       
   239     
       
   240     parser->SetInputFileHandleL(file);
       
   241     iOperation = database->ImportLandmarksL(*parser, CPosLandmarkDatabase::EIncludeCategories);
       
   242     
       
   243     ExecuteAndDeleteLD(iOperation);
       
   244     iOperation=NULL;
       
   245     
       
   246     CPosLmItemIterator* iter = database->LandmarkIteratorL();
       
   247     CleanupStack::PushL(iter);
       
   248     
       
   249     CDesCArrayFlat* landmarkNames = new (ELeave) CDesCArrayFlat(KNrOfLandmarks);
       
   250     landmarkNames->AppendL(_L("Billigt"));
       
   251     landmarkNames->AppendL(_L("LOG9"));
       
   252     landmarkNames->AppendL(_L("Kalles Hundgård"));
       
   253     landmarkNames->AppendL(_L("MLFW"));
       
   254     landmarkNames->AppendL(_L("TE, Lund"));
       
   255     landmarkNames->AppendL(_L("asdf"));
       
   256     landmarkNames->AppendL(_L("TP48LandmarkWithAllXMLFields"));
       
   257     landmarkNames->AppendL(_L("TP48Landmark With Empty XML Fields"));
       
   258     
       
   259     TPosLmItemId id = iter->NextL();
       
   260     TInt counter = 0;
       
   261     while (id != KPosLmNullItemId)
       
   262         {
       
   263         CPosLandmark* lm = database->ReadLandmarkLC(id);
       
   264         RArray<TPosLmItemId> arr;
       
   265         CleanupClosePushL(arr);
       
   266         
       
   267         TPtrC name;
       
   268         lm->GetLandmarkName(name);
       
   269         TPtrC expName(landmarkNames->MdcaPoint(counter));
       
   270         iLog->Log(_L("Landmark %d, Actual name '%S', Expected '%S'"), counter, &name, &expName);
       
   271         if (expName.CompareC(name) != KErrNone)
       
   272             {
       
   273             iLog->Log(_L("ERROR: Wrong Landmark Name"));
       
   274             iErrorsFound++;
       
   275             }
       
   276         
       
   277         lm->GetCategoriesL(arr);
       
   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);
       
   321     CleanupStack::PopAndDestroy(parser);
       
   322     CleanupStack::PopAndDestroy(database);
       
   323     }
       
   324 	
       
   325 //  End of File