diff -r 33a5d2bbf6fc -r 73a1feb507fb mmsharing/mmshengine/tsrc/ut_engine/src/ut_musengtelephoneutils.cpp --- a/mmsharing/mmshengine/tsrc/ut_engine/src/ut_musengtelephoneutils.cpp Thu Aug 19 09:51:39 2010 +0300 +++ b/mmsharing/mmshengine/tsrc/ut_engine/src/ut_musengtelephoneutils.cpp Tue Aug 31 15:12:07 2010 +0300 @@ -27,7 +27,7 @@ // SYSTEM INCLUDES #include #include - +#include @@ -95,27 +95,24 @@ void UT_CMusEngTelephoneUtils::SetupL() { iObserver = new( ELeave ) CMusEngObserverStub; - iTelephoneUtils = CMusEngTelephoneUtils::NewL(); + iTelephoneUtils = CMusEngTelephoneUtils::NewL( *iObserver ); } - // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- // void UT_CMusEngTelephoneUtils::Teardown() { + delete iTelephoneUtils; + iTelephoneUtils = NULL; delete iObserver; - delete iTelephoneUtils; + iObserver = NULL; + PropertyHelper::Close(); } - -// TEST CASES - - - - +// TEST CASES // ----------------------------------------------------------------------------- // @@ -155,77 +152,13 @@ iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = CTelephonyAudioRouting::EBTAudioAccessory; - EUNIT_ASSERT( iTelephoneUtils->AudioRoutingCanBeChanged() ); + EUNIT_ASSERT( !iTelephoneUtils->AudioRoutingCanBeChanged() ); iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = CTelephonyAudioRouting::ETTY; - EUNIT_ASSERT( !iTelephoneUtils->AudioRoutingCanBeChanged() ); - - } - - -// ----------------------------------------------------------------------------- -// -// ----------------------------------------------------------------------------- -// -void UT_CMusEngTelephoneUtils::UT_IsAudioRoutingHeadsetL() - { - iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::EBTAudioAccessory; - EUNIT_ASSERT( iTelephoneUtils->IsAudioRoutingHeadset()); - - iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::ENotActive; - EUNIT_ASSERT( !iTelephoneUtils->IsAudioRoutingHeadset() ); - - iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::ENone; - EUNIT_ASSERT( !iTelephoneUtils->IsAudioRoutingHeadset() ); - - iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::EHandset; - EUNIT_ASSERT( !iTelephoneUtils->IsAudioRoutingHeadset() ); - - iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::ELoudspeaker; - EUNIT_ASSERT( !iTelephoneUtils->IsAudioRoutingHeadset() ); - - iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::EWiredAudioAccessory; - EUNIT_ASSERT( iTelephoneUtils->IsAudioRoutingHeadset() ); - - iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::ETTY; - EUNIT_ASSERT( !iTelephoneUtils->IsAudioRoutingHeadset() ); - + EUNIT_ASSERT( !iTelephoneUtils->AudioRoutingCanBeChanged() ); } -void UT_CMusEngTelephoneUtils::UT_IsAudioRoutingLoudSpeakerL() - { - iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::ELoudspeaker; - iTelephoneUtils->iAudioOutputAtStartup = - CTelephonyAudioRouting::ELoudspeaker; - EUNIT_ASSERT( !iTelephoneUtils->IsAudioRoutingLoudSpeaker()); - - iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::ELoudspeaker; - iTelephoneUtils->iAudioOutputAtStartup = - CTelephonyAudioRouting::EHandset; - EUNIT_ASSERT( iTelephoneUtils->IsAudioRoutingLoudSpeaker() ); - - iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::ELoudspeaker; - iTelephoneUtils->iAudioOutputAtStartup = - CTelephonyAudioRouting::EBTAudioAccessory; - EUNIT_ASSERT( iTelephoneUtils->IsAudioRoutingLoudSpeaker() ); - - iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::ELoudspeaker; - iTelephoneUtils->iAudioOutputAtStartup = - CTelephonyAudioRouting::EWiredAudioAccessory; - EUNIT_ASSERT( iTelephoneUtils->IsAudioRoutingLoudSpeaker() ); - } // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -237,19 +170,18 @@ CTelephonyAudioRouting::EHandset; // Set loudspeaker on, succeeds - iTelephoneUtils->LoudspeakerL( ETrue, ETrue ); + iTelephoneUtils->LoudspeakerL( ETrue ); EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput == CTelephonyAudioRouting::ELoudspeaker ); EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iShowNoteMode == EFalse ); - EUNIT_ASSERT( iTelephoneUtils->iShowDialog == ETrue ); // Change conditions iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = CTelephonyAudioRouting::EWiredAudioAccessory; // Try to set loudspeaker on, fails because current set is not handset - iTelephoneUtils->LoudspeakerL( ETrue, ETrue ); + iTelephoneUtils->LoudspeakerL( ETrue ); EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput == CTelephonyAudioRouting::EWiredAudioAccessory ); @@ -260,7 +192,7 @@ CTelephonyAudioRouting::ELoudspeaker; // Try to set loudspeaker off, goes to handset - iTelephoneUtils->LoudspeakerL( EFalse, ETrue ); + iTelephoneUtils->LoudspeakerL( EFalse ); EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput == CTelephonyAudioRouting::EHandset ); @@ -271,12 +203,11 @@ CTelephonyAudioRouting::EWiredAudioAccessory; // Try to set loudspeaker off, goes to wired - iTelephoneUtils->LoudspeakerL( EFalse, ETrue ); + iTelephoneUtils->LoudspeakerL( EFalse ); EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput == CTelephonyAudioRouting::EWiredAudioAccessory ); } - // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -292,7 +223,6 @@ EUNIT_ASSERT( !iTelephoneUtils->IsLoudSpeakerEnabled() ); } - // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -310,10 +240,8 @@ volume = iTelephoneUtils->GetVolumeL(); EUNIT_ASSERT( volume == 8 ); - } - // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -364,7 +292,6 @@ EUNIT_ASSERT( loudSpeakerVolume == 10 ); } - // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -377,94 +304,56 @@ *iTelephoneUtils->iTelephonyAudioRouting ); } - // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- // void UT_CMusEngTelephoneUtils::UT_OutputChangedL() { + // Loudspeaker iTelephoneUtils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset; iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::ELoudspeaker; - iTelephoneUtils->iRepository->Set( KTelIncallLoudspeakerVolume, 8 ); - EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 4 ) - EUNIT_ASSERT( iObserver->iVolume == 0 ); + CTelephonyAudioRouting::ELoudspeaker; iTelephoneUtils->OutputChanged( *iTelephoneUtils->iTelephonyAudioRouting ); EUNIT_ASSERT_EQUALS( iTelephoneUtils->iAudioOutputAtStartup, CTelephonyAudioRouting::ELoudspeaker ) - - EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 8 ) - EUNIT_ASSERT( iObserver->iVolume == 0 ); - // Test observer + EUNIT_ASSERT( iObserver->iAudioRoutingChangedCalled ) - iTelephoneUtils->SetAudioRoutingObserver( iObserver ); - iTelephoneUtils->SetVolumeChangeObserver(iObserver); - + // Handset iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::EHandset; + CTelephonyAudioRouting::EHandset; iTelephoneUtils->OutputChanged( *iTelephoneUtils->iTelephonyAudioRouting ); - - EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 4 ) - EUNIT_ASSERT( iObserver->iVolume == 4 ); + EUNIT_ASSERT_EQUALS( iTelephoneUtils->iAudioOutputAtStartup, CTelephonyAudioRouting::EHandset ) EUNIT_ASSERT( iObserver->iAudioRoutingChangedCalled ) } - // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- // void UT_CMusEngTelephoneUtils::UT_SetOutputCompleteL() { - iTelephoneUtils->SetAudioRoutingObserver( iObserver ); - iTelephoneUtils->SetVolumeChangeObserver(iObserver); - EUNIT_ASSERT( iObserver->iVolume == 0 ); - EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 4 ) - // Setoutput fails iTelephoneUtils->SetOutputComplete( *iTelephoneUtils->iTelephonyAudioRouting, - KErrGeneral ); - + KErrGeneral ); EUNIT_ASSERT( !iObserver->iAudioRoutingChangedCalled ) - EUNIT_ASSERT( iObserver->iVolume == 0 ); + iObserver->Reset(); - // Setoutput succesful and note is shown by audiorouting api - // There's already next pending setoutput for which we are going to - // show note -> that cannot be forgotten - iTelephoneUtils->iRepository->Set( KTelIncallEarVolume, 5 ); - iTelephoneUtils->iShowDialog = ETrue; - iTelephoneUtils->iTelephonyAudioRouting->SetShowNote( ETrue ); + // Setoutput ok iTelephoneUtils->SetOutputComplete( *iTelephoneUtils->iTelephonyAudioRouting, KErrNone ); - EUNIT_ASSERT( iObserver->iAudioRoutingChangedCalled == ETrue ) - EUNIT_ASSERT( iObserver->iShowNote == EFalse ) - EUNIT_ASSERT( iTelephoneUtils->iShowDialog == ETrue ) - EUNIT_ASSERT( iObserver->iVolume == 5 ); - EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 5 ) - - iObserver->Reset(); - - // Setoutput succesful and note is shown by us - iTelephoneUtils->iTelephonyAudioRouting->SetShowNote( EFalse ); - iTelephoneUtils->SetOutputComplete( - *iTelephoneUtils->iTelephonyAudioRouting, - KErrNone ); - EUNIT_ASSERT( iObserver->iAudioRoutingChangedCalled == ETrue ) - EUNIT_ASSERT( iObserver->iShowNote == ETrue ) - EUNIT_ASSERT( iTelephoneUtils->iShowDialog == EFalse ) + EUNIT_ASSERT( iObserver->iAudioRoutingChangedCalled ) } - // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -476,7 +365,6 @@ EUNIT_ASSERT( iTelephoneUtils->ValidateVolume( 5 ) == 5 ); } - // ----------------------------------------------------------------------------- // We cannot assert anything after destruction. All we can do is to make // such condition before destruction that coverage will be achieved. @@ -485,139 +373,48 @@ void UT_CMusEngTelephoneUtils::UT_DestructorL() { // Simulate that 2nd phase construction has not succeeded - CMusEngTelephoneUtils* utils = CMusEngTelephoneUtils::NewL(); + CMusEngTelephoneUtils* utils = CMusEngTelephoneUtils::NewL( *iObserver ); CleanupStack::PushL( utils ); delete utils->iTelephonyAudioRouting; utils->iTelephonyAudioRouting = NULL; CleanupStack::PopAndDestroy( utils ); // Simulate that current audio output mode is same as original - utils = CMusEngTelephoneUtils::NewL(); + utils = CMusEngTelephoneUtils::NewL( *iObserver ); CleanupStack::PushL( utils ); utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset; utils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::EHandset; - CTelephonyAudioRouting::iPreviousOutput = - CTelephonyAudioRouting::ELoudspeaker; + CTelephonyAudioRouting::EHandset; CleanupStack::PopAndDestroy( utils ); - EUNIT_ASSERT( CTelephonyAudioRouting::iPreviousOutput == - CTelephonyAudioRouting::ELoudspeaker ) // Simulate that current audio output mode is not the same as original, // Setting fails - utils = CMusEngTelephoneUtils::NewL(); - CleanupStack::PushL( utils ); - utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset; - utils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::ELoudspeaker; - CTelephonyAudioRouting::iPreviousOutput = - CTelephonyAudioRouting::EHandset; - utils->iTelephonyAudioRouting->iForceFailWithCode = KErrGeneral; - CleanupStack::PopAndDestroy( utils ); - EUNIT_ASSERT( CTelephonyAudioRouting::iPreviousOutput == - CTelephonyAudioRouting::EHandset ) - EUNIT_ASSERT( CTelephonyAudioRouting::iCurrentOutput == - CTelephonyAudioRouting::ELoudspeaker ) - - // Simulate that current audio output mode is not the same as original, - // Setting succeeds - utils = CMusEngTelephoneUtils::NewL(); + utils = CMusEngTelephoneUtils::NewL( *iObserver ); CleanupStack::PushL( utils ); utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset; utils->iTelephonyAudioRouting->iCurrentOutput = CTelephonyAudioRouting::ELoudspeaker; - CTelephonyAudioRouting::iPreviousOutput = - CTelephonyAudioRouting::EHandset; + utils->iTelephonyAudioRouting->iForceFailWithCode = KErrGeneral; CleanupStack::PopAndDestroy( utils ); - EUNIT_ASSERT( CTelephonyAudioRouting::iPreviousOutput == - CTelephonyAudioRouting::ELoudspeaker ) - EUNIT_ASSERT( CTelephonyAudioRouting::iCurrentOutput == - CTelephonyAudioRouting::EHandset ) // Simulate that current audio output mode is not the same as original, - // Setting not done due to special case handling (ENotActive) - utils = CMusEngTelephoneUtils::NewL(); - CleanupStack::PushL( utils ); - utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset; - utils->iTelephonyAudioRouting->iCurrentOutput = - CTelephonyAudioRouting::ENotActive; - CTelephonyAudioRouting::iPreviousOutput = - CTelephonyAudioRouting::ELoudspeaker; - CleanupStack::PopAndDestroy( utils ); - EUNIT_ASSERT( CTelephonyAudioRouting::iPreviousOutput == - CTelephonyAudioRouting::ELoudspeaker ) - EUNIT_ASSERT( CTelephonyAudioRouting::iCurrentOutput == - CTelephonyAudioRouting::ENotActive ) - - // Simulate that current audio output mode is not the same as original, - // Setting does not succeed as observer does not allow changes anymore - utils = CMusEngTelephoneUtils::NewL(); - iObserver->iAudioRouteChangeAllowed = EFalse; - utils->SetAudioRoutingObserver( iObserver ); + // Setting succeeds + utils = CMusEngTelephoneUtils::NewL( *iObserver ); CleanupStack::PushL( utils ); utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset; utils->iTelephonyAudioRouting->iCurrentOutput = CTelephonyAudioRouting::ELoudspeaker; - CTelephonyAudioRouting::iPreviousOutput = - CTelephonyAudioRouting::EHandset; CleanupStack::PopAndDestroy( utils ); - EUNIT_ASSERT( CTelephonyAudioRouting::iPreviousOutput == - CTelephonyAudioRouting::EHandset ) - EUNIT_ASSERT( CTelephonyAudioRouting::iCurrentOutput == - CTelephonyAudioRouting::ELoudspeaker ) - } - -// ----------------------------------------------------------------------------- -// -// ----------------------------------------------------------------------------- -// -void UT_CMusEngTelephoneUtils::UT_UpdateCurrentVolumeL() - { - //Volume changed, no observer - EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 4 ) - iTelephoneUtils->iRepository->Set( KTelIncallEarVolume, 5 ); - iTelephoneUtils->UpdateCurrentVolume(EFalse); - EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 5 ) - EUNIT_ASSERT( iObserver->iVolume == 0 ); - - //Volume changed, observer set - iTelephoneUtils->SetVolumeChangeObserver(iObserver); - iTelephoneUtils->iRepository->Set( KTelIncallEarVolume, 6 ); - iTelephoneUtils->UpdateCurrentVolume(EFalse); - EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 6 ) - EUNIT_ASSERT( iObserver->iVolume == 6 ); - - //Volume didn't change, observer not notified - iObserver->iVolume = 0; - iTelephoneUtils->UpdateCurrentVolume(EFalse); - EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 6 ) - EUNIT_ASSERT( iObserver->iVolume == 0 ); - } - -// ----------------------------------------------------------------------------- -// -// ----------------------------------------------------------------------------- -// -void UT_CMusEngTelephoneUtils::UT_HandleNotifyGenericL() - { - //Loudspeakers volume changed, no observer - iTelephoneUtils->iRepository->Set( KTelIncallLoudspeakerVolume, 8 ); - EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 4 ) - iTelephoneUtils->HandleNotifyGeneric(KTelIncallLoudspeakerVolume); - EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 8 ) - EUNIT_ASSERT( iObserver->iVolume == 0 ); - //Ear volume changed, observer set => observer notified - iTelephoneUtils->SetVolumeChangeObserver(iObserver); - iTelephoneUtils->HandleNotifyGeneric(KTelIncallEarVolume); - EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 4 ) - EUNIT_ASSERT( iObserver->iVolume == 4 ); - - //Volume hasn't changed => observer not notifies - iObserver->iVolume = 0; - iTelephoneUtils->HandleNotifyGeneric(KTelIncallEarVolume); - EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 4 ) - EUNIT_ASSERT( iObserver->iVolume == 0 ); + // Simulate that current audio output mode is not the same as original, + // Setting does not succeed as observer does not allow changes anymore + utils = CMusEngTelephoneUtils::NewL( *iObserver ); + CleanupStack::PushL( utils ); + utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset; + utils->iTelephonyAudioRouting->iCurrentOutput = + CTelephonyAudioRouting::ELoudspeaker; + CleanupStack::PopAndDestroy( utils ); + // Cannot really assert anything } @@ -643,20 +440,6 @@ SetupL, UT_AudioRoutingCanBeChangedL, Teardown) EUNIT_TEST( - "IsAudioRoutingHeadset - test ", - "CMusEngTelephoneUtils", - "IsAudioRoutingHeadset", - "FUNCTIONALITY", - SetupL, UT_IsAudioRoutingHeadsetL, Teardown) - -EUNIT_TEST( - "IsAudioRoutingLoudSpeaker - test ", - "CMusEngTelephoneUtils", - "IsAudioRoutingLoudSpeaker", - "FUNCTIONALITY", - SetupL, UT_IsAudioRoutingLoudSpeakerL, Teardown) - -EUNIT_TEST( "LoudspeakerL - test ", "CMusEngTelephoneUtils", "LoudspeakerL", @@ -719,20 +502,7 @@ "FUNCTIONALITY", SetupL, UT_DestructorL, Teardown) -EUNIT_TEST( - "UpdateCurrentVolume - test ", - "UpdateCurrentVolume", - "Destructor", - "FUNCTIONALITY", - SetupL, UT_UpdateCurrentVolumeL, Teardown) - -EUNIT_TEST( - "HandleNotifyGeneric - test ", - "CMusEngTelephoneUtils", - "HandleNotifyGeneric", - "FUNCTIONALITY", - SetupL, UT_HandleNotifyGenericL, Teardown) - + EUNIT_END_TEST_TABLE