testexecfw/stf/stffw/event/src/SUEventCases.cpp
changeset 2 8bb370ba6d1d
equal deleted inserted replaced
1:bbd31066657e 2:8bb370ba6d1d
       
     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 SUEvent module implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32math.h>
       
    20 #include "SUEvent.h"
       
    21 #include <StifTestEventInterface.h>
       
    22 
       
    23 #include <e32svr.h>
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 //extern  ?external_data;
       
    27 
       
    28 // EXTERNAL FUNCTION PROTOTYPES  
       
    29 //extern ?external_function( ?arg_type,?arg_type );
       
    30 
       
    31 // CONSTANTS
       
    32 //const ?type ?constant_var = ?constant;
       
    33 
       
    34 // MACROS
       
    35 //#define ?macro ?macro_def
       
    36 
       
    37 // LOCAL CONSTANTS AND MACROS
       
    38 //const ?type ?constant_var = ?constant;
       
    39 //#define ?macro_name ?macro_def
       
    40 
       
    41 // MODULE DATA STRUCTURES
       
    42 //enum ?declaration
       
    43 //typedef ?declaration
       
    44 
       
    45 // LOCAL FUNCTION PROTOTYPES
       
    46 //?type ?function_name( ?arg_type, ?arg_type );
       
    47 
       
    48 // FORWARD DECLARATIONS
       
    49 //class ?FORWARD_CLASSNAME;
       
    50 
       
    51 // ============================= LOCAL FUNCTIONS ===============================
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // ?function_name ?description.
       
    55 // ?description
       
    56 // Returns: ?value_1: ?description
       
    57 //          ?value_n: ?description_line1
       
    58 //                    ?description_line2
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 /*
       
    62 ?type ?function_name(
       
    63     ?arg_type arg,  // ?description
       
    64     ?arg_type arg)  // ?description
       
    65     {
       
    66 
       
    67     ?code  // ?comment
       
    68 
       
    69     // ?comment
       
    70     ?code
       
    71     }
       
    72 */
       
    73 
       
    74 // ============================ MEMBER FUNCTIONS ===============================
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CSUEvent::Case
       
    78 // Returns a test case by number.
       
    79 //
       
    80 // This function contains an array of all available test cases 
       
    81 // i.e pair of case name and test function. If case specified by parameter
       
    82 // aCaseNumber is found from array, then that item is returned.
       
    83 // 
       
    84 // The reason for this rather complicated function is to specify all the
       
    85 // test cases only in one place. It is not necessary to understand how
       
    86 // function pointers to class member functions works when adding new test
       
    87 // cases. See function body for instructions how to add new test case.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 const TCaseInfo CSUEvent::Case ( 
       
    91     const TInt aCaseNumber ) const 
       
    92      {
       
    93 
       
    94     /**
       
    95     * To add new test cases, implement new test case function and add new 
       
    96     * line to KCases array specify the name of the case and the function 
       
    97     * doing the test case
       
    98     * In practice, do following
       
    99     * 1) Make copy of existing test case function and change its name
       
   100     *    and functionality. Note that the function must be added to 
       
   101     *    SUEvent.cpp file and to SUEvent.h 
       
   102     *    header file.
       
   103     *
       
   104     * 2) Add entry to following KCases array either by using:
       
   105     *
       
   106     * 2.1: FUNCENTRY or ENTRY macro
       
   107     * ENTRY macro takes two parameters: test case name and test case 
       
   108     * function name.
       
   109     *
       
   110     * FUNCENTRY macro takes only test case function name as a parameter and
       
   111     * uses that as a test case name and test case function name.
       
   112     *
       
   113     * Or
       
   114     *
       
   115     * 2.2: OOM_FUNCENTRY or OOM_ENTRY macro. Note that these macros are used
       
   116     * only with OOM (Out-Of-Memory) testing!
       
   117     *
       
   118     * OOM_ENTRY macro takes five parameters: test case name, test case 
       
   119     * function name, TBool which specifies is method supposed to be run using
       
   120     * OOM conditions, TInt value for first heap memory allocation failure and 
       
   121     * TInt value for last heap memory allocation failure.
       
   122     * 
       
   123     * OOM_FUNCENTRY macro takes test case function name as a parameter and uses
       
   124     * that as a test case name, TBool which specifies is method supposed to be
       
   125     * run using OOM conditions, TInt value for first heap memory allocation 
       
   126     * failure and TInt value for last heap memory allocation failure. 
       
   127     */ 
       
   128 
       
   129     static TCaseInfoInternal const KCases[] =
       
   130         {
       
   131         // To add new test cases, add new items to this array
       
   132 
       
   133         // NOTE: When compiled to GCCE, there must be Classname::
       
   134         // declaration in front of the method name, e.g.
       
   135         // CSUEvent::PrintTest. Otherwise the compiler
       
   136         // gives errors.
       
   137 
       
   138 		//sets event as state event
       
   139         ENTRY("SetEventState",			CSUEvent::SetEventState),
       
   140         //sets event as indication event
       
   141         ENTRY("SetEventIndication",		CSUEvent::SetEventIndication),
       
   142         //unsets event
       
   143         ENTRY("UnsetEvent",				CSUEvent::UnsetEvent),
       
   144         //waits for evenr
       
   145         ENTRY("WaitEvent",				CSUEvent::WaitEvent),
       
   146         //sets event as indication in hard mode
       
   147         ENTRY("SetEventIndicationHard",	CSUEvent::SetEventIndicationHard),
       
   148         // Example how to use OOM functionality
       
   149         //OOM_ENTRY( "Loop test with OOM", CSUEvent::LoopTest, ETrue, 2, 3),
       
   150         //OOM_FUNCENTRY( CSUEvent::PrintTest, ETrue, 1, 3 ),
       
   151         };
       
   152 
       
   153     // Verify that case number is valid
       
   154     if( (TUint) aCaseNumber >= sizeof( KCases ) /
       
   155                                sizeof( TCaseInfoInternal ) )
       
   156         {
       
   157         // Invalid case, construct empty object
       
   158         TCaseInfo null( (const TText*) L"" );
       
   159         null.iMethod = NULL;
       
   160         null.iIsOOMTest = EFalse;
       
   161         null.iFirstMemoryAllocation = 0;
       
   162         null.iLastMemoryAllocation = 0;
       
   163         return null;
       
   164         }
       
   165 
       
   166     // Construct TCaseInfo object and return it
       
   167     TCaseInfo tmp ( KCases[ aCaseNumber ].iCaseName );
       
   168     tmp.iMethod = KCases[ aCaseNumber ].iMethod;
       
   169     tmp.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest;
       
   170     tmp.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation;
       
   171     tmp.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation;
       
   172     return tmp;
       
   173 
       
   174     }
       
   175 
       
   176 //#0
       
   177 TInt CSUEvent::SetEventState(TTestResult& aResult, const TFileName& aEventName)
       
   178     {
       
   179 //RDebug::Print(_L(" CSUEvent::SetEventState start event_name=%S (%d)"), &aEventName, RThread().Id().Id());
       
   180 	iLog->Log(_L("CSUEvent::SetEventState event=%S"), &aEventName);
       
   181 
       
   182 	//Set state event
       
   183 	TEventIf setEvent(TEventIf::ESetEvent, aEventName, TEventIf::EState);
       
   184 //RDebug::Print(_L(" CSUEvent::SetEventState call Event (%d)"), RThread().Id().Id());
       
   185 	TestModuleIf().Event(setEvent);
       
   186 	
       
   187 //RDebug::Print(_L(" CSUEvent::SetEventState call SetResult (%d)"), RThread().Id().Id());
       
   188 	aResult.SetResult(KErrNone, _L(""));
       
   189 
       
   190 //RDebug::Print(_L(" CSUEvent::SetEventState end (%d)"), RThread().Id().Id());
       
   191     return KErrNone;
       
   192     }
       
   193 
       
   194 //#1
       
   195 TInt CSUEvent::SetEventIndication(TTestResult& aResult, const TFileName& aEventName)
       
   196     {
       
   197 //RDebug::Print(_L(" CSUEvent::SetEventIndication start event_name=%S (%d)"), &aEventName, RThread().Id().Id());
       
   198 	iLog->Log(_L("CSUEvent::SetEventIndication event=%S"), &aEventName);
       
   199 
       
   200 	//Set indication event
       
   201 	TEventIf setEvent(TEventIf::ESetEvent, aEventName, TEventIf::EIndication);
       
   202 //RDebug::Print(_L(" CSUEvent::SetEventIndication call Event (%d)"), RThread().Id().Id());
       
   203 	TestModuleIf().Event(setEvent);
       
   204 
       
   205 //RDebug::Print(_L(" CSUEvent::SetEventIndication call SetResult (%d)"), RThread().Id().Id());
       
   206 	aResult.SetResult(KErrNone, _L(""));
       
   207 //RDebug::Print(_L(" CSUEvent::SetEventIndication end (%d)"), RThread().Id().Id());
       
   208     return KErrNone;
       
   209     }
       
   210 
       
   211 //#2
       
   212 TInt CSUEvent::UnsetEvent(TTestResult& aResult, const TFileName& aEventName)
       
   213     {
       
   214 RDebug::Print(_L("CSUEvent::UnsetEvent start event_name=%S"), &aEventName);
       
   215 	iLog->Log(_L("CSUEvent::UnsetEvent event=%S"), &aEventName);
       
   216 
       
   217 	//Unset event
       
   218 	TEventIf event(TEventIf::EUnsetEvent, aEventName, TEventIf::EState);
       
   219 RDebug::Print(_L("CSUEvent::UnsetEvent call Event"));
       
   220 	TestModuleIf().Event(event);
       
   221 
       
   222 RDebug::Print(_L("CSUEvent::UnsetEvent call SetResult"));
       
   223 	aResult.SetResult(KErrNone, _L(""));
       
   224 RDebug::Print(_L("CSUEvent::UnsetEvent end"));
       
   225     return KErrNone;
       
   226     }
       
   227 
       
   228 
       
   229 //#3
       
   230 TInt CSUEvent::WaitEvent(TTestResult& aResult, const TFileName& aEventName)
       
   231     {
       
   232 //RDebug::Print(_L(" CSUEvent::WaitEvent start event name=%S (%d)"), &aEventName, RThread().Id().Id());
       
   233 	iLog->Log(_L("CSUEvent::WaitEvent event=%S"), &aEventName);
       
   234 
       
   235 	//Request, wait for, and release event
       
   236 //RDebug::Print(_L(" CSUEvent::WaitEvent set event request (%d)"), RThread().Id().Id());
       
   237 	TEventIf event(TEventIf::EReqEvent, aEventName, TEventIf::EState);
       
   238 //RDebug::Print(_L(" CSUEvent::WaitEvent call Event (%d)"), RThread().Id().Id());
       
   239 	TestModuleIf().Event(event);
       
   240 //RDebug::Print(_L(" CSUEvent::WaitEvent set event (%d)"), RThread().Id().Id());
       
   241 	event.SetType(TEventIf::EWaitEvent);
       
   242 //RDebug::Print(_L(" CSUEvent::WaitEvent call Event (%d)"), RThread().Id().Id());
       
   243 	TestModuleIf().Event(event);
       
   244 //RDebug::Print(_L(" CSUEvent::WaitEvent set event release (%d)"), RThread().Id().Id());
       
   245 	event.SetType(TEventIf::ERelEvent);
       
   246 //RDebug::Print(_L(" CSUEvent::WaitEvent call Event (%d)"), RThread().Id().Id());
       
   247 	TestModuleIf().Event(event);
       
   248 
       
   249 //RDebug::Print(_L(" CSUEvent::WaitEvent call SetResult (%d)"), RThread().Id().Id());
       
   250 	aResult.SetResult(KErrNone, _L(""));
       
   251 //RDebug::Print(_L(" CSUEvent::WaitEvent end (%d)"), RThread().Id().Id());
       
   252     return KErrNone;
       
   253     }
       
   254 
       
   255 
       
   256 //#4
       
   257 TInt CSUEvent::SetEventIndicationHard(TTestResult& aResult, const TFileName& /*aEventName*/)
       
   258     {
       
   259 //RDebug::Print(_L(" CSUEvent::SetEventIndicationHard start (%d)"), RThread().Id().Id());
       
   260 	iLog->Log(_L("CSUEvent::SetEventIndicationHard"));
       
   261 
       
   262 	TBuf<20> eventName;
       
   263 	eventName.Copy(_L("event1"));
       
   264 	//Set indication event
       
   265 	TEventIf setEvent(TEventIf::ESetEvent, eventName, TEventIf::EIndication);
       
   266 //RDebug::Print(_L(" CSUEvent::SetEventIndicationHard call Event (%d)"), RThread().Id().Id());
       
   267 	TestModuleIf().Event(setEvent);
       
   268 
       
   269 //RDebug::Print(_L(" CSUEvent::SetEventIndicationHard call SetResult (%d)"), RThread().Id().Id());
       
   270 	aResult.SetResult(KErrNone, _L(""));
       
   271 //RDebug::Print(_L(" CSUEvent::SetEventIndicationHard end (%d)"), RThread().Id().Id());
       
   272     return KErrNone;
       
   273     }
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // ?classname::?member_function
       
   277 // ?implementation_description
       
   278 // (other items were commented in a header).
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 /*
       
   282 ?type ?classname::?member_function(
       
   283    ?arg_type arg,
       
   284    ?arg_type arg )
       
   285    {
       
   286 
       
   287    ?code
       
   288 
       
   289    }
       
   290 */
       
   291 
       
   292 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // ?function_name implements...
       
   296 // ?implementation_description.
       
   297 // Returns: ?value_1: ?description
       
   298 //          ?value_n: ?description
       
   299 //                    ?description
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 /*
       
   303 ?type  ?function_name(
       
   304     ?arg_type arg,  // ?description
       
   305     ?arg_type arg )  // ?description
       
   306     {
       
   307 
       
   308     ?code
       
   309 
       
   310     }
       
   311 */
       
   312 //  End of File