stif/TestModuleTemplates/HardCodedTestModuleXXX/src/HardCodedTestModuleXXXCases.cpp
changeset 0 a03f92240627
child 18 3406c99bc375
equal deleted inserted replaced
-1:000000000000 0:a03f92240627
       
     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: This file contains hardcoded module implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // [INCLUDE FILES] - do not remove
       
    20 #include <e32math.h>
       
    21 #include "HardCodedTestModuleXXX.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 // CHardCodedTestModuleXXX::Case
       
    76 // Returns a test case by number.
       
    77 //
       
    78 // This function contains an array of all available test cases 
       
    79 // i.e pair of case name and test function. If case specified by parameter
       
    80 // aCaseNumber is found from array, then that item is returned.
       
    81 // 
       
    82 // The reason for this rather complicated function is to specify all the
       
    83 // test cases only in one place. It is not necessary to understand how
       
    84 // function pointers to class member functions works when adding new test
       
    85 // cases. See function body for instructions how to add new test case.
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 const TCaseInfo CHardCodedTestModuleXXX::Case ( 
       
    89     const TInt aCaseNumber ) const 
       
    90      {
       
    91 
       
    92     /**
       
    93     * To add new test cases, implement new test case function and add new 
       
    94     * line to KCases array specify the name of the case and the function 
       
    95     * doing the test case
       
    96     * In practice, do following
       
    97     * 1) Make copy of existing test case function and change its name
       
    98     *    and functionality. Note that the function must be added to 
       
    99     *    HardCodedTestModuleXXX.cpp file and to HardCodedTestModuleXXX.h 
       
   100     *    header file.
       
   101     *
       
   102     * 2) Add entry to following KCases array either by using:
       
   103     *
       
   104     * 2.1: FUNCENTRY or ENTRY macro
       
   105     * ENTRY macro takes two parameters: test case name and test case 
       
   106     * function name.
       
   107     *
       
   108     * FUNCENTRY macro takes only test case function name as a parameter and
       
   109     * uses that as a test case name and test case function name.
       
   110     *
       
   111     * Or
       
   112     *
       
   113     * 2.2: OOM_FUNCENTRY or OOM_ENTRY macro. Note that these macros are used
       
   114     * only with OOM (Out-Of-Memory) testing!
       
   115     *
       
   116     * OOM_ENTRY macro takes five parameters: test case name, test case 
       
   117     * function name, TBool which specifies is method supposed to be run using
       
   118     * OOM conditions, TInt value for first heap memory allocation failure and 
       
   119     * TInt value for last heap memory allocation failure.
       
   120     * 
       
   121     * OOM_FUNCENTRY macro takes test case function name as a parameter and uses
       
   122     * that as a test case name, TBool which specifies is method supposed to be
       
   123     * run using OOM conditions, TInt value for first heap memory allocation 
       
   124     * failure and TInt value for last heap memory allocation failure. 
       
   125     */ 
       
   126 
       
   127     static TCaseInfoInternal const KCases[] =
       
   128         {
       
   129         // [test cases entries] - do not remove
       
   130         
       
   131         // NOTE: When compiled to GCCE, there must be Classname::
       
   132         // declaration in front of the method name, e.g. 
       
   133         // CHardCodedTestModuleXXX::PrintTest. Otherwise the compiler
       
   134         // gives errors.
       
   135         
       
   136         FUNCENTRY( CHardCodedTestModuleXXX::PrintTest ),
       
   137         ENTRY( "Loop test", CHardCodedTestModuleXXX::LoopTest ),
       
   138         // Example how to use OOM functionality
       
   139         //OOM_ENTRY( "Loop test with OOM", CHardCodedTestModuleXXX::LoopTest, ETrue, 2, 3),
       
   140         //OOM_FUNCENTRY( CHardCodedTestModuleXXX::PrintTest, ETrue, 1, 3 ),
       
   141         };
       
   142 
       
   143     // Verify that case number is valid
       
   144     if( (TUint) aCaseNumber >= sizeof( KCases ) / 
       
   145                                sizeof( TCaseInfoInternal ) )
       
   146         {
       
   147         // Invalid case, construct empty object
       
   148         TCaseInfo null( (const TText*) L"" );
       
   149         null.iMethod = NULL;
       
   150         null.iIsOOMTest = EFalse;
       
   151         null.iFirstMemoryAllocation = 0;
       
   152         null.iLastMemoryAllocation = 0;
       
   153         return null;
       
   154         } 
       
   155 
       
   156     // Construct TCaseInfo object and return it
       
   157     TCaseInfo tmp ( KCases[ aCaseNumber ].iCaseName );
       
   158     tmp.iMethod = KCases[ aCaseNumber ].iMethod;
       
   159     tmp.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest;
       
   160     tmp.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation;
       
   161     tmp.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation;
       
   162     return tmp;
       
   163 
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CHardCodedTestModuleXXX::PrintTest
       
   168 // Simple printing to UI test.
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 TInt CHardCodedTestModuleXXX::PrintTest( 
       
   172     TTestResult& aResult )
       
   173     {
       
   174      /* Simple print test */
       
   175     _LIT( KPrintTest, "PrintTest" );
       
   176     _LIT( KEnter, "Enter" );
       
   177     _LIT( KOnGoing, "On-going" );
       
   178     _LIT( KExit, "Exit" );
       
   179 
       
   180     TestModuleIf().Printf( 0, KPrintTest, KEnter );
       
   181            
       
   182     TestModuleIf().Printf( 1, KPrintTest, KOnGoing );
       
   183     
       
   184     TestModuleIf().Printf( 0, KPrintTest, KExit );
       
   185 
       
   186     // Test case passed
       
   187 
       
   188     // Sets test case result and description(Maximum size is KStifMaxResultDes)
       
   189     _LIT( KDescription, "PrintTest passed" );
       
   190     aResult.SetResult( KErrNone, KDescription );
       
   191 
       
   192     // Case was executed
       
   193     return KErrNone;
       
   194 
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CHardCodedTestModuleXXX::LoopTest
       
   199 // Another printing to UI test.
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 TInt CHardCodedTestModuleXXX::LoopTest( TTestResult& aResult )
       
   203     {
       
   204 
       
   205     /* Simple print and wait loop */
       
   206     _LIT( KState, "State" );
       
   207     _LIT( KLooping, "Looping" );
       
   208 
       
   209     TestModuleIf().Printf( 0, KState, KLooping );
       
   210 
       
   211     _LIT( KRunning, "Running" );
       
   212     _LIT( KLoop, "%d" );
       
   213     for( TInt i=0; i<10; i++)
       
   214         {
       
   215         TestModuleIf().Printf( 1, KRunning, KLoop, i);
       
   216         User::After( 1000000 );
       
   217         }
       
   218 
       
   219     _LIT( KFinished, "Finished" );
       
   220     TestModuleIf().Printf( 0, KState, KFinished );
       
   221 
       
   222     // Test case passed
       
   223 
       
   224     // Sets test case result and description(Maximum size is KStifMaxResultDes)
       
   225     _LIT( KDescription, "LoopTest passed" );
       
   226     aResult.SetResult( KErrNone, KDescription );
       
   227 
       
   228     // Case was executed
       
   229     return KErrNone;
       
   230 
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // ?classname::?member_function
       
   235 // ?implementation_description
       
   236 // (other items were commented in a header).
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 /*
       
   240 ?type ?classname::?member_function(
       
   241    ?arg_type arg,
       
   242    ?arg_type arg )
       
   243    {
       
   244 
       
   245    ?code
       
   246 
       
   247    }
       
   248 */
       
   249 
       
   250 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // ?function_name implements...
       
   254 // ?implementation_description.
       
   255 // Returns: ?value_1: ?description
       
   256 //          ?value_n: ?description
       
   257 //                    ?description
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 /*
       
   261 ?type  ?function_name(
       
   262     ?arg_type arg,  // ?description
       
   263     ?arg_type arg )  // ?description
       
   264     {
       
   265 
       
   266     ?code
       
   267 
       
   268     }
       
   269 */
       
   270 //  [End of File] - do not remove