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