mmmw_plat/openmax_al_api/tsrc/openmaxaltestmodule/src/player/openmaxalprefetchstatusitftests.cpp
changeset 53 eabc8c503852
equal deleted inserted replaced
48:a493a607b5bf 53:eabc8c503852
       
     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 testclass implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // [INCLUDE FILES] - do not remove
       
    19 #include <e32svr.h>
       
    20 #include <StifParser.h>
       
    21 #include <StifTestInterface.h>
       
    22 #include <StifTestEventInterface.h>
       
    23 #include "openmaxaltestmodule.h"
       
    24 #include "profileutilmacro.h"
       
    25 
       
    26 // EXTERNAL DATA STRUCTURES
       
    27 //extern  ?external_data;
       
    28 
       
    29 // EXTERNAL FUNCTION PROTOTYPES  
       
    30 //extern ?external_function( ?arg_type,?arg_type );
       
    31 
       
    32 // CONSTANTS
       
    33 //const ?type ?constant_var = ?constant;
       
    34 
       
    35 // MACROS
       
    36 //#define ?macro ?macro_def
       
    37 
       
    38 // LOCAL CONSTANTS AND MACROS
       
    39 //const ?type ?constant_var = ?constant;
       
    40 //#define ?macro_name ?macro_def
       
    41 
       
    42 // MODULE DATA STRUCTURES
       
    43 //enum ?declaration
       
    44 //typedef ?declaration
       
    45 
       
    46 // LOCAL FUNCTION PROTOTYPES
       
    47 //?type ?function_name( ?arg_type, ?arg_type );
       
    48 void PrefetchStatusItfCallback (
       
    49     XAPrefetchStatusItf caller,
       
    50     void * pContext,
       
    51     XAuint32 event);
       
    52 
       
    53 void PrefetchStatusItfTestEventCallback (
       
    54     XAPrefetchStatusItf caller,
       
    55     void * pContext,
       
    56     XAuint32 event);
       
    57 // FORWARD DECLARATIONS
       
    58 //class ?FORWARD_CLASSNAME;
       
    59 
       
    60 // ============================= LOCAL FUNCTIONS ===============================
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // ?function_name ?description.
       
    64 // ?description
       
    65 // Returns: ?value_1: ?description
       
    66 //          ?value_n: ?description_line1
       
    67 //                    ?description_line2
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 /*
       
    71 ?type ?function_name(
       
    72     ?arg_type arg,  // ?description
       
    73     ?arg_type arg)  // ?description
       
    74     {
       
    75 
       
    76     ?code  // ?comment
       
    77 
       
    78     // ?comment
       
    79     ?code
       
    80     }
       
    81 */
       
    82 
       
    83 TInt COpenMAXALTestModule::al_prefetchstatusitf_GetFillLevel( CStifItemParser& aItem )
       
    84 {
       
    85     TInt status(KErrGeneral);
       
    86     XApermille fL(0);
       
    87     
       
    88     TInt fillLevel = 0;
       
    89     status = aItem.GetNextInt(fillLevel);
       
    90 
       
    91     if((status==KErrNone) && m_PrefetchStatusItf)
       
    92     {
       
    93         XAresult res = (*m_PrefetchStatusItf)->GetFillLevel(m_PrefetchStatusItf, &fL);              
       
    94         status = MapErr(res);
       
    95     }
       
    96     
       
    97     if((m_PrefetchStatusItf == NULL) || 
       
    98        (status != KErrNone) || 
       
    99        (fL != fillLevel))  
       
   100     {
       
   101         status = KErrNotFound;
       
   102     }    
       
   103     
       
   104     return status;
       
   105 }
       
   106 
       
   107 TInt COpenMAXALTestModule::al_prefetchstatusitf_GetPrefetchStatus( CStifItemParser& aItem )
       
   108 {
       
   109     TInt status(KErrGeneral);
       
   110     XAuint32 pfs(0);
       
   111     
       
   112     TInt prefetchStatus = 0;
       
   113     status = aItem.GetNextInt(prefetchStatus);
       
   114     
       
   115     if((status==KErrNone) && m_PrefetchStatusItf)
       
   116     {
       
   117         XAresult res = (*m_PrefetchStatusItf)->GetPrefetchStatus(m_PrefetchStatusItf, &pfs);              
       
   118         status = MapErr(res);
       
   119     }
       
   120     
       
   121     if( (m_PrefetchStatusItf == NULL) || 
       
   122         (status != KErrNone) || 
       
   123         (pfs != prefetchStatus))  
       
   124     {
       
   125         status = KErrNotFound;
       
   126     }    
       
   127     
       
   128     return status;
       
   129 }
       
   130 
       
   131 TInt COpenMAXALTestModule::al_prefetchstatusitf_RegisterCallback( CStifItemParser& /*aItem*/ )
       
   132     {
       
   133     TInt status(KErrNone);
       
   134     XAresult res;
       
   135 
       
   136     if(m_PrefetchStatusItf)
       
   137         {
       
   138         res = (*m_PrefetchStatusItf)->RegisterCallback(
       
   139                 m_PrefetchStatusItf, &PrefetchStatusItfCallback, (void*)this);              
       
   140         status = MapErr(res);
       
   141         }
       
   142     else
       
   143         {
       
   144         status = KErrNotFound;
       
   145         }    
       
   146 
       
   147     return status;
       
   148     }
       
   149 
       
   150 TInt COpenMAXALTestModule::al_prefetchstatusitf_RegisterTestEventCallback( CStifItemParser& /*aItem*/ )
       
   151     {
       
   152     TInt status(KErrNone);
       
   153     XAresult res;
       
   154 
       
   155     if(m_PrefetchStatusItf)
       
   156         {
       
   157         res = (*m_PrefetchStatusItf)->RegisterCallback(
       
   158                 m_PrefetchStatusItf, &PrefetchStatusItfTestEventCallback, (void*)this);              
       
   159         status = MapErr(res);
       
   160         }
       
   161     else
       
   162         {
       
   163         status = KErrNotFound;
       
   164         }    
       
   165 
       
   166     return status;
       
   167     }
       
   168 
       
   169 TInt COpenMAXALTestModule::al_prefetchstatusitf_SetCallbackEventMask( CStifItemParser& aItem )
       
   170     {
       
   171     TInt status(KErrNone);
       
   172     TInt eventMask;
       
   173     status = aItem.GetNextInt(eventMask);
       
   174     RET_ERR_IF_ERR(status);
       
   175 
       
   176     if(m_PrefetchStatusItf)
       
   177         {
       
   178         status = (*m_PrefetchStatusItf)->SetCallbackEventsMask(
       
   179                 m_PrefetchStatusItf, eventMask);              
       
   180         }
       
   181     else
       
   182         {
       
   183         status = KErrNotFound;
       
   184         }
       
   185     return status;
       
   186     }
       
   187 
       
   188 TInt COpenMAXALTestModule::al_prefetchstatusitf_GetCallbackEventMaskNullParam( CStifItemParser& /*aItem*/ )
       
   189     {
       
   190     TInt status(KErrNone);
       
   191     if(m_PrefetchStatusItf)
       
   192         {
       
   193         status = (*m_PrefetchStatusItf)->GetCallbackEventsMask(
       
   194                 m_PrefetchStatusItf, NULL);              
       
   195         }
       
   196     else
       
   197         {
       
   198         status = KErrNotFound;
       
   199         }    
       
   200 
       
   201     return status;
       
   202     }
       
   203 
       
   204 TInt COpenMAXALTestModule::al_prefetchstatusitf_GetCallbackEventMask( CStifItemParser& aItem )
       
   205     {
       
   206     TInt status(KErrNone);
       
   207     XAuint32 eventMask;
       
   208     TInt expectedEventMask;
       
   209     status = aItem.GetNextInt(expectedEventMask);
       
   210     RET_ERR_IF_ERR(status);
       
   211 
       
   212     if(m_PrefetchStatusItf)
       
   213         {
       
   214         status = (*m_PrefetchStatusItf)->GetCallbackEventsMask(
       
   215                 m_PrefetchStatusItf, &eventMask);              
       
   216         if (!status)
       
   217             {
       
   218             /* Fail if position is not expected*/
       
   219             if (eventMask != expectedEventMask)
       
   220                 {
       
   221                 status = KErrCompletion;
       
   222                 }
       
   223             }
       
   224         }
       
   225     else
       
   226         {
       
   227         status = KErrNotFound;
       
   228         }    
       
   229 
       
   230     return status;
       
   231     }
       
   232 
       
   233 TInt COpenMAXALTestModule::al_prefetchstatusitf_SetFillUpdatePeriod( CStifItemParser& aItem )
       
   234 {
       
   235     TInt status(KErrNone);
       
   236     TInt updatePeriod;
       
   237     status = aItem.GetNextInt(updatePeriod);
       
   238     RET_ERR_IF_ERR(status);
       
   239 
       
   240     if(m_PrefetchStatusItf)
       
   241     {
       
   242         status = (*m_PrefetchStatusItf)->SetFillUpdatePeriod(
       
   243                 m_PrefetchStatusItf, (XAmillisecond)updatePeriod);
       
   244         
       
   245         //used for testing fill events
       
   246         iFillUpdateIncrement = updatePeriod;
       
   247     }
       
   248     else
       
   249     {
       
   250         status = KErrNotFound;
       
   251     }    
       
   252     return status;
       
   253 }
       
   254 
       
   255 TInt COpenMAXALTestModule::al_prefetchstatusitf_GetFillUpdatePeriodNullParam( CStifItemParser& /*aItem*/ )
       
   256 {
       
   257     TInt status(KErrNone);
       
   258 
       
   259     if(m_PrefetchStatusItf)
       
   260     {
       
   261         status = (*m_PrefetchStatusItf)->GetFillUpdatePeriod(
       
   262                 m_PrefetchStatusItf, NULL);
       
   263     }
       
   264     else
       
   265     {
       
   266         status = KErrNotFound;
       
   267     }    
       
   268     return status;
       
   269 }
       
   270 
       
   271 TInt COpenMAXALTestModule::al_prefetchstatusitf_GetFillUpdatePeriod( CStifItemParser& aItem )
       
   272 {
       
   273     TInt status(KErrNone);
       
   274     TInt expectedUpdatePeriod(0);
       
   275     status = aItem.GetNextInt(expectedUpdatePeriod);
       
   276     XApermille updatePeriod;
       
   277     RET_ERR_IF_ERR(status);
       
   278 
       
   279     if(m_PrefetchStatusItf)
       
   280     {
       
   281         status = (*m_PrefetchStatusItf)->GetFillUpdatePeriod(
       
   282                 m_PrefetchStatusItf, &updatePeriod);
       
   283         if (!status && (updatePeriod != expectedUpdatePeriod))
       
   284         {
       
   285             status = KErrCompletion;
       
   286         }
       
   287     }
       
   288     else
       
   289     {
       
   290         status = KErrNotFound;
       
   291     }    
       
   292     return status;
       
   293 }
       
   294 
       
   295 TInt COpenMAXALTestModule::al_prefetchstatusitf_TestEvent( CStifItemParser& /*aItem*/ )
       
   296 {
       
   297     iStatusEventCount = 0;
       
   298     iFillEventCount = 0;
       
   299     iLastFillIncrement = 0;
       
   300     iPrefetchEventTesting = ETrue;
       
   301     iPrefetchEventError = EFalse;
       
   302     
       
   303     return KErrNone;
       
   304 }
       
   305 
       
   306 void COpenMAXALTestModule::HandlePrefetchStatusItfCallback( XAPrefetchStatusItf /*caller*/, XAuint32 event )
       
   307 {
       
   308     switch (event)
       
   309     {
       
   310         case XA_PREFETCHEVENT_STATUSCHANGE:
       
   311         {
       
   312             TEventIf event( TEventIf::ESetEvent, _L("Event_XA_PREFETCHEVENT_STATUSCHANGE") );
       
   313             TestModuleIf().Event( event );
       
   314         }
       
   315         break;
       
   316         case XA_PREFETCHEVENT_FILLLEVELCHANGE:
       
   317         {
       
   318                 TEventIf event( TEventIf::ESetEvent, _L("Event_XA_PREFETCHEVENT_FILLLEVELCHANGE") );
       
   319                 TestModuleIf().Event( event );
       
   320         }
       
   321         break;
       
   322        default:
       
   323             break;
       
   324     }
       
   325 }
       
   326 
       
   327 void COpenMAXALTestModule::HandlePrefetchStatusItfTestEventCallback( XAPrefetchStatusItf /*caller*/, XAuint32 event )
       
   328 {
       
   329     switch (event)
       
   330     {
       
   331         case XA_PREFETCHEVENT_STATUSCHANGE:
       
   332         {
       
   333             ++iStatusEventCount;                
       
   334             if(iStatusEventCount==2)
       
   335             {
       
   336                 XAuint32 pfs(0);
       
   337                 XAresult res = (*m_PrefetchStatusItf)->GetPrefetchStatus(m_PrefetchStatusItf, &pfs);
       
   338                 if((res==XA_RESULT_SUCCESS) && (pfs == XA_PREFETCHSTATUS_SUFFICIENTDATA))
       
   339                 {
       
   340                     TEventIf event( TEventIf::ESetEvent, _L("Event_XA_PREFETCHEVENT_STATUSCHANGE") );
       
   341                     TestModuleIf().Event( event );
       
   342                 }
       
   343             }
       
   344         }
       
   345         break;
       
   346         case XA_PREFETCHEVENT_FILLLEVELCHANGE:
       
   347         {
       
   348             if(iPrefetchEventError)
       
   349             {
       
   350                 return;
       
   351             }
       
   352 
       
   353             XApermille fL = 0;
       
   354             XAresult res = (*m_PrefetchStatusItf)->GetFillLevel(m_PrefetchStatusItf, &fL);
       
   355             
       
   356             if((res != XA_RESULT_SUCCESS) ||
       
   357                ((iFillEventCount>0) && (fL<(iLastFillIncrement + iFillUpdateIncrement))))
       
   358             {
       
   359                 iPrefetchEventError = ETrue;
       
   360             }
       
   361             else
       
   362             {
       
   363                 iLastFillIncrement = fL - (fL % iFillUpdateIncrement);
       
   364                 
       
   365                 if(fL == 1000)
       
   366                 {
       
   367                     TEventIf event( TEventIf::ESetEvent, _L("Event_XA_PREFETCHEVENT_FILLLEVELCHANGE") );
       
   368                     TestModuleIf().Event( event );
       
   369                 }
       
   370                 
       
   371                 ++iFillEventCount;
       
   372             }
       
   373         }
       
   374         break;
       
   375        default:
       
   376             break;
       
   377     }
       
   378 }
       
   379 
       
   380 
       
   381 void PrefetchStatusItfCallback (
       
   382     XAPrefetchStatusItf caller,
       
   383     void * pContext,
       
   384     XAuint32 event)
       
   385     {
       
   386     if (pContext)
       
   387         {
       
   388         ((COpenMAXALTestModule*)pContext)->HandlePrefetchStatusItfCallback(caller, event);
       
   389         }
       
   390     }
       
   391 
       
   392 void PrefetchStatusItfTestEventCallback (
       
   393     XAPrefetchStatusItf caller,
       
   394     void * pContext,
       
   395     XAuint32 event)
       
   396     {
       
   397     if (pContext)
       
   398         {
       
   399         ((COpenMAXALTestModule*)pContext)->HandlePrefetchStatusItfTestEventCallback(caller, event);
       
   400         }
       
   401     }