phoneapp/phoneuistates/tsrc/ut_cphonesinglecall/Src/ut_cphonesinglecall.cpp
changeset 77 2be0b271d017
child 76 cfea66083b62
equal deleted inserted replaced
72:c76a0b1755b9 77:2be0b271d017
       
     1 /*
       
     2 * Copyright (c) 2009 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 #include <csmcmockcontext.h>
       
    19 #include <smcdefaultvalue.h>
       
    20 #include <msmcmockspecbuilder.h>
       
    21 #include <smcobjecttotypemapper.h>
       
    22 #include <EUnitMacros.h>
       
    23 #include <EUnitDecorators.h>
       
    24 #include <featmgr.h>
       
    25 #include "ut_cphonesinglecall.h"
       
    26 #include "CPhoneMainResourceResolver.h"
       
    27 #include "CPhoneStateMachineGSM.h"
       
    28 #include "mock_cphoneviewcommandhandle.h"
       
    29 #include "PEVirtualEngine.h"
       
    30 #include "MPhoneKeyEvents.h"
       
    31 #include "TPhoneCommandParam.h"
       
    32 #include "TPhoneCmdParamCallHeaderData.h"
       
    33 #include "TPhoneCmdParamAudioOutput.h"
       
    34 #include "cpeengineinfoimpl.h"
       
    35 #include "phonerssbase.h"
       
    36 #include "phonestatedefinitionsgsm.h"
       
    37 #include "TPhoneCmdParamInteger.h"
       
    38 #include "CPhoneSingleCall.h"
       
    39 
       
    40 // needed for mocking CPhoneMainResourceResolver::Instance()
       
    41 class CPhoneMainResourceResolverMock : public CPhoneMainResourceResolver
       
    42     {
       
    43     };
       
    44 
       
    45 // - Construction -----------------------------------------------------------
       
    46 
       
    47 ut_cphonesinglecall* ut_cphonesinglecall::NewL()
       
    48     {
       
    49     ut_cphonesinglecall* self = ut_cphonesinglecall::NewLC();
       
    50     CleanupStack::Pop();
       
    51     return self;
       
    52     }
       
    53 
       
    54 ut_cphonesinglecall* ut_cphonesinglecall::NewLC()
       
    55     {
       
    56     ut_cphonesinglecall* self = new( ELeave ) ut_cphonesinglecall();
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL();
       
    59     return self;
       
    60     }
       
    61 
       
    62 ut_cphonesinglecall::~ut_cphonesinglecall()
       
    63     {
       
    64     CSmcMockContext::Release();
       
    65     }
       
    66 
       
    67 ut_cphonesinglecall::ut_cphonesinglecall()
       
    68     {
       
    69     }
       
    70 
       
    71 void ut_cphonesinglecall::ConstructL()
       
    72     {
       
    73     CEUnitTestSuiteClass::ConstructL();
       
    74     iMockContext = CSmcMockContext::InstanceL();
       
    75     }
       
    76 
       
    77 // - Test methods -----------------------------------------------------------
       
    78 
       
    79 
       
    80 
       
    81 void ut_cphonesinglecall::SetupL(  )
       
    82     {
       
    83     iMockContext->InitializeL();
       
    84 
       
    85     iCPhoneMainResourceResolverMock = new ( ELeave ) CPhoneMainResourceResolverMock();
       
    86           SmcDefaultValue<CPhoneMainResourceResolver*>::SetL( iCPhoneMainResourceResolverMock );
       
    87 
       
    88     iViewCmdHandleMock = new CPhoneViewCommandHandleMock();
       
    89 
       
    90     iStateMachineMock = CPhoneStateMachineGSM::NewL( iViewCmdHandleMock );
       
    91 
       
    92     iStateSingleCall  = CPhoneSingleCall::NewL(
       
    93             iStateMachineMock, iViewCmdHandleMock, NULL );
       
    94 
       
    95     iEngineInfoMock = CPEEngineInfoImpl::NewL();
       
    96     SmcDefaultValue<MPEEngineInfo*>::SetL( iEngineInfoMock );
       
    97 
       
    98     SmcDefaultValue<TPESimState>::SetL( EPESimUsable );
       
    99     SmcDefaultValue<const TPEAudioOutput&>::SetL( EPENotActive );
       
   100 
       
   101     }
       
   102 
       
   103 void ut_cphonesinglecall::Teardown(  )
       
   104     {
       
   105     delete iViewCmdHandleMock;
       
   106         iViewCmdHandleMock = NULL;
       
   107     delete iStateSingleCall;
       
   108         iStateSingleCall = NULL;
       
   109     delete iStateMachineMock;
       
   110         iStateMachineMock = NULL;
       
   111     delete iEngineInfoMock;
       
   112         iEngineInfoMock = NULL;
       
   113     delete iCPhoneMainResourceResolverMock;
       
   114         iCPhoneMainResourceResolverMock = NULL;
       
   115 
       
   116     SmcDefaultValue<TPESimState>::Reset();
       
   117     SmcDefaultValue<const TPEAudioOutput&>::Reset();
       
   118 
       
   119     iMockContext->Reset();
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // Test  conference idle
       
   124 // -check commands
       
   125 // -----------------------------------------------------------------------------
       
   126 //  
       
   127 void ut_cphonesinglecall::T_HandleConnectedL( )
       
   128     {
       
   129     const TInt callId( 0 );
       
   130     iMockContext->ExpectCallL("CPhoneState::UpdateUiCommands");
       
   131     iMockContext->ExpectCallL("CPhoneViewCommandHandleMock::ExecuteCommandL").
       
   132         WithL<TPhoneViewCommandId, TInt>(EPhoneViewUpdateBubble, callId);
       
   133         
       
   134     iStateSingleCall->HandlePhoneEngineMessageL( MEngineMonitor::EPEMessageConnected, callId );   
       
   135     
       
   136     EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
       
   137      
       
   138     }
       
   139 
       
   140 // - EUnit test table -------------------------------------------------------
       
   141 
       
   142 EUNIT_BEGIN_TEST_TABLE(
       
   143     ut_cphonesinglecall,
       
   144     "ut_cphonesinglecall",
       
   145     "UNIT" )
       
   146 
       
   147 EUNIT_TEST(
       
   148     "2. HandleConnectedL",
       
   149     "",
       
   150     "HandleConnectedL",
       
   151     "FUNCTIONALITY",
       
   152     SetupL, T_HandleConnectedL, Teardown)    
       
   153     
       
   154 EUNIT_END_TEST_TABLE
       
   155 
       
   156