multimediacommsengine/mmcesrv/mmceserver/tsrc/ut_server/src/UT_CMCENatStateCreateOfferRequested.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_cmcenatstatecreateofferrequested.h"
       
    23 
       
    24 //  EXTERNAL INCLUDES
       
    25 #include <digia/eunit/eunitmacros.h>
       
    26 
       
    27 
       
    28 //  INTERNAL INCLUDES
       
    29 #include "MCETestHelper.h"
       
    30 
       
    31 //#include "mcesipsession.h"
       
    32 #include "mcenatsipsession.h"
       
    33 #include "mceservercore.h"
       
    34 #include "mcecssession.h"
       
    35 #include "mcecssessionimplementation.h"
       
    36 #include "mcenatstatecreateofferrequested.h"
       
    37 #include "mcenatsipstatemachine.h"
       
    38 
       
    39 
       
    40 // CONSTRUCTION
       
    41 UT_CMceNatStateCreateOfferRequested* UT_CMceNatStateCreateOfferRequested::NewL()
       
    42     {
       
    43     UT_CMceNatStateCreateOfferRequested* self =
       
    44     	UT_CMceNatStateCreateOfferRequested::NewLC();
       
    45     CleanupStack::Pop();
       
    46     return self;
       
    47     }
       
    48 
       
    49 UT_CMceNatStateCreateOfferRequested* UT_CMceNatStateCreateOfferRequested::NewLC()
       
    50     {
       
    51     UT_CMceNatStateCreateOfferRequested* self =
       
    52     	new ( ELeave ) UT_CMceNatStateCreateOfferRequested();
       
    53     CleanupStack::PushL( self );
       
    54 	self->ConstructL();
       
    55     return self;
       
    56     }
       
    57 
       
    58 // Destructor (virtual by CBase)
       
    59 UT_CMceNatStateCreateOfferRequested::~UT_CMceNatStateCreateOfferRequested()
       
    60     {
       
    61     }
       
    62 
       
    63 // Default constructor
       
    64 UT_CMceNatStateCreateOfferRequested::UT_CMceNatStateCreateOfferRequested()
       
    65     {
       
    66     }
       
    67 
       
    68 // Second phase construct
       
    69 void UT_CMceNatStateCreateOfferRequested::ConstructL()
       
    70     {
       
    71     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
    72     // It generates the test case table.
       
    73     CEUnitTestSuiteClass::ConstructL();
       
    74     }
       
    75 
       
    76 //  METHODS
       
    77 
       
    78 void UT_CMceNatStateCreateOfferRequested::SetupL()
       
    79     {
       
    80     CMCETls::OpenL();
       
    81     SdpCodecStringPool::OpenL();
       
    82 
       
    83     iIds.iProfileID = 1;
       
    84     iIds.iManagerType = KMceCSSIPSession;
       
    85     iIds.iDialogType = KMceDlgTypeInvite;
       
    86     iServerCore = CMceServerCore::NewL();
       
    87     
       
    88     iStorage = CMCETls::Storage();
       
    89     
       
    90 	CDesC8ArrayFlat* params = new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity );
       
    91 	CleanupStack::PushL( params );
       
    92 	params->AppendL( _L8("User <user2@host>") );
       
    93 	params->AppendL( _L8("User <user@host>") );
       
    94     
       
    95     CMceMsgTextArray* msgParams = new (ELeave) CMceMsgTextArray( *params );
       
    96     CleanupStack::PushL( msgParams );
       
    97     iStorage->StoreL( iIds, *msgParams );
       
    98     CleanupStack::PopAndDestroy( msgParams );
       
    99     CleanupStack::PopAndDestroy( params );
       
   100 
       
   101     iSession = CMceCsSession::NewL(*iServerCore);
       
   102     iSession->CreateSubSessionL(iIds, RMessage2());
       
   103     iSipSession = static_cast<CMceSipSession*>
       
   104     	((iSession->Implementation().SubSessions())[0]);    
       
   105 
       
   106 	CMceSipManager& manager = iServerCore->Manager();
       
   107     CSIPProfile& profile = manager.ProfileL( iIds.iProfileID );
       
   108 
       
   109     iNatSession = CMceNatSipSession::NewL( *iSession,
       
   110 		iSipSession->SIPConnection(),
       
   111 		*iSipSession->iStateMachine,
       
   112 		profile,
       
   113 		NULL );
       
   114 	iNatSession->iNatStateMachine->iCurrentState = KMceNatStateCreateOfferRequested;
       
   115     iState = iNatSession->iNatStateMachine->iStates[
       
   116     	iNatSession->iNatStateMachine->iCurrentState ];
       
   117     }
       
   118 
       
   119 void UT_CMceNatStateCreateOfferRequested::Teardown()
       
   120     {
       
   121     CMCETls::Close();
       
   122 	delete iSession;
       
   123 	iSession = NULL;
       
   124 	delete iNatSession;
       
   125 	iNatSession = NULL;
       
   126     delete iServerCore;
       
   127     iServerCore = NULL;
       
   128 
       
   129     SdpCodecStringPool::Close();
       
   130     }
       
   131 
       
   132 void UT_CMceNatStateCreateOfferRequested::
       
   133 	UT_CMceNatStateCreateOfferRequested_AcceptLL()
       
   134     {
       
   135     EUNIT_ASSERT( DoesAccept( EMceNatInitialized ) );
       
   136     EUNIT_ASSERT( DoesAccept( EMceNatUpdated ) );
       
   137     EUNIT_ASSERT( !DoesAccept( EMceNatOffer ) );
       
   138     EUNIT_ASSERT( !DoesAccept( EMceNatUpdateSdp ) );
       
   139     EUNIT_ASSERT( !DoesAccept( EMceNatError ) );
       
   140     EUNIT_ASSERT( !DoesAccept( EMceNatHandleSIP ) );
       
   141     EUNIT_ASSERT( !DoesAccept( EMceNatSync ) );
       
   142     }
       
   143 
       
   144 void UT_CMceNatStateCreateOfferRequested::
       
   145 	UT_CMceNatStateCreateOfferRequested_EntryLL()
       
   146     {
       
   147     TMceNatStateTransitionEvent event( NULL,
       
   148     								   *iNatSession,
       
   149     								   EMceNatInitialized,
       
   150     								   *iNatSession,
       
   151     								   EMceInvite );
       
   152     event.ParamStatus() = KMceReady;
       
   153 
       
   154 	iState->TransitionHandler().EntryL( event );
       
   155 	
       
   156     EUNIT_ASSERT( event.ParamStatus() == KMceAsync );
       
   157     }
       
   158     
       
   159 void UT_CMceNatStateCreateOfferRequested::
       
   160 	UT_CMceNatStateCreateOfferRequested_ExitLL()
       
   161 	{
       
   162 	TMceNatStateTransitionEvent event( NULL,
       
   163     								   *iNatSession,
       
   164     								   EMceNatInitialized,
       
   165     								   *iNatSession,
       
   166     								   EMceInvite );
       
   167 	iState->TransitionHandler().ExitL( event );
       
   168 
       
   169 	EUNIT_ASSERT( iNatSession->iNatStateMachine->iCurrentState ==
       
   170 				  KMceNatStateIdle );
       
   171 	}
       
   172 
       
   173 TBool
       
   174 UT_CMceNatStateCreateOfferRequested::DoesAccept( TMceNatEventCode aEventCode )
       
   175     {
       
   176     TMceNatStateTransitionEvent event( NULL,
       
   177     								   *iNatSession,
       
   178     								   aEventCode,
       
   179     								   *iNatSession,
       
   180     								   EMceInvite );
       
   181     return iState->Accept( event );
       
   182     }
       
   183     
       
   184 //  TEST TABLE
       
   185 
       
   186 EUNIT_BEGIN_TEST_TABLE( 
       
   187     UT_CMceNatStateCreateOfferRequested,
       
   188     "UT_CMceNatStateCreateOfferRequested",
       
   189     "UNIT" )
       
   190 
       
   191 EUNIT_TEST(
       
   192     "DoAcceptL - test ",
       
   193     "CMceNatStateCreateOfferRequested",
       
   194     "AcceptL",
       
   195     "FUNCTIONALITY",
       
   196     SetupL, UT_CMceNatStateCreateOfferRequested_AcceptLL, Teardown)
       
   197 
       
   198 EUNIT_TEST(
       
   199     "EntryL - test ",
       
   200     "CMceNatStateCreateOfferRequested",
       
   201     "EntryL",
       
   202     "FUNCTIONALITY",
       
   203     SetupL, UT_CMceNatStateCreateOfferRequested_EntryLL, Teardown)
       
   204 
       
   205 EUNIT_TEST(
       
   206     "ExitL - test ",
       
   207     "CMceNatStateCreateOfferRequested",
       
   208     "ExitL",
       
   209     "FUNCTIONALITY",
       
   210     SetupL, UT_CMceNatStateCreateOfferRequested_ExitLL, Teardown)
       
   211 
       
   212 EUNIT_END_TEST_TABLE
       
   213 
       
   214 //  END OF FILE