rtp/srtpstack/tsrc/ut_srtpstack/src/UT_CSRTPSession.cpp
changeset 0 307788aac0a8
child 19 b5e99d8877c7
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2004 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 
       
    20 //  CLASS HEADER
       
    21 #include "UT_CSRTPSession.h"
       
    22 
       
    23 
       
    24 //  EXTERNAL INCLUDES
       
    25 #include <digia/eunit/eunitmacros.h>
       
    26 #include "srtpcryptohandlersrtp.h"
       
    27 #include "srtpcryptohandlersrtcp.h"
       
    28 #include "srtpmastersalt.h"
       
    29 #include "srtpmasterkey.h"
       
    30 #include "srtpstreamin.h"
       
    31 #include "srtpstreamout.h"
       
    32 #include "srtpsession.h"
       
    33 #include "srtputils.h"
       
    34 
       
    35 _LIT8(KRFC3711_TestMasterKey128bits,    "E1F97A0D3E018BE0D64FA32C06DE4139");
       
    36 _LIT8(KRFC3711_TestMasterSalt112bits,   "0EC675AD498AFEEBB6960B3AABE6");	
       
    37 _LIT8(KTestMKI128Bits,      			"ABCDEF1234567890ABCDEF1234567890");
       
    38 
       
    39 #define RTP_EUNIT_ASSERT_SPECIFIC_LEAVE( func, val ) \
       
    40 {\
       
    41 TRAPD( rtpUnitTestRetVal, func );\
       
    42 if ( val != KErrNoMemory && rtpUnitTestRetVal == KErrNoMemory ){\
       
    43 	User::Leave( KErrNoMemory );\
       
    44 	}\
       
    45 else{\
       
    46 	EUNIT_ASSERT_EQUALS( rtpUnitTestRetVal, val );\
       
    47 	}\
       
    48 }
       
    49 
       
    50 
       
    51 //  INTERNAL INCLUDES
       
    52 #include "srtpsession.h"
       
    53 // CONSTANTS
       
    54 _LIT8(KDummyRTCPPacket, "dummyrtcp");
       
    55 // CONSTRUCTION
       
    56 UT_CSRTPSession* UT_CSRTPSession::NewL()
       
    57     {
       
    58     UT_CSRTPSession* self = UT_CSRTPSession::NewLC(); 
       
    59     CleanupStack::Pop();
       
    60 
       
    61     return self;
       
    62     }
       
    63 
       
    64 UT_CSRTPSession* UT_CSRTPSession::NewLC()
       
    65     {
       
    66     UT_CSRTPSession* self = new( ELeave ) UT_CSRTPSession();
       
    67     CleanupStack::PushL( self );
       
    68 
       
    69 	self->ConstructL(); 
       
    70 
       
    71     return self;
       
    72     }
       
    73 
       
    74 // Destructor (virtual by CBase)
       
    75 UT_CSRTPSession::~UT_CSRTPSession()
       
    76     {
       
    77     }
       
    78 
       
    79 // Default constructor
       
    80 UT_CSRTPSession::UT_CSRTPSession()
       
    81     {
       
    82     }
       
    83 
       
    84 // Second phase construct
       
    85 void UT_CSRTPSession::ConstructL()
       
    86     {
       
    87     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
    88     // It generates the test case table.
       
    89     CEUnitTestSuiteClass::ConstructL();
       
    90     }
       
    91 void UT_CSRTPSession::SRTPMasterKeyStaleEvent(const CSRTPStream& /*aStream*/ )
       
    92     {
       
    93     }
       
    94 void UT_CSRTPSession::SRTPMasterKeyStaleEvent(const CSRTPSession& /*aSession*/ )
       
    95     {
       
    96     }
       
    97 
       
    98 
       
    99 void UT_CSRTPSession::Hex(HBufC8& aString)
       
   100 {
       
   101     TPtr8 ptr=aString.Des();
       
   102     TInt length = aString.Length();
       
   103     if (aString.Length()%2)
       
   104         {
       
   105         ptr.SetLength(0);
       
   106         return;
       
   107         }
       
   108     TInt i;
       
   109     for (i=0;i<aString.Length();i+=2)
       
   110         {
       
   111         TUint8 tmp;
       
   112         tmp=(TUint8)(aString[i]-(aString[i]>'9'?('A'-10):'0'));
       
   113         tmp*=16;
       
   114         tmp|=(TUint8)(aString[i+1]-(aString[i+1]>'9'?('A'-10):'0'));
       
   115         ptr[i/2]=tmp;
       
   116         }
       
   117     ptr.SetLength(aString.Length()/2);
       
   118 
       
   119 }
       
   120 //  METHODS
       
   121 
       
   122 
       
   123 void UT_CSRTPSession::SetupL(  )
       
   124     {
       
   125     HBufC8* masterKey = HBufC8::NewL(KRFC3711_TestMasterKey128bits().Length());
       
   126     CleanupStack::PushL( masterKey );
       
   127     *masterKey = KRFC3711_TestMasterKey128bits;
       
   128 
       
   129     
       
   130     
       
   131     HBufC8* masterSalt =HBufC8::NewL(KRFC3711_TestMasterSalt112bits().Length());
       
   132     CleanupStack::PushL( masterSalt);
       
   133 	*masterSalt = KRFC3711_TestMasterSalt112bits;
       
   134 
       
   135 	
       
   136 	iMasterKey = CSRTPMasterKey::NewL( *masterKey, _L8("") );
       
   137     iMasterSalt = CSRTPMasterSalt::NewL( *masterSalt );
       
   138     
       
   139     TSrtpCryptoParams params;
       
   140     
       
   141     iContext = CSRTPCryptoContext::NewL(iMasterKey, iMasterSalt, params );
       
   142     
       
   143     CleanupStack::PopAndDestroy( masterSalt );
       
   144     CleanupStack::PopAndDestroy( masterKey ); 
       
   145     iDestination.Input(_L("127.0.0.1"));
       
   146     } 
       
   147 
       
   148 void UT_CSRTPSession::Teardown(  )
       
   149     {
       
   150     delete iContext;
       
   151     iContext=NULL;
       
   152     }
       
   153 
       
   154 void UT_CSRTPSession::UT_CSRTPSession_NewL_1L(  )
       
   155     {
       
   156     CSRTPSession* srtpSession = CSRTPSession::NewL( iDestination); 
       
   157     EUNIT_ASSERT(srtpSession);
       
   158     delete srtpSession;
       
   159     }
       
   160 
       
   161 void UT_CSRTPSession::UT_CSRTPSession_NewL_2L(  )
       
   162     {
       
   163                             
       
   164     CSRTPSession* srtpSession = CSRTPSession::NewL(iDestination,
       
   165     												iContext,
       
   166     												*this); 
       
   167     iContext=NULL; // Ownership was transferred
       
   168     
       
   169     EUNIT_ASSERT(srtpSession);	
       
   170     
       
   171     delete srtpSession;       
       
   172          
       
   173     }
       
   174 
       
   175 void UT_CSRTPSession::UT_CSRTPSession_ConstructLL(  )
       
   176     {         
       
   177     delete iContext; iContext=0;
       
   178     CSRTPSession* srtpSession;
       
   179     RTP_EUNIT_ASSERT_SPECIFIC_LEAVE( srtpSession= CSRTPSession::NewLC(iDestination,
       
   180     												iContext,
       
   181     												*this), 
       
   182     							KErrArgument); 
       
   183     						
       
   184     }
       
   185 
       
   186 void UT_CSRTPSession::UT_CSRTPSession_RemoveStreamL(  )
       
   187     {
       
   188     
       
   189     CSRTPSession* srtpSession = CSRTPSession::NewLC(iDestination,
       
   190     												iContext,
       
   191     												*this); 
       
   192     iContext=NULL; // Ownership was transferred
       
   193     
       
   194     //automatically added stream in the constructor												
       
   195     CSRTPStreamIn* tempStreamIn = CSRTPStreamIn::NewL(*srtpSession, (TUint)1);
       
   196     CleanupStack::PushL( tempStreamIn );
       
   197     
       
   198 	EUNIT_ASSERT(srtpSession->iStreamList.First());
       
   199 	srtpSession->RemoveStreamFromList(tempStreamIn);
       
   200 	// Will not found stream so just not remove it
       
   201 	srtpSession->RemoveStreamFromList(tempStreamIn);
       
   202 
       
   203 
       
   204     CleanupStack::PopAndDestroy( tempStreamIn );
       
   205     CleanupStack::PopAndDestroy( srtpSession );
       
   206    
       
   207     }
       
   208 
       
   209 void UT_CSRTPSession::UT_CSRTPSession_GetCryptoContextL(  )
       
   210     {
       
   211  
       
   212     CSRTPSession* srtpSession = CSRTPSession::NewLC(iDestination,
       
   213     												iContext,
       
   214     												*this); 
       
   215     iContext=NULL; // Ownership was transferred
       
   216     
       
   217     EUNIT_ASSERT(srtpSession->iSesssionCrypto);
       
   218     CleanupStack::PopAndDestroy( srtpSession );												
       
   219     }
       
   220     
       
   221 void UT_CSRTPSession::UT_CSRTPSession_UpdateCryptoContextLL()
       
   222 	{
       
   223 	//Test case 1 :set crypto context in session
       
   224 	HBufC8* masterKey = HBufC8::NewL(KRFC3711_TestMasterKey128bits().Length());
       
   225     CleanupStack::PushL( masterKey );
       
   226     *masterKey = KRFC3711_TestMasterKey128bits;
       
   227     
       
   228     HBufC8* masterSalt =HBufC8::NewL(KRFC3711_TestMasterSalt112bits().Length());
       
   229     CleanupStack::PushL( masterSalt);
       
   230 	*masterSalt = KRFC3711_TestMasterSalt112bits;
       
   231 
       
   232 	
       
   233 	CSRTPMasterKey* mKey = CSRTPMasterKey::NewLC( *masterKey, _L8("") );
       
   234     CSRTPMasterSalt* mSalt = CSRTPMasterSalt::NewLC( *masterSalt );
       
   235     
       
   236     TSrtpCryptoParams params;
       
   237     
       
   238     CSRTPCryptoContext* context = CSRTPCryptoContext::NewL(mKey, mSalt, params );
       
   239     CleanupStack::Pop( mSalt );
       
   240     CleanupStack::Pop( mKey );
       
   241     CleanupStack::PopAndDestroy( masterSalt );
       
   242     CleanupStack::PopAndDestroy( masterKey ); 
       
   243     CleanupStack::PushL( context );
       
   244     CSRTPSession* srtpSession = CSRTPSession::NewL(iDestination,
       
   245     												iContext,
       
   246     												*this); 
       
   247 	iContext=NULL; // Ownership was transferred
       
   248 	
       
   249 	CleanupStack::PushL( srtpSession );
       
   250 	srtpSession->SetCryptoContextL(context);
       
   251 	CleanupStack::Pop( srtpSession );
       
   252 	CleanupStack::Pop( context );
       
   253 	CleanupStack::PushL( srtpSession );
       
   254 	
       
   255 	//Test cases 2: Create stream and then set the crypto context again
       
   256 	CSRTPStreamIn* streamIn =CSRTPStreamIn::NewL( *srtpSession,
       
   257                                       (TUint)1,
       
   258                                       *this );
       
   259     CleanupStack::PushL( streamIn );
       
   260     
       
   261 	CSRTPStreamOut* streamOut = CSRTPStreamOut::NewL(*srtpSession, (TUint)1);
       
   262 	CleanupStack::PushL( streamOut );
       
   263 	HBufC8* masterKey2 = HBufC8::NewL(KRFC3711_TestMasterKey128bits().Length());
       
   264     CleanupStack::PushL( masterKey2 );
       
   265     *masterKey2 = KRFC3711_TestMasterKey128bits;
       
   266     
       
   267     HBufC8* masterSalt2 =HBufC8::NewL(KRFC3711_TestMasterSalt112bits().Length());
       
   268     CleanupStack::PushL( masterSalt2);
       
   269 	*masterSalt2 = KRFC3711_TestMasterSalt112bits;
       
   270 
       
   271 	
       
   272 	CSRTPMasterKey* mKey2 = CSRTPMasterKey::NewLC( *masterKey2, _L8("") );
       
   273     CSRTPMasterSalt* mSalt2 = CSRTPMasterSalt::NewLC( *masterSalt2 );
       
   274     
       
   275     //TSrtpCryptoParams params;
       
   276     
       
   277     CSRTPCryptoContext* context2 = CSRTPCryptoContext::NewL(mKey2, mSalt2, params );
       
   278     CleanupStack::Pop( mSalt2 );
       
   279     CleanupStack::Pop( mKey2 );
       
   280     CleanupStack::PopAndDestroy( masterSalt2 );
       
   281     CleanupStack::PopAndDestroy( masterKey2 ); 
       
   282     CleanupStack::PushL( context2 );
       
   283 	srtpSession->SetCryptoContextL(context2);
       
   284 	CleanupStack::Pop( context2 );
       
   285 	
       
   286 	// Test case 4: create stream with specdific context
       
   287 	HBufC8* masterKey3 = HBufC8::NewL(KRFC3711_TestMasterKey128bits().Length());
       
   288     CleanupStack::PushL( masterKey3 );
       
   289     *masterKey3 = KRFC3711_TestMasterKey128bits;
       
   290     
       
   291     HBufC8* masterSalt3 =HBufC8::NewL(KRFC3711_TestMasterSalt112bits().Length());
       
   292     CleanupStack::PushL( masterSalt3);
       
   293 	*masterSalt3 = KRFC3711_TestMasterSalt112bits;
       
   294 
       
   295 	
       
   296 	CSRTPMasterKey* mKey3 = CSRTPMasterKey::NewLC( *masterKey3, _L8("") );
       
   297     CSRTPMasterSalt* mSalt3 = CSRTPMasterSalt::NewLC( *masterSalt3 );
       
   298     
       
   299     //TSrtpCryptoParams params;
       
   300 	CSRTPCryptoContext* context3 = CSRTPCryptoContext::NewL(mKey3, mSalt3, params );
       
   301 	CleanupStack::Pop( mSalt3 );
       
   302     CleanupStack::Pop( mKey3 );
       
   303     CleanupStack::PopAndDestroy( masterSalt3 );
       
   304     CleanupStack::PopAndDestroy( masterKey3 ); 
       
   305     CleanupStack::PushL( context3 );
       
   306 	HBufC8* masterKey4 = HBufC8::NewL(KRFC3711_TestMasterKey128bits().Length());
       
   307     CleanupStack::PushL( masterKey4 );
       
   308     *masterKey4 = KRFC3711_TestMasterKey128bits;
       
   309     
       
   310     HBufC8* masterSalt4 =HBufC8::NewL(KRFC3711_TestMasterSalt112bits().Length());
       
   311     CleanupStack::PushL( masterSalt4);
       
   312 	*masterSalt4 = KRFC3711_TestMasterSalt112bits;
       
   313 
       
   314 	
       
   315 	CSRTPMasterKey* mKey4 = CSRTPMasterKey::NewLC( *masterKey4, _L8("") );
       
   316     CSRTPMasterSalt* mSalt4 = CSRTPMasterSalt::NewLC( *masterSalt4 );
       
   317     
       
   318     //TSrtpCryptoParams params;
       
   319 	CSRTPCryptoContext* context4 = CSRTPCryptoContext::NewL(mKey4, mSalt4, params );
       
   320 	CleanupStack::Pop( mSalt4 );
       
   321     CleanupStack::Pop( mKey4 );
       
   322     CleanupStack::PopAndDestroy( masterSalt4 );
       
   323     CleanupStack::PopAndDestroy( masterKey4); 
       
   324     CleanupStack::PushL( context4 );
       
   325 	CSRTPStreamIn* streamIn2 =CSRTPStreamIn::NewL( *srtpSession,
       
   326                                       context3,
       
   327                                       *this );
       
   328     CleanupStack::Pop( context4 );
       
   329     CleanupStack::Pop( context3 );
       
   330     CleanupStack::PushL( streamIn2 );
       
   331     CleanupStack::PushL( context4 );
       
   332 	CSRTPStreamOut* streamOut2 = CSRTPStreamOut::NewL(*srtpSession, (TUint)2, context4, *this);
       
   333 	CleanupStack::Pop( context4 );
       
   334 	CleanupStack::PushL( streamOut2 );
       
   335 	
       
   336 	HBufC8* masterKey5 = HBufC8::NewL(KRFC3711_TestMasterKey128bits().Length());
       
   337     CleanupStack::PushL( masterKey5 );
       
   338     *masterKey5 = KRFC3711_TestMasterKey128bits;
       
   339     
       
   340     HBufC8* masterSalt5 =HBufC8::NewL(KRFC3711_TestMasterSalt112bits().Length());
       
   341     CleanupStack::PushL( masterSalt5);
       
   342 	*masterSalt5 = KRFC3711_TestMasterSalt112bits;
       
   343 
       
   344 	
       
   345 	CSRTPMasterKey* mKey5 = CSRTPMasterKey::NewLC( *masterKey5, _L8("") );
       
   346     CSRTPMasterSalt* mSalt5 = CSRTPMasterSalt::NewLC( *masterSalt5 );
       
   347     
       
   348     //TSrtpCryptoParams params;
       
   349 	CSRTPCryptoContext* context5 = CSRTPCryptoContext::NewL(mKey5, mSalt5, params );
       
   350 	CleanupStack::Pop( mSalt5 );
       
   351     CleanupStack::Pop( mKey5 );
       
   352     CleanupStack::PopAndDestroy( masterSalt5 );
       
   353     CleanupStack::PopAndDestroy( masterKey5 ); 
       
   354     CleanupStack::PushL( context5 );
       
   355     srtpSession->SetCryptoContextL(context5);
       
   356 	CleanupStack::Pop( context5 );
       
   357 	
       
   358 	//Test case 5: Set the context=NULL			
       
   359 	CSRTPCryptoContext* context6=NULL;
       
   360 	EUNIT_ASSERT_SPECIFIC_LEAVE(srtpSession->SetCryptoContextL(context6), KErrArgument);
       
   361 	
       
   362 	CleanupStack::PopAndDestroy( streamOut2 );
       
   363 	CleanupStack::PopAndDestroy( streamIn2 );
       
   364 	CleanupStack::PopAndDestroy( streamOut );
       
   365 	CleanupStack::PopAndDestroy( streamIn );
       
   366 	CleanupStack::PopAndDestroy( srtpSession );
       
   367 	}
       
   368     
       
   369 void UT_CSRTPSession::UT_CSRTPSession_RemoteAddrL()
       
   370 	{
       
   371 	CSRTPSession* srtpSession = CSRTPSession::NewL(iDestination,
       
   372     												iContext,
       
   373     												*this); 
       
   374 	iContext=NULL; // Ownership was transferred
       
   375 	
       
   376 	TInetAddr tempaddr =srtpSession->RemoteAddr();
       
   377 	EUNIT_ASSERT(tempaddr==iDestination);
       
   378 	delete srtpSession;
       
   379 	}
       
   380 	
       
   381 void UT_CSRTPSession::UT_CSRTPSession_StreamLL()
       
   382 	{
       
   383     CSRTPSession* srtpSession = CSRTPSession::NewLC(iDestination,
       
   384     												iContext,
       
   385     												*this); 
       
   386     iContext=NULL; // Ownership was transferred
       
   387     
       
   388     //automatically added stream in the constructor												
       
   389     CSRTPStreamIn* tempStreamIn = CSRTPStreamIn::NewL(*srtpSession, (TUint)1);
       
   390     CleanupStack::PushL( tempStreamIn );
       
   391     
       
   392 	CSRTPStream* stream= &(srtpSession->StreamL(1, ETrue));
       
   393 	EUNIT_ASSERT(stream!=NULL);
       
   394 	EUNIT_ASSERT_SPECIFIC_LEAVE(srtpSession->StreamL(2, ETrue), KErrNotFound);
       
   395 
       
   396     CleanupStack::PopAndDestroy( tempStreamIn );
       
   397     CleanupStack::PopAndDestroy( srtpSession );
       
   398 	
       
   399 	}
       
   400 void UT_CSRTPSession::UT_CSRTPSession_ProtectRTPLL()
       
   401 	{
       
   402 
       
   403     CSRTPSession* srtpSession = CSRTPSession::NewLC(iDestination,
       
   404     												iContext,
       
   405     												*this); 
       
   406     iContext=NULL; // Ownership was transferred
       
   407     
       
   408     //automatically added stream in the constructor												
       
   409     CSRTPStreamOut* tempStreamOut = CSRTPStreamOut::NewL(*srtpSession, (TUint)1);
       
   410     CleanupStack::PushL( tempStreamOut );
       
   411     //will probably panic becasuse packet is not built properly
       
   412 	RTP_EUNIT_ASSERT_SPECIFIC_LEAVE( srtpSession->ProtectRTPL(1, KDummyRTCPPacket()), 
       
   413 							KErrCorrupt)
       
   414 				
       
   415 
       
   416     CleanupStack::PopAndDestroy( tempStreamOut );
       
   417     CleanupStack::PopAndDestroy( srtpSession );	
       
   418 	}
       
   419 
       
   420 void UT_CSRTPSession::UT_CSRTPSession_UnprotectRTPLL()
       
   421 	{
       
   422 
       
   423     CSRTPSession* srtpSession = CSRTPSession::NewLC(iDestination,
       
   424     												iContext,
       
   425     												*this); 
       
   426     iContext=NULL; // Ownership was transferred
       
   427     
       
   428     //automatically added stream in the constructor												
       
   429     CSRTPStreamIn* tempStreamIn = CSRTPStreamIn::NewL(*srtpSession, (TUint)1);
       
   430     CleanupStack::PushL( tempStreamIn );
       
   431     //will probably panic
       
   432 	
       
   433 	RTP_EUNIT_ASSERT_SPECIFIC_LEAVE( srtpSession->UnprotectRTPL(1, KDummyRTCPPacket()), 
       
   434 							KErrCorrupt)
       
   435 	
       
   436 
       
   437     CleanupStack::PopAndDestroy( tempStreamIn );
       
   438     CleanupStack::PopAndDestroy( srtpSession );		
       
   439 	}
       
   440 void UT_CSRTPSession::UT_CSRTPSession_UnprotectRTPL2L()
       
   441 	{
       
   442     CSRTPSession* srtpSession = CSRTPSession::NewLC(iDestination,
       
   443     												iContext,
       
   444     												*this); 
       
   445 
       
   446     iContext=NULL; // Ownership was transferred
       
   447     
       
   448 	CSRTPStreamIn* tempStreamIn2 = CSRTPStreamIn::NewL(*srtpSession, (TUint)0);	
       
   449 	CleanupStack::PushL( tempStreamIn2 );
       
   450 	//will probably panic
       
   451 	    //will probably panic becasuse packet is not built properly
       
   452 	RTP_EUNIT_ASSERT_SPECIFIC_LEAVE( srtpSession->UnprotectRTPL(2, KDummyRTCPPacket()), 
       
   453 							KErrCorrupt)
       
   454 	
       
   455 	
       
   456 
       
   457     CleanupStack::PopAndDestroy( tempStreamIn2 );
       
   458     CleanupStack::PopAndDestroy( srtpSession );			
       
   459 	}	
       
   460 void UT_CSRTPSession::UT_CSRTPSession_ProtectRTCPLL()
       
   461 	{
       
   462 
       
   463     CSRTPSession* srtpSession = CSRTPSession::NewLC(iDestination,
       
   464     												iContext,
       
   465     												*this); 
       
   466     iContext=NULL; // Ownership was transferred
       
   467     
       
   468     //automatically added stream in the constructor												
       
   469     CSRTPStreamOut* tempStreamOut = CSRTPStreamOut::NewL(*srtpSession, (TUint)1);
       
   470     CleanupStack::PushL( tempStreamOut );
       
   471     //will probably panic becasuse packet is not built properly
       
   472 	RTP_EUNIT_ASSERT_SPECIFIC_LEAVE( srtpSession->ProtectRTCPL(1, KDummyRTCPPacket()), 
       
   473 							KErrCorrupt)
       
   474 				
       
   475 
       
   476     CleanupStack::PopAndDestroy( tempStreamOut );
       
   477     CleanupStack::PopAndDestroy( srtpSession );	
       
   478 	}
       
   479 
       
   480 void UT_CSRTPSession::UT_CSRTPSession_UnprotectRTCPLL()
       
   481 	{
       
   482 
       
   483     CSRTPSession* srtpSession = CSRTPSession::NewLC(iDestination,
       
   484     												iContext,
       
   485     												*this); 
       
   486     iContext=NULL; // Ownership was transferred
       
   487     
       
   488     //automatically added stream in the constructor												
       
   489     CSRTPStreamIn* tempStreamIn = CSRTPStreamIn::NewL(*srtpSession, (TUint)1);
       
   490     CleanupStack::PushL( tempStreamIn );
       
   491     //will probably panic
       
   492 	
       
   493 	RTP_EUNIT_ASSERT_SPECIFIC_LEAVE( srtpSession->UnprotectRTCPL(1, KDummyRTCPPacket()), 
       
   494 							KErrCorrupt)
       
   495 	
       
   496 
       
   497     CleanupStack::PopAndDestroy( tempStreamIn );
       
   498     CleanupStack::PopAndDestroy( srtpSession );			
       
   499 	}	
       
   500 
       
   501 void UT_CSRTPSession::UT_CSRTPSession_UnprotectRTCPL2L()
       
   502 	{
       
   503     CSRTPSession* srtpSession = CSRTPSession::NewLC(iDestination,
       
   504     												iContext,
       
   505     												*this); 
       
   506     iContext=NULL; // Ownership was transferred
       
   507     
       
   508 	CSRTPStreamIn* tempStreamIn2 = CSRTPStreamIn::NewL(*srtpSession, (TUint)0);	
       
   509 	CleanupStack::PushL( tempStreamIn2 );
       
   510 	//will probably panic
       
   511 	    //will probably panic becasuse packet is not built properly
       
   512 	RTP_EUNIT_ASSERT_SPECIFIC_LEAVE( srtpSession->UnprotectRTCPL(2, KDummyRTCPPacket()), 
       
   513 							KErrCorrupt)
       
   514 	
       
   515 	
       
   516 
       
   517     CleanupStack::PopAndDestroy( tempStreamIn2 );
       
   518     CleanupStack::PopAndDestroy( srtpSession );				
       
   519 	}		
       
   520 	
       
   521 void UT_CSRTPSession::UT_CSRTPSession_FindStreamL()
       
   522 	{
       
   523     CSRTPSession* srtpSession = CSRTPSession::NewLC(iDestination,
       
   524     												iContext,
       
   525     												*this); 
       
   526     iContext=NULL; // Ownership was transferred
       
   527     
       
   528     //automatically added stream in the constructor												
       
   529     CSRTPStreamIn* tempStreamIn = CSRTPStreamIn::NewL(*srtpSession, (TUint)1);
       
   530     CleanupStack::PushL( tempStreamIn );
       
   531     
       
   532 	EUNIT_ASSERT(srtpSession->FindStream(1, ETrue));
       
   533 	EUNIT_ASSERT(srtpSession->FindStream(22, ETrue)==EFalse);
       
   534 	
       
   535     CleanupStack::PopAndDestroy( tempStreamIn );
       
   536     CleanupStack::PopAndDestroy( srtpSession );		
       
   537 	}
       
   538 	
       
   539 void UT_CSRTPSession::FindLateBindingStreamAndUnprotectRTPLL()
       
   540 	{
       
   541     CSRTPSession* srtpSession = CSRTPSession::NewLC(iDestination,
       
   542     												iContext,
       
   543     												*this); 
       
   544     iContext=NULL; // Ownership was transferred
       
   545     
       
   546     EUNIT_ASSERT_SPECIFIC_LEAVE(srtpSession->
       
   547     	FindLateBindingStreamAndUnprotectRTPL(0,KDummyRTCPPacket()), KErrCorrupt );
       
   548     
       
   549     CSRTPStreamIn* tempStreamIn = 
       
   550     		CSRTPStreamIn::NewL(*srtpSession, (TUint)1);	
       
   551     CleanupStack::PushL( tempStreamIn );
       
   552     tempStreamIn->ChangeRTPState(MSRTPStreamInContext::ESRTPStreamInNormal);
       
   553     
       
   554     EUNIT_ASSERT_SPECIFIC_LEAVE(srtpSession->
       
   555     	FindLateBindingStreamAndUnprotectRTPL(1,KDummyRTCPPacket()), KErrCorrupt );
       
   556     		
       
   557     CleanupStack::PopAndDestroy( tempStreamIn );
       
   558     CleanupStack::PopAndDestroy( srtpSession );		
       
   559 	}	
       
   560 	
       
   561 void UT_CSRTPSession::FindLateBindingStreamAndUnprotectRTCPLL()
       
   562 	{
       
   563     CSRTPSession* srtpSession = CSRTPSession::NewLC(iDestination,
       
   564     												iContext,
       
   565     												*this); 
       
   566     iContext=NULL; // Ownership was transferred
       
   567     
       
   568     EUNIT_ASSERT_SPECIFIC_LEAVE(srtpSession->
       
   569     	FindLateBindingStreamAndUnprotectRTCPL(0,KDummyRTCPPacket()), KErrCorrupt );
       
   570     
       
   571     CSRTPStreamIn* tempStreamIn = 
       
   572     		CSRTPStreamIn::NewL(*srtpSession, (TUint)1);	
       
   573     CleanupStack::PushL( tempStreamIn );
       
   574     
       
   575     tempStreamIn->ChangeRTCPState(MSRTPStreamInContext::ESRTPStreamInNormal);
       
   576     
       
   577     EUNIT_ASSERT_SPECIFIC_LEAVE(srtpSession->
       
   578     	FindLateBindingStreamAndUnprotectRTCPL(1,KDummyRTCPPacket()), KErrCorrupt );
       
   579     
       
   580     //Test: 2
       
   581 	tempStreamIn->ChangeRTCPState(MSRTPStreamInContext::ESRTPStreamInLateBinding);
       
   582 	tempStreamIn->ChangeRTPState(MSRTPStreamInContext::ESRTPStreamInNormal);
       
   583     
       
   584     RTP_EUNIT_ASSERT_SPECIFIC_LEAVE(srtpSession->
       
   585     	FindLateBindingStreamAndUnprotectRTCPL(2,KDummyRTCPPacket()), KErrCorrupt );
       
   586     	
       
   587     	
       
   588 	//Test 2a    	
       
   589 	tempStreamIn->ChangeRTCPState(MSRTPStreamInContext::ESRTPStreamInLateBinding);
       
   590 	tempStreamIn->ChangeRTPState(MSRTPStreamInContext::ESRTPStreamInNormal);
       
   591     
       
   592     RTP_EUNIT_ASSERT_SPECIFIC_LEAVE(srtpSession->
       
   593     	FindLateBindingStreamAndUnprotectRTCPL(1,KDummyRTCPPacket()), KErrCorrupt );
       
   594     
       
   595     CleanupStack::PopAndDestroy( tempStreamIn );
       
   596     	
       
   597 	
       
   598 	//Test 3: Check where there is no InSTream and RTCP Packet is received
       
   599 	
       
   600 	CSRTPStreamOut* streamOut = CSRTPStreamOut::NewL(*srtpSession, (TUint)1);
       
   601 	CleanupStack::PushL( streamOut );
       
   602     
       
   603     RTP_EUNIT_ASSERT_SPECIFIC_LEAVE(srtpSession->
       
   604     	FindLateBindingStreamAndUnprotectRTCPL(1,KDummyRTCPPacket()), KErrCorrupt );
       
   605 
       
   606     CleanupStack::PopAndDestroy( streamOut );		
       
   607     CleanupStack::PopAndDestroy( srtpSession );	
       
   608 	}
       
   609 	
       
   610 void UT_CSRTPSession::UT_CSRTPSession_RemoveAllStreamL()	
       
   611 	{
       
   612 	CSRTPSession* srtpSession = CSRTPSession::NewL(iDestination,
       
   613     												iContext,
       
   614     												*this); 
       
   615     iContext=NULL; // Ownership was transferred
       
   616     
       
   617     srtpSession->RemoveAllStream( );
       
   618     delete srtpSession;												
       
   619 	}
       
   620 
       
   621 //  TEST TABLE
       
   622 
       
   623 EUNIT_BEGIN_TEST_TABLE( 
       
   624     UT_CSRTPSession,
       
   625     "CSRTPSession Class",
       
   626     "UNIT" )
       
   627 
       
   628 EUNIT_TEST(
       
   629     "NewL - test ",
       
   630     "CSRTPSession",
       
   631     "NewL",
       
   632     "FUNCTIONALITY",
       
   633     SetupL, UT_CSRTPSession_NewL_1L, Teardown)
       
   634 
       
   635 EUNIT_TEST(
       
   636     "NewL - test ",
       
   637     "CSRTPSession",
       
   638     "NewL",
       
   639     "FUNCTIONALITY",
       
   640     SetupL, UT_CSRTPSession_NewL_2L, Teardown)
       
   641 EUNIT_TEST(
       
   642     "ConstructL ",
       
   643     "CSRTPSession",
       
   644     "ConstructL",
       
   645     "FUNCTIONALITY",
       
   646     SetupL, UT_CSRTPSession_ConstructLL, Teardown)
       
   647 
       
   648 EUNIT_TEST(
       
   649     "RemoveStream - test ",
       
   650     "CSRTPSession",
       
   651     "RemoveStream",
       
   652     "FUNCTIONALITY",
       
   653     SetupL, UT_CSRTPSession_RemoveStreamL, Teardown)
       
   654 
       
   655 EUNIT_TEST(
       
   656     "GetCryptoContext - test ",
       
   657     "CSRTPSession",
       
   658     "GetCryptoContext",
       
   659     "FUNCTIONALITY",
       
   660     SetupL, UT_CSRTPSession_GetCryptoContextL, Teardown)
       
   661 
       
   662 EUNIT_TEST(
       
   663     "StreamLL ",
       
   664     "CSRTPSession",
       
   665     "StreamLL",
       
   666     "FUNCTIONALITY",
       
   667     SetupL, UT_CSRTPSession_StreamLL, Teardown)
       
   668 
       
   669 EUNIT_TEST(
       
   670     "ProtectRTPLL ",
       
   671     "CSRTPSession",
       
   672     "ProtectRTPLL",
       
   673     "FUNCTIONALITY",
       
   674     SetupL, UT_CSRTPSession_ProtectRTPLL, Teardown)
       
   675 
       
   676 EUNIT_TEST(
       
   677     "unintial UnprotectRTPL",
       
   678     "CSRTPSession",
       
   679     "UnprotectRTPLL",
       
   680     "FUNCTIONALITY",
       
   681     SetupL, UT_CSRTPSession_UnprotectRTPLL, Teardown)
       
   682 
       
   683 EUNIT_TEST(
       
   684     "latebinding UnprotectRTPL ",
       
   685     "CSRTPSession",
       
   686     "UnprotectRTPL",
       
   687     "FUNCTIONALITY",
       
   688     SetupL, UT_CSRTPSession_UnprotectRTPL2L, Teardown)
       
   689     
       
   690 EUNIT_TEST(
       
   691     "ProtectRTCPLL ",
       
   692     "CSRTPSession",
       
   693     "ProtectRTCPLL",
       
   694     "FUNCTIONALITY",
       
   695     SetupL, UT_CSRTPSession_ProtectRTCPLL, Teardown)
       
   696 
       
   697 EUNIT_TEST(
       
   698     "UnprotectRTCPL",
       
   699     "CSRTPSession",
       
   700     "UnprotectRTCPLL",
       
   701     "FUNCTIONALITY",
       
   702     SetupL, UT_CSRTPSession_UnprotectRTCPLL, Teardown)
       
   703 
       
   704 
       
   705 EUNIT_TEST(
       
   706     "FindStreamL - test ",
       
   707     "CSRTPSession",
       
   708     "FindStreamL",
       
   709     "FUNCTIONALITY",
       
   710     SetupL, UT_CSRTPSession_FindStreamL, Teardown)
       
   711 
       
   712 EUNIT_TEST(
       
   713     "FindLateBindingStreamL - test ",
       
   714     "CSRTPSession",
       
   715     "FindStreamL",
       
   716     "FUNCTIONALITY",
       
   717     SetupL, FindLateBindingStreamAndUnprotectRTPLL, Teardown)
       
   718 
       
   719 EUNIT_TEST(
       
   720     "UpdateCryptoContext",
       
   721     "CSRTPSession",
       
   722     "UpdateCryptoContext",
       
   723     "FUNCTIONALITY",
       
   724     SetupL, UT_CSRTPSession_UpdateCryptoContextLL, Teardown)
       
   725     
       
   726 EUNIT_TEST(
       
   727     "RemoteAddr",
       
   728     "CSRTPSession",
       
   729     "RemoteAddr",
       
   730     "FUNCTIONALITY",
       
   731     SetupL, UT_CSRTPSession_RemoteAddrL, Teardown)    
       
   732 
       
   733 EUNIT_TEST(
       
   734     "UnprotectRTCPL2L",
       
   735     "CSRTPSession",
       
   736     "UnprotectRTCPL2L",
       
   737     "FUNCTIONALITY",
       
   738     SetupL, UT_CSRTPSession_UnprotectRTCPL2L, Teardown)    
       
   739     
       
   740 EUNIT_TEST(
       
   741     "FindLBUnprotectRTCPLL",
       
   742     "CSRTPSession",
       
   743     "FindLBUnprotectRTCPLL",
       
   744     "FUNCTIONALITY",
       
   745     SetupL, FindLateBindingStreamAndUnprotectRTCPLL, Teardown)        
       
   746 
       
   747 EUNIT_TEST(
       
   748     "RemoveAllStreamL",
       
   749     "CSRTPSession",
       
   750     "RemoveAllStreamL",
       
   751     "FUNCTIONALITY",
       
   752     SetupL, UT_CSRTPSession_RemoveAllStreamL, Teardown)        
       
   753 
       
   754 EUNIT_TEST(
       
   755     "UpdateCryptoContextLL",
       
   756     "CSRTPSession",
       
   757     "UpdateCryptoContextLL",
       
   758     "FUNCTIONALITY",
       
   759     SetupL, UT_CSRTPSession_UpdateCryptoContextLL, Teardown)        
       
   760 
       
   761 
       
   762 EUNIT_END_TEST_TABLE
       
   763 
       
   764 //  END OF FILE