mpviewplugins/mpdetailsviewplugin/tsrc/unittest_mpsongdata/src/unittest_mpsongdata.cpp
changeset 43 0f32e550d9d8
parent 38 b93f525c9244
child 45 612c4815aebe
equal deleted inserted replaced
38:b93f525c9244 43:0f32e550d9d8
     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: Unit test for mpsongdata
       
    15 *
       
    16 */
       
    17 #include <QSignalSpy>
       
    18 #include <hbapplication.h>
       
    19 #include <hbmainwindow.h>
       
    20 #include <hbicon.h>
       
    21 
       
    22 #include"unittest_mpsongdata.h"
       
    23 #include "stub/inc/thumbnailmanager_qt.h"
       
    24 
       
    25 // Do this so we can access all member variables.
       
    26 #define private public
       
    27 #include "mpsongdata.h"
       
    28 #undef private
       
    29 
       
    30 
       
    31 /*!
       
    32  Make our test case a stand-alone executable that runs all the test functions.
       
    33  */
       
    34 int main(int argc, char *argv[])
       
    35 {
       
    36     HbApplication app(argc, argv);
       
    37     HbMainWindow window;
       
    38 
       
    39     TestMpSongData tv;
       
    40 
       
    41     char *pass[3];
       
    42     pass[0] = argv[0];
       
    43     pass[1] = "-o";
       
    44     pass[2] = "c:\\data\\unittest_testmpsongdata.txt";
       
    45 
       
    46     int res = QTest::qExec(&tv, 3, pass);
       
    47 
       
    48     return res;
       
    49 }
       
    50 
       
    51 //Constructor
       
    52 TestMpSongData::TestMpSongData()
       
    53     : mTest(0)
       
    54 {
       
    55 
       
    56 }
       
    57 
       
    58 //Destructor
       
    59 TestMpSongData::~TestMpSongData()
       
    60 {
       
    61     delete mTest;
       
    62 }
       
    63 
       
    64 /*!
       
    65  Called before the first testfunction is executed.
       
    66  */
       
    67 void TestMpSongData::initTestCase()
       
    68 {
       
    69     
       
    70 }
       
    71 
       
    72 /*!
       
    73  Called after the last testfunction was executed.
       
    74  */
       
    75 void TestMpSongData::cleanupTestCase()
       
    76 {
       
    77 
       
    78 }
       
    79 
       
    80 /*!
       
    81  Called before each testfunction is executed.
       
    82  */
       
    83 void TestMpSongData::init()
       
    84 {
       
    85     mTest = new MpSongData();
       
    86 }
       
    87 
       
    88 /*!
       
    89  Called after every testfunction.
       
    90  */
       
    91 void TestMpSongData::cleanup()
       
    92 {
       
    93     delete mTest;
       
    94     mTest = 0;
       
    95 }
       
    96 
       
    97 /*!
       
    98  Tests correct cleanup of member variables.
       
    99  */
       
   100 void TestMpSongData::testMemberCleanup()
       
   101 {
       
   102     cleanup();
       
   103     ThumbnailManager::resetInitCounter();
       
   104     init();
       
   105     cleanup();
       
   106     QCOMPARE(ThumbnailManager::getInitCounter(), 0);
       
   107 }
       
   108 
       
   109 /*!
       
   110  Tests that albumArt() returns NULL
       
   111  */
       
   112 void TestMpSongData::testAlbumArtIsNull()
       
   113     {
       
   114     QPixmap dummyAlbumArt;
       
   115     mTest->albumArt(dummyAlbumArt);
       
   116     QVERIFY(dummyAlbumArt.isNull() == true); // TODO: Hkn: What's the point of this ?
       
   117     }
       
   118 
       
   119 /*!
       
   120  Tests that albumArt() returns correct QPixmap when not NULL.
       
   121  */
       
   122 
       
   123 void TestMpSongData::testAlbumArtNotNull()
       
   124     {
       
   125     QPixmap dummyAlbumArt;
       
   126     mTest->mAlbumArt = QPixmap( ":/playbackviewicons/someAlbumArt.png" );
       
   127     mTest->albumArt(dummyAlbumArt);
       
   128     }
       
   129 
       
   130 /*!
       
   131  Tests that title() returns NULL
       
   132  */
       
   133 void TestMpSongData::testTitleIsNull()
       
   134     {
       
   135      QVERIFY(mTest->mTitle.isNull() == true);
       
   136     }
       
   137 
       
   138 /*!
       
   139  Tests that album() returns NULL
       
   140  */
       
   141 void TestMpSongData::testAlbumIsNull()
       
   142     {
       
   143      QVERIFY(mTest->mAlbum.isNull() == true);
       
   144     }
       
   145 
       
   146 /*!
       
   147  Tests that artist() returns NULL
       
   148  */
       
   149 void TestMpSongData::testArtistIsNull()
       
   150     {
       
   151      QVERIFY(mTest->mArtist.isNull() == true);
       
   152     }
       
   153 
       
   154 /*!
       
   155  Tests that comment() returns NULL
       
   156  */
       
   157 void TestMpSongData::testCommentIsNull()
       
   158     {
       
   159      QVERIFY(mTest->mComment.isNull() == true);
       
   160     }
       
   161 
       
   162 /*!
       
   163  Tests that composer() returns NULL
       
   164  */
       
   165 void TestMpSongData::testComposerIsNull()
       
   166     {
       
   167      QVERIFY(mTest->mComposer.isNull() == true);
       
   168     }
       
   169 
       
   170 /*!
       
   171  Tests that genre() returns NULL
       
   172  */
       
   173 void TestMpSongData::testGenreIsNull()
       
   174     {
       
   175      QVERIFY(mTest->mGenre.isNull() == true);
       
   176     }
       
   177 
       
   178 
       
   179 /*!
       
   180  Tests that albumTrack() returns NULL
       
   181  */
       
   182 void TestMpSongData::testAlbumtrackIsNull()
       
   183     {
       
   184      QVERIFY(mTest->mAlbumTrack.isNull() == true);
       
   185     }
       
   186 
       
   187 /*!
       
   188  Tests that link() returns NULL
       
   189  */
       
   190 void TestMpSongData::testLinkIsNull()
       
   191     {
       
   192      QVERIFY(mTest->mLink.isNull() == true);
       
   193     }
       
   194 
       
   195 /*!
       
   196  Tests that year() returns NULL
       
   197  */
       
   198 void TestMpSongData::testYearIsNull()
       
   199     {
       
   200      QVERIFY(mTest->mYear.isNull() == true);
       
   201     }
       
   202 
       
   203 /*!
       
   204  Tests that setTitle() returns TRUE
       
   205  */
       
   206 void TestMpSongData::testSetTitleTrue()
       
   207     {
       
   208     bool result;
       
   209     QString title("SomeTitle");
       
   210     result=mTest->setTitle( title );
       
   211     QCOMPARE(result, true);
       
   212      
       
   213     }
       
   214 
       
   215 /*!
       
   216  Tests that setTitle() returns FALSE
       
   217  */
       
   218 void TestMpSongData::testSetTitleFalse()
       
   219     {
       
   220     bool result;
       
   221     QString title(NULL);
       
   222     result=mTest->setTitle( title );
       
   223     QCOMPARE(result, false);
       
   224     }
       
   225 
       
   226 /*!
       
   227  Tests that setAlbum() returns TRUE
       
   228  */
       
   229 void TestMpSongData::testsetAlbumTrue()
       
   230     {
       
   231     bool result;
       
   232     QString album("Some");
       
   233     result=mTest->setAlbum(album);
       
   234     QCOMPARE(result, true);
       
   235      
       
   236     }
       
   237 
       
   238 /*!
       
   239  Tests that setAlbum() returns FALSE
       
   240  */
       
   241 void TestMpSongData::testsetAlbumFalse()
       
   242     {
       
   243     bool result;
       
   244     QString album(NULL);
       
   245     result=mTest->setAlbum( album );
       
   246     QCOMPARE(result, false);
       
   247     }
       
   248 
       
   249 
       
   250 /*!
       
   251  Tests that setArtist() returns TRUE
       
   252  */
       
   253 void TestMpSongData::testsetArtistTrue()
       
   254     {
       
   255     bool result;
       
   256     QString artist("SomeArtist");
       
   257     result=mTest->setArtist( artist );
       
   258     QCOMPARE(result, true);
       
   259      
       
   260     }
       
   261 
       
   262 /*!
       
   263  Tests that setArtist() returns FALSE
       
   264  */
       
   265 void TestMpSongData::testsetArtistFalse()
       
   266     {
       
   267     bool result;
       
   268     QString artist(NULL);
       
   269     result=mTest->setArtist( artist );
       
   270     QCOMPARE(result, false);
       
   271     }
       
   272 
       
   273 /*!
       
   274  Tests that setComment() returns TRUE
       
   275  */
       
   276 void TestMpSongData::testsetCommentTrue()
       
   277     {
       
   278     bool result;
       
   279     QString comment("SomeComment");
       
   280     result=mTest->setComment(comment);
       
   281     QCOMPARE(result, true);
       
   282      
       
   283     }
       
   284 
       
   285 /*!
       
   286  Tests that setComment() returns FALSE
       
   287  */
       
   288 void TestMpSongData::testsetCommentFalse()
       
   289     {
       
   290     bool result;
       
   291     QString comment(NULL);
       
   292     result=mTest->setComment(comment);
       
   293     QCOMPARE(result, false);
       
   294     }
       
   295 
       
   296 /*!
       
   297  Tests that setComposer() returns TRUE
       
   298  */
       
   299 void TestMpSongData::testsetComposerTrue()
       
   300     {
       
   301     bool result;
       
   302     QString composer("SomeComposer");
       
   303     result=mTest->setComposer(composer);
       
   304     QCOMPARE(result, true);
       
   305      
       
   306     }
       
   307 
       
   308 /*!
       
   309  Tests that setComposer() returns FALSE
       
   310  */
       
   311 void TestMpSongData::testsetComposerFalse()
       
   312     {
       
   313     bool result;
       
   314     QString composer(NULL);
       
   315     result=mTest->setComposer( composer );
       
   316     QCOMPARE(result, false);
       
   317     }
       
   318 
       
   319 /*!
       
   320  Tests that setGenre() returns TRUE
       
   321  */
       
   322 void TestMpSongData::testsetGenreTrue()
       
   323     {
       
   324     bool result;
       
   325     QString genre("SomeGenre");
       
   326     result=mTest->setGenre(genre);
       
   327     QCOMPARE(result, true);
       
   328      
       
   329     }
       
   330 
       
   331 /*!
       
   332  Tests that setGenre() returns FALSE
       
   333  */
       
   334 void TestMpSongData::testsetGenreFalse()
       
   335     {
       
   336     bool result;
       
   337     QString genre(NULL);
       
   338     result=mTest->setGenre( genre );
       
   339     QCOMPARE(result, false);
       
   340     }
       
   341 
       
   342 /*!
       
   343  Tests that setYear() returns TRUE
       
   344  */
       
   345 void TestMpSongData::testsetYearTrue()
       
   346     {
       
   347     bool result;
       
   348     int year = 2010;
       
   349     result=mTest->setYear(year);
       
   350     QCOMPARE(result, true);
       
   351      
       
   352     }
       
   353 
       
   354 /*!
       
   355  Tests that setYear() returns FALSE
       
   356  */
       
   357 void TestMpSongData::testsetYearFalse()
       
   358     {
       
   359     /*    
       
   360     TODO: Fix this
       
   361     bool result;
       
   362     int year(0);
       
   363     result=mTest->setYear( year );
       
   364     QCOMPARE(result, false);
       
   365     */
       
   366     }
       
   367 
       
   368 /*!
       
   369  Tests that setAlbumTrack() returns TRUE
       
   370  */
       
   371 void TestMpSongData::testsetAlbumTrackTrue()
       
   372     {
       
   373     bool result;
       
   374     QString albumTrack("SomeAlbumTrack");
       
   375     result=mTest->setAlbumTrack(albumTrack);
       
   376     QCOMPARE(result, true);
       
   377      
       
   378     }
       
   379 
       
   380 /*!
       
   381  Tests that setAlbumTrack() returns FALSE
       
   382  */
       
   383 void TestMpSongData::testsetAlbumTrackFalse()
       
   384     {
       
   385     bool result;
       
   386     QString albumTrack(NULL);
       
   387     result=mTest->setAlbumTrack( albumTrack );
       
   388     QCOMPARE(result, false);
       
   389     }
       
   390 
       
   391 /*!
       
   392  Tests setAlbumArtUri() 
       
   393  */
       
   394 void TestMpSongData::testsetAlbumArtUri() 
       
   395     {
       
   396     const QString albumArtUri("AlbumArt");
       
   397     const QString albumArtUriEmpty("");
       
   398     
       
   399     QSignalSpy spy( mTest, SIGNAL( albumArtReady() ) );
       
   400     
       
   401     QVERIFY( spy.isValid() );
       
   402     QCOMPARE( spy.count(), 0 );
       
   403     
       
   404     mTest->setAlbumArtUri(albumArtUri);
       
   405     QCOMPARE( spy.count(), 0 );
       
   406     
       
   407     mTest->mThumbnailManager->mGetThumbFails=true;
       
   408     mTest->setAlbumArtUri(albumArtUri);
       
   409     QCOMPARE( spy.count(), 1 );
       
   410     QCOMPARE(mTest->mAlbumArt, mTest->mDefaultAlbumArt);
       
   411     
       
   412     mTest->setAlbumArtUri(albumArtUriEmpty);
       
   413     QCOMPARE( spy.count(), 2 );
       
   414     QCOMPARE(mTest->mAlbumArt, mTest->mDefaultAlbumArt);
       
   415     
       
   416     }
       
   417 
       
   418 /*!
       
   419  Tests thumbnailReady()() 
       
   420  */
       
   421 void TestMpSongData::testThumbnailReady()
       
   422 {
       
   423    connect( this, SIGNAL(thumbnailReady(QPixmap, void *, int, int)),
       
   424            mTest->mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void *, int, int)) );    
       
   425 
       
   426    QSignalSpy spy(mTest, SIGNAL(albumArtReady()));
       
   427    QVERIFY( spy.isValid() );
       
   428    QCOMPARE( spy.count(), 0 );
       
   429    
       
   430    QPixmap dummyAlbumArt(":/playbackviewicons/someAlbumArt.png" );
       
   431    
       
   432    emit thumbnailReady(dummyAlbumArt, 0, -1, 0);
       
   433    QCOMPARE( spy.count(), 1 );
       
   434    QCOMPARE( mTest->mAlbumArt, dummyAlbumArt );
       
   435    
       
   436    emit thumbnailReady(dummyAlbumArt, 0, -1 , 1);
       
   437    QCOMPARE( spy.count(), 2 );
       
   438    QCOMPARE( mTest->mAlbumArt, mTest->mDefaultAlbumArt );
       
   439    
       
   440 }
       
   441 
       
   442 
       
   443 /*!
       
   444  Tests commitPlaybackInfo() 
       
   445  */
       
   446 void TestMpSongData::testCommitPlaybackInfo() 
       
   447     {
       
   448     QSignalSpy spy( mTest, SIGNAL( playbackInfoChanged() ) );
       
   449     
       
   450     QVERIFY( spy.isValid() );
       
   451     QCOMPARE( spy.count(), 0 );
       
   452     
       
   453     mTest->commitPlaybackInfo();
       
   454     QCOMPARE( spy.count(), 1 );
       
   455     
       
   456     }
       
   457 
       
   458 /*!
       
   459  Tests commitSongDetailInfo() 
       
   460  */
       
   461 void TestMpSongData::testCommitSongDetailInfo() 
       
   462     {
       
   463     QSignalSpy spy( mTest, SIGNAL( songDetailInfoChanged() ) );
       
   464     
       
   465     QVERIFY( spy.isValid() );
       
   466     QCOMPARE( spy.count(), 0 );
       
   467     
       
   468     mTest->commitSongDetailInfo();
       
   469     QCOMPARE( spy.count(), 1 );
       
   470     
       
   471     }