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