phoneapp/phoneuiview2/tsrc/ut_phoneuiqtview/unit_tests.cpp
branchGCC_SURGE
changeset 51 f39ed5e045e0
parent 30 ebdbd102c78a
parent 46 bc5a64e5bc3c
equal deleted inserted replaced
40:bab96b7ed1a4 51:f39ed5e045e0
    26 #include <hbmainwindow.h>
    26 #include <hbmainwindow.h>
    27 #include <hbinstance.h>
    27 #include <hbinstance.h>
    28 #include <hbmainwindow.h>
    28 #include <hbmainwindow.h>
    29 #include <bubblemanagerif.h>
    29 #include <bubblemanagerif.h>
    30 #define protected public
    30 #define protected public
       
    31 #define private public
    31 #include "phoneuiqtview.h"
    32 #include "phoneuiqtview.h"
    32 #undef public
    33 #undef public
    33 #include "phoneaction.h"
    34 #include "phoneaction.h"
    34 #include <hbtoolbar.h>
    35 #include <hbtoolbar.h>
    35 #include <hbvolumesliderpopup.h>
    36 #include <hbvolumesliderpopup.h>
    36 #include <hbaction.h>
    37 #include <hbaction.h>
       
    38 #include <dialpad.h>
       
    39 #include <hblineedit.h>
    37 #include "xqserviceutil.h"
    40 #include "xqserviceutil.h"
    38 #include "phoneaction.h"
    41 #include "phoneaction.h"
    39 
    42 
    40 //CONSTANTS
    43 //CONSTANTS
    41 static const int KMAXVOLUME = 10;
    44 static const int KMAXVOLUME = 10;
    92     void testShowDialpad();
    95     void testShowDialpad();
    93     void testDialpadText();
    96     void testDialpadText();
    94     void testSetMenuActions();
    97     void testSetMenuActions();
    95     void testLongEndKeyPressEventOutsideTelephony();
    98     void testLongEndKeyPressEventOutsideTelephony();
    96     void testNetworkNameChanged();
    99     void testNetworkNameChanged();
       
   100     void testCaptureKey();
       
   101     void testRestrictedMode();
    97 
   102 
    98 private:
   103 private:
    99     int createCallHeader();
   104     int createCallHeader();
   100 
   105 
   101 private:
   106 private:
   361 }
   366 }
   362 
   367 
   363 void TestPhoneUIQtView::testDialpadText()
   368 void TestPhoneUIQtView::testDialpadText()
   364 {
   369 {
   365     m_view->showDialpad();
   370     m_view->showDialpad();
       
   371     m_view->clearDialpad();
   366     QVERIFY(QString("") == m_view->dialpadText());
   372     QVERIFY(QString("") == m_view->dialpadText());
   367     m_view->clearAndHideDialpad();
   373     m_view->clearAndHideDialpad();
   368 }
   374 }
   369 
   375 
   370 void TestPhoneUIQtView::testSetMenuActions()
   376 void TestPhoneUIQtView::testSetMenuActions()
   403     QCOMPARE(spy.count(), 1);*/
   409     QCOMPARE(spy.count(), 1);*/
   404 }
   410 }
   405 
   411 
   406 void TestPhoneUIQtView::testNetworkNameChanged()
   412 void TestPhoneUIQtView::testNetworkNameChanged()
   407 {
   413 {
   408     // Title is changed only for GmsMode
   414     // Title is changed for GmsMode
   409     m_view->networkNameChanged(QSystemNetworkInfo::GsmMode, QString("test"));
   415     m_view->networkNameChanged(QSystemNetworkInfo::GsmMode, QString("test"));
   410     QCOMPARE(m_networkName, QString("test"));
   416     QCOMPARE(m_networkName, QString("test"));
   411 
   417 
       
   418     // Title is changed for WcdmaMode
       
   419     m_view->networkNameChanged(QSystemNetworkInfo::WcdmaMode, QString("test2"));
       
   420     QCOMPARE(m_networkName, QString("test2"));
       
   421 
   412     // Other modes shouldn't affect the title
   422     // Other modes shouldn't affect the title
   413     m_view->networkNameChanged(QSystemNetworkInfo::CdmaMode, QString("another operator"));
   423     m_view->networkNameChanged(QSystemNetworkInfo::CdmaMode, QString("another operator"));
   414     QCOMPARE(m_networkName, QString("test"));
   424     QCOMPARE(m_networkName, QString("test2"));
       
   425 }
       
   426 
       
   427 void TestPhoneUIQtView::testCaptureKey()
       
   428 {
       
   429     m_view->captureKey( Qt::Key_No, true );
       
   430     m_view->captureKey( Qt::Key_No, true );	
       
   431     m_view->captureKey( Qt::Key_Yes, false );
       
   432     m_view->captureKey( Qt::Key_No, false );
       
   433     m_view->captureKey( Qt::Key_No, false );		
       
   434 }
       
   435 
       
   436 void TestPhoneUIQtView::testRestrictedMode()
       
   437 {
       
   438     qRegisterMetaType<QKeyEvent*>("QKeyEvent*");
       
   439     QKeyEvent yesDown(QEvent::KeyPress, Qt::Key_Yes, Qt::NoModifier);
       
   440     QKeyEvent yesUp(QEvent::KeyRelease, Qt::Key_Yes, Qt::NoModifier);
       
   441     QKeyEvent oneDown(QEvent::KeyPress, Qt::Key_1, Qt::NoModifier);
       
   442     QKeyEvent oneUp(QEvent::KeyRelease, Qt::Key_1, Qt::NoModifier);
       
   443     QSignalSpy downSpy(m_view, SIGNAL(keyPressed(QKeyEvent*)));
       
   444     QSignalSpy upSpy(m_view, SIGNAL(keyReleased(QKeyEvent*)));
       
   445 
       
   446     m_view->setRestrictedMode(true);
       
   447     m_view->m_dialpad->editor().setText("1"); // emits signal
       
   448     QCOMPARE(m_view->m_dialpad->isCallButtonEnabled(), false);
       
   449     m_view->eventFilter(0, &oneDown);
       
   450     m_view->eventFilter(0, &oneUp);
       
   451     m_view->eventFilter(0, &yesDown);
       
   452     m_view->eventFilter(0, &yesUp);
       
   453     QCOMPARE(downSpy.count(), 1); // Only Key_1 is passed
       
   454     QCOMPARE(upSpy.count(), 1); // Only Key_1 is passed
       
   455     QCOMPARE(m_view->m_dialpad->isCallButtonEnabled(), false);
       
   456     QCOMPARE(m_view->m_backAction->isEnabled(), false);
       
   457     
       
   458     // Test backbutton
       
   459     m_view->setBackButtonVisible(true);
       
   460     QCOMPARE(m_view->m_backAction->isEnabled(), false);
       
   461 
       
   462     // Test return to normal mode
       
   463     downSpy.clear();
       
   464     upSpy.clear();
       
   465     m_view->setRestrictedMode(false);
       
   466     m_view->m_dialpad->editor().setText("1"); // emits signal
       
   467     QCOMPARE(m_view->m_dialpad->isCallButtonEnabled(), true);
       
   468     m_view->eventFilter(0, &oneDown);
       
   469     m_view->eventFilter(0, &oneUp);
       
   470     m_view->eventFilter(0, &yesDown);
       
   471     m_view->eventFilter(0, &yesUp);
       
   472     QCOMPARE(downSpy.count(), 2);
       
   473     QCOMPARE(upSpy.count(), 2);
       
   474     QCOMPARE(m_view->m_dialpad->isCallButtonEnabled(), true);
       
   475     QCOMPARE(m_view->m_backAction->isEnabled(), true);
   415 }
   476 }
   416 
   477 
   417 void HbView::setTitle (const QString &title)
   478 void HbView::setTitle (const QString &title)
   418 {
   479 {
   419     m_networkName = title;
   480     m_networkName = title;
   420 }
   481 }
       
   482 
   421 
   483 
   422 PHONE_QT_VIEW_TEST_MAIN(TestPhoneUIQtView)
   484 PHONE_QT_VIEW_TEST_MAIN(TestPhoneUIQtView)
   423 Q_DECLARE_METATYPE(QKeyEvent *)
   485 Q_DECLARE_METATYPE(QKeyEvent *)
   424 #include "unit_tests.moc"
   486 #include "unit_tests.moc"