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