camera_plat/camcorder_ui_constants_api/tsrc/src/CamAppPerfTest.cpp
branchRCL_3
changeset 54 bac7acad7cb3
parent 0 1ddebce53859
equal deleted inserted replaced
53:61bc0f252b2b 54:bac7acad7cb3
       
     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:  CamAppPerfTest class member functions
       
    15 *
       
    16 */
       
    17 
       
    18 // [INCLUDE FILES] - do not remove
       
    19 #include <Stiftestinterface.h>
       
    20 #include "CamAppPerfTest.h"
       
    21 #include <SettingServerClient.h>
       
    22 
       
    23 // ============================ MEMBER FUNCTIONS ===============================
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // CCamAppPerfTest::CCamAppPerfTest
       
    27 // C++ default constructor can NOT contain any code, that
       
    28 // might leave.
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CCamAppPerfTest::CCamAppPerfTest()
       
    32     {
       
    33     // Do nothing
       
    34     }
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CCamAppPerfTest::ConstructL
       
    38 // Symbian 2nd phase constructor can leave.
       
    39 //
       
    40 // Note: If OOM test case uses STIF Logger, then STIF Logger must be created
       
    41 // with static buffer size parameter (aStaticBufferSize). Otherwise Logger 
       
    42 // allocates memory from heap and therefore causes error situations with OOM 
       
    43 // testing. For more information about STIF Logger construction, see STIF Users 
       
    44 // Guide.
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 void CCamAppPerfTest::ConstructL()
       
    48     {
       
    49     //Read logger settings to check whether test case name is to be
       
    50     //appended to log file name.
       
    51     RSettingServer settingServer;
       
    52     TInt ret = settingServer.Connect();
       
    53     if(ret != KErrNone)
       
    54         {
       
    55         User::Leave(ret);
       
    56         }
       
    57     // Struct to StifLogger settigs.
       
    58     TLoggerSettings loggerSettings; 
       
    59     // Parse StifLogger defaults from STIF initialization file.
       
    60     ret = settingServer.GetLoggerSettings(loggerSettings);
       
    61     if(ret != KErrNone)
       
    62         {
       
    63         User::Leave(ret);
       
    64         } 
       
    65     // Close Setting server session
       
    66     settingServer.Close();
       
    67     iAddTestCaseTitleToLogName = loggerSettings.iAddTestCaseTitle;
       
    68 
       
    69     iStdLog = CStifLogger::NewL( KCamAppPerfTestLogPath, 
       
    70                           KCamAppPerfTestLogFile);
       
    71     iLog = iStdLog;
       
    72 
       
    73     // Sample how to use logging
       
    74     _LIT( KLogStart, "CamAppPerfTest logging starts!" );
       
    75     iLog->Log( KLogStart );
       
    76 
       
    77     iVersionLogged = EFalse;
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CCamAppPerfTest::NewL
       
    82 // Two-phased constructor.
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 CCamAppPerfTest* CCamAppPerfTest::NewL()
       
    86     {
       
    87     CCamAppPerfTest* self = new (ELeave) CCamAppPerfTest;
       
    88 
       
    89     CleanupStack::PushL( self );
       
    90     self->ConstructL();
       
    91     CleanupStack::Pop();
       
    92 
       
    93     return self;
       
    94 
       
    95     }
       
    96 
       
    97 // Destructor
       
    98 CCamAppPerfTest::~CCamAppPerfTest()
       
    99     {
       
   100     iLog = NULL;
       
   101     delete iStdLog;
       
   102     iStdLog = NULL;
       
   103     delete iTCLog;
       
   104     iTCLog = NULL;
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CCamAppPerfTest::InitL
       
   109 // InitL is used to initialize the Test Module.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 TInt CCamAppPerfTest::InitL( 
       
   113     TFileName& /*aIniFile*/, 
       
   114     TBool /*aFirstTime*/ )
       
   115     {
       
   116     return KErrNone;
       
   117 
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CCamAppPerfTest::GetTestCasesL
       
   122 // GetTestCases is used to inquire test cases from the Test Module. Test
       
   123 // cases are stored to array of test cases. The Test Framework will be 
       
   124 // the owner of the data in the RPointerArray after GetTestCases return
       
   125 // and it does the memory deallocation. 
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 TInt CCamAppPerfTest::GetTestCasesL( 
       
   129     const TFileName& /*aConfig*/, 
       
   130     RPointerArray<TTestCaseInfo>& aTestCases )
       
   131     {
       
   132 
       
   133     // Loop through all test cases and create new
       
   134     // TTestCaseInfo items and append items to aTestCase array    
       
   135     for( TInt i = 0; Case(i).iMethod != NULL; i++ )
       
   136         {
       
   137 
       
   138         // Allocate new TTestCaseInfo from heap for a testcase definition.
       
   139         TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo();
       
   140 
       
   141         // PushL TTestCaseInfo to CleanupStack.    
       
   142         CleanupStack::PushL( newCase );
       
   143 
       
   144         // Set number for the testcase.
       
   145         // When the testcase is run, this comes as a parameter to RunTestCaseL.
       
   146         newCase->iCaseNumber = i;
       
   147 
       
   148         // Set title for the test case. This is shown in UI to user.
       
   149         newCase->iTitle.Copy( Case(i).iCaseName );
       
   150 
       
   151         // Append TTestCaseInfo to the testcase array. After appended 
       
   152         // successfully the TTestCaseInfo object is owned (and freed) 
       
   153         // by the TestServer. 
       
   154         User::LeaveIfError(aTestCases.Append ( newCase ) );
       
   155 
       
   156         // Pop TTestCaseInfo from the CleanupStack.
       
   157         CleanupStack::Pop( newCase );
       
   158 
       
   159         }
       
   160 
       
   161     return KErrNone;
       
   162 
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CCamAppPerfTest::RunTestCaseL
       
   167 // RunTestCaseL is used to run an individual test case specified 
       
   168 // by aTestCase. Test cases that can be run may be requested from 
       
   169 // Test Module by GetTestCases method before calling RunTestCase.
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 TInt CCamAppPerfTest::RunTestCaseL( 
       
   173     const TInt aCaseNumber,   
       
   174     const TFileName& /*aConfig*/,
       
   175     TTestResult& aResult )
       
   176     {
       
   177     if(!iVersionLogged)
       
   178     	{
       
   179     	SendTestModuleVersion();
       
   180     	iVersionLogged = ETrue;
       
   181     	}
       
   182     
       
   183     // Return value
       
   184     TInt execStatus = KErrNone;
       
   185 
       
   186     // Get the pointer to test case function
       
   187     TCaseInfo tmp = Case ( aCaseNumber );
       
   188 
       
   189     _LIT( KLogStartTC, "Starting testcase [%S]" );
       
   190     iLog->Log( KLogStartTC, &tmp.iCaseName);
       
   191 
       
   192     // Check that case number was valid
       
   193     if ( tmp.iMethod != NULL )
       
   194         {
       
   195         //Open new log file with test case title in file name
       
   196         if(iAddTestCaseTitleToLogName)
       
   197             {
       
   198             //Delete test case logger if exists
       
   199             if(iTCLog)
       
   200                 {
       
   201                 delete iTCLog;
       
   202                 iTCLog = NULL;
       
   203                 }
       
   204 
       
   205             TFileName logFileName;
       
   206             TName title;
       
   207             TestModuleIf().GetTestCaseTitleL(title);
       
   208         
       
   209             logFileName.Format(KCamAppPerfTestLogFileWithTitle, &title);
       
   210 
       
   211             iTCLog = CStifLogger::NewL(KCamAppPerfTestLogPath, 
       
   212                                        logFileName);
       
   213             iLog = iTCLog;                                       
       
   214             }
       
   215 
       
   216         // Valid case was found, call it via function pointer
       
   217         iMethod = tmp.iMethod;        
       
   218         //execStatus  = ( this->*iMethod )( aResult );
       
   219         TRAPD(err, execStatus  = ( this->*iMethod )( aResult ));
       
   220         if(iAddTestCaseTitleToLogName)
       
   221             {
       
   222             //Restore standard log and destroy test case logger
       
   223             iLog = iStdLog;
       
   224             delete iTCLog; //Close test case log
       
   225             iTCLog = NULL;
       
   226             }
       
   227         User::LeaveIfError(err);
       
   228         }
       
   229     else
       
   230         {
       
   231         // Valid case was not found, return error.
       
   232         execStatus = KErrNotFound;
       
   233         }
       
   234 
       
   235     // Return case execution status (not the result of the case execution)
       
   236     return execStatus;
       
   237 
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CCamAppPerfTest::OOMTestQueryL
       
   242 // Used to check if a particular test case should be run in OOM conditions and 
       
   243 // which memory allocations should fail.    
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 TBool CCamAppPerfTest::OOMTestQueryL( 
       
   247                                 const TFileName& /* aTestCaseFile */, 
       
   248                                 const TInt aCaseNumber, 
       
   249                                 TOOMFailureType& /* aFailureType */, 
       
   250                                 TInt& aFirstMemFailure, 
       
   251                                 TInt& aLastMemFailure ) 
       
   252     {
       
   253     _LIT( KLogOOMTestQueryL, "CCamAppPerfTest::OOMTestQueryL" );
       
   254     iLog->Log( KLogOOMTestQueryL );     
       
   255 
       
   256     aFirstMemFailure = Case( aCaseNumber ).iFirstMemoryAllocation;
       
   257     aLastMemFailure = Case( aCaseNumber ).iLastMemoryAllocation;
       
   258 
       
   259     return Case( aCaseNumber ).iIsOOMTest;
       
   260 
       
   261     }
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CCamAppPerfTest::OOMTestInitializeL
       
   265 // Used to perform the test environment setup for a particular OOM test case. 
       
   266 // Test Modules may use the initialization file to read parameters for Test 
       
   267 // Module initialization but they can also have their own configure file or 
       
   268 // some other routine to initialize themselves.  
       
   269 //
       
   270 // NOTE: User may add implementation for OOM test environment initialization.
       
   271 // Usually no implementation is required.
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 void CCamAppPerfTest::OOMTestInitializeL( 
       
   275                                 const TFileName& /* aTestCaseFile */, 
       
   276                                 const TInt /* aCaseNumber */ )
       
   277     {
       
   278     }
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // CCamAppPerfTest::OOMHandleWarningL
       
   282 // In some cases the heap memory allocation should be skipped, either due to
       
   283 // problems in the OS code or components used by the code being tested, or even 
       
   284 // inside the tested components which are implemented this way on purpose (by 
       
   285 // design), so it is important to give the tester a way to bypass allocation 
       
   286 // failures.
       
   287 //
       
   288 // NOTE: User may add implementation for OOM test warning handling. Usually no
       
   289 // implementation is required.
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 void CCamAppPerfTest::OOMHandleWarningL( 
       
   293                                 const TFileName& /* aTestCaseFile */,
       
   294                                 const TInt /* aCaseNumber */, 
       
   295                                 TInt& /* aFailNextValue */ )
       
   296     {
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // CCamAppPerfTest::OOMTestFinalizeL
       
   301 // Used to perform the test environment cleanup for a particular OOM test case.
       
   302 //
       
   303 // NOTE: User may add implementation for OOM test environment finalization.
       
   304 // Usually no implementation is required.
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 void CCamAppPerfTest::OOMTestFinalizeL( 
       
   308                                 const TFileName& /* aTestCaseFile */, 
       
   309                                 const TInt /* aCaseNumber */ )
       
   310     {
       
   311     }
       
   312 
       
   313 //-----------------------------------------------------------------------------
       
   314 // CCamAppPerfTest::SendTestModuleVersion
       
   315 // Method used to send version of test module
       
   316 //-----------------------------------------------------------------------------
       
   317 //
       
   318 void CCamAppPerfTest::SendTestModuleVersion()
       
   319 	{
       
   320 	TVersion moduleVersion;
       
   321 	moduleVersion.iMajor = TEST_MODULE_VERSION_MAJOR;
       
   322 	moduleVersion.iMinor = TEST_MODULE_VERSION_MINOR;
       
   323 	moduleVersion.iBuild = TEST_MODULE_VERSION_BUILD;
       
   324 	
       
   325 	TFileName moduleName;
       
   326 	moduleName = _L("CamAppPerfTest.dll");
       
   327 
       
   328 	TBool newVersionOfMethod = ETrue;
       
   329 	TestModuleIf().SendTestModuleVersion(moduleVersion, moduleName, newVersionOfMethod);
       
   330 	}
       
   331 
       
   332 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // LibEntryL is a polymorphic Dll entry point
       
   336 // Returns: CTestModuleBase*: Pointer to Test Module object
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 EXPORT_C CTestModuleBase* LibEntryL()
       
   340     {
       
   341     return CCamAppPerfTest::NewL();
       
   342 
       
   343     }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // SetRequirements handles test module parameters(implements evolution
       
   347 // version 1 for test module's heap and stack sizes configuring).
       
   348 // Returns: TInt: Symbian error code.
       
   349 // -----------------------------------------------------------------------------
       
   350 //
       
   351 EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/, 
       
   352                                 TUint32& /*aParameterValid*/ )
       
   353     {
       
   354     return KErrNone;
       
   355     }
       
   356 
       
   357 
       
   358 //  End of File