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