landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp146.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_CPosTp146.h"
       
    23 #include <e32math.h>
       
    24 #include <LbsPosition.h>
       
    25 
       
    26 #include <EPos_CPosLandmark.h>
       
    27 #include <EPos_CPosLandmarkCategory.h>
       
    28 #include <EPos_PosLandmarkSerialization.h>
       
    29 #include <EPos_PosLmCategorySerialization.h>
       
    30            
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 
       
    34 // ---------------------------------------------------------
       
    35 // CPosTp146::StartL
       
    36 //
       
    37 // (other items were commented in a header).
       
    38 // ---------------------------------------------------------
       
    39 //
       
    40 void CPosTp146::StartL()
       
    41     {  
       
    42     
       
    43   		CheckLmCatSerializationInvalidL();
       
    44   		
       
    45 	}
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // CPosTp146::CreateDummyLandmarkLC
       
    49 //
       
    50 // ---------------------------------------------------------
       
    51 
       
    52 CPosLandmark* CPosTp146::CreateDummyLandmarkLC()
       
    53     {
       
    54     CPosLandmark* lm = CPosLandmark::NewLC();
       
    55 
       
    56     _LIT(KName, "Name");
       
    57     _LIT(KDesc, "Description");
       
    58     _LIT(KIcon, "IconFile");
       
    59     const TInt KIconIndex = 1, KIconMaskIndex = 2;
       
    60 
       
    61     const TPosLmItemId KCat[] = { 3, 4, 5 };
       
    62     const TInt KCats = sizeof KCat / sizeof(TPosLmItemId);
       
    63 
       
    64     _LIT(KField1Val, "field1");
       
    65     _LIT(KField2Val, "field11");
       
    66     const TPositionFieldId KField[] =
       
    67         {
       
    68         EPositionFieldComment,
       
    69         EPositionFieldCountry
       
    70         };
       
    71     const TInt KFields = sizeof KField / sizeof(TPositionFieldId);
       
    72     const TPtrC KFieldData[] =
       
    73         {
       
    74         KField1Val(), KField2Val()
       
    75         };
       
    76 
       
    77     const TReal32 KRadius = 0.12;
       
    78     const TReal32 KHacc = 0.23, KVacc = 0.34;
       
    79     const TReal KLat = 12, KLon = -23, KAlt = 34;
       
    80 
       
    81     lm->SetLandmarkNameL(KName);
       
    82     lm->SetLandmarkDescriptionL(KDesc);
       
    83     lm->SetIconL(KIcon, KIconIndex, KIconMaskIndex);
       
    84 
       
    85     const TLocality KLoc(TCoordinate(KLat,KLon,KAlt), KHacc, KVacc);
       
    86     lm->SetPositionL(KLoc);
       
    87     lm->SetCoverageRadius(KRadius);
       
    88 
       
    89     for (TInt c = 0; c < KCats; c++)
       
    90         {
       
    91         lm->AddCategoryL(KCat[c]);
       
    92         }
       
    93 
       
    94     for (TInt f = 0; f < KFields; f++)
       
    95         {
       
    96         lm->SetPositionFieldL(KField[f], KFieldData[f]);
       
    97         }
       
    98 
       
    99     return lm;
       
   100     }
       
   101  
       
   102 // ---------------------------------------------------------
       
   103 // CPosTp146::CreateDummyCategoryLC
       
   104 //
       
   105 // ---------------------------------------------------------
       
   106  
       
   107  
       
   108 CPosLandmarkCategory* CPosTp146::CreateDummyCategoryLC()
       
   109     {
       
   110     CPosLandmarkCategory* cat = CPosLandmarkCategory::NewLC();
       
   111 
       
   112     TInt KCatId = cat->CategoryId();
       
   113     _LIT(KName, "Name");
       
   114     _LIT(KIcon, "IconFile");
       
   115     const TInt KIconIndex = 1, KIconMaskIndex = 2;
       
   116     cat->SetCategoryNameL(KName);
       
   117     cat->SetIconL(KIcon, KIconIndex, KIconMaskIndex);
       
   118     return cat;
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------
       
   122 // CPosTp146::CheckLmCatSerializationInvalidL
       
   123 //
       
   124 // ---------------------------------------------------------
       
   125 
       
   126 void CPosTp146::CheckLmCatSerializationInvalidL()
       
   127     {
       
   128     DECLARE_ERROR_LOGGING
       
   129     
       
   130 
       
   131     TInt err = KErrNone;
       
   132     HBufC8* buf1 = NULL;
       
   133     HBufC8* buf2 = NULL;
       
   134 
       
   135     CPosLandmark* lm = CreateDummyLandmarkLC();
       
   136     TRAP(err, buf1 = PosLandmarkSerialization::PackL(*lm));
       
   137     CleanupStack::PopAndDestroy(lm);
       
   138     lm = NULL;
       
   139 
       
   140     IF_ERROR(err, "Packing failed");
       
   141     User::LeaveIfError(err);
       
   142     CleanupStack::PushL(buf1);
       
   143 
       
   144     CPosLandmarkCategory* cat = CreateDummyCategoryLC();
       
   145     TRAP(err, buf2 = PosLmCategorySerialization::PackL(*cat));
       
   146     CleanupStack::PopAndDestroy(cat);
       
   147     cat = NULL;
       
   148 
       
   149     IF_ERROR(err, "Packing failed");
       
   150     User::LeaveIfError(err);
       
   151     CleanupStack::PushL(buf2);
       
   152 
       
   153     TRAP(err, cat = PosLmCategorySerialization::UnpackL(*buf1));
       
   154     delete cat;
       
   155 
       
   156     ERROR(err == KErrNone, "Wrong error (lm->cat)");
       
   157 
       
   158     TRAP(err, lm = PosLandmarkSerialization::UnpackL(*buf2));
       
   159     delete lm;
       
   160 
       
   161     ERROR(err == KErrNone, "Wrong error (cat->lm)");
       
   162 
       
   163     CleanupStack::PopAndDestroy(buf2);
       
   164     CleanupStack::PopAndDestroy(buf1);
       
   165 
       
   166     
       
   167     LEAVE_IF_ERRORS()
       
   168     }
       
   169 
       
   170  
       
   171     
       
   172 //  End of File