imservices/xmppsettingsfetcher/tsrc/xmppsettingsfetchermt/src/xmppsettingsfetchermt.cpp
changeset 0 e6b17d312c8b
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     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:  xmppsettingsfetchermt class member functions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // [INCLUDE FILES] - do not remove
       
    21 #include <StifTestInterface.h>
       
    22 #include "xmppsettingsfetchermt.h"
       
    23 #include <SettingServerClient.h>
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 //extern  ?external_data;
       
    27 
       
    28 // EXTERNAL FUNCTION PROTOTYPES  
       
    29 //extern ?external_function( ?arg_type,?arg_type );
       
    30 
       
    31 // CONSTANTS
       
    32 //const ?type ?constant_var = ?constant;
       
    33 
       
    34 // MACROS
       
    35 //#define ?macro ?macro_def
       
    36 
       
    37 // LOCAL CONSTANTS AND MACROS
       
    38 //const ?type ?constant_var = ?constant;
       
    39 //#define ?macro_name ?macro_def
       
    40 
       
    41 // MODULE DATA STRUCTURES
       
    42 //enum ?declaration
       
    43 //typedef ?declaration
       
    44 
       
    45 // LOCAL FUNCTION PROTOTYPES
       
    46 //?type ?function_name( ?arg_type, ?arg_type );
       
    47 
       
    48 // FORWARD DECLARATIONS
       
    49 //class ?FORWARD_CLASSNAME;
       
    50 
       
    51 // ============================= LOCAL FUNCTIONS ===============================
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // ?function_name ?description.
       
    55 // ?description
       
    56 // Returns: ?value_1: ?description
       
    57 //          ?value_n: ?description_line1
       
    58 //                    ?description_line2
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 /*
       
    62 ?type ?function_name(
       
    63     ?arg_type arg,  // ?description
       
    64     ?arg_type arg)  // ?description
       
    65     {
       
    66 
       
    67     ?code  // ?comment
       
    68 
       
    69     // ?comment
       
    70     ?code
       
    71     }
       
    72 */
       
    73 
       
    74 // ============================ MEMBER FUNCTIONS ===============================
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // Cxmppsettingsfetchermt::Cxmppsettingsfetchermt
       
    78 // C++ default constructor can NOT contain any code, that
       
    79 // might leave.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 Cxmppsettingsfetchermt::Cxmppsettingsfetchermt()
       
    83     {
       
    84 
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // Cxmppsettingsfetchermt::ConstructL
       
    89 // Symbian 2nd phase constructor can leave.
       
    90 //
       
    91 // Note: If OOM test case uses STIF Logger, then STIF Logger must be created
       
    92 // with static buffer size parameter (aStaticBufferSize). Otherwise Logger 
       
    93 // allocates memory from heap and therefore causes error situations with OOM 
       
    94 // testing. For more information about STIF Logger construction, see STIF Users 
       
    95 // Guide.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void Cxmppsettingsfetchermt::ConstructL()
       
    99     {
       
   100     //Read logger settings to check whether test case name is to be
       
   101     //appended to log file name.
       
   102     RSettingServer settingServer;
       
   103     TInt ret = settingServer.Connect();
       
   104     if(ret != KErrNone)
       
   105         {
       
   106         User::Leave(ret);
       
   107         }
       
   108     // Struct to StifLogger settigs.
       
   109     TLoggerSettings loggerSettings; 
       
   110     // Parse StifLogger defaults from STIF initialization file.
       
   111     ret = settingServer.GetLoggerSettings(loggerSettings);
       
   112     if(ret != KErrNone)
       
   113         {
       
   114         User::Leave(ret);
       
   115         } 
       
   116     // Close Setting server session
       
   117     settingServer.Close();
       
   118     iAddTestCaseTitleToLogName = loggerSettings.iAddTestCaseTitle;
       
   119 
       
   120     iStdLog = CStifLogger::NewL( KxmppsettingsfetchermtLogPath, 
       
   121                           KxmppsettingsfetchermtLogFile);
       
   122     iLog = iStdLog;
       
   123 
       
   124     // Sample how to use logging
       
   125     _LIT( KLogStart, "xmppsettingsfetchermt logging starts!" );
       
   126     iLog->Log( KLogStart );
       
   127 
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // Cxmppsettingsfetchermt::NewL
       
   132 // Two-phased constructor.
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 Cxmppsettingsfetchermt* Cxmppsettingsfetchermt::NewL()
       
   136     {
       
   137     Cxmppsettingsfetchermt* self = new (ELeave) Cxmppsettingsfetchermt;
       
   138 
       
   139     CleanupStack::PushL( self );
       
   140     self->ConstructL();
       
   141     CleanupStack::Pop();
       
   142 
       
   143     return self;
       
   144 
       
   145     }
       
   146 
       
   147 // Destructor
       
   148 Cxmppsettingsfetchermt::~Cxmppsettingsfetchermt()
       
   149     {
       
   150     iLog = NULL;
       
   151     delete iStdLog;
       
   152     iStdLog = NULL;
       
   153     delete iTCLog;
       
   154     iTCLog = NULL;
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // Cxmppsettingsfetchermt::InitL
       
   159 // InitL is used to initialize the Test Module.
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 TInt Cxmppsettingsfetchermt::InitL( 
       
   163     TFileName& /*aIniFile*/, 
       
   164     TBool /*aFirstTime*/ )
       
   165     {
       
   166     return KErrNone;
       
   167 
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // Cxmppsettingsfetchermt::GetTestCasesL
       
   172 // GetTestCases is used to inquire test cases from the Test Module. Test
       
   173 // cases are stored to array of test cases. The Test Framework will be 
       
   174 // the owner of the data in the RPointerArray after GetTestCases return
       
   175 // and it does the memory deallocation. 
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 TInt Cxmppsettingsfetchermt::GetTestCasesL( 
       
   179     const TFileName& /*aConfig*/, 
       
   180     RPointerArray<TTestCaseInfo>& aTestCases )
       
   181     {
       
   182 
       
   183     // Loop through all test cases and create new
       
   184     // TTestCaseInfo items and append items to aTestCase array    
       
   185     for( TInt i = 0; Case(i).iMethod != NULL; i++ )
       
   186         {
       
   187 
       
   188         // Allocate new TTestCaseInfo from heap for a testcase definition.
       
   189         TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo();
       
   190 
       
   191         // PushL TTestCaseInfo to CleanupStack.    
       
   192         CleanupStack::PushL( newCase );
       
   193 
       
   194         // Set number for the testcase.
       
   195         // When the testcase is run, this comes as a parameter to RunTestCaseL.
       
   196         newCase->iCaseNumber = i;
       
   197 
       
   198         // Set title for the test case. This is shown in UI to user.
       
   199         newCase->iTitle.Copy( Case(i).iCaseName );
       
   200 
       
   201         // Append TTestCaseInfo to the testcase array. After appended 
       
   202         // successfully the TTestCaseInfo object is owned (and freed) 
       
   203         // by the TestServer. 
       
   204         User::LeaveIfError(aTestCases.Append ( newCase ) );
       
   205 
       
   206         // Pop TTestCaseInfo from the CleanupStack.
       
   207         CleanupStack::Pop( newCase );
       
   208 
       
   209         }
       
   210 
       
   211     return KErrNone;
       
   212 
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // Cxmppsettingsfetchermt::RunTestCaseL
       
   217 // RunTestCaseL is used to run an individual test case specified 
       
   218 // by aTestCase. Test cases that can be run may be requested from 
       
   219 // Test Module by GetTestCases method before calling RunTestCase.
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 TInt Cxmppsettingsfetchermt::RunTestCaseL( 
       
   223     const TInt aCaseNumber,   
       
   224     const TFileName& /*aConfig*/,
       
   225     TTestResult& aResult )
       
   226     {
       
   227 
       
   228     // Return value
       
   229     TInt execStatus = KErrNone;
       
   230 
       
   231     // Get the pointer to test case function
       
   232     TCaseInfo tmp = Case ( aCaseNumber );
       
   233 
       
   234     _LIT( KLogStartTC, "Starting testcase [%S]" );
       
   235     iLog->Log( KLogStartTC, &tmp.iCaseName);
       
   236 
       
   237     // Check that case number was valid
       
   238     if ( tmp.iMethod != NULL )
       
   239         {
       
   240         //Open new log file with test case title in file name
       
   241         if(iAddTestCaseTitleToLogName)
       
   242             {
       
   243             //Delete test case logger if exists
       
   244             if(iTCLog)
       
   245                 {
       
   246                 delete iTCLog;
       
   247                 iTCLog = NULL;
       
   248                 }
       
   249 
       
   250             TFileName logFileName;
       
   251             TName title;
       
   252             TestModuleIf().GetTestCaseTitleL(title);
       
   253         
       
   254             logFileName.Format(KxmppsettingsfetchermtLogFileWithTitle, &title);
       
   255 
       
   256             iTCLog = CStifLogger::NewL(KxmppsettingsfetchermtLogPath, 
       
   257                                        logFileName);
       
   258             iLog = iTCLog;                                       
       
   259             }
       
   260 
       
   261         // Valid case was found, call it via function pointer
       
   262         iMethod = tmp.iMethod;        
       
   263         //execStatus  = ( this->*iMethod )( aResult );
       
   264         TRAPD(err, execStatus  = ( this->*iMethod )( aResult ));
       
   265         if(iAddTestCaseTitleToLogName)
       
   266             {
       
   267             //Restore standard log and destroy test case logger
       
   268             iLog = iStdLog;
       
   269             delete iTCLog; //Close test case log
       
   270             iTCLog = NULL;
       
   271             }
       
   272         User::LeaveIfError(err);
       
   273         }
       
   274     else
       
   275         {
       
   276         // Valid case was not found, return error.
       
   277         execStatus = KErrNotFound;
       
   278         }
       
   279 
       
   280     // Return case execution status (not the result of the case execution)
       
   281     return execStatus;
       
   282 
       
   283     }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // Cxmppsettingsfetchermt::OOMTestQueryL
       
   287 // Used to check if a particular test case should be run in OOM conditions and 
       
   288 // which memory allocations should fail.    
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 TBool Cxmppsettingsfetchermt::OOMTestQueryL( 
       
   292                                 const TFileName& /* aTestCaseFile */, 
       
   293                                 const TInt aCaseNumber, 
       
   294                                 TOOMFailureType& /* aFailureType */, 
       
   295                                 TInt& aFirstMemFailure, 
       
   296                                 TInt& aLastMemFailure ) 
       
   297     {
       
   298     _LIT( KLogOOMTestQueryL, "Cxmppsettingsfetchermt::OOMTestQueryL" );
       
   299     iLog->Log( KLogOOMTestQueryL );     
       
   300 
       
   301     aFirstMemFailure = Case( aCaseNumber ).iFirstMemoryAllocation;
       
   302     aLastMemFailure = Case( aCaseNumber ).iLastMemoryAllocation;
       
   303 
       
   304     return Case( aCaseNumber ).iIsOOMTest;
       
   305 
       
   306     }
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // Cxmppsettingsfetchermt::OOMTestInitializeL
       
   310 // Used to perform the test environment setup for a particular OOM test case. 
       
   311 // Test Modules may use the initialization file to read parameters for Test 
       
   312 // Module initialization but they can also have their own configure file or 
       
   313 // some other routine to initialize themselves.  
       
   314 //
       
   315 // NOTE: User may add implementation for OOM test environment initialization.
       
   316 // Usually no implementation is required.
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 void Cxmppsettingsfetchermt::OOMTestInitializeL( 
       
   320                                 const TFileName& /* aTestCaseFile */, 
       
   321                                 const TInt /* aCaseNumber */ )
       
   322     {
       
   323     }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // Cxmppsettingsfetchermt::OOMHandleWarningL
       
   327 // In some cases the heap memory allocation should be skipped, either due to
       
   328 // problems in the OS code or components used by the code being tested, or even 
       
   329 // inside the tested components which are implemented this way on purpose (by 
       
   330 // design), so it is important to give the tester a way to bypass allocation 
       
   331 // failures.
       
   332 //
       
   333 // NOTE: User may add implementation for OOM test warning handling. Usually no
       
   334 // implementation is required.
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 void Cxmppsettingsfetchermt::OOMHandleWarningL( 
       
   338                                 const TFileName& /* aTestCaseFile */,
       
   339                                 const TInt /* aCaseNumber */, 
       
   340                                 TInt& /* aFailNextValue */ )
       
   341     {
       
   342     }
       
   343 
       
   344 // -----------------------------------------------------------------------------
       
   345 // Cxmppsettingsfetchermt::OOMTestFinalizeL
       
   346 // Used to perform the test environment cleanup for a particular OOM test case.
       
   347 //
       
   348 // NOTE: User may add implementation for OOM test environment finalization.
       
   349 // Usually no implementation is required.
       
   350 // -----------------------------------------------------------------------------
       
   351 //
       
   352 void Cxmppsettingsfetchermt::OOMTestFinalizeL( 
       
   353                                 const TFileName& /* aTestCaseFile */, 
       
   354                                 const TInt /* aCaseNumber */ )
       
   355     {
       
   356     }
       
   357 
       
   358 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 // LibEntryL is a polymorphic Dll entry point
       
   362 // Returns: CTestModuleBase*: Pointer to Test Module object
       
   363 // -----------------------------------------------------------------------------
       
   364 //
       
   365 EXPORT_C CTestModuleBase* LibEntryL()
       
   366     {
       
   367     return Cxmppsettingsfetchermt::NewL();
       
   368 
       
   369     }
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // SetRequirements handles test module parameters(implements evolution
       
   373 // version 1 for test module's heap and stack sizes configuring).
       
   374 // Returns: TInt: Symbian error code.
       
   375 // -----------------------------------------------------------------------------
       
   376 //
       
   377 EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/, 
       
   378                                 TUint32& /*aParameterValid*/ )
       
   379     {
       
   380 
       
   381     /* --------------------------------- NOTE ---------------------------------
       
   382     USER PANICS occurs in test thread creation when:
       
   383     1) "The panic occurs when the value of the stack size is negative."
       
   384     2) "The panic occurs if the minimum heap size specified is less
       
   385        than KMinHeapSize".
       
   386        KMinHeapSize: "Functions that require a new heap to be allocated will
       
   387        either panic, or will reset the required heap size to this value if
       
   388        a smaller heap size is specified".
       
   389     3) "The panic occurs if the minimum heap size specified is greater than
       
   390        the maximum size to which the heap can grow".
       
   391     Other:
       
   392     1) Make sure that your hardware or Symbian OS is supporting given sizes.
       
   393        e.g. Hardware might support only sizes that are divisible by four.
       
   394     ------------------------------- NOTE end ------------------------------- */
       
   395 
       
   396     // Normally STIF uses default heap and stack sizes for test thread, see:
       
   397     // KTestThreadMinHeap, KTestThreadMinHeap and KStackSize.
       
   398     // If needed heap and stack sizes can be configured here by user. Remove
       
   399     // comments and define sizes.
       
   400 
       
   401 /*
       
   402     aParameterValid = KStifTestModuleParameterChanged;
       
   403 
       
   404     CTestModuleParamVer01* param = CTestModuleParamVer01::NewL();
       
   405     // Stack size
       
   406     param->iTestThreadStackSize= 16384; // 16K stack
       
   407     // Heap sizes
       
   408     param->iTestThreadMinHeap = 4096;   // 4K heap min
       
   409     param->iTestThreadMaxHeap = 1048576;// 1M heap max
       
   410 
       
   411     aTestModuleParam = param;
       
   412 */
       
   413     return KErrNone;
       
   414 
       
   415     }
       
   416 
       
   417 
       
   418 //  End of File