phoneapp/phoneuicontrol/tsrc/ut_cphonestatecallsetup/src/ut_cphonestatecallsetup.cpp
changeset 77 2be0b271d017
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 #include <csmcmockcontext.h>
       
    18 #include <smcdefaultvalue.h>
       
    19 #include <msmcmockspecbuilder.h>
       
    20 #include <smcobjecttotypemapper.h>
       
    21 #include <EUnitMacros.h>
       
    22 #include <EUnitDecorators.h>
       
    23 #include <featmgr.h>
       
    24 #include "ut_cphonestatecallsetup.h"
       
    25 #include "cphonestatecallsetup.h"
       
    26 #include "cphonemainresourceresolver.h"
       
    27 #include "cphonestatemachinegsm.h"
       
    28 #include "pevirtualengine.h" 
       
    29 #include "mphonekeyevents.h"
       
    30 #include "tphonecommandparam.h"
       
    31 #include "tphonecmdparamcallheaderdata.h"
       
    32 #include "tphonecmdparamaudiooutput.h"
       
    33 #include "cpeengineinfo.h"
       
    34 #include "cpeengineinfoimpl.h"
       
    35 #include "mock_cphoneviewcommandhandle.h"
       
    36 
       
    37 //test
       
    38 #include "TPhoneCmdParamInteger.h"
       
    39 #include "tphonecmdparamboolean.h"
       
    40 
       
    41 // needed for mocking CPhoneMainResourceResolver::Instance()
       
    42 class CPhoneMainResourceResolverMock : public CPhoneMainResourceResolver
       
    43     {
       
    44     };
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // operator for comparing parameter expected and result value.   
       
    48 // -
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 TBool operator==(const TPhoneCommandParam& param1, const TPhoneCommandParam& param2 )
       
    52     {
       
    53     TBool ret( EFalse );
       
    54     
       
    55     if ( param1.ParamId() == param2.ParamId() )
       
    56         {
       
    57         if ( TPhoneCommandParam::EPhoneParamIdBoolean == param1.ParamId() )
       
    58             {
       
    59             const TPhoneCmdParamBoolean  &value1 = static_cast<const TPhoneCmdParamBoolean&> (param1);
       
    60             const TPhoneCmdParamBoolean  &value2 = static_cast<const TPhoneCmdParamBoolean&> (param2);
       
    61             if (  value1.Boolean() == value2.Boolean() )
       
    62                 {
       
    63                 ret = ETrue;
       
    64                 }
       
    65             }
       
    66         else if ( TPhoneCommandParam::EPhoneParamIdCallHeaderData == param1.ParamId() )
       
    67             {
       
    68             const TPhoneCmdParamCallHeaderData  &value1 = static_cast<const TPhoneCmdParamCallHeaderData&> (param1);
       
    69             const TPhoneCmdParamCallHeaderData  &value2 = static_cast<const TPhoneCmdParamCallHeaderData&> (param2);
       
    70             if ( value1.CallState() == value2.CallState() )
       
    71                 {
       
    72                 ret = ETrue;
       
    73                 }
       
    74             }
       
    75         else if ( TPhoneCommandParam::EPhoneParamIdInteger == param1.ParamId() )
       
    76             {
       
    77             const TPhoneCmdParamInteger  &value1 = static_cast<const TPhoneCmdParamInteger&> (param1);
       
    78             const TPhoneCmdParamInteger  &value2 = static_cast<const TPhoneCmdParamInteger&> (param2);
       
    79             if ( value1.Integer() == value2.Integer() )
       
    80                 {
       
    81                 ret = ETrue;
       
    82                 }
       
    83             }
       
    84         else if ( TPhoneCommandParam::EPhoneParamIdAudioOutput == param1.ParamId() )
       
    85             {
       
    86             const TPhoneCmdParamAudioOutput  &value1 = static_cast<const TPhoneCmdParamAudioOutput&> (param1);
       
    87             const TPhoneCmdParamAudioOutput  &value2 = static_cast<const TPhoneCmdParamAudioOutput&> (param2);
       
    88             if ( value1.AudioOutput() == value2.AudioOutput() )
       
    89                 {
       
    90                 ret = ETrue;
       
    91                 }
       
    92             }
       
    93         else  
       
    94             {
       
    95             ret = ETrue;  // just paramiId compared
       
    96             }
       
    97         }
       
    98     return ret;
       
    99     }
       
   100 
       
   101 // - Construction -----------------------------------------------------------
       
   102 ut_cphonestatecallsetup* ut_cphonestatecallsetup::NewL()
       
   103     {
       
   104     ut_cphonestatecallsetup* self = ut_cphonestatecallsetup::NewLC();
       
   105     CleanupStack::Pop();
       
   106     return self;
       
   107     }
       
   108 	
       
   109 ut_cphonestatecallsetup* ut_cphonestatecallsetup::NewLC()
       
   110     {
       
   111     ut_cphonestatecallsetup* self = new( ELeave ) ut_cphonestatecallsetup();
       
   112     CleanupStack::PushL( self );
       
   113     self->ConstructL();
       
   114     return self;
       
   115     }
       
   116 
       
   117 ut_cphonestatecallsetup::~ut_cphonestatecallsetup()
       
   118     {
       
   119     CSmcMockContext::Release();
       
   120     }
       
   121 
       
   122 ut_cphonestatecallsetup::ut_cphonestatecallsetup()
       
   123     {
       
   124     }
       
   125 
       
   126 void ut_cphonestatecallsetup::ConstructL()
       
   127     {
       
   128     CEUnitTestSuiteClass::ConstructL();
       
   129     iMockContext = CSmcMockContext::InstanceL();
       
   130     }
       
   131 
       
   132 // - Test methods -----------------------------------------------------------
       
   133 
       
   134 
       
   135 
       
   136 void ut_cphonestatecallsetup::SetupL(  )
       
   137     {
       
   138     iMockContext->InitializeL();
       
   139 
       
   140     iCPhoneMainResourceResolverMock = new ( ELeave ) CPhoneMainResourceResolverMock();
       
   141           SmcDefaultValue<CPhoneMainResourceResolver*>::SetL( iCPhoneMainResourceResolverMock );
       
   142     
       
   143     iViewCmdHandleMock = new CPhoneViewCommandHandleMock();
       
   144   
       
   145     iStateMachineMock = CPhoneStateMachineGSM::NewL( iViewCmdHandleMock ); 
       
   146   
       
   147   	// Have to be here otherwise execution will stop to ASSERT_DEBUG when 
       
   148 	// construct the CPhoneStateCallSetup-object.
       
   149     iEngineInfoMock = CPEEngineInfo::NewL();
       
   150     SmcDefaultValue<MPEEngineInfo*>::SetL( iEngineInfoMock );
       
   151     
       
   152     iStateCallSetup  = CPhoneStateCallSetup::NewL(
       
   153             iStateMachineMock, iViewCmdHandleMock, NULL );
       
   154       
       
   155     SmcDefaultValue<TPESimState>::SetL( EPESimStatusUninitialized );
       
   156     SmcDefaultValue<const TPEAudioOutput&>::SetL( EPENotActive );
       
   157     }
       
   158     
       
   159 
       
   160 void ut_cphonestatecallsetup::Teardown(  )
       
   161     {
       
   162     delete iViewCmdHandleMock;
       
   163     iViewCmdHandleMock = NULL;
       
   164     delete iStateCallSetup;
       
   165     iStateCallSetup = NULL;
       
   166     delete iStateMachineMock;
       
   167     iStateMachineMock = NULL;
       
   168     delete iEngineInfoMock;
       
   169     iEngineInfoMock = NULL;
       
   170     delete iCPhoneMainResourceResolverMock;
       
   171     iCPhoneMainResourceResolverMock = NULL;
       
   172     
       
   173     SmcDefaultValue<TPESimState>::Reset();
       
   174     SmcDefaultValue<const TPEAudioOutput&>::Reset();
       
   175     
       
   176     iMockContext->Reset();
       
   177     }
       
   178     
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // ut_cphonestatecallsetup::T_EmptyL
       
   182 // -check commands
       
   183 // -----------------------------------------------------------------------------
       
   184 // 
       
   185 void ut_cphonestatecallsetup::T_EmptyL()
       
   186     {
       
   187     }
       
   188  
       
   189 // - EUnit test table -------------------------------------------------------
       
   190 
       
   191 EUNIT_BEGIN_TEST_TABLE(
       
   192     ut_cphonestatecallsetup,
       
   193     "Add test suite description here.",
       
   194     "UNIT" )
       
   195 
       
   196 EUNIT_TEST(
       
   197     "1- Constrcution & destruction.",
       
   198     "CPhoneStateCallSetup",
       
   199     "1- Constrcution & destruction.",
       
   200     "FUNCTIONALITY",
       
   201     SetupL, T_EmptyL, Teardown)
       
   202     
       
   203 EUNIT_END_TEST_TABLE
       
   204