uiacceltk/hitchcock/CommonInc/alfmoduletestitem.h
branchRCL_3
changeset 7 88b23e2e82e1
equal deleted inserted replaced
6:10534483575f 7:88b23e2e82e1
       
     1 /**
       
     2  * @note This class is provided only if module test hooks are set on.
       
     3  */
       
     4 
       
     5 #include "alfmoduletestconf.h"
       
     6 #ifdef USE_MODULE_TEST_HOOKS_FOR_ALF
       
     7 
       
     8 #ifndef ALFMODULETESTITEM_H
       
     9 #define ALFMODULETESTITEM_H
       
    10 
       
    11 #include <e32def.h> 
       
    12 #include "alfmoduletesttype.h"
       
    13 
       
    14 
       
    15 /**
       
    16  * CAlfModuleTestItem
       
    17  * 
       
    18  * Provides key-value pair that is used in TAlfModuleTestMap.
       
    19  */
       
    20 template< class T >
       
    21 NONSHARABLE_CLASS( TAlfModuleTestItem )
       
    22     {
       
    23     
       
    24 public:
       
    25 
       
    26     /**
       
    27      * Default constructor
       
    28      * 
       
    29      * This is provided for copy operations that may required default constructor.
       
    30      * For normal cases, use another constructor instead to initialize the item
       
    31      * with correct values.
       
    32      */
       
    33     TAlfModuleTestItem():
       
    34         iTestType( EAlfModuleTestTypeNone ),    
       
    35         iKey( 0 ),
       
    36         iValueSetCount( 0 ),
       
    37         iLinkTargetKey( KErrNotFound )
       
    38         {    
       
    39         }
       
    40 
       
    41 
       
    42     /**
       
    43      * Constructor to initialize variables.
       
    44      * 
       
    45      * @param aTestType Defines for what this test item is meant for.
       
    46      * @param aKey Key that identifies the item.
       
    47      *             In test cases this could be for example handle.
       
    48      * @param aDefaultValue Default value for the map item.
       
    49      */
       
    50     TAlfModuleTestItem( const TAlfModuleTestType& aTestType, TInt aKey, const T& aDefaultValue ):
       
    51         iTestType( aTestType ),
       
    52         iKey( aKey ),
       
    53         iValue( aDefaultValue ),
       
    54         iValueSetCount( 0 ),
       
    55         iLinkTargetKey( KErrNotFound )
       
    56         {
       
    57         }
       
    58 
       
    59     
       
    60     /**
       
    61      * @note Be carefull when comparing items because some items may
       
    62      * be link items instead of original items.
       
    63      * 
       
    64      * @param aTestType Test type of accepted item.
       
    65      * @param aValue Item value to be compared.
       
    66      * @return ETrue if given object equals the value of this item.
       
    67      *         Else EFalse.
       
    68      */
       
    69     TBool Equals( const TAlfModuleTestType& aTestType, const T& aValue ) const
       
    70         {
       
    71         // Also, check that value has been set. If it has not been set,
       
    72         // then think objects as unequals.
       
    73         return ( iValueSetCount > 0 
       
    74                  && iValue == aValue 
       
    75                  && TestTypeMatch( aTestType ) );
       
    76         }
       
    77 
       
    78     
       
    79     /**
       
    80      * @return TInt Key that should be set during creation of this object.
       
    81      */
       
    82     TInt Key() const
       
    83         {
       
    84         return iKey;
       
    85         }
       
    86 
       
    87     
       
    88     /**
       
    89      * @see TAlfModuleTestItem::ValueSetCount to check if the value has already been set.
       
    90      * 
       
    91      * @return const T& Value that corresonds the key.
       
    92      */
       
    93     const T& Value() const
       
    94         {
       
    95         return iValue;
       
    96         }
       
    97     
       
    98     
       
    99     /**
       
   100      * @param aValue Value to be set for the key
       
   101      */
       
   102     void SetValue( const T& aValue )
       
   103         {
       
   104         iValue = aValue;
       
   105         ++iValueSetCount;
       
   106         }
       
   107 
       
   108     
       
   109     /**
       
   110      * @return TInt Informs how many times the value has been set. 
       
   111      */
       
   112     TInt ValueSetCount() const
       
   113         {
       
   114         return iValueSetCount;
       
   115         }
       
   116     
       
   117     
       
   118     /**
       
   119      * @return const TAlfModuleTestType& Defines what the test is for.
       
   120      */
       
   121     const TAlfModuleTestType& TestType() const
       
   122         {
       
   123         return iTestType;
       
   124         }
       
   125 
       
   126     
       
   127     /**
       
   128      * @param aTestType Type of the test this item is for.
       
   129      * @return TBool ETrue if flag matches this item. Else EFalse.
       
   130      */
       
   131     TBool TestTypeMatch( const TAlfModuleTestType& aTestType ) const
       
   132         {
       
   133         return ( EAlfModuleTestTypeAll == aTestType
       
   134                  || EAlfModuleTestTypeAll == iTestType
       
   135                  || iTestType == aTestType );
       
   136         }
       
   137 
       
   138     
       
   139     /**
       
   140      * @param aLinkTargetKey Key of the item that this item links to. 
       
   141      *                       KErrNotFound if this is not a link item.
       
   142      */
       
   143     void SetLinkTargetKey( TInt aLinkTargetKey )
       
   144         {
       
   145         iLinkTargetKey = aLinkTargetKey;
       
   146         }
       
   147 
       
   148     
       
   149     /**
       
   150      * @return TInt Key of the item that this item links to. 
       
   151      *              KErrNotFound if this is not a link item.
       
   152      */    
       
   153     TInt LinkTargetKey() const
       
   154         {
       
   155         return iLinkTargetKey;
       
   156         }
       
   157 
       
   158     
       
   159     /**
       
   160      * Resets this item to the given default value and 
       
   161      * sets value set count to zero.
       
   162      * 
       
   163      * @note Type, key and link target remain unchanged.
       
   164      * 
       
   165      * @param aDefaultValue Default value for the item.
       
   166      */
       
   167     void Reset( const T& aDefaultValue )
       
   168         {
       
   169         iValue = aDefaultValue;
       
   170         iValueSetCount = 0;
       
   171         }
       
   172 
       
   173     
       
   174 private: // data    
       
   175 
       
   176     TAlfModuleTestType iTestType;
       
   177     TInt iKey;
       
   178     T iValue;
       
   179     TInt iValueSetCount;
       
   180     TInt iLinkTargetKey;
       
   181     
       
   182     };
       
   183 
       
   184 #endif // ALFMODULETESTITEM_H
       
   185 
       
   186 #endif // USE_MODULE_TEST_HOOKS_FOR_ALF
       
   187 
       
   188 // End of File