videoplayback/hbvideoplaybackview/tsrc/testvideoplaybackview/src/testvideoplaybackview.cpp
changeset 44 518105d52e45
parent 42 17f382c040b1
child 49 824471cb468a
equal deleted inserted replaced
42:17f382c040b1 44:518105d52e45
     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 VideoSortFilterProxyModel
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version: 10 %
       
    19 
       
    20 #include <e32err.h>
       
    21 #include <w32std.h>
       
    22 
       
    23 #include <mmf/common/mmferrors.h>
       
    24 #include <caf/caferr.h>
       
    25 
       
    26 #include <mpxvideoplaybackdefs.h>
       
    27 
       
    28 #include <hbapplication.h>
       
    29 #include <hbinstance.h>
       
    30 #include <qgraphicssceneevent>
       
    31 #include <QDebug>
       
    32 
       
    33 #include "mpxvideoplaybackviewfiledetails.h"
       
    34 #include "mpxcommonvideoplaybackview.hrh"
       
    35 
       
    36 #include "testvideoplaybackview.h"
       
    37 #include "mpxvideoviewwrapper.h"
       
    38 #include "hbtapgesture.h"
       
    39 #include "hbpangesture.h"
       
    40 
       
    41 #define private public
       
    42 #define protected public
       
    43 #include "hbvideoplaybackview.h"
       
    44 #include "hbvideobaseplaybackview.h"
       
    45 #undef protected
       
    46 #undef private
       
    47 
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // main
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 int main(int argc, char *argv[])
       
    54 {
       
    55     HbApplication app(argc, argv);
       
    56     HbMainWindow window;
       
    57 
       
    58     TestVideoPlaybackView tv;
       
    59 
       
    60     char *pass[3];
       
    61     pass[0] = argv[0];
       
    62     pass[1] = "-o";
       
    63     pass[2] = "c:\\data\\TestVideoPlaybackView.txt";
       
    64 
       
    65     int res = QTest::qExec(&tv, 3, pass);
       
    66 
       
    67     return res;
       
    68 }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // init
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 void TestVideoPlaybackView::init()
       
    75 {
       
    76 	  mVideoView = new HbVideoPlaybackView();
       
    77 }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // cleanup
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 void TestVideoPlaybackView::cleanup()
       
    84 {
       
    85     delete mVideoView;
       
    86     mVideoView = NULL;
       
    87 }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // setup
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void TestVideoPlaybackView::setup()
       
    94 {
       
    95     init();
       
    96     mVideoView->handleActivateView();
       
    97 }
       
    98 
       
    99 // -------------------------------------------------------------------------------------------------
       
   100 //   TestVideoPlaybackView::testHandleActivateView()
       
   101 // -------------------------------------------------------------------------------------------------
       
   102 //
       
   103 void TestVideoPlaybackView::testHandleActivateView()
       
   104 {
       
   105     init();
       
   106     mVideoView->handleActivateView();
       
   107 
       
   108     QVERIFY( mVideoView->mVideoMpxWrapper->iMediaRequested == true );
       
   109     QCOMPARE( mVideoView->mVideoMpxWrapper->iFileDetails->mBitRate, 16000 );
       
   110     QCOMPARE( mVideoView->mVideoMpxWrapper->iFileDetails->mTitle, QString("Test Video Title") );
       
   111 
       
   112     cleanup();
       
   113 }
       
   114 
       
   115 // -------------------------------------------------------------------------------------------------
       
   116 //   TestVideoPlaybackView::testHandlePluginError()
       
   117 // -------------------------------------------------------------------------------------------------
       
   118 //
       
   119 void TestVideoPlaybackView::testHandlePluginError()
       
   120 {
       
   121     //
       
   122     // playback view is closed after displaying these error notes
       
   123     //
       
   124     verifyHandlePluginError( KErrNotSupported );
       
   125     verifyHandlePluginError( KErrUnknown );
       
   126     verifyHandlePluginError( KErrMMDecoder );
       
   127     verifyHandlePluginError( KErrCorrupt );
       
   128     verifyHandlePluginError( KErrTooBig );
       
   129     verifyHandlePluginError( KErrMMInvalidProtocol );
       
   130     verifyHandlePluginError( KErrMMInvalidURL );
       
   131     verifyHandlePluginError( KErrArgument );
       
   132     verifyHandlePluginError( KErrSessionClosed );
       
   133     verifyHandlePluginError( KErrTimedOut );
       
   134     verifyHandlePluginError( KErrNotFound );
       
   135     verifyHandlePluginError( KErrMMNotEnoughBandwidth );
       
   136     verifyHandlePluginError( KErrDisconnected );
       
   137     verifyHandlePluginError( KErrMMProxyServer );
       
   138     verifyHandlePluginError( KErrCouldNotConnect );
       
   139     verifyHandlePluginError( KErrAbort );
       
   140     verifyHandlePluginError( KErrCancel );
       
   141     verifyHandlePluginError( KErrMMDRMNotAuthorized );
       
   142     verifyHandlePluginError( KErrCANoRights );
       
   143     verifyHandlePluginError( KErrCANoPermission );
       
   144 
       
   145     //
       
   146     // playback view remains open after displaying these error notes
       
   147     //
       
   148     verifyHandlePluginError( KMPXVideoCallOngoingError, false );
       
   149     verifyHandlePluginError( KMPXVideoPlayOver2GDuringVoiceCallError, false );
       
   150 
       
   151     //
       
   152     // default error case, playback view is closed after displaying error note
       
   153     //
       
   154     verifyHandlePluginError( KErrGeneral );
       
   155 }
       
   156 
       
   157 // -------------------------------------------------------------------------------------------------
       
   158 //   TestVideoPlaybackView::testShowDialog()
       
   159 // -------------------------------------------------------------------------------------------------
       
   160 //
       
   161 void TestVideoPlaybackView::testShowDialog()
       
   162 {
       
   163     //
       
   164     // construct and activate playback view
       
   165     //
       
   166     setup();
       
   167 
       
   168     //
       
   169     // ensure that playback view is currently activated
       
   170     //
       
   171     QVERIFY( ! mVideoView->mTimerForClosingView->isActive() );
       
   172 
       
   173     //
       
   174     // test showDialog() method
       
   175     //
       
   176     mVideoView->showDialog( "test error msg" );
       
   177 
       
   178     //
       
   179     // connect and emit signal for handleClosePopupDialog() slot
       
   180     //
       
   181     connect( this, SIGNAL( commandSignal() ), mVideoView, SLOT( handleClosePopupDialog() ) );
       
   182     emit commandSignal();
       
   183 
       
   184     //
       
   185     // verify that playback view is properly closed
       
   186     //
       
   187     QVERIFY( mVideoView->mTimerForClosingView->isActive() );
       
   188 
       
   189     //
       
   190     // disconnect signal for handleClosePopupDialog() slot
       
   191     //
       
   192     disconnect( this, SIGNAL( commandSignal() ), mVideoView, SLOT( handleClosePopupDialog() ) );
       
   193 
       
   194     //
       
   195     // destruct playback view
       
   196     //
       
   197     cleanup();
       
   198 }
       
   199 
       
   200 // -------------------------------------------------------------------------------------------------
       
   201 //   TestVideoPlaybackView::testGetWindow()
       
   202 // -------------------------------------------------------------------------------------------------
       
   203 //
       
   204 void TestVideoPlaybackView::testGetWindow()
       
   205 {
       
   206     setup();
       
   207 
       
   208     QVERIFY( mVideoView->getWindow() != NULL );
       
   209 
       
   210     cleanup();
       
   211 }
       
   212 
       
   213 // -------------------------------------------------------------------------------------------------
       
   214 //   TestVideoPlaybackView::testIssuePlayCommand()
       
   215 // -------------------------------------------------------------------------------------------------
       
   216 //
       
   217 void TestVideoPlaybackView::testIssuePlayCommand()
       
   218 {
       
   219     setup();
       
   220 
       
   221     mVideoView->issuePlayCommand();
       
   222 
       
   223     //JAM remove
       
   224     QVERIFY( mVideoView->isEnabled() );
       
   225 
       
   226     cleanup();
       
   227 }
       
   228 
       
   229 // -------------------------------------------------------------------------------------------------
       
   230 //   TestVideoPlaybackView::testEventFilter()
       
   231 // -------------------------------------------------------------------------------------------------
       
   232 //
       
   233 void TestVideoPlaybackView::testEventFilter()
       
   234 {
       
   235     setup();
       
   236 
       
   237     //
       
   238     // ensure default foreground is false
       
   239     //
       
   240     QCOMPARE( mVideoView->mVideoMpxWrapper->iForeground, 0 );
       
   241 
       
   242     //
       
   243     // declare foreground/background event
       
   244     //
       
   245     QEvent* appActivate   = new QEvent( QEvent::ApplicationActivate );
       
   246     QEvent* appDeactivate = new QEvent( QEvent::ApplicationDeactivate );
       
   247 
       
   248     //
       
   249     // verify the returned value (consumed) of HbVideoBasePlaybackView::event()
       
   250     // for QEvent::ApplicationActivate is false
       
   251     //
       
   252     QVERIFY( ! mVideoView->eventFilter( NULL, appActivate ) );
       
   253 
       
   254     //
       
   255     // verify view is in foreground
       
   256     //
       
   257     QCOMPARE( mVideoView->mVideoMpxWrapper->iForeground, 1 );
       
   258 
       
   259     //
       
   260     // verify the returned value (consumed) of HbVideoBasePlaybackView::event()
       
   261     // for QEvent::ApplicationDeactivate is false
       
   262     //
       
   263     QVERIFY( ! mVideoView->eventFilter( NULL, appDeactivate ) );
       
   264 
       
   265     //
       
   266     // verify view is in background
       
   267     //
       
   268     QCOMPARE( mVideoView->mVideoMpxWrapper->iForeground, 0 );
       
   269 
       
   270     //
       
   271     // clean up
       
   272     //
       
   273     if ( appActivate )
       
   274     {
       
   275         delete appActivate;
       
   276         appActivate = NULL;
       
   277     }
       
   278 
       
   279     if ( appDeactivate )
       
   280     {
       
   281         delete appDeactivate;
       
   282         appDeactivate = NULL;
       
   283     }
       
   284 
       
   285     cleanup();
       
   286 }
       
   287 
       
   288 // -------------------------------------------------------------------------------------------------
       
   289 //   TestVideoPlaybackView::testClosePlaybackView()
       
   290 // -------------------------------------------------------------------------------------------------
       
   291 //
       
   292 void TestVideoPlaybackView::testClosePlaybackView()
       
   293 {
       
   294     setup();
       
   295 
       
   296     QVERIFY( ! mVideoView->mTimerForClosingView->isActive() );
       
   297 
       
   298     mVideoView->closePlaybackView();
       
   299 
       
   300     QVERIFY( mVideoView->mTimerForClosingView->isActive() );
       
   301 
       
   302     cleanup();
       
   303 }
       
   304 
       
   305 // -------------------------------------------------------------------------------------------------
       
   306 //   TestVideoPlaybackView::testHandlePdlStateChange()
       
   307 // -------------------------------------------------------------------------------------------------
       
   308 //
       
   309 void TestVideoPlaybackView::testHandlePdlStateChange()
       
   310 {
       
   311     setup();
       
   312 
       
   313     QCOMPARE( mVideoView->mVideoMpxWrapper->iFileDetails->mClipName, QString("testClip.3gp") );
       
   314 
       
   315     mVideoView->handlePdlStateChange( 0 );
       
   316 
       
   317     QCOMPARE( mVideoView->mVideoMpxWrapper->iFileDetails->mClipName, QString("testClip.3gp") );
       
   318 
       
   319     cleanup();
       
   320 }
       
   321 
       
   322 // -------------------------------------------------------------------------------------------------
       
   323 //   TestVideoPlaybackView::testHandleStoppedStateNoPrevView()
       
   324 // -------------------------------------------------------------------------------------------------
       
   325 //
       
   326 void TestVideoPlaybackView::testHandleStoppedStateNoPrevView()
       
   327 {
       
   328     setup();
       
   329 
       
   330     QVERIFY( ! mVideoView->mTimerForClosingView->isActive() );
       
   331     mVideoView->handleStoppedState();
       
   332 
       
   333     QVERIFY( mVideoView->mTimerForClosingView->isActive() );
       
   334 
       
   335     cleanup();
       
   336 }
       
   337 
       
   338 // -------------------------------------------------------------------------------------------------
       
   339 //   TestVideoPlaybackView::testHandleStoppedStatePrevView()
       
   340 // -------------------------------------------------------------------------------------------------
       
   341 //
       
   342 void TestVideoPlaybackView::testHandleStoppedStatePrevView()
       
   343 {
       
   344     setup();
       
   345 
       
   346     mVideoView->handleStoppedState();
       
   347 
       
   348     QVERIFY( mVideoView->mTimerForClosingView->isActive() );
       
   349 
       
   350     cleanup();
       
   351 
       
   352 }
       
   353 
       
   354 // -------------------------------------------------------------------------------------------------
       
   355 //   TestVideoPlaybackView::testHandleBackNoPrevView()
       
   356 // -------------------------------------------------------------------------------------------------
       
   357 //
       
   358 void TestVideoPlaybackView::testHandleBackNoPrevView()
       
   359 {
       
   360     setup();
       
   361 
       
   362     QVERIFY( ! mVideoView->mTimerForClosingView->isActive() );
       
   363     mVideoView->handleBack();
       
   364 
       
   365     QVERIFY( mVideoView->mTimerForClosingView->isActive() );
       
   366 
       
   367     cleanup();
       
   368 
       
   369 }
       
   370 
       
   371 // -------------------------------------------------------------------------------------------------
       
   372 //   TestVideoPlaybackView::testHandleBackPrevView()
       
   373 // -------------------------------------------------------------------------------------------------
       
   374 //
       
   375 void TestVideoPlaybackView::testHandleBackPrevView()
       
   376 {
       
   377     setup();
       
   378 
       
   379     mVideoView->handleBack();
       
   380 
       
   381     QVERIFY( mVideoView->mTimerForClosingView->isActive() );
       
   382 
       
   383     cleanup();
       
   384 }
       
   385 
       
   386 // -------------------------------------------------------------------------------------------------
       
   387 //   TestVideoPlaybackView::testHandleSoftkeyback()
       
   388 // -------------------------------------------------------------------------------------------------
       
   389 //
       
   390 void TestVideoPlaybackView::testHandleSoftkeyback()
       
   391 {
       
   392     setup();
       
   393 
       
   394     mVideoView->handleSoftkeyBack();
       
   395 
       
   396     QVERIFY( mVideoView->mTimerForClosingView->isActive() );
       
   397 
       
   398     cleanup();
       
   399 }
       
   400 
       
   401 // -------------------------------------------------------------------------------------------------
       
   402 //   TestVideoPlaybackView::testDoClosePlayer()
       
   403 // -------------------------------------------------------------------------------------------------
       
   404 //
       
   405 void TestVideoPlaybackView::testDoClosePlayer()
       
   406 {
       
   407     // quits app - which can be problematic for the qvptestrunner app
       
   408 
       
   409 //    setup();
       
   410 //
       
   411 //    mVideoView->handleActivateView();
       
   412 //
       
   413 //    mVideoView->doClosePlayer();
       
   414 //
       
   415 //    cleanup();
       
   416 
       
   417 }
       
   418 
       
   419 // -------------------------------------------------------------------------------------------------
       
   420 //   TestVideoPlaybackView::testHandleDeactivateView()
       
   421 // -------------------------------------------------------------------------------------------------
       
   422 //
       
   423 void TestVideoPlaybackView::testHandleDeactivateView()
       
   424 {
       
   425     setup();
       
   426 
       
   427     mVideoView->handleDeactivateView();
       
   428 
       
   429     QVERIFY( mVideoView->mVideoMpxWrapper == NULL );
       
   430 
       
   431     cleanup();
       
   432 }
       
   433 
       
   434 // -------------------------------------------------------------------------------------------------
       
   435 //   TestVideoPlaybackView::verifyHandlePluginError()
       
   436 // -------------------------------------------------------------------------------------------------
       
   437 //
       
   438 void TestVideoPlaybackView::verifyHandlePluginError( TInt error, bool closeView )
       
   439 {
       
   440     //
       
   441     // construct and activate playback view
       
   442     //
       
   443     setup();
       
   444 
       
   445     //
       
   446     // ensure that playback view is currently open
       
   447     //
       
   448     QVERIFY( ! mVideoView->mTimerForClosingView->isActive() );
       
   449 
       
   450     //
       
   451     // test handlePluginError() method
       
   452     //
       
   453     mVideoView->handlePluginError( error );
       
   454 
       
   455     //
       
   456     // close playback view after error note has been launched
       
   457     //
       
   458     if ( closeView )
       
   459     {
       
   460         //
       
   461         // connect and emit signal for handleClosePopupDialog() slot
       
   462         //
       
   463         connect( this, SIGNAL( commandSignal() ), mVideoView, SLOT( handleClosePopupDialog() ) );
       
   464         emit commandSignal();
       
   465 
       
   466         //
       
   467         // verify that playback view is properly closed
       
   468         //
       
   469         QVERIFY( mVideoView->mTimerForClosingView->isActive() );
       
   470 
       
   471         //
       
   472         // disconnect signal for handleClosePopupDialog() slot
       
   473         //
       
   474         disconnect( this, SIGNAL( commandSignal() ), mVideoView, SLOT( handleClosePopupDialog() ) );
       
   475     }
       
   476     else
       
   477     {
       
   478         //
       
   479         // verify that playback view is still open after error note has been launched
       
   480         //
       
   481         QVERIFY( ! mVideoView->mTimerForClosingView->isActive() );
       
   482     }
       
   483 
       
   484     //
       
   485     // destruct playback view
       
   486     //
       
   487     cleanup();
       
   488 }
       
   489 
       
   490 // -------------------------------------------------------------------------------------------------
       
   491 //   TestVideoPlaybackView::testGestureEvent()
       
   492 // -------------------------------------------------------------------------------------------------
       
   493 //
       
   494 void TestVideoPlaybackView::testGestureEvent()
       
   495 {
       
   496     setup();
       
   497 
       
   498     //
       
   499     // 1. Test tap gesture
       
   500     //
       
   501     QList<QGesture *> list;
       
   502     HbTapGesture *tapGesture = new HbTapGesture();
       
   503     list.append( tapGesture );
       
   504     QGestureEvent* event = new QGestureEvent( list );
       
   505 
       
   506     //
       
   507     // connect to tappedOnScreen() signal and record its emission
       
   508     //
       
   509     QSignalSpy spy( mVideoView, SIGNAL( tappedOnScreen() ) );
       
   510 
       
   511     //
       
   512     // ensure signal has not been emitted yet
       
   513     //
       
   514     QCOMPARE( spy.count(), 0 );
       
   515 
       
   516     //
       
   517     // With GestureStarted
       
   518     //
       
   519     tapGesture->mState = Qt::GestureStarted;
       
   520     mVideoView->gestureEvent( event );
       
   521 
       
   522     //
       
   523     // ensure signal hasn't been emitted and its emission count is not incremented
       
   524     //
       
   525     QCOMPARE( spy.count(), 0 );
       
   526 
       
   527     //
       
   528     // With GestureFinished
       
   529     //
       
   530     tapGesture->mState = Qt::GestureFinished;
       
   531     mVideoView->gestureEvent( event );
       
   532 
       
   533     //
       
   534     // ensure signal has been emitted and its emission count is incremented
       
   535     //
       
   536     QCOMPARE( spy.count(), 1 );
       
   537 
       
   538     //
       
   539     // clean up
       
   540     //
       
   541     spy.clear();
       
   542 
       
   543     list.clear();
       
   544 
       
   545     if ( tapGesture )
       
   546     {
       
   547         delete tapGesture;
       
   548         tapGesture = NULL;
       
   549     }
       
   550 
       
   551     if ( event )
       
   552     {
       
   553         delete event;
       
   554         event = NULL;
       
   555     }
       
   556 
       
   557     //
       
   558     // 2. Test pan gesture
       
   559     //
       
   560     HbPanGesture *panGesture = new HbPanGesture();
       
   561     list.append( panGesture );
       
   562     event = new QGestureEvent( list );
       
   563 
       
   564     //
       
   565     // connect to pannedToRight() signal and record its emission
       
   566     //
       
   567     QSignalSpy spy1( mVideoView, SIGNAL( pannedToRight() ) );
       
   568 
       
   569     //
       
   570     // ensure signal has not been emitted yet
       
   571     //
       
   572     QCOMPARE( spy1.count(), 0 );
       
   573 
       
   574     //
       
   575     // Test pan gesture With GestureStarted
       
   576     //
       
   577     panGesture->mState = Qt::GestureStarted;
       
   578     mVideoView->gestureEvent( event );
       
   579 
       
   580     //
       
   581     // ensure signal has not been emitted yet
       
   582     //
       
   583     QCOMPARE( spy1.count(), 0 );
       
   584 
       
   585     //
       
   586     // Test pan gesture with GestureFinished
       
   587     //
       
   588     panGesture->mState = Qt::GestureFinished;
       
   589     panGesture->mSceneDelta = QPointF( 5, 0 );
       
   590     mVideoView->gestureEvent( event );
       
   591 
       
   592     //
       
   593     // ensure signal has been emitted
       
   594     //
       
   595     QCOMPARE( spy1.count(), 1 );
       
   596     spy1.clear();
       
   597 
       
   598     //
       
   599     // Test pan gesture with GestureFinished
       
   600     //
       
   601 
       
   602     //
       
   603     // connect to pannedToRight() signal and record its emission
       
   604     //
       
   605     QSignalSpy spy2( mVideoView, SIGNAL( pannedToLeft() ) );
       
   606 
       
   607     //
       
   608     // ensure signal has not been emitted yet
       
   609     //
       
   610     QCOMPARE( spy2.count(), 0 );
       
   611 
       
   612     panGesture->mState = Qt::GestureFinished;
       
   613     panGesture->mSceneDelta = QPointF( -5, 0 );
       
   614     mVideoView->gestureEvent( event );
       
   615 
       
   616     //
       
   617     // ensure signal has not been emitted yet
       
   618     //
       
   619     QCOMPARE( spy2.count(), 1 );
       
   620 
       
   621     //
       
   622     // clean up
       
   623     //
       
   624     spy2.clear();
       
   625     list.clear();
       
   626 
       
   627     if ( panGesture )
       
   628     {
       
   629         delete panGesture;
       
   630         panGesture = NULL;
       
   631     }
       
   632 
       
   633     if ( event )
       
   634     {
       
   635         delete event;
       
   636         event = NULL;
       
   637     }
       
   638 
       
   639     cleanup();
       
   640 }
       
   641 
       
   642 // End of file