landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp131.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_CPosTp131.h"
       
    22 #include <EPos_CPosLandmarkDatabase.h>
       
    23 #include <EPos_CPosLandmarkSearch.h>
       
    24 #include <EPos_CPosLmTextCriteria.h>
       
    25 #include <EPos_CPosLMItemIterator.h>
       
    26 #include <EPos_CPosLmDisplayData.h>
       
    27 #include <EPos_CPosLmDisplayItem.h>
       
    28 #include <EPos_TPosLMSortPref.h>
       
    29 #include "FT_CSearchResult.h"
       
    30 #include <LbsPosition.h>
       
    31 #include "FT_LandmarkConstants.h"
       
    32      
       
    33 // CONSTANTS
       
    34 
       
    35 // ================= MEMBER FUNCTIONS =======================
       
    36 
       
    37 // ---------------------------------------------------------
       
    38 // CPosTp131::CloseTest
       
    39 //
       
    40 // (other items were commented in a header).
       
    41 // ---------------------------------------------------------
       
    42 //
       
    43 void CPosTp131::CloseTest()
       
    44     {
       
    45     iLog->Log(_L("CloseTest"));
       
    46     iSearchResults.ResetAndDestroy();
       
    47         
       
    48     //CHECK TR   Delete of landmarks search - ESLI-5WNG9N
       
    49     delete iDatabase;
       
    50     iDatabase = NULL;
       
    51     
       
    52     iLandmarkSearch->UnsetDisplayData();
       
    53     delete iDisplayData;
       
    54     iDisplayData = NULL;
       
    55 
       
    56     delete iLandmarkSearch;
       
    57     iLandmarkSearch = NULL;
       
    58     
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------
       
    62 // CPosTp131::StartL
       
    63 //
       
    64 // (other items were commented in a header).
       
    65 // ---------------------------------------------------------
       
    66 //
       
    67 void CPosTp131::StartL()
       
    68     {
       
    69     iErrorsFound = KErrNone;
       
    70     // copy test db to the private path
       
    71     _LIT(KTestPath, "c:\\system\\test\\testdata\\");
       
    72 
       
    73     CFileMan* fileMan = CFileMan::NewL(iFileSession);
       
    74     CleanupStack::PushL(fileMan);
       
    75 
       
    76     TBuf<150> srcPath;
       
    77 
       
    78     srcPath.Append(KTestPath);
       
    79     srcPath.Append(KTp131TestDb);
       
    80 
       
    81     TInt er = fileMan->Copy(srcPath, KLmTp131DefaultDbPath,
       
    82             CFileMan::EOverWrite);
       
    83     if (er != KErrNone)
       
    84         iLog->Log(_L("Error when copying file"));
       
    85 
       
    86     CleanupStack::PopAndDestroy(fileMan);
       
    87     
       
    88     CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL();
       
    89     CleanupStack::PushL(manager);
       
    90 
       
    91     // This db must exist
       
    92     manager->SetDefaultDatabaseUriL(KTp131TestDb);
       
    93     CleanupStack::PopAndDestroy(manager);
       
    94 
       
    95     iDatabase = CPosLandmarkDatabase::OpenL(KTp131TestDb);
       
    96     if (iDatabase->IsInitializingNeeded())
       
    97         {
       
    98         TRAPD( err, ExecuteAndDeleteLD( iDatabase->InitializeL() ) );
       
    99         AssertTrueSecL(err == KErrNone, _L("Init db failed"));
       
   100         }
       
   101 
       
   102     iLandmarkSearch = CPosLandmarkSearch::NewL(*iDatabase);
       
   103     AppendSearchResultsL();
       
   104 
       
   105     iLog->Log(_L("Testing search with a defined sortorder"));
       
   106     SearchWithSortOrderL(iSearchResults);
       
   107 
       
   108     // Test Partial landmarks
       
   109     iLog->Log(_L("Testing search with a defined sortorder for partial landmarks"));
       
   110 	SearchPartialLandmarksL(iSearchResults);
       
   111            
       
   112     iLog->Log(_L("Testing reset of DisplayData"));
       
   113     CheckResetL(iSearchResults);
       
   114 
       
   115     iLog->Log(_L("Testing cancel and displaydata"));
       
   116     CancelTestL(iSearchResults);
       
   117     
       
   118     // Test DisplayDataItem, create Landmark type
       
   119     TUint dbIndex = 0;
       
   120     CPosLandmark* lm = CPosLandmark::NewLC();
       
   121     lm->SetLandmarkNameL(_L("Tp131Landmarkname"));
       
   122     CPosLmDisplayItem* item = CPosLmDisplayItem::NewL(lm, dbIndex);
       
   123     CleanupStack::PushL(item);
       
   124     
       
   125     CPosLmDisplayItem::TDisplayItemType type = item->DisplayItemType();
       
   126     AssertTrueSecL(type == CPosLmDisplayItem::ELandmarkItem, _L("Wrong TDisplayItemType"));
       
   127     CleanupStack::PopAndDestroy(item);
       
   128     CleanupStack::Pop(lm); // lm deleted when deleting displaydata
       
   129         
       
   130     // Test DisplayDataItem, create Category type
       
   131     CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC();
       
   132     category->SetCategoryNameL(_L("Tp131CategoryName"));
       
   133     item = CPosLmDisplayItem::NewL(category, dbIndex);
       
   134     CleanupStack::PushL(item);
       
   135     type = item->DisplayItemType();
       
   136     
       
   137     AssertTrueSecL(type == CPosLmDisplayItem::ECategoryItem, _L("Wrong TDisplayItemType"));
       
   138     CleanupStack::PopAndDestroy(item);
       
   139     CleanupStack::Pop(category); // category deleted when deleting displaydata
       
   140     
       
   141     if (iErrorsFound != KErrNone) 
       
   142     	{
       
   143     	iLog->Log(_L("Errors were found in TP131"));
       
   144     	User::Leave(-1);
       
   145     	}
       
   146 
       
   147     }
       
   148     	
       
   149 // ---------------------------------------------------------
       
   150 // CPosTp131::ChechPartialLandmarkL
       
   151 //
       
   152 // (other items were commented in a header).
       
   153 // ---------------------------------------------------------
       
   154 //
       
   155 void CPosTp131::CheckPartialLandmarkL(const CPosLandmark& aLandmark, 
       
   156                                      const CPosLandmark::TAttributes& aAttr, const RArray<TUint>& aReqFields)
       
   157     {
       
   158     _LIT(KPartialIdErr, "Incorrect Id when reading from a Partial landmark");
       
   159     _LIT(KPartialCategoryInfoErr, "Incorrect Category info when reading from a Partial landmark");
       
   160 
       
   161     TPosLmItemId id = aLandmark.LandmarkId();
       
   162     AssertTrueSecL(id != 0, KPartialIdErr); 
       
   163     
       
   164     AssertTrueSecL(aLandmark.IsPartial(), _L("Landmark is not partial"));
       
   165     
       
   166     TInt err;
       
   167     TPtrC name;
       
   168     err = aLandmark.GetLandmarkName(name);
       
   169     // Name is always included
       
   170     CheckPartialErrorCodeL(aAttr & CPosLandmark::ELandmarkName, err); 
       
   171     
       
   172     TReal32 coverageR;     
       
   173     err = aLandmark.GetCoverageRadius(coverageR);
       
   174     CheckPartialErrorCodeL(aAttr & CPosLandmark::ECoverageRadius, err);
       
   175     
       
   176     TPtrC desc;
       
   177     err = aLandmark.GetLandmarkDescription(desc); 
       
   178     CheckPartialErrorCodeL(aAttr & CPosLandmark::EDescription, err);
       
   179     
       
   180     TPtrC iconName;
       
   181     TInt iconIndex;
       
   182     TInt iconMaskIndex;
       
   183     err = aLandmark.GetIcon(iconName, iconIndex, iconMaskIndex); 
       
   184     CheckPartialErrorCodeL(aAttr & CPosLandmark::EIcon, err);
       
   185     
       
   186     RArray<TPosLmItemId> categories;
       
   187     CleanupClosePushL(categories);
       
   188 
       
   189     aLandmark.GetCategoriesL(categories);
       
   190     if (aAttr & CPosLandmark::ECategoryInfo)
       
   191         {
       
   192         AssertTrueSecL(categories.Count() != 0, KPartialCategoryInfoErr);
       
   193         }
       
   194     else
       
   195         {
       
   196         AssertTrueSecL(categories.Count() == 0, KPartialCategoryInfoErr);
       
   197         }
       
   198     CleanupStack::PopAndDestroy(&categories);
       
   199 
       
   200     TLocality loc;
       
   201     err = aLandmark.GetPosition(loc); 
       
   202     CheckPartialErrorCodeL(aAttr & CPosLandmark::EPosition, err);
       
   203     
       
   204     // Check PositionFields    
       
   205     // Check fields from EPositionFieldCompassCapabilitiesBegin up to EPositionFieldMediaCapabilitiesBegin+100 
       
   206     // should be enough to also cover URL
       
   207     for (TInt i=EPositionFieldCompassCapabilitiesBegin; i<EPositionFieldMediaCapabilitiesBegin+100; i++) 
       
   208      	{
       
   209      	TBool avail = aLandmark.IsPositionFieldAvailable((TUint16)i);
       
   210      	TInt found = aReqFields.Find(i);
       
   211      	if (avail && found != KErrNotFound)
       
   212      		{
       
   213      		TPtrC value;
       
   214      		err = aLandmark.GetPositionField((TUint16)aReqFields[found], value);
       
   215      		AssertTrueSecL(err == KErrNone, _L("Could not retrieve positionfield value"), err);
       
   216      		iLog->Log(value);
       
   217      		}
       
   218      	else if (!avail && found != KErrNotFound || avail && found == KErrNotFound)
       
   219      		{
       
   220 			// Fields 405 and 802 are not always set     		
       
   221      		if (i!=405 && i!=802)
       
   222      			{
       
   223 		 		TBuf<100> buf;
       
   224 		 		buf.Format(_L("ERROR: Mismatch in positionfields, id %d were not found"), i);
       
   225 		 		iLog->Log(buf);
       
   226 		 		iErrorsFound++;
       
   227 		 		}
       
   228      		}
       
   229      	}
       
   230     }
       
   231 
       
   232 // ---------------------------------------------------------
       
   233 // CPosTp131::ChechPartialErrorCodeL
       
   234 //
       
   235 // (other items were commented in a header).
       
   236 // ---------------------------------------------------------
       
   237 //
       
   238 void CPosTp131::CheckPartialErrorCodeL(const TBool aPartial, const TInt aErr)
       
   239     {
       
   240     _LIT(KPartialLmErr, "Incorrect error code returned when reading from a Partial landmark");
       
   241 
       
   242     if (aPartial)
       
   243         {
       
   244         AssertTrueSecL(aErr == KErrNone, KPartialLmErr); 
       
   245         }
       
   246     else
       
   247         {
       
   248         AssertTrueSecL(aErr == KErrNotFound, KPartialLmErr);
       
   249         }
       
   250     }
       
   251 
       
   252 // ---------------------------------------------------------
       
   253 // CPosTp131::SearchPartialLandmarksL
       
   254 //
       
   255 // (other items were commented in a header).
       
   256 // ---------------------------------------------------------
       
   257 //
       
   258 void CPosTp131::SearchPartialLandmarksL(const RPointerArray<CSearchResult>& aSearchResults)
       
   259     {
       
   260     _LIT(KNumOfMatchesErr, "No. of matches is incorrect");
       
   261     _LIT(KNumOfMatchesErr2, "No. of display data matches is incorrect");
       
   262     _LIT(KSortorderErr, "The sortorder is incorrect");
       
   263    
       
   264     TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);  
       
   265     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   266     
       
   267     // Set DisplayData
       
   268 	iDisplayData = CPosLmDisplayData::NewL();
       
   269     iLandmarkSearch->SetDisplayData(*iDisplayData);
       
   270         
       
   271 	// Only do search for index KWhatToSearchFor in lmDbSearchResult.txt
       
   272 	// index 11 is MLFW
       
   273 	TInt KWhatToSearchFor = 11;
       
   274     textCriteria->SetTextL(aSearchResults[KWhatToSearchFor]->TextCriteria());
       
   275     textCriteria->SetAttributesToSearch(aSearchResults[KWhatToSearchFor]->Attributes());
       
   276     textCriteria->SetPositionFieldsToSearchL(aSearchResults[KWhatToSearchFor]->PositionFields()); 
       
   277 
       
   278     RArray<TUint> reqFields;
       
   279     CleanupClosePushL(reqFields);
       
   280     
       
   281     iLog->Log(aSearchResults[KWhatToSearchFor]->TextCriteria());
       
   282     CPosLmPartialReadParameters* partialParam = CPosLmPartialReadParameters::NewLC();
       
   283     
       
   284     CPosLmPartialReadParameters* fakePartialParam = CPosLmPartialReadParameters::NewLC();
       
   285     reqFields.Append(EPositionFieldStreet);
       
   286     fakePartialParam->SetRequestedPositionFields(reqFields);
       
   287     reqFields.Reset();
       
   288 
       
   289 	// Dont search for all search criteras 
       
   290 	// takes just too long time on target (approx 1 hour for this test on target)
       
   291 	        	
       
   292 	// Search for all combinations from 0 - CPosLandmark::EDescription
       
   293 	// Ex attr=0, attr=1, attr=2, attr=3, .....attr=63,
       
   294 #ifdef __WINS__	
       
   295     TUint max = CPosLandmark::EDescription;
       
   296     max <<= 1;
       
   297     max -= 1;
       
   298 #else
       
   299     TUint max = CPosLandmark::ECategoryInfo;
       
   300     max <<= 1;
       
   301     max -= 1;
       
   302 #endif
       
   303     
       
   304     TUint attr=0;
       
   305     for (attr=0; attr<=max; attr++)
       
   306         {
       
   307         partialParam->SetRequestedAttributes(attr);
       
   308         reqFields.Reset();
       
   309         
       
   310         if (attr == 5)
       
   311         	{
       
   312         	// Add EPositionFieldCountry
       
   313         	iLog->Log(_L("Also cover EPositionFieldCountry"));
       
   314         	reqFields.Append(EPositionFieldCountry);
       
   315         	}
       
   316         else if (attr == 12)
       
   317         	{
       
   318         	// Add EPositionFieldCity, EPositionFieldStreet, EPositionFieldCountry
       
   319         	iLog->Log(_L("Also cover EPositionFieldCity, EPositionFieldStreet, EPositionFieldCountry"));
       
   320         	reqFields.Append(EPositionFieldCity);
       
   321         	reqFields.Append(EPositionFieldStreet);
       
   322         	reqFields.Append(EPositionFieldCountry);
       
   323         	
       
   324         	}
       
   325         else if (attr == 32)
       
   326         	{
       
   327         	// Add EPositionFieldMediaLinksStart, EPositionFieldDistrict
       
   328         	iLog->Log(_L("Also cover EPositionFieldMediaLinksStart, EPositionFieldDistrict"));
       
   329         	reqFields.Append(EPositionFieldMediaLinksStart);
       
   330         	reqFields.Append(EPositionFieldDistrict);
       
   331         	}
       
   332         	
       
   333 		iDisplayData->UnsetPartialReadParameters();
       
   334         partialParam->SetRequestedPositionFields(reqFields);
       
   335     	iDisplayData->SetPartialReadParametersL(*partialParam);
       
   336     	
       
   337         for (TInt i=0; i<2; i++)
       
   338             {
       
   339             switch (i)
       
   340                 {
       
   341                 case 0:
       
   342                 	{
       
   343                 	//**** async
       
   344                 	//iLog->Log(_L("*****Async, EDescending"));
       
   345                 	sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending);
       
   346                     iAscendedSorted = EFalse;
       
   347                     iOperation = iLandmarkSearch->StartLandmarkSearchL(*textCriteria, sortPref, aSearchResults[KWhatToSearchFor]->Redefined());
       
   348                     // Test that if SetPartialReadParametersL is called after search has started it has no affect
       
   349                     iDisplayData->SetPartialReadParametersL(*fakePartialParam);
       
   350                     ExecuteLmOpL();
       
   351                     }
       
   352                     break;
       
   353                 case 1:
       
   354                 	{
       
   355                 	partialParam->SetRequestedPositionFields(reqFields);
       
   356     				iDisplayData->SetPartialReadParametersL(*partialParam);
       
   357     	
       
   358                     sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   359                     //iLog->Log(_L("*****Async EAscending"));
       
   360                     iAscendedSorted = ETrue;
       
   361                     iOperation = iLandmarkSearch->StartLandmarkSearchL(*textCriteria, sortPref, aSearchResults[KWhatToSearchFor]->Redefined());
       
   362                     ExecuteLmOpL();
       
   363                     }
       
   364                     break;
       
   365                 }
       
   366             
       
   367             CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   368             CleanupStack::PushL(iter);
       
   369             
       
   370             RArray<TPosLmItemId>* searchResults = &aSearchResults[KWhatToSearchFor]->SearchResult();
       
   371             if ((TUint)searchResults->Count() != iLandmarkSearch->NumOfMatches())
       
   372                 {
       
   373                 TBuf<50> buf;
       
   374                 buf.Append(_L("KNumOfMatchesError when searching for "));
       
   375                 buf.Append(aSearchResults[KWhatToSearchFor]->TextCriteria());
       
   376                 iLog->Log(buf);
       
   377                
       
   378                iLog->Log(KNumOfMatchesErr);
       
   379                User::Leave(-1);
       
   380                
       
   381                 }
       
   382                 
       
   383             // Check correct displayData
       
   384             AssertTrueSecL(iter->NumOfItemsL() == iDisplayData->Count(), KNumOfMatchesErr2);
       
   385             LandmarksSortL(*searchResults, sortPref);
       
   386             
       
   387             TInt ii=0;
       
   388             TPosLmItemId id = iter->NextL();
       
   389                    
       
   390             for (TInt i=0;i<iDisplayData->Count();i++)
       
   391                 {
       
   392                 CPosLmDisplayItem& item = iDisplayData->DisplayItem(i);
       
   393                 TInt lmId = item.Landmark().LandmarkId();
       
   394 
       
   395                 CPosLandmark* target = iDatabase->ReadLandmarkLC((*searchResults)[ii]);
       
   396                 TPtrC sourceName, targetName;
       
   397                 item.Landmark().GetLandmarkName(sourceName);
       
   398                 target->GetLandmarkName(targetName);
       
   399                 
       
   400                 if (lmId != (*searchResults)[ii])
       
   401                     {
       
   402                     // If found multiple match -> "Mölndal" etc
       
   403                     //Check if same name then don't Leave
       
   404                     AssertTrueSecL(sourceName.CompareC(targetName) == 0,KSortorderErr, lmId);
       
   405                     }
       
   406                 else
       
   407                     {
       
   408                     //CompareLandmarksL(item.Landmark(), *target);
       
   409                     // Add some check of partial landmarks here
       
   410                     AssertTrueSecL(sourceName.CompareC(targetName) == 0,KSortorderErr, lmId);
       
   411                     
       
   412                     // Landmarkname is always included when sorting
       
   413                     CheckPartialLandmarkL(item.Landmark() , attr | CPosLandmark::ELandmarkName, reqFields);
       
   414                     }
       
   415 
       
   416                     CleanupStack::PopAndDestroy(target);
       
   417                 id = iter->NextL();
       
   418 
       
   419                 ++ii;
       
   420                 }
       
   421             CleanupStack::PopAndDestroy(iter);
       
   422             iDisplayData->Reset();
       
   423             } 
       
   424         } 
       
   425         
       
   426     iLandmarkSearch->UnsetDisplayData();
       
   427     CleanupStack::PopAndDestroy(fakePartialParam);
       
   428     CleanupStack::PopAndDestroy(partialParam);
       
   429     CleanupStack::PopAndDestroy(&reqFields);
       
   430     CleanupStack::PopAndDestroy(textCriteria);
       
   431     delete iDisplayData;
       
   432     iDisplayData = NULL;
       
   433     }
       
   434 
       
   435 // ---------------------------------------------------------
       
   436 // CPosTp131::SearchWithSortOrderL
       
   437 //
       
   438 // (other items were commented in a header).
       
   439 // ---------------------------------------------------------
       
   440 //
       
   441 void CPosTp131::SearchWithSortOrderL(const RPointerArray<CSearchResult>& aSearchResults)
       
   442     {
       
   443     _LIT(KNumOfMatchesErr, "No. of matches is incorrect");
       
   444     _LIT(KNumOfMatchesErr2, "No. of display data matches is incorrect");
       
   445     _LIT(KSortorderErr, "The sortorder is incorrect");
       
   446    
       
   447     TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);  
       
   448     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   449     
       
   450     // Set DisplayData
       
   451 	iDisplayData = CPosLmDisplayData::NewL();
       
   452     iLandmarkSearch->SetDisplayData(*iDisplayData);
       
   453 
       
   454 	CPosLmPartialReadParameters* partialParam = CPosLmPartialReadParameters::NewLC();
       
   455 	
       
   456 	RArray<TUint> reqFields;
       
   457     CleanupClosePushL(reqFields);
       
   458 
       
   459 	// Test that UnsetPartialReadParameters works	
       
   460 	reqFields.Append(EPositionFieldCountry);
       
   461 	partialParam->SetRequestedPositionFields(reqFields);
       
   462     iDisplayData->SetPartialReadParametersL(*partialParam);
       
   463     CleanupStack::PopAndDestroy(&reqFields);
       
   464     CleanupStack::PopAndDestroy(partialParam);
       
   465     iDisplayData->UnsetPartialReadParameters();
       
   466     
       
   467 	// Dont search for all search criteras (see excel file)
       
   468 	// takes just too long time on target (approx 1 hour for this test on target)
       
   469 	// therefore start at j=7
       
   470 #ifdef __WINS__	
       
   471     for(TInt j=2; j<aSearchResults.Count(); j++)
       
   472 #else
       
   473     for(TInt j=7; j<aSearchResults.Count(); j++)
       
   474 #endif
       
   475         {   
       
   476         textCriteria->SetTextL(aSearchResults[j]->TextCriteria());
       
   477         textCriteria->SetAttributesToSearch(aSearchResults[j]->Attributes());
       
   478         textCriteria->SetPositionFieldsToSearchL(aSearchResults[j]->PositionFields()); 
       
   479 
       
   480         iLog->Log(aSearchResults[j]->TextCriteria());
       
   481         
       
   482         // Dont test sync search
       
   483         for (TInt i=2; i<6; i++)
       
   484             {
       
   485             switch (i)
       
   486                 {
       
   487                 //**** sync
       
   488                 case 0:
       
   489                 	{
       
   490                 	sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   491                     ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL(
       
   492                         *textCriteria, 
       
   493                         sortPref, 
       
   494                         aSearchResults[j]->Redefined()));
       
   495                     }
       
   496                     break;
       
   497                 case 1:
       
   498                 	{
       
   499                     sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending);
       
   500                     ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL(
       
   501                         *textCriteria, 
       
   502                         sortPref, 
       
   503                         aSearchResults[j]->Redefined()));
       
   504                     }
       
   505                     break;
       
   506                 case 2:
       
   507                 	{
       
   508                 	//**** async
       
   509                 	//iLog->Log(_L("*****Async, EDescending"));
       
   510                 	sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending);
       
   511                     iAscendedSorted = EFalse;
       
   512                     //iLog->Log(_L("Start"));
       
   513                     iOperation = iLandmarkSearch->StartLandmarkSearchL(*textCriteria, sortPref, aSearchResults[j]->Redefined());
       
   514                     ExecuteLmOpL();
       
   515                     //iLog->Log(_L("Done"));
       
   516                     }
       
   517                     break;
       
   518                 case 3:
       
   519                 	{
       
   520                     sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   521                     //iLog->Log(_L("*****Async EAscending"));
       
   522                     iAscendedSorted = ETrue;
       
   523                     iOperation = iLandmarkSearch->StartLandmarkSearchL(*textCriteria, sortPref, aSearchResults[j]->Redefined());
       
   524                     ExecuteLmOpL();
       
   525                     }
       
   526                     break;
       
   527                 //**** asych with User::WaitForRequest()
       
   528                 case 4:
       
   529                     {
       
   530                     //iLog->Log(_L("*****User::WaitForRequest() EDescending"));
       
   531                     sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending);
       
   532                     CPosLmOperation* op = iLandmarkSearch->StartLandmarkSearchL(
       
   533                         *textCriteria, 
       
   534                         sortPref, 
       
   535                         aSearchResults[j]->Redefined());
       
   536                     CleanupStack::PushL(op);
       
   537                     RunAsyncOperationByWaitForReqL(op);
       
   538                     CleanupStack::PopAndDestroy(op);
       
   539                     }
       
   540                     break;
       
   541                 case 5:
       
   542                     {
       
   543                     //iLog->Log(_L("*****User::WaitForRequest() EAscending"));
       
   544                     sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   545                     CPosLmOperation* op = iLandmarkSearch->StartLandmarkSearchL(
       
   546                         *textCriteria, 
       
   547                         sortPref, 
       
   548                         aSearchResults[j]->Redefined());
       
   549                     CleanupStack::PushL(op);
       
   550                     RunAsyncOperationByWaitForReqL(op);
       
   551                     CleanupStack::PopAndDestroy(op);
       
   552                     }
       
   553                     break;
       
   554                 }
       
   555             
       
   556         CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   557         CleanupStack::PushL(iter);
       
   558         
       
   559         RArray<TPosLmItemId>* searchResults = &aSearchResults[j]->SearchResult();
       
   560         if ((TUint)searchResults->Count() != iLandmarkSearch->NumOfMatches())
       
   561             {
       
   562             TBuf<50> buf;
       
   563             buf.Append(_L("KNumOfMatchesError when searching for "));
       
   564             buf.Append(aSearchResults[j]->TextCriteria());
       
   565             iLog->Log(buf);
       
   566             
       
   567             iLog->Log(KNumOfMatchesErr);
       
   568             User::Leave(-1);
       
   569             }
       
   570             
       
   571         // Check correct displayData
       
   572         AssertTrueSecL(iter->NumOfItemsL() == iDisplayData->Count(), KNumOfMatchesErr2);
       
   573         LandmarksSortL(*searchResults, sortPref);
       
   574         
       
   575         TInt ii=0;
       
   576         TPosLmItemId id = iter->NextL();
       
   577                
       
   578         for (TInt i=0;i<iDisplayData->Count();i++)
       
   579             {
       
   580             CPosLmDisplayItem& item = iDisplayData->DisplayItem(i);
       
   581             TInt lmId = item.Landmark().LandmarkId();
       
   582 
       
   583             CPosLandmark* target = iDatabase->ReadLandmarkLC((*searchResults)[ii]);
       
   584             TPtrC sourceName, targetName;
       
   585             item.Landmark().GetLandmarkName(sourceName);
       
   586             target->GetLandmarkName(targetName);
       
   587             
       
   588             if (lmId != (*searchResults)[ii])
       
   589                 {
       
   590                 // If found multiple match -> "Mölndal" etc
       
   591                 //Check if same name then don't Leave
       
   592                 AssertTrueSecL(sourceName.CompareC(targetName) == 0,KSortorderErr, lmId);
       
   593                 }
       
   594             else
       
   595                 {
       
   596                 CompareLandmarksL(item.Landmark(), *target);
       
   597                 }
       
   598 
       
   599             CleanupStack::PopAndDestroy(target);
       
   600             id = iter->NextL();
       
   601 
       
   602             ++ii;
       
   603             }
       
   604         CleanupStack::PopAndDestroy(iter);
       
   605         iDisplayData->Reset();
       
   606         }
       
   607         }
       
   608     iLandmarkSearch->UnsetDisplayData();
       
   609     CleanupStack::PopAndDestroy(textCriteria);
       
   610     delete iDisplayData;
       
   611     iDisplayData = NULL;
       
   612     }
       
   613 
       
   614 // ---------------------------------------------------------
       
   615 // CPosTp131::CheckResetL
       
   616 //
       
   617 // (other items were commented in a header).
       
   618 // ---------------------------------------------------------
       
   619 //
       
   620 void CPosTp131::CheckResetL(const RPointerArray<CSearchResult>& aSearchResults)
       
   621     {
       
   622     iLog->Log(_L("CheckResetL"));
       
   623     CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   624     
       
   625     // Set DisplayData
       
   626     CPosLmDisplayData* displayData = CPosLmDisplayData::NewL();
       
   627 	CleanupStack::PushL(displayData);
       
   628     iLandmarkSearch->SetDisplayData(*displayData);
       
   629         
       
   630     for(TInt j=0; j<aSearchResults.Count(); j++)
       
   631         {
       
   632 		textCriteria->SetTextL(aSearchResults[j]->TextCriteria());
       
   633 		textCriteria->SetAttributesToSearch(aSearchResults[j]->Attributes());
       
   634 		textCriteria->SetPositionFieldsToSearchL(aSearchResults[j]->PositionFields());
       
   635 
       
   636 		// Sync
       
   637 		ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL(*textCriteria, aSearchResults[j]->Redefined()));
       
   638 		AssertTrueSecL(iLandmarkSearch->NumOfMatches() == displayData->Count(),_L("Wrong number of matches1"),j);
       
   639 		displayData->Reset();
       
   640 		AssertTrueSecL(displayData->Count() == 0,_L("DisplayData should have been resetted"));
       
   641 		
       
   642 		// Async
       
   643 		RunAsyncOperationLD(iLandmarkSearch->StartLandmarkSearchL(*textCriteria, aSearchResults[j]->Redefined()));
       
   644 		AssertTrueSecL(iLandmarkSearch->NumOfMatches() == displayData->Count(),_L("Wrong number of matches2"),j);
       
   645     
       
   646     	RArray<TPosLmItemId>* searchResults = &aSearchResults[j]->SearchResult();
       
   647         //AssertTrueSecL(iLandmarkSearch->NumOfMatches() == searchResults->Count(),_L("Wrong number of matches3"),j);
       
   648         if (iLandmarkSearch->NumOfMatches() != searchResults->Count())
       
   649         	{
       
   650 	        TBuf<150> buf;
       
   651 	        buf.Format(_L("Exp %d nr of matches, got %d, searching for: "), searchResults->Count(), iLandmarkSearch->NumOfMatches());
       
   652 	        buf.Append(aSearchResults[j]->TextCriteria());
       
   653 	        iLog->Log(buf);
       
   654         	}
       
   655         
       
   656         AssertTrueSecL(displayData->Count() == iLandmarkSearch->NumOfMatches(),_L("DisplayData matches is not correct"));
       
   657         
       
   658     }
       
   659 
       
   660 	// Test unset of displaydata
       
   661 	iLandmarkSearch->UnsetDisplayData();
       
   662     CleanupStack::PopAndDestroy(displayData);
       
   663     
       
   664     displayData = CPosLmDisplayData::NewL();
       
   665 	CleanupStack::PushL(displayData);
       
   666     iLandmarkSearch->SetDisplayData(*displayData);
       
   667     iLandmarkSearch->UnsetDisplayData();
       
   668     
       
   669     textCriteria->SetTextL(aSearchResults[0]->TextCriteria());
       
   670 	textCriteria->SetAttributesToSearch(aSearchResults[0]->Attributes());
       
   671 	textCriteria->SetPositionFieldsToSearchL(aSearchResults[0]->PositionFields());
       
   672 	ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL(*textCriteria));
       
   673 	AssertTrueSecL(displayData->Count() == 0,_L("No matches should be found in DisplayData"));
       
   674         
       
   675     iLandmarkSearch->SetDisplayData(*displayData);
       
   676     
       
   677     textCriteria->SetTextL(aSearchResults[0]->TextCriteria());
       
   678 	textCriteria->SetAttributesToSearch(aSearchResults[0]->Attributes());
       
   679 	textCriteria->SetPositionFieldsToSearchL(aSearchResults[0]->PositionFields());
       
   680 	ExecuteAndDeleteLD(iLandmarkSearch->StartLandmarkSearchL(*textCriteria));
       
   681 	RArray<TPosLmItemId>* searchResults = &aSearchResults[0]->SearchResult();
       
   682    	AssertTrueSecL(iLandmarkSearch->NumOfMatches() == displayData->Count(),_L("Wrong number of matches4"));
       
   683     AssertTrueSecL(iLandmarkSearch->NumOfMatches() == searchResults->Count(),_L("Wrong number of matches5"));
       
   684     
       
   685     iLandmarkSearch->UnsetDisplayData();
       
   686     CleanupStack::PopAndDestroy(displayData);
       
   687 	CleanupStack::PopAndDestroy(textCriteria);
       
   688     }
       
   689 
       
   690 // ---------------------------------------------------------
       
   691 // CPosTp131::CancelTestL
       
   692 //
       
   693 // (other items were commented in a header).
       
   694 // ---------------------------------------------------------
       
   695 //
       
   696 void CPosTp131::CancelTestL(const RPointerArray<CSearchResult>& aSearchResults)
       
   697     {
       
   698     iLog->Log(_L("CancelTestL"));
       
   699 	CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC();
       
   700 	
       
   701 	// Cancel search operation and verify that the displayData result is sorted correctly
       
   702 	TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   703 	
       
   704     for (TInt pp=0;pp<2;pp++)
       
   705     	{
       
   706     	if (pp == 0) 
       
   707     		{
       
   708     		//iLog->Log(_L("Sorting Descending"));
       
   709     		sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending);
       
   710     		}
       
   711     	else {
       
   712     		sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   713     		//iLog->Log(_L("Sorting Ascending"));
       
   714     		}
       
   715     		
       
   716 	    // Set DisplayData
       
   717 	    iLandmarkSearch->UnsetDisplayData();
       
   718 	    delete iDisplayData;
       
   719 	    iDisplayData = NULL;
       
   720 	    CPosLmDisplayData* displayData = CPosLmDisplayData::NewL();
       
   721 		CleanupStack::PushL(displayData);
       
   722 	    iLandmarkSearch->SetDisplayData(*displayData);
       
   723 	        
       
   724 	    for(TInt j=0; j<aSearchResults.Count(); j++)
       
   725 	        {
       
   726 			textCriteria->SetTextL(aSearchResults[j]->TextCriteria());
       
   727 			textCriteria->SetAttributesToSearch(aSearchResults[j]->Attributes());
       
   728 			textCriteria->SetPositionFieldsToSearchL(aSearchResults[j]->PositionFields());
       
   729 
       
   730 			TBuf<150> buf;
       
   731 		    buf.Append(aSearchResults[j]->TextCriteria());
       
   732 		    //iLog->Log(buf);
       
   733 		        
       
   734 			// Cancel operation in callback
       
   735 			RunAsyncOperationAndCancelInCallbackLD(iLandmarkSearch->StartLandmarkSearchL(*textCriteria, sortPref, EFalse));
       
   736 			AssertTrueSecL(iLandmarkSearch->NumOfMatches() == displayData->Count(),_L("Wrong number of matches after cancel"),j);
       
   737 			
       
   738 			buf.Zero();
       
   739 			buf.Format(_L("Search returned %d nr of matches, displayData %d nr of matches"),iLandmarkSearch->NumOfMatches(), displayData->Count());
       
   740 			//iLog->Log(buf);
       
   741 			
       
   742 			// Check sort order below
       
   743 			CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   744 	        CleanupStack::PushL(iter);
       
   745 	        
       
   746 	        if (iter->NumOfItemsL()>0)
       
   747 	        	{
       
   748 	        	RArray<TPosLmItemId> arr;
       
   749 	        	CleanupClosePushL(arr);
       
   750 	        	iter->GetItemIdsL(arr, 0, iter->NumOfItemsL());
       
   751 	        
       
   752 	        	// Sort matchiterator
       
   753 	        	LandmarksSortL(arr, sortPref);
       
   754 			    
       
   755 			    TInt index=0;
       
   756 				TInt itemId = displayData->NewItemIndex();
       
   757 			    while (itemId != KPosLmNoNewItems)
       
   758 			        {
       
   759 			        CPosLmDisplayItem& item = displayData->DisplayItem(itemId);
       
   760 			        
       
   761 			        AssertTrueSecL(item.DisplayItemType() == CPosLmDisplayItem::ELandmarkItem, 
       
   762 			        	_L("Wrong item returned, only ELandmarkItem should be returned"));
       
   763 			        
       
   764 			        AssertTrueSecL(item.DatabaseIndex() == 0, _L("Wrong DatabaseIndex, should be 0"));
       
   765 			    	
       
   766 				    TInt lmId = item.Landmark().LandmarkId();
       
   767 				    
       
   768 				    
       
   769 	//		    	AssertTrueSecL(arr[index] == lmId , _L("Incorrect sortorder"));
       
   770 			    	CPosLandmark* lm = iDatabase->ReadLandmarkLC(arr[index]);
       
   771 			    	
       
   772 				    if ( arr[index] != lmId )
       
   773 				        {
       
   774 			    	TPtrC sourceName;
       
   775 				    item.Landmark().GetLandmarkName(sourceName);
       
   776 					TPtrC name2;
       
   777 					lm->GetLandmarkName(name2);
       
   778                         iLog->Log( _L("CancelTestL: #%02d, exp %d, act %d, '%S', '%S'"), 
       
   779                             index, arr[index], lmId, &name2, &sourceName );
       
   780 					
       
   781                         if ( sourceName.CompareC( name2 ) != 0 )
       
   782                             {
       
   783                             AssertTrueSecL( arr[index] == lmId, _L("Incorrect sort order") );
       
   784                             }
       
   785 				        }
       
   786 				    else
       
   787 				        {
       
   788 					CompareLandmarksL(*lm, item.Landmark());
       
   789 				        }
       
   790 					
       
   791 			        itemId = displayData->NewItemIndex();
       
   792 			        index++;
       
   793 			        CleanupStack::PopAndDestroy(lm);
       
   794 			        }
       
   795 			    CleanupStack::PopAndDestroy(&arr);       
       
   796 	        	}
       
   797 	        CleanupStack::PopAndDestroy(iter);
       
   798 			}
       
   799 			iLandmarkSearch->UnsetDisplayData();
       
   800 	    	CleanupStack::PopAndDestroy(displayData);
       
   801 	    }
       
   802 		CleanupStack::PopAndDestroy(textCriteria);
       
   803 	}
       
   804 
       
   805 // ---------------------------------------------------------
       
   806 // Tp131InternalLandmarksSortL
       
   807 // 
       
   808 // (other items were commented in a header).
       
   809 // ---------------------------------------------------------
       
   810 //	
       
   811 TInt Tp131InternalLandmarksSortL(const CPosLandmark& aSource, const CPosLandmark& aTarget)
       
   812     {
       
   813     TPtrC sourceName, targetName;
       
   814     
       
   815     User::LeaveIfError(aSource.GetLandmarkName(sourceName));  
       
   816     User::LeaveIfError(aTarget.GetLandmarkName(targetName));
       
   817     
       
   818     return sourceName.CompareC(targetName);
       
   819     }
       
   820     	
       
   821 // ---------------------------------------------------------
       
   822 // CPosTp131::LandmarksSortL
       
   823 // 
       
   824 // (other items were commented in a header).
       
   825 // ---------------------------------------------------------
       
   826 //
       
   827 void CPosTp131::LandmarksSortL(RArray<TPosLmItemId>& aArray, const TPosLmSortPref& aSortPref)
       
   828     {
       
   829     
       
   830     RPointerArray<CPosLandmark> landmarks;
       
   831     CleanupClosePushL(landmarks);
       
   832     
       
   833     for (TInt i=0; i<aArray.Count(); i++)
       
   834         {
       
   835         CPosLandmark* lm = iDatabase->ReadLandmarkLC(aArray[i]);
       
   836         landmarks.Append(lm);
       
   837         CleanupStack::Pop(lm);
       
   838         }
       
   839     
       
   840     TLinearOrder<CPosLandmark> order(Tp131InternalLandmarksSortL);
       
   841     landmarks.Sort(order);
       
   842   
       
   843     aArray.Reset();
       
   844 
       
   845     if (aSortPref.SortOrder() == TPosLmSortPref::EAscending)
       
   846         {
       
   847         for (TInt j=0; j<landmarks.Count(); j++)
       
   848             {
       
   849             aArray.Append(landmarks[j]->LandmarkId());
       
   850             }
       
   851         }
       
   852     else
       
   853         {
       
   854         for (TInt k=landmarks.Count()-1; k>=0; k--)
       
   855             {
       
   856             aArray.Append(landmarks[k]->LandmarkId());
       
   857             }
       
   858         }
       
   859     landmarks.ResetAndDestroy();
       
   860     CleanupStack::PopAndDestroy(&landmarks);
       
   861     
       
   862     }
       
   863 
       
   864 // ---------------------------------------------------------
       
   865 // CPosTp131::ExecuteLmOpL
       
   866 //
       
   867 // (other items were commented in a header).
       
   868 // ---------------------------------------------------------
       
   869 //
       
   870 void CPosTp131::ExecuteLmOpL()
       
   871     {
       
   872     CActiveLmOperation* operationWrapper = new (ELeave) CActiveLmOperation(iLog);
       
   873     CleanupStack::PushL(operationWrapper);
       
   874         
       
   875 	operationWrapper->Start(iOperation, this);        
       
   876     CActiveScheduler::Start();
       
   877     
       
   878     operationWrapper->CheckOperationL();
       
   879     operationWrapper->DeleteOperationD();
       
   880 
       
   881     CleanupStack::PopAndDestroy(operationWrapper);
       
   882     
       
   883     }
       
   884     
       
   885 // ---------------------------------------------------------
       
   886 // CPosTp131::NotifyProgress
       
   887 //
       
   888 // (other items were commented in a header).
       
   889 // ---------------------------------------------------------
       
   890 //
       
   891 void CPosTp131::NotifyProgress(TReal aProgress)
       
   892     {
       
   893 
       
   894     TBuf<100> buf;
       
   895 
       
   896     TInt progress = (TInt) (aProgress * 100);
       
   897     buf.Format(_L("Progress: %d"), progress);
       
   898     
       
   899     
       
   900     if (iDisplayData)
       
   901     	{
       
   902     
       
   903 		
       
   904 		if (iDisplayData->Count()>0)
       
   905 			{
       
   906 			CPosLmItemIterator* iter = iLandmarkSearch->MatchIteratorL();
       
   907         	CleanupStack::PushL(iter);
       
   908         	
       
   909         	RArray<TPosLmItemId> arr;
       
   910         	CleanupClosePushL(arr);
       
   911         	iter->GetItemIdsL(arr, 0, iter->NumOfItemsL());
       
   912         	TPosLmSortPref sortPref(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);  
       
   913         	
       
   914         	if (iAscendedSorted) sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EAscending);
       
   915         	else sortPref.SetSortByLandmarkAttribute(CPosLandmark::ELandmarkName, TPosLmSortPref::EDescending);
       
   916         	// Sort matchiterator
       
   917         	LandmarksSortL(arr, sortPref);
       
   918         	
       
   919         	if (iter->NumOfItemsL() != iDisplayData->Count())
       
   920 		    	{
       
   921 		    	iLog->Log(_L("Error: Wrong number of items"));
       
   922 		    	iErrorsFound++;
       
   923 		    	}		    
       
   924 
       
   925 			TInt itemId = iDisplayData->NewItemIndex();
       
   926 		    while (itemId != KPosLmNoNewItems)
       
   927 		        {
       
   928 		        CPosLmDisplayItem& item = iDisplayData->DisplayItem(itemId);
       
   929 		        
       
   930 		        if (item.DisplayItemType() != CPosLmDisplayItem::ELandmarkItem)
       
   931             	{
       
   932             	iLog->Log(_L("Error: TDisplayItemType should be ELandmarkItem"));
       
   933             	iErrorsFound++;
       
   934             	}
       
   935             
       
   936             if (item.DatabaseIndex() != 0)
       
   937             	{
       
   938             	// When single search, index should always be 0
       
   939             	iLog->Log(_L("Error: Wrong DatabaseIndex, should be 0"));
       
   940             	iErrorsFound++;
       
   941             	}
       
   942 
       
   943 				TPtrC lmName;
       
   944 				item.Landmark().GetLandmarkName(lmName);
       
   945 				TInt lmId = item.Landmark().LandmarkId();
       
   946 				
       
   947 				// Compare all landmarks from CPosLmDisplayItem and landmarks from MatchIteratorL
       
   948 		        for (TInt i=0;i<iDisplayData->Count();i++)
       
   949 			            {
       
   950 			            CPosLmDisplayItem& item = iDisplayData->DisplayItem(i);
       
   951 			            TPtrC sourceName;
       
   952 			            item.Landmark().GetLandmarkName(sourceName);
       
   953 						
       
   954 						
       
   955 						CPosLandmark* lm2 = iDatabase->ReadLandmarkLC(arr[i]);
       
   956 						TPtrC name;
       
   957 						lm2->GetLandmarkName(name);
       
   958 					
       
   959 						
       
   960 						// Only compare names
       
   961 						if (name.Compare(sourceName) != 0) 
       
   962 							{
       
   963 							iLog->Log(_L("ERROR: No match, name %S, sourceName %S"), &name, &sourceName);
       
   964 							iErrorsFound++;
       
   965 							}
       
   966 						
       
   967 						CleanupStack::PopAndDestroy(lm2);							
       
   968 						}
       
   969 				
       
   970 		        itemId = iDisplayData->NewItemIndex();		        
       
   971 		        }
       
   972 
       
   973 		    CleanupStack::PopAndDestroy(&arr);
       
   974         	CleanupStack::PopAndDestroy(iter);
       
   975         	}
       
   976         }
       
   977 	}
       
   978         
       
   979 //  End of File