phoneapp/phoneuiview2/tsrc/ut_phoneuiqtview/unit_tests.cpp
changeset 78 baacf668fe89
parent 76 cfea66083b62
equal deleted inserted replaced
76:cfea66083b62 78:baacf668fe89
    14 * Description:  Unit tests for PhoneUIQtView.
    14 * Description:  Unit tests for PhoneUIQtView.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <QtTest/QtTest>
    18 #include <QtTest/QtTest>
       
    19 #include <mockservice.h>
    19 #include <QtGui>
    20 #include <QtGui>
    20 #include <QVariant>
    21 #include <QVariant>
    21 #include <QKeyEvent>
    22 #include <QKeyEvent>
    22 #include <QTimer>
    23 #include <QTimer>
    23 #include <QShortcutEvent>
    24 #include <QShortcutEvent>
    25 #include <hbapplication.h>
    26 #include <hbapplication.h>
    26 #include <hbmainwindow.h>
    27 #include <hbmainwindow.h>
    27 #include <hbinstance.h>
    28 #include <hbinstance.h>
    28 #include <hbmainwindow.h>
    29 #include <hbmainwindow.h>
    29 #include <bubblemanagerif.h>
    30 #include <bubblemanagerif.h>
    30 #define protected public
    31 #include "phoneuiqtview_p.h"
    31 #define private public
       
    32 #include "phoneuiqtview.h"
       
    33 #undef public
       
    34 #include "phoneaction.h"
       
    35 #include <hbtoolbar.h>
    32 #include <hbtoolbar.h>
    36 #include <hbvolumesliderpopup.h>
    33 #include <hbvolumesliderpopup.h>
    37 #include <hbaction.h>
    34 #include <hbaction.h>
    38 #include <dialpad.h>
    35 #include <dialpad.h>
    39 #include <hblineedit.h>
    36 #include <hblineedit.h>
    40 #include "xqserviceutil.h"
    37 #include "xqserviceutil.h"
    41 #include "phoneaction.h"
    38 #define private public
       
    39 #include "phoneuiqtview.h"
    42 
    40 
    43 //CONSTANTS
    41 //CONSTANTS
    44 static const int KMAXVOLUME = 10;
    42 static const int KMAXVOLUME = 10;
    45 static const int KMINVOLUME = 0;
    43 static const int KMINVOLUME = 0;
    46 static const int KVOLUMECOMMAND = 5;
    44 static const int KVOLUMECOMMAND = 5;
    47 
    45 
    48 bool m_qtimer_stop_called;
       
    49 QString m_networkName;
       
    50 bool m_take_menu_called;
       
    51 bool m_set_menu_called;
       
    52 
       
    53 #define PHONE_QT_VIEW_TEST_MAIN(TestObject) \
    46 #define PHONE_QT_VIEW_TEST_MAIN(TestObject) \
    54 int main(int argc, char *argv[]) \
    47 int main(int argc, char *argv[]) \
    55 { \
    48 { \
    56     HbApplication app(argc, argv); \
    49     QCoreApplication app(argc, argv); \
    57     TestObject tc; \
    50     TestObject tc; \
    58     QResource::registerResource("../hbcore.rcc"); \
    51     QResource::registerResource("../hbcore.rcc"); \
    59     int ret = QTest::qExec(&tc, argc, argv); \
    52     int ret = QTest::qExec(&tc, argc, argv); \
    60     /* Core dump if HbIconLoader instance is not destroyed before the application instance. */ \
    53     /* Core dump if HbIconLoader instance is not destroyed before the application instance. */ \
    61     /* HbIconLoader uses QCoreApplication::aboutToQuit() signal to destroy itself. */ \
    54     /* HbIconLoader uses QCoreApplication::aboutToQuit() signal to destroy itself. */ \
    63     /* So, invoking the signal explicitly. */ \
    56     /* So, invoking the signal explicitly. */ \
    64     QMetaObject::invokeMethod(&app, "aboutToQuit", Qt::DirectConnection); \
    57     QMetaObject::invokeMethod(&app, "aboutToQuit", Qt::DirectConnection); \
    65     return ret; \
    58     return ret; \
    66 }
    59 }
    67 
    60 
    68 class TestPhoneUIQtView : public QObject
    61 class TestPhoneUIQtView : public QObject, public MockService
    69 {
    62 {
    70     Q_OBJECT
    63     Q_OBJECT
    71     
    64     
    72 public:
    65 public:
    73     TestPhoneUIQtView ();
    66     TestPhoneUIQtView ();
    89     void testRemoveVolumeSlider ();
    82     void testRemoveVolumeSlider ();
    90     void testVolumeSliderValue ();
    83     void testVolumeSliderValue ();
    91     void testVolumeSliderChanged ();
    84     void testVolumeSliderChanged ();
    92     void testParticipantListAction ();
    85     void testParticipantListAction ();
    93     void testSetExpandAction ();
    86     void testSetExpandAction ();
    94     void testPhoneAction ();
       
    95     void testSetOrientation ();
    87     void testSetOrientation ();
    96     void testBackButtonClicked();
    88     void testBackButtonClicked();
    97     void testShowDialpad();
    89     void testShowDialpad();
    98     void testDialpadText();
    90     void testDialpadText();
    99     void testSetMenuActions();
    91     void testSetMenuActions();
   107     int createCallHeader();
    99     int createCallHeader();
   108 
   100 
   109 private:
   101 private:
   110     PhoneUIQtView *m_view; // class under test
   102     PhoneUIQtView *m_view; // class under test
   111     HbMainWindow *m_main_window;
   103     HbMainWindow *m_main_window;
   112 
   104     HbLineEdit *m_lineEdit;
       
   105     HbToolBar *m_toolBar;
   113 };
   106 };
   114 
   107 
   115 void QTimer::stop()
       
   116 {
       
   117     m_qtimer_stop_called = true;   
       
   118 }
       
   119     
       
   120 TestPhoneUIQtView::TestPhoneUIQtView ()
   108 TestPhoneUIQtView::TestPhoneUIQtView ()
   121 {    
   109 {
       
   110 
   122 }
   111 }
   123 
   112 
   124 TestPhoneUIQtView::~TestPhoneUIQtView ()
   113 TestPhoneUIQtView::~TestPhoneUIQtView ()
   125 {
   114 {
   126 }
   115 }
   127 
   116 
   128 void TestPhoneUIQtView::initTestCase ()
   117 void TestPhoneUIQtView::initTestCase ()
   129 {	
   118 {	
   130     m_main_window = new HbMainWindow();
   119     m_main_window = new HbMainWindow();
       
   120     m_lineEdit = new HbLineEdit();
       
   121     m_toolBar = new HbToolBar();
       
   122     SmcDefaultValue<QPointF>::SetL(QPointF(0, 0));
       
   123     SmcDefaultValue<QRectF>::SetL(QRectF(0, 0, 0, 0));
       
   124     SmcDefaultValue<QVariant>::SetL(QVariant(0));
       
   125     SmcDefaultValue<Qt::Orientation>::SetL(Qt::Horizontal);
       
   126     SmcDefaultValue<HbLineEdit *>::SetL(m_lineEdit);
       
   127     SmcDefaultValue<HbLineEdit &>::SetL(*m_lineEdit);
       
   128     
       
   129     EXPECT(HbView, setTitle).with(QString("Unit test network"));
       
   130     EXPECT(QtMobility::QSystemNetworkInfo, networkName).returns(QString("Unit test network"));
   131     m_view = new PhoneUIQtView(*m_main_window);
   131     m_view = new PhoneUIQtView(*m_main_window);
   132     QCOMPARE(m_networkName, QString("Unit test network"));
   132     QVERIFY(verify());
   133 }
   133 }
   134 
   134 
   135 void TestPhoneUIQtView::cleanupTestCase ()
   135 void TestPhoneUIQtView::cleanupTestCase ()
   136 {
   136 {
       
   137     SmcDefaultValue<QPointF>::Reset();
       
   138     SmcDefaultValue<QRectF>::Reset();
       
   139     SmcDefaultValue<QVariant>::Reset();
       
   140     SmcDefaultValue<Qt::Orientation>::Reset();
       
   141     SmcDefaultValue<HbLineEdit *>::Reset();
       
   142     SmcDefaultValue<HbLineEdit &>::Reset();
   137     delete m_view;
   143     delete m_view;
   138 }
   144     delete m_lineEdit;
   139 
   145     delete m_toolBar;
   140 void TestPhoneUIQtView::init ()
   146     delete m_main_window;
   141 {
   147 }
   142     m_qtimer_stop_called = false;
   148 
   143     m_take_menu_called = false;
   149 void TestPhoneUIQtView::init()
   144     m_set_menu_called = false;
   150 {
       
   151     initialize();
   145 }
   152 }
   146 
   153 
   147 void TestPhoneUIQtView::cleanup ()
   154 void TestPhoneUIQtView::cleanup ()
   148 {
   155 {
       
   156     reset();
   149 }
   157 }
   150 
   158 
   151 void TestPhoneUIQtView::testAddBubbleCommand ()
   159 void TestPhoneUIQtView::testAddBubbleCommand ()
   152 {
   160 {
   153     m_view->bubbleManager ().startChanges ();
   161     m_view->bubbleManager().startChanges();
   154     int bubbleId = createCallHeader();
   162     int bubbleId = createCallHeader();
   155     int bubbleId2 = createCallHeader();
   163     int bubbleId2 = createCallHeader();
   156     
   164     
   157     PhoneAction action1;
   165     HbAction *action1 = new HbAction;
   158     action1.setText("Command 1");
   166     action1->setText("Command 1");
   159     action1.setCommand(1);
   167     action1->setProperty("command", 1);
   160     action1.setActionRole(PhoneAction::None);
   168     action1->setSoftKeyRole(QAction::NoSoftKey);
   161     
   169     
   162     PhoneAction action2;
   170     HbAction *action2 = new HbAction;
   163     action2.setText("Command 2");
   171     action2->setText("Command 2");
   164     action2.setCommand(2);
   172     action2->setProperty("command", 2);
   165     action2.setActionRole(PhoneAction::Accept);
   173     action2->setSoftKeyRole(QAction::PositiveSoftKey);
   166     
   174     
   167     PhoneAction action3;
   175     HbAction *action3 = new HbAction;
   168     action3.setText("Command 3");
   176     action3->setText("Command 3");
   169     action3.setCommand(3);
   177     action3->setProperty("command", 3);
   170     action3.setActionRole(PhoneAction::Decline);
   178     action3->setSoftKeyRole(QAction::NegativeSoftKey);
   171     
   179     
   172     m_view->addBubbleCommand (bubbleId, action1);
   180     m_view->addBubbleCommand(bubbleId, action1);
   173     m_view->addBubbleCommand (bubbleId, action2);
   181     m_view->addBubbleCommand(bubbleId, action2);
   174     m_view->addBubbleCommand (bubbleId2, action3);
   182     m_view->addBubbleCommand(bubbleId2, action3);
   175     m_view->bubbleManager ().endChanges ();
   183     m_view->bubbleManager().endChanges();
   176     
   184     
   177     m_view->bubbleManager ().startChanges ();
   185     m_view->bubbleManager().startChanges();
   178     m_view->clearBubbleCommands (bubbleId);
   186     m_view->clearBubbleCommands(bubbleId);
   179     m_view->clearBubbleCommands (bubbleId2);
   187     m_view->clearBubbleCommands(bubbleId2);
   180     m_view->clearBubbleCommands (bubbleId2);
   188     m_view->clearBubbleCommands(bubbleId2);
   181     m_view->bubbleManager ().endChanges ();
   189     m_view->bubbleManager().endChanges();
   182 }
   190 }
   183 
   191 
   184 void TestPhoneUIQtView::testHideToolbar ()
   192 void TestPhoneUIQtView::testHideToolbar ()
   185 {
   193 {
   186     m_view->hideToolbar ();
   194     EXPECT(HbView, toolBar).returns(m_toolBar);
   187     QCOMPARE (m_hideCalled, true);	
   195     m_view->hideToolbar();
       
   196     QVERIFY(verify());
   188 }
   197 }
   189 
   198 
   190 void TestPhoneUIQtView::testShowToolbar ()
   199 void TestPhoneUIQtView::testShowToolbar ()
   191 {
   200 {
   192     m_view->showToolbar ();
   201     EXPECT(HbView, toolBar).returns(m_toolBar);
   193     QCOMPARE (m_showCalled, true);
   202     m_view->showToolbar();
       
   203     QVERIFY(verify());
   194 }
   204 }
   195 
   205 
   196 void TestPhoneUIQtView::testAddToolbarActions ()
   206 void TestPhoneUIQtView::testAddToolbarActions ()
   197 {
   207 {
   198     m_actions.clear();
       
   199     HbIcon icon ("foo.jpg");
   208     HbIcon icon ("foo.jpg");
   200     PhoneAction *testAction = new PhoneAction ();
   209     HbAction *testAction = new HbAction ();
   201     testAction->setIcon(icon);
   210     testAction->setIcon(icon);
   202     testAction->setText("foo");
   211     testAction->setText("foo");
   203     testAction->setCommand(20);
   212     testAction->setProperty("command", 20);
   204     QList<PhoneAction*> actions;
   213     QList<HbAction*> actions;
       
   214     QList<QAction *> retActions;
       
   215     EXPECT(QGraphicsWidget, actions).returns(retActions);
   205     actions.append(testAction);
   216     actions.append(testAction);
   206     
   217     
   207     m_view->setToolbarActions(actions);
   218     m_view->setToolbarActions(actions);
   208     QCOMPARE (m_action->icon(), icon);
   219     //QCOMPARE (m_action->icon(), icon);
   209     QCOMPARE(true, m_toolBarUpdateCalled);
   220     //QCOMPARE(true, m_toolBarUpdateCalled);
   210     
   221     
       
   222     actions[0] = new HbAction();
       
   223     EXPECT(QGraphicsWidget, actions).returns(retActions);
   211     m_view->setToolbarActions(actions);
   224     m_view->setToolbarActions(actions);
   212     
   225     
   213     m_toolBarUpdateCalled = false;
   226     EXPECT(QGraphicsItem, update);
   214     PhoneAction *testAction2 = new PhoneAction ();
   227     HbAction *testAction2 = new HbAction ();
   215     testAction2->setIcon(icon);
   228     testAction2->setIcon(icon);
   216     testAction2->setText("foo2");
   229     testAction2->setText("foo2");
   217     testAction2->setCommand(21);
   230     testAction2->setProperty("command", 21);
       
   231     actions[0] = new HbAction();
   218     actions.append(testAction2);
   232     actions.append(testAction2);
   219     
   233     
       
   234     EXPECT(QGraphicsWidget, actions).returns(retActions);
   220     m_view->setToolbarActions(actions);
   235     m_view->setToolbarActions(actions);
   221     QCOMPARE(true, m_toolBarUpdateCalled);
   236     QVERIFY(verify());
   222     actions.removeOne(testAction2);
   237     actions.removeOne(testAction2);
   223     
   238     
   224     m_toolBarUpdateCalled = false;
   239     EXPECT(QGraphicsItem, update);
       
   240     actions[0] = new HbAction();
       
   241     EXPECT(QGraphicsWidget, actions).returns(retActions);
   225     m_view->setToolbarActions(actions);
   242     m_view->setToolbarActions(actions);
   226     QCOMPARE(true, m_toolBarUpdateCalled);
   243     QVERIFY(verify());
   227     
   244     
   228     actions.clear();
   245     actions.clear();
   229     delete testAction;
       
   230     delete testAction2;
       
   231 }
   246 }
   232 
   247 
   233 void TestPhoneUIQtView::testSetVolumeSliderValue ()
   248 void TestPhoneUIQtView::testSetVolumeSliderValue ()
   234 {
   249 {
   235     m_view->setVolumeSliderValue (1, KVOLUMECOMMAND, KMAXVOLUME, KMINVOLUME);
   250     EXPECT(HbPopup, setDismissPolicy).with(HbDialog::TapOutside);
   236     QCOMPARE (m_volumeSliderContructorCalled, true);
   251     EXPECT(HbPopup, setTimeout).with(10000);
   237     QCOMPARE (m_sliderRangeMin, KMINVOLUME);
   252     EXPECT(HbSliderPopup, minimum).returns(0);
   238     QCOMPARE (m_sliderRangeMax, KMAXVOLUME);
   253     EXPECT(HbSliderPopup, maximum).returns(100);
   239     QCOMPARE (m_volumeSliderSetTimeoutCalled, true);
   254     EXPECT(HbSliderPopup, setRange).with(KMINVOLUME, KMAXVOLUME);
   240     QCOMPARE (m_sliderTimeout, 10000);
   255     EXPECT(HbSliderPopup, setValue).with(1);
   241     QCOMPARE (m_volumeSliderSetValueCalled, true);
   256     EXPECT(QGraphicsItem, isVisible).returns(false);
   242     QCOMPARE (m_sliderValue, 1);
   257     //EXPECT(QGraphicsItem, show);
   243     QCOMPARE (m_volumeSliderShowCalled, true);
   258     m_view->setVolumeSliderValue(1, KVOLUMECOMMAND, KMAXVOLUME, KMINVOLUME);
   244     
   259 
   245     // reset values
   260     QVERIFY(verify());
   246     m_volumeSliderContructorCalled = false;
   261     reset();
   247     m_volumeSliderSetValueCalled = false;
   262     
   248     m_sliderRangeMin = -1;
       
   249     m_sliderRangeMax = -1;
       
   250     m_volumeSliderSetTimeoutCalled = false;
       
   251     m_sliderTimeout = -1;
       
   252     m_volumeSliderSetValueCalled = false;
       
   253     m_sliderValue = -1;
       
   254     m_volumeSliderShowCalled = false;
       
   255 
       
   256     // The second call shouldn't create a new instance
   263     // The second call shouldn't create a new instance
       
   264     EXPECT(HbPopup, setDismissPolicy).with(HbDialog::TapOutside).times(0);
       
   265     EXPECT(HbPopup, setTimeout).with(10000).times(0);
       
   266     EXPECT(HbSliderPopup, minimum).returns(0);
       
   267     EXPECT(HbSliderPopup, maximum).returns(100);
       
   268     EXPECT(HbSliderPopup, setRange).with(KMINVOLUME, KMAXVOLUME);
       
   269     EXPECT(HbSliderPopup, setValue).with(2);
       
   270     EXPECT(QGraphicsItem, isVisible).returns(true);
       
   271     //EXPECT(QGraphicsItem, show).times(0);
   257     m_view->setVolumeSliderValue (2, KVOLUMECOMMAND, KMAXVOLUME, KMINVOLUME);
   272     m_view->setVolumeSliderValue (2, KVOLUMECOMMAND, KMAXVOLUME, KMINVOLUME);
   258     QCOMPARE (m_volumeSliderContructorCalled, false);
   273     
   259     QCOMPARE (m_sliderRangeMin, KMINVOLUME);
   274     QVERIFY(verify());
   260     QCOMPARE (m_sliderRangeMax, KMAXVOLUME);
       
   261     QCOMPARE (m_volumeSliderSetTimeoutCalled, false);
       
   262     QCOMPARE (m_sliderTimeout, -1);
       
   263     QCOMPARE (m_volumeSliderSetValueCalled, true);
       
   264     QCOMPARE (m_sliderValue, 2);
       
   265     QCOMPARE (m_volumeSliderShowCalled, false);
       
   266 }
   275 }
   267 
   276 
   268 void TestPhoneUIQtView::testRemoveVolumeSlider ()
   277 void TestPhoneUIQtView::testRemoveVolumeSlider ()
   269 {
   278 {
       
   279     //EXPECT(QGraphicsItem, hide);
   270     m_view->setVolumeSliderValue (1, KVOLUMECOMMAND, KMAXVOLUME, KMINVOLUME);
   280     m_view->setVolumeSliderValue (1, KVOLUMECOMMAND, KMAXVOLUME, KMINVOLUME);
   271     m_view->removeVolumeSlider ();
   281     m_view->removeVolumeSlider ();
   272     QCOMPARE (m_volumeSliderHideCalled, true);
   282     QVERIFY(verify());
   273 }
   283 }
   274 
   284 
   275 void TestPhoneUIQtView::testVolumeSliderValue ()
   285 void TestPhoneUIQtView::testVolumeSliderValue ()
   276 {
   286 {
   277     m_sliderValue = -1;
   287     EXPECT(HbSliderPopup, value).returns(4);
   278     int value = m_view->volumeSliderValue ();
   288     int value = m_view->volumeSliderValue();
   279     QCOMPARE (m_sliderValue, -1);
   289     QCOMPARE (value, -1);
   280     m_view->setVolumeSliderValue (3, KVOLUMECOMMAND, KMAXVOLUME, KMINVOLUME);
   290     
   281     value = m_view->volumeSliderValue ();
   291     // Create slider
   282     QCOMPARE (m_volumeSliderValueCalled, true);
   292     m_view->setVolumeSliderValue (1, KVOLUMECOMMAND, KMAXVOLUME, KMINVOLUME);
       
   293     
       
   294     EXPECT(HbSliderPopup, value).returns(7);
       
   295     value = m_view->volumeSliderValue();
       
   296     QCOMPARE (value, 7);
       
   297     
       
   298     EXPECT(HbSliderPopup, value).returns(3);
       
   299     value = m_view->volumeSliderValue();
   283     QCOMPARE (value, 3);
   300     QCOMPARE (value, 3);
   284 }
   301 }
   285 
   302 
   286 void TestPhoneUIQtView::testVolumeSliderChanged ()
   303 void TestPhoneUIQtView::testVolumeSliderChanged ()
   287 {
   304 {
   288     m_view->setVolumeSliderValue (3, KVOLUMECOMMAND, KMAXVOLUME, KMINVOLUME);
   305     m_view->setVolumeSliderValue(3, KVOLUMECOMMAND, KMAXVOLUME, KMINVOLUME);
   289     QSignalSpy spy (m_view, SIGNAL(command(int)));
   306     QSignalSpy spy(m_view, SIGNAL(command(int)));
   290     m_view->volumeSliderChanged (1);
   307     m_view->m_priv->volumeSliderChanged(1);
   291     QCOMPARE (spy.count(), 1);
   308     QCOMPARE(spy.count(), 1);
   292     int command = qvariant_cast<int>(spy.at (0).at (0));
   309     int command = qvariant_cast<int>(spy.at(0).at(0));
   293     QCOMPARE (command, (int)KVOLUMECOMMAND);
   310     QCOMPARE(command, (int)KVOLUMECOMMAND);
   294 }
   311 }
   295 
   312 
   296 void TestPhoneUIQtView::testParticipantListAction ()
   313 void TestPhoneUIQtView::testParticipantListAction ()
   297 {
   314 {
   298     m_view->bubbleManager ().startChanges ();
   315     m_view->bubbleManager ().startChanges ();
   322     m_view->bubbleManager().removeCallHeader(bubbleId);
   339     m_view->bubbleManager().removeCallHeader(bubbleId);
   323     m_view->bubbleManager().removeCallHeader(bubbleId2);
   340     m_view->bubbleManager().removeCallHeader(bubbleId2);
   324     m_view->bubbleManager ().endChanges ();
   341     m_view->bubbleManager ().endChanges ();
   325 }
   342 }
   326 
   343 
   327 void TestPhoneUIQtView::testPhoneAction ()
       
   328 {
       
   329     PhoneAction *action = new PhoneAction ();
       
   330     QString string("Action");
       
   331     action->setText(string);
       
   332     HbIcon icon;
       
   333     action->setIcon(icon);
       
   334     int commandId(1);
       
   335     action->setCommand(commandId);
       
   336     action->setDisabled(true);
       
   337     QCOMPARE( string, action->text() );
       
   338     QCOMPARE( icon, action->icon() );
       
   339     QCOMPARE( commandId, action->command() );
       
   340     QCOMPARE( true, action->isDisabled() );
       
   341     delete action;
       
   342 }
       
   343 
       
   344 void TestPhoneUIQtView::testSetOrientation ()
   344 void TestPhoneUIQtView::testSetOrientation ()
   345 {
   345 {
   346 
   346     EXPECT(HbToolBar, setOrientation).times(0);
   347     m_setOrientationCalled = false;
       
   348     
       
   349     m_view->handleOrientationChange(Qt::Vertical);
   347     m_view->handleOrientationChange(Qt::Vertical);
   350     QVERIFY( false == m_setOrientationCalled );
   348     QVERIFY(verify());
   351     
   349     
       
   350     reset(); // Reset mock framework
       
   351     EXPECT(HbToolBar, setOrientation).times(1);
   352     m_view->handleOrientationChange(Qt::Horizontal);
   352     m_view->handleOrientationChange(Qt::Horizontal);
   353     QVERIFY( true == m_setOrientationCalled );
   353     QVERIFY(verify());
   354     
       
   355 }
   354 }
   356 
   355 
   357 void TestPhoneUIQtView::testBackButtonClicked()
   356 void TestPhoneUIQtView::testBackButtonClicked()
   358 {
   357 {
   359     // not possible to mock xqservice because it is in \epoc32\include
   358     // not possible to mock xqservice because it is in \epoc32\include
   361     // m_view->backButtonClicked();
   360     // m_view->backButtonClicked();
   362 }
   361 }
   363 
   362 
   364 void TestPhoneUIQtView::testShowDialpad()
   363 void TestPhoneUIQtView::testShowDialpad()
   365 {
   364 {
       
   365     EXPECT(QGraphicsItem, isVisible).returns(true);
       
   366     EXPECT(Dialpad, closeDialpad);
   366     m_view->hideDialpad();
   367     m_view->hideDialpad();
       
   368     QVERIFY(verify());
       
   369 
       
   370     EXPECT(QGraphicsItem, isVisible).returns(false);
       
   371     EXPECT(Dialpad, openDialpad);
   367     m_view->showDialpad();
   372     m_view->showDialpad();
       
   373     QVERIFY(verify());
       
   374     
       
   375     reset();
       
   376     EXPECT(QGraphicsItem, isVisible).returns(true);
       
   377     EXPECT(Dialpad, openDialpad).times(0);
   368     m_view->showDialpad();
   378     m_view->showDialpad();
   369     QVERIFY(true == m_view->isDialpadVisible());
   379     QVERIFY(verify());
       
   380     
       
   381     EXPECT(Dialpad, closeDialpad);
       
   382     EXPECT(QGraphicsItem, isVisible).returns(true);
   370     m_view->hideDialpad();
   383     m_view->hideDialpad();
       
   384     QVERIFY(verify());
   371 }
   385 }
   372 
   386 
   373 void TestPhoneUIQtView::testDialpadText()
   387 void TestPhoneUIQtView::testDialpadText()
   374 {
   388 {
   375     m_view->showDialpad();
   389     m_view->showDialpad();
   376     m_view->clearDialpad();
   390     m_view->clearDialpad();
   377     QVERIFY(QString("") == m_view->dialpadText());
   391     EXPECT(HbLineEdit, text).returns(QString("12345"));
       
   392     QCOMPARE(m_view->dialpadText(), QString("12345"));
   378     m_view->clearAndHideDialpad();
   393     m_view->clearAndHideDialpad();
       
   394     QVERIFY(verify());
   379 }
   395 }
   380 
   396 
   381 void TestPhoneUIQtView::testSetMenuActions()
   397 void TestPhoneUIQtView::testSetMenuActions()
   382 {
   398 {
   383     QList<PhoneAction*> actions;
   399     EXPECT(HbView, takeMenu);
       
   400     QList<HbAction *> actions;
       
   401     QList<QAction *> retActions;
       
   402     EXPECT(QGraphicsWidget, actions).returns(retActions).times(1);
   384     m_view->setMenuActions(actions);
   403     m_view->setMenuActions(actions);
   385     
   404     QVERIFY(verify());
   386     QVERIFY(m_take_menu_called);
   405     reset();
   387     
   406     
   388     PhoneAction* phoneAction = new PhoneAction; 
   407     HbAction* action = new HbAction; 
   389     phoneAction->setText(QString("test"));
   408     action->setText(QString("test"));
   390     phoneAction->setCommand(1);
   409     action->setProperty("command", 1);
   391     actions.append(phoneAction);
   410     actions.append(action);
   392     
   411     
       
   412     retActions.append(new HbAction);
       
   413     EXPECT(HbView, takeMenu).times(0);
       
   414     EXPECT(QGraphicsWidget, actions).returns(retActions).times(1);
   393     m_view->setMenuActions(actions);
   415     m_view->setMenuActions(actions);
   394     qDeleteAll(actions);
       
   395     actions.clear();
   416     actions.clear();
   396     
   417     retActions.clear();
   397     m_take_menu_called = false;
   418     QVERIFY(verify());
       
   419     reset();
       
   420     
       
   421     EXPECT(HbView, takeMenu);
       
   422     EXPECT(QGraphicsWidget, actions).returns(retActions).times(1);
   398     m_view->setMenuActions(actions);
   423     m_view->setMenuActions(actions);
   399     QVERIFY(m_take_menu_called);
   424     
       
   425     QVERIFY(verify());
       
   426     reset();
   400 }
   427 }
   401 
   428 
   402 //Private methods
   429 //Private methods
   403 int TestPhoneUIQtView::createCallHeader ()
   430 int TestPhoneUIQtView::createCallHeader ()
   404 {
   431 {
   405     int bubble = m_view->bubbleManager().createCallHeader ();
   432     int bubble = m_view->bubbleManager().createCallHeader();
   406 
   433 
   407     return bubble;
   434     return bubble;
   408 }
   435 }
   409 
   436 
   410 void TestPhoneUIQtView::testLongEndKeyPressEventOutsideTelephony()
   437 void TestPhoneUIQtView::testLongEndKeyPressEventOutsideTelephony()
   419 }
   446 }
   420 
   447 
   421 void TestPhoneUIQtView::testNetworkNameChanged()
   448 void TestPhoneUIQtView::testNetworkNameChanged()
   422 {
   449 {
   423     // Title is changed for GmsMode
   450     // Title is changed for GmsMode
   424     m_view->networkNameChanged(QSystemNetworkInfo::GsmMode, QString("test"));
   451     EXPECT(HbView, setTitle).with(QString("test"));
   425     QCOMPARE(m_networkName, QString("test"));
   452     m_view->m_priv->networkNameChanged(QSystemNetworkInfo::GsmMode, QString("test"));
   426 
   453 
   427     // Title is changed for WcdmaMode
   454     // Title is changed for WcdmaMode
   428     m_view->networkNameChanged(QSystemNetworkInfo::WcdmaMode, QString("test2"));
   455     EXPECT(HbView, setTitle).with(QString("test2"));
   429     QCOMPARE(m_networkName, QString("test2"));
   456     m_view->m_priv->networkNameChanged(QSystemNetworkInfo::WcdmaMode, QString("test2"));
   430 
   457 
   431     // Other modes shouldn't affect the title
   458     // Other modes shouldn't affect the title
   432     m_view->networkNameChanged(QSystemNetworkInfo::CdmaMode, QString("another operator"));
   459     EXPECT(HbView, setTitle).times(0);
   433     QCOMPARE(m_networkName, QString("test2"));
   460     m_view->m_priv->networkNameChanged(QSystemNetworkInfo::CdmaMode, QString("another operator"));
       
   461     QVERIFY(verify());
   434 }
   462 }
   435 
   463 
   436 void TestPhoneUIQtView::testCaptureKey()
   464 void TestPhoneUIQtView::testCaptureKey()
   437 {
   465 {
   438     m_view->captureKey( Qt::Key_No, true );
   466     m_view->captureKey( Qt::Key_No, true );
   451     QKeyEvent oneUp(QEvent::KeyRelease, Qt::Key_1, Qt::NoModifier);
   479     QKeyEvent oneUp(QEvent::KeyRelease, Qt::Key_1, Qt::NoModifier);
   452     QSignalSpy downSpy(m_view, SIGNAL(keyPressed(QKeyEvent*)));
   480     QSignalSpy downSpy(m_view, SIGNAL(keyPressed(QKeyEvent*)));
   453     QSignalSpy upSpy(m_view, SIGNAL(keyReleased(QKeyEvent*)));
   481     QSignalSpy upSpy(m_view, SIGNAL(keyReleased(QKeyEvent*)));
   454 
   482 
   455     m_view->setRestrictedMode(true);
   483     m_view->setRestrictedMode(true);
   456     m_view->m_dialpad->editor().setText("1"); // emits signal
   484     
   457     QCOMPARE(m_view->m_dialpad->isCallButtonEnabled(), false);
   485     EXPECT(HbLineEdit, text).returns(QString("1")).times(4);
   458     m_view->eventFilter(0, &oneDown);
   486     EXPECT(Dialpad, setCallButtonEnabled).times(0);
   459     m_view->eventFilter(0, &oneUp);
   487     EXPECT(Dialpad, isCallButtonEnabled).returns(false);
   460     m_view->eventFilter(0, &yesDown);
   488     /*m_view->m_priv->onEditorContentChanged(); // Simulate signal
   461     m_view->eventFilter(0, &yesUp);
   489     */
       
   490     m_view->m_priv->eventFilter(0, &oneDown);
       
   491     m_view->m_priv->eventFilter(0, &oneUp);
       
   492     m_view->m_priv->eventFilter(0, &yesDown);
       
   493     m_view->m_priv->eventFilter(0, &yesUp);
   462     QCOMPARE(downSpy.count(), 1); // Only Key_1 is passed
   494     QCOMPARE(downSpy.count(), 1); // Only Key_1 is passed
   463     QCOMPARE(upSpy.count(), 1); // Only Key_1 is passed
   495     QCOMPARE(upSpy.count(), 1); // Only Key_1 is passed
   464     QCOMPARE(m_view->m_dialpad->isCallButtonEnabled(), false);
   496     QCOMPARE(m_view->m_priv->m_backAction->isEnabled(), false);
   465     QCOMPARE(m_view->m_backAction->isEnabled(), false);
       
   466     
   497     
   467     // Test backbutton
   498     // Test backbutton
   468     m_view->setBackButtonVisible(true);
   499     m_view->setBackButtonVisible(true);
   469     QCOMPARE(m_view->m_backAction->isEnabled(), false);
   500     QCOMPARE(m_view->m_priv->m_backAction->isEnabled(), false);
   470 
   501 
   471     // Test return to normal mode
   502     // Test return to normal mode
   472     downSpy.clear();
   503     downSpy.clear();
   473     upSpy.clear();
   504     upSpy.clear();
   474     m_view->setRestrictedMode(false);
   505     m_view->setRestrictedMode(false);
   475     m_view->m_dialpad->editor().setText("1"); // emits signal
   506     EXPECT(HbLineEdit, text).returns(QString("1")).times(5);
   476     QCOMPARE(m_view->m_dialpad->isCallButtonEnabled(), true);
   507     EXPECT(Dialpad, setCallButtonEnabled).with(true);
   477     m_view->eventFilter(0, &oneDown);
   508     EXPECT(Dialpad, isCallButtonEnabled).returns(true).times(4);
   478     m_view->eventFilter(0, &oneUp);
   509     m_view->m_priv->onEditorContentChanged(); // Simulate signal
   479     m_view->eventFilter(0, &yesDown);
   510     m_view->m_priv->eventFilter(0, &oneDown);
   480     m_view->eventFilter(0, &yesUp);
   511     m_view->m_priv->eventFilter(0, &oneUp);
       
   512     m_view->m_priv->eventFilter(0, &yesDown);
       
   513     m_view->m_priv->eventFilter(0, &yesUp);
   481     QCOMPARE(downSpy.count(), 2);
   514     QCOMPARE(downSpy.count(), 2);
   482     QCOMPARE(upSpy.count(), 2);
   515     QCOMPARE(upSpy.count(), 2);
   483     QCOMPARE(m_view->m_dialpad->isCallButtonEnabled(), true);
   516     QCOMPARE(m_view->m_priv->m_backAction->isEnabled(), true);
   484     QCOMPARE(m_view->m_backAction->isEnabled(), true);
   517 }
   485 }
       
   486 
       
   487 HbMenu * HbView::takeMenu()
       
   488 {
       
   489     m_take_menu_called = true; 
       
   490     return 0;
       
   491 }
       
   492 
       
   493 void HbView::setMenu(HbMenu* menu)
       
   494 {
       
   495     m_set_menu_called = true;
       
   496 }
       
   497 
       
   498 void HbView::setTitle (const QString &title)
       
   499 {
       
   500     m_networkName = title;
       
   501 }
       
   502 
       
   503 
   518 
   504 PHONE_QT_VIEW_TEST_MAIN(TestPhoneUIQtView)
   519 PHONE_QT_VIEW_TEST_MAIN(TestPhoneUIQtView)
   505 Q_DECLARE_METATYPE(QKeyEvent *)
   520 Q_DECLARE_METATYPE(QKeyEvent *)
   506 #include "unit_tests.moc"
   521 #include "unit_tests.moc"