mmsharing/mmshengine/tsrc/ut_engine/src/ut_musengoutsession.cpp
changeset 22 496ad160a278
equal deleted inserted replaced
15:ccd8e69b5392 22:496ad160a278
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INTERNAL INCLUDES
       
    20 #include "ut_musengoutsession.h"
       
    21 #include "musengstubs.h"
       
    22 #include "musengtestdefs.h"
       
    23 #include "sipprofile.h"
       
    24 #include "musenglivesession.h"
       
    25 #include "musengclipsession.h"
       
    26 #include "mussipprofilehandler.h"
       
    27 #include "mussessionproperties.h"
       
    28 #include "contactenginestub.h"
       
    29 
       
    30 //  SYSTEM INCLUDES
       
    31 #include <lcsourcefilecontrol.h>
       
    32 #include <digia/eunit/eunitmacros.h>
       
    33 #include <mceoutsession.h>
       
    34 #include <mcestreambundle.h>
       
    35 #include <mceaudiostream.h>
       
    36 #include <mcevideostream.h>
       
    37 #include <mcespeakersink.h>
       
    38 #include <mcedisplaysink.h>
       
    39 #include <mceh263codec.h>
       
    40 #include <mceavccodec.h>
       
    41 #include <mceaudiocodec.h>
       
    42 #include <mcecamerasource.h>
       
    43 
       
    44 
       
    45 #include <sipstrings.h>
       
    46 
       
    47 #include <audiopreference.h>
       
    48 #include <uri8.h>
       
    49 
       
    50 _LIT( KTestContactName, "nokia" );
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 UT_CMusEngOutSession* UT_CMusEngOutSession::NewL()
       
    57     {
       
    58     UT_CMusEngOutSession* self = UT_CMusEngOutSession::NewLC();
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }
       
    62 
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 UT_CMusEngOutSession* UT_CMusEngOutSession::NewLC()
       
    69     {
       
    70     UT_CMusEngOutSession* self = new( ELeave ) UT_CMusEngOutSession();
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL();
       
    73     return self;
       
    74     }
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 UT_CMusEngOutSession::~UT_CMusEngOutSession()
       
    82     {
       
    83     // NOP
       
    84     }
       
    85 
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // Default constructor
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 UT_CMusEngOutSession::UT_CMusEngOutSession()
       
    92     {
       
    93     // NOP
       
    94     }
       
    95 
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // Second phase construct
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void UT_CMusEngOutSession::ConstructL()
       
   102     {
       
   103     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
   104     // It generates the test case table.
       
   105     CEUnitTestSuiteClass::ConstructL();
       
   106     }
       
   107     
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void UT_CMusEngOutSession::SetupL()
       
   114     {
       
   115     
       
   116     PropertyHelper::SetErrorCode( KErrNone );
       
   117     
       
   118     iLcSessionObserver = new( ELeave )CLcSessionObserverStub;
       
   119     iLcUiProvider = new( ELeave )CLcUiProviderStub;
       
   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 
       
   129     SIPStrings::OpenL();
       
   130     
       
   131     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   132                                         NMusSessionApi::KRemoteSipAddress,
       
   133                                         KTestRecipientSipUri ) );
       
   134     }
       
   135 
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void UT_CMusEngOutSession::Teardown()
       
   142     {
       
   143     SIPStrings::Close();
       
   144     delete iLiveSession;
       
   145     delete iLcSessionObserver;
       
   146     delete iLcUiProvider;
       
   147     delete iAudioRoutingObserver;
       
   148     PropertyHelper::SetErrorCode( KErrNone );
       
   149     PropertyHelper::Close();
       
   150     }
       
   151 
       
   152 
       
   153 // TEST CASES
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 void UT_CMusEngOutSession::UT_EstablishLcSessionL()
       
   160     {
       
   161     // Initial state
       
   162     EUNIT_ASSERT( !iLiveSession->iSession );
       
   163     
       
   164     ///////////////////////////////////////////////////////////////////////////
       
   165     // 1. Simulate failing session structure construction.
       
   166     iLiveSession->EstablishLcSessionL();
       
   167     
       
   168     iLiveSession->iSession->iState = CMceSession::EIdle;
       
   169     delete iLiveSession->iSession->Streams()[0];
       
   170     const RPointerArray<CMceMediaStream>& constStreams = 
       
   171                                             iLiveSession->iSession->Streams();
       
   172     const_cast<RPointerArray<CMceMediaStream>&>(constStreams)[0] = NULL;
       
   173 
       
   174     ///////////////////////////////////////////////////////////////////////////
       
   175     // 2. Normal invite
       
   176     iLiveSession->EstablishLcSessionL();
       
   177     
       
   178     EUNIT_ASSERT( iLiveSession->iSession );
       
   179     // Next assertion ensures that session structure is new
       
   180     EUNIT_ASSERT( iLiveSession->iSession->Streams().Count() > 0 );   
       
   181     EUNIT_ASSERT( iLiveSession->iSession->Streams()[0] ); 
       
   182     EUNIT_ASSERT( *(iLiveSession->iRecipient) == KTestRecipientSipUri8() );
       
   183     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
       
   184     
       
   185     EUNIT_ASSERT( iLiveSession->iSession->iHeaders );
       
   186     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->Count() == 2 );
       
   187     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 0 ) ==
       
   188                   KMusEngAcceptContactHeader() );
       
   189     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 1 ) ==
       
   190                   KMusAcceptHeader() );    
       
   191     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines );
       
   192     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->Count() == 1 );
       
   193     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->MdcaPoint( 0 ) ==
       
   194                   KMusEngSessionSdpLineXApplication() );
       
   195         
       
   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
       
   204     delete iLiveSession;
       
   205     iLiveSession = NULL;
       
   206     iLiveSession = CMusEngLiveSession::NewL();
       
   207     iLiveSession->SetLcSessionObserver( iLcSessionObserver );
       
   208     iLiveSession->SetLcUiProvider( iLcUiProvider );    
       
   209    	iLiveSession->iOperatorVariant = ETrue;
       
   210    	CSIPProfile* profile = iLiveSession->iSipProfileHandler->Profile();
       
   211     delete profile->iArray;
       
   212     profile->iArray = NULL;
       
   213     profile->iArray = new ( ELeave ) CDesC8ArrayFlat( 1 );
       
   214     profile->iArray->AppendL( KMusTestUri );
       
   215 
       
   216     iLiveSession->EstablishLcSessionL();
       
   217     
       
   218     EUNIT_ASSERT( iLiveSession->iSession );
       
   219     // Next assertion ensures that session structure is new
       
   220     EUNIT_ASSERT( *(iLiveSession->iRecipient) == KTestRecipientSipUri8() );
       
   221     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
       
   222     
       
   223     EUNIT_ASSERT( iLiveSession->iSession->iHeaders );
       
   224     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->Count() == 3 );
       
   225     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 0 ) ==
       
   226                   KMusEngAcceptContactHeader() );
       
   227     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 1 ) ==
       
   228                   KMusAcceptHeader() );
       
   229     
       
   230     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 2 ) ==
       
   231                   KMusPPreferredIdentityTestHeader() );
       
   232     
       
   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 );
       
   236     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->Count() == 2 );
       
   237     EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->MdcaPoint( 0 ) ==
       
   238                   KMusEngSessionSdpLineApplication() )
       
   239    	EUNIT_ASSERT( iLiveSession->iSession->iSessionSDPLines->MdcaPoint( 1 ) ==
       
   240                   KMusEngSessionSdpLineType() )
       
   241                   
       
   242     EUNIT_ASSERT( iLiveSession->iSession->Streams().Count() > 0 );   
       
   243     EUNIT_ASSERT( iLiveSession->iSession->Streams()[0] ); 
       
   244     EUNIT_ASSERT( iLiveSession->iSession->Streams()[0]->Type() == KMceVideo );
       
   245 
       
   246     // Ensure there is only b=AS and no b=TIAS present at media level
       
   247     // for operator variant
       
   248     mediaSdpLines = iLiveSession->iSession->Streams()[0]->iMediaSDPLines;
       
   249     EUNIT_ASSERT( mediaSdpLines );
       
   250     EUNIT_ASSERT( mediaSdpLines->MdcaCount() == 1 );
       
   251     EUNIT_ASSERT( mediaSdpLines->MdcaPoint( 0 ) == 
       
   252                   KMusEngSessionSdpLineBandwidthField() );
       
   253     
       
   254     ///////////////////////////////////////////////////////////////////////////
       
   255     // 4. Try invite again, must fail
       
   256     TRAPD( error, iLiveSession->EstablishLcSessionL() );
       
   257     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
       
   258     EUNIT_ASSERT( error == KErrAlreadyExists );
       
   259     
       
   260     // 5. Simulate normal session ending, no need for observer call in this case
       
   261     iLiveSession->iSession->iState = CMceSession::ETerminated;
       
   262     
       
   263     // Try again. Establishment must be OK with new MceSession object
       
   264     iLiveSession->EstablishLcSessionL();
       
   265     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
       
   266     }
       
   267     
       
   268 // -----------------------------------------------------------------------------
       
   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     }
       
   419 
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 // -----------------------------------------------------------------------------
       
   423 //    
       
   424 void UT_CMusEngOutSession::UT_TerminateLcSessionL()
       
   425     {
       
   426     // No MCE session
       
   427     EUNIT_ASSERT_SPECIFIC_LEAVE( 
       
   428         iLiveSession->TerminateLcSessionL(), KErrNotReady )
       
   429 
       
   430     // Cancel a session that is in offering state
       
   431     iLiveSession->EstablishLcSessionL();
       
   432     EUNIT_ASSERT_EQUALS( TInt( CMceSession::EOffering ),
       
   433                          TInt( iLiveSession->iSession->iState ) )
       
   434     iLiveSession->TerminateLcSessionL();
       
   435     EUNIT_ASSERT_EQUALS( TInt( CMceSession::ECancelling ),
       
   436                          TInt( iLiveSession->iSession->iState ) )
       
   437     
       
   438     // Terminate an established session
       
   439     iLiveSession->iSession->iState = CMceSession::ETerminated;
       
   440     iLiveSession->EstablishLcSessionL();
       
   441     iLiveSession->iSession->iState = CMceSession::EEstablished;
       
   442     iLiveSession->TerminateLcSessionL();
       
   443     EUNIT_ASSERT_EQUALS( TInt( CMceSession::ETerminating ),
       
   444                          TInt( iLiveSession->iSession->iState ) )
       
   445     }
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 //
       
   449 // -----------------------------------------------------------------------------
       
   450 //  
       
   451 void UT_CMusEngOutSession::UT_EstablishSessionLL()
       
   452     {
       
   453     // Try to establish, must fail, because of missing session
       
   454     TRAPD( error, iLiveSession->EstablishSessionL() );
       
   455     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
       
   456     EUNIT_ASSERT( error == KErrNotReady );
       
   457     
       
   458     // Call to CMusEngOutMceSession::InviteL leads to call to EstablishL
       
   459     iLiveSession->EstablishLcSessionL();
       
   460     
       
   461     // Check that ports are correct
       
   462     
       
   463     for ( TInt i = 0; i < iLiveSession->iSession->Streams().Count(); ++i )
       
   464         {
       
   465         CMceMediaStream* stream = iLiveSession->iSession->Streams()[i];
       
   466         if ( stream->Type() == KMceAudio )
       
   467             {
       
   468             EUNIT_ASSERT( stream->iLocalMediaPort == 57344 )
       
   469             }
       
   470         else
       
   471             {
       
   472             EUNIT_ASSERT( stream->iLocalMediaPort == 49152 )
       
   473             }
       
   474         }
       
   475         
       
   476     // Check Accept-Contact -header
       
   477     
       
   478     EUNIT_ASSERT( iLiveSession->iSession->iHeaders )
       
   479     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->Count() == 2 )
       
   480     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 0 ) ==
       
   481                   KMusEngAcceptContactHeader() )
       
   482     EUNIT_ASSERT( iLiveSession->iSession->iHeaders->MdcaPoint( 1 ) ==
       
   483                   KMusAcceptHeader() );   
       
   484     EUNIT_ASSERT( iLiveSession->iSession->State() == CMceSession::EOffering );
       
   485     }
       
   486 
       
   487 // -----------------------------------------------------------------------------
       
   488 //
       
   489 // -----------------------------------------------------------------------------
       
   490 //    
       
   491 void UT_CMusEngOutSession::UT_HandleTerminationL()
       
   492     {
       
   493     // Try different values    
       
   494     iLiveSession->HandleTermination( KSipStatusCode408ConnectionTimeOut, 
       
   495                                      KNullDesC8() );
       
   496     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   497                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   498     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   499                          TInt( MLcSession::ENoAnswer ) )
       
   500     iLcSessionObserver->Reset();
       
   501     
       
   502     iLiveSession->HandleTermination( KSipStatusCode415UnsupportedMediaType, 
       
   503                                      KNullDesC8() );
       
   504     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   505                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   506     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   507                          TInt( MLcSession::ESessionRejected ) ) 
       
   508     iLcSessionObserver->Reset();
       
   509     
       
   510     iLiveSession->HandleTermination( KSipStatusCode488NotAcceptableHere, 
       
   511                                      KNullDesC8() );
       
   512     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   513                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   514     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   515                          TInt( MLcSession::ESessionRejected ) )
       
   516     iLcSessionObserver->Reset();
       
   517     
       
   518     iLiveSession->HandleTermination( KSipStatusCode606NotAcceptable, 
       
   519                                      KNullDesC8() );
       
   520     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   521                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   522     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   523                          TInt( MLcSession::ESessionRejected ) )
       
   524     iLcSessionObserver->Reset(); 
       
   525     
       
   526     iLiveSession->HandleTermination( KSipStatusCode486BusyHere, 
       
   527                                      KNullDesC8() );
       
   528     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   529                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   530     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   531                          TInt( MLcSession::ERecipientBusy ) )
       
   532     iLcSessionObserver->Reset();
       
   533     
       
   534     iLiveSession->HandleTermination( KSipStatusCode487RequestCancelled, 
       
   535                                      KNullDesC8() );
       
   536     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   537                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   538     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   539                          TInt( MLcSession::ESessionCancelled ) )
       
   540     iLcSessionObserver->Reset();
       
   541     
       
   542     iLiveSession->HandleTermination( KSipStatusCode603Decline, KNullDesC8()  );
       
   543     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   544                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   545     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   546                          TInt( MLcSession::ESessionRejected ) )
       
   547     iLcSessionObserver->Reset();
       
   548 
       
   549     iLiveSession->HandleTermination( KSipStatusCode480TemporarilyNotAvailable, 
       
   550                                      KNullDesC8() );
       
   551     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   552                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   553     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   554                          TInt( MLcSession::ERecipientTemporarilyNotAvailable ) )
       
   555     iLcSessionObserver->Reset();
       
   556     
       
   557     // Receive 486 with operator variant
       
   558     iLiveSession->iOperatorVariant = ETrue;
       
   559     iLiveSession->HandleTermination( KSipStatusCode486BusyHere, KNullDesC8()  );
       
   560     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   561                          TInt( CLcSessionObserverStub::ESessionFailed ) )
       
   562     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iError,
       
   563                          TInt( MLcSession::ESessionRejected ) )    
       
   564     iLcSessionObserver->Reset();
       
   565     iLiveSession->iOperatorVariant = EFalse;
       
   566     
       
   567     // Normal termination, let the base class handle
       
   568     iLiveSession->HandleTermination(  KSipStatusCode200OK, KNullDesC8()  );
       
   569     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   570                          TInt( CLcSessionObserverStub::ESessionStateChanged ) )
       
   571     iLcSessionObserver->Reset();
       
   572     }    
       
   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     }
       
   655 
       
   656 // -----------------------------------------------------------------------------
       
   657 //
       
   658 // -----------------------------------------------------------------------------
       
   659 //   
       
   660 void UT_CMusEngOutSession::UT_AdjustVideoCodecLL()
       
   661     {
       
   662     //H263
       
   663     CMceH263Codec* codecH263 = CMceH263Codec::NewLC( KMceSDPNameH2632000() );
       
   664     iLiveSession->CMusEngMceOutSession::AdjustVideoCodecL( *codecH263,
       
   665                                                            KMceCameraSource );
       
   666     // Test payloadtype
       
   667     EUNIT_ASSERT( codecH263->iPayloadType == 96 )
       
   668     CleanupStack::PopAndDestroy( codecH263 );
       
   669     
       
   670     //H264
       
   671     CMceAvcCodec* codecAvc = CMceAvcCodec::NewLC( KMceSDPNameH264() );
       
   672     iLiveSession->CMusEngMceOutSession::AdjustVideoCodecL( *codecAvc,
       
   673                                                            KMceCameraSource  );
       
   674     // Test payloadtype
       
   675     EUNIT_ASSERT( codecAvc->iPayloadType == 98 )
       
   676     CleanupStack::PopAndDestroy( codecAvc );
       
   677     }
       
   678 
       
   679 // -----------------------------------------------------------------------------
       
   680 //
       
   681 // -----------------------------------------------------------------------------
       
   682 //   
       
   683 void UT_CMusEngOutSession::UT_AdjustAudioCodecLL()
       
   684     {
       
   685     CMceAudioCodec* codec = 
       
   686                 iLiveSession->iManager->SupportedAudioCodecs()[0]->CloneL();
       
   687     CleanupStack::PushL( codec );
       
   688     iLiveSession->CMusEngMceOutSession::AdjustAudioCodecL( *codec );
       
   689     
       
   690     // Test payloadtype
       
   691     
       
   692     EUNIT_ASSERT( codec->iPayloadType == 97 )
       
   693     
       
   694     // Test that base class has been called
       
   695     
       
   696     EUNIT_ASSERT( codec->iMMFPriority == KAudioPrioritySwisPlayback )
       
   697     EUNIT_ASSERT( codec->iMMFPriorityPreference == KAudioPrefSwisPlayback )
       
   698     
       
   699     CleanupStack::PopAndDestroy( codec );
       
   700     }
       
   701         
       
   702 // -----------------------------------------------------------------------------
       
   703 //
       
   704 // -----------------------------------------------------------------------------
       
   705 //   
       
   706 void UT_CMusEngOutSession::UT_CreateMceSessionStructureLL()
       
   707     {
       
   708     // Test removal of QoS-lines
       
   709     
       
   710     iLiveSession->iRecipient = KTestRecipientSipUri8().AllocL();
       
   711   
       
   712     // IETF profile
       
   713     iLiveSession->CreateMceSessionStructureL();
       
   714     TUint modifierValue = 500; //Just some value that is not used
       
   715     iLiveSession->iSession->GetModifierL( KMcePreconditions, modifierValue );
       
   716     EUNIT_ASSERT( modifierValue == KMcePreconditionsNotUsed );
       
   717     
       
   718     delete iLiveSession->iSession;
       
   719     iLiveSession->iSession = NULL;
       
   720     
       
   721     // IMS profile
       
   722     CSIPProfile* profile = iLiveSession->iSipProfileHandler->Profile();
       
   723     profile->iTypeInfo.iSIPProfileClass = TSIPProfileTypeInfo::EIms;
       
   724     iLiveSession->CreateMceSessionStructureL();
       
   725     modifierValue = 0;
       
   726     iLiveSession->iSession->GetModifierL( KMcePreconditions, modifierValue );
       
   727     EUNIT_ASSERT( modifierValue == KMcePreconditionsSupported );
       
   728     
       
   729     // IMS profile with force internet signaling
       
   730     
       
   731     // TODO: Stub MultimediaSharingSettings, set ForceInternetSignalingSettingL
       
   732     // to return EForceInternetSignaling and test again
       
   733     
       
   734     // Test bundling
       
   735     
       
   736     EUNIT_ASSERT( iLiveSession->iSession->Bundles().Count() == 0 )
       
   737 
       
   738     CMusEngClipSession* clipSession = CMusEngClipSession::NewL();
       
   739     CleanupStack::PushL( clipSession );
       
   740     clipSession->SetLcSessionObserver( iLcSessionObserver );
       
   741     clipSession->SetLcUiProvider( iLcUiProvider );    
       
   742     clipSession->LocalVideoPlayer()->LcSourceFileControl()->SetLcFileNameL(
       
   743         KTestVideoFileName() );
       
   744     
       
   745     clipSession->iRecipient = KTestRecipientSipUri8().AllocL();
       
   746     
       
   747     clipSession->CreateMceSessionStructureL();
       
   748     
       
   749     CMceSession* session = clipSession->iSession;
       
   750     
       
   751     EUNIT_ASSERT( session->Bundles().Count() == 1 )
       
   752     EUNIT_ASSERT( session->Bundles()[0]->Streams().Count() == 2 )
       
   753     EUNIT_ASSERT( session->Bundles()[0]->Streams()[0]->Type() == KMceAudio )
       
   754     EUNIT_ASSERT( session->Bundles()[0]->Streams()[0]->Sinks()[0]->Type() == 
       
   755                   KMceSpeakerSink )
       
   756     EUNIT_ASSERT( session->Bundles()[0]->Streams()[1]->Type() == KMceVideo )              
       
   757     EUNIT_ASSERT( session->Bundles()[0]->Streams()[1]->Sinks()[0]->Type() == 
       
   758                   KMceDisplaySink )
       
   759 
       
   760     CleanupStack::PopAndDestroy( clipSession );
       
   761     }
       
   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 
       
   987 //  TEST TABLE
       
   988 
       
   989 EUNIT_BEGIN_TEST_TABLE(
       
   990     UT_CMusEngOutSession,
       
   991     "UT_CMusEngOutSesssion",
       
   992     "UNIT" )
       
   993 
       
   994 EUNIT_TEST(
       
   995     "EstablishLcSessionL - test ",
       
   996     "CMusEngOutSession",
       
   997     "EstablishLcSessionL",
       
   998     "FUNCTIONALITY",
       
   999     SetupL, UT_EstablishLcSessionL, Teardown)
       
  1000 
       
  1001 EUNIT_TEST(
       
  1002     "TerminateLcSessionL - test ",
       
  1003     "CMusEngOutSession",
       
  1004     "TerminateLcSessionL",
       
  1005     "FUNCTIONALITY",
       
  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)
       
  1021 
       
  1022 EUNIT_TEST(
       
  1023     "EstablishSessionL - test ",
       
  1024     "CMusEngOutSession",
       
  1025     "EstablishSessionL",
       
  1026     "FUNCTIONALITY",
       
  1027     SetupL, UT_EstablishSessionLL, Teardown)   
       
  1028 
       
  1029 EUNIT_TEST(
       
  1030     "HandleTermination - test ",
       
  1031     "CMusEngOutSession",
       
  1032     "HandleTermination",
       
  1033     "FUNCTIONALITY",
       
  1034     SetupL, UT_HandleTerminationL, Teardown)   
       
  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     
       
  1043 EUNIT_TEST(
       
  1044     "AdjustVideoCodecL - test ",
       
  1045     "CMusEngOutSession",
       
  1046     "AdjustVideoCodecL",
       
  1047     "FUNCTIONALITY",
       
  1048     SetupL, UT_AdjustVideoCodecLL, Teardown)   
       
  1049 
       
  1050 EUNIT_TEST(
       
  1051     "AdjustAudioCodecL - test ",
       
  1052     "CMusEngOutSession",
       
  1053     "AdjustAudioCodecL",
       
  1054     "FUNCTIONALITY",
       
  1055     SetupL, UT_AdjustAudioCodecLL, Teardown)   
       
  1056     
       
  1057 EUNIT_TEST(
       
  1058     "CreateMceSessionStructureL - test ",
       
  1059     "CMusEngOutSession",
       
  1060     "CreateMceSessionStructureL",
       
  1061     "FUNCTIONALITY",
       
  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)
       
  1091 
       
  1092 EUNIT_END_TEST_TABLE
       
  1093 
       
  1094 //  END OF FILE
       
  1095 
       
  1096