landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp8.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_CPosTp8.h"
       
    22 #include <EPos_CPosLandmarkDatabase.h> 
       
    23 #include <EPos_CPosLandmark.h>
       
    24 #include <LbsPosition.h>
       
    25 #include <EPos_CPosLMOperation.h> 
       
    26 #include "FT_LandmarkConstants.h"
       
    27 
       
    28 // CONSTANTS
       
    29 const TInt KNoLandmarks = 100;
       
    30  
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // CPosTp8::CloseTest
       
    35 //
       
    36 // (other items were commented in a header).
       
    37 // ---------------------------------------------------------
       
    38 //
       
    39 void CPosTp8::CloseTest()
       
    40     {
       
    41     iLog->Log(_L("CloseTest"));
       
    42     iLandmarks.ResetAndDestroy();
       
    43     iLandmarks.Close();    
       
    44     delete iDatabase;
       
    45     iDatabase=NULL;
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------
       
    49 // CPosTp8::StartL
       
    50 //
       
    51 // (other items were commented in a header).
       
    52 // ---------------------------------------------------------
       
    53 //
       
    54 void CPosTp8::StartL()
       
    55     {    
       
    56     _LIT(KLogFileName, "c:\\documents\\TP8TimeMeasurements.txt");
       
    57     
       
    58     TTime start, stop, totalStart, totalStop;
       
    59     totalStart.UniversalTime();
       
    60 	start.UniversalTime();
       
    61     RemoveDefaultDbL();
       
    62     RemoveAllLmDatabasesL();
       
    63     
       
    64     _LIT(KTestPath, "c:\\system\\test\\testdata\\");
       
    65     // copy the test db to the private path
       
    66     CFileMan* fileMan = CFileMan::NewL(iFileSession);
       
    67     CleanupStack::PushL(fileMan);
       
    68 
       
    69     TBuf<150> srcPath;
       
    70 
       
    71     srcPath.Append(KTestPath);
       
    72     srcPath.Append(KTp8TestDb);
       
    73 
       
    74     TInt err = fileMan->Copy(srcPath, KLmTp8DefaultDbPath,
       
    75             CFileMan::EOverWrite);
       
    76     if (err != KErrNone)
       
    77         iLog->Log(_L("Error when copying file"));
       
    78 
       
    79     CleanupStack::PopAndDestroy(fileMan);
       
    80     CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL();
       
    81     CleanupStack::PushL(manager);
       
    82 
       
    83     // This db must exist
       
    84     manager->SetDefaultDatabaseUriL(KTp8TestDb);
       
    85     CleanupStack::PopAndDestroy(manager);
       
    86 
       
    87     start.UniversalTime();
       
    88     iDatabase= CPosLandmarkDatabase::OpenL(KTp8TestDb);
       
    89     stop.UniversalTime();
       
    90     
       
    91     TInt64 msec = (stop.Int64() - start.Int64())/1000;
       
    92 	TBuf8<KMsgBufSize> msg;
       
    93 	_LIT8(KTrace, "Opening (creating) an empty database = %d msec");
       
    94 	msg.Format(KTrace, msec);
       
    95 	LogToFileL(KLogFileName, msg);
       
    96     
       
    97     if (iDatabase->IsInitializingNeeded())
       
    98        {
       
    99        start.UniversalTime();
       
   100        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   101         
       
   102        stop.UniversalTime();
       
   103        msec = (stop.Int64() - start.Int64())/1000;
       
   104        _LIT8(KTrace2, "Initializing an empty database = %d msec");
       
   105 	   msg.Format(KTrace2, msec);
       
   106 	   LogToFileL(KLogFileName, msg);
       
   107        }
       
   108 
       
   109 // Add landmarks      
       
   110     start.UniversalTime();
       
   111     AddLandmarksL(iDatabase);
       
   112     stop.UniversalTime();    
       
   113  
       
   114     msec = (stop.Int64() - start.Int64())/1000;
       
   115     _LIT8(KTrace3, "AddLandmarksL = %d msec");
       
   116 	msg.Format(KTrace3, msec);
       
   117 	LogToFileL(KLogFileName, msg);
       
   118         
       
   119     delete iDatabase;
       
   120     iDatabase=NULL;   
       
   121     iDatabase = BackupTp8DbFileL();
       
   122 
       
   123 if (iDatabase->IsInitializingNeeded())
       
   124        {
       
   125        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   126        }
       
   127        
       
   128 // Read landmarks    
       
   129     start.UniversalTime();
       
   130     ReadLandmarksL(iDatabase);
       
   131     stop.UniversalTime();    
       
   132     
       
   133     msec = (stop.Int64() - start.Int64())/1000;
       
   134     _LIT8(KTrace4, "ReadLandmarksL = %d msec");
       
   135 	msg.Format(KTrace4, msec);
       
   136 	LogToFileL(KLogFileName, msg);
       
   137 
       
   138 // Update landmarks    
       
   139     start.UniversalTime();
       
   140     UpdateLandmarksL(iDatabase);
       
   141     stop.UniversalTime();   
       
   142     
       
   143     msec = (stop.Int64() - start.Int64())/1000;
       
   144     _LIT8(KTrace5, "UpdateLandmarksL = %d msec");
       
   145 	msg.Format(KTrace5, msec);
       
   146 	LogToFileL(KLogFileName, msg);
       
   147     
       
   148     ReadLandmarksL(iDatabase);
       
   149     
       
   150 // Remove landmarks one by one
       
   151     start.UniversalTime();
       
   152     RemoveLandmarksL(iDatabase);
       
   153     stop.UniversalTime();   
       
   154     
       
   155     msec = (stop.Int64() - start.Int64())/1000;
       
   156     _LIT8(KTrace6, "RemoveLandmarksL = %d msec");
       
   157 	msg.Format(KTrace6, msec);
       
   158 	LogToFileL(KLogFileName, msg);
       
   159 
       
   160     // Restore database
       
   161     delete iDatabase;
       
   162     iDatabase=NULL;
       
   163     iDatabase=RestoreTp8DbFileL();
       
   164         
       
   165         if (iDatabase->IsInitializingNeeded())
       
   166        {
       
   167        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   168        }
       
   169 
       
   170 // Remove set of landmarks synchronously
       
   171     start.UniversalTime();
       
   172     RemoveSetOfLandmarksL(iDatabase);
       
   173     stop.UniversalTime();   
       
   174     
       
   175     msec = (stop.Int64() - start.Int64())/1000;
       
   176     _LIT8(KTrace7, "RemoveSetOfLandmarksL = %d msec");
       
   177 	msg.Format(KTrace7, msec);
       
   178 	LogToFileL(KLogFileName, msg);
       
   179     
       
   180     // Restore database
       
   181     delete iDatabase;
       
   182     iDatabase=NULL;
       
   183     iDatabase=RestoreTp8DbFileL();
       
   184     
       
   185     if (iDatabase->IsInitializingNeeded())
       
   186        {
       
   187        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   188        }
       
   189 
       
   190 // Remove set of landmarks and remove all landmarks asynchronously
       
   191     start.UniversalTime();
       
   192     RemoveLandmarksAsyncL(iDatabase);
       
   193     stop.UniversalTime();   
       
   194     
       
   195     msec = (stop.Int64() - start.Int64())/1000;
       
   196     _LIT8(KTrace8, "RemoveLandmarksAsyncL = %d msec");
       
   197 	msg.Format(KTrace8, msec);
       
   198 	LogToFileL(KLogFileName, msg);
       
   199 	
       
   200     // Restore database
       
   201     delete iDatabase;
       
   202     iDatabase=NULL;
       
   203     iDatabase=RestoreTp8DbFileL();
       
   204     
       
   205     if (iDatabase->IsInitializingNeeded())
       
   206        {
       
   207        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   208        }
       
   209      
       
   210 // Remove set of landmarks and remove all landmarks with User::WaitForRequest()
       
   211     start.UniversalTime();
       
   212     RemoveLandmarksAsyncWithWaitForReqL(iDatabase);
       
   213     stop.UniversalTime();   
       
   214     
       
   215     msec = (stop.Int64() - start.Int64())/1000;
       
   216     _LIT8(KTrace9, "RemoveLandmarksAsyncWithWaitForReqL = %d msec");
       
   217 	msg.Format(KTrace9, msec);
       
   218 	LogToFileL(KLogFileName, msg);
       
   219 
       
   220     // Restore database
       
   221     delete iDatabase;
       
   222     iDatabase=NULL;
       
   223     iDatabase=RestoreTp8DbFileL();
       
   224     
       
   225     if (iDatabase->IsInitializingNeeded())
       
   226        {
       
   227        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   228        }
       
   229     
       
   230 // Remove set of landmarks asynchronously and cancel
       
   231     iLog->Log(_L("TESTS BELOW ARE TESTING CANCEL"));
       
   232     RemoveLandmarksAsyncAndCancelL();
       
   233     
       
   234     // Check maximum length of Landmarkname
       
   235     CheckLandmarkNameMaxLengthL();
       
   236 	
       
   237     totalStop.UniversalTime();   
       
   238     msec = (totalStop.Int64() - totalStart.Int64())/1000;
       
   239     _LIT8(KTrace10, "Complete test case = %d msec");
       
   240 	msg.Format(KTrace10, msec);
       
   241 	LogToFileL(KLogFileName, msg);
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------
       
   245 // CPosTp8::AddLandmarksL
       
   246 //
       
   247 // (other items were commented in a header).
       
   248 // ---------------------------------------------------------
       
   249 //
       
   250 void CPosTp8::AddLandmarksL(CPosLandmarkDatabase* aDatabase)
       
   251     {
       
   252     iLog->Log(_L("Adding and copying landmarks"));
       
   253     
       
   254     _LIT(KCategoryAddedErr, "A category that doesn't exist in the database should not be added to the landmark");    
       
   255     _LIT(KLmName, "LmTP8 - %d");
       
   256     _LIT(KLmDescription, "LmTP8Description - %d");
       
   257     
       
   258     iLandmarks.ResetAndDestroy();
       
   259     for (TInt i=0; i<(KNoLandmarks/4); i++)
       
   260         {
       
   261         TBuf<100> lmName;
       
   262         TBuf<100> lmDesc;
       
   263         lmName.Format(KLmName,i);
       
   264         CPosLandmark* landmark = CPosLandmark::NewLC();
       
   265         landmark->SetLandmarkNameL(lmName);
       
   266         lmDesc.Format(KLmDescription,i);
       
   267         landmark->SetLandmarkDescriptionL(lmDesc);
       
   268 
       
   269         CPosLandmark* copy = CPosLandmark::NewLC(*landmark);
       
   270       
       
   271         CPosLandmark* landmark2 = CPosLandmark::NewL();
       
   272         CleanupStack::PushL(landmark2);    
       
   273         landmark2->SetLandmarkNameL(lmName); 
       
   274         landmark2->SetLandmarkDescriptionL(lmDesc); 
       
   275 
       
   276         CPosLandmark* copy2 = CPosLandmark::NewL(*landmark2);
       
   277         CleanupStack::PushL(copy2);
       
   278         TInt err = KErrLocked;
       
   279         
       
   280         ExecuteAndDeleteLD(aDatabase->CompactL());
       
   281         
       
   282         while (err == KErrLocked)
       
   283             {
       
   284             TRAP(err, aDatabase->AddLandmarkL(*landmark));
       
   285             }
       
   286         err = KErrLocked;
       
   287         while (err == KErrLocked)
       
   288             {
       
   289             TRAP(err, aDatabase->AddLandmarkL(*copy));
       
   290             }
       
   291         err = KErrLocked;
       
   292         while (err == KErrLocked)
       
   293             {
       
   294             TRAP(err, aDatabase->AddLandmarkL(*landmark2));
       
   295             }
       
   296         err = KErrLocked;
       
   297         while (err == KErrLocked)
       
   298             {
       
   299             TRAP(err, aDatabase->AddLandmarkL(*copy2));
       
   300             }
       
   301       
       
   302         TPosLmItemId id2 = 5123321;
       
   303         CPosLandmark* landmark3 = CPosLandmark::NewLC();
       
   304         landmark3->AddCategoryL(id2);
       
   305         landmark3->AddCategoryL(id2);
       
   306         
       
   307         err = KErrLocked;
       
   308         while (err == KErrLocked)
       
   309             {
       
   310             TRAP(err, aDatabase->AddLandmarkL(*landmark3)); // CR115 this should not fail any more 
       
   311             }
       
   312         
       
   313         CPosLandmark* readLm3 = aDatabase->ReadLandmarkLC(landmark3->LandmarkId());
       
   314         
       
   315         RArray<TPosLmItemId> catIds;
       
   316         CleanupClosePushL(catIds);
       
   317         readLm3->GetCategoriesL(catIds);
       
   318         AssertTrueSecL(catIds.Count() == 0, KCategoryAddedErr); 
       
   319         CleanupStack::PopAndDestroy(3, landmark3);
       
   320 
       
   321         iLandmarks.Append(landmark);
       
   322         iLandmarks.Append(copy);
       
   323         iLandmarks.Append(landmark2);
       
   324         iLandmarks.Append(copy2);
       
   325             
       
   326         CleanupStack::Pop(4, landmark); 
       
   327         }   
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------
       
   331 // CPosTp8::ReadLandmarksL
       
   332 //
       
   333 // (other items were commented in a header).
       
   334 // ---------------------------------------------------------
       
   335 //
       
   336 void CPosTp8::ReadLandmarksL(CPosLandmarkDatabase* aDatabase)
       
   337     {
       
   338     iLog->Log(_L("Reading landmarks"));
       
   339 
       
   340     _LIT(KReadNotFoundErr, "The landmark id doesn't exist so ReadLandmark should return not found");    
       
   341     TBuf<100> buf;
       
   342     buf.Format(_L("Reading %d nr of landmarks from id %d to id %d"), iLandmarks.Count(), 
       
   343     				iLandmarks[0]->LandmarkId(), iLandmarks[iLandmarks.Count()-1]->LandmarkId());
       
   344     iLog->Log(buf);
       
   345     for (TInt i = 0; i<iLandmarks.Count(); i++)
       
   346         {
       
   347         
       
   348         CPosLandmark* lm = aDatabase->ReadLandmarkLC(iLandmarks[i]->LandmarkId());
       
   349         CompareLandmarksL(*iLandmarks[i], *lm);    
       
   350         CleanupStack::PopAndDestroy(); // lm 
       
   351         }
       
   352     
       
   353     TPosLmItemId id = 5123321;
       
   354     CPosLandmark* lm=NULL;
       
   355     TRAPD(err, lm=aDatabase->ReadLandmarkLC(id));
       
   356     delete lm;
       
   357     lm = NULL;
       
   358     AssertTrueSecL(err == KErrNotFound, KReadNotFoundErr);
       
   359     
       
   360     id = 13434;
       
   361     lm=NULL;
       
   362     TRAP(err, lm=aDatabase->ReadLandmarkLC(id));
       
   363     delete lm;
       
   364     AssertTrueSecL(err == KErrNotFound, KReadNotFoundErr);
       
   365     
       
   366     id = 0;
       
   367     lm=NULL;
       
   368     TRAP(err, lm=aDatabase->ReadLandmarkLC(id));
       
   369     delete lm;
       
   370     AssertTrueSecL(err == KErrNotFound, KReadNotFoundErr);
       
   371     
       
   372     }
       
   373 
       
   374 
       
   375 // ---------------------------------------------------------
       
   376 // CPosTp8::UpdateLandmarksL
       
   377 //
       
   378 // (other items were commented in a header).
       
   379 // ---------------------------------------------------------
       
   380 //
       
   381 void CPosTp8::UpdateLandmarksL(CPosLandmarkDatabase* aDatabase)    
       
   382     {
       
   383     iLog->Log(_L("Updating landmarks"));
       
   384     _LIT(KCategoryName, "UpdatedCategory %d");
       
   385     _LIT(KCategoryName2, "UpdatedCategory2:%d:%d");
       
   386     _LIT(KCategoryAddedErr, "A category that doesn't exist in the database should not be added to the landmark"); 
       
   387     
       
   388     for (TInt i = 0; i<iLandmarks.Count(); i++)
       
   389         {
       
   390         TCoordinate coord(KLatitude2, KLongitude2, KAltitude2);
       
   391         TLocality loc(coord, KHorizontalAcc2, KVerticalAcc2);
       
   392         TInt j = 0;
       
   393         switch(i)
       
   394             {
       
   395             case 0:
       
   396                 iLandmarks[i]->SetLandmarkNameL(KName2);
       
   397                 break;
       
   398             case 1:        
       
   399                 iLandmarks[i]->SetPositionL(loc);
       
   400                 break;
       
   401             case 2:
       
   402                 iLandmarks[i]->SetIconL(KMbmFileName2, KIconIndex2, KPosLmIconMaskNotUsed);
       
   403                 break;
       
   404             case 3:
       
   405                 iLandmarks[i]->SetLandmarkDescriptionL(KDescription2);
       
   406                 break;
       
   407             case 4:
       
   408                 iLandmarks[i]->SetCoverageRadius(KCoverageRadius); 
       
   409                 break;
       
   410             case 5:
       
   411                 AddFields2L(iLandmarks[i]);
       
   412                 break;
       
   413             case 6:
       
   414                 for(j=0; j<KNoCategories; j++)
       
   415                     {
       
   416                     TBuf<100> name;
       
   417                     name.Format(KCategoryName, j);
       
   418                     iLandmarks[i]->AddCategoryL(CreateCategoryL(name));
       
   419                     }
       
   420                 break;
       
   421             case 8:
       
   422                 AddFields3L(iLandmarks[i]);
       
   423                 break;
       
   424             case 9:
       
   425                 break;
       
   426             default:
       
   427                 iLandmarks[i]->SetLandmarkNameL(KName2);
       
   428                 iLandmarks[i]->SetPositionL(loc);
       
   429                 iLandmarks[i]->SetIconL(KMbmFileName2, KIconIndex2, KPosLmIconMaskNotUsed);
       
   430                 iLandmarks[i]->SetLandmarkDescriptionL(KDescription2);
       
   431                 iLandmarks[i]->SetCoverageRadius(KCoverageRadius); 
       
   432                 AddFields2L(iLandmarks[i]);
       
   433                
       
   434                 for(j=0; j<KNoCategories; j++)
       
   435                     {
       
   436                     TBuf<100> name;
       
   437                     name.Format(KCategoryName2, j, i);
       
   438                     iLandmarks[i]->AddCategoryL(CreateCategoryL(name));
       
   439                     }
       
   440                 break;
       
   441             } 
       
   442         }
       
   443     TInt err = KErrLocked;
       
   444     for (TInt k = 0; k<iLandmarks.Count(); k++)
       
   445         {
       
   446         err = KErrLocked;
       
   447         while (err == KErrLocked)
       
   448             {
       
   449             TRAP(err, aDatabase->UpdateLandmarkL(*iLandmarks[k]));
       
   450             }
       
   451         }
       
   452 
       
   453     ExecuteAndDeleteLD(aDatabase->CompactL());
       
   454              
       
   455     _LIT(KTemp, "temp");
       
   456     TPosLmItemId id2 = 8787876;
       
   457     CPosLandmark* landmark = CreateLandmarkLC(KTemp);
       
   458     err = KErrLocked;
       
   459     while (err == KErrLocked)
       
   460         {
       
   461         TRAP(err, aDatabase->AddLandmarkL(*landmark));
       
   462         }
       
   463     
       
   464     landmark->AddCategoryL(id2);
       
   465     
       
   466     // 0 is equal to KPosLmNullItemId, should leave
       
   467     id2 = 0;
       
   468     TRAP(err, landmark->AddCategoryL(id2));
       
   469     AssertTrueSecL(err == KErrArgument, _L("AddCategory(0) should leave with KErrArgument"));
       
   470     err = KErrLocked;
       
   471     while (err == KErrLocked)
       
   472         {  
       
   473         TRAP(err, aDatabase->UpdateLandmarkL(*landmark)); // CR115 this should not fail any more 
       
   474         }
       
   475     
       
   476     // Make sure category not added to lm (TR ESLI-5X7FTZ)
       
   477     CPosLandmark* readLm = aDatabase->ReadLandmarkLC(landmark->LandmarkId());
       
   478     RArray<TPosLmItemId> catIds;
       
   479     CleanupClosePushL(catIds);
       
   480     readLm->GetCategoriesL(catIds);
       
   481     AssertTrueSecL(catIds.Count() == 3, KCategoryAddedErr); 
       
   482     
       
   483     aDatabase->RemoveLandmarkL(landmark->LandmarkId());
       
   484       
       
   485     CleanupStack::PopAndDestroy(3, landmark);
       
   486     }
       
   487 
       
   488 // ---------------------------------------------------------
       
   489 // CPosTp8::RemoveLandmarksL
       
   490 //
       
   491 // (other items were commented in a header).
       
   492 // ---------------------------------------------------------
       
   493 //
       
   494 void CPosTp8::RemoveLandmarksL(CPosLandmarkDatabase* aDatabase)
       
   495     {
       
   496     iLog->Log(_L("Removing landmarks"));
       
   497     ExecuteAndDeleteLD(aDatabase->CompactL());   
       
   498     const TInt start=9;
       
   499     const TInt end=55;
       
   500     
       
   501     // First check invalid landmark ids, nothing should happen
       
   502     CheckRemovedL(iLandmarks.Count(), iLandmarks.Count());
       
   503     TPosLmItemId id = 5123321;
       
   504     TInt err = KErrLocked;
       
   505     while (err == KErrLocked)
       
   506         {
       
   507         TRAP(err, aDatabase->RemoveLandmarkL(id));
       
   508         }
       
   509         
       
   510     id = 11233;
       
   511     err = KErrLocked;
       
   512     while (err == KErrLocked)
       
   513         {
       
   514         TRAP(err, aDatabase->RemoveLandmarkL(id));
       
   515         }
       
   516     id = 0;
       
   517     err = KErrLocked;
       
   518     while (err == KErrLocked)
       
   519         {
       
   520         TRAP(err, aDatabase->RemoveLandmarkL(id));
       
   521         }
       
   522     
       
   523     CheckRemovedL(iLandmarks.Count(), iLandmarks.Count());
       
   524 
       
   525     for (TInt i = start; i<=end; i++)
       
   526         {
       
   527         err = KErrLocked;
       
   528         while (err == KErrLocked)
       
   529             {
       
   530             TRAP(err, aDatabase->RemoveLandmarkL(iLandmarks[i]->LandmarkId()));
       
   531             }
       
   532         }
       
   533     CheckRemovedL(start, end);
       
   534     for (TInt j = start; j<=end; j++)
       
   535         {
       
   536         err = KErrLocked;
       
   537         while (err == KErrLocked)
       
   538             {
       
   539             TRAP(err, aDatabase->RemoveLandmarkL(iLandmarks[j]->LandmarkId())); // nothing should happen 
       
   540             }
       
   541         } 
       
   542     
       
   543     CheckRemovedL(start, end);
       
   544     
       
   545     iLog->Log(_L("Removing all landmarks"));
       
   546     ExecuteAndDeleteLD(aDatabase->CompactL());
       
   547     ExecuteAndDeleteLD(aDatabase->RemoveAllLandmarksL());
       
   548     
       
   549     CheckRemovedL(0, iLandmarks.Count()-1);
       
   550 
       
   551     ExecuteAndDeleteLD(aDatabase->RemoveAllLandmarksL());
       
   552     
       
   553     CheckRemovedL(0, iLandmarks.Count()-1);
       
   554     
       
   555     }
       
   556 
       
   557 // ---------------------------------------------------------
       
   558 // CPosTp8::RemoveLandmarksAsyncL
       
   559 //
       
   560 // (other items were commented in a header).
       
   561 // ---------------------------------------------------------
       
   562 //
       
   563 void CPosTp8::RemoveLandmarksAsyncL(CPosLandmarkDatabase* aDatabase)
       
   564     {
       
   565     iLog->Log(_L("Removing landmarks asynchronously"));
       
   566     
       
   567     // Remove a set of landmarks async
       
   568     const TInt start=3;
       
   569     const TInt end=47;
       
   570     
       
   571     RArray<TPosLmItemId> ids;
       
   572     CleanupClosePushL(ids);
       
   573     
       
   574     for(TInt i=start; i<=end; i++)
       
   575         {
       
   576         ids.Append(iLandmarks[i]->LandmarkId());
       
   577         }
       
   578     
       
   579     RunAsyncOperationLD(aDatabase->RemoveLandmarksL(ids));
       
   580     CleanupStack::PopAndDestroy(&ids);
       
   581 
       
   582     CheckRemovedL(start, end);    
       
   583     
       
   584     // Remove all async
       
   585     delete iDatabase;
       
   586     iDatabase=NULL;
       
   587     iDatabase=RestoreTp8DbFileL();
       
   588     
       
   589         if (iDatabase->IsInitializingNeeded())
       
   590        {
       
   591        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   592        }
       
   593    
       
   594     iLog->Log(_L("Removing all landmarks asynchronously"));
       
   595 
       
   596     RunAsyncOperationLD(iDatabase->RemoveAllLandmarksL());
       
   597     
       
   598     CheckRemovedL(0, iLandmarks.Count()-1);
       
   599     }
       
   600 
       
   601 // ---------------------------------------------------------
       
   602 // CPosTp8::RemoveLandmarksAsyncWithWaitForReqL
       
   603 //
       
   604 // (other items were commented in a header).
       
   605 // ---------------------------------------------------------
       
   606 //
       
   607 void CPosTp8::RemoveLandmarksAsyncWithWaitForReqL(CPosLandmarkDatabase* aDatabase)
       
   608     {
       
   609     iLog->Log(_L("Removing landmarks asynchronously with User::WaitForRequest"));
       
   610     
       
   611     // Remove a set of landmarks async with WaitForReq
       
   612     const TInt start=3;
       
   613     const TInt end=47;
       
   614     
       
   615     RArray<TPosLmItemId> ids;
       
   616     CleanupClosePushL(ids);
       
   617     
       
   618     for(TInt i=start; i<=end; i++)
       
   619         {
       
   620         ids.Append(iLandmarks[i]->LandmarkId());
       
   621         }
       
   622     
       
   623     CPosLmOperation* op = aDatabase->RemoveLandmarksL(ids);
       
   624     CleanupStack::PushL(op);
       
   625     RunAsyncOperationByWaitForReqL(op);
       
   626     CleanupStack::PopAndDestroy(op);
       
   627 
       
   628     CheckRemovedL(start, end);
       
   629     
       
   630     // Remove all async with WaitForReq
       
   631     delete iDatabase;
       
   632     iDatabase=NULL;
       
   633     iDatabase=RestoreTp8DbFileL();
       
   634    
       
   635        
       
   636         if (iDatabase->IsInitializingNeeded())
       
   637        {
       
   638        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   639        }
       
   640     
       
   641     iLog->Log(_L("Removing all landmarks asynchronously with User::WaitForRequest"));
       
   642     TRAPD(error,op = iDatabase->RemoveAllLandmarksL());
       
   643     iLog->Log(_L("error while RemoveAllLandmarksL = %d"),error);
       
   644     CleanupStack::PushL(op);
       
   645     RunAsyncOperationByWaitForReqL(op);
       
   646     CleanupStack::PopAndDestroy(2, &ids);
       
   647     
       
   648     CheckRemovedL(0, iLandmarks.Count()-1);
       
   649     }
       
   650 
       
   651 // ---------------------------------------------------------
       
   652 // CPosTp8::RemoveLandmarksAsyncAndCancelL
       
   653 //
       
   654 // (other items were commented in a header).
       
   655 // ---------------------------------------------------------
       
   656 //
       
   657 void CPosTp8::RemoveLandmarksAsyncAndCancelL()
       
   658     {
       
   659     iLog->Log(_L("Removing landmarks asynchronously and cancel"));
       
   660     
       
   661     // Remove a set of landmarks async
       
   662     const TInt start=3;
       
   663     const TInt end=47;
       
   664     
       
   665     RArray<TPosLmItemId> ids;
       
   666     CleanupClosePushL(ids);
       
   667     
       
   668     for(TInt i=start; i<=end; i++)
       
   669         {
       
   670         ids.Append(iLandmarks[i]->LandmarkId());
       
   671         }
       
   672     
       
   673     TReal32 progress(0);
       
   674     while (progress < 1.0)
       
   675         {
       
   676         RunAsyncOperationAndCancelInCallbackLD(iDatabase->RemoveLandmarksL(ids), progress);
       
   677        
       
   678         delete iDatabase;
       
   679         iDatabase=NULL;
       
   680         iDatabase=RestoreTp8DbFileL();
       
   681          if (iDatabase->IsInitializingNeeded())
       
   682        {
       
   683        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   684        }
       
   685         progress = progress + 0.09;
       
   686         }
       
   687     CleanupStack::PopAndDestroy(&ids);
       
   688    
       
   689     iLog->Log(_L("Removing all landmarks asynchronously and cancel"));
       
   690 
       
   691     progress = 0;
       
   692     while (progress < 1.0)
       
   693         {
       
   694         RunAsyncOperationAndCancelInCallbackLD(iDatabase->RemoveAllLandmarksL(), progress);
       
   695         
       
   696         delete iDatabase;
       
   697         iDatabase=NULL;
       
   698         iDatabase=RestoreTp8DbFileL();
       
   699          if (iDatabase->IsInitializingNeeded())
       
   700        {
       
   701        ExecuteAndDeleteLD(iDatabase->InitializeL());
       
   702        }
       
   703         
       
   704         progress = progress + 0.09;
       
   705         }
       
   706     }
       
   707 
       
   708 // ---------------------------------------------------------
       
   709 // CPosTp8::RemoveSetOfLandmarksL
       
   710 //
       
   711 // (other items were commented in a header).
       
   712 // ---------------------------------------------------------
       
   713 //
       
   714 void CPosTp8::RemoveSetOfLandmarksL(CPosLandmarkDatabase* aDatabase)
       
   715     {
       
   716     iLog->Log(_L("Removing set of landmarks"));
       
   717    
       
   718     const TInt start=3;
       
   719     const TInt end=57;
       
   720     
       
   721     RArray<TPosLmItemId> ids;
       
   722     CleanupClosePushL(ids);
       
   723     
       
   724     // Test with empty list, should leave with KErrArgument
       
   725     TRAPD(err, iOperation = aDatabase->RemoveLandmarksL(ids));
       
   726     if (err != KErrArgument)
       
   727     {
       
   728     iLog->Log(_L("Removing empty iterator should leave with KErrArgument"));
       
   729    	User::Leave(err);
       
   730     
       
   731     }
       
   732     
       
   733     #if 0
       
   734     // Added for testing -- Start    
       
   735     iOperation->ExecuteL(); 
       
   736     // Added for testing -- End
       
   737     
       
   738     delete iOperation;
       
   739     iOperation = NULL;
       
   740     #endif 
       
   741     
       
   742     // Test with invalid sets of lm id arrays
       
   743     ids.Append(11234);
       
   744     ids.Append(556);
       
   745     ids.Append(908);
       
   746    
       
   747     ExecuteAndDeleteLD(aDatabase->RemoveLandmarksL(ids));
       
   748    
       
   749     // Check that no landmark has been removed 
       
   750     CheckRemovedL(iLandmarks.Count(), iLandmarks.Count());
       
   751     
       
   752     for(TInt i=start; i<=end; i++)
       
   753         {
       
   754         ids.Append(iLandmarks[i]->LandmarkId());
       
   755         // Also add invalid ids
       
   756         ids.Append(i+5000);
       
   757         }
       
   758     
       
   759     ExecuteAndDeleteLD(aDatabase->RemoveLandmarksL(ids));
       
   760 
       
   761     CheckRemovedL(start, end);
       
   762 
       
   763     ExecuteAndDeleteLD(aDatabase->RemoveLandmarksL(ids));
       
   764     
       
   765     CleanupStack::PopAndDestroy(&ids);
       
   766 
       
   767     CheckRemovedL(start, end);
       
   768     }
       
   769 
       
   770 // ---------------------------------------------------------
       
   771 // CPosTp8::CheckRemoved
       
   772 //
       
   773 // (other items were commented in a header).
       
   774 // ---------------------------------------------------------
       
   775 //
       
   776 void CPosTp8::CheckRemovedL(const TInt startIndex, const TInt stopIndex)
       
   777     {
       
   778     _LIT(KRemoveNotFoundErr, "Landmark has not been removed");
       
   779     _LIT(KRemoveFoundErr, "Landmark should not been removed");
       
   780 
       
   781        for (TInt i = 0; i<iLandmarks.Count(); i++)
       
   782         {
       
   783         TRAPD(err, ReadLandmarkL(iLandmarks[i]->LandmarkId()));
       
   784         if (i >= startIndex && i <= stopIndex)
       
   785             {    
       
   786             AssertTrueSecL(err == KErrNotFound, KRemoveNotFoundErr);               
       
   787             }
       
   788         else
       
   789             {
       
   790             AssertTrueSecL(err == KErrNone, KRemoveFoundErr);
       
   791             }
       
   792         }
       
   793     }
       
   794 
       
   795 // ---------------------------------------------------------
       
   796 // CPosTp8::ReadLandmarkL
       
   797 //
       
   798 // (other items were commented in a header).
       
   799 // ---------------------------------------------------------
       
   800 //
       
   801 void CPosTp8::ReadLandmarkL(TPosLmItemId aCategoryId)
       
   802     {
       
   803     CPosLandmark* lm = iDatabase->ReadLandmarkLC(aCategoryId); 
       
   804     CleanupStack::PopAndDestroy(lm);
       
   805     }
       
   806 
       
   807 //---------------------------------------------------------
       
   808 // CPosTp8::CheckLandmarkNameMaxLengthL
       
   809 //
       
   810 // (other items were commented in a header).
       
   811 // ---------------------------------------------------------
       
   812 //
       
   813 void CPosTp8::CheckLandmarkNameMaxLengthL()
       
   814     {
       
   815     _LIT(K255Error, "Landmark name is not limited to 255 characters");
       
   816     
       
   817     iLog->Log(_L("CheckLandmarkNameMaxLengthL"));
       
   818 
       
   819     const TInt KPosLmMaxTextFieldLength = 255;
       
   820     
       
   821     HBufC* hbuf = HBufC::NewLC(KPosLmMaxTextFieldLength+1);
       
   822 
       
   823     CPosLandmark* lm = CPosLandmark::NewLC();
       
   824     // Test empty name, is OK
       
   825     lm->SetLandmarkNameL(*hbuf);
       
   826  
       
   827     while(hbuf->Des().Length() < KPosLmMaxTextFieldLength)
       
   828         {
       
   829         hbuf->Des().Append(_L("X"));
       
   830         }
       
   831 
       
   832     lm->SetLandmarkNameL(*hbuf);
       
   833     
       
   834     hbuf->Des().Append(_L("X"));
       
   835 
       
   836     TRAPD(err, lm->SetLandmarkNameL(*hbuf));
       
   837     AssertTrueSecL(err == KErrArgument, K255Error);
       
   838 
       
   839     CleanupStack::PopAndDestroy(2, hbuf);
       
   840     }
       
   841 
       
   842 // ---------------------------------------------------------
       
   843 // CPosTp8::BackupTp8DbFileL()
       
   844 //
       
   845 // (other items were commented in a header).
       
   846 // ---------------------------------------------------------
       
   847 //
       
   848 CPosLandmarkDatabase* CPosTp8::BackupTp8DbFileL()
       
   849     {
       
   850 
       
   851     CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL();
       
   852     CleanupStack::PushL(manager);
       
   853     manager->SetDefaultDatabaseUriL(KTp8TestDb);
       
   854     HBufC* defaultDbUri = manager->DefaultDatabaseUriLC();
       
   855     TBuf<255> buf;
       
   856     // Extract URI except characters ".ldb"
       
   857     buf.Append(defaultDbUri->Left(defaultDbUri->Length()-4));
       
   858     buf.Append(_L("COPY.LDB"));
       
   859     // Delete in case it already exist
       
   860     TRAPD(err, manager->DeleteDatabaseL(buf));
       
   861     if (err != KErrNone && err != KErrNotFound) iLog->Log(_L("Could not delete file"));
       
   862     manager->CopyDatabaseL(*defaultDbUri, buf);
       
   863 
       
   864     CleanupStack::PopAndDestroy(defaultDbUri);
       
   865     CleanupStack::PopAndDestroy(manager);
       
   866     return CPosLandmarkDatabase::OpenL();
       
   867     }
       
   868 
       
   869 // ---------------------------------------------------------
       
   870 // CPosTp8::RestoreTp8DbFileL()
       
   871 //
       
   872 // (other items were commented in a header).
       
   873 // ---------------------------------------------------------
       
   874 //
       
   875 CPosLandmarkDatabase* CPosTp8::RestoreTp8DbFileL()
       
   876     {
       
   877 
       
   878 
       
   879     CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL();
       
   880     CleanupStack::PushL(manager);
       
   881     manager->SetDefaultDatabaseUriL(KTp8TestDb);
       
   882     HBufC* defaultDbUri = manager->DefaultDatabaseUriLC();
       
   883     TBuf<255> buf;
       
   884     // Extract URI except characters ".ldb"
       
   885     buf.Append(defaultDbUri->Left(defaultDbUri->Length()-4));
       
   886     buf.Append(_L("COPY.LDB"));
       
   887     // Delete in case it already exist
       
   888     TRAPD(err, manager->DeleteDatabaseL(*defaultDbUri));
       
   889     if (err != KErrNone && err != KErrNotFound) iLog->Log(_L("Could not delete file"));
       
   890     manager->CopyDatabaseL(buf, *defaultDbUri);
       
   891 
       
   892     CleanupStack::PopAndDestroy(defaultDbUri);
       
   893     CleanupStack::PopAndDestroy(manager);
       
   894     return CPosLandmarkDatabase::OpenL();
       
   895     }
       
   896     
       
   897 //  End of File