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