landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp145.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 
       
    22 #include "FT_CPosTp145.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 // CPosTp145::StartL
       
    36 //
       
    37 // (other items were commented in a header).
       
    38 // ---------------------------------------------------------
       
    39 //
       
    40 void CPosTp145::StartL()
       
    41     {  
       
    42     
       
    43   		CheckLmCatSerializationL();
       
    44   		
       
    45 	}
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // CPosTp145::CompareBuffers
       
    49 //
       
    50 // ---------------------------------------------------------
       
    51 
       
    52  
       
    53  void CPosTp145::CompareBuffers(
       
    54     const TDesC8& aBuf1,
       
    55     const TDesC8& aBuf2)
       
    56     {
       
    57     DECLARE_ERROR_LOGGING
       
    58 
       
    59     CHECK_EQUAL(aBuf1.Length(), aBuf2.Length(), "Different buffer lengths");
       
    60     for (TInt i = 0; i < Min(aBuf1.Length(), aBuf2.Length()); i++)
       
    61         {
       
    62         TInt c1 = aBuf1[i], c2 = aBuf2[i];
       
    63         if (c1 != c2)
       
    64             {
       
    65             _LIT(KMessage, "Different at offset %d (actual = %d, expected %d)");
       
    66             message.Format(KMessage, i, c1, c2);
       
    67             ERR_DES(message);
       
    68             }
       
    69         }
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------
       
    73 // CPosTp145::CreateDummyCategoryLC
       
    74 //
       
    75 // ---------------------------------------------------------
       
    76  
       
    77 CPosLandmarkCategory* CPosTp145::CreateDummyCategoryLC()
       
    78     {
       
    79     CPosLandmarkCategory* cat = CPosLandmarkCategory::NewLC();
       
    80 
       
    81     TInt KCatId = cat->CategoryId();
       
    82     _LIT(KName, "Name");
       
    83     _LIT(KIcon, "IconFile");
       
    84     const TInt KIconIndex = 1, KIconMaskIndex = 2;
       
    85     cat->SetCategoryNameL(KName);
       
    86     cat->SetIconL(KIcon, KIconIndex, KIconMaskIndex);
       
    87     return cat;
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // CPosTp145::CompareCategoriesL
       
    92 //
       
    93 // ---------------------------------------------------------
       
    94 
       
    95 void CPosTp145::CompareCategoriesL(
       
    96     CPosLandmarkCategory& aCat1,
       
    97     CPosLandmarkCategory& aCat2)
       
    98     {
       
    99     DECLARE_ERROR_LOGGING;
       
   100 
       
   101     CHECK_EQUAL(aCat1.CategoryId(), aCat2.CategoryId(), "Diff id");
       
   102     CHECK_EQUAL(aCat1.GlobalCategory(), aCat2.GlobalCategory(), "Diff global category");
       
   103 
       
   104     TPtrC name1, name2;
       
   105     aCat1.GetCategoryName(name1);
       
   106     aCat2.GetCategoryName(name2);
       
   107     ERROR(name1 != name2, "Diff name");
       
   108 
       
   109     TInt iconIndex1 = 0, iconMaskIndex1 = 0;
       
   110     TInt iconIndex2 = 1, iconMaskIndex2 = 2;
       
   111 
       
   112     TInt found1 = aCat1.GetIcon(name1, iconIndex1, iconMaskIndex1);
       
   113     TInt found2 = aCat2.GetIcon(name2, iconIndex2, iconMaskIndex2);
       
   114 
       
   115     if (found1 == found2)
       
   116         {
       
   117         if (found1 != KErrNotFound)
       
   118             {
       
   119             ERROR(name1 != name2, "Diff icon name");
       
   120             CHECK_EQUAL(iconIndex1, iconIndex2, "Diff icon index");
       
   121             CHECK_EQUAL(iconMaskIndex1, iconMaskIndex2, "Diff icon mask index");
       
   122             }
       
   123         }
       
   124     else
       
   125         {
       
   126         ERR("Diff icon");
       
   127         }
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------
       
   131 // CPosTp145::CheckLmCatSerializationL
       
   132 //
       
   133 // ---------------------------------------------------------
       
   134 
       
   135 void CPosTp145::CheckLmCatSerializationL()
       
   136     {
       
   137     DECLARE_ERROR_LOGGING;
       
   138    
       
   139 
       
   140     LOG("1. Dummy category")
       
   141     CPosLandmarkCategory* cat = CreateDummyCategoryLC();
       
   142     CheckLmCatSerialization_SubL(cat);
       
   143     CleanupStack::PopAndDestroy(cat);
       
   144 
       
   145     LOG("2. Empty category")
       
   146     cat = CPosLandmarkCategory::NewLC();
       
   147     CheckLmCatSerialization_SubL(cat);
       
   148     CleanupStack::PopAndDestroy(cat);
       
   149 
       
   150     
       
   151     LEAVE_IF_ERRORS()
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------
       
   155 // CPosTp145::CheckLmCatSerialization_SubL
       
   156 //
       
   157 // ---------------------------------------------------------
       
   158 
       
   159 void CPosTp145::CheckLmCatSerialization_SubL(CPosLandmarkCategory* aTest)
       
   160     {
       
   161     DECLARE_ERROR_LOGGING;
       
   162 
       
   163     CPosLandmarkCategory* cat1 = aTest;
       
   164     CPosLandmarkCategory* cat2 = NULL;
       
   165 
       
   166     TInt err = KErrNone;
       
   167     HBufC8* buf1 = NULL;
       
   168     HBufC8* buf2 = NULL;
       
   169 
       
   170     TRAP(err, buf1 = PosLmCategorySerialization::PackL(*cat1));
       
   171     IF_ERROR(err, "Packing failed");
       
   172     User::LeaveIfError(err);
       
   173     CleanupStack::PushL(buf1);
       
   174 
       
   175     TRAP(err, cat2 = PosLmCategorySerialization::UnpackL(*buf1));
       
   176     IF_ERROR(err, "Unpacking failed");
       
   177     User::LeaveIfError(err);
       
   178     CleanupStack::PushL(cat2);
       
   179 
       
   180     CompareCategoriesL(*cat1, *cat2);
       
   181 
       
   182     // compare by buffer
       
   183     TRAP(err, buf2 = PosLmCategorySerialization::PackL(*cat2));
       
   184     CleanupStack::PushL(buf2);
       
   185 
       
   186     CompareBuffers(*buf1, *buf2);
       
   187 
       
   188     // cleanup
       
   189     CleanupStack::PopAndDestroy(buf2);
       
   190     CleanupStack::PopAndDestroy(cat2);
       
   191     CleanupStack::PopAndDestroy(buf1);
       
   192     }
       
   193     
       
   194 //  End of File