radioapp/radiouiengine/tsrc/src/t_radiostation.cpp
changeset 51 bbebb0235466
parent 47 74b7c6e79031
equal deleted inserted replaced
47:74b7c6e79031 51:bbebb0235466
    13 *
    13 *
    14 * Description: radiostation test implementation
    14 * Description: radiostation test implementation
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #define UNIT_TESTS_FOR_10_1
       
    19 #ifdef UNIT_TESTS_FOR_10_1
       
    20 #include <e32base.h>
    18 #include <e32base.h>
    21 #include <eikenv.h>
    19 #include <eikenv.h>
    22 #endif
       
    23 #include "t_radiostation.h"
    20 #include "t_radiostation.h"
    24 #include "radiopresetstorage.h"
    21 #include "radiopresetstorage.h"
    25 #include "radiostation.h"
    22 #include "radiostation.h"
    26 #include "radiostationmodel.h"
    23 #include "radiostationmodel.h"
    27 #include "radiohistorymodel.h"
    24 #include "radiohistorymodel.h"
    65  *
    62  *
    66  */
    63  */
    67 int main(int /* argc*/, char *argv[])
    64 int main(int /* argc*/, char *argv[])
    68 {
    65 {
    69     FUNC_LOG;
    66     FUNC_LOG;
    70     TestRadioUiEngine tv;
    67     TestRadioUiEngine* tv = new TestRadioUiEngine();
    71 
    68 
    72     char *pass[3];
    69     char *pass[3];
    73     pass[0] = argv[0];
    70     pass[0] = argv[0];
    74     pass[1] = "-o";
    71     pass[1] = "-o";
    75     pass[2] = "c:\\data\\testradiouiengine.txt";
    72     pass[2] = "c:\\data\\testradiouiengine.txt";
    76 
    73 
    77     int res = QTest::qExec(&tv, 3, pass);
    74     int res = QTest::qExec(tv, 3, pass);
    78 
    75 
       
    76     INFO_1( "Main, result value %i", res );
       
    77     delete tv;
    79     return res;
    78     return res;
    80 }
    79 }
    81 
    80 
    82 
    81 
    83 TestRadioUiEngine::TestRadioUiEngine()
    82 TestRadioUiEngine::TestRadioUiEngine()
   147  * Destructor
   146  * Destructor
   148  */
   147  */
   149 TestRadioUiEngine::~TestRadioUiEngine()
   148 TestRadioUiEngine::~TestRadioUiEngine()
   150 {
   149 {
   151     FUNC_LOG;
   150     FUNC_LOG;
   152 	delete mUiEngine;
   151     mEngineWrapper.reset( NULL );
       
   152     mPresetStorage.reset( NULL );
       
   153     delete mSchedulerTimer;
       
   154     delete mScheduler;
       
   155     RadioEngineUtils::Release();
   153 }
   156 }
   154 
   157 
   155 /*!
   158 /*!
   156  * called before each testfunction is executed
   159  * called before each testfunction is executed
   157  */
   160  */
   172  * called before the first testfunction is executed
   175  * called before the first testfunction is executed
   173  */
   176  */
   174 void TestRadioUiEngine::initTestCase()
   177 void TestRadioUiEngine::initTestCase()
   175 {
   178 {
   176     FUNC_LOG;
   179     FUNC_LOG;
   177 #ifdef UNIT_TESTS_FOR_10_1
   180     // Workaround for the below panic, occured after porting to 10.1 
   178 // Workaround for the below panic, occured after porting to 10.1 
   181     // Main Panic E32USER-CBase 44
   179 // Main Panic E32USER-CBase 44
   182     // Create and install the active scheduler
   180 // Create and install the active scheduler
   183     mScheduler = new(ELeave) CActiveScheduler;
   181     CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
   184     CActiveScheduler::Install( mScheduler );
   182     CleanupStack::PushL(scheduler);
   185     TInt err( KErrNone);
   183     CActiveScheduler::Install(scheduler);
   186     TRAP( err, mSchedulerTimer = CSchedulerStopAndStartTimer::NewL( *this ) );
   184 #endif 
   187     QVERIFY2(  KErrNone == err, "CSchedulerStopAndStartTimer not constructed!" );     
   185     RadioEngineUtils::InitializeL();
   188     mSchedulerTimer->StartTimer( 1000000, CSchedulerStopAndStartTimer::ETimerIdCreateMUT );
   186     mUiEngine = new RadioUiEngine;
   189 }
   187     mUiEngine->init();
   190 
   188     
   191 /*!
   189     mEngineWrapper.reset( new RadioEngineWrapper( mUiEngine->stationModel().stationHandlerIf() ) );
   192  * called after the last testfunction was executed
   190     mEngineWrapper->init();
   193  */
   191     mPresetStorage.reset( new RadioPresetStorage() );
   194 void TestRadioUiEngine::cleanupTestCase()
   192     mUiEngine->stationModel().initialize( mPresetStorage.data(), mEngineWrapper.data() );
   195 {
   193     
   196     FUNC_LOG;
   194     //TODO:: Check why ASSERT fails when mModel->rowCount() == 0 
   197     Radio::disconnect( &mUiEngine->stationModel(),  SIGNAL(dataChanged(const QModelIndex, const QModelIndex)),
   195     if(mUiEngine->stationModel().rowCount()>0)
       
   196     {
       
   197     	mUiEngine->stationModel().removeAll(); //ASSERT: \"last >= first\" in file qabstractitemmodel.cpp, line 2110	
       
   198     }    
       
   199 
       
   200     Radio::connect( &mUiEngine->stationModel(),  SIGNAL(dataChanged(const QModelIndex, const QModelIndex)),
       
   201         this,    SLOT(dataChanged(const QModelIndex, const QModelIndex)) );
   198         this,    SLOT(dataChanged(const QModelIndex, const QModelIndex)) );
   202     
   199     
   203     Radio::connect( &mUiEngine->stationModel(),           SIGNAL(stationDataChanged(RadioStation)),
   200     Radio::disconnect( &mUiEngine->stationModel(),           SIGNAL(stationDataChanged(RadioStation)),
   204         this,    SLOT(stationDataChanged(RadioStation)) );
   201         this,    SLOT(stationDataChanged(RadioStation)) );
   205     
   202     
   206     Radio::connect( &mUiEngine->stationModel(),           SIGNAL(favoriteChanged(RadioStation)),
   203     Radio::disconnect( &mUiEngine->stationModel(),           SIGNAL(favoriteChanged(RadioStation)),
   207         this,    SLOT(favoriteChanged(RadioStation)) );
   204         this,    SLOT(favoriteChanged(RadioStation)) );
   208     
   205     
   209     Radio::connect( &mUiEngine->historyModel(),           SIGNAL(itemAdded()),
   206     Radio::disconnect( &mUiEngine->historyModel(),           SIGNAL(itemAdded()),
   210         this,    SLOT(itemAdded()) );
   207         this,    SLOT(itemAdded()) );
   211 }
   208     mSchedulerTimer->StartTimer( 1000000, CSchedulerStopAndStartTimer::ETimerIdDeleteMUT );
   212 
       
   213 /*!
       
   214  * called after the last testfunction was executed
       
   215  */
       
   216 void TestRadioUiEngine::cleanupTestCase()
       
   217 {
       
   218     FUNC_LOG;
       
   219 	delete &mUiEngine->stationModel();
       
   220 	delete mUiEngine;
       
   221 }
   209 }
   222 
   210 
   223 /*!
   211 /*!
   224  * 
   212  * 
   225  */
   213  */
   923     FUNC_LOG;
   911     FUNC_LOG;
   924     //TODO:: Check why ASSERT fails when mUiEngine->historyModel().rowCount() == 0 
   912     //TODO:: Check why ASSERT fails when mUiEngine->historyModel().rowCount() == 0 
   925     if( mUiEngine->historyModel().rowCount()>0 )
   913     if( mUiEngine->historyModel().rowCount()>0 )
   926     {       
   914     {       
   927         mUiEngine->historyModel().removeAll( EFalse );
   915         mUiEngine->historyModel().removeAll( EFalse );
   928         QVERIFY2((mUiEngine->stationModel().rowCount()==0), "API:RadioHistoryModel removeAll() 1");
       
   929     }
   916     }
   930     QVERIFY2((mUiEngine->historyModel().rowCount()==0), "API:RadioHistoryModel removeAll() 2");           
   917     QVERIFY2((mUiEngine->historyModel().rowCount()==0), "API:RadioHistoryModel removeAll()");           
   931 }
   918 }
   932 
   919 
   933 /*!
   920 /*!
   934  *
   921  *
   935  */
   922  */
   949     QStringList stringList = mUiEngine->historyModel().data( index, Qt::DisplayRole ).value<QStringList>();        
   936     QStringList stringList = mUiEngine->historyModel().data( index, Qt::DisplayRole ).value<QStringList>();        
   950     QString artistTitle = stringList.at(0);    
   937     QString artistTitle = stringList.at(0);    
   951     QVERIFY2(!(artistTitle.compare(KTestArtist1+" - "+KTestTitle1)), "API:RadioHistoryModel addItem() 3");
   938     QVERIFY2(!(artistTitle.compare(KTestArtist1+" - "+KTestTitle1)), "API:RadioHistoryModel addItem() 3");
   952     
   939     
   953     
   940     
   954     expectedHistoryItemCount = mUiEngine->historyModel().rowCount();
   941     expectedHistoryItemCount = mUiEngine->historyModel().rowCount() + 1;
   955     // trying to add an item that allready exists must not increase the item count
   942     // trying to add an item that allready exists must increase the item count
   956     mUiEngine->historyModel().addItem( KTestArtist1, KTestTitle1, station );
   943     mUiEngine->historyModel().addItem( KTestArtist1, KTestTitle1, station );
       
   944     INFO_1( "mUiEngine->historyModel().rowCount()== %i", mUiEngine->historyModel().rowCount() );
   957     QVERIFY2((mUiEngine->historyModel().rowCount()==expectedHistoryItemCount), "API:RadioHistoryModel addItem() 4");
   945     QVERIFY2((mUiEngine->historyModel().rowCount()==expectedHistoryItemCount), "API:RadioHistoryModel addItem() 4");
   958 }
   946 }
   959 
   947 
   960 /*!
   948 /*!
   961  *
   949  *
   993     item->reset();
   981     item->reset();
   994     QVERIFY2(!item->isValid(), "API:testHistoryModelItem isValid() 2");
   982     QVERIFY2(!item->isValid(), "API:testHistoryModelItem isValid() 2");
   995     delete item;
   983     delete item;
   996     item = NULL;
   984     item = NULL;
   997 }
   985 }
       
   986 
       
   987 void TestRadioUiEngine::Timeout( TUint aTimerId )
       
   988     {
       
   989     FUNC_LOG;    
       
   990     if ( CSchedulerStopAndStartTimer::ETimerIdCreateMUT == aTimerId )
       
   991         {
       
   992         INFO("ETimerIdCreateMUT elapsed");
       
   993         }
       
   994     else if ( CSchedulerStopAndStartTimer::ETimerIdDeleteMUT == aTimerId )
       
   995         {
       
   996         INFO("ETimerIdDeleteMUT elapsed");
       
   997         }
       
   998     else if ( CSchedulerStopAndStartTimer::ETimerIdRunMUT == aTimerId )
       
   999         {
       
  1000         INFO("ETimerIdRunMUT elapsed");
       
  1001         }
       
  1002     else
       
  1003         {
       
  1004         INFO("Unknown timer elapsed");        
       
  1005         }
       
  1006     }
       
  1007 
       
  1008 void TestRadioUiEngine::CreateMUT()
       
  1009     {
       
  1010     FUNC_LOG;
       
  1011     RadioEngineUtils::InitializeL();
       
  1012     mUiEngine = new RadioUiEngine;
       
  1013     mUiEngine->init();
       
  1014     
       
  1015     mEngineWrapper.reset( new RadioEngineWrapper( mUiEngine->stationModel().stationHandlerIf() ) );
       
  1016     mEngineWrapper->init();
       
  1017     mPresetStorage.reset( new RadioPresetStorage() );
       
  1018     mUiEngine->stationModel().initialize( mPresetStorage.data(), mEngineWrapper.data() );
       
  1019     
       
  1020     //TODO:: Check why ASSERT fails when mModel->rowCount() == 0 
       
  1021     if(mUiEngine->stationModel().rowCount()>0)
       
  1022     {
       
  1023         mUiEngine->stationModel().removeAll(); //ASSERT: \"last >= first\" in file qabstractitemmodel.cpp, line 2110    
       
  1024     }    
       
  1025 
       
  1026     Radio::connect( &mUiEngine->stationModel(),  SIGNAL(dataChanged(const QModelIndex, const QModelIndex)),
       
  1027         this,    SLOT(dataChanged(const QModelIndex, const QModelIndex)) );
       
  1028     
       
  1029     Radio::connect( &mUiEngine->stationModel(),           SIGNAL(stationDataChanged(RadioStation)),
       
  1030         this,    SLOT(stationDataChanged(RadioStation)) );
       
  1031     
       
  1032     Radio::connect( &mUiEngine->stationModel(),           SIGNAL(favoriteChanged(RadioStation)),
       
  1033         this,    SLOT(favoriteChanged(RadioStation)) );
       
  1034     
       
  1035     Radio::connect( &mUiEngine->historyModel(),           SIGNAL(itemAdded()),
       
  1036         this,    SLOT(itemAdded()) );
       
  1037     mSchedulerTimer->StartTimer( 1000000, CSchedulerStopAndStartTimer::ETimerIdRunMUT );
       
  1038     }
       
  1039 
       
  1040 void TestRadioUiEngine::DeleteMUT()
       
  1041     {
       
  1042     FUNC_LOG;
       
  1043     if ( NULL != mUiEngine )
       
  1044         {
       
  1045         delete mUiEngine;
       
  1046         mUiEngine = NULL;        
       
  1047         }
       
  1048     }