phonebookui/Phonebook2/ccapplication/ccacommlauncherplugin/tsrc/ut_commlaunchercontacthandler/src/t_commlaunchercontacthandler.cpp
changeset 0 e686773b3f54
child 7 b3431bff8c19
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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:  t_commlaunchercontacthandler class member functions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // [INCLUDE FILES] - do not remove
       
    21 #include <Stiftestinterface.h>
       
    22 #include <SettingServerClient.h>
       
    23 #include "t_commlaunchercontacthandler.h"
       
    24 
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ===============================
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // T_CCCAppCommLauncherContactHandler::T_CCCAppCommLauncherContactHandler
       
    30 // C++ default constructor can NOT contain any code, that
       
    31 // might leave.
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 T_CCCAppCommLauncherContactHandler::T_CCCAppCommLauncherContactHandler()
       
    35     {
       
    36 
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // T_CCCAppCommLauncherContactHandler::ConstructL
       
    41 // Symbian 2nd phase constructor can leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 void T_CCCAppCommLauncherContactHandler::ConstructL()
       
    45     {
       
    46     //Read logger settings to check whether test case name is to be
       
    47     //appended to log file name.
       
    48     RSettingServer settingServer;
       
    49     TInt ret = settingServer.Connect();
       
    50     if(ret != KErrNone)
       
    51         {
       
    52         User::Leave(ret);
       
    53         }
       
    54     // Struct to StifLogger settigs.
       
    55     TLoggerSettings loggerSettings; 
       
    56     // Parse StifLogger defaults from STIF initialization file.
       
    57     ret = settingServer.GetLoggerSettings(loggerSettings);
       
    58     if(ret != KErrNone)
       
    59         {
       
    60         User::Leave(ret);
       
    61         } 
       
    62     // Close Setting server session
       
    63     settingServer.Close();
       
    64     iAddTestCaseTitleToLogName = loggerSettings.iAddTestCaseTitle;
       
    65 
       
    66     iStdLog = CStifLogger::NewL( Kt_commlaunchercontacthandlerLogPath, 
       
    67                           Kt_commlaunchercontacthandlerLogFile);
       
    68     iLog = iStdLog;
       
    69 
       
    70     // Sample how to use logging
       
    71     _LIT( KLogStart, "t_commlaunchercontacthandler logging starts!" );
       
    72     iLog->Log( KLogStart );
       
    73 
       
    74     iVersionLogged = EFalse;
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // T_CCCAppCommLauncherContactHandler::NewL
       
    79 // Two-phased constructor.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 T_CCCAppCommLauncherContactHandler* T_CCCAppCommLauncherContactHandler::NewL()
       
    83     {
       
    84     T_CCCAppCommLauncherContactHandler* self = new (ELeave) T_CCCAppCommLauncherContactHandler;
       
    85 
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     CleanupStack::Pop();
       
    89 
       
    90     return self;
       
    91 
       
    92     }
       
    93 // -----------------------------------------------------------------------------
       
    94 // T_CCCAppCommLauncherContactHandler::~T_CCCAppCommLauncherContactHandler
       
    95 // Destructor
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 T_CCCAppCommLauncherContactHandler::~T_CCCAppCommLauncherContactHandler()
       
    99     {
       
   100     iLog = NULL;
       
   101     delete iStdLog;
       
   102     iStdLog = NULL;
       
   103     delete iTCLog;
       
   104     iTCLog = NULL;
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // T_CCCAppCommLauncherContactHandler::InitL
       
   109 // InitL is used to initialize the Test Module.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 TInt T_CCCAppCommLauncherContactHandler::InitL( 
       
   113     TFileName& /*aIniFile*/, 
       
   114     TBool /*aFirstTime*/ )
       
   115     {
       
   116     return KErrNone;
       
   117 
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // T_CCCAppCommLauncherContactHandler::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 T_CCCAppCommLauncherContactHandler::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 // T_CCCAppCommLauncherContactHandler::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 T_CCCAppCommLauncherContactHandler::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(Kt_commlaunchercontacthandlerLogFileWithTitle, &title);
       
   210 
       
   211             iTCLog = CStifLogger::NewL(Kt_commlaunchercontacthandlerLogPath, 
       
   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 // T_CCCAppCommLauncherContactHandler::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 T_CCCAppCommLauncherContactHandler::OOMTestQueryL( 
       
   247                                 const TFileName& /* aTestCaseFile */, 
       
   248                                 const TInt aCaseNumber, 
       
   249                                 TOOMFailureType& /* aFailureType */, 
       
   250                                 TInt& aFirstMemFailure, 
       
   251                                 TInt& aLastMemFailure ) 
       
   252     {
       
   253     _LIT( KLogOOMTestQueryL, "T_CCCAppCommLauncherContactHandler::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 // T_CCCAppCommLauncherContactHandler::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 T_CCCAppCommLauncherContactHandler::OOMTestInitializeL( 
       
   275                                 const TFileName& /* aTestCaseFile */, 
       
   276                                 const TInt /* aCaseNumber */ )
       
   277     {
       
   278     }
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // T_CCCAppCommLauncherContactHandler::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 T_CCCAppCommLauncherContactHandler::OOMHandleWarningL( 
       
   293                                 const TFileName& /* aTestCaseFile */,
       
   294                                 const TInt /* aCaseNumber */, 
       
   295                                 TInt& /* aFailNextValue */ )
       
   296     {
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // T_CCCAppCommLauncherContactHandler::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 T_CCCAppCommLauncherContactHandler::OOMTestFinalizeL( 
       
   308                                 const TFileName& /* aTestCaseFile */, 
       
   309                                 const TInt /* aCaseNumber */ )
       
   310     {
       
   311     }
       
   312     
       
   313 
       
   314 
       
   315 
       
   316 //-----------------------------------------------------------------------------
       
   317 // T_CCCAppCommLauncherContactHandler::SendTestModuleVersion
       
   318 // Method used to send version of test module
       
   319 //-----------------------------------------------------------------------------
       
   320 //
       
   321 void T_CCCAppCommLauncherContactHandler::SendTestModuleVersion()
       
   322 	{
       
   323 	TVersion moduleVersion;
       
   324 	moduleVersion.iMajor = TEST_MODULE_VERSION_MAJOR;
       
   325 	moduleVersion.iMinor = TEST_MODULE_VERSION_MINOR;
       
   326 	moduleVersion.iBuild = TEST_MODULE_VERSION_BUILD;
       
   327 	
       
   328 	TFileName moduleName;
       
   329 	moduleName = _L("t_commlaunchercontacthandler.dll");
       
   330 
       
   331 	TestModuleIf().SendTestModuleVersion(moduleVersion, moduleName);
       
   332 	}
       
   333 
       
   334 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   335 
       
   336 // -----------------------------------------------------------------------------
       
   337 // LibEntryL is a polymorphic Dll entry point
       
   338 // Returns: CTestModuleBase*: Pointer to Test Module object
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341 EXPORT_C CTestModuleBase* LibEntryL()
       
   342     {
       
   343     return T_CCCAppCommLauncherContactHandler::NewL();
       
   344 
       
   345     }
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // SetRequirements handles test module parameters(implements evolution
       
   349 // version 1 for test module's heap and stack sizes configuring).
       
   350 // Returns: TInt: Symbian error code.
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/, 
       
   354                                 TUint32& /*aParameterValid*/ )
       
   355     {
       
   356 
       
   357     /* --------------------------------- NOTE ---------------------------------
       
   358     USER PANICS occurs in test thread creation when:
       
   359     1) "The panic occurs when the value of the stack size is negative."
       
   360     2) "The panic occurs if the minimum heap size specified is less
       
   361        than KMinHeapSize".
       
   362        KMinHeapSize: "Functions that require a new heap to be allocated will
       
   363        either panic, or will reset the required heap size to this value if
       
   364        a smaller heap size is specified".
       
   365     3) "The panic occurs if the minimum heap size specified is greater than
       
   366        the maximum size to which the heap can grow".
       
   367     Other:
       
   368     1) Make sure that your hardware or Symbian OS is supporting given sizes.
       
   369        e.g. Hardware might support only sizes that are divisible by four.
       
   370     ------------------------------- NOTE end ------------------------------- */
       
   371 
       
   372     // Normally STIF uses default heap and stack sizes for test thread, see:
       
   373     // KTestThreadMinHeap, KTestThreadMinHeap and KStackSize.
       
   374     // If needed heap and stack sizes can be configured here by user. Remove
       
   375     // comments and define sizes.
       
   376 
       
   377 /*
       
   378     aParameterValid = KStifTestModuleParameterChanged;
       
   379 
       
   380     CTestModuleParamVer01* param = CTestModuleParamVer01::NewL();
       
   381     // Stack size
       
   382     param->iTestThreadStackSize= 16384; // 16K stack
       
   383     // Heap sizes
       
   384     param->iTestThreadMinHeap = 4096;   // 4K heap min
       
   385     param->iTestThreadMaxHeap = 1048576;// 1M heap max
       
   386 
       
   387     aTestModuleParam = param;
       
   388 */
       
   389     return KErrNone;
       
   390 
       
   391     }
       
   392 
       
   393 
       
   394 //  End of File