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