telutils/dialpad/tsrc/unit/ut_dialpademergencycalleventfilter/ut_dialpademergencycalleventfilter.cpp
branchRCL_3
changeset 19 7d48bed6ce0c
equal deleted inserted replaced
18:594d59766373 19:7d48bed6ce0c
       
     1 /*!
       
     2 * Copyright (c) 2010 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QtGui>
       
    19 #include <QtTest/QtTest>
       
    20 
       
    21 #include <hbapplication.h>
       
    22 #include <hbmainwindow.h>
       
    23 #include <hbaction.h>
       
    24 #include <hbtoolbar.h>
       
    25 #include <hbview.h>
       
    26 #include <hblineedit.h>
       
    27 #include <hbinstance.h>
       
    28 #include <mockservice.h>
       
    29 
       
    30 #include "mock_cphcltemergencycall.h"
       
    31 #include "dialpadtest.h"
       
    32 #include "dialpadtestutil.h"
       
    33 #include "dialpademergencycalleventfilter.h"
       
    34 #include "dialpad.h"
       
    35 
       
    36 const int WAIT_TIME = 300;
       
    37 
       
    38 // test cases
       
    39 class ut_DialpadEmergencyCallEventFilter : public QObject, public MockService
       
    40 {
       
    41     Q_OBJECT
       
    42 
       
    43 private slots:
       
    44     void initTestCase();
       
    45     void init();
       
    46     void cleanupTestCase();
       
    47     void cleanup();
       
    48 
       
    49     // These are actual emergency call event filter unit tests
       
    50     void testEmergencyCallEventFilter();
       
    51 
       
    52 private:
       
    53     HbMainWindow*  mMainWindow; 
       
    54     Dialpad*       mDialpad;
       
    55     DialpadEmergencyCallEventFilter *mEventFilter;
       
    56     DialpadTestUtil* mUtil;
       
    57 };
       
    58 
       
    59 void ut_DialpadEmergencyCallEventFilter::initTestCase()
       
    60 {
       
    61     mMainWindow = new HbMainWindow;
       
    62 
       
    63     mDialpad = new Dialpad();
       
    64     mEventFilter = new DialpadEmergencyCallEventFilter(mDialpad, this);
       
    65     //hbInstance->allMainWindows().at(0)->installEventFilter(mEventFilter);
       
    66     mMainWindow->installEventFilter(mEventFilter);
       
    67 
       
    68     mUtil = new DialpadTestUtil(*mMainWindow);
       
    69     
       
    70     QRectF rect(mMainWindow->contentsRect());
       
    71     rect.setHeight(rect.height()*0.7);
       
    72     rect.moveTop((mMainWindow->contentsRect().height()-rect.height())/2);
       
    73 
       
    74     mDialpad->setPreferredSize(mMainWindow->layoutRect().width(),
       
    75                                mMainWindow->layoutRect().height()/2);
       
    76     mDialpad->setPos(0,mMainWindow->layoutRect().height()/4);
       
    77 
       
    78     mMainWindow->show();
       
    79     mDialpad->show();
       
    80     mDialpad->hide();
       
    81 }
       
    82 
       
    83 void ut_DialpadEmergencyCallEventFilter::init()
       
    84 {
       
    85     initialize();
       
    86 }
       
    87 
       
    88 void ut_DialpadEmergencyCallEventFilter::cleanupTestCase()
       
    89 {
       
    90     delete mDialpad;
       
    91     delete mMainWindow;
       
    92     delete mUtil;
       
    93 }
       
    94 
       
    95 void ut_DialpadEmergencyCallEventFilter::cleanup()
       
    96 {
       
    97     reset();
       
    98     mDialpad->editor().setText(QString());
       
    99     QTest::qWait( WAIT_TIME ); // delay between tests
       
   100 }
       
   101 
       
   102 void checkNumber(const TDesC& aNumber, TBool& aIsEmergencyNumber)
       
   103 {
       
   104     if (aNumber == _L("112")) {
       
   105         aIsEmergencyNumber = true;
       
   106     }
       
   107 }
       
   108 
       
   109 void ut_DialpadEmergencyCallEventFilter::testEmergencyCallEventFilter()
       
   110 {
       
   111     EXPECT(CPhCltEmergencyCallMock, IsEmergencyPhoneNumber).willOnce(
       
   112             invoke(checkNumber));
       
   113     EXPECT(CPhCltEmergencyCallMock, DialEmergencyCallL);
       
   114     
       
   115     mDialpad->openDialpad();
       
   116     QTest::qWait(WAIT_TIME);
       
   117     mUtil->mouseClickDialpad(Qt::Key_1);
       
   118     QTest::qWait(1000);
       
   119     mUtil->mouseClickDialpad(Qt::Key_1);
       
   120     QTest::qWait(1000);
       
   121     mUtil->mouseClickDialpad(Qt::Key_2);
       
   122     QTest::qWait(1000);
       
   123     mUtil->mouseClickDialpad(Qt::Key_Yes);
       
   124     QTest::qWait(1000);
       
   125     
       
   126     mDialpad->closeDialpad();
       
   127 
       
   128     QVERIFY(verify());
       
   129 }
       
   130 
       
   131 DIALPAD_TEST_MAIN(ut_DialpadEmergencyCallEventFilter)
       
   132 #include "ut_dialpademergencycalleventfilter.moc"
       
   133