phoneengine/phoneservices/tsrc/ut_dtmfservice/unit_tests.cpp
changeset 77 2be0b271d017
parent 37 ba76fc04e6c2
child 76 cfea66083b62
equal deleted inserted replaced
72:c76a0b1755b9 77:2be0b271d017
    14 * Description:  Unit tests for DTMFService.
    14 * Description:  Unit tests for DTMFService.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <QtTest/QtTest>
    18 #include <QtTest/QtTest>
    19 
    19 #include <csmcmockcontext.h>
    20 //#include <hbglobal_p.h>
    20 #include <smcdefaultvalue.h>
       
    21 #include <msmcmockspecbuilder.h>
       
    22 #include <smcobjecttotypemapper.h>
       
    23 #include <mockservice.h>
    21 #include "dtmfservice.h"
    24 #include "dtmfservice.h"
    22 
    25 #include "qtestmains60.h"
    23 class TestDTMFService : public QObject, public MPECallControlIF, public MPECallSettersIF
    26 
       
    27 typedef QSet<int> IntegerSet;
       
    28 
       
    29 class TestDTMFService : public QObject, public MPECallControlIF, public MPECallSettersIF, public MockService
    24 {
    30 {
    25     Q_OBJECT
    31     Q_OBJECT
    26 public:
    32 public:
    27     TestDTMFService();
    33     TestDTMFService();
    28     virtual ~TestDTMFService();    
    34     virtual ~TestDTMFService();    
    44     void SetServiceIdCommand( TUint32 aServiceId );
    50     void SetServiceIdCommand( TUint32 aServiceId );
    45     
    51     
    46 private slots:
    52 private slots:
    47     void testPlayDTMFTone ();
    53     void testPlayDTMFTone ();
    48     void testStopDTMFPlay ();
    54     void testStopDTMFPlay ();
       
    55     void testPlayDTMFTone_nocaps();
    49 
    56 
    50 private:
    57 private:
    51     DTMFService *m_dtmfService; // class under test
    58     DTMFService *m_dtmfService; // class under test
    52     bool m_setPhoneNumberCalled;
    59     bool m_setPhoneNumberCalled;
    53     bool m_setCallTypeCommandCalled;
    60     bool m_setCallTypeCommandCalled;
    60     bool m_handleEndDTMFCalled;
    67     bool m_handleEndDTMFCalled;
    61     bool m_handlePlayDTMFLCalled;
    68     bool m_handlePlayDTMFLCalled;
    62     bool m_setKeyCodeCalled;
    69     bool m_setKeyCodeCalled;
    63     bool m_handlePlayDtmfLeave;
    70     bool m_handlePlayDtmfLeave;
    64     ushort keyValue;
    71     ushort keyValue;
       
    72     XQRequestInfo m_XQRequestInfoMock;
    65 };
    73 };
    66 
    74 
    67 TestDTMFService::TestDTMFService ()
    75 TestDTMFService::TestDTMFService ()
    68 {
    76 {
    69 }
    77 }
    80 {
    88 {
    81 }
    89 }
    82 
    90 
    83 void TestDTMFService::init ()
    91 void TestDTMFService::init ()
    84 {
    92 {
       
    93     initialize();
       
    94     IntegerSet caps;
       
    95     caps.insert(ECapabilityNetworkServices);
       
    96     caps.insert(ECapabilityNetworkControl);
       
    97     SmcDefaultValue<IntegerSet>::SetL(caps);
       
    98     SmcDefaultValue<XQRequestInfo>::SetL(m_XQRequestInfoMock);
       
    99 
    85     m_setPhoneNumberCalled = false;
   100     m_setPhoneNumberCalled = false;
    86     m_setCallTypeCommandCalled = false;
   101     m_setCallTypeCommandCalled = false;
    87     m_handleDialCallCalled = false;
   102     m_handleDialCallCalled = false;
    88     m_clientCall = false;
   103     m_clientCall = false;
    89     m_setContactIdCalled = false;
   104     m_setContactIdCalled = false;
    96     m_dtmfService = new DTMFService (*this, *this, this);
   111     m_dtmfService = new DTMFService (*this, *this, this);
    97 }
   112 }
    98 
   113 
    99 void TestDTMFService::cleanup ()
   114 void TestDTMFService::cleanup ()
   100 {
   115 {
       
   116     SmcDefaultValue<IntegerSet>::Reset();
       
   117     SmcDefaultValue<XQRequestInfo>::Reset();
       
   118     reset();
   101     delete m_dtmfService;
   119     delete m_dtmfService;
   102 }
   120 }
   103 
   121 
   104 void TestDTMFService::SetKeyCode( const TChar& aKeyCode )
   122 void TestDTMFService::SetKeyCode( const TChar& aKeyCode )
   105 {
   123 {
   148 {
   166 {
   149     m_handleDialCallCalled = true;
   167     m_handleDialCallCalled = true;
   150     m_clientCall = aClientCall;
   168     m_clientCall = aClientCall;
   151     return KErrNone;
   169     return KErrNone;
   152 }
   170 }
       
   171 
       
   172 // Test cases
   153 
   173 
   154 void TestDTMFService::testPlayDTMFTone()
   174 void TestDTMFService::testPlayDTMFTone()
   155 {
   175 {
   156     QChar six('6');
   176     QChar six('6');
   157     m_dtmfService->playDTMFTone(six);
   177     m_dtmfService->playDTMFTone(six);
   170 {
   190 {
   171     m_dtmfService->stopDTMFPlay();
   191     m_dtmfService->stopDTMFPlay();
   172     QVERIFY (m_handleEndDTMFCalled == true);
   192     QVERIFY (m_handleEndDTMFCalled == true);
   173 }
   193 }
   174 
   194 
   175 QTEST_MAIN(TestDTMFService)
   195 void TestDTMFService::testPlayDTMFTone_nocaps()
       
   196 {
       
   197     QSet<int> caps;
       
   198     expect( "XQRequestInfo::clientCapabilities" ).
       
   199         returns(caps).
       
   200         times(2);
       
   201     QChar six('6');
       
   202     int ret = m_dtmfService->playDTMFTone(six);
       
   203     QVERIFY (ret == KErrPermissionDenied);
       
   204     ret = m_dtmfService->stopDTMFPlay();
       
   205     QVERIFY (ret == KErrPermissionDenied);
       
   206     
       
   207     QVERIFY( verify() );
       
   208 }
       
   209 
       
   210 
       
   211 QTEST_MAIN_S60(TestDTMFService)
   176 #include "unit_tests.moc"
   212 #include "unit_tests.moc"
       
   213