phoneengine/phoneservices/tsrc/ut_dtmfservice/unit_tests.cpp
changeset 21 92ab7f8d0eab
child 30 ebdbd102c78a
equal deleted inserted replaced
4:c84cf270c54f 21:92ab7f8d0eab
       
     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 testExecuteKeySequence ();
       
    48     void testPlayDTMFTone ();
       
    49     void testStopDTMFPlay ();
       
    50 
       
    51 private:
       
    52     DTMFService *m_dtmfService; // class under test
       
    53     bool m_setPhoneNumberCalled;
       
    54     bool m_setCallTypeCommandCalled;
       
    55     bool m_handleDialCallCalled;
       
    56     TPEPhoneNumber m_phoneNumber;
       
    57     TPECallType m_callType;
       
    58     bool m_clientCall;
       
    59     int m_contactId;
       
    60     bool m_setContactIdCalled;
       
    61     bool m_handleEndDTMFCalled;
       
    62     bool m_handlePlayDTMFLCalled;
       
    63     bool m_setKeyCodeCalled;
       
    64     bool m_handlePlayDtmfLeave;
       
    65     ushort keyValue;
       
    66 };
       
    67 
       
    68 TestDTMFService::TestDTMFService ()
       
    69 {
       
    70 }
       
    71 
       
    72 TestDTMFService::~TestDTMFService ()
       
    73 {
       
    74 }
       
    75 
       
    76 void TestDTMFService::initTestCase ()
       
    77 {
       
    78 }
       
    79 
       
    80 void TestDTMFService::cleanupTestCase ()
       
    81 {
       
    82 }
       
    83 
       
    84 void TestDTMFService::init ()
       
    85 {
       
    86     m_setPhoneNumberCalled = false;
       
    87     m_setCallTypeCommandCalled = false;
       
    88     m_handleDialCallCalled = false;
       
    89     m_clientCall = false;
       
    90     m_setContactIdCalled = false;
       
    91     m_contactId = -1;
       
    92     m_handleEndDTMFCalled = false;
       
    93     m_handlePlayDTMFLCalled = false;
       
    94     m_setKeyCodeCalled = false;
       
    95     m_handlePlayDtmfLeave = false;
       
    96     keyValue = -1;
       
    97     m_dtmfService = new DTMFService (*this, *this, this);
       
    98 }
       
    99 
       
   100 void TestDTMFService::cleanup ()
       
   101 {
       
   102     delete m_dtmfService;
       
   103 }
       
   104 
       
   105 void TestDTMFService::SetKeyCode( const TChar& aKeyCode )
       
   106 {
       
   107     m_setKeyCodeCalled = true;
       
   108     keyValue = aKeyCode;
       
   109 }
       
   110 
       
   111 void TestDTMFService::SetPhoneNumber( const TPEPhoneNumber& aPhoneNumber )
       
   112 {
       
   113     m_setPhoneNumberCalled = true;
       
   114     m_phoneNumber = aPhoneNumber;	
       
   115 }
       
   116 
       
   117 void TestDTMFService::SetCallTypeCommand( const TPECallType& aCallType )
       
   118 {
       
   119     m_setCallTypeCommandCalled = true;
       
   120     m_callType = aCallType;	
       
   121 }
       
   122 
       
   123 void TestDTMFService::HandlePlayDTMFL()
       
   124 {
       
   125     m_handlePlayDTMFLCalled = true;
       
   126     
       
   127     if (m_handlePlayDtmfLeave)
       
   128         User::Leave(KErrNotFound);
       
   129 }
       
   130 
       
   131 TInt TestDTMFService::HandleEndDTMF()
       
   132 {
       
   133     m_handleEndDTMFCalled = true;
       
   134     return 0;
       
   135 }
       
   136 
       
   137 void TestDTMFService::SetContactId2( const TInt aContactId )
       
   138 {
       
   139     m_setContactIdCalled = true;
       
   140     m_contactId = aContactId;	
       
   141 }
       
   142 
       
   143 void TestDTMFService::SetServiceIdCommand( TUint32 aServiceId )
       
   144 {
       
   145 
       
   146 }
       
   147 
       
   148 TInt TestDTMFService::HandleDialServiceCall( const TBool aClientCall )
       
   149 {
       
   150     m_handleDialCallCalled = true;
       
   151     m_clientCall = aClientCall;
       
   152     return KErrNone;
       
   153 }
       
   154 
       
   155 void TestDTMFService::testExecuteKeySequence()
       
   156 {
       
   157     m_dtmfService->executeKeySequence(QString("*#0000#"));
       
   158     QString keySequence((QChar*)m_phoneNumber.Ptr(), m_phoneNumber.Length());
       
   159     QVERIFY (m_setPhoneNumberCalled == true);
       
   160     QCOMPARE (keySequence, QString("*#0000#"));
       
   161 }
       
   162 
       
   163 void TestDTMFService::testPlayDTMFTone()
       
   164 {
       
   165     QChar six('6');
       
   166     m_dtmfService->playDTMFTone(six);
       
   167     QVERIFY (m_setKeyCodeCalled == true);
       
   168     QCOMPARE (keyValue, six.unicode());
       
   169     QVERIFY (m_handlePlayDTMFLCalled == true);
       
   170     
       
   171     m_handlePlayDtmfLeave = true;
       
   172     
       
   173     TRAP_IGNORE(m_dtmfService->playDTMFTone(six));
       
   174     
       
   175     m_handlePlayDtmfLeave = false;
       
   176 }
       
   177 
       
   178 void TestDTMFService::testStopDTMFPlay()
       
   179 {
       
   180     m_dtmfService->stopDTMFPlay();
       
   181     QVERIFY (m_handleEndDTMFCalled == true);
       
   182 }
       
   183 
       
   184 QTEST_MAIN(TestDTMFService)
       
   185 #include "unit_tests.moc"