radioapp/radiouiengine/tsrc/src/t_radiostation.cpp
changeset 16 f54ebcfc1b80
parent 13 46974bebc798
child 37 451b2e1545b2
equal deleted inserted replaced
14:63aabac4416d 16:f54ebcfc1b80
    22 #endif
    22 #endif
    23 #include "t_radiostation.h"
    23 #include "t_radiostation.h"
    24 #include "radiopresetstorage.h"
    24 #include "radiopresetstorage.h"
    25 #include "radiostation.h"
    25 #include "radiostation.h"
    26 #include "radiostationmodel.h"
    26 #include "radiostationmodel.h"
    27 #include "radioplaylogmodel.h"
    27 #include "radiohistorymodel.h"
    28 #include "radioenginewrapper.h"
    28 #include "radioenginewrapper.h"
    29 #include "radiouiengine.h"
    29 #include "radiouiengine.h"
    30 #include "radiologger.h" //connectAndTest
    30 #include "radiologger.h" //connectAndTest
    31 
    31 
    32 // Constants
    32 // Constants
   166 // CCoeEnv::Static() call in CRadioEngineTls returns NULL
   166 // CCoeEnv::Static() call in CRadioEngineTls returns NULL
   167     CCoeEnv* env = new CCoeEnv;
   167     CCoeEnv* env = new CCoeEnv;
   168 #endif 
   168 #endif 
   169     mUiEngine = new RadioUiEngine;
   169     mUiEngine = new RadioUiEngine;
   170     mRadioStationModel = new RadioStationModel( *mUiEngine );
   170     mRadioStationModel = new RadioStationModel( *mUiEngine );
   171     mPlayLogModel = new RadioPlayLogModel( *mUiEngine );
   171     mhistoryModel = new RadioHistoryModel( *mUiEngine );
   172     
   172     
   173     mEngineWrapper.reset( new RadioEngineWrapper( mRadioStationModel->stationHandlerIf(), *this ) );
   173     mEngineWrapper.reset( new RadioEngineWrapper( mRadioStationModel->stationHandlerIf(), *this ) );
   174     mPresetStorage.reset( new RadioPresetStorage() );
   174     mPresetStorage.reset( new RadioPresetStorage() );
   175     mRadioStationModel->initialize( mPresetStorage.data(), mEngineWrapper.data() );
   175     mRadioStationModel->initialize( mPresetStorage.data(), mEngineWrapper.data() );
   176     
   176     
   190         this,    SLOT(stationDataChanged(RadioStation)) );
   190         this,    SLOT(stationDataChanged(RadioStation)) );
   191     
   191     
   192     connectAndTest( mRadioStationModel,           SIGNAL(favoriteChanged(RadioStation)),
   192     connectAndTest( mRadioStationModel,           SIGNAL(favoriteChanged(RadioStation)),
   193         this,    SLOT(favoriteChanged(RadioStation)) );
   193         this,    SLOT(favoriteChanged(RadioStation)) );
   194     
   194     
   195     connectAndTest( mPlayLogModel,           SIGNAL(itemAdded()),
   195     connectAndTest( mhistoryModel,           SIGNAL(itemAdded()),
   196         this,    SLOT(itemAdded()) );
   196         this,    SLOT(itemAdded()) );
   197 }
   197 }
   198 
   198 
   199 /*!
   199 /*!
   200  * called after the last testfunction was executed
   200  * called after the last testfunction was executed
   871 	testSetFavorite();
   871 	testSetFavorite();
   872 	testRenameStation();
   872 	testRenameStation();
   873 	testSetRadioTextPlus();
   873 	testSetRadioTextPlus();
   874 }
   874 }
   875 /*!
   875 /*!
   876  * Test RadioPlayLogModel API
   876  * Test RadioHistoryModel API
   877  */
   877  */
   878 void TestRadioUiEngine::testPlayLogModel()
   878 void TestRadioUiEngine::testhistoryModel()
   879     {
   879     {
   880     testPlayLogModelInit();
   880     testHistoryModelInit();
   881     testPlayLogModelAddItem();
   881     testHistoryModelAddItem();
   882     testPlayLogModelFindItem();
   882     testHistoryModelFindItem();
   883     testPlayLogModelUpdateItem();
   883     testHistoryModelUpdateItem();
   884     testPlayLogModelSetData();
   884     testHistoryModelSetData();
   885     testAddRadioTextPlus();
   885     testAddRadioTextPlus();
   886     testClearRadioTextPlus();
   886     testClearRadioTextPlus();
   887     }
   887     }
   888 
   888 
   889 /*!
   889 /*!
   890  * Testing of RadioPlayLogModel initial state
   890  * Testing of RadioHistoryModel initial state
   891  */
   891  */
   892 void TestRadioUiEngine::testPlayLogModelInit()
   892 void TestRadioUiEngine::testHistoryModelInit()
   893 {
   893 {
   894     //TODO:: Check why ASSERT fails when mPlayLogModel->rowCount() == 0 
   894     //TODO:: Check why ASSERT fails when mhistoryModel->rowCount() == 0 
   895     if( mPlayLogModel->rowCount()>0 )
   895     if( mhistoryModel->rowCount()>0 )
   896     {       
   896     {       
   897         mPlayLogModel->removeAll();
   897         mhistoryModel->removeAll();
   898         QVERIFY2((mRadioStationModel->rowCount()==0), "API:RadioPlayLogModel removeAll() 1");
   898         QVERIFY2((mRadioStationModel->rowCount()==0), "API:RadioHistoryModel removeAll() 1");
   899     }
   899     }
   900     QVERIFY2((mPlayLogModel->rowCount()==0), "API:RadioPlayLogModel removeAll() 2");           
   900     QVERIFY2((mhistoryModel->rowCount()==0), "API:RadioHistoryModel removeAll() 2");           
   901 }
   901 }
   902 
   902 
   903 /*!
   903 /*!
   904  *
   904  *
   905  */
   905  */
   906 void TestRadioUiEngine::testPlayLogModelAddItem()
   906 void TestRadioUiEngine::testHistoryModelAddItem()
   907 {
   907 {
   908     int expectedPlayLogItemCount( mPlayLogModel->rowCount() + 1 );
   908     int expectedHistoryItemCount( mhistoryModel->rowCount() + 1 );
   909     mEnteredSlots = NoSlotsEntered;
   909     mEnteredSlots = NoSlotsEntered;
   910     mPlayLogModel->addItem( KTestArtist1, KTestTitle1 );    
   910     mhistoryModel->addItem( KTestArtist1, KTestTitle1 );    
   911     bool correctSignalsReceived = mEnteredSlots.testFlag( ItemAdded );
   911     bool correctSignalsReceived = mEnteredSlots.testFlag( ItemAdded );
   912     // check that correct signals received
   912     // check that correct signals received
   913     QVERIFY2(correctSignalsReceived, "API:RadioPlayLogModel addItem() 1");
   913     QVERIFY2(correctSignalsReceived, "API:RadioHistoryModel addItem() 1");
   914     // check that item count increases
   914     // check that item count increases
   915     QVERIFY2((mPlayLogModel->rowCount()==expectedPlayLogItemCount), "API:RadioPlayLogModel addItem() 2");
   915     QVERIFY2((mhistoryModel->rowCount()==expectedHistoryItemCount), "API:RadioHistoryModel addItem() 2");
   916     
   916     
   917     // check that artist/title stored into the model conforms to the one read from the model
   917     // check that artist/title stored into the model conforms to the one read from the model
   918     QModelIndex index = mPlayLogModel->index( 0, 0 );
   918     QModelIndex index = mhistoryModel->index( 0, 0 );
   919     QStringList stringList = mPlayLogModel->data( index, Qt::DisplayRole ).value<QStringList>();        
   919     QStringList stringList = mhistoryModel->data( index, Qt::DisplayRole ).value<QStringList>();        
   920     QString artistTitle = stringList.at(0);    
   920     QString artistTitle = stringList.at(0);    
   921     QVERIFY2(!(artistTitle.compare(KTestArtist1+" - "+KTestTitle1)), "API:RadioPlayLogModel addItem() 3");
   921     QVERIFY2(!(artistTitle.compare(KTestArtist1+" - "+KTestTitle1)), "API:RadioHistoryModel addItem() 3");
   922     
   922     
   923     
   923     
   924     expectedPlayLogItemCount = mPlayLogModel->rowCount();
   924     expectedHistoryItemCount = mhistoryModel->rowCount();
   925     // trying to add an item that allready exists must not increase the item count
   925     // trying to add an item that allready exists must not increase the item count
   926     mPlayLogModel->addItem( KTestArtist1, KTestTitle1 );
   926     mhistoryModel->addItem( KTestArtist1, KTestTitle1 );
   927     QVERIFY2((mPlayLogModel->rowCount()==expectedPlayLogItemCount), "API:RadioPlayLogModel addItem() 4");
   927     QVERIFY2((mhistoryModel->rowCount()==expectedHistoryItemCount), "API:RadioHistoryModel addItem() 4");
   928 }
   928 }
   929 
   929 
   930 /*!
   930 /*!
   931  *
   931  *
   932  */
   932  */
   933 void TestRadioUiEngine::testPlayLogModelFindItem()
   933 void TestRadioUiEngine::testHistoryModelFindItem()
   934 {
   934 {
   935     RadioPlayLogItem item;
   935     RadioHistoryItem item;
   936     mPlayLogModel->findItem( KTestArtist1, KTestTitle1, item );
   936     mhistoryModel->findItem( KTestArtist1, KTestTitle1, item );
   937     QVERIFY2((item.artist()==KTestArtist1), "API:RadioPlayLogModel findItem() 1");
   937     QVERIFY2((item.artist()==KTestArtist1), "API:RadioHistoryModel findItem() 1");
   938     QVERIFY2((item.title()==KTestTitle1), "API:RadioPlayLogModel findItem() 2");
   938     QVERIFY2((item.title()==KTestTitle1), "API:RadioHistoryModel findItem() 2");
   939     // try to find an item that doesn't exist
   939     // try to find an item that doesn't exist
   940     int ret = mPlayLogModel->findItem( KTestArtist1+"+", KTestTitle1, item );
   940     int ret = mhistoryModel->findItem( KTestArtist1+"+", KTestTitle1, item );
   941     QVERIFY2(ret==-1, "API:RadioPlayLogModel findItem() 3");
   941     QVERIFY2(ret==-1, "API:RadioHistoryModel findItem() 3");
   942 }
   942 }
   943 
   943 
   944 /*!
   944 /*!
   945  *
   945  *
   946  */
   946  */
   947 void TestRadioUiEngine::testPlayLogModelUpdateItem()
   947 void TestRadioUiEngine::testHistoryModelUpdateItem()
   948 {
   948 {
   949     RadioPlayLogItem item;    
   949     RadioHistoryItem item;    
   950     mPlayLogModel->findItem( KTestArtist1, KTestTitle1, item );
   950     mhistoryModel->findItem( KTestArtist1, KTestTitle1, item );
   951     item.setTitle( KTestTitle2 );    
   951     item.setTitle( KTestTitle2 );    
   952     // update an existing item
   952     // update an existing item
   953     mPlayLogModel->updateItem( 0, item, true );
   953     mhistoryModel->updateItem( 0, item, true );
   954     
   954     
   955     RadioPlayLogItem foundItem;
   955     RadioHistoryItem foundItem;
   956     // original item must not be found any more
   956     // original item must not be found any more
   957     int ret = mPlayLogModel->findItem(KTestArtist1, KTestTitle1, foundItem);
   957     int ret = mhistoryModel->findItem(KTestArtist1, KTestTitle1, foundItem);
   958     QVERIFY2(ret==-1, "API:RadioPlayLogModel updateItem() 1");
   958     QVERIFY2(ret==-1, "API:RadioHistoryModel updateItem() 1");
   959     // but the updated one instead
   959     // but the updated one instead
   960     mPlayLogModel->findItem(KTestArtist1, KTestTitle2, foundItem);
   960     mhistoryModel->findItem(KTestArtist1, KTestTitle2, foundItem);
   961     QVERIFY2((foundItem.title()==KTestTitle2), "API:RadioPlayLogModel updateItem() 2"); 
   961     QVERIFY2((foundItem.title()==KTestTitle2), "API:RadioHistoryModel updateItem() 2"); 
   962 }
   962 }
   963 
   963 
   964 /*!
   964 /*!
   965  *
   965  *
   966  */
   966  */
   967 void TestRadioUiEngine::testPlayLogModelSetData()
   967 void TestRadioUiEngine::testHistoryModelSetData()
   968 {
   968 {
   969    RadioPlayLogItem foundItem;
   969    RadioHistoryItem foundItem;
   970    mPlayLogModel->findItem(KTestArtist1, KTestTitle2, foundItem);
   970    mhistoryModel->findItem(KTestArtist1, KTestTitle2, foundItem);
   971    QVERIFY2(!foundItem.isFavorite(), "API:RadioPlayLogModel SetData() 1");
   971    QVERIFY2(!foundItem.isFavorite(), "API:RadioHistoryModel SetData() 1");
   972    
   972    
   973    QModelIndex index = mPlayLogModel->index( 0, 0 );
   973    QModelIndex index = mhistoryModel->index( 0, 0 );
   974    QString artistTitle = KTestArtist1 + KTestTitle2;
   974    QString artistTitle = KTestArtist1 + KTestTitle2;
   975    mPlayLogModel->setData( index, artistTitle, RadioPlayLogModel::SetFavoriteRole );
   975    mhistoryModel->setData( index, artistTitle, RadioHistoryModel::SetFavoriteRole );
   976    mPlayLogModel->findItem(KTestArtist1, KTestTitle2, foundItem);
   976    mhistoryModel->findItem(KTestArtist1, KTestTitle2, foundItem);
   977    // item should be now favorite
   977    // item should be now favorite
   978    QVERIFY2(foundItem.isFavorite(), "API:RadioPlayLogModel SetData() 2");    
   978    QVERIFY2(foundItem.isFavorite(), "API:RadioHistoryModel SetData() 2");    
   979 }
   979 }
   980 
   980 
   981 /*!
   981 /*!
   982  *
   982  *
   983  */
   983  */
   984 void TestRadioUiEngine::testAddRadioTextPlus()
   984 void TestRadioUiEngine::testAddRadioTextPlus()
   985 {   
   985 {   
   986     mPlayLogModel->addRadioTextPlus( RtPlus::Artist, KTestArtist1 );
   986     mhistoryModel->addRadioTextPlus( RtPlus::Artist, KTestArtist1 );
   987     mPlayLogModel->addRadioTextPlus( RtPlus::Title, KTestTitle1 );
   987     mhistoryModel->addRadioTextPlus( RtPlus::Title, KTestTitle1 );
   988 }
   988 }
   989 
   989 
   990 /*!
   990 /*!
   991  *
   991  *
   992  */
   992  */
   993 void TestRadioUiEngine::testClearRadioTextPlus()
   993 void TestRadioUiEngine::testClearRadioTextPlus()
   994 {   
   994 {   
   995     mPlayLogModel->clearRadioTextPlus();
   995     mhistoryModel->clearRadioTextPlus();
   996 }
   996 }
   997 
   997 
   998 /*!
   998 /*!
   999  * Test RadioPlayLogModelItem API
   999  * Test RadioHistoryModelItem API
  1000  */
  1000  */
  1001 void TestRadioUiEngine::testPlayLogModelItem()
  1001 void TestRadioUiEngine::testHistoryModelItem()
  1002 {
  1002 {
  1003     RadioPlayLogItem* item = new RadioPlayLogItem( KTestArtist3, KTestTitle3 );
  1003     RadioHistoryItem* item = new RadioHistoryItem( KTestArtist3, KTestTitle3 );
  1004     item->setArtist( KTestArtist3 );
  1004     item->setArtist( KTestArtist3 );
  1005     QVERIFY2(!(item->artist().compare(KTestArtist3)), "API:testPlayLogModelItem setArtist()");
  1005     QVERIFY2(!(item->artist().compare(KTestArtist3)), "API:testHistoryModelItem setArtist()");
  1006     item->setTitle( KTestTitle3 );
  1006     item->setTitle( KTestTitle3 );
  1007     QVERIFY2(!(item->title().compare(KTestTitle3)), "API:testPlayLogModelItem setTitle()");
  1007     QVERIFY2(!(item->title().compare(KTestTitle3)), "API:testHistoryModelItem setTitle()");
  1008     QVERIFY2(!item->isFavorite(), "API:testPlayLogModelItem isFavorite() 1");
  1008     QVERIFY2(!item->isFavorite(), "API:testHistoryModelItem isFavorite() 1");
  1009     item->setFavorite();
  1009     item->setFavorite();
  1010     QVERIFY2(item->isFavorite(), "API:testPlayLogModelItem isFavorite() 2");
  1010     QVERIFY2(item->isFavorite(), "API:testHistoryModelItem isFavorite() 2");
  1011     item->setFavorite();
  1011     item->setFavorite();
  1012     delete item;
  1012     delete item;
  1013     item = NULL;
  1013     item = NULL;
  1014 }
  1014 }