homescreensrv_plat/context_utility_api/tsrc/testbase/hgtestbase.h
branchRCL_3
changeset 14 15e4dd19031c
parent 12 502e5d91ad42
child 15 a0713522ab97
equal deleted inserted replaced
12:502e5d91ad42 14:15e4dd19031c
     1 /*
       
     2 * Copyright (c) 2002 - 2007 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:  hgtestbase module.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32svr.h>
       
    20 #include "StifTestModule.h"
       
    21 #include <StifLogger.h>
       
    22 
       
    23 #include "hgtestbasemacros.h"
       
    24 
       
    25 // MACROS
       
    26 #define TEST_MODULE_VERSION_MAJOR 0
       
    27 #define TEST_MODULE_VERSION_MINOR 0
       
    28 #define TEST_MODULE_VERSION_BUILD 0
       
    29 
       
    30 // CLASS DECLARATION
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 class CHgTestClass;
       
    34 class CEikonEnv;
       
    35 class CAknAppUi;
       
    36 
       
    37 // DATA TYPES
       
    38 typedef TInt (CHgTestClass::* TestFunction)(TTestResult&);
       
    39 
       
    40 /**
       
    41 *  An internal structure containing a test case name and
       
    42 *  the pointer to function doing the test
       
    43 */
       
    44 class TCaseInfoInternal
       
    45 {
       
    46 public:
       
    47     const TText*    iCaseName;
       
    48     TestFunction    iMethod;
       
    49     TBool           iIsOOMTest;
       
    50     TInt            iFirstMemoryAllocation;
       
    51     TInt            iLastMemoryAllocation;
       
    52 };
       
    53 
       
    54 // CLASS DECLARATION
       
    55 
       
    56 /**
       
    57 *  A structure containing a test case name and
       
    58 *  the pointer to function doing the test
       
    59 */
       
    60 class TCaseInfo
       
    61 {
       
    62 public:
       
    63     TPtrC           iCaseName;
       
    64     TestFunction    iMethod;
       
    65     TBool           iIsOOMTest;
       
    66     TInt            iFirstMemoryAllocation;
       
    67     TInt            iLastMemoryAllocation;
       
    68 
       
    69 TCaseInfo( const TText* a ) : iCaseName( (TText*) a )
       
    70     {
       
    71     };
       
    72 
       
    73 };
       
    74     
       
    75 class CHgTestBase : public CTestModuleBase
       
    76 {
       
    77 
       
    78 public:  //Enums
       
    79         // Reason for running test method
       
    80 		enum TCallReason
       
    81 		    {
       
    82 		    EEnumerateTestCases,
       
    83 		    ERunTestCase,
       
    84 		    };
       
    85         
       
    86 public:  // Constructors and destructor
       
    87     /**
       
    88     * Destructor.
       
    89     */
       
    90     virtual ~CHgTestBase();
       
    91     
       
    92 public: // New functions
       
    93     static TInt CallStop( TAny* aWait )
       
    94         {
       
    95         (static_cast<CActiveSchedulerWait*>(aWait))->AsyncStop();
       
    96         }
       
    97 public: // Functions from base classes
       
    98 
       
    99     /**
       
   100     * From CTestModuleBase InitL is used to initialize the 
       
   101     *       test class object. It is called once for every instance of 
       
   102     *       TestModule test class object after its creation.
       
   103     * @param aIniFile Initialization file for the test module (optional)
       
   104     * @param aFirstTime Flag is true when InitL is executed for first 
       
   105     *               created instance of test class object
       
   106     * @return Symbian OS error code
       
   107     */
       
   108     TInt InitL( TFileName& aIniFile, TBool aFirstTime );
       
   109 
       
   110     /**
       
   111     * From CTestModuleBase GetTestCasesL is used to inquiry test cases 
       
   112     *   from test class object. 
       
   113     * @param aTestCaseFile Test case file (optional)
       
   114     * @param aTestCases  Array of TestCases returned to test framework
       
   115     * @return Symbian OS error code
       
   116     */
       
   117     TInt GetTestCasesL( const TFileName& aTestCaseFile, 
       
   118                         RPointerArray<TTestCaseInfo>& aTestCases );
       
   119 
       
   120 
       
   121     /**
       
   122     * From CTestModuleBase; OOMTestQueryL is used to specify is particular
       
   123     * test case going to be executed using OOM conditions
       
   124     * @param aTestCaseFile Test case file (optional)
       
   125     * @param aCaseNumber Test case number (optional)
       
   126     * @param aFailureType OOM failure type (optional)
       
   127     * @param aFirstMemFailure The first heap memory allocation failure value (optional)
       
   128     * @param aLastMemFailure The last heap memory allocation failure value (optional)
       
   129     * @return TBool
       
   130     */
       
   131     virtual TBool OOMTestQueryL( const TFileName& /* aTestCaseFile */, 
       
   132                                  const TInt /* aCaseNumber */, 
       
   133                                  TOOMFailureType& aFailureType, 
       
   134                                  TInt& /* aFirstMemFailure */, 
       
   135                                  TInt& /* aLastMemFailure */ );
       
   136 
       
   137     /**
       
   138     * From CTestModuleBase; OOMTestInitializeL may be used to initialize OOM
       
   139     * test environment
       
   140     * @param aTestCaseFile Test case file (optional)
       
   141     * @param aCaseNumber Test case number (optional)
       
   142     * @return None
       
   143     */
       
   144     virtual void OOMTestInitializeL( const TFileName& /* aTestCaseFile */, 
       
   145                                 const TInt /* aCaseNumber */ ); 
       
   146 
       
   147     /**
       
   148     * From CTestModuleBase; OOMHandleWarningL
       
   149     * @param aTestCaseFile Test case file (optional)
       
   150     * @param aCaseNumber Test case number (optional)
       
   151     * @param aFailNextValue FailNextValue for OOM test execution (optional)
       
   152     * @return None
       
   153     *
       
   154     * User may add implementation for OOM test warning handling. Usually no
       
   155     * implementation is required.           
       
   156     */
       
   157     virtual void OOMHandleWarningL( const TFileName& /* aTestCaseFile */,
       
   158                                     const TInt /* aCaseNumber */, 
       
   159                                     TInt& /* aFailNextValue */); 
       
   160 
       
   161     /**
       
   162     * From CTestModuleBase; OOMTestFinalizeL may be used to finalize OOM
       
   163     * test environment
       
   164     * @param aTestCaseFile Test case file (optional)
       
   165     * @param aCaseNumber Test case number (optional)
       
   166     * @return None
       
   167     *
       
   168     */
       
   169     virtual void OOMTestFinalizeL( const TFileName& /* aTestCaseFile */, 
       
   170                                    const TInt /* aCaseNumber */ );
       
   171 
       
   172     /**
       
   173      * Method used to log version of test module
       
   174      */
       
   175     void SendTestModuleVersion( const TDesC& aTestPath );
       
   176 
       
   177 private:
       
   178     /**
       
   179     * From CTestModuleBase RunTestCaseL is used to run an individual 
       
   180     *   test case. 
       
   181     * @param aCaseNumber Test case number
       
   182     * @param aTestCaseFile Test case file (optional)
       
   183     * @param aResult Test case result returned to test framework (PASS/FAIL)
       
   184     * @return Symbian OS error code (test case execution error, which is 
       
   185     *           not reported in aResult parameter as test case failure).
       
   186     */   
       
   187     TInt RunTestCaseL( const TInt aCaseNumber, 
       
   188                        const TFileName& aTestCaseFile,
       
   189                        TTestResult& aResult );
       
   190 
       
   191     /**
       
   192     * Method containing all test cases, setup and teardown sections.
       
   193     */
       
   194     TInt MainTestL(CHgTestBase::TCallReason aRunReason, TInt aTestToRun, RPointerArray<TTestCaseInfo>& aTestCases,
       
   195             TTestResult& aResult);
       
   196 
       
   197 protected:
       
   198 
       
   199     /**
       
   200     * C++ default constructor.
       
   201     */
       
   202     CHgTestBase();
       
   203 
       
   204     /**
       
   205     * By default Symbian 2nd phase constructor is private.
       
   206     */
       
   207     void BaseConstructL( const TDesC& aTestPath,
       
   208                      const TDesC& aTestFile );
       
   209 
       
   210     /**
       
   211      * Put here the #include of the test cases cpp file
       
   212      */
       
   213     virtual TInt RunTestL(
       
   214             CHgTestBase::TCallReason aRunReason, 
       
   215             TInt aTestToRun, 
       
   216             RPointerArray<TTestCaseInfo>& aTestCases,
       
   217             TTestResult& aResult) = 0;
       
   218 
       
   219 protected:    // Data
       
   220     // Pointer to test (function) to be executed
       
   221     TestFunction iMethod;
       
   222 
       
   223     // Pointer to logger
       
   224     CStifLogger * iLog; 
       
   225 
       
   226     // Flag saying if version of test module was already sent
       
   227     TBool iVersionLogged;
       
   228     // Total number of test cases
       
   229     TInt iNumberOfTestCases;
       
   230       HBufC16* iTestDllName;
       
   231     // activescheduler for connecting
       
   232     CActiveScheduler* iActiveScheduler;
       
   233 };