emailservices/emailstore/tsrc/bufferedmsgcreator_test/src/t_bufferedmsgcreator.cpp
changeset 1 12c456ceeff2
equal deleted inserted replaced
0:8466d47a6819 1:12c456ceeff2
       
     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_msgstore class member functions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // [INCLUDE FILES] - do not remove
       
    21 #include <Stiftestinterface.h>
       
    22 #include "t_bufferedmsgcreatore.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 // Ct_msgstore::Ct_msgstore
       
    78 // C++ default constructor can NOT contain any code, that
       
    79 // might leave.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 Ct_bufferedmsgcreator::Ct_bufferedmsgcreator()
       
    83     {
       
    84 
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // Ct_msgstore::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 Ct_bufferedmsgcreator::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( Kt_msgstoreLogPath, 
       
   121                           Kt_msgstoreLogFile);
       
   122     iLog = iStdLog;
       
   123 
       
   124     // Sample how to use logging
       
   125     _LIT( KLogStart, "t_msgstore logging starts!" );
       
   126     iLog->Log( KLogStart );
       
   127 
       
   128     iVersionLogged = EFalse;
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // Ct_msgstore::NewL
       
   133 // Two-phased constructor.
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 Ct_bufferedmsgcreator* Ct_bufferedmsgcreator::NewL()
       
   137     {
       
   138     Ct_bufferedmsgcreator* self = new (ELeave) Ct_bufferedmsgcreator;
       
   139 
       
   140     CleanupStack::PushL( self );
       
   141     self->ConstructL();
       
   142     CleanupStack::Pop();
       
   143 
       
   144     return self;
       
   145 
       
   146     }
       
   147 
       
   148 // Destructor
       
   149 Ct_bufferedmsgcreator::~Ct_bufferedmsgcreator()
       
   150     {
       
   151     iLog = NULL;
       
   152     delete iStdLog;
       
   153     iStdLog = NULL;
       
   154     delete iTCLog;
       
   155     iTCLog = NULL;
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // Ct_msgstore::InitL
       
   160 // InitL is used to initialize the Test Module.
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 TInt Ct_bufferedmsgcreator::InitL( 
       
   164     TFileName& /*aIniFile*/, 
       
   165     TBool /*aFirstTime*/ )
       
   166     {
       
   167     return KErrNone;
       
   168 
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // Ct_msgstore::GetTestCasesL
       
   173 // GetTestCases is used to inquire test cases from the Test Module. Test
       
   174 // cases are stored to array of test cases. The Test Framework will be 
       
   175 // the owner of the data in the RPointerArray after GetTestCases return
       
   176 // and it does the memory deallocation. 
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 TInt Ct_bufferedmsgcreator::GetTestCasesL( 
       
   180     const TFileName& /*aConfig*/, 
       
   181     RPointerArray<TTestCaseInfo>& aTestCases )
       
   182     {
       
   183 
       
   184     // Loop through all test cases and create new
       
   185     // TTestCaseInfo items and append items to aTestCase array    
       
   186     for( TInt i = 0; Case(i).iMethod != NULL; i++ )
       
   187         {
       
   188 
       
   189         // Allocate new TTestCaseInfo from heap for a testcase definition.
       
   190         TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo();
       
   191 
       
   192         // PushL TTestCaseInfo to CleanupStack.    
       
   193         CleanupStack::PushL( newCase );
       
   194 
       
   195         // Set number for the testcase.
       
   196         // When the testcase is run, this comes as a parameter to RunTestCaseL.
       
   197         newCase->iCaseNumber = i;
       
   198 
       
   199         // Set title for the test case. This is shown in UI to user.
       
   200         newCase->iTitle.Copy( Case(i).iCaseName );
       
   201 
       
   202         // Append TTestCaseInfo to the testcase array. After appended 
       
   203         // successfully the TTestCaseInfo object is owned (and freed) 
       
   204         // by the TestServer. 
       
   205         User::LeaveIfError(aTestCases.Append ( newCase ) );
       
   206 
       
   207         // Pop TTestCaseInfo from the CleanupStack.
       
   208         CleanupStack::Pop( newCase );
       
   209 
       
   210         }
       
   211 
       
   212     return KErrNone;
       
   213 
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // Ct_msgstore::RunTestCaseL
       
   218 // RunTestCaseL is used to run an individual test case specified 
       
   219 // by aTestCase. Test cases that can be run may be requested from 
       
   220 // Test Module by GetTestCases method before calling RunTestCase.
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 TInt Ct_bufferedmsgcreator::RunTestCaseL( 
       
   224     const TInt aCaseNumber,   
       
   225     const TFileName& /*aConfig*/,
       
   226     TTestResult& aResult )
       
   227     {
       
   228     if(!iVersionLogged)
       
   229     	{
       
   230     	SendTestModuleVersion();
       
   231     	iVersionLogged = ETrue;
       
   232     	}
       
   233     
       
   234     // Return value
       
   235     TInt execStatus = KErrNone;
       
   236 
       
   237     // Get the pointer to test case function
       
   238     TCaseInfo tmp = Case ( aCaseNumber );
       
   239 
       
   240     _LIT( KLogStartTC, "Starting testcase [%S]" );
       
   241     iLog->Log( KLogStartTC, &tmp.iCaseName);
       
   242 
       
   243     // Check that case number was valid
       
   244     if ( tmp.iMethod != NULL )
       
   245         {
       
   246         //Open new log file with test case title in file name
       
   247         if(iAddTestCaseTitleToLogName)
       
   248             {
       
   249             //Delete test case logger if exists
       
   250             if(iTCLog)
       
   251                 {
       
   252                 delete iTCLog;
       
   253                 iTCLog = NULL;
       
   254                 }
       
   255 
       
   256             TFileName logFileName;
       
   257             TName title;
       
   258             TestModuleIf().GetTestCaseTitleL(title);
       
   259         
       
   260             logFileName.Format(Kt_msgstoreLogFileWithTitle, &title);
       
   261 
       
   262             iTCLog = CStifLogger::NewL(Kt_msgstoreLogPath, 
       
   263                                        logFileName);
       
   264             iLog = iTCLog;                                       
       
   265             }
       
   266 
       
   267         // Valid case was found, call it via function pointer
       
   268         iMethod = tmp.iMethod;        
       
   269         //execStatus  = ( this->*iMethod )( aResult );
       
   270         TRAPD(err, execStatus  = ( this->*iMethod )( aResult ));
       
   271         if(iAddTestCaseTitleToLogName)
       
   272             {
       
   273             //Restore standard log and destroy test case logger
       
   274             iLog = iStdLog;
       
   275             delete iTCLog; //Close test case log
       
   276             iTCLog = NULL;
       
   277             }
       
   278         User::LeaveIfError(err);
       
   279         }
       
   280     else
       
   281         {
       
   282         // Valid case was not found, return error.
       
   283         execStatus = KErrNotFound;
       
   284         }
       
   285 
       
   286     // Return case execution status (not the result of the case execution)
       
   287     return execStatus;
       
   288 
       
   289     }
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // Ct_msgstore::OOMTestQueryL
       
   293 // Used to check if a particular test case should be run in OOM conditions and 
       
   294 // which memory allocations should fail.    
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 TBool Ct_bufferedmsgcreator::OOMTestQueryL( 
       
   298                                 const TFileName& /* aTestCaseFile */, 
       
   299                                 const TInt aCaseNumber, 
       
   300                                 TOOMFailureType& /* aFailureType */, 
       
   301                                 TInt& aFirstMemFailure, 
       
   302                                 TInt& aLastMemFailure ) 
       
   303     {
       
   304     _LIT( KLogOOMTestQueryL, "Ct_msgstore::OOMTestQueryL" );
       
   305     iLog->Log( KLogOOMTestQueryL );     
       
   306 
       
   307     aFirstMemFailure = Case( aCaseNumber ).iFirstMemoryAllocation;
       
   308     aLastMemFailure = Case( aCaseNumber ).iLastMemoryAllocation;
       
   309 
       
   310     return Case( aCaseNumber ).iIsOOMTest;
       
   311 
       
   312     }
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // Ct_msgstore::OOMTestInitializeL
       
   316 // Used to perform the test environment setup for a particular OOM test case. 
       
   317 // Test Modules may use the initialization file to read parameters for Test 
       
   318 // Module initialization but they can also have their own configure file or 
       
   319 // some other routine to initialize themselves.  
       
   320 //
       
   321 // NOTE: User may add implementation for OOM test environment initialization.
       
   322 // Usually no implementation is required.
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 void Ct_bufferedmsgcreator::OOMTestInitializeL( 
       
   326                                 const TFileName& /* aTestCaseFile */, 
       
   327                                 const TInt /* aCaseNumber */ )
       
   328     {
       
   329     }
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // Ct_msgstore::OOMHandleWarningL
       
   333 // In some cases the heap memory allocation should be skipped, either due to
       
   334 // problems in the OS code or components used by the code being tested, or even 
       
   335 // inside the tested components which are implemented this way on purpose (by 
       
   336 // design), so it is important to give the tester a way to bypass allocation 
       
   337 // failures.
       
   338 //
       
   339 // NOTE: User may add implementation for OOM test warning handling. Usually no
       
   340 // implementation is required.
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 void Ct_bufferedmsgcreator::OOMHandleWarningL( 
       
   344                                 const TFileName& /* aTestCaseFile */,
       
   345                                 const TInt /* aCaseNumber */, 
       
   346                                 TInt& /* aFailNextValue */ )
       
   347     {
       
   348     }
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // Ct_msgstore::OOMTestFinalizeL
       
   352 // Used to perform the test environment cleanup for a particular OOM test case.
       
   353 //
       
   354 // NOTE: User may add implementation for OOM test environment finalization.
       
   355 // Usually no implementation is required.
       
   356 // -----------------------------------------------------------------------------
       
   357 //
       
   358 void Ct_bufferedmsgcreator::OOMTestFinalizeL( 
       
   359                                 const TFileName& /* aTestCaseFile */, 
       
   360                                 const TInt /* aCaseNumber */ )
       
   361     {
       
   362     }
       
   363 
       
   364 //-----------------------------------------------------------------------------
       
   365 // Ct_msgstore::SendTestModuleVersion
       
   366 // Method used to send version of test module
       
   367 //-----------------------------------------------------------------------------
       
   368 //
       
   369 void Ct_bufferedmsgcreator::SendTestModuleVersion()
       
   370 	{
       
   371 	TVersion moduleVersion;
       
   372 	moduleVersion.iMajor = TEST_MODULE_VERSION_MAJOR;
       
   373 	moduleVersion.iMinor = TEST_MODULE_VERSION_MINOR;
       
   374 	moduleVersion.iBuild = TEST_MODULE_VERSION_BUILD;
       
   375 	
       
   376 	TFileName moduleName;
       
   377 	moduleName = _L("t_msgstore.dll");
       
   378 
       
   379 	TBool newVersionOfMethod = ETrue;
       
   380 	TestModuleIf().SendTestModuleVersion(moduleVersion, moduleName, newVersionOfMethod);
       
   381 	}
       
   382 
       
   383 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   384 
       
   385 // -----------------------------------------------------------------------------
       
   386 // LibEntryL is a polymorphic Dll entry point
       
   387 // Returns: CTestModuleBase*: Pointer to Test Module object
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 EXPORT_C CTestModuleBase* LibEntryL()
       
   391     {
       
   392     return Ct_bufferedmsgcreator::NewL();
       
   393 
       
   394     }
       
   395 
       
   396 // -----------------------------------------------------------------------------
       
   397 // SetRequirements handles test module parameters(implements evolution
       
   398 // version 1 for test module's heap and stack sizes configuring).
       
   399 // Returns: TInt: Symbian error code.
       
   400 // -----------------------------------------------------------------------------
       
   401 //
       
   402 EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/, 
       
   403                                 TUint32& /*aParameterValid*/ )
       
   404     {
       
   405 
       
   406     /* --------------------------------- NOTE ---------------------------------
       
   407     USER PANICS occurs in test thread creation when:
       
   408     1) "The panic occurs when the value of the stack size is negative."
       
   409     2) "The panic occurs if the minimum heap size specified is less
       
   410        than KMinHeapSize".
       
   411        KMinHeapSize: "Functions that require a new heap to be allocated will
       
   412        either panic, or will reset the required heap size to this value if
       
   413        a smaller heap size is specified".
       
   414     3) "The panic occurs if the minimum heap size specified is greater than
       
   415        the maximum size to which the heap can grow".
       
   416     Other:
       
   417     1) Make sure that your hardware or Symbian OS is supporting given sizes.
       
   418        e.g. Hardware might support only sizes that are divisible by four.
       
   419     ------------------------------- NOTE end ------------------------------- */
       
   420 
       
   421     // Normally STIF uses default heap and stack sizes for test thread, see:
       
   422     // KTestThreadMinHeap, KTestThreadMinHeap and KStackSize.
       
   423     // If needed heap and stack sizes can be configured here by user. Remove
       
   424     // comments and define sizes.
       
   425 
       
   426 /*
       
   427     aParameterValid = KStifTestModuleParameterChanged;
       
   428 
       
   429     CTestModuleParamVer01* param = CTestModuleParamVer01::NewL();
       
   430     // Stack size
       
   431     param->iTestThreadStackSize= 16384; // 16K stack
       
   432     // Heap sizes
       
   433     param->iTestThreadMinHeap = 4096;   // 4K heap min
       
   434     param->iTestThreadMaxHeap = 1048576;// 1M heap max
       
   435 
       
   436     aTestModuleParam = param;
       
   437 */
       
   438     return KErrNone;
       
   439 
       
   440     }
       
   441 
       
   442 
       
   443 //  End of File