os/ossrv/stdcpp/tsrc/BC/apps/widecharclassapiBCTest/src/widecharclassapiBCTest.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/stdcpp/tsrc/BC/apps/widecharclassapiBCTest/src/widecharclassapiBCTest.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,441 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:       
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +// [INCLUDE FILES] - do not remove
    1.23 +#include <Stiftestinterface.h>
    1.24 +#include "widecharclassapiBCTest.h"
    1.25 +#include <SettingServerClient.h>
    1.26 +
    1.27 +// EXTERNAL DATA STRUCTURES
    1.28 +//extern  ?external_data;
    1.29 +
    1.30 +// EXTERNAL FUNCTION PROTOTYPES  
    1.31 +//extern ?external_function( ?arg_type,?arg_type );
    1.32 +
    1.33 +// CONSTANTS
    1.34 +//const ?type ?constant_var = ?constant;
    1.35 +
    1.36 +// MACROS
    1.37 +//#define ?macro ?macro_def
    1.38 +
    1.39 +// LOCAL CONSTANTS AND MACROS
    1.40 +//const ?type ?constant_var = ?constant;
    1.41 +//#define ?macro_name ?macro_def
    1.42 +
    1.43 +// MODULE DATA STRUCTURES
    1.44 +//enum ?declaration
    1.45 +//typedef ?declaration
    1.46 +
    1.47 +// LOCAL FUNCTION PROTOTYPES
    1.48 +//?type ?function_name( ?arg_type, ?arg_type );
    1.49 +
    1.50 +// FORWARD DECLARATIONS
    1.51 +//class ?FORWARD_CLASSNAME;
    1.52 +
    1.53 +// ============================= LOCAL FUNCTIONS ===============================
    1.54 +
    1.55 +// -----------------------------------------------------------------------------
    1.56 +// ?function_name ?description.
    1.57 +// ?description
    1.58 +// Returns: ?value_1: ?description
    1.59 +//          ?value_n: ?description_line1
    1.60 +//                    ?description_line2
    1.61 +// -----------------------------------------------------------------------------
    1.62 +//
    1.63 +/*
    1.64 +?type ?function_name(
    1.65 +    ?arg_type arg,  // ?description
    1.66 +    ?arg_type arg)  // ?description
    1.67 +    {
    1.68 +
    1.69 +    ?code  // ?comment
    1.70 +
    1.71 +    // ?comment
    1.72 +    ?code
    1.73 +    }
    1.74 +*/
    1.75 +
    1.76 +// ============================ MEMBER FUNCTIONS ===============================
    1.77 +
    1.78 +// -----------------------------------------------------------------------------
    1.79 +// CwidecharclassapiBCTest::CwidecharclassapiBCTest
    1.80 +// C++ default constructor can NOT contain any code, that
    1.81 +// might leave.
    1.82 +// -----------------------------------------------------------------------------
    1.83 +//
    1.84 +CwidecharclassapiBCTest::CwidecharclassapiBCTest()
    1.85 +    {
    1.86 +
    1.87 +    }
    1.88 +
    1.89 +// -----------------------------------------------------------------------------
    1.90 +// CwidecharclassapiBCTest::ConstructL
    1.91 +// Symbian 2nd phase constructor can leave.
    1.92 +//
    1.93 +// Note: If OOM test case uses STIF Logger, then STIF Logger must be created
    1.94 +// with static buffer size parameter (aStaticBufferSize). Otherwise Logger 
    1.95 +// allocates memory from heap and therefore causes error situations with OOM 
    1.96 +// testing. For more information about STIF Logger construction, see STIF Users 
    1.97 +// Guide.
    1.98 +// -----------------------------------------------------------------------------
    1.99 +//
   1.100 +void CwidecharclassapiBCTest::ConstructL()
   1.101 +    {
   1.102 +    //Read logger settings to check whether test case name is to be
   1.103 +    //appended to log file name.
   1.104 +    RSettingServer settingServer;
   1.105 +    TInt ret = settingServer.Connect();
   1.106 +    if(ret != KErrNone)
   1.107 +        {
   1.108 +        User::Leave(ret);
   1.109 +        }
   1.110 +    // Struct to StifLogger settigs.
   1.111 +    TLoggerSettings loggerSettings; 
   1.112 +    // Parse StifLogger defaults from STIF initialization file.
   1.113 +    ret = settingServer.GetLoggerSettings(loggerSettings);
   1.114 +    if(ret != KErrNone)
   1.115 +        {
   1.116 +        User::Leave(ret);
   1.117 +        } 
   1.118 +    // Close Setting server session
   1.119 +    settingServer.Close();
   1.120 +    iAddTestCaseTitleToLogName = loggerSettings.iAddTestCaseTitle;
   1.121 +
   1.122 +    iStdLog = CStifLogger::NewL( KwidecharclassapiBCTestLogPath, 
   1.123 +                          KwidecharclassapiBCTestLogFile);
   1.124 +    iLog = iStdLog;
   1.125 +
   1.126 +    // Sample how to use logging
   1.127 +    _LIT( KLogStart, "widecharclassapiBCTest logging starts!" );
   1.128 +    iLog->Log( KLogStart );
   1.129 +
   1.130 +    iVersionLogged = EFalse;
   1.131 +    }
   1.132 +
   1.133 +// -----------------------------------------------------------------------------
   1.134 +// CwidecharclassapiBCTest::NewL
   1.135 +// Two-phased constructor.
   1.136 +// -----------------------------------------------------------------------------
   1.137 +//
   1.138 +CwidecharclassapiBCTest* CwidecharclassapiBCTest::NewL()
   1.139 +    {
   1.140 +    CwidecharclassapiBCTest* self = new (ELeave) CwidecharclassapiBCTest;
   1.141 +
   1.142 +    CleanupStack::PushL( self );
   1.143 +    self->ConstructL();
   1.144 +    CleanupStack::Pop();
   1.145 +
   1.146 +    return self;
   1.147 +
   1.148 +    }
   1.149 +
   1.150 +// Destructor
   1.151 +CwidecharclassapiBCTest::~CwidecharclassapiBCTest()
   1.152 +    {
   1.153 +    iLog = NULL;
   1.154 +    delete iStdLog;
   1.155 +    iStdLog = NULL;
   1.156 +    delete iTCLog;
   1.157 +    iTCLog = NULL;
   1.158 +    }
   1.159 +
   1.160 +// -----------------------------------------------------------------------------
   1.161 +// CwidecharclassapiBCTest::InitL
   1.162 +// InitL is used to initialize the Test Module.
   1.163 +// -----------------------------------------------------------------------------
   1.164 +//
   1.165 +TInt CwidecharclassapiBCTest::InitL( 
   1.166 +    TFileName& /*aIniFile*/, 
   1.167 +    TBool /*aFirstTime*/ )
   1.168 +    {
   1.169 +    return KErrNone;
   1.170 +
   1.171 +    }
   1.172 +
   1.173 +// -----------------------------------------------------------------------------
   1.174 +// CwidecharclassapiBCTest::GetTestCasesL
   1.175 +// GetTestCases is used to inquire test cases from the Test Module. Test
   1.176 +// cases are stored to array of test cases. The Test Framework will be 
   1.177 +// the owner of the data in the RPointerArray after GetTestCases return
   1.178 +// and it does the memory deallocation. 
   1.179 +// -----------------------------------------------------------------------------
   1.180 +//
   1.181 +TInt CwidecharclassapiBCTest::GetTestCasesL( 
   1.182 +    const TFileName& /*aConfig*/, 
   1.183 +    RPointerArray<TTestCaseInfo>& aTestCases )
   1.184 +    {
   1.185 +
   1.186 +    // Loop through all test cases and create new
   1.187 +    // TTestCaseInfo items and append items to aTestCase array    
   1.188 +    for( TInt i = 0; Case(i).iMethod != NULL; i++ )
   1.189 +        {
   1.190 +
   1.191 +        // Allocate new TTestCaseInfo from heap for a testcase definition.
   1.192 +        TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo();
   1.193 +
   1.194 +        // PushL TTestCaseInfo to CleanupStack.    
   1.195 +        CleanupStack::PushL( newCase );
   1.196 +
   1.197 +        // Set number for the testcase.
   1.198 +        // When the testcase is run, this comes as a parameter to RunTestCaseL.
   1.199 +        newCase->iCaseNumber = i;
   1.200 +
   1.201 +        // Set title for the test case. This is shown in UI to user.
   1.202 +        newCase->iTitle.Copy( Case(i).iCaseName );
   1.203 +
   1.204 +        // Append TTestCaseInfo to the testcase array. After appended 
   1.205 +        // successfully the TTestCaseInfo object is owned (and freed) 
   1.206 +        // by the TestServer. 
   1.207 +        User::LeaveIfError(aTestCases.Append ( newCase ) );
   1.208 +
   1.209 +        // Pop TTestCaseInfo from the CleanupStack.
   1.210 +        CleanupStack::Pop( newCase );
   1.211 +
   1.212 +        }
   1.213 +
   1.214 +    return KErrNone;
   1.215 +
   1.216 +    }
   1.217 +
   1.218 +// -----------------------------------------------------------------------------
   1.219 +// CwidecharclassapiBCTest::RunTestCaseL
   1.220 +// RunTestCaseL is used to run an individual test case specified 
   1.221 +// by aTestCase. Test cases that can be run may be requested from 
   1.222 +// Test Module by GetTestCases method before calling RunTestCase.
   1.223 +// -----------------------------------------------------------------------------
   1.224 +//
   1.225 +TInt CwidecharclassapiBCTest::RunTestCaseL( 
   1.226 +    const TInt aCaseNumber,   
   1.227 +    const TFileName& /*aConfig*/,
   1.228 +    TTestResult& aResult )
   1.229 +    {
   1.230 +    if(!iVersionLogged)
   1.231 +    	{
   1.232 +    	SendTestModuleVersion();
   1.233 +    	iVersionLogged = ETrue;
   1.234 +    	}
   1.235 +    
   1.236 +    // Return value
   1.237 +    TInt execStatus = KErrNone;
   1.238 +
   1.239 +    // Get the pointer to test case function
   1.240 +    TCaseInfo tmp = Case ( aCaseNumber );
   1.241 +
   1.242 +    _LIT( KLogStartTC, "Starting testcase [%S]" );
   1.243 +    iLog->Log( KLogStartTC, &tmp.iCaseName);
   1.244 +
   1.245 +    // Check that case number was valid
   1.246 +    if ( tmp.iMethod != NULL )
   1.247 +        {
   1.248 +        //Open new log file with test case title in file name
   1.249 +        if(iAddTestCaseTitleToLogName)
   1.250 +            {
   1.251 +            //Delete test case logger if exists
   1.252 +            if(iTCLog)
   1.253 +                {
   1.254 +                delete iTCLog;
   1.255 +                iTCLog = NULL;
   1.256 +                }
   1.257 +
   1.258 +            TFileName logFileName;
   1.259 +            TName title;
   1.260 +            TestModuleIf().GetTestCaseTitleL(title);
   1.261 +        
   1.262 +            logFileName.Format(KwidecharclassapiBCTestLogFileWithTitle, &title);
   1.263 +
   1.264 +            iTCLog = CStifLogger::NewL(KwidecharclassapiBCTestLogPath, 
   1.265 +                                       logFileName);
   1.266 +            iLog = iTCLog;                                       
   1.267 +            }
   1.268 +
   1.269 +        // Valid case was found, call it via function pointer
   1.270 +        iMethod = tmp.iMethod;        
   1.271 +        //execStatus  = ( this->*iMethod )( aResult );
   1.272 +        TRAPD(err, execStatus  = ( this->*iMethod )( aResult ));
   1.273 +        if(iAddTestCaseTitleToLogName)
   1.274 +            {
   1.275 +            //Restore standard log and destroy test case logger
   1.276 +            iLog = iStdLog;
   1.277 +            delete iTCLog; //Close test case log
   1.278 +            iTCLog = NULL;
   1.279 +            }
   1.280 +        User::LeaveIfError(err);
   1.281 +        }
   1.282 +    else
   1.283 +        {
   1.284 +        // Valid case was not found, return error.
   1.285 +        execStatus = KErrNotFound;
   1.286 +        }
   1.287 +
   1.288 +    // Return case execution status (not the result of the case execution)
   1.289 +    return execStatus;
   1.290 +
   1.291 +    }
   1.292 +
   1.293 +// -----------------------------------------------------------------------------
   1.294 +// CwidecharclassapiBCTest::OOMTestQueryL
   1.295 +// Used to check if a particular test case should be run in OOM conditions and 
   1.296 +// which memory allocations should fail.    
   1.297 +// -----------------------------------------------------------------------------
   1.298 +//
   1.299 +TBool CwidecharclassapiBCTest::OOMTestQueryL( 
   1.300 +                                const TFileName& /* aTestCaseFile */, 
   1.301 +                                const TInt aCaseNumber, 
   1.302 +                                TOOMFailureType& /* aFailureType */, 
   1.303 +                                TInt& aFirstMemFailure, 
   1.304 +                                TInt& aLastMemFailure ) 
   1.305 +    {
   1.306 +    _LIT( KLogOOMTestQueryL, "CwidecharclassapiBCTest::OOMTestQueryL" );
   1.307 +    iLog->Log( KLogOOMTestQueryL );     
   1.308 +
   1.309 +    aFirstMemFailure = Case( aCaseNumber ).iFirstMemoryAllocation;
   1.310 +    aLastMemFailure = Case( aCaseNumber ).iLastMemoryAllocation;
   1.311 +
   1.312 +    return Case( aCaseNumber ).iIsOOMTest;
   1.313 +
   1.314 +    }
   1.315 +
   1.316 +// -----------------------------------------------------------------------------
   1.317 +// CwidecharclassapiBCTest::OOMTestInitializeL
   1.318 +// Used to perform the test environment setup for a particular OOM test case. 
   1.319 +// Test Modules may use the initialization file to read parameters for Test 
   1.320 +// Module initialization but they can also have their own configure file or 
   1.321 +// some other routine to initialize themselves.  
   1.322 +//
   1.323 +// NOTE: User may add implementation for OOM test environment initialization.
   1.324 +// Usually no implementation is required.
   1.325 +// -----------------------------------------------------------------------------
   1.326 +//
   1.327 +void CwidecharclassapiBCTest::OOMTestInitializeL( 
   1.328 +                                const TFileName& /* aTestCaseFile */, 
   1.329 +                                const TInt /* aCaseNumber */ )
   1.330 +    {
   1.331 +    }
   1.332 +
   1.333 +// -----------------------------------------------------------------------------
   1.334 +// CwidecharclassapiBCTest::OOMHandleWarningL
   1.335 +// In some cases the heap memory allocation should be skipped, either due to
   1.336 +// problems in the OS code or components used by the code being tested, or even 
   1.337 +// inside the tested components which are implemented this way on purpose (by 
   1.338 +// design), so it is important to give the tester a way to bypass allocation 
   1.339 +// failures.
   1.340 +//
   1.341 +// NOTE: User may add implementation for OOM test warning handling. Usually no
   1.342 +// implementation is required.
   1.343 +// -----------------------------------------------------------------------------
   1.344 +//
   1.345 +void CwidecharclassapiBCTest::OOMHandleWarningL( 
   1.346 +                                const TFileName& /* aTestCaseFile */,
   1.347 +                                const TInt /* aCaseNumber */, 
   1.348 +                                TInt& /* aFailNextValue */ )
   1.349 +    {
   1.350 +    }
   1.351 +
   1.352 +// -----------------------------------------------------------------------------
   1.353 +// CwidecharclassapiBCTest::OOMTestFinalizeL
   1.354 +// Used to perform the test environment cleanup for a particular OOM test case.
   1.355 +//
   1.356 +// NOTE: User may add implementation for OOM test environment finalization.
   1.357 +// Usually no implementation is required.
   1.358 +// -----------------------------------------------------------------------------
   1.359 +//
   1.360 +void CwidecharclassapiBCTest::OOMTestFinalizeL( 
   1.361 +                                const TFileName& /* aTestCaseFile */, 
   1.362 +                                const TInt /* aCaseNumber */ )
   1.363 +    {
   1.364 +    }
   1.365 +
   1.366 +//-----------------------------------------------------------------------------
   1.367 +// CwidecharclassapiBCTest::SendTestModuleVersion
   1.368 +// Method used to send version of test module
   1.369 +//-----------------------------------------------------------------------------
   1.370 +//
   1.371 +void CwidecharclassapiBCTest::SendTestModuleVersion()
   1.372 +	{
   1.373 +	TVersion moduleVersion;
   1.374 +	moduleVersion.iMajor = TEST_MODULE_VERSION_MAJOR;
   1.375 +	moduleVersion.iMinor = TEST_MODULE_VERSION_MINOR;
   1.376 +	moduleVersion.iBuild = TEST_MODULE_VERSION_BUILD;
   1.377 +	
   1.378 +	TFileName moduleName;
   1.379 +	moduleName = _L("widecharclassapiBCTest.dll");
   1.380 +
   1.381 +	TestModuleIf().SendTestModuleVersion(moduleVersion, moduleName);
   1.382 +	}
   1.383 +
   1.384 +// ========================== OTHER EXPORTED FUNCTIONS =========================
   1.385 +
   1.386 +// -----------------------------------------------------------------------------
   1.387 +// LibEntryL is a polymorphic Dll entry point
   1.388 +// Returns: CTestModuleBase*: Pointer to Test Module object
   1.389 +// -----------------------------------------------------------------------------
   1.390 +//
   1.391 +EXPORT_C CTestModuleBase* LibEntryL()
   1.392 +    {
   1.393 +    return CwidecharclassapiBCTest::NewL();
   1.394 +
   1.395 +    }
   1.396 +
   1.397 +// -----------------------------------------------------------------------------
   1.398 +// SetRequirements handles test module parameters(implements evolution
   1.399 +// version 1 for test module's heap and stack sizes configuring).
   1.400 +// Returns: TInt: Symbian error code.
   1.401 +// -----------------------------------------------------------------------------
   1.402 +//
   1.403 +EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/, 
   1.404 +                                TUint32& /*aParameterValid*/ )
   1.405 +    {
   1.406 +
   1.407 +    /* --------------------------------- NOTE ---------------------------------
   1.408 +    USER PANICS occurs in test thread creation when:
   1.409 +    1) "The panic occurs when the value of the stack size is negative."
   1.410 +    2) "The panic occurs if the minimum heap size specified is less
   1.411 +       than KMinHeapSize".
   1.412 +       KMinHeapSize: "Functions that require a new heap to be allocated will
   1.413 +       either panic, or will reset the required heap size to this value if
   1.414 +       a smaller heap size is specified".
   1.415 +    3) "The panic occurs if the minimum heap size specified is greater than
   1.416 +       the maximum size to which the heap can grow".
   1.417 +    Other:
   1.418 +    1) Make sure that your hardware or Symbian OS is supporting given sizes.
   1.419 +       e.g. Hardware might support only sizes that are divisible by four.
   1.420 +    ------------------------------- NOTE end ------------------------------- */
   1.421 +
   1.422 +    // Normally STIF uses default heap and stack sizes for test thread, see:
   1.423 +    // KTestThreadMinHeap, KTestThreadMinHeap and KStackSize.
   1.424 +    // If needed heap and stack sizes can be configured here by user. Remove
   1.425 +    // comments and define sizes.
   1.426 +
   1.427 +/*
   1.428 +    aParameterValid = KStifTestModuleParameterChanged;
   1.429 +
   1.430 +    CTestModuleParamVer01* param = CTestModuleParamVer01::NewL();
   1.431 +    // Stack size
   1.432 +    param->iTestThreadStackSize= 16384; // 16K stack
   1.433 +    // Heap sizes
   1.434 +    param->iTestThreadMinHeap = 4096;   // 4K heap min
   1.435 +    param->iTestThreadMaxHeap = 1048576;// 1M heap max
   1.436 +
   1.437 +    aTestModuleParam = param;
   1.438 +*/
   1.439 +    return KErrNone;
   1.440 +
   1.441 +    }
   1.442 +
   1.443 +
   1.444 +//  End of File