landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTP27.cpp
branchRCL_3
changeset 44 2b4ea9893b66
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
       
     1 /*
       
     2 * Copyright (c) 2004 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_CPosTp27.h"
       
    22 #include <EPos_CPosLmTextCriteria.h>
       
    23 #include <EPos_CPosLMItemIterator.h>
       
    24 #include <EPos_CPosLmCatNameCriteria.h>
       
    25 #include <EPos_CPosLmCategoryCriteria.h>
       
    26 
       
    27 // CONSTANTS
       
    28 
       
    29 // ================= MEMBER FUNCTIONS =======================
       
    30 
       
    31 // ---------------------------------------------------------
       
    32 // CPosTp27::CloseTest
       
    33 //
       
    34 // (other items were commented in a header).
       
    35 // ---------------------------------------------------------
       
    36 //
       
    37 void CPosTp27::CloseTest()
       
    38     {
       
    39     delete iPeriodicTimer;
       
    40     iPeriodicTimer = NULL;
       
    41 
       
    42     delete iDatabase;
       
    43     iDatabase = NULL;
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // CPosTp27::StartL
       
    48 //
       
    49 // (other items were commented in a header).
       
    50 // ---------------------------------------------------------
       
    51 //
       
    52 void CPosTp27::StartL()
       
    53     {
       
    54     iDatabase = UseGeneratedDbFileL();   
       
    55 
       
    56     if (iDatabase->IsInitializingNeeded())
       
    57        {
       
    58        CPosLmOperation* op = iDatabase->InitializeL();
       
    59        delete op;
       
    60        }
       
    61 
       
    62     CancelLandmarkCategorySearch();
       
    63 
       
    64     CancelLandmarkSearch();
       
    65 
       
    66     AssertTrueSecL(iGlobalErr != KErrNone, _L("Errors found in TP27"));
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------
       
    70 // CPosTp27::CancelLandmarkCategorySearch
       
    71 //
       
    72 // (other items were commented in a header).
       
    73 // ---------------------------------------------------------
       
    74 //
       
    75 void CPosTp27::CancelLandmarkCategorySearch()
       
    76     {
       
    77     iLog->Log(_L("CancelLandmarkCategorySearch"));
       
    78     CPosLmCatNameCriteria* searchCriteria = CPosLmCatNameCriteria::NewLC();
       
    79 
       
    80     // Use name specified in test landmarksdb
       
    81     searchCriteria->SetSearchPatternL(_L("Taxi"));       
       
    82 
       
    83     iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase, this);
       
    84     // Get maximum number of search attempts
       
    85     iLandmarkSearch->StartCategorySearchL(*searchCriteria, CPosLmCategoryManager::ECategorySortOrderNone);
       
    86 
       
    87     iHandleOperationDisabled = EFalse;
       
    88     iActiveSchedulerWait->Start();
       
    89     iHandleOperationDisabled = ETrue;
       
    90     // Get the maximum of needed search rounds until search is complete
       
    91     TInt MaxNrOfSearchRounds = iNrSearchRounds;
       
    92 
       
    93     // First test to cancel the search before it even has started
       
    94     // use the callback StopActiveSchedulerWait to stop the active scheduler
       
    95     // just to make sure that no HandleOperationProgress take place
       
    96     iNrSearchRounds = 0;
       
    97     iLandmarkSearch->StartCategorySearchL(*searchCriteria, CPosLmCategoryManager::ECategorySortOrderNone);
       
    98     iLandmarkSearch->Cancel();
       
    99 
       
   100     TCallBack callback(StopActiveSchedulerWait, this);
       
   101     iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityStandard);
       
   102     TTimeIntervalMicroSeconds32 stopTime = TTimeIntervalMicroSeconds32(4000000); // 4 sec
       
   103     iPeriodicTimer->Start(stopTime, stopTime, callback);
       
   104     iHandleOperationDisabled = ETrue;
       
   105     iActiveSchedulerWait->Start();
       
   106 
       
   107     delete iPeriodicTimer;
       
   108     iPeriodicTimer = NULL;
       
   109 
       
   110     iLog->Log(_L("Starting"));
       
   111     TInt i=0;
       
   112     for (i=0; i<=MaxNrOfSearchRounds; i++)
       
   113         {
       
   114         iNrSearchRounds = 0;
       
   115         iBreakSearch = i;
       
   116         // Set to 100 so that it differs from progress the first time
       
   117         iProgress=100;
       
   118         iLog->Log(_L("StartCategorySearchL->"));
       
   119         iLandmarkSearch->StartCategorySearchL(*searchCriteria, CPosLmCategoryManager::ECategorySortOrderNone);
       
   120         iHandleOperationDisabled = EFalse;
       
   121         iActiveSchedulerWait->Start();
       
   122 
       
   123         iLog->Log(_L("After iActiveSchedulerWait->Start() inside for loop"));
       
   124         iHandleOperationDisabled = ETrue;
       
   125 
       
   126         // Check if anything was found
       
   127         CPosLmItemIterator* iterator = iLandmarkSearch->MatchIteratorL();
       
   128         CleanupStack::PushL(iterator);
       
   129         
       
   130         TInt numOfItems = 0;
       
   131         numOfItems = iLandmarkSearch->NumOfMatches();
       
   132        
       
   133         RArray<TPosLmItemId> ids;
       
   134         CleanupClosePushL(ids);
       
   135         
       
   136         if (numOfItems != 0)
       
   137             {
       
   138             iLog->Log(_L("Found something"));
       
   139             // Maybe we should check this item
       
   140             iterator->GetItemIdsL(ids, 0, numOfItems);
       
   141             }
       
   142         
       
   143         CleanupStack::PopAndDestroy(&ids);
       
   144         CleanupStack::PopAndDestroy(iterator);
       
   145         }
       
   146     
       
   147     iNrSearchRounds=0;
       
   148     iBreakSearch = -1;
       
   149     iCancelOrDelete = ETrue;
       
   150 
       
   151     delete iLandmarkSearch;
       
   152     iLandmarkSearch = NULL;
       
   153 
       
   154     iLog->Log(_L("This time, delete the search object to cancel the search"));
       
   155     for (i=0; i<=MaxNrOfSearchRounds; i++)
       
   156         {
       
   157         iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase, this);   
       
   158         // Set to 100 so that it differs from progress the first time
       
   159         iProgress=100;
       
   160         iNrSearchRounds = 0;
       
   161         iBreakSearch = i;
       
   162         iLog->Log(_L("StartCategorySearchL2->"));
       
   163         iLandmarkSearch->StartCategorySearchL(*searchCriteria, CPosLmCategoryManager::ECategorySortOrderNone);
       
   164         iHandleOperationDisabled = EFalse;
       
   165         iActiveSchedulerWait->Start();
       
   166         iHandleOperationDisabled = ETrue;
       
   167         iLog->Log(_L("After iActiveSchedulerWait->Start() inside for loop"));
       
   168         }
       
   169     iHandleOperationDisabled = EFalse;
       
   170     CleanupStack::PopAndDestroy(searchCriteria);
       
   171 
       
   172     iCancelOrDelete = EFalse;
       
   173     delete iLandmarkSearch;
       
   174     iLandmarkSearch = NULL;
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------
       
   178 // CPosTp27::CancelLandmarkSearch
       
   179 //
       
   180 // (other items were commented in a header).
       
   181 // ---------------------------------------------------------
       
   182 //
       
   183 void CPosTp27::CancelLandmarkSearch()
       
   184     {
       
   185     iLog->Log(_L("CancelLandmarkSearch"));
       
   186 
       
   187     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   188     TUint attr = CPosLandmark::ELandmarkName | CPosLandmark::EDescription;
       
   189     textCriteria->SetAttributesToSearch(attr);
       
   190     // Use name specified in test landmarksdb
       
   191     textCriteria->SetTextL(_L("enator"));
       
   192         
       
   193     iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase, this);
       
   194     iLandmarkSearch->StartLandmarkSearchL(*textCriteria);
       
   195     iHandleOperationDisabled = EFalse;
       
   196     iActiveSchedulerWait->Start();
       
   197     iHandleOperationDisabled = ETrue;
       
   198 
       
   199     // Get the maximum of needed search rounds until search is complete
       
   200     TInt MaxNrOfSearchRounds = iNrSearchRounds;
       
   201 
       
   202     // First test to cancel the search before it even has started
       
   203     // use the callback StopActiveSchedulerWait to stop the active scheduler
       
   204     // just to make sure that no HandleOperationProgress take place
       
   205     iNrSearchRounds = 0;
       
   206     iLandmarkSearch->StartLandmarkSearchL(*textCriteria);
       
   207     iLandmarkSearch->Cancel();
       
   208 
       
   209     TCallBack callback(StopActiveSchedulerWait, this);
       
   210     iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityStandard);
       
   211     TTimeIntervalMicroSeconds32 stopTime = TTimeIntervalMicroSeconds32(4000000); // 4 sec
       
   212     iPeriodicTimer->Start(stopTime, stopTime, callback);
       
   213     iHandleOperationDisabled = ETrue;
       
   214     iActiveSchedulerWait->Start();
       
   215 
       
   216     delete iPeriodicTimer;
       
   217     iPeriodicTimer = NULL;
       
   218 
       
   219     iLog->Log(_L("Starting"));
       
   220     TInt i=0;
       
   221     for (i=0; i<=MaxNrOfSearchRounds; i++)
       
   222         {
       
   223         iNrSearchRounds = 0;
       
   224         iBreakSearch = i;
       
   225         // Set to 100 so that it differs from progress the first time
       
   226         iProgress=100;
       
   227         iLog->Log(_L("StartLandmarkSearchL->"));
       
   228         iLandmarkSearch->StartLandmarkSearchL(*textCriteria);
       
   229         iHandleOperationDisabled = EFalse;
       
   230         iActiveSchedulerWait->Start();
       
   231 
       
   232         iLog->Log(_L("After iActiveSchedulerWait->Start() inside for loop"));
       
   233         iHandleOperationDisabled = ETrue;
       
   234 
       
   235         // Check if anything was found
       
   236         CPosLmItemIterator* iterator = iLandmarkSearch->MatchIteratorL();
       
   237         CleanupStack::PushL(iterator);
       
   238         
       
   239         TInt numOfItems = 0;
       
   240         numOfItems = iLandmarkSearch->NumOfMatches();
       
   241        
       
   242         RArray<TPosLmItemId> ids;
       
   243         CleanupClosePushL(ids);
       
   244         
       
   245         if (numOfItems != 0)
       
   246             {
       
   247             iLog->Log(_L("Found something"));
       
   248             iterator->GetItemIdsL(ids, 0, numOfItems);
       
   249             }
       
   250         
       
   251         CleanupStack::PopAndDestroy(&ids);
       
   252         CleanupStack::PopAndDestroy(iterator);
       
   253         }
       
   254     
       
   255     iNrSearchRounds=0;
       
   256     iBreakSearch = -1;
       
   257     iCancelOrDelete = ETrue;
       
   258 
       
   259     delete iLandmarkSearch;
       
   260     iLandmarkSearch = NULL;
       
   261 
       
   262     iLog->Log(_L("This time, delete the search object to cancel the search"));
       
   263     for (i=0; i<=MaxNrOfSearchRounds; i++)
       
   264         {
       
   265         iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase, this);   
       
   266         // Set to 100 so that it differs from progress the first time
       
   267         iProgress=100;
       
   268         iNrSearchRounds = 0;
       
   269         iBreakSearch = i;
       
   270         iLog->Log(_L("StartLandmarkSearchL2->"));
       
   271         iLandmarkSearch->StartLandmarkSearchL(*textCriteria);
       
   272         iHandleOperationDisabled = EFalse;
       
   273         iActiveSchedulerWait->Start();
       
   274         iHandleOperationDisabled = ETrue;
       
   275         iLog->Log(_L("After iActiveSchedulerWait->Start() inside for loop"));
       
   276         }
       
   277     iHandleOperationDisabled = EFalse;
       
   278     CleanupStack::PopAndDestroy(textCriteria);
       
   279 
       
   280     iCancelOrDelete = EFalse;
       
   281 
       
   282     delete iLandmarkSearch;
       
   283     iLandmarkSearch = NULL;    
       
   284     }
       
   285 
       
   286 
       
   287 // ---------------------------------------------------------
       
   288 // CPosTp27::StopActiveSchedulerWait
       
   289 //
       
   290 // (other items were commented in a header).
       
   291 // ---------------------------------------------------------
       
   292 //
       
   293 TInt CPosTp27::StopActiveSchedulerWait(TAny* aSelf)
       
   294     {
       
   295     //do not forget to cancel the timer
       
   296     CPosTp27* self = static_cast<CPosTp27*> (aSelf);
       
   297     self->iPeriodicTimer->Cancel();
       
   298     self->iActiveSchedulerWait->AsyncStop();
       
   299     return KErrNone;
       
   300     }
       
   301 
       
   302 // ---------------------------------------------------------
       
   303 // CPosTp27::HandleOperationProgress
       
   304 //
       
   305 // (other items were commented in a header).
       
   306 // ---------------------------------------------------------
       
   307 //
       
   308 void CPosTp27::HandleOperationProgress(CPosLmOperation*  aOperation)
       
   309     {
       
   310     //if (iDebug) iLog->Log(_L("HandleOperationProgress"));
       
   311 
       
   312     // If no HandleOperationProgress should occur, eg no search is started
       
   313     if (iHandleOperationDisabled)
       
   314         {
       
   315         iLog->Log(_L("ERROR: No HandleOperationProgress should occur"));
       
   316         iGlobalErr++;
       
   317         }
       
   318     else
       
   319     {
       
   320     // If progress is 100%, always stop the search
       
   321     // Check that progress is moving
       
   322     TReal32 progress = aOperation->Progress();
       
   323     if (iProgress == progress)
       
   324         {
       
   325         iLog->Log(_L("MyError:Progressindicator not moving"));
       
   326         iGlobalErr++;
       
   327         }
       
   328     iProgress = progress;
       
   329     TBuf<50> buf;
       
   330     buf.Format(_L("****Progress %f"), progress);
       
   331     if (iDebug) iLog->Log(buf);
       
   332 
       
   333     // Not sure about this condition, is it ok to compare TReal32 like this
       
   334     if (progress == 1)
       
   335         {
       
   336         if (iDebug) iLog->Log(_L("Stopping"));
       
   337         iActiveSchedulerWait->AsyncStop();
       
   338         return;
       
   339         }
       
   340 
       
   341     if (iNrSearchRounds == iBreakSearch)
       
   342         {
       
   343         if (!iCancelOrDelete)
       
   344             {
       
   345             if (iDebug) iLog->Log(_L("Cancelling"));
       
   346             aOperation->Cancel();
       
   347             iActiveSchedulerWait->AsyncStop();
       
   348             if (aOperation->Status() != KErrCancel)
       
   349                 {
       
   350                 TBuf<50> buf;
       
   351                 buf.Format(_L("MyError: Wrong status, should be KErrCancel, but was %d"), aOperation->Status());
       
   352                 iLog->Log(buf);
       
   353                 iGlobalErr++;
       
   354                 }
       
   355             }
       
   356         else
       
   357             {
       
   358             if (iDebug) iLog->Log(_L("Cancel by deleting search object"));
       
   359             delete iLandmarkSearch;
       
   360             iLandmarkSearch = NULL;
       
   361             iActiveSchedulerWait->AsyncStop();
       
   362             }
       
   363         }
       
   364         iNrSearchRounds++;
       
   365     }
       
   366     }
       
   367 // End of file
       
   368