mmsharing/mmshengine/tsrc/ut_engine/src/ut_musengtelephoneutils.cpp
branchRCL_3
changeset 22 73a1feb507fb
parent 21 33a5d2bbf6fc
child 23 bc78a40cd63c
equal deleted inserted replaced
21:33a5d2bbf6fc 22:73a1feb507fb
    25 #include "musengtelephoneutils.h"
    25 #include "musengtelephoneutils.h"
    26 
    26 
    27 //  SYSTEM INCLUDES
    27 //  SYSTEM INCLUDES
    28 #include <digia/eunit/eunitmacros.h>
    28 #include <digia/eunit/eunitmacros.h>
    29 #include <centralrepository.h>
    29 #include <centralrepository.h>
    30 
    30 #include <e32property.h>
    31 
    31 
    32 
    32 
    33 
    33 
    34 // -----------------------------------------------------------------------------
    34 // -----------------------------------------------------------------------------
    35 //
    35 //
    93 // -----------------------------------------------------------------------------
    93 // -----------------------------------------------------------------------------
    94 //
    94 //
    95 void UT_CMusEngTelephoneUtils::SetupL()
    95 void UT_CMusEngTelephoneUtils::SetupL()
    96     {
    96     {
    97     iObserver = new( ELeave ) CMusEngObserverStub;
    97     iObserver = new( ELeave ) CMusEngObserverStub;
    98     iTelephoneUtils = CMusEngTelephoneUtils::NewL();
    98     iTelephoneUtils = CMusEngTelephoneUtils::NewL( *iObserver );
    99     }
    99     }
   100 
       
   101 
   100 
   102 // -----------------------------------------------------------------------------
   101 // -----------------------------------------------------------------------------
   103 //
   102 //
   104 // -----------------------------------------------------------------------------
   103 // -----------------------------------------------------------------------------
   105 //
   104 //
   106 void UT_CMusEngTelephoneUtils::Teardown()
   105 void UT_CMusEngTelephoneUtils::Teardown()
   107     {
   106     {
       
   107     delete iTelephoneUtils;
       
   108     iTelephoneUtils = NULL;
   108     delete iObserver;
   109     delete iObserver;
   109     delete iTelephoneUtils;
   110     iObserver = NULL;
   110     }
   111     PropertyHelper::Close();
   111 
   112     }
   112 
   113 
   113 
   114 
   114 // TEST CASES
   115 // TEST CASES  
   115 
       
   116 
       
   117 
       
   118     
       
   119 
   116 
   120 // -----------------------------------------------------------------------------
   117 // -----------------------------------------------------------------------------
   121 //
   118 //
   122 // -----------------------------------------------------------------------------
   119 // -----------------------------------------------------------------------------
   123 //
   120 //
   153                   CTelephonyAudioRouting::EWiredAudioAccessory;
   150                   CTelephonyAudioRouting::EWiredAudioAccessory;
   154     EUNIT_ASSERT( !iTelephoneUtils->AudioRoutingCanBeChanged() );
   151     EUNIT_ASSERT( !iTelephoneUtils->AudioRoutingCanBeChanged() );
   155     
   152     
   156     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
   153     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
   157                   CTelephonyAudioRouting::EBTAudioAccessory;
   154                   CTelephonyAudioRouting::EBTAudioAccessory;
   158     EUNIT_ASSERT( iTelephoneUtils->AudioRoutingCanBeChanged() );
   155     EUNIT_ASSERT( !iTelephoneUtils->AudioRoutingCanBeChanged() );
   159     
   156     
   160     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
   157     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
   161                   CTelephonyAudioRouting::ETTY;
   158                   CTelephonyAudioRouting::ETTY;
   162     EUNIT_ASSERT( !iTelephoneUtils->AudioRoutingCanBeChanged() );
   159     EUNIT_ASSERT( !iTelephoneUtils->AudioRoutingCanBeChanged() );         
   163             
   160     }
   164     }
   161 
   165     
   162 // -----------------------------------------------------------------------------
   166 
   163 //
   167 // -----------------------------------------------------------------------------
   164 // -----------------------------------------------------------------------------
   168 //
   165 //
   169 // -----------------------------------------------------------------------------
   166 void UT_CMusEngTelephoneUtils::UT_LoudspeakerLL()
   170 //	   
   167     {
   171 void UT_CMusEngTelephoneUtils::UT_IsAudioRoutingHeadsetL()
   168     // Precondition of test
   172     {
       
   173     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
       
   174                   CTelephonyAudioRouting::EBTAudioAccessory;
       
   175     EUNIT_ASSERT( iTelephoneUtils->IsAudioRoutingHeadset());
       
   176     
       
   177     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
       
   178                   CTelephonyAudioRouting::ENotActive;
       
   179     EUNIT_ASSERT( !iTelephoneUtils->IsAudioRoutingHeadset() );
       
   180        
       
   181     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
       
   182                   CTelephonyAudioRouting::ENone;
       
   183     EUNIT_ASSERT( !iTelephoneUtils->IsAudioRoutingHeadset() );
       
   184     
       
   185     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
   169     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
   186                   CTelephonyAudioRouting::EHandset;
   170                   CTelephonyAudioRouting::EHandset;
   187     EUNIT_ASSERT( !iTelephoneUtils->IsAudioRoutingHeadset() );
       
   188     
       
   189     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
       
   190                   CTelephonyAudioRouting::ELoudspeaker;
       
   191     EUNIT_ASSERT( !iTelephoneUtils->IsAudioRoutingHeadset() );
       
   192     
       
   193     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
       
   194                   CTelephonyAudioRouting::EWiredAudioAccessory;
       
   195     EUNIT_ASSERT( iTelephoneUtils->IsAudioRoutingHeadset() );
       
   196     
       
   197     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
       
   198                   CTelephonyAudioRouting::ETTY;
       
   199     EUNIT_ASSERT( !iTelephoneUtils->IsAudioRoutingHeadset() );
       
   200             
       
   201     }
       
   202 
       
   203 void UT_CMusEngTelephoneUtils::UT_IsAudioRoutingLoudSpeakerL()
       
   204 	{
       
   205 	iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
       
   206 	              CTelephonyAudioRouting::ELoudspeaker;
       
   207 	iTelephoneUtils->iAudioOutputAtStartup = 
       
   208 			      CTelephonyAudioRouting::ELoudspeaker;
       
   209 	EUNIT_ASSERT( !iTelephoneUtils->IsAudioRoutingLoudSpeaker());
       
   210 	
       
   211 	iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
       
   212 				  CTelephonyAudioRouting::ELoudspeaker;
       
   213 	iTelephoneUtils->iAudioOutputAtStartup = 
       
   214 			      CTelephonyAudioRouting::EHandset;
       
   215 	EUNIT_ASSERT( iTelephoneUtils->IsAudioRoutingLoudSpeaker() );
       
   216 	
       
   217 	iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
       
   218 				  CTelephonyAudioRouting::ELoudspeaker;
       
   219     iTelephoneUtils->iAudioOutputAtStartup = 
       
   220     		      CTelephonyAudioRouting::EBTAudioAccessory;
       
   221     EUNIT_ASSERT( iTelephoneUtils->IsAudioRoutingLoudSpeaker() );
       
   222 		
       
   223     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
       
   224                   CTelephonyAudioRouting::ELoudspeaker;
       
   225     iTelephoneUtils->iAudioOutputAtStartup = 
       
   226     		      CTelephonyAudioRouting::EWiredAudioAccessory;
       
   227     EUNIT_ASSERT( iTelephoneUtils->IsAudioRoutingLoudSpeaker() );
       
   228 	}
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void UT_CMusEngTelephoneUtils::UT_LoudspeakerLL()
       
   234     {
       
   235     // Precondition of test
       
   236     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
       
   237                   CTelephonyAudioRouting::EHandset;
       
   238     
   171     
   239     // Set loudspeaker on, succeeds
   172     // Set loudspeaker on, succeeds
   240     iTelephoneUtils->LoudspeakerL( ETrue, ETrue );
   173     iTelephoneUtils->LoudspeakerL( ETrue );
   241     EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput ==
   174     EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput ==
   242                   CTelephonyAudioRouting::ELoudspeaker );
   175                   CTelephonyAudioRouting::ELoudspeaker );
   243     EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iShowNoteMode ==
   176     EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iShowNoteMode ==
   244                   EFalse );
   177                   EFalse );
   245     EUNIT_ASSERT( iTelephoneUtils->iShowDialog == ETrue );
       
   246     
   178     
   247     // Change conditions
   179     // Change conditions
   248     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
   180     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
   249                   CTelephonyAudioRouting::EWiredAudioAccessory;              
   181                   CTelephonyAudioRouting::EWiredAudioAccessory;              
   250     
   182     
   251     // Try to set loudspeaker on, fails because current set is not handset
   183     // Try to set loudspeaker on, fails because current set is not handset
   252     iTelephoneUtils->LoudspeakerL( ETrue, ETrue );
   184     iTelephoneUtils->LoudspeakerL( ETrue );
   253     EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput ==
   185     EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput ==
   254                   CTelephonyAudioRouting::EWiredAudioAccessory );  
   186                   CTelephonyAudioRouting::EWiredAudioAccessory );  
   255     
   187     
   256     // Change conditions
   188     // Change conditions
   257     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
   189     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
   258                   CTelephonyAudioRouting::ELoudspeaker;           
   190                   CTelephonyAudioRouting::ELoudspeaker;           
   259     iTelephoneUtils->iAudioOutputAtStartup =
   191     iTelephoneUtils->iAudioOutputAtStartup =
   260                   CTelephonyAudioRouting::ELoudspeaker;  
   192                   CTelephonyAudioRouting::ELoudspeaker;  
   261                               
   193                               
   262     // Try to set loudspeaker off, goes to handset
   194     // Try to set loudspeaker off, goes to handset
   263     iTelephoneUtils->LoudspeakerL( EFalse, ETrue );   
   195     iTelephoneUtils->LoudspeakerL( EFalse );   
   264     EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput ==
   196     EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput ==
   265                   CTelephonyAudioRouting::EHandset );  
   197                   CTelephonyAudioRouting::EHandset );  
   266     
   198     
   267     // Change conditions
   199     // Change conditions
   268     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
   200     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
   269                   CTelephonyAudioRouting::ELoudspeaker;           
   201                   CTelephonyAudioRouting::ELoudspeaker;           
   270     iTelephoneUtils->iAudioOutputAtStartup =
   202     iTelephoneUtils->iAudioOutputAtStartup =
   271                   CTelephonyAudioRouting::EWiredAudioAccessory; 
   203                   CTelephonyAudioRouting::EWiredAudioAccessory; 
   272     
   204     
   273     // Try to set loudspeaker off, goes to wired
   205     // Try to set loudspeaker off, goes to wired
   274     iTelephoneUtils->LoudspeakerL( EFalse, ETrue );   
   206     iTelephoneUtils->LoudspeakerL( EFalse );   
   275     EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput ==
   207     EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput ==
   276                   CTelephonyAudioRouting::EWiredAudioAccessory ); 
   208                   CTelephonyAudioRouting::EWiredAudioAccessory ); 
   277     }
   209     }
   278 
   210 
   279 
       
   280 // -----------------------------------------------------------------------------
   211 // -----------------------------------------------------------------------------
   281 //
   212 //
   282 // -----------------------------------------------------------------------------
   213 // -----------------------------------------------------------------------------
   283 //
   214 //
   284 void UT_CMusEngTelephoneUtils::UT_IsLoudSpeakerEnabledL()
   215 void UT_CMusEngTelephoneUtils::UT_IsLoudSpeakerEnabledL()
   290     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
   221     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput =
   291                                         CTelephonyAudioRouting::EHandset;
   222                                         CTelephonyAudioRouting::EHandset;
   292     EUNIT_ASSERT( !iTelephoneUtils->IsLoudSpeakerEnabled() );
   223     EUNIT_ASSERT( !iTelephoneUtils->IsLoudSpeakerEnabled() );
   293     }
   224     }
   294 
   225 
   295 
       
   296 // -----------------------------------------------------------------------------
   226 // -----------------------------------------------------------------------------
   297 //
   227 //
   298 // -----------------------------------------------------------------------------
   228 // -----------------------------------------------------------------------------
   299 //
   229 //
   300 void UT_CMusEngTelephoneUtils::UT_GetVolumeLL()
   230 void UT_CMusEngTelephoneUtils::UT_GetVolumeLL()
   308                                         CTelephonyAudioRouting::ELoudspeaker;
   238                                         CTelephonyAudioRouting::ELoudspeaker;
   309     iTelephoneUtils->iRepository->Set( KTelIncallLoudspeakerVolume, 8 );
   239     iTelephoneUtils->iRepository->Set( KTelIncallLoudspeakerVolume, 8 );
   310     
   240     
   311     volume = iTelephoneUtils->GetVolumeL();
   241     volume = iTelephoneUtils->GetVolumeL();
   312     EUNIT_ASSERT( volume == 8 );
   242     EUNIT_ASSERT( volume == 8 );
   313     
   243     }
   314     }
       
   315 
       
   316 
   244 
   317 // -----------------------------------------------------------------------------
   245 // -----------------------------------------------------------------------------
   318 //
   246 //
   319 // -----------------------------------------------------------------------------
   247 // -----------------------------------------------------------------------------
   320 //
   248 //
   361     
   289     
   362     iTelephoneUtils->iRepository->Get( KTelIncallLoudspeakerVolume, 
   290     iTelephoneUtils->iRepository->Get( KTelIncallLoudspeakerVolume, 
   363                                        loudSpeakerVolume );
   291                                        loudSpeakerVolume );
   364     EUNIT_ASSERT( loudSpeakerVolume == 10 );
   292     EUNIT_ASSERT( loudSpeakerVolume == 10 );
   365     }
   293     }
   366 
       
   367 
   294 
   368 // -----------------------------------------------------------------------------
   295 // -----------------------------------------------------------------------------
   369 //
   296 //
   370 // -----------------------------------------------------------------------------
   297 // -----------------------------------------------------------------------------
   371 //
   298 //
   375     // call it to avoid coverage loss.
   302     // call it to avoid coverage loss.
   376     iTelephoneUtils->AvailableOutputsChanged(  
   303     iTelephoneUtils->AvailableOutputsChanged(  
   377                             *iTelephoneUtils->iTelephonyAudioRouting );
   304                             *iTelephoneUtils->iTelephonyAudioRouting );
   378     }
   305     }
   379 
   306 
   380 
       
   381 // -----------------------------------------------------------------------------
   307 // -----------------------------------------------------------------------------
   382 //
   308 //
   383 // -----------------------------------------------------------------------------
   309 // -----------------------------------------------------------------------------
   384 //
   310 //
   385 void UT_CMusEngTelephoneUtils::UT_OutputChangedL()
   311 void UT_CMusEngTelephoneUtils::UT_OutputChangedL()
   386     {
   312     {
       
   313     // Loudspeaker
   387     iTelephoneUtils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset;
   314     iTelephoneUtils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset;
   388     
   315     
   389     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = 
   316     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = 
   390                                         CTelephonyAudioRouting::ELoudspeaker;
   317         CTelephonyAudioRouting::ELoudspeaker;
   391     iTelephoneUtils->iRepository->Set( KTelIncallLoudspeakerVolume, 8 );
       
   392     EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 4 )
       
   393     EUNIT_ASSERT( iObserver->iVolume == 0 );
       
   394     
   318     
   395     iTelephoneUtils->OutputChanged( *iTelephoneUtils->iTelephonyAudioRouting );
   319     iTelephoneUtils->OutputChanged( *iTelephoneUtils->iTelephonyAudioRouting );
   396                                                                 
   320                                                                 
   397     EUNIT_ASSERT_EQUALS( iTelephoneUtils->iAudioOutputAtStartup, 
   321     EUNIT_ASSERT_EQUALS( iTelephoneUtils->iAudioOutputAtStartup, 
   398                          CTelephonyAudioRouting::ELoudspeaker )
   322                          CTelephonyAudioRouting::ELoudspeaker )
   399     
   323     EUNIT_ASSERT( iObserver->iAudioRoutingChangedCalled )
   400     EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 8 )
   324     
   401     EUNIT_ASSERT( iObserver->iVolume == 0 );
   325     // Handset   
   402     // Test observer
       
   403     
       
   404     iTelephoneUtils->SetAudioRoutingObserver( iObserver );
       
   405     iTelephoneUtils->SetVolumeChangeObserver(iObserver);
       
   406     
       
   407     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = 
   326     iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = 
   408                                         CTelephonyAudioRouting::EHandset;
   327         CTelephonyAudioRouting::EHandset;
   409     
   328     
   410     iTelephoneUtils->OutputChanged( *iTelephoneUtils->iTelephonyAudioRouting );
   329     iTelephoneUtils->OutputChanged( *iTelephoneUtils->iTelephonyAudioRouting );
   411     
   330                                                                 
   412     EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 4 )
       
   413     EUNIT_ASSERT( iObserver->iVolume == 4 );                                                               
       
   414     EUNIT_ASSERT_EQUALS( iTelephoneUtils->iAudioOutputAtStartup,
   331     EUNIT_ASSERT_EQUALS( iTelephoneUtils->iAudioOutputAtStartup,
   415                          CTelephonyAudioRouting::EHandset )
   332                          CTelephonyAudioRouting::EHandset )
   416     
   333     
   417     EUNIT_ASSERT( iObserver->iAudioRoutingChangedCalled )
   334     EUNIT_ASSERT( iObserver->iAudioRoutingChangedCalled )
   418     }
   335     }
   419 
   336 
   420 
       
   421 // -----------------------------------------------------------------------------
   337 // -----------------------------------------------------------------------------
   422 //
   338 //
   423 // -----------------------------------------------------------------------------
   339 // -----------------------------------------------------------------------------
   424 //
   340 //
   425 void UT_CMusEngTelephoneUtils::UT_SetOutputCompleteL()
   341 void UT_CMusEngTelephoneUtils::UT_SetOutputCompleteL()
   426     {
   342     {
   427     iTelephoneUtils->SetAudioRoutingObserver( iObserver );
       
   428     iTelephoneUtils->SetVolumeChangeObserver(iObserver);
       
   429     EUNIT_ASSERT( iObserver->iVolume == 0 );
       
   430     EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 4 )
       
   431 
       
   432     // Setoutput fails
   343     // Setoutput fails
   433     iTelephoneUtils->SetOutputComplete( 
   344     iTelephoneUtils->SetOutputComplete( 
   434                             *iTelephoneUtils->iTelephonyAudioRouting,
   345                             *iTelephoneUtils->iTelephonyAudioRouting,
   435                             KErrGeneral );
   346                             KErrGeneral );                         
   436                             
       
   437     EUNIT_ASSERT( !iObserver->iAudioRoutingChangedCalled )
   347     EUNIT_ASSERT( !iObserver->iAudioRoutingChangedCalled )
   438     EUNIT_ASSERT( iObserver->iVolume == 0 );
   348     iObserver->Reset();
   439     
   349     
   440     // Setoutput succesful and note is shown by audiorouting api
   350     // Setoutput ok
   441     // There's already next pending setoutput for which we are going to
       
   442     // show note -> that cannot be forgotten
       
   443     iTelephoneUtils->iRepository->Set( KTelIncallEarVolume, 5 );
       
   444     iTelephoneUtils->iShowDialog = ETrue;
       
   445     iTelephoneUtils->iTelephonyAudioRouting->SetShowNote( ETrue );
       
   446     iTelephoneUtils->SetOutputComplete( 
   351     iTelephoneUtils->SetOutputComplete( 
   447                             *iTelephoneUtils->iTelephonyAudioRouting,
   352                             *iTelephoneUtils->iTelephonyAudioRouting,
   448                             KErrNone );
   353                             KErrNone );
   449     EUNIT_ASSERT( iObserver->iAudioRoutingChangedCalled == ETrue )
   354     EUNIT_ASSERT( iObserver->iAudioRoutingChangedCalled )
   450     EUNIT_ASSERT( iObserver->iShowNote == EFalse )
   355     }
   451     EUNIT_ASSERT( iTelephoneUtils->iShowDialog == ETrue )
       
   452     EUNIT_ASSERT( iObserver->iVolume == 5 );
       
   453     EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 5 )
       
   454     
       
   455     iObserver->Reset();
       
   456     
       
   457     // Setoutput succesful and note is shown by us
       
   458     iTelephoneUtils->iTelephonyAudioRouting->SetShowNote( EFalse );
       
   459     iTelephoneUtils->SetOutputComplete( 
       
   460                             *iTelephoneUtils->iTelephonyAudioRouting,
       
   461                             KErrNone );
       
   462     EUNIT_ASSERT( iObserver->iAudioRoutingChangedCalled == ETrue )
       
   463     EUNIT_ASSERT( iObserver->iShowNote == ETrue )
       
   464     EUNIT_ASSERT( iTelephoneUtils->iShowDialog == EFalse )
       
   465     }
       
   466 
       
   467 
   356 
   468 // -----------------------------------------------------------------------------
   357 // -----------------------------------------------------------------------------
   469 //
   358 //
   470 // -----------------------------------------------------------------------------
   359 // -----------------------------------------------------------------------------
   471 //
   360 //
   474     EUNIT_ASSERT( iTelephoneUtils->ValidateVolume( 0 ) == 0 );
   363     EUNIT_ASSERT( iTelephoneUtils->ValidateVolume( 0 ) == 0 );
   475     EUNIT_ASSERT( iTelephoneUtils->ValidateVolume( 11 ) == 10 );
   364     EUNIT_ASSERT( iTelephoneUtils->ValidateVolume( 11 ) == 10 );
   476     EUNIT_ASSERT( iTelephoneUtils->ValidateVolume( 5 ) == 5 );
   365     EUNIT_ASSERT( iTelephoneUtils->ValidateVolume( 5 ) == 5 );
   477     }
   366     }
   478 
   367 
   479 
       
   480 // -----------------------------------------------------------------------------
   368 // -----------------------------------------------------------------------------
   481 // We cannot assert anything after destruction. All we can do is to make
   369 // We cannot assert anything after destruction. All we can do is to make
   482 // such condition before destruction that coverage will be achieved.
   370 // such condition before destruction that coverage will be achieved.
   483 // -----------------------------------------------------------------------------
   371 // -----------------------------------------------------------------------------
   484 //
   372 //
   485 void UT_CMusEngTelephoneUtils::UT_DestructorL()
   373 void UT_CMusEngTelephoneUtils::UT_DestructorL()
   486     {
   374     {
   487     // Simulate that 2nd phase construction has not succeeded
   375     // Simulate that 2nd phase construction has not succeeded
   488     CMusEngTelephoneUtils* utils = CMusEngTelephoneUtils::NewL();
   376     CMusEngTelephoneUtils* utils = CMusEngTelephoneUtils::NewL( *iObserver );
   489     CleanupStack::PushL( utils );
   377     CleanupStack::PushL( utils );
   490     delete utils->iTelephonyAudioRouting;
   378     delete utils->iTelephonyAudioRouting;
   491     utils->iTelephonyAudioRouting = NULL;
   379     utils->iTelephonyAudioRouting = NULL;
   492     CleanupStack::PopAndDestroy( utils );
   380     CleanupStack::PopAndDestroy( utils );
   493     
   381     
   494     // Simulate that current audio output mode is same as original
   382     // Simulate that current audio output mode is same as original
   495     utils = CMusEngTelephoneUtils::NewL();
   383     utils = CMusEngTelephoneUtils::NewL( *iObserver );
   496     CleanupStack::PushL( utils );
   384     CleanupStack::PushL( utils );
   497     utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset;
   385     utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset;
   498     utils->iTelephonyAudioRouting->iCurrentOutput = 
   386     utils->iTelephonyAudioRouting->iCurrentOutput = 
   499                                         CTelephonyAudioRouting::EHandset;
   387                                             CTelephonyAudioRouting::EHandset;
   500     CTelephonyAudioRouting::iPreviousOutput = 
       
   501                                         CTelephonyAudioRouting::ELoudspeaker;
       
   502     CleanupStack::PopAndDestroy( utils );
   388     CleanupStack::PopAndDestroy( utils );
   503     EUNIT_ASSERT( CTelephonyAudioRouting::iPreviousOutput == 
       
   504                   CTelephonyAudioRouting::ELoudspeaker )
       
   505     
   389     
   506     // Simulate that current audio output mode is not the same as original,
   390     // Simulate that current audio output mode is not the same as original,
   507     // Setting fails
   391     // Setting fails
   508     utils = CMusEngTelephoneUtils::NewL();
   392     utils = CMusEngTelephoneUtils::NewL( *iObserver );
   509     CleanupStack::PushL( utils );
   393     CleanupStack::PushL( utils );
   510     utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset;
   394     utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset;
   511     utils->iTelephonyAudioRouting->iCurrentOutput = 
   395     utils->iTelephonyAudioRouting->iCurrentOutput = 
   512                                     CTelephonyAudioRouting::ELoudspeaker;
   396                                     CTelephonyAudioRouting::ELoudspeaker;
   513     CTelephonyAudioRouting::iPreviousOutput = 
       
   514                                     CTelephonyAudioRouting::EHandset;
       
   515     utils->iTelephonyAudioRouting->iForceFailWithCode = KErrGeneral;
   397     utils->iTelephonyAudioRouting->iForceFailWithCode = KErrGeneral;
   516     CleanupStack::PopAndDestroy( utils );
   398     CleanupStack::PopAndDestroy( utils );
   517     EUNIT_ASSERT( CTelephonyAudioRouting::iPreviousOutput == 
       
   518                   CTelephonyAudioRouting::EHandset )
       
   519     EUNIT_ASSERT( CTelephonyAudioRouting::iCurrentOutput == 
       
   520                   CTelephonyAudioRouting::ELoudspeaker )
       
   521     
   399     
   522     // Simulate that current audio output mode is not the same as original,
   400     // Simulate that current audio output mode is not the same as original,
   523     // Setting succeeds
   401     // Setting succeeds
   524     utils = CMusEngTelephoneUtils::NewL();
   402     utils = CMusEngTelephoneUtils::NewL( *iObserver );
   525     CleanupStack::PushL( utils );
   403     CleanupStack::PushL( utils );
   526     utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset;
   404     utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset;
   527     utils->iTelephonyAudioRouting->iCurrentOutput = 
   405     utils->iTelephonyAudioRouting->iCurrentOutput = 
   528                                     CTelephonyAudioRouting::ELoudspeaker;
   406                                     CTelephonyAudioRouting::ELoudspeaker;
   529     CTelephonyAudioRouting::iPreviousOutput = 
       
   530                                     CTelephonyAudioRouting::EHandset;
       
   531     CleanupStack::PopAndDestroy( utils );
   407     CleanupStack::PopAndDestroy( utils );
   532     EUNIT_ASSERT( CTelephonyAudioRouting::iPreviousOutput == 
   408     
   533                   CTelephonyAudioRouting::ELoudspeaker )
       
   534     EUNIT_ASSERT( CTelephonyAudioRouting::iCurrentOutput == 
       
   535                   CTelephonyAudioRouting::EHandset )
       
   536     
       
   537     // Simulate that current audio output mode is not the same as original,
       
   538     // Setting not done due to special case handling (ENotActive)
       
   539     utils = CMusEngTelephoneUtils::NewL();
       
   540     CleanupStack::PushL( utils );
       
   541     utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset;
       
   542     utils->iTelephonyAudioRouting->iCurrentOutput = 
       
   543                                     CTelephonyAudioRouting::ENotActive;
       
   544     CTelephonyAudioRouting::iPreviousOutput = 
       
   545                                     CTelephonyAudioRouting::ELoudspeaker;
       
   546     CleanupStack::PopAndDestroy( utils );
       
   547     EUNIT_ASSERT( CTelephonyAudioRouting::iPreviousOutput == 
       
   548                   CTelephonyAudioRouting::ELoudspeaker )
       
   549     EUNIT_ASSERT( CTelephonyAudioRouting::iCurrentOutput == 
       
   550                   CTelephonyAudioRouting::ENotActive )                  
       
   551                   
       
   552     // Simulate that current audio output mode is not the same as original,
   409     // Simulate that current audio output mode is not the same as original,
   553     // Setting does not succeed as observer does not allow changes anymore
   410     // Setting does not succeed as observer does not allow changes anymore
   554     utils = CMusEngTelephoneUtils::NewL();
   411     utils = CMusEngTelephoneUtils::NewL( *iObserver );
   555     iObserver->iAudioRouteChangeAllowed = EFalse;
       
   556     utils->SetAudioRoutingObserver( iObserver );
       
   557     CleanupStack::PushL( utils );
   412     CleanupStack::PushL( utils );
   558     utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset;
   413     utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset;
   559     utils->iTelephonyAudioRouting->iCurrentOutput = 
   414     utils->iTelephonyAudioRouting->iCurrentOutput = 
   560                                     CTelephonyAudioRouting::ELoudspeaker;
   415                                     CTelephonyAudioRouting::ELoudspeaker;
   561     CTelephonyAudioRouting::iPreviousOutput = 
       
   562                                     CTelephonyAudioRouting::EHandset;
       
   563     CleanupStack::PopAndDestroy( utils );
   416     CleanupStack::PopAndDestroy( utils );
   564     EUNIT_ASSERT( CTelephonyAudioRouting::iPreviousOutput == 
   417     // Cannot really assert anything
   565                   CTelephonyAudioRouting::EHandset )
       
   566     EUNIT_ASSERT( CTelephonyAudioRouting::iCurrentOutput == 
       
   567                   CTelephonyAudioRouting::ELoudspeaker )
       
   568     }
       
   569 
       
   570 // -----------------------------------------------------------------------------
       
   571 //
       
   572 // -----------------------------------------------------------------------------
       
   573 //
       
   574 void UT_CMusEngTelephoneUtils::UT_UpdateCurrentVolumeL()
       
   575     {    
       
   576     //Volume changed, no observer
       
   577     EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 4 )
       
   578     iTelephoneUtils->iRepository->Set( KTelIncallEarVolume, 5 );
       
   579     iTelephoneUtils->UpdateCurrentVolume(EFalse);
       
   580     EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 5 )
       
   581     EUNIT_ASSERT( iObserver->iVolume == 0 );
       
   582 
       
   583     //Volume changed, observer set
       
   584     iTelephoneUtils->SetVolumeChangeObserver(iObserver);
       
   585     iTelephoneUtils->iRepository->Set( KTelIncallEarVolume, 6 );
       
   586     iTelephoneUtils->UpdateCurrentVolume(EFalse);
       
   587     EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 6 )
       
   588     EUNIT_ASSERT( iObserver->iVolume == 6 );
       
   589 
       
   590     //Volume didn't change, observer not notified
       
   591     iObserver->iVolume = 0;
       
   592     iTelephoneUtils->UpdateCurrentVolume(EFalse);
       
   593     EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 6 )
       
   594     EUNIT_ASSERT( iObserver->iVolume == 0 );    
       
   595     }
       
   596 
       
   597 // -----------------------------------------------------------------------------
       
   598 //
       
   599 // -----------------------------------------------------------------------------
       
   600 //
       
   601 void UT_CMusEngTelephoneUtils::UT_HandleNotifyGenericL()
       
   602     {
       
   603     //Loudspeakers volume changed, no observer
       
   604     iTelephoneUtils->iRepository->Set( KTelIncallLoudspeakerVolume, 8 );
       
   605     EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 4 )
       
   606     iTelephoneUtils->HandleNotifyGeneric(KTelIncallLoudspeakerVolume);    
       
   607     EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 8 )
       
   608     EUNIT_ASSERT( iObserver->iVolume == 0 );
       
   609     
       
   610     //Ear volume changed, observer set => observer notified
       
   611     iTelephoneUtils->SetVolumeChangeObserver(iObserver);
       
   612     iTelephoneUtils->HandleNotifyGeneric(KTelIncallEarVolume);    
       
   613     EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 4 )
       
   614     EUNIT_ASSERT( iObserver->iVolume == 4 );
       
   615     
       
   616     //Volume hasn't changed => observer not notifies
       
   617     iObserver->iVolume = 0;
       
   618     iTelephoneUtils->HandleNotifyGeneric(KTelIncallEarVolume);    
       
   619     EUNIT_ASSERT( iTelephoneUtils->iCurrentVolume == 4 )
       
   620     EUNIT_ASSERT( iObserver->iVolume == 0 );
       
   621     }
   418     }
   622 
   419 
   623 
   420 
   624 //  TEST TABLE
   421 //  TEST TABLE
   625 
   422 
   641     "AudioRoutingCanBeChanged",
   438     "AudioRoutingCanBeChanged",
   642     "FUNCTIONALITY",
   439     "FUNCTIONALITY",
   643     SetupL, UT_AudioRoutingCanBeChangedL, Teardown)
   440     SetupL, UT_AudioRoutingCanBeChangedL, Teardown)
   644 
   441 
   645 EUNIT_TEST(
   442 EUNIT_TEST(
   646     "IsAudioRoutingHeadset - test ",
       
   647     "CMusEngTelephoneUtils",
       
   648     "IsAudioRoutingHeadset",
       
   649     "FUNCTIONALITY",
       
   650     SetupL, UT_IsAudioRoutingHeadsetL, Teardown)
       
   651     
       
   652 EUNIT_TEST(
       
   653     "IsAudioRoutingLoudSpeaker - test ",
       
   654     "CMusEngTelephoneUtils",
       
   655     "IsAudioRoutingLoudSpeaker",
       
   656     "FUNCTIONALITY",
       
   657     SetupL, UT_IsAudioRoutingLoudSpeakerL, Teardown)    
       
   658     
       
   659 EUNIT_TEST(
       
   660     "LoudspeakerL - test ",
   443     "LoudspeakerL - test ",
   661     "CMusEngTelephoneUtils",
   444     "CMusEngTelephoneUtils",
   662     "LoudspeakerL",
   445     "LoudspeakerL",
   663     "FUNCTIONALITY",
   446     "FUNCTIONALITY",
   664     SetupL, UT_LoudspeakerLL, Teardown)
   447     SetupL, UT_LoudspeakerLL, Teardown)
   717     "CMusEngTelephoneUtils",
   500     "CMusEngTelephoneUtils",
   718     "Destructor",
   501     "Destructor",
   719     "FUNCTIONALITY",
   502     "FUNCTIONALITY",
   720     SetupL, UT_DestructorL, Teardown)
   503     SetupL, UT_DestructorL, Teardown)
   721 
   504 
   722 EUNIT_TEST(
   505      
   723     "UpdateCurrentVolume - test ",
       
   724     "UpdateCurrentVolume",
       
   725     "Destructor",
       
   726     "FUNCTIONALITY",
       
   727     SetupL, UT_UpdateCurrentVolumeL, Teardown)
       
   728     
       
   729 EUNIT_TEST(
       
   730     "HandleNotifyGeneric - test ",
       
   731     "CMusEngTelephoneUtils",
       
   732     "HandleNotifyGeneric",
       
   733     "FUNCTIONALITY",
       
   734     SetupL, UT_HandleNotifyGenericL, Teardown)
       
   735 
       
   736     
   506     
   737 EUNIT_END_TEST_TABLE
   507 EUNIT_END_TEST_TABLE
   738 
   508 
   739 //  END OF FILE
   509 //  END OF FILE
   740 
   510