phoneapp/phoneui/tsrc/public/basic/3dringingtoneinterface_tests/src/3dringingtoneinterface_testsCases.cpp
changeset 0 5f000ab63145
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Implementation of C3dringingtoneinterface_tests class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32math.h>
       
    22 #include "3dringingtoneinterface_tests.h"
       
    23 
       
    24 
       
    25 #include <c3dringingtoneinterface.h>
       
    26  
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 //extern  ?external_data;
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES  
       
    31 //extern ?external_function( ?arg_type,?arg_type );
       
    32 
       
    33 // CONSTANTS
       
    34 //const ?type ?constant_var = ?constant;
       
    35 
       
    36 // MACROS
       
    37 //#define ?macro ?macro_def
       
    38 
       
    39 // LOCAL CONSTANTS AND MACROS
       
    40 //const ?type ?constant_var = ?constant;
       
    41 //#define ?macro_name ?macro_def
       
    42 
       
    43 // MODULE DATA STRUCTURES
       
    44 //enum ?declaration
       
    45 //typedef ?declaration
       
    46 
       
    47 // LOCAL FUNCTION PROTOTYPES
       
    48 //?type ?function_name( ?arg_type, ?arg_type );
       
    49 
       
    50 // FORWARD DECLARATIONS
       
    51 //class ?FORWARD_CLASSNAME;
       
    52 
       
    53 // ============================= LOCAL FUNCTIONS ===============================
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // ?function_name ?description.
       
    57 // ?description
       
    58 // Returns: ?value_1: ?description
       
    59 //          ?value_n: ?description_line1
       
    60 //                    ?description_line2
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 /*
       
    64 ?type ?function_name(
       
    65     ?arg_type arg,  // ?description
       
    66     ?arg_type arg)  // ?description
       
    67     {
       
    68 
       
    69     ?code  // ?comment
       
    70 
       
    71     // ?comment
       
    72     ?code
       
    73     }
       
    74 */
       
    75 
       
    76 // ============================ MEMBER FUNCTIONS ===============================
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // C3dringingtoneinterface_tests::Case
       
    80 // Returns a test case by number.
       
    81 //
       
    82 // This function contains an array of all available test cases 
       
    83 // i.e pair of case name and test function. If case specified by parameter
       
    84 // aCaseNumber is found from array, then that item is returned.
       
    85 // 
       
    86 // The reason for this rather complicated function is to specify all the
       
    87 // test cases only in one place. It is not necessary to understand how
       
    88 // function pointers to class member functions works when adding new test
       
    89 // cases. See function body for instructions how to add new test case.
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 const TCaseInfo C3dringingtoneinterface_tests::Case ( 
       
    93     const TInt aCaseNumber ) const 
       
    94      {
       
    95 
       
    96     /**
       
    97     * To add new test cases, implement new test case function and add new 
       
    98     * line to KCases array specify the name of the case and the function 
       
    99     * doing the test case
       
   100     * In practice, do following
       
   101     * 1) Make copy of existing test case function and change its name
       
   102     *    and functionality. Note that the function must be added to 
       
   103     *    3dringingtoneinterface_tests.cpp file and to 3dringingtoneinterface_tests.h 
       
   104     *    header file.
       
   105     *
       
   106     * 2) Add entry to following KCases array either by using:
       
   107     *
       
   108     * 2.1: FUNCENTRY or ENTRY macro
       
   109     * ENTRY macro takes two parameters: test case name and test case 
       
   110     * function name.
       
   111     *
       
   112     * FUNCENTRY macro takes only test case function name as a parameter and
       
   113     * uses that as a test case name and test case function name.
       
   114     *
       
   115     * Or
       
   116     *
       
   117     * 2.2: OOM_FUNCENTRY or OOM_ENTRY macro. Note that these macros are used
       
   118     * only with OOM (Out-Of-Memory) testing!
       
   119     *
       
   120     * OOM_ENTRY macro takes five parameters: test case name, test case 
       
   121     * function name, TBool which specifies is method supposed to be run using
       
   122     * OOM conditions, TInt value for first heap memory allocation failure and 
       
   123     * TInt value for last heap memory allocation failure.
       
   124     * 
       
   125     * OOM_FUNCENTRY macro takes test case function name as a parameter and uses
       
   126     * that as a test case name, TBool which specifies is method supposed to be
       
   127     * run using OOM conditions, TInt value for first heap memory allocation 
       
   128     * failure and TInt value for last heap memory allocation failure. 
       
   129     */ 
       
   130 
       
   131     static TCaseInfoInternal const KCases[] =
       
   132         {
       
   133         // To add new test cases, add new items to this array
       
   134         
       
   135         // NOTE: When compiled to GCCE, there must be Classname::
       
   136         // declaration in front of the method name, e.g. 
       
   137         // C3dringingtoneinterface_tests::PrintTest. Otherwise the compiler
       
   138         // gives errors.
       
   139         
       
   140         ENTRY( "3DRinging CreateAndDelete", C3dringingtoneinterface_tests::CreateAndDelete ),
       
   141         ENTRY( "3DRinging PlayAndStop", C3dringingtoneinterface_tests::PlayAndStop ),
       
   142         // Example how to use OOM functionality
       
   143         //OOM_ENTRY( "Loop test with OOM", C3dringingtoneinterface_tests::LoopTest, ETrue, 2, 3),
       
   144         //OOM_FUNCENTRY( C3dringingtoneinterface_tests::PrintTest, ETrue, 1, 3 ),
       
   145         };
       
   146 
       
   147     // Verify that case number is valid
       
   148     if( (TUint) aCaseNumber >= sizeof( KCases ) / 
       
   149                                sizeof( TCaseInfoInternal ) )
       
   150         {
       
   151         // Invalid case, construct empty object
       
   152         TCaseInfo null( (const TText*) L"" );
       
   153         null.iMethod = NULL;
       
   154         null.iIsOOMTest = EFalse;
       
   155         null.iFirstMemoryAllocation = 0;
       
   156         null.iLastMemoryAllocation = 0;
       
   157         return null;
       
   158         } 
       
   159 
       
   160     // Construct TCaseInfo object and return it
       
   161     TCaseInfo tmp ( KCases[ aCaseNumber ].iCaseName );
       
   162     tmp.iMethod = KCases[ aCaseNumber ].iMethod;
       
   163     tmp.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest;
       
   164     tmp.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation;
       
   165     tmp.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation;
       
   166     return tmp;
       
   167 
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // C3dringingtoneinterface_tests::PrintTest
       
   172 // Simple printing to UI test.
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 TInt C3dringingtoneinterface_tests::PrintTest( 
       
   176     TTestResult& aResult )
       
   177     {
       
   178      /* Simple print test */
       
   179     _LIT( KPrintTest, "PrintTest" );
       
   180     _LIT( KEnter, "Enter" );
       
   181     _LIT( KOnGoing, "On-going" );
       
   182     _LIT( KExit, "Exit" );
       
   183 
       
   184     TestModuleIf().Printf( 0, KPrintTest, KEnter );
       
   185            
       
   186     TestModuleIf().Printf( 1, KPrintTest, KOnGoing );
       
   187     
       
   188     TestModuleIf().Printf( 0, KPrintTest, KExit );
       
   189 
       
   190     // Test case passed
       
   191 
       
   192     // Sets test case result and description(Maximum size is KStifMaxResultDes)
       
   193     _LIT( KDescription, "PrintTest passed" );
       
   194     aResult.SetResult( KErrNone, KDescription );
       
   195 
       
   196     // Case was executed
       
   197     return KErrNone;
       
   198 
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // C3dringingtoneinterface_tests::LoopTest
       
   203 // Another printing to UI test.
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 TInt C3dringingtoneinterface_tests::LoopTest( TTestResult& aResult )
       
   207     {
       
   208 
       
   209     /* Simple print and wait loop */
       
   210     _LIT( KState, "State" );
       
   211     _LIT( KLooping, "Looping" );
       
   212 
       
   213     TestModuleIf().Printf( 0, KState, KLooping );
       
   214 
       
   215     _LIT( KRunning, "Running" );
       
   216     _LIT( KLoop, "%d" );
       
   217     for( TInt i=0; i<10; i++)
       
   218         {
       
   219         TestModuleIf().Printf( 1, KRunning, KLoop, i);
       
   220         User::After( 1000000 );
       
   221         }
       
   222 
       
   223     _LIT( KFinished, "Finished" );
       
   224     TestModuleIf().Printf( 0, KState, KFinished );
       
   225 
       
   226     // Test case passed
       
   227 
       
   228     // Sets test case result and description(Maximum size is KStifMaxResultDes)
       
   229     _LIT( KDescription, "LoopTest passed" );
       
   230     aResult.SetResult( KErrNone, KDescription );
       
   231 
       
   232     // Case was executed
       
   233     return KErrNone;
       
   234 
       
   235     }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // C3dringingtoneinterface_tests::CreateAndDelete
       
   239 // Another printing to UI test.
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 TInt C3dringingtoneinterface_tests::CreateAndDelete( TTestResult& aResult )
       
   243     {
       
   244     __UHEAP_MARK;
       
   245     
       
   246     CActiveScheduler* scheduler = new( ELeave )CActiveScheduler();
       
   247     CActiveScheduler::Install( scheduler );
       
   248     CleanupStack::PushL( scheduler );
       
   249     
       
   250     C3DRingingToneInterface* plugin=NULL;
       
   251         
       
   252     TRAPD( err,plugin = C3DRingingToneInterface::NewL( KNullUid ) );
       
   253         
       
   254     delete plugin;
       
   255     
       
   256     CleanupStack::PopAndDestroy( scheduler );
       
   257 
       
   258  
       
   259     REComSession::FinalClose();
       
   260     __UHEAP_MARKEND;
       
   261     
       
   262     // Sets test case result and description(Maximum size is KStifMaxResultDes)
       
   263     _LIT( KDescription, "CreateAndDelete passed" );
       
   264     aResult.SetResult( KErrNone, KDescription );
       
   265 
       
   266     // Case was executed
       
   267     return KErrNone;
       
   268 
       
   269     }
       
   270     
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // C3dringingtoneinterface_tests::PlayAndStop
       
   274 // Another printing to UI test.
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 TInt C3dringingtoneinterface_tests::PlayAndStop( TTestResult& aResult )
       
   278     {
       
   279     __UHEAP_MARK;
       
   280     
       
   281     CActiveScheduler* scheduler = new( ELeave )CActiveScheduler();
       
   282     CActiveScheduler::Install( scheduler );
       
   283     CleanupStack::PushL( scheduler );
       
   284  
       
   285     C3DRingingToneInterface* plugin=NULL;
       
   286     
       
   287         
       
   288     TRAPD( err,plugin = C3DRingingToneInterface::NewL( KNullUid ) );
       
   289     
       
   290     if ( !err && plugin )
       
   291         {
       
   292         plugin->PlayL();
       
   293         plugin->Stop();
       
   294         }
       
   295   
       
   296     delete plugin;
       
   297     
       
   298     CleanupStack::PopAndDestroy( scheduler );
       
   299 
       
   300     REComSession::FinalClose();
       
   301     __UHEAP_MARKEND;
       
   302     
       
   303     // Sets test case result and description(Maximum size is KStifMaxResultDes)
       
   304     _LIT( KDescription, "PlayAndStop passed" );
       
   305     aResult.SetResult( KErrNone, KDescription );
       
   306 
       
   307     // Case was executed
       
   308     return KErrNone;
       
   309 
       
   310     }    
       
   311   
       
   312 //  End of File