mmsharing/mmshengine/tsrc/ut_engine/src/ut_musengreceivesession.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
    19 //  INTERNAL INCLUDES
    19 //  INTERNAL INCLUDES
    20 #include "ut_musengreceivesession.h"
    20 #include "ut_musengreceivesession.h"
    21 #include "musengstubs.h"
    21 #include "musengstubs.h"
    22 #include "musengtestdefs.h"
    22 #include "musengtestdefs.h"
    23 #include "musengreceivesession.h"
    23 #include "musengreceivesession.h"
    24 #include "mussessionproperties.h"
    24 #include "centralrepository.h"
    25 #include "contactenginestub.h"
       
    26 #include "musengremotevideoplayer.h"
       
    27 
    25 
    28 //  SYSTEM INCLUDES
    26 //  SYSTEM INCLUDES
    29 #include <digia/eunit/eunitmacros.h>
    27 #include <digia/eunit/eunitmacros.h>
    30 
    28 
    31 #include <mceinsession.h>
    29 #include <mceinsession.h>
    41 #include <mceaudiocodec.h>
    39 #include <mceaudiocodec.h>
    42 #include <mceh263codec.h>
    40 #include <mceh263codec.h>
    43 #include <mceavccodec.h>
    41 #include <mceavccodec.h>
    44 
    42 
    45 #include <audiopreference.h>
    43 #include <audiopreference.h>
    46 #include <centralrepository.h>
    44 
    47 
    45 
    48 
       
    49 // Using following value increases treshold buffer to 1 second from 
       
    50 // default 100 ms
       
    51 const TInt KMusEngJitterBufferTreshold = 50;
       
    52 const TInt KMusEngTresholdToSecondsFactor = 20;
       
    53 const TInt KMusEngTwoSecondInMilliSeconds = 2000; 
       
    54 // Use inactivity timer value that is a little bigger than treshold in seconds
       
    55 const TUint KMusEngInactivityTimer = KMusEngTresholdToSecondsFactor * 
       
    56                                      KMusEngJitterBufferTreshold + 
       
    57                                      KMusEngTwoSecondInMilliSeconds;
       
    58 
       
    59 _LIT( KTestContactName, "nokia" );
       
    60 
    46 
    61 
    47 
    62 // -----------------------------------------------------------------------------
    48 // -----------------------------------------------------------------------------
    63 //
    49 //
    64 // -----------------------------------------------------------------------------
    50 // -----------------------------------------------------------------------------
   120 //
   106 //
   121 // -----------------------------------------------------------------------------
   107 // -----------------------------------------------------------------------------
   122 //
   108 //
   123 void UT_CMusEngReceiveSession::SetupL(  )
   109 void UT_CMusEngReceiveSession::SetupL(  )
   124     {
   110     {
   125     // set fast mode ON
   111     CRepository::iStaticEncoderUid = 0;
   126     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
   112     iObserver = new( ELeave ) CMusEngObserverStub;
   127                                         NMusSessionApi::KFastMode,
   113     iReceiveSession = CMusEngReceiveSession::NewL( TRect(0,0, 100,100), 
   128                                         0 ) );
   114                                                    *iObserver,
   129     iLcSessionObserver = new( ELeave )CLcSessionObserverStub;
   115                                                    *iObserver );
   130     iLcUiProvider = new( ELeave )CLcUiProviderStub;    
   116     
   131     iReceiveSession = CMusEngReceiveSession::NewL();
   117     }
   132     iReceiveSession->SetLcSessionObserver( iLcSessionObserver );  
   118 
   133     iReceiveSession->SetLcUiProvider( iLcUiProvider );    
       
   134     }
       
   135 
   119 
   136 // -----------------------------------------------------------------------------
   120 // -----------------------------------------------------------------------------
   137 //
   121 //
   138 // -----------------------------------------------------------------------------
   122 // -----------------------------------------------------------------------------
   139 //
   123 //
   140 void UT_CMusEngReceiveSession::Teardown(  )
   124 void UT_CMusEngReceiveSession::Teardown(  )
   141     {
   125     {
   142     PropertyHelper::Close();
       
   143     delete iReceiveSession;
   126     delete iReceiveSession;
   144     delete iLcUiProvider;
   127     delete iObserver;
   145     delete iLcSessionObserver;
   128     CRepository::iStaticEncoderUid = 0;
   146     PropertyHelper::Close();
   129     
   147     // Delete static data from CenRep stub
       
   148     CRepository::ResetStubGlobal();
       
   149     CRepository::iForceFailWithCode = KErrNone;
       
   150     }
   130     }
   151 
   131 
   152 
   132 
   153 // TEST HELPERS
   133 // TEST HELPERS
   154 
   134 
   296 //
   276 //
   297 void UT_CMusEngReceiveSession::UT_NewLL(  )
   277 void UT_CMusEngReceiveSession::UT_NewLL(  )
   298     {
   278     {
   299     EUNIT_ASSERT( iReceiveSession );
   279     EUNIT_ASSERT( iReceiveSession );
   300     EUNIT_ASSERT( !iReceiveSession->iSession );
   280     EUNIT_ASSERT( !iReceiveSession->iSession );
   301     EUNIT_ASSERT( iReceiveSession->iMceManagerUid == TUid::Uid( KMusUiUid ) );
   281     }
   302     }
   282 
   303 
   283 
   304 // -----------------------------------------------------------------------------
   284 // -----------------------------------------------------------------------------
   305 //
   285 //
   306 // -----------------------------------------------------------------------------
   286 // -----------------------------------------------------------------------------
   307 //
   287 //
   308 void UT_CMusEngReceiveSession::UT_LcSessionStateL()
   288 void UT_CMusEngReceiveSession::UT_AcceptInvitationLL()
   309     {
   289     {
   310     // No MCE session -> Convert to MLcSession::EReceived
       
   311     EUNIT_ASSERT_EQUALS( TInt( MLcSession::EReceived ), 
       
   312                          TInt( iReceiveSession->LcSessionState() ) )
       
   313                          
       
   314     // Some other state -> State returned from the base class 
       
   315     TMceTransactionDataContainer container;
   290     TMceTransactionDataContainer container;
       
   291     
       
   292     // There is no pending session to accept, must fail
       
   293     TRAPD( error, iReceiveSession->AcceptInvitationL( ETrue ) );
       
   294     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
       
   295     EUNIT_ASSERT( error == KErrNotReady );
       
   296 
       
   297     // There is pending session, but it is not yet reserved resources,
       
   298     // so accepting fails
   316     CMceInSession* inSession = ConstructInSessionLC( 1, 0 );
   299     CMceInSession* inSession = ConstructInSessionLC( 1, 0 );
   317     iReceiveSession->IncomingSession( inSession, &container );
   300     iReceiveSession->IncomingSession( inSession, &container );
   318     CleanupStack::Pop( inSession );
   301     CleanupStack::Pop( inSession );
       
   302     
       
   303     TRAP( error, iReceiveSession->AcceptInvitationL( ETrue ) );
       
   304     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
       
   305     EUNIT_ASSERT( error == KErrNotReady );
       
   306     
       
   307     // Simulate resource reservation and reject
   319     iReceiveSession->iSession->iState = CMceSession::EProceeding;
   308     iReceiveSession->iSession->iState = CMceSession::EProceeding;
   320     iReceiveSession->EstablishLcSessionL();  
   309     iReceiveSession->AcceptInvitationL( EFalse );
   321     EUNIT_ASSERT_EQUALS( TInt( MLcSession::EOpening ), 
   310     
   322                          TInt( iReceiveSession->LcSessionState() ) )
   311     EUNIT_ASSERT( iReceiveSession->iSession->iState ==
   323     }
   312                   CMceSession::ETerminated );
   324 
   313     
   325 // -----------------------------------------------------------------------------
   314     // Construct new session and reject it with operator variant
   326 //
       
   327 // -----------------------------------------------------------------------------
       
   328 //
       
   329 void UT_CMusEngReceiveSession::UT_EstablishLcSessionL()
       
   330     {
       
   331     // No MCE session
       
   332     EUNIT_ASSERT_SPECIFIC_LEAVE( 
       
   333         iReceiveSession->EstablishLcSessionL(), KErrNotReady )    
       
   334  
       
   335     // Construct a new session and accept it
       
   336     TMceTransactionDataContainer container;
       
   337     CMceInSession* inSession = ConstructInSessionLC( 1, 0 );
       
   338     iReceiveSession->IncomingSession( inSession, &container );
       
   339     CleanupStack::Pop( inSession );
       
   340     iReceiveSession->iSession->iState = CMceSession::EProceeding;
       
   341     iReceiveSession->EstablishLcSessionL();
       
   342     EUNIT_ASSERT( iReceiveSession->iSession )
       
   343     EUNIT_ASSERT_EQUALS( inSession, iReceiveSession->iSession );
       
   344     EUNIT_ASSERT_EQUALS( TInt( CMceSession::EAnswering ),
       
   345                          TInt( iReceiveSession->iSession->iState ) )    
       
   346     }   
       
   347 
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 // -----------------------------------------------------------------------------
       
   351 //
       
   352 void UT_CMusEngReceiveSession::UT_TerminateLcSessionL()
       
   353     {
       
   354     // No MCE session
       
   355     EUNIT_ASSERT_SPECIFIC_LEAVE( 
       
   356         iReceiveSession->TerminateLcSessionL(), KErrNotReady )
       
   357     
       
   358     // Reject session, session state incoming, no operator variant
       
   359     TMceTransactionDataContainer container;
       
   360     CMceInSession* inSession = ConstructInSessionLC( 1, 0 );
       
   361     iReceiveSession->IncomingSession( inSession, &container );
       
   362     CleanupStack::Pop( inSession );
       
   363     iReceiveSession->iSession->iState = CMceSession::EIncoming;
       
   364     iReceiveSession->iOperatorVariant = EFalse;
       
   365     iReceiveSession->TerminateLcSessionL();   
       
   366     EUNIT_ASSERT_EQUALS( TInt( CMceSession::ETerminated ),
       
   367                          TInt( iReceiveSession->iSession->iState ) )
       
   368  
       
   369     // Reject session, session state proceeding, no operator variant
       
   370     inSession = ConstructInSessionLC( 1, 0 );
   315     inSession = ConstructInSessionLC( 1, 0 );
   371     iReceiveSession->IncomingSession( inSession, &container );
   316     iReceiveSession->IncomingSession( inSession, &container );
   372     CleanupStack::Pop( inSession );
   317     CleanupStack::Pop( inSession );
   373     iReceiveSession->iSession->iState = CMceSession::EProceeding;
   318     iReceiveSession->iSession->iState = CMceSession::EProceeding;
   374     iReceiveSession->iOperatorVariant = EFalse;
   319     iReceiveSession->iOperatorVariant = ETrue;
   375     iReceiveSession->TerminateLcSessionL();   
   320     
   376     EUNIT_ASSERT_EQUALS( TInt( CMceSession::ETerminated ),
   321     iReceiveSession->AcceptInvitationL( EFalse );
   377                          TInt( iReceiveSession->iSession->iState ) )
   322     
   378     
   323     EUNIT_ASSERT( iReceiveSession->iSession->iState ==
   379     // Reject session, operator variant
   324                   CMceSession::ETerminated );
       
   325 
       
   326     // Construct new session and accept it
   380     inSession = ConstructInSessionLC( 1, 0 );
   327     inSession = ConstructInSessionLC( 1, 0 );
   381     iReceiveSession->IncomingSession( inSession, &container );
   328     iReceiveSession->IncomingSession( inSession, &container );
   382     CleanupStack::Pop( inSession );
   329     CleanupStack::Pop( inSession );
   383     iReceiveSession->iSession->iState = CMceSession::EProceeding;
   330     iReceiveSession->iSession->iState = CMceSession::EProceeding;
   384     iReceiveSession->iOperatorVariant = ETrue;
   331 
   385     iReceiveSession->TerminateLcSessionL(); 
   332     iReceiveSession->AcceptInvitationL( ETrue );   
   386     EUNIT_ASSERT_EQUALS( TInt( CMceSession::ETerminated ),
   333     
   387                          TInt( iReceiveSession->iSession->iState ) )
   334     EUNIT_ASSERT( iReceiveSession->iSession );
   388     
   335     EUNIT_ASSERT( iReceiveSession->iSession == inSession );
   389     // Terminate an established session
   336     EUNIT_ASSERT( iReceiveSession->iSession->iState == 
   390     inSession = ConstructInSessionLC( 1, 0 );
   337                   CMceSession::EAnswering );
   391     iReceiveSession->IncomingSession( inSession, &container );
   338     
   392     CleanupStack::Pop( inSession );
   339     
   393     iReceiveSession->iSession->iState = CMceSession::EEstablished;
   340     }    
   394     iReceiveSession->iOperatorVariant = EFalse;
   341 
   395     iReceiveSession->TerminateLcSessionL(); 
       
   396     EUNIT_ASSERT_EQUALS( TInt( CMceSession::ETerminating ),
       
   397                          TInt( iReceiveSession->iSession->iState ) )    
       
   398     }
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 //
       
   402 // -----------------------------------------------------------------------------
       
   403 //
       
   404 void UT_CMusEngReceiveSession::UT_RemoteVideoPlayerL()
       
   405     {
       
   406     EUNIT_ASSERT( iReceiveSession->RemoteVideoPlayer() == 
       
   407                   iReceiveSession->iRemoteVideoPlayer )
       
   408     }
       
   409 
       
   410 // -----------------------------------------------------------------------------
       
   411 // 
       
   412 // -----------------------------------------------------------------------------
       
   413 //
       
   414 void UT_CMusEngReceiveSession::UT_RemoteDisplayName()
       
   415     {
       
   416 
       
   417     // Creating Valid Session     
       
   418     CMceInSession* inSession = ConstructInSessionLC( 1, 0 );
       
   419     iReceiveSession->iSession = inSession; // Transfers ownership
       
   420     CleanupStack::Pop( inSession );
       
   421     iReceiveSession->CompleteSessionStructureL();
       
   422     EUNIT_ASSERT( inSession->Streams().Count() == 1 );
       
   423     
       
   424 
       
   425     // Name is published using publish/subscribe key by Availblity
       
   426     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   427                                         NMusSessionApi::KContactName,
       
   428                                         KTestContactName ) );
       
   429 
       
   430     EUNIT_ASSERT_EQUALS ( KTestContactName(), iReceiveSession->RemoteDisplayName() )
       
   431     
       
   432     
       
   433     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
   434                                        NMusSessionApi::KContactName,
       
   435                                        KNullDesC) );
       
   436     
       
   437     // Ensure its not null and its not equal
       
   438     EUNIT_ASSERT( KTestContactName() != iReceiveSession->RemoteDisplayName() );
       
   439     }
       
   440 
   342 
   441 // -----------------------------------------------------------------------------
   343 // -----------------------------------------------------------------------------
   442 //
   344 //
   443 // -----------------------------------------------------------------------------
   345 // -----------------------------------------------------------------------------
   444 //
   346 //
   460     
   362     
   461     // The normal cases:
   363     // The normal cases:
   462     
   364     
   463     // 1 ) First transition to state EProceeding, user and remote end should
   365     // 1 ) First transition to state EProceeding, user and remote end should
   464     //     be notified
   366     //     be notified
   465     inSession->iState = CMceSession::EProceeding;   
   367     inSession->iState = CMceSession::EProceeding;
       
   368     
   466     iReceiveSession->HandleSessionStateChanged( *inSession, 0, KNullDesC8() );
   369     iReceiveSession->HandleSessionStateChanged( *inSession, 0, KNullDesC8() );
   467     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   370     EUNIT_ASSERT( iObserver->iIncomingSessionCalled )
   468                          TInt( CLcSessionObserverStub::ESessionStateChanged ) )
       
   469     EUNIT_ASSERT( iReceiveSession->iRingLCalled )
   371     EUNIT_ASSERT( iReceiveSession->iRingLCalled )
   470 
   372     iObserver->Reset();
   471     // Ensure Originator is taken from the incoming session
       
   472     EUNIT_ASSERT_EQUALS ( KTestOriginator(), *iReceiveSession->iOriginator )
       
   473     
       
   474     iLcSessionObserver->Reset();
       
   475     
   373     
   476     // 2 ) Now simulate second transition to EProceeding state which can happen
   374     // 2 ) Now simulate second transition to EProceeding state which can happen
   477     //     if we force 100rel to be used. User and remote end should not be 
   375     //     if we force 100rel to be used. User and remote end should not be 
   478     //     notified anymore but change should be ignored.
   376     //     notified anymore but change should be ignored.
   479     inSession->iState = CMceSession::EProceeding;
       
   480     iReceiveSession->HandleSessionStateChanged( *inSession, 0, KNullDesC8() );
   377     iReceiveSession->HandleSessionStateChanged( *inSession, 0, KNullDesC8() );
   481     EUNIT_ASSERT_EQUALS( TInt( CLcSessionObserverStub::EUnknown ),
   378     EUNIT_ASSERT( iObserver->IsReseted() )
   482                          TInt( iLcSessionObserver->iCalledFunction ) )
   379     iObserver->Reset();
   483     }
   380     
       
   381     }
       
   382 
   484 
   383 
   485 // -----------------------------------------------------------------------------
   384 // -----------------------------------------------------------------------------
   486 //
   385 //
   487 // -----------------------------------------------------------------------------
   386 // -----------------------------------------------------------------------------
   488 // 
   387 // 
   491     CMceVideoCodec* codecH263 = CMceH263Codec::NewLC( KMceSDPNameH263() );    
   390     CMceVideoCodec* codecH263 = CMceH263Codec::NewLC( KMceSDPNameH263() );    
   492     CMceVideoCodec* codecH2632000 = CMceH263Codec::NewLC( KMceSDPNameH2632000() );
   391     CMceVideoCodec* codecH2632000 = CMceH263Codec::NewLC( KMceSDPNameH2632000() );
   493     CMceVideoCodec* codecAvc = CMceAvcCodec::NewLC( KMceSDPNameH264() );
   392     CMceVideoCodec* codecAvc = CMceAvcCodec::NewLC( KMceSDPNameH264() );
   494     CMceVideoCodec* codecUnknown = CMceH263Codec::NewLC( KNullDesC8() );
   393     CMceVideoCodec* codecUnknown = CMceH263Codec::NewLC( KNullDesC8() );
   495     
   394     
   496     iReceiveSession->AdjustVideoCodecL( *codecH263, KMceRTPSource );
   395     iReceiveSession->AdjustVideoCodecL( *codecH263 );
   497     iReceiveSession->AdjustVideoCodecL( *codecH2632000, KMceRTPSource );
   396     iReceiveSession->AdjustVideoCodecL( *codecH2632000 );
   498     iReceiveSession->AdjustVideoCodecL( *codecAvc, KMceRTPSource );
   397     iReceiveSession->AdjustVideoCodecL( *codecAvc );
   499     iReceiveSession->AdjustVideoCodecL( *codecUnknown, KMceRTPSource );
   398     iReceiveSession->AdjustVideoCodecL( *codecUnknown );
   500     
   399     
   501     EUNIT_ASSERT_EQUALS( codecH263->KeepAliveTimer(), 5 )
   400     EUNIT_ASSERT_EQUALS( codecH263->KeepAliveTimer(), 5 )
   502     EUNIT_ASSERT_EQUALS( codecH263->KeepAlivePayloadType(), 96 )
   401     EUNIT_ASSERT_EQUALS( codecH263->KeepAlivePayloadType(), 96 )
   503     EUNIT_ASSERT_EQUALS( codecH263->KeepAliveData(), KNullDesC8() )
   402     EUNIT_ASSERT_EQUALS( codecH263->KeepAliveData(), KNullDesC8() )
   504     
   403     
   683     CleanupStack::Pop( headers );
   582     CleanupStack::Pop( headers );
   684     iReceiveSession->IncomingSession( inSession, &container );    
   583     iReceiveSession->IncomingSession( inSession, &container );    
   685     CleanupStack::Pop( inSession );
   584     CleanupStack::Pop( inSession );
   686     container.Clear();
   585     container.Clear();
   687     
   586     
       
   587     EUNIT_ASSERT( iObserver->iIncomingSessionPreNotificationCalled )
       
   588     
   688     EUNIT_ASSERT( iReceiveSession->iSession );
   589     EUNIT_ASSERT( iReceiveSession->iSession );
   689     EUNIT_ASSERT( iReceiveSession->iSession->iState == 
   590     EUNIT_ASSERT( iReceiveSession->iSession->iState == 
   690                   CMceSession::ETerminated );
   591                   CMceSession::ETerminated );
   691     
   592     
   692     EUNIT_ASSERT( iReceiveSession->iSession->i100RelUsage == 
   593     EUNIT_ASSERT( iReceiveSession->iSession->i100RelUsage == 
   727     
   628     
   728     EUNIT_ASSERT( iReceiveSession->iSession );
   629     EUNIT_ASSERT( iReceiveSession->iSession );
   729     EUNIT_ASSERT( iReceiveSession->iSession != inSession );
   630     EUNIT_ASSERT( iReceiveSession->iSession != inSession );
   730     EUNIT_ASSERT( iReceiveSession->iSession->iState == 
   631     EUNIT_ASSERT( iReceiveSession->iSession->iState == 
   731                   CMceSession::EReserving );
   632                   CMceSession::EReserving );
       
   633     
       
   634     // Try again when there is usage of avc is turned off
       
   635     iReceiveSession->iSession->iState = CMceSession::ETerminated;
       
   636     TInt32 KMusDisableAVC = 0x0fffffff;
       
   637     CRepository::iStaticEncoderUid = KMusDisableAVC;
       
   638 
       
   639     inSession = ConstructInSessionLC( 1, 0 );
       
   640     
       
   641     // There will 3 AVC codecs and 1 H263 codec
       
   642     EUNIT_ASSERT( static_cast<CMceVideoStream*>( inSession->Streams()[0] )->Codecs().Count() == 4 );
       
   643     iReceiveSession->IncomingSession( inSession, &container );    
       
   644     CleanupStack::Pop( inSession );
       
   645     
       
   646     EUNIT_ASSERT( iReceiveSession->iSession->iState == 
       
   647                   CMceSession::EReserving ||
       
   648                   iReceiveSession->iSession->iState == 
       
   649                   CMceSession::ETerminated );
       
   650     
       
   651     // Should be only the H263 codec
       
   652     EUNIT_ASSERT( static_cast<CMceVideoStream*>( iReceiveSession->iSession->Streams()[0] )->Codecs().Count() <= 4 );
       
   653     
       
   654     //No supported codecs
       
   655     iReceiveSession->iSession->iState = CMceSession::ETerminated;
       
   656     iReceiveSession->iManager->iSupportedVideoCodecs.ResetAndDestroy();
       
   657     inSession = ConstructInSessionLC( 1, 0 );
       
   658     
       
   659     // There will no codecs, simulates situation where no codecs were match
       
   660     //currently session is not been rejected
       
   661     EUNIT_ASSERT( static_cast<CMceVideoStream*>( inSession->Streams()[0] )->Codecs().Count() == 0 );
       
   662     iReceiveSession->IncomingSession( inSession, &container );    
       
   663     CleanupStack::Pop( inSession );
       
   664     
       
   665     EUNIT_ASSERT( iReceiveSession->iSession->iState == 
       
   666                   CMceSession::EReserving ||
       
   667                   iReceiveSession->iSession->iState == 
       
   668                   CMceSession::ETerminated );
       
   669     
       
   670     // Should be only the H263 codec
       
   671     EUNIT_ASSERT( static_cast<CMceVideoStream*>( inSession->Streams()[0] )->Codecs().Count() == 0 );
       
   672     
   732     }
   673     }
   733 
   674 
   734 
   675 
   735 // -----------------------------------------------------------------------------
   676 // -----------------------------------------------------------------------------
   736 //
   677 //
   752     CMceInSession* inSession = ConstructInSessionLC( 1, 0 );
   693     CMceInSession* inSession = ConstructInSessionLC( 1, 0 );
   753     iReceiveSession->IncomingSession( inSession, &container );
   694     iReceiveSession->IncomingSession( inSession, &container );
   754     CleanupStack::Pop( inSession );
   695     CleanupStack::Pop( inSession );
   755     
   696     
   756     iReceiveSession->iSession->iState = CMceSession::EProceeding;
   697     iReceiveSession->iSession->iState = CMceSession::EProceeding;
   757     iReceiveSession->EstablishLcSessionL();
   698     iReceiveSession->AcceptInvitationL( ETrue );
   758     
   699     
   759     // Now we have an insession, try to update session that is not ours, 
   700     // Now we have an insession, try to update session that is not ours, 
   760     // new one gets rejected and deleted.
   701     // new one gets rejected and deleted.
   761     oldSession = ConstructInSessionLC( 0, 0 );
   702     oldSession = ConstructInSessionLC( 0, 0 );
   762     newSession = ConstructInSessionLC( 0, 0 );
   703     newSession = ConstructInSessionLC( 0, 0 );
   809     CMceMediaStream* audioStream = inSession->Streams()[1];
   750     CMceMediaStream* audioStream = inSession->Streams()[1];
   810     
   751     
   811     // Try without a session, nothing happens
   752     // Try without a session, nothing happens
   812     iReceiveSession->StreamStateChanged( *audioStream );
   753     iReceiveSession->StreamStateChanged( *audioStream );
   813     
   754     
   814     // Establish session
   755     // Establish session 
       
   756     
   815     iReceiveSession->IncomingSession( inSession, &container );    
   757     iReceiveSession->IncomingSession( inSession, &container );    
   816     CleanupStack::Pop( inSession );
   758     CleanupStack::Pop( inSession );
   817     iLcSessionObserver->Reset();
   759     iObserver->Reset();
   818 
   760 
   819     // Try with audiostream, nothing happens
   761     // Try with audiostream, nothing happens
   820     audioStream->iState = CMceMediaStream::EBuffering;
   762     audioStream->iState = CMceMediaStream::EBuffering;
   821     iReceiveSession->StreamStateChanged( *audioStream );
   763     iReceiveSession->StreamStateChanged( *audioStream );
   822     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
   764     EUNIT_ASSERT( iObserver->IsReseted() )
   823     
   765     
   824     // Try with videostream, but without a source, nothing happens
   766     // Try with videostream, but without a source, nothing happens 
   825     CMceRtpSource* rtpSource = 
   767         
   826         static_cast<CMceRtpSource*>( videoStream->Source() ); //hack
   768         // Needed hacking
   827     videoStream->iSource = NULL;   
   769         CMceRtpSource* rtpSource = 
       
   770                         static_cast<CMceRtpSource*>( videoStream->Source() );
       
   771     videoStream->iSource = NULL;
       
   772     
   828     iReceiveSession->StreamStateChanged( *videoStream );
   773     iReceiveSession->StreamStateChanged( *videoStream );
   829     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
   774     EUNIT_ASSERT( iObserver->IsReseted() )
   830     
   775     
   831     // Try with videostream and a camera source, nothing happens 
   776     // Try with videostream and a camera source, nothing happens 
   832     videoStream->iSource = 
   777         
   833         CMceCameraSource::NewL( *iReceiveSession->iManager ); //hack
   778         // Needed hacking
       
   779         videoStream->iSource = 
       
   780                     CMceCameraSource::NewLC( *iReceiveSession->iManager );
       
   781         CleanupStack::Pop();
       
   782     
   834     iReceiveSession->StreamStateChanged( *videoStream );
   783     iReceiveSession->StreamStateChanged( *videoStream );
   835     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
   784     EUNIT_ASSERT( iObserver->IsReseted() )
   836     
   785     
   837     // Remove hacks
   786     // Remove hacks
   838     delete videoStream->iSource;
   787     delete videoStream->iSource;
   839     videoStream->iSource = rtpSource;
   788     videoStream->iSource = rtpSource;
   840         
   789         
   841     // Buffering, normal case
   790     // Buffering, normal case
   842     videoStream->iState = CMceMediaStream::EBuffering;
   791     videoStream->iState = CMceMediaStream::EBuffering;
   843     iReceiveSession->StreamStateChanged( *videoStream );
   792     iReceiveSession->StreamStateChanged( *videoStream );
   844     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   793     EUNIT_ASSERT( iObserver->iStreamBufferingCalled )
   845                          TInt( CLcSessionObserverStub::EPlayerStateChanged ) )
   794     iObserver->Reset();
   846     EUNIT_ASSERT( iReceiveSession->iBuffered )
       
   847     iLcSessionObserver->Reset();
       
   848     
   795     
   849     // Streaming, normal case
   796     // Streaming, normal case
   850     videoStream->iState = CMceMediaStream::EStreaming;
   797     videoStream->iState = CMceMediaStream::EStreaming;
   851     iReceiveSession->iReceiving = EFalse;
       
   852     iReceiveSession->iBuffered = ETrue;
       
   853     iReceiveSession->StreamStateChanged( *videoStream );
   798     iReceiveSession->StreamStateChanged( *videoStream );
   854     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   799     EUNIT_ASSERT( iObserver->iStreamStreamingCalled )
   855                          TInt( CLcSessionObserverStub::EPlayerStateChanged ) )
   800     EUNIT_ASSERT( rtpSource->iInactivityTimer == 2000 ) 
   856     EUNIT_ASSERT_EQUALS( KMusEngInactivityTimer, rtpSource->iInactivityTimer ) 
   801     iObserver->Reset();
   857     iLcSessionObserver->Reset();
       
   858     EUNIT_ASSERT_EQUALS( TInt( iLcUiProvider->iCalledFunction ),
       
   859                          TInt( CLcUiProviderStub::EHandleForegroundStatus ) )    
       
   860     iLcUiProvider->Reset();
       
   861     // Normally background info will be cleared once ui comes to foreground and
       
   862     // notifies engine about it
       
   863     iReceiveSession->iBackground = EFalse;
       
   864 
       
   865     // Streaming, event is received even when already receiving. Streaming
       
   866     // event is anyway notified.
       
   867     videoStream->iState = CMceMediaStream::EStreaming;
       
   868     iReceiveSession->iReceiving = ETrue;
       
   869     iReceiveSession->iBuffered = ETrue;
       
   870     iReceiveSession->StreamStateChanged( *videoStream );
       
   871     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   872                          TInt( CLcSessionObserverStub::EPlayerStateChanged ) )
       
   873     EUNIT_ASSERT_EQUALS( KMusEngInactivityTimer, rtpSource->iInactivityTimer ) 
       
   874     iLcSessionObserver->Reset();
       
   875     EUNIT_ASSERT_EQUALS( TInt( iLcUiProvider->iCalledFunction ),
       
   876                          TInt( CLcUiProviderStub::EUnknown ) )
       
   877       
       
   878     // Streaming and receiving started already. Streaming is not notified because
       
   879     // of buffering event hasn't been received
       
   880     videoStream->iState = CMceMediaStream::EStreaming;
       
   881     iReceiveSession->iReceiving = ETrue;
       
   882     iReceiveSession->iBuffered = EFalse;
       
   883     iReceiveSession->StreamStateChanged( *videoStream );
       
   884     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
       
   885     iLcSessionObserver->Reset();
       
   886     
       
   887     // Streaming, receiving not started and buffering not happened ( means no packet
       
   888     // received yet. Ignore this event too.
       
   889     videoStream->iState = CMceMediaStream::EStreaming;
       
   890     iReceiveSession->iReceiving = EFalse;
       
   891     iReceiveSession->iBuffered = EFalse;
       
   892     iReceiveSession->StreamStateChanged( *videoStream );
       
   893     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
       
   894     iLcSessionObserver->Reset();
       
   895     
       
   896     // Streaming, receiving not started and buffering happened.
       
   897     // Enabling RTP timer leaves. Should be a failure case.
       
   898     videoStream->iState = CMceMediaStream::EStreaming;
       
   899     iReceiveSession->iReceiving = EFalse;
       
   900     iReceiveSession->iBuffered = ETrue;
       
   901     iReceiveSession->StreamStateChanged( *videoStream );
       
   902     EUNIT_ASSERT_NOT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
       
   903                              TInt( CLcSessionObserverStub::EPlayerFailed ) )    
       
   904     iLcSessionObserver->Reset();
       
   905     
   802     
   906     // Try default behaviors
   803     // Try default behaviors
   907     videoStream->iState = CMceMediaStream::EIdle;
   804     videoStream->iState = CMceMediaStream::EIdle;
   908     iReceiveSession->StreamStateChanged( *videoStream );
   805     iReceiveSession->StreamStateChanged( *videoStream );
   909     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
   806     EUNIT_ASSERT( iObserver->iStreamIdleCalled );
       
   807     
   910     }
   808     }
   911 
   809 
   912 
   810 
   913 // -----------------------------------------------------------------------------
   811 // -----------------------------------------------------------------------------
   914 //
   812 //
   981     EUNIT_ASSERT( inSession->Streams()[0]->Sinks()[0]->Type() == 
   879     EUNIT_ASSERT( inSession->Streams()[0]->Sinks()[0]->Type() == 
   982                   KMceDisplaySink )
   880                   KMceDisplaySink )
   983     
   881     
   984     // No audio, bundle is not constructed
   882     // No audio, bundle is not constructed
   985     EUNIT_ASSERT( inSession->Bundles().Count() == 0 )
   883     EUNIT_ASSERT( inSession->Bundles().Count() == 0 )
       
   884 
   986     }
   885     }
   987 
   886 
   988 
   887 
   989 // -----------------------------------------------------------------------------
   888 // -----------------------------------------------------------------------------
   990 // Video out is bound stream, it gets disabled
   889 // Video out is bound stream, it gets disabled
  1163     EUNIT_ASSERT( inSession->Streams()[1]->Sinks().Count() == 1 )
  1062     EUNIT_ASSERT( inSession->Streams()[1]->Sinks().Count() == 1 )
  1164     EUNIT_ASSERT( inSession->Streams()[1]->Sinks()[0]->Type() == 
  1063     EUNIT_ASSERT( inSession->Streams()[1]->Sinks()[0]->Type() == 
  1165                   KMceSpeakerSink );
  1064                   KMceSpeakerSink );
  1166     CMceSpeakerSink* speaker = 
  1065     CMceSpeakerSink* speaker = 
  1167         static_cast<CMceSpeakerSink*>(inSession->Streams()[1]->Sinks()[0]);
  1066         static_cast<CMceSpeakerSink*>(inSession->Streams()[1]->Sinks()[0]);
  1168     EUNIT_ASSERT( speaker->VolumeL() == iReceiveSession->LcVolumeL() )
  1067     EUNIT_ASSERT( speaker->VolumeL() == iReceiveSession->VolumeL() )
  1169     
  1068     
  1170     // Stream 2 and bound stream
  1069     // Stream 2 and bound stream
  1171     EUNIT_ASSERT( inSession->Streams()[2]->Type() == KMceAudio )
  1070     EUNIT_ASSERT( inSession->Streams()[2]->Type() == KMceAudio )
  1172     EUNIT_ASSERT( inSession->Streams()[2]->IsEnabled() )
  1071     EUNIT_ASSERT( inSession->Streams()[2]->IsEnabled() )
  1173     EUNIT_ASSERT( inSession->Streams()[2]->Sinks().Count() == 1 )
  1072     EUNIT_ASSERT( inSession->Streams()[2]->Sinks().Count() == 1 )
  1174     EUNIT_ASSERT( inSession->Streams()[2]->Sinks()[0]->Type() == 
  1073     EUNIT_ASSERT( inSession->Streams()[2]->Sinks()[0]->Type() == 
  1175                   KMceSpeakerSink );
  1074                   KMceSpeakerSink );
  1176     speaker = static_cast<CMceSpeakerSink*>(inSession->Streams()[2]->Sinks()[0]);
  1075     speaker = static_cast<CMceSpeakerSink*>(inSession->Streams()[2]->Sinks()[0]);
  1177     EUNIT_ASSERT( speaker->VolumeL() == iReceiveSession->LcVolumeL() )
  1076     EUNIT_ASSERT( speaker->VolumeL() == iReceiveSession->VolumeL() )
  1178 
  1077 
  1179     EUNIT_ASSERT( inSession->Streams()[2]->BoundStream() )
  1078     EUNIT_ASSERT( inSession->Streams()[2]->BoundStream() )
  1180     EUNIT_ASSERT( !inSession->Streams()[2]->BoundStreamL().IsEnabled() )
  1079     EUNIT_ASSERT( !inSession->Streams()[2]->BoundStreamL().IsEnabled() )
  1181     EUNIT_ASSERT( inSession->Streams()[2]->BoundStreamL().Type() == KMceAudio )
  1080     EUNIT_ASSERT( inSession->Streams()[2]->BoundStreamL().Type() == KMceAudio )
  1182     
  1081     
  1197     EUNIT_ASSERT( inSession->Streams()[3]->BoundStreamL().Sinks().Count() == 1 )    
  1096     EUNIT_ASSERT( inSession->Streams()[3]->BoundStreamL().Sinks().Count() == 1 )    
  1198     EUNIT_ASSERT( inSession->Streams()[3]->BoundStreamL().Sinks()[0]->Type() == 
  1097     EUNIT_ASSERT( inSession->Streams()[3]->BoundStreamL().Sinks()[0]->Type() == 
  1199                   KMceSpeakerSink )
  1098                   KMceSpeakerSink )
  1200     speaker = static_cast<CMceSpeakerSink*>
  1099     speaker = static_cast<CMceSpeakerSink*>
  1201                         (inSession->Streams()[3]->BoundStreamL().Sinks()[0]);
  1100                         (inSession->Streams()[3]->BoundStreamL().Sinks()[0]);
  1202     EUNIT_ASSERT( speaker->VolumeL() == iReceiveSession->LcVolumeL() )
  1101     EUNIT_ASSERT( speaker->VolumeL() == iReceiveSession->VolumeL() )
  1203               
  1102               
  1204     // Check for bundles
  1103     // Check for bundles
  1205     EUNIT_ASSERT( inSession->Bundles().Count() == 1 )
  1104     EUNIT_ASSERT( inSession->Bundles().Count() == 1 )
  1206     EUNIT_ASSERT( inSession->Bundles()[0]->Streams().Count() == 4 )
  1105     EUNIT_ASSERT( inSession->Bundles()[0]->Streams().Count() == 4 )
  1207     EUNIT_ASSERT( inSession->Bundles()[0]->Streams()[0]->Type() == KMceAudio  )              
  1106     EUNIT_ASSERT( inSession->Bundles()[0]->Streams()[0]->Type() == KMceAudio  )              
  1263     EUNIT_ASSERT_EQUALS( inSession->Streams().Count(), 1 )
  1162     EUNIT_ASSERT_EQUALS( inSession->Streams().Count(), 1 )
  1264     EUNIT_ASSERT_EQUALS( inSession->Streams()[0]->Type(), KMceVideo )
  1163     EUNIT_ASSERT_EQUALS( inSession->Streams()[0]->Type(), KMceVideo )
  1265     EUNIT_ASSERT_EQUALS( inSession->Bundles().Count(), 0 )
  1164     EUNIT_ASSERT_EQUALS( inSession->Bundles().Count(), 0 )
  1266     
  1165     
  1267     
  1166     
  1268     // Session with bandwidth attributes b=AS and b=TIAS at session and media
  1167     // Session with bandwidth attribute at sessionlevel
  1269     // levels -> b=AS is taken in use at session level (b=TIAS is ignored)
  1168     // -> bandwidth is taken in use at session level
  1270     //
  1169     //
  1271     delete iReceiveSession->iSession;
  1170     delete iReceiveSession->iSession;
  1272     iReceiveSession->iSession = NULL;
  1171     iReceiveSession->iSession = NULL;
  1273     
  1172     
  1274     inSession = ConstructInSessionLC( 1, 0 );
  1173     inSession = ConstructInSessionLC( 1, 0 );
  1275     //setting session level SDP attributes
  1174     CDesC8Array* sdpLines = new ( ELeave ) CDesC8ArrayFlat( 1 );
  1276     CDesC8Array* sdpLines = new ( ELeave ) CDesC8ArrayFlat( 2 );
       
  1277     CleanupStack::PushL( sdpLines );
  1175     CleanupStack::PushL( sdpLines );
  1278     sdpLines->AppendL( KMusEngSessionSdpLineBandwidthField() );
  1176     sdpLines->AppendL( KMusEngSessionSdpLineBandwidthField() );
  1279     sdpLines->AppendL( KMusEngSessionSdpLineTiasLine() );
       
  1280     inSession->SetSessionSDPLinesL( sdpLines );
  1177     inSession->SetSessionSDPLinesL( sdpLines );
  1281     CleanupStack::Pop( sdpLines );
  1178     CleanupStack::Pop( sdpLines );
  1282     
  1179     
  1283     //setting media level SDP attributes
       
  1284     sdpLines = new ( ELeave ) CDesC8ArrayFlat( 2 );
       
  1285     CleanupStack::PushL( sdpLines );
       
  1286     sdpLines->AppendL( KMusEngSessionSdpLineBandwidthField() );
       
  1287     sdpLines->AppendL( KMusEngSessionSdpLineTiasLine() );
       
  1288     inSession->Streams()[ 0 ]->SetMediaAttributeLinesL( sdpLines );
       
  1289     CleanupStack::Pop( sdpLines );
       
  1290  
       
  1291     // Transfers ownership
  1180     // Transfers ownership
  1292     iReceiveSession->iSession = inSession; 
  1181     iReceiveSession->iSession = inSession; 
  1293     CleanupStack::Pop( inSession );
  1182     CleanupStack::Pop( inSession );
  1294     
  1183     
  1295     iReceiveSession->CompleteSessionStructureL();
  1184     iReceiveSession->CompleteSessionStructureL();
  1296  
  1185     
  1297     // Ensure there is only b=AS and no b=TIAS present at session level 
  1186     MDesC8Array* newSdpLines = iReceiveSession->iSession->SessionSDPLinesL();
  1298     MDesC8Array* newSdpLines = iReceiveSession->iSession->iSessionSDPLines;
  1187     CleanupDeletePushL( newSdpLines );
  1299     TBool bandwidthFoundFromSessionLevel = EFalse;
  1188     TBool bandwidthFoundFromSessionLevel( EFalse );
  1300     TBool tiasFoundFromSessionLevel = EFalse;
       
  1301     for ( TInt i = 0; newSdpLines && i < newSdpLines->MdcaCount(); i++ )
  1189     for ( TInt i = 0; newSdpLines && i < newSdpLines->MdcaCount(); i++ )
  1302         {
  1190         {
  1303         if ( newSdpLines->MdcaPoint( i ).Compare( 
  1191         if ( newSdpLines->MdcaPoint( i ).Compare( 
  1304                 KMusEngSessionSdpLineBandwidthField() ) == 0 )
  1192                 KMusEngSessionSdpLineBandwidthField() ) == 0 )
  1305             {
  1193             {
  1306             bandwidthFoundFromSessionLevel = ETrue;
  1194             bandwidthFoundFromSessionLevel = ETrue;
  1307             }
  1195             }
  1308         else if ( newSdpLines->MdcaPoint( i ).Find( 
  1196         }
  1309                 KMusEngSessionSdpLineTiasLine() ) == 0 )
  1197     EUNIT_ASSERT( bandwidthFoundFromSessionLevel );
       
  1198     CleanupStack::PopAndDestroy( newSdpLines );
       
  1199     
       
  1200     newSdpLines = iReceiveSession->iSession->Streams()[ 0 ]->MediaAttributeLinesL();
       
  1201     CleanupDeletePushL( newSdpLines );
       
  1202     TBool bandwidthFoundFromMediaLevel( EFalse );
       
  1203     for ( TInt i = 0; newSdpLines && i < newSdpLines->MdcaCount(); i++ )
       
  1204         {
       
  1205         if ( newSdpLines->MdcaPoint( i ).Compare( 
       
  1206                 KMusEngSessionSdpLineBandwidthField() ) == 0 )
  1310             {
  1207             {
  1311             tiasFoundFromSessionLevel = ETrue;
  1208             bandwidthFoundFromMediaLevel = ETrue;
  1312             }
  1209             }
  1313         }
  1210         }
  1314     EUNIT_ASSERT( bandwidthFoundFromSessionLevel );
  1211     EUNIT_ASSERT( !bandwidthFoundFromMediaLevel );
  1315     EUNIT_ASSERT( !tiasFoundFromSessionLevel );
  1212     CleanupStack::PopAndDestroy( newSdpLines );
  1316  
  1213     
  1317     // Ensure there is no bandwidth attributes at media level 
  1214     // Session with bandwidth attribute at media level
  1318     newSdpLines = iReceiveSession->iSession->Streams()[ 0 ]->iMediaSDPLines;
  1215     // -> bandwidth is taken in use at media level
  1319     EUNIT_ASSERT( !newSdpLines->MdcaCount() );
       
  1320 
       
  1321     
       
  1322     // Session with bandwidth AS and TIAS attributes at media level
       
  1323     // -> bandwidth AS is taken in use at media level
       
  1324     //
  1216     //
  1325     delete iReceiveSession->iSession;
  1217     delete iReceiveSession->iSession;
  1326     iReceiveSession->iSession = NULL;
  1218     iReceiveSession->iSession = NULL;
  1327     
  1219     
  1328     inSession = ConstructInSessionLC( 1, 0 );
  1220     inSession = ConstructInSessionLC( 1, 0 );
  1329     
  1221     
  1330     sdpLines = new ( ELeave ) CDesC8ArrayFlat( 2 );
  1222     sdpLines = new ( ELeave ) CDesC8ArrayFlat( 1 );
  1331     CleanupStack::PushL( sdpLines );
  1223     CleanupStack::PushL( sdpLines );
  1332     sdpLines->AppendL( KMusEngSessionSdpLineBandwidthField() );
  1224     sdpLines->AppendL( KMusEngSessionSdpLineBandwidthField() );
  1333     sdpLines->AppendL( KMusEngSessionSdpLineTiasLine() );
       
  1334     inSession->Streams()[ 0 ]->SetMediaAttributeLinesL( sdpLines );
  1225     inSession->Streams()[ 0 ]->SetMediaAttributeLinesL( sdpLines );
  1335     CleanupStack::Pop( sdpLines );
  1226     CleanupStack::Pop( sdpLines );
  1336     
  1227     
  1337     // Transfers ownership
  1228     // Transfers ownership
  1338     iReceiveSession->iSession = inSession; 
  1229     iReceiveSession->iSession = inSession; 
  1339     CleanupStack::Pop( inSession );
  1230     CleanupStack::Pop( inSession );
  1340     
  1231     
  1341     iReceiveSession->CompleteSessionStructureL();
  1232     iReceiveSession->CompleteSessionStructureL();
  1342     
  1233     
  1343     // Ensure there is no bandwidth attribute at session level  
  1234     newSdpLines = iReceiveSession->iSession->SessionSDPLinesL();
  1344     newSdpLines = iReceiveSession->iSession->iSessionSDPLines;
  1235     CleanupDeletePushL( newSdpLines );
  1345     bandwidthFoundFromSessionLevel = EFalse;
  1236     bandwidthFoundFromSessionLevel = EFalse;
  1346     for ( TInt i = 0; newSdpLines && i < newSdpLines->MdcaCount(); i++ )
  1237     for ( TInt i = 0; newSdpLines && i < newSdpLines->MdcaCount(); i++ )
  1347         {
  1238         {
  1348         if ( newSdpLines->MdcaPoint( i ).Compare( 
  1239         if ( newSdpLines->MdcaPoint( i ).Compare( 
  1349                 KMusEngSessionSdpLineBandwidthField() ) == 0
  1240                 KMusEngSessionSdpLineBandwidthField() ) == 0 )
  1350              || newSdpLines->MdcaPoint( i ).Find( 
       
  1351                      KMusEngSessionSdpLineTiasLine() ) == 0 )
       
  1352             {
  1241             {
  1353             bandwidthFoundFromSessionLevel = ETrue;
  1242             bandwidthFoundFromSessionLevel = ETrue;
  1354             }
  1243             }
  1355         }
  1244         }
  1356     EUNIT_ASSERT( !bandwidthFoundFromSessionLevel );
  1245     EUNIT_ASSERT( !bandwidthFoundFromSessionLevel );
  1357     
  1246     CleanupStack::PopAndDestroy( newSdpLines );
  1358     // Ensure media level has only b=AS attribute
  1247     
  1359     newSdpLines = iReceiveSession->iSession->Streams()[ 0 ]->iMediaSDPLines;
  1248     newSdpLines = iReceiveSession->iSession->Streams()[ 0 ]->MediaAttributeLinesL();
  1360     EUNIT_ASSERT( newSdpLines );
  1249     CleanupDeletePushL( newSdpLines );
  1361     EUNIT_ASSERT( newSdpLines->MdcaCount() == 1 );
  1250     bandwidthFoundFromMediaLevel = EFalse;
  1362     EUNIT_ASSERT( newSdpLines->MdcaPoint( 0 ) == KMusEngSessionSdpLineBandwidthField() );
  1251     for ( TInt i = 0; newSdpLines && i < newSdpLines->MdcaCount(); i++ )
  1363     }
  1252         {
  1364     
  1253         if ( newSdpLines->MdcaPoint( i ).Compare( 
  1365 
  1254                 KMusEngSessionSdpLineBandwidthField() ) == 0 )
  1366 // -----------------------------------------------------------------------------
  1255             {
  1367 //
  1256             bandwidthFoundFromMediaLevel = ETrue;
  1368 // -----------------------------------------------------------------------------
  1257             }
  1369 // 
  1258         }
  1370 void UT_CMusEngReceiveSession::UT_CompleteSessionStructureL_SdpBandwidthAttributesL()
  1259     EUNIT_ASSERT( bandwidthFoundFromMediaLevel );
  1371     {
  1260     CleanupStack::PopAndDestroy( newSdpLines );
  1372     CRepository::SetStubGlobal( MusSettingsKeys::KVideoBandwidth,
  1261     }
  1373                                 128 );
  1262     
  1374 
       
  1375     // 1. Session without bandwidth attributes. => b=AS and b=TIAS will be
       
  1376     //    taken at media level
       
  1377     CMceInSession* inSession = ConstructInSessionLC( 1, 0 );
       
  1378 
       
  1379     iReceiveSession->iSession = inSession; // Transfers ownership
       
  1380     CleanupStack::Pop( inSession );
       
  1381 
       
  1382     iReceiveSession->CompleteSessionStructureL();
       
  1383 
       
  1384     // Ensure b=AS and b=TIAS present at media level only
       
  1385     MDesC8Array* newSdpLines = iReceiveSession->iSession->iSessionSDPLines;
       
  1386     EUNIT_ASSERT( newSdpLines->MdcaCount() == 1 );
       
  1387     EUNIT_ASSERT( newSdpLines->MdcaPoint( 0 ) == KMusEngSessionSdpLineXApplication() );
       
  1388 
       
  1389     // Ensure b=AS and b=TIAS present at media level
       
  1390     EUNIT_ASSERT( iReceiveSession->iSession->Streams().Count() > 0 );
       
  1391     newSdpLines = iReceiveSession->iSession->Streams()[ 0 ]->iMediaSDPLines;
       
  1392     EUNIT_ASSERT( newSdpLines );
       
  1393     EUNIT_ASSERT( newSdpLines->MdcaCount() == 2 );
       
  1394     EUNIT_ASSERT( newSdpLines->MdcaPoint( 0 ).Find(
       
  1395                   KMusEngSessionSdpLineBandwidthLine() ) == 0 );
       
  1396     EUNIT_ASSERT( newSdpLines->MdcaPoint( 1 ).Find( 
       
  1397                   KMusEngSessionSdpLineTiasLine() ) == 0 );    
       
  1398     
       
  1399     
       
  1400     // 2. Session with b=AS bandwidth attribute at session level
       
  1401     //     => b=AS and b=TIAS will be taken at session level
       
  1402     delete iReceiveSession->iSession;
       
  1403     iReceiveSession->iSession = NULL;
       
  1404     
       
  1405     inSession = ConstructInSessionLC( 1, 0 );
       
  1406     //setting session level SDP attributes
       
  1407     CDesC8Array* sdpLines = new ( ELeave ) CDesC8ArrayFlat( 1 );
       
  1408     CleanupStack::PushL( sdpLines );
       
  1409     sdpLines->AppendL( KMusEngSessionSdpLineBandwidthField() );
       
  1410     inSession->SetSessionSDPLinesL( sdpLines );
       
  1411     CleanupStack::Pop( sdpLines );
       
  1412  
       
  1413     // Transfers ownership
       
  1414     iReceiveSession->iSession = inSession; 
       
  1415     CleanupStack::Pop( inSession );
       
  1416     
       
  1417     iReceiveSession->CompleteSessionStructureL();
       
  1418  
       
  1419     // Ensure b=AS and b=TIAS present at session level only 
       
  1420     newSdpLines = iReceiveSession->iSession->iSessionSDPLines;
       
  1421     EUNIT_ASSERT( newSdpLines );
       
  1422     EUNIT_ASSERT( newSdpLines->MdcaCount() == 3 );
       
  1423     EUNIT_ASSERT( newSdpLines->MdcaPoint( 0 ) == KMusEngSessionSdpLineXApplication() );
       
  1424     EUNIT_ASSERT( newSdpLines->MdcaPoint( 1 ).Find ( 
       
  1425                   KMusEngSessionSdpLineBandwidthLine() ) == 0 );
       
  1426     EUNIT_ASSERT( newSdpLines->MdcaPoint( 2 ).Find( 
       
  1427                   KMusEngSessionSdpLineTiasLine() ) == 0 );    
       
  1428 
       
  1429     EUNIT_ASSERT( iReceiveSession->iSession->Streams().Count() > 0 );    
       
  1430     newSdpLines = iReceiveSession->iSession->Streams()[ 0 ]->iMediaSDPLines;
       
  1431     EUNIT_ASSERT( newSdpLines );
       
  1432     EUNIT_ASSERT( newSdpLines->MdcaCount() == 0 );
       
  1433 
       
  1434     // 3. Session with b=AS bandwidth attribute at media level
       
  1435     //     => b=AS and b=TIAS will be taken at media level
       
  1436     delete iReceiveSession->iSession;
       
  1437     iReceiveSession->iSession = NULL;
       
  1438     
       
  1439     inSession = ConstructInSessionLC( 1, 0 );
       
  1440     //setting media level SDP attributes
       
  1441     sdpLines = new ( ELeave ) CDesC8ArrayFlat( 1 );
       
  1442     CleanupStack::PushL( sdpLines );
       
  1443     sdpLines->AppendL( KMusEngSessionSdpLineBandwidthField() );
       
  1444     inSession->Streams()[ 0 ]->SetMediaAttributeLinesL( sdpLines );
       
  1445     CleanupStack::Pop( sdpLines );
       
  1446  
       
  1447     // Transfers ownership
       
  1448     iReceiveSession->iSession = inSession; 
       
  1449     CleanupStack::Pop( inSession );
       
  1450     
       
  1451     iReceiveSession->CompleteSessionStructureL();
       
  1452  
       
  1453     // Ensure b=AS and b=TIAS present only at media level 
       
  1454     newSdpLines = iReceiveSession->iSession->iSessionSDPLines;
       
  1455     EUNIT_ASSERT( newSdpLines );
       
  1456     EUNIT_ASSERT( newSdpLines->MdcaCount() == 1 );
       
  1457     EUNIT_ASSERT( newSdpLines->MdcaPoint( 0 ) == KMusEngSessionSdpLineXApplication() );
       
  1458 
       
  1459     EUNIT_ASSERT( iReceiveSession->iSession->Streams().Count() > 0 );    
       
  1460     newSdpLines = iReceiveSession->iSession->Streams()[ 0 ]->iMediaSDPLines;
       
  1461     EUNIT_ASSERT( newSdpLines );
       
  1462     EUNIT_ASSERT( newSdpLines->MdcaCount() == 2 );
       
  1463     EUNIT_ASSERT( newSdpLines->MdcaPoint( 0 ).Find ( 
       
  1464                   KMusEngSessionSdpLineBandwidthLine() ) == 0 );
       
  1465     EUNIT_ASSERT( newSdpLines->MdcaPoint( 1 ).Find( 
       
  1466                   KMusEngSessionSdpLineTiasLine() ) == 0 );    
       
  1467 
       
  1468    
       
  1469     // 4. Session with b=AS attribute at session level and
       
  1470     //    b=AS and b=TIAS at media level
       
  1471     //    => b=AS and b=TIAS will be taken at session and media level
       
  1472     delete iReceiveSession->iSession;
       
  1473     iReceiveSession->iSession = NULL;
       
  1474     
       
  1475     inSession = ConstructInSessionLC( 1, 0 );
       
  1476     //setting session level SDP attributes
       
  1477     sdpLines = new ( ELeave ) CDesC8ArrayFlat( 1 );
       
  1478     CleanupStack::PushL( sdpLines );
       
  1479     sdpLines->AppendL( KMusEngSessionSdpLineBandwidthField() );
       
  1480     inSession->SetSessionSDPLinesL( sdpLines );
       
  1481     CleanupStack::Pop( sdpLines );
       
  1482  
       
  1483     //setting media level SDP attributes
       
  1484     sdpLines = new ( ELeave ) CDesC8ArrayFlat( 2 );
       
  1485     CleanupStack::PushL( sdpLines );
       
  1486     sdpLines->AppendL( KMusEngSessionSdpLineBandwidthField() );
       
  1487     sdpLines->AppendL( KMusEngSessionSdpLineTiasLine() );
       
  1488     inSession->Streams()[ 0 ]->SetMediaAttributeLinesL( sdpLines );
       
  1489     CleanupStack::Pop( sdpLines );
       
  1490 
       
  1491     // Transfers ownership
       
  1492     iReceiveSession->iSession = inSession; 
       
  1493     CleanupStack::Pop( inSession );
       
  1494     
       
  1495     iReceiveSession->CompleteSessionStructureL();
       
  1496  
       
  1497     // Ensure b=AS and b=TIAS present at session and media level 
       
  1498     newSdpLines = iReceiveSession->iSession->iSessionSDPLines;
       
  1499     EUNIT_ASSERT( newSdpLines );
       
  1500     EUNIT_ASSERT( newSdpLines->MdcaCount() == 3 );
       
  1501     EUNIT_ASSERT( newSdpLines->MdcaPoint( 0 ) == KMusEngSessionSdpLineXApplication() );
       
  1502     EUNIT_ASSERT( newSdpLines->MdcaPoint( 1 ).Find ( 
       
  1503                   KMusEngSessionSdpLineBandwidthLine() ) == 0 );
       
  1504     EUNIT_ASSERT( newSdpLines->MdcaPoint( 2 ).Find( 
       
  1505                   KMusEngSessionSdpLineTiasLine() ) == 0 );    
       
  1506 
       
  1507     EUNIT_ASSERT( iReceiveSession->iSession->Streams().Count() > 0 );    
       
  1508     newSdpLines = iReceiveSession->iSession->Streams()[ 0 ]->iMediaSDPLines;
       
  1509     EUNIT_ASSERT( newSdpLines );
       
  1510     EUNIT_ASSERT( newSdpLines->MdcaCount() == 2 );
       
  1511     EUNIT_ASSERT( newSdpLines->MdcaPoint( 0 ).Find ( 
       
  1512                   KMusEngSessionSdpLineBandwidthLine() ) == 0 );
       
  1513     EUNIT_ASSERT( newSdpLines->MdcaPoint( 1 ).Find( 
       
  1514                   KMusEngSessionSdpLineTiasLine() ) == 0 );
       
  1515     }
       
  1516 
       
  1517     
  1263     
  1518 // -----------------------------------------------------------------------------
  1264 // -----------------------------------------------------------------------------
  1519 //
  1265 //
  1520 // -----------------------------------------------------------------------------
  1266 // -----------------------------------------------------------------------------
  1521 // 
  1267 // 
  1585     // null header
  1331     // null header
  1586     iReceiveSession->ParseAssertedIdentity( &container );
  1332     iReceiveSession->ParseAssertedIdentity( &container );
  1587     EUNIT_ASSERT_EQUALS( iReceiveSession->iIdentity, KNullDesC8 )    
  1333     EUNIT_ASSERT_EQUALS( iReceiveSession->iIdentity, KNullDesC8 )    
  1588     }
  1334     }
  1589 
  1335 
  1590 // -----------------------------------------------------------------------------
       
  1591 // 
       
  1592 // -----------------------------------------------------------------------------
       
  1593 //
       
  1594 void UT_CMusEngReceiveSession::UT_ContactSavingLL()
       
  1595     {
       
  1596     ContactEngineStubHelper::Reset();
       
  1597     
       
  1598     // Saving of contact is done at destruction phase only if originator value
       
  1599     // exists
       
  1600     //
       
  1601     CMusEngReceiveSession* receiveSession = CMusEngReceiveSession::NewL();
       
  1602     receiveSession->SetLcSessionObserver( iLcSessionObserver );    
       
  1603     delete receiveSession;
       
  1604     receiveSession = NULL;
       
  1605     EUNIT_ASSERT( ContactEngineStubHelper::GetCalledFunction() == EContactEngineStubNone );
       
  1606     
       
  1607     
       
  1608     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
  1609                                         NMusSessionApi::KContactId,
       
  1610                                         2 ) );
       
  1611     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
       
  1612                                         NMusSessionApi::KTelNumber,
       
  1613                                         _L("12341234") ) );
       
  1614     
       
  1615     receiveSession = CMusEngReceiveSession::NewL();
       
  1616     CleanupStack::PushL( receiveSession );
       
  1617     receiveSession->SetLcSessionObserver( iLcSessionObserver );
       
  1618     delete receiveSession->iOriginator;
       
  1619     receiveSession->iOriginator = NULL;
       
  1620     receiveSession->iOriginator = _L8("sip:yep@10.10.10.10").AllocL();
       
  1621     CleanupStack::PopAndDestroy( receiveSession );
       
  1622     if ( ContactEngineStubHelper::GetCalledFunction() != EContactEngineStubSetText )
       
  1623         {
       
  1624         // out-of-memory was trap ignored and saving failed because of that
       
  1625         User::Leave( KErrNoMemory );
       
  1626         }
       
  1627     EUNIT_ASSERT( ContactEngineStubHelper::GetCalledFunction() == EContactEngineStubSetText );
       
  1628     }
       
  1629 
       
  1630 // -----------------------------------------------------------------------------
       
  1631 // 
       
  1632 // -----------------------------------------------------------------------------
       
  1633 //
       
  1634 void UT_CMusEngReceiveSession::UT_IsDisplayActive()
       
  1635     {
       
  1636     // Display is active only if receiving and display is explicitly enabled
       
  1637     CMceInSession* inSession = ConstructInSessionLC( 1, 1 );
       
  1638     iReceiveSession->iSession = inSession; // Transfers ownership
       
  1639     CleanupStack::Pop( inSession );
       
  1640     iReceiveSession->EnableDisplayL( ETrue );
       
  1641     EUNIT_ASSERT( !iReceiveSession->IsDisplayActive() )
       
  1642     iReceiveSession->iReceiving = ETrue;
       
  1643     EUNIT_ASSERT( iReceiveSession->IsDisplayActive() )
       
  1644     }
       
  1645 
       
  1646 // -----------------------------------------------------------------------------
       
  1647 //
       
  1648 // -----------------------------------------------------------------------------
       
  1649 //
       
  1650 void UT_CMusEngReceiveSession::UT_InactivityTimeoutL()
       
  1651     {
       
  1652     // Not receiving, no effect
       
  1653     iReceiveSession->iReceiving = EFalse;
       
  1654     CMceVideoStream* videoStream = CMceVideoStream::NewLC();
       
  1655     CMceRtpSource* rtpSource = CMceRtpSource::NewLC();
       
  1656     iReceiveSession->InactivityTimeout( *videoStream, *rtpSource );
       
  1657     EUNIT_ASSERT( iLcSessionObserver->IsReseted() );
       
  1658     
       
  1659     // Receiving, state change is notified and
       
  1660     // receiving and buffering status are cleared
       
  1661     iReceiveSession->iBuffered = ETrue;
       
  1662     iReceiveSession->iReceiving = ETrue;
       
  1663     iReceiveSession->InactivityTimeout( *videoStream, *rtpSource );
       
  1664     EUNIT_ASSERT_EQUALS( iLcSessionObserver->iCalledFunction, 
       
  1665                          CLcSessionObserverStub::EPlayerStateChanged );
       
  1666     EUNIT_ASSERT( !iReceiveSession->iReceiving );
       
  1667     EUNIT_ASSERT( !iReceiveSession->iBuffered );
       
  1668     CleanupStack::PopAndDestroy( rtpSource );
       
  1669     CleanupStack::PopAndDestroy( videoStream );
       
  1670     }
       
  1671 
       
  1672 
  1336 
  1673 //  TEST TABLE
  1337 //  TEST TABLE
  1674 
  1338 
  1675 EUNIT_BEGIN_TEST_TABLE(
  1339 EUNIT_BEGIN_TEST_TABLE(
  1676     UT_CMusEngReceiveSession,
  1340     UT_CMusEngReceiveSession,
  1683     "NewL",
  1347     "NewL",
  1684     "FUNCTIONALITY",
  1348     "FUNCTIONALITY",
  1685     SetupL, UT_NewLL, Teardown)
  1349     SetupL, UT_NewLL, Teardown)
  1686 
  1350 
  1687 EUNIT_TEST(
  1351 EUNIT_TEST(
  1688     "LcSessionState - test ",
  1352     "AcceptInvitationL - test ",
  1689     "CMusEngReceiveSession",
  1353     "CMusEngReceiveSession",
  1690     "LcSessionState",
  1354     "AcceptInvitationL",
  1691     "FUNCTIONALITY",
  1355     "FUNCTIONALITY",
  1692     SetupL, UT_LcSessionStateL, Teardown)
  1356     SetupL, UT_AcceptInvitationLL, Teardown)
  1693     
       
  1694 EUNIT_TEST(
       
  1695     "EstablishLcSessionL - test ",
       
  1696     "CMusEngReceiveSession",
       
  1697     "EstablishLcSessionL",
       
  1698     "FUNCTIONALITY",
       
  1699     SetupL, UT_EstablishLcSessionL, Teardown)    
       
  1700     
       
  1701 EUNIT_TEST(
       
  1702     "TerminateLcSessionL - test ",
       
  1703     "CMusEngReceiveSession",
       
  1704     "TerminateLcSessionL",
       
  1705     "FUNCTIONALITY",
       
  1706     SetupL, UT_TerminateLcSessionL, Teardown)
       
  1707 
       
  1708 EUNIT_TEST(
       
  1709     "RemoteVideoPlayer - test ",
       
  1710     "CMusEngReceiveSession",
       
  1711     "RemoteVideoPlayer",
       
  1712     "FUNCTIONALITY",
       
  1713     SetupL, UT_RemoteVideoPlayerL, Teardown)
       
  1714     
       
  1715 EUNIT_TEST(
       
  1716     "RemoteDisplayName - test ",
       
  1717     "CMusEngReceiveSession",
       
  1718     "RemoteDisplayName",
       
  1719     "FUNCTIONALITY",
       
  1720     SetupL, UT_RemoteDisplayName, Teardown)
       
  1721 
  1357 
  1722 EUNIT_TEST(
  1358 EUNIT_TEST(
  1723     "HandleSessionStateChanged - test ",
  1359     "HandleSessionStateChanged - test ",
  1724     "CMusEngReceiveSession",
  1360     "CMusEngReceiveSession",
  1725     "HandleSessionStateChanged",
  1361     "HandleSessionStateChanged",
  1830     "CompleteSessionStructureL",
  1466     "CompleteSessionStructureL",
  1831     "FUNCTIONALITY",
  1467     "FUNCTIONALITY",
  1832     SetupL, UT_CompleteSessionStructureL_OperatorVariant, Teardown)
  1468     SetupL, UT_CompleteSessionStructureL_OperatorVariant, Teardown)
  1833    
  1469    
  1834 EUNIT_TEST(
  1470 EUNIT_TEST(
  1835     "CompleteSessionStructureL - test SDP bandwidth attributes handling",
       
  1836     "CMusEngReceiveSession",
       
  1837     "CompleteSessionStructureL",
       
  1838     "FUNCTIONALITY",
       
  1839     SetupL, UT_CompleteSessionStructureL_SdpBandwidthAttributesL, Teardown)
       
  1840 
       
  1841 EUNIT_TEST(
       
  1842     "ParseAssertedIdentity",
  1471     "ParseAssertedIdentity",
  1843     "CMusEngReceiveSession",
  1472     "CMusEngReceiveSession",
  1844     "ParseAssertedIdentity",
  1473     "ParseAssertedIdentity",
  1845     "FUNCTIONALITY",
  1474     "FUNCTIONALITY",
  1846     SetupL, UT_ParseAssertedIdentityL, Teardown)
  1475     SetupL, UT_ParseAssertedIdentityL, Teardown)
  1847       
  1476       
  1848 EUNIT_TEST(
  1477    
  1849     "ContactSavingL - test",
       
  1850     "CMusEngReceiveSession",
       
  1851     "ContactSavingL",
       
  1852     "FUNCTIONALITY",
       
  1853     SetupL, UT_ContactSavingLL, Teardown)
       
  1854 
       
  1855 EUNIT_TEST(
       
  1856     "IsDisplayActive - test",
       
  1857     "CMusEngReceiveSession",
       
  1858     "IsDisplayActive",
       
  1859     "FUNCTIONALITY",
       
  1860     SetupL, UT_IsDisplayActive, Teardown)
       
  1861     
       
  1862 EUNIT_TEST(
       
  1863     "InactivityTimeout - test ",
       
  1864     "CMusEngReceiveSession",
       
  1865     "InactivityTimeout",
       
  1866     "FUNCTIONALITY",
       
  1867     SetupL, UT_InactivityTimeoutL, Teardown)      
       
  1868     
       
  1869 EUNIT_END_TEST_TABLE
  1478 EUNIT_END_TEST_TABLE
  1870 
  1479 
  1871 //  END OF FILE
  1480 //  END OF FILE
  1872 
  1481 
  1873 
  1482