sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: // [INCLUDE FILES] - do not remove sl@0: #include sl@0: #include "widecharclassapiBCTest.h" sl@0: #include sl@0: sl@0: // EXTERNAL DATA STRUCTURES sl@0: //extern ?external_data; sl@0: sl@0: // EXTERNAL FUNCTION PROTOTYPES sl@0: //extern ?external_function( ?arg_type,?arg_type ); sl@0: sl@0: // CONSTANTS sl@0: //const ?type ?constant_var = ?constant; sl@0: sl@0: // MACROS sl@0: //#define ?macro ?macro_def sl@0: sl@0: // LOCAL CONSTANTS AND MACROS sl@0: //const ?type ?constant_var = ?constant; sl@0: //#define ?macro_name ?macro_def sl@0: sl@0: // MODULE DATA STRUCTURES sl@0: //enum ?declaration sl@0: //typedef ?declaration sl@0: sl@0: // LOCAL FUNCTION PROTOTYPES sl@0: //?type ?function_name( ?arg_type, ?arg_type ); sl@0: sl@0: // FORWARD DECLARATIONS sl@0: //class ?FORWARD_CLASSNAME; sl@0: sl@0: // ============================= LOCAL FUNCTIONS =============================== sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // ?function_name ?description. sl@0: // ?description sl@0: // Returns: ?value_1: ?description sl@0: // ?value_n: ?description_line1 sl@0: // ?description_line2 sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: /* sl@0: ?type ?function_name( sl@0: ?arg_type arg, // ?description sl@0: ?arg_type arg) // ?description sl@0: { sl@0: sl@0: ?code // ?comment sl@0: sl@0: // ?comment sl@0: ?code sl@0: } sl@0: */ sl@0: sl@0: // ============================ MEMBER FUNCTIONS =============================== sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CwidecharclassapiBCTest::CwidecharclassapiBCTest sl@0: // C++ default constructor can NOT contain any code, that sl@0: // might leave. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: CwidecharclassapiBCTest::CwidecharclassapiBCTest() sl@0: { sl@0: sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CwidecharclassapiBCTest::ConstructL sl@0: // Symbian 2nd phase constructor can leave. sl@0: // sl@0: // Note: If OOM test case uses STIF Logger, then STIF Logger must be created sl@0: // with static buffer size parameter (aStaticBufferSize). Otherwise Logger sl@0: // allocates memory from heap and therefore causes error situations with OOM sl@0: // testing. For more information about STIF Logger construction, see STIF Users sl@0: // Guide. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: void CwidecharclassapiBCTest::ConstructL() sl@0: { sl@0: //Read logger settings to check whether test case name is to be sl@0: //appended to log file name. sl@0: RSettingServer settingServer; sl@0: TInt ret = settingServer.Connect(); sl@0: if(ret != KErrNone) sl@0: { sl@0: User::Leave(ret); sl@0: } sl@0: // Struct to StifLogger settigs. sl@0: TLoggerSettings loggerSettings; sl@0: // Parse StifLogger defaults from STIF initialization file. sl@0: ret = settingServer.GetLoggerSettings(loggerSettings); sl@0: if(ret != KErrNone) sl@0: { sl@0: User::Leave(ret); sl@0: } sl@0: // Close Setting server session sl@0: settingServer.Close(); sl@0: iAddTestCaseTitleToLogName = loggerSettings.iAddTestCaseTitle; sl@0: sl@0: iStdLog = CStifLogger::NewL( KwidecharclassapiBCTestLogPath, sl@0: KwidecharclassapiBCTestLogFile); sl@0: iLog = iStdLog; sl@0: sl@0: // Sample how to use logging sl@0: _LIT( KLogStart, "widecharclassapiBCTest logging starts!" ); sl@0: iLog->Log( KLogStart ); sl@0: sl@0: iVersionLogged = EFalse; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CwidecharclassapiBCTest::NewL sl@0: // Two-phased constructor. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: CwidecharclassapiBCTest* CwidecharclassapiBCTest::NewL() sl@0: { sl@0: CwidecharclassapiBCTest* self = new (ELeave) CwidecharclassapiBCTest; sl@0: sl@0: CleanupStack::PushL( self ); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: sl@0: return self; sl@0: sl@0: } sl@0: sl@0: // Destructor sl@0: CwidecharclassapiBCTest::~CwidecharclassapiBCTest() sl@0: { sl@0: iLog = NULL; sl@0: delete iStdLog; sl@0: iStdLog = NULL; sl@0: delete iTCLog; sl@0: iTCLog = NULL; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CwidecharclassapiBCTest::InitL sl@0: // InitL is used to initialize the Test Module. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: TInt CwidecharclassapiBCTest::InitL( sl@0: TFileName& /*aIniFile*/, sl@0: TBool /*aFirstTime*/ ) sl@0: { sl@0: return KErrNone; sl@0: sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CwidecharclassapiBCTest::GetTestCasesL sl@0: // GetTestCases is used to inquire test cases from the Test Module. Test sl@0: // cases are stored to array of test cases. The Test Framework will be sl@0: // the owner of the data in the RPointerArray after GetTestCases return sl@0: // and it does the memory deallocation. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: TInt CwidecharclassapiBCTest::GetTestCasesL( sl@0: const TFileName& /*aConfig*/, sl@0: RPointerArray& aTestCases ) sl@0: { sl@0: sl@0: // Loop through all test cases and create new sl@0: // TTestCaseInfo items and append items to aTestCase array sl@0: for( TInt i = 0; Case(i).iMethod != NULL; i++ ) sl@0: { sl@0: sl@0: // Allocate new TTestCaseInfo from heap for a testcase definition. sl@0: TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo(); sl@0: sl@0: // PushL TTestCaseInfo to CleanupStack. sl@0: CleanupStack::PushL( newCase ); sl@0: sl@0: // Set number for the testcase. sl@0: // When the testcase is run, this comes as a parameter to RunTestCaseL. sl@0: newCase->iCaseNumber = i; sl@0: sl@0: // Set title for the test case. This is shown in UI to user. sl@0: newCase->iTitle.Copy( Case(i).iCaseName ); sl@0: sl@0: // Append TTestCaseInfo to the testcase array. After appended sl@0: // successfully the TTestCaseInfo object is owned (and freed) sl@0: // by the TestServer. sl@0: User::LeaveIfError(aTestCases.Append ( newCase ) ); sl@0: sl@0: // Pop TTestCaseInfo from the CleanupStack. sl@0: CleanupStack::Pop( newCase ); sl@0: sl@0: } sl@0: sl@0: return KErrNone; sl@0: sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CwidecharclassapiBCTest::RunTestCaseL sl@0: // RunTestCaseL is used to run an individual test case specified sl@0: // by aTestCase. Test cases that can be run may be requested from sl@0: // Test Module by GetTestCases method before calling RunTestCase. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: TInt CwidecharclassapiBCTest::RunTestCaseL( sl@0: const TInt aCaseNumber, sl@0: const TFileName& /*aConfig*/, sl@0: TTestResult& aResult ) sl@0: { sl@0: if(!iVersionLogged) sl@0: { sl@0: SendTestModuleVersion(); sl@0: iVersionLogged = ETrue; sl@0: } sl@0: sl@0: // Return value sl@0: TInt execStatus = KErrNone; sl@0: sl@0: // Get the pointer to test case function sl@0: TCaseInfo tmp = Case ( aCaseNumber ); sl@0: sl@0: _LIT( KLogStartTC, "Starting testcase [%S]" ); sl@0: iLog->Log( KLogStartTC, &tmp.iCaseName); sl@0: sl@0: // Check that case number was valid sl@0: if ( tmp.iMethod != NULL ) sl@0: { sl@0: //Open new log file with test case title in file name sl@0: if(iAddTestCaseTitleToLogName) sl@0: { sl@0: //Delete test case logger if exists sl@0: if(iTCLog) sl@0: { sl@0: delete iTCLog; sl@0: iTCLog = NULL; sl@0: } sl@0: sl@0: TFileName logFileName; sl@0: TName title; sl@0: TestModuleIf().GetTestCaseTitleL(title); sl@0: sl@0: logFileName.Format(KwidecharclassapiBCTestLogFileWithTitle, &title); sl@0: sl@0: iTCLog = CStifLogger::NewL(KwidecharclassapiBCTestLogPath, sl@0: logFileName); sl@0: iLog = iTCLog; sl@0: } sl@0: sl@0: // Valid case was found, call it via function pointer sl@0: iMethod = tmp.iMethod; sl@0: //execStatus = ( this->*iMethod )( aResult ); sl@0: TRAPD(err, execStatus = ( this->*iMethod )( aResult )); sl@0: if(iAddTestCaseTitleToLogName) sl@0: { sl@0: //Restore standard log and destroy test case logger sl@0: iLog = iStdLog; sl@0: delete iTCLog; //Close test case log sl@0: iTCLog = NULL; sl@0: } sl@0: User::LeaveIfError(err); sl@0: } sl@0: else sl@0: { sl@0: // Valid case was not found, return error. sl@0: execStatus = KErrNotFound; sl@0: } sl@0: sl@0: // Return case execution status (not the result of the case execution) sl@0: return execStatus; sl@0: sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CwidecharclassapiBCTest::OOMTestQueryL sl@0: // Used to check if a particular test case should be run in OOM conditions and sl@0: // which memory allocations should fail. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: TBool CwidecharclassapiBCTest::OOMTestQueryL( sl@0: const TFileName& /* aTestCaseFile */, sl@0: const TInt aCaseNumber, sl@0: TOOMFailureType& /* aFailureType */, sl@0: TInt& aFirstMemFailure, sl@0: TInt& aLastMemFailure ) sl@0: { sl@0: _LIT( KLogOOMTestQueryL, "CwidecharclassapiBCTest::OOMTestQueryL" ); sl@0: iLog->Log( KLogOOMTestQueryL ); sl@0: sl@0: aFirstMemFailure = Case( aCaseNumber ).iFirstMemoryAllocation; sl@0: aLastMemFailure = Case( aCaseNumber ).iLastMemoryAllocation; sl@0: sl@0: return Case( aCaseNumber ).iIsOOMTest; sl@0: sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CwidecharclassapiBCTest::OOMTestInitializeL sl@0: // Used to perform the test environment setup for a particular OOM test case. sl@0: // Test Modules may use the initialization file to read parameters for Test sl@0: // Module initialization but they can also have their own configure file or sl@0: // some other routine to initialize themselves. sl@0: // sl@0: // NOTE: User may add implementation for OOM test environment initialization. sl@0: // Usually no implementation is required. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: void CwidecharclassapiBCTest::OOMTestInitializeL( sl@0: const TFileName& /* aTestCaseFile */, sl@0: const TInt /* aCaseNumber */ ) sl@0: { sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CwidecharclassapiBCTest::OOMHandleWarningL sl@0: // In some cases the heap memory allocation should be skipped, either due to sl@0: // problems in the OS code or components used by the code being tested, or even sl@0: // inside the tested components which are implemented this way on purpose (by sl@0: // design), so it is important to give the tester a way to bypass allocation sl@0: // failures. sl@0: // sl@0: // NOTE: User may add implementation for OOM test warning handling. Usually no sl@0: // implementation is required. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: void CwidecharclassapiBCTest::OOMHandleWarningL( sl@0: const TFileName& /* aTestCaseFile */, sl@0: const TInt /* aCaseNumber */, sl@0: TInt& /* aFailNextValue */ ) sl@0: { sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CwidecharclassapiBCTest::OOMTestFinalizeL sl@0: // Used to perform the test environment cleanup for a particular OOM test case. sl@0: // sl@0: // NOTE: User may add implementation for OOM test environment finalization. sl@0: // Usually no implementation is required. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: void CwidecharclassapiBCTest::OOMTestFinalizeL( sl@0: const TFileName& /* aTestCaseFile */, sl@0: const TInt /* aCaseNumber */ ) sl@0: { sl@0: } sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: // CwidecharclassapiBCTest::SendTestModuleVersion sl@0: // Method used to send version of test module sl@0: //----------------------------------------------------------------------------- sl@0: // sl@0: void CwidecharclassapiBCTest::SendTestModuleVersion() sl@0: { sl@0: TVersion moduleVersion; sl@0: moduleVersion.iMajor = TEST_MODULE_VERSION_MAJOR; sl@0: moduleVersion.iMinor = TEST_MODULE_VERSION_MINOR; sl@0: moduleVersion.iBuild = TEST_MODULE_VERSION_BUILD; sl@0: sl@0: TFileName moduleName; sl@0: moduleName = _L("widecharclassapiBCTest.dll"); sl@0: sl@0: TestModuleIf().SendTestModuleVersion(moduleVersion, moduleName); sl@0: } sl@0: sl@0: // ========================== OTHER EXPORTED FUNCTIONS ========================= sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // LibEntryL is a polymorphic Dll entry point sl@0: // Returns: CTestModuleBase*: Pointer to Test Module object sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: EXPORT_C CTestModuleBase* LibEntryL() sl@0: { sl@0: return CwidecharclassapiBCTest::NewL(); sl@0: sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // SetRequirements handles test module parameters(implements evolution sl@0: // version 1 for test module's heap and stack sizes configuring). sl@0: // Returns: TInt: Symbian error code. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/, sl@0: TUint32& /*aParameterValid*/ ) sl@0: { sl@0: sl@0: /* --------------------------------- NOTE --------------------------------- sl@0: USER PANICS occurs in test thread creation when: sl@0: 1) "The panic occurs when the value of the stack size is negative." sl@0: 2) "The panic occurs if the minimum heap size specified is less sl@0: than KMinHeapSize". sl@0: KMinHeapSize: "Functions that require a new heap to be allocated will sl@0: either panic, or will reset the required heap size to this value if sl@0: a smaller heap size is specified". sl@0: 3) "The panic occurs if the minimum heap size specified is greater than sl@0: the maximum size to which the heap can grow". sl@0: Other: sl@0: 1) Make sure that your hardware or Symbian OS is supporting given sizes. sl@0: e.g. Hardware might support only sizes that are divisible by four. sl@0: ------------------------------- NOTE end ------------------------------- */ sl@0: sl@0: // Normally STIF uses default heap and stack sizes for test thread, see: sl@0: // KTestThreadMinHeap, KTestThreadMinHeap and KStackSize. sl@0: // If needed heap and stack sizes can be configured here by user. Remove sl@0: // comments and define sizes. sl@0: sl@0: /* sl@0: aParameterValid = KStifTestModuleParameterChanged; sl@0: sl@0: CTestModuleParamVer01* param = CTestModuleParamVer01::NewL(); sl@0: // Stack size sl@0: param->iTestThreadStackSize= 16384; // 16K stack sl@0: // Heap sizes sl@0: param->iTestThreadMinHeap = 4096; // 4K heap min sl@0: param->iTestThreadMaxHeap = 1048576;// 1M heap max sl@0: sl@0: aTestModuleParam = param; sl@0: */ sl@0: return KErrNone; sl@0: sl@0: } sl@0: sl@0: sl@0: // End of File