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