landmarks/locationlandmarks/tsrc/LandmarkTestModule/src/FT_CPosTp6.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_CPosTp6.h"
       
    23 
       
    24 #include <EPos_CPosLandmarkDatabase.h> 
       
    25 #include <EPos_CPosLandmarkCategory.h> 
       
    26 #include <EPos_CPosLMCategoryManager.h>
       
    27 
       
    28 #include "FT_LandmarkConstants.h"
       
    29 
       
    30 // CONSTANTS
       
    31 // _LIT(KGetCategoryNameErr, "GetCategoryName returns incorrect error code");
       
    32 _LIT(KCategoryNameErr, "Category name is incorrect");
       
    33 _LIT(KCategoryIdErr, "Category Id is incorrect");
       
    34 _LIT(KGlobalCategoryIdErr, "Global Category Id is incorrect");
       
    35 _LIT(KCategoryIconIndexErr, "Category Icon index is incorrect");
       
    36 _LIT(KCategoryIconMaskIndexErr, "Category Icon Mask Index is incorrect");
       
    37 _LIT(KCategoryMbmFileNameErr, "Category MbmFileName is incorrect");
       
    38 _LIT(KAddCategoryErr, "AddCategory should return an error");
       
    39 
       
    40 
       
    41 // ================= MEMBER FUNCTIONS =======================
       
    42 
       
    43 
       
    44 // ---------------------------------------------------------
       
    45 // CPosTp6::StartL
       
    46 //
       
    47 // (other items were commented in a header).
       
    48 // ---------------------------------------------------------
       
    49 //
       
    50 void CPosTp6::StartL()
       
    51     {
       
    52     iLog->Log(_L("In the StartL of FT_CPosTp6.h"));
       
    53     RemoveDefaultDbL();
       
    54     
       
    55     CPosLandmarkCategory* category = CreateCategoryLC(KCategoryName);
       
    56     CPosLandmarkCategory* copy = CPosLandmarkCategory::NewLC(*category);
       
    57 
       
    58     CheckGetMethodsL(category, KCategoryName);
       
    59     
       
    60     copy->SetCategoryNameL(KCategoryName2);
       
    61     CheckGetMethodsL(copy, KCategoryName2);
       
    62 
       
    63     CheckRemoveMethodsL(category);
       
    64     CheckRemoveMethodsL(copy);
       
    65     
       
    66     CPosLandmarkDatabase* lmd = OpenDatabaseLC();
       
    67     ExecuteAndDeleteLD(lmd->CompactL());
       
    68     CPosLmCategoryManager* cm = CPosLmCategoryManager::NewL(*lmd); 
       
    69     CleanupStack::PushL(cm); 
       
    70     User::After(1000000);
       
    71     TRAPD(err, cm->AddCategoryL(*copy));
       
    72     AssertTrueSecL(err == KErrArgument, KAddCategoryErr);
       
    73     
       
    74     CheckFieldsMaxLengthL();
       
    75     
       
    76     CheckEmptyCategoryNameL();
       
    77     
       
    78     CheckSetIconL();
       
    79 
       
    80     CleanupStack::PopAndDestroy(4); // category, copy, lmd, cm
       
    81 	}
       
    82 
       
    83 // ---------------------------------------------------------
       
    84 // CPosTp6::CheckGetmethods
       
    85 //
       
    86 // (other items were commented in a header).
       
    87 // ---------------------------------------------------------
       
    88 //
       
    89 void CPosTp6::CheckGetMethodsL(CPosLandmarkCategory* aCategory, const TDesC& aName)
       
    90     {
       
    91     TPtrC categoryName;
       
    92    
       
    93     aCategory->GetCategoryName(categoryName);  
       
    94    
       
    95     AssertTrueSecL(categoryName.Compare(aName) == KErrNone, KCategoryNameErr);
       
    96     AssertTrueSecL(aCategory->CategoryId() == 0, KCategoryIdErr);
       
    97     AssertTrueSecL(aCategory->GlobalCategory() == 0, KGlobalCategoryIdErr);
       
    98     
       
    99     TPtrC mbmFileName;
       
   100     TInt index;
       
   101     TInt indexMask;
       
   102     aCategory->GetIcon(mbmFileName, index, indexMask);
       
   103     AssertTrueSecL(mbmFileName.Compare(KMbmFileName) == KErrNone, KCategoryMbmFileNameErr);
       
   104     AssertTrueSecL(index == KIconIndex, KCategoryIconIndexErr);
       
   105     AssertTrueSecL(indexMask == KIconMaskIndex, KCategoryIconMaskIndexErr);    
       
   106 
       
   107     CPosLandmarkDatabase* lmd = OpenDatabaseLC();
       
   108     CPosLmCategoryManager* cm = CPosLmCategoryManager::NewL(*lmd); 
       
   109     CleanupStack::PushL(cm);
       
   110     
       
   111     TPosLmItemId id1 = cm->AddCategoryL(*aCategory);
       
   112     User::After(1000000);
       
   113     TRAPD(err, cm->AddCategoryL(*aCategory));
       
   114     AssertTrueSecL(err == KErrAlreadyExists, KAddCategoryErr);
       
   115     AssertTrueSecL(id1 == aCategory->CategoryId(), KCategoryIdErr);
       
   116     
       
   117     CleanupStack::PopAndDestroy(2); // lmd, cm
       
   118 	}
       
   119 
       
   120 // ---------------------------------------------------------
       
   121 // CPosTp6::CheckRemoveMethodsL
       
   122 //
       
   123 // (other items were commented in a header).
       
   124 // ---------------------------------------------------------
       
   125 //    
       
   126 void CPosTp6::CheckRemoveMethodsL(CPosLandmarkCategory* aCategory)
       
   127     {
       
   128     aCategory->RemoveCategoryAttributes(CPosLandmarkCategory::ENoAttribute);
       
   129     aCategory->RemoveCategoryAttributes(CPosLandmarkCategory::ECategoryName);
       
   130     aCategory->RemoveCategoryAttributes(CPosLandmarkCategory::EIcon);
       
   131     
       
   132     CheckRemovedL(aCategory);
       
   133 
       
   134     CPosLandmarkCategory* category = CreateCategoryLC(KCategoryName);
       
   135     category->RemoveCategoryAttributes(CPosLandmarkCategory::EAllAttributes);
       
   136     CheckRemovedL(category);
       
   137     CleanupStack::PopAndDestroy(category);
       
   138 	
       
   139 	// Check with attributes outside defined interval
       
   140 	// since TAttributes is a TUint32 -1 is casted to EAllAttributes = 0xFFFF 
       
   141     category = CreateCategoryLC(_L("NewCategory"));
       
   142     category->RemoveCategoryAttributes((CPosLandmarkCategory::TAttributes)-1);
       
   143     
       
   144     TPtrC categoryName;
       
   145     if (category->GetCategoryName(categoryName) == KErrNotFound) iLog->Log(_L("Category Name has been removed"));
       
   146     TPtrC mbmFileName;
       
   147     TInt index;
       
   148     TInt indexMask;
       
   149     if (aCategory->GetIcon(mbmFileName, index, indexMask) == KErrNotFound) iLog->Log(_L("Catgory Icon has been removed"));
       
   150     
       
   151     CleanupStack::PopAndDestroy(category);
       
   152     
       
   153     // Check with attributes outside defined interval
       
   154     category = CreateCategoryLC(_L("NewCategory2"));
       
   155     category->RemoveCategoryAttributes(0);
       
   156     category->GetCategoryName(categoryName);
       
   157     AssertTrueSecL(categoryName.CompareC(_L("NewCategory2")) == KErrNone, _L("Wrong category name returned after remove invalid attribute"));
       
   158 	
       
   159     CleanupStack::PopAndDestroy(category);
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------
       
   163 // CPosTp6::CheckRemovedL
       
   164 //
       
   165 // (other items were commented in a header).
       
   166 // ---------------------------------------------------------
       
   167 //
       
   168 void CPosTp6::CheckRemovedL(CPosLandmarkCategory* aCategory)
       
   169     {
       
   170     TPtrC name;
       
   171     AssertTrueSecL(aCategory->GetCategoryName(name) == KErrNotFound, KCategoryNameErr);
       
   172 
       
   173     TPtrC mbmFileName;
       
   174     TInt index;
       
   175     TInt indexMask;
       
   176     AssertTrueSecL(aCategory->GetIcon(mbmFileName, index, indexMask) == KErrNotFound, KCategoryMbmFileNameErr);   
       
   177     
       
   178     }
       
   179     
       
   180 //---------------------------------------------------------
       
   181 // CPosTp6::CheckEmptyCategoryNameL
       
   182 //
       
   183 // (other items were commented in a header).
       
   184 // ---------------------------------------------------------
       
   185 //
       
   186 void CPosTp6::CheckEmptyCategoryNameL()
       
   187 	{
       
   188 	
       
   189 	iLog->Log(_L("CheckEmptyCategoryNameL"));
       
   190 	CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC();
       
   191 	
       
   192 	// Set empty string as category name
       
   193 	// should not be accepted
       
   194     TRAPD(err, category->SetCategoryNameL(_L("")));
       
   195     
       
   196     if (err != KErrArgument)
       
   197     {
       
   198     iLog->Log(_L("Empty category name should not be accepted"));
       
   199     User::Leave(err);	
       
   200     }
       
   201     
       
   202     
       
   203     CleanupStack::PopAndDestroy(category);
       
   204 	}
       
   205 
       
   206 //---------------------------------------------------------
       
   207 // CPosTp6::CheckSetIconL
       
   208 //
       
   209 // (other items were commented in a header).
       
   210 // ---------------------------------------------------------
       
   211 //
       
   212 void CPosTp6::CheckSetIconL()
       
   213 	{
       
   214 	iLog->Log(_L("CheckSetIconL"));
       
   215 	
       
   216 	_LIT(K124Error, "Icon name is not limited to 255 characters");
       
   217 
       
   218     
       
   219 	// Defined in KMaxFileName e32const.h
       
   220     HBufC* hbuf = HBufC::NewLC(KMaxFileName+1);
       
   221     while(hbuf->Des().Length() < KMaxFileName)
       
   222         {
       
   223         hbuf->Des().Append(_L("X"));
       
   224         }
       
   225         
       
   226     CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC();
       
   227     category->SetIconL(*hbuf, 0, KPosLmIconMaskNotUsed);
       
   228     
       
   229     hbuf->Des().Append(_L("X"));
       
   230 
       
   231     TRAPD(err, category->SetIconL(*hbuf, 0, KPosLmIconMaskNotUsed));
       
   232     AssertTrueSecL(err == KErrArgument, K124Error);
       
   233 
       
   234     CleanupStack::PopAndDestroy(2, hbuf);
       
   235 	}
       
   236 	
       
   237 //---------------------------------------------------------
       
   238 // CPosTp6::CheckFieldsMaxLength
       
   239 //
       
   240 // (other items were commented in a header).
       
   241 // ---------------------------------------------------------
       
   242 //
       
   243 void CPosTp6::CheckFieldsMaxLengthL()
       
   244     {
       
   245     _LIT(K124Error, "Category name is not limited to 255 characters");
       
   246 
       
   247     const TInt KMaxFileName = 124;
       
   248     HBufC* hbuf = HBufC::NewLC(KMaxFileName+1);
       
   249  
       
   250     while(hbuf->Des().Length() < KMaxFileName)
       
   251         {
       
   252         hbuf->Des().Append(_L("X"));
       
   253         }
       
   254 
       
   255     CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC();
       
   256     category->SetCategoryNameL(*hbuf);
       
   257     
       
   258     hbuf->Des().Append(_L("X"));
       
   259 
       
   260     TRAPD(err, category->SetCategoryNameL(*hbuf));
       
   261     AssertTrueSecL(err == KErrArgument, K124Error);
       
   262 
       
   263     CleanupStack::PopAndDestroy(2, hbuf);
       
   264     }
       
   265     
       
   266 //  End of File