videoplayback/videoplaybackview/tsrc/testvolumecontrol/src/testvolumecontrol.cpp
changeset 66 adb51f74b890
equal deleted inserted replaced
63:4707a0db12f6 66:adb51f74b890
       
     1 /**
       
     2 * Copyright (c) 2010 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 TestVolumeControl
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version:  1 %
       
    19 
       
    20 
       
    21 #include <qdebug>
       
    22 #include <QTimer>
       
    23 #include <hbmainwindow.h>
       
    24 #include <hbapplication.h>
       
    25 #include <qgraphicssceneevent>
       
    26 #include <hbvolumesliderpopup.h>
       
    27 
       
    28 
       
    29 #include "testvolumecontrol.h"
       
    30 #include "videoplaybackviewfiledetails.h"
       
    31 #include "videoplaybackcontrolscontroller.h"
       
    32 
       
    33 #define private public
       
    34 #include "videoplaybackvolumecontrol.h"
       
    35 #undef private
       
    36 
       
    37 // -------------------------------------------------------------------------------------------------
       
    38 // main
       
    39 // -------------------------------------------------------------------------------------------------
       
    40 //
       
    41 int main(int argc, char *argv[])
       
    42 {
       
    43     MPX_ENTER_EXIT(_L("TestVolumeControl::Main()"));
       
    44 
       
    45     HbApplication app(argc, argv);
       
    46     HbMainWindow window;
       
    47 
       
    48     TestVolumeControl tv;
       
    49 
       
    50     char *pass[3];
       
    51     pass[0] = argv[0];
       
    52     pass[1] = "-o";
       
    53     pass[2] = "c:\\data\\testvolumecontrol.txt";
       
    54 
       
    55     int res = QTest::qExec(&tv, 3, pass);
       
    56 
       
    57     return res;
       
    58 }
       
    59 
       
    60 // -------------------------------------------------------------------------------------------------
       
    61 // init
       
    62 // -------------------------------------------------------------------------------------------------
       
    63 //
       
    64 void TestVolumeControl::init()
       
    65 {
       
    66     MPX_ENTER_EXIT(_L("TestVolumeControl::init()"));
       
    67 
       
    68     mController = new VideoPlaybackControlsController();
       
    69     mVolumeControl = new VideoPlaybackVolumeControl( mController );
       
    70 }
       
    71 
       
    72 // -------------------------------------------------------------------------------------------------
       
    73 // init
       
    74 // -------------------------------------------------------------------------------------------------
       
    75 //
       
    76 void TestVolumeControl::setup()
       
    77 {
       
    78     MPX_ENTER_EXIT(_L("TestVolumeControl::init()"));
       
    79 
       
    80     init();
       
    81     mController->mVolumeSteps = 10;
       
    82     mController->fileDetails()->mAudioEnabled = true;
       
    83     mVolumeControl->setVisible( true );
       
    84 }
       
    85 
       
    86 // -------------------------------------------------------------------------------------------------
       
    87 // cleanup
       
    88 // -------------------------------------------------------------------------------------------------
       
    89 //
       
    90 void TestVolumeControl::cleanup()
       
    91 {
       
    92     MPX_ENTER_EXIT(_L("TestVolumeControl::cleanup()"));
       
    93 
       
    94     if ( mController )
       
    95     {
       
    96         delete mController;
       
    97         mController = NULL;
       
    98     }
       
    99 
       
   100     if ( mVolumeControl )
       
   101     {
       
   102         delete mVolumeControl;
       
   103         mVolumeControl = NULL;
       
   104     }
       
   105 }
       
   106 
       
   107 // -------------------------------------------------------------------------------------------------
       
   108 // testVolumeChanged
       
   109 // -------------------------------------------------------------------------------------------------
       
   110 //
       
   111 void TestVolumeControl::testVolumeChanged()
       
   112 {
       
   113     MPX_ENTER_EXIT(_L("TestVolumeControl::testVolumeChanged()"));
       
   114 
       
   115     setup();
       
   116 
       
   117     int changedVolume = 3;
       
   118     int currentVolume = 5;
       
   119     mVolumeControl->mVolume = 5;
       
   120 
       
   121     //
       
   122     // If mExpectedVolList is not empty
       
   123     //
       
   124     mVolumeControl->mExpectedVolList.append( changedVolume );
       
   125     mVolumeControl->volumeChanged( changedVolume );
       
   126 
       
   127     QVERIFY( mVolumeControl->mVolume == currentVolume );
       
   128 
       
   129     //
       
   130     // If mExpectedVolList is empty
       
   131     //
       
   132     mVolumeControl->mExpectedVolList.clear();
       
   133 
       
   134     //
       
   135     // If user is dragging the thumb, we don't update volume
       
   136     //
       
   137     mVolumeControl->mDragging = true;
       
   138 
       
   139     mVolumeControl->volumeChanged( changedVolume );
       
   140 
       
   141     QVERIFY( mVolumeControl->mVolume == currentVolume );
       
   142     QVERIFY( mVolumeControl->mVolumePopup->isVisible() );
       
   143 
       
   144     //
       
   145     // If user isn't dragging the thumb, we update volume
       
   146     //
       
   147     mVolumeControl->mDragging = false;
       
   148 
       
   149     mVolumeControl->volumeChanged( changedVolume );
       
   150 
       
   151     QVERIFY( mVolumeControl->mVolume == changedVolume );
       
   152     QVERIFY( mVolumeControl->mVolumePopup->isVisible() );
       
   153 
       
   154     cleanup();
       
   155 }
       
   156 
       
   157 // -------------------------------------------------------------------------------------------------
       
   158 // testSetVisible
       
   159 // -------------------------------------------------------------------------------------------------
       
   160 //
       
   161 void TestVolumeControl::testSetVisible()
       
   162 {
       
   163     MPX_ENTER_EXIT(_L("TestVolumeControl::testSetVisible()"));
       
   164 
       
   165     init();
       
   166 
       
   167     //
       
   168     // Audio + video clip
       
   169     //
       
   170     mController->mVolumeSteps = 30;
       
   171     mController->fileDetails()->mAudioEnabled = true;
       
   172 
       
   173     bool visible = true;
       
   174 
       
   175     mVolumeControl->setVisible( visible );
       
   176 
       
   177     QVERIFY( mVolumeControl->mVolumePopup->isVisible() == visible );
       
   178     QVERIFY( mVolumeControl->mVolumePopup->mMin == 0 );
       
   179     QVERIFY( mVolumeControl->mVolumePopup->mMax ==  mController->mVolumeSteps );
       
   180     QVERIFY( mVolumeControl->mDraggingHandlerTimer );
       
   181 
       
   182     cleanup();
       
   183 
       
   184     //
       
   185     // Audio only
       
   186     //
       
   187     init();
       
   188 
       
   189     mController->fileDetails()->mAudioEnabled = false;
       
   190 
       
   191     mVolumeControl->setVisible( visible );
       
   192 
       
   193     QVERIFY( mVolumeControl->mVolumePopup->isVisible() == visible );
       
   194     QVERIFY( ! mVolumeControl->mVolumePopup->isEnabled() );
       
   195     QVERIFY( ! mVolumeControl->mDraggingHandlerTimer );
       
   196 
       
   197     cleanup();
       
   198 }
       
   199 
       
   200 // -------------------------------------------------------------------------------------------------
       
   201 // testIsVisible
       
   202 // -------------------------------------------------------------------------------------------------
       
   203 //
       
   204 void TestVolumeControl::testIsVisible()
       
   205 {
       
   206     MPX_ENTER_EXIT(_L("TestVolumeControl::testIsVisible()"));
       
   207 
       
   208     setup();
       
   209 
       
   210     bool visible = true;
       
   211     mVolumeControl->mVolumePopup->mVisible = visible;
       
   212 
       
   213     QVERIFY( mVolumeControl->mVolumePopup->isVisible() == visible );
       
   214 
       
   215     cleanup();
       
   216 }
       
   217 
       
   218 // -------------------------------------------------------------------------------------------------
       
   219 // testHandleSliderValueChanged
       
   220 // -------------------------------------------------------------------------------------------------
       
   221 //
       
   222 void TestVolumeControl::testHandleSliderValueChanged()
       
   223 {
       
   224     MPX_ENTER_EXIT(_L("TestVolumeControl::testHandleSliderValueChanged()"));
       
   225 
       
   226     setup();
       
   227 
       
   228     int changedValue = 3;
       
   229     mVolumeControl->mVolume = 5;
       
   230 
       
   231     connect( this, SIGNAL( commandSignal( int ) ), mVolumeControl, SLOT( handleSliderValueChanged( int ) ) );
       
   232 
       
   233     //
       
   234     // If mDragging is ture
       
   235     //
       
   236     mVolumeControl->mDragging = true;
       
   237     emit commandSignal( changedValue );
       
   238 
       
   239     QVERIFY( mVolumeControl->mDraggingVolume == changedValue * mVolumeControl->mVolumeNormalizer );
       
   240 
       
   241     //
       
   242     // If mDragging is false
       
   243     //
       
   244     mVolumeControl->mDragging = false;
       
   245     emit commandSignal( changedValue );
       
   246 
       
   247     QVERIFY( mVolumeControl->mVolume == changedValue * mVolumeControl->mVolumeNormalizer );
       
   248     QVERIFY( mController->mCommand == EMPXPbvCmdSetVolume );
       
   249     QVERIFY( mController->mValue == changedValue * mVolumeControl->mVolumeNormalizer );
       
   250 
       
   251     disconnect( this, SIGNAL( commandSignal( int ) ), mVolumeControl, SLOT( handleSliderValueChanged( int ) ) );
       
   252 
       
   253     cleanup();
       
   254 }
       
   255 
       
   256 // -------------------------------------------------------------------------------------------------
       
   257 // testHandleMuteIconClicked
       
   258 // -------------------------------------------------------------------------------------------------
       
   259 //
       
   260 void TestVolumeControl::testHandleMuteIconClicked()
       
   261 {
       
   262     MPX_ENTER_EXIT(_L("TestVolumeControl::testHandleMuteIconClicked()"));
       
   263 
       
   264     setup();
       
   265 
       
   266     connect( this, SIGNAL( commandSignal() ), mVolumeControl, SLOT( handleMuteIconClicked() ) );
       
   267 
       
   268     //
       
   269     // mVolumePopup->value() is not 0
       
   270     //
       
   271     mVolumeControl->mVolumePopup->mValue = 5;
       
   272 
       
   273     emit commandSignal();
       
   274 
       
   275     QVERIFY( mController->mCommand == EMPXPbvCmdUnMute );
       
   276 
       
   277     //
       
   278     // mVolumePopup->value() is 0
       
   279     //
       
   280     mVolumeControl->mVolumePopup->mValue = 0;
       
   281     mVolumeControl->mMutedByMuteIcon = false;
       
   282 
       
   283     emit commandSignal();
       
   284 
       
   285     QVERIFY( mVolumeControl->mMutedByMuteIcon );
       
   286     QVERIFY( mController->mCommand == EMPXPbvCmdMute );
       
   287 
       
   288     disconnect( this, SIGNAL( commandSignal() ), mVolumeControl, SLOT( handleMuteIconClicked() ) );
       
   289 
       
   290     cleanup();
       
   291 }
       
   292 
       
   293 // -------------------------------------------------------------------------------------------------
       
   294 // testHandleSliderPressed
       
   295 // -------------------------------------------------------------------------------------------------
       
   296 //
       
   297 void TestVolumeControl::testHandleSliderPressed()
       
   298 {
       
   299     MPX_ENTER_EXIT(_L("TestVolumeControl::testHandleSliderPressed()"));
       
   300 
       
   301     setup();
       
   302 
       
   303     connect( this, SIGNAL( commandSignal() ), mVolumeControl, SLOT( handleSliderPressed() ) );
       
   304 
       
   305     mVolumeControl->mDragging = false;
       
   306     mVolumeControl->mDraggingHandlerTimer->start();
       
   307 
       
   308     emit commandSignal();
       
   309 
       
   310     QVERIFY( mVolumeControl->mDragging );
       
   311     QVERIFY( mVolumeControl->mDraggingHandlerTimer->isActive() );
       
   312 
       
   313     disconnect( this, SIGNAL( commandSignal() ), mVolumeControl, SLOT( handleSliderPressed() ) );
       
   314 
       
   315     cleanup();
       
   316 }
       
   317 
       
   318 // -------------------------------------------------------------------------------------------------
       
   319 // testHandleSliderReleased
       
   320 // -------------------------------------------------------------------------------------------------
       
   321 //
       
   322 void TestVolumeControl::testHandleSliderReleased()
       
   323 {
       
   324     MPX_ENTER_EXIT(_L("TestVolumeControl::testHandleSliderReleased()"));
       
   325 
       
   326     setup();
       
   327 
       
   328     connect( this, SIGNAL( commandSignal() ), mVolumeControl, SLOT( handleSliderReleased() ) );
       
   329 
       
   330     mVolumeControl->mDragging = true;
       
   331     mVolumeControl->mDraggingVolume = 3;
       
   332     mVolumeControl->mVolume = 5;
       
   333 
       
   334     emit commandSignal();
       
   335 
       
   336     QVERIFY( ! mVolumeControl->mDragging );
       
   337     QVERIFY( ! mVolumeControl->mDraggingHandlerTimer->isActive() );
       
   338     QVERIFY( mVolumeControl->mVolume == mVolumeControl->mDraggingVolume );
       
   339     QVERIFY( mController->mCommand == EMPXPbvCmdSetVolume );
       
   340     QVERIFY( mController->mValue == mVolumeControl->mDraggingVolume );
       
   341 
       
   342     disconnect( this, SIGNAL( commandSignal() ), mVolumeControl, SLOT( handleSliderReleased() ) );
       
   343 
       
   344     cleanup();
       
   345 }
       
   346 
       
   347 // -------------------------------------------------------------------------------------------------
       
   348 // testHandleDraggingTimerTimeOut
       
   349 // -------------------------------------------------------------------------------------------------
       
   350 //
       
   351 void TestVolumeControl::testHandleDraggingTimerTimeOut()
       
   352 {
       
   353     MPX_ENTER_EXIT(_L("TestVolumeControl::testHandleDraggingTimerTimeOut()"));
       
   354 
       
   355     setup();
       
   356 
       
   357     connect( this, SIGNAL( commandSignal() ), mVolumeControl, SLOT( handleDraggingTimerTimeOut() ) );
       
   358 
       
   359     //
       
   360     // mDragging is false
       
   361     //
       
   362     mVolumeControl->mDragging = false;
       
   363     mVolumeControl->mVolume = 6;
       
   364     mVolumeControl->mDraggingVolume = 10;
       
   365 
       
   366     emit commandSignal();
       
   367 
       
   368     QVERIFY( mVolumeControl->mVolume != mVolumeControl->mDraggingVolume );
       
   369 
       
   370     //
       
   371     // mDragging is true
       
   372     //
       
   373     mVolumeControl->mDragging = true;
       
   374 
       
   375     emit commandSignal();
       
   376 
       
   377     QVERIFY( mVolumeControl->mVolume == mVolumeControl->mDraggingVolume );
       
   378     QVERIFY( mController->mCommand == EMPXPbvCmdSetVolume );
       
   379     QVERIFY( mController->mValue == mVolumeControl->mVolume );
       
   380 
       
   381 
       
   382     //
       
   383     // mDragging is true && vol == 0 && mMutedByMuteIcon is true
       
   384     //
       
   385     mVolumeControl->mDragging = true;
       
   386     mVolumeControl->mDraggingVolume = 0;
       
   387     mVolumeControl->mMutedByMuteIcon = true;
       
   388 
       
   389     emit commandSignal();
       
   390 
       
   391     QVERIFY( ! mVolumeControl->mMutedByMuteIcon );
       
   392 
       
   393     disconnect( this, SIGNAL( commandSignal() ), mVolumeControl, SLOT( handleDraggingTimerTimeOut() ) );
       
   394 
       
   395     cleanup();
       
   396 }
       
   397 
       
   398 // End of file