cryptomgmtlibs/securitytestfw/test/testhandler2/t_testrunner.h
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2004-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 the License "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 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __T_TESTRUNNER_H__
       
    20 #define __T_TESTRUNNER_H__
       
    21 
       
    22 #include <e32base.h>
       
    23 
       
    24 class Output;
       
    25 class CTestAction;
       
    26 
       
    27 /**
       
    28  * A class that is used to invoke individual tests.  This can be derived to
       
    29  * implement OOM testing, cancel testing and the like.  The default
       
    30  * implementation just runs the test.
       
    31  *
       
    32  * One instance of this class is used to run multiple tests.  A CTestHandler
       
    33  * owns an instance of this class (or a class derived from it).
       
    34  *
       
    35  * Note that this class provides a synchronous interface, which is implemented
       
    36  * in terms of CTestActions's asynchronous interface.
       
    37  */
       
    38 class CTestRunner : public CActive
       
    39     {
       
    40  public:
       
    41     IMPORT_C CTestRunner(Output& aOut);
       
    42     IMPORT_C virtual ~CTestRunner();
       
    43 
       
    44     // The following methods return the status code from test action, but leave
       
    45     // if there is an error in the test handler.
       
    46     
       
    47     IMPORT_C virtual TInt PerformPrerequisiteL(CTestAction* aAction);
       
    48     IMPORT_C virtual TInt PerformActionL(CTestAction* aAction);
       
    49     IMPORT_C virtual TInt PerformPostrequisiteL(CTestAction* aAction, TInt aInitialStatus);
       
    50 
       
    51  protected:
       
    52     /// Typedef for any of CTestAction's async methods
       
    53     typedef void (CTestAction::*TTestMethod)(TRequestStatus&);
       
    54         
       
    55     /// Run one of CTestAction's async methods synchronously and return the result
       
    56     TInt RunAsyncMethodL(TTestMethod aMethod, CTestAction* aAction, TInt aInitialStatus);
       
    57 
       
    58 	/// Run the active scheduler until our request is completed
       
    59 	void RunSchedulerL();
       
    60 
       
    61 	/// Run the active scheduler to process one outstanding request
       
    62 	/// @return If our request has been completed yet
       
    63 	TBool StepScheduler();
       
    64 	
       
    65  protected:
       
    66     Output& iOut;
       
    67 
       
    68  private:
       
    69     IMPORT_C virtual TInt RunError(TInt aError);
       
    70     IMPORT_C virtual void DoCancel();
       
    71     IMPORT_C virtual void RunL();
       
    72 
       
    73  private:
       
    74     /// Whether an async method is currently being executed by the active scheduler
       
    75     TBool iSchedulerRunning;  
       
    76     };
       
    77 
       
    78 /**
       
    79  * Abstract base class for a test runner that implements OOM testing.
       
    80  */
       
    81 class COOMTestRunnerBase : public CTestRunner
       
    82     {
       
    83  public:
       
    84     IMPORT_C virtual ~COOMTestRunnerBase();
       
    85 
       
    86  protected:
       
    87     IMPORT_C COOMTestRunnerBase(Output& aOut);
       
    88 
       
    89 	/// Called at the start of the OOM test
       
    90 	virtual void StartOOMTestL() = 0;	
       
    91 	/// Increment the simulated heap fail point
       
    92 	virtual void IncHeapFailPoint() = 0;
       
    93 	/// Reset simulated heap failures
       
    94 	virtual void ResetHeapFail() = 0;
       
    95 	/// Get the number of cells currently allocated
       
    96 	virtual TInt AllocCount() = 0;
       
    97 	/// Called at the end of the OOM test
       
    98 	virtual void EndOOMTestL() = 0;
       
    99 	
       
   100  private:
       
   101 	// Override CTestRunner interface
       
   102     IMPORT_C virtual TInt PerformActionL(CTestAction* aAction);
       
   103     };
       
   104 
       
   105 /**
       
   106  * Implementation of an test runner for OOM testing.
       
   107  */
       
   108 class COOMTestRunner : public COOMTestRunnerBase
       
   109 	{
       
   110  public:
       
   111 	COOMTestRunner(Output& aOut);
       
   112 	virtual ~COOMTestRunner();
       
   113 	
       
   114  private:
       
   115 	// Implement interface defined by COOMTestRunnerBase
       
   116 	virtual void StartOOMTestL();	
       
   117 	virtual void IncHeapFailPoint();
       
   118 	virtual void ResetHeapFail();
       
   119 	virtual TInt AllocCount();
       
   120 	virtual void EndOOMTestL();
       
   121 
       
   122  private:
       
   123 	TInt iFailPoint;
       
   124 	};
       
   125 
       
   126 /// A test runner that performs cancellation tests.
       
   127 class CCancelTestRunner : public CTestRunner
       
   128     {
       
   129  public:
       
   130     CCancelTestRunner(Output& aOut);
       
   131     virtual ~CCancelTestRunner();
       
   132 
       
   133     virtual TInt PerformActionL(CTestAction* aAction);
       
   134 
       
   135  private:
       
   136     TInt RunAndCancelPeformActionMethod(CTestAction* aAction, TInt aInitialStatus,
       
   137                                         TInt aCancelStep, TInt& aStep);
       
   138     TInt RunAndCancelTestAction(CTestAction* aAction, TInt aCancelStep);
       
   139 
       
   140  private:
       
   141     TBool iAbort;         ///< Set when we want to abort the test
       
   142     };
       
   143 
       
   144 #endif