diff -r e14766a36cdc -r c44f9bb56771 radioapp/radiouiengine/tsrc/src/t_radiostation.cpp --- a/radioapp/radiouiengine/tsrc/src/t_radiostation.cpp Thu Sep 02 20:26:56 2010 +0300 +++ b/radioapp/radiouiengine/tsrc/src/t_radiostation.cpp Fri Sep 17 08:29:29 2010 +0300 @@ -27,7 +27,9 @@ #include "radiohistorymodel.h" #include "radioenginewrapper.h" #include "radiouiengine.h" +#include "radioengineutils.h" #include "radiologger.h" //Radio::connect +#include "trace.h" // Constants const uint KTestFrequency1 = 89000000; @@ -64,6 +66,7 @@ */ int main(int /* argc*/, char *argv[]) { + FUNC_LOG; TestRadioUiEngine tv; char *pass[3]; @@ -79,53 +82,65 @@ TestRadioUiEngine::TestRadioUiEngine() { + FUNC_LOG; } void TestRadioUiEngine::tunedToFrequency( uint /* frequency */, int /* commandSender */) { + FUNC_LOG; } -void TestRadioUiEngine::seekingStarted( Seeking::Direction /* direction */) +void TestRadioUiEngine::seekingStarted( Seek::Direction /* direction */) { + FUNC_LOG; } void TestRadioUiEngine::radioStatusChanged( bool /* radioIsOn */) { + FUNC_LOG; } void TestRadioUiEngine::rdsAvailabilityChanged( bool /* available */) { + FUNC_LOG; } void TestRadioUiEngine::volumeChanged( int /* volume */) { + FUNC_LOG; } void TestRadioUiEngine::muteChanged( bool /* muted */) { + FUNC_LOG; } void TestRadioUiEngine::audioRouteChanged( bool /* loudspeaker */) { + FUNC_LOG; } void TestRadioUiEngine::scanAndSaveFinished() { + FUNC_LOG; } void TestRadioUiEngine::headsetStatusChanged( bool /* connected */) { + FUNC_LOG; } void TestRadioUiEngine::skipPrevious() { + FUNC_LOG; } void TestRadioUiEngine::skipNext() { + FUNC_LOG; } /*! @@ -133,7 +148,7 @@ */ TestRadioUiEngine::~TestRadioUiEngine() { - delete mRadioStationModel; + FUNC_LOG; delete mUiEngine; } @@ -142,6 +157,7 @@ */ void TestRadioUiEngine::init() { + FUNC_LOG; } /*! @@ -149,6 +165,7 @@ */ void TestRadioUiEngine::cleanup() { + FUNC_LOG; } /*! @@ -156,6 +173,7 @@ */ void TestRadioUiEngine::initTestCase() { + FUNC_LOG; #ifdef UNIT_TESTS_FOR_10_1 // Workaround for the below panic, occured after porting to 10.1 // Main Panic E32USER-CBase 44 @@ -163,36 +181,32 @@ CActiveScheduler* scheduler = new(ELeave) CActiveScheduler; CleanupStack::PushL(scheduler); CActiveScheduler::Install(scheduler); -// CCoeEnv::Static() call in CRadioEngineTls returns NULL - CCoeEnv* env = new CCoeEnv; #endif + RadioEngineUtils::InitializeL(); mUiEngine = new RadioUiEngine; - mRadioStationModel = new RadioStationModel( *mUiEngine ); - mhistoryModel = new RadioHistoryModel( *mUiEngine ); + mUiEngine->init(); - mEngineWrapper.reset( new RadioEngineWrapper( mRadioStationModel->stationHandlerIf(), *this ) ); + mEngineWrapper.reset( new RadioEngineWrapper( mUiEngine->stationModel().stationHandlerIf() ) ); + mEngineWrapper->init(); mPresetStorage.reset( new RadioPresetStorage() ); - mRadioStationModel->initialize( mPresetStorage.data(), mEngineWrapper.data() ); + mUiEngine->stationModel().initialize( mPresetStorage.data(), mEngineWrapper.data() ); //TODO:: Check why ASSERT fails when mModel->rowCount() == 0 - if(mRadioStationModel->rowCount()>0) + if(mUiEngine->stationModel().rowCount()>0) { - mRadioStationModel->removeAll(); //ASSERT: \"last >= first\" in file qabstractitemmodel.cpp, line 2110 + mUiEngine->stationModel().removeAll(); //ASSERT: \"last >= first\" in file qabstractitemmodel.cpp, line 2110 } - Radio::connect( mRadioStationModel, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)), + Radio::connect( &mUiEngine->stationModel(), SIGNAL(dataChanged(const QModelIndex, const QModelIndex)), this, SLOT(dataChanged(const QModelIndex, const QModelIndex)) ); - Radio::connect( mRadioStationModel, SIGNAL(stationAdded(RadioStation)), - this, SLOT(stationAdded(RadioStation)) ); - - Radio::connect( mRadioStationModel, SIGNAL(stationDataChanged(RadioStation)), + Radio::connect( &mUiEngine->stationModel(), SIGNAL(stationDataChanged(RadioStation)), this, SLOT(stationDataChanged(RadioStation)) ); - Radio::connect( mRadioStationModel, SIGNAL(favoriteChanged(RadioStation)), + Radio::connect( &mUiEngine->stationModel(), SIGNAL(favoriteChanged(RadioStation)), this, SLOT(favoriteChanged(RadioStation)) ); - Radio::connect( mhistoryModel, SIGNAL(itemAdded()), + Radio::connect( &mUiEngine->historyModel(), SIGNAL(itemAdded()), this, SLOT(itemAdded()) ); } @@ -201,7 +215,8 @@ */ void TestRadioUiEngine::cleanupTestCase() { - delete mRadioStationModel; + FUNC_LOG; + delete &mUiEngine->stationModel(); delete mUiEngine; } @@ -210,6 +225,7 @@ */ void TestRadioUiEngine::dataChanged(const QModelIndex /* topLeft */, const QModelIndex /* bottomRight */) { + FUNC_LOG; mEnteredSlots |= DataChanged; } @@ -218,6 +234,7 @@ */ void TestRadioUiEngine::stationDataChanged( RadioStation /* addedStation */ ) { + FUNC_LOG; mEnteredSlots |= StationDataChanged; } @@ -226,6 +243,7 @@ */ void TestRadioUiEngine::favoriteChanged( RadioStation /* addedStation */) { + FUNC_LOG; mEnteredSlots |= FavoriteChanged; } @@ -234,26 +252,17 @@ */ void TestRadioUiEngine::itemAdded() { + FUNC_LOG; mEnteredSlots |= ItemAdded; } -/*! - * - */ -void TestRadioUiEngine::stationAdded( RadioStation addedStation ) -{ - mEnteredSlots |= StationAdded; - - QVERIFY2(( mStationToBeAdded == addedStation.name() ), "API:RadioStationModel stationAdded 1"); - QVERIFY2(( mExpectedStationCount == mRadioStationModel->rowCount() ), "API:RadioStationModel stationAdded 2"); -} - /*! * Testing of implicit sharing a.k.a. copy-on-write */ void TestRadioUiEngine::testImplicitSharing() { + FUNC_LOG; RadioStation t_RadioStation_1; int originalPresetIndex = t_RadioStation_1.presetIndex(); @@ -334,6 +343,7 @@ */ void TestRadioUiEngine::testChangeFlags() { + FUNC_LOG; RadioStation t_RadioStation; QVERIFY2(!t_RadioStation.isValid(), "API:Radiostation Init failure"); @@ -417,6 +427,8 @@ */ void TestRadioUiEngine::TestCallSignChar() { + FUNC_LOG; + /* for(uint i = 0; i < KLastCallSignCharCode; i++) { RadioStation t_RadioStation; @@ -426,6 +438,7 @@ RadioStation t_RadioStation; bool passed = t_RadioStation.callSignChar(KLastCallSignCharCode + 1) == static_cast( '?' ); QVERIFY2(passed, "API:Radiostation TestCallSignChar 2"); + */ } /*! @@ -433,7 +446,9 @@ */ void TestRadioUiEngine::testPICodeToCallSign() { - RadioStation t_RadioStation; + FUNC_LOG; + /* + RadioStation t_RadioStation; // boundary values, two typical values and three chars call sign case QString callSign = t_RadioStation.piCodeToCallSign( KKxxxCallSignPiFirst - 1 ); @@ -456,6 +471,7 @@ QVERIFY2((callSign=="WJZ"), "API:Radiostation Call sign WJZ"); callSign = t_RadioStation.piCodeToCallSign( 0x99C0 ); QVERIFY2((callSign==""), "API:Radiostation Call sign ????"); + */ } /*! @@ -463,16 +479,17 @@ */ void TestRadioUiEngine::testRadioStationModelInit() { + FUNC_LOG; //TODO:: Check why ASSERT fails when mModel->rowCount() == 0 - if( mRadioStationModel->rowCount()>0 ) + if( mUiEngine->stationModel().rowCount()>0 ) { - mRadioStationModel->removeAll(); - QVERIFY2((mRadioStationModel->rowCount()==0), "API:RadioStationModel removeAll()"); + mUiEngine->stationModel().removeAll(); + QVERIFY2((mUiEngine->stationModel().rowCount()==0), "API:RadioStationModel removeAll()"); } RadioStation foundStation; // no stations in the model in this phase - QVERIFY2(!(mRadioStationModel->findFrequency( KTestFrequency1, foundStation )), + QVERIFY2(!(mUiEngine->stationModel().findFrequency( KTestFrequency1, foundStation )), "API:RadioStationModel findFrequency 1"); } @@ -481,6 +498,7 @@ */ void TestRadioUiEngine::testAddStation1() { + FUNC_LOG; RadioStation station; station.setFrequency( KTestFrequency1 ); station.setFrequency( KTestFrequency1 ); @@ -496,24 +514,25 @@ QVERIFY2(!(station.dynamicPsText().compare(KTestDynamicPSText)), "API:RadioStationModel addStation 1"); station.setDynamicPsText( KTestDynamicPSText ); // check that adding station increases model row count - mExpectedStationCount = mRadioStationModel->rowCount() + 1; + mExpectedStationCount = mUiEngine->stationModel().rowCount() + 1; mStationToBeAdded = station.name(); - mRadioStationModel->addStation( station ); - QVERIFY2((mRadioStationModel->rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 2"); - bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && - mEnteredSlots.testFlag( StationAdded ) && mEnteredSlots.testFlag( DataChanged ); + mUiEngine->stationModel().addStation( station ); + QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 2"); + bool correctSignalsReceived = mEnteredSlots.testFlag( DataChanged ); - bool frequencyUpdated = station.frequencyMhz().toDouble()*1000000 == KTestFrequency1; + bool frequencyUpdated = station.frequency() == KTestFrequency1; QVERIFY2(frequencyUpdated, "API:RadioStationModel addStation 1"); // check that correct signals received QVERIFY2(correctSignalsReceived, "API:RadioStationModel addStation 3"); mEnteredSlots = NoSlotsEntered; // check that added station can be found by frequency - QModelIndex index = mRadioStationModel->modelIndexFromFrequency( KTestFrequency1 ); - QVariant stationData = mRadioStationModel->data( index, Qt::DisplayRole ); - QString stationName = stationData.toString().right( KTestStationName1.length() ); - QVERIFY2(!(stationName.compare(KTestStationName1)), "API:RadioStationModel modelIndexFromFrequency"); + int index( KErrNotFound ); + index = mUiEngine->stationModel().indexFromFrequency( KTestFrequency1 ); + QVERIFY2(index != KErrNotFound, "Added station not found from model!"); + + RadioStation readStation ( mUiEngine->stationModel().stationAt( index ) ); + QVERIFY2( !readStation.name().compare(KTestStationName1), "Added station's name not found from model!"); } /*! @@ -521,22 +540,26 @@ */ void TestRadioUiEngine::testSaveStation1() { + FUNC_LOG; RadioStation newStation1; // check that find by frequency works // this is needed for preset index to be updated into newStation1 - QVERIFY2((mRadioStationModel->findFrequency( KTestFrequency1, newStation1 )), + QVERIFY2((mUiEngine->stationModel().findFrequency( KTestFrequency1, newStation1 )), "API:RadioStationModel findFrequency 2"); newStation1.setType( RadioStation::Favorite ); - mRadioStationModel->saveStation( newStation1 ); + mEnteredSlots = NoSlotsEntered; + mUiEngine->stationModel().saveStation( newStation1 ); bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && mEnteredSlots.testFlag( FavoriteChanged ) && mEnteredSlots.testFlag( DataChanged );; QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 1"); + mEnteredSlots = NoSlotsEntered; newStation1.setGenre(newStation1.genre()+1); - mRadioStationModel->saveStation( newStation1 ); + mUiEngine->stationModel().saveStation( newStation1 ); correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && mEnteredSlots.testFlag( DataChanged ); // check that correct signals received QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 2"); + mEnteredSlots = NoSlotsEntered; } /*! @@ -544,21 +567,19 @@ */ void TestRadioUiEngine::testAddStation2() { + FUNC_LOG; RadioStation newStation2; newStation2.setFrequency( KTestFrequency2 ); - QVERIFY2(!newStation2.hasRds(), "API:RadioStationModel addStation 1"); newStation2.setGenre( KTestGenre2 ); - // setting genre should set this true - QVERIFY2(newStation2.hasRds(), "API:RadioStationModel addStation 2"); newStation2.setUrl( KTestUrl2 ); newStation2.setType( RadioStation::LocalStation | RadioStation::Favorite ); newStation2.setName("Radio ice"); // check that adding station increases model row count - mExpectedStationCount = mRadioStationModel->rowCount()+1; + mExpectedStationCount = mUiEngine->stationModel().rowCount()+1; mStationToBeAdded = newStation2.name(); - mRadioStationModel->addStation( newStation2 ); + mUiEngine->stationModel().addStation( newStation2 ); - QVERIFY2((mRadioStationModel->rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 3"); + QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 3"); mEnteredSlots = NoSlotsEntered; } @@ -567,37 +588,38 @@ */ void TestRadioUiEngine::testSaveStation2() { + FUNC_LOG; RadioStation newStation1; // this is needed for preset index to be updated into newStation1 - QVERIFY2((mRadioStationModel->findFrequency( KTestFrequency1, newStation1 )), + QVERIFY2((mUiEngine->stationModel().findFrequency( KTestFrequency1, newStation1 )), "API:RadioStationModel findFrequency 2"); newStation1.setFrequency( KTestFrequency2 ); - mExpectedStationCount = mRadioStationModel->rowCount(); + mExpectedStationCount = mUiEngine->stationModel().rowCount(); // updating existing station data must not increase station count - mRadioStationModel->saveStation( newStation1 ); - QVERIFY2((mRadioStationModel->rowCount()==mExpectedStationCount), "API:RadioStationModel saveStation 1"); + mUiEngine->stationModel().saveStation( newStation1 ); + QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel saveStation 1"); // because frequency tried to be updated no signals should be received either - bool correctSignalsReceived = mEnteredSlots.testFlag( NoSlotsEntered ); + bool correctSignalsReceived = mEnteredSlots.testFlag( DataChanged ); QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 2"); mEnteredSlots = NoSlotsEntered; // original frequency resumed newStation1.setFrequency( KTestFrequency1 ); newStation1.setGenre(newStation1.genre()+1); - mExpectedStationCount = mRadioStationModel->rowCount(); + mExpectedStationCount = mUiEngine->stationModel().rowCount(); // now that frequency resumed signal should be received also - mRadioStationModel->saveStation( newStation1 ); + mUiEngine->stationModel().saveStation( newStation1 ); correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && mEnteredSlots.testFlag( DataChanged ); QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 3"); // updating existing station data must not increase station count - QVERIFY2((mRadioStationModel->rowCount()==mExpectedStationCount), "API:RadioStationModel saveStation 2"); + QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel saveStation 2"); - mExpectedStationCount = mRadioStationModel->rowCount(); + mExpectedStationCount = mUiEngine->stationModel().rowCount(); mStationToBeAdded = newStation1.name(); // adding station must fail because the frequency is the same as previously used frequency - mRadioStationModel->addStation( newStation1 ); - QVERIFY2((mRadioStationModel->rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 3"); + mUiEngine->stationModel().addStation( newStation1 ); + QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 3"); } /*! @@ -605,6 +627,7 @@ */ void TestRadioUiEngine::testAddStation3() { + FUNC_LOG; RadioStation newStation3; newStation3.setFrequency( KTestFrequency2 ); newStation3.setGenre(3); @@ -612,18 +635,18 @@ newStation3.setType( RadioStation::LocalStation | RadioStation::Favorite ); newStation3.setName("Radio e"); // adding station must fail because frequency is the same as previously used frequency - mExpectedStationCount = mRadioStationModel->rowCount(); + mExpectedStationCount = mUiEngine->stationModel().rowCount(); mStationToBeAdded = newStation3.name(); - mRadioStationModel->addStation( newStation3 ); - QVERIFY2((mRadioStationModel->rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 4"); + mUiEngine->stationModel().addStation( newStation3 ); + QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 4"); // adding station must success because the station frequency is different now newStation3.setFrequency( KTestFrequency2 + 1 ); - mExpectedStationCount = mRadioStationModel->rowCount() + 1; - mRadioStationModel->addStation( newStation3 ); - QVERIFY2((mRadioStationModel->rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 5"); + mExpectedStationCount = mUiEngine->stationModel().rowCount() + 1; + mUiEngine->stationModel().addStation( newStation3 ); + QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 5"); // test that station can be found by frequency range QList stations; - stations = mRadioStationModel->stationsInRange( KTestFrequency1, KTestFrequency3 ); + stations = mUiEngine->stationModel().stationsInRange( KTestFrequency1, KTestFrequency3 ); QVERIFY2((stations.count()==3), "API:RadioStationModel stationsInRange"); } @@ -632,34 +655,33 @@ */ void TestRadioUiEngine::testSaveStation3() { + FUNC_LOG; RadioStation newStation3; RadioStation foundStation; - QVERIFY2(mRadioStationModel->findFrequency( KTestFrequency2 + 1, newStation3 ), + QVERIFY2(mUiEngine->stationModel().findFrequency( KTestFrequency2 + 1, newStation3 ), "API:RadioStationModel findFrequency 4"); newStation3.setFrequency( KTestFrequency3 ); // because frequency or preset index don't have change flag the frequency must not be updated - mRadioStationModel->saveStation( newStation3 ); + mUiEngine->stationModel().saveStation( newStation3 ); - QVERIFY2(!(mRadioStationModel->findFrequency( KTestFrequency3, foundStation )), + QVERIFY2(!(mUiEngine->stationModel().findFrequency( KTestFrequency3, foundStation )), "API:RadioStationModel findFrequency 3"); - int stationGenre; - stationGenre = newStation3.genre(); newStation3.setGenre( newStation3.genre() + 1 ); // allthough genre changed so the frequency update must not become effective - mRadioStationModel->saveStation( newStation3 ); + mUiEngine->stationModel().saveStation( newStation3 ); - QVERIFY2(!(mRadioStationModel->findFrequency( KTestFrequency3, foundStation )), + QVERIFY2(!(mUiEngine->stationModel().findFrequency( KTestFrequency3, foundStation )), "API:RadioStationModel findFrequency 4"); mEnteredSlots = NoSlotsEntered; - foreach( const RadioStation& station, mRadioStationModel->list() ) + foreach( const RadioStation& station, mUiEngine->stationModel().list() ) { if ( station.frequency() == KTestFrequency2 ) { - mRadioStationModel->setFavoriteByFrequency( KTestFrequency2, !station.isFavorite() ); + mUiEngine->stationModel().setFavoriteByFrequency( KTestFrequency2, !station.isFavorite() ); } } bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && @@ -674,13 +696,14 @@ */ void TestRadioUiEngine::testSortByFrequency() { - int role = RadioStationModel::RadioStationRole; + FUNC_LOG; + int role = RadioRole::RadioStationRole; int previousFrequency(0); // int not initialized zero as default - for (int i = 0; i< mRadioStationModel->rowCount(); i++ ) + for (int i = 0; i< mUiEngine->stationModel().rowCount(); i++ ) { - QModelIndex index = mRadioStationModel->index( i, 0 ); - QVariant stationData = mRadioStationModel->data( index, role ); + QModelIndex index = mUiEngine->stationModel().index( i, 0 ); + QVariant stationData = mUiEngine->stationModel().data( index, role ); RadioStation station = stationData.value(); // stations must be obtainded at ascending frequency order QVERIFY2((station.frequency()>previousFrequency), "API:RadioStationModel testSortByFrequency"); @@ -693,12 +716,13 @@ */ void TestRadioUiEngine::testFindPresetIndex() { + FUNC_LOG; RadioStation station; - for (int i = 0; i< mRadioStationModel->rowCount(); i++ ) + for (int i = 0; i< mUiEngine->stationModel().rowCount(); i++ ) { - QVERIFY2((mRadioStationModel->findPresetIndex(i) != RadioStation::NotFound), + QVERIFY2((mUiEngine->stationModel().findPresetIndex(i) != RadioStation::NotFound), "API:RadioStationModel testFindPresetIndex 1"); - QVERIFY2((mRadioStationModel->findPresetIndex( i, station ) != RadioStation::NotFound), + QVERIFY2((mUiEngine->stationModel().findPresetIndex( i, station ) != RadioStation::NotFound), "API:RadioStationModel testFindPresetIndex 2"); QVERIFY2((station.presetIndex() == i), "API:RadioStationModel testFindPresetIndex 3"); } @@ -709,21 +733,22 @@ */ void TestRadioUiEngine::testRemoveByFrequency() { + FUNC_LOG; RadioStation station; - int initialStationCount( mRadioStationModel->rowCount() ); + int initialStationCount( mUiEngine->stationModel().rowCount() ); int presetIndex(0); // find valid preset index - for(int i = 0; irowCount(); i++) + for(int i = 0; istationModel().rowCount(); i++) { - presetIndex = mRadioStationModel->findPresetIndex( i, station ); + presetIndex = mUiEngine->stationModel().findPresetIndex( i, station ); if(presetIndex!=RadioStation::NotFound) break; } QVERIFY2((presetIndex != RadioStation::NotFound), "API:RadioStationModel testRemoveByFrequency 1"); - mRadioStationModel->removeByFrequency( station.frequency() ); - QVERIFY2((mRadioStationModel->rowCount()==(initialStationCount-1)), "API:RadioStationModel testRemoveByFrequency 2"); + mUiEngine->stationModel().removeByFrequency( station.frequency() ); + QVERIFY2((mUiEngine->stationModel().rowCount()==(initialStationCount-1)), "API:RadioStationModel testRemoveByFrequency 2"); } /*! @@ -731,18 +756,19 @@ */ void TestRadioUiEngine::testRemoveByPresetIndex() { + FUNC_LOG; RadioStation station; station.setFrequency( KTestFrequency4 ); mStationToBeAdded = ""; - mExpectedStationCount = mRadioStationModel->rowCount() + 1; - mRadioStationModel->addStation( station ); + mExpectedStationCount = mUiEngine->stationModel().rowCount() + 1; + mUiEngine->stationModel().addStation( station ); // for updating station preset index - QVERIFY2((mRadioStationModel->findFrequency( KTestFrequency4, station )), + QVERIFY2((mUiEngine->stationModel().findFrequency( KTestFrequency4, station )), "API:RadioStationModel testRemoveByPresetIndex 1"); - int initialStationCount( mRadioStationModel->rowCount() ); - mRadioStationModel->removeByPresetIndex( station.presetIndex() ); - QVERIFY2((mRadioStationModel->rowCount()==(initialStationCount-1)), "API:RadioStationModel testRemoveByPresetIndex 2"); + int initialStationCount( mUiEngine->stationModel().rowCount() ); + mUiEngine->stationModel().removeByPresetIndex( station.presetIndex() ); + QVERIFY2((mUiEngine->stationModel().rowCount()==(initialStationCount-1)), "API:RadioStationModel testRemoveByPresetIndex 2"); } /*! @@ -750,18 +776,19 @@ */ void TestRadioUiEngine::testRemoveStation() { + FUNC_LOG; RadioStation station; station.setFrequency( KTestFrequency5 ); mStationToBeAdded = ""; - mExpectedStationCount = mRadioStationModel->rowCount() + 1; - mRadioStationModel->addStation( station ); - int initialStationCount( mRadioStationModel->rowCount() ); + mExpectedStationCount = mUiEngine->stationModel().rowCount() + 1; + mUiEngine->stationModel().addStation( station ); + int initialStationCount( mUiEngine->stationModel().rowCount() ); // for updating station preset index - QVERIFY2(mRadioStationModel->findFrequency( KTestFrequency5, station ), + QVERIFY2(mUiEngine->stationModel().findFrequency( KTestFrequency5, station ), "API:RadioStationModel testRemoveStation"); - mRadioStationModel->removeStation( station ); - QVERIFY2((mRadioStationModel->rowCount()==(initialStationCount-1)), "API:RadioStationModel testRemoveStation"); + mUiEngine->stationModel().removeStation( station ); + QVERIFY2((mUiEngine->stationModel().rowCount()==(initialStationCount-1)), "API:RadioStationModel testRemoveStation"); } @@ -770,32 +797,33 @@ */ void TestRadioUiEngine::testSetFavorite() { + FUNC_LOG; RadioStation station; station.setFrequency( KTestFrequency6 ); station.setType( RadioStation::Favorite ); QVERIFY2(station.isFavorite(), "API:RadioStationModel testSetFavorite 1"); - mRadioStationModel->addStation( station ); + mUiEngine->stationModel().addStation( station ); mEnteredSlots = NoSlotsEntered; - mRadioStationModel->setFavoriteByFrequency( KTestFrequency6, false ); + mUiEngine->stationModel().setFavoriteByFrequency( KTestFrequency6, false ); bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && mEnteredSlots.testFlag( FavoriteChanged ) && mEnteredSlots.testFlag( DataChanged ); QVERIFY2(correctSignalsReceived, "API:RadioStationModel testSetFavorite 2"); - mRadioStationModel->findFrequency( KTestFrequency6, station ); + mUiEngine->stationModel().findFrequency( KTestFrequency6, station ); QVERIFY2(!station.isFavorite(), "API:RadioStationModel testSetFavorite 3"); mEnteredSlots = NoSlotsEntered; - mRadioStationModel->setFavoriteByPreset( station.presetIndex(), true ); + mUiEngine->stationModel().setFavoriteByPreset( station.presetIndex(), true ); correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && mEnteredSlots.testFlag( FavoriteChanged ) && mEnteredSlots.testFlag( DataChanged ); QVERIFY2(correctSignalsReceived, "API:RadioStationModel testSetFavorite 4"); // test toggling the favorite - QModelIndex index = mRadioStationModel->modelIndexFromFrequency( KTestFrequency6 ); - mRadioStationModel->setData( index, KTestFrequencyString6 ,RadioStationModel::ToggleFavoriteRole); - RadioStation station1 = mRadioStationModel->stationAt( index.row() ); - QVERIFY2(!station1.isFavorite(), "API:RadioStationModel testToggleFavourite"); + int index = mUiEngine->stationModel().indexFromFrequency( KTestFrequency6 ); + mUiEngine->stationModel().setFavoriteByFrequency( KTestFrequency6, ETrue ); + RadioStation station1 = mUiEngine->stationModel().stationAt( index ); + QVERIFY2(station1.isFavorite(), "API:RadioStationModel testToggleFavourite"); } @@ -804,12 +832,13 @@ */ void TestRadioUiEngine::testRenameStation() { + FUNC_LOG; RadioStation station; int presetIndex(0); // find valid preset index - for( int i = 0; irowCount(); i++ ) + for( int i = 0; istationModel().rowCount(); i++ ) { - if( mRadioStationModel->findPresetIndex( i, station ) != RadioStation::NotFound ) + if( mUiEngine->stationModel().findPresetIndex( i, station ) != RadioStation::NotFound ) { presetIndex = i; break; @@ -817,11 +846,11 @@ } QString initialStationName( station.name() ); mEnteredSlots = NoSlotsEntered; - mRadioStationModel->renameStation( presetIndex, initialStationName + "Renamed" ); + mUiEngine->stationModel().renameStation( presetIndex, initialStationName + "Renamed" ); bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && mEnteredSlots.testFlag( DataChanged ); QVERIFY2(correctSignalsReceived, "API:RadioStationModel testRenameStation 1"); - QVERIFY2(initialStationName!=mRadioStationModel->stationAt(presetIndex).name(), "API:RadioStationModel testRenameStation 2"); + QVERIFY2(initialStationName!=mUiEngine->stationModel().stationAt(presetIndex).name(), "API:RadioStationModel testRenameStation 2"); station.setUserDefinedName( KTestStationName2 ); QVERIFY2(station.isRenamed(), "API:RadioStationModel testRenameStation 1"); @@ -833,8 +862,9 @@ */ void TestRadioUiEngine::testSetRadioTextPlus() { + FUNC_LOG; RadioStation station; - mRadioStationModel->findFrequency( KTestFrequency6, station ); + mUiEngine->stationModel().findFrequency( KTestFrequency6, station ); station.setRadioText( "" ); station.setRadioText( KTestRadioTextRadioText ); station.setRadioText( KTestRadioTextRadioText ); @@ -842,7 +872,7 @@ station.setRadioTextPlus( RtPlus::Title, KTestRadioTextPlusTitle ); station.setRadioTextPlus( RtPlus::Homepage, KTestRadioTextPlusUrl ); station.setRadioTextPlus( RtPlus::Homepage + 1, KTestRadioTextPlusUnsupportedTag ); - mRadioStationModel->saveStation( station ); + mUiEngine->stationModel().saveStation( station ); bool effective = station.radioText().contains( KTestRadioTextPlusArtist, Qt::CaseSensitive ); QVERIFY2(effective, "API:RadioStationModel testSetRadioTextPlus 1"); effective = station.radioText().contains( KTestRadioTextPlusTitle, Qt::CaseSensitive ); @@ -856,6 +886,7 @@ */ void TestRadioUiEngine::testRadioStationModel() { + FUNC_LOG; testRadioStationModelInit(); testAddStation1(); testSaveStation1(); @@ -877,11 +908,9 @@ */ void TestRadioUiEngine::testhistoryModel() { + FUNC_LOG; testHistoryModelInit(); testHistoryModelAddItem(); - testHistoryModelFindItem(); - testHistoryModelUpdateItem(); - testHistoryModelSetData(); testAddRadioTextPlus(); testClearRadioTextPlus(); } @@ -891,13 +920,14 @@ */ void TestRadioUiEngine::testHistoryModelInit() { - //TODO:: Check why ASSERT fails when mhistoryModel->rowCount() == 0 - if( mhistoryModel->rowCount()>0 ) + FUNC_LOG; + //TODO:: Check why ASSERT fails when mUiEngine->historyModel().rowCount() == 0 + if( mUiEngine->historyModel().rowCount()>0 ) { - mhistoryModel->removeAll(); - QVERIFY2((mRadioStationModel->rowCount()==0), "API:RadioHistoryModel removeAll() 1"); + mUiEngine->historyModel().removeAll( EFalse ); + QVERIFY2((mUiEngine->stationModel().rowCount()==0), "API:RadioHistoryModel removeAll() 1"); } - QVERIFY2((mhistoryModel->rowCount()==0), "API:RadioHistoryModel removeAll() 2"); + QVERIFY2((mUiEngine->historyModel().rowCount()==0), "API:RadioHistoryModel removeAll() 2"); } /*! @@ -905,77 +935,26 @@ */ void TestRadioUiEngine::testHistoryModelAddItem() { - int expectedHistoryItemCount( mhistoryModel->rowCount() + 1 ); + FUNC_LOG; + RadioStation station; + mUiEngine->stationModel().findFrequency( KTestFrequency6, station ); + int expectedHistoryItemCount( mUiEngine->historyModel().rowCount() + 1 ); mEnteredSlots = NoSlotsEntered; - mhistoryModel->addItem( KTestArtist1, KTestTitle1 ); - bool correctSignalsReceived = mEnteredSlots.testFlag( ItemAdded ); - // check that correct signals received - QVERIFY2(correctSignalsReceived, "API:RadioHistoryModel addItem() 1"); + mUiEngine->historyModel().addItem( KTestArtist1, KTestTitle1, station ); // check that item count increases - QVERIFY2((mhistoryModel->rowCount()==expectedHistoryItemCount), "API:RadioHistoryModel addItem() 2"); + QVERIFY2((mUiEngine->historyModel().rowCount()==expectedHistoryItemCount), "API:RadioHistoryModel addItem() 2"); // check that artist/title stored into the model conforms to the one read from the model - QModelIndex index = mhistoryModel->index( 0, 0 ); - QStringList stringList = mhistoryModel->data( index, Qt::DisplayRole ).value(); + QModelIndex index = mUiEngine->historyModel().index( 0, 0 ); + QStringList stringList = mUiEngine->historyModel().data( index, Qt::DisplayRole ).value(); QString artistTitle = stringList.at(0); QVERIFY2(!(artistTitle.compare(KTestArtist1+" - "+KTestTitle1)), "API:RadioHistoryModel addItem() 3"); - expectedHistoryItemCount = mhistoryModel->rowCount(); + expectedHistoryItemCount = mUiEngine->historyModel().rowCount(); // trying to add an item that allready exists must not increase the item count - mhistoryModel->addItem( KTestArtist1, KTestTitle1 ); - QVERIFY2((mhistoryModel->rowCount()==expectedHistoryItemCount), "API:RadioHistoryModel addItem() 4"); -} - -/*! - * - */ -void TestRadioUiEngine::testHistoryModelFindItem() -{ - RadioHistoryItem item; - mhistoryModel->findItem( KTestArtist1, KTestTitle1, item ); - QVERIFY2((item.artist()==KTestArtist1), "API:RadioHistoryModel findItem() 1"); - QVERIFY2((item.title()==KTestTitle1), "API:RadioHistoryModel findItem() 2"); - // try to find an item that doesn't exist - int ret = mhistoryModel->findItem( KTestArtist1+"+", KTestTitle1, item ); - QVERIFY2(ret==-1, "API:RadioHistoryModel findItem() 3"); -} - -/*! - * - */ -void TestRadioUiEngine::testHistoryModelUpdateItem() -{ - RadioHistoryItem item; - mhistoryModel->findItem( KTestArtist1, KTestTitle1, item ); - item.setTitle( KTestTitle2 ); - // update an existing item - mhistoryModel->updateItem( 0, item, true ); - - RadioHistoryItem foundItem; - // original item must not be found any more - int ret = mhistoryModel->findItem(KTestArtist1, KTestTitle1, foundItem); - QVERIFY2(ret==-1, "API:RadioHistoryModel updateItem() 1"); - // but the updated one instead - mhistoryModel->findItem(KTestArtist1, KTestTitle2, foundItem); - QVERIFY2((foundItem.title()==KTestTitle2), "API:RadioHistoryModel updateItem() 2"); -} - -/*! - * - */ -void TestRadioUiEngine::testHistoryModelSetData() -{ - RadioHistoryItem foundItem; - mhistoryModel->findItem(KTestArtist1, KTestTitle2, foundItem); - QVERIFY2(!foundItem.isFavorite(), "API:RadioHistoryModel SetData() 1"); - - QModelIndex index = mhistoryModel->index( 0, 0 ); - QString artistTitle = KTestArtist1 + KTestTitle2; - mhistoryModel->setData( index, artistTitle, RadioHistoryModel::SetFavoriteRole ); - mhistoryModel->findItem(KTestArtist1, KTestTitle2, foundItem); - // item should be now favorite - QVERIFY2(foundItem.isFavorite(), "API:RadioHistoryModel SetData() 2"); + mUiEngine->historyModel().addItem( KTestArtist1, KTestTitle1, station ); + QVERIFY2((mUiEngine->historyModel().rowCount()==expectedHistoryItemCount), "API:RadioHistoryModel addItem() 4"); } /*! @@ -983,8 +962,11 @@ */ void TestRadioUiEngine::testAddRadioTextPlus() { - mhistoryModel->addRadioTextPlus( RtPlus::Artist, KTestArtist1 ); - mhistoryModel->addRadioTextPlus( RtPlus::Title, KTestTitle1 ); + FUNC_LOG; + RadioStation station; + mUiEngine->stationModel().findFrequency( KTestFrequency6, station ); + mUiEngine->historyModel().addRadioTextPlus( RtPlus::Artist, KTestArtist1, station ); + mUiEngine->historyModel().addRadioTextPlus( RtPlus::Title, KTestTitle1, station ); } /*! @@ -992,7 +974,8 @@ */ void TestRadioUiEngine::testClearRadioTextPlus() { - mhistoryModel->clearRadioTextPlus(); + FUNC_LOG; + mUiEngine->historyModel().clearRadioTextPlus(); } /*! @@ -1000,15 +983,15 @@ */ void TestRadioUiEngine::testHistoryModelItem() { + FUNC_LOG; RadioHistoryItem* item = new RadioHistoryItem( KTestArtist3, KTestTitle3 ); item->setArtist( KTestArtist3 ); QVERIFY2(!(item->artist().compare(KTestArtist3)), "API:testHistoryModelItem setArtist()"); item->setTitle( KTestTitle3 ); QVERIFY2(!(item->title().compare(KTestTitle3)), "API:testHistoryModelItem setTitle()"); - QVERIFY2(!item->isFavorite(), "API:testHistoryModelItem isFavorite() 1"); - item->setFavorite(); - QVERIFY2(item->isFavorite(), "API:testHistoryModelItem isFavorite() 2"); - item->setFavorite(); + QVERIFY2( item->isValid(), "API:testHistoryModelItem isValid() 1"); + item->reset(); + QVERIFY2(!item->isValid(), "API:testHistoryModelItem isValid() 2"); delete item; item = NULL; }