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