mpviewplugins/mpplaybackviewplugin/tsrc/unittest_mpmpxpbframeworkwrapper/src/unittest_mpmpxpbframeworkwrapper.cpp
branchGCC_SURGE
changeset 44 eff9df3d9c98
parent 30 b95ddb5a0d10
parent 42 79c49924ae23
equal deleted inserted replaced
30:b95ddb5a0d10 44:eff9df3d9c98
     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 mpmpxpbframeworkwrapper
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QSignalSpy>
       
    19 #include <hbapplication.h>
       
    20 #include <hbmainwindow.h>
       
    21 
       
    22 #include <mpxmedia.h>
       
    23 #include <mpxcollectionplaylist.h>
       
    24 
       
    25 
       
    26 
       
    27 #include "unittest_mpmpxpbframeworkwrapper.h"
       
    28 #include "stub/inc/mpplaybackdata.h"
       
    29 #include "stub/inc/mpxcollectionutility.h"
       
    30 #include "stub/inc/mpxplaybackutility.h"
       
    31 
       
    32 
       
    33 // Do this so we can access all member variables.
       
    34 #define private public
       
    35 #include "mpmpxpbframeworkwrapper.h"
       
    36 #include "mpmpxpbframeworkwrapper_p.h"
       
    37 #undef private
       
    38 
       
    39 //This so we can test private functions
       
    40 #include "../../src/mpmpxpbframeworkwrapper.cpp"
       
    41 #include "../../src/mpmpxpbframeworkwrapper_p.cpp"
       
    42 //Test data
       
    43 struct TTestAttrs
       
    44     {
       
    45     const wchar_t* GeneralTitle;
       
    46     const wchar_t* MusicArtist;
       
    47     const TInt GeneralCount;
       
    48     const wchar_t* MusicAlbumArtFileName;
       
    49     const wchar_t* MusicAlbum;
       
    50     const wchar_t* MusicUri;
       
    51     };
       
    52     
       
    53 const TTestAttrs KAllSongsTestData[] =
       
    54     {
       
    55      { L"Title 1", L"Artist 1", 1, L"e:\\data\\images\\art1.jpg", L"Album 1", L"Uri 1"}
       
    56     ,{ L"Title 2", L"Artist 2", 1, L"e:\\data\\images\\art2.jpg", L"Album 2", L"Uri 2"}  
       
    57     };
       
    58 
       
    59 /*!
       
    60  Make our test case a stand-alone executable that runs all the test functions.
       
    61  */
       
    62 int main(int argc, char *argv[])
       
    63 {
       
    64     HbApplication app(argc, argv);
       
    65     HbMainWindow window;
       
    66 
       
    67     TestMpMpxPbFrameworkWrapper tv;
       
    68 
       
    69     char *pass[3];
       
    70     pass[0] = argv[0];
       
    71     pass[1] = "-o";
       
    72     pass[2] = "c:\\data\\unittest_mpmpxpbframeworkwrapper.txt";
       
    73 
       
    74     int res = QTest::qExec(&tv, 3, pass);
       
    75 
       
    76     return res;
       
    77 }
       
    78 
       
    79 TestMpMpxPbFrameworkWrapper::TestMpMpxPbFrameworkWrapper()
       
    80     : mTest(0),
       
    81       iMediaTestData(0)
       
    82 {
       
    83 }
       
    84 
       
    85 TestMpMpxPbFrameworkWrapper::~TestMpMpxPbFrameworkWrapper()
       
    86 {
       
    87     delete mTest;
       
    88 }
       
    89 
       
    90 /*!
       
    91  Called before the first testfunction is executed.
       
    92  */
       
    93 void TestMpMpxPbFrameworkWrapper::initTestCase()
       
    94 {
       
    95 }
       
    96 
       
    97 /*!
       
    98  Called after the last testfunction was executed.
       
    99  */
       
   100 void TestMpMpxPbFrameworkWrapper::cleanupTestCase()
       
   101 {
       
   102 }
       
   103 
       
   104 /*!
       
   105  Called before each testfunction is executed.
       
   106  */
       
   107 void TestMpMpxPbFrameworkWrapper::init()
       
   108 {
       
   109     
       
   110     mTest = new MpMpxPbFrameworkWrapper();
       
   111     mTestPrivate = mTest->d_ptr;
       
   112 }
       
   113 
       
   114 /*!
       
   115  Called after every testfunction.
       
   116  */
       
   117 void TestMpMpxPbFrameworkWrapper::cleanup()
       
   118 {
       
   119     delete mTest;
       
   120     mTest = 0;
       
   121 }
       
   122 
       
   123 /*!
       
   124  Tests constructor.
       
   125  */
       
   126 void TestMpMpxPbFrameworkWrapper::testConstructor()
       
   127 {
       
   128     QVERIFY(mTestPrivate->iCollectionUtility != 0);
       
   129     QVERIFY(mTestPrivate->iPlaybackUtility != 0);
       
   130     QVERIFY(mTestPrivate->iPlaybackData != 0);
       
   131 }
       
   132 
       
   133 /*!
       
   134  Tests playbackData
       
   135  */
       
   136 void TestMpMpxPbFrameworkWrapper::testPlaybackData()
       
   137 {
       
   138     MpPlaybackData *playbackdata;
       
   139     playbackdata = mTest->playbackData();
       
   140     QCOMPARE(mTestPrivate->iPlaybackData, playbackdata);
       
   141 }
       
   142 
       
   143 /*!
       
   144  Tests stop.
       
   145  */
       
   146 void TestMpMpxPbFrameworkWrapper::testStop()
       
   147 {
       
   148     mTest->stop();
       
   149     QCOMPARE(mTestPrivate->iPlaybackUtility->iCmd, EPbCmdStop);
       
   150 }
       
   151 
       
   152 /*!
       
   153  Tests playPause.
       
   154  */
       
   155 void TestMpMpxPbFrameworkWrapper::testPlayPause()
       
   156 {
       
   157     mTest->playPause();
       
   158     QCOMPARE(mTestPrivate->iPlaybackUtility->iCmd, EPbCmdPlayPause);
       
   159 }
       
   160 
       
   161 /*!
       
   162  Tests skipForward.
       
   163  */
       
   164 void TestMpMpxPbFrameworkWrapper::testSkipForward()
       
   165 {
       
   166     mTest->skipForward();
       
   167     QCOMPARE(mTestPrivate->iPlaybackUtility->iCmd, EPbCmdNext);
       
   168 }
       
   169 
       
   170 /*!
       
   171  Tests skipBackward
       
   172  */
       
   173 void TestMpMpxPbFrameworkWrapper::testSkipBackward()
       
   174 {
       
   175     mTest->skipBackward();
       
   176     QCOMPARE(mTestPrivate->iPlaybackUtility->iCmd, EPbCmdPrevious);
       
   177 }
       
   178 
       
   179 /*!
       
   180  Tests setPosition
       
   181  */
       
   182 void TestMpMpxPbFrameworkWrapper::testSetPosition()
       
   183 {
       
   184     mTest->setPosition(100);
       
   185     QCOMPARE(mTestPrivate->iPlaybackUtility->iValue, 100);
       
   186     QCOMPARE(mTestPrivate->iPlaybackUtility->iProperty, EPbPropertyPosition);
       
   187     mTest->setPosition(50);
       
   188     QCOMPARE(mTestPrivate->iPlaybackUtility->iValue, 50);
       
   189     QCOMPARE(mTestPrivate->iPlaybackUtility->iProperty, EPbPropertyPosition);
       
   190     mTest->setPosition(700);
       
   191     QCOMPARE(mTestPrivate->iPlaybackUtility->iValue, 700);
       
   192     QCOMPARE(mTestPrivate->iPlaybackUtility->iProperty, EPbPropertyPosition);    
       
   193 }
       
   194 
       
   195 /*!
       
   196  Tests setShuffle
       
   197  */
       
   198 void TestMpMpxPbFrameworkWrapper::testSetShuffle()
       
   199 {
       
   200     mTest->setShuffle(true);
       
   201     QCOMPARE(mTestPrivate->iPlaybackUtility->iValue, TBool(ETrue));
       
   202     QCOMPARE(mTestPrivate->iPlaybackUtility->iProperty, EPbPropertyRandomMode);
       
   203     mTest->setShuffle(false);
       
   204     QCOMPARE(mTestPrivate->iPlaybackUtility->iValue, TBool(EFalse));
       
   205     QCOMPARE(mTestPrivate->iPlaybackUtility->iProperty, EPbPropertyRandomMode);
       
   206 }
       
   207 
       
   208 /*!
       
   209  Tests setRepeat
       
   210  */
       
   211 void TestMpMpxPbFrameworkWrapper::testSetRepeat()
       
   212 {
       
   213     mTest->setRepeat(true);
       
   214     QCOMPARE(TMPXPlaybackRepeatMode(mTestPrivate->iPlaybackUtility->iValue), EPbRepeatAll);
       
   215     QCOMPARE(mTestPrivate->iPlaybackUtility->iProperty, EPbPropertyRepeatMode);
       
   216     mTest->setRepeat(false);
       
   217     QCOMPARE(TMPXPlaybackRepeatMode(mTestPrivate->iPlaybackUtility->iValue), EPbRepeatOff);
       
   218     QCOMPARE(mTestPrivate->iPlaybackUtility->iProperty, EPbPropertyRepeatMode);
       
   219 }
       
   220 
       
   221 /*!
       
   222  Tests handleProperty
       
   223  */
       
   224 void TestMpMpxPbFrameworkWrapper::testHandlePlaybackMessage()
       
   225 {
       
   226     RArray<TInt> supportedIds;
       
   227     CleanupClosePushL( supportedIds );
       
   228     supportedIds.AppendL( KMPXMessageContentIdGeneral );
       
   229     CMPXMedia* testMessage = CMPXMedia::NewL(supportedIds.Array());
       
   230     CleanupStack::PopAndDestroy(&supportedIds);
       
   231     CleanupStack::PushL(testMessage);
       
   232     testMessage->SetTObjectValueL<TMPXMessageId>( KMPXMessageGeneralId, KMPXMessageGeneral);
       
   233     
       
   234     //Update State
       
   235     testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralEvent,TMPXPlaybackMessage::EStateChanged);
       
   236     testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralType,0);
       
   237     testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralData,0);
       
   238     mTestPrivate->iPlaybackUtility->iState = EPbStatePlaying;
       
   239     mTestPrivate->HandlePlaybackMessage(testMessage, KErrNone);
       
   240     QCOMPARE(mTestPrivate->iPlaybackData->mPlaybackState, MpPlaybackData::Playing);
       
   241     
       
   242     //Initialize complete
       
   243     testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralEvent,TMPXPlaybackMessage::EInitializeComplete);
       
   244     testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralType,0);
       
   245     testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralData,1);
       
   246     mTestPrivate->HandlePlaybackMessage(testMessage, KErrNone);
       
   247     QCOMPARE(mTestPrivate->iPlaybackUtility->iCMPXCmd->ValueTObjectL<TInt>(KMPXCommandGeneralId),KMPXCommandIdPlaybackGeneral);
       
   248     QCOMPARE(mTestPrivate->iPlaybackUtility->iCMPXCmd->ValueTObjectL<TInt>(KMPXCommandPlaybackGeneralType),TInt(EPbCmdPlay));
       
   249     QCOMPARE(mTestPrivate->iPlaybackUtility->iCMPXCmd->ValueTObjectL<TBool>(KMPXCommandGeneralDoSync),TBool(ETrue));
       
   250     QCOMPARE(mTestPrivate->iPlaybackUtility->iCMPXCmd->ValueTObjectL<TBool>(KMPXCommandPlaybackGeneralNoBuffer),TBool(ETrue));
       
   251 
       
   252     //Property change
       
   253     testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralEvent,TMPXPlaybackMessage::EPropertyChanged);
       
   254     testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralType,EPbPropertyPosition);
       
   255     testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralData,50);
       
   256     mTestPrivate->HandlePlaybackMessage(testMessage, KErrNone);
       
   257     QCOMPARE(mTestPrivate->iPlaybackData->mPosition, 50);
       
   258     
       
   259     testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralType,EPbPropertyDuration);
       
   260     testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralData,100);
       
   261     mTestPrivate->HandlePlaybackMessage(testMessage, KErrNone);
       
   262     QCOMPARE(mTestPrivate->iPlaybackData->mDuration, 100);
       
   263     
       
   264     //Media change
       
   265     testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralEvent,TMPXPlaybackMessage::EMediaChanged);
       
   266     testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralType,0);
       
   267     testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralData,0);
       
   268     mTestPrivate->HandlePlaybackMessage(testMessage, KErrNone);
       
   269     QCOMPARE(mTestPrivate->iPlaybackUtility->iAttrs->Count(), 5);
       
   270 }
       
   271 
       
   272 /*!
       
   273  Tests handleProperty
       
   274  */
       
   275 void TestMpMpxPbFrameworkWrapper::testHandleProperty()
       
   276 {
       
   277     for(TInt i = 0; i < 10; i++){
       
   278         mTestPrivate->HandlePropertyL(EPbPropertyPosition, i, KErrNone);
       
   279         mTestPrivate->HandlePropertyL(EPbPropertyDuration, i+1, KErrNone);
       
   280         QCOMPARE(mTestPrivate->iPlaybackData->mPosition, i);
       
   281         QCOMPARE(mTestPrivate->iPlaybackData->mDuration, i+1);       
       
   282     }
       
   283     mTestPrivate->iPlaybackData->mPosition = 100;
       
   284     mTestPrivate->iPlaybackData->mDuration = 100;
       
   285     mTestPrivate->HandlePropertyL(EPbPropertyPosition, 10, KErrNotFound);
       
   286     mTestPrivate->HandlePropertyL(EPbPropertyDuration, 10, KErrNotFound);
       
   287     
       
   288     QCOMPARE(mTestPrivate->iPlaybackData->mPosition, 100);
       
   289     QCOMPARE(mTestPrivate->iPlaybackData->mDuration, 100);
       
   290 }
       
   291 
       
   292 /*!
       
   293  Tests handleMedia
       
   294  */
       
   295 void TestMpMpxPbFrameworkWrapper::testHandleMedia()
       
   296 {
       
   297     loadTestData(0);
       
   298     mTestPrivate->HandleMediaL(*iMediaTestData, KErrNone);
       
   299     QCOMPARE(mTestPrivate->iPlaybackData->mMediaReady, TBool(ETrue));
       
   300     mTestPrivate->iPlaybackData->mMediaReady = EFalse;
       
   301     mTestPrivate->HandleMediaL(*iMediaTestData, KErrNone);
       
   302     QCOMPARE(mTestPrivate->iPlaybackData->mMediaReady, TBool(EFalse));
       
   303     
       
   304     loadTestData(1);
       
   305     mTestPrivate->iPlaybackData->mMediaReady = EFalse;
       
   306     mTestPrivate->HandleMediaL(*iMediaTestData, KErrNone);
       
   307     QCOMPARE(mTestPrivate->iPlaybackData->mMediaReady, TBool(ETrue));
       
   308     const TDesC& title = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[1].GeneralTitle));
       
   309     QCOMPARE(mTestPrivate->iPlaybackData->title(), QString::fromUtf16( title.Ptr(), title.Length() ));
       
   310     const TDesC& artist = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[1].MusicArtist));
       
   311     QCOMPARE(mTestPrivate->iPlaybackData->artist(), QString::fromUtf16( artist.Ptr(), artist.Length() ));
       
   312     const TDesC& album = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[1].MusicAlbum));
       
   313     QCOMPARE(mTestPrivate->iPlaybackData->album(), QString::fromUtf16( album.Ptr(), album.Length() ));
       
   314     const TDesC& albumArt = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[1].MusicAlbumArtFileName));
       
   315     QCOMPARE(mTestPrivate->iPlaybackData->currentAAUri, QString::fromUtf16( albumArt.Ptr(), albumArt.Length() ));
       
   316     const TDesC& albumUri = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[1].MusicUri));
       
   317     QCOMPARE(mTestPrivate->iPlaybackData->currentUri, QString::fromUtf16( albumUri.Ptr(), albumUri.Length() ));
       
   318 }
       
   319 
       
   320 /*!
       
   321  Tests retrieveSong
       
   322  */
       
   323 void TestMpMpxPbFrameworkWrapper::testRetrieveSongDetails()
       
   324 {
       
   325     mTestPrivate->RetrieveSongDetailsL();
       
   326     QCOMPARE(mTestPrivate->iPlaybackUtility->iAttrs->Count(), 5);
       
   327 }
       
   328 
       
   329 /*!
       
   330  Tests updateState
       
   331  */
       
   332 void TestMpMpxPbFrameworkWrapper::testUpdateState()
       
   333 {
       
   334     mTestPrivate->iPlaybackUtility->iState = EPbStatePlaying;
       
   335     mTestPrivate->UpdateStateL();
       
   336     QCOMPARE(mTestPrivate->iPlaybackData->mPlaybackState, MpPlaybackData::Playing);
       
   337     mTestPrivate->iPlaybackUtility->iState = EPbStatePaused;
       
   338     mTestPrivate->UpdateStateL();
       
   339     QCOMPARE(mTestPrivate->iPlaybackData->mPlaybackState, MpPlaybackData::Paused);
       
   340     mTestPrivate->iPlaybackUtility->iState = EPbStatePlaying;
       
   341     mTestPrivate->UpdateStateL();
       
   342     QCOMPARE(mTestPrivate->iPlaybackData->mPlaybackState, MpPlaybackData::Playing);
       
   343     mTestPrivate->iPlaybackUtility->iState = EPbStateStopped;
       
   344     mTestPrivate->UpdateStateL();
       
   345     QCOMPARE(mTestPrivate->iPlaybackData->mPlaybackState, MpPlaybackData::Stopped);   
       
   346 }
       
   347 
       
   348 /*!
       
   349  Tests forceStop
       
   350  */
       
   351 void TestMpMpxPbFrameworkWrapper::testForceStop()
       
   352 {
       
   353     mTestPrivate->ForceStopL();
       
   354     QCOMPARE(mTestPrivate->iPlaybackUtility->iCMPXCmd->ValueTObjectL<TInt>(KMPXCommandGeneralId),KMPXCommandIdPlaybackGeneral);
       
   355     QCOMPARE(mTestPrivate->iPlaybackUtility->iCMPXCmd->ValueTObjectL<TInt>(KMPXCommandPlaybackGeneralType),TInt(EPbCmdStop));
       
   356     QCOMPARE(mTestPrivate->iPlaybackUtility->iCMPXCmd->ValueTObjectL<TBool>(KMPXCommandGeneralDoSync),TBool(ETrue));
       
   357     QCOMPARE(mTestPrivate->iPlaybackUtility->iCMPXCmd->ValueTObjectL<TBool>(KMPXCommandPlaybackGeneralNoBuffer),TBool(ETrue));
       
   358     QVERIFY(mTestPrivate->iPlaybackUtility->iObs == 0);
       
   359 }
       
   360 
       
   361 /*!
       
   362  Used to load test data
       
   363  */
       
   364 void TestMpMpxPbFrameworkWrapper::loadTestData(TInt aPos)
       
   365 {
       
   366     if(iMediaTestData){
       
   367         delete iMediaTestData;
       
   368         iMediaTestData=0;
       
   369     }
       
   370     RArray<TInt> supportedIds;
       
   371     CleanupClosePushL( supportedIds );
       
   372     supportedIds.AppendL( KMPXMediaIdMusic );
       
   373     supportedIds.AppendL( KMPXMediaIdGeneral );
       
   374     CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array());
       
   375     CleanupStack::PopAndDestroy(&supportedIds);
       
   376     CleanupStack::PushL(entries);
       
   377 
       
   378     entries->SetTextValueL(KMPXMediaGeneralTitle, TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[aPos].GeneralTitle)));
       
   379     entries->SetTextValueL(KMPXMediaMusicArtist, TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[aPos].MusicArtist)));
       
   380     entries->SetTObjectValueL<TInt>(KMPXMediaGeneralCount, KAllSongsTestData[aPos].GeneralCount);
       
   381     entries->SetTextValueL(KMPXMediaMusicAlbumArtFileName, TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[aPos].MusicAlbumArtFileName)));
       
   382     entries->SetTextValueL(KMPXMediaMusicAlbum, TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[aPos].MusicAlbum)));
       
   383     entries->SetTextValueL(KMPXMediaGeneralUri, TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[aPos].MusicUri)));
       
   384  
       
   385     iMediaTestData = CMPXMedia::NewL(*entries);
       
   386     CleanupStack::PopAndDestroy(entries);
       
   387 }
       
   388 
       
   389 //end of file