landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTP55.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_CPosTp55.h"
       
    22 #include "FT_LandmarkConstants.h"
       
    23 //#include <eposlmintservices.rsg>
       
    24 #include <centralrepository.h>
       
    25 #include <UiklafInternalCRKeys.h>
       
    26 #include <utfw.h>
       
    27 #include <f32file.h>
       
    28 #include <coemain.h>
       
    29 #include <EPos_CPosLandmarkEncoder.h>
       
    30 #include <EPos_CPosLandmarkParser.h>
       
    31 #include <barsread.h>
       
    32 #include <bautils.h>
       
    33 
       
    34 // CONSTANTS
       
    35 _LIT(KFile1, "c:\\documents\\Tp55_1.txt");
       
    36 _LIT(KFile2, "c:\\documents\\Tp55_2.txt");
       
    37 _LIT(KFile3, "c:\\documents\\Tp55_3.txt");
       
    38 const TInt KOneK = 1024;
       
    39 const TInt KNrOfLandmarksToExport = 10;
       
    40 //_LIT(KPosResourceFile, "\\resource\\eposlmintservices.rsc");
       
    41 #ifdef __WINS__
       
    42 _LIT(KXmlInputFile, "z:\\system\\test\\testdata\\TP55-DiskFullDuringExportImport.xml"); 
       
    43 #else
       
    44 _LIT(KXmlInputFile, "c:\\system\\test\\testdata\\TP55-DiskFullDuringExportImport.xml"); 
       
    45 #endif
       
    46 _LIT(KXmlOutputFile, "c:\\documents\\TP55-ExportedLandmarks.xml"); 
       
    47 _LIT(KXmlBufferDumpFile, "c:\\documents\\BufferDump.xml");
       
    48 _LIT(KInternalServicesResFileRom, "z:\\resource\\eposlmintservices.rsc");
       
    49 _LIT(KInternalServicesResFileBackup, "c:\\resource\\copy_of_eposlmintservices.rsc");
       
    50 _LIT(KInternalServicesResFileCdrive, "c:\\resource\\eposlmintservices.rsc");
       
    51 //_LIT(KInternalServicesLargeResFile, "c:\\system\\test\\testdata\\eposlmintservices_453KB.rsc");
       
    52 //_LIT(KInternalServicesSmallResFile, "c:\\system\\test\\testdata\\eposlmintservices_198KB.rsc");
       
    53 
       
    54 // Approx 2141 bytes
       
    55 _LIT8(KNonsense, "nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    56 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    57 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    58 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    59 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    60 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    61 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    62 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    63 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    64 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    65 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    66 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    67 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    68 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    69 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    70 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    71 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    72 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    73 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    74 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    75 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    76 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    77 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    78 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    79 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    80 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    81 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    82 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    83 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    84 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    85 nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense\
       
    86 sensenonsensenonsensenonsensenonsensenonsensenonsense");
       
    87 
       
    88 _LIT8(K64B, "nonsensenonsensenonsensenonsensenonsensenonsensenonsensenonsense");
       
    89 
       
    90 // ================= MEMBER FUNCTIONS =======================
       
    91 
       
    92 // ---------------------------------------------------------
       
    93 // CPosTp55::GetName
       
    94 //
       
    95 // (other items were commented in a header).
       
    96 // ---------------------------------------------------------
       
    97 //
       
    98 void CPosTp55::GetName(TDes& aName) const
       
    99     {
       
   100     _LIT(KTestName, "Tp55 - Disk Full Checking during Import/Export");
       
   101     aName = KTestName;
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------
       
   105 // CPosTp55::CloseTest
       
   106 //
       
   107 // (other items were commented in a header).
       
   108 // ---------------------------------------------------------
       
   109 //
       
   110 void CPosTp55::CloseTest()
       
   111     {
       
   112     delete iDatabase;
       
   113     iDatabase = NULL;
       
   114 
       
   115     delete iOperationWrapper;
       
   116     delete iLandmarkEncoder;
       
   117     delete iLandmarkParser;
       
   118     delete iOutputBuffer;
       
   119     delete iInputBuffer;
       
   120 
       
   121     iFile1.Close();
       
   122     iFile2.Close();
       
   123     iFile3.Close();
       
   124     iFileServer.Delete(KFile1);
       
   125     iFileServer.Delete(KFile2);
       
   126     iFileServer.Delete(KFile3);
       
   127 
       
   128     //TryRestoreResourceFile();
       
   129 
       
   130     iXmlOutputFile.Close();
       
   131     iFileServer.Delete(KXmlOutputFile);
       
   132     iFileServer.Delete(KXmlBufferDumpFile);
       
   133 
       
   134     iFileServer.Close();
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------
       
   138 // CPosTp55::InitTestL
       
   139 //
       
   140 // (other items were commented in a header).
       
   141 // ---------------------------------------------------------
       
   142 //
       
   143 void CPosTp55::InitTestL()
       
   144     {
       
   145     // File setup, create two files
       
   146     User::LeaveIfError(iFileServer.Connect());
       
   147 
       
   148     // Try to restore if previous execution of Tp55 panicked or was killed.
       
   149     //TryRestoreResourceFile();
       
   150 
       
   151     iOperationWrapper = new (ELeave) CActiveLmOperation(iLog);
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------
       
   155 // CPosTp55::StartL
       
   156 //
       
   157 // (other items were commented in a header).
       
   158 // ---------------------------------------------------------
       
   159 //
       
   160 void CPosTp55::StartL()
       
   161     {
       
   162     // Retreive threshold from centralrepository
       
   163     CRepository* repository = CRepository::NewLC(KCRUidUiklaf);
       
   164     User::LeaveIfError(repository->Get(KUikOODDiskCriticalThreshold, iCriticalThreshold));
       
   165     CleanupStack::PopAndDestroy(repository);
       
   166 
       
   167     // Test import/export LMs when critical level is set to MLFW defined value.
       
   168     InitiateCriticalLevelL();
       
   169     TestCriticalLevelL();
       
   170 
       
   171 /*
       
   172     // Test import/export LMs when critical level is set to a large value.
       
   173     iLog->Put(_L("\r\nRedefining critical level to 453 KB and running all tests again...."));
       
   174     CopyResourceFileL(KInternalServicesLargeResFile);
       
   175     InitiateCriticalLevelL();
       
   176     TestCriticalLevelL();
       
   177 
       
   178     // Test import/export LMs when critical level is set to a small value.
       
   179     iLog->Put(_L("\r\nRedefining critical level to 198 KB and running all tests again...."));
       
   180     CopyResourceFileL(KInternalServicesSmallResFile);
       
   181     InitiateCriticalLevelL();
       
   182     TestCriticalLevelL();
       
   183     */
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------
       
   187 // CPosTp55::NotifyProgress
       
   188 //
       
   189 // (other items were commented in a header).
       
   190 // ---------------------------------------------------------
       
   191 //
       
   192 void CPosTp55::NotifyProgress(TReal aProgress)
       
   193     {
       
   194     iProgress = (TInt) (aProgress * 100);
       
   195 //    iMsg.Format(_L("Progress = %d"), iProgress);
       
   196 //    iLog->Put(iMsg);
       
   197 //    LogVolumeInfoL();
       
   198     }
       
   199 
       
   200 // ---------------------------------------------------------
       
   201 // CPosTp55::TestCriticalLevelL
       
   202 //
       
   203 // (other items were commented in a header).
       
   204 // ---------------------------------------------------------
       
   205 //
       
   206 void CPosTp55::TestCriticalLevelL()
       
   207     {
       
   208     // Restore disk space
       
   209     RecreateAndOpenFilesL();
       
   210 
       
   211     // ************ 1. Open database ************
       
   212     delete iDatabase;
       
   213     iDatabase = NULL;
       
   214     iDatabase = UseGeneratedDbFileL();
       
   215     if (iDatabase->IsInitializingNeeded())
       
   216        {
       
   217        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   218        }
       
   219 
       
   220     // ************ 2. Fill up disk space ************
       
   221     iLog->Put(_L("Consuming disk space..."));
       
   222     ConsumeDiskSpaceL(iFile1, iCriticalLevel + 3 * KOneK);
       
   223     LogVolumeInfoL();
       
   224 
       
   225 //// Test importing landmarks
       
   226     iLog->Put(_L("Testing Importing..."));
       
   227     iLog->Put(_L("-- Testing import below critical level"));
       
   228     TBool testBeyondCriticalLevel = ETrue;
       
   229     ImportLandmarksTestL(!testBeyondCriticalLevel);
       
   230     
       
   231     // ************ 11. Repeat steps 3-10 ************
       
   232     iLog->Put(_L("\r\n-- Testing import beyond critical level"));
       
   233     ExecuteAndDeleteLD(iDatabase->CompactL());
       
   234     iLog->Put(_L("Consuming disk space..."));
       
   235     User::LeaveIfError(iFile2.Create(iFileServer, KFile2, EFileWrite));
       
   236     ConsumeDiskSpaceL(iFile2, iSizeLimit2);
       
   237     LogVolumeInfoL();
       
   238     ImportLandmarksTestL(testBeyondCriticalLevel);
       
   239 
       
   240     // Restore disk space
       
   241     RecreateAndOpenFilesL();
       
   242 
       
   243     // Use suitable database for exporting LMs
       
   244     delete iDatabase;
       
   245     iDatabase = NULL;
       
   246     iDatabase = UseGeneratedDbFileL();
       
   247     if (iDatabase->IsInitializingNeeded())
       
   248        {
       
   249        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   250        }
       
   251 
       
   252     // ************ 12. Fill up disk space ************
       
   253     iLog->Put(_L("Consuming disk space..."));
       
   254     ConsumeDiskSpaceL(iFile1, iSizeLimit1);
       
   255     LogVolumeInfoL();
       
   256 
       
   257 //// Test importing landmarks
       
   258     iLog->Put(_L("Testing Exporting..."));
       
   259     ExportLandmarksTestL();
       
   260     }
       
   261 
       
   262 // ---------------------------------------------------------
       
   263 // CPosTp55::RecreateAndOpenFilesL
       
   264 //
       
   265 // (other items were commented in a header).
       
   266 // ---------------------------------------------------------
       
   267 //
       
   268 void CPosTp55::RecreateAndOpenFilesL()
       
   269     {
       
   270     iLog->Put(_L("Removing large files..."));
       
   271 
       
   272     // Delete files
       
   273     iFile1.Close();
       
   274     iFileServer.Delete(KFile1);
       
   275     iFile2.Close();
       
   276     iFileServer.Delete(KFile2);
       
   277     iFile3.Close();
       
   278     iFileServer.Delete(KFile3);
       
   279 
       
   280     // Create and open files
       
   281     User::LeaveIfError(iFile1.Create(iFileServer, KFile1, EFileWrite));
       
   282     User::LeaveIfError(iFile2.Create(iFileServer, KFile2, EFileWrite));
       
   283     User::LeaveIfError(iFile3.Create(iFileServer, KFile3, EFileWrite));
       
   284     }
       
   285 
       
   286 // ---------------------------------------------------------
       
   287 // CPosTp55::ExportLandmarksTestL
       
   288 //
       
   289 // (other items were commented in a header).
       
   290 // ---------------------------------------------------------
       
   291 //
       
   292 void CPosTp55::ExportLandmarksTestL()
       
   293     {
       
   294     TInt result(0);
       
   295     TBool doAddAllLandmarks = ETrue;
       
   296     TBool doExecuteIncrementally = ETrue;
       
   297 
       
   298 //// Testing Disk full during addition of LMs to encoder
       
   299     iLog->Put(_L("\r\n--- Testing Disk full during addition of LMs to encoder"));
       
   300 
       
   301     // 13. ************ Export to file using encoder stand-alone ************
       
   302     iLog->Put(_L("------ Export to file incrementally using encoder stand-alone"));
       
   303     ReInitializeEncoderEtcL();
       
   304     iLandmarkEncoder->SetOutputFileL(KXmlOutputFile);
       
   305     AddCollectionDataToEncoderL();
       
   306     AddLandmarksToEncoderL(doAddAllLandmarks);
       
   307 
       
   308     // ************ Export to buffer incrementally using encoder stand-alone ************
       
   309 //    iLog->Put(_L("------ Export to buffer incrementally using encoder stand-alone"));
       
   310 // Not tested here since it does not result in KErrDiskFull but in KErrNoMemory. Time-consuming test
       
   311 /*    ReInitializeEncoderEtcL();
       
   312     delete iOutputBuffer;
       
   313     iOutputBuffer = NULL;
       
   314     iOutputBuffer = iLandmarkEncoder->SetUseOutputBufferL();
       
   315     AddCollectionDataToEncoderL();
       
   316     while (result == KErrNone)
       
   317         {
       
   318         TRAP(result, AddLandmarksToEncoderL(!doAddAllLandmarks));
       
   319         iMsg.Format(_L("Size of output buffer: %d"), iOutputBuffer->Size());
       
   320         iLog->Put(iMsg);
       
   321         }
       
   322     iMsg.Format(_L("Export to buffer left with error code %d"), result);
       
   323     iLog->Put(iMsg);
       
   324     */
       
   325 
       
   326 //// Testing Disk full during ExportLandmarksL()
       
   327     iLog->Put(_L("\r\n--- Testing Disk full during ExportLandmarksL()"));
       
   328 
       
   329     // Create array of all IDs in database
       
   330     RArray<TPosLmItemId> itemIds;
       
   331     CleanupClosePushL(itemIds);
       
   332     PopulateArrayL(itemIds, doAddAllLandmarks);
       
   333 
       
   334     // ************ 14. Export to file incrementally using ExportLandmarksL() ************
       
   335     iLog->Put(_L("------ Export to file incrementally using ExportLandmarksL()"));
       
   336     ReInitializeEncoderEtcL();
       
   337     iLandmarkEncoder->SetOutputFileL(KXmlOutputFile);
       
   338     AddCollectionDataToEncoderL();
       
   339     ExportWithExportLandmarksMethodL(itemIds, doExecuteIncrementally);
       
   340 
       
   341     // ************ 15. Export to file synchronously using ExportLandmarksL() ************
       
   342     iLog->Put(_L("------ Export to file synchronously using ExportLandmarksL()"));
       
   343     ReInitializeEncoderEtcL();
       
   344     iLandmarkEncoder->SetOutputFileL(KXmlOutputFile);
       
   345     AddCollectionDataToEncoderL();
       
   346     ExportWithExportLandmarksMethodL(itemIds, !doExecuteIncrementally);
       
   347 
       
   348     // ************ Export to buffer incrementally using ExportLandmarksL() ************
       
   349 //    iLog->Put(_L("------ Export to buffer incrementally using ExportLandmarksL()"));
       
   350 // Not tested here since it does not result in KErrDiskFull but in KErrNoMemory. Time-consuming test
       
   351 
       
   352     // ************ Export to buffer synchronously ExportLandmarksL() ************
       
   353 //    iLog->Put(_L("------ Export to buffer synchronously ExportLandmarksL() ------"));
       
   354 // Not tested here since it does not result in KErrDiskFull but in KErrNoMemory. Time-consuming test
       
   355 
       
   356     CleanupStack::PopAndDestroy(&itemIds);
       
   357 
       
   358 //// Testing Disk full during finalizing of encoder
       
   359     iLog->Put(_L("\r\n--- Testing Disk full during finalizing of encoder"));
       
   360 
       
   361     // ************ 16. Export to file using encoder stand-alone and finalizing incrementally ************
       
   362     iLog->Put(_L("------ Export to file using encoder stand-alone and finalizing incrementally"));
       
   363     ReInitializeEncoderEtcL();
       
   364     iLandmarkEncoder->SetOutputFileL(KXmlOutputFile);
       
   365     AddCollectionDataToEncoderL();
       
   366     AddLandmarksToEncoderL(!doAddAllLandmarks);
       
   367     FillFile3L(); // Fill up disk space so much that next call to FinalizeL results in KErrDiskFull.
       
   368     FinalizeEncoderL(doExecuteIncrementally);
       
   369 
       
   370     // ************ 17. Export to file using encoder stand-alone and finalizing synchronously ************
       
   371     iLog->Put(_L("------ Export to file using encoder stand-alone and finalizing synchronously"));
       
   372     ReInitializeEncoderEtcL();
       
   373     iLandmarkEncoder->SetOutputFileL(KXmlOutputFile);
       
   374     AddCollectionDataToEncoderL();
       
   375     AddLandmarksToEncoderL(!doAddAllLandmarks);
       
   376     FillFile3L(); // Fill up disk space so much that next call to FinalizeL results in KErrDiskFull.
       
   377     FinalizeEncoderL(!doExecuteIncrementally);
       
   378 
       
   379     // Create array of some IDs in database
       
   380     CleanupClosePushL(itemIds);
       
   381     PopulateArrayL(itemIds, !doAddAllLandmarks);
       
   382 
       
   383     // ************ 18. Export to file using ExportLandmarksL() and finalizing incrementally ************
       
   384     iLog->Put(_L("------ Export to file using ExportLandmarksL() and finalizing incrementally"));
       
   385     ReInitializeEncoderEtcL();
       
   386     iLandmarkEncoder->SetOutputFileL(KXmlOutputFile);
       
   387     AddCollectionDataToEncoderL();
       
   388     ExportWithExportLandmarksMethodL(itemIds, doExecuteIncrementally);
       
   389     FillFile3L(); // Fill up disk space so much that next call to FinalizeL results in KErrDiskFull.
       
   390     FinalizeEncoderL(doExecuteIncrementally);
       
   391 
       
   392     // ************ 19. Export to file using ExportLandmarksL() and finalizing synchronously ************
       
   393     iLog->Put(_L("------ Export to file using ExportLandmarksL() and finalizing synchronously"));
       
   394     ReInitializeEncoderEtcL();
       
   395     iLandmarkEncoder->SetOutputFileL(KXmlOutputFile);
       
   396     AddCollectionDataToEncoderL();
       
   397     ExportWithExportLandmarksMethodL(itemIds, !doExecuteIncrementally);
       
   398     FillFile3L(); // Fill up disk space so much that next call to FinalizeL results in KErrDiskFull.
       
   399     FinalizeEncoderL(!doExecuteIncrementally);
       
   400 
       
   401     CleanupStack::PopAndDestroy(&itemIds);
       
   402 
       
   403 //// Testing when disk is already full
       
   404     iLog->Put(_L("\r\n--- Testing when disk is already full"));
       
   405     TVolumeInfo volumeInfoBeforeTest, volumeInfoAfterTest;
       
   406 
       
   407     // ************ 20. CPosLandmarkEncoder::SetOutPutFileL() ************
       
   408     iLog->Put(_L("------ CPosLandmarkEncoder::SetOutPutFileL()"));
       
   409     iFile2.Close();
       
   410     DeleteFileL(KFile2);
       
   411     ReInitializeEncoderEtcL();
       
   412     User::LeaveIfError(iFile2.Create(iFileServer, KFile2, EFileWrite));
       
   413     ConsumeDiskSpaceL(iFile2, iSizeLimit2);
       
   414     User::LeaveIfError(iFileServer.Volume(volumeInfoBeforeTest, EDriveC));
       
   415     TRAP(result, iLandmarkEncoder->SetOutputFileL(KXmlOutputFile));
       
   416     User::LeaveIfError(iFileServer.Volume(volumeInfoAfterTest, EDriveC));
       
   417 
       
   418     // Verify
       
   419     _LIT(KSetFile1, "SetOutPutFileL() didn't result in KErrDiskFull but in %d");
       
   420     AssertTrueSecL(result == KErrDiskFull, KSetFile1, result);
       
   421     iLog->Put(_L("SetOutputFileL() left with KErrDiskFull"));
       
   422     _LIT(KSetFile2, "SetOutPutFileL() consumed disk space even if critical level has been passed. %d");
       
   423     AssertTrueSecL(volumeInfoBeforeTest.iFree == volumeInfoAfterTest.iFree, KSetFile2);
       
   424 
       
   425     // ************ 21. CPosLandmarkEncoder::AddLandmarkL() ************
       
   426     iLog->Put(_L("------ CPosLandmarkEncoder::AddLandmarkL()"));
       
   427     iFile2.Close();
       
   428     DeleteFileL(KFile2);
       
   429     ReInitializeEncoderEtcL();
       
   430     iLandmarkEncoder->SetOutputFileL(KXmlOutputFile);
       
   431     AddCollectionDataToEncoderL();
       
   432     CPosLmItemIterator* iterator = iDatabase->LandmarkIteratorL();
       
   433     CleanupStack::PushL(iterator);
       
   434     CPosLandmark* landmark = iDatabase->ReadLandmarkLC(iterator->NextL());
       
   435     User::LeaveIfError(iFile2.Create(iFileServer, KFile2, EFileWrite));
       
   436     ConsumeDiskSpaceL(iFile2, iSizeLimit2);
       
   437     User::LeaveIfError(iFileServer.Volume(volumeInfoBeforeTest, EDriveC));
       
   438     TRAP(result, iLandmarkEncoder->AddLandmarkL(*landmark));
       
   439     User::LeaveIfError(iFileServer.Volume(volumeInfoAfterTest, EDriveC));
       
   440     CleanupStack::PopAndDestroy(2, iterator);
       
   441 
       
   442     // Verify
       
   443     _LIT(KAddLmErr1, "Adding LM to encoder didn't result in KErrDiskFull but in %d when beyond critical level");
       
   444     AssertTrueSecL(result == KErrDiskFull, KAddLmErr1, result);
       
   445     iLog->Put(_L("AddLandmarkL() left with KErrDiskFull"));
       
   446     _LIT(KAddLmErr2, "AddLandmarkL() consumed disk space even if critical level has been passed. %d");
       
   447     AssertTrueSecL(volumeInfoBeforeTest.iFree == volumeInfoAfterTest.iFree, KAddLmErr2);
       
   448 
       
   449     // ************ 22. CPosLandmarkEncoder::FinalizeL() ************
       
   450     iLog->Put(_L("------ CPosLandmarkEncoder::FinalizeL()"));
       
   451     iFile2.Close();
       
   452     DeleteFileL(KFile2);
       
   453     ReInitializeEncoderEtcL();
       
   454     iLandmarkEncoder->SetOutputFileL(KXmlOutputFile);
       
   455     AddCollectionDataToEncoderL();
       
   456     AddLandmarksToEncoderL(!doAddAllLandmarks);
       
   457     User::LeaveIfError(iFile2.Create(iFileServer, KFile2, EFileWrite));
       
   458     ConsumeDiskSpaceL(iFile2, iSizeLimit2);
       
   459     delete iOperation;
       
   460     iOperation = NULL;
       
   461     User::LeaveIfError(iFileServer.Volume(volumeInfoBeforeTest, EDriveC));
       
   462     TRAP(result, iOperation = iLandmarkEncoder->FinalizeEncodingL());
       
   463     User::LeaveIfError(iFileServer.Volume(volumeInfoAfterTest, EDriveC));
       
   464 
       
   465     // Verify
       
   466     _LIT(KFinalizeErr1, "FinalizeL() didn't result in KErrDiskFull but in %d");
       
   467     AssertTrueSecL(result == KErrDiskFull, KFinalizeErr1, result);
       
   468     iLog->Put(_L("FinalizeEncodingL() left with KErrDiskFull"));
       
   469     _LIT(KFinalizeErr2, "FinalizeL() consumed disk space even if critical level has been passed. %d");
       
   470     AssertTrueSecL(volumeInfoBeforeTest.iFree == volumeInfoAfterTest.iFree, KFinalizeErr2);
       
   471 
       
   472     // ************ 23. CPosLandmarkEncoder::SetOutPutFileL() - Bonus test 1 ************
       
   473     iLog->Put(_L("------ CPosLandmarkEncoder::SetOutPutFileL() - Bonus test 1"));
       
   474     iFile2.Close();
       
   475     DeleteFileL(KFile2);
       
   476     ReInitializeEncoderEtcL();
       
   477     User::LeaveIfError(iFile2.Create(iFileServer, KFile2, EFileWrite));
       
   478     ConsumeDiskSpaceL(iFile2, iSizeLimit2);
       
   479     TRAP(result, iLandmarkEncoder->SetOutputFileL(KXmlOutputFile));
       
   480 
       
   481     // Verify
       
   482     AssertTrueSecL(result == KErrDiskFull, KSetFile1, result);
       
   483     iLog->Put(_L("SetOutputFileL() left with KErrDiskFull"));
       
   484 
       
   485     // Try it again
       
   486     TRAP(result, iLandmarkEncoder->SetOutputFileL(KXmlOutputFile));
       
   487 
       
   488     // Verify
       
   489     _LIT(KSetFile3, "SetOutPutFileL() didn't result in KErrAlreadyExists but in %d");
       
   490     AssertTrueSecL(result == KErrAlreadyExists, KSetFile3, result);
       
   491     iLog->Put(_L("SetOutputFileL() left with KErrAlreadyExists"));
       
   492 
       
   493     // ************ 24. CPosLandmarkEncoder::FinalizeL() - Bonus test 2 ************
       
   494     // This test tests if it is possible to finalize when adding LMs to encoder has 
       
   495     // been interrupted due to KErrDiskFull.
       
   496     iLog->Put(_L("------ CPosLandmarkEncoder::FinalizeL() - Bonus test 2"));
       
   497     iFile2.Close();
       
   498     DeleteFileL(KFile2);
       
   499     ReInitializeEncoderEtcL();
       
   500     iLandmarkEncoder->SetOutputFileL(KXmlOutputFile);
       
   501     AddCollectionDataToEncoderL();
       
   502 
       
   503     // Add landmarks will result in KErrDiskFull
       
   504     AddLandmarksToEncoderL(doAddAllLandmarks);
       
   505 
       
   506     // Restore some disk space
       
   507     iFile1.Close();
       
   508     DeleteFileL(KFile1);
       
   509 
       
   510     // Try to finalize
       
   511     delete iOperation;
       
   512     iOperation = NULL;
       
   513     TRAP(result, ExecuteAndDeleteLD(iLandmarkEncoder->FinalizeEncodingL()));
       
   514     AssertTrueSecL(result == KErrNone, _L("FinalizeL() left with %d"), result);
       
   515     iLog->Put(_L("FinalizeL() successful"));
       
   516 
       
   517     // ************ CPosLandmarkEncoder::SetOutPutFileL() - Bonus test 3 ************
       
   518 //  Not tested here since this is a panic test. (Not tested anywhere else)
       
   519 /*    iLog->Put(_L("------ CPosLandmarkEncoder::SetOutPutFileL() - Bonus test 3"));
       
   520     iFile2.Close();
       
   521     DeleteFileL(KFile2);
       
   522     ReInitializeEncoderEtcL();
       
   523     User::LeaveIfError(iFile2.Create(iFileServer, KFile2, EFileWrite));
       
   524     ConsumeDiskSpaceL(iFile2, iSizeLimit2);
       
   525     TRAP(result, iLandmarkEncoder->SetOutputFileL(KXmlOutputFile));
       
   526 
       
   527     // Verify
       
   528     AssertTrueSecL(result == KErrDiskFull, KSetFile1, result);
       
   529     iLog->Put(_L("SetOutputFileL() left with KErrDiskFull"));
       
   530 
       
   531     // Free some disc space and try to finish the export operation. (AddLandmarksL will panic with EPosLmProtocolBreak)
       
   532     iFile2.Close();
       
   533     DeleteFileL(KFile2);
       
   534     AddLandmarksToEncoderL(!doAddAllLandmarks);
       
   535     FinalizeEncoderL(doExecuteIncrementally);*/
       
   536     }
       
   537 
       
   538 // ---------------------------------------------------------
       
   539 // CPosTp55::ImportLandmarksTestL
       
   540 //
       
   541 // (other items were commented in a header).
       
   542 // ---------------------------------------------------------
       
   543 //
       
   544 void CPosTp55::ImportLandmarksTestL(TBool aCriticalLevelPassed)
       
   545     {
       
   546     delete iInputBuffer;
       
   547     iInputBuffer = NULL;
       
   548     iInputBuffer = CreateInputBufferL();
       
   549     TBool doExecuteIncrementally = ETrue;
       
   550 
       
   551     // ************ 3. Import all LMs in XML file incrementally ************
       
   552     iLog->Put(_L("---- Import all LMs in XML file incrementally"));
       
   553     ImportLandmarksL(KXmlInputFile, NULL, doExecuteIncrementally, aCriticalLevelPassed);
       
   554 
       
   555     // ************ 4. Import all LMs in XML file synchronously ************
       
   556     iLog->Put(_L("---- Import all LMs in XML file synchronously"));
       
   557     ImportLandmarksL(KXmlInputFile, NULL, !doExecuteIncrementally, aCriticalLevelPassed);
       
   558 
       
   559     // ************ 5. Import all LMs in XML buffer incrementally ************
       
   560     iLog->Put(_L("---- Import all LMs in XML buffer incrementally"));
       
   561     ImportLandmarksL(KNullDesC, NULL, doExecuteIncrementally, aCriticalLevelPassed);
       
   562 
       
   563     // ************ 6. Import all LMs in XML buffer synchronously ************
       
   564     iLog->Put(_L("---- Import all LMs in XML buffer synchronously"));
       
   565     ImportLandmarksL(KNullDesC, NULL, !doExecuteIncrementally, aCriticalLevelPassed);
       
   566 
       
   567     // Create array of ids to Import (subset of all landmarks in the input file/buffer)
       
   568     RArray<TUint> itemIds;
       
   569     CleanupClosePushL(itemIds);
       
   570     for (TInt i = 10; i < 60; i++)
       
   571         {
       
   572         User::LeaveIfError(itemIds.Append(i));
       
   573         }
       
   574 
       
   575     // ************ 7. Import a subset of LMs in XML file incrementally ************
       
   576     iLog->Put(_L("---- Import a subset of LMs in XML file incrementally"));
       
   577     ImportLandmarksL(KXmlInputFile, &itemIds, doExecuteIncrementally, aCriticalLevelPassed);
       
   578 
       
   579     // ************ 8. Import a subset of LMs in XML file synchronously ************
       
   580     iLog->Put(_L("---- Import a subset of LMs in XML file synchronously"));
       
   581     ImportLandmarksL(KXmlInputFile, &itemIds, !doExecuteIncrementally, aCriticalLevelPassed);
       
   582 
       
   583     // ************ 9. Import a subset of LMs in XML buffer incrementally ************
       
   584     iLog->Put(_L("---- Import a subset of LMs in XML buffer incrementally"));
       
   585     ImportLandmarksL(KNullDesC, &itemIds, doExecuteIncrementally, aCriticalLevelPassed);
       
   586 
       
   587     // ************ 10. Import a subset of LMs in XML buffer synchronously ************
       
   588     iLog->Put(_L("---- Import a subset of LMs in XML buffer synchronously"));
       
   589     ImportLandmarksL(KNullDesC, &itemIds, !doExecuteIncrementally, aCriticalLevelPassed);
       
   590 
       
   591     CleanupStack::PopAndDestroy(&itemIds);
       
   592 
       
   593     iFile2.Close();
       
   594     DeleteFileL(KFile2);
       
   595     }
       
   596 
       
   597 // ---------------------------------------------------------
       
   598 // CPosTp55::ConsumeDiskSpaceL
       
   599 //
       
   600 // (other items were commented in a header).
       
   601 // ---------------------------------------------------------
       
   602 //
       
   603 void CPosTp55::ConsumeDiskSpaceL(
       
   604     RFile& aFile, TInt aSizeLimit)
       
   605     {
       
   606     TInt err(KErrNone);
       
   607 
       
   608     TVolumeInfo volumeInfo;
       
   609     err=iFileServer.Volume(volumeInfo, EDriveC);
       
   610 
       
   611     // Fill file fast
       
   612     HBufC8* bigBuf = (&KNonsense)->AllocLC();
       
   613     while (volumeInfo.iFree > aSizeLimit)
       
   614         {
       
   615         err = aFile.Write(*bigBuf);
       
   616         if (err != KErrNone) iLog->Put(_L("Problem writing"));
       
   617         err = iFileServer.Volume(volumeInfo, EDriveC);
       
   618         if (err != KErrNone) iLog->Put(_L("Problem voluming"));
       
   619         }
       
   620 
       
   621     CleanupStack::PopAndDestroy(bigBuf);
       
   622     }
       
   623 
       
   624 // ---------------------------------------------------------
       
   625 // CPosTp55::ImportLandmarksL
       
   626 //
       
   627 // (other items were commented in a header).
       
   628 // ---------------------------------------------------------
       
   629 //	
       
   630 void CPosTp55::ImportLandmarksL(
       
   631     const TDesC& aInputFile,
       
   632     RArray<TUint>* aArrayOfIds,
       
   633     TBool aExecuteIncrementally,
       
   634     TBool aTestBeyondCriticalLevel)
       
   635     {
       
   636     // Recreate parser
       
   637     delete iLandmarkParser;
       
   638     iLandmarkParser = NULL;
       
   639     
       
   640     // to minimize risk of KErrLocked
       
   641     User::After(500000);
       
   642     iLog->Put(_L("Compacting"));
       
   643     ExecuteAndDeleteLD(iDatabase->CompactL());
       
   644     User::After(500000);
       
   645 
       
   646     iLandmarkParser = CPosLandmarkParser::NewL(KMimeType);
       
   647 
       
   648     iProgress = 0;
       
   649     TBool useInputFile = aInputFile != KNullDesC;
       
   650     TBool importSubset = aArrayOfIds != NULL;
       
   651     TInt result(KErrNone);
       
   652 
       
   653     // Prepare and set output for exported LMs
       
   654     if (useInputFile)
       
   655         {
       
   656         iLog->Put(_L("SetInputFileL"));
       
   657         iLandmarkParser->SetInputFileL(aInputFile);
       
   658         }
       
   659     else // use buffer as output
       
   660         {
       
   661         iLog->Put(_L("SetInputBuffer"));
       
   662         iLandmarkParser->SetInputBuffer(*iInputBuffer);
       
   663         }
       
   664 
       
   665     // Sample the db size
       
   666     CPosLandmarkDatabase::TSize dbSizeBeforeImport;
       
   667     TInt err = KErrLocked;
       
   668     while (err == KErrLocked)
       
   669         {
       
   670         TRAP(err, dbSizeBeforeImport = iDatabase->SizeL());
       
   671         if (err == KErrLocked) 
       
   672             {
       
   673             iLog->Put(_L("KErrLocked from iDatabase->SizeL()"));
       
   674             User::After(100000);
       
   675             }
       
   676         }
       
   677 
       
   678     // Start importing LMs.
       
   679     delete iOperation;
       
   680     iOperation = NULL;
       
   681     if (importSubset)
       
   682         {
       
   683         iLog->Put(_L("ImportLandmarksL"));
       
   684         iOperation = iDatabase->ImportLandmarksL(
       
   685             *iLandmarkParser, *aArrayOfIds, CPosLandmarkDatabase::EDefaultOptions);
       
   686         }
       
   687     else
       
   688         {
       
   689         iLog->Put(_L("ImportLandmarksL"));
       
   690         iOperation = iDatabase->ImportLandmarksL(
       
   691             *iLandmarkParser, CPosLandmarkDatabase::EDefaultOptions);
       
   692         }
       
   693 
       
   694     // Execute importing LMs
       
   695     iLog->Put(_L("ExecuteLmOperationL"));
       
   696     result = ExecuteLmOperationL(aExecuteIncrementally);
       
   697 
       
   698     // Check result
       
   699     _LIT(KErrMsg, "ImportLandmarksL() didn't result in KErrDiskFull but in %d");
       
   700     AssertTrueSecL(result == KErrDiskFull, KErrMsg, result);
       
   701 
       
   702     if (aTestBeyondCriticalLevel)
       
   703         {
       
   704         // Sample the db size
       
   705         TInt err2 = KErrLocked;
       
   706         CPosLandmarkDatabase::TSize dbSizeAfterImport;
       
   707         while (err2 == KErrLocked)
       
   708             {
       
   709             TRAP(err2, dbSizeAfterImport = iDatabase->SizeL());
       
   710             if (err2 == KErrLocked)
       
   711                 {
       
   712                 iLog->Put(_L("KErrLocked from iDatabase->SizeL(2)"));
       
   713                 User::After(100000);
       
   714                 }
       
   715             }
       
   716 
       
   717         TBool dbSizeIsConstant = dbSizeAfterImport.iFileSize == dbSizeBeforeImport.iFileSize;
       
   718         _LIT(KErrMsg, "Database size has changed when importing landmarks beyond critical level");
       
   719         if (!dbSizeIsConstant)
       
   720             {
       
   721             LogErrorAndLeave(KErrMsg);
       
   722             }
       
   723         iLog->Put(_L("Size of database untouched when importing landmarks beyond critical level"));
       
   724         }
       
   725     else
       
   726         {
       
   727         if (aExecuteIncrementally)
       
   728             {
       
   729             _LIT(KFormat, "Got KErrDiskFull after importing %d%% of the landmarks.");
       
   730             iMsg.Format(KFormat, iProgress);
       
   731             }
       
   732         else
       
   733             {
       
   734             _LIT(KFormat, "Got KErrDiskFull when importing landmarks synchronously");
       
   735             iMsg.Copy(KFormat());
       
   736             }
       
   737         iLog->Put(iMsg);
       
   738         }
       
   739     }
       
   740 
       
   741 // ---------------------------------------------------------
       
   742 // CPosTp55::InitiateCriticalLevelL
       
   743 // Initiates iCriticalLevel. (value of iCriticalLevel is extracted from an MLFW 
       
   744 // resource file that can reside on any drive)
       
   745 // (other items were commented in a header).
       
   746 // ---------------------------------------------------------
       
   747 //	
       
   748 void CPosTp55::InitiateCriticalLevelL()
       
   749     { 
       
   750     iLog->Put(_L("InitiateCriticalLevelL"));
       
   751     /*
       
   752     // Find drive that the resource file resides on.
       
   753     TFindFile* filefinder = new (ELeave) TFindFile(iFileServer);
       
   754     CleanupStack::PushL(filefinder);
       
   755     TParse* fileparser = new (ELeave) TParse;
       
   756     CleanupStack::PushL(fileparser);
       
   757     fileparser->Set(KPosResourceFile, NULL, NULL);
       
   758     User::LeaveIfError(
       
   759         filefinder->FindByDir(fileparser->NameAndExt(), fileparser->DriveAndPath()));
       
   760 
       
   761     // Open resource file
       
   762     RResourceFile resFile;
       
   763     resFile.OpenL(iFileServer, filefinder->File());
       
   764     CleanupClosePushL(resFile);
       
   765 
       
   766     // Allocate the critical level as a buffer
       
   767     //TInt R_POS_LANDMARK_INTERNAL_CRITICAL_DISK_LEVEL = 250;
       
   768     HBufC8* resourceBuffer = resFile.AllocReadLC(iCriticalThreshold);
       
   769 
       
   770     // Convert the buffer to an int
       
   771     TResourceReader resReader;
       
   772     resReader.SetBuffer(resourceBuffer);
       
   773     iCriticalLevel = KOneK * resReader.ReadInt16();
       
   774     CleanupStack::PopAndDestroy(4, filefinder);
       
   775     */
       
   776     iCriticalLevel = iCriticalThreshold;
       
   777     iSizeLimit1 = iCriticalLevel + 18 * KOneK; // Do not mess with this value!
       
   778     iSizeLimit2 = iCriticalLevel - 20 * KOneK;
       
   779 
       
   780     iMsg.Format(_L("CriticalLevel = %d, limit1 = %d, limit2 = %d "), iCriticalLevel, iSizeLimit1, iSizeLimit2);
       
   781     iLog->Put(iMsg);
       
   782     }
       
   783 
       
   784 // ---------------------------------------------------------
       
   785 // CPosTp55::LogVolumeInfoL
       
   786 // Initiates iCriticalLevel. (value of iCriticalLevel is extracted from an MLFW 
       
   787 // resource file that can reside on any drive)
       
   788 // (other items were commented in a header).
       
   789 // ---------------------------------------------------------
       
   790 //	
       
   791 void CPosTp55::LogVolumeInfoL()
       
   792     {
       
   793     _LIT(KUID,"Unique ID: %08x\r\n");
       
   794     _LIT(KSize,"Size: %d bytes\r\n");
       
   795     _LIT(KFree,"Free space: %d bytes\r\n");
       
   796 
       
   797     TVolumeInfo volumeInfo;
       
   798     TInt err = iFileServer.Volume(volumeInfo, EDriveC);
       
   799     if (err != KErrNone) 
       
   800         LogErrorAndLeave(_L("Error from iFileServer"));
       
   801 
       
   802     iMsg.Zero();
       
   803     iMsg.AppendFormat(KUID, volumeInfo.iUniqueID);
       
   804 	iMsg.AppendFormat(KSize, volumeInfo.iSize);
       
   805 	iMsg.AppendFormat(KFree, volumeInfo.iFree);
       
   806     iLog->Put(_L("\r\nMemory info:"));
       
   807     iLog->Put(iMsg);
       
   808     }
       
   809 
       
   810 // ---------------------------------------------------------
       
   811 // CPosTp55::DeleteFileL
       
   812 //
       
   813 // (other items were commented in a header).
       
   814 // ---------------------------------------------------------
       
   815 //
       
   816 void CPosTp55::DeleteFileL(const TDesC& aFile)
       
   817     {
       
   818     TInt err = iFileServer.Delete(aFile);
       
   819 
       
   820     if (err != KErrNone && err != KErrNotFound)
       
   821         {
       
   822         _LIT(KErrText, "DeleteFileL(): The file %S could not be deleted, errorcode %d");
       
   823         iMsg.Format(KErrText, &aFile, err);
       
   824         LogErrorAndLeave(iMsg, err);
       
   825         }
       
   826     }
       
   827 
       
   828 // ---------------------------------------------------------
       
   829 // CPosTp55::FillFile3L
       
   830 //
       
   831 // (other items were commented in a header).
       
   832 // ---------------------------------------------------------
       
   833 //
       
   834 void CPosTp55::FillFile3L()
       
   835     {
       
   836     iFile3.Close();
       
   837     iFileServer.Delete(KFile3);
       
   838     User::LeaveIfError(iFile3.Create(iFileServer, KFile3, EFileWrite));
       
   839 
       
   840     TVolumeInfo volumeInfo;
       
   841     User::LeaveIfError(iFileServer.Volume(volumeInfo, EDriveC));
       
   842     while (volumeInfo.iFree > iCriticalLevel + 512)
       
   843         {
       
   844         User::LeaveIfError(iFile3.Write(K64B));
       
   845         User::LeaveIfError(iFileServer.Volume(volumeInfo, EDriveC));
       
   846         }
       
   847     }
       
   848 
       
   849 // ---------------------------------------------------------
       
   850 // CPosTp55::CreateInputBufferL
       
   851 //
       
   852 // (other items were commented in a header).
       
   853 // ---------------------------------------------------------
       
   854 //
       
   855 HBufC8* CPosTp55::CreateInputBufferL()
       
   856     {
       
   857     RFile inputFile;
       
   858     User::LeaveIfError(inputFile.Open(iFileServer, KXmlInputFile, EFileRead));
       
   859     CleanupClosePushL(inputFile);
       
   860 
       
   861     TInt fileSize;
       
   862     User::LeaveIfError(inputFile.Size(fileSize));
       
   863     HBufC8* buffer = HBufC8::NewLC(fileSize);
       
   864 
       
   865     // Copy file contents to buffer
       
   866     TPtr8 writableBuffer = buffer->Des();
       
   867     User::LeaveIfError(inputFile.Read(writableBuffer, fileSize));
       
   868 
       
   869     CleanupStack::Pop(buffer);
       
   870     CleanupStack::PopAndDestroy(&inputFile);
       
   871     return buffer;
       
   872     }
       
   873 
       
   874 // ---------------------------------------------------------
       
   875 // CPosTp55::ReInitializeEncoderEtcL
       
   876 //
       
   877 // (other items were commented in a header).
       
   878 // ---------------------------------------------------------
       
   879 //
       
   880 void CPosTp55::ReInitializeEncoderEtcL()
       
   881     {
       
   882     delete iLandmarkEncoder;
       
   883     iLandmarkEncoder = NULL;
       
   884     iLandmarkEncoder = CPosLandmarkEncoder::NewL(KMimeType);
       
   885 
       
   886     DeleteFileL(KXmlOutputFile);
       
   887     DeleteFileL(KXmlBufferDumpFile);
       
   888     iFile3.Close();
       
   889     DeleteFileL(KFile3);
       
   890 
       
   891     iProgress = 0;
       
   892     }
       
   893 
       
   894 // ---------------------------------------------------------
       
   895 // CPosTp55::ReInitializeEncoderEtcL
       
   896 //
       
   897 // (other items were commented in a header).
       
   898 // ---------------------------------------------------------
       
   899 //
       
   900 TInt CPosTp55::ExecuteLmOperationL(
       
   901     TBool aExecuteIncrementally)
       
   902     {
       
   903     TInt result(0);
       
   904 
       
   905     if (aExecuteIncrementally)
       
   906         {
       
   907         // Execute the finalizing incrementally.
       
   908         iOperationWrapper->Start(iOperation, this);
       
   909         CActiveScheduler::Start();
       
   910         result = iOperationWrapper->iStatus.Int();
       
   911         }
       
   912     else
       
   913         {
       
   914         TRAP(result, iOperation->ExecuteL());
       
   915         }
       
   916 
       
   917     return result;
       
   918     }
       
   919 
       
   920 // ---------------------------------------------------------
       
   921 // CPosTp55::SetOutputBufferL
       
   922 //
       
   923 // (other items were commented in a header).
       
   924 // ---------------------------------------------------------
       
   925 //
       
   926 void CPosTp55::SetOutputBufferL()
       
   927     {
       
   928     delete iOutputBuffer;
       
   929     iOutputBuffer = NULL;
       
   930     iOutputBuffer = iLandmarkEncoder->SetUseOutputBufferL(); 
       
   931     }
       
   932 
       
   933 // ---------------------------------------------------------
       
   934 // CPosTp55::AddCollectionDataToEncoderL
       
   935 //
       
   936 // (other items were commented in a header).
       
   937 // ---------------------------------------------------------
       
   938 //
       
   939 void CPosTp55::AddCollectionDataToEncoderL()
       
   940     {
       
   941     // Add long collection name to encoder
       
   942     HBufC* collectionName = HBufC::NewLC(2 * KNonsense().Length());
       
   943     collectionName->Des().Copy(KNonsense);
       
   944     iLandmarkEncoder->AddCollectionDataL(EPosLmCollDataCollectionName, *collectionName);
       
   945 
       
   946     // Add long collection desc to encoder
       
   947     HBufC* collectionDesc = HBufC::NewLC(3 * collectionName->Length());
       
   948     collectionDesc->Des().Append(*collectionName);
       
   949     collectionDesc->Des().Append(*collectionName);
       
   950     collectionDesc->Des().Append(*collectionName);
       
   951     iLandmarkEncoder->AddCollectionDataL(EPosLmCollDataCollectionDescription, *collectionDesc);
       
   952     CleanupStack::PopAndDestroy(2, collectionName);
       
   953     }
       
   954 
       
   955 // ---------------------------------------------------------
       
   956 // CPosTp55::AddLandmarksToEncoderL
       
   957 //
       
   958 // (other items were commented in a header).
       
   959 // ---------------------------------------------------------
       
   960 //
       
   961 void CPosTp55::AddLandmarksToEncoderL(TBool aAddAll)
       
   962     {
       
   963     // Add landmarks to export to encoder manually.
       
   964     TInt result(0);
       
   965     CPosLmItemIterator* iterator = iDatabase->LandmarkIteratorL();
       
   966     CleanupStack::PushL(iterator);
       
   967     TInt maxNrOfLMs = (aAddAll) ? iterator->NumOfItemsL() : KNrOfLandmarksToExport;
       
   968     for (TInt i = 0; i < maxNrOfLMs && result != KErrDiskFull; i++)
       
   969         {
       
   970         CPosLandmark* landmark = iDatabase->ReadLandmarkLC(iterator->NextL());
       
   971         TRAP(result, iLandmarkEncoder->AddLandmarkL(*landmark));
       
   972         if (result == KErrLocked)
       
   973             {
       
   974             iLog->Put(_L("KErrLocked when AddLandmarkL in AddLandmarksToEncoderL"));
       
   975             User::After(100000);
       
   976             }
       
   977         CleanupStack::PopAndDestroy(landmark);
       
   978         iProgress = (TInt) (100 * i / maxNrOfLMs);
       
   979         }
       
   980     CleanupStack::PopAndDestroy(iterator);
       
   981 
       
   982     if (aAddAll)
       
   983         {
       
   984         if (result == KErrDiskFull)
       
   985             {
       
   986             iMsg.Format(_L("Got KErrDiskFull after adding %d%% of the landmarks to the encoder."), iProgress);
       
   987             iLog->Put(iMsg);
       
   988             }
       
   989         else
       
   990             {
       
   991             _LIT(KAddLmErr, "Didn't get EKrrDiskFull but %d when adding LMs to encoder");
       
   992             LogVolumeInfoL();
       
   993             LogErrorAndLeave(KAddLmErr);
       
   994             }
       
   995         }
       
   996     else
       
   997         {
       
   998         _LIT(KAddLmErr, "Didn't get EKrrNone but %d when adding LMs to encoder");
       
   999         AssertTrueSecL(result == KErrNone, KAddLmErr, result);
       
  1000         }
       
  1001     }
       
  1002 
       
  1003 // ---------------------------------------------------------
       
  1004 // CPosTp55::ExportWithExportLandmarksMethodL()
       
  1005 //
       
  1006 // (other items were commented in a header).
       
  1007 // ---------------------------------------------------------
       
  1008 //
       
  1009 void CPosTp55::ExportWithExportLandmarksMethodL(
       
  1010     RArray<TPosLmItemId>& aArrayOfIds,
       
  1011     TBool aExecuteIncrementally)
       
  1012     {
       
  1013     delete iOperation;
       
  1014     iOperation = NULL;
       
  1015     iOperation = iDatabase->ExportLandmarksL(
       
  1016         *iLandmarkEncoder, aArrayOfIds, CPosLandmarkDatabase::EDefaultOptions);
       
  1017     TInt result = ExecuteLmOperationL(aExecuteIncrementally);
       
  1018 
       
  1019     if (aArrayOfIds.Count() == KNrOfLandmarksToExport) // not all of the LMs have been added
       
  1020         {
       
  1021         // Check that KErrDiskFull is not returned
       
  1022         _LIT(KErrMsg, "Expected KErrNone from ExportLandmarksL() but got %d.");
       
  1023         AssertTrueSecL(result == KErrNone, KErrMsg, result);
       
  1024         }
       
  1025     else // We should have gotten KErrDiskFull when adding LMs to encoder.
       
  1026         {
       
  1027         _LIT(KErrMsg, "ExportLandmarksL() didn't result in KErrDiskFull but in %d");
       
  1028         AssertTrueSecL(result == KErrDiskFull, KErrMsg, result);
       
  1029         if (aExecuteIncrementally)
       
  1030             {
       
  1031             iMsg.Format(_L("Got KErrDiskFull after adding %d%% of the landmarks to the encoder."), iProgress);
       
  1032             }
       
  1033         else
       
  1034             {
       
  1035             iMsg = _L("Got KErrDiskFull when exporting landmarks synchronously");            
       
  1036             }
       
  1037         iLog->Put(iMsg);
       
  1038         }
       
  1039     }
       
  1040 
       
  1041 // ---------------------------------------------------------
       
  1042 // CPosTp55::FinalizeEncoderL()
       
  1043 //
       
  1044 // (other items were commented in a header).
       
  1045 // ---------------------------------------------------------
       
  1046 //
       
  1047 void CPosTp55::FinalizeEncoderL(
       
  1048     TBool aExecuteIncrementally)
       
  1049     {
       
  1050     delete iOperation;
       
  1051     iOperation = NULL;
       
  1052     TRAPD(result, iOperation = iLandmarkEncoder->FinalizeEncodingL());
       
  1053     if (result == KErrNone)
       
  1054         {
       
  1055         result = ExecuteLmOperationL(aExecuteIncrementally);
       
  1056 
       
  1057         // Check that KErrDiskFull is returned
       
  1058         _LIT(KErrMsg, "FinalizeL() didn't result in KErrDiskFull but in %d");
       
  1059         AssertTrueSecL(result == KErrDiskFull, KErrMsg, result);
       
  1060         iLog->Put(_L("Execution of FinalizeEncodingL() left with KErrDiskFull"));
       
  1061         }
       
  1062     else
       
  1063         {
       
  1064         AssertTrueSecL(result == KErrDiskFull, _L("FinalizeEncodingL() left with %d"), result);
       
  1065         iLog->Put(_L("FinalizeEncodingL() left with KErrDiskFull"));
       
  1066         }
       
  1067     }
       
  1068 
       
  1069 // ---------------------------------------------------------
       
  1070 // CPosTp55::FinalizeEncoderL()
       
  1071 //
       
  1072 // (other items were commented in a header).
       
  1073 // ---------------------------------------------------------
       
  1074 //
       
  1075 void CPosTp55::PopulateArrayL(
       
  1076     RArray<TPosLmItemId>& aArray,
       
  1077     TBool aDoAddAllLms)
       
  1078     {
       
  1079     CPosLmItemIterator* iterator = iDatabase->LandmarkIteratorL();
       
  1080     CleanupStack::PushL(iterator);
       
  1081     TInt nrOfLms = aDoAddAllLms ? iterator->NumOfItemsL() : KNrOfLandmarksToExport;
       
  1082     for (TInt i = 0; i < nrOfLms; i++)
       
  1083         {
       
  1084         CPosLandmark* landmark = iDatabase->ReadLandmarkLC(iterator->NextL());
       
  1085         User::LeaveIfError(aArray.Append(landmark->LandmarkId()));
       
  1086         CleanupStack::PopAndDestroy(landmark);
       
  1087         }
       
  1088     CleanupStack::PopAndDestroy(iterator);
       
  1089     }
       
  1090 
       
  1091 // ---------------------------------------------------------
       
  1092 // CPosTp55::CopyResourceFileL
       
  1093 // 
       
  1094 // (other items were commented in a header).
       
  1095 // ---------------------------------------------------------
       
  1096 //
       
  1097 void CPosTp55::CopyResourceFileL(const TDesC& aResourceFile)
       
  1098     {
       
  1099     // Release all landmark references to make DLLs be unloaded.
       
  1100     delete iDatabase;
       
  1101     iDatabase = NULL;
       
  1102     delete iLandmarkEncoder;
       
  1103     iLandmarkEncoder = NULL;
       
  1104     delete iLandmarkParser;
       
  1105     iLandmarkParser = NULL;
       
  1106     delete iOperation;
       
  1107     iOperation = NULL;
       
  1108 
       
  1109     CFileMan* fileMan = CFileMan::NewL(iFileServer);
       
  1110     CleanupStack::PushL(fileMan);
       
  1111     
       
  1112     // Check if landmark is flashed
       
  1113      if (!BaflUtils::FileExists(iFileServer, KInternalServicesResFileRom))
       
  1114         {
       
  1115          iLog->Put(_L("Landmark is NOT flashed, backing up eposlmintservices.rsc by renaming it bofore copying rsc-file."));
       
  1116         // Landmark FW is not flashed. Rename the file before copying an own defiend file.
       
  1117         // Since landmark FW is not flashed the file should exist hence leaving if it is not found!
       
  1118          User::LeaveIfError(fileMan->Rename(KInternalServicesResFileCdrive, KInternalServicesResFileBackup, CFileMan::EOverWrite));
       
  1119         }
       
  1120      else
       
  1121         {
       
  1122         iLog->Put(_L("Landmark framework is flashed, copying global categories to c:"));
       
  1123         }
       
  1124 
       
  1125     User::LeaveIfError(fileMan->Copy(aResourceFile, KInternalServicesResFileCdrive, CFileMan::EOverWrite));
       
  1126  
       
  1127     CleanupStack::PopAndDestroy(fileMan);
       
  1128     }
       
  1129 
       
  1130 // ---------------------------------------------------------
       
  1131 // CPosTp55::TryRestoreResourceFile
       
  1132 // 
       
  1133 // (other items were commented in a header).
       
  1134 // ---------------------------------------------------------
       
  1135 //
       
  1136 void CPosTp55::TryRestoreResourceFile()
       
  1137     {
       
  1138     CFileMan* fileMan = NULL;
       
  1139     TRAPD(err, fileMan = CFileMan::NewL(iFileServer));
       
  1140     if (fileMan)
       
  1141         {
       
  1142         // Try to restore the backup up rsc-file (only possible when LM FW is not flashed.
       
  1143         TInt result = fileMan->Copy(KInternalServicesResFileBackup, KInternalServicesResFileCdrive, CFileMan::EOverWrite);
       
  1144         if (result == KErrNotFound)
       
  1145             {
       
  1146             if (BaflUtils::FileExists(iFileServer, KInternalServicesResFileRom))
       
  1147                 {
       
  1148                 // LM FW is flashed. We need to remove the rsc-file on c:
       
  1149                 fileMan->Delete(KInternalServicesResFileCdrive);
       
  1150                 }
       
  1151             }
       
  1152         delete fileMan;
       
  1153         }
       
  1154     }
       
  1155 
       
  1156 // End of file