videoplayback/hbvideoplaybackview/tsrc/testvideoplaybackview/src/testvideoplaybackview.cpp
changeset 46 adbe7d5ba2f5
parent 24 7d93ee07fb27
--- a/videoplayback/hbvideoplaybackview/tsrc/testvideoplaybackview/src/testvideoplaybackview.cpp	Fri Jun 11 13:39:54 2010 +0300
+++ b/videoplayback/hbvideoplaybackview/tsrc/testvideoplaybackview/src/testvideoplaybackview.cpp	Wed Jun 23 18:14:16 2010 +0300
@@ -1,5 +1,5 @@
 /**
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -12,10 +12,10 @@
 * Contributors:
 *
 * Description:   tester for methods in VideoSortFilterProxyModel
-* 
+*
 */
 
-// Version : %version: 9 %
+// Version : %version: 10 %
 
 #include <e32err.h>
 #include <w32std.h>
@@ -31,9 +31,12 @@
 #include <QDebug>
 
 #include "mpxvideoplaybackviewfiledetails.h"
+#include "mpxcommonvideoplaybackview.hrh"
 
 #include "testvideoplaybackview.h"
 #include "mpxvideoviewwrapper.h"
+#include "hbtapgesture.h"
+#include "hbpangesture.h"
 
 #define private public
 #define protected public
@@ -43,8 +46,6 @@
 #undef private
 
 
-
-
 // ---------------------------------------------------------------------------
 // main
 // ---------------------------------------------------------------------------
@@ -53,27 +54,26 @@
 {
     HbApplication app(argc, argv);
     HbMainWindow window;
-    
+
     TestVideoPlaybackView tv;
 
     char *pass[3];
     pass[0] = argv[0];
     pass[1] = "-o";
     pass[2] = "c:\\data\\TestVideoPlaybackView.txt";
-    
+
     int res = QTest::qExec(&tv, 3, pass);
-    
+
     return res;
 }
 
-
 // ---------------------------------------------------------------------------
 // init
 // ---------------------------------------------------------------------------
 //
 void TestVideoPlaybackView::init()
-{	  
-	  mVideoView = new HbVideoPlaybackView();	  
+{
+	  mVideoView = new HbVideoPlaybackView();
 }
 
 // ---------------------------------------------------------------------------
@@ -96,21 +96,28 @@
     mVideoView->handleActivateView();
 }
 
-
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testHandleActivateView()
+// -------------------------------------------------------------------------------------------------
+//
 void TestVideoPlaybackView::testHandleActivateView()
 {
-    init();		
-    mVideoView->handleActivateView();    
-        
+    init();
+    mVideoView->handleActivateView();
+
     QVERIFY( mVideoView->mVideoMpxWrapper->iMediaRequested == true );
     QCOMPARE( mVideoView->mVideoMpxWrapper->iFileDetails->mBitRate, 16000 );
     QCOMPARE( mVideoView->mVideoMpxWrapper->iFileDetails->mTitle, QString("Test Video Title") );
-    
-    cleanup();        
+
+    cleanup();
 }
 
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testHandlePluginError()
+// -------------------------------------------------------------------------------------------------
+//
 void TestVideoPlaybackView::testHandlePluginError()
-{   
+{
     //
     // playback view is closed after displaying these error notes
     //
@@ -122,53 +129,57 @@
     verifyHandlePluginError( KErrMMInvalidProtocol );
     verifyHandlePluginError( KErrMMInvalidURL );
     verifyHandlePluginError( KErrArgument );
-    verifyHandlePluginError( KErrSessionClosed ); 
+    verifyHandlePluginError( KErrSessionClosed );
     verifyHandlePluginError( KErrTimedOut );
     verifyHandlePluginError( KErrNotFound );
-    verifyHandlePluginError( KErrMMNotEnoughBandwidth );   
+    verifyHandlePluginError( KErrMMNotEnoughBandwidth );
     verifyHandlePluginError( KErrDisconnected );
-    verifyHandlePluginError( KErrMMProxyServer ); 
+    verifyHandlePluginError( KErrMMProxyServer );
     verifyHandlePluginError( KErrCouldNotConnect );
     verifyHandlePluginError( KErrAbort );
-    verifyHandlePluginError( KErrCancel ); 
+    verifyHandlePluginError( KErrCancel );
     verifyHandlePluginError( KErrMMDRMNotAuthorized );
     verifyHandlePluginError( KErrCANoRights );
     verifyHandlePluginError( KErrCANoPermission );
-    
+
     //
     // playback view remains open after displaying these error notes
     //
     verifyHandlePluginError( KMPXVideoCallOngoingError, false );
     verifyHandlePluginError( KMPXVideoPlayOver2GDuringVoiceCallError, false );
-            
+
     //
     // default error case, playback view is closed after displaying error note
     //
-    verifyHandlePluginError( KErrGeneral );    
+    verifyHandlePluginError( KErrGeneral );
 }
 
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testShowDialog()
+// -------------------------------------------------------------------------------------------------
+//
 void TestVideoPlaybackView::testShowDialog()
-{   
+{
     //
     // construct and activate playback view
     //
     setup();
-    
+
     //
     // ensure that playback view is currently activated
     //
     QVERIFY( ! mVideoView->mTimerForClosingView->isActive() );
-    
+
     //
     // test showDialog() method
     //
     mVideoView->showDialog( "test error msg" );
-    
+
     //
     // connect and emit signal for handleClosePopupDialog() slot
     //
     connect( this, SIGNAL( commandSignal() ), mVideoView, SLOT( handleClosePopupDialog() ) );
-    emit commandSignal();     
+    emit commandSignal();
 
     //
     // verify that playback view is properly closed
@@ -179,40 +190,50 @@
     // disconnect signal for handleClosePopupDialog() slot
     //
     disconnect( this, SIGNAL( commandSignal() ), mVideoView, SLOT( handleClosePopupDialog() ) );
-    
+
     //
     // destruct playback view
     //
-    cleanup();    
+    cleanup();
 }
 
-
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testGetWindow()
+// -------------------------------------------------------------------------------------------------
+//
 void TestVideoPlaybackView::testGetWindow()
-{      
+{
     setup();
-    
-    QVERIFY( mVideoView->getWindow() != NULL );     
-    
+
+    QVERIFY( mVideoView->getWindow() != NULL );
+
     cleanup();
 }
 
-
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testIssuePlayCommand()
+// -------------------------------------------------------------------------------------------------
+//
 void TestVideoPlaybackView::testIssuePlayCommand()
-{      
+{
     setup();
-    
-    mVideoView->issuePlayCommand();      
-    
+
+    mVideoView->issuePlayCommand();
+
     //JAM remove
     QVERIFY( mVideoView->isEnabled() );
-    
+
     cleanup();
 }
 
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testEventFilter()
+// -------------------------------------------------------------------------------------------------
+//
 void TestVideoPlaybackView::testEventFilter()
 {
     setup();
-    
+
     //
     // ensure default foreground is false
     //
@@ -223,29 +244,29 @@
     //
     QEvent* appActivate   = new QEvent( QEvent::ApplicationActivate );
     QEvent* appDeactivate = new QEvent( QEvent::ApplicationDeactivate );
-    
+
     //
-    // verify the returned value (consumed) of HbVideoBasePlaybackView::event() 
+    // verify the returned value (consumed) of HbVideoBasePlaybackView::event()
     // for QEvent::ApplicationActivate is false
     //
-    QVERIFY( ! mVideoView->eventFilter( NULL, appActivate ) );  
-    
+    QVERIFY( ! mVideoView->eventFilter( NULL, appActivate ) );
+
     //
     // verify view is in foreground
     //
     QCOMPARE( mVideoView->mVideoMpxWrapper->iForeground, 1 );
 
     //
-    // verify the returned value (consumed) of HbVideoBasePlaybackView::event() 
+    // verify the returned value (consumed) of HbVideoBasePlaybackView::event()
     // for QEvent::ApplicationDeactivate is false
     //
-    QVERIFY( ! mVideoView->eventFilter( NULL, appDeactivate ) );   
-    
+    QVERIFY( ! mVideoView->eventFilter( NULL, appDeactivate ) );
+
     //
     // verify view is in background
     //
     QCOMPARE( mVideoView->mVideoMpxWrapper->iForeground, 0 );
-    
+
     //
     // clean up
     //
@@ -264,207 +285,173 @@
     cleanup();
 }
 
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testClosePlaybackView()
+// -------------------------------------------------------------------------------------------------
+//
 void TestVideoPlaybackView::testClosePlaybackView()
 {
     setup();
-    
+
     QVERIFY( ! mVideoView->mTimerForClosingView->isActive() );
 
     mVideoView->closePlaybackView();
-    
+
     QVERIFY( mVideoView->mTimerForClosingView->isActive() );
 
     cleanup();
 }
 
-void TestVideoPlaybackView::testMousePressEvent()
-{
-    setup();
-    
-    //
-    // declare QEvent::GraphicsSceneMousePress
-    //
-    QGraphicsSceneMouseEvent* event = new QGraphicsSceneMouseEvent( QEvent::GraphicsSceneMousePress );
-        
-    //
-    // set m_accept value to false
-    //        
-    event->setAccepted( false );
-    
-    // 
-    // simulate QEvent::GraphicsSceneMousePress event
-    //
-    mVideoView->mousePressEvent( event );  
-    
-    //
-    // verify event has been accepted
-    //        
-    QVERIFY( event->isAccepted() );
-    
-    //
-    // clean up
-    //    
-    delete event;
-    event = NULL;    
-    cleanup();
-}
-
-void TestVideoPlaybackView::testMouseReleaseEvent()
-{
-    setup();
-    
-    //
-    // declare QEvent::GraphicsSceneMouseRelease
-    //
-    QGraphicsSceneMouseEvent* event = new QGraphicsSceneMouseEvent( QEvent::GraphicsSceneMouseRelease );
-    
-    //
-    // connect to tappedOnScreen() signal and record its emission
-    //
-    QSignalSpy spy( mVideoView, SIGNAL(tappedOnScreen()) );  
-    
-    //
-    // ensure signal has not been emitted yet
-    //
-    QCOMPARE(spy.count(), 0);     
-    
-    // 
-    // simulate QEvent::GraphicsSceneMousePress event
-    //
-    mVideoView->mouseReleaseEvent( event );        
-    
-    //
-    // ensure signal has been emitted and its emission count is incremented
-    //    
-    QCOMPARE(spy.count(), 1);  
-    
-    //
-    // clean up
-    //
-    delete event;
-    event = NULL;    
-    spy.clear();
-    cleanup();    
-}
-
-
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testHandlePdlStateChange()
+// -------------------------------------------------------------------------------------------------
+//
 void TestVideoPlaybackView::testHandlePdlStateChange()
 {
     setup();
 
     QCOMPARE( mVideoView->mVideoMpxWrapper->iFileDetails->mClipName, QString("testClip.3gp") );
-    
+
     mVideoView->handlePdlStateChange( 0 );
-    
+
     QCOMPARE( mVideoView->mVideoMpxWrapper->iFileDetails->mClipName, QString("testClip.3gp") );
-    
+
+    cleanup();
+}
+
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testHandleStoppedStateNoPrevView()
+// -------------------------------------------------------------------------------------------------
+//
+void TestVideoPlaybackView::testHandleStoppedStateNoPrevView()
+{
+    setup();
+
+    QVERIFY( ! mVideoView->mTimerForClosingView->isActive() );
+    mVideoView->handleStoppedState();
+
+    QVERIFY( mVideoView->mTimerForClosingView->isActive() );
+
     cleanup();
 }
 
-void TestVideoPlaybackView::testHandleStoppedStateNoPrevView()
-{    
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testHandleStoppedStatePrevView()
+// -------------------------------------------------------------------------------------------------
+//
+void TestVideoPlaybackView::testHandleStoppedStatePrevView()
+{
     setup();
 
-    QVERIFY( ! mVideoView->mTimerForClosingView->isActive() );        
     mVideoView->handleStoppedState();
 
-    QVERIFY( mVideoView->mTimerForClosingView->isActive() );    
+    QVERIFY( mVideoView->mTimerForClosingView->isActive() );
 
-    cleanup();   
+    cleanup();
+
 }
 
-
-void TestVideoPlaybackView::testHandleStoppedStatePrevView()
-{ 
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testHandleBackNoPrevView()
+// -------------------------------------------------------------------------------------------------
+//
+void TestVideoPlaybackView::testHandleBackNoPrevView()
+{
     setup();
-           
-    mVideoView->handleStoppedState();
-    
-    QVERIFY( mVideoView->mTimerForClosingView->isActive() );
-    
-    cleanup();
-    
-}
 
-void TestVideoPlaybackView::testHandleBackNoPrevView()
-{    
-    setup();
-       
     QVERIFY( ! mVideoView->mTimerForClosingView->isActive() );
     mVideoView->handleBack();
 
-    QVERIFY( mVideoView->mTimerForClosingView->isActive() );  
-  
+    QVERIFY( mVideoView->mTimerForClosingView->isActive() );
+
     cleanup();
-    
+
 }
 
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testHandleBackPrevView()
+// -------------------------------------------------------------------------------------------------
+//
 void TestVideoPlaybackView::testHandleBackPrevView()
-{  
+{
     setup();
-           
+
     mVideoView->handleBack();
-    
-    QVERIFY( mVideoView->mTimerForClosingView->isActive() ); 
-    
+
+    QVERIFY( mVideoView->mTimerForClosingView->isActive() );
+
+    cleanup();
+}
+
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testHandleSoftkeyback()
+// -------------------------------------------------------------------------------------------------
+//
+void TestVideoPlaybackView::testHandleSoftkeyback()
+{
+    setup();
+
+    mVideoView->handleSoftkeyBack();
+
+    QVERIFY( mVideoView->mTimerForClosingView->isActive() );
+
     cleanup();
 }
 
-void TestVideoPlaybackView::testHandleSoftkeyback()
-{        
-    setup();
-           
-    mVideoView->handleSoftkeyBack();
-    
-    QVERIFY( mVideoView->mTimerForClosingView->isActive() ); 
-    
-    cleanup();    
-}
-
-
-
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testDoClosePlayer()
+// -------------------------------------------------------------------------------------------------
+//
 void TestVideoPlaybackView::testDoClosePlayer()
-{    
-    // quits app - which can be problematic for the qvptestrunner app    
+{
+    // quits app - which can be problematic for the qvptestrunner app
 
 //    setup();
-//    
+//
 //    mVideoView->handleActivateView();
 //
 //    mVideoView->doClosePlayer();
-//    
+//
 //    cleanup();
-    
+
 }
 
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testHandleDeactivateView()
+// -------------------------------------------------------------------------------------------------
+//
 void TestVideoPlaybackView::testHandleDeactivateView()
-{    
+{
     setup();
-    
+
     mVideoView->handleDeactivateView();
-    
-    QVERIFY( mVideoView->mVideoMpxWrapper == NULL );   
-    
-    cleanup();        
+
+    QVERIFY( mVideoView->mVideoMpxWrapper == NULL );
+
+    cleanup();
 }
 
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::verifyHandlePluginError()
+// -------------------------------------------------------------------------------------------------
+//
 void TestVideoPlaybackView::verifyHandlePluginError( TInt error, bool closeView )
-{       
+{
     //
     // construct and activate playback view
     //
     setup();
-    
+
     //
     // ensure that playback view is currently open
     //
     QVERIFY( ! mVideoView->mTimerForClosingView->isActive() );
-    
+
     //
     // test handlePluginError() method
     //
-    mVideoView->handlePluginError( error );   
-    
+    mVideoView->handlePluginError( error );
+
     //
     // close playback view after error note has been launched
     //
@@ -474,33 +461,182 @@
         // connect and emit signal for handleClosePopupDialog() slot
         //
         connect( this, SIGNAL( commandSignal() ), mVideoView, SLOT( handleClosePopupDialog() ) );
-        emit commandSignal();  
+        emit commandSignal();
 
         //
         // verify that playback view is properly closed
         //
         QVERIFY( mVideoView->mTimerForClosingView->isActive() );
-    
+
         //
         // disconnect signal for handleClosePopupDialog() slot
         //
         disconnect( this, SIGNAL( commandSignal() ), mVideoView, SLOT( handleClosePopupDialog() ) );
     }
     else
-    {    
+    {
         //
         // verify that playback view is still open after error note has been launched
         //
         QVERIFY( ! mVideoView->mTimerForClosingView->isActive() );
-    }        
-    
+    }
+
     //
     // destruct playback view
     //
     cleanup();
 }
 
+// -------------------------------------------------------------------------------------------------
+//   TestVideoPlaybackView::testGestureEvent()
+// -------------------------------------------------------------------------------------------------
+//
+void TestVideoPlaybackView::testGestureEvent()
+{
+    setup();
+
+    //
+    // 1. Test tap gesture
+    //
+    QList<QGesture *> list;
+    HbTapGesture *tapGesture = new HbTapGesture();
+    list.append( tapGesture );
+    QGestureEvent* event = new QGestureEvent( list );
+
+    //
+    // connect to tappedOnScreen() signal and record its emission
+    //
+    QSignalSpy spy( mVideoView, SIGNAL( tappedOnScreen() ) );
+
+    //
+    // ensure signal has not been emitted yet
+    //
+    QCOMPARE( spy.count(), 0 );
+
+    //
+    // With GestureStarted
+    //
+    tapGesture->mState = Qt::GestureStarted;
+    mVideoView->gestureEvent( event );
+
+    //
+    // ensure signal hasn't been emitted and its emission count is not incremented
+    //
+    QCOMPARE( spy.count(), 0 );
+
+    //
+    // With GestureFinished
+    //
+    tapGesture->mState = Qt::GestureFinished;
+    mVideoView->gestureEvent( event );
+
+    //
+    // ensure signal has been emitted and its emission count is incremented
+    //
+    QCOMPARE( spy.count(), 1 );
+
+    //
+    // clean up
+    //
+    spy.clear();
+
+    list.clear();
+
+    if ( tapGesture )
+    {
+        delete tapGesture;
+        tapGesture = NULL;
+    }
+
+    if ( event )
+    {
+        delete event;
+        event = NULL;
+    }
+
+    //
+    // 2. Test pan gesture
+    //
+    HbPanGesture *panGesture = new HbPanGesture();
+    list.append( panGesture );
+    event = new QGestureEvent( list );
+
+    //
+    // connect to pannedToRight() signal and record its emission
+    //
+    QSignalSpy spy1( mVideoView, SIGNAL( pannedToRight() ) );
+
+    //
+    // ensure signal has not been emitted yet
+    //
+    QCOMPARE( spy1.count(), 0 );
+
+    //
+    // Test pan gesture With GestureStarted
+    //
+    panGesture->mState = Qt::GestureStarted;
+    mVideoView->gestureEvent( event );
+
+    //
+    // ensure signal has not been emitted yet
+    //
+    QCOMPARE( spy1.count(), 0 );
+
+    //
+    // Test pan gesture with GestureFinished
+    //
+    panGesture->mState = Qt::GestureFinished;
+    panGesture->mSceneDelta = QPointF( 5, 0 );
+    mVideoView->gestureEvent( event );
+
+    //
+    // ensure signal has been emitted
+    //
+    QCOMPARE( spy1.count(), 1 );
+    spy1.clear();
+
+    //
+    // Test pan gesture with GestureFinished
+    //
+
+    //
+    // connect to pannedToRight() signal and record its emission
+    //
+    QSignalSpy spy2( mVideoView, SIGNAL( pannedToLeft() ) );
+
+    //
+    // ensure signal has not been emitted yet
+    //
+    QCOMPARE( spy2.count(), 0 );
+
+    panGesture->mState = Qt::GestureFinished;
+    panGesture->mSceneDelta = QPointF( -5, 0 );
+    mVideoView->gestureEvent( event );
+
+    //
+    // ensure signal has not been emitted yet
+    //
+    QCOMPARE( spy2.count(), 1 );
+
+    //
+    // clean up
+    //
+    spy2.clear();
+    list.clear();
+
+    if ( panGesture )
+    {
+        delete panGesture;
+        panGesture = NULL;
+    }
+
+    if ( event )
+    {
+        delete event;
+        event = NULL;
+    }
+
+    cleanup();
+}
+
 // End of file
-    
-
-