landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp127.cpp
changeset 33 834e27cad510
child 35 1a92308afc46
equal deleted inserted replaced
32:b12ea03c50a3 33:834e27cad510
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Symbian Foundation License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *   ?description_line
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 //  INCLUDES
       
    21 #include "FT_CPosTp127.h"
       
    22 #include <Lbs.h>
       
    23 #include <EPos_CPosLmDatabaseManager.h>
       
    24 #include <EPos_CPosLandmarkParser.h>
       
    25 #include <EPos_CPosLandmarkEncoder.h>
       
    26 #include <EPos_CPosLandmark.h>
       
    27 #include <EPos_CPosLmMultiDbSearch.h>
       
    28 #include <EPos_CPosLmCatNameCriteria.h>
       
    29 #include <EPos_CPosLmTextCriteria.h>
       
    30 #include <EPos_CPosLmCategoryCriteria.h>
       
    31 #include "FT_LandmarkConstants.h"
       
    32 
       
    33 // CONSTANTS
       
    34 const TInt KShortExecutionTimeInSeconds = 15;
       
    35 const TInt KLongExecutionTimeInSeconds = 5 * 60; // Five minutes. The longer the more errors seem appear...
       
    36 const TInt KNrOfDatabases = 5;
       
    37 const TInt KLockedDbIndex = 2;
       
    38 const TInt KMaxNrOfLms = 20;
       
    39 const TInt KLockThreadStartupTime = 500000;
       
    40 _LIT(KCreateThreadErr, "Creating thread failed with %d");
       
    41 _LIT(KLockThreadSearchPattern, "*TP127_LockThread*"); 
       
    42 _LIT(KTestDbUri, "TestDatabase.ldb");
       
    43 _LIT(KTestDbUriUC, "TESTDATABASE.LDB");
       
    44 
       
    45 // ================= LOCAL FUNCTIONS =======================
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // LOCAL_C ThreadFunction
       
    49 //
       
    50 // (other items were commented in a header).
       
    51 // ---------------------------------------------------------
       
    52 //
       
    53 LOCAL_C TInt ThreadFunction(TAny* aData)
       
    54     {
       
    55     CTrapCleanup* cleanup = CTrapCleanup::New(); 
       
    56     CActiveScheduler* actSch = new (ELeave) CActiveScheduler;
       
    57     CActiveScheduler::Install(actSch);
       
    58     
       
    59     TThreadParam* params = reinterpret_cast<TThreadParam*> (aData);
       
    60     TRAPD(err, (*params->iTestFunction)(params->iMessage));
       
    61        
       
    62     delete actSch;
       
    63     delete cleanup;
       
    64     return err;
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------
       
    68 // LOCAL_C AssertTrueL
       
    69 //
       
    70 // (other items were commented in a header).
       
    71 // ---------------------------------------------------------
       
    72 //
       
    73 LOCAL_C void AssertTrueL(
       
    74     TBool aCondition, 
       
    75     const TDesC& aBuf, 
       
    76     TDes* aMessage, 
       
    77     TInt aError = KErrGeneral)
       
    78     {
       
    79     if (!aCondition)
       
    80         {
       
    81         _LIT(KFormat, "%S, error = %d");
       
    82         aMessage->Format(KFormat, &aBuf, aError);
       
    83         
       
    84         aError == KErrNone ? User::Leave(KErrGeneral) : User::Leave(aError);
       
    85         }
       
    86     }
       
    87     
       
    88 // ---------------------------------------------------------
       
    89 // LOCAL_C ThreadExistsL
       
    90 //
       
    91 // (other items were commented in a header).
       
    92 // ---------------------------------------------------------
       
    93 //
       
    94 LOCAL_C TBool ThreadExistsL(const TDesC& aSearchPattern)
       
    95     {
       
    96     TFindThread threadSearcher;
       
    97     threadSearcher.Find(aSearchPattern);
       
    98     TFullName fullName;
       
    99     return (threadSearcher.Next(fullName) == KErrNone);
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------
       
   103 // LOCAL_C VerifyResultL
       
   104 //
       
   105 // (other items were commented in a header).
       
   106 // ---------------------------------------------------------
       
   107 //
       
   108 LOCAL_C void VerifyResultL(
       
   109     TBool aLockThreadExists, 
       
   110     CPosLmMultiDbSearch* aMultiDbSearcher, 
       
   111     TDes* aDes)
       
   112     {
       
   113     TInt nrOfErrors = aMultiDbSearcher->NumOfSearchErrors();
       
   114     if (aLockThreadExists)
       
   115         {
       
   116         // Reading locked db should result in KErrLocked
       
   117         AssertTrueL(nrOfErrors == 1, _L("Not one error as expected"), aDes);
       
   118         CPosLmMultiDbSearch::TSearchError error;
       
   119         aMultiDbSearcher->GetSearchError(0, error);
       
   120         AssertTrueL(error.iDatabaseIndex == KLockedDbIndex, _L("Error in wrong db"), aDes);
       
   121         AssertTrueL(error.iErrorCode == KErrLocked, _L("Wrong error"), aDes, error.iErrorCode);
       
   122         }
       
   123     else
       
   124         {
       
   125         AssertTrueL(nrOfErrors == 0, _L("Search failed with errors"), aDes);
       
   126         }
       
   127         
       
   128     aDes->Zero();    
       
   129     }
       
   130 
       
   131 // ================= CThreadMonitor MEMBER FUNCTIONS =======================
       
   132 
       
   133 // Constructor
       
   134 CThreadMonitor::CThreadMonitor(RThread* aThread) 
       
   135 : CActive(CActive::EPriorityStandard), iThread(aThread)
       
   136     {
       
   137     CActiveScheduler::Add(this);
       
   138     }
       
   139 
       
   140 // Destructor
       
   141 CThreadMonitor::~CThreadMonitor()
       
   142     {
       
   143     Cancel();
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------
       
   147 // CThreadMonitor::NewL
       
   148 //
       
   149 // (other items were commented in a header).
       
   150 // ---------------------------------------------------------
       
   151 //
       
   152 CThreadMonitor* CThreadMonitor::NewL(RThread* aThread)
       
   153     {
       
   154     CThreadMonitor* self = new (ELeave) CThreadMonitor(aThread);
       
   155     CleanupStack::PushL(self);
       
   156     self->ConstructL();
       
   157     CleanupStack::Pop(self);
       
   158     return self;
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------
       
   162 // CThreadMonitor::ConstructL
       
   163 //
       
   164 // (other items were commented in a header).
       
   165 // ---------------------------------------------------------
       
   166 //
       
   167 void CThreadMonitor::ConstructL()
       
   168     {
       
   169     iThread->Resume();
       
   170     iThread->Logon(iStatus);
       
   171     SetActive();
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------
       
   175 // CThreadMonitor::DoCancel
       
   176 //
       
   177 // (other items were commented in a header).
       
   178 // ---------------------------------------------------------
       
   179 //
       
   180 void CThreadMonitor::DoCancel()
       
   181     {
       
   182     iThread->LogonCancel(iStatus);
       
   183 
       
   184     // Kill thread
       
   185     TRequestStatus status;
       
   186     iThread->Logon(status);
       
   187     iThread->Kill(KErrCancel);
       
   188     User::WaitForRequest(status);
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------
       
   192 // CThreadMonitor::RunL
       
   193 //
       
   194 // (other items were commented in a header).
       
   195 // ---------------------------------------------------------
       
   196 //
       
   197 void CThreadMonitor::RunL()
       
   198     {
       
   199     CActiveScheduler::Stop();
       
   200     }
       
   201 
       
   202 // ================= CPosTp127 MEMBER FUNCTIONS =======================
       
   203 
       
   204 // ---------------------------------------------------------
       
   205 // CPosTp127::GetName
       
   206 //
       
   207 // (other items were commented in a header).
       
   208 // ---------------------------------------------------------
       
   209 //
       
   210 void CPosTp127::GetName(TDes& aName) const
       
   211     {
       
   212     _LIT(KTestName, "TP127 - Multiple databases, multiple clients");
       
   213     aName = KTestName;
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------
       
   217 // CPosTp127::InitTestL
       
   218 //
       
   219 // (other items were commented in a header).
       
   220 // ---------------------------------------------------------
       
   221 //
       
   222 void CPosTp127::InitTestL()
       
   223     {
       
   224     MakeSurePanicDebugFileExistsL();
       
   225     
       
   226     // PrepareDatabases
       
   227     RemoveAllLmDatabasesL();
       
   228     CopyTestDbFileL(KDb20);
       
   229     CopyTestDbFileL(KDb40);
       
   230     CopyTestDbFileL(KDb60);
       
   231     CopyTestDbFileL(KDb80);
       
   232     CopyTestDbFileL(KDb105);
       
   233 
       
   234     // Initialize databases - is this really needed?
       
   235     CPosLmDatabaseManager* dbMan = CPosLmDatabaseManager::NewL();
       
   236     CleanupStack::PushL(dbMan);
       
   237     CDesCArray* dbList = dbMan->ListDatabasesLC();
       
   238     for (TInt i = 0; i < KNrOfDatabases; i++)
       
   239         {
       
   240         CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(dbList->operator[](i));
       
   241         CleanupStack::PushL(db);
       
   242         ExecuteAndDeleteLD(db->InitializeL());
       
   243         CleanupStack::PopAndDestroy(db);
       
   244         }
       
   245 
       
   246     // Remove the last 5 lms of the the last db
       
   247     CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(KDb105);
       
   248     CleanupStack::PushL(db);
       
   249     CPosLmItemIterator* iter = db->LandmarkIteratorL();
       
   250     CleanupStack::PushL(iter);
       
   251     RIdArray idArray;
       
   252     CleanupClosePushL(idArray);
       
   253     iter->GetItemIdsL(idArray, 20, iter->NumOfItemsL() - 20);
       
   254     ExecuteAndDeleteLD(db->RemoveLandmarksL(idArray));
       
   255     CleanupStack::PopAndDestroy(3, db);
       
   256     
       
   257     CleanupStack::PopAndDestroy(2, dbMan);
       
   258     }
       
   259     
       
   260 // ---------------------------------------------------------
       
   261 // CPosTp127::CloseTest
       
   262 //
       
   263 // (other items were commented in a header).
       
   264 // ---------------------------------------------------------
       
   265 //
       
   266 void CPosTp127::CloseTest()
       
   267     {
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------
       
   271 // CPosTp127::StartL
       
   272 //
       
   273 // (other items were commented in a header).
       
   274 // ---------------------------------------------------------
       
   275 //
       
   276 void CPosTp127::StartL()
       
   277     {
       
   278     // 1. Create multiple db search threads 
       
   279     iLog->Put(_L("<<<< 1. Create multiple db search threads >>>>"));
       
   280     TBool lockDb = ETrue;
       
   281     TBool successful = MultipleDbSearchClientsL(!lockDb);
       
   282     //TBool successful = MultipleDbSearchClientsL(lockDb);
       
   283     
       
   284     // Sometimes error ESLI-69LDJD DBMS - Error occurs
       
   285     // 2. One of the databases is locked
       
   286     iLog->Put(_L("<<<< 2. One of the databases is locked >>>>"));
       
   287     User::After(KLockThreadStartupTime); // Let previous thread instances really die
       
   288     if (!MultipleDbSearchClientsL(lockDb))
       
   289         {        
       
   290         successful = EFalse;
       
   291         }
       
   292         
       
   293     // 3. Copy database in use
       
   294     iLog->Put(_L("<<<< 3. Copy database in use >>>>"));
       
   295     if (!VerifyInUseWhenCopyL())
       
   296         {        
       
   297         successful = EFalse;
       
   298         }
       
   299    
       
   300     // 4. Copy databases continuously in parallel
       
   301     iLog->Put(_L("<<<< 4. Copy databases continuously in parallel >>>>"));
       
   302     if (!VerifyCopyStressL())
       
   303         {        
       
   304         successful = EFalse;
       
   305         }
       
   306    
       
   307     // 5. Use all LM APIs
       
   308     iLog->Put(_L("<<<< 5. Use all LM APIs simultaneously >>>>"));
       
   309     if (!MultipleLmClientsL())
       
   310         {        
       
   311         successful = EFalse;
       
   312         }
       
   313     // Leave if error    
       
   314     if (!successful)
       
   315         {        
       
   316         User::Leave(KErrGeneral);
       
   317         }
       
   318     }
       
   319 
       
   320 // ---------------------------------------------------------
       
   321 // CPosTp127::MultipleDbSearchClientsL
       
   322 //
       
   323 // (other items were commented in a header).
       
   324 // ---------------------------------------------------------
       
   325 //
       
   326 TBool CPosTp127::MultipleDbSearchClientsL(TBool aLockDb)
       
   327     {
       
   328     RThread searchThread1, searchThread2, searchThread3, lockThread;
       
   329     TThreadParam params1, params2, params3, params4;
       
   330     TBuf<200> threadMsg1, threadMsg2, threadMsg3, threadMsg4;
       
   331     RArray<TThreadParam> threadArray;
       
   332     CleanupClosePushL(threadArray);
       
   333 
       
   334     // Create search thread 1
       
   335     _LIT(KSearchThread1, "TP127 - Search thread 1");
       
   336     TInt err = searchThread1.Create(KSearchThread1, ThreadFunction, 
       
   337         KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &params1);
       
   338     AssertTrueSecL(err == KErrNone, KCreateThreadErr, err);
       
   339     CleanupClosePushL(searchThread1);
       
   340     params1.iMessage = &threadMsg1;
       
   341     params1.iTestFunction = MultipleDbCategorySearchL;
       
   342     params1.iThread = &searchThread1;
       
   343     threadArray.AppendL(params1);
       
   344 
       
   345     // Create search thread 2
       
   346     _LIT(KSearchThread2, "TP127 - Search thread 2");
       
   347     err = searchThread2.Create(KSearchThread2, ThreadFunction, 
       
   348         KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &params2);
       
   349     AssertTrueSecL(err == KErrNone, KCreateThreadErr, err);
       
   350     CleanupClosePushL(searchThread2);
       
   351     params2.iMessage = &threadMsg2;
       
   352     params2.iTestFunction = MultipleDbLandmarkSearchL;
       
   353     params2.iThread = &searchThread2;
       
   354     threadArray.AppendL(params2);
       
   355 
       
   356     // Create search thread 3
       
   357     _LIT(KSearchThread3, "TP127 - Search thread 3");
       
   358     err = searchThread3.Create(KSearchThread3, ThreadFunction, 
       
   359         KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &params3);
       
   360     AssertTrueSecL(err == KErrNone, KCreateThreadErr, err);
       
   361     CleanupClosePushL(searchThread3);
       
   362     params3.iMessage = &threadMsg3;
       
   363     params3.iTestFunction = MultipleDbLandmarkWithoutCategorySearchL;
       
   364     params3.iThread = &searchThread3;
       
   365     threadArray.AppendL(params3);
       
   366     
       
   367     if (aLockDb)
       
   368         {
       
   369         // Create db lock thread
       
   370         _LIT(KLockThread, "TP127 - TP127_LockThread");        
       
   371         err = lockThread.Create(KLockThread, ThreadFunction, 
       
   372             KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &params4);
       
   373         AssertTrueSecL(err == KErrNone, KCreateThreadErr, err);
       
   374         CleanupClosePushL(lockThread);
       
   375         params4.iMessage = &threadMsg4;
       
   376         params4.iTestFunction = LockDatabaseL;
       
   377         params4.iThread = &lockThread;
       
   378         threadArray.AppendL(params4);
       
   379         }
       
   380 
       
   381     TBool successful = ResumeThreadsAndVerifyExitL(threadArray); 
       
   382     
       
   383     if (aLockDb)
       
   384         {
       
   385         CleanupStack::PopAndDestroy(&lockThread);
       
   386         }
       
   387     CleanupStack::PopAndDestroy(4, &threadArray);
       
   388     return successful;
       
   389     }
       
   390     
       
   391 // ---------------------------------------------------------
       
   392 // CPosTp127::MultipleLmClientsL
       
   393 //
       
   394 // (other items were commented in a header).
       
   395 // ---------------------------------------------------------
       
   396 //
       
   397 TBool CPosTp127::MultipleLmClientsL()
       
   398     {
       
   399     // Set default db
       
   400     CPosLmDatabaseManager* dbMan = CPosLmDatabaseManager::NewL();
       
   401     CleanupStack::PushL(dbMan);
       
   402     HPosLmDatabaseInfo* dbInfo = HPosLmDatabaseInfo::NewLC(KTestDbUri);
       
   403     dbMan->CreateDatabaseL(*dbInfo);
       
   404     CleanupStack::PopAndDestroy(dbInfo);
       
   405     dbMan->SetDefaultDatabaseUriL(KTestDbUri);
       
   406     CleanupStack::PopAndDestroy(dbMan);
       
   407     
       
   408     RThread dbManThread, multiSearchThread, dbThread, singleSearchThread;
       
   409     TThreadParam params1, params2, params3, params4;
       
   410     TBuf<200> threadMsg1, threadMsg2, threadMsg3, threadMsg4;
       
   411     RArray<TThreadParam> threadArray;
       
   412     CleanupClosePushL(threadArray);
       
   413 
       
   414     // Create db management thread
       
   415     _LIT(KDbManThread, "TP127 - Db manager thread");
       
   416     TInt err = dbManThread.Create(KDbManThread, ThreadFunction, 
       
   417         KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &params1);
       
   418     AssertTrueSecL(err == KErrNone, KCreateThreadErr, err);
       
   419     CleanupClosePushL(dbManThread);
       
   420     params1.iMessage = &threadMsg1;
       
   421     params1.iTestFunction = DbManagementL;
       
   422     params1.iThread = &dbManThread;
       
   423     threadArray.AppendL(params1);
       
   424 
       
   425     // Create multi db search thread
       
   426     _LIT(KMultiSearchThread, "TP127 - Multi search thread");
       
   427     err = multiSearchThread.Create(KMultiSearchThread, ThreadFunction, 
       
   428         KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &params2);
       
   429     AssertTrueSecL(err == KErrNone, KCreateThreadErr, err);
       
   430     CleanupClosePushL(multiSearchThread);
       
   431     params2.iMessage = &threadMsg2;
       
   432     params2.iTestFunction = MultipleDbSearchL;
       
   433     params2.iThread = &multiSearchThread;
       
   434     threadArray.AppendL(params2);
       
   435 
       
   436     // Create LM API thread
       
   437     _LIT(KDbThread, "TP127 - db thread");
       
   438     err = dbThread.Create(KDbThread, ThreadFunction, 
       
   439         KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &params3);
       
   440     AssertTrueSecL(err == KErrNone, KCreateThreadErr, err);
       
   441     CleanupClosePushL(dbThread);
       
   442     params3.iMessage = &threadMsg3;
       
   443     params3.iTestFunction = DbAccessL;
       
   444     params3.iThread = &dbThread;
       
   445     threadArray.AppendL(params3);
       
   446     
       
   447     // Create single db search thread
       
   448     _LIT(KSingleSearchThread, "TP127 - Single search thread");        
       
   449     err = singleSearchThread.Create(KSingleSearchThread, ThreadFunction, 
       
   450         KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &params4);
       
   451     AssertTrueSecL(err == KErrNone, KCreateThreadErr, err);
       
   452     CleanupClosePushL(singleSearchThread);
       
   453     params4.iMessage = &threadMsg4;
       
   454     params4.iTestFunction = SingleDbSearchL;
       
   455     params4.iThread = &singleSearchThread;
       
   456     threadArray.AppendL(params4);
       
   457 
       
   458     TBool successful = ResumeThreadsAndVerifyExitL(threadArray); 
       
   459     
       
   460     CleanupStack::PopAndDestroy(5, &threadArray);
       
   461     return successful;
       
   462     }
       
   463     
       
   464 // ---------------------------------------------------------
       
   465 // CPosTp127::VerifyInUseWhenCopyL
       
   466 //
       
   467 // (other items were commented in a header).
       
   468 // ---------------------------------------------------------
       
   469 //
       
   470 TBool CPosTp127::VerifyInUseWhenCopyL()
       
   471     {
       
   472     RThread copyThread, lockThread;
       
   473     TThreadParam params1, params2;
       
   474     TBuf<200> threadMsg1, threadMsg2;
       
   475     RArray<TThreadParam> threadArray;
       
   476     CleanupClosePushL(threadArray);
       
   477 
       
   478     // Create copy thread
       
   479     _LIT(KCopyThread, "TP127 - Copy thread");
       
   480     TInt err = copyThread.Create(KCopyThread, ThreadFunction, 
       
   481         KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &params1);
       
   482     AssertTrueSecL(err == KErrNone, KCreateThreadErr, err);
       
   483     CleanupClosePushL(copyThread);
       
   484     params1.iMessage = &threadMsg1;
       
   485     params1.iTestFunction = CopyLockedDatabaseL;
       
   486     params1.iThread = &copyThread;
       
   487     threadArray.AppendL(params1);
       
   488 
       
   489     // Create db lock thread
       
   490     _LIT(KLockThread, "TP127 - TP127_LockThread");
       
   491     err = KErrAlreadyExists;
       
   492     while (err == KErrAlreadyExists)
       
   493         {
       
   494         err = lockThread.Create(KLockThread, ThreadFunction, 
       
   495             KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &params2);
       
   496         }
       
   497     AssertTrueSecL(err == KErrNone, KCreateThreadErr, err);
       
   498     CleanupClosePushL(lockThread);
       
   499     params2.iMessage = &threadMsg2;
       
   500     params2.iTestFunction = LockDatabaseL;
       
   501     params2.iThread = &lockThread;
       
   502     threadArray.AppendL(params2);
       
   503 
       
   504     TBool successful = ResumeThreadsAndVerifyExitL(threadArray); 
       
   505     
       
   506     CleanupStack::PopAndDestroy(3, &threadArray);
       
   507     return successful;
       
   508     }
       
   509     
       
   510 // ---------------------------------------------------------
       
   511 // CPosTp127::VerifyCopyStressL
       
   512 //
       
   513 // (other items were commented in a header).
       
   514 // ---------------------------------------------------------
       
   515 //
       
   516 TBool CPosTp127::VerifyCopyStressL()
       
   517     {
       
   518     RThread copyThread1, copyThread2, copyThread3, copyThread4, copyThread5;
       
   519     TThreadParam params1, params2, params3, params4, params5;
       
   520     TBuf<200> threadMsg1, threadMsg2, threadMsg3, threadMsg4, threadMsg5;
       
   521     RArray<TThreadParam> threadArray;
       
   522     CleanupClosePushL(threadArray);
       
   523 
       
   524     // Create copy thread1
       
   525     _LIT(KCopyThread1, "TP127 - Copy thread1");
       
   526     TInt err = copyThread1.Create(KCopyThread1, ThreadFunction, 
       
   527         KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &params1);
       
   528     AssertTrueSecL(err == KErrNone, KCreateThreadErr, err);
       
   529     CleanupClosePushL(copyThread1);
       
   530     params1.iMessage = &threadMsg1;
       
   531     params1.iTestFunction = CopyDatabaseL;
       
   532     params1.iThread = &copyThread1;
       
   533     threadArray.AppendL(params1);
       
   534 
       
   535     // Create copy thread2
       
   536     _LIT(KCopyThread2, "TP127 - Copy thread2");
       
   537     err = copyThread2.Create(KCopyThread2, ThreadFunction, 
       
   538         KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &params2);
       
   539     AssertTrueSecL(err == KErrNone, KCreateThreadErr, err);
       
   540     CleanupClosePushL(copyThread2);
       
   541     params2.iMessage = &threadMsg2;
       
   542     params2.iTestFunction = CopyDatabaseL;
       
   543     params2.iThread = &copyThread2;
       
   544     threadArray.AppendL(params2);
       
   545 
       
   546     // Create copy thread3
       
   547     _LIT(KCopyThread3, "TP127 - Copy thread3");
       
   548     err = copyThread3.Create(KCopyThread3, ThreadFunction, 
       
   549         KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &params3);
       
   550     AssertTrueSecL(err == KErrNone, KCreateThreadErr, err);
       
   551     CleanupClosePushL(copyThread3);
       
   552     params3.iMessage = &threadMsg3;
       
   553     params3.iTestFunction = CopyDatabaseL;
       
   554     params3.iThread = &copyThread3;
       
   555     threadArray.AppendL(params3);
       
   556 
       
   557     // Create copy thread4
       
   558     _LIT(KCopyThread4, "TP127 - Copy thread4");
       
   559     err = copyThread4.Create(KCopyThread4, ThreadFunction, 
       
   560         KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &params4);
       
   561     AssertTrueSecL(err == KErrNone, KCreateThreadErr, err);
       
   562     CleanupClosePushL(copyThread4);
       
   563     params4.iMessage = &threadMsg4;
       
   564     params4.iTestFunction = CopyDatabaseL;
       
   565     params4.iThread = &copyThread4;
       
   566     threadArray.AppendL(params4);
       
   567 
       
   568     // Create copy thread5
       
   569     _LIT(KCopyThread5, "TP127 - Copy thread5");
       
   570     err = copyThread5.Create(KCopyThread5, ThreadFunction, 
       
   571         KDefaultStackSize, KMinHeapSize, KMaxHeapSize, &params5);
       
   572     AssertTrueSecL(err == KErrNone, KCreateThreadErr, err);
       
   573     CleanupClosePushL(copyThread5);
       
   574     params5.iMessage = &threadMsg5;
       
   575     params5.iTestFunction = CopyDatabaseL;
       
   576     params5.iThread = &copyThread5;
       
   577     threadArray.AppendL(params5);
       
   578 
       
   579     TBool successful = ResumeThreadsAndVerifyExitL(threadArray); 
       
   580     
       
   581     CleanupStack::PopAndDestroy(6, &threadArray);
       
   582     return successful;
       
   583     }
       
   584     
       
   585 // ---------------------------------------------------------
       
   586 // CPosTp127::ResumeThreadsAndVerifyExitL
       
   587 //
       
   588 // (other items were commented in a header).
       
   589 // ---------------------------------------------------------
       
   590 //
       
   591 TBool CPosTp127::ResumeThreadsAndVerifyExitL(const RArray<TThreadParam>& aThreadParams)
       
   592     {
       
   593     // Start threads.
       
   594     RPointerArray<CThreadMonitor> threadMonitors;    
       
   595     CleanupClosePushL(threadMonitors);
       
   596     TInt nrOfThreads = aThreadParams.Count();
       
   597     for (TInt j = 0; j < nrOfThreads; j++)
       
   598         {
       
   599         threadMonitors.AppendL(CThreadMonitor::NewL(aThreadParams[j].iThread));
       
   600         }
       
   601 
       
   602 // <<<< Commented code below can be enabled for immediate interruption when any thread fails >>>>
       
   603 
       
   604     // Wait until any of the threads exits.
       
   605     TInt error = KErrNone;
       
   606     TBool allThreadsTerminated = EFalse;
       
   607     while (!allThreadsTerminated
       
   608 /* && error == KErrNone*/)
       
   609         {
       
   610         CActiveScheduler::Start();
       
   611 
       
   612         // Assume all threads are terminated
       
   613         allThreadsTerminated = ETrue;
       
   614         for (TInt i = 0; i < nrOfThreads
       
   615 /* && error == KErrNone*/; i++)
       
   616             {
       
   617             if (threadMonitors[i]->IsActive())
       
   618                 {
       
   619                 // Thread is still alive
       
   620                 allThreadsTerminated = EFalse;
       
   621                 }
       
   622             else
       
   623                 {
       
   624 /*                if (aThreadParams[i].iThread->ExitType() != EExitKill)
       
   625                     {
       
   626                     error = KErrGeneral;
       
   627                     }
       
   628                 else if (aThreadParams[i].iThread->ExitReason())
       
   629                     {
       
   630                     error = aThreadParams[i].iThread->ExitReason();
       
   631                     }
       
   632 */                }
       
   633             }
       
   634         }
       
   635 
       
   636 // <<<< Commented code above can be enabled for immediate interruption when any thread fails >>>>
       
   637 
       
   638     // Terminate all remaining threads (in case of errors)
       
   639     threadMonitors.ResetAndDestroy();
       
   640     CleanupStack::PopAndDestroy(&threadMonitors);
       
   641 
       
   642     // Log summary
       
   643     for (TInt i = 0; i < nrOfThreads; i++)
       
   644         {
       
   645         if (*aThreadParams[i].iMessage != KNullDesC)
       
   646             {
       
   647             iLog->Put(*aThreadParams[i].iMessage);
       
   648             }
       
   649         TName threadName = aThreadParams[i].iThread->Name();
       
   650         if (aThreadParams[i].iThread->ExitType() != EExitKill)
       
   651             {
       
   652             iBuf.Format(_L("%S was not killed!"), &threadName);
       
   653             iLog->PutError(iBuf);
       
   654             TExitCategoryName category = aThreadParams[i].iThread->ExitCategory();
       
   655             iBuf.Format(_L("Exit Category = %S %d"), &category, aThreadParams[i].iThread->ExitReason());
       
   656             iLog->Put(iBuf);
       
   657             error = KErrGeneral;
       
   658             }
       
   659         else
       
   660             {
       
   661             TInt exitReason = aThreadParams[i].iThread->ExitReason();
       
   662             if (exitReason != 0)
       
   663                 {
       
   664                 iBuf.Format(_L("%S's exit reason wasn't 0 but %d."), &threadName, exitReason);
       
   665                 iLog->PutError(iBuf);
       
   666                 error = exitReason;
       
   667                 }
       
   668             }
       
   669         }
       
   670     
       
   671     return (error == KErrNone);
       
   672     }
       
   673 
       
   674 // ================= STATIC THREAD FUNCTIONS =======================
       
   675 
       
   676 // ---------------------------------------------------------
       
   677 // CPosTp127::MultipleDbCategorySearchL
       
   678 //
       
   679 // (other items were commented in a header).
       
   680 // ---------------------------------------------------------
       
   681 //
       
   682 void CPosTp127::MultipleDbCategorySearchL(TDes* aMessage)
       
   683     {
       
   684     TBool lockThreadExists = ThreadExistsL(KLockThreadSearchPattern);
       
   685     if (lockThreadExists)
       
   686         {
       
   687         // Let lock thread launch first
       
   688         User::After(KLockThreadStartupTime);
       
   689         }
       
   690         
       
   691     // Search multiple databases for some seconds
       
   692     TTime startTime, stopTime;
       
   693     startTime.HomeTime();
       
   694     stopTime.HomeTime();
       
   695     TTimeIntervalSeconds executionTime;
       
   696     User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
   697 
       
   698     while (executionTime.Int() < KShortExecutionTimeInSeconds)
       
   699         {
       
   700         CPosLmDatabaseManager* dbMan = CPosLmDatabaseManager::NewL();
       
   701         CleanupStack::PushL(dbMan);
       
   702         CDesCArray* dbList = dbMan->ListDatabasesLC();
       
   703         AssertTrueL(dbList->Count() == KNrOfDatabases, _L("MultipleDbCategorySearchL: Wrong number of databases"), aMessage);
       
   704         CPosLmMultiDbSearch* dbSearcher = CPosLmMultiDbSearch::NewL(*dbList);
       
   705         CleanupStack::PushL(dbSearcher);
       
   706         
       
   707         // Search for categories containing a specific string
       
   708         CPosLmCatNameCriteria* criteria = CPosLmCatNameCriteria::NewLC();
       
   709         criteria->SetSearchPatternL(_L("*Log*"));
       
   710         CPosLmOperation* operation = dbSearcher->StartCategorySearchL(*criteria, CPosLmCategoryManager::ECategorySortOrderNone);
       
   711         ExecuteAndDeleteLD(operation);
       
   712         
       
   713         aMessage->Copy(_L("MultipleDbCategorySearchL: "));
       
   714         VerifyResultL(lockThreadExists, dbSearcher, aMessage);
       
   715         
       
   716         stopTime.HomeTime();
       
   717         User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
   718         
       
   719         CleanupStack::PopAndDestroy(4, dbMan);
       
   720         }
       
   721     }
       
   722 
       
   723 // ---------------------------------------------------------
       
   724 // CPosTp127::MultipleDbLandmarkSearchL
       
   725 //
       
   726 // (other items were commented in a header).
       
   727 // ---------------------------------------------------------
       
   728 //
       
   729 void CPosTp127::MultipleDbLandmarkSearchL(TDes* aMessage)
       
   730     {
       
   731     TBool lockThreadExists = ThreadExistsL(KLockThreadSearchPattern);
       
   732     if (lockThreadExists)
       
   733         {
       
   734         // Let lock thread launch first
       
   735         User::After(KLockThreadStartupTime);
       
   736         }
       
   737 
       
   738     // Execute thread for a number of seconds
       
   739     TTime startTime, stopTime;
       
   740     startTime.HomeTime();
       
   741     stopTime.HomeTime();
       
   742     TTimeIntervalSeconds executionTime;
       
   743     User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
   744 
       
   745     while (executionTime.Int() < KShortExecutionTimeInSeconds)
       
   746         {
       
   747         CPosLmDatabaseManager* dbMan = CPosLmDatabaseManager::NewL();
       
   748         CleanupStack::PushL(dbMan);
       
   749         CDesCArray* dbList = dbMan->ListDatabasesLC();
       
   750         CPosLmMultiDbSearch* dbSearcher = CPosLmMultiDbSearch::NewL(*dbList);
       
   751         CleanupStack::PushL(dbSearcher);
       
   752         
       
   753         // Search for landmarks containing a specific string
       
   754         CPosLmTextCriteria* criteria = CPosLmTextCriteria::NewLC();
       
   755         criteria->SetTextL(_L("*as*"));
       
   756         CPosLmOperation* operation = dbSearcher->StartLandmarkSearchL(*criteria);
       
   757         ExecuteAndDeleteLD(operation);
       
   758         
       
   759         aMessage->Copy(_L("MultipleDbLandmarkSearchL: "));
       
   760         VerifyResultL(lockThreadExists, dbSearcher, aMessage);
       
   761 
       
   762         stopTime.HomeTime();
       
   763         User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
   764         
       
   765         CleanupStack::PopAndDestroy(4, dbMan);
       
   766         }
       
   767     }
       
   768 
       
   769 // ---------------------------------------------------------
       
   770 // CPosTp127::MultipleDbLandmarkWithoutCategorySearchL
       
   771 //
       
   772 // (other items were commented in a header).
       
   773 // ---------------------------------------------------------
       
   774 //
       
   775 void CPosTp127::MultipleDbLandmarkWithoutCategorySearchL(TDes* aMessage)
       
   776     {
       
   777     TBool lockThreadExists = ThreadExistsL(KLockThreadSearchPattern);
       
   778     if (lockThreadExists)
       
   779         {
       
   780         // Let lock thread launch first
       
   781         User::After(KLockThreadStartupTime);
       
   782         }
       
   783 
       
   784     // Execute thread for a number of seconds
       
   785     TTime startTime, stopTime;
       
   786     startTime.HomeTime();
       
   787     stopTime.HomeTime();
       
   788     TTimeIntervalSeconds executionTime;
       
   789     User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
   790 
       
   791     while (executionTime.Int() < KShortExecutionTimeInSeconds)
       
   792         {
       
   793         CPosLmDatabaseManager* dbMan = CPosLmDatabaseManager::NewL();
       
   794         CleanupStack::PushL(dbMan);
       
   795         CDesCArray* dbList = dbMan->ListDatabasesLC();
       
   796         AssertTrueL(dbList->Count() == KNrOfDatabases, _L("MultipleDbLandmarkWithoutCategorySearchL: Wrong number of databases"), aMessage);
       
   797         CPosLmMultiDbSearch* dbSearcher = CPosLmMultiDbSearch::NewL(*dbList);
       
   798         CleanupStack::PushL(dbSearcher);
       
   799         
       
   800         // Search for uncategorized landmarks
       
   801         CPosLmCategoryCriteria* criteria = CPosLmCategoryCriteria::NewLC();
       
   802         CPosLmOperation* operation = dbSearcher->StartLandmarkSearchL(*criteria);
       
   803         ExecuteAndDeleteLD(operation);
       
   804         
       
   805         aMessage->Copy(_L("MultipleDbLandmarkWithoutCategorySearchL: "));
       
   806         VerifyResultL(lockThreadExists, dbSearcher, aMessage);
       
   807 
       
   808         stopTime.HomeTime();
       
   809         User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
   810         
       
   811         CleanupStack::PopAndDestroy(4, dbMan);
       
   812         }
       
   813     }
       
   814 
       
   815 // ---------------------------------------------------------
       
   816 // CPosTp127::LockDatabaseL
       
   817 //
       
   818 // (other items were commented in a header).
       
   819 // ---------------------------------------------------------
       
   820 //
       
   821 void CPosTp127::LockDatabaseL(TDes* aMessage)
       
   822     {
       
   823     CPosLmDatabaseManager* dbMan = CPosLmDatabaseManager::NewL();
       
   824     CleanupStack::PushL(dbMan);
       
   825     CDesCArray* dbList = dbMan->ListDatabasesLC();
       
   826     AssertTrueL(dbList->Count() == KNrOfDatabases, _L("MultipleDbLandmarkWithoutCategorySearchL: Wrong number of databases"), aMessage);
       
   827     CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL((*dbList)[KLockedDbIndex]);
       
   828     CleanupStack::PushL(db);
       
   829     CPosLmOperation* operation = db->RemoveAllLandmarksL();
       
   830     User::After((KShortExecutionTimeInSeconds + 1) * 1000000);
       
   831     delete operation;
       
   832     
       
   833     CleanupStack::PopAndDestroy(3, dbMan);
       
   834     }
       
   835 
       
   836 // ---------------------------------------------------------
       
   837 // CPosTp127::DbManagementL
       
   838 //
       
   839 // (other items were commented in a header).
       
   840 // ---------------------------------------------------------
       
   841 //
       
   842 void CPosTp127::DbManagementL(TDes* aMessage)
       
   843     {
       
   844     // Execute thread for a number of seconds
       
   845     TTime startTime, stopTime;
       
   846     startTime.HomeTime();
       
   847     stopTime.HomeTime();
       
   848     TTimeIntervalSeconds executionTime;
       
   849     User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
   850     TInt i(0);
       
   851     TBool errorsFound = EFalse;
       
   852     
       
   853     while (executionTime.Int() < KLongExecutionTimeInSeconds)
       
   854         {
       
   855         CPosLmDatabaseManager* dbMan = CPosLmDatabaseManager::NewL();
       
   856         CleanupStack::PushL(dbMan);
       
   857         
       
   858         // List dbs
       
   859         CDesCArray* dbList = dbMan->ListDatabasesLC();
       
   860         
       
   861         // Create db
       
   862         HPosLmDatabaseInfo* dbInfo = HPosLmDatabaseInfo::NewLC(KTestDbUri);
       
   863         TRAPD(err, dbMan->CreateDatabaseL(*dbInfo));
       
   864         CleanupStack::PopAndDestroy(dbInfo);
       
   865         if (err != KErrAlreadyExists)
       
   866             {
       
   867             AssertTrueL(dbMan->DatabaseExistsL(KTestDbUri), _L("DbManagementL: Created database does not exist"), aMessage);        
       
   868             }
       
   869             
       
   870         // Try to read default URI
       
   871         HBufC* defaultDb = dbMan->DefaultDatabaseUriLC();
       
   872         
       
   873         // Set default db to the created one
       
   874         dbMan->SetDefaultDatabaseUriL(KTestDbUri);
       
   875         
       
   876         // Remove default db
       
   877         TRAP(err, dbMan->DeleteDatabaseL(KTestDbUri));
       
   878         AssertTrueL(err == KErrNone || err == KErrInUse, _L("DbManagementL: Wrong error code when removing created database"), aMessage, err);
       
   879         if (err == KErrNone)
       
   880             {
       
   881             AssertTrueL(!dbMan->DatabaseExistsL(KTestDbUri), _L("DbManagementL: Removed database exists"), aMessage);
       
   882             }
       
   883                 
       
   884         // Create a copy of a db
       
   885         if (dbList->Count() > 0)
       
   886             {
       
   887             TRAP(err, dbMan->CopyDatabaseL((*dbList)[0], KTestDbUri));
       
   888 // TBD: How can err == KErrLocked happen? Refer to ESLI-68HKE6
       
   889 // TBD: Sometimes KErrDied is returned from this function. Why? Write error report?
       
   890             AssertTrueL(err == KErrNone || err == KErrAlreadyExists || err == KErrInUse || err == KErrLocked, _L("DbManagementL: Wrong error code when copying database"), aMessage, err);
       
   891             if (err == KErrNone || err == KErrAlreadyExists)
       
   892                 {
       
   893                 AssertTrueL(dbMan->DatabaseExistsL(KTestDbUri), _L("DbManagementL: Copied database does not exist"), aMessage);
       
   894                 
       
   895                 // Remove copy
       
   896                 TRAP(err, dbMan->DeleteDatabaseL(KTestDbUri));
       
   897                 AssertTrueL(err == KErrNone || err == KErrInUse, _L("DbManagementL: Wrong error code when removing copied database"), aMessage, err);
       
   898                 if (err == KErrNone)
       
   899                     {
       
   900                     AssertTrueL(!dbMan->DatabaseExistsL(KTestDbUri), _L("DbManagementL: Removed database exists"), aMessage);
       
   901                     }
       
   902                 }
       
   903             else if (err == KErrLocked) // To be removed when ESLI-68HKE6 is solved
       
   904                 {
       
   905                 aMessage->Copy(_L("DbManagementL: CPosLmDatabaseManager::CopyDatabaseL() left with KErrLocked - check ESLI-68HKE6"));
       
   906                 errorsFound = ETrue;
       
   907                 }
       
   908             }
       
   909             
       
   910         // Set default db to another uri
       
   911         dbMan->SetDefaultDatabaseUriL((*dbList)[i]);
       
   912         if (++i == 5)
       
   913             {
       
   914             i = 0;
       
   915             }
       
   916             
       
   917         // Increase probability that (*dbList)[i] and not KTestDbUri is default db most of the time
       
   918         User::After(10000);
       
   919         
       
   920         CleanupStack::PopAndDestroy(3, dbMan);
       
   921         
       
   922         stopTime.HomeTime();
       
   923         User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
   924         }
       
   925         
       
   926     if (errorsFound)
       
   927         {
       
   928         User::Leave(KErrGeneral);
       
   929         }
       
   930     }
       
   931 
       
   932 // ---------------------------------------------------------
       
   933 // CPosTp127::DbAccessL
       
   934 //
       
   935 // (other items were commented in a header).
       
   936 // ---------------------------------------------------------
       
   937 //
       
   938 void CPosTp127::DbAccessL(TDes* aMessage)
       
   939     {
       
   940     // Execute thread for a number of seconds
       
   941     TTime startTime, stopTime;
       
   942     startTime.HomeTime();
       
   943     stopTime.HomeTime();
       
   944     TTimeIntervalSeconds executionTime;
       
   945     User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
   946     TBool errorsFound = EFalse;
       
   947     
       
   948     while (executionTime.Int() < KLongExecutionTimeInSeconds)
       
   949         {
       
   950         CPosLandmarkDatabase* db = NULL;
       
   951         TRAPD(err, db = CPosLandmarkDatabase::OpenL());
       
   952 // TBD: How can KErrNotFound happen? Refer to ESLI-68HE4P
       
   953         if (err == KErrLocked || err == KErrInUse || err == KErrNotFound)
       
   954             {
       
   955             if (err == KErrNotFound) // To be removed when ESLI-68HE4P is solved
       
   956                 {
       
   957                 aMessage->Copy(_L("DbAccessL: CPosLandmarkDatabase::OpenL() left with KErrNotFound - check ESLI-68HE4P"));
       
   958                 errorsFound = ETrue;
       
   959                 }
       
   960             // Some client is writing(KErrLocked)/deleting(KErrInUse) the db. Try again.
       
   961             continue;
       
   962             }
       
   963         AssertTrueL(err == KErrNone, _L("DbAccessL: Wrong error code when opening db"), aMessage, err);
       
   964         CleanupStack::PushL(db);
       
   965         
       
   966         // We don't want to use the empty test database
       
   967         HBufC* dbUri = db->DatabaseUriLC();
       
   968 // TBD: Both UC and original case need to be checked here due to SDK bug! To be updated. (refer to INC053631 in teamtrack and ESLI-68HK3W in TSW)
       
   969         if (dbUri->Find(KTestDbUriUC) != KErrNotFound || dbUri->Find(KTestDbUri) != KErrNotFound)
       
   970             {
       
   971             if (dbUri->Find(KTestDbUriUC) != KErrNotFound) // To be removed when ESLI-68HK3W is solved
       
   972                 {
       
   973                 aMessage->Copy(_L("DbAccessL: UPPER CASE of db URI found - check ESLI-68HK3W"));
       
   974                 errorsFound = ETrue;
       
   975                 }            
       
   976             CleanupStack::PopAndDestroy(2, db);
       
   977             stopTime.HomeTime();
       
   978             User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
   979             continue;
       
   980             }
       
   981             
       
   982         // Fetch db iterator
       
   983         CPosLmItemIterator* iterator = NULL;
       
   984         TRAP(err, iterator = db->LandmarkIteratorL());
       
   985 // TBD: KErrPosLmNotInitialized should not be accepted. Refer to ESLI-68JAMD
       
   986         if (err == KErrCorrupt || err == KErrPosLmNotInitialized)
       
   987             {
       
   988             if (err == KErrPosLmNotInitialized) // To be removed when ESLI-68JAMD is solved
       
   989                 {
       
   990                 aMessage->Copy(_L("DbAccessL: CPosLandmarkDatabase::LandmarkIteratorL() left with KErrPosLmNotInitialized - check ESLI-68JAMD"));
       
   991                 errorsFound = ETrue;
       
   992                 }            
       
   993 // TBD: Databases need to be re-initialized, because they haved been damaged. Why do they become damaged?
       
   994             err = KErrLocked;
       
   995             while (err == KErrLocked && db->IsInitializingNeeded())
       
   996                 {
       
   997                 TRAP(err, ExecuteAndDeleteLD(db->InitializeL()));
       
   998                 AssertTrueL(err == KErrNone || err == KErrLocked, _L("DbAccessL: Wrong error code when initializing"), aMessage, err);
       
   999                 }
       
  1000             TRAP(err, iterator = db->LandmarkIteratorL());
       
  1001             }
       
  1002         TBuf<100> buf;
       
  1003         _LIT(KFormat, "DbAccessL: Wrong error code when creating iterator for db %S");
       
  1004         buf.Format(KFormat, dbUri);
       
  1005         AssertTrueL(err == KErrNone, buf, aMessage, err);
       
  1006         CleanupStack::PopAndDestroy(dbUri);
       
  1007         CleanupStack::PushL(iterator);
       
  1008         
       
  1009         // Add, read and update a landmark
       
  1010         CPosLandmark* lm = CPosLandmark::NewLC();
       
  1011         TPosLmItemId id = KPosLmNullItemId;
       
  1012         TRAP(err, id = db->AddLandmarkL(*lm));
       
  1013         CleanupStack::PopAndDestroy(lm);        
       
  1014         if (err == KErrNone)
       
  1015             {            
       
  1016             TRAP(err, CleanupStack::Pop(lm = db->ReadLandmarkLC(id)));
       
  1017             CleanupStack::PushL(lm);
       
  1018             AssertTrueL(err == KErrNone, _L("DbAccessL: Wrong error code when reading created landmark"), aMessage, err);
       
  1019             lm->SetLandmarkNameL(_L("A landmark"));
       
  1020             TRAP(err, db->UpdateLandmarkL(*lm));
       
  1021             AssertTrueL(err == KErrNone || err == KErrLocked, _L("DbAccessL: Wrong error code when updating lm"), aMessage, err);
       
  1022             CleanupStack::PopAndDestroy(lm);
       
  1023             }
       
  1024         else
       
  1025             {
       
  1026             AssertTrueL(err == KErrLocked, _L("DbAccessL: Wrong error code when adding lm"), aMessage, err);
       
  1027             }
       
  1028         
       
  1029         // Remove possible added landmarks
       
  1030         TInt nrOfItems = iterator->NumOfItemsL();
       
  1031         if (nrOfItems > KMaxNrOfLms)
       
  1032             {
       
  1033             RIdArray idArray;
       
  1034             CleanupClosePushL(idArray);
       
  1035             iterator->GetItemIdsL(idArray, KMaxNrOfLms, nrOfItems - KMaxNrOfLms);
       
  1036             err = KErrLocked;
       
  1037             while (err != KErrNone)
       
  1038                 {
       
  1039                 TRAP(err, ExecuteAndDeleteLD(db->RemoveLandmarksL(idArray)));
       
  1040                 AssertTrueL(err == KErrNone || err == KErrLocked, _L("DbAccessL: Wrong error code when removing lm"), aMessage, err);
       
  1041                 }
       
  1042             CleanupStack::PopAndDestroy(&idArray);
       
  1043             }
       
  1044 
       
  1045         CleanupStack::PopAndDestroy(2, db);
       
  1046         
       
  1047         stopTime.HomeTime();
       
  1048         User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
  1049         }
       
  1050         
       
  1051     if (errorsFound)
       
  1052         {
       
  1053         User::Leave(KErrGeneral);
       
  1054         }
       
  1055     }
       
  1056 
       
  1057 // ---------------------------------------------------------
       
  1058 // CPosTp127::SingleDbSearchL
       
  1059 //
       
  1060 // (other items were commented in a header).
       
  1061 // ---------------------------------------------------------
       
  1062 //
       
  1063 void CPosTp127::SingleDbSearchL(TDes* aMessage)
       
  1064     {
       
  1065     // Execute thread for a number of seconds
       
  1066     TTime startTime, stopTime;
       
  1067     startTime.HomeTime();
       
  1068     stopTime.HomeTime();
       
  1069     TTimeIntervalSeconds executionTime;
       
  1070     User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
  1071     TInt64 seed = startTime.Int64();
       
  1072     TBool errorsFound = EFalse;
       
  1073     
       
  1074     while (executionTime.Int() < KLongExecutionTimeInSeconds)
       
  1075         {
       
  1076         CPosLmDatabaseManager* dbMan = CPosLmDatabaseManager::NewL();
       
  1077         CleanupStack::PushL(dbMan);
       
  1078         CDesCArray* dbList = dbMan->ListDatabasesLC();
       
  1079         
       
  1080         // Open one of the pre-defined databases
       
  1081         TInt index = (TInt) (Math::FRand(seed) * dbList->Count());
       
  1082         TPtrC uri = (*dbList)[index];
       
  1083 // TBD: Both UC and original case need to be checked here due to SDK bug! To be updated. (refer to INC053631 in teamtrack and ESLI-68HK3W in TSW)
       
  1084         if (uri.Find(KTestDbUriUC) != KErrNotFound || uri.Find(KTestDbUri) != KErrNotFound)
       
  1085             {
       
  1086             if (uri.Find(KTestDbUriUC) != KErrNotFound) // To be removed when ESLI-68HK3W is solved
       
  1087                 {
       
  1088                 aMessage->Copy(_L("SingleDbSearchL: UPPER CASE of db URI found - check ESLI-68HK3W"));
       
  1089                 errorsFound = ETrue;
       
  1090                 }                            
       
  1091             // We don't want to search the empty test database
       
  1092             CleanupStack::PopAndDestroy(2, dbMan);
       
  1093             continue;
       
  1094             }
       
  1095         CPosLandmarkDatabase* db = NULL;
       
  1096         TRAPD(err, db = CPosLandmarkDatabase::OpenL(uri));
       
  1097         if (err == KErrLocked)
       
  1098             {
       
  1099             // Some client is writing to the db. Try again.
       
  1100             CleanupStack::PopAndDestroy(2, dbMan);
       
  1101             continue;
       
  1102             }
       
  1103         _LIT(KFormat, "SingleDbSearchL: Wrong error code when opening db %S");
       
  1104         TBuf<100> buf;        
       
  1105         buf.Format(KFormat, &uri);
       
  1106         AssertTrueL(err == KErrNone, buf, aMessage, err);
       
  1107         CleanupStack::PushL(db);
       
  1108 
       
  1109         CPosLandmarkSearch* dbSearcher = NULL;
       
  1110         TRAP(err, dbSearcher = CPosLandmarkSearch::NewL(*db));
       
  1111         AssertTrueL(err == KErrNone, _L("SingleDbSearchL: Wrong error code when calling CPosLandmarkSearch::NewL"), aMessage, err);
       
  1112         CleanupStack::PushL(dbSearcher);
       
  1113         
       
  1114         // Search for landmarks containing a specific string
       
  1115         CPosLmTextCriteria* criteria = CPosLmTextCriteria::NewLC();
       
  1116         criteria->SetTextL(_L("*as*"));
       
  1117         CPosLmOperation* operation = NULL;
       
  1118         TRAP(err, operation = dbSearcher->StartLandmarkSearchL(*criteria));
       
  1119         AssertTrueL(err == KErrNone || err == KErrLocked, _L("SingleDbSearchL: Wrong error code when creating search op"), aMessage, err);
       
  1120         if (operation)
       
  1121             {
       
  1122             CleanupStack::PushL(operation);
       
  1123             TRAP(err, operation->ExecuteL());
       
  1124             AssertTrueL(err == KErrNone || err == KErrLocked, _L("SingleDbSearchL: Wrong error code when executing search op"), aMessage, err);
       
  1125             CleanupStack::PopAndDestroy(operation);
       
  1126             }
       
  1127         
       
  1128         CleanupStack::PopAndDestroy(5, dbMan);
       
  1129 
       
  1130         stopTime.HomeTime();
       
  1131         User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
  1132         }
       
  1133 
       
  1134     if (errorsFound)
       
  1135         {
       
  1136         User::Leave(KErrGeneral);
       
  1137         }
       
  1138     }
       
  1139 
       
  1140 // ---------------------------------------------------------
       
  1141 // CPosTp127::MultipleDbSearchL
       
  1142 //
       
  1143 // (other items were commented in a header).
       
  1144 // ---------------------------------------------------------
       
  1145 //
       
  1146 void CPosTp127::MultipleDbSearchL(TDes* aMessage)
       
  1147     {
       
  1148     // Execute thread for a number of seconds
       
  1149     TTime startTime, stopTime;
       
  1150     startTime.HomeTime();
       
  1151     stopTime.HomeTime();
       
  1152     TTimeIntervalSeconds executionTime;
       
  1153     User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
  1154 /*    
       
  1155     RArray<RIdArray> expectedResult; // contains expected matches when search patern is *e*
       
  1156     CleanupClosePushL(expectedResult);
       
  1157     
       
  1158     RIdArray array1;
       
  1159     CleanupClosePushL(array1);
       
  1160     array1.AppendL(4); // vegetariskt
       
  1161     array1.AppendL(5); // Inte sa bra
       
  1162     array1.AppendL(8); // Medel
       
  1163     array1.AppendL(9); // Medel2
       
  1164     array1.AppendL(12); // GatesB    
       
  1165     array1.AppendL(13); // Text"'1
       
  1166     array1.AppendL(14); // GatesF
       
  1167     array1.AppendL(15); // xStekt
       
  1168     array1.AppendL(18); // enat?r
       
  1169     array1.AppendL(19); // enator
       
  1170     expectedResult.AppendL(array1);
       
  1171     
       
  1172     RIdArray array2;
       
  1173     CleanupClosePushL(array2);
       
  1174     for (TInt i = 29; i <= 40; i++)
       
  1175         {
       
  1176         array2.AppendL(i); // Unique - Text10
       
  1177         }
       
  1178     expectedResult.AppendL(array2);
       
  1179     
       
  1180     RIdArray array3;
       
  1181     CleanupClosePushL(array3);
       
  1182     array3.AppendL(45); // Several
       
  1183     array3.AppendL(51); // PellesPizza
       
  1184     array3.AppendL(52); // Kalles Hundgård
       
  1185     for (TInt i = 54; i <= 60; i++)
       
  1186         {
       
  1187         array3.AppendL(i); // TE, Gårda - TE, Oulu
       
  1188         }
       
  1189     expectedResult.AppendL(array3);
       
  1190 
       
  1191     RIdArray array4;
       
  1192     CleanupClosePushL(array4);
       
  1193     array4.AppendL(61); // TE, Tampere
       
  1194     array4.AppendL(62); // Nokia, Köpenhamn
       
  1195     array4.AppendL(65); // Tampere
       
  1196     array4.AppendL(66); // Helsinki
       
  1197     array4.AppendL(67); // Bengtfors
       
  1198     array4.AppendL(70); // Göteborg
       
  1199     array4.AppendL(71); // PallesPalör
       
  1200     array4.AppendL(72); // Läkare utan gränser
       
  1201     array4.AppendL(74); // Läkargruppen
       
  1202     array4.AppendL(75); // Läkarhuset
       
  1203     array4.AppendL(76); // Sahlgrenska
       
  1204     array4.AppendL(77); // östra sjukhuset
       
  1205     array4.AppendL(80); // GöteborgsTaxi
       
  1206     expectedResult.AppendL(array4);
       
  1207 
       
  1208     RIdArray array5;
       
  1209     CleanupClosePushL(array5);
       
  1210     array5.AppendL(81); // LandvetterTaxi
       
  1211     array5.AppendL(84); // Länsmuseumet
       
  1212     array5.AppendL(85); // Sjöfartsmuseumet
       
  1213     array5.AppendL(86); // KinaMuseumet
       
  1214     array5.AppendL(88); // Etnogfrafiska
       
  1215     array5.AppendL(89); // TekniskaMuseumet
       
  1216     array5.AppendL(91); // Centrum dagiset
       
  1217     array5.AppendL(93); // Lackarbäcks daghem
       
  1218     for (TInt i = 95; i <= 100; i++)
       
  1219         {
       
  1220         array5.AppendL(i); // TE dagis - krokslätts frisörerna
       
  1221         }
       
  1222     expectedResult.AppendL(array5);
       
  1223 */
       
  1224     RArray<TInt> nrOfExpectedMatches; // contains the number of matches for each db when search pattern is *e*
       
  1225     CleanupClosePushL(nrOfExpectedMatches);
       
  1226     nrOfExpectedMatches.AppendL(10);
       
  1227     nrOfExpectedMatches.AppendL(12);
       
  1228     nrOfExpectedMatches.AppendL(10);
       
  1229     nrOfExpectedMatches.AppendL(13);
       
  1230     nrOfExpectedMatches.AppendL(14);
       
  1231     
       
  1232     while (executionTime.Int() < KLongExecutionTimeInSeconds)
       
  1233         {
       
  1234         CDesCArray* dbList = new (ELeave) CDesCArrayFlat(5);
       
  1235         CleanupStack::PushL(dbList);
       
  1236         dbList->AppendL(KDb20);
       
  1237         dbList->AppendL(KDb40);
       
  1238         dbList->AppendL(KDb60);
       
  1239         dbList->AppendL(KDb80);
       
  1240         dbList->AppendL(KDb105);
       
  1241         CPosLmMultiDbSearch* dbSearcher = CPosLmMultiDbSearch::NewL(*dbList);
       
  1242         CleanupStack::PushL(dbSearcher);
       
  1243         
       
  1244         // Search for landmarks containing a specific string in name
       
  1245         CPosLmTextCriteria* criteria = CPosLmTextCriteria::NewLC();
       
  1246         criteria->SetTextL(_L("*e*"));
       
  1247         criteria->SetAttributesToSearch(CPosLandmark::ELandmarkName);
       
  1248         CPosLmOperation* operation = NULL;
       
  1249         TRAPD(err, operation = dbSearcher->StartLandmarkSearchL(*criteria))
       
  1250         AssertTrueL(err == KErrNone || err == KErrLocked, _L("MultipleDbSearchL: Wrong error code when creating search op"), aMessage, err);
       
  1251         if (operation)
       
  1252             {
       
  1253             CleanupStack::PushL(operation);
       
  1254             TRAP(err, operation->ExecuteL());
       
  1255             AssertTrueL(err == KErrNone || err == KErrLocked, _L("MultipleDbSearchL: Wrong error code when executing search op"), aMessage, err);
       
  1256             CleanupStack::PopAndDestroy(operation);
       
  1257             }
       
  1258         
       
  1259         // Check errors
       
  1260         RArray<TInt> dbsWithErrors;
       
  1261         CleanupClosePushL(dbsWithErrors);
       
  1262         TUint nrOfSearchErrors = dbSearcher->NumOfSearchErrors();
       
  1263         for (TUint i = 0; i < nrOfSearchErrors; i++)
       
  1264             {
       
  1265             CPosLmMultiDbSearch::TSearchError error;
       
  1266             dbSearcher->GetSearchError(i, error);
       
  1267             AssertTrueL(error.iErrorCode == KErrLocked, _L("MultipleDbSearchL: Wrong error code when searching"), aMessage, error.iErrorCode);
       
  1268             dbsWithErrors.AppendL(error.iDatabaseIndex);
       
  1269             }
       
  1270             
       
  1271         // Check number of matches
       
  1272         for (TInt i = 0; i < dbList->Count(); i++)
       
  1273             {
       
  1274             if (dbsWithErrors.Find(i) == KErrNotFound)
       
  1275                 {
       
  1276                 TInt nrOfMatches = dbSearcher->NumOfMatches(i);
       
  1277                 TInt expectedResult = nrOfExpectedMatches[i];
       
  1278 				AssertTrueL(nrOfMatches == expectedResult, _L("MultipleDbSearchL: Wrong number of matches"), aMessage);
       
  1279                 }
       
  1280             }
       
  1281         
       
  1282         CleanupStack::PopAndDestroy(4, dbList);
       
  1283         
       
  1284         stopTime.HomeTime();
       
  1285         User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
  1286         }
       
  1287         
       
  1288     CleanupStack::PopAndDestroy(&nrOfExpectedMatches);
       
  1289     }
       
  1290 
       
  1291 // ---------------------------------------------------------
       
  1292 // CPosTp127::CopyLockedDatabaseL
       
  1293 //
       
  1294 // (other items were commented in a header).
       
  1295 // ---------------------------------------------------------
       
  1296 //
       
  1297 void CPosTp127::CopyLockedDatabaseL(TDes* aMessage)
       
  1298     {
       
  1299     TBool lockThreadExists = ThreadExistsL(KLockThreadSearchPattern);
       
  1300     if (lockThreadExists)
       
  1301         {
       
  1302         // Let lock thread launch first
       
  1303         User::After(KLockThreadStartupTime);
       
  1304         }
       
  1305 
       
  1306     CPosLmDatabaseManager* dbMan = CPosLmDatabaseManager::NewL();
       
  1307     CleanupStack::PushL(dbMan);
       
  1308     CDesCArray* dbList = dbMan->ListDatabasesLC();
       
  1309     AssertTrueL(dbList->Count() == KNrOfDatabases, _L("CopyLockedDatabaseL: Wrong number of databases"), aMessage);
       
  1310     
       
  1311     // Try to copy database. Should result in KErrInUse
       
  1312     TRAPD(err, dbMan->CopyDatabaseL((*dbList)[KLockedDbIndex], KTestDbUri));
       
  1313 // TBD: KErrLocked should not be accepted. Refer to ESLI-68HKE6
       
  1314     AssertTrueL(err != KErrLocked, _L("CopyLockedDatabaseL: Wrong error code when copying database - check ESLI-68HKE6"), aMessage, err);
       
  1315     AssertTrueL(err == KErrInUse , _L("CopyLockedDatabaseL: Wrong error code when copying database"), aMessage, err);
       
  1316     
       
  1317     CleanupStack::PopAndDestroy(2, dbMan);
       
  1318     }
       
  1319     
       
  1320 // ---------------------------------------------------------
       
  1321 // CPosTp127::CopyDatabaseL
       
  1322 //
       
  1323 // (other items were commented in a header).
       
  1324 // ---------------------------------------------------------
       
  1325 //
       
  1326 void CPosTp127::CopyDatabaseL(TDes* aMessage)
       
  1327     {
       
  1328     // Execute thread for a number of seconds
       
  1329     TTime startTime, stopTime;
       
  1330     startTime.HomeTime();
       
  1331     stopTime.HomeTime();
       
  1332     TTimeIntervalSeconds executionTime;
       
  1333     User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
  1334     TInt64 seed = startTime.Int64();
       
  1335     TBool errorsFound = EFalse;
       
  1336 
       
  1337     CPosLmDatabaseManager* dbMan = CPosLmDatabaseManager::NewL();
       
  1338     CleanupStack::PushL(dbMan);
       
  1339     while (executionTime.Int() < KShortExecutionTimeInSeconds)
       
  1340         {
       
  1341         CDesCArray* dbList = dbMan->ListDatabasesLC();
       
  1342         
       
  1343         // Create a source and a target URI
       
  1344         _LIT(KCopy, "_copy");
       
  1345         TInt copyLength = KCopy().Length();
       
  1346         TInt index = (TInt) (Math::FRand(seed) * dbList->Count());
       
  1347         TPtrC sourceUri = (*dbList)[index];
       
  1348         HBufC* targetUriBuffer = HBufC::NewLC(sourceUri.Length() + copyLength);
       
  1349         TPtr targetUri = targetUriBuffer->Des();
       
  1350         targetUri.Copy(sourceUri);
       
  1351         targetUri.Insert(targetUri.Length() - 4, KCopy); // 4 == length of ".ldb"
       
  1352 
       
  1353         // Try to copy database. Should result in KErrInUse if locked, KErrNone otherwise
       
  1354         TRAPD(err, dbMan->CopyDatabaseL(sourceUri, targetUri));
       
  1355         AssertTrueL(err == KErrNone || err == KErrAlreadyExists, _L("CopyDatabaseL: Wrong error code when copying database"), aMessage, err);
       
  1356         
       
  1357         // Set default database to the created one
       
  1358         TRAP(err, dbMan->SetDefaultDatabaseUriL(targetUri));
       
  1359         AssertTrueL(err == KErrNone || err == KErrNotFound, _L("CopyDatabaseL: Wrong error code when setting default db to target"), aMessage, err);
       
  1360         
       
  1361         // Remove the created database
       
  1362         err = KErrLocked;
       
  1363         while (err != KErrNone && err != KErrNotFound)
       
  1364             {
       
  1365             TRAP(err, dbMan->DeleteDatabaseL(targetUri));
       
  1366             }
       
  1367         
       
  1368         // Set default database to the source
       
  1369         TRAP(err, dbMan->SetDefaultDatabaseUriL(sourceUri));
       
  1370         AssertTrueL(err == KErrNone, _L("CopyDatabaseL: Wrong error code when setting default db to source"), aMessage, err);
       
  1371         
       
  1372         CleanupStack::PopAndDestroy(2, dbList);
       
  1373         
       
  1374         stopTime.HomeTime();
       
  1375         User::LeaveIfError(stopTime.SecondsFrom(startTime, executionTime));
       
  1376         }
       
  1377         
       
  1378     if (errorsFound)
       
  1379         {
       
  1380         User::Leave(KErrGeneral);
       
  1381         }
       
  1382     CleanupStack::PopAndDestroy(dbMan);
       
  1383     }
       
  1384         
       
  1385 //  End of File