mmsharing/mmshengine/tsrc/ut_engine/src/ut_musengoutsession.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
    18 
    18 
    19 //  INTERNAL INCLUDES
    19 //  INTERNAL INCLUDES
    20 #include "ut_musengoutsession.h"
    20 #include "ut_musengoutsession.h"
    21 #include "musengstubs.h"
    21 #include "musengstubs.h"
    22 #include "musengtestdefs.h"
    22 #include "musengtestdefs.h"
    23 #include "sipprofile.h"
    23 
    24 #include "musenglivesession.h"
    24 #include "musenglivesession.h"
    25 #include "musengclipsession.h"
    25 #include "musengclipsession.h"
    26 #include "mussipprofilehandler.h"
    26 #include "mussipprofilehandler.h"
    27 #include "mussessionproperties.h"
    27 
    28 #include "contactenginestub.h"
       
    29 
    28 
    30 //  SYSTEM INCLUDES
    29 //  SYSTEM INCLUDES
    31 #include <lcsourcefilecontrol.h>
       
    32 #include <digia/eunit/eunitmacros.h>
    30 #include <digia/eunit/eunitmacros.h>
       
    31 
    33 #include <mceoutsession.h>
    32 #include <mceoutsession.h>
    34 #include <mcestreambundle.h>
    33 #include <mcestreambundle.h>
    35 #include <mceaudiostream.h>
    34 #include <mceaudiostream.h>
    36 #include <mcevideostream.h>
    35 #include <mcevideostream.h>
    37 #include <mcespeakersink.h>
    36 #include <mcespeakersink.h>
    38 #include <mcedisplaysink.h>
    37 #include <mcedisplaysink.h>
    39 #include <mceh263codec.h>
    38 #include <mceh263codec.h>
    40 #include <mceavccodec.h>
    39 #include <mceavccodec.h>
    41 #include <mceaudiocodec.h>
    40 #include <mceaudiocodec.h>
    42 #include <mcecamerasource.h>
    41 
    43 
    42 #include <sipprofile.h>
    44 
       
    45 #include <sipstrings.h>
    43 #include <sipstrings.h>
    46 
    44 
    47 #include <audiopreference.h>
    45 #include <audiopreference.h>
    48 #include <uri8.h>
    46 #include <uri8.h>
    49 
    47 
    50 _LIT( KTestContactName, "nokia" );
       
    51 
    48 
    52 // -----------------------------------------------------------------------------
    49 // -----------------------------------------------------------------------------
    53 //
    50 //
    54 // -----------------------------------------------------------------------------
    51 // -----------------------------------------------------------------------------
    55 //
    52 //
   110 //
   107 //
   111 // -----------------------------------------------------------------------------
   108 // -----------------------------------------------------------------------------
   112 //
   109 //
   113 void UT_CMusEngOutSession::SetupL()
   110 void UT_CMusEngOutSession::SetupL()
   114     {
   111     {
   115     
   112     iObserver = new( ELeave ) CMusEngObserverStub;
   116     PropertyHelper::SetErrorCode( KErrNone );
   113     iLiveSession = CMusEngLiveSession::NewL( KNullDesC(),
   117     
   114                                              TRect(0,0, 100,100),
   118     iLcSessionObserver = new( ELeave )CLcSessionObserverStub;
   115                                              *iObserver,
   119     iLcUiProvider = new( ELeave )CLcUiProviderStub;
   116                                              *iObserver,
   120     iAudioRoutingObserver = new( ELeave )CMusEngObserverStub;
   117                                              *iObserver );
   121     // Name is published using publish/subscribe key by Availblity
       
   122     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   123                                         NMusSessionApi::KContactName,
       
   124                                         KTestContactName ) );
       
   125     iLiveSession = CMusEngLiveSession::NewL();
       
   126     iLiveSession->SetLcSessionObserver( iLcSessionObserver );
       
   127     iLiveSession->SetLcUiProvider( iLcUiProvider );    
       
   128 
       
   129     SIPStrings::OpenL();
   118     SIPStrings::OpenL();
   130     
   119     
   131     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
   120     iLiveSession->iPrivate = EFalse;
   132                                         NMusSessionApi::KRemoteSipAddress,
   121     iLiveSession->iPrivateNumber = EFalse;
   133                                         KTestRecipientSipUri ) );
   122     
   134     }
   123     }
   135 
   124 
   136 
   125 
   137 // -----------------------------------------------------------------------------
   126 // -----------------------------------------------------------------------------
   138 //
   127 //
   140 //
   129 //
   141 void UT_CMusEngOutSession::Teardown()
   130 void UT_CMusEngOutSession::Teardown()
   142     {
   131     {
   143     SIPStrings::Close();
   132     SIPStrings::Close();
   144     delete iLiveSession;
   133     delete iLiveSession;
   145     delete iLcSessionObserver;
   134     delete iObserver;
   146     delete iLcUiProvider;
   135     }
   147     delete iAudioRoutingObserver;
   136 
   148     PropertyHelper::SetErrorCode( KErrNone );
       
   149     PropertyHelper::Close();
       
   150     }
       
   151 
   137 
   152 
   138 
   153 // TEST CASES
   139 // TEST CASES
   154 
   140 
   155 // -----------------------------------------------------------------------------
   141 
   156 //
   142 // -----------------------------------------------------------------------------
   157 // -----------------------------------------------------------------------------
   143 //
   158 //
   144 // -----------------------------------------------------------------------------
   159 void UT_CMusEngOutSession::UT_EstablishLcSessionL()
   145 //
   160     {
   146 void UT_CMusEngOutSession::UT_CMusEngOutSession_InviteLL()
       
   147     {
       
   148 
   161     // Initial state
   149     // Initial state
   162     EUNIT_ASSERT( !iLiveSession->iSession );
   150     EUNIT_ASSERT( !iLiveSession->iSession );
   163     
   151     
   164     ///////////////////////////////////////////////////////////////////////////
   152     // Simulate failing session structure construction.
   165     // 1. Simulate failing session structure construction.
   153     iLiveSession->InviteL( KTestRecipientSipUri );
   166     iLiveSession->EstablishLcSessionL();
       
   167     
   154     
   168     iLiveSession->iSession->iState = CMceSession::EIdle;
   155     iLiveSession->iSession->iState = CMceSession::EIdle;
   169     delete iLiveSession->iSession->Streams()[0];
   156     delete iLiveSession->iSession->Streams()[0];
   170     const RPointerArray<CMceMediaStream>& constStreams = 
   157     const RPointerArray<CMceMediaStream>& constStreams = 
   171                                             iLiveSession->iSession->Streams();
   158                                             iLiveSession->iSession->Streams();
   172     const_cast<RPointerArray<CMceMediaStream>&>(constStreams)[0] = NULL;
   159     const_cast<RPointerArray<CMceMediaStream>&>(constStreams)[0] = NULL;
   173 
   160 
   174     ///////////////////////////////////////////////////////////////////////////
   161     // Normal invite
   175     // 2. Normal invite
   162     iLiveSession->InviteL( KTestRecipientSipUri );
   176     iLiveSession->EstablishLcSessionL();
       
   177     
   163     
   178     EUNIT_ASSERT( iLiveSession->iSession );
   164     EUNIT_ASSERT( iLiveSession->iSession );
   179     // Next assertion ensures that session structure is new
   165     // Next assertion ensures that session structure is new
   180     EUNIT_ASSERT( iLiveSession->iSession->Streams().Count() > 0 );   
       
   181     EUNIT_ASSERT( iLiveSession->iSession->Streams()[0] ); 
   166     EUNIT_ASSERT( iLiveSession->iSession->Streams()[0] ); 
   182     EUNIT_ASSERT( *(iLiveSession->iRecipient) == KTestRecipientSipUri8() );
   167     EUNIT_ASSERT( *(iLiveSession->iRecipient) == KTestRecipientSipUri8() );
   183     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   168     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   184     
   169     
   185     EUNIT_ASSERT( iLiveSession->iSession->iHeaders );
   170     EUNIT_ASSERT( iLiveSession->iSession->iHeaders );
   190                   KMusAcceptHeader() );    
   175                   KMusAcceptHeader() );    
   191     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines );
   176     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines );
   192     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->Count() == 1 );
   177     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->Count() == 1 );
   193     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->MdcaPoint( 0 ) ==
   178     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->MdcaPoint( 0 ) ==
   194                   KMusEngSessionSdpLineXApplication() );
   179                   KMusEngSessionSdpLineXApplication() );
   195         
   180     
   196     // Ensure there is no SDP lines at media level
   181     // Normal operator invite
   197     MDesC8Array* mediaSdpLines = 
       
   198         iLiveSession->iSession->Streams()[0]->iMediaSDPLines;
       
   199     EUNIT_ASSERT( mediaSdpLines );
       
   200     EUNIT_ASSERT( mediaSdpLines->MdcaCount() == 0 );
       
   201 
       
   202     ///////////////////////////////////////////////////////////////////////////
       
   203     // 3. Normal operator invite
       
   204     delete iLiveSession;
   182     delete iLiveSession;
   205     iLiveSession = NULL;
   183     iLiveSession = NULL;
   206     iLiveSession = CMusEngLiveSession::NewL();
   184     iLiveSession = CMusEngLiveSession::NewL( KNullDesC,
   207     iLiveSession->SetLcSessionObserver( iLcSessionObserver );
   185                                              TRect(0,0, 100,100),
   208     iLiveSession->SetLcUiProvider( iLcUiProvider );    
   186                                              *iObserver,
       
   187                                              *iObserver,
       
   188                                              *iObserver );
   209    	iLiveSession->iOperatorVariant = ETrue;
   189    	iLiveSession->iOperatorVariant = ETrue;
   210    	CSIPProfile* profile = iLiveSession->iSipProfileHandler->Profile();
   190    	CSIPProfile* profile = iLiveSession->iSipProfileHandler->Profile();
   211     delete profile->iArray;
   191     delete profile->iArray;
   212     profile->iArray = NULL;
   192     profile->iArray = NULL;
   213     profile->iArray = new ( ELeave ) CDesC8ArrayFlat( 1 );
   193     profile->iArray = new ( ELeave ) CDesC8ArrayFlat( 1 );
   214     profile->iArray->AppendL( KMusTestUri );
   194     profile->iArray->AppendL( KMusTestUri );
   215 
   195 
   216     iLiveSession->EstablishLcSessionL();
   196     iLiveSession->InviteL( KTestRecipientSipUri );
   217     
   197     
   218     EUNIT_ASSERT( iLiveSession->iSession );
   198     EUNIT_ASSERT( iLiveSession->iSession );
   219     // Next assertion ensures that session structure is new
   199     // Next assertion ensures that session structure is new
       
   200     EUNIT_ASSERT( iLiveSession->iSession->Streams()[0] ); 
   220     EUNIT_ASSERT( *(iLiveSession->iRecipient) == KTestRecipientSipUri8() );
   201     EUNIT_ASSERT( *(iLiveSession->iRecipient) == KTestRecipientSipUri8() );
   221     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   202     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   222     
   203     
   223     EUNIT_ASSERT( iLiveSession->iSession->iHeaders );
   204     EUNIT_ASSERT( iLiveSession->iSession->iHeaders );
   224     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->Count() == 3 );
   205     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->Count() == 3 );
   228                   KMusAcceptHeader() );
   209                   KMusAcceptHeader() );
   229     
   210     
   230     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 2 ) ==
   211     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 2 ) ==
   231                   KMusPPreferredIdentityTestHeader() );
   212                   KMusPPreferredIdentityTestHeader() );
   232     
   213     
   233     // Ensure there is only a=type and a=application attributes (and no b=TIAS)
       
   234     // at session level for operator variant
       
   235     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines );
   214     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines );
   236     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->Count() == 2 );
   215     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->Count() == 2 );
   237     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->MdcaPoint( 0 ) ==
   216     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->MdcaPoint( 0 ) ==
   238                   KMusEngSessionSdpLineApplication() )
   217                   KMusEngSessionSdpLineApplication() )
   239    	EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->MdcaPoint( 1 ) ==
   218    	EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->MdcaPoint( 1 ) ==
   240                   KMusEngSessionSdpLineType() )
   219                   KMusEngSessionSdpLineType() )
   241                   
   220                   
   242     EUNIT_ASSERT( iLiveSession->iSession->Streams().Count() > 0 );   
   221     EUNIT_ASSERT( iLiveSession->iSession->Streams().Count() > 0 );   
   243     EUNIT_ASSERT( iLiveSession->iSession->Streams()[0] ); 
   222     TBool foundBandwidthLineFromMediaLevel( EFalse );
   244     EUNIT_ASSERT( iLiveSession->iSession->Streams()[0]->Type() == KMceVideo );
   223     for ( TInt i = 0; i <  iLiveSession->iSession->Streams().Count(); i++ )
   245 
   224         {
   246     // Ensure there is only b=AS and no b=TIAS present at media level
   225         if ( iLiveSession->iSession->Streams()[0]->Type() == KMceVideo )
   247     // for operator variant
   226             {
   248     mediaSdpLines = iLiveSession->iSession->Streams()[0]->iMediaSDPLines;
   227             if ( iLiveSession->iSession->Streams()[0]->iMediaSDPLines->MdcaCount() > 0 &&
   249     EUNIT_ASSERT( mediaSdpLines );
   228                  iLiveSession->iSession->Streams()[0]->iMediaSDPLines->MdcaPoint( 0 ) ==
   250     EUNIT_ASSERT( mediaSdpLines->MdcaCount() == 1 );
   229                     KMusEngSessionSdpLineBandwidthField() )
   251     EUNIT_ASSERT( mediaSdpLines->MdcaPoint( 0 ) == 
   230                 {
   252                   KMusEngSessionSdpLineBandwidthField() );
   231                 foundBandwidthLineFromMediaLevel = ETrue;
   253     
   232                 }
   254     ///////////////////////////////////////////////////////////////////////////
   233             }
   255     // 4. Try invite again, must fail
   234         }
   256     TRAPD( error, iLiveSession->EstablishLcSessionL() );
   235     EUNIT_ASSERT( foundBandwidthLineFromMediaLevel );
       
   236                       
       
   237     // Try invite again, must fail
       
   238     TRAPD( error, iLiveSession->InviteL( KTestRecipientSipUri ) );
   257     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
   239     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
   258     EUNIT_ASSERT( error == KErrAlreadyExists );
   240     EUNIT_ASSERT( error == KErrAlreadyExists );
   259     
   241     
   260     // 5. Simulate normal session ending, no need for observer call in this case
   242     // Simulate normal session ending, no need for observer call in this case
   261     iLiveSession->iSession->iState = CMceSession::ETerminated;
   243     iLiveSession->iSession->iState = CMceSession::ETerminated;
   262     
   244     
   263     // Try again. Establishment must be OK with new MceSession object
   245     // Try again. Establishment must be OK with new MceSession object
   264     iLiveSession->EstablishLcSessionL();
   246     iLiveSession->InviteL( KTestRecipientSipUri );
   265     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   247     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   266     }
   248 
   267     
   249       
   268 // -----------------------------------------------------------------------------
   250     }
   269 //
   251     
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 void UT_CMusEngOutSession::UT_EstablishLcSession_RecipientResolvingL()
       
   273     {   
       
   274     // Manual query from user, 
       
   275     // the user cancels the query (MLcUiProvider::Query returns EFalse)
       
   276     PropertyHelper::SetErrorCode( KErrNotFound );
       
   277     TRAPD( err, iLiveSession->EstablishLcSessionL() )
       
   278     if ( err == KErrNoMemory )
       
   279         {
       
   280         User::Leave( err );
       
   281         }
       
   282     EUNIT_ASSERT_EQUALS( KErrCancel, err )        
       
   283  
       
   284     // Manual query from user succeeds
       
   285     iLcSessionObserver->Reset();
       
   286     iLcUiProvider->Reset();        
       
   287     delete iLiveSession;
       
   288     iLiveSession = NULL;
       
   289     iLiveSession = CMusEngLiveSession::NewL();
       
   290     iLiveSession->SetLcSessionObserver( iLcSessionObserver );
       
   291     iLiveSession->SetLcUiProvider( iLcUiProvider );    
       
   292     iLcUiProvider->iSimulatedReturnValue = ETrue;
       
   293     iLcUiProvider->iRecipient.Set( KTestRecipient2SipUri );
       
   294     PropertyHelper::SetErrorCode( KErrNotFound );
       
   295     iLiveSession->EstablishLcSessionL();
       
   296     EUNIT_ASSERT_EQUALS( 1, iLiveSession->iTriedInvitations )
       
   297     EUNIT_ASSERT_EQUALS( 
       
   298         TInt( CLcUiProviderStub::EInputRecipient ),
       
   299         iLcUiProvider->iCalledFunction )
       
   300     EUNIT_ASSERT_EQUALS( 
       
   301         KTestRecipient2SipUri8(), 
       
   302         *( iLiveSession->iRecipient ) )        
       
   303     EUNIT_ASSERT_EQUALS( KTestRecipient2SipUri(),iLiveSession->RemoteDisplayName() )  
       
   304 
       
   305     // Multiple resolved recipients
       
   306     iLcSessionObserver->Reset();
       
   307     iLcUiProvider->Reset();
       
   308     iLcUiProvider->iSimulatedReturnValue = ETrue;
       
   309     PropertyHelper::SetErrorCode( KErrNone );
       
   310     TBuf<200> multipleAddr;
       
   311     multipleAddr.Append( KTestRecipient2SipUri );
       
   312     multipleAddr.Append( _L(",") );
       
   313     multipleAddr.Append( KTestRecipientSipUri );
       
   314     
       
   315     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   316                                         NMusSessionApi::KRemoteSipAddress,
       
   317                                         multipleAddr ) );
       
   318     delete iLiveSession;
       
   319     iLiveSession = NULL;
       
   320     iLiveSession = CMusEngLiveSession::NewL();
       
   321     iLiveSession->SetLcSessionObserver( iLcSessionObserver );
       
   322     iLiveSession->SetLcUiProvider( iLcUiProvider );    
       
   323     iLiveSession->EstablishLcSessionL();
       
   324         
       
   325     EUNIT_ASSERT_EQUALS( 0, iLiveSession->iTriedInvitations )
       
   326     EUNIT_ASSERT_EQUALS( 
       
   327         TInt( CLcUiProviderStub::ESelectRecipient ),
       
   328         iLcUiProvider->iCalledFunction )
       
   329     // Stub selected first one from multiple addresses list
       
   330     EUNIT_ASSERT_EQUALS( 
       
   331         KTestRecipient2SipUri8(), 
       
   332         *( iLiveSession->iRecipient ) )    
       
   333        
       
   334     // Multiple resolved recipient, user doesn't select any
       
   335     iLcSessionObserver->Reset();
       
   336     iLcUiProvider->Reset();
       
   337     delete iLiveSession;
       
   338     iLiveSession = NULL;
       
   339     iLiveSession = CMusEngLiveSession::NewL();
       
   340     iLiveSession->SetLcSessionObserver( iLcSessionObserver );
       
   341     iLiveSession->SetLcUiProvider( iLcUiProvider );    
       
   342     TRAP( err, iLiveSession->EstablishLcSessionL() );
       
   343     if ( err == KErrNoMemory )
       
   344         {
       
   345         User::Leave( err );
       
   346         }
       
   347     EUNIT_ASSERT_EQUALS( KErrNotFound, err )   
       
   348     EUNIT_ASSERT_EQUALS( 0, iLiveSession->iTriedInvitations )
       
   349     EUNIT_ASSERT_EQUALS( 
       
   350         TInt( CLcUiProviderStub::ESelectRecipient ),
       
   351         iLcUiProvider->iCalledFunction )
       
   352     
       
   353     // Malformed multiple addresses, selection fails, manual entry is launched
       
   354     iLcSessionObserver->Reset();
       
   355     iLcUiProvider->Reset();
       
   356     iLcUiProvider->iSimulatedReturnValue = ETrue;
       
   357     iLcUiProvider->iRecipient.Set( KTestRecipient2SipUri );
       
   358     PropertyHelper::SetErrorCode( KErrNone );
       
   359     multipleAddr.Copy( _L(",") );
       
   360     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   361                                         NMusSessionApi::KRemoteSipAddress,
       
   362                                         multipleAddr ) );
       
   363     delete iLiveSession;
       
   364     iLiveSession = NULL;
       
   365     iLiveSession = CMusEngLiveSession::NewL();
       
   366     iLiveSession->SetLcSessionObserver( iLcSessionObserver );
       
   367     iLiveSession->SetLcUiProvider( iLcUiProvider );    
       
   368     TRAP( err, iLiveSession->EstablishLcSessionL() );
       
   369     if ( err == KErrNoMemory )
       
   370        {
       
   371        User::Leave( err );
       
   372        }
       
   373     EUNIT_ASSERT_EQUALS( 
       
   374         TInt( CLcUiProviderStub::EInputRecipient ),
       
   375         iLcUiProvider->iCalledFunction )    
       
   376     EUNIT_ASSERT_EQUALS( KErrNone, err );
       
   377     EUNIT_ASSERT_EQUALS( 1, iLiveSession->iTriedInvitations )
       
   378     EUNIT_ASSERT_EQUALS( 
       
   379         KTestRecipient2SipUri8(), 
       
   380         *( iLiveSession->iRecipient ) )
       
   381     }
       
   382 
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 // -----------------------------------------------------------------------------
       
   386 //
       
   387 void UT_CMusEngOutSession::UT_EstablishLcSession_RegistrationPendingL()
       
   388     {
       
   389     // Set registration as pending
       
   390     iLiveSession->iSipProfileHandler->Profile()->iTBoolValue = EFalse;
       
   391     
       
   392     iLiveSession->EstablishLcSessionL();
       
   393     EUNIT_ASSERT( !iLiveSession->iSession )
       
   394     EUNIT_ASSERT( iLiveSession->iRegistrationPending )
       
   395     
       
   396     // Fake registration, session starts
       
   397     iLiveSession->iSipProfileHandler->Profile()->iTBoolValue = ETrue;
       
   398     iLiveSession->ProfileRegistered();
       
   399     
       
   400     if ( iLcSessionObserver->iCalledFunction == CLcSessionObserverStub::ESessionFailed )
       
   401         {
       
   402         // Session didn't start because of running out of memory
       
   403         User::Leave( KErrNoMemory );
       
   404         }
       
   405     
       
   406     iLiveSession->iDeltaTimer->Remove( iLiveSession->iInvitationResponseEntry );
       
   407     CMusEngMceOutSession::InvitationResponseTimerExpired( iLiveSession );
       
   408     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   409                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   410     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   411                          TInt( MLcSession::ENoAnswer ) )    
       
   412     iLcSessionObserver->Reset();
       
   413     
       
   414     EUNIT_ASSERT( iLiveSession->iSession )
       
   415     EUNIT_ASSERT_EQUALS( iLiveSession->iSession->State(), 
       
   416                          CMceSession::EOffering )
       
   417     EUNIT_ASSERT( !iLiveSession->iRegistrationPending )    
       
   418     }
       
   419 
   252 
   420 // -----------------------------------------------------------------------------
   253 // -----------------------------------------------------------------------------
   421 //
   254 //
   422 // -----------------------------------------------------------------------------
   255 // -----------------------------------------------------------------------------
   423 //    
   256 //    
   424 void UT_CMusEngOutSession::UT_TerminateLcSessionL()
   257 void UT_CMusEngOutSession::UT_CMusEngOutSession_CancelInviteLL()
   425     {
   258     {
   426     // No MCE session
   259     // Try to cancel, must fail
   427     EUNIT_ASSERT_SPECIFIC_LEAVE( 
   260     TRAPD( error, iLiveSession->CancelInviteL() );
   428         iLiveSession->TerminateLcSessionL(), KErrNotReady )
   261     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
   429 
   262     EUNIT_ASSERT( error == KErrNotReady );
   430     // Cancel a session that is in offering state
   263     
   431     iLiveSession->EstablishLcSessionL();
   264     // Invite
   432     EUNIT_ASSERT_EQUALS( TInt( CMceSession::EOffering ),
   265     iLiveSession->InviteL( KTestRecipientSipUri );
   433                          TInt( iLiveSession->iSession->iState ) )
   266     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   434     iLiveSession->TerminateLcSessionL();
   267     
   435     EUNIT_ASSERT_EQUALS( TInt( CMceSession::ECancelling ),
   268     // Cancel
   436                          TInt( iLiveSession->iSession->iState ) )
   269     iLiveSession->CancelInviteL();
   437     
   270     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::ECancelling );
   438     // Terminate an established session
   271     
   439     iLiveSession->iSession->iState = CMceSession::ETerminated;
   272     // Try to cancel again, does nothing
   440     iLiveSession->EstablishLcSessionL();
   273     iLiveSession->CancelInviteL();
   441     iLiveSession->iSession->iState = CMceSession::EEstablished;
   274     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::ECancelling );
   442     iLiveSession->TerminateLcSessionL();
   275     }
   443     EUNIT_ASSERT_EQUALS( TInt( CMceSession::ETerminating ),
   276 
   444                          TInt( iLiveSession->iSession->iState ) )
       
   445     }
       
   446 
   277 
   447 // -----------------------------------------------------------------------------
   278 // -----------------------------------------------------------------------------
   448 //
   279 //
   449 // -----------------------------------------------------------------------------
   280 // -----------------------------------------------------------------------------
   450 //  
   281 //  
   451 void UT_CMusEngOutSession::UT_EstablishSessionLL()
   282 void UT_CMusEngOutSession::UT_CMusEngOutSession_EstablishSessionLL()
   452     {
   283     {
   453     // Try to establish, must fail, because of missing session
   284     // Try to establish, must fail, because of missing session
   454     TRAPD( error, iLiveSession->EstablishSessionL() );
   285     TRAPD( error, iLiveSession->EstablishSessionL() );
   455     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
   286     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
   456     EUNIT_ASSERT( error == KErrNotReady );
   287     EUNIT_ASSERT( error == KErrNotReady );
       
   288     iLiveSession->iPrivate = ETrue;
       
   289     iLiveSession->iPrivateNumber = EFalse;
   457     
   290     
   458     // Call to CMusEngOutMceSession::InviteL leads to call to EstablishL
   291     // Call to CMusEngOutMceSession::InviteL leads to call to EstablishL
   459     iLiveSession->EstablishLcSessionL();
   292     iLiveSession->InviteL( KTestRecipientSipUri );
   460     
   293     
   461     // Check that ports are correct
   294     // Check that ports are correct
   462     
   295     
   463     for ( TInt i = 0; i < iLiveSession->iSession->Streams().Count(); ++i )
   296     for ( TInt i = 0; i < iLiveSession->iSession->Streams().Count(); ++i )
   464         {
   297         {
   480     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 0 ) ==
   313     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 0 ) ==
   481                   KMusEngAcceptContactHeader() )
   314                   KMusEngAcceptContactHeader() )
   482     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 1 ) ==
   315     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 1 ) ==
   483                   KMusAcceptHeader() );   
   316                   KMusAcceptHeader() );   
   484     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   317     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   485     }
   318     
       
   319     // Privacy test : Check Private -header & originator
       
   320     delete iLiveSession;
       
   321     iLiveSession = NULL;
       
   322     iLiveSession = CMusEngLiveSession::NewL( KNullDesC(),
       
   323                                                 TRect(0,0, 100,100),
       
   324                                                 *iObserver,
       
   325                                                 *iObserver,
       
   326                                                 *iObserver );
       
   327     iLiveSession->iPrivate = ETrue;
       
   328     iLiveSession->iPrivateNumber = ETrue;
       
   329     
       
   330     // Call to CMusEngOutMceSession::InviteL leads to call to EstablishL
       
   331     iLiveSession->InviteL( KTestRecipientSipUri );
       
   332     EUNIT_ASSERT( *iLiveSession->iSession->iOriginator == KMusAnonymousHeader );
       
   333     
       
   334     EUNIT_ASSERT( iLiveSession->iSession->iHeaders )
       
   335     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->Count() == 3 )
       
   336     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 0 ) ==
       
   337                   KMusEngAcceptContactHeader() )
       
   338     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 1 ) ==
       
   339                   KMusAcceptHeader() );   
       
   340     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 2 ).Find( KMusPrivacyHeader() ) == 0 );
       
   341     
       
   342     
       
   343     }
       
   344 
   486 
   345 
   487 // -----------------------------------------------------------------------------
   346 // -----------------------------------------------------------------------------
   488 //
   347 //
   489 // -----------------------------------------------------------------------------
   348 // -----------------------------------------------------------------------------
   490 //    
   349 //    
   491 void UT_CMusEngOutSession::UT_HandleTerminationL()
   350 void UT_CMusEngOutSession::UT_CMusEngOutSession_HandleTerminationL()
   492     {
   351     {
   493     // Try different values    
   352 
       
   353     // Try different values
       
   354     iLiveSession->HandleTermination( KSipStatusCode400BadRequest, 
       
   355                                      KNullDesC8() );
       
   356     EUNIT_ASSERT( iObserver->iSessionBadRequestCalled );
       
   357     iObserver->Reset();
       
   358     
       
   359     iLiveSession->HandleTermination( KSipStatusCode401Unauthorized, 
       
   360                                      KNullDesC8() );
       
   361     EUNIT_ASSERT( iObserver->iSessionUnauthorizedCalled );
       
   362     iObserver->Reset();
       
   363     
       
   364     iLiveSession->HandleTermination( KSipStatusCode402PaymentRequired, 
       
   365                                      KNullDesC8() );
       
   366     EUNIT_ASSERT( iObserver->iSessionPaymentRequiredCalled );
       
   367     iObserver->Reset();
       
   368     
       
   369     iLiveSession->HandleTermination( KSipStatusCode404RecipientNotFound, 
       
   370                                      KNullDesC8() );
       
   371     EUNIT_ASSERT( iObserver->iSessionRecipientNotFoundCalled );
       
   372     iObserver->Reset();
       
   373     
       
   374     iLiveSession->HandleTermination( KSipStatusCode416UnsupportedUriScheme, 
       
   375                                      KNullDesC8() );
       
   376     EUNIT_ASSERT( iObserver->iSessionRecipientNotFoundCalled );
       
   377     iObserver->Reset();
       
   378 
       
   379     iLiveSession->HandleTermination( KSipStatusCode479NotAbleToProcessURI, 
       
   380                                      KNullDesC8() );
       
   381     EUNIT_ASSERT( iObserver->iSessionRecipientNotFoundCalled );
       
   382     iObserver->Reset();
       
   383     
       
   384     iLiveSession->HandleTermination( 
       
   385                             KSipStatusCode407ProxyAuthenticationRequired, 
       
   386                             KNullDesC8() );
       
   387     EUNIT_ASSERT( iObserver->iSessionProxyAuthenticationRequiredCalled );
       
   388     iObserver->Reset();
       
   389     
   494     iLiveSession->HandleTermination( KSipStatusCode408ConnectionTimeOut, 
   390     iLiveSession->HandleTermination( KSipStatusCode408ConnectionTimeOut, 
   495                                      KNullDesC8() );
   391                                      KNullDesC8() );
   496     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   392     EUNIT_ASSERT( iObserver->iSessionRequestTimeOutCalled );
   497                          TInt( CLcSessionObserverStub::ESessionFailed ) )
   393     iObserver->Reset();
   498     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   499                          TInt( MLcSession::ENoAnswer ) )
       
   500     iLcSessionObserver->Reset();
       
   501     
   394     
   502     iLiveSession->HandleTermination( KSipStatusCode415UnsupportedMediaType, 
   395     iLiveSession->HandleTermination( KSipStatusCode415UnsupportedMediaType, 
   503                                      KNullDesC8() );
   396                                      KNullDesC8() );
   504     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   397     EUNIT_ASSERT( iObserver->iSessionUnsupportedMediaTypeCalled );
   505                          TInt( CLcSessionObserverStub::ESessionFailed ) )
   398     iObserver->Reset();
   506     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   507                          TInt( MLcSession::ESessionRejected ) ) 
       
   508     iLcSessionObserver->Reset();
       
   509     
   399     
   510     iLiveSession->HandleTermination( KSipStatusCode488NotAcceptableHere, 
   400     iLiveSession->HandleTermination( KSipStatusCode488NotAcceptableHere, 
   511                                      KNullDesC8() );
   401                                      KNullDesC8() );
   512     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   402     EUNIT_ASSERT( iObserver->iSessionUnsupportedMediaTypeCalled );
   513                          TInt( CLcSessionObserverStub::ESessionFailed ) )
   403     iObserver->Reset();
   514     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   515                          TInt( MLcSession::ESessionRejected ) )
       
   516     iLcSessionObserver->Reset();
       
   517     
   404     
   518     iLiveSession->HandleTermination( KSipStatusCode606NotAcceptable, 
   405     iLiveSession->HandleTermination( KSipStatusCode606NotAcceptable, 
   519                                      KNullDesC8() );
   406                                      KNullDesC8() );
   520     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   407     EUNIT_ASSERT( iObserver->iSessionUnsupportedMediaTypeCalled );
   521                          TInt( CLcSessionObserverStub::ESessionFailed ) )
   408     iObserver->Reset(); 
   522     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   523                          TInt( MLcSession::ESessionRejected ) )
       
   524     iLcSessionObserver->Reset(); 
       
   525     
   409     
   526     iLiveSession->HandleTermination( KSipStatusCode486BusyHere, 
   410     iLiveSession->HandleTermination( KSipStatusCode486BusyHere, 
   527                                      KNullDesC8() );
   411                                      KNullDesC8() );
   528     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   412     EUNIT_ASSERT( iObserver->iSessionBusyHereCalled );
   529                          TInt( CLcSessionObserverStub::ESessionFailed ) )
   413     iObserver->Reset();
   530     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   531                          TInt( MLcSession::ERecipientBusy ) )
       
   532     iLcSessionObserver->Reset();
       
   533     
   414     
   534     iLiveSession->HandleTermination( KSipStatusCode487RequestCancelled, 
   415     iLiveSession->HandleTermination( KSipStatusCode487RequestCancelled, 
   535                                      KNullDesC8() );
   416                                      KNullDesC8() );
   536     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   417     EUNIT_ASSERT( iObserver->iSessionRequestCancelledCalled );
   537                          TInt( CLcSessionObserverStub::ESessionFailed ) )
   418     iObserver->Reset();
   538     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   539                          TInt( MLcSession::ESessionCancelled ) )
       
   540     iLcSessionObserver->Reset();
       
   541     
   419     
   542     iLiveSession->HandleTermination( KSipStatusCode603Decline, KNullDesC8()  );
   420     iLiveSession->HandleTermination( KSipStatusCode603Decline, KNullDesC8()  );
   543     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   421     EUNIT_ASSERT( iObserver->iSessionRejectedCalled );
   544                          TInt( CLcSessionObserverStub::ESessionFailed ) )
   422     iObserver->Reset();
   545     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   546                          TInt( MLcSession::ESessionRejected ) )
       
   547     iLcSessionObserver->Reset();
       
   548 
   423 
   549     iLiveSession->HandleTermination( KSipStatusCode480TemporarilyNotAvailable, 
   424     iLiveSession->HandleTermination( KSipStatusCode480TemporarilyNotAvailable, 
   550                                      KNullDesC8() );
   425                                      KNullDesC8() );
   551     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   426     EUNIT_ASSERT( iObserver->iSessionTemporarilyNotAvailable );
   552                          TInt( CLcSessionObserverStub::ESessionFailed ) )
   427     iObserver->Reset();
   553     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   554                          TInt( MLcSession::ERecipientTemporarilyNotAvailable ) )
       
   555     iLcSessionObserver->Reset();
       
   556     
   428     
   557     // Receive 486 with operator variant
   429     // Receive 486 with operator variant
   558     iLiveSession->iOperatorVariant = ETrue;
   430     iLiveSession->iOperatorVariant = ETrue;
   559     iLiveSession->HandleTermination( KSipStatusCode486BusyHere, KNullDesC8()  );
   431     iLiveSession->HandleTermination( KSipStatusCode486BusyHere, KNullDesC8()  );
   560     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   432     EUNIT_ASSERT( iObserver->iSessionRejectedCalled )
   561                          TInt( CLcSessionObserverStub::ESessionFailed ) )
   433     EUNIT_ASSERT( !iObserver->iSessionBusyHereCalled )
   562     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
   434     iObserver->Reset();
   563                          TInt( MLcSession::ESessionRejected ) )    
       
   564     iLcSessionObserver->Reset();
       
   565     iLiveSession->iOperatorVariant = EFalse;
   435     iLiveSession->iOperatorVariant = EFalse;
   566     
   436     
   567     // Normal termination, let the base class handle
   437     // Normal termination, let the base class handle
   568     iLiveSession->HandleTermination(  KSipStatusCode200OK, KNullDesC8()  );
   438     iLiveSession->HandleTermination(  KSipStatusCode200OK, KNullDesC8()  );
   569     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   439     EUNIT_ASSERT( iObserver->iSessionTerminatedCalled ); // called by base class
   570                          TInt( CLcSessionObserverStub::ESessionStateChanged ) )
   440     iObserver->Reset();
   571     iLcSessionObserver->Reset();
   441 
   572     }    
   442     }    
   573 
   443 
   574 // -----------------------------------------------------------------------------
       
   575 //
       
   576 // -----------------------------------------------------------------------------
       
   577 //    
       
   578 void UT_CMusEngOutSession::UT_HandleRecipientNotFoundTerminationL()
       
   579     {
       
   580     EUNIT_ASSERT_EQUALS( iLiveSession->iTriedInvitations, 0 );
       
   581     
       
   582     // Retry possible when 404 is received but fails because of recipient 
       
   583     // proposal is missing for some reason, recipient not found callback
       
   584     // is called instead of retry
       
   585     delete iLiveSession->iRemoteSipAddressProposal;
       
   586     iLiveSession->iRemoteSipAddressProposal = NULL;
       
   587     iLcSessionObserver->Reset();
       
   588     iLiveSession->HandleTermination( KSipStatusCode404RecipientNotFound, 
       
   589                                      KNullDesC8() );
       
   590     
       
   591     EUNIT_ASSERT( iLiveSession->iDeltaTimer->IsActive() == ETrue )
       
   592     iLiveSession->AsyncBrakeCompleted( iLiveSession );
       
   593     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   594                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   595     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   596                          TInt( MLcSession::ERecipientNotFound ) )
       
   597     
       
   598     // Retry possible when 404 is received
       
   599     delete iLiveSession->iRemoteSipAddressProposal;
       
   600     iLiveSession->iRemoteSipAddressProposal = NULL;
       
   601     iLiveSession->iRemoteSipAddressProposal = KTestRecipient2SipUri().AllocL();
       
   602     iLcSessionObserver->Reset();
       
   603     iLcUiProvider->iRecipient.Set( KTestRecipient2SipUri );
       
   604     iLcUiProvider->iSimulatedReturnValue = ETrue;
       
   605     iLiveSession->HandleTermination( KSipStatusCode404RecipientNotFound, 
       
   606                                      KNullDesC8() );
       
   607        
       
   608     EUNIT_ASSERT( iLiveSession->iDeltaTimer->IsActive() == ETrue );
       
   609     iLiveSession->AsyncBrakeCompleted( iLiveSession );
       
   610 
       
   611     // Memory running out might cause that retry is not done
       
   612     if ( iLcSessionObserver->iCalledFunction == CLcSessionObserverStub::ESessionFailed )
       
   613         {
       
   614         User::Leave( KErrNoMemory );
       
   615         }
       
   616     EUNIT_ASSERT_EQUALS( 1, iLiveSession->iTriedInvitations )    
       
   617     EUNIT_ASSERT_EQUALS( 
       
   618         KTestRecipient2SipUri8(), 
       
   619         *( iLiveSession->iRecipient ) )
       
   620     
       
   621     // Retry not anymore possible when 404 received (e.g. manual address query
       
   622     // was done for invite).
       
   623     iLcSessionObserver->Reset();
       
   624     iLiveSession->HandleTermination( KSipStatusCode404RecipientNotFound, 
       
   625                                      KNullDesC8() );
       
   626     EUNIT_ASSERT( iLiveSession->iDeltaTimer->IsActive() == ETrue )
       
   627     iLiveSession->AsyncBrakeCompleted( iLiveSession );
       
   628     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   629                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   630     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   631                          TInt( MLcSession::ERecipientNotFound ) )
       
   632     
       
   633     // 416 has identical handling
       
   634     iLcSessionObserver->Reset();
       
   635     iLiveSession->HandleTermination( KSipStatusCode416UnsupportedUriScheme, 
       
   636                                      KNullDesC8() );
       
   637     EUNIT_ASSERT( iLiveSession->iDeltaTimer->IsActive() == ETrue );
       
   638     iLiveSession->AsyncBrakeCompleted( iLiveSession );
       
   639     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   640                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   641     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   642                          TInt( MLcSession::ERecipientNotFound ) )
       
   643    
       
   644     // 479 has identical handling
       
   645     iLcSessionObserver->Reset();
       
   646     iLiveSession->HandleTermination( KSipStatusCode479NotAbleToProcessURI, 
       
   647                                     KNullDesC8() );
       
   648     EUNIT_ASSERT( iLiveSession->iDeltaTimer->IsActive() == ETrue );
       
   649     iLiveSession->AsyncBrakeCompleted( iLiveSession );
       
   650     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   651                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   652     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   653                          TInt( MLcSession::ERecipientNotFound ) )
       
   654     }
       
   655 
   444 
   656 // -----------------------------------------------------------------------------
   445 // -----------------------------------------------------------------------------
   657 //
   446 //
   658 // -----------------------------------------------------------------------------
   447 // -----------------------------------------------------------------------------
   659 //   
   448 //   
   660 void UT_CMusEngOutSession::UT_AdjustVideoCodecLL()
   449 void UT_CMusEngOutSession::UT_CMusEngOutSession_AdjustVideoCodecLL()
   661     {
   450     {
   662     //H263
   451     //H263
   663     CMceH263Codec* codecH263 = CMceH263Codec::NewLC( KMceSDPNameH2632000() );
   452     CMceH263Codec* codecH263 = CMceH263Codec::NewLC( KMceSDPNameH2632000() );
   664     iLiveSession->CMusEngMceOutSession::AdjustVideoCodecL( *codecH263,
   453     iLiveSession->CMusEngMceOutSession::AdjustVideoCodecL( *codecH263 );
   665                                                            KMceCameraSource );
       
   666     // Test payloadtype
   454     // Test payloadtype
   667     EUNIT_ASSERT( codecH263->iPayloadType == 96 )
   455     EUNIT_ASSERT( codecH263->iPayloadType == 96 )
   668     CleanupStack::PopAndDestroy( codecH263 );
   456     CleanupStack::PopAndDestroy( codecH263 );
   669     
   457     
   670     //H264
   458     //H264
   671     CMceAvcCodec* codecAvc = CMceAvcCodec::NewLC( KMceSDPNameH264() );
   459     CMceAvcCodec* codecAvc = CMceAvcCodec::NewLC( KMceSDPNameH264() );
   672     iLiveSession->CMusEngMceOutSession::AdjustVideoCodecL( *codecAvc,
   460     iLiveSession->CMusEngMceOutSession::AdjustVideoCodecL( *codecAvc );
   673                                                            KMceCameraSource  );
       
   674     // Test payloadtype
   461     // Test payloadtype
   675     EUNIT_ASSERT( codecAvc->iPayloadType == 98 )
   462     EUNIT_ASSERT( codecAvc->iPayloadType == 98 )
   676     CleanupStack::PopAndDestroy( codecAvc );
   463     CleanupStack::PopAndDestroy( codecAvc );
   677     }
   464     }
   678 
   465 
       
   466 
   679 // -----------------------------------------------------------------------------
   467 // -----------------------------------------------------------------------------
   680 //
   468 //
   681 // -----------------------------------------------------------------------------
   469 // -----------------------------------------------------------------------------
   682 //   
   470 //   
   683 void UT_CMusEngOutSession::UT_AdjustAudioCodecLL()
   471 void UT_CMusEngOutSession::UT_CMusEngOutSession_AdjustAudioCodecLL()
   684     {
   472     {
   685     CMceAudioCodec* codec = 
   473     CMceAudioCodec* codec = 
   686                 iLiveSession->iManager->SupportedAudioCodecs()[0]->CloneL();
   474                 iLiveSession->iManager->SupportedAudioCodecs()[0]->CloneL();
   687     CleanupStack::PushL( codec );
   475     CleanupStack::PushL( codec );
   688     iLiveSession->CMusEngMceOutSession::AdjustAudioCodecL( *codec );
   476     iLiveSession->CMusEngMceOutSession::AdjustAudioCodecL( *codec );
   697     EUNIT_ASSERT( codec->iMMFPriorityPreference == KAudioPrefSwisPlayback )
   485     EUNIT_ASSERT( codec->iMMFPriorityPreference == KAudioPrefSwisPlayback )
   698     
   486     
   699     CleanupStack::PopAndDestroy( codec );
   487     CleanupStack::PopAndDestroy( codec );
   700     }
   488     }
   701         
   489         
       
   490 
   702 // -----------------------------------------------------------------------------
   491 // -----------------------------------------------------------------------------
   703 //
   492 //
   704 // -----------------------------------------------------------------------------
   493 // -----------------------------------------------------------------------------
   705 //   
   494 //   
   706 void UT_CMusEngOutSession::UT_CreateMceSessionStructureLL()
   495 void UT_CMusEngOutSession::UT_CMusEngOutSession_CreateMceSessionStructureLL()
   707     {
   496     {
   708     // Test removal of QoS-lines
   497     // Test removal of QoS-lines
   709     
   498     
   710     iLiveSession->iRecipient = KTestRecipientSipUri8().AllocL();
   499     iLiveSession->iRecipient = KTestRecipientSipUri8().AllocL();
   711   
   500   
   733     
   522     
   734     // Test bundling
   523     // Test bundling
   735     
   524     
   736     EUNIT_ASSERT( iLiveSession->iSession->Bundles().Count() == 0 )
   525     EUNIT_ASSERT( iLiveSession->iSession->Bundles().Count() == 0 )
   737 
   526 
   738     CMusEngClipSession* clipSession = CMusEngClipSession::NewL();
   527     CMusEngClipSession* clipSession = CMusEngClipSession::NewL(
       
   528                                                     TRect(0, 100, 200, 300 ),
       
   529                                                     *iObserver,
       
   530                                                     *iObserver,
       
   531                                                     *iObserver );
   739     CleanupStack::PushL( clipSession );
   532     CleanupStack::PushL( clipSession );
   740     clipSession->SetLcSessionObserver( iLcSessionObserver );
   533     
   741     clipSession->SetLcUiProvider( iLcUiProvider );    
   534     clipSession->SetClipL( KTestVideoFileName );
   742     clipSession->LocalVideoPlayer()->LcSourceFileControl()->SetLcFileNameL(
       
   743         KTestVideoFileName() );
       
   744     
   535     
   745     clipSession->iRecipient = KTestRecipientSipUri8().AllocL();
   536     clipSession->iRecipient = KTestRecipientSipUri8().AllocL();
   746     
   537     
   747     clipSession->CreateMceSessionStructureL();
   538     clipSession->CreateMceSessionStructureL();
   748     
   539     
   758                   KMceDisplaySink )
   549                   KMceDisplaySink )
   759 
   550 
   760     CleanupStack::PopAndDestroy( clipSession );
   551     CleanupStack::PopAndDestroy( clipSession );
   761     }
   552     }
   762 
   553 
   763 // -----------------------------------------------------------------------------
       
   764 //
       
   765 // -----------------------------------------------------------------------------
       
   766 //   
       
   767 void UT_CMusEngOutSession::UT_ConstructLL()
       
   768     {
       
   769     TUint32 profileid = 0;
       
   770     CSIPProfile* profile = iLiveSession->iSipProfileHandler->Profile();
       
   771     profile->GetParameter( KSIPProfileId, profileid );
       
   772     //stub creates defaultprofile if profileid is zero
       
   773     //stub does not care if the profileid is given or not
       
   774     //profileid of new profile is always 1
       
   775     EUNIT_ASSERT(profile->iIsDefaultProfile)
       
   776 
       
   777     TInt error = NULL;
       
   778     const TUint KSipProfileId2( 2 );
       
   779     TRAP( error, RProperty::Set( NMusSessionApi::KCategoryUid,
       
   780                                  NMusSessionApi::KSipProfileId,
       
   781                                  KSipProfileId2 ) );
       
   782     if ( error == KErrNoMemory ) User::Leave( error );
       
   783     EUNIT_ASSERT ( error == KErrNone );
       
   784     profile = NULL;
       
   785     profileid = 0;
       
   786     
       
   787     SIPStrings::Close();
       
   788     delete iLcSessionObserver;
       
   789     iLcSessionObserver = NULL;
       
   790     delete iLiveSession;
       
   791     iLiveSession = NULL;
       
   792         
       
   793     iLcSessionObserver = new( ELeave )CLcSessionObserverStub;
       
   794     iLiveSession = CMusEngLiveSession::NewL();
       
   795     iLiveSession->SetLcSessionObserver( iLcSessionObserver );
       
   796     iLiveSession->SetLcUiProvider( iLcUiProvider );    
       
   797     
       
   798     SIPStrings::OpenL();
       
   799     
       
   800     profile = iLiveSession->iSipProfileHandler->Profile();
       
   801     profile->GetParameter( KSIPProfileId, profileid );
       
   802     EUNIT_ASSERT( !profile->iIsDefaultProfile )
       
   803     
       
   804     
       
   805     TRAP( error, RProperty::Delete( NMusSessionApi::KCategoryUid,
       
   806                                      NMusSessionApi::KSipProfileId ) );
       
   807     if ( error == KErrNoMemory ) User::Leave( error );
       
   808     EUNIT_ASSERT ( error == KErrNone );
       
   809     profile = NULL;
       
   810     profileid = 0;
       
   811     }
       
   812 
       
   813 // -----------------------------------------------------------------------------
       
   814 // 
       
   815 // -----------------------------------------------------------------------------
       
   816 //
       
   817 void UT_CMusEngOutSession::UT_ContactSavingLL()
       
   818     {
       
   819     ContactEngineStubHelper::Reset();
       
   820     
       
   821     // Saving of contact is done at destruction phase only if recipient
       
   822     // has been queried from client
       
   823     //
       
   824     CMusEngLiveSession* liveSession = CMusEngLiveSession::NewL();
       
   825     liveSession->SetLcSessionObserver( iLcSessionObserver );
       
   826     liveSession->SetLcUiProvider( iLcUiProvider );    
       
   827     delete liveSession;
       
   828     liveSession = NULL;
       
   829     EUNIT_ASSERT( ContactEngineStubHelper::GetCalledFunction() == EContactEngineStubNone );
       
   830     
       
   831     
       
   832     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   833                                         NMusSessionApi::KContactId,
       
   834                                         2 ) );
       
   835     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   836                                         NMusSessionApi::KTelNumber,
       
   837                                         _L("12341234") ) );
       
   838     
       
   839     liveSession = CMusEngLiveSession::NewL();
       
   840     CleanupStack::PushL( liveSession );
       
   841     liveSession->SetLcSessionObserver( iLcSessionObserver );
       
   842     liveSession->SetLcUiProvider( iLcUiProvider );    
       
   843     
       
   844     delete liveSession->iRecipient;
       
   845     liveSession->iRecipient = NULL;
       
   846     liveSession->iRecipient = _L8("sip:yep@10.10.10.10").AllocL();
       
   847     liveSession->iAddressQueried = ETrue;
       
   848     CleanupStack::PopAndDestroy( liveSession );
       
   849     if ( ContactEngineStubHelper::GetCalledFunction() != EContactEngineStubSetText )
       
   850         {
       
   851         // out-of-memory was trap ignored and saving failed because of that
       
   852         User::Leave( KErrNoMemory );
       
   853         }
       
   854     EUNIT_ASSERT( ContactEngineStubHelper::GetCalledFunction() == EContactEngineStubSetText );
       
   855     }
       
   856 
       
   857 // -----------------------------------------------------------------------------
       
   858 //
       
   859 // -----------------------------------------------------------------------------
       
   860 //  
       
   861 void UT_CMusEngOutSession::UT_RemoteAddressLL()
       
   862     {
       
   863     delete iLiveSession->iRecipient;
       
   864     iLiveSession->iRecipient = NULL;
       
   865     EUNIT_ASSERT_SPECIFIC_LEAVE( iLiveSession->RemoteAddressL(), KErrNotReady )
       
   866     
       
   867     iLiveSession->iRecipient = KTestRecipient2SipUri8().AllocL();
       
   868     
       
   869     HBufC* remoteAddr = iLiveSession->RemoteAddressL();
       
   870     CleanupStack::PushL( remoteAddr );
       
   871     EUNIT_ASSERT_EQUALS( KTestRecipient2SipUri(), *remoteAddr )
       
   872     CleanupStack::PopAndDestroy( remoteAddr );
       
   873     }
       
   874 
       
   875 // -----------------------------------------------------------------------------
       
   876 // 
       
   877 // -----------------------------------------------------------------------------
       
   878 //
       
   879 void UT_CMusEngOutSession::UT_RemoteDisplayNameL()
       
   880     {
       
   881     // Test 1 : Default setting, contact name set
       
   882     EUNIT_ASSERT_EQUALS ( KTestContactName(), iLiveSession->RemoteDisplayName() )    
       
   883     
       
   884     // Test 2 : Contact name set to null descriptor
       
   885     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   886                                        NMusSessionApi::KContactName,
       
   887                                        KNullDesC) );
       
   888     delete iLiveSession;
       
   889     iLiveSession = NULL;
       
   890     iLiveSession = CMusEngLiveSession::NewL();
       
   891     iLiveSession->SetLcSessionObserver( iLcSessionObserver );
       
   892     iLiveSession->SetLcUiProvider( iLcUiProvider );    
       
   893     EUNIT_ASSERT( iLiveSession->RemoteDisplayName().Length() == 0 );
       
   894     
       
   895     // Test 3 : Manual address entered
       
   896     PropertyHelper::SetErrorCode( KErrNone );
       
   897     delete iLiveSession;
       
   898     iLiveSession = NULL;
       
   899     iLcSessionObserver->Reset();
       
   900     iLcUiProvider->Reset();
       
   901     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   902                                         NMusSessionApi::KContactName,
       
   903                                         KTestContactName ) );    
       
   904     iLcUiProvider->iSimulatedReturnValue = ETrue;
       
   905     iLcUiProvider->iRecipient.Set( KTestRecipientSipUri );
       
   906     iLiveSession = CMusEngLiveSession::NewL();
       
   907     iLiveSession->SetLcSessionObserver( iLcSessionObserver );
       
   908     iLiveSession->SetLcUiProvider( iLcUiProvider );    
       
   909     PropertyHelper::SetErrorCode( KErrNotFound );
       
   910     iLiveSession->EstablishLcSessionL();    
       
   911     EUNIT_ASSERT_EQUALS( 1, iLiveSession->iTriedInvitations )
       
   912     EUNIT_ASSERT_EQUALS( KTestRecipientSipUri(),iLiveSession->RemoteDisplayName() )
       
   913     
       
   914     // Test 4 : Contact name has zero lenth and multiple address entry query. 
       
   915     //          Displayname should have user selected address.
       
   916     //          Rare scenario.
       
   917     PropertyHelper::SetErrorCode( KErrNone );
       
   918     iLcSessionObserver->Reset();
       
   919     iLcUiProvider->Reset();
       
   920     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   921                                         NMusSessionApi::KContactName,
       
   922                                         KNullDesC) );
       
   923     delete iLiveSession;
       
   924     iLiveSession = NULL;    
       
   925     iLiveSession = CMusEngLiveSession::NewL();
       
   926     iLiveSession->SetLcSessionObserver( iLcSessionObserver );
       
   927     iLiveSession->SetLcUiProvider( iLcUiProvider );    
       
   928     iLcUiProvider->iSimulatedReturnValue = ETrue;    
       
   929     PropertyHelper::SetErrorCode( KErrNone );
       
   930     TBuf<200> multipleAddr;
       
   931     multipleAddr.Append( KTestRecipientTelUri );
       
   932     multipleAddr.Append( _L(",") );
       
   933     multipleAddr.Append( KTestRecipientSipUri );
       
   934     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   935                                         NMusSessionApi::KRemoteSipAddress,
       
   936                                         multipleAddr ) );
       
   937     iLiveSession->EstablishLcSessionL();    
       
   938     /* Stub selects the first one automatically */
       
   939     EUNIT_ASSERT_EQUALS( KTestRecipientTelUri(),iLiveSession->RemoteDisplayName() );
       
   940     
       
   941     // Test 5 : Contact name has zero lenth and no manual entry queried. 
       
   942     //          Recipient has only teluri. So displayname should have tel uri address.
       
   943     PropertyHelper::SetErrorCode( KErrNone );
       
   944     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   945                                         NMusSessionApi::KContactName,
       
   946                                         KNullDesC) );
       
   947     delete iLiveSession;
       
   948     iLiveSession = NULL;    
       
   949     iLiveSession = CMusEngLiveSession::NewL();
       
   950     iLiveSession->SetLcSessionObserver( iLcSessionObserver );
       
   951     iLiveSession->SetLcUiProvider( iLcUiProvider );    
       
   952     iLcUiProvider->iSimulatedReturnValue = ETrue;
       
   953     TBuf<200> singleAddr;
       
   954     singleAddr.Append( KTestRecipientTelUri );    
       
   955     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   956                                         NMusSessionApi::KRemoteSipAddress,
       
   957                                         singleAddr ) );
       
   958     PropertyHelper::SetErrorCode( KErrNone );
       
   959     iLiveSession->EstablishLcSessionL();
       
   960     EUNIT_ASSERT_EQUALS( KTestRecipientTelUri(),iLiveSession->RemoteDisplayName() );
       
   961     
       
   962     // Test 6 : Contact name has zero lenth and recipient has teluri 
       
   963     //          and invitation fails to teluri.
       
   964     //          Manual address query entered and now display should have entered 
       
   965     //          manual address.
       
   966     PropertyHelper::SetErrorCode( KErrNone );
       
   967     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   968                                            NMusSessionApi::KContactName,
       
   969                                            KNullDesC) );
       
   970     delete iLiveSession;
       
   971     iLiveSession = NULL;    
       
   972     iLiveSession = CMusEngLiveSession::NewL();
       
   973     iLiveSession->SetLcSessionObserver( iLcSessionObserver );
       
   974     iLiveSession->SetLcUiProvider( iLcUiProvider );    
       
   975     iLcUiProvider->iRecipient.Set( KTestRecipientSipUri );
       
   976     iLcUiProvider->iSimulatedReturnValue = ETrue;
       
   977     singleAddr.Copy( KTestRecipientTelUri );
       
   978     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   979                                         NMusSessionApi::KRemoteSipAddress,
       
   980                                         singleAddr ) );
       
   981     PropertyHelper::SetErrorCode( KErrNotFound );
       
   982     iLiveSession->EstablishLcSessionL(); 
       
   983     EUNIT_ASSERT_EQUALS( 1, iLiveSession->iTriedInvitations )
       
   984     EUNIT_ASSERT_EQUALS( KTestRecipientSipUri(),iLiveSession->RemoteDisplayName() );
       
   985     }
       
   986 
       
   987 //  TEST TABLE
   554 //  TEST TABLE
   988 
   555 
   989 EUNIT_BEGIN_TEST_TABLE(
   556 EUNIT_BEGIN_TEST_TABLE(
   990     UT_CMusEngOutSession,
   557     UT_CMusEngOutSession,
   991     "UT_CMusEngOutSesssion",
   558     "UT_CMusEngOutSesssion",
   992     "UNIT" )
   559     "UNIT" )
   993 
   560 
   994 EUNIT_TEST(
   561 EUNIT_TEST(
   995     "EstablishLcSessionL - test ",
   562     "InviteL - test ",
   996     "CMusEngOutSession",
   563     "CMusEngOutSession",
   997     "EstablishLcSessionL",
   564     "InviteL",
   998     "FUNCTIONALITY",
   565     "FUNCTIONALITY",
   999     SetupL, UT_EstablishLcSessionL, Teardown)
   566     SetupL, UT_CMusEngOutSession_InviteLL, Teardown)
  1000 
   567 
  1001 EUNIT_TEST(
   568 EUNIT_TEST(
  1002     "TerminateLcSessionL - test ",
   569     "CancelInviteL - test ",
  1003     "CMusEngOutSession",
   570     "CMusEngOutSession",
  1004     "TerminateLcSessionL",
   571     "CancelInviteL",
  1005     "FUNCTIONALITY",
   572     "FUNCTIONALITY",
  1006     SetupL, UT_TerminateLcSessionL, Teardown)    
   573     SetupL, UT_CMusEngOutSession_CancelInviteLL, Teardown)
  1007     
       
  1008 EUNIT_TEST(
       
  1009     "EstablishLcSessionL recipient resolving - test ",
       
  1010     "CMusEngOutSession",
       
  1011     "EstablishLcSessionL",
       
  1012     "FUNCTIONALITY",
       
  1013     SetupL, UT_EstablishLcSession_RecipientResolvingL, Teardown)
       
  1014 
       
  1015 EUNIT_TEST(
       
  1016     "EstablishLcSessionL registration pending - test ",
       
  1017     "CMusEngOutSession",
       
  1018     "EstablishLcSessionL",
       
  1019     "FUNCTIONALITY",
       
  1020     SetupL, UT_EstablishLcSession_RegistrationPendingL, Teardown)
       
  1021 
   574 
  1022 EUNIT_TEST(
   575 EUNIT_TEST(
  1023     "EstablishSessionL - test ",
   576     "EstablishSessionL - test ",
  1024     "CMusEngOutSession",
   577     "CMusEngOutSession",
  1025     "EstablishSessionL",
   578     "EstablishSessionL",
  1026     "FUNCTIONALITY",
   579     "FUNCTIONALITY",
  1027     SetupL, UT_EstablishSessionLL, Teardown)   
   580     SetupL, UT_CMusEngOutSession_EstablishSessionLL, Teardown)   
  1028 
   581 
  1029 EUNIT_TEST(
   582 EUNIT_TEST(
  1030     "HandleTermination - test ",
   583     "HandleTermination - test ",
  1031     "CMusEngOutSession",
   584     "CMusEngOutSession",
  1032     "HandleTermination",
   585     "HandleTermination",
  1033     "FUNCTIONALITY",
   586     "FUNCTIONALITY",
  1034     SetupL, UT_HandleTerminationL, Teardown)   
   587     SetupL, UT_CMusEngOutSession_HandleTerminationL, Teardown)   
  1035 
   588 
  1036 EUNIT_TEST(
       
  1037     "HandleTermination recipient not found - test ",
       
  1038     "CMusEngOutSession",
       
  1039     "HandleTermination recipient not found",
       
  1040     "FUNCTIONALITY",
       
  1041     SetupL, UT_HandleRecipientNotFoundTerminationL, Teardown)  
       
  1042     
       
  1043 EUNIT_TEST(
   589 EUNIT_TEST(
  1044     "AdjustVideoCodecL - test ",
   590     "AdjustVideoCodecL - test ",
  1045     "CMusEngOutSession",
   591     "CMusEngOutSession",
  1046     "AdjustVideoCodecL",
   592     "AdjustVideoCodecL",
  1047     "FUNCTIONALITY",
   593     "FUNCTIONALITY",
  1048     SetupL, UT_AdjustVideoCodecLL, Teardown)   
   594     SetupL, UT_CMusEngOutSession_AdjustVideoCodecLL, Teardown)   
  1049 
   595 
  1050 EUNIT_TEST(
   596 EUNIT_TEST(
  1051     "AdjustAudioCodecL - test ",
   597     "AdjustAudioCodecL - test ",
  1052     "CMusEngOutSession",
   598     "CMusEngOutSession",
  1053     "AdjustAudioCodecL",
   599     "AdjustAudioCodecL",
  1054     "FUNCTIONALITY",
   600     "FUNCTIONALITY",
  1055     SetupL, UT_AdjustAudioCodecLL, Teardown)   
   601     SetupL, UT_CMusEngOutSession_AdjustAudioCodecLL, Teardown)   
  1056     
   602     
  1057 EUNIT_TEST(
   603 EUNIT_TEST(
  1058     "CreateMceSessionStructureL - test ",
   604     "CreateMceSessionStructureL - test ",
  1059     "CMusEngOutSession",
   605     "CMusEngOutSession",
  1060     "CreateMceSessionStructureL",
   606     "CreateMceSessionStructureL",
  1061     "FUNCTIONALITY",
   607     "FUNCTIONALITY",
  1062     SetupL, UT_CreateMceSessionStructureLL, Teardown)    
   608     SetupL, UT_CMusEngOutSession_CreateMceSessionStructureLL, Teardown)    
  1063   
       
  1064 EUNIT_TEST(
       
  1065     "ConstructLL - test ",
       
  1066     "CMusEngOutSession",
       
  1067     "ConstructLL",
       
  1068     "FUNCTIONALITY",
       
  1069     SetupL, UT_ConstructLL, Teardown) 
       
  1070 
       
  1071 EUNIT_TEST(
       
  1072     "ContactSavingL - test ",
       
  1073     "CMusEngOutSession",
       
  1074     "ContactSavingL",
       
  1075     "FUNCTIONALITY",
       
  1076     SetupL, UT_ContactSavingLL, Teardown) 
       
  1077 
       
  1078 EUNIT_TEST(
       
  1079     "RemoteAddressLL - test ",
       
  1080     "CMusEngOutSession",
       
  1081     "RemoteAddressLL",
       
  1082     "FUNCTIONALITY",
       
  1083     SetupL, UT_RemoteAddressLL, Teardown)
       
  1084 
       
  1085 EUNIT_TEST(
       
  1086     "RemoteDisplayName - test ",
       
  1087     "CMusEngOutSession",
       
  1088     "RemoteDisplayName",
       
  1089     "FUNCTIONALITY",
       
  1090     SetupL, UT_RemoteDisplayNameL, Teardown)
       
  1091 
   609 
  1092 EUNIT_END_TEST_TABLE
   610 EUNIT_END_TEST_TABLE
  1093 
   611 
  1094 //  END OF FILE
   612 //  END OF FILE
  1095 
   613