camerasrv_plat/asynchronous_file_saving_queue_api/tsrc/src/StifFSQTestTop.cpp
branchRCL_3
changeset 20 e3cdd00b5ae3
parent 19 18fa9327a158
child 21 27fe719c32e6
equal deleted inserted replaced
19:18fa9327a158 20:e3cdd00b5ae3
     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:  FSQ Test DLL
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32math.h>
       
    21 #include "../inc/StifFSQTestTop.h"
       
    22 #include "../inc/TestFramework/testSuite.h"
       
    23 #include "../inc/AFSQTestTop.h"
       
    24 #include "../inc/AFSQTestAsynchSave.h"
       
    25 
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 // None
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES  
       
    31 // None
       
    32 
       
    33 // CONSTANTS
       
    34 // None
       
    35 
       
    36 // MACROS
       
    37 // None
       
    38 
       
    39 // LOCAL CONSTANTS AND MACROS
       
    40 // None
       
    41 
       
    42 // MODULE DATA STRUCTURES
       
    43 // None
       
    44 
       
    45 // LOCAL FUNCTION PROTOTYPES
       
    46 // None
       
    47 
       
    48 // FORWARD DECLARATIONS
       
    49 // None
       
    50 
       
    51 // ==================== LOCAL FUNCTIONS =======================================
       
    52 
       
    53            
       
    54 /*
       
    55 -------------------------------------------------------------------------------
       
    56 
       
    57     DESCRIPTION
       
    58     
       
    59     This file (DemoModule.cpp) contains all STIF test framework related parts of
       
    60     this test module.
       
    61 
       
    62 -------------------------------------------------------------------------------
       
    63 */
       
    64 EXPORT_C TInt SetRequirements( CTestModuleParam*& aTestModuleParam, TUint32& aParameterValid )
       
    65     {
       
    66     aParameterValid = KStifTestModuleParameterChanged;
       
    67     
       
    68     TRAP_IGNORE(
       
    69         CTestModuleParamVer01* param = CTestModuleParamVer01::NewL();
       
    70         
       
    71     	// Stack size
       
    72     	param->iTestThreadStackSize= 2*16384; // 2*16K stack
       
    73 
       
    74     	// Heap sizes
       
    75     	param->iTestThreadMinHeap = 4096;   // 4K heap min
       
    76     	param->iTestThreadMaxHeap = 8*1048576;// 8M heap max
       
    77 
       
    78     	aTestModuleParam = param;
       
    79 	);
       
    80 	
       
    81     return KErrNone;
       
    82     }
       
    83 
       
    84 // ================= MEMBER FUNCTIONS =========================================
       
    85 
       
    86 
       
    87 CTestModule::CTestModule()
       
    88     {
       
    89     }
       
    90 
       
    91 
       
    92 void CTestModule::ConstructL()
       
    93     {  
       
    94     iTestSuite = CTestSuite::NewL(_L8("Test Suite Container"));
       
    95 
       
    96     iTestSuite->addTestL( CAFSQTestAsynchSave::suiteL() );    
       
    97     
       
    98 
       
    99     
       
   100     // SetAllocFailureSimulation( RHeap::EDeterministic, 0 ); // Enable OOM test loop
       
   101     SetAllocFailureSimulation( RHeap::ENone, 0 ); // Disable OOM test loop
       
   102 
       
   103     /* Install an active scheduler */
       
   104     iScheduler = new(ELeave)CActiveScheduler;
       
   105     CActiveScheduler::Install(iScheduler);
       
   106 
       
   107     }
       
   108 
       
   109 
       
   110 CTestModule* CTestModule::NewL()
       
   111     {
       
   112 
       
   113     // Construct new CTestModule instance.
       
   114     CTestModule* self = new ( ELeave ) CTestModule();    
       
   115     CleanupStack::PushL( self );
       
   116     self->ConstructL();
       
   117     CleanupStack::Pop();
       
   118 
       
   119     return self;
       
   120   
       
   121     }
       
   122 
       
   123 
       
   124 CTestModule::~CTestModule()
       
   125     {
       
   126     delete iTestSuite;
       
   127     delete iScheduler;
       
   128     }
       
   129 
       
   130 
       
   131 /*
       
   132 -------------------------------------------------------------------------------
       
   133 
       
   134     Class: CTestModule
       
   135 
       
   136     Method: GetTestCases
       
   137 
       
   138     Description: GetTestCases is used to inquire test cases 
       
   139     from the test module. Because this test module have hard coded test cases
       
   140     (i.e cases are not read from file), paramter aConfigFile is not used.
       
   141 
       
   142     This function loops through all cases defined in Cases() function and 
       
   143     adds corresponding items to aTestCases array.
       
   144 
       
   145     Parameters: const TFileName&  : in: Configuration file name. Not used                                                       
       
   146                 RPointerArray<TTestCaseInfo>& aTestCases: out: 
       
   147                       Array of TestCases.
       
   148     
       
   149     Return Values: KErrNone: No error
       
   150 
       
   151     Errors/Exceptions: Function leaves if any memory allocation operation fails
       
   152 
       
   153     Status: Proposal
       
   154     
       
   155 -------------------------------------------------------------------------------
       
   156 */      
       
   157 TInt CTestModule::GetTestCasesL( const TFileName& /*aConfigFile*/, 
       
   158                                      RPointerArray<TTestCaseInfo>& aTestCases )
       
   159     {
       
   160 
       
   161     // Loop through all test cases and create new
       
   162     // TTestCaseInfo items and append items to aTestCase array    
       
   163     for( TInt i = 0; i< iTestSuite->CountTestCases(); i++ )
       
   164         {
       
   165  
       
   166 	    // Allocate new TTestCaseInfo from heap for a testcase definition.
       
   167         TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo();
       
   168     
       
   169 	    // PushL TTestCaseInfo to CleanupStack.    
       
   170         CleanupStack::PushL( newCase );
       
   171 
       
   172 	    // Set number for the testcase.
       
   173 	    // When the testcase is run, this comes as a parameter to RunTestCaseL.
       
   174         newCase->iCaseNumber = i;
       
   175 
       
   176 	    // Set title for the test case. This is shown in UI to user.
       
   177         newCase->iTitle.Copy( iTestSuite->TestCaseName(i) );
       
   178 
       
   179 	    // Append TTestCaseInfo to the testcase array. After appended 
       
   180 	    // successfully the TTestCaseInfo object is owned (and freed) 
       
   181 	    // by the TestServer. 
       
   182         User::LeaveIfError(aTestCases.Append ( newCase ) );
       
   183         
       
   184 	    // Pop TTestCaseInfo from the CleanupStack.
       
   185         CleanupStack::Pop( newCase );
       
   186 
       
   187         }
       
   188     
       
   189     return KErrNone;
       
   190   
       
   191     }
       
   192 
       
   193 /*
       
   194 -------------------------------------------------------------------------------
       
   195 
       
   196     Class: CTestModule
       
   197 
       
   198     Method: RunTestCase
       
   199 
       
   200     Description: Run a specified testcase.
       
   201 
       
   202     Function runs a test case specified by test case number. Test case file
       
   203     parameter is not used.
       
   204 
       
   205     If case number is valid, this function runs a test case returned by
       
   206     function Cases(). 
       
   207   
       
   208     Parameters: const TInt aCaseNumber: in: Testcase number 
       
   209                 const TFileName& : in: Configuration file name. Not used
       
   210                 TTestResult& aResult: out: Testcase result
       
   211     
       
   212     Return Values: KErrNone: Testcase ran.
       
   213                    KErrNotFound: Unknown testcase
       
   214 
       
   215     Errors/Exceptions: None
       
   216     
       
   217     Status: Proposal
       
   218     
       
   219 -------------------------------------------------------------------------------
       
   220 */
       
   221 TInt CTestModule::RunTestCaseL( const TInt aCaseNumber, 
       
   222                                     const TFileName& /*aConfig*/,
       
   223                                     TTestResult& aResult )
       
   224     {
       
   225     // Next is a temporary solution for Stif memory leak error
       
   226     //TestModuleIf().SetBehavior(CTestModuleIf::ETestLeaksMem);
       
   227     // TestModuleIf().SetBehavior(CTestModuleIf::ETestLeaksRequests);
       
   228     // TestModuleIf().SetBehavior(CTestModuleIf::ETestLeaksHandles);
       
   229 
       
   230     if ( iAllocFailureType != RHeap::ENone )
       
   231         {
       
   232         RunTestCaseInOOMLoopL( aCaseNumber, aResult );
       
   233         }
       
   234     else
       
   235         {
       
   236         iTestSuite->ExecuteTestL( aResult, aCaseNumber );
       
   237         }
       
   238 
       
   239     // Return case execution status (not the result of the case execution)
       
   240     return KErrNone; 
       
   241     }
       
   242 
       
   243 
       
   244 /*
       
   245 */    
       
   246 
       
   247 void CTestModule::RunTestCaseInOOMLoopL( const TInt aCaseNumber,
       
   248                                         TTestResult& aResult )
       
   249     {
       
   250 
       
   251     // 
       
   252     TInt error = KErrNone; 
       
   253     aResult.SetResult( KErrNoMemory, _L("") ); // Initial value
       
   254 
       
   255     for (; ( aResult.iResult == KErrNoMemory ) && !error;)
       
   256         {      
       
   257         // Switches on alloc failure simulation if the parameters are set for it
       
   258         AllocFailureSimulation( ETrue ); 
       
   259         RDebug::Print(_L("*** OOM loop : %d ***\n"), iCurrentAllocFailureRate );
       
   260         TRAP( error, iTestSuite->ExecuteTestL( aResult, aCaseNumber ) );
       
   261         if ( error == KErrNoMemory )
       
   262             {
       
   263             error = KErrNone;
       
   264             }
       
   265         }
       
   266     
       
   267     //
       
   268     AllocFailureSimulation( EFalse );
       
   269     User::LeaveIfError( error ); 
       
   270     }
       
   271 
       
   272 
       
   273 /*
       
   274 */    
       
   275 
       
   276 void CTestModule::AllocFailureSimulation (TBool aSwitchedOn)
       
   277 	{
       
   278 	if (aSwitchedOn)
       
   279 		{
       
   280 		__UHEAP_SETFAIL ( iAllocFailureType, iCurrentAllocFailureRate );
       
   281         iCurrentAllocFailureRate++;
       
   282 		}
       
   283 	else
       
   284 		{
       
   285 		__UHEAP_RESET;
       
   286         iCurrentAllocFailureRate = iAllocFailureRate;
       
   287 		}
       
   288 	}
       
   289 
       
   290 
       
   291 /*
       
   292 */    
       
   293 
       
   294 void CTestModule::SetAllocFailureSimulation( RHeap::TAllocFail aAllocFailureType, TInt aAllocFailureRate )
       
   295     {
       
   296     iAllocFailureType = aAllocFailureType;
       
   297     iAllocFailureRate = aAllocFailureRate;
       
   298     iCurrentAllocFailureRate = aAllocFailureRate;
       
   299     }
       
   300 
       
   301 // ================= OTHER EXPORTED FUNCTIONS =================================
       
   302 
       
   303 /*
       
   304 -------------------------------------------------------------------------------
       
   305    
       
   306     Function: LibEntryL
       
   307 
       
   308     Description: Polymorphic Dll Entry Point
       
   309     
       
   310     Test framework calls this function to obtain new instance of test module
       
   311     class. 
       
   312 
       
   313     Parameters:    None
       
   314     
       
   315     Return Values: CTestModule*    Pointer to CTestModule instance
       
   316     
       
   317     Errors/Exceptions: Leaves if CTestModule::NewL leaves
       
   318     
       
   319     Status: Approved
       
   320 
       
   321 -------------------------------------------------------------------------------
       
   322 */
       
   323 EXPORT_C CTestModule* LibEntryL()
       
   324     {
       
   325     return CTestModule::NewL();
       
   326 
       
   327     }
       
   328 
       
   329 /*
       
   330 -------------------------------------------------------------------------------
       
   331    
       
   332     Function: E32Dll
       
   333 
       
   334     Description: DLL entry point function
       
   335     
       
   336     Parameters:    TDllReason: Not used
       
   337     
       
   338     Return Values: KErrNone: always
       
   339     
       
   340     Errors/Exceptions: None
       
   341 
       
   342     Status: Approved
       
   343 
       
   344 -------------------------------------------------------------------------------
       
   345 */
       
   346 #ifndef EKA2
       
   347 GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
       
   348     {
       
   349     return( KErrNone );
       
   350 
       
   351     }
       
   352 #endif
       
   353 
       
   354 // End of File