multimediacommsengine/mmcesrv/mmceserver/tsrc/ut_server/src/UT_CMceNatStateCreateOffer.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_CMceNatStateCreateOffer.h"
       
    23 
       
    24 //  EXTERNAL INCLUDES
       
    25 #include <digia/eunit/eunitmacros.h>
       
    26 
       
    27 //  INTERNAL INCLUDES
       
    28 #include "mcetesthelper.h"
       
    29 #include "mceservercore.h"
       
    30 #include "cmcetls.h"
       
    31 #include "mceactionset.h"
       
    32 #include "mcecssession.h"
       
    33 #include "mcecssessionimplementation.h"
       
    34 #include "mcenatsipsession.h"
       
    35 #include "mcenatsipstatemachine.h"
       
    36 #include "mcemediamanager.h"
       
    37 #include "../inc/mcenatpluginmanager.h"
       
    38 #include "nspplugin.h"
       
    39 
       
    40 
       
    41 _LIT8( KIceOffer,
       
    42 "v=0\r\n\
       
    43 o=alice 2890844526 2890844527 IN IP4 131.117.0.4\r\n\
       
    44 s=-\r\n\
       
    45 c=IN IP4 192.0.0.19\r\n\
       
    46 t=0 0\r\n\
       
    47 a=ice-ufrag:xStE\r\n\
       
    48 a=ice-pwd:ermyyyErTTeseEWWtr\r\n\
       
    49 m=audio 6231 RTP/AVP 96\r\n\
       
    50 a=candidate:1 1 UDP 11435664 192.0.0.19 4356 typ srflx\r\n\
       
    51 a=candidate:1 2 UDP 10435664 192.0.0.19 5333 typ srflx\r\n\
       
    52 a=rtpmap:96 AMR/8000\r\n\
       
    53 a=rtcp:6232 IN IP4 192.0.0.19\r\n" );
       
    54 
       
    55 
       
    56 // CONSTRUCTION
       
    57 UT_CMceNatStateCreateOffer* UT_CMceNatStateCreateOffer::NewL()
       
    58     {
       
    59     UT_CMceNatStateCreateOffer* self =
       
    60     	UT_CMceNatStateCreateOffer::NewLC();
       
    61     CleanupStack::Pop();
       
    62     return self;
       
    63     }
       
    64 
       
    65 UT_CMceNatStateCreateOffer* UT_CMceNatStateCreateOffer::NewLC()
       
    66     {
       
    67     UT_CMceNatStateCreateOffer* self =
       
    68     	new ( ELeave ) UT_CMceNatStateCreateOffer();
       
    69     CleanupStack::PushL( self );
       
    70 	self->ConstructL();
       
    71     return self;
       
    72     }
       
    73 
       
    74 // Destructor (virtual by CBase)
       
    75 UT_CMceNatStateCreateOffer::~UT_CMceNatStateCreateOffer()
       
    76     {
       
    77     }
       
    78 
       
    79 // Default constructor
       
    80 UT_CMceNatStateCreateOffer::UT_CMceNatStateCreateOffer()
       
    81     {
       
    82     }
       
    83 
       
    84 // Second phase construct
       
    85 void UT_CMceNatStateCreateOffer::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     
       
    92  
       
    93 
       
    94 //  METHODS
       
    95 
       
    96 void UT_CMceNatStateCreateOffer::SetupL()
       
    97     {
       
    98     CMCETls::OpenL();
       
    99     SdpCodecStringPool::OpenL();
       
   100 	
       
   101 	iIds.iAppUID = 10;
       
   102     iIds.iProfileID = 1;
       
   103     iIds.iManagerType = KMceCSSIPSession;
       
   104     iIds.iDialogType = KMceDlgTypeInvite;
       
   105     iServerCore = CMceServerCore::NewL();
       
   106     
       
   107     iStorage = CMCETls::Storage();
       
   108     
       
   109     iNatSessionId = 3;
       
   110     iServerCore->Manager().MediaManager().NatPluginManager().iEnabled = ETrue;    
       
   111     
       
   112 	CDesC8ArrayFlat* params = new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity );
       
   113 	CleanupStack::PushL( params );
       
   114 	params->AppendL( _L8("User <user2@host>") );
       
   115 	params->AppendL( _L8("User <user@host>") );
       
   116     
       
   117     CMceMsgTextArray* msgParams = new (ELeave) CMceMsgTextArray( *params );
       
   118     CleanupStack::PushL( msgParams );
       
   119     iStorage->StoreL( iIds, *msgParams );
       
   120     CleanupStack::PopAndDestroy( msgParams );
       
   121     CleanupStack::PopAndDestroy( params );
       
   122 
       
   123     iSession = CMceCsSession::NewL(*iServerCore);
       
   124     iSession->CreateSubSessionL(iIds, RMessage2());
       
   125     iSipSession = static_cast<CMceSipSession*>
       
   126 	   	((iSession->Implementation().SubSessions())[0]);    
       
   127 	
       
   128 	CMceSipManager& manager = iServerCore->Manager();
       
   129     CSIPProfile& profile = manager.ProfileL( iIds.iProfileID );
       
   130 	
       
   131 	iNatSession = CMceNatSipSession::NewL( *iSession,
       
   132 		iSipSession->SIPConnection(),
       
   133 		*iSipSession->iStateMachine,
       
   134 		profile,
       
   135 		NULL );
       
   136 	iNatSession->iNatStateMachine->iCurrentState = KMceNatStateCreateOffer;
       
   137     iState = iNatSession->iNatStateMachine->iStates[
       
   138     	iNatSession->iNatStateMachine->iCurrentState ]; 	   	
       
   139         
       
   140     }
       
   141 
       
   142 void UT_CMceNatStateCreateOffer::Teardown()
       
   143     {
       
   144     CMCETls::Close();
       
   145 	delete iSession;
       
   146 	iSession = NULL;
       
   147 	delete iNatSession;
       
   148 	iNatSession = NULL;
       
   149     delete iServerCore;
       
   150     iServerCore = NULL;
       
   151 
       
   152     SdpCodecStringPool::Close();
       
   153     }
       
   154 
       
   155 void UT_CMceNatStateCreateOffer::
       
   156 	UT_CMceNatStateCreateOffer_AcceptLL()
       
   157     {
       
   158     EUNIT_ASSERT( DoesAccept( EMceNatOffer ) );
       
   159     EUNIT_ASSERT( DoesAccept( EMceNatError ) );
       
   160     EUNIT_ASSERT( DoesAccept( EMceNatICMPError ) );
       
   161     
       
   162     EUNIT_ASSERT( !DoesAccept( EMceNatInitialized ) );
       
   163     EUNIT_ASSERT( !DoesAccept( EMceNatUpdated ) );
       
   164     EUNIT_ASSERT( !DoesAccept( EMceNatUpdateSdp ) );
       
   165     EUNIT_ASSERT( !DoesAccept( EMceNatSync ) );
       
   166     EUNIT_ASSERT( !DoesAccept( EMceNatAnswer ) );
       
   167     EUNIT_ASSERT( !DoesAccept( EMceNatUpdated ) );
       
   168     }
       
   169 
       
   170 void UT_CMceNatStateCreateOffer::
       
   171 	UT_CMceNatStateCreateOffer_EntryLL()
       
   172     {
       
   173     
       
   174  	iNatSession->SetOffer( CSdpDocument::DecodeL( KIceOffer() ) );
       
   175    	iNatSession->iBody = CMceComSession::NewL( CMceComSession::EOutSession );
       
   176     
       
   177     TMceNatEventCode eventcode = EMceNatOffer;
       
   178 	iNatSession->iNatDisabled = EFalse;
       
   179 	iNatSession->iEntryPoint = CMceNatSipSession::ENatEntryUpdated;
       
   180     
       
   181 	TMceNatStateTransitionEvent event( NULL,*iNatSession,eventcode,
       
   182     								   *iNatSession, EMceInvite );
       
   183    	    
       
   184     iState->TransitionHandler().EntryL( event );
       
   185     
       
   186     EUNIT_ASSERT( KMceNatStateWait ==
       
   187                   iNatSession->iNatStateMachine->iCurrentState );
       
   188 	EUNIT_ASSERT( !iNatSession->iNatDisabled );                  
       
   189 	   
       
   190        
       
   191     }
       
   192     
       
   193 
       
   194 void UT_CMceNatStateCreateOffer::
       
   195 	UT_CMceNatStateCreateOffer_ExitLL()
       
   196 	{
       
   197 	
       
   198 	// NAT Error Occured
       
   199 	iNatSession->iBody = CMceComSession::NewL( CMceComSession::EOutSession );
       
   200     TMceNatEventCode eventcode = EMceNatError;
       
   201 	iNatSession->iNatDisabled = EFalse;
       
   202 	iNatSession->iEntryPoint = CMceNatSipSession::ENatEntryUpdated;
       
   203     
       
   204 	TMceNatStateTransitionEvent event( NULL,*iNatSession,eventcode,
       
   205     								   *iNatSession, EMceInvite );
       
   206    	EUNIT_ASSERT_LEAVE( iState->TransitionHandler().ExitL( event ));
       
   207              
       
   208     // NAT ICMP IGnored
       
   209     iNatSession->iNatDisabled = EFalse;
       
   210     eventcode = EMceNatICMPError;
       
   211     TMceNatStateTransitionEvent event1( NULL, *iNatSession,eventcode,
       
   212     								   *iNatSession, EMceInvite );
       
   213     EUNIT_ASSERT_NO_LEAVE( iState->TransitionHandler().ExitL( event1 ));
       
   214         
       
   215     // NAT ICMP Handled i.e MCE State is Established
       
   216     iNatSession->iNatDisabled = EFalse;
       
   217     eventcode = EMceNatICMPError;
       
   218     iNatSession->NextState( KMceStateEstablished ); 
       
   219 	TMceNatStateTransitionEvent event2( NULL, *iNatSession,eventcode,
       
   220     								   *iNatSession, EMceInvite );
       
   221     EUNIT_ASSERT_LEAVE( iState->TransitionHandler().ExitL( event2 ));
       
   222    
       
   223 	}
       
   224 
       
   225 TBool
       
   226 UT_CMceNatStateCreateOffer::DoesAccept( TMceNatEventCode aEventCode )
       
   227     {
       
   228     TMceNatStateTransitionEvent event( NULL,
       
   229     								   *iNatSession,
       
   230     								   aEventCode,
       
   231     								   *iNatSession,
       
   232     								   EMceInvite );
       
   233     return iState->Accept( event );
       
   234     }			
       
   235 
       
   236     
       
   237 //  TEST TABLE
       
   238 
       
   239 EUNIT_BEGIN_TEST_TABLE( 
       
   240     UT_CMceNatStateCreateOffer,
       
   241     "UT_CMceNatStateCreateOffer",
       
   242     "UNIT" )
       
   243 
       
   244 EUNIT_TEST(
       
   245     "DoAcceptL - test ",
       
   246     "CMceNatStateCreateOffer",
       
   247     "AcceptL",
       
   248     "FUNCTIONALITY",
       
   249     SetupL, UT_CMceNatStateCreateOffer_AcceptLL, Teardown)
       
   250 
       
   251 EUNIT_TEST(
       
   252     "EntryL - test ",
       
   253     "CMceNatStateCreateOffer",
       
   254     "EntryL",
       
   255     "FUNCTIONALITY",
       
   256     SetupL, UT_CMceNatStateCreateOffer_EntryLL, Teardown)
       
   257 
       
   258 EUNIT_TEST(
       
   259     "ExitL - test ",
       
   260     "CMceNatStateCreateOffer",
       
   261     "ExitL",
       
   262     "FUNCTIONALITY",
       
   263     SetupL, UT_CMceNatStateCreateOffer_ExitLL, Teardown)
       
   264    
       
   265 
       
   266 EUNIT_END_TEST_TABLE
       
   267 
       
   268 //  END OF FILE
       
   269