landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp41.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 
       
    22 #include "FT_CPosTp41.h"
       
    23 #include <EPos_CPosLandmarkDatabase.h> 
       
    24 #include <EPos_CPosLMItemIterator.h> 
       
    25 #include <EPos_CPosLandmark.h>
       
    26 #include <EPos_TPosLMSortPref.h> 
       
    27 
       
    28 // CONSTANTS
       
    29 
       
    30 // ================= MEMBER FUNCTIONS =======================
       
    31 
       
    32 // ---------------------------------------------------------
       
    33 // CPosTp41::GetName
       
    34 //
       
    35 // (other items were commented in a header).
       
    36 // ---------------------------------------------------------
       
    37 //
       
    38 void CPosTp41::GetName(TDes& aName) const
       
    39     {
       
    40     _LIT(KTestName, "Tp41 - Empty Landmark Name and Descriptor");
       
    41     aName = KTestName;
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------
       
    45 // CPosTp41::StartL
       
    46 //
       
    47 // (other items were commented in a header).
       
    48 // ---------------------------------------------------------
       
    49 //
       
    50 void CPosTp41::StartL()
       
    51     {
       
    52     RemoveDefaultDbL();
       
    53     iDatabase = CPosLandmarkDatabase::OpenL();
       
    54     if (iDatabase->IsInitializingNeeded())
       
    55        {
       
    56        ExecuteAndDeleteLD(iDatabase->InitializeL()); 
       
    57        }
       
    58     ExecuteAndDeleteLD(iDatabase->CompactL()); 
       
    59 
       
    60     VerifyEmptyLandmarksL();
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------
       
    64 // CPosTp41::CloseTestL
       
    65 //
       
    66 // (other items were commented in a header).
       
    67 // ---------------------------------------------------------
       
    68 //
       
    69 void CPosTp41::CloseTest()
       
    70     {
       
    71     delete iDatabase;
       
    72     iDatabase = NULL;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------
       
    76 // CPosTp41::VerifyEmptyLandmarksL
       
    77 //
       
    78 // (other items were commented in a header).
       
    79 // ---------------------------------------------------------
       
    80 //
       
    81 void CPosTp41::VerifyEmptyLandmarksL()
       
    82     {
       
    83     _LIT(KLmName, "LmTp41 - %d");
       
    84     _LIT(KLmDescription, "LmTp41Description - %d");
       
    85 
       
    86     _LIT(KCompareNameErr, "Landmark names are not equal");
       
    87     _LIT(KCompareDescErr, "Landmark descriptions are not equal");
       
    88     
       
    89     _LIT(KNameErr, "GetLandmarkName returned wrong");
       
    90     _LIT(KDescErr, "GetLandmarkDescription returned wrong");
       
    91     
       
    92     // 1) Create landmark with name and descriptor
       
    93     TBuf<100> lmName;
       
    94     lmName.Format(KLmName,1);
       
    95     TBuf<100> lmDesc;
       
    96     lmDesc.Format(KLmDescription,1);
       
    97     CPosLandmark* landmark = CPosLandmark::NewLC();
       
    98     landmark->SetLandmarkNameL(lmName); 
       
    99     landmark->SetLandmarkDescriptionL(lmDesc);
       
   100     TPosLmItemId id = iDatabase->AddLandmarkL(*landmark);
       
   101     User::After(200000);
       
   102 
       
   103     // Read landmark from local landmark
       
   104     TPtrC sourceDesc;
       
   105     TPtrC sourceName;
       
   106     TInt sourceErr = landmark->GetLandmarkName(sourceName);
       
   107     AssertTrueSecL(sourceErr == KErrNone, KNameErr);
       
   108     sourceErr = landmark->GetLandmarkDescription(sourceDesc);
       
   109     AssertTrueSecL(sourceErr == KErrNone, KDescErr);
       
   110 
       
   111     AssertTrueSecL(sourceName.Compare(lmName) == KErrNone, KCompareNameErr);
       
   112     AssertTrueSecL(sourceDesc.Compare(lmDesc) == KErrNone, KCompareDescErr);
       
   113 
       
   114     CleanupStack::PopAndDestroy(landmark);
       
   115     // Read landmark from landmark db
       
   116     CheckLandmarkL(id, lmName, lmDesc);
       
   117     lmName.Zero();
       
   118     lmDesc.Zero();
       
   119 
       
   120     // 2) Create landmark with name and and empty descriptor
       
   121     lmName.Format(KLmName,2);
       
   122     lmDesc.Append(_L(""));
       
   123     landmark = CPosLandmark::NewLC();
       
   124     landmark->SetLandmarkNameL(lmName); 
       
   125     landmark->SetLandmarkDescriptionL(lmDesc); 
       
   126     id = iDatabase->AddLandmarkL(*landmark);
       
   127     User::After(200000);
       
   128 
       
   129     // Read landmark from local landmark
       
   130     sourceErr = landmark->GetLandmarkName(sourceName);   
       
   131     AssertTrueSecL(sourceErr == KErrNone, KNameErr);
       
   132     sourceErr = landmark->GetLandmarkDescription(sourceDesc);
       
   133     AssertTrueSecL(sourceErr == KErrNone, KDescErr);
       
   134 
       
   135     AssertTrueSecL(sourceName.Compare(lmName) == KErrNone, KCompareNameErr);
       
   136     AssertTrueSecL(sourceDesc.Compare(lmDesc) == KErrNone, KCompareDescErr);
       
   137 
       
   138     CleanupStack::PopAndDestroy(landmark);
       
   139     // Read landmark from landmark db
       
   140     CheckLandmarkL(id, lmName, lmDesc);
       
   141     lmName.Zero();
       
   142     lmDesc.Zero();
       
   143 
       
   144     // 3) Create landmark with name and and no descriptor set
       
   145     lmName.Format(KLmName, 2);
       
   146     lmDesc.Append(_L(""));
       
   147     landmark = CPosLandmark::NewLC();
       
   148     landmark->SetLandmarkNameL(lmName); 
       
   149     id = iDatabase->AddLandmarkL(*landmark);
       
   150     User::After(200000);
       
   151 
       
   152     // Read landmark from local landmark, GetLandmarkDescription should return KErrNotFound since it is not set
       
   153     sourceErr = landmark->GetLandmarkName(sourceName);   
       
   154     AssertTrueSecL(sourceErr == KErrNone, KNameErr);
       
   155     sourceErr = landmark->GetLandmarkDescription(sourceDesc);
       
   156     AssertTrueSecL(sourceErr == KErrNotFound, KDescErr);
       
   157 
       
   158     AssertTrueSecL(sourceName.Compare(lmName) == KErrNone, KCompareNameErr);
       
   159 
       
   160     CleanupStack::PopAndDestroy(landmark);
       
   161     // Read landmark from landmark db
       
   162     CheckLandmarkL(id, lmName, lmDesc);
       
   163     lmName.Zero();
       
   164     lmDesc.Zero();
       
   165 
       
   166     // 4) Create landmark with empty name and no description set
       
   167     lmName.Append(_L(""));
       
   168     lmDesc.Append(_L(""));
       
   169     landmark = CPosLandmark::NewLC();
       
   170     landmark->SetLandmarkNameL(lmName); 
       
   171     id = iDatabase->AddLandmarkL(*landmark);
       
   172     User::After(200000);
       
   173 
       
   174     // Read landmark from local landmark, GetLandmarkDescription
       
   175     // should return KErrNotFound since it is not set
       
   176     sourceErr = landmark->GetLandmarkName(sourceName);   
       
   177     AssertTrueSecL(sourceErr == KErrNone, KNameErr);
       
   178     sourceErr = landmark->GetLandmarkDescription(sourceDesc);
       
   179     AssertTrueSecL(sourceErr == KErrNotFound, KDescErr);
       
   180 
       
   181     AssertTrueSecL(sourceName.Compare(lmName) == KErrNone, KCompareNameErr);
       
   182 
       
   183     CleanupStack::PopAndDestroy(landmark);
       
   184     // Read landmark from landmark db
       
   185     CheckLandmarkL(id, lmName, lmDesc);
       
   186     lmName.Zero();
       
   187     lmDesc.Zero();
       
   188 
       
   189     // 5) Create landmark with no name set but with description
       
   190     lmName.Append(_L(""));
       
   191     lmDesc.Format(KLmDescription,2);
       
   192     landmark = CPosLandmark::NewLC();
       
   193     landmark->SetLandmarkDescriptionL(lmDesc); 
       
   194     id = iDatabase->AddLandmarkL(*landmark);
       
   195     User::After(200000);
       
   196 
       
   197     // Read landmark from local landmark, GetLandmarkName
       
   198     // should return KErrNotFound since it is not set
       
   199     sourceErr = landmark->GetLandmarkName(sourceName);   
       
   200     AssertTrueSecL(sourceErr == KErrNotFound, KNameErr);
       
   201     sourceErr = landmark->GetLandmarkDescription(sourceDesc);
       
   202     AssertTrueSecL(sourceErr == KErrNone, KDescErr);
       
   203     AssertTrueSecL(sourceDesc.Compare(lmDesc) == KErrNone, KCompareDescErr);
       
   204 
       
   205     CleanupStack::PopAndDestroy(landmark);
       
   206     // Read landmark from landmark db
       
   207     CheckLandmarkL(id, lmName, lmDesc);
       
   208     lmName.Zero();
       
   209     lmDesc.Zero();
       
   210 
       
   211     // 6) Create empty landmark
       
   212     landmark = CPosLandmark::NewLC();
       
   213     id = iDatabase->AddLandmarkL(*landmark);
       
   214     User::After(200000);
       
   215     lmName.Append(_L(""));
       
   216     lmDesc.Append(_L(""));
       
   217 
       
   218     // Read landmark from local landmark, GetLandmarkName and GetLandmarkDescription
       
   219     // should return KErrNotFound since it is not set
       
   220     sourceErr = landmark->GetLandmarkName(sourceName);   
       
   221     AssertTrueSecL(sourceErr == KErrNotFound, KNameErr);
       
   222     sourceErr = landmark->GetLandmarkDescription(sourceDesc);
       
   223     AssertTrueSecL(sourceErr == KErrNotFound, KDescErr);
       
   224 
       
   225     CleanupStack::PopAndDestroy(landmark);
       
   226     // Read landmark from landmark db
       
   227     CheckLandmarkL(id, lmName, lmDesc);
       
   228     lmName.Zero();
       
   229     lmDesc.Zero();
       
   230     }
       
   231 
       
   232 // ---------------------------------------------------------
       
   233 // CPosTp41::InternalGet
       
   234 //
       
   235 // (other items were commented in a header).
       
   236 // ---------------------------------------------------------
       
   237 //
       
   238 void CPosTp41::CheckLandmarkL(TPosLmItemId aId, TDesC& aName, TDesC& aDesc)
       
   239     {
       
   240     iLog->Put(_L("CheckLandmarkL"));
       
   241     _LIT(KNameErr2, "lm->GetLandmarkName returned wrong");
       
   242     _LIT(KDescErr2, "lm->GetLandmarkDescription returned wrong");
       
   243 
       
   244     _LIT(KCompareNameErr, "Landmark names are not equal");
       
   245     _LIT(KCompareDescErr, "Landmark descriptions are not equal");
       
   246 
       
   247     TPtrC sourceDesc;
       
   248     TPtrC sourceName;
       
   249 
       
   250     CPosLandmark* lm = iDatabase->ReadLandmarkLC(aId);
       
   251     
       
   252     TInt sourceErr = lm->GetLandmarkName(sourceName);
       
   253     AssertTrueSecL(sourceErr == KErrNone, KNameErr2);
       
   254     
       
   255     AssertTrueSecL(sourceName.Compare(aName) == KErrNone, KCompareNameErr);
       
   256     sourceErr = lm->GetLandmarkDescription(sourceDesc);
       
   257     AssertTrueSecL(sourceErr == KErrNone, KDescErr2);
       
   258     AssertTrueSecL(sourceDesc.Compare(aDesc) == KErrNone, KCompareDescErr);
       
   259 
       
   260     CleanupStack::PopAndDestroy(lm);
       
   261     }
       
   262 
       
   263 //  End of File