multimediacommsengine/mmcesrv/mmceserver/tsrc/ut_server/src/UT_CMceNatStateIdle.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     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 
       
    21 //  CLASS HEADER
       
    22 #include "UT_CMceNatStateIdle.h"
       
    23 
       
    24 //  EXTERNAL INCLUDES
       
    25 #include <digia/eunit/eunitmacros.h>
       
    26 
       
    27 
       
    28 //  INTERNAL INCLUDES
       
    29 #include "mcetesthelper.h"
       
    30 #include "mceservercore.h"
       
    31 #include "cmcetls.h"
       
    32 #include "mceactionset.h"
       
    33 #include "mcecssession.h"
       
    34 #include "mcecssessionimplementation.h"
       
    35 #include "mcenatsipsession.h"
       
    36 #include "mcenatsipstatemachine.h"
       
    37 #include "mcemediamanager.h"
       
    38 #include "../inc/mcenatpluginmanager.h"
       
    39 #include "nspplugin.h"
       
    40 
       
    41 
       
    42 _LIT8( KIceOffer,
       
    43 "v=0\r\n\
       
    44 o=alice 2890844526 2890844527 IN IP4 131.117.0.4\r\n\
       
    45 s=-\r\n\
       
    46 c=IN IP4 192.0.0.19\r\n\
       
    47 t=0 0\r\n\
       
    48 a=ice-ufrag:xStE\r\n\
       
    49 a=ice-pwd:ermyyyErTTeseEWWtr\r\n\
       
    50 m=audio 6231 RTP/AVP 96\r\n\
       
    51 a=candidate:1 1 UDP 11435664 192.0.0.19 4356 typ srflx\r\n\
       
    52 a=candidate:1 2 UDP 10435664 192.0.0.19 5333 typ srflx\r\n\
       
    53 a=rtpmap:96 AMR/8000\r\n\
       
    54 a=rtcp:6232 IN IP4 192.0.0.19\r\n" );
       
    55 
       
    56 
       
    57 // CONSTRUCTION
       
    58 UT_CMceNatStateIdle* UT_CMceNatStateIdle::NewL()
       
    59     {
       
    60     UT_CMceNatStateIdle* self =
       
    61     	UT_CMceNatStateIdle::NewLC();
       
    62     CleanupStack::Pop();
       
    63     return self;
       
    64     }
       
    65 
       
    66 UT_CMceNatStateIdle* UT_CMceNatStateIdle::NewLC()
       
    67     {
       
    68     UT_CMceNatStateIdle* self =
       
    69     	new ( ELeave ) UT_CMceNatStateIdle();
       
    70     CleanupStack::PushL( self );
       
    71 	self->ConstructL();
       
    72     return self;
       
    73     }
       
    74 
       
    75 // Destructor (virtual by CBase)
       
    76 UT_CMceNatStateIdle::~UT_CMceNatStateIdle()
       
    77     {
       
    78     }
       
    79 
       
    80 // Default constructor
       
    81 UT_CMceNatStateIdle::UT_CMceNatStateIdle()
       
    82     {
       
    83     }
       
    84 
       
    85 // Second phase construct
       
    86 void UT_CMceNatStateIdle::ConstructL()
       
    87     {
       
    88     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
    89     // It generates the test case table.
       
    90     CEUnitTestSuiteClass::ConstructL();
       
    91     }
       
    92 
       
    93 //  METHODS
       
    94 
       
    95 void UT_CMceNatStateIdle::SetupL()
       
    96     {
       
    97     CMCETls::OpenL();
       
    98     SdpCodecStringPool::OpenL();
       
    99 	
       
   100 	iIds.iAppUID = 10;
       
   101     iIds.iProfileID = 1;
       
   102     iIds.iManagerType = KMceCSSIPSession;
       
   103     iIds.iDialogType = KMceDlgTypeInvite;
       
   104     iServerCore = CMceServerCore::NewL();
       
   105     
       
   106     iStorage = CMCETls::Storage();
       
   107     
       
   108     iNatSessionId = 3;
       
   109     iServerCore->Manager().MediaManager().NatPluginManager().iEnabled = ETrue;    
       
   110     
       
   111 	CDesC8ArrayFlat* params = new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity );
       
   112 	CleanupStack::PushL( params );
       
   113 	params->AppendL( _L8("User <user2@host>") );
       
   114 	params->AppendL( _L8("User <user@host>") );
       
   115     
       
   116     CMceMsgTextArray* msgParams = new (ELeave) CMceMsgTextArray( *params );
       
   117     CleanupStack::PushL( msgParams );
       
   118     iStorage->StoreL( iIds, *msgParams );
       
   119     CleanupStack::PopAndDestroy( msgParams );
       
   120     CleanupStack::PopAndDestroy( params );
       
   121 
       
   122     iSession = CMceCsSession::NewL(*iServerCore);
       
   123     iSession->CreateSubSessionL(iIds, RMessage2());
       
   124     iSipSession = static_cast<CMceSipSession*>
       
   125 	   	((iSession->Implementation().SubSessions())[0]); 
       
   126 	
       
   127 	CMceSipManager& manager = iServerCore->Manager();
       
   128     CSIPProfile& profile = manager.ProfileL( iIds.iProfileID );
       
   129 	
       
   130 	iNatSession = CMceNatSipSession::NewL( *iSession,
       
   131 										iSipSession->SIPConnection(),
       
   132 										*iSipSession->iStateMachine,
       
   133 										profile,
       
   134 										NULL );
       
   135 	iNatSession->iNatStateMachine->iCurrentState = KMceNatStateIdle;
       
   136     iState = iNatSession->iNatStateMachine->iStates[
       
   137     	iNatSession->iNatStateMachine->iCurrentState ];    	
       
   138     		   	
       
   139     }
       
   140 
       
   141 void UT_CMceNatStateIdle::Teardown()
       
   142     {
       
   143     CMCETls::Close();
       
   144 	delete iSession;
       
   145 	iSession = NULL;
       
   146 	delete iNatSession;
       
   147 	iNatSession = NULL;
       
   148     delete iServerCore;
       
   149     iServerCore = NULL;
       
   150 
       
   151     SdpCodecStringPool::Close();
       
   152     }
       
   153 
       
   154 void UT_CMceNatStateIdle::
       
   155 	UT_CMceNatStateIdle_AcceptLL()
       
   156     {
       
   157     EUNIT_ASSERT( DoesAccept( EMceNatUpdated ) );
       
   158     EUNIT_ASSERT( DoesAccept( EMceNatError ) );
       
   159     EUNIT_ASSERT( DoesAccept( EMceNatICMPError ) );
       
   160     
       
   161     EUNIT_ASSERT( !DoesAccept( EMceNatInitialized ) );
       
   162     EUNIT_ASSERT( !DoesAccept( EMceNatOffer ) );
       
   163     EUNIT_ASSERT( !DoesAccept( EMceNatAnswer ) );
       
   164     EUNIT_ASSERT( !DoesAccept( EMceNatHandleSIP ) );
       
   165     EUNIT_ASSERT( !DoesAccept( EMceNatSync ) );
       
   166     
       
   167     }
       
   168 
       
   169 void UT_CMceNatStateIdle::
       
   170 	UT_CMceNatStateIdle_EntryLL()
       
   171     {
       
   172 	// TBD    
       
   173 	}
       
   174     
       
   175 
       
   176 void UT_CMceNatStateIdle::
       
   177 	UT_CMceNatStateIdle_ExitLL()
       
   178 	{
       
   179 	// NAT Error Occured
       
   180 	iNatSession->iBody = CMceComSession::NewL( CMceComSession::EOutSession );
       
   181     TMceNatEventCode eventcode = EMceNatError;
       
   182 	iNatSession->iNatDisabled = EFalse;
       
   183 	iNatSession->iEntryPoint = CMceNatSipSession::ENatEntryUpdated;
       
   184     
       
   185 	TMceNatStateTransitionEvent event( NULL,*iNatSession,eventcode,
       
   186     								   *iNatSession, EMceInvite );
       
   187    	   	
       
   188    	EUNIT_ASSERT_LEAVE( iState->TransitionHandler().ExitL( event ));
       
   189    
       
   190           
       
   191     // NAT ICMP IGnored
       
   192     iNatSession->iNatDisabled = EFalse;
       
   193     eventcode = EMceNatICMPError;
       
   194     TMceNatStateTransitionEvent event1( NULL, *iNatSession,eventcode,
       
   195     								   *iNatSession, EMceInvite );
       
   196     EUNIT_ASSERT_NO_LEAVE( iState->TransitionHandler().ExitL( event1 ));
       
   197         
       
   198     
       
   199     // NAT ICMP Handled i.e MCE State is Established
       
   200     iNatSession->iNatDisabled = EFalse;
       
   201     eventcode = EMceNatICMPError;
       
   202     iNatSession->NextState( KMceStateEstablished ); 
       
   203 	TMceNatStateTransitionEvent event2( NULL, *iNatSession,eventcode,
       
   204     								   *iNatSession, EMceInvite );
       
   205     EUNIT_ASSERT_LEAVE( iState->TransitionHandler().ExitL( event2 ));
       
   206 
       
   207 	}
       
   208 	
       
   209 void UT_CMceNatStateIdle::
       
   210 	UT_CMceNatStateIdle_Exit2LL()
       
   211 	
       
   212 	{
       
   213 	// Exit Default (MO)
       
   214 	iNatSession->iBody = CMceComSession::NewL( CMceComSession::EOutSession );
       
   215     
       
   216     TMceIds ids;
       
   217     CMceMsgBase* msg = NULL;
       
   218   	iNatSession->iType = CMceCsSubSession::EOutSession; // make this MT case
       
   219    	
       
   220    	TMceNatEventCode eventcode = EMceNatUpdated;
       
   221    	
       
   222 	iNatSession->iNatDisabled = EFalse;
       
   223     TMceNatStateTransitionEvent event1( NULL, *iNatSession,eventcode,
       
   224     								   *iNatSession, EMceInvite );
       
   225     MCE_EUNIT_ASSERT_NO_LEAVE( iState->TransitionHandler().ExitL( event1 ));
       
   226 		
       
   227 	EUNIT_ASSERT( KMceNatStateWait ==
       
   228                   iNatSession->iNatStateMachine->iCurrentState );
       
   229 	}
       
   230 	
       
   231 	
       
   232 void UT_CMceNatStateIdle::
       
   233 	UT_CMceNatStateIdle_Exit2_1LL()
       
   234 	{
       
   235 	// Pull mode Exit Default (MT)
       
   236 	
       
   237 	iNatSession->iBody = CMceComSession::NewL( CMceComSession::EInSession );
       
   238     
       
   239     TMceIds ids;
       
   240     CMceMsgBase* msg = NULL;
       
   241   
       
   242     CSIPServerTransaction* trx = 
       
   243         MCETestHelper::ServerTransactionL( SipStrConsts::EInvite, EFalse );
       
   244     CleanupStack::PushL(trx);
       
   245     EUNIT_ASSERT( &iNatSession->Request() == NULL );
       
   246     iNatSession->iPendingReceivedRequests.AppendL( trx );
       
   247     CleanupStack::Pop(trx);
       
   248     EUNIT_ASSERT( &iNatSession->Request() == trx );
       
   249         
       
   250     iNatSession->iType = CMceCsSubSession::EInSession; // make this MT case
       
   251    	
       
   252    	TMceNatEventCode eventcode = EMceNatUpdated;
       
   253    	
       
   254 	iNatSession->iNatDisabled = EFalse;
       
   255     TMceNatStateTransitionEvent event1( NULL, *iNatSession,eventcode,
       
   256     								   *iNatSession, EMceInvite );
       
   257     MCE_EUNIT_ASSERT_NO_LEAVE( iState->TransitionHandler().ExitL( event1 ));
       
   258 		
       
   259 	EUNIT_ASSERT( KMceNatStateWait ==
       
   260                   iNatSession->iNatStateMachine->iCurrentState );
       
   261                                 
       
   262     	
       
   263 	}	
       
   264 		
       
   265 	
       
   266 TBool
       
   267 UT_CMceNatStateIdle::DoesAccept( TMceNatEventCode aEventCode )
       
   268     {
       
   269     TMceNatStateTransitionEvent event( NULL,
       
   270     								   *iNatSession,
       
   271     								   aEventCode,
       
   272     								   *iNatSession,
       
   273     								   EMceInvite );
       
   274     return iState->Accept( event );
       
   275     }			
       
   276 
       
   277     
       
   278 //  TEST TABLE
       
   279 
       
   280 EUNIT_BEGIN_TEST_TABLE( 
       
   281     UT_CMceNatStateIdle,
       
   282     "UT_CMceNatStateIdle",
       
   283     "UNIT" )
       
   284 
       
   285 EUNIT_TEST(
       
   286     "DoAcceptL - test ",
       
   287     "CMceNatStateIdle",
       
   288     "AcceptL",
       
   289     "FUNCTIONALITY",
       
   290     SetupL, UT_CMceNatStateIdle_AcceptLL, Teardown)
       
   291 
       
   292 EUNIT_TEST(
       
   293     "EntryL - test ",
       
   294     "CMceNatStateIdle",
       
   295     "EntryL",
       
   296     "FUNCTIONALITY",
       
   297     SetupL, UT_CMceNatStateIdle_EntryLL, Teardown)
       
   298 
       
   299 EUNIT_TEST(
       
   300     "ExitL - test ",
       
   301     "CMceNatStateIdle",
       
   302     "ExitL",
       
   303     "FUNCTIONALITY",
       
   304     SetupL, UT_CMceNatStateIdle_ExitLL, Teardown)
       
   305     
       
   306 EUNIT_TEST(
       
   307     "ExitL Default- test ",
       
   308     "CMceNatStateIdle",
       
   309     "ExitL",
       
   310     "FUNCTIONALITY",
       
   311     SetupL, UT_CMceNatStateIdle_Exit2LL, Teardown)
       
   312     
       
   313 EUNIT_TEST(
       
   314     "ExitL Default Pull Mode - test ",
       
   315     "CMceNatStateIdle",
       
   316     "ExitL",
       
   317     "FUNCTIONALITY",
       
   318     SetupL, UT_CMceNatStateIdle_Exit2_1LL, Teardown)
       
   319     
       
   320          
       
   321 
       
   322 EUNIT_END_TEST_TABLE
       
   323 
       
   324 //  END OF FILE