mpengine/tsrc/unittest_mpmediakeyhandler/src/unittest_mpmediakeyhandler.cpp
changeset 47 4cc1412daed0
parent 45 612c4815aebe
child 51 560ce2306a17
equal deleted inserted replaced
45:612c4815aebe 47:4cc1412daed0
     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: Unit test for mpmediakeyhandler
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QSignalSpy>
       
    19 #include <QMetaType>
       
    20 #include <hbapplication.h>
       
    21 #include <hbmainwindow.h>
       
    22 #include <e32debug.h>
       
    23 
       
    24 #include "unittest_mpmediakeyhandler.h"
       
    25 #include "mpcommondefs.h"
       
    26 #include "stub/inc/mpxplaybackutility.h"
       
    27 #include "stub/inc/remconcoreapitarget.h"
       
    28 #include "stub/inc/remconinterfaceselector.h"
       
    29 
       
    30 
       
    31 // Do this so we can access all member variables.
       
    32 #define private public
       
    33 #include "mpmediakeyhandler.h"
       
    34 #include "mpmediakeyhandler_p.h"
       
    35 #undef private
       
    36 
       
    37 
       
    38 /*!
       
    39  Make our test case a stand-alone executable that runs all the test functions.
       
    40  */
       
    41 int main(int argc, char *argv[])
       
    42 {
       
    43     HbApplication app(argc, argv);
       
    44     HbMainWindow window;
       
    45 
       
    46     TestMpMediaKeyHandler tv;
       
    47 
       
    48     char *pass[3];
       
    49     pass[0] = argv[0];
       
    50     pass[1] = "-o";
       
    51     pass[2] = "c:\\data\\unittest_mpmediakeyhandler.txt";
       
    52 
       
    53     int res = QTest::qExec(&tv, 3, pass);
       
    54 
       
    55     return res;
       
    56 }
       
    57 
       
    58 TestMpMediaKeyHandler::TestMpMediaKeyHandler()
       
    59     : mTest(0)
       
    60 {
       
    61 }
       
    62 
       
    63 TestMpMediaKeyHandler::~TestMpMediaKeyHandler()
       
    64 {
       
    65     delete mTest;
       
    66 }
       
    67 
       
    68 /*!
       
    69  Called before the first testfunction is executed.
       
    70  */
       
    71 void TestMpMediaKeyHandler::initTestCase()
       
    72 {
       
    73     RDebug::Print(_L("initTestCase()"));
       
    74 }
       
    75 
       
    76 /*!
       
    77  Called after the last testfunction was executed.
       
    78  */
       
    79 void TestMpMediaKeyHandler::cleanupTestCase()
       
    80 {
       
    81     RDebug::Print(_L("cleanupTestCase()"));
       
    82 }
       
    83 
       
    84 /*!
       
    85  Called before each testfunction is executed.
       
    86  */
       
    87 void TestMpMediaKeyHandler::init()
       
    88 {
       
    89     RDebug::Print(_L(">>init()"));
       
    90     mTest = new MpMediaKeyHandler();
       
    91     mTestPrivate = mTest->d_ptr;
       
    92     RDebug::Print(_L("<<init()"));
       
    93 }
       
    94 
       
    95 /*!
       
    96  Called after every testfunction.
       
    97  */
       
    98 void TestMpMediaKeyHandler::cleanup()
       
    99 {
       
   100     if (mTest)
       
   101     {
       
   102         delete mTest;
       
   103         mTest = 0;
       
   104         mTestPrivate = 0;
       
   105     }
       
   106 }
       
   107 
       
   108 void TestMpMediaKeyHandler::testConstructor()
       
   109 {
       
   110     RDebug::Print(_L(">>testConstructor()"));
       
   111     
       
   112     QVERIFY(mTest != 0);
       
   113     QVERIFY(mTestPrivate != 0);
       
   114     QVERIFY(mTestPrivate->iInterfaceSelector != 0);
       
   115     QVERIFY(mTestPrivate->iResponseHandler != 0);
       
   116     QVERIFY(mTestPrivate->iPlaybackUtility != 0);
       
   117     
       
   118     RDebug::Print(_L("<<testConstructor()"));
       
   119 }
       
   120 
       
   121 void TestMpMediaKeyHandler::testDestructor()
       
   122 {
       
   123     RDebug::Print(_L(">>testDestructor()"));
       
   124     
       
   125     // it is been observed that CRemConCoreApiTarget is not being deleted by anyone
       
   126     // the creator claim it does not own it, while others never claim the ownership neither
       
   127     cleanup();
       
   128     QVERIFY(mTest == 0);
       
   129     QCOMPARE(MMPXPlaybackUtility::getCount(), 0);
       
   130     QCOMPARE(CRemConCoreApiTarget::getCount(), 0);
       
   131     QCOMPARE(CRemConInterfaceSelector::getCount(), 0);
       
   132     
       
   133     RDebug::Print(_L("<<testDestructor()"));
       
   134 }
       
   135 
       
   136 void TestMpMediaKeyHandler::testConstructorFail()
       
   137 {
       
   138     RDebug::Print(_L(">>testConstructorFail()"));
       
   139 
       
   140     // errorOccured signal cannot be connected until mediakeyhandler is created,
       
   141     // and error during construction cannot be feedback.
       
   142     // solution should be to seperate construction/init
       
   143     cleanup();
       
   144     CRemConInterfaceSelector::setNewLLeave();
       
   145     init();
       
   146     QSignalSpy spy1(mTest, SIGNAL(errorOccured(int)));
       
   147     QVERIFY(mTest != 0);
       
   148     //QCOMPARE(spy1.count(), 1);    // failed if comment in
       
   149     
       
   150     cleanup();
       
   151     CRemConInterfaceSelector::setOpenTargetLLeave();
       
   152     init();
       
   153     QSignalSpy spy2(mTest, SIGNAL(errorOccured(int)));
       
   154     QVERIFY(mTest != 0);
       
   155     //QCOMPARE(spy2.count(), 1);    // failed if comment in
       
   156     
       
   157     cleanup();
       
   158     CRemConCoreApiTarget::setNewLLeave();
       
   159     init();
       
   160     QSignalSpy spy3(mTest, SIGNAL(errorOccured(int)));
       
   161     QVERIFY(mTest != 0);
       
   162     //QCOMPARE(spy3.count(), 1);    // failed if comment in
       
   163 
       
   164     cleanup();
       
   165     MMPXPlaybackUtility::setNewLLeave();
       
   166     init();
       
   167     QSignalSpy spy4(mTest, SIGNAL(errorOccured(int)));
       
   168     QVERIFY(mTest != 0);
       
   169     //QCOMPARE(spy4.count(), 1);    // failed if comment in
       
   170     
       
   171     cleanup();
       
   172     MMPXPlaybackUtility::setAddObserverLLeave();
       
   173     init();
       
   174     QSignalSpy spy5(mTest, SIGNAL(errorOccured(int)));
       
   175     QVERIFY(mTest != 0);
       
   176     //QCOMPARE(spy5.count(), 1);    // failed if comment in
       
   177     
       
   178     RDebug::Print(_L("<<testConstructorFail()"));
       
   179 }
       
   180 
       
   181 void TestMpMediaKeyHandler::testDestructorFail()
       
   182 {
       
   183     RDebug::Print(_L(">>testDestructorFail()"));
       
   184     
       
   185     MMPXPlaybackUtility::setRemoveObserverLLeave();
       
   186     cleanup();
       
   187     QVERIFY(mTest == 0);
       
   188     QCOMPARE(MMPXPlaybackUtility::getCount(), 0);
       
   189     QCOMPARE(CRemConCoreApiTarget::getCount(), 0);
       
   190     QCOMPARE(CRemConInterfaceSelector::getCount(), 0);
       
   191     
       
   192     RDebug::Print(_L("<<testDestructorFail()"));
       
   193 }
       
   194 
       
   195 void TestMpMediaKeyHandler::testCommandVolumeUpKey()
       
   196 {
       
   197     RDebug::Print(_L(">>testCommandVolumeUpKey()"));
       
   198     
       
   199     // volumeChanged signal would not emit until mediakeyhandler is not added as an observer to MMPXPlaybackUtility
       
   200     QSignalSpy spy(mTest, SIGNAL(volumeChanged(int)));
       
   201     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   202     MMPXPlaybackUtility::setPlaying();
       
   203     mTestPrivate->MrccatoCommand(ERemConCoreApiVolumeUp, ERemConCoreApiButtonClick);
       
   204     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   205     QCOMPARE(spy.count(), 1);
       
   206     
       
   207     // impossible to stub out the CPeriodic class which is part of the Press/Release handling
       
   208     // hence, those logic could not be tested 
       
   209     
       
   210     RDebug::Print(_L("<<testCommandVolumeUpKey()"));
       
   211 }
       
   212 
       
   213 void TestMpMediaKeyHandler::testCommandVolumeDownKey()
       
   214 {
       
   215     RDebug::Print(_L(">>testCommandVolumeDownKey()"));
       
   216     
       
   217     // volumeChanged signal would not emit until mediakeyhandler is not added as an observer to MMPXPlaybackUtility
       
   218     QSignalSpy spy(mTest, SIGNAL(volumeChanged(int)));
       
   219     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   220     MMPXPlaybackUtility::setPlaying();
       
   221     mTestPrivate->MrccatoCommand(ERemConCoreApiVolumeDown, ERemConCoreApiButtonClick);
       
   222     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   223     QCOMPARE(spy.count(), 1);
       
   224     
       
   225     // impossible to stub out the CPeriodic class which is part of the Press/Release handling
       
   226     // hence, those logic could not be tested
       
   227     
       
   228     RDebug::Print(_L("<<testCommandVolumeDownKey()"));
       
   229 }
       
   230 
       
   231 void TestMpMediaKeyHandler::testCommandPlayKey()
       
   232 {
       
   233     RDebug::Print(_L(">>testCommandPlayKey()"));
       
   234     
       
   235     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   236     mTestPrivate->MrccatoCommand(ERemConCoreApiPlay, ERemConCoreApiButtonClick);
       
   237     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   238     
       
   239     RDebug::Print(_L("<<testCommandPlayKey()"));
       
   240 }
       
   241 
       
   242 void TestMpMediaKeyHandler::testCommandPauseKey()
       
   243 {
       
   244     RDebug::Print(_L(">>testCommandPauseKey()"));
       
   245     
       
   246     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   247     mTestPrivate->MrccatoCommand(ERemConCoreApiPause, ERemConCoreApiButtonClick);
       
   248     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   249         
       
   250     RDebug::Print(_L("<<testCommandPauseKey()"));
       
   251 }
       
   252 
       
   253 void TestMpMediaKeyHandler::testCommandPlayPauseKey()
       
   254 {
       
   255     RDebug::Print(_L(">>testCommandPlayPauseKey()"));
       
   256     
       
   257     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   258     mTestPrivate->MrccatoCommand(ERemConCoreApiPausePlayFunction, ERemConCoreApiButtonClick);
       
   259     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   260     
       
   261     RDebug::Print(_L("<<testCommandPlayPauseKey()"));
       
   262 }
       
   263 
       
   264 void TestMpMediaKeyHandler::testCommandStopKey()
       
   265 {
       
   266     RDebug::Print(_L(">>testCommandStopKey()"));
       
   267     
       
   268     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   269     mTestPrivate->MrccatoCommand(ERemConCoreApiStop, ERemConCoreApiButtonClick);
       
   270     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   271     
       
   272     RDebug::Print(_L("<<testCommandStopKey()"));
       
   273 }
       
   274 
       
   275 void TestMpMediaKeyHandler::testCommandFastForwardKeyPress()
       
   276 {
       
   277     RDebug::Print(_L(">>testCommandFastForwardKeyPress()"));
       
   278     
       
   279     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   280     mTestPrivate->MrccatoCommand(ERemConCoreApiFastForward, ERemConCoreApiButtonPress);
       
   281     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   282     
       
   283     RDebug::Print(_L("<<testCommandFastForwardKeyPress()"));
       
   284 }
       
   285 
       
   286 void TestMpMediaKeyHandler::testCommandFastForwardKeyRelease()
       
   287 {
       
   288     RDebug::Print(_L(">>testCommandFastForwardKeyRelease()"));
       
   289     
       
   290     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   291     mTestPrivate->MrccatoCommand(ERemConCoreApiFastForward, ERemConCoreApiButtonRelease);
       
   292     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   293     
       
   294     RDebug::Print(_L("<<testCommandFastForwardKeyRelease()"));
       
   295 }
       
   296 
       
   297 void TestMpMediaKeyHandler::testCommandRewindKeyPress()
       
   298 {
       
   299     RDebug::Print(_L(">>testCommandRewindKey()"));
       
   300     
       
   301     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   302     mTestPrivate->MrccatoCommand(ERemConCoreApiRewind, ERemConCoreApiButtonPress);
       
   303     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   304     
       
   305     RDebug::Print(_L("<<testCommandRewindKey()"));
       
   306 }
       
   307 
       
   308 void TestMpMediaKeyHandler::testCommandRewindKeyRelease()
       
   309 {
       
   310     RDebug::Print(_L(">>testCommandRewindKeyRelease()"));
       
   311     
       
   312     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   313     mTestPrivate->MrccatoCommand(ERemConCoreApiRewind, ERemConCoreApiButtonRelease);
       
   314     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   315     
       
   316     RDebug::Print(_L("<<testCommandRewindKeyRelease()"));
       
   317 }
       
   318 
       
   319 void TestMpMediaKeyHandler::testCommandForwardKey()
       
   320 {
       
   321     RDebug::Print(_L(">>testCommandForwardKey()"));
       
   322     
       
   323     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   324     mTestPrivate->MrccatoCommand(ERemConCoreApiForward, ERemConCoreApiButtonClick);
       
   325     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   326     
       
   327     RDebug::Print(_L("<<testCommandForwardKey()"));
       
   328 }
       
   329 
       
   330 void TestMpMediaKeyHandler::testCommandBackwardKey()
       
   331 {
       
   332     RDebug::Print(_L(">>testCommandBackwardKey()"));
       
   333     
       
   334     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   335     mTestPrivate->MrccatoCommand(ERemConCoreApiBackward, ERemConCoreApiButtonClick);
       
   336     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   337     
       
   338     RDebug::Print(_L("<<testCommandBackwardKey()"));
       
   339 }
       
   340 
       
   341 void TestMpMediaKeyHandler::testPlay()
       
   342 {
       
   343     RDebug::Print(_L(">>testPlay()"));
       
   344     
       
   345     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   346     mTestPrivate->MrccatoPlay(ERemConCoreApiPlaybackSpeedX1, ERemConCoreApiButtonClick);
       
   347     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   348     
       
   349     RDebug::Print(_L("<<testPlay()"));
       
   350 }
       
   351 
       
   352 void TestMpMediaKeyHandler::testAudioInputFunction()
       
   353 {
       
   354     RDebug::Print(_L(">>testAudioInputFunction()"));
       
   355     
       
   356     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   357     mTestPrivate->MrccatoSelectAudioInputFunction(0, ERemConCoreApiButtonClick);
       
   358     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   359         
       
   360     RDebug::Print(_L("<<testAudioInputFunction()"));
       
   361 }
       
   362 
       
   363 void TestMpMediaKeyHandler::testSelectAvInputFunction()
       
   364 {
       
   365     RDebug::Print(_L(">>testSelectAvInputFunction()"));
       
   366     
       
   367     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   368     mTestPrivate->MrccatoSelectAvInputFunction(0, ERemConCoreApiButtonClick);
       
   369     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   370 
       
   371     RDebug::Print(_L("<<testSelectAvInputFunction()"));
       
   372 }
       
   373 
       
   374 void TestMpMediaKeyHandler::testSelectDiskFunction()
       
   375 {
       
   376     RDebug::Print(_L(">>testSelectDiskFunction()"));
       
   377     
       
   378     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   379     mTestPrivate->MrccatoSelectDiskFunction(0, ERemConCoreApiButtonClick);
       
   380     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   381 
       
   382     RDebug::Print(_L("<<testSelectDiskFunction()"));
       
   383 }
       
   384 
       
   385 void TestMpMediaKeyHandler::testTuneFunction()
       
   386 {
       
   387     RDebug::Print(_L(">>testTuneFunction()"));
       
   388 
       
   389     int oldCount = CRemConCoreApiTarget::getSendResponseCount();
       
   390     mTestPrivate->MrccatoTuneFunction(ETrue, 0, 1, ERemConCoreApiButtonClick);
       
   391     QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
       
   392 
       
   393     RDebug::Print(_L("<<testTuneFunction()"));
       
   394 }
       
   395 
       
   396 // End of file