websrv_pub/hostlet_connection_api/tsrc/hostconn/src/hostletconnection.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:          SenHostletConnection class member functions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 // INCLUDE FILES
       
    27 #include <StifTestInterface.h>
       
    28 #include "senhostletconnectionbctest.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 // CSenHostletConnectionBCTest::CSenHostletConnectionBCTest
       
    83 // C++ default constructor can NOT contain any code, that
       
    84 // might leave.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 CSenHostletConnectionBCTest::CSenHostletConnectionBCTest()
       
    88     {
       
    89 
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CSenHostletConnectionBCTest::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 CSenHostletConnectionBCTest::ConstructL()
       
   104     {
       
   105     iLog = CStifLogger::NewL( KSenHostletConnection_stifLogPath, 
       
   106                           KSenHostletConnection_stifLogFile);
       
   107 
       
   108     // Sample how to use logging
       
   109     _LIT( KLogStart, "KSenHostletConnection_stif logging starts!" );
       
   110     iLog->Log( KLogStart );
       
   111     
       
   112     iActiveScheduler = new CActiveScheduler;
       
   113 	CActiveScheduler::Install( iActiveScheduler );
       
   114 
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CSenHostletConnectionBCTest::NewL
       
   119 // Two-phased constructor.
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 CSenHostletConnectionBCTest* CSenHostletConnectionBCTest::NewL()
       
   123     {
       
   124     CSenHostletConnectionBCTest* self = new (ELeave) CSenHostletConnectionBCTest;
       
   125 
       
   126     CleanupStack::PushL( self );
       
   127     self->ConstructL();
       
   128     CleanupStack::Pop();
       
   129 
       
   130     return self;
       
   131 
       
   132     }
       
   133 
       
   134 // Destructor
       
   135 CSenHostletConnectionBCTest::~CSenHostletConnectionBCTest()
       
   136     {
       
   137     delete iLog;
       
   138     
       
   139     delete iActiveScheduler;
       
   140    
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CSenHostletConnectionBCTest::InitL
       
   145 // InitL is used to initialize the Test Module.
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 TInt CSenHostletConnectionBCTest::InitL( 
       
   149     TFileName& /*aIniFile*/, 
       
   150     TBool /*aFirstTime*/ )
       
   151     {
       
   152     return KErrNone;
       
   153 
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CSenHostletConnectionBCTest::GetTestCasesL
       
   158 // GetTestCases is used to inquire test cases from the Test Module. Test
       
   159 // cases are stored to array of test cases. The Test Framework will be 
       
   160 // the owner of the data in the RPointerArray after GetTestCases return
       
   161 // and it does the memory deallocation. 
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 TInt CSenHostletConnectionBCTest::GetTestCasesL( 
       
   165     const TFileName& /*aConfig*/, 
       
   166     RPointerArray<TTestCaseInfo>& aTestCases )
       
   167     {
       
   168 
       
   169     // Loop through all test cases and create new
       
   170     // TTestCaseInfo items and append items to aTestCase array    
       
   171     for( TInt i = 0; Case(i).iMethod != NULL; i++ )
       
   172         {
       
   173 
       
   174         // Allocate new TTestCaseInfo from heap for a testcase definition.
       
   175         TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo();
       
   176 
       
   177         // PushL TTestCaseInfo to CleanupStack.    
       
   178         CleanupStack::PushL( newCase );
       
   179 
       
   180         // Set number for the testcase.
       
   181         // When the testcase is run, this comes as a parameter to RunTestCaseL.
       
   182         newCase->iCaseNumber = i;
       
   183 
       
   184         // Set title for the test case. This is shown in UI to user.
       
   185         newCase->iTitle.Copy( Case(i).iCaseName );
       
   186 
       
   187         // Append TTestCaseInfo to the testcase array. After appended 
       
   188         // successfully the TTestCaseInfo object is owned (and freed) 
       
   189         // by the TestServer. 
       
   190         User::LeaveIfError(aTestCases.Append ( newCase ) );
       
   191 
       
   192         // Pop TTestCaseInfo from the CleanupStack.
       
   193         CleanupStack::Pop( newCase );
       
   194 
       
   195         }
       
   196 
       
   197     return KErrNone;
       
   198 
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CSenHostletConnectionBCTest::RunTestCaseL
       
   203 // RunTestCaseL is used to run an individual test case specified 
       
   204 // by aTestCase. Test cases that can be run may be requested from 
       
   205 // Test Module by GetTestCases method before calling RunTestCase.
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 TInt CSenHostletConnectionBCTest::RunTestCaseL( 
       
   209     const TInt aCaseNumber,   
       
   210     const TFileName& /*aConfig*/,
       
   211     TTestResult& aResult )
       
   212     {
       
   213 
       
   214     // Return value
       
   215     TInt execStatus = KErrNone;
       
   216 
       
   217     // Get the pointer to test case function
       
   218     TCaseInfo tmp = Case ( aCaseNumber );
       
   219 
       
   220     _LIT( KLogStartTC, "Starting testcase [%S]" );
       
   221     iLog->Log( KLogStartTC, &tmp.iCaseName);
       
   222 
       
   223     // Check that case number was valid
       
   224     if ( tmp.iMethod != NULL )
       
   225         {
       
   226         // Valid case was found, call it via function pointer
       
   227         iMethod = tmp.iMethod;        
       
   228         execStatus  = ( this->*iMethod )( aResult );
       
   229         }
       
   230     else
       
   231         {
       
   232         // Valid case was not found, return error.
       
   233         execStatus = KErrNotFound;
       
   234         }
       
   235 
       
   236     // Return case execution status (not the result of the case execution)
       
   237     return execStatus;
       
   238 
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CSenHostletConnectionBCTest::OOMTestQueryL
       
   243 // Used to check if a particular test case should be run in OOM conditions and 
       
   244 // which memory allocations should fail.    
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 TBool CSenHostletConnectionBCTest::OOMTestQueryL( 
       
   248                                 const TFileName& /* aTestCaseFile */, 
       
   249                                 const TInt aCaseNumber, 
       
   250                                 TOOMFailureType& /* aFailureType */, 
       
   251                                 TInt& aFirstMemFailure, 
       
   252                                 TInt& aLastMemFailure ) 
       
   253     {
       
   254     _LIT( KLogOOMTestQueryL, "CSenHostletConnectionBCTest::OOMTestQueryL" );
       
   255     iLog->Log( KLogOOMTestQueryL );     
       
   256 
       
   257     aFirstMemFailure = Case( aCaseNumber ).iFirstMemoryAllocation;
       
   258     aLastMemFailure = Case( aCaseNumber ).iLastMemoryAllocation;
       
   259 
       
   260     return Case( aCaseNumber ).iIsOOMTest;
       
   261 
       
   262     }
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CSenHostletConnectionBCTest::OOMTestInitializeL
       
   266 // Used to perform the test environment setup for a particular OOM test case. 
       
   267 // Test Modules may use the initialization file to read parameters for Test 
       
   268 // Module initialization but they can also have their own configure file or 
       
   269 // some other routine to initialize themselves.  
       
   270 //
       
   271 // NOTE: User may add implementation for OOM test environment initialization.
       
   272 // Usually no implementation is required.
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 void CSenHostletConnectionBCTest::OOMTestInitializeL( 
       
   276                                 const TFileName& /* aTestCaseFile */, 
       
   277                                 const TInt /* aCaseNumber */ )
       
   278     {
       
   279     }
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // CSenHostletConnectionBCTest::OOMHandleWarningL
       
   283 // In some cases the heap memory allocation should be skipped, either due to
       
   284 // problems in the OS code or components used by the code being tested, or even 
       
   285 // inside the tested components which are implemented this way on purpose (by 
       
   286 // design), so it is important to give the tester a way to bypass allocation 
       
   287 // failures.
       
   288 //
       
   289 // NOTE: User may add implementation for OOM test warning handling. Usually no
       
   290 // implementation is required.
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 void CSenHostletConnectionBCTest::OOMHandleWarningL( 
       
   294                                 const TFileName& /* aTestCaseFile */,
       
   295                                 const TInt /* aCaseNumber */, 
       
   296                                 TInt& /* aFailNextValue */ )
       
   297     {
       
   298     }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CSenHostletConnectionBCTest::OOMTestFinalizeL
       
   302 // Used to perform the test environment cleanup for a particular OOM test case.
       
   303 //
       
   304 // NOTE: User may add implementation for OOM test environment finalization.
       
   305 // Usually no implementation is required.
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 void CSenHostletConnectionBCTest::OOMTestFinalizeL( 
       
   309                                 const TFileName& /* aTestCaseFile */, 
       
   310                                 const TInt /* aCaseNumber */ )
       
   311     {
       
   312     }
       
   313 
       
   314 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // LibEntryL is a polymorphic Dll entry point
       
   318 // Returns: CTestModuleBase*: Pointer to Test Module object
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 EXPORT_C CTestModuleBase* LibEntryL()
       
   322     {
       
   323     return CSenHostletConnectionBCTest::NewL();
       
   324 
       
   325     }
       
   326 
       
   327 // -----------------------------------------------------------------------------
       
   328 // SetRequirements handles test module parameters(implements evolution
       
   329 // version 1 for test module's heap and stack sizes configuring).
       
   330 // Returns: TInt: Symbian error code.
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/, 
       
   334                                 TUint32& /*aParameterValid*/ )
       
   335     {
       
   336 
       
   337     /* --------------------------------- NOTE ---------------------------------
       
   338     USER PANICS occurs in test thread creation when:
       
   339     1) "The panic occurs when the value of the stack size is negative."
       
   340     2) "The panic occurs if the minimum heap size specified is less
       
   341        than KMinHeapSize".
       
   342        KMinHeapSize: "Functions that require a new heap to be allocated will
       
   343        either panic, or will reset the required heap size to this value if
       
   344        a smaller heap size is specified".
       
   345     3) "The panic occurs if the minimum heap size specified is greater than
       
   346        the maximum size to which the heap can grow".
       
   347     Other:
       
   348     1) Make sure that your hardware or Symbian OS is supporting given sizes.
       
   349        e.g. Hardware might support only sizes that are divisible by four.
       
   350     ------------------------------- NOTE end ------------------------------- */
       
   351 
       
   352     // Normally STIF uses default heap and stack sizes for test thread, see:
       
   353     // KTestThreadMinHeap, KTestThreadMinHeap and KStackSize.
       
   354     // If needed heap and stack sizes can be configured here by user. Remove
       
   355     // comments and define sizes.
       
   356 
       
   357 /*
       
   358     aParameterValid = KStifTestModuleParameterChanged;
       
   359 
       
   360     CTestModuleParamVer01* param = CTestModuleParamVer01::NewL();
       
   361     // Stack size
       
   362     param->iTestThreadStackSize= 16384; // 16K stack
       
   363     // Heap sizes
       
   364     param->iTestThreadMinHeap = 4096;   // 4K heap min
       
   365     param->iTestThreadMaxHeap = 1048576;// 1M heap max
       
   366 
       
   367     aTestModuleParam = param;
       
   368 */
       
   369     return KErrNone;
       
   370 
       
   371     }
       
   372 
       
   373 
       
   374 //  End of File