phoneengine/phoneservices/tsrc/ut_dtmfservice/unit_tests.cpp
changeset 37 ba76fc04e6c2
child 51 f39ed5e045e0
child 74 d1c62c765e48
equal deleted inserted replaced
36:2eacb6118286 37:ba76fc04e6c2
       
     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:  Unit tests for DTMFService.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtTest/QtTest>
       
    19 
       
    20 //#include <hbglobal_p.h>
       
    21 #include "dtmfservice.h"
       
    22 
       
    23 class TestDTMFService : public QObject, public MPECallControlIF, public MPECallSettersIF
       
    24 {
       
    25     Q_OBJECT
       
    26 public:
       
    27     TestDTMFService();
       
    28     virtual ~TestDTMFService();    
       
    29 
       
    30 public slots:
       
    31     void initTestCase ();
       
    32     void cleanupTestCase ();
       
    33     void init ();
       
    34     void cleanup ();
       
    35     
       
    36 public:
       
    37     void SetKeyCode( const TChar& aKeyCode );
       
    38     void SetPhoneNumber( const TPEPhoneNumber& aPhoneNumber );
       
    39     void SetCallTypeCommand( const TPECallType& aCallType );
       
    40     TInt HandleDialServiceCall( const TBool aClientCall = EFalse );
       
    41     void HandlePlayDTMFL();
       
    42     TInt HandleEndDTMF();
       
    43     void SetContactId2( const TInt aContactId );
       
    44     void SetServiceIdCommand( TUint32 aServiceId );
       
    45     
       
    46 private slots:
       
    47     void testPlayDTMFTone ();
       
    48     void testStopDTMFPlay ();
       
    49 
       
    50 private:
       
    51     DTMFService *m_dtmfService; // class under test
       
    52     bool m_setPhoneNumberCalled;
       
    53     bool m_setCallTypeCommandCalled;
       
    54     bool m_handleDialCallCalled;
       
    55     TPEPhoneNumber m_phoneNumber;
       
    56     TPECallType m_callType;
       
    57     bool m_clientCall;
       
    58     int m_contactId;
       
    59     bool m_setContactIdCalled;
       
    60     bool m_handleEndDTMFCalled;
       
    61     bool m_handlePlayDTMFLCalled;
       
    62     bool m_setKeyCodeCalled;
       
    63     bool m_handlePlayDtmfLeave;
       
    64     ushort keyValue;
       
    65 };
       
    66 
       
    67 TestDTMFService::TestDTMFService ()
       
    68 {
       
    69 }
       
    70 
       
    71 TestDTMFService::~TestDTMFService ()
       
    72 {
       
    73 }
       
    74 
       
    75 void TestDTMFService::initTestCase ()
       
    76 {
       
    77 }
       
    78 
       
    79 void TestDTMFService::cleanupTestCase ()
       
    80 {
       
    81 }
       
    82 
       
    83 void TestDTMFService::init ()
       
    84 {
       
    85     m_setPhoneNumberCalled = false;
       
    86     m_setCallTypeCommandCalled = false;
       
    87     m_handleDialCallCalled = false;
       
    88     m_clientCall = false;
       
    89     m_setContactIdCalled = false;
       
    90     m_contactId = -1;
       
    91     m_handleEndDTMFCalled = false;
       
    92     m_handlePlayDTMFLCalled = false;
       
    93     m_setKeyCodeCalled = false;
       
    94     m_handlePlayDtmfLeave = false;
       
    95     keyValue = -1;
       
    96     m_dtmfService = new DTMFService (*this, *this, this);
       
    97 }
       
    98 
       
    99 void TestDTMFService::cleanup ()
       
   100 {
       
   101     delete m_dtmfService;
       
   102 }
       
   103 
       
   104 void TestDTMFService::SetKeyCode( const TChar& aKeyCode )
       
   105 {
       
   106     m_setKeyCodeCalled = true;
       
   107     keyValue = aKeyCode;
       
   108 }
       
   109 
       
   110 void TestDTMFService::SetPhoneNumber( const TPEPhoneNumber& aPhoneNumber )
       
   111 {
       
   112     m_setPhoneNumberCalled = true;
       
   113     m_phoneNumber = aPhoneNumber;	
       
   114 }
       
   115 
       
   116 void TestDTMFService::SetCallTypeCommand( const TPECallType& aCallType )
       
   117 {
       
   118     m_setCallTypeCommandCalled = true;
       
   119     m_callType = aCallType;	
       
   120 }
       
   121 
       
   122 void TestDTMFService::HandlePlayDTMFL()
       
   123 {
       
   124     m_handlePlayDTMFLCalled = true;
       
   125     
       
   126     if (m_handlePlayDtmfLeave)
       
   127         User::Leave(KErrNotFound);
       
   128 }
       
   129 
       
   130 TInt TestDTMFService::HandleEndDTMF()
       
   131 {
       
   132     m_handleEndDTMFCalled = true;
       
   133     return 0;
       
   134 }
       
   135 
       
   136 void TestDTMFService::SetContactId2( const TInt aContactId )
       
   137 {
       
   138     m_setContactIdCalled = true;
       
   139     m_contactId = aContactId;	
       
   140 }
       
   141 
       
   142 void TestDTMFService::SetServiceIdCommand( TUint32 aServiceId )
       
   143 {
       
   144     Q_UNUSED(aServiceId)
       
   145 }
       
   146 
       
   147 TInt TestDTMFService::HandleDialServiceCall( const TBool aClientCall )
       
   148 {
       
   149     m_handleDialCallCalled = true;
       
   150     m_clientCall = aClientCall;
       
   151     return KErrNone;
       
   152 }
       
   153 
       
   154 void TestDTMFService::testPlayDTMFTone()
       
   155 {
       
   156     QChar six('6');
       
   157     m_dtmfService->playDTMFTone(six);
       
   158     QVERIFY (m_setKeyCodeCalled == true);
       
   159     QCOMPARE (keyValue, six.unicode());
       
   160     QVERIFY (m_handlePlayDTMFLCalled == true);
       
   161     
       
   162     m_handlePlayDtmfLeave = true;
       
   163     
       
   164     TRAP_IGNORE(m_dtmfService->playDTMFTone(six));
       
   165     
       
   166     m_handlePlayDtmfLeave = false;
       
   167 }
       
   168 
       
   169 void TestDTMFService::testStopDTMFPlay()
       
   170 {
       
   171     m_dtmfService->stopDTMFPlay();
       
   172     QVERIFY (m_handleEndDTMFCalled == true);
       
   173 }
       
   174 
       
   175 QTEST_MAIN(TestDTMFService)
       
   176 #include "unit_tests.moc"