radioapp/radiouiengine/tsrc/src/t_radiostation.cpp
changeset 50 c44f9bb56771
parent 28 075425b8d9a4
child 51 bbebb0235466
equal deleted inserted replaced
48:e14766a36cdc 50:c44f9bb56771
    25 #include "radiostation.h"
    25 #include "radiostation.h"
    26 #include "radiostationmodel.h"
    26 #include "radiostationmodel.h"
    27 #include "radiohistorymodel.h"
    27 #include "radiohistorymodel.h"
    28 #include "radioenginewrapper.h"
    28 #include "radioenginewrapper.h"
    29 #include "radiouiengine.h"
    29 #include "radiouiengine.h"
       
    30 #include "radioengineutils.h"
    30 #include "radiologger.h" //Radio::connect
    31 #include "radiologger.h" //Radio::connect
       
    32 #include "trace.h"
    31 
    33 
    32 // Constants
    34 // Constants
    33 const uint KTestFrequency1 = 89000000;
    35 const uint KTestFrequency1 = 89000000;
    34 const uint KTestFrequency2 = 89500000;
    36 const uint KTestFrequency2 = 89500000;
    35 const uint KTestFrequency3 = 90000000;
    37 const uint KTestFrequency3 = 90000000;
    62 /*!
    64 /*!
    63  *
    65  *
    64  */
    66  */
    65 int main(int /* argc*/, char *argv[])
    67 int main(int /* argc*/, char *argv[])
    66 {
    68 {
       
    69     FUNC_LOG;
    67     TestRadioUiEngine tv;
    70     TestRadioUiEngine tv;
    68 
    71 
    69     char *pass[3];
    72     char *pass[3];
    70     pass[0] = argv[0];
    73     pass[0] = argv[0];
    71     pass[1] = "-o";
    74     pass[1] = "-o";
    77 }
    80 }
    78 
    81 
    79 
    82 
    80 TestRadioUiEngine::TestRadioUiEngine()
    83 TestRadioUiEngine::TestRadioUiEngine()
    81 {
    84 {
       
    85     FUNC_LOG;
    82 }
    86 }
    83 
    87 
    84 
    88 
    85 void TestRadioUiEngine::tunedToFrequency( uint /* frequency */, int /* commandSender */)
    89 void TestRadioUiEngine::tunedToFrequency( uint /* frequency */, int /* commandSender */)
    86 {
    90 {
    87 }
    91     FUNC_LOG;
    88 
    92 }
    89 
    93 
    90 void TestRadioUiEngine::seekingStarted( Seeking::Direction /* direction */)
    94 
    91 {
    95 void TestRadioUiEngine::seekingStarted( Seek::Direction /* direction */)
       
    96 {
       
    97     FUNC_LOG;
    92 }
    98 }
    93     
    99     
    94 void TestRadioUiEngine::radioStatusChanged( bool /* radioIsOn */)
   100 void TestRadioUiEngine::radioStatusChanged( bool /* radioIsOn */)
    95 {
   101 {
       
   102     FUNC_LOG;
    96 }
   103 }
    97     
   104     
    98 void TestRadioUiEngine::rdsAvailabilityChanged( bool /* available */)
   105 void TestRadioUiEngine::rdsAvailabilityChanged( bool /* available */)
    99 {
   106 {
       
   107     FUNC_LOG;
   100 }
   108 }
   101     
   109     
   102 void TestRadioUiEngine::volumeChanged( int /* volume */)
   110 void TestRadioUiEngine::volumeChanged( int /* volume */)
   103 {
   111 {
       
   112     FUNC_LOG;
   104 }
   113 }
   105     
   114     
   106 void TestRadioUiEngine::muteChanged( bool /* muted */)
   115 void TestRadioUiEngine::muteChanged( bool /* muted */)
   107 {
   116 {
       
   117     FUNC_LOG;
   108 }
   118 }
   109 
   119 
   110 void TestRadioUiEngine::audioRouteChanged( bool /* loudspeaker */)
   120 void TestRadioUiEngine::audioRouteChanged( bool /* loudspeaker */)
   111 {
   121 {
       
   122     FUNC_LOG;
   112 }
   123 }
   113 
   124 
   114 void TestRadioUiEngine::scanAndSaveFinished()
   125 void TestRadioUiEngine::scanAndSaveFinished()
   115 {
   126 {
       
   127     FUNC_LOG;
   116 }
   128 }
   117 
   129 
   118     
   130     
   119 void TestRadioUiEngine::headsetStatusChanged( bool /* connected */)
   131 void TestRadioUiEngine::headsetStatusChanged( bool /* connected */)
   120 {
   132 {
       
   133     FUNC_LOG;
   121 }
   134 }
   122         
   135         
   123 void TestRadioUiEngine::skipPrevious()
   136 void TestRadioUiEngine::skipPrevious()
   124 {
   137 {
       
   138     FUNC_LOG;
   125 }
   139 }
   126     
   140     
   127 void TestRadioUiEngine::skipNext()
   141 void TestRadioUiEngine::skipNext()
   128 {
   142 {
       
   143     FUNC_LOG;
   129 }
   144 }
   130 
   145 
   131 /*!
   146 /*!
   132  * Destructor
   147  * Destructor
   133  */
   148  */
   134 TestRadioUiEngine::~TestRadioUiEngine()
   149 TestRadioUiEngine::~TestRadioUiEngine()
   135 {
   150 {
   136 	delete mRadioStationModel;	
   151     FUNC_LOG;
   137 	delete mUiEngine;
   152 	delete mUiEngine;
   138 }
   153 }
   139 
   154 
   140 /*!
   155 /*!
   141  * called before each testfunction is executed
   156  * called before each testfunction is executed
   142  */
   157  */
   143 void TestRadioUiEngine::init()
   158 void TestRadioUiEngine::init()
   144 {
   159 {
       
   160     FUNC_LOG;
   145 }
   161 }
   146 
   162 
   147 /*!
   163 /*!
   148  * called after every testfunction
   164  * called after every testfunction
   149  */
   165  */
   150 void TestRadioUiEngine::cleanup()
   166 void TestRadioUiEngine::cleanup()
   151 {
   167 {
       
   168     FUNC_LOG;
   152 }
   169 }
   153 
   170 
   154 /*!
   171 /*!
   155  * called before the first testfunction is executed
   172  * called before the first testfunction is executed
   156  */
   173  */
   157 void TestRadioUiEngine::initTestCase()
   174 void TestRadioUiEngine::initTestCase()
   158 {
   175 {
       
   176     FUNC_LOG;
   159 #ifdef UNIT_TESTS_FOR_10_1
   177 #ifdef UNIT_TESTS_FOR_10_1
   160 // Workaround for the below panic, occured after porting to 10.1 
   178 // Workaround for the below panic, occured after porting to 10.1 
   161 // Main Panic E32USER-CBase 44
   179 // Main Panic E32USER-CBase 44
   162 // Create and install the active scheduler
   180 // Create and install the active scheduler
   163     CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
   181     CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
   164     CleanupStack::PushL(scheduler);
   182     CleanupStack::PushL(scheduler);
   165     CActiveScheduler::Install(scheduler);
   183     CActiveScheduler::Install(scheduler);
   166 // CCoeEnv::Static() call in CRadioEngineTls returns NULL
       
   167     CCoeEnv* env = new CCoeEnv;
       
   168 #endif 
   184 #endif 
       
   185     RadioEngineUtils::InitializeL();
   169     mUiEngine = new RadioUiEngine;
   186     mUiEngine = new RadioUiEngine;
   170     mRadioStationModel = new RadioStationModel( *mUiEngine );
   187     mUiEngine->init();
   171     mhistoryModel = new RadioHistoryModel( *mUiEngine );
   188     
   172     
   189     mEngineWrapper.reset( new RadioEngineWrapper( mUiEngine->stationModel().stationHandlerIf() ) );
   173     mEngineWrapper.reset( new RadioEngineWrapper( mRadioStationModel->stationHandlerIf(), *this ) );
   190     mEngineWrapper->init();
   174     mPresetStorage.reset( new RadioPresetStorage() );
   191     mPresetStorage.reset( new RadioPresetStorage() );
   175     mRadioStationModel->initialize( mPresetStorage.data(), mEngineWrapper.data() );
   192     mUiEngine->stationModel().initialize( mPresetStorage.data(), mEngineWrapper.data() );
   176     
   193     
   177     //TODO:: Check why ASSERT fails when mModel->rowCount() == 0 
   194     //TODO:: Check why ASSERT fails when mModel->rowCount() == 0 
   178     if(mRadioStationModel->rowCount()>0)
   195     if(mUiEngine->stationModel().rowCount()>0)
   179     {
   196     {
   180     	mRadioStationModel->removeAll(); //ASSERT: \"last >= first\" in file qabstractitemmodel.cpp, line 2110	
   197     	mUiEngine->stationModel().removeAll(); //ASSERT: \"last >= first\" in file qabstractitemmodel.cpp, line 2110	
   181     }    
   198     }    
   182 
   199 
   183     Radio::connect( mRadioStationModel,  SIGNAL(dataChanged(const QModelIndex, const QModelIndex)),
   200     Radio::connect( &mUiEngine->stationModel(),  SIGNAL(dataChanged(const QModelIndex, const QModelIndex)),
   184         this,    SLOT(dataChanged(const QModelIndex, const QModelIndex)) );
   201         this,    SLOT(dataChanged(const QModelIndex, const QModelIndex)) );
   185     
   202     
   186     Radio::connect( mRadioStationModel,           SIGNAL(stationAdded(RadioStation)),
   203     Radio::connect( &mUiEngine->stationModel(),           SIGNAL(stationDataChanged(RadioStation)),
   187         this,    SLOT(stationAdded(RadioStation)) );
       
   188     
       
   189     Radio::connect( mRadioStationModel,           SIGNAL(stationDataChanged(RadioStation)),
       
   190         this,    SLOT(stationDataChanged(RadioStation)) );
   204         this,    SLOT(stationDataChanged(RadioStation)) );
   191     
   205     
   192     Radio::connect( mRadioStationModel,           SIGNAL(favoriteChanged(RadioStation)),
   206     Radio::connect( &mUiEngine->stationModel(),           SIGNAL(favoriteChanged(RadioStation)),
   193         this,    SLOT(favoriteChanged(RadioStation)) );
   207         this,    SLOT(favoriteChanged(RadioStation)) );
   194     
   208     
   195     Radio::connect( mhistoryModel,           SIGNAL(itemAdded()),
   209     Radio::connect( &mUiEngine->historyModel(),           SIGNAL(itemAdded()),
   196         this,    SLOT(itemAdded()) );
   210         this,    SLOT(itemAdded()) );
   197 }
   211 }
   198 
   212 
   199 /*!
   213 /*!
   200  * called after the last testfunction was executed
   214  * called after the last testfunction was executed
   201  */
   215  */
   202 void TestRadioUiEngine::cleanupTestCase()
   216 void TestRadioUiEngine::cleanupTestCase()
   203 {
   217 {
   204 	delete mRadioStationModel;
   218     FUNC_LOG;
       
   219 	delete &mUiEngine->stationModel();
   205 	delete mUiEngine;
   220 	delete mUiEngine;
   206 }
   221 }
   207 
   222 
   208 /*!
   223 /*!
   209  * 
   224  * 
   210  */
   225  */
   211 void TestRadioUiEngine::dataChanged(const QModelIndex /* topLeft */, const QModelIndex /* bottomRight */)
   226 void TestRadioUiEngine::dataChanged(const QModelIndex /* topLeft */, const QModelIndex /* bottomRight */)
   212 {
   227 {
       
   228     FUNC_LOG;
   213 	mEnteredSlots |= DataChanged;
   229 	mEnteredSlots |= DataChanged;
   214 }
   230 }
   215 
   231 
   216 /*!
   232 /*!
   217  * 
   233  * 
   218  */
   234  */
   219 void TestRadioUiEngine::stationDataChanged( RadioStation /* addedStation */ )
   235 void TestRadioUiEngine::stationDataChanged( RadioStation /* addedStation */ )
   220 {
   236 {
       
   237     FUNC_LOG;
   221 	mEnteredSlots |= StationDataChanged;	
   238 	mEnteredSlots |= StationDataChanged;	
   222 }
   239 }
   223 
   240 
   224 /*!
   241 /*!
   225  * 
   242  * 
   226  */
   243  */
   227 void TestRadioUiEngine::favoriteChanged( RadioStation /* addedStation */)
   244 void TestRadioUiEngine::favoriteChanged( RadioStation /* addedStation */)
   228 {
   245 {
       
   246     FUNC_LOG;
   229 	mEnteredSlots |= FavoriteChanged;
   247 	mEnteredSlots |= FavoriteChanged;
   230 }
   248 }
   231 
   249 
   232 /*!
   250 /*!
   233  * 
   251  * 
   234  */
   252  */
   235 void TestRadioUiEngine::itemAdded()
   253 void TestRadioUiEngine::itemAdded()
   236 {
   254 {
       
   255     FUNC_LOG;
   237     mEnteredSlots |= ItemAdded;
   256     mEnteredSlots |= ItemAdded;
   238 }
       
   239 
       
   240 /*!
       
   241  * 
       
   242  */
       
   243 void TestRadioUiEngine::stationAdded( RadioStation addedStation )
       
   244 {
       
   245 	mEnteredSlots |= StationAdded;
       
   246 	
       
   247 	QVERIFY2(( mStationToBeAdded == addedStation.name() ), "API:RadioStationModel stationAdded 1");
       
   248 	QVERIFY2(( mExpectedStationCount == mRadioStationModel->rowCount() ), "API:RadioStationModel stationAdded 2");	
       
   249 }
   257 }
   250 
   258 
   251 
   259 
   252 /*!
   260 /*!
   253  * Testing of implicit sharing a.k.a. copy-on-write
   261  * Testing of implicit sharing a.k.a. copy-on-write
   254  */
   262  */
   255 void TestRadioUiEngine::testImplicitSharing()
   263 void TestRadioUiEngine::testImplicitSharing()
   256 {	
   264 {	
       
   265     FUNC_LOG;
   257 	RadioStation t_RadioStation_1;
   266 	RadioStation t_RadioStation_1;
   258 	
   267 	
   259 	int originalPresetIndex = t_RadioStation_1.presetIndex();
   268 	int originalPresetIndex = t_RadioStation_1.presetIndex();
   260 	// before any values assigned into any data field
   269 	// before any values assigned into any data field
   261 	QVERIFY2(( originalPresetIndex == RadioStation::SharedNull ), "API:Radiostation init failed 1");
   270 	QVERIFY2(( originalPresetIndex == RadioStation::SharedNull ), "API:Radiostation init failed 1");
   332 /*!
   341 /*!
   333  * Testing of change flags set by RadioStation class
   342  * Testing of change flags set by RadioStation class
   334  */
   343  */
   335 void TestRadioUiEngine::testChangeFlags()
   344 void TestRadioUiEngine::testChangeFlags()
   336 {
   345 {
       
   346     FUNC_LOG;
   337 	RadioStation t_RadioStation;
   347 	RadioStation t_RadioStation;
   338 		
   348 		
   339     QVERIFY2(!t_RadioStation.isValid(), "API:Radiostation Init failure");
   349     QVERIFY2(!t_RadioStation.isValid(), "API:Radiostation Init failure");
   340     t_RadioStation.setUserDefinedName("");
   350     t_RadioStation.setUserDefinedName("");
   341 	t_RadioStation.setUserDefinedName("Radio Noice");
   351 	t_RadioStation.setUserDefinedName("Radio Noice");
   415 /*!
   425 /*!
   416  * Testing of call sign integer to char conversion
   426  * Testing of call sign integer to char conversion
   417  */
   427  */
   418 void TestRadioUiEngine::TestCallSignChar()
   428 void TestRadioUiEngine::TestCallSignChar()
   419 {
   429 {
       
   430     FUNC_LOG;
       
   431     /*
   420 	for(uint i = 0; i < KLastCallSignCharCode; i++)
   432 	for(uint i = 0; i < KLastCallSignCharCode; i++)
   421 	{
   433 	{
   422 	    RadioStation t_RadioStation;
   434 	    RadioStation t_RadioStation;
   423 	    bool passed =  t_RadioStation.callSignChar(i) == static_cast<char>( 'A' + i ); 	    	
   435 	    bool passed =  t_RadioStation.callSignChar(i) == static_cast<char>( 'A' + i ); 	    	
   424 	    QVERIFY2(passed, "API:Radiostation TestCallSignChar 1");	
   436 	    QVERIFY2(passed, "API:Radiostation TestCallSignChar 1");	
   425 	}
   437 	}
   426 	RadioStation t_RadioStation;
   438 	RadioStation t_RadioStation;
   427 	bool passed = t_RadioStation.callSignChar(KLastCallSignCharCode + 1) == static_cast<char>( '?' );
   439 	bool passed = t_RadioStation.callSignChar(KLastCallSignCharCode + 1) == static_cast<char>( '?' );
   428 	QVERIFY2(passed, "API:Radiostation TestCallSignChar 2");
   440 	QVERIFY2(passed, "API:Radiostation TestCallSignChar 2");
       
   441 	*/
   429 }
   442 }
   430 
   443 
   431 /*!
   444 /*!
   432  * Testing of PI code to call sign conversion
   445  * Testing of PI code to call sign conversion
   433  */
   446  */
   434 void TestRadioUiEngine::testPICodeToCallSign()
   447 void TestRadioUiEngine::testPICodeToCallSign()
   435 {
   448 {
   436 	RadioStation t_RadioStation;
   449     FUNC_LOG;
       
   450 	/*
       
   451     RadioStation t_RadioStation;
   437 	
   452 	
   438 	// boundary values, two typical values and three chars call sign case
   453 	// boundary values, two typical values and three chars call sign case
   439 	QString callSign = t_RadioStation.piCodeToCallSign( KKxxxCallSignPiFirst - 1 );
   454 	QString callSign = t_RadioStation.piCodeToCallSign( KKxxxCallSignPiFirst - 1 );
   440 	QVERIFY2((callSign==""), "API:Radiostation Call sign <");
   455 	QVERIFY2((callSign==""), "API:Radiostation Call sign <");
   441 	callSign = t_RadioStation.piCodeToCallSign( KKxxxCallSignPiFirst );
   456 	callSign = t_RadioStation.piCodeToCallSign( KKxxxCallSignPiFirst );
   454     QVERIFY2((callSign=="KEX"), "API:Radiostation Call sign KEX");
   469     QVERIFY2((callSign=="KEX"), "API:Radiostation Call sign KEX");
   455     callSign = t_RadioStation.piCodeToCallSign( 0x99B5 );
   470     callSign = t_RadioStation.piCodeToCallSign( 0x99B5 );
   456     QVERIFY2((callSign=="WJZ"), "API:Radiostation Call sign WJZ");    
   471     QVERIFY2((callSign=="WJZ"), "API:Radiostation Call sign WJZ");    
   457     callSign = t_RadioStation.piCodeToCallSign( 0x99C0 );
   472     callSign = t_RadioStation.piCodeToCallSign( 0x99C0 );
   458     QVERIFY2((callSign==""), "API:Radiostation Call sign ????");
   473     QVERIFY2((callSign==""), "API:Radiostation Call sign ????");
       
   474     */
   459 }
   475 }
   460 
   476 
   461 /*!
   477 /*!
   462  * Testing of RadioStationModel initial state
   478  * Testing of RadioStationModel initial state
   463  */
   479  */
   464 void TestRadioUiEngine::testRadioStationModelInit()
   480 void TestRadioUiEngine::testRadioStationModelInit()
   465 {
   481 {
       
   482     FUNC_LOG;
   466 	//TODO:: Check why ASSERT fails when mModel->rowCount() == 0 
   483 	//TODO:: Check why ASSERT fails when mModel->rowCount() == 0 
   467 	if( mRadioStationModel->rowCount()>0 )
   484 	if( mUiEngine->stationModel().rowCount()>0 )
   468     {	    
   485     {	    
   469 		mRadioStationModel->removeAll();
   486 		mUiEngine->stationModel().removeAll();
   470 		QVERIFY2((mRadioStationModel->rowCount()==0), "API:RadioStationModel removeAll()");
   487 		QVERIFY2((mUiEngine->stationModel().rowCount()==0), "API:RadioStationModel removeAll()");
   471 	}
   488 	}
   472 		 
   489 		 
   473 	RadioStation foundStation;
   490 	RadioStation foundStation;
   474 	// no stations in the model in this phase
   491 	// no stations in the model in this phase
   475 	QVERIFY2(!(mRadioStationModel->findFrequency( KTestFrequency1, foundStation )), 
   492 	QVERIFY2(!(mUiEngine->stationModel().findFrequency( KTestFrequency1, foundStation )), 
   476 		"API:RadioStationModel findFrequency 1");	
   493 		"API:RadioStationModel findFrequency 1");	
   477 }
   494 }
   478 
   495 
   479 /*!
   496 /*!
   480  * Testing of RadioStationModel addStation method and resulting RadioStationModel signals
   497  * Testing of RadioStationModel addStation method and resulting RadioStationModel signals
   481  */
   498  */
   482 void TestRadioUiEngine::testAddStation1()
   499 void TestRadioUiEngine::testAddStation1()
   483 {
   500 {
       
   501     FUNC_LOG;
   484 	RadioStation station;
   502 	RadioStation station;
   485 	station.setFrequency( KTestFrequency1 );
   503 	station.setFrequency( KTestFrequency1 );
   486 	station.setFrequency( KTestFrequency1 );
   504 	station.setFrequency( KTestFrequency1 );
   487 	station.setGenre( KTestGenre1 );
   505 	station.setGenre( KTestGenre1 );
   488 	station.setGenre( KTestGenre1 );
   506 	station.setGenre( KTestGenre1 );
   494 	station.setDynamicPsText( KTestDynamicPSText );
   512 	station.setDynamicPsText( KTestDynamicPSText );
   495 	station.setPiCode( 0xC004, RadioRegion::America ); //88.1 CBEE-FM - Chatham, ON
   513 	station.setPiCode( 0xC004, RadioRegion::America ); //88.1 CBEE-FM - Chatham, ON
   496     QVERIFY2(!(station.dynamicPsText().compare(KTestDynamicPSText)), "API:RadioStationModel addStation 1");
   514     QVERIFY2(!(station.dynamicPsText().compare(KTestDynamicPSText)), "API:RadioStationModel addStation 1");
   497     station.setDynamicPsText( KTestDynamicPSText );
   515     station.setDynamicPsText( KTestDynamicPSText );
   498 	// check that adding station increases model row count
   516 	// check that adding station increases model row count
   499 	mExpectedStationCount = mRadioStationModel->rowCount() + 1;	
   517 	mExpectedStationCount = mUiEngine->stationModel().rowCount() + 1;	
   500 	mStationToBeAdded = station.name();
   518 	mStationToBeAdded = station.name();
   501 	mRadioStationModel->addStation( station );
   519 	mUiEngine->stationModel().addStation( station );
   502 	QVERIFY2((mRadioStationModel->rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 2");
   520 	QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 2");
   503 	bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && 
   521 	bool correctSignalsReceived = mEnteredSlots.testFlag( DataChanged );
   504 	    mEnteredSlots.testFlag( StationAdded ) && mEnteredSlots.testFlag( DataChanged );
   522 	
   505 	
   523 	bool frequencyUpdated = station.frequency() == KTestFrequency1;
   506 	bool frequencyUpdated = station.frequencyMhz().toDouble()*1000000 == KTestFrequency1;
       
   507 	QVERIFY2(frequencyUpdated, "API:RadioStationModel addStation 1");
   524 	QVERIFY2(frequencyUpdated, "API:RadioStationModel addStation 1");
   508 	// check that correct signals received
   525 	// check that correct signals received
   509 	QVERIFY2(correctSignalsReceived, "API:RadioStationModel addStation 3");
   526 	QVERIFY2(correctSignalsReceived, "API:RadioStationModel addStation 3");
   510 	mEnteredSlots = NoSlotsEntered;
   527 	mEnteredSlots = NoSlotsEntered;
   511 	
   528 	
   512 	// check that added station can be found by frequency
   529 	// check that added station can be found by frequency
   513     QModelIndex index = mRadioStationModel->modelIndexFromFrequency( KTestFrequency1 );
   530     int index( KErrNotFound );
   514     QVariant stationData = mRadioStationModel->data( index, Qt::DisplayRole );
   531     index = mUiEngine->stationModel().indexFromFrequency( KTestFrequency1 );
   515     QString stationName = stationData.toString().right( KTestStationName1.length() );    
   532     QVERIFY2(index != KErrNotFound, "Added station not found from model!");
   516     QVERIFY2(!(stationName.compare(KTestStationName1)), "API:RadioStationModel modelIndexFromFrequency");
   533     
       
   534     RadioStation readStation ( mUiEngine->stationModel().stationAt( index ) );    
       
   535     QVERIFY2( !readStation.name().compare(KTestStationName1), "Added station's name not found from model!");
   517 }
   536 }
   518 
   537 
   519 /*!
   538 /*!
   520  * Testing of RadioStationModel saveStation method and resulting RadioStationModel signals
   539  * Testing of RadioStationModel saveStation method and resulting RadioStationModel signals
   521  */
   540  */
   522 void TestRadioUiEngine::testSaveStation1()
   541 void TestRadioUiEngine::testSaveStation1()
   523 {
   542 {
       
   543     FUNC_LOG;
   524 	RadioStation newStation1;
   544 	RadioStation newStation1;
   525     // check that find by frequency works
   545     // check that find by frequency works
   526     // this is needed for preset index to be updated into newStation1
   546     // this is needed for preset index to be updated into newStation1
   527     QVERIFY2((mRadioStationModel->findFrequency( KTestFrequency1, newStation1 )), 
   547     QVERIFY2((mUiEngine->stationModel().findFrequency( KTestFrequency1, newStation1 )), 
   528         "API:RadioStationModel findFrequency 2");
   548         "API:RadioStationModel findFrequency 2");
   529     newStation1.setType( RadioStation::Favorite );
   549     newStation1.setType( RadioStation::Favorite );
   530     mRadioStationModel->saveStation( newStation1 );    
   550     mEnteredSlots = NoSlotsEntered;
       
   551     mUiEngine->stationModel().saveStation( newStation1 );    
   531     bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && 
   552     bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && 
   532             mEnteredSlots.testFlag( FavoriteChanged ) && mEnteredSlots.testFlag( DataChanged );;
   553             mEnteredSlots.testFlag( FavoriteChanged ) && mEnteredSlots.testFlag( DataChanged );;
   533     QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 1");
   554     QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 1");
       
   555     mEnteredSlots = NoSlotsEntered;
   534     
   556     
   535     newStation1.setGenre(newStation1.genre()+1);
   557     newStation1.setGenre(newStation1.genre()+1);
   536     mRadioStationModel->saveStation( newStation1 );
   558     mUiEngine->stationModel().saveStation( newStation1 );
   537     correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged  ) && mEnteredSlots.testFlag( DataChanged );
   559     correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged  ) && mEnteredSlots.testFlag( DataChanged );
   538     // check that correct signals received
   560     // check that correct signals received
   539     QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 2");
   561     QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 2");
       
   562     mEnteredSlots = NoSlotsEntered;
   540 }
   563 }
   541 
   564 
   542 /*!
   565 /*!
   543  * Testing of RadioStationModel addStation method and rowCount methods
   566  * Testing of RadioStationModel addStation method and rowCount methods
   544  */
   567  */
   545 void TestRadioUiEngine::testAddStation2()
   568 void TestRadioUiEngine::testAddStation2()
   546 {
   569 {
       
   570     FUNC_LOG;
   547     RadioStation newStation2;
   571     RadioStation newStation2;
   548 	newStation2.setFrequency( KTestFrequency2 );
   572 	newStation2.setFrequency( KTestFrequency2 );
   549     QVERIFY2(!newStation2.hasRds(), "API:RadioStationModel addStation 1");
       
   550 	newStation2.setGenre( KTestGenre2 );
   573 	newStation2.setGenre( KTestGenre2 );
   551 	// setting genre should set this true
       
   552 	QVERIFY2(newStation2.hasRds(), "API:RadioStationModel addStation 2");
       
   553 	newStation2.setUrl( KTestUrl2 );
   574 	newStation2.setUrl( KTestUrl2 );
   554     newStation2.setType( RadioStation::LocalStation | RadioStation::Favorite );
   575     newStation2.setType( RadioStation::LocalStation | RadioStation::Favorite );
   555     newStation2.setName("Radio ice");
   576     newStation2.setName("Radio ice");
   556     // check that adding station increases model row count
   577     // check that adding station increases model row count
   557     mExpectedStationCount = mRadioStationModel->rowCount()+1;
   578     mExpectedStationCount = mUiEngine->stationModel().rowCount()+1;
   558     mStationToBeAdded = newStation2.name();
   579     mStationToBeAdded = newStation2.name();
   559     mRadioStationModel->addStation( newStation2 );
   580     mUiEngine->stationModel().addStation( newStation2 );
   560     
   581     
   561     QVERIFY2((mRadioStationModel->rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 3");
   582     QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 3");
   562     mEnteredSlots = NoSlotsEntered;
   583     mEnteredSlots = NoSlotsEntered;
   563 }
   584 }
   564 
   585 
   565 /*!
   586 /*!
   566  * Testing of RadioStationModel saveStation method special cases
   587  * Testing of RadioStationModel saveStation method special cases
   567  */
   588  */
   568 void TestRadioUiEngine::testSaveStation2()
   589 void TestRadioUiEngine::testSaveStation2()
   569 {
   590 {
       
   591     FUNC_LOG;
   570     RadioStation newStation1;
   592     RadioStation newStation1;
   571     // this is needed for preset index to be updated into newStation1
   593     // this is needed for preset index to be updated into newStation1
   572     QVERIFY2((mRadioStationModel->findFrequency( KTestFrequency1, newStation1 )), 
   594     QVERIFY2((mUiEngine->stationModel().findFrequency( KTestFrequency1, newStation1 )), 
   573         "API:RadioStationModel findFrequency 2");
   595         "API:RadioStationModel findFrequency 2");
   574     
   596     
   575 	newStation1.setFrequency( KTestFrequency2 );	
   597 	newStation1.setFrequency( KTestFrequency2 );	
   576 	mExpectedStationCount = mRadioStationModel->rowCount();
   598 	mExpectedStationCount = mUiEngine->stationModel().rowCount();
   577 	// updating existing station data must not increase station count
   599 	// updating existing station data must not increase station count
   578 	mRadioStationModel->saveStation( newStation1 );
   600 	mUiEngine->stationModel().saveStation( newStation1 );
   579 	QVERIFY2((mRadioStationModel->rowCount()==mExpectedStationCount), "API:RadioStationModel saveStation 1");    
   601 	QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel saveStation 1");    
   580     // because frequency tried to be updated no signals should be received either
   602     // because frequency tried to be updated no signals should be received either
   581 	bool correctSignalsReceived = mEnteredSlots.testFlag( NoSlotsEntered );
   603 	bool correctSignalsReceived = mEnteredSlots.testFlag( DataChanged );
   582     QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 2");
   604     QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 2");
   583     mEnteredSlots = NoSlotsEntered;
   605     mEnteredSlots = NoSlotsEntered;
   584     
   606     
   585     // original frequency resumed
   607     // original frequency resumed
   586     newStation1.setFrequency( KTestFrequency1 );
   608     newStation1.setFrequency( KTestFrequency1 );
   587     newStation1.setGenre(newStation1.genre()+1);
   609     newStation1.setGenre(newStation1.genre()+1);
   588     mExpectedStationCount = mRadioStationModel->rowCount();
   610     mExpectedStationCount = mUiEngine->stationModel().rowCount();
   589     // now that frequency resumed signal should be received also
   611     // now that frequency resumed signal should be received also
   590     mRadioStationModel->saveStation( newStation1 );
   612     mUiEngine->stationModel().saveStation( newStation1 );
   591     correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && mEnteredSlots.testFlag( DataChanged );
   613     correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && mEnteredSlots.testFlag( DataChanged );
   592     QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 3");
   614     QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 3");
   593     // updating existing station data must not increase station count
   615     // updating existing station data must not increase station count
   594     QVERIFY2((mRadioStationModel->rowCount()==mExpectedStationCount), "API:RadioStationModel saveStation 2");
   616     QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel saveStation 2");
   595     
   617     
   596     mExpectedStationCount = mRadioStationModel->rowCount();
   618     mExpectedStationCount = mUiEngine->stationModel().rowCount();
   597     mStationToBeAdded = newStation1.name();
   619     mStationToBeAdded = newStation1.name();
   598     // adding station must fail because the frequency is the same as previously used frequency
   620     // adding station must fail because the frequency is the same as previously used frequency
   599     mRadioStationModel->addStation( newStation1 );
   621     mUiEngine->stationModel().addStation( newStation1 );
   600     QVERIFY2((mRadioStationModel->rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 3");
   622     QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 3");
   601 }
   623 }
   602 
   624 
   603 /*!
   625 /*!
   604  * Testing of RadioStationModel addStation method special cases
   626  * Testing of RadioStationModel addStation method special cases
   605  */
   627  */
   606 void TestRadioUiEngine::testAddStation3()
   628 void TestRadioUiEngine::testAddStation3()
   607 {
   629 {
       
   630     FUNC_LOG;
   608     RadioStation newStation3;
   631     RadioStation newStation3;
   609     newStation3.setFrequency( KTestFrequency2 );
   632     newStation3.setFrequency( KTestFrequency2 );
   610     newStation3.setGenre(3);
   633     newStation3.setGenre(3);
   611     newStation3.setUrl("http://www.radio4noice.com");
   634     newStation3.setUrl("http://www.radio4noice.com");
   612     newStation3.setType( RadioStation::LocalStation | RadioStation::Favorite );
   635     newStation3.setType( RadioStation::LocalStation | RadioStation::Favorite );
   613     newStation3.setName("Radio e");
   636     newStation3.setName("Radio e");
   614     // adding station must fail because frequency is the same as previously used frequency
   637     // adding station must fail because frequency is the same as previously used frequency
   615     mExpectedStationCount = mRadioStationModel->rowCount();
   638     mExpectedStationCount = mUiEngine->stationModel().rowCount();
   616     mStationToBeAdded = newStation3.name();
   639     mStationToBeAdded = newStation3.name();
   617     mRadioStationModel->addStation( newStation3 );    
   640     mUiEngine->stationModel().addStation( newStation3 );    
   618     QVERIFY2((mRadioStationModel->rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 4");
   641     QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 4");
   619     // adding station must success because the station frequency is different now
   642     // adding station must success because the station frequency is different now
   620     newStation3.setFrequency( KTestFrequency2 + 1 );
   643     newStation3.setFrequency( KTestFrequency2 + 1 );
   621     mExpectedStationCount = mRadioStationModel->rowCount() + 1;
   644     mExpectedStationCount = mUiEngine->stationModel().rowCount() + 1;
   622     mRadioStationModel->addStation( newStation3 );
   645     mUiEngine->stationModel().addStation( newStation3 );
   623     QVERIFY2((mRadioStationModel->rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 5");
   646     QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 5");
   624     // test that station can be found by frequency range
   647     // test that station can be found by frequency range
   625     QList<RadioStation> stations;
   648     QList<RadioStation> stations;
   626     stations = mRadioStationModel->stationsInRange( KTestFrequency1, KTestFrequency3 );
   649     stations = mUiEngine->stationModel().stationsInRange( KTestFrequency1, KTestFrequency3 );
   627     QVERIFY2((stations.count()==3), "API:RadioStationModel stationsInRange");
   650     QVERIFY2((stations.count()==3), "API:RadioStationModel stationsInRange");
   628 }
   651 }
   629 
   652 
   630 /*!
   653 /*!
   631  * Testing of RadioStationModel saveStation method special cases
   654  * Testing of RadioStationModel saveStation method special cases
   632  */
   655  */
   633 void TestRadioUiEngine::testSaveStation3()
   656 void TestRadioUiEngine::testSaveStation3()
   634 {
   657 {
       
   658     FUNC_LOG;
   635     RadioStation newStation3;
   659     RadioStation newStation3;
   636     RadioStation foundStation;
   660     RadioStation foundStation;
   637     QVERIFY2(mRadioStationModel->findFrequency( KTestFrequency2 + 1, newStation3 ),			
   661     QVERIFY2(mUiEngine->stationModel().findFrequency( KTestFrequency2 + 1, newStation3 ),			
   638         "API:RadioStationModel findFrequency 4");
   662         "API:RadioStationModel findFrequency 4");
   639     
   663     
   640     newStation3.setFrequency( KTestFrequency3 );
   664     newStation3.setFrequency( KTestFrequency3 );
   641     // because frequency or preset index don't have change flag the frequency must not be updated 
   665     // because frequency or preset index don't have change flag the frequency must not be updated 
   642     mRadioStationModel->saveStation( newStation3 );
   666     mUiEngine->stationModel().saveStation( newStation3 );
   643 
   667 
   644     QVERIFY2(!(mRadioStationModel->findFrequency( KTestFrequency3, foundStation )),			
   668     QVERIFY2(!(mUiEngine->stationModel().findFrequency( KTestFrequency3, foundStation )),			
   645         "API:RadioStationModel findFrequency 3");
   669         "API:RadioStationModel findFrequency 3");
   646 
   670 
   647     int stationGenre;
       
   648     stationGenre = newStation3.genre();	
       
   649     newStation3.setGenre( newStation3.genre() + 1 );
   671     newStation3.setGenre( newStation3.genre() + 1 );
   650     // allthough genre changed so the frequency update must not become effective  
   672     // allthough genre changed so the frequency update must not become effective  
   651     mRadioStationModel->saveStation( newStation3 );	
   673     mUiEngine->stationModel().saveStation( newStation3 );	
   652 
   674 
   653     QVERIFY2(!(mRadioStationModel->findFrequency( KTestFrequency3, foundStation )),			
   675     QVERIFY2(!(mUiEngine->stationModel().findFrequency( KTestFrequency3, foundStation )),			
   654         "API:RadioStationModel findFrequency 4");
   676         "API:RadioStationModel findFrequency 4");
   655     
   677     
   656 
   678 
   657     mEnteredSlots = NoSlotsEntered;
   679     mEnteredSlots = NoSlotsEntered;
   658     foreach( const RadioStation& station, mRadioStationModel->list() ) 
   680     foreach( const RadioStation& station, mUiEngine->stationModel().list() ) 
   659     {
   681     {
   660         if ( station.frequency() == KTestFrequency2 ) 
   682         if ( station.frequency() == KTestFrequency2 ) 
   661         {        
   683         {        
   662             mRadioStationModel->setFavoriteByFrequency( KTestFrequency2, !station.isFavorite() );
   684             mUiEngine->stationModel().setFavoriteByFrequency( KTestFrequency2, !station.isFavorite() );
   663         }
   685         }
   664     }
   686     }
   665     bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && 
   687     bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && 
   666         mEnteredSlots.testFlag( FavoriteChanged ) && mEnteredSlots.testFlag( DataChanged );
   688         mEnteredSlots.testFlag( FavoriteChanged ) && mEnteredSlots.testFlag( DataChanged );
   667     QVERIFY2(correctSignalsReceived, "API:RadioStationModel findFrequency 5");
   689     QVERIFY2(correctSignalsReceived, "API:RadioStationModel findFrequency 5");
   672 /*!
   694 /*!
   673  * Test that stations are stored into RadioStationModel in ascending frequency order  
   695  * Test that stations are stored into RadioStationModel in ascending frequency order  
   674  */
   696  */
   675 void TestRadioUiEngine::testSortByFrequency()
   697 void TestRadioUiEngine::testSortByFrequency()
   676 {
   698 {
   677 	int role = RadioStationModel::RadioStationRole;
   699     FUNC_LOG;
       
   700 	int role = RadioRole::RadioStationRole;
   678 	int previousFrequency(0); // int not initialized zero as default
   701 	int previousFrequency(0); // int not initialized zero as default
   679 	
   702 	
   680 	for (int i = 0; i< mRadioStationModel->rowCount(); i++ )
   703 	for (int i = 0; i< mUiEngine->stationModel().rowCount(); i++ )
   681 	{
   704 	{
   682 		QModelIndex index = mRadioStationModel->index( i, 0 );
   705 		QModelIndex index = mUiEngine->stationModel().index( i, 0 );
   683 		QVariant stationData = mRadioStationModel->data( index, role );
   706 		QVariant stationData = mUiEngine->stationModel().data( index, role );
   684 		RadioStation station = stationData.value<RadioStation>();
   707 		RadioStation station = stationData.value<RadioStation>();
   685 		// stations must be obtainded at ascending frequency order
   708 		// stations must be obtainded at ascending frequency order
   686 		QVERIFY2((station.frequency()>previousFrequency), "API:RadioStationModel testSortByFrequency");
   709 		QVERIFY2((station.frequency()>previousFrequency), "API:RadioStationModel testSortByFrequency");
   687 		previousFrequency = station.frequency();
   710 		previousFrequency = station.frequency();
   688 	}
   711 	}
   691 /*!
   714 /*!
   692  * Test that preset indexes match
   715  * Test that preset indexes match
   693  */
   716  */
   694 void TestRadioUiEngine::testFindPresetIndex()
   717 void TestRadioUiEngine::testFindPresetIndex()
   695 {
   718 {
       
   719     FUNC_LOG;
   696 	RadioStation station;
   720 	RadioStation station;
   697 	for (int i = 0; i< mRadioStationModel->rowCount(); i++ )
   721 	for (int i = 0; i< mUiEngine->stationModel().rowCount(); i++ )
   698     {
   722     {
   699 		QVERIFY2((mRadioStationModel->findPresetIndex(i) != RadioStation::NotFound), 
   723 		QVERIFY2((mUiEngine->stationModel().findPresetIndex(i) != RadioStation::NotFound), 
   700 	        "API:RadioStationModel testFindPresetIndex 1");
   724 	        "API:RadioStationModel testFindPresetIndex 1");
   701 		QVERIFY2((mRadioStationModel->findPresetIndex( i, station ) != RadioStation::NotFound), 
   725 		QVERIFY2((mUiEngine->stationModel().findPresetIndex( i, station ) != RadioStation::NotFound), 
   702 			"API:RadioStationModel testFindPresetIndex 2");
   726 			"API:RadioStationModel testFindPresetIndex 2");
   703 		QVERIFY2((station.presetIndex() == i), "API:RadioStationModel testFindPresetIndex 3");
   727 		QVERIFY2((station.presetIndex() == i), "API:RadioStationModel testFindPresetIndex 3");
   704 	}
   728 	}
   705 }
   729 }
   706 
   730 
   707 /*!
   731 /*!
   708  * Test that preset can be removed from model by frequency
   732  * Test that preset can be removed from model by frequency
   709  */
   733  */
   710 void TestRadioUiEngine::testRemoveByFrequency()
   734 void TestRadioUiEngine::testRemoveByFrequency()
   711 {
   735 {
       
   736     FUNC_LOG;
   712 	RadioStation station;
   737 	RadioStation station;
   713 	int initialStationCount( mRadioStationModel->rowCount() );
   738 	int initialStationCount( mUiEngine->stationModel().rowCount() );
   714 	int presetIndex(0);
   739 	int presetIndex(0);
   715 	
   740 	
   716 	// find valid preset index
   741 	// find valid preset index
   717 	for(int i = 0; i<mRadioStationModel->rowCount(); i++)
   742 	for(int i = 0; i<mUiEngine->stationModel().rowCount(); i++)
   718 	{
   743 	{
   719 		presetIndex = mRadioStationModel->findPresetIndex( i, station );
   744 		presetIndex = mUiEngine->stationModel().findPresetIndex( i, station );
   720 		if(presetIndex!=RadioStation::NotFound)
   745 		if(presetIndex!=RadioStation::NotFound)
   721 			break;
   746 			break;
   722 	}
   747 	}
   723 	QVERIFY2((presetIndex != RadioStation::NotFound), "API:RadioStationModel testRemoveByFrequency 1");
   748 	QVERIFY2((presetIndex != RadioStation::NotFound), "API:RadioStationModel testRemoveByFrequency 1");
   724 		
   749 		
   725 	mRadioStationModel->removeByFrequency( station.frequency() );	
   750 	mUiEngine->stationModel().removeByFrequency( station.frequency() );	
   726 	QVERIFY2((mRadioStationModel->rowCount()==(initialStationCount-1)), "API:RadioStationModel testRemoveByFrequency 2");
   751 	QVERIFY2((mUiEngine->stationModel().rowCount()==(initialStationCount-1)), "API:RadioStationModel testRemoveByFrequency 2");
   727 }
   752 }
   728 
   753 
   729 /*!
   754 /*!
   730  * Test that station can be removed from model by preset index 
   755  * Test that station can be removed from model by preset index 
   731  */
   756  */
   732 void TestRadioUiEngine::testRemoveByPresetIndex()
   757 void TestRadioUiEngine::testRemoveByPresetIndex()
   733 {
   758 {
       
   759     FUNC_LOG;
   734 	RadioStation station;
   760 	RadioStation station;
   735 	station.setFrequency( KTestFrequency4 );
   761 	station.setFrequency( KTestFrequency4 );
   736 	mStationToBeAdded = "";
   762 	mStationToBeAdded = "";
   737 	mExpectedStationCount = mRadioStationModel->rowCount() + 1;
   763 	mExpectedStationCount = mUiEngine->stationModel().rowCount() + 1;
   738 	mRadioStationModel->addStation( station );
   764 	mUiEngine->stationModel().addStation( station );
   739 	// for updating station preset index
   765 	// for updating station preset index
   740 	QVERIFY2((mRadioStationModel->findFrequency( KTestFrequency4, station )), 
   766 	QVERIFY2((mUiEngine->stationModel().findFrequency( KTestFrequency4, station )), 
   741 			"API:RadioStationModel testRemoveByPresetIndex 1");
   767 			"API:RadioStationModel testRemoveByPresetIndex 1");
   742 	
   768 	
   743 	int initialStationCount( mRadioStationModel->rowCount() );
   769 	int initialStationCount( mUiEngine->stationModel().rowCount() );
   744 	mRadioStationModel->removeByPresetIndex( station.presetIndex() );    
   770 	mUiEngine->stationModel().removeByPresetIndex( station.presetIndex() );    
   745     QVERIFY2((mRadioStationModel->rowCount()==(initialStationCount-1)), "API:RadioStationModel testRemoveByPresetIndex 2");
   771     QVERIFY2((mUiEngine->stationModel().rowCount()==(initialStationCount-1)), "API:RadioStationModel testRemoveByPresetIndex 2");
   746 }
   772 }
   747 
   773 
   748 /*!
   774 /*!
   749  * Test RadioStationModel method removeStation
   775  * Test RadioStationModel method removeStation
   750  */
   776  */
   751 void TestRadioUiEngine::testRemoveStation()
   777 void TestRadioUiEngine::testRemoveStation()
   752 {
   778 {
       
   779     FUNC_LOG;
   753 	RadioStation station;
   780 	RadioStation station;
   754 	station.setFrequency( KTestFrequency5 );
   781 	station.setFrequency( KTestFrequency5 );
   755 	mStationToBeAdded = "";
   782 	mStationToBeAdded = "";
   756 	mExpectedStationCount = mRadioStationModel->rowCount() + 1;
   783 	mExpectedStationCount = mUiEngine->stationModel().rowCount() + 1;
   757 	mRadioStationModel->addStation( station );
   784 	mUiEngine->stationModel().addStation( station );
   758 	int initialStationCount( mRadioStationModel->rowCount() );
   785 	int initialStationCount( mUiEngine->stationModel().rowCount() );
   759 	// for updating station preset index
   786 	// for updating station preset index
   760 	QVERIFY2(mRadioStationModel->findFrequency( KTestFrequency5, station ),			
   787 	QVERIFY2(mUiEngine->stationModel().findFrequency( KTestFrequency5, station ),			
   761 	        "API:RadioStationModel testRemoveStation");
   788 	        "API:RadioStationModel testRemoveStation");
   762 	
   789 	
   763 	mRadioStationModel->removeStation( station );	
   790 	mUiEngine->stationModel().removeStation( station );	
   764 	QVERIFY2((mRadioStationModel->rowCount()==(initialStationCount-1)), "API:RadioStationModel testRemoveStation");
   791 	QVERIFY2((mUiEngine->stationModel().rowCount()==(initialStationCount-1)), "API:RadioStationModel testRemoveStation");
   765 }
   792 }
   766 
   793 
   767 
   794 
   768 /*!
   795 /*!
   769  * Test setting and unsetting station type favourite
   796  * Test setting and unsetting station type favourite
   770  */
   797  */
   771 void TestRadioUiEngine::testSetFavorite()
   798 void TestRadioUiEngine::testSetFavorite()
   772 {	
   799 {	
       
   800     FUNC_LOG;
   773 	RadioStation station;	
   801 	RadioStation station;	
   774 	station.setFrequency( KTestFrequency6 );
   802 	station.setFrequency( KTestFrequency6 );
   775 	station.setType( RadioStation::Favorite );	
   803 	station.setType( RadioStation::Favorite );	
   776     QVERIFY2(station.isFavorite(), "API:RadioStationModel testSetFavorite 1");
   804     QVERIFY2(station.isFavorite(), "API:RadioStationModel testSetFavorite 1");
   777 	mRadioStationModel->addStation( station );
   805 	mUiEngine->stationModel().addStation( station );
   778 	mEnteredSlots = NoSlotsEntered;	
   806 	mEnteredSlots = NoSlotsEntered;	
   779 	
   807 	
   780 	mRadioStationModel->setFavoriteByFrequency( KTestFrequency6, false );	
   808 	mUiEngine->stationModel().setFavoriteByFrequency( KTestFrequency6, false );	
   781 	bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && 
   809 	bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && 
   782 	    mEnteredSlots.testFlag( FavoriteChanged ) && mEnteredSlots.testFlag( DataChanged );
   810 	    mEnteredSlots.testFlag( FavoriteChanged ) && mEnteredSlots.testFlag( DataChanged );
   783 	QVERIFY2(correctSignalsReceived, "API:RadioStationModel testSetFavorite 2");
   811 	QVERIFY2(correctSignalsReceived, "API:RadioStationModel testSetFavorite 2");
   784 	
   812 	
   785 	mRadioStationModel->findFrequency( KTestFrequency6, station );
   813 	mUiEngine->stationModel().findFrequency( KTestFrequency6, station );
   786 	QVERIFY2(!station.isFavorite(), "API:RadioStationModel testSetFavorite 3");
   814 	QVERIFY2(!station.isFavorite(), "API:RadioStationModel testSetFavorite 3");
   787 	mEnteredSlots = NoSlotsEntered;
   815 	mEnteredSlots = NoSlotsEntered;
   788 	
   816 	
   789 	mRadioStationModel->setFavoriteByPreset( station.presetIndex(), true );
   817 	mUiEngine->stationModel().setFavoriteByPreset( station.presetIndex(), true );
   790 	correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && 
   818 	correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && 
   791 		mEnteredSlots.testFlag( FavoriteChanged ) && mEnteredSlots.testFlag( DataChanged );
   819 		mEnteredSlots.testFlag( FavoriteChanged ) && mEnteredSlots.testFlag( DataChanged );
   792 	QVERIFY2(correctSignalsReceived, "API:RadioStationModel testSetFavorite 4");
   820 	QVERIFY2(correctSignalsReceived, "API:RadioStationModel testSetFavorite 4");
   793     
   821     
   794 	// test toggling the favorite 
   822 	// test toggling the favorite 
   795 	QModelIndex index = mRadioStationModel->modelIndexFromFrequency( KTestFrequency6 );
   823 	int index = mUiEngine->stationModel().indexFromFrequency( KTestFrequency6 );
   796     mRadioStationModel->setData( index, KTestFrequencyString6 ,RadioStationModel::ToggleFavoriteRole);
   824 	mUiEngine->stationModel().setFavoriteByFrequency( KTestFrequency6, ETrue );
   797     RadioStation station1 = mRadioStationModel->stationAt( index.row() );
   825     RadioStation station1 = mUiEngine->stationModel().stationAt( index );
   798     QVERIFY2(!station1.isFavorite(), "API:RadioStationModel testToggleFavourite");
   826     QVERIFY2(station1.isFavorite(), "API:RadioStationModel testToggleFavourite");
   799 
   827 
   800 }
   828 }
   801 
   829 
   802 /*!
   830 /*!
   803  * Test renaming station
   831  * Test renaming station
   804  */
   832  */
   805 void TestRadioUiEngine::testRenameStation()
   833 void TestRadioUiEngine::testRenameStation()
   806 {	
   834 {	
       
   835     FUNC_LOG;
   807 	RadioStation station;
   836 	RadioStation station;
   808 	int presetIndex(0);
   837 	int presetIndex(0);
   809 	// find valid preset index
   838 	// find valid preset index
   810     for( int i = 0; i<mRadioStationModel->rowCount(); i++ )
   839     for( int i = 0; i<mUiEngine->stationModel().rowCount(); i++ )
   811 	{
   840 	{
   812 		if( mRadioStationModel->findPresetIndex( i, station ) != RadioStation::NotFound )
   841 		if( mUiEngine->stationModel().findPresetIndex( i, station ) != RadioStation::NotFound )
   813 		{
   842 		{
   814 			presetIndex = i;
   843 			presetIndex = i;
   815 			break;
   844 			break;
   816 		}
   845 		}
   817 	}   
   846 	}   
   818     QString initialStationName( station.name() );
   847     QString initialStationName( station.name() );
   819     mEnteredSlots = NoSlotsEntered;
   848     mEnteredSlots = NoSlotsEntered;
   820 	mRadioStationModel->renameStation( presetIndex, initialStationName + "Renamed" );	
   849 	mUiEngine->stationModel().renameStation( presetIndex, initialStationName + "Renamed" );	
   821 	bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && 
   850 	bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && 
   822         mEnteredSlots.testFlag( DataChanged );
   851         mEnteredSlots.testFlag( DataChanged );
   823 	QVERIFY2(correctSignalsReceived, "API:RadioStationModel testRenameStation 1");	
   852 	QVERIFY2(correctSignalsReceived, "API:RadioStationModel testRenameStation 1");	
   824     QVERIFY2(initialStationName!=mRadioStationModel->stationAt(presetIndex).name(), "API:RadioStationModel testRenameStation 2");
   853     QVERIFY2(initialStationName!=mUiEngine->stationModel().stationAt(presetIndex).name(), "API:RadioStationModel testRenameStation 2");
   825         
   854         
   826     station.setUserDefinedName( KTestStationName2 );
   855     station.setUserDefinedName( KTestStationName2 );
   827     QVERIFY2(station.isRenamed(), "API:RadioStationModel testRenameStation 1");
   856     QVERIFY2(station.isRenamed(), "API:RadioStationModel testRenameStation 1");
   828     
   857     
   829 }
   858 }
   831 /*!
   860 /*!
   832  * Test setting radio text
   861  * Test setting radio text
   833  */
   862  */
   834 void TestRadioUiEngine::testSetRadioTextPlus()
   863 void TestRadioUiEngine::testSetRadioTextPlus()
   835 {
   864 {
       
   865     FUNC_LOG;
   836     RadioStation station;
   866     RadioStation station;
   837     mRadioStationModel->findFrequency( KTestFrequency6, station );
   867     mUiEngine->stationModel().findFrequency( KTestFrequency6, station );
   838     station.setRadioText( "" );
   868     station.setRadioText( "" );
   839     station.setRadioText( KTestRadioTextRadioText );
   869     station.setRadioText( KTestRadioTextRadioText );
   840     station.setRadioText( KTestRadioTextRadioText );
   870     station.setRadioText( KTestRadioTextRadioText );
   841     station.setRadioTextPlus( RtPlus::Artist, KTestRadioTextPlusArtist );
   871     station.setRadioTextPlus( RtPlus::Artist, KTestRadioTextPlusArtist );
   842     station.setRadioTextPlus( RtPlus::Title, KTestRadioTextPlusTitle );
   872     station.setRadioTextPlus( RtPlus::Title, KTestRadioTextPlusTitle );
   843     station.setRadioTextPlus( RtPlus::Homepage, KTestRadioTextPlusUrl );
   873     station.setRadioTextPlus( RtPlus::Homepage, KTestRadioTextPlusUrl );
   844     station.setRadioTextPlus( RtPlus::Homepage + 1, KTestRadioTextPlusUnsupportedTag );
   874     station.setRadioTextPlus( RtPlus::Homepage + 1, KTestRadioTextPlusUnsupportedTag );
   845     mRadioStationModel->saveStation( station );
   875     mUiEngine->stationModel().saveStation( station );
   846     bool effective = station.radioText().contains( KTestRadioTextPlusArtist, Qt::CaseSensitive );
   876     bool effective = station.radioText().contains( KTestRadioTextPlusArtist, Qt::CaseSensitive );
   847     QVERIFY2(effective, "API:RadioStationModel testSetRadioTextPlus 1");
   877     QVERIFY2(effective, "API:RadioStationModel testSetRadioTextPlus 1");
   848     effective = station.radioText().contains( KTestRadioTextPlusTitle, Qt::CaseSensitive );
   878     effective = station.radioText().contains( KTestRadioTextPlusTitle, Qt::CaseSensitive );
   849     QVERIFY2(effective, "API:RadioStationModel testSetRadioTextPlus 2");
   879     QVERIFY2(effective, "API:RadioStationModel testSetRadioTextPlus 2");
   850     effective = !station.url().compare( KTestRadioTextPlusUrl );
   880     effective = !station.url().compare( KTestRadioTextPlusUrl );
   854 /*!
   884 /*!
   855  * Test RadioStationModel API
   885  * Test RadioStationModel API
   856  */	
   886  */	
   857 void TestRadioUiEngine::testRadioStationModel()
   887 void TestRadioUiEngine::testRadioStationModel()
   858 {
   888 {
       
   889     FUNC_LOG;
   859 	testRadioStationModelInit();
   890 	testRadioStationModelInit();
   860 	testAddStation1();
   891 	testAddStation1();
   861 	testSaveStation1();
   892 	testSaveStation1();
   862 	testAddStation2();
   893 	testAddStation2();
   863 	testSaveStation2();
   894 	testSaveStation2();
   875 /*!
   906 /*!
   876  * Test RadioHistoryModel API
   907  * Test RadioHistoryModel API
   877  */
   908  */
   878 void TestRadioUiEngine::testhistoryModel()
   909 void TestRadioUiEngine::testhistoryModel()
   879     {
   910     {
       
   911     FUNC_LOG;
   880     testHistoryModelInit();
   912     testHistoryModelInit();
   881     testHistoryModelAddItem();
   913     testHistoryModelAddItem();
   882     testHistoryModelFindItem();
       
   883     testHistoryModelUpdateItem();
       
   884     testHistoryModelSetData();
       
   885     testAddRadioTextPlus();
   914     testAddRadioTextPlus();
   886     testClearRadioTextPlus();
   915     testClearRadioTextPlus();
   887     }
   916     }
   888 
   917 
   889 /*!
   918 /*!
   890  * Testing of RadioHistoryModel initial state
   919  * Testing of RadioHistoryModel initial state
   891  */
   920  */
   892 void TestRadioUiEngine::testHistoryModelInit()
   921 void TestRadioUiEngine::testHistoryModelInit()
   893 {
   922 {
   894     //TODO:: Check why ASSERT fails when mhistoryModel->rowCount() == 0 
   923     FUNC_LOG;
   895     if( mhistoryModel->rowCount()>0 )
   924     //TODO:: Check why ASSERT fails when mUiEngine->historyModel().rowCount() == 0 
       
   925     if( mUiEngine->historyModel().rowCount()>0 )
   896     {       
   926     {       
   897         mhistoryModel->removeAll();
   927         mUiEngine->historyModel().removeAll( EFalse );
   898         QVERIFY2((mRadioStationModel->rowCount()==0), "API:RadioHistoryModel removeAll() 1");
   928         QVERIFY2((mUiEngine->stationModel().rowCount()==0), "API:RadioHistoryModel removeAll() 1");
   899     }
   929     }
   900     QVERIFY2((mhistoryModel->rowCount()==0), "API:RadioHistoryModel removeAll() 2");           
   930     QVERIFY2((mUiEngine->historyModel().rowCount()==0), "API:RadioHistoryModel removeAll() 2");           
   901 }
   931 }
   902 
   932 
   903 /*!
   933 /*!
   904  *
   934  *
   905  */
   935  */
   906 void TestRadioUiEngine::testHistoryModelAddItem()
   936 void TestRadioUiEngine::testHistoryModelAddItem()
   907 {
   937 {
   908     int expectedHistoryItemCount( mhistoryModel->rowCount() + 1 );
   938     FUNC_LOG;
       
   939     RadioStation station;
       
   940     mUiEngine->stationModel().findFrequency( KTestFrequency6, station );
       
   941     int expectedHistoryItemCount( mUiEngine->historyModel().rowCount() + 1 );
   909     mEnteredSlots = NoSlotsEntered;
   942     mEnteredSlots = NoSlotsEntered;
   910     mhistoryModel->addItem( KTestArtist1, KTestTitle1 );    
   943     mUiEngine->historyModel().addItem( KTestArtist1, KTestTitle1, station );    
   911     bool correctSignalsReceived = mEnteredSlots.testFlag( ItemAdded );
       
   912     // check that correct signals received
       
   913     QVERIFY2(correctSignalsReceived, "API:RadioHistoryModel addItem() 1");
       
   914     // check that item count increases
   944     // check that item count increases
   915     QVERIFY2((mhistoryModel->rowCount()==expectedHistoryItemCount), "API:RadioHistoryModel addItem() 2");
   945     QVERIFY2((mUiEngine->historyModel().rowCount()==expectedHistoryItemCount), "API:RadioHistoryModel addItem() 2");
   916     
   946     
   917     // check that artist/title stored into the model conforms to the one read from the model
   947     // check that artist/title stored into the model conforms to the one read from the model
   918     QModelIndex index = mhistoryModel->index( 0, 0 );
   948     QModelIndex index = mUiEngine->historyModel().index( 0, 0 );
   919     QStringList stringList = mhistoryModel->data( index, Qt::DisplayRole ).value<QStringList>();        
   949     QStringList stringList = mUiEngine->historyModel().data( index, Qt::DisplayRole ).value<QStringList>();        
   920     QString artistTitle = stringList.at(0);    
   950     QString artistTitle = stringList.at(0);    
   921     QVERIFY2(!(artistTitle.compare(KTestArtist1+" - "+KTestTitle1)), "API:RadioHistoryModel addItem() 3");
   951     QVERIFY2(!(artistTitle.compare(KTestArtist1+" - "+KTestTitle1)), "API:RadioHistoryModel addItem() 3");
   922     
   952     
   923     
   953     
   924     expectedHistoryItemCount = mhistoryModel->rowCount();
   954     expectedHistoryItemCount = mUiEngine->historyModel().rowCount();
   925     // trying to add an item that allready exists must not increase the item count
   955     // trying to add an item that allready exists must not increase the item count
   926     mhistoryModel->addItem( KTestArtist1, KTestTitle1 );
   956     mUiEngine->historyModel().addItem( KTestArtist1, KTestTitle1, station );
   927     QVERIFY2((mhistoryModel->rowCount()==expectedHistoryItemCount), "API:RadioHistoryModel addItem() 4");
   957     QVERIFY2((mUiEngine->historyModel().rowCount()==expectedHistoryItemCount), "API:RadioHistoryModel addItem() 4");
   928 }
       
   929 
       
   930 /*!
       
   931  *
       
   932  */
       
   933 void TestRadioUiEngine::testHistoryModelFindItem()
       
   934 {
       
   935     RadioHistoryItem item;
       
   936     mhistoryModel->findItem( KTestArtist1, KTestTitle1, item );
       
   937     QVERIFY2((item.artist()==KTestArtist1), "API:RadioHistoryModel findItem() 1");
       
   938     QVERIFY2((item.title()==KTestTitle1), "API:RadioHistoryModel findItem() 2");
       
   939     // try to find an item that doesn't exist
       
   940     int ret = mhistoryModel->findItem( KTestArtist1+"+", KTestTitle1, item );
       
   941     QVERIFY2(ret==-1, "API:RadioHistoryModel findItem() 3");
       
   942 }
       
   943 
       
   944 /*!
       
   945  *
       
   946  */
       
   947 void TestRadioUiEngine::testHistoryModelUpdateItem()
       
   948 {
       
   949     RadioHistoryItem item;    
       
   950     mhistoryModel->findItem( KTestArtist1, KTestTitle1, item );
       
   951     item.setTitle( KTestTitle2 );    
       
   952     // update an existing item
       
   953     mhistoryModel->updateItem( 0, item, true );
       
   954     
       
   955     RadioHistoryItem foundItem;
       
   956     // original item must not be found any more
       
   957     int ret = mhistoryModel->findItem(KTestArtist1, KTestTitle1, foundItem);
       
   958     QVERIFY2(ret==-1, "API:RadioHistoryModel updateItem() 1");
       
   959     // but the updated one instead
       
   960     mhistoryModel->findItem(KTestArtist1, KTestTitle2, foundItem);
       
   961     QVERIFY2((foundItem.title()==KTestTitle2), "API:RadioHistoryModel updateItem() 2"); 
       
   962 }
       
   963 
       
   964 /*!
       
   965  *
       
   966  */
       
   967 void TestRadioUiEngine::testHistoryModelSetData()
       
   968 {
       
   969    RadioHistoryItem foundItem;
       
   970    mhistoryModel->findItem(KTestArtist1, KTestTitle2, foundItem);
       
   971    QVERIFY2(!foundItem.isFavorite(), "API:RadioHistoryModel SetData() 1");
       
   972    
       
   973    QModelIndex index = mhistoryModel->index( 0, 0 );
       
   974    QString artistTitle = KTestArtist1 + KTestTitle2;
       
   975    mhistoryModel->setData( index, artistTitle, RadioHistoryModel::SetFavoriteRole );
       
   976    mhistoryModel->findItem(KTestArtist1, KTestTitle2, foundItem);
       
   977    // item should be now favorite
       
   978    QVERIFY2(foundItem.isFavorite(), "API:RadioHistoryModel SetData() 2");    
       
   979 }
   958 }
   980 
   959 
   981 /*!
   960 /*!
   982  *
   961  *
   983  */
   962  */
   984 void TestRadioUiEngine::testAddRadioTextPlus()
   963 void TestRadioUiEngine::testAddRadioTextPlus()
   985 {   
   964 {   
   986     mhistoryModel->addRadioTextPlus( RtPlus::Artist, KTestArtist1 );
   965     FUNC_LOG;
   987     mhistoryModel->addRadioTextPlus( RtPlus::Title, KTestTitle1 );
   966     RadioStation station;
       
   967     mUiEngine->stationModel().findFrequency( KTestFrequency6, station );
       
   968     mUiEngine->historyModel().addRadioTextPlus( RtPlus::Artist, KTestArtist1, station );
       
   969     mUiEngine->historyModel().addRadioTextPlus( RtPlus::Title, KTestTitle1, station );
   988 }
   970 }
   989 
   971 
   990 /*!
   972 /*!
   991  *
   973  *
   992  */
   974  */
   993 void TestRadioUiEngine::testClearRadioTextPlus()
   975 void TestRadioUiEngine::testClearRadioTextPlus()
   994 {   
   976 {   
   995     mhistoryModel->clearRadioTextPlus();
   977     FUNC_LOG;
       
   978     mUiEngine->historyModel().clearRadioTextPlus();
   996 }
   979 }
   997 
   980 
   998 /*!
   981 /*!
   999  * Test RadioHistoryModelItem API
   982  * Test RadioHistoryModelItem API
  1000  */
   983  */
  1001 void TestRadioUiEngine::testHistoryModelItem()
   984 void TestRadioUiEngine::testHistoryModelItem()
  1002 {
   985 {
       
   986     FUNC_LOG;
  1003     RadioHistoryItem* item = new RadioHistoryItem( KTestArtist3, KTestTitle3 );
   987     RadioHistoryItem* item = new RadioHistoryItem( KTestArtist3, KTestTitle3 );
  1004     item->setArtist( KTestArtist3 );
   988     item->setArtist( KTestArtist3 );
  1005     QVERIFY2(!(item->artist().compare(KTestArtist3)), "API:testHistoryModelItem setArtist()");
   989     QVERIFY2(!(item->artist().compare(KTestArtist3)), "API:testHistoryModelItem setArtist()");
  1006     item->setTitle( KTestTitle3 );
   990     item->setTitle( KTestTitle3 );
  1007     QVERIFY2(!(item->title().compare(KTestTitle3)), "API:testHistoryModelItem setTitle()");
   991     QVERIFY2(!(item->title().compare(KTestTitle3)), "API:testHistoryModelItem setTitle()");
  1008     QVERIFY2(!item->isFavorite(), "API:testHistoryModelItem isFavorite() 1");
   992     QVERIFY2( item->isValid(), "API:testHistoryModelItem isValid() 1");
  1009     item->setFavorite();
   993     item->reset();
  1010     QVERIFY2(item->isFavorite(), "API:testHistoryModelItem isFavorite() 2");
   994     QVERIFY2(!item->isValid(), "API:testHistoryModelItem isValid() 2");
  1011     item->setFavorite();
       
  1012     delete item;
   995     delete item;
  1013     item = NULL;
   996     item = NULL;
  1014 }
   997 }