uiacceltk/hitchcock/CommonInc/alfmoduletest.h
branchRCL_3
changeset 8 10534483575f
parent 7 433cbbb6a04b
child 10 88b23e2e82e1
--- a/uiacceltk/hitchcock/CommonInc/alfmoduletest.h	Fri Mar 12 15:47:04 2010 +0200
+++ b/uiacceltk/hitchcock/CommonInc/alfmoduletest.h	Mon Mar 15 12:43:37 2010 +0200
@@ -5,13 +5,16 @@
 #define ALFMODULETEST_H
 
 // Define this to build module testing enchanced version of ALF
-// #define USE_MODULE_TEST_HOOKS_FOR_ALF 
+//#define USE_MODULE_TEST_HOOKS_FOR_ALF 
 
 #if !defined(USE_MODULE_TEST_HOOKS_FOR_ALF) || !defined(AMT_CONTROL)
 
+#define AMT_DATA()
 #define AMT_FUNC(func)                                
-#define AMT_FUNC_EXC(func)    
-#define AMT_FUNC_EXC_IF(cond, func)    
+#define AMT_FUNC_EXC(func)
+#define AMT_FUNC_EXC_RET(ret, func)
+#define AMT_FUNC_EXC_IF(cond, func)
+#define AMT_FUNC_EXC_IF_RET(cond, ret, func)
 #define AMT_INC_COUNTER(member)
 #define AMT_DEC_COUNTER(member)
 #define AMT_SET_VALUE(member, val)
@@ -20,6 +23,16 @@
 #define AMT_DEC_COUNTER_IF(cond, member)
 #define AMT_SET_VALUE_IF(cond, member, val)
 #define AMT_GET_VALUE_IF(cond, x, member)
+
+#define AMT_MAP_APPEND(memberMap, key, type, defaultValue)          
+#define AMT_MAP_SET_VALUE_IF(cond, memberMap, key, value, type)     
+#define AMT_MAP_INC_VALUE_IF(cond, memberMap, key, type)            
+#define AMT_MAP_DEC_VALUE_IF(cond, memberMap, key, type)            
+#define AMT_MAP_SET_VALUE(memberMap, key, value, type)              
+#define AMT_MAP_INC_VALUE(memberMap, key, type)                              
+#define AMT_MAP_DEC_VALUE(memberMap, key, type)                     
+#define AMT_MAP_RESET(memberMap)                                    
+
 #define AMT_PRINT_STATE()
 
 #ifndef AMT_CONTROL
@@ -46,8 +59,10 @@
 // Generic macros
 #define AMT_DATA()                  AMT_CONTROL()->iModuleTestData
 #define AMT_FUNC(func)              if (AMT_DATA()->iIsEnabled) {func;}                                         
-#define AMT_FUNC_EXC(func)          {AMT_CONTROL()->Lock(); if (AMT_DATA()->iIsEnabled) {func;} AMT_CONTROL()->Unlock();}        
+#define AMT_FUNC_EXC(func)          {AMT_CONTROL()->Lock(); if (AMT_DATA()->iIsEnabled) {func;} AMT_CONTROL()->Unlock();}
+#define AMT_FUNC_EXC_RET(ret, func) {AMT_CONTROL()->Lock(); if (AMT_DATA()->iIsEnabled) {ret = func;} AMT_CONTROL()->Unlock();}
 #define AMT_FUNC_EXC_IF(cond, func) {AMT_CONTROL()->Lock(); if (AMT_DATA()->iIsEnabled && (cond)) {func;} AMT_CONTROL()->Unlock();}        
+#define AMT_FUNC_EXC_IF_RET(cond, ret, func) {AMT_CONTROL()->Lock(); if (AMT_DATA()->iIsEnabled && (cond)) {ret = func;} AMT_CONTROL()->Unlock();}
 
 // Single operation macros, that will do lock/unlock.
 #define AMT_INC_COUNTER(member)     AMT_FUNC_EXC(AMT_DATA()->member++)
@@ -62,11 +77,351 @@
 #define AMT_SET_VALUE_IF(cond, member, val) AMT_FUNC_EXC_IF((cond), AMT_DATA()->member=(val))
 #define AMT_GET_VALUE_IF(cond, x, member)   AMT_FUNC_EXC_IF((cond), (x) = AMT_DATA()->member)
 
+// Map operation macros, that will do lock/unlock
+#define AMT_MAP_APPEND(memberMap, key, type, defaultValue)          AMT_FUNC_EXC(AMT_DATA()->memberMap.Append(key, type, defaultValue))
+#define AMT_MAP_SET_VALUE_IF(cond, memberMap, key, value, type)     AMT_FUNC_EXC_IF((cond), AMT_DATA()->memberMap.SetValue(key, value, type))
+#define AMT_MAP_INC_VALUE_IF(cond, memberMap, key, type)            AMT_FUNC_EXC_IF((cond && AMT_DATA()->memberMap.Find(key, type)), AMT_DATA()->memberMap.SetValue(key, AMT_DATA()->memberMap.Find(key, type)->Value() + 1, type))
+#define AMT_MAP_DEC_VALUE_IF(cond, memberMap, key, type)            AMT_FUNC_EXC_IF((cond && AMT_DATA()->memberMap.Find(key, type)), AMT_DATA()->memberMap.SetValue(key, AMT_DATA()->memberMap.Find(key, type)->Value() - 1, type))
+#define AMT_MAP_SET_VALUE(memberMap, key, value, type)              AMT_FUNC_EXC_IF(ETrue, AMT_DATA()->memberMap.SetValue(key, value, type))
+#define AMT_MAP_INC_VALUE(memberMap, key, type)                     AMT_MAP_INC_VALUE_IF(ETrue, memberMap, key, type)              
+#define AMT_MAP_DEC_VALUE(memberMap, key, type)                     AMT_MAP_DEC_VALUE_IF(ETrue, memberMap, key, type)
+#define AMT_MAP_RESET(memberMap)                                    AMT_FUNC_EXC(AMT_DATA()->memberMap.Reset())
 
 // *** Global object names
 _LIT(KAlfModuleTestChunkName, "ALF_MODULE_TEST_CHUNK");
 _LIT(KAlfModuleTestMutexName, "ALF_MODULE_TEST_MUTEX");
 
+
+/**
+ * TAlfModuleTestType specifies recognized test types.
+ */
+enum TAlfModuleTestType
+    {
+    // Do not use this value when creating item.
+    EAlfModuleTestTypeNone,
+    
+    // Render stage component specific tests
+    EAlfModuleTestTypeRenderStageChangeSize,
+    EAlfModuleTestTypeRenderStageChangePosition,
+    EAlfModuleTestTypeRenderStageChangeFlag,
+    
+    // Streamer hierarchy model component specific tests
+    EAlfModuleTestTypeHierarchyModelChangeSize,
+    EAlfModuleTestTypeHierarchyModelChangePosition,
+    EAlfModuleTestTypeHierarchyModelChangeFlag,    
+    
+    // Server bridge component specific tests
+    EAlfModuleTestTypeBridgeChangeSize,
+    EAlfModuleTestTypeBridgeChangePosition,
+    EAlfModuleTestTypeBridgeChangeFlag,
+    
+    // Do not use this value when creating item.
+    // This is just meant for Find operations when all tests are accepted.
+    EAlfModuleTestTypeAll
+    };
+
+
+/**
+ * CAlfModuleTestItem
+ * 
+ * Provides key-value pair that is used in TAlfModuleTestMap.
+ */
+template< class T >
+NONSHARABLE_CLASS( TAlfModuleTestItem )
+    {
+    
+public:
+
+    /**
+     * Constructor to initialize variables.
+     * 
+     * @param aKey Key that identifies the item.
+     *             In test cases this could be for example handle.
+     * @param aTestType Defines for what this test item is meant for.
+     */
+    TAlfModuleTestItem( TInt aKey, const TAlfModuleTestType& aTestType, const T& aDefaultValue ):
+        iKey( aKey ),
+        iTestType( aTestType ),
+        iValue( aDefaultValue ),
+        iValueSetCount( 0 )
+        {
+        }
+
+    
+    /**
+     * @param aObject Value to be compared.
+     * @return ETrue if given object equals the value of this item.
+     *         Else EFalse.
+     */
+    TBool Equals( const T& aValue, const TAlfModuleTestType& aTestType ) const
+        {
+        // Also, check that value has been set. If it has not been set,
+        // then think objects as unequals.
+        return ( iValueSetCount > 0 
+                 && iValue == aValue 
+                 && TestTypeMatch( aTestType ) );
+        }
+
+    
+    /**
+     * @return TInt Key that should be set during creation of this object.
+     */
+    TInt Key() const
+        {
+        return iKey;
+        }
+
+    /**
+     * @see ValueSet to check if the value has already been set.
+     * 
+     * @return const T& Value that corresonds the key.
+     */
+    const T& Value() const
+        {
+        return iValue;
+        }
+    
+    
+    /**
+     * @param aValue Value to be set for the key
+     */
+    void SetValue( const T& aValue )
+        {
+        iValue = aValue;
+        ++iValueSetCount;
+        }
+
+    
+    /**
+     * @return TInt Informs how many times the value has been set. 
+     */
+    TInt ValueSetCount() const
+        {
+        return iValueSetCount;
+        }
+    
+    /**
+     * @return const TAlfModuleTestType& Defines what the test is for
+     */
+    const TAlfModuleTestType& TestType() const
+        {
+        return iTestType;
+        }
+
+    
+    /**
+     * @param aTestType
+     * @return TBool ETrue if flag matches this item. Else EFalse.
+     */
+    TBool TestTypeMatch( const TAlfModuleTestType& aTestType ) const
+        {
+        return ( EAlfModuleTestTypeAll == aTestType
+                 || iTestType == aTestType );
+        }
+
+    
+    /**
+     * Resets the item info
+     */
+    void Reset()
+        {
+        iValueSetCount = 0;
+        }
+
+    
+private: // data    
+    
+    TInt iKey;
+    TAlfModuleTestType iTestType;    
+    T iValue;
+    TInt iValueSetCount;
+    
+    };
+
+
+/**
+ * Class CAlfModuleTestMap
+ * 
+ * Provides map functionality for the key-value-pairs.
+ * In test cases, this should most likely be used so, that 
+ * first test case classes create items with certain keys, for example with handle values.
+ * Then, define hooks are used in the code to update values that corresond the correct handles.
+ * In the end, test case classes can check that items have correct values set and if the test
+ * is passed.
+ */
+template< class T >
+NONSHARABLE_CLASS( TAlfModuleTestMap )
+    {
+public:
+
+    // Maximum item count in the map
+    static const TInt KMaxArrayCount = 50;
+
+    
+    /**
+     * Constructor to initialize variables.
+     */
+    TAlfModuleTestMap():
+        iCount( 0 ),
+        iSetValueCallCount( 0 )
+        {            
+        }
+
+    
+    /**
+     * @param aKey
+     * @param aTestType Informs what type of test is accepted. Others are skipped.
+     * @return T* Ownership is not transferred.
+     *            NULL if item is not found.
+     */
+    TAlfModuleTestItem< T >* Find( TInt aKey, const TAlfModuleTestType& aTestType )
+        {
+        // Try to find the item corresponding the given key.
+        for ( TInt i = 0; i < iCount; ++i )
+            {
+            TAlfModuleTestItem< T >& testItem( iArray[ i ] );
+            if ( testItem.Key() == aKey
+                 && testItem.TestTypeMatch( aTestType ) )
+                {
+                return &( testItem );
+                }
+            }
+        // Item corresponding the given key was not found.
+        return NULL;
+        }    
+    
+    
+    /**
+     * Function to append new item into the map.
+     * 
+     * @param aKey
+     * @param aTestType Describes for what case the appended test item is created for.
+     * @return TInt System wide error code.
+     */    
+    TInt Append( TInt aKey, const TAlfModuleTestType& aTestType, const T& aDefaultValue )
+        {
+        if ( iCount == KMaxArrayCount )
+            {
+            // Array already full.
+            return KErrOverflow;
+            }
+        else if ( Find( aKey, aTestType ) )
+            {
+            // Key has already been inserted.
+            return KErrAlreadyExists;
+            }
+        
+        // Append new key value set into the array.
+        iArray[ iCount ] = TAlfModuleTestItem< T >( aKey, aTestType, aDefaultValue );
+        ++iCount;
+        return KErrNone;        
+        }
+
+    
+    /**
+     * Sets the value for the item.
+     * Item itself should already exist in the array before
+     * setting its value here. See, Append function.
+     * 
+     * @param aKey
+     * @param aValue
+     * @return TInt System wide error code.
+     */
+    TInt SetValue( TInt aKey, const T& aValue, const TAlfModuleTestType& aTestType )
+        {
+        // Increase counter, because this function is called.
+        ++iSetValueCallCount;
+        TAlfModuleTestItem< T >* item( Find( aKey, aTestType ) );        
+        if ( !item )
+            {
+            // Item was not found from the array.        
+            return KErrNotFound;
+            }        
+        // Item exists. So, set its values.
+        item->SetValue( aValue );
+        return KErrNone;
+        }
+
+    
+    /**
+     * Resets the map
+     */
+    void Reset()
+        {
+        // Just reset the counter.
+        // We do not bother to reset map items, because when counter is reseted
+        // already set items and their info is left out of the scope.
+        iCount = 0;
+        iSetValueCallCount = 0;
+        }
+    
+    
+    /**
+     * Checks if all the values of items in the array match the given value.
+     * 
+     * @param aValue Reference to the value that items are compared to.
+     * @param aTestType Informs the test type whose items should be compared.
+     */
+    TInt CountEquals( const T& aValue, const TAlfModuleTestType& aTestType ) const
+        {
+        TInt count( 0 );
+        for ( TInt i = 0; i < iCount; ++i )
+            {
+            if ( iArray[ i ].Equals( aValue, aTestType ) )
+                {
+                // Item matches
+                ++count;            
+                }
+            }
+        return count;
+        }
+
+
+    /**
+     * @return TInt Number of map items
+     */
+    TInt ItemCount() const
+        {
+        return iCount;
+        }
+
+
+    /**
+     * @return const TAlfModuleTestItem< T >& Reference to the map item
+     */
+    const TAlfModuleTestItem< T >& Item( TInt aIndex ) const
+        {
+        return iArray[ aIndex ];
+        }
+
+    
+    /**
+     * @return TInt Number of times SetValue function has been called
+     *              since last reset. This information can be used
+     *              to check if hooks have been used correct times during
+     *              a test case. Notice, that this informs the number of
+     *              function calls, not the number of times a value has actually
+     *              set for some item.
+     */
+    TInt SetValueCallCount() const
+        {
+        return iSetValueCallCount;
+        }
+    
+    
+private: // data
+    
+    TAlfModuleTestItem< T > iArray[ KMaxArrayCount ];
+    // Informs number of array items
+    TInt iCount;
+    // Informs how many times SetItem has been called since last reset.
+    // Notice, that this informs the number of function calls, not the number
+    // of times a value has actually set for some item.
+    TInt iSetValueCallCount;
+    
+    };
+
+    
 /*
  *  Class CAlfModuleTestData
  */
@@ -115,10 +470,48 @@
                          iLatestVisualExtentRect.iTl.iX, iLatestVisualExtentRect.iTl.iY, 
                          iLatestVisualExtentRect.Width(), iLatestVisualExtentRect.Height());
         RDebug::Print(_L("iTotalVisualFlagChangedCount=%d"), iTotalVisualFlagChangedCount);
-        RDebug::Print(_L("iTotalVisualAttributeChangedCount=%d"), iTotalVisualAttributeChangedCount);        
+        RDebug::Print(_L("iTotalVisualAttributeChangedCount=%d"), iTotalVisualAttributeChangedCount);
+        RDebug::Print(_L("iSizeMap =>"));
+        PrintSizeMapState( iSizeMap );
+        RDebug::Print(_L("iPositionMap =>"));
+        PrintPositionMapState( iPositionMap );        
         RDebug::Print(_L("*** ALF INTERNAL STATE ***"));
         }
+
     
+    void PrintSizeMapState( TAlfModuleTestMap< TSize > aMap )
+        {
+        RDebug::Print(_L("*** ALF INTERNAL SIZE MAP STATE -->"));
+        RDebug::Print(_L("Map item count=%d, SetValue call count=%d"), 
+                         aMap.ItemCount(), aMap.SetValueCallCount());
+        for ( TInt i = 0; i < aMap.ItemCount(); ++i )
+            {
+            const TAlfModuleTestItem< TSize >& item( aMap.Item( i ) );
+            RDebug::Print(_L("Map item %d, iKey=%d, iTestType=%d, iValueSetCount=%d"),
+                             i, item.Key(), item.TestType(), item.ValueSetCount());
+            RDebug::Print(_L("Map item index=%d, width=%d, height=%d"),
+                             i, item.Value().iWidth, item.Value().iHeight);
+            }
+        RDebug::Print(_L("<-- ALF INTERNAL SIZE MAP STATE ***"));
+        }
+
+    
+    void PrintPositionMapState( TAlfModuleTestMap< TPoint > aMap )
+        {
+        RDebug::Print(_L("*** ALF INTERNAL POSITION MAP STATE -->"));
+        RDebug::Print(_L("Map item count=%d, SetValue call count=%d"), 
+                         aMap.ItemCount(), aMap.SetValueCallCount());
+        for ( TInt i = 0; i < aMap.ItemCount(); ++i )
+            {
+            const TAlfModuleTestItem< TPoint >& item( aMap.Item( i ) );
+            RDebug::Print(_L("Map item %d, iKey=%d, iTestType=%d, iValueSetCount=%d"),
+                             i, item.Key(), item.TestType(), item.ValueSetCount());
+            RDebug::Print(_L("Map item index=%d, x=%d, y=%d"),
+                             i, item.Value().iX, item.Value().iY);
+            }
+        RDebug::Print(_L("<-- ALF INTERNAL POSITION MAP STATE ***"));
+        }    
+
     
 public:
     TBool iIsEnabled;           // *** not yet implemented. For run-time enabling/disabling of the test system.  
@@ -177,6 +570,14 @@
     TInt iASE_Temp2;
     TInt iASE_Temp3;
     TInt iASE_Temp4;
+
+    // Map that contains integer items that can be specified for certain test cases.
+    TAlfModuleTestMap< TInt > iIntMap;    
+    // Map that contains size items that can be specified for certain test cases.
+    TAlfModuleTestMap< TSize > iSizeMap;
+    // Map that contains position items that can be specified for certain test cases.
+    TAlfModuleTestMap< TPoint > iPositionMap;    
+
     };