phoneapp/phoneuistates/tsrc/ut_cphoneidle/Src/ut_cphoneidle.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 
       
    22 #include "ut_cphoneidle.h"
       
    23 #include "cphoneidle_inherited.h"
       
    24 
       
    25 #include <EUnitMacros.h>
       
    26 #include <EUnitDecorators.h>
       
    27 #include "CPhoneIdle.h"
       
    28 #include <featmgr.h>
       
    29 #include "PEVirtualEngine.h" 
       
    30 #include "CPhoneViewControllerStub.h"
       
    31 #include "CPhoneStateMachineStub.h"
       
    32 #include "MPhoneKeyEvents.h"
       
    33 #include "TPhoneCommandParam.h"
       
    34 #include "CPhoneMainResourceResolver.h"
       
    35 #include "phonerssbase.h"
       
    36 
       
    37 
       
    38 // - Construction -----------------------------------------------------------
       
    39 
       
    40 ut_cphoneidle* ut_cphoneidle::NewL()
       
    41     {
       
    42     ut_cphoneidle* self = ut_cphoneidle::NewLC();
       
    43     CleanupStack::Pop();
       
    44     return self;
       
    45     }
       
    46     
       
    47 ut_cphoneidle* ut_cphoneidle::NewLC()
       
    48     {
       
    49     ut_cphoneidle* self = new( ELeave ) ut_cphoneidle();
       
    50     CleanupStack::PushL( self );
       
    51     self->ConstructL();
       
    52     return self;
       
    53     }
       
    54 
       
    55 ut_cphoneidle::~ut_cphoneidle()
       
    56     {
       
    57     CSmcMockContext::Release();
       
    58     }
       
    59 
       
    60 ut_cphoneidle::ut_cphoneidle()
       
    61     {
       
    62     }
       
    63 
       
    64 void ut_cphoneidle::ConstructL()
       
    65     {
       
    66     CEUnitTestSuiteClass::ConstructL();
       
    67     iMockContext = CSmcMockContext::InstanceL();
       
    68     }
       
    69 
       
    70 // - Test methods -----------------------------------------------------------
       
    71 
       
    72 
       
    73 
       
    74 void ut_cphoneidle::SetupL(  )
       
    75     {
       
    76     iMockContext->InitializeL();
       
    77         
       
    78     iViewCommandHandle = CPhoneViewController::NewL();//TRect() );
       
    79     iStateMachineMock = CPhoneStateMachineStub::NewL();
       
    80     
       
    81     iStateIdle  = CPhoneIdle::NewL(
       
    82             iStateMachineMock, iViewCommandHandle, NULL );
       
    83     
       
    84     iIdleInherited = CPhoneIdle_Inherited::NewL(
       
    85         iStateMachineMock, iViewCommandHandle, NULL);
       
    86     
       
    87     }
       
    88     
       
    89 
       
    90 void ut_cphoneidle::Teardown(  )
       
    91     {
       
    92     delete CPhoneMainResourceResolver::Instance();
       
    93     delete iStateIdle;
       
    94     delete iIdleInherited;
       
    95     delete iViewCommandHandle;
       
    96     delete iStateMachineMock;
       
    97     
       
    98     iMockContext->Reset();
       
    99     }
       
   100     
       
   101 
       
   102 void ut_cphoneidle::T_ConstructionL(  )
       
   103     {
       
   104     //empty
       
   105     }
       
   106 
       
   107 
       
   108 void ut_cphoneidle::T_HandlePhoneEngineMessageL(  )
       
   109     {
       
   110     TInt callId(1);
       
   111     iMockContext->ExpectCallL( "CPhoneState::SendGlobalInfoNoteL" ).
       
   112             WithL<TPhoneViewCommandId, TBool> ( EPhoneInformationRemotePutOnHoldNote, ETrue );
       
   113     iStateIdle->HandlePhoneEngineMessageL( MEngineMonitor::EPEMessageRemoteHeld, callId );
       
   114     EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
       
   115     
       
   116     iMockContext->ExpectCallL( "CPhoneState::SendGlobalInfoNoteL" ).
       
   117             WithL<TPhoneViewCommandId, TBool> ( EPhoneInformationConnectedNote, ETrue );
       
   118     iStateIdle->HandlePhoneEngineMessageL( MEngineMonitor::EPEMessageRemoteResumed, callId );
       
   119     EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
       
   120     
       
   121     iMockContext->ExpectCallL( "CPhoneState::HandleAudioOutputChangedL" ).TimesL(1);
       
   122     iStateIdle->HandlePhoneEngineMessageL( MEngineMonitor::EPEMessageAudioOutputChanged, callId );
       
   123     EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
       
   124         
       
   125     iMockContext->ExpectCallL( "CPhoneGeneralGsmMessagesHandler::NewL" );
       
   126     iMockContext->ExpectCallL( "CPhoneGeneralGsmMessagesHandler::HandlePhoneEngineMessageL" );
       
   127     iStateIdle->HandlePhoneEngineMessageL( MEngineMonitor::EPEMessageIssuedSSRequest, callId );
       
   128     EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
       
   129     
       
   130     iMockContext->ExpectCallL( "CPhoneStateIdle::HandlePhoneEngineMessageL" ).
       
   131             WithL<TInt, TInt> ( MEngineMonitor::EPEMessageSecureNotSpecified, callId );
       
   132     iStateIdle->HandlePhoneEngineMessageL( MEngineMonitor::EPEMessageSecureNotSpecified, callId );
       
   133     EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
       
   134     }
       
   135 
       
   136 void ut_cphoneidle::T_HandleErrorL(  )
       
   137     {
       
   138     TPEErrorInfo aErrorInfo;
       
   139     aErrorInfo.iErrorCode = ECCPErrorCCUserAlertingNoAnswer;
       
   140     iMockContext->ExpectCallL( "CPhoneState::HandleErrorL" ).WithL<TPEErrorInfo>( aErrorInfo );
       
   141     iIdleInherited->User_HandleErrorL( aErrorInfo );
       
   142     EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
       
   143     }
       
   144 
       
   145 // - EUnit test table -------------------------------------------------------
       
   146 
       
   147 EUNIT_BEGIN_TEST_TABLE(
       
   148     ut_cphoneidle,
       
   149     "Add test suite description here.",
       
   150     "UNIT" )
       
   151 
       
   152 EUNIT_TEST(
       
   153     "Construction",
       
   154     "ut_cphoneidle",
       
   155     "test1",
       
   156     "FUNCTIONALITY",
       
   157     SetupL, T_ConstructionL, Teardown)
       
   158     
       
   159 EUNIT_TEST(
       
   160     "T_HandlePhoneEngineMessageL",
       
   161     "ut_cphoneidle",
       
   162     "test2",
       
   163     "FUNCTIONALITY",
       
   164     SetupL, T_HandlePhoneEngineMessageL, Teardown)
       
   165     
       
   166 EUNIT_TEST(
       
   167     "T_HandleErrorL",
       
   168     "ut_cphoneidle",
       
   169     "test3",
       
   170     "FUNCTIONALITY",
       
   171     SetupL, T_HandleErrorL, Teardown)
       
   172 
       
   173 EUNIT_END_TEST_TABLE