landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp48.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_CPosTp48.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 <LbsPosition.h>
       
    29 #include <bautils.h>
       
    30 
       
    31 // CONSTANTS
       
    32 _LIT(KXMLFile, "c:\\documents\\Tp48.xml");
       
    33 // Filename with 260 characters
       
    34 _LIT(KLongFileName, "c:\\File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File123456File12");
       
    35 _LIT(KEmptyFileName1, "c:\\");
       
    36 _LIT(KEmptyFileName2, "");
       
    37 _LIT(KNonExistingFileName, "c:\\NonExistingFile.xml");
       
    38 
       
    39 _LIT(KNewGlobalCategory, "OutSight");
       
    40 
       
    41 const TInt KOrigGlobalCategoryId = 45000;// "Transport"
       
    42 
       
    43 //#define DEBUG EFalse
       
    44 #define DEBUG ETrue
       
    45 // ================= MEMBER FUNCTIONS =======================
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // CPosTp48::CloseTest
       
    49 //
       
    50 // (other items were commented in a header).
       
    51 // ---------------------------------------------------------
       
    52 //
       
    53 void CPosTp48::CloseTest()
       
    54     {
       
    55     iLog->Log(_L("CloseTest"));
       
    56 
       
    57     delete iLandmarkSearch;
       
    58     iLandmarkSearch = NULL;
       
    59 
       
    60     iLandmarks.ResetAndDestroy();
       
    61     iLandmarks.Close();
       
    62 
       
    63     delete iLandmarkParser;
       
    64     iLandmarkParser = NULL;
       
    65 
       
    66     delete iLandmarkEncoder;
       
    67     iLandmarkEncoder = NULL;
       
    68 
       
    69     delete iOperation;
       
    70     iOperation = NULL;
       
    71 
       
    72     delete iDatabase;
       
    73     iDatabase=NULL;
       
    74     
       
    75     delete iEncoderBuffer;
       
    76     iEncoderBuffer = NULL;
       
    77 
       
    78     iLog->Log(_L("CloseTest Done"));
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------
       
    82 // CPosTp48::StartL
       
    83 //
       
    84 // (other items were commented in a header).
       
    85 // ---------------------------------------------------------
       
    86 //
       
    87 void CPosTp48::StartL()
       
    88     {
       
    89     BaflUtils::EnsurePathExistsL( iFileSession, KXMLFile );
       
    90 
       
    91     TInt lang = User::Language();
       
    92     iLog->Log(_L("StartL"));
       
    93    
       
    94     // Use file
       
    95     DoTestL(ETrue, EFalse);
       
    96 
       
    97     // Use buffer
       
    98     DoTestL(EFalse, EFalse);
       
    99 
       
   100     // Use file, parse XML content before import
       
   101     DoTestL(ETrue, ETrue);
       
   102 
       
   103     // Use buffer, parse XML content before import
       
   104     DoTestL(EFalse, ETrue);
       
   105 
       
   106     // Use file, cancel before complete
       
   107     iLog->Log(_L("Use file, cancel before complete"));
       
   108     DoTestL(ETrue, EFalse, EFalse, ETrue);
       
   109 
       
   110     iLog->Log(_L("Use buffer, cancel before complete"));
       
   111     // Use buffer, cancel before complete
       
   112     DoTestL(EFalse, EFalse, EFalse, ETrue);
       
   113 
       
   114     ResetLandmarksDbL();
       
   115     DeleteFileL(KXMLFile);
       
   116     
       
   117     iLandmarkEncoder = CPosLandmarkEncoder::NewL(KLmxMimeType);
       
   118     // Use file for encoding, set output file
       
   119     iLandmarkEncoder->SetOutputFileL(KXMLFile);
       
   120     CreateXMLDataL();
       
   121     delete iLandmarkEncoder;
       
   122     iLandmarkEncoder = NULL;
       
   123 
       
   124     // Remove one global category
       
   125     iLog->Log(_L("TC_Step10 Delete one global category"));
       
   126     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   127     CleanupStack::PushL(categoryManager);
       
   128     // Remove global category "Hotel global id=4"
       
   129     
       
   130     TPosLmItemId id = categoryManager->GetGlobalCategoryL(39000);
       
   131     ExecuteAndDeleteLD(categoryManager->RemoveCategoryL(id));
       
   132     
       
   133     //Verify removed
       
   134     
       
   135     id = categoryManager->GetGlobalCategoryL(39000);
       
   136     if (id != KPosLmNullItemId) 
       
   137     {
       
   138     	iLog->Log(_L("Global category has not been removed"));
       
   139     	User::Leave(-1);
       
   140     }
       
   141 
       
   142     iLandmarkParser = CPosLandmarkParser::NewL(KLmxMimeType);
       
   143     iLandmarkParser->SetInputFileL(KXMLFile);
       
   144     
       
   145     iLog->Log(_L("TC_Step11 Import all landmarks"));    
       
   146     ExecuteAndDeleteLD(iDatabase->ImportLandmarksL(*iLandmarkParser, CPosLandmarkDatabase::EIncludeCategories));
       
   147 
       
   148     delete iLandmarkParser;
       
   149     iLandmarkParser = NULL;
       
   150 
       
   151     //Verify that global category has been added again, since it is predefined it should be 
       
   152     // imported as a global category (otherwise it should be a local category)
       
   153    
       
   154     id = categoryManager->GetGlobalCategoryL(39000);
       
   155     if (id == KPosLmNullItemId) iLog->Log(_L("Global category has not been added"));
       
   156 
       
   157 	CPosLandmarkCategory* catte = categoryManager->ReadCategoryLC(id);
       
   158 
       
   159     if (catte->GlobalCategory() == KPosLmNullGlobalCategory) iLog->Log(_L("  Not global category"));
       
   160    
       
   161     CleanupStack::PopAndDestroy(catte);
       
   162 
       
   163     ResetLandmarksDbL();
       
   164     DeleteFileL(KXMLFile);
       
   165     
       
   166     CleanupStack::PopAndDestroy(categoryManager);
       
   167     categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   168     CleanupStack::PushL(categoryManager);
       
   169     
       
   170     iLandmarkEncoder = CPosLandmarkEncoder::NewL(KLmxMimeType);
       
   171     // Use file for encoding, set output file
       
   172     iLandmarkEncoder->SetOutputFileL(KXMLFile);
       
   173     CreateXMLDataL();
       
   174     delete iLandmarkEncoder;
       
   175     iLandmarkEncoder = NULL;
       
   176 
       
   177     // Rename one global category
       
   178     // Rename global category "Shop global id=5" to Nisses BilAffär
       
   179     iLog->Log(_L("TC_Step12 Rename one global category"));
       
   180     id = categoryManager->GetGlobalCategoryL(15000);
       
   181     catte = categoryManager->ReadCategoryLC(id);
       
   182     catte->SetCategoryNameL(_L("Nisses BilAffär"));
       
   183     categoryManager->UpdateCategoryL(*catte);
       
   184     CleanupStack::PopAndDestroy(catte);
       
   185 
       
   186     iLandmarkParser = CPosLandmarkParser::NewL(KLmxMimeType);
       
   187     iLandmarkParser->SetInputFileL(KXMLFile);
       
   188     
       
   189     iLog->Log(_L("TC_Step13 Import all landmarks"));
       
   190     ExecuteAndDeleteLD(iDatabase->ImportLandmarksL(*iLandmarkParser, CPosLandmarkDatabase::EIncludeCategories));
       
   191 
       
   192     delete iLandmarkParser;
       
   193     iLandmarkParser = NULL;
       
   194 
       
   195     //Verify that global category has been added again, since it is predefined it should be 
       
   196     // imported as a global category (otherwise it should be a local category)
       
   197     
       
   198     TPosLmItemId id1 = categoryManager->GetGlobalCategoryL(15000);
       
   199     if (id1 == KPosLmNullItemId) iLog->Log(_L("Global category has not been added"));
       
   200 
       
   201     TPosLmItemId id2 = categoryManager->GetCategoryL(_L("Nisses BilAffär"));
       
   202     if (id2 == KPosLmNullItemId) iLog->Log(_L("Global category has not been added 2"));
       
   203 
       
   204     if (id1 != id2) 
       
   205     {
       
   206     	iLog->Log(_L("Categories should have the same id"));
       
   207     	User::Leave(-1);
       
   208     }
       
   209 
       
   210     catte = categoryManager->ReadCategoryLC(id1);
       
   211     if (catte->GlobalCategory() == KPosLmNullGlobalCategory) iLog->Log(_L("Nisses Bilaffär is no global category"));
       
   212 
       
   213     id = categoryManager->GetCategoryL(_L("Shop"));
       
   214     if (id != KPosLmNullItemId) iLog->Log(_L("Shop should not exist"));
       
   215   
       
   216     CleanupStack::PopAndDestroy(catte);
       
   217     CleanupStack::PopAndDestroy(categoryManager);
       
   218 
       
   219     iLog->Log(_L("TC_Step14 Test import with long file name"));
       
   220     ImportFromFileWithLongFileNameL();
       
   221 
       
   222     iLog->Log(_L("TC_Step15 Change "));
       
   223     DoTestChangeInputMethodL();
       
   224     
       
   225     if (iErrorsFound != KErrNone)
       
   226         {
       
   227        
       
   228        	iLog->Log(_L("Errors were found in TP48"));
       
   229     	User::Leave(-1);
       
   230         }
       
   231 
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------
       
   235 // CPosTp48::DoTestL
       
   236 //
       
   237 // (other items were commented in a header).
       
   238 // ---------------------------------------------------------
       
   239 //
       
   240 void CPosTp48::DoTestL(TBool aFile, TBool aFullParse, TBool aDoParse, TBool aCancel)
       
   241     {
       
   242     iLog->Log(_L("DoTestL"));
       
   243 
       
   244     // find localized name of needed category
       
   245     HBufC* origGlobalCategory = GetGlobalCategoryFromResourceLC( KOrigGlobalCategoryId );
       
   246 
       
   247     RArray<TUint> subset;
       
   248     CleanupClosePushL(subset);
       
   249 
       
   250     ResetLandmarksDbL();
       
   251     DeleteFileL(KXMLFile);
       
   252 
       
   253     HBufC8* bufferContent = NULL;
       
   254 
       
   255     iLandmarkEncoder = CPosLandmarkEncoder::NewL(KLmxMimeType);
       
   256     if (aFile)
       
   257         {
       
   258         // Use file for encoding, set output file
       
   259         iLandmarkEncoder->SetOutputFileL(KXMLFile);
       
   260         }
       
   261     else 
       
   262         {
       
   263         // Use buffer for encoding
       
   264         iEncoderBuffer = iLandmarkEncoder->SetUseOutputBufferL();
       
   265         }
       
   266 
       
   267     CreateXMLDataL();
       
   268     delete iLandmarkEncoder;
       
   269     iLandmarkEncoder = NULL;
       
   270     iLandmarkParser = CPosLandmarkParser::NewL(KLmxMimeType);
       
   271 
       
   272     if (aFile)
       
   273         {
       
   274         iLog->Log(_L("TC_Step2 Set input to be parsed from XML File"));
       
   275         iLandmarkParser->SetInputFileL(KXMLFile);
       
   276         }
       
   277     else
       
   278         {
       
   279         iLog->Log(_L("TC_Step2 Set input to be parsed from buffer"));
       
   280         bufferContent = HBufC8::NewLC(iEncoderBuffer->Size());
       
   281         TPtr8 ptr = bufferContent->Des();
       
   282         iEncoderBuffer->Read(0, ptr, iEncoderBuffer->Size());
       
   283         iLandmarkParser->SetInputBuffer(*bufferContent);
       
   284         }
       
   285     
       
   286     iLog->Log(_L("TC_Step3 Import all landmarks Synchronously"));
       
   287     ImportLandmarksL(ETrue, aFullParse, CPosLandmarkDatabase::EDefaultOptions, subset, aDoParse, aCancel);
       
   288     delete iLandmarkParser;
       
   289     iLandmarkParser = NULL;
       
   290     if (!aFile) CleanupStack::PopAndDestroy(bufferContent);
       
   291 
       
   292     ResetLandmarksDbL();
       
   293     DeleteFileL(KXMLFile);
       
   294     iLandmarkEncoder = CPosLandmarkEncoder::NewL(KLmxMimeType);
       
   295     // Use file for encoding, set output file
       
   296     iLandmarkEncoder->SetOutputFileL(KXMLFile);
       
   297     CreateXMLDataL();
       
   298     delete iLandmarkEncoder;
       
   299     iLandmarkEncoder = NULL;
       
   300     iLandmarkParser = CPosLandmarkParser::NewL(KLmxMimeType);
       
   301     
       
   302     if (aFile)
       
   303         {
       
   304         iLog->Log(_L("TC_Step3 Set input to be parsed from XML File"));
       
   305         iLandmarkParser->SetInputFileL(KXMLFile);
       
   306         }
       
   307     else
       
   308         {
       
   309         iLog->Log(_L("TC_Step3 Set input to be parsed from buffer"));
       
   310         bufferContent = HBufC8::NewLC(iEncoderBuffer->Size());
       
   311         TPtr8 ptr = bufferContent->Des();
       
   312         iEncoderBuffer->Read(0, ptr, iEncoderBuffer->Size());
       
   313         iLandmarkParser->SetInputBuffer(*bufferContent);
       
   314         }
       
   315 
       
   316     iLog->Log(_L("TC_Step3 Import all landmarks Asynchronously"));
       
   317     ImportLandmarksL(EFalse, aFullParse, CPosLandmarkDatabase::EDefaultOptions, subset, aDoParse, aCancel);
       
   318     delete iLandmarkParser;
       
   319     iLandmarkParser = NULL;
       
   320     if (!aFile) CleanupStack::PopAndDestroy(bufferContent);
       
   321 
       
   322     ResetLandmarksDbL();
       
   323     DeleteFileL(KXMLFile);
       
   324     iLandmarkEncoder = CPosLandmarkEncoder::NewL(KLmxMimeType);
       
   325     // Use file for encoding, set output file
       
   326     iLandmarkEncoder->SetOutputFileL(KXMLFile);
       
   327     CreateXMLDataL();
       
   328     delete iLandmarkEncoder;
       
   329     iLandmarkEncoder = NULL;
       
   330     iLandmarkParser = CPosLandmarkParser::NewL(KLmxMimeType);
       
   331     
       
   332     if (aFile)
       
   333         {
       
   334         iLog->Log(_L("TC_Step3 Set input to be parsed from XML File"));
       
   335         iLandmarkParser->SetInputFileL(KXMLFile);
       
   336         }
       
   337     else
       
   338         {
       
   339         iLog->Log(_L("TC_Step3 Set input to be parsed from buffer"));
       
   340         bufferContent = HBufC8::NewLC(iEncoderBuffer->Size());
       
   341         TPtr8 ptr = bufferContent->Des();
       
   342         iEncoderBuffer->Read(0, ptr, iEncoderBuffer->Size());
       
   343         iLandmarkParser->SetInputBuffer(*bufferContent);
       
   344         }
       
   345 
       
   346     iLog->Log(_L("TC_Step3 Import all landmarks Synchronously"));
       
   347     ImportLandmarksL(ETrue, aFullParse, CPosLandmarkDatabase::EDefaultOptions, subset, aDoParse, aCancel);
       
   348     delete iLandmarkParser;
       
   349     iLandmarkParser = NULL;
       
   350     if (!aFile) CleanupStack::PopAndDestroy(bufferContent);
       
   351        
       
   352     // Only import a subset of landmarks
       
   353     iLog->Log(_L("TC_Step4 Only import a subset of landmarks, Sync"));
       
   354     ResetLandmarksDbL();
       
   355     DeleteFileL(KXMLFile);
       
   356     iLandmarkEncoder = CPosLandmarkEncoder::NewL(KLmxMimeType);
       
   357     // Use file for encoding, set output file
       
   358     iLandmarkEncoder->SetOutputFileL(KXMLFile);
       
   359     CreateXMLDataL();
       
   360     delete iLandmarkEncoder;
       
   361     iLandmarkEncoder = NULL;
       
   362     iLandmarkParser = CPosLandmarkParser::NewL(KLmxMimeType);
       
   363     
       
   364     if (aFile)
       
   365         {
       
   366         iLog->Log(_L("TC_Step4 Set input to be parsed from XML File"));
       
   367         iLandmarkParser->SetInputFileL(KXMLFile);
       
   368         }
       
   369     else
       
   370         {
       
   371         iLog->Log(_L("TC_Step4 Set input to be parsed from buffer"));
       
   372         bufferContent = HBufC8::NewLC(iEncoderBuffer->Size());
       
   373         TPtr8 ptr = bufferContent->Des();
       
   374         iEncoderBuffer->Read(0, ptr, iEncoderBuffer->Size());
       
   375         iLandmarkParser->SetInputBuffer(*bufferContent);
       
   376         }
       
   377     
       
   378     subset.Append(0);
       
   379     subset.Append(1);
       
   380     subset.Append(2);
       
   381     subset.Append(3);
       
   382 
       
   383     delete iLandmarks[7];
       
   384     delete iLandmarks[6];
       
   385     delete iLandmarks[5];
       
   386     delete iLandmarks[4];
       
   387 
       
   388     iLandmarks.Remove(7);
       
   389     iLandmarks.Remove(6);
       
   390     iLandmarks.Remove(5);
       
   391     iLandmarks.Remove(4);
       
   392 
       
   393     ImportLandmarksL(ETrue, aFullParse, CPosLandmarkDatabase::EDefaultOptions, subset, aDoParse, aCancel);
       
   394     delete iLandmarkParser;
       
   395     iLandmarkParser = NULL;
       
   396     if (!aFile) CleanupStack::PopAndDestroy(bufferContent);
       
   397     subset.Reset();
       
   398 
       
   399     // Only import a subset of landmarks
       
   400     iLog->Log(_L("TC_Step4 Only import a subset of landmarks, Async"));
       
   401     ResetLandmarksDbL();
       
   402     DeleteFileL(KXMLFile);
       
   403     iLandmarkEncoder = CPosLandmarkEncoder::NewL(KLmxMimeType);
       
   404     // Use file for encoding, set output file
       
   405     iLandmarkEncoder->SetOutputFileL(KXMLFile);
       
   406     CreateXMLDataL();
       
   407     delete iLandmarkEncoder;
       
   408     iLandmarkEncoder = NULL;
       
   409     iLandmarkParser = CPosLandmarkParser::NewL(KLmxMimeType);
       
   410     
       
   411     if (aFile)
       
   412         {
       
   413         iLog->Log(_L("TC_Step4 Set input to be parsed from XML File"));
       
   414         iLandmarkParser->SetInputFileL(KXMLFile);
       
   415         }
       
   416     else
       
   417         {
       
   418         iLog->Log(_L("TC_Step4 Set input to be parsed from buffer"));
       
   419         bufferContent = HBufC8::NewLC(iEncoderBuffer->Size());
       
   420         TPtr8 ptr = bufferContent->Des();
       
   421         iEncoderBuffer->Read(0, ptr, iEncoderBuffer->Size());
       
   422         iLandmarkParser->SetInputBuffer(*bufferContent);
       
   423         }
       
   424     
       
   425     subset.Append(0);
       
   426     subset.Append(1);
       
   427     subset.Append(2);
       
   428     subset.Append(3);
       
   429 
       
   430     delete iLandmarks[7];
       
   431     delete iLandmarks[6];
       
   432     delete iLandmarks[5];
       
   433     delete iLandmarks[4];
       
   434 
       
   435     iLandmarks.Remove(7);
       
   436     iLandmarks.Remove(6);
       
   437     iLandmarks.Remove(5);
       
   438     iLandmarks.Remove(4);
       
   439 
       
   440     ImportLandmarksL(EFalse, aFullParse, CPosLandmarkDatabase::EDefaultOptions, subset, aDoParse, aCancel);
       
   441     delete iLandmarkParser;
       
   442     iLandmarkParser = NULL;
       
   443     if (!aFile) CleanupStack::PopAndDestroy(bufferContent);
       
   444     subset.Reset();
       
   445     
       
   446     iLog->Log(_L("TC_Step5 Only import a subset of landmarks, use EIncludeCategories, ASync"));
       
   447     ResetLandmarksDbL();
       
   448     subset.Reset();
       
   449     DeleteFileL(KXMLFile);
       
   450     iLandmarkEncoder = CPosLandmarkEncoder::NewL(KLmxMimeType);
       
   451     // Use file for encoding, set output file
       
   452     iLandmarkEncoder->SetOutputFileL(KXMLFile);
       
   453     CreateXMLDataL();
       
   454     delete iLandmarkEncoder;
       
   455     iLandmarkEncoder = NULL;
       
   456     iLandmarkParser = CPosLandmarkParser::NewL(KLmxMimeType);
       
   457     
       
   458     if (aFile)
       
   459         {
       
   460         iLog->Log(_L("TC_Step5 Set input to be parsed from XML File"));
       
   461         iLandmarkParser->SetInputFileL(KXMLFile);
       
   462         }
       
   463     else
       
   464         {
       
   465         iLog->Log(_L("TC_Step5 Set input to be parsed from buffer"));
       
   466         bufferContent = HBufC8::NewLC(iEncoderBuffer->Size());
       
   467         TPtr8 ptr = bufferContent->Des();
       
   468         iEncoderBuffer->Read(0, ptr, iEncoderBuffer->Size());
       
   469         iLandmarkParser->SetInputBuffer(*bufferContent);
       
   470         }
       
   471     
       
   472     subset.Append(0);
       
   473     subset.Append(1);
       
   474     subset.Append(2);
       
   475     subset.Append(3);
       
   476     subset.Append(7);
       
   477 
       
   478     delete iLandmarks[6];
       
   479     delete iLandmarks[5];
       
   480     delete iLandmarks[4];
       
   481 
       
   482     iLandmarks.Remove(6);
       
   483     iLandmarks.Remove(5);
       
   484     iLandmarks.Remove(4);
       
   485 
       
   486     ImportLandmarksL(EFalse, aFullParse, CPosLandmarkDatabase::EIncludeCategories, subset, aDoParse, aCancel);
       
   487     delete iLandmarkParser;
       
   488     iLandmarkParser = NULL;
       
   489     if (!aFile) CleanupStack::PopAndDestroy(bufferContent);
       
   490 
       
   491     iLog->Log(_L("TC_Step5 Only import a subset of landmarks, use EIncludeCategories, Sync"));
       
   492     ResetLandmarksDbL();
       
   493     subset.Reset();
       
   494     DeleteFileL(KXMLFile);
       
   495     iLandmarkEncoder = CPosLandmarkEncoder::NewL(KLmxMimeType);
       
   496     // Use file for encoding, set output file
       
   497     iLandmarkEncoder->SetOutputFileL(KXMLFile);
       
   498     CreateXMLDataL();
       
   499     delete iLandmarkEncoder;
       
   500     iLandmarkEncoder = NULL;
       
   501     iLandmarkParser = CPosLandmarkParser::NewL(KLmxMimeType);
       
   502     
       
   503     if (aFile)
       
   504         {
       
   505         iLog->Log(_L("TC_Step5 Set input to be parsed from XML File"));
       
   506         iLandmarkParser->SetInputFileL(KXMLFile);
       
   507         }
       
   508     else
       
   509         {
       
   510         iLog->Log(_L("TC_Step5 Set input to be parsed from buffer"));
       
   511         bufferContent = HBufC8::NewLC(iEncoderBuffer->Size());
       
   512         TPtr8 ptr = bufferContent->Des();
       
   513         iEncoderBuffer->Read(0, ptr, iEncoderBuffer->Size());
       
   514         iLandmarkParser->SetInputBuffer(*bufferContent);
       
   515         }
       
   516    
       
   517     subset.Append(0);
       
   518     subset.Append(1);
       
   519     subset.Append(2);
       
   520     subset.Append(3);
       
   521     subset.Append(7);
       
   522 
       
   523     delete iLandmarks[6];
       
   524     delete iLandmarks[5];
       
   525     delete iLandmarks[4];
       
   526 
       
   527     iLandmarks.Remove(6);
       
   528     iLandmarks.Remove(5);
       
   529     iLandmarks.Remove(4);
       
   530 
       
   531     ImportLandmarksL(ETrue, aFullParse, CPosLandmarkDatabase::EIncludeCategories, subset, aDoParse, aCancel);
       
   532     delete iLandmarkParser;
       
   533     iLandmarkParser = NULL;
       
   534     if (!aFile) CleanupStack::PopAndDestroy(bufferContent);
       
   535     // Since only EIncludeCategories was used, the global category should not have been overwritten
       
   536     CheckGlobalCategoryExistL(*origGlobalCategory, KNewGlobalCategory);
       
   537 
       
   538     // Now use EIncludeCategories | EIncludeGlobalCategoryNames which should cause the global cateory name to 
       
   539     // be overwritten
       
   540     iLog->Log(_L("TC_Step5 Only import a subset of landmarks, use EIncludeCategories | EIncludeGlobalCategoryNames, Sync"));
       
   541     subset.Reset();
       
   542     ResetLandmarksDbL();
       
   543     DeleteFileL(KXMLFile);
       
   544     iLandmarkEncoder = CPosLandmarkEncoder::NewL(KLmxMimeType);
       
   545     // Use file for encoding, set output file
       
   546     iLandmarkEncoder->SetOutputFileL(KXMLFile);
       
   547     CreateXMLDataL();
       
   548     delete iLandmarkEncoder;
       
   549     iLandmarkEncoder = NULL;
       
   550     iLandmarkParser = CPosLandmarkParser::NewL(KLmxMimeType);
       
   551 
       
   552     if (aFile)
       
   553         {
       
   554         iLog->Log(_L("TC_Step5 Set input to be parsed from XML File"));
       
   555         iLandmarkParser->SetInputFileL(KXMLFile);
       
   556         }
       
   557     else
       
   558         {
       
   559         iLog->Log(_L("TC_Step5 Set input to be parsed from buffer"));
       
   560         bufferContent = HBufC8::NewLC(iEncoderBuffer->Size());
       
   561         TPtr8 ptr = bufferContent->Des();
       
   562         iEncoderBuffer->Read(0, ptr, iEncoderBuffer->Size());
       
   563         iLandmarkParser->SetInputBuffer(*bufferContent);
       
   564         }    
       
   565 
       
   566     subset.Append(0);
       
   567     subset.Append(1);
       
   568     subset.Append(2);
       
   569     subset.Append(3);
       
   570     subset.Append(4);
       
   571     subset.Append(5);
       
   572     subset.Append(6);
       
   573     subset.Append(7);
       
   574 
       
   575     ImportLandmarksL(ETrue, aFullParse, CPosLandmarkDatabase::EIncludeCategories | CPosLandmarkDatabase::EIncludeGlobalCategoryNames, subset, aDoParse, aCancel);
       
   576     delete iLandmarkParser;
       
   577     iLandmarkParser = NULL;
       
   578     if (!aFile) CleanupStack::PopAndDestroy(bufferContent);
       
   579     // Since EIncludeCategories| EIncludeGlobalCategoryNames was used, the global category should have been overwritten
       
   580     // Dont do check if cancel was performed
       
   581     if (!aCancel) CheckGlobalCategoryExistL(KNewGlobalCategory, *origGlobalCategory);
       
   582 
       
   583     iLog->Log(_L("TC_Step5 Only import a subset of landmarks, use EIncludeCategories | EIncludeGlobalCategoryNames, Async"));
       
   584     ResetLandmarksDbL();
       
   585     DeleteFileL(KXMLFile);
       
   586     iLandmarkEncoder = CPosLandmarkEncoder::NewL(KLmxMimeType);
       
   587     // Use file for encoding, set output file
       
   588     iLandmarkEncoder->SetOutputFileL(KXMLFile);
       
   589     CreateXMLDataL();
       
   590     delete iLandmarkEncoder;
       
   591     iLandmarkEncoder = NULL;
       
   592     iLandmarkParser = CPosLandmarkParser::NewL(KLmxMimeType);
       
   593 
       
   594     if (aFile)
       
   595         {
       
   596         iLog->Log(_L("TC_Step5 Set input to be parsed from XML File"));
       
   597         iLandmarkParser->SetInputFileL(KXMLFile);
       
   598         }
       
   599     else
       
   600         {
       
   601         iLog->Log(_L("TC_Step5 Set input to be parsed from buffer"));
       
   602         bufferContent = HBufC8::NewLC(iEncoderBuffer->Size());
       
   603         TPtr8 ptr = bufferContent->Des();
       
   604         iEncoderBuffer->Read(0, ptr, iEncoderBuffer->Size());
       
   605         iLandmarkParser->SetInputBuffer(*bufferContent);
       
   606         }
       
   607 
       
   608     ImportLandmarksL(EFalse, aFullParse, CPosLandmarkDatabase::EIncludeCategories | CPosLandmarkDatabase::EIncludeGlobalCategoryNames, subset, aDoParse, aCancel);
       
   609     delete iLandmarkParser;
       
   610     iLandmarkParser = NULL;
       
   611     if (!aFile) CleanupStack::PopAndDestroy(bufferContent);
       
   612     // Since EIncludeCategories| EIncludeGlobalCategoryNames was used, the global category should have been overwritten
       
   613     // Dont do check if cancel was performed
       
   614     if (!aCancel) CheckGlobalCategoryExistL(KNewGlobalCategory, *origGlobalCategory);
       
   615 
       
   616     CleanupStack::PopAndDestroy(&subset);
       
   617     delete iEncoderBuffer;
       
   618     iEncoderBuffer = NULL;
       
   619     CleanupStack::PopAndDestroy( origGlobalCategory );
       
   620 	}
       
   621 
       
   622 // ---------------------------------------------------------
       
   623 // CPosTp48::ImportLandmarksL
       
   624 //
       
   625 // (other items were commented in a header).
       
   626 // ---------------------------------------------------------
       
   627 //
       
   628 void CPosTp48::ImportLandmarksL(TBool aSync, TBool aFullParse, TUint aTransferOption, const RArray<TUint>&  aLandmarkSubSet, TBool aDoParse, TBool aCancel)
       
   629     {
       
   630     iLog->Log(_L("ImportLandmarksL"));
       
   631 
       
   632     TRequestStatus status = KPosLmOperationNotComplete;
       
   633     TReal32 progress = 0;
       
   634 
       
   635     if (aFullParse)
       
   636         {
       
   637         // ParseContent before importing
       
   638         ExecuteAndDeleteLD(iLandmarkParser->ParseContentL());
       
   639         iLog->Log(_L("After ExecuteAndDeleteLD(iLandmarkParser->ParseContentL());"));
       
   640         }
       
   641    
       
   642     if (aDoParse)
       
   643         {
       
   644         // Do an "almost full" parsecontent before import
       
   645         iOperation = iLandmarkParser->ParseContentL();
       
   646         
       
   647         
       
   648         while (progress <0.7)
       
   649             {
       
   650             iOperation->NextStep(status, progress);
       
   651             // Wait for NextStep to complete
       
   652             User::WaitForRequest(status);
       
   653             }
       
   654         iLog->Log(_L("After aDoParse"));
       
   655         delete iOperation;
       
   656         iOperation = NULL;
       
   657         }
       
   658 
       
   659     if (aLandmarkSubSet.Count() == 0)
       
   660         {
       
   661         iOperation = iDatabase->ImportLandmarksL(*iLandmarkParser, aTransferOption);
       
   662         }
       
   663     else
       
   664         {
       
   665         // Import only a subset of the landmarks in parser
       
   666         iOperation = iDatabase->ImportLandmarksL(*iLandmarkParser, aLandmarkSubSet,  aTransferOption);
       
   667         }
       
   668 
       
   669     if (aSync)
       
   670         {
       
   671         // Synchronous
       
   672         ExecuteAndDeleteLD(iOperation);
       
   673         iOperation = NULL;
       
   674         iLog->Log(_L("After aSync"));
       
   675         }
       
   676     else
       
   677         {
       
   678         // Asynchronous
       
   679         // Progress us checked in test procedure base
       
   680         if (aCancel)
       
   681             {
       
   682             
       
   683             // It is no more possible to do WaitForRequest after ImportLandmarksL
       
   684             RunAsyncOperationAndCancelInCallbackLD(iOperation);
       
   685             iOperation = NULL;
       
   686             iLog->Log(_L("After aCancel"));
       
   687             }
       
   688         else
       
   689             {
       
   690             RunAsyncOperationLD(iOperation);
       
   691             iOperation = NULL;
       
   692             iLog->Log(_L("After RunAsyncOperationLD(iOperation);"));
       
   693             }
       
   694         }
       
   695 
       
   696     if (!aCancel) CheckLandmarksDatabaseL(aTransferOption);
       
   697 
       
   698     }
       
   699 
       
   700 // ---------------------------------------------------------
       
   701 // CPosTp48::ResetLandmarksDbL
       
   702 //
       
   703 // (other items were commented in a header).
       
   704 // ---------------------------------------------------------
       
   705 //
       
   706 void CPosTp48::ListLandmarksDbL()
       
   707     {   
       
   708     iLog->Log(_L("ListLandmarksDbL"));
       
   709 
       
   710     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   711     CleanupStack::PushL(categoryManager);
       
   712 
       
   713     CPosLmItemIterator* iter = iDatabase->LandmarkIteratorL();
       
   714     CleanupStack::PushL(iter);
       
   715     RArray<TPosLmItemId> categories;
       
   716     CleanupClosePushL(categories);
       
   717 
       
   718     iLog->Log(_L("Landmarks:"));
       
   719     TPosLmItemId id = iter->NextL();
       
   720     TBuf<255> buffe;
       
   721     while (id != KPosLmNullItemId)
       
   722         {
       
   723         TPtrC name;
       
   724         
       
   725         CPosLandmark* lm = iDatabase->ReadLandmarkLC(id);
       
   726         lm->GetLandmarkName(name);
       
   727 
       
   728         buffe.Zero();
       
   729         buffe.Append(name);
       
   730         lm->GetCategoriesL(categories);
       
   731 
       
   732         buffe.Append(_L(" With Categories: "));
       
   733         iLog->Log(buffe);
       
   734         for (TInt i=0;i<categories.Count();i++)
       
   735             {
       
   736             CPosLandmarkCategory* cat = categoryManager->ReadCategoryLC(categories[i]);
       
   737             cat->GetCategoryName(name);
       
   738             buffe.Zero();
       
   739             buffe.Append(name);
       
   740             iLog->Log(buffe);
       
   741             CleanupStack::PopAndDestroy(cat);
       
   742             }
       
   743         CleanupStack::PopAndDestroy(lm);
       
   744         id = iter->NextL();
       
   745         }
       
   746 
       
   747     CleanupStack::PopAndDestroy(&categories);
       
   748     CleanupStack::PopAndDestroy(iter);
       
   749 
       
   750     iter = categoryManager->CategoryIteratorL();
       
   751     CleanupStack::PushL(iter);
       
   752 
       
   753     iLog->Log(_L("Categories:"));
       
   754     id = iter->NextL();
       
   755     while (id != KPosLmNullItemId)
       
   756         {
       
   757         TPtrC name;
       
   758         TBuf<255> buffe;
       
   759 
       
   760         CPosLandmarkCategory* cat = categoryManager->ReadCategoryLC(id);
       
   761         cat->GetCategoryName(name);
       
   762         buffe.Zero();
       
   763         buffe.Append(name);
       
   764         iLog->Log(buffe);
       
   765         CleanupStack::PopAndDestroy(cat);
       
   766         id = iter->NextL();
       
   767         }
       
   768 
       
   769     CleanupStack::PopAndDestroy(iter);
       
   770     CleanupStack::PopAndDestroy(categoryManager);
       
   771     }
       
   772 
       
   773 // ---------------------------------------------------------
       
   774 // CPosTp48::ResetLandmarksDbL
       
   775 //
       
   776 // (other items were commented in a header).
       
   777 // ---------------------------------------------------------
       
   778 //
       
   779 void CPosTp48::ResetLandmarksDbL()
       
   780     {
       
   781     iLog->Log(_L("ResetLandmarksDbL"));
       
   782     
       
   783     
       
   784     delete iLandmarkSearch;
       
   785     iLandmarkSearch = NULL;
       
   786 
       
   787     iLandmarks.ResetAndDestroy();
       
   788     iLandmarks.Close();
       
   789 
       
   790     delete iLandmarkParser;
       
   791     iLandmarkParser = NULL;
       
   792 
       
   793     delete iLandmarkEncoder;
       
   794     iLandmarkEncoder = NULL;
       
   795 
       
   796     delete iDatabase;
       
   797     iDatabase=NULL;
       
   798 
       
   799     // Use same lm db as in composite search test
       
   800     iDatabase = UseCompositeLandmarksDbFileL();
       
   801     if (iDatabase->IsInitializingNeeded())
       
   802         {
       
   803         ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   804         }
       
   805     
       
   806     delete iDatabase;
       
   807     iDatabase = NULL;
       
   808     iDatabase = CPosLandmarkDatabase::OpenL();
       
   809     	
       
   810     	if (iDatabase->IsInitializingNeeded())
       
   811        {
       
   812        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   813        }
       
   814     // Do reset so that global categories are included
       
   815     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   816     CleanupStack::PushL(categoryManager);   
       
   817     ExecuteAndDeleteLD(categoryManager->ResetGlobalCategoriesL());
       
   818     CleanupStack::PopAndDestroy(categoryManager);
       
   819 
       
   820     iLog->Log(_L("ResetLandmarksDbL Done"));
       
   821     }
       
   822 
       
   823 // ---------------------------------------------------------
       
   824 // CPosTp48::DoTestChangeInputMethodL
       
   825 //
       
   826 // (other items were commented in a header).
       
   827 // ---------------------------------------------------------
       
   828 //
       
   829 void CPosTp48::DoTestChangeInputMethodL()
       
   830     {
       
   831     iLog->Log(_L("DoTestChangeInputMethodL"));
       
   832     ResetLandmarksDbL();
       
   833 
       
   834     HBufC8* bufferContent = NULL;
       
   835 
       
   836     iLandmarkEncoder = CPosLandmarkEncoder::NewL(KLmxMimeType);
       
   837     iEncoderBuffer = iLandmarkEncoder->SetUseOutputBufferL();
       
   838 
       
   839     CreateXMLDataL();
       
   840     delete iLandmarkEncoder;
       
   841     iLandmarkEncoder = NULL;
       
   842     iLandmarkParser = CPosLandmarkParser::NewL(KLmxMimeType);
       
   843 
       
   844     bufferContent = HBufC8::NewLC(iEncoderBuffer->Size());
       
   845     TPtr8 ptr = bufferContent->Des();
       
   846     iEncoderBuffer->Read(0, ptr, iEncoderBuffer->Size());
       
   847     iLandmarkParser->SetInputBuffer(*bufferContent);
       
   848 
       
   849     TRequestStatus status = KPosLmOperationNotComplete;
       
   850     TReal32 progress = 0;
       
   851 
       
   852     // Do an "almost full" parsecontent
       
   853     iOperation = iLandmarkParser->ParseContentL();
       
   854     while (progress <0.5)
       
   855         {
       
   856         iOperation->NextStep(status, progress);
       
   857         // Wait for NextStep to complete
       
   858         User::WaitForRequest(status);
       
   859         }
       
   860 
       
   861     delete iOperation;
       
   862     iOperation = NULL;
       
   863     
       
   864     // Change input method
       
   865     iLandmarkParser->SetInputFileL(KXMLFile);
       
   866 
       
   867     // Now import all XML data from file
       
   868     ExecuteAndDeleteLD(iDatabase->ImportLandmarksL(*iLandmarkParser, CPosLandmarkDatabase::EDefaultOptions));
       
   869     CheckLandmarksDatabaseL(CPosLandmarkDatabase::EDefaultOptions);
       
   870 
       
   871     CleanupStack::PopAndDestroy(bufferContent);
       
   872 
       
   873     delete iLandmarkParser;
       
   874     iLandmarkParser = NULL;
       
   875     }
       
   876 
       
   877 // ---------------------------------------------------------
       
   878 // CPosTp48::ImportFromFileWithLongFileNameL
       
   879 //
       
   880 // (other items were commented in a header).
       
   881 // ---------------------------------------------------------
       
   882 //
       
   883 void CPosTp48::ImportFromFileWithLongFileNameL()
       
   884     {
       
   885     iLog->Log(_L("ImportFromFileWithLongFileNameL"));
       
   886     delete iLandmarkParser;
       
   887     iLandmarkParser = NULL;
       
   888 
       
   889     iLandmarkParser = CPosLandmarkParser::NewL(KLmxMimeType);
       
   890     TRAPD(err, iLandmarkParser->SetInputFileL(KLongFileName));
       
   891     
       
   892     // Error differs between winscw and target
       
   893    
       
   894     if ( err != KErrBadName ) 
       
   895         {
       
   896         TBuf<100> buf;    
       
   897         buf.Format(_L("ERROR: SetInputFileL should leave with KErrBadName, instead err: %d"), err);  
       
   898         iLog->Log(buf);
       
   899         iErrorsFound++;        
       
   900         }
       
   901     
       
   902     // Also test empty filename here
       
   903     TRAP(err, iLandmarkParser->SetInputFileL(KEmptyFileName1));
       
   904     if (err != KErrBadName)
       
   905         {
       
   906         iLog->Log(_L("ERROR: SetInputFileL(KEmptyFileName1) should leave with KErrBadName"));
       
   907         iErrorsFound++;
       
   908         }
       
   909         
       
   910     // Also test empty filename here
       
   911     TRAP(err, iLandmarkParser->SetInputFileL(KEmptyFileName2));
       
   912     if (err != KErrBadName)
       
   913         {
       
   914         TBuf<100> buf;
       
   915         buf.Format(_L("ERROR: SetInputFileL(KEmptyFileName2) should leave with KErrBadName, instead err: %d"), err);
       
   916         iLog->Log(buf);
       
   917         iErrorsFound++;
       
   918         }    
       
   919     
       
   920     // Also test non existing filen here
       
   921     TRAP(err, iLandmarkParser->SetInputFileL(KNonExistingFileName));
       
   922     if (err != KErrNotFound)
       
   923         {
       
   924         iLog->Log(_L("ERROR: SetInputFileL(KNonExistingFileName) should leave with KErrNotFound"));
       
   925         iErrorsFound++;
       
   926         }    
       
   927     
       
   928     delete iLandmarkParser;
       
   929     iLandmarkParser = NULL;
       
   930     iLog->Log(_L("ImportFromFileWithLongFileNameL Done"));
       
   931     }
       
   932 
       
   933 // ---------------------------------------------------------
       
   934 // CPosTp48::CheckLandmarksDatabaseL
       
   935 //
       
   936 // (other items were commented in a header).
       
   937 // ---------------------------------------------------------
       
   938 //
       
   939 void CPosTp48::CheckLandmarksDatabaseL(TUint aTransferOption)
       
   940     {
       
   941     iLog->Log(_L("CheckLandmarksDatabaseL"));
       
   942     iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase);
       
   943     TUint attr = CPosLandmark::ELandmarkName;
       
   944 
       
   945     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   946     RArray<TPosLmItemId> sourceArray;
       
   947     CleanupClosePushL(sourceArray);
       
   948 
       
   949     RArray<TPosLmItemId> array;
       
   950     CleanupClosePushL(array);
       
   951 
       
   952     TInt nrOfLandmarks = iLandmarks.Count();
       
   953     TPtrC lmName;
       
   954 
       
   955     for (TInt i=0;i<nrOfLandmarks; i++)
       
   956         {
       
   957         iLandmarks[i]->GetLandmarkName(lmName);
       
   958 
       
   959         textCriteria->SetAttributesToSearch(attr);
       
   960         textCriteria->SetTextL(lmName);
       
   961 
       
   962         ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL(*textCriteria));
       
   963  
       
   964         CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   965         CleanupStack::PushL(iter);
       
   966     
       
   967         TUint nr = iLandmarkSearch->NumOfMatches();
       
   968         iLog->Log(_L("****** Found %d nr of landmarks when looking for '%S'"),nr, &lmName);
       
   969         TPosLmItemId id = iter->NextL();
       
   970         
       
   971         if (nr > 1)
       
   972             {
       
   973             // The first landmark is the one existing in db before import,
       
   974             // no need to check that one, only the one added from import (the second one)
       
   975             id = iter->NextL();
       
   976             }
       
   977             
       
   978         while (id != KPosLmNullItemId)
       
   979             {
       
   980             CPosLandmark* source = iDatabase->ReadLandmarkLC(id);
       
   981             TPtrC sourceName;
       
   982             source->GetLandmarkName(sourceName);
       
   983 
       
   984             iLog->Log(_L("Found landmark '%S'"), &sourceName);
       
   985             
       
   986             TInt err = CompareXMLLandmarksL(*iLandmarks[i], *source, DEBUG);
       
   987             if (err != KErrNone)
       
   988                 {
       
   989                 PrintLandmarkIdFieldsL(*iLandmarks[i]);
       
   990                 PrintLandmarkIdFieldsL(*source);
       
   991                 iLog->Log(_L("ERROR: CompareXMLLandmarksL returned error"));
       
   992                 iErrorsFound+=err;
       
   993                 }
       
   994 
       
   995             source->GetCategoriesL(sourceArray);
       
   996             iLandmarks[i]->GetCategoriesL(array);
       
   997 
       
   998             CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
   999             CleanupStack::PushL(categoryManager);
       
  1000 
       
  1001             if (aTransferOption == CPosLandmarkDatabase::EDefaultOptions)
       
  1002                 {
       
  1003                 // No categories imported
       
  1004                 if (sourceArray.Count() != 0)
       
  1005                     {
       
  1006                     iLog->Log(_L("ERROR: No categories should have been imported, found %d "), sourceArray.Count());
       
  1007                     iErrorsFound++;
       
  1008                     }
       
  1009                 }
       
  1010             else
       
  1011                 {
       
  1012                 if (sourceArray.Count() != array.Count())
       
  1013                     {
       
  1014                     for (TInt j=0;j<sourceArray.Count();j++)
       
  1015                         {
       
  1016                         CPosLandmarkCategory* sourceCat = categoryManager->ReadCategoryLC(sourceArray[j]);
       
  1017                         TPtrC sourceName;
       
  1018                         sourceCat->GetCategoryName( sourceName );
       
  1019                         iLog->Log(_L("Found category '%S'"), &sourceName);
       
  1020                         }
       
  1021                     iLog->Log(_L("ERROR: Nr of categories differ, was %d should be %d"), sourceArray.Count(), array.Count());
       
  1022 					User::Leave(KErrNone);
       
  1023                     }
       
  1024 
       
  1025                 for (TInt j=0;j<sourceArray.Count();j++)
       
  1026                     {
       
  1027                     iLog->Log(_L("Src Id: %d Id: %d"), sourceArray[j], array[j]);
       
  1028                     
       
  1029                     CPosLandmarkCategory* sourceCat = categoryManager->ReadCategoryLC(sourceArray[j]);
       
  1030                     CPosLandmarkCategory* cat = categoryManager->ReadCategoryLC(array[j]);
       
  1031                     TPtrC sourceName, name;
       
  1032                     cat->GetCategoryName(name);
       
  1033                     sourceCat->GetCategoryName(sourceName);
       
  1034                     iLog->Log(_L("Found category, source cat '%S', cat '%S'"), &sourceName, &name);
       
  1035                     iErrorsFound += CompareXMLCategoriesL(*cat, *sourceCat, DEBUG);
       
  1036                     CleanupStack::PopAndDestroy(cat);
       
  1037                     CleanupStack::PopAndDestroy(sourceCat);
       
  1038                     }
       
  1039                 }
       
  1040             CleanupStack::PopAndDestroy(categoryManager);
       
  1041 
       
  1042             CleanupStack::PopAndDestroy(source);
       
  1043             id = iter->NextL();
       
  1044             }
       
  1045         CleanupStack::PopAndDestroy(iter);
       
  1046         }
       
  1047 
       
  1048     CleanupStack::PopAndDestroy(&array);
       
  1049     CleanupStack::PopAndDestroy(&sourceArray);
       
  1050     CleanupStack::PopAndDestroy(textCriteria);
       
  1051 
       
  1052     delete iLandmarkSearch;
       
  1053     iLandmarkSearch = NULL;
       
  1054     }
       
  1055 
       
  1056 // ---------------------------------------------------------
       
  1057 // CPosTp48::RemoveCategoriesFromLandmarkL
       
  1058 //
       
  1059 // (other items were commented in a header).
       
  1060 // ---------------------------------------------------------
       
  1061 //
       
  1062 void CPosTp48::RemoveCategoriesFromLandmarkL(CPosLandmark& aLandmark)
       
  1063     {
       
  1064     RArray<TPosLmItemId> array;
       
  1065     CleanupClosePushL(array);
       
  1066 
       
  1067     aLandmark.GetCategoriesL(array);
       
  1068 
       
  1069     for (TInt i=0;i<array.Count();i++)
       
  1070         {
       
  1071         aLandmark.RemoveCategory(array[i]);
       
  1072         }
       
  1073     CleanupStack::PopAndDestroy(&array);
       
  1074     }
       
  1075 
       
  1076 // ---------------------------------------------------------
       
  1077 // CPosTp48::CreateXMLDataL
       
  1078 //
       
  1079 // (other items were commented in a header).
       
  1080 // ---------------------------------------------------------
       
  1081 //
       
  1082 void CPosTp48::CreateXMLDataL()
       
  1083     {
       
  1084     iLog->Log(_L("CreateXMLDataL"));
       
  1085 
       
  1086     // 3 Add one landmark to be encoded (id7 name "Billigt" in categories 1-3,14-17)
       
  1087     CPosLandmark* lm1 = iDatabase->ReadLandmarkLC(7);
       
  1088     iLandmarkEncoder->AddLandmarkL(*lm1);
       
  1089     // Remove field 408 which is not exported
       
  1090     lm1->RemovePositionField(408);
       
  1091     RemoveCategoriesFromLandmarkL(*lm1);
       
  1092     iLandmarks.Append(lm1);
       
  1093     CleanupStack::Pop(lm1);
       
  1094     // 4 Add one more landmark to be encoded (id27 "LOG9" in categories 11-17)
       
  1095     CPosLandmark* lm2 = iDatabase->ReadLandmarkLC(27);
       
  1096     iLandmarkEncoder->AddLandmarkL(*lm2);
       
  1097     // Remove field 408 which is not exported
       
  1098     lm2->RemovePositionField(408);
       
  1099 
       
  1100     // 5 Create a new category and add to the latest added landmark
       
  1101     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
  1102     CleanupStack::PushL(categoryManager);
       
  1103     CPosLandmarkCategory* landmarkCategory = categoryManager->ReadCategoryLC(37);
       
  1104     iLandmarkEncoder->AddCategoryForLatestLandmarkL(*landmarkCategory);
       
  1105     CleanupStack::PopAndDestroy(landmarkCategory);
       
  1106     CleanupStack::PopAndDestroy(categoryManager);
       
  1107 
       
  1108     RemoveCategoriesFromLandmarkL(*lm2);
       
  1109     lm2->AddCategoryL(37);
       
  1110     iLandmarks.Append(lm2);
       
  1111     CleanupStack::Pop(lm2);
       
  1112 
       
  1113     // 6 Add one more landmark to be encoded (id52 "Kalles Hundgård" in category 19)
       
  1114     lm2 = iDatabase->ReadLandmarkLC(52);
       
  1115     iLandmarkEncoder->AddLandmarkL(*lm2);
       
  1116     // Remove field 408 which is not exported
       
  1117     lm2->RemovePositionField(408);
       
  1118 
       
  1119     // 7 Add several global and local categories to the latest added landmark
       
  1120     categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
  1121     CleanupStack::PushL(categoryManager);
       
  1122     landmarkCategory = categoryManager->ReadCategoryLC(26);
       
  1123     iLandmarkEncoder->AddCategoryForLatestLandmarkL(*landmarkCategory);
       
  1124     CleanupStack::PopAndDestroy(landmarkCategory);
       
  1125 
       
  1126     landmarkCategory = categoryManager->ReadCategoryLC(25);
       
  1127     iLandmarkEncoder->AddCategoryForLatestLandmarkL(*landmarkCategory);
       
  1128     CleanupStack::PopAndDestroy(landmarkCategory);
       
  1129     
       
  1130     
       
  1131     TPosLmItemId globalCategoryId = categoryManager->GetGlobalCategoryL(3000);
       
  1132     if (globalCategoryId != KPosLmNullItemId)
       
  1133         {
       
  1134         landmarkCategory = categoryManager->ReadCategoryLC(globalCategoryId);
       
  1135         iLandmarkEncoder->AddCategoryForLatestLandmarkL(*landmarkCategory);
       
  1136         CleanupStack::PopAndDestroy(landmarkCategory);
       
  1137     }
       
  1138     else 
       
  1139     {
       
  1140     	iLog->Log(_L("Global category was not found1"));
       
  1141     	User::Leave(-1);
       
  1142     }
       
  1143 
       
  1144     
       
  1145     globalCategoryId = categoryManager->GetGlobalCategoryL(15000);
       
  1146     if (globalCategoryId != KPosLmNullItemId)
       
  1147         {
       
  1148         landmarkCategory = categoryManager->ReadCategoryLC(globalCategoryId);
       
  1149         iLandmarkEncoder->AddCategoryForLatestLandmarkL(*landmarkCategory);
       
  1150         CleanupStack::PopAndDestroy(landmarkCategory);
       
  1151         }
       
  1152     else 
       
  1153     {
       
  1154     	iLog->Log(_L("Global category was not found2"));
       
  1155     	User::Leave(-1);	
       
  1156     }
       
  1157 
       
  1158     CleanupStack::PopAndDestroy(categoryManager);
       
  1159 
       
  1160     RemoveCategoriesFromLandmarkL(*lm2);
       
  1161     lm2->AddCategoryL(26);
       
  1162     lm2->AddCategoryL(25);
       
  1163     lm2->AddCategoryL(27);
       
  1164     lm2->AddCategoryL(31);
       
  1165     iLandmarks.Append(lm2);
       
  1166     CleanupStack::Pop(lm2);
       
  1167 
       
  1168     // 8 Add one landmark (not containing any categories), id=11 "MLFW"
       
  1169     lm2 = iDatabase->ReadLandmarkLC(11);
       
  1170     iLandmarkEncoder->AddLandmarkL(*lm2);
       
  1171     // Remove field 408 which is not exported
       
  1172     lm2->RemovePositionField(408);
       
  1173     RemoveCategoriesFromLandmarkL(*lm2);
       
  1174     iLandmarks.Append(lm2);
       
  1175     CleanupStack::Pop(lm2);
       
  1176 
       
  1177     // 9 Add one more landmark (not containing any categories), id=56 "TE, Lund"
       
  1178     lm2 = iDatabase->ReadLandmarkLC(56);
       
  1179     iLandmarkEncoder->AddLandmarkL(*lm2);
       
  1180     // Remove field 408 which is not exported
       
  1181     lm2->RemovePositionField(408);
       
  1182     
       
  1183     // 10 Add one category to the latest added landmark
       
  1184     categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
  1185     CleanupStack::PushL(categoryManager);
       
  1186     landmarkCategory = categoryManager->ReadCategoryLC(18);
       
  1187         
       
  1188     iLandmarkEncoder->AddCategoryForLatestLandmarkL(*landmarkCategory);
       
  1189     CleanupStack::PopAndDestroy(landmarkCategory);
       
  1190     CleanupStack::PopAndDestroy(categoryManager);
       
  1191 
       
  1192     RemoveCategoriesFromLandmarkL(*lm2);
       
  1193     lm2->AddCategoryL(18);
       
  1194     iLandmarks.Append(lm2);
       
  1195     CleanupStack::Pop(lm2);
       
  1196 
       
  1197     // 11 Add one landmark (not containing any categories), id=43 "asdf"
       
  1198     categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
  1199     CleanupStack::PushL(categoryManager);
       
  1200     lm2 = iDatabase->ReadLandmarkLC(43);
       
  1201     iLandmarkEncoder->AddLandmarkL(*lm2);
       
  1202     // Remove field 408 which is not exported
       
  1203     lm2->RemovePositionField(408);
       
  1204 
       
  1205     // 12 Add several local and global categories to the latest added landmark
       
  1206     landmarkCategory = categoryManager->ReadCategoryLC(23);
       
  1207         
       
  1208     iLandmarkEncoder->AddCategoryForLatestLandmarkL(*landmarkCategory);
       
  1209     CleanupStack::PopAndDestroy(landmarkCategory);
       
  1210     landmarkCategory = categoryManager->ReadCategoryLC(17);
       
  1211         
       
  1212     iLandmarkEncoder->AddCategoryForLatestLandmarkL(*landmarkCategory);
       
  1213     CleanupStack::PopAndDestroy(landmarkCategory);
       
  1214     
       
  1215     
       
  1216     globalCategoryId = categoryManager->GetGlobalCategoryL(39000);
       
  1217     
       
  1218     if (globalCategoryId != KPosLmNullItemId)
       
  1219         {
       
  1220         landmarkCategory = categoryManager->ReadCategoryLC(globalCategoryId);
       
  1221         iLandmarkEncoder->AddCategoryForLatestLandmarkL(*landmarkCategory);
       
  1222         CleanupStack::PopAndDestroy(landmarkCategory);
       
  1223         }
       
  1224     else 
       
  1225         {   
       
  1226 		iLog->Log(_L("Global category was not found3"));
       
  1227     	User::Leave(-1);
       
  1228         }
       
  1229 
       
  1230     
       
  1231     globalCategoryId = categoryManager->GetGlobalCategoryL(27000);
       
  1232     if (globalCategoryId != KPosLmNullItemId)
       
  1233         {
       
  1234         landmarkCategory = categoryManager->ReadCategoryLC(globalCategoryId);
       
  1235         iLandmarkEncoder->AddCategoryForLatestLandmarkL(*landmarkCategory);
       
  1236         CleanupStack::PopAndDestroy(landmarkCategory);
       
  1237         }
       
  1238     else 
       
  1239         {
       
  1240     	iLog->Log(_L("Global category was not found4"));
       
  1241     	User::Leave(-1);
       
  1242         }
       
  1243     
       
  1244     RemoveCategoriesFromLandmarkL(*lm2);
       
  1245     lm2->AddCategoryL(23);
       
  1246     lm2->AddCategoryL(17);
       
  1247     lm2->AddCategoryL(39);
       
  1248     lm2->AddCategoryL(35);
       
  1249 
       
  1250     iLandmarks.Append(lm2);
       
  1251     CleanupStack::Pop(lm2);
       
  1252 
       
  1253     // 13) Add a landmark with fields that are encoded to XML set
       
  1254     lm1 = CreateXMLLandmarkLC(_L("TP48LandmarkWithAllXMLFields"));
       
  1255     AddAllXMLFieldsL(lm1);
       
  1256     iLandmarkEncoder->AddLandmarkL(*lm1);
       
  1257     
       
  1258     // 13) Add one global category  (Garage) to the latest added landmark
       
  1259     globalCategoryId = categoryManager->GetGlobalCategoryL(24000);
       
  1260     if (globalCategoryId != KPosLmNullItemId)
       
  1261         {
       
  1262         landmarkCategory = categoryManager->ReadCategoryLC(globalCategoryId);
       
  1263         iLandmarkEncoder->AddCategoryForLatestLandmarkL(*landmarkCategory);
       
  1264         CleanupStack::PopAndDestroy(landmarkCategory);
       
  1265         }
       
  1266     else 
       
  1267         {
       
  1268     	iLog->Log(_L("Global category was not found4"));
       
  1269     	User::Leave(-1);
       
  1270         }
       
  1271 
       
  1272     // 14) Add one global category  (Bus stop) to the latest added landmark
       
  1273     globalCategoryId = categoryManager->GetGlobalCategoryL(42000);//30000
       
  1274     if (globalCategoryId != KPosLmNullItemId)
       
  1275         {
       
  1276         landmarkCategory = categoryManager->ReadCategoryLC(globalCategoryId);
       
  1277         iLandmarkEncoder->AddCategoryForLatestLandmarkL(*landmarkCategory);
       
  1278         CleanupStack::PopAndDestroy(landmarkCategory);
       
  1279         }
       
  1280     else 
       
  1281         {
       
  1282     	iLog->Log(_L("Global category was not found4"));
       
  1283     	User::Leave(-1);
       
  1284         }
       
  1285 
       
  1286     // 15) Add one category (BurgerKing) to the latest added landmark
       
  1287     landmarkCategory = categoryManager->ReadCategoryLC(17);
       
  1288      
       
  1289     iLandmarkEncoder->AddCategoryForLatestLandmarkL(*landmarkCategory);
       
  1290     CleanupStack::PopAndDestroy(landmarkCategory);
       
  1291 
       
  1292     RemoveCategoriesFromLandmarkL(*lm1);
       
  1293     lm1->AddCategoryL(34);
       
  1294     lm1->AddCategoryL(40);
       
  1295     lm1->AddCategoryL(17);
       
  1296     iLandmarks.Append(lm1);
       
  1297     CleanupStack::Pop(lm1);
       
  1298 
       
  1299     CleanupStack::PopAndDestroy(categoryManager);
       
  1300 
       
  1301     // 16 Create new landmark with empty fields
       
  1302     lm1 = CreateXMLLandmarkLC(_L("TP48Landmark With Empty XML Fields"));
       
  1303     AddAllEmptyXMLFieldsL(lm1);
       
  1304     iLandmarkEncoder->AddLandmarkL(*lm1);
       
  1305     
       
  1306     // 17 Create a new category and add to the latest added landmark
       
  1307     categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
  1308     CleanupStack::PushL(categoryManager);
       
  1309 
       
  1310     //landmarkCategory = CPosLandmarkCategory::NewLC();
       
  1311     landmarkCategory = categoryManager->ReadCategoryLC(38);
       
  1312     iLandmarkEncoder->AddCategoryForLatestLandmarkL(*landmarkCategory);
       
  1313     CleanupStack::PopAndDestroy(landmarkCategory);
       
  1314 
       
  1315     // 18 Add global category "Outsight" which is "Sight" id=6 with changed name
       
  1316     // and add to the latest added landmark
       
  1317     globalCategoryId = categoryManager->GetGlobalCategoryL(KOrigGlobalCategoryId);
       
  1318     landmarkCategory = categoryManager->ReadCategoryLC(globalCategoryId);
       
  1319     landmarkCategory->SetCategoryNameL(KNewGlobalCategory);
       
  1320     categoryManager->UpdateCategoryL(*landmarkCategory);
       
  1321     CleanupStack::PopAndDestroy(landmarkCategory);
       
  1322 
       
  1323   
       
  1324     globalCategoryId = categoryManager->GetGlobalCategoryL(KOrigGlobalCategoryId);
       
  1325     if (globalCategoryId != KPosLmNullItemId)
       
  1326         {
       
  1327         landmarkCategory = categoryManager->ReadCategoryLC(globalCategoryId);
       
  1328         iLandmarkEncoder->AddCategoryForLatestLandmarkL(*landmarkCategory);
       
  1329         CleanupStack::PopAndDestroy(landmarkCategory);
       
  1330         }
       
  1331     else 
       
  1332         {
       
  1333     	iLog->Log(_L("Global category was not found4"));
       
  1334     	User::Leave(-1);
       
  1335         }
       
  1336     
       
  1337     CleanupStack::PopAndDestroy(categoryManager);
       
  1338 
       
  1339     RemoveCategoriesFromLandmarkL(*lm1);
       
  1340     // The new category will have id=38
       
  1341     lm1->AddCategoryL(38);
       
  1342     lm1->AddCategoryL(globalCategoryId);
       
  1343     // Remove field 402 which is not included
       
  1344     lm1->RemovePositionField(402);
       
  1345     iLandmarks.Append(lm1);
       
  1346     CleanupStack::Pop(lm1);
       
  1347         
       
  1348     // 13 Finalize encoding
       
  1349     //iLog->Log(_L("FinalizeEncodingL"));
       
  1350     ExecuteAndDeleteLD(iLandmarkEncoder->FinalizeEncodingL());
       
  1351     //iLog->Log(_L("FinalizeEncodingL Done"));
       
  1352 
       
  1353     categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
  1354     CleanupStack::PushL(categoryManager);
       
  1355     //Change back name for this global category, needed to test use of TTransferOptions::EIncludeGlobalCategoryNames
       
  1356     // by resetting global categories
       
  1357     ExecuteAndDeleteLD(categoryManager->ResetGlobalCategoriesL());
       
  1358     CleanupStack::PopAndDestroy(categoryManager);
       
  1359 
       
  1360     iLog->Log(_L("CreateXMLDataL Done"));
       
  1361     }
       
  1362 
       
  1363 
       
  1364 // ---------------------------------------------------------
       
  1365 // CPosTp48::CheckGlobalCategoryExistL
       
  1366 //
       
  1367 // (other items were commented in a header).
       
  1368 // ---------------------------------------------------------
       
  1369 //
       
  1370 void CPosTp48::CheckGlobalCategoryExistL(const TDesC& aShouldExistName, const TDesC& aShouldNotExistName)
       
  1371     {
       
  1372     CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL(*iDatabase);
       
  1373     CleanupStack::PushL(categoryManager);
       
  1374 
       
  1375     // Should be found
       
  1376     TPosLmItemId id1 = categoryManager->GetCategoryL(aShouldExistName);
       
  1377     // Should not be found
       
  1378     TPosLmItemId id2 = categoryManager->GetCategoryL(aShouldNotExistName);
       
  1379 
       
  1380     if (id1 == KPosLmNullItemId)
       
  1381         {
       
  1382         iLog->Log(_L("ERROR: CheckGlobalCategoryExistL Global Category '%S' should be found"),
       
  1383             &aShouldExistName);
       
  1384         iErrorsFound++;
       
  1385         }
       
  1386 
       
  1387     if (id2 != KPosLmNullItemId)
       
  1388         {
       
  1389         iLog->Log(_L("ERROR: CheckGlobalCategoryExistL Global Category '%S' should NOT be found"),
       
  1390             &aShouldNotExistName);
       
  1391         iErrorsFound++;
       
  1392         }
       
  1393 
       
  1394     CleanupStack::PopAndDestroy(categoryManager);
       
  1395     }
       
  1396 
       
  1397 // ---------------------------------------------------------
       
  1398 // CPosTp48::PrintLandmarkIdFieldsL
       
  1399 //
       
  1400 // (other items were commented in a header).
       
  1401 // ---------------------------------------------------------
       
  1402 //
       
  1403 void CPosTp48::PrintLandmarkIdFieldsL(const CPosLandmark& aLandmark)
       
  1404     {
       
  1405     TPositionFieldId sourceFieldId = aLandmark.FirstPositionFieldId();
       
  1406     TLocality loc;
       
  1407     TBuf<150> buf;    
       
  1408     TInt err = aLandmark.GetPosition(loc);
       
  1409     if (err == KErrNone)
       
  1410         {
       
  1411         TReal vertAcc(loc.VerticalAccuracy());
       
  1412         TReal horAcc(loc.HorizontalAccuracy());
       
  1413         TReal alt(loc.Altitude());
       
  1414         TReal lon = loc.Longitude();
       
  1415         TReal lat = loc.Latitude();
       
  1416         TReal32 sourceR;
       
  1417         err = aLandmark.GetCoverageRadius(sourceR);
       
  1418         if (err == KErrNone )
       
  1419             {
       
  1420             buf.Format(_L("LM: Long %f Lat %f vertAcc %f horAcc %f alt %f srcRadius %f"), lon, lat, vertAcc, horAcc, alt, sourceR);
       
  1421             }
       
  1422         else
       
  1423             {
       
  1424             buf.Format(_L("LM: Long %f Lat %f vertAcc %f horAcc %f alt %f "), lon, lat, vertAcc, horAcc, alt);
       
  1425             }
       
  1426         iLog->Log(buf);
       
  1427         }
       
  1428 
       
  1429     while (sourceFieldId != EPositionFieldNone)
       
  1430         {
       
  1431         TPtrC sourceValue;
       
  1432         aLandmark.GetPositionField(sourceFieldId, sourceValue);
       
  1433         buf.Format(_L("IdField Id: %d Value:"), sourceFieldId);
       
  1434         buf.Append(sourceValue);
       
  1435         iLog->Log(buf);
       
  1436         sourceFieldId = aLandmark.NextPositionFieldId(sourceFieldId);
       
  1437         }
       
  1438     }
       
  1439     
       
  1440 
       
  1441 
       
  1442 //  End of File