multimediacommsengine/mmcesrv/mmceserver/tsrc/ut_server/src/UT_CMceNatStateDecodeAnswer.cpp
changeset 0 1bce908db942
child 3 513a8b745b2f
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_CMceNatStateDecodeAnswer.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 _LIT8( KIceAnswer,
       
    42 "v=0\r\n\
       
    43 o=alice 2890844526 2890844527 IN IP4 192.168.0.12\r\n\
       
    44 s=-\r\n\
       
    45 c=IN IP4 172.0.0.19\r\n\
       
    46 t=0 0\r\n\
       
    47 a=ice-ufrag:xStB\r\n\
       
    48 a=ice-pwd:ermyyyErRReseEWWtr\r\n\
       
    49 m=audio 9345 RTP/AVP 96\r\n\
       
    50 a=candidate:1 1 UDP 11435664 172.0.0.19 5356 typ srflx\r\n\
       
    51 a=candidate:1 2 UDP 10435664 172.0.0.19 6333 typ srflx\r\n\
       
    52 a=rtpmap:96 AMR/8000\r\n\
       
    53 a=rtcp:7232 IN IP4 172.0.0.19\r\n" );
       
    54 
       
    55 
       
    56 
       
    57 // CONSTRUCTION
       
    58 UT_CMceNatStateDecodeAnswer* UT_CMceNatStateDecodeAnswer::NewL()
       
    59     {
       
    60     UT_CMceNatStateDecodeAnswer* self =
       
    61     	UT_CMceNatStateDecodeAnswer::NewLC();
       
    62     CleanupStack::Pop();
       
    63     return self;
       
    64     }
       
    65 
       
    66 UT_CMceNatStateDecodeAnswer* UT_CMceNatStateDecodeAnswer::NewLC()
       
    67     {
       
    68     UT_CMceNatStateDecodeAnswer* self =
       
    69     	new ( ELeave ) UT_CMceNatStateDecodeAnswer();
       
    70     CleanupStack::PushL( self );
       
    71 	self->ConstructL();
       
    72     return self;
       
    73     }
       
    74 
       
    75 // Destructor (virtual by CBase)
       
    76 UT_CMceNatStateDecodeAnswer::~UT_CMceNatStateDecodeAnswer()
       
    77     {
       
    78     }
       
    79 
       
    80 // Default constructor
       
    81 UT_CMceNatStateDecodeAnswer::UT_CMceNatStateDecodeAnswer()
       
    82     {
       
    83     }
       
    84 
       
    85 // Second phase construct
       
    86 void UT_CMceNatStateDecodeAnswer::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_CMceNatStateDecodeAnswer::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 = KMceNatStateDecodeAnswer;
       
   136     iState = iNatSession->iNatStateMachine->iStates[
       
   137     							iNatSession->iNatStateMachine->iCurrentState ]; 	  	   	
       
   138     }
       
   139 
       
   140 void UT_CMceNatStateDecodeAnswer::Teardown()
       
   141     {
       
   142     CMCETls::Close();
       
   143 	delete iSession;
       
   144 	iSession = NULL;
       
   145 	delete iNatSession;
       
   146 	iNatSession = NULL;
       
   147     delete iServerCore;
       
   148     iServerCore = NULL;
       
   149 
       
   150     SdpCodecStringPool::Close();
       
   151     }
       
   152 
       
   153 void UT_CMceNatStateDecodeAnswer::
       
   154 	UT_CMceNatStateDecodeAnswer_AcceptLL()
       
   155     {
       
   156     EUNIT_ASSERT( DoesAccept( EMceNatAnswer ) );
       
   157     EUNIT_ASSERT( DoesAccept( EMceNatError ) );
       
   158     EUNIT_ASSERT( DoesAccept( EMceNatICMPError ) );
       
   159            
       
   160     EUNIT_ASSERT( !DoesAccept( EMceNatInitialized ) );
       
   161     EUNIT_ASSERT( !DoesAccept( EMceNatUpdateSdp ) );
       
   162     EUNIT_ASSERT( !DoesAccept( EMceNatOffer ) );
       
   163     EUNIT_ASSERT( !DoesAccept( EMceNatHandleSIP ) );
       
   164     EUNIT_ASSERT( !DoesAccept( EMceNatUpdated ) );
       
   165     EUNIT_ASSERT( !DoesAccept( EMceNatSync ) );
       
   166        
       
   167     }
       
   168 
       
   169 void UT_CMceNatStateDecodeAnswer::
       
   170 	UT_CMceNatStateDecodeAnswer_EntryLL()
       
   171     {
       
   172     iNatSession->iBody = CMceComSession::NewL( CMceComSession::EOutSession );
       
   173     iNatSession->iEntryPoint = CMceNatSipSession::ENatEntryUpdated;
       
   174     iNatSession->iNatStateMachine->iCurrentState = KMceNatStateDecodeAnswer;
       
   175     iNatSession->AnswerReady( iNatSessionId, CSdpDocument::DecodeL( KIceAnswer() ) );
       
   176    
       
   177    
       
   178     EUNIT_ASSERT( KMceNatStateConnected ==
       
   179                   iNatSession->iNatStateMachine->iCurrentState );
       
   180     EUNIT_ASSERT( !iNatSession->iNatDisabled );
       
   181           
       
   182     }
       
   183     
       
   184 	
       
   185 void UT_CMceNatStateDecodeAnswer::
       
   186 	UT_CMceNatStateDecodeAnswer_ExitLL()
       
   187 	{
       
   188 	// NAT Error Occured
       
   189 	iNatSession->iBody = CMceComSession::NewL( CMceComSession::EOutSession );
       
   190     TMceNatEventCode eventcode = EMceNatError;
       
   191 	iNatSession->iNatDisabled = EFalse;
       
   192 	iNatSession->iEntryPoint = CMceNatSipSession::ENatEntryUpdated;
       
   193     
       
   194 	TMceNatStateTransitionEvent event( NULL,*iNatSession,eventcode,
       
   195     								   *iNatSession, EMceInvite );
       
   196    	   	
       
   197    	EUNIT_ASSERT_LEAVE( iState->TransitionHandler().ExitL( event ));
       
   198    
       
   199           
       
   200     // NAT ICMP IGnored
       
   201     iNatSession->iNatDisabled = EFalse;
       
   202     eventcode = EMceNatICMPError;
       
   203     TMceNatStateTransitionEvent event1( NULL, *iNatSession,eventcode,
       
   204     								   *iNatSession, EMceInvite );
       
   205     EUNIT_ASSERT_NO_LEAVE( iState->TransitionHandler().ExitL( event1 ));
       
   206         
       
   207     
       
   208     // NAT ICMP Handled i.e MCE State is Established
       
   209     iNatSession->iNatDisabled = EFalse;
       
   210     eventcode = EMceNatICMPError;
       
   211     iNatSession->NextState( KMceStateEstablished ); 
       
   212 	TMceNatStateTransitionEvent event2( NULL, *iNatSession,eventcode,
       
   213     								   *iNatSession, EMceInvite );
       
   214     EUNIT_ASSERT_LEAVE( iState->TransitionHandler().ExitL( event2 ));
       
   215 
       
   216 
       
   217 	}
       
   218 	
       
   219 TBool
       
   220 UT_CMceNatStateDecodeAnswer::DoesAccept( TMceNatEventCode aEventCode, 
       
   221 											TMceSipEventCode aSIPCode )
       
   222     {
       
   223     TMceNatStateTransitionEvent event( NULL,
       
   224     								   *iNatSession,
       
   225     								   aEventCode,
       
   226     								   *iNatSession,
       
   227     								   aSIPCode );
       
   228     return iState->Accept( event );
       
   229     }		
       
   230 
       
   231 //  TEST TABLE
       
   232 
       
   233 EUNIT_BEGIN_TEST_TABLE( 
       
   234     UT_CMceNatStateDecodeAnswer,
       
   235     "UT_CMceNatStateDecodeAnswer",
       
   236     "UNIT" )
       
   237 
       
   238 EUNIT_TEST(
       
   239     "DoAcceptL - test ",
       
   240     "CMceNatStateDecodeAnswer",
       
   241     "AcceptL",
       
   242     "FUNCTIONALITY",
       
   243     SetupL, UT_CMceNatStateDecodeAnswer_AcceptLL, Teardown)
       
   244 
       
   245 EUNIT_TEST(
       
   246     "EntryL - test ",
       
   247     "CMceNatStateDecodeAnswer",
       
   248     "EntryL",
       
   249     "FUNCTIONALITY",
       
   250     SetupL, UT_CMceNatStateDecodeAnswer_EntryLL, Teardown)
       
   251 
       
   252 EUNIT_TEST(
       
   253     "ExitL - test ",
       
   254     "CMceNatStateDecodeAnswer",
       
   255     "ExitL",
       
   256     "FUNCTIONALITY",
       
   257     SetupL, UT_CMceNatStateDecodeAnswer_ExitLL, Teardown)
       
   258     
       
   259 
       
   260 EUNIT_END_TEST_TABLE
       
   261 
       
   262 //  END OF FILE
       
   263