phoneapp/phoneuicontrol/tsrc/ut_cphoneuicommandmanager/Src/ut_cphoneuicommandmanager.cpp
changeset 74 d1c62c765e48
child 78 baacf668fe89
equal deleted inserted replaced
65:2a5d4ab426d3 74:d1c62c765e48
       
     1 
       
     2 /*
       
     3 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     4 * All rights reserved.
       
     5 * This component and the accompanying materials are made available
       
     6 * under the terms of "Eclipse Public License v1.0"
       
     7 * which accompanies this distribution, and is available
       
     8 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 *
       
    10 * Initial Contributors:
       
    11 * Nokia Corporation - initial contribution.
       
    12 *
       
    13 * Contributors:
       
    14 *
       
    15 * Description:
       
    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 
       
    25 #include <phoneui.rsg>
       
    26 
       
    27 #include "mock_cphoneviewcommandhandle.h"
       
    28 #include "cphonestatemachine.h"
       
    29 #include "ut_cphoneuicommandmanager.h"
       
    30 #include "CPhoneCenRepProxy.h"
       
    31 #include "cpeengineinfo.h"
       
    32 #include "phonerssbase.h"
       
    33 #include "CPhoneMainResourceResolver.h"
       
    34 
       
    35 #include <csmcmockcontext.h>
       
    36 #include <msmcmockspecbuilder.h>
       
    37 
       
    38 #include "telephonyvariant.hrh"
       
    39 #include "TPhoneCmdParamInteger.h"
       
    40 #include "TPhoneCmdParamBoolean.h"
       
    41 #include <startupdomainpskeys.h>
       
    42 #include <hwrmdomainpskeys.h>
       
    43 #include "tphonecmdparamcallstatedata.h"
       
    44 #include "phoneresourceids.h"
       
    45 
       
    46 CPhoneCenRepProxy* GlobalCPhoneCenRepProxy;
       
    47 TPEPhoneAudioRouteParameters routeParameters;
       
    48 
       
    49 // needed for mocking CPhoneMainResourceResolver::Instance()
       
    50 class CPhoneMainResourceResolverMock : public CPhoneMainResourceResolver
       
    51     {
       
    52     
       
    53     };
       
    54 
       
    55 // Class to access protected constructor
       
    56 class CPhoneStateMachineMock : public CPhoneStateMachine
       
    57     {
       
    58 public:
       
    59     CPhoneStateMachineMock( MPhoneViewCommandHandle* aViewCommandHandle )
       
    60         : CPhoneStateMachine( aViewCommandHandle )
       
    61         {
       
    62             
       
    63         }
       
    64     };
       
    65 
       
    66 //---------------------------------------------------------------------------
       
    67 
       
    68 //CONSTANS
       
    69 _LIT( KTestString, "test_string" );
       
    70 
       
    71 // - Construction -----------------------------------------------------------
       
    72 
       
    73 ut_cphoneuicommandmanager* ut_cphoneuicommandmanager::NewL()
       
    74     {
       
    75     ut_cphoneuicommandmanager* self = ut_cphoneuicommandmanager::NewLC();
       
    76     CleanupStack::Pop();
       
    77     return self;
       
    78     }
       
    79 
       
    80 ut_cphoneuicommandmanager* ut_cphoneuicommandmanager::NewLC()
       
    81     {
       
    82     ut_cphoneuicommandmanager* self = new( ELeave ) ut_cphoneuicommandmanager();
       
    83     CleanupStack::PushL( self );
       
    84     self->ConstructL();
       
    85     return self;
       
    86     }
       
    87 
       
    88 ut_cphoneuicommandmanager::~ut_cphoneuicommandmanager()
       
    89     {
       
    90     CSmcMockContext::Release();
       
    91     }
       
    92 
       
    93 ut_cphoneuicommandmanager::ut_cphoneuicommandmanager()
       
    94     {
       
    95     }
       
    96 
       
    97 void ut_cphoneuicommandmanager::ConstructL()
       
    98     {
       
    99     CEUnitTestSuiteClass::ConstructL();
       
   100     iMockContext = CSmcMockContext::InstanceL();
       
   101     }
       
   102 
       
   103 // - Test methods -----------------------------------------------------------
       
   104 
       
   105 
       
   106 
       
   107 void ut_cphoneuicommandmanager::SetupL(  )
       
   108     {    
       
   109     iViewCmdHandleMock = new CPhoneViewCommandHandleMock();
       
   110     iStateMachineMock = new (ELeave) CPhoneStateMachineMock( iViewCmdHandleMock );
       
   111     iCustomization = NULL;
       
   112     iPhoneStateMock = new (ELeave) CPhoneState(iStateMachineMock, iViewCmdHandleMock, iCustomization );
       
   113     iCmdManager = CPhoneUiCommandManager::NewL(
       
   114                 iPhoneStateMock,
       
   115                 *iViewCmdHandleMock,
       
   116                 *iStateMachineMock );
       
   117     
       
   118     iCPhoneMainResourceResolverMock = new ( ELeave ) CPhoneMainResourceResolverMock();
       
   119     SmcDefaultValue<CPhoneMainResourceResolver*>::SetL( iCPhoneMainResourceResolverMock );
       
   120         
       
   121     GlobalCPhoneCenRepProxy = NULL;      
       
   122     
       
   123     iEngineInfoMock = CPEEngineInfo::NewL();    
       
   124     SmcDefaultValue<MPEEngineInfo*>::SetL( iEngineInfoMock );
       
   125     
       
   126     SmcDefaultValue<const TPESimState&>::SetL( EPESimUsable );
       
   127     SmcDefaultValue<const TPEAudioOutput&>::SetL( EPENotActive );
       
   128     SmcDefaultValue<const TPEPhoneAudioRouteParameters&>::SetL( routeParameters );
       
   129     SmcDefaultValue<const TBool&>::SetL( EFalse );
       
   130     }
       
   131 
       
   132 void ut_cphoneuicommandmanager::Teardown(  )
       
   133     {
       
   134     delete iCmdManager;
       
   135     iCmdManager = NULL;
       
   136     delete iPhoneStateMock;
       
   137     iPhoneStateMock = NULL;
       
   138     delete iViewCmdHandleMock;
       
   139     iViewCmdHandleMock = NULL;
       
   140     delete iStateMachineMock;
       
   141     iStateMachineMock = NULL;
       
   142     delete iCustomization;
       
   143     iCustomization = NULL;
       
   144     delete iCPhoneMainResourceResolverMock;
       
   145     iCPhoneMainResourceResolverMock = NULL;
       
   146     SmcDefaultValue<CPhoneMainResourceResolver*>::Reset();
       
   147     iMockContext->Reset();
       
   148     delete iEngineInfoMock;
       
   149     iEngineInfoMock = NULL;
       
   150     
       
   151     SmcDefaultValue<MPEEngineInfo*>::Reset();
       
   152     SmcDefaultValue<const TPESimState&>::Reset();
       
   153     SmcDefaultValue<const TPEAudioOutput&>::Reset();
       
   154     SmcDefaultValue<const TPEPhoneAudioRouteParameters&>::Reset();
       
   155     SmcDefaultValue<const TBool&>::Reset();
       
   156     }
       
   157     
       
   158 void ut_cphoneuicommandmanager::T_CPhoneUiCommandManager__EmptyL(  )
       
   159     {
       
   160     //EMPTY CASE
       
   161     }
       
   162 
       
   163 /**
       
   164  *  Test name: T_UpdateUiCommands
       
   165  *      
       
   166  *  Use case: Client calls UpdateUiCommands check that SetButtonFlags/SetTouchButtons/SetToolBarButtons gets called. 
       
   167  *  Motivation: 
       
   168  */
       
   169 void ut_cphoneuicommandmanager::T_UpdateUiCommands(  )
       
   170     {
       
   171     /*expect call from SetButtonFlags*/
       
   172     TPhoneCmdParamBoolean muteParam;
       
   173     iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommand" ).
       
   174             WithL<TPhoneViewCommandId, TPhoneCommandParam&> ( EPhoneViewSetMuteFlag, muteParam ); 
       
   175     
       
   176     /*expect call from SetTouchButtons*/
       
   177     TPhoneCmdParamBoolean booleanParam;
       
   178     iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommand" ).
       
   179             WithL<TPhoneViewCommandId, TPhoneCommandParam&> ( EPhoneViewSetTouchPaneButtons, booleanParam ); 
       
   180         
       
   181     /*expect call from SetToolBarButtons*/
       
   182     TPhoneCmdParamInteger integerParam;
       
   183     iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommand" ).
       
   184            WithL<TPhoneViewCommandId, TPhoneCommandParam&> ( EPhoneViewUpdateCba, integerParam ); 
       
   185     
       
   186     iCmdManager->UpdateUiCommands();
       
   187     
       
   188     EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
       
   189     }
       
   190 
       
   191 /**
       
   192  *  Test name: T_UpdateUiCommands
       
   193  *      
       
   194  *  Use case: Client calls UpdateUiCommands check that SetButtonFlags/SetTouchButtons/SetToolBarButtons gets called. 
       
   195  *  Motivation: 
       
   196  */
       
   197 void ut_cphoneuicommandmanager::T_Set_Get_SoftRejectStatus(  )
       
   198     {
       
   199     iCmdManager->SetSoftRejectStatus(ETrue);
       
   200     EUNIT_ASSERT_EQUALS( ETrue, iCmdManager->SoftRejectStatus() );
       
   201     }
       
   202 
       
   203 // - EUnit test table -------------------------------------------------------
       
   204 
       
   205 EUNIT_BEGIN_TEST_TABLE(
       
   206     ut_cphoneuicommandmanager,
       
   207     "Add test suite description here.",
       
   208     "UNIT" )
       
   209 
       
   210 EUNIT_TEST(
       
   211     "1- ut_cphoneuicommandmanager",
       
   212     "ut_cphoneuicommandmanager",
       
   213     "1- Setup-teardown",
       
   214     "FUNCTIONALITY",
       
   215     SetupL, T_CPhoneUiCommandManager__EmptyL, Teardown)
       
   216     
       
   217 EUNIT_TEST(
       
   218     "2- ut_cphoneuicommandmanager",
       
   219     "ut_cphoneuicommandmanager",
       
   220     "2- T_UpdateUiCommands",
       
   221     "FUNCTIONALITY",
       
   222     SetupL, T_UpdateUiCommands, Teardown)
       
   223     
       
   224 EUNIT_TEST(
       
   225     "3- ut_cphoneuicommandmanager",
       
   226     "ut_cphoneuicommandmanager",
       
   227     "3- T_Set_Get_SoftRejectStatus",
       
   228     "FUNCTIONALITY",
       
   229     SetupL, T_Set_Get_SoftRejectStatus, Teardown)
       
   230 
       
   231 EUNIT_END_TEST_TABLE