keepalive/flextimer/test/testflextimer/inc/testflextimer.h
changeset 32 5c4486441ae6
equal deleted inserted replaced
31:c16e04725da3 32:5c4486441ae6
       
     1 /*
       
     2 * Copyright (c) 2009 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: STIF normal test module declaration
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef TESTFLEXTIMER_H
       
    19 #define TESTFLEXTIMER_H
       
    20 
       
    21 // INCLUDES
       
    22 #include "StifTestModule.h"
       
    23 #include <StifLogger.h>
       
    24 #include <NormalHardcodedAssert.h>
       
    25 
       
    26 // MACROS
       
    27 #define TEST_MODULE_VERSION_MAJOR 0
       
    28 #define TEST_MODULE_VERSION_MINOR 0
       
    29 #define TEST_MODULE_VERSION_BUILD 0
       
    30 
       
    31 // Logging path
       
    32 _LIT( KTestFlexTimerLogPath, "\\logs\\testframework\\TestFlexTimer\\" ); 
       
    33 // Log file
       
    34 _LIT( KTestFlexTimerLogFile, "TestFlexTimer.txt" ); 
       
    35 _LIT( KTestFlexTimerLogFileWithTitle, "TestFlexTimer_[%S].txt" );
       
    36 
       
    37 _LIT( KTestFlexTimerPanicCategory, "FLEX-TEST" );
       
    38 
       
    39 // Function pointer related internal definitions
       
    40 #define GETPTR &  
       
    41 #define ENTRY(str,func) {_S(str), GETPTR func,0,0,0}
       
    42 #define FUNCENTRY(func) {_S(#func), GETPTR func,0,0,0}
       
    43 #define OOM_ENTRY(str,func,a,b,c) {_S(str), GETPTR func,a,b,c}
       
    44 #define OOM_FUNCENTRY(func,a,b,c) {_S(#func), GETPTR func,a,b,c}
       
    45 
       
    46 
       
    47 // Forward declaration
       
    48 class CTestFlexTimer;
       
    49 
       
    50 // A typedef for function that does the actual testing,
       
    51 // function is a type 
       
    52 // TInt CDemoModule::<NameOfFunction> ( TTestResult& aResult, CTestFlexTimer *cb )
       
    53 typedef TInt (*TestFunction)(TTestResult&, CTestFlexTimer*);    
       
    54 
       
    55 const TInt KTimerAccuracyMicroSeconds = 1000 * 1000; //1s - accuracy of symbian At timer.
       
    56 const double KDefaultWindowMultiplier = 0.2; //default window. defined in flextimersession.cpp 
       
    57 const TUint KTickInMicroSeconds( 1000000 / 64 ); // One tick = 1/64 sec
       
    58 
       
    59 
       
    60 // CLASS DECLARATION
       
    61 
       
    62 /**
       
    63 *  An internal structure containing a test case name and
       
    64 *  the pointer to function doing the test
       
    65 *
       
    66 *  @lib ?library
       
    67 *  @since ?Series60_version
       
    68 */
       
    69 class TCaseInfoInternal
       
    70     {
       
    71     public:
       
    72         const TText*    iCaseName;
       
    73         TestFunction    iMethod;
       
    74         TBool           iIsOOMTest;
       
    75         TInt            iFirstMemoryAllocation;
       
    76         TInt            iLastMemoryAllocation;
       
    77     };
       
    78 
       
    79 // CLASS DECLARATION
       
    80 
       
    81 /**
       
    82 *  A structure containing a test case name and
       
    83 *  the pointer to function doing the test
       
    84 *
       
    85 *  @lib ?library
       
    86 *  @since ?Series60_version
       
    87 */
       
    88 class TCaseInfo
       
    89     {
       
    90     public:
       
    91         TPtrC           iCaseName;    
       
    92         TestFunction    iMethod;
       
    93         TBool           iIsOOMTest;
       
    94         TInt            iFirstMemoryAllocation;
       
    95         TInt            iLastMemoryAllocation;
       
    96 
       
    97     TCaseInfo( const TText* a ) : iCaseName( (TText*) a )
       
    98         {        
       
    99         };
       
   100     };
       
   101 
       
   102 //Exteded result that can "return" also status code to CB function 
       
   103 class TExtendedTestResult
       
   104     {
       
   105     public:
       
   106         TTestResult *iTestResult; //the real test result
       
   107         TInt iStatusCode; //Return code from timer
       
   108         TBool iCaseAlreadyFailed;
       
   109         TInt iTimerID;
       
   110         TInt64 iTimerStartedTime;
       
   111         TInt64 iTimerStoppedTime;
       
   112         TInt64 iTimerExpiryTime;
       
   113 
       
   114     TExtendedTestResult(TTestResult *aResult) : iTestResult( aResult ), iStatusCode(0), iCaseAlreadyFailed(EFalse), 
       
   115             iTimerID(0), iTimerStartedTime(0), iTimerStoppedTime(0) {};
       
   116     };
       
   117 // CLASS DECLARATION
       
   118 
       
   119 /**
       
   120 *  This a TestFlexTimer class.
       
   121 *
       
   122 *  @lib ?library
       
   123 *  @since ?Series60_version
       
   124 */
       
   125 NONSHARABLE_CLASS(CTestFlexTimer) : public CTestModuleBase
       
   126     {
       
   127     public:  // Constructors and destructor
       
   128 
       
   129         /**
       
   130         * Two-phased constructor.
       
   131         */
       
   132         static CTestFlexTimer* NewL();
       
   133 
       
   134         /**
       
   135         * Destructor.
       
   136         */
       
   137         virtual ~CTestFlexTimer();
       
   138   
       
   139     public: // Functions from base classes
       
   140 
       
   141         
       
   142         /**
       
   143         * From CTestModuleBase InitL is used to initialize the TestFlexTimer. 
       
   144         *       It is called once for every instance of TestFlexTimer after
       
   145         *       its creation.
       
   146         * @since ?Series60_version
       
   147         * @param aIniFile Initialization file for the test module (optional)
       
   148         * @param aFirstTime Flag is true when InitL is executed for first 
       
   149         *               created instance of TestFlexTimer.
       
   150         * @return Symbian OS error code
       
   151         */
       
   152         TInt InitL( TFileName& aIniFile, TBool aFirstTime );
       
   153 
       
   154         /**
       
   155         * From CTestModuleBase GetTestCasesL is used to inquiry test cases 
       
   156         *   from TestFlexTimer. 
       
   157         * @since ?Series60_version
       
   158         * @param aTestCaseFile Test case file (optional)
       
   159         * @param aTestCases  Array of TestCases returned to test framework
       
   160         * @return Symbian OS error code
       
   161         */
       
   162         TInt GetTestCasesL( const TFileName& aTestCaseFile, 
       
   163                             RPointerArray<TTestCaseInfo>& aTestCases );
       
   164 
       
   165         /**
       
   166         * From CTestModuleBase RunTestCaseL is used to run an individual 
       
   167         *   test case. 
       
   168         * @since ?Series60_version
       
   169         * @param aCaseNumber Test case number
       
   170         * @param aTestCaseFile Test case file (optional)
       
   171         * @param aResult Test case result returned to test framework (PASS/FAIL)
       
   172         * @return Symbian OS error code (test case execution error, which is 
       
   173         *           not reported in aResult parameter as test case failure).
       
   174         */   
       
   175         TInt RunTestCaseL( const TInt aCaseNumber, 
       
   176                            const TFileName& aTestCaseFile,
       
   177                            TTestResult& aResult );
       
   178 
       
   179         /**
       
   180         * From CTestModuleBase; OOMTestQueryL is used to specify is particular
       
   181         * test case going to be executed using OOM conditions
       
   182         * @param aTestCaseFile Test case file (optional)
       
   183         * @param aCaseNumber Test case number (optional)
       
   184         * @param aFailureType OOM failure type (optional)
       
   185         * @param aFirstMemFailure The first heap memory allocation failure value (optional)
       
   186         * @param aLastMemFailure The last heap memory allocation failure value (optional)
       
   187         * @return TBool
       
   188         */
       
   189         virtual TBool OOMTestQueryL( const TFileName& /* aTestCaseFile */, 
       
   190                                      const TInt /* aCaseNumber */, 
       
   191                                      TOOMFailureType& /* aFailureType */,
       
   192                                      TInt& /* aFirstMemFailure */, 
       
   193                                      TInt& /* aLastMemFailure */ );
       
   194 
       
   195         /**
       
   196         * From CTestModuleBase; User may add implementation for OOM test 
       
   197         * environment initialization. Usually no implementation is required.
       
   198         * @param aTestCaseFile Test case file (optional)
       
   199         * @param aCaseNumber Test case number (optional)
       
   200         * @return None
       
   201         */
       
   202         virtual void OOMTestInitializeL( const TFileName& /* aTestCaseFile */, 
       
   203                                     const TInt /* aCaseNumber */ ); 
       
   204 
       
   205         /**
       
   206         * From CTestModuleBase; OOMHandleWarningL. User may add implementation 
       
   207         * for OOM test warning handling. Usually no implementation is required.
       
   208         * @param aTestCaseFile Test case file (optional)
       
   209         * @param aCaseNumber Test case number (optional)
       
   210         * @param aFailNextValue FailNextValue for OOM test execution (optional)
       
   211         * @return None
       
   212         */
       
   213         virtual void OOMHandleWarningL( const TFileName& /* aTestCaseFile */,
       
   214                                         const TInt /* aCaseNumber */, 
       
   215                                         TInt& /* aFailNextValue */);
       
   216 
       
   217         /**
       
   218         * From CTestModuleBase; OOMTestFinalizeL may be used to finalize OOM
       
   219         * test environment. Usually no implementation is required.
       
   220         * @param aTestCaseFile Test case file (optional)
       
   221         * @param aCaseNumber Test case number (optional)
       
   222         * @return None
       
   223         */
       
   224         virtual void OOMTestFinalizeL( const TFileName& /* aTestCaseFile */, 
       
   225                                        const TInt /* aCaseNumber */ );
       
   226 
       
   227         /**
       
   228          * Method used to log version of test module
       
   229          */
       
   230         void SendTestModuleVersion();
       
   231 
       
   232 
       
   233     private:
       
   234 
       
   235         /**
       
   236         * C++ default constructor.
       
   237         */
       
   238         CTestFlexTimer();
       
   239 
       
   240         /**
       
   241         * By default Symbian 2nd phase constructor is private.
       
   242         */
       
   243         void ConstructL();
       
   244 
       
   245         /**
       
   246         * Check for settings and create logger with test case title in file name.
       
   247         */
       
   248         void CreateTitleLoggerL(void);
       
   249 
       
   250         /**
       
   251         * Check for logger settings and delete title logger.
       
   252         */
       
   253         void DeleteTitleLogger(void);
       
   254 
       
   255         /**
       
   256          * Function returning test case name and pointer to test case function.
       
   257          * @since ?Series60_version
       
   258          * @param aCaseNumber test case number
       
   259          * @return TCaseInfo 
       
   260          */
       
   261         const TCaseInfo Case( const TInt aCaseNumber ) const;
       
   262 
       
   263         /**
       
   264         * Start monitoring FlexTimer server crashes
       
   265         * 
       
   266         * @param aResult The result of the test.
       
   267         * @param aCallback Pointer to the STIF test class
       
   268         * @return The status of execution of the test. KErrNone if the test
       
   269         *         was executed ok, any system wide errorcode otherwise.
       
   270         */
       
   271         static TInt StartServerMonitoringL(
       
   272             TTestResult& aResult, 
       
   273             CTestFlexTimer* aCallback );
       
   274 
       
   275         /**
       
   276         * Stop monitoring FlexTimer server crashes and fail the test case if
       
   277         * a crash has happened.
       
   278         * 
       
   279         * @param aResult The result of the test.
       
   280         * @param aCallback Pointer to the STIF test class
       
   281         * @return The status of execution of the test. KErrNone if the test
       
   282         *         was executed ok, any system wide errorcode otherwise.
       
   283         */
       
   284         static TInt StopServerMonitoringL(
       
   285             TTestResult& aResult, 
       
   286             CTestFlexTimer* aCallback );
       
   287         
       
   288         /**
       
   289         * Start second FlexTimerServer. 
       
   290         * 
       
   291         * Increase test coverage by testing server side destructors.
       
   292         * 
       
   293         * Starting of the server fails with panic "FlexTimerServer" 23 
       
   294         * (EFlexTimerServerStartServer).
       
   295         * 
       
   296         * @param aResult The result of the test.
       
   297         * @param aCallback Pointer to the STIF test class
       
   298         * @return The status of execution of the test. KErrNone if the test
       
   299         *         was executed ok, any system wide errorcode otherwise.
       
   300         */
       
   301         static TInt StartSecondServerL(
       
   302             TTestResult& aResult, 
       
   303             CTestFlexTimer* aCallback );
       
   304         
       
   305         /**
       
   306         * Changes Test client thread priority to EPriorityMuchMore
       
   307         * 
       
   308         * @param aResult The result of the test, always Passed.
       
   309         * @param aCallback Pointer to the STIF test class
       
   310         * @return The status of execution of the test. KErrNone always
       
   311         */
       
   312         static TInt SetThreadPriorityMuchMore(
       
   313             TTestResult& aResult, 
       
   314             CTestFlexTimer* aCallback );
       
   315         
       
   316         /**
       
   317         * Changes Test client thread priority to EPriorityNormal
       
   318         * 
       
   319         * @param aResult The result of the test, always Passed.
       
   320         * @param aCallback Pointer to the STIF test class
       
   321         * @return The status of execution of the test. KErrNone always
       
   322         */
       
   323         static TInt SetThreadPriorityNormal(
       
   324             TTestResult& aResult, 
       
   325             CTestFlexTimer* aCallback );
       
   326 
       
   327     public:     // Data
       
   328         // ?one_line_short_description_of_data
       
   329         //?data_declaration;
       
   330 
       
   331     protected:  // Data
       
   332         // ?one_line_short_description_of_data
       
   333         //?data_declaration;
       
   334 
       
   335     private:    // Data
       
   336         // ?one_line_short_description_of_data
       
   337         //?data_declaration;
       
   338 
       
   339         CStifLogger * iLog;
       
   340 
       
   341         // Standard logger
       
   342         CStifLogger *iStdLog;
       
   343 
       
   344         // Logger for currently running test case
       
   345         CStifLogger *iTCLog;
       
   346         
       
   347         // Flag saying if test case title should be added to log file name
       
   348         TBool iAddTestCaseTitleToLogName;
       
   349         
       
   350         // Flag saying if test module version was already sent
       
   351         TBool iVersionLogged;
       
   352 
       
   353         // Reserved pointer for future extension
       
   354         //TAny* iReserved;
       
   355 
       
   356         // Pointer to test (function) to be executed
       
   357         TestFunction iMethod;
       
   358         
       
   359         //CTimer CB failed case
       
   360         TBool iCTimerCBFailedCase;
       
   361         
       
   362     public:     // Friend classes
       
   363         //?friend_class_declaration;
       
   364     protected:  // Friend classes
       
   365         //?friend_class_declaration;
       
   366     private:    // Friend classes
       
   367         //?friend_class_declaration;
       
   368 
       
   369     };
       
   370 
       
   371 #endif      // TESTFLEXTIMER_H
       
   372 
       
   373 // End of File