mmsharing/mmshengine/tsrc/ut_engine/src/ut_musengoutsession.cpp
branchRCL_3
changeset 22 73a1feb507fb
parent 0 f0cf47e981f9
child 23 bc78a40cd63c
equal deleted inserted replaced
21:33a5d2bbf6fc 22:73a1feb507fb
    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 
    23 #include "sipprofile.h"
    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 
    27 #include "mussessionproperties.h"
       
    28 #include "contactenginestub.h"
    28 
    29 
    29 //  SYSTEM INCLUDES
    30 //  SYSTEM INCLUDES
       
    31 #include <lcsourcefilecontrol.h>
    30 #include <digia/eunit/eunitmacros.h>
    32 #include <digia/eunit/eunitmacros.h>
    31 
       
    32 #include <mceoutsession.h>
    33 #include <mceoutsession.h>
    33 #include <mcestreambundle.h>
    34 #include <mcestreambundle.h>
    34 #include <mceaudiostream.h>
    35 #include <mceaudiostream.h>
    35 #include <mcevideostream.h>
    36 #include <mcevideostream.h>
    36 #include <mcespeakersink.h>
    37 #include <mcespeakersink.h>
    37 #include <mcedisplaysink.h>
    38 #include <mcedisplaysink.h>
    38 #include <mceh263codec.h>
    39 #include <mceh263codec.h>
    39 #include <mceavccodec.h>
    40 #include <mceavccodec.h>
    40 #include <mceaudiocodec.h>
    41 #include <mceaudiocodec.h>
    41 
    42 #include <mcecamerasource.h>
    42 #include <sipprofile.h>
    43 
       
    44 
    43 #include <sipstrings.h>
    45 #include <sipstrings.h>
    44 
    46 
    45 #include <audiopreference.h>
    47 #include <audiopreference.h>
    46 #include <uri8.h>
    48 #include <uri8.h>
    47 
    49 
       
    50 _LIT( KTestContactName, "nokia" );
    48 
    51 
    49 // -----------------------------------------------------------------------------
    52 // -----------------------------------------------------------------------------
    50 //
    53 //
    51 // -----------------------------------------------------------------------------
    54 // -----------------------------------------------------------------------------
    52 //
    55 //
   107 //
   110 //
   108 // -----------------------------------------------------------------------------
   111 // -----------------------------------------------------------------------------
   109 //
   112 //
   110 void UT_CMusEngOutSession::SetupL()
   113 void UT_CMusEngOutSession::SetupL()
   111     {
   114     {
   112     iObserver = new( ELeave ) CMusEngObserverStub;
   115     
   113     iLiveSession = CMusEngLiveSession::NewL( KNullDesC(),
   116     PropertyHelper::SetErrorCode( KErrNone );
   114                                              TRect(0,0, 100,100),
   117     
   115                                              *iObserver,
   118     iLcSessionObserver = new( ELeave )CLcSessionObserverStub;
   116                                              *iObserver,
   119     iLcUiProvider = new( ELeave )CLcUiProviderStub;
   117                                              *iObserver );
   120     iAudioRoutingObserver = new( ELeave )CMusEngObserverStub;
       
   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 
   118     SIPStrings::OpenL();
   129     SIPStrings::OpenL();
   119     
   130     
   120     iLiveSession->iPrivate = EFalse;
   131     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
   121     iLiveSession->iPrivateNumber = EFalse;
   132                                         NMusSessionApi::KRemoteSipAddress,
   122     
   133                                         KTestRecipientSipUri ) );
   123     }
   134     }
   124 
   135 
   125 
   136 
   126 // -----------------------------------------------------------------------------
   137 // -----------------------------------------------------------------------------
   127 //
   138 //
   129 //
   140 //
   130 void UT_CMusEngOutSession::Teardown()
   141 void UT_CMusEngOutSession::Teardown()
   131     {
   142     {
   132     SIPStrings::Close();
   143     SIPStrings::Close();
   133     delete iLiveSession;
   144     delete iLiveSession;
   134     delete iObserver;
   145     delete iLcSessionObserver;
   135     }
   146     delete iLcUiProvider;
   136 
   147     delete iAudioRoutingObserver;
       
   148     PropertyHelper::SetErrorCode( KErrNone );
       
   149     PropertyHelper::Close();
       
   150     }
   137 
   151 
   138 
   152 
   139 // TEST CASES
   153 // TEST CASES
   140 
   154 
   141 
   155 // -----------------------------------------------------------------------------
   142 // -----------------------------------------------------------------------------
   156 //
   143 //
   157 // -----------------------------------------------------------------------------
   144 // -----------------------------------------------------------------------------
   158 //
   145 //
   159 void UT_CMusEngOutSession::UT_EstablishLcSessionL()
   146 void UT_CMusEngOutSession::UT_CMusEngOutSession_InviteLL()
   160     {
   147     {
       
   148 
       
   149     // Initial state
   161     // Initial state
   150     EUNIT_ASSERT( !iLiveSession->iSession );
   162     EUNIT_ASSERT( !iLiveSession->iSession );
   151     
   163     
   152     // Simulate failing session structure construction.
   164     ///////////////////////////////////////////////////////////////////////////
   153     iLiveSession->InviteL( KTestRecipientSipUri );
   165     // 1. Simulate failing session structure construction.
       
   166     iLiveSession->EstablishLcSessionL();
   154     
   167     
   155     iLiveSession->iSession->iState = CMceSession::EIdle;
   168     iLiveSession->iSession->iState = CMceSession::EIdle;
   156     delete iLiveSession->iSession->Streams()[0];
   169     delete iLiveSession->iSession->Streams()[0];
   157     const RPointerArray<CMceMediaStream>& constStreams = 
   170     const RPointerArray<CMceMediaStream>& constStreams = 
   158                                             iLiveSession->iSession->Streams();
   171                                             iLiveSession->iSession->Streams();
   159     const_cast<RPointerArray<CMceMediaStream>&>(constStreams)[0] = NULL;
   172     const_cast<RPointerArray<CMceMediaStream>&>(constStreams)[0] = NULL;
   160 
   173 
   161     // Normal invite
   174     ///////////////////////////////////////////////////////////////////////////
   162     iLiveSession->InviteL( KTestRecipientSipUri );
   175     // 2. Normal invite
       
   176     iLiveSession->EstablishLcSessionL();
   163     
   177     
   164     EUNIT_ASSERT( iLiveSession->iSession );
   178     EUNIT_ASSERT( iLiveSession->iSession );
   165     // Next assertion ensures that session structure is new
   179     // Next assertion ensures that session structure is new
       
   180     EUNIT_ASSERT( iLiveSession->iSession->Streams().Count() > 0 );   
   166     EUNIT_ASSERT( iLiveSession->iSession->Streams()[0] ); 
   181     EUNIT_ASSERT( iLiveSession->iSession->Streams()[0] ); 
   167     EUNIT_ASSERT( *(iLiveSession->iRecipient) == KTestRecipientSipUri8() );
   182     EUNIT_ASSERT( *(iLiveSession->iRecipient) == KTestRecipientSipUri8() );
   168     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   183     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   169     
   184     
   170     EUNIT_ASSERT( iLiveSession->iSession->iHeaders );
   185     EUNIT_ASSERT( iLiveSession->iSession->iHeaders );
   175                   KMusAcceptHeader() );    
   190                   KMusAcceptHeader() );    
   176     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines );
   191     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines );
   177     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->Count() == 1 );
   192     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->Count() == 1 );
   178     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->MdcaPoint( 0 ) ==
   193     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->MdcaPoint( 0 ) ==
   179                   KMusEngSessionSdpLineXApplication() );
   194                   KMusEngSessionSdpLineXApplication() );
   180     
   195         
   181     // Normal operator invite
   196     // Ensure there is no SDP lines at media level
       
   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
   182     delete iLiveSession;
   204     delete iLiveSession;
   183     iLiveSession = NULL;
   205     iLiveSession = NULL;
   184     iLiveSession = CMusEngLiveSession::NewL( KNullDesC,
   206     iLiveSession = CMusEngLiveSession::NewL();
   185                                              TRect(0,0, 100,100),
   207     iLiveSession->SetLcSessionObserver( iLcSessionObserver );
   186                                              *iObserver,
   208     iLiveSession->SetLcUiProvider( iLcUiProvider );    
   187                                              *iObserver,
       
   188                                              *iObserver );
       
   189    	iLiveSession->iOperatorVariant = ETrue;
   209    	iLiveSession->iOperatorVariant = ETrue;
   190    	CSIPProfile* profile = iLiveSession->iSipProfileHandler->Profile();
   210    	CSIPProfile* profile = iLiveSession->iSipProfileHandler->Profile();
   191     delete profile->iArray;
   211     delete profile->iArray;
   192     profile->iArray = NULL;
   212     profile->iArray = NULL;
   193     profile->iArray = new ( ELeave ) CDesC8ArrayFlat( 1 );
   213     profile->iArray = new ( ELeave ) CDesC8ArrayFlat( 1 );
   194     profile->iArray->AppendL( KMusTestUri );
   214     profile->iArray->AppendL( KMusTestUri );
   195 
   215 
   196     iLiveSession->InviteL( KTestRecipientSipUri );
   216     iLiveSession->EstablishLcSessionL();
   197     
   217     
   198     EUNIT_ASSERT( iLiveSession->iSession );
   218     EUNIT_ASSERT( iLiveSession->iSession );
   199     // Next assertion ensures that session structure is new
   219     // Next assertion ensures that session structure is new
   200     EUNIT_ASSERT( iLiveSession->iSession->Streams()[0] ); 
       
   201     EUNIT_ASSERT( *(iLiveSession->iRecipient) == KTestRecipientSipUri8() );
   220     EUNIT_ASSERT( *(iLiveSession->iRecipient) == KTestRecipientSipUri8() );
   202     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   221     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   203     
   222     
   204     EUNIT_ASSERT( iLiveSession->iSession->iHeaders );
   223     EUNIT_ASSERT( iLiveSession->iSession->iHeaders );
   205     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->Count() == 3 );
   224     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->Count() == 3 );
   209                   KMusAcceptHeader() );
   228                   KMusAcceptHeader() );
   210     
   229     
   211     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 2 ) ==
   230     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 2 ) ==
   212                   KMusPPreferredIdentityTestHeader() );
   231                   KMusPPreferredIdentityTestHeader() );
   213     
   232     
       
   233     // Ensure there is only a=type and a=application attributes (and no b=TIAS)
       
   234     // at session level for operator variant
   214     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines );
   235     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines );
   215     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->Count() == 2 );
   236     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->Count() == 2 );
   216     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->MdcaPoint( 0 ) ==
   237     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->MdcaPoint( 0 ) ==
   217                   KMusEngSessionSdpLineApplication() )
   238                   KMusEngSessionSdpLineApplication() )
   218    	EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->MdcaPoint( 1 ) ==
   239    	EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->MdcaPoint( 1 ) ==
   219                   KMusEngSessionSdpLineType() )
   240                   KMusEngSessionSdpLineType() )
   220                   
   241                   
   221     EUNIT_ASSERT( iLiveSession->iSession->Streams().Count() > 0 );   
   242     EUNIT_ASSERT( iLiveSession->iSession->Streams().Count() > 0 );   
   222     TBool foundBandwidthLineFromMediaLevel( EFalse );
   243     EUNIT_ASSERT( iLiveSession->iSession->Streams()[0] ); 
   223     for ( TInt i = 0; i <  iLiveSession->iSession->Streams().Count(); i++ )
   244     EUNIT_ASSERT( iLiveSession->iSession->Streams()[0]->Type() == KMceVideo );
   224         {
   245 
   225         if ( iLiveSession->iSession->Streams()[0]->Type() == KMceVideo )
   246     // Ensure there is only b=AS and no b=TIAS present at media level
   226             {
   247     // for operator variant
   227             if ( iLiveSession->iSession->Streams()[0]->iMediaSDPLines->MdcaCount() > 0 &&
   248     mediaSdpLines = iLiveSession->iSession->Streams()[0]->iMediaSDPLines;
   228                  iLiveSession->iSession->Streams()[0]->iMediaSDPLines->MdcaPoint( 0 ) ==
   249     EUNIT_ASSERT( mediaSdpLines );
   229                     KMusEngSessionSdpLineBandwidthField() )
   250     EUNIT_ASSERT( mediaSdpLines->MdcaCount() == 1 );
   230                 {
   251     EUNIT_ASSERT( mediaSdpLines->MdcaPoint( 0 ) == 
   231                 foundBandwidthLineFromMediaLevel = ETrue;
   252                   KMusEngSessionSdpLineBandwidthField() );
   232                 }
   253     
   233             }
   254     ///////////////////////////////////////////////////////////////////////////
   234         }
   255     // 4. Try invite again, must fail
   235     EUNIT_ASSERT( foundBandwidthLineFromMediaLevel );
   256     TRAPD( error, iLiveSession->EstablishLcSessionL() );
   236                       
       
   237     // Try invite again, must fail
       
   238     TRAPD( error, iLiveSession->InviteL( KTestRecipientSipUri ) );
       
   239     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
   257     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
   240     EUNIT_ASSERT( error == KErrAlreadyExists );
   258     EUNIT_ASSERT( error == KErrAlreadyExists );
   241     
   259     
   242     // Simulate normal session ending, no need for observer call in this case
   260     // 5. Simulate normal session ending, no need for observer call in this case
   243     iLiveSession->iSession->iState = CMceSession::ETerminated;
   261     iLiveSession->iSession->iState = CMceSession::ETerminated;
   244     
   262     
   245     // Try again. Establishment must be OK with new MceSession object
   263     // Try again. Establishment must be OK with new MceSession object
   246     iLiveSession->InviteL( KTestRecipientSipUri );
   264     iLiveSession->EstablishLcSessionL();
   247     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   265     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   248 
   266     }
   249       
   267     
   250     }
   268 // -----------------------------------------------------------------------------
   251     
   269 //
       
   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     }
   252 
   419 
   253 // -----------------------------------------------------------------------------
   420 // -----------------------------------------------------------------------------
   254 //
   421 //
   255 // -----------------------------------------------------------------------------
   422 // -----------------------------------------------------------------------------
   256 //    
   423 //    
   257 void UT_CMusEngOutSession::UT_CMusEngOutSession_CancelInviteLL()
   424 void UT_CMusEngOutSession::UT_TerminateLcSessionL()
   258     {
   425     {
   259     // Try to cancel, must fail
   426     // No MCE session
   260     TRAPD( error, iLiveSession->CancelInviteL() );
   427     EUNIT_ASSERT_SPECIFIC_LEAVE( 
   261     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
   428         iLiveSession->TerminateLcSessionL(), KErrNotReady )
   262     EUNIT_ASSERT( error == KErrNotReady );
   429 
   263     
   430     // Cancel a session that is in offering state
   264     // Invite
   431     iLiveSession->EstablishLcSessionL();
   265     iLiveSession->InviteL( KTestRecipientSipUri );
   432     EUNIT_ASSERT_EQUALS( TInt( CMceSession::EOffering ),
   266     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   433                          TInt( iLiveSession->iSession->iState ) )
   267     
   434     iLiveSession->TerminateLcSessionL();
   268     // Cancel
   435     EUNIT_ASSERT_EQUALS( TInt( CMceSession::ECancelling ),
   269     iLiveSession->CancelInviteL();
   436                          TInt( iLiveSession->iSession->iState ) )
   270     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::ECancelling );
   437     
   271     
   438     // Terminate an established session
   272     // Try to cancel again, does nothing
   439     iLiveSession->iSession->iState = CMceSession::ETerminated;
   273     iLiveSession->CancelInviteL();
   440     iLiveSession->EstablishLcSessionL();
   274     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::ECancelling );
   441     iLiveSession->iSession->iState = CMceSession::EEstablished;
   275     }
   442     iLiveSession->TerminateLcSessionL();
   276 
   443     EUNIT_ASSERT_EQUALS( TInt( CMceSession::ETerminating ),
       
   444                          TInt( iLiveSession->iSession->iState ) )
       
   445     }
   277 
   446 
   278 // -----------------------------------------------------------------------------
   447 // -----------------------------------------------------------------------------
   279 //
   448 //
   280 // -----------------------------------------------------------------------------
   449 // -----------------------------------------------------------------------------
   281 //  
   450 //  
   282 void UT_CMusEngOutSession::UT_CMusEngOutSession_EstablishSessionLL()
   451 void UT_CMusEngOutSession::UT_EstablishSessionLL()
   283     {
   452     {
   284     // Try to establish, must fail, because of missing session
   453     // Try to establish, must fail, because of missing session
   285     TRAPD( error, iLiveSession->EstablishSessionL() );
   454     TRAPD( error, iLiveSession->EstablishSessionL() );
   286     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
   455     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
   287     EUNIT_ASSERT( error == KErrNotReady );
   456     EUNIT_ASSERT( error == KErrNotReady );
   288     iLiveSession->iPrivate = ETrue;
       
   289     iLiveSession->iPrivateNumber = EFalse;
       
   290     
   457     
   291     // Call to CMusEngOutMceSession::InviteL leads to call to EstablishL
   458     // Call to CMusEngOutMceSession::InviteL leads to call to EstablishL
   292     iLiveSession->InviteL( KTestRecipientSipUri );
   459     iLiveSession->EstablishLcSessionL();
   293     
   460     
   294     // Check that ports are correct
   461     // Check that ports are correct
   295     
   462     
   296     for ( TInt i = 0; i < iLiveSession->iSession->Streams().Count(); ++i )
   463     for ( TInt i = 0; i < iLiveSession->iSession->Streams().Count(); ++i )
   297         {
   464         {
   313     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 0 ) ==
   480     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 0 ) ==
   314                   KMusEngAcceptContactHeader() )
   481                   KMusEngAcceptContactHeader() )
   315     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 1 ) ==
   482     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 1 ) ==
   316                   KMusAcceptHeader() );   
   483                   KMusAcceptHeader() );   
   317     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   484     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
   318     
   485     }
   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 
       
   345 
   486 
   346 // -----------------------------------------------------------------------------
   487 // -----------------------------------------------------------------------------
   347 //
   488 //
   348 // -----------------------------------------------------------------------------
   489 // -----------------------------------------------------------------------------
   349 //    
   490 //    
   350 void UT_CMusEngOutSession::UT_CMusEngOutSession_HandleTerminationL()
   491 void UT_CMusEngOutSession::UT_HandleTerminationL()
   351     {
   492     {
   352 
   493     // Try different values    
   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     
       
   390     iLiveSession->HandleTermination( KSipStatusCode408ConnectionTimeOut, 
   494     iLiveSession->HandleTermination( KSipStatusCode408ConnectionTimeOut, 
   391                                      KNullDesC8() );
   495                                      KNullDesC8() );
   392     EUNIT_ASSERT( iObserver->iSessionRequestTimeOutCalled );
   496     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   393     iObserver->Reset();
   497                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   498     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   499                          TInt( MLcSession::ENoAnswer ) )
       
   500     iLcSessionObserver->Reset();
   394     
   501     
   395     iLiveSession->HandleTermination( KSipStatusCode415UnsupportedMediaType, 
   502     iLiveSession->HandleTermination( KSipStatusCode415UnsupportedMediaType, 
   396                                      KNullDesC8() );
   503                                      KNullDesC8() );
   397     EUNIT_ASSERT( iObserver->iSessionUnsupportedMediaTypeCalled );
   504     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   398     iObserver->Reset();
   505                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   506     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   507                          TInt( MLcSession::ESessionRejected ) ) 
       
   508     iLcSessionObserver->Reset();
   399     
   509     
   400     iLiveSession->HandleTermination( KSipStatusCode488NotAcceptableHere, 
   510     iLiveSession->HandleTermination( KSipStatusCode488NotAcceptableHere, 
   401                                      KNullDesC8() );
   511                                      KNullDesC8() );
   402     EUNIT_ASSERT( iObserver->iSessionUnsupportedMediaTypeCalled );
   512     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   403     iObserver->Reset();
   513                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   514     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   515                          TInt( MLcSession::ESessionRejected ) )
       
   516     iLcSessionObserver->Reset();
   404     
   517     
   405     iLiveSession->HandleTermination( KSipStatusCode606NotAcceptable, 
   518     iLiveSession->HandleTermination( KSipStatusCode606NotAcceptable, 
   406                                      KNullDesC8() );
   519                                      KNullDesC8() );
   407     EUNIT_ASSERT( iObserver->iSessionUnsupportedMediaTypeCalled );
   520     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   408     iObserver->Reset(); 
   521                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   522     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   523                          TInt( MLcSession::ESessionRejected ) )
       
   524     iLcSessionObserver->Reset(); 
   409     
   525     
   410     iLiveSession->HandleTermination( KSipStatusCode486BusyHere, 
   526     iLiveSession->HandleTermination( KSipStatusCode486BusyHere, 
   411                                      KNullDesC8() );
   527                                      KNullDesC8() );
   412     EUNIT_ASSERT( iObserver->iSessionBusyHereCalled );
   528     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   413     iObserver->Reset();
   529                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   530     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   531                          TInt( MLcSession::ERecipientBusy ) )
       
   532     iLcSessionObserver->Reset();
   414     
   533     
   415     iLiveSession->HandleTermination( KSipStatusCode487RequestCancelled, 
   534     iLiveSession->HandleTermination( KSipStatusCode487RequestCancelled, 
   416                                      KNullDesC8() );
   535                                      KNullDesC8() );
   417     EUNIT_ASSERT( iObserver->iSessionRequestCancelledCalled );
   536     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   418     iObserver->Reset();
   537                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   538     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   539                          TInt( MLcSession::ESessionCancelled ) )
       
   540     iLcSessionObserver->Reset();
   419     
   541     
   420     iLiveSession->HandleTermination( KSipStatusCode603Decline, KNullDesC8()  );
   542     iLiveSession->HandleTermination( KSipStatusCode603Decline, KNullDesC8()  );
   421     EUNIT_ASSERT( iObserver->iSessionRejectedCalled );
   543     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   422     iObserver->Reset();
   544                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   545     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   546                          TInt( MLcSession::ESessionRejected ) )
       
   547     iLcSessionObserver->Reset();
   423 
   548 
   424     iLiveSession->HandleTermination( KSipStatusCode480TemporarilyNotAvailable, 
   549     iLiveSession->HandleTermination( KSipStatusCode480TemporarilyNotAvailable, 
   425                                      KNullDesC8() );
   550                                      KNullDesC8() );
   426     EUNIT_ASSERT( iObserver->iSessionTemporarilyNotAvailable );
   551     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   427     iObserver->Reset();
   552                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   553     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   554                          TInt( MLcSession::ERecipientTemporarilyNotAvailable ) )
       
   555     iLcSessionObserver->Reset();
   428     
   556     
   429     // Receive 486 with operator variant
   557     // Receive 486 with operator variant
   430     iLiveSession->iOperatorVariant = ETrue;
   558     iLiveSession->iOperatorVariant = ETrue;
   431     iLiveSession->HandleTermination( KSipStatusCode486BusyHere, KNullDesC8()  );
   559     iLiveSession->HandleTermination( KSipStatusCode486BusyHere, KNullDesC8()  );
   432     EUNIT_ASSERT( iObserver->iSessionRejectedCalled )
   560     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   433     EUNIT_ASSERT( !iObserver->iSessionBusyHereCalled )
   561                          TInt( CLcSessionObserverStub::ESessionFailed ) )
   434     iObserver->Reset();
   562     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   563                          TInt( MLcSession::ESessionRejected ) )    
       
   564     iLcSessionObserver->Reset();
   435     iLiveSession->iOperatorVariant = EFalse;
   565     iLiveSession->iOperatorVariant = EFalse;
   436     
   566     
   437     // Normal termination, let the base class handle
   567     // Normal termination, let the base class handle
   438     iLiveSession->HandleTermination(  KSipStatusCode200OK, KNullDesC8()  );
   568     iLiveSession->HandleTermination(  KSipStatusCode200OK, KNullDesC8()  );
   439     EUNIT_ASSERT( iObserver->iSessionTerminatedCalled ); // called by base class
   569     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   440     iObserver->Reset();
   570                          TInt( CLcSessionObserverStub::ESessionStateChanged ) )
   441 
   571     iLcSessionObserver->Reset();
   442     }    
   572     }    
   443 
   573 
       
   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     }
   444 
   655 
   445 // -----------------------------------------------------------------------------
   656 // -----------------------------------------------------------------------------
   446 //
   657 //
   447 // -----------------------------------------------------------------------------
   658 // -----------------------------------------------------------------------------
   448 //   
   659 //   
   449 void UT_CMusEngOutSession::UT_CMusEngOutSession_AdjustVideoCodecLL()
   660 void UT_CMusEngOutSession::UT_AdjustVideoCodecLL()
   450     {
   661     {
   451     //H263
   662     //H263
   452     CMceH263Codec* codecH263 = CMceH263Codec::NewLC( KMceSDPNameH2632000() );
   663     CMceH263Codec* codecH263 = CMceH263Codec::NewLC( KMceSDPNameH2632000() );
   453     iLiveSession->CMusEngMceOutSession::AdjustVideoCodecL( *codecH263 );
   664     iLiveSession->CMusEngMceOutSession::AdjustVideoCodecL( *codecH263,
       
   665                                                            KMceCameraSource );
   454     // Test payloadtype
   666     // Test payloadtype
   455     EUNIT_ASSERT( codecH263->iPayloadType == 96 )
   667     EUNIT_ASSERT( codecH263->iPayloadType == 96 )
   456     CleanupStack::PopAndDestroy( codecH263 );
   668     CleanupStack::PopAndDestroy( codecH263 );
   457     
   669     
   458     //H264
   670     //H264
   459     CMceAvcCodec* codecAvc = CMceAvcCodec::NewLC( KMceSDPNameH264() );
   671     CMceAvcCodec* codecAvc = CMceAvcCodec::NewLC( KMceSDPNameH264() );
   460     iLiveSession->CMusEngMceOutSession::AdjustVideoCodecL( *codecAvc );
   672     iLiveSession->CMusEngMceOutSession::AdjustVideoCodecL( *codecAvc,
       
   673                                                            KMceCameraSource  );
   461     // Test payloadtype
   674     // Test payloadtype
   462     EUNIT_ASSERT( codecAvc->iPayloadType == 98 )
   675     EUNIT_ASSERT( codecAvc->iPayloadType == 98 )
   463     CleanupStack::PopAndDestroy( codecAvc );
   676     CleanupStack::PopAndDestroy( codecAvc );
   464     }
   677     }
   465 
   678 
   466 
       
   467 // -----------------------------------------------------------------------------
   679 // -----------------------------------------------------------------------------
   468 //
   680 //
   469 // -----------------------------------------------------------------------------
   681 // -----------------------------------------------------------------------------
   470 //   
   682 //   
   471 void UT_CMusEngOutSession::UT_CMusEngOutSession_AdjustAudioCodecLL()
   683 void UT_CMusEngOutSession::UT_AdjustAudioCodecLL()
   472     {
   684     {
   473     CMceAudioCodec* codec = 
   685     CMceAudioCodec* codec = 
   474                 iLiveSession->iManager->SupportedAudioCodecs()[0]->CloneL();
   686                 iLiveSession->iManager->SupportedAudioCodecs()[0]->CloneL();
   475     CleanupStack::PushL( codec );
   687     CleanupStack::PushL( codec );
   476     iLiveSession->CMusEngMceOutSession::AdjustAudioCodecL( *codec );
   688     iLiveSession->CMusEngMceOutSession::AdjustAudioCodecL( *codec );
   485     EUNIT_ASSERT( codec->iMMFPriorityPreference == KAudioPrefSwisPlayback )
   697     EUNIT_ASSERT( codec->iMMFPriorityPreference == KAudioPrefSwisPlayback )
   486     
   698     
   487     CleanupStack::PopAndDestroy( codec );
   699     CleanupStack::PopAndDestroy( codec );
   488     }
   700     }
   489         
   701         
   490 
       
   491 // -----------------------------------------------------------------------------
   702 // -----------------------------------------------------------------------------
   492 //
   703 //
   493 // -----------------------------------------------------------------------------
   704 // -----------------------------------------------------------------------------
   494 //   
   705 //   
   495 void UT_CMusEngOutSession::UT_CMusEngOutSession_CreateMceSessionStructureLL()
   706 void UT_CMusEngOutSession::UT_CreateMceSessionStructureLL()
   496     {
   707     {
   497     // Test removal of QoS-lines
   708     // Test removal of QoS-lines
   498     
   709     
   499     iLiveSession->iRecipient = KTestRecipientSipUri8().AllocL();
   710     iLiveSession->iRecipient = KTestRecipientSipUri8().AllocL();
   500   
   711   
   522     
   733     
   523     // Test bundling
   734     // Test bundling
   524     
   735     
   525     EUNIT_ASSERT( iLiveSession->iSession->Bundles().Count() == 0 )
   736     EUNIT_ASSERT( iLiveSession->iSession->Bundles().Count() == 0 )
   526 
   737 
   527     CMusEngClipSession* clipSession = CMusEngClipSession::NewL(
   738     CMusEngClipSession* clipSession = CMusEngClipSession::NewL();
   528                                                     TRect(0, 100, 200, 300 ),
       
   529                                                     *iObserver,
       
   530                                                     *iObserver,
       
   531                                                     *iObserver );
       
   532     CleanupStack::PushL( clipSession );
   739     CleanupStack::PushL( clipSession );
   533     
   740     clipSession->SetLcSessionObserver( iLcSessionObserver );
   534     clipSession->SetClipL( KTestVideoFileName );
   741     clipSession->SetLcUiProvider( iLcUiProvider );    
       
   742     clipSession->LocalVideoPlayer()->LcSourceFileControl()->SetLcFileNameL(
       
   743         KTestVideoFileName() );
   535     
   744     
   536     clipSession->iRecipient = KTestRecipientSipUri8().AllocL();
   745     clipSession->iRecipient = KTestRecipientSipUri8().AllocL();
   537     
   746     
   538     clipSession->CreateMceSessionStructureL();
   747     clipSession->CreateMceSessionStructureL();
   539     
   748     
   549                   KMceDisplaySink )
   758                   KMceDisplaySink )
   550 
   759 
   551     CleanupStack::PopAndDestroy( clipSession );
   760     CleanupStack::PopAndDestroy( clipSession );
   552     }
   761     }
   553 
   762 
       
   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 
   554 //  TEST TABLE
   987 //  TEST TABLE
   555 
   988 
   556 EUNIT_BEGIN_TEST_TABLE(
   989 EUNIT_BEGIN_TEST_TABLE(
   557     UT_CMusEngOutSession,
   990     UT_CMusEngOutSession,
   558     "UT_CMusEngOutSesssion",
   991     "UT_CMusEngOutSesssion",
   559     "UNIT" )
   992     "UNIT" )
   560 
   993 
   561 EUNIT_TEST(
   994 EUNIT_TEST(
   562     "InviteL - test ",
   995     "EstablishLcSessionL - test ",
   563     "CMusEngOutSession",
   996     "CMusEngOutSession",
   564     "InviteL",
   997     "EstablishLcSessionL",
   565     "FUNCTIONALITY",
   998     "FUNCTIONALITY",
   566     SetupL, UT_CMusEngOutSession_InviteLL, Teardown)
   999     SetupL, UT_EstablishLcSessionL, Teardown)
   567 
  1000 
   568 EUNIT_TEST(
  1001 EUNIT_TEST(
   569     "CancelInviteL - test ",
  1002     "TerminateLcSessionL - test ",
   570     "CMusEngOutSession",
  1003     "CMusEngOutSession",
   571     "CancelInviteL",
  1004     "TerminateLcSessionL",
   572     "FUNCTIONALITY",
  1005     "FUNCTIONALITY",
   573     SetupL, UT_CMusEngOutSession_CancelInviteLL, Teardown)
  1006     SetupL, UT_TerminateLcSessionL, 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)
   574 
  1021 
   575 EUNIT_TEST(
  1022 EUNIT_TEST(
   576     "EstablishSessionL - test ",
  1023     "EstablishSessionL - test ",
   577     "CMusEngOutSession",
  1024     "CMusEngOutSession",
   578     "EstablishSessionL",
  1025     "EstablishSessionL",
   579     "FUNCTIONALITY",
  1026     "FUNCTIONALITY",
   580     SetupL, UT_CMusEngOutSession_EstablishSessionLL, Teardown)   
  1027     SetupL, UT_EstablishSessionLL, Teardown)   
   581 
  1028 
   582 EUNIT_TEST(
  1029 EUNIT_TEST(
   583     "HandleTermination - test ",
  1030     "HandleTermination - test ",
   584     "CMusEngOutSession",
  1031     "CMusEngOutSession",
   585     "HandleTermination",
  1032     "HandleTermination",
   586     "FUNCTIONALITY",
  1033     "FUNCTIONALITY",
   587     SetupL, UT_CMusEngOutSession_HandleTerminationL, Teardown)   
  1034     SetupL, UT_HandleTerminationL, Teardown)   
   588 
  1035 
       
  1036 EUNIT_TEST(
       
  1037     "HandleTermination recipient not found - test ",
       
  1038     "CMusEngOutSession",
       
  1039     "HandleTermination recipient not found",
       
  1040     "FUNCTIONALITY",
       
  1041     SetupL, UT_HandleRecipientNotFoundTerminationL, Teardown)  
       
  1042     
   589 EUNIT_TEST(
  1043 EUNIT_TEST(
   590     "AdjustVideoCodecL - test ",
  1044     "AdjustVideoCodecL - test ",
   591     "CMusEngOutSession",
  1045     "CMusEngOutSession",
   592     "AdjustVideoCodecL",
  1046     "AdjustVideoCodecL",
   593     "FUNCTIONALITY",
  1047     "FUNCTIONALITY",
   594     SetupL, UT_CMusEngOutSession_AdjustVideoCodecLL, Teardown)   
  1048     SetupL, UT_AdjustVideoCodecLL, Teardown)   
   595 
  1049 
   596 EUNIT_TEST(
  1050 EUNIT_TEST(
   597     "AdjustAudioCodecL - test ",
  1051     "AdjustAudioCodecL - test ",
   598     "CMusEngOutSession",
  1052     "CMusEngOutSession",
   599     "AdjustAudioCodecL",
  1053     "AdjustAudioCodecL",
   600     "FUNCTIONALITY",
  1054     "FUNCTIONALITY",
   601     SetupL, UT_CMusEngOutSession_AdjustAudioCodecLL, Teardown)   
  1055     SetupL, UT_AdjustAudioCodecLL, Teardown)   
   602     
  1056     
   603 EUNIT_TEST(
  1057 EUNIT_TEST(
   604     "CreateMceSessionStructureL - test ",
  1058     "CreateMceSessionStructureL - test ",
   605     "CMusEngOutSession",
  1059     "CMusEngOutSession",
   606     "CreateMceSessionStructureL",
  1060     "CreateMceSessionStructureL",
   607     "FUNCTIONALITY",
  1061     "FUNCTIONALITY",
   608     SetupL, UT_CMusEngOutSession_CreateMceSessionStructureLL, Teardown)    
  1062     SetupL, UT_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)
   609 
  1091 
   610 EUNIT_END_TEST_TABLE
  1092 EUNIT_END_TEST_TABLE
   611 
  1093 
   612 //  END OF FILE
  1094 //  END OF FILE
   613 
  1095