phoneapp/phoneuiview2/tsrc/ut_phoneuiqtview/unit_tests.cpp
branchGCC_SURGE
changeset 51 f39ed5e045e0
parent 30 ebdbd102c78a
parent 46 bc5a64e5bc3c
--- a/phoneapp/phoneuiview2/tsrc/ut_phoneuiqtview/unit_tests.cpp	Tue Jun 15 14:14:38 2010 +0100
+++ b/phoneapp/phoneuiview2/tsrc/ut_phoneuiqtview/unit_tests.cpp	Thu Jul 22 16:33:21 2010 +0100
@@ -28,12 +28,15 @@
 #include <hbmainwindow.h>
 #include <bubblemanagerif.h>
 #define protected public
+#define private public
 #include "phoneuiqtview.h"
 #undef public
 #include "phoneaction.h"
 #include <hbtoolbar.h>
 #include <hbvolumesliderpopup.h>
 #include <hbaction.h>
+#include <dialpad.h>
+#include <hblineedit.h>
 #include "xqserviceutil.h"
 #include "phoneaction.h"
 
@@ -94,6 +97,8 @@
     void testSetMenuActions();
     void testLongEndKeyPressEventOutsideTelephony();
     void testNetworkNameChanged();
+    void testCaptureKey();
+    void testRestrictedMode();
 
 private:
     int createCallHeader();
@@ -363,6 +368,7 @@
 void TestPhoneUIQtView::testDialpadText()
 {
     m_view->showDialpad();
+    m_view->clearDialpad();
     QVERIFY(QString("") == m_view->dialpadText());
     m_view->clearAndHideDialpad();
 }
@@ -405,13 +411,68 @@
 
 void TestPhoneUIQtView::testNetworkNameChanged()
 {
-    // Title is changed only for GmsMode
+    // Title is changed for GmsMode
     m_view->networkNameChanged(QSystemNetworkInfo::GsmMode, QString("test"));
     QCOMPARE(m_networkName, QString("test"));
 
+    // Title is changed for WcdmaMode
+    m_view->networkNameChanged(QSystemNetworkInfo::WcdmaMode, QString("test2"));
+    QCOMPARE(m_networkName, QString("test2"));
+
     // Other modes shouldn't affect the title
     m_view->networkNameChanged(QSystemNetworkInfo::CdmaMode, QString("another operator"));
-    QCOMPARE(m_networkName, QString("test"));
+    QCOMPARE(m_networkName, QString("test2"));
+}
+
+void TestPhoneUIQtView::testCaptureKey()
+{
+    m_view->captureKey( Qt::Key_No, true );
+    m_view->captureKey( Qt::Key_No, true );	
+    m_view->captureKey( Qt::Key_Yes, false );
+    m_view->captureKey( Qt::Key_No, false );
+    m_view->captureKey( Qt::Key_No, false );		
+}
+
+void TestPhoneUIQtView::testRestrictedMode()
+{
+    qRegisterMetaType<QKeyEvent*>("QKeyEvent*");
+    QKeyEvent yesDown(QEvent::KeyPress, Qt::Key_Yes, Qt::NoModifier);
+    QKeyEvent yesUp(QEvent::KeyRelease, Qt::Key_Yes, Qt::NoModifier);
+    QKeyEvent oneDown(QEvent::KeyPress, Qt::Key_1, Qt::NoModifier);
+    QKeyEvent oneUp(QEvent::KeyRelease, Qt::Key_1, Qt::NoModifier);
+    QSignalSpy downSpy(m_view, SIGNAL(keyPressed(QKeyEvent*)));
+    QSignalSpy upSpy(m_view, SIGNAL(keyReleased(QKeyEvent*)));
+
+    m_view->setRestrictedMode(true);
+    m_view->m_dialpad->editor().setText("1"); // emits signal
+    QCOMPARE(m_view->m_dialpad->isCallButtonEnabled(), false);
+    m_view->eventFilter(0, &oneDown);
+    m_view->eventFilter(0, &oneUp);
+    m_view->eventFilter(0, &yesDown);
+    m_view->eventFilter(0, &yesUp);
+    QCOMPARE(downSpy.count(), 1); // Only Key_1 is passed
+    QCOMPARE(upSpy.count(), 1); // Only Key_1 is passed
+    QCOMPARE(m_view->m_dialpad->isCallButtonEnabled(), false);
+    QCOMPARE(m_view->m_backAction->isEnabled(), false);
+    
+    // Test backbutton
+    m_view->setBackButtonVisible(true);
+    QCOMPARE(m_view->m_backAction->isEnabled(), false);
+
+    // Test return to normal mode
+    downSpy.clear();
+    upSpy.clear();
+    m_view->setRestrictedMode(false);
+    m_view->m_dialpad->editor().setText("1"); // emits signal
+    QCOMPARE(m_view->m_dialpad->isCallButtonEnabled(), true);
+    m_view->eventFilter(0, &oneDown);
+    m_view->eventFilter(0, &oneUp);
+    m_view->eventFilter(0, &yesDown);
+    m_view->eventFilter(0, &yesUp);
+    QCOMPARE(downSpy.count(), 2);
+    QCOMPARE(upSpy.count(), 2);
+    QCOMPARE(m_view->m_dialpad->isCallButtonEnabled(), true);
+    QCOMPARE(m_view->m_backAction->isEnabled(), true);
 }
 
 void HbView::setTitle (const QString &title)
@@ -419,6 +480,7 @@
     m_networkName = title;
 }
 
+
 PHONE_QT_VIEW_TEST_MAIN(TestPhoneUIQtView)
 Q_DECLARE_METATYPE(QKeyEvent *)
 #include "unit_tests.moc"