stif/TestEngine/src/Testcasetimeout.cpp
branchRCL_3
changeset 59 8ad140f3dd41
parent 0 a03f92240627
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     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: This module contains implementation of 
       
    15 * CTestCaseTimeout class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32svr.h>
       
    21 #include <hal.h>
       
    22 #include <StifLogger.h>
       
    23 #include "TestReport.h"
       
    24 #include "TestEngine.h"
       
    25 #include "TestEngineCommon.h"
       
    26 #include "TestCaseController.h"
       
    27 
       
    28 // EXTERNAL DATA STRUCTURES
       
    29 // None
       
    30 
       
    31 // EXTERNAL FUNCTION PROTOTYPES  
       
    32 // None
       
    33 
       
    34 // CONSTANTS
       
    35 // None
       
    36 
       
    37 // MACROS
       
    38 // None
       
    39 
       
    40 // LOCAL CONSTANTS AND MACROS
       
    41 // None
       
    42 
       
    43 // MODULE DATA STRUCTURES
       
    44 // None
       
    45 
       
    46 // LOCAL FUNCTION PROTOTYPES
       
    47 // None
       
    48 
       
    49 // FORWARD DECLARATIONS
       
    50 // None
       
    51 
       
    52 // ==================== LOCAL FUNCTIONS =======================================
       
    53 // None
       
    54 
       
    55 // ================= MEMBER FUNCTIONS =========================================
       
    56 
       
    57 /*
       
    58 -------------------------------------------------------------------------------
       
    59 
       
    60     Class: CTestCaseTimeout
       
    61 
       
    62     Method: CTestCaseTimeout
       
    63 
       
    64     Description: Default constructor
       
    65 
       
    66     C++ default constructor can NOT contain any code, that
       
    67     might leave.
       
    68 
       
    69     Parameters: None
       
    70 
       
    71     Return Values: None
       
    72 
       
    73     Errors/Exceptions: None
       
    74 
       
    75     Status: Approved
       
    76 
       
    77 -------------------------------------------------------------------------------
       
    78 */
       
    79 CTestCaseTimeout::CTestCaseTimeout() : CActive (CActive::EPriorityStandard)
       
    80     {
       
    81 
       
    82     }
       
    83 
       
    84 /*
       
    85 -------------------------------------------------------------------------------
       
    86 
       
    87     Class: CTestCaseTimeout
       
    88 
       
    89     Method: ConstructL
       
    90 
       
    91     Description: Symbian OS second phase constructor
       
    92 
       
    93     Symbian OS default constructor can leave.
       
    94 
       
    95     Parameters: 
       
    96 
       
    97     Return Values: None
       
    98 
       
    99     Errors/Exceptions: 
       
   100 
       
   101     Status: Approved
       
   102 
       
   103 -------------------------------------------------------------------------------
       
   104 */
       
   105 void CTestCaseTimeout::ConstructL( CTestCaseController* aCase,
       
   106                                    TTimeIntervalMicroSeconds aTimeout )
       
   107     {
       
   108     iCase = aCase;
       
   109     iTimeout = aTimeout;  
       
   110     iTimer.CreateLocal();
       
   111 
       
   112 	iTestCaseTimeout = 0;  // Initialize
       
   113 
       
   114     }
       
   115 
       
   116 /*
       
   117 -------------------------------------------------------------------------------
       
   118 
       
   119     Class: CTestCaseTimeout
       
   120 
       
   121     Method: NewL
       
   122 
       
   123     Description: Two-phased constructor.
       
   124 
       
   125     Parameters: const TTestReportOutput aReportOutput: in: Report output type
       
   126 
       
   127     Return Values: CTestCaseTimeout* : pointer to created object
       
   128 
       
   129     Errors/Exceptions: Leaves if memory allocation for object fails
       
   130                        Leaves if ConstructL leaves
       
   131 
       
   132     Status: Approved
       
   133 
       
   134 -------------------------------------------------------------------------------
       
   135 */
       
   136 CTestCaseTimeout* CTestCaseTimeout::NewL( CTestCaseController* aCase, 
       
   137                                           TTimeIntervalMicroSeconds aTimeout )
       
   138     {
       
   139     CTestCaseTimeout* self = new ( ELeave ) CTestCaseTimeout();
       
   140     CleanupStack::PushL( self );
       
   141     self->ConstructL( aCase, aTimeout );
       
   142     CleanupStack::Pop( self );
       
   143     return self;
       
   144 
       
   145     }
       
   146 
       
   147 /*
       
   148 -------------------------------------------------------------------------------
       
   149 
       
   150     Class: CTestCaseTimeout
       
   151 
       
   152     Method: ~CTestCaseTimeout
       
   153 
       
   154     Description: Destructor.
       
   155 
       
   156     Cancel request
       
   157 
       
   158     Parameters: None
       
   159 
       
   160     Return Values: None
       
   161 
       
   162     Errors/Exceptions: None
       
   163 
       
   164     Status: Approved
       
   165 
       
   166 -------------------------------------------------------------------------------
       
   167 */
       
   168 CTestCaseTimeout::~CTestCaseTimeout()
       
   169     {
       
   170     Cancel();
       
   171 
       
   172     }
       
   173 
       
   174 /*
       
   175 -------------------------------------------------------------------------------
       
   176 
       
   177     Class: CTestCaseTimeout
       
   178 
       
   179     Method: Start
       
   180 
       
   181     Description: Start timeout counting
       
   182 
       
   183     Parameters: None
       
   184 
       
   185     Return Values: None
       
   186 
       
   187     Errors/Exceptions: None
       
   188 
       
   189     Status: Approved
       
   190 
       
   191 -------------------------------------------------------------------------------
       
   192 */
       
   193 void CTestCaseTimeout::Start()
       
   194     {
       
   195     // Add to active scheduler
       
   196     CActiveScheduler::Add ( this );
       
   197     SetActive();
       
   198 
       
   199     // Request timer
       
   200     TTime timeout;
       
   201     timeout.HomeTime();
       
   202     timeout = timeout + iTimeout;
       
   203     
       
   204     // Store absolute timeout
       
   205     iTestCaseTimeout = timeout;
       
   206 
       
   207     // Note: iTimer.After() method cannot use because there needed
       
   208     // TTimeIntervalMicroSeconds32 and it is 32 bit. So then cannot create 
       
   209     // timeout time that is long enough. At() uses 64 bit value=>Long enough.
       
   210     iTimer.At( iStatus, timeout );
       
   211 
       
   212     }
       
   213 
       
   214 /*
       
   215 -------------------------------------------------------------------------------
       
   216 
       
   217     Class: CTestCaseTimeout
       
   218 
       
   219     Method: RunL
       
   220 
       
   221     Description: RunL handles completed timeouts.
       
   222 
       
   223     Parameters: None
       
   224 
       
   225     Return Values: None
       
   226 
       
   227     Errors/Exceptions: None
       
   228 
       
   229     Status: Approved
       
   230 
       
   231 -------------------------------------------------------------------------------
       
   232 */
       
   233 void CTestCaseTimeout::RunL()
       
   234     {
       
   235     // Timeout
       
   236 	TTime timeout;
       
   237 	timeout.HomeTime();
       
   238 	// Handle the abort case when system time gets changed, but timeout is
       
   239     // still valid. All other cases should timeout since they invalidate the
       
   240     // logic of the timers.
       
   241 	if ( iStatus == KErrAbort)
       
   242 		{
       
   243 		if ( iTestCaseTimeout > timeout )
       
   244 			{  
       
   245 			RDebug::Print( _L( "Absolute timer still valid. Restaring timer. iStatus: %d" ), iStatus.Int() );
       
   246 			// Start new timer
       
   247 			iStatus = KErrNone; // reset value
       
   248 			iTimer.At ( iStatus, iTestCaseTimeout );  // restart timer
       
   249 			SetActive();
       
   250 			}
       
   251 		else
       
   252 			{
       
   253 			// Absolute timer no longer valid. Must timeout.
       
   254 			iCase->Timeout();
       
   255 			}
       
   256 
       
   257 		}
       
   258 	else
       
   259 		{
       
   260 		// Status was not KErrAbort. Timing out!
       
   261 		iCase->Timeout();
       
   262 		}
       
   263 
       
   264     }
       
   265 
       
   266 /*
       
   267 -------------------------------------------------------------------------------
       
   268 
       
   269     Class: CTestCaseTimeout
       
   270 
       
   271     Method: DoCancel
       
   272 
       
   273     Description: Cancel active request
       
   274 
       
   275     Parameters: None
       
   276 
       
   277     Return Values: None
       
   278 
       
   279     Errors/Exceptions: None
       
   280 
       
   281     Status: Approved
       
   282 
       
   283 -------------------------------------------------------------------------------
       
   284 */
       
   285 void CTestCaseTimeout::DoCancel()
       
   286     {
       
   287     iTimer.Cancel();
       
   288 
       
   289     }
       
   290 
       
   291 /*
       
   292 -------------------------------------------------------------------------------
       
   293 
       
   294     Class: CTestCaseTimeout
       
   295 
       
   296     Method: RunError
       
   297 
       
   298     Description: Handle errors. Just let framework handle errors because
       
   299     RunL does not leave.
       
   300 
       
   301     Parameters: TInt aError: in: Symbian OS error: Error code
       
   302 
       
   303     Return Values: TInt: Symbian OS error code
       
   304 
       
   305     Errors/Exceptions: None
       
   306 
       
   307     Status: Approved
       
   308 
       
   309 -------------------------------------------------------------------------------
       
   310 */
       
   311 TInt CTestCaseTimeout::RunError( TInt aError )
       
   312     {
       
   313     return aError;
       
   314 
       
   315     }
       
   316 
       
   317 // ================= OTHER EXPORTED FUNCTIONS =================================
       
   318 
       
   319 // None
       
   320 
       
   321 // End of File