landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp52.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 #include "FT_CPosTp52.h"
       
    22 #include <EPos_CPosLandmarkDatabase.h>
       
    23 #include <EPos_CPosLandmarkParser.h>
       
    24 #include <EPos_CPosLandmarkEncoder.h>
       
    25 #include <EPos_CPosLandmarkSearch.h>
       
    26 #include <EPos_CPosLmTextCriteria.h>
       
    27 #include <EPos_CPosLMItemIterator.h>
       
    28 #include <Xml/XmlParserErrors.h>
       
    29 #include <LbsPosition.h>
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 _LIT(KErronousXMLFile, "c:\\system\\test\\TestData\\Tp47ErrounousXMLData.xml");
       
    34 _LIT(KErronousXMLFileDataMissing1, "c:\\system\\test\\TestData\\Tp47ErrounousXMLDataMissingFields1.xml");
       
    35 _LIT(KErronousXMLFileDataMissing2, "c:\\system\\test\\TestData\\Tp47ErrounousXMLDataMissingFields2.xml");
       
    36 _LIT(KErronousXMLFileDataMissing3, "c:\\system\\test\\TestData\\Tp47ErrounousXMLDataMissingFields3.xml");
       
    37 _LIT(KUnknownTags, "c:\\system\\test\\TestData\\Tp47UnknownTags.xml");
       
    38 _LIT(KUnknownTrees, "c:\\system\\test\\TestData\\Tp47UnknownTrees.xml");
       
    39 _LIT(KNoEndTag1, "c:\\system\\test\\TestData\\Tp47ErrounousXMLNoEndTag1.xml");
       
    40 _LIT(KNoEndTag2, "c:\\system\\test\\TestData\\Tp47ErrounousXMLNoEndTag2.xml");
       
    41 _LIT(KXMLFileWithLongCategoryName, "c:\\system\\test\\TestData\\Tp47XMLWithLongCategoryName.xml");
       
    42 _LIT(KXMLFileWithLongLandmarkName, "c:\\system\\test\\TestData\\Tp47XMLWithLongName.xml");
       
    43 _LIT(KXMLFileWithLongLatitudeField, "c:\\system\\test\\TestData\\Tp47XMLWithLongLatitudeField.xml");
       
    44 _LIT(KXMLFileWithEmptyCollection, "c:\\system\\test\\TestData\\Tp47ErronousXMLFileEmptyCollection.xml");
       
    45 _LIT(KXMLFileWithXMLTagAsDataField1, "c:\\system\\test\\TestData\\Tp47UsingXMLTagAsDataField1.xml");
       
    46 _LIT(KXMLFileWithXMLTagAsDataField2, "c:\\system\\test\\TestData\\Tp47UsingXMLTagAsDataField2.xml");
       
    47 _LIT(KXMLFileWithXMLTagAsDataField3, "c:\\system\\test\\TestData\\Tp47UsingXMLTagAsDataField3.xml");
       
    48 _LIT(KXMLFileWithQuotedXMLTagAsDataField1, "c:\\system\\test\\TestData\\Tp52QuotedXMLTag1.xml");
       
    49 
       
    50 // ================= MEMBER FUNCTIONS =======================
       
    51 // ---------------------------------------------------------
       
    52 // CPosTp52::CloseTest
       
    53 //
       
    54 // (other items were commented in a header).
       
    55 // ---------------------------------------------------------
       
    56 //
       
    57 void CPosTp52::CloseTest()
       
    58     {
       
    59     iLog->Log(_L("CloseTest"));
       
    60 
       
    61     delete iLandmarkSearch;
       
    62     iLandmarkSearch = NULL;
       
    63 
       
    64 
       
    65     delete iLandmarkParser;
       
    66     iLandmarkParser = NULL;
       
    67 
       
    68 
       
    69     delete iDatabase;
       
    70     iDatabase=NULL;
       
    71     
       
    72     
       
    73     iLog->Log(_L("CloseTest Done"));
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------
       
    77 // CPosTp52::StartL
       
    78 //
       
    79 // (other items were commented in a header).
       
    80 // ---------------------------------------------------------
       
    81 //
       
    82 void CPosTp52::StartL()
       
    83     {
       
    84     iLog->Log(_L("1)) *********************"));
       
    85     DoTestL(KErronousXMLFile, KLmxMimeType, KErrPosLmUnknownFormat);
       
    86     DoTestL(KErronousXMLFile, KGpxMimeType, KErrPosLmUnknownFormat);
       
    87 
       
    88     iLog->Log(_L("2)) *********************"));
       
    89     DoTestL(KUnknownTags, KLmxMimeType, KErrNone, 1);
       
    90     DoTestL(KUnknownTags, KGpxMimeType, KErrNone, 1);
       
    91 
       
    92     DoTestL(KUnknownTrees, KLmxMimeType, KErrNone, 1);
       
    93     DoTestL(KUnknownTrees, KGpxMimeType, KErrNone, 1);
       
    94     
       
    95     iLog->Log(_L("3)) *********************"));
       
    96     DoTestL(KNoEndTag1, KLmxMimeType, EXmlTagMismatch, 0);
       
    97     DoTestL(KNoEndTag1, KGpxMimeType, EXmlTagMismatch, 0);
       
    98 
       
    99     iLog->Log(_L("4)) *********************"));
       
   100     DoTestL(KNoEndTag2, KLmxMimeType, KErrPosLmUnknownFormat, 0);
       
   101     DoTestL(KNoEndTag2, KGpxMimeType, KErrPosLmUnknownFormat, 0);
       
   102 
       
   103     // Containing XML tags as data field
       
   104     iLog->Log(_L("5)) *********************"));
       
   105     DoTestL(KXMLFileWithXMLTagAsDataField1, KLmxMimeType, EXmlTagMismatch, 0);
       
   106     DoTestL(KXMLFileWithXMLTagAsDataField1, KGpxMimeType, EXmlTagMismatch, 0);
       
   107     
       
   108     // Containing XML tags as data field
       
   109     iLog->Log(_L("6)) *********************"));
       
   110     DoTestL(KXMLFileWithXMLTagAsDataField2, KLmxMimeType, EXmlTagMismatch, 0);
       
   111     DoTestL(KXMLFileWithXMLTagAsDataField2, KGpxMimeType, EXmlTagMismatch, 0);
       
   112 
       
   113     // Containing XML tags as data field
       
   114     iLog->Log(_L("7)) *********************"));
       
   115     DoTestL(KXMLFileWithXMLTagAsDataField3, KLmxMimeType, EXmlTagMismatch, 0);
       
   116     DoTestL(KXMLFileWithXMLTagAsDataField3, KGpxMimeType, EXmlTagMismatch, 0);
       
   117 
       
   118     iLog->Log(_L("8)) *********************"));
       
   119     DoTestL(KXMLFileWithEmptyCollection, KLmxMimeType, KErrPosLmUnknownFormat, 0);
       
   120     // N/A for GPX
       
   121 
       
   122     iLog->Log(_L("9)) *********************"));
       
   123     DoTestL(KXMLFileWithLongCategoryName, KLmxMimeType, KErrNone, 1);
       
   124     CheckLongCategoryNameL(4);
       
   125     DoTestL(KXMLFileWithLongCategoryName, KGpxMimeType, KErrNone, 1);
       
   126     CheckLongCategoryNameL(1);
       
   127 
       
   128     iLog->Log(_L("10)) *********************"));
       
   129     DoTestL(KXMLFileWithLongLandmarkName, KLmxMimeType, KErrNone, 1);
       
   130     CheckLongLandmarkNameL();
       
   131     DoTestL(KXMLFileWithLongLandmarkName, KGpxMimeType, KErrNone, 1);
       
   132     CheckLongLandmarkNameL();
       
   133 
       
   134     iLog->Log(_L("11)) *********************"));
       
   135     DoTestL(KXMLFileWithLongLatitudeField, KLmxMimeType, KErrNone, 1);
       
   136     DoTestL(KXMLFileWithLongLatitudeField, KGpxMimeType, KErrNone, 1);
       
   137 
       
   138     iLog->Log(_L("12)) *********************"));
       
   139     DoTestL(KErronousXMLFileDataMissing1, KLmxMimeType, KErrPosLmUnknownFormat, 0);
       
   140     DoTestL(KErronousXMLFileDataMissing1, KGpxMimeType, KErrPosLmUnknownFormat, 0);
       
   141 
       
   142     iLog->Log(_L("13)) *********************"));
       
   143     DoTestL(KErronousXMLFileDataMissing2, KLmxMimeType, KErrNone, 1);
       
   144     DoTestL(KErronousXMLFileDataMissing2, KGpxMimeType, KErrNone, 1);
       
   145 
       
   146     iLog->Log(_L("14)) *********************"));
       
   147     DoTestL(KErronousXMLFileDataMissing3, KLmxMimeType, KErrNone, 1);
       
   148     DoTestL(KErronousXMLFileDataMissing3, KGpxMimeType, KErrNone, 1);
       
   149     
       
   150     iLog->Log(_L("15)) *********************"));
       
   151     DoTestL(KXMLFileWithQuotedXMLTagAsDataField1, KLmxMimeType, KErrNone, 2);
       
   152     DoTestL(KXMLFileWithQuotedXMLTagAsDataField1, KGpxMimeType, KErrNone, 2);
       
   153 
       
   154     if (iErrorsFound != KErrNone)
       
   155         {
       
   156         iLog->Log(_L("Errors were found in Tp52"));
       
   157         User::Leave(-1);
       
   158         }
       
   159 	}
       
   160 
       
   161 // ---------------------------------------------------------
       
   162 // CPosTp52::DoTestL
       
   163 //
       
   164 // (other items were commented in a header).
       
   165 // ---------------------------------------------------------
       
   166 //
       
   167 void CPosTp52::DoTestL(
       
   168     const TDesC&  aTestFile, 
       
   169     const TDesC8& aMimeType,
       
   170     TInt aExpectedErrorCode, 
       
   171     TInt aExpNrImportedLandmarks )
       
   172     {
       
   173     TBuf<150> buf;
       
   174     TInt nr=0;
       
   175     ResetLandmarksDbL();
       
   176 
       
   177     TFileName file( aTestFile );
       
   178     if ( aMimeType == KGpxMimeType )
       
   179         {
       
   180         TInt pos = file.Find( KXmlFileExt );
       
   181         file.Replace( pos, KXmlFileExt().Length(), KGpxFileExt );
       
   182         }
       
   183     
       
   184     iLog->Log(_L("FILE (%S)"), &file );
       
   185     iLandmarkParser = CPosLandmarkParser::NewL(aMimeType);
       
   186     iLandmarkParser->SetInputFileL(file);
       
   187     
       
   188     TInt errorCode = 0;
       
   189     // Test sync
       
   190     errorCode = ImportLandmarksL(ETrue, CPosLandmarkDatabase::EIncludeCategories);
       
   191 
       
   192     if (errorCode != aExpectedErrorCode)
       
   193         {
       
   194         buf.Format(_L("ERROR: Errorcode %d , should be %d when importing from "), errorCode, aExpectedErrorCode);
       
   195         buf.Append(file);
       
   196         iLog->Log(buf);
       
   197         iErrorsFound++;
       
   198         }
       
   199     else
       
   200         {
       
   201         buf.Format(_L("Correct errorcode %d returned when from "), errorCode);
       
   202         buf.Append(file);
       
   203         iLog->Log(buf);
       
   204         }
       
   205     
       
   206     delete iLandmarkParser;
       
   207     iLandmarkParser = NULL;
       
   208 
       
   209     nr = GetNrOfLandmarksL();
       
   210     if (nr != aExpNrImportedLandmarks)
       
   211         {
       
   212         buf.Format(_L("ERROR: Found %d landmarks should found %d"), nr, aExpNrImportedLandmarks);
       
   213         iLog->Log(buf);
       
   214         iErrorsFound++;
       
   215         }
       
   216     
       
   217     ResetLandmarksDbL();
       
   218 
       
   219     iLandmarkParser = CPosLandmarkParser::NewL(aMimeType);
       
   220     iLandmarkParser->SetInputFileL(file);
       
   221 
       
   222     // Test async
       
   223     errorCode = ImportLandmarksL(ETrue, CPosLandmarkDatabase::EIncludeCategories);
       
   224 
       
   225     if (errorCode != aExpectedErrorCode)
       
   226         {
       
   227         buf.Format(_L("ERROR: Errorcode %d , should be %d when importing from "), errorCode, aExpectedErrorCode);
       
   228         buf.Append(file);
       
   229         iLog->Log(buf);
       
   230         iErrorsFound++;
       
   231         }
       
   232     else
       
   233         {
       
   234         buf.Format(_L("Correct errorcode %d returned when importing landmarks from file "), errorCode);
       
   235         buf.Append(file);
       
   236         iLog->Log(buf);
       
   237         }
       
   238     
       
   239     delete iLandmarkParser;
       
   240     iLandmarkParser = NULL;
       
   241 
       
   242     nr = GetNrOfLandmarksL();
       
   243     if (nr != aExpNrImportedLandmarks)
       
   244         {
       
   245         buf.Format(_L("ERROR: Found %d landmarks should found %d"), nr, aExpNrImportedLandmarks);
       
   246         iLog->Log(buf);
       
   247         iErrorsFound++;
       
   248         }
       
   249     }
       
   250 
       
   251 // ---------------------------------------------------------
       
   252 // CPosTp52::ImportLandmarksL
       
   253 //
       
   254 // (other items were commented in a header).
       
   255 // ---------------------------------------------------------
       
   256 //
       
   257 TInt CPosTp52::ImportLandmarksL(TBool aSync, TUint aTransferOption)
       
   258     {
       
   259     iLog->Log(_L("ImportLandmarksL"));
       
   260 
       
   261     //TRequestStatus status = KPosLmOperationNotComplete;
       
   262     //TReal32 progress = 0;
       
   263     TInt err = KErrNone;
       
   264     
       
   265     CPosLmOperation* op;
       
   266     op = iDatabase->ImportLandmarksL(*iLandmarkParser, aTransferOption);
       
   267 
       
   268     CleanupStack::PushL(op);
       
   269     // Import only a subset of the landmarks in parser
       
   270     // iOperation = iDatabase->ImportLandmarksL(*iLandmarkParser, aLandmarkSubSet,  aTransferOption);
       
   271     if (aSync)
       
   272         {
       
   273         // Synchronous
       
   274         TRAP(err, op->ExecuteL());
       
   275         iOperation = NULL;
       
   276         }
       
   277     else
       
   278         {
       
   279         // Asynchronous
       
   280         // Progress us checked in test procedure base
       
   281         RunAsyncOperationLD(iDatabase->ImportLandmarksL(*iLandmarkParser, aTransferOption));
       
   282         iOperation = NULL;
       
   283         }
       
   284     CleanupStack::PopAndDestroy(op);
       
   285     return err;
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------
       
   289 // CPosTp52::ResetLandmarksDbL
       
   290 //
       
   291 // (other items were commented in a header).
       
   292 // ---------------------------------------------------------
       
   293 //
       
   294 void CPosTp52::ResetLandmarksDbL()
       
   295     {
       
   296     iLog->Log(_L("ResetLandmarksDbL()"));
       
   297     
       
   298     delete iLandmarkSearch;
       
   299     iLandmarkSearch = NULL;
       
   300 
       
   301     delete iLandmarkParser;
       
   302     iLandmarkParser = NULL;
       
   303 
       
   304     delete iDatabase;
       
   305     iDatabase=NULL;
       
   306 
       
   307 
       
   308     // Use an empty landmarks db in this test
       
   309     RemoveDefaultDbL();
       
   310     iDatabase = CPosLandmarkDatabase::OpenL();
       
   311     if (iDatabase->IsInitializingNeeded())
       
   312         {
       
   313         ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   314         }    
       
   315     
       
   316     delete iDatabase;
       
   317     iDatabase = NULL;
       
   318     iDatabase = CPosLandmarkDatabase::OpenL();
       
   319     // Do reset so that global categories are included
       
   320     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   321     CleanupStack::PushL(categoryManager);   
       
   322     ExecuteAndDeleteLD(categoryManager->ResetGlobalCategoriesL());
       
   323     CleanupStack::PopAndDestroy(categoryManager);
       
   324     }
       
   325 
       
   326 // ---------------------------------------------------------
       
   327 // CPosTp52::CheckLongLandmarkNameL
       
   328 //
       
   329 // (other items were commented in a header).
       
   330 // ---------------------------------------------------------
       
   331 //
       
   332 void CPosTp52::CheckLongLandmarkNameL()
       
   333     {
       
   334     iLog->Log(_L("CheckLandmarkL"));
       
   335     // Should only exist one landmark in db
       
   336     CPosLandmark* lm = iDatabase->ReadLandmarkLC(1);
       
   337 
       
   338     TPtrC lmname;
       
   339     TInt res = lm->GetLandmarkName(lmname);
       
   340 
       
   341     if (res != KErrNone) //LogErrorAndLeave(_L("Problem getting Landmark"));
       
   342     {
       
   343         iLog->Log(_L("Problem getting Landmark"));
       
   344         User::Leave(-1);
       
   345 
       
   346     }
       
   347 
       
   348     _LIT(KLONGNAME, "Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landmark10Landm");
       
   349     if (lmname.Compare(KLONGNAME) != 0)
       
   350         {
       
   351         iLog->Log(_L("Long landmark name does not match"));
       
   352         iErrorsFound++;
       
   353         }
       
   354 
       
   355     CleanupStack::PopAndDestroy(lm);
       
   356     }
       
   357 
       
   358 // ---------------------------------------------------------
       
   359 // CPosTp52::CheckLongCategoryNameL
       
   360 //
       
   361 // (other items were commented in a header).
       
   362 // ---------------------------------------------------------
       
   363 //
       
   364 void CPosTp52::CheckLongCategoryNameL(TInt aNumExpectedCategories )
       
   365     {
       
   366     iLog->Log(_L("CheckLongCategoryNameL"));
       
   367     // Should only exist one landmark in db
       
   368     CPosLandmark* lm = iDatabase->ReadLandmarkLC(1);
       
   369 
       
   370     RArray<TPosLmItemId> array;
       
   371     CleanupClosePushL(array);
       
   372     lm->GetCategoriesL(array);
       
   373     TInt nr = array.Count();
       
   374     TPtrC name;
       
   375 
       
   376     _LIT(KLONGNAME1, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234");
       
   377     _LIT(KLONGNAME2, "Pizzeria10Pizzeria20Pizzeria30Pizzeria40Pizzeria50Pizzeria60Pizzeria70Pizzeria80Pizzeria90Pizzeria10Pizzeria10Pizzeria20Pizz");
       
   378     _LIT(KLONGNAME3, "Gizzeria10Gizzeria20Gizzeria30Gizzeria40Gizzeria50Gizzeria60Gizzeria70Gizzeria80Gizzeria90Gizzeria10Gizzeria10Gizzeria20_ABC");
       
   379     _LIT(KLONGNAME4, "Dizzeria10Dizzeria20Dizzeria30Dizzeria40Dizzeria50Dizzeria60Dizzeria70Dizzeria80Dizzeria90Dizzeria10Dizzeria10Dizzeria20_ABC");
       
   380 
       
   381     const TInt numNames = 4;
       
   382     const TPtrC names[] = { KLONGNAME1(), KLONGNAME2(), KLONGNAME3(), KLONGNAME4() };
       
   383     
       
   384     if (nr != aNumExpectedCategories) //LogErrorAndLeave(_L("Wrong number of categories for landmark"));
       
   385     {
       
   386         iLog->Log(_L("Wrong number of categories for landmark"));
       
   387         User::Leave(-1);
       
   388     }
       
   389 
       
   390     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   391     CleanupStack::PushL(categoryManager);
       
   392     
       
   393     for ( TInt i = 0; i < aNumExpectedCategories; i++ )
       
   394         {
       
   395         CPosLandmarkCategory* cat = categoryManager->ReadCategoryLC(array[i]);
       
   396 
       
   397         cat->GetCategoryName(name);
       
   398         // Maximum size for category name is 124 characters
       
   399         if (name.Length() != 124) 
       
   400         {
       
   401             iLog->Log(_L("Category name has wrong size, should be 124"));
       
   402             User::Leave(-1);
       
   403 
       
   404         }
       
   405         if (name.Compare(names[i]) != 0) 
       
   406             {
       
   407             iLog->Log(_L("Long category name does not match"));
       
   408             iErrorsFound++;
       
   409             }
       
   410         CleanupStack::PopAndDestroy(cat);
       
   411         }
       
   412 
       
   413     CleanupStack::PopAndDestroy(categoryManager);
       
   414 
       
   415     CleanupStack::PopAndDestroy(&array);
       
   416     CleanupStack::PopAndDestroy(lm);
       
   417     }
       
   418 
       
   419 // ---------------------------------------------------------
       
   420 // CPosTp52::GetNrOfLandmarksL
       
   421 //
       
   422 // (other items were commented in a header).
       
   423 // ---------------------------------------------------------
       
   424 //
       
   425 TInt CPosTp52::GetNrOfLandmarksL()
       
   426     {
       
   427     TInt nrOfLandmarks = 0;
       
   428     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   429     // Search pattern "*" should match all existing landmarks
       
   430     textCriteria->SetTextL(_L("*"));
       
   431 
       
   432     CPosLandmarkSearch* landmarkSearch = CPosLandmarkSearch::NewL(*iDatabase);
       
   433     CleanupStack::PushL(landmarkSearch);
       
   434 
       
   435     TPosLmSortPref sortAsc(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   436     ExecuteAndDeleteLD(landmarkSearch->StartLandmarkSearchL(
       
   437                 *textCriteria, 
       
   438                 sortAsc,
       
   439                 EFalse));
       
   440 
       
   441     CPosLmItemIterator* iter = landmarkSearch->MatchIteratorL();
       
   442     CleanupStack::PushL(iter);
       
   443 
       
   444     nrOfLandmarks = iter->NumOfItemsL();
       
   445     CleanupStack::PopAndDestroy(iter);
       
   446     CleanupStack::PopAndDestroy(landmarkSearch);
       
   447     CleanupStack::PopAndDestroy(textCriteria);
       
   448     return nrOfLandmarks;
       
   449     }
       
   450 
       
   451 //  End of File