videoplayback/hbvideoplaybackview/tsrc/testvideodisplayhandler/src/testvideodisplayhandler.cpp
changeset 52 e3cecb93e76a
parent 47 45e72b57a2fd
child 59 a76e86df7ccd
equal deleted inserted replaced
47:45e72b57a2fd 52:e3cecb93e76a
     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:   tester for methods in Video Display Handler
       
    15 * 
       
    16 */
       
    17 
       
    18 #include <e32err.h>
       
    19 #include <w32std.h>
       
    20 #include <eikenv.h>
       
    21 
       
    22 #include <hbapplication.h>
       
    23 #include <hbinstance.h>
       
    24 #include <QDebug>
       
    25 
       
    26 #include <mpxplaybackutility.h>
       
    27 
       
    28 #include "testvideodisplayhandler.h"
       
    29 #include "../stub/inc/hbvideobaseplaybackview.h"
       
    30 #include "../stub/inc/mpxvideoplaybackviewfiledetails.h"
       
    31 #include "mpxvideoviewwrapper.h"
       
    32 
       
    33 #define private public
       
    34 #include "mpxvideoplaybackdisplayhandler.h"
       
    35 #undef private
       
    36 
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // main
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 int main(int argc, char *argv[])
       
    43 {
       
    44     HbApplication app(argc, argv);
       
    45     HbMainWindow window;
       
    46     
       
    47     TestVideoDisplayHandler tv;
       
    48 
       
    49     char *pass[3];
       
    50     pass[0] = argv[0];
       
    51     pass[1] = "-o";
       
    52     pass[2] = "c:\\data\\TestVideoDisplayHandler.txt";
       
    53     
       
    54     int res = QTest::qExec(&tv, 3, pass);
       
    55     
       
    56     return res;
       
    57 }
       
    58 
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // init
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 void TestVideoDisplayHandler::init()
       
    65 {	  
       
    66     mPlaybackUtility = MMPXPlaybackUtility::UtilityL( KPbModeDefault );
       
    67     
       
    68 	  mBaseVideoView    = new HbVideoBasePlaybackView();
       
    69 	  mVideoViewWrapper = CMPXVideoViewWrapper::NewL( mBaseVideoView );   
       
    70     
       
    71     mDispHdlr = CMPXVideoPlaybackDisplayHandler::NewL(mPlaybackUtility, mVideoViewWrapper);
       
    72 }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // cleanup
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void TestVideoDisplayHandler::cleanup()
       
    79 {    
       
    80     if ( mPlaybackUtility )
       
    81     {
       
    82         mPlaybackUtility->Close();
       
    83         mPlaybackUtility = NULL;
       
    84     }    
       
    85     
       
    86     delete mDispHdlr;
       
    87     mDispHdlr = NULL;  
       
    88     
       
    89     delete mVideoViewWrapper;
       
    90     mVideoViewWrapper = NULL;
       
    91         
       
    92     delete mBaseVideoView;
       
    93     mBaseVideoView = NULL;              
       
    94 }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // setup
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void TestVideoDisplayHandler::setup()
       
   101 {    
       
   102     init();
       
   103     
       
   104     RWindow *window = mBaseVideoView->getWindow();
       
   105 
       
   106     TRect displayRect = TRect( window->Position().iX,
       
   107                                window->Position().iY,
       
   108                                window->Position().iX + window->Size().iWidth,                  
       
   109                                window->Position().iY + window->Size().iHeight );    
       
   110 
       
   111     mDispHdlr->CreateDisplayWindowL( CCoeEnv::Static()->WsSession(),
       
   112                                      *(CCoeEnv::Static()->ScreenDevice()),
       
   113                                      *window,
       
   114                                      displayRect);
       
   115     
       
   116     QCOMPARE( mDispHdlr->iWindowRect, displayRect);    
       
   117     
       
   118 }
       
   119 
       
   120 
       
   121 void TestVideoDisplayHandler::testCreateDisplayWindowL()
       
   122 {
       
   123     setup();        
       
   124     
       
   125     cleanup();
       
   126 }
       
   127 
       
   128 void TestVideoDisplayHandler::testRemoveDisplayWindow()
       
   129 {
       
   130     setup();
       
   131     
       
   132     mDispHdlr->RemoveDisplayWindow(); 
       
   133         
       
   134     QVERIFY( mDispHdlr->iVideoContainer == NULL );
       
   135     
       
   136     cleanup();        
       
   137 }
       
   138 
       
   139 void TestVideoDisplayHandler::testHandleSurfaceCreatedMessageL()
       
   140 {
       
   141     setup();
       
   142     
       
   143     CMPXMessage* message = NULL;
       
   144     TRAP_IGNORE
       
   145     ( 
       
   146         message = CMPXMessage::NewL();    
       
   147         message->SetTObjectValueL<TMPXVideoDisplayCommand>
       
   148                     ( KMPXMediaVideoDisplayCommand, EPbMsgVideoSurfaceCreated );
       
   149     );    
       
   150     
       
   151     mDispHdlr->HandleVideoDisplayMessageL( message );
       
   152     
       
   153     QVERIFY( ! mDispHdlr->iSurfaceId.IsNull() );
       
   154            
       
   155     mDispHdlr->RemoveDisplayWindow(); 
       
   156     cleanup();    
       
   157 }
       
   158 
       
   159 void TestVideoDisplayHandler::testHandleSurfaceChangedMessageL()
       
   160 {
       
   161     setup();
       
   162     
       
   163     CMPXMessage* message = NULL;
       
   164     TRAP_IGNORE
       
   165     ( 
       
   166         message = CMPXMessage::NewL();    
       
   167         message->SetTObjectValueL<TMPXVideoDisplayCommand>
       
   168                     ( KMPXMediaVideoDisplayCommand, EPbMsgVideoSurfaceChanged );
       
   169     );    
       
   170     
       
   171     mDispHdlr->HandleVideoDisplayMessageL( message );
       
   172     
       
   173     QVERIFY( ! mDispHdlr->iSurfaceId.IsNull() );
       
   174            
       
   175     mDispHdlr->RemoveDisplayWindow(); 
       
   176     cleanup();    
       
   177 }
       
   178 
       
   179 void TestVideoDisplayHandler::testHandleVideoRemovedMessageL()
       
   180 {
       
   181     setup();
       
   182 
       
   183     CMPXMessage* message = NULL;
       
   184     TRAP_IGNORE
       
   185     ( 
       
   186         message = CMPXMessage::NewL();    
       
   187         message->SetTObjectValueL<TMPXVideoDisplayCommand>
       
   188                     ( KMPXMediaVideoDisplayCommand, EPbMsgVideoSurfaceRemoved );
       
   189     );    
       
   190     
       
   191     mDispHdlr->HandleVideoDisplayMessageL( message );
       
   192     
       
   193     QVERIFY( mDispHdlr->iSurfaceId.IsNull() );
       
   194            
       
   195     mDispHdlr->RemoveDisplayWindow(); 
       
   196     cleanup();    
       
   197 }
       
   198 
       
   199 void TestVideoDisplayHandler::testSetAspectRatioL()
       
   200 {
       
   201     setup();
       
   202    
       
   203     int aspectRatio = mDispHdlr->SetAspectRatioL( EPbCmdNaturalAspectRatio );    
       
   204     
       
   205     QVERIFY( aspectRatio == EMMFNatural ); 
       
   206     
       
   207     mDispHdlr->RemoveDisplayWindow();    
       
   208     cleanup(); 
       
   209 }
       
   210 
       
   211 void TestVideoDisplayHandler::testSetDefaultAspectRatioL()
       
   212 {
       
   213     setup();
       
   214         
       
   215     //
       
   216     // get window size
       
   217     //
       
   218     RWindow *window = mBaseVideoView->getWindow();
       
   219     TRect displayRect = TRect( TPoint( window->Position() ), TSize( window->Size() ) );
       
   220 
       
   221     //
       
   222     // get window aspect ratio
       
   223     //   if device is in landscape mode, width > height
       
   224     //   if device is in portrait mode, width < height
       
   225     //
       
   226     TReal32 width = (TReal32) displayRect.Width();
       
   227     TReal32 height = (TReal32) displayRect.Height();
       
   228     TReal32 displayAspectRatio = (width > height)? (width / height) : (height / width);
       
   229     
       
   230     //
       
   231     // aspect ratio zoom
       
   232     //
       
   233     mFileDetails = new QMPXVideoPlaybackViewFileDetails(); 
       
   234     mFileDetails->mVideoHeight = 280;
       
   235     mFileDetails->mVideoWidth  = 600;
       
   236 
       
   237     int aspectRatio = mDispHdlr->SetDefaultAspectRatioL( mFileDetails, displayAspectRatio );
       
   238     
       
   239     QVERIFY( aspectRatio == EMMFZoom ); 
       
   240        
       
   241     //
       
   242     // aspect ratio stretch
       
   243     //
       
   244     mFileDetails->mVideoHeight = 144;
       
   245     mFileDetails->mVideoWidth  = 220;
       
   246 
       
   247     aspectRatio = mDispHdlr->SetDefaultAspectRatioL( mFileDetails, displayAspectRatio );
       
   248     
       
   249     QVERIFY( aspectRatio == EMMFStretch ); 
       
   250  
       
   251     mDispHdlr->RemoveDisplayWindow();   
       
   252 
       
   253     cleanup(); 
       
   254 }
       
   255 
       
   256 void TestVideoDisplayHandler::testUpdateVideoRectL()
       
   257 {
       
   258     setup();
       
   259 
       
   260     RWindow *window = mBaseVideoView->getWindow();
       
   261 
       
   262     TRect displayRect = TRect( 0, 0, 200, 300 );
       
   263     
       
   264     mDispHdlr->UpdateVideoRectL( displayRect, false );
       
   265     
       
   266     QCOMPARE( mDispHdlr->iWindowRect, displayRect);
       
   267 
       
   268     mDispHdlr->RemoveDisplayWindow();    
       
   269     cleanup(); 
       
   270 }
       
   271 
       
   272 
       
   273 
       
   274 // End of file
       
   275     
       
   276 
       
   277