telutils/dialpad/tsrc/unit/ut_dialpadhasheventfilter/ut_dialpadhasheventfilter.cpp
branchRCL_3
changeset 20 987c9837762f
parent 19 7d48bed6ce0c
child 21 0a6dd2dc9970
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
     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 #include <HbMainWindow>
       
    21 #include <HbLineEdit>
       
    22 #ifdef Q_OS_SYMBIAN
       
    23 #include <xqaiwinterfacedescriptor.h>
       
    24 #include <xqaiwrequest.h>
       
    25 #endif
       
    26 #include "ut_dialpadhasheventfilter.h"
       
    27 #include "dialpadtest.h"
       
    28 #include "dialpadhasheventfilter.h"
       
    29 #include "dialpad.h"
       
    30 
       
    31 const int WAIT_TIME = 300;
       
    32 
       
    33 /*void setValidatorReturnValue(QVariant &returnValue)
       
    34 {
       
    35     returnValue.setValue<QString>(QRegExp::escape(KValidKeySequence));
       
    36 }*/
       
    37 
       
    38 UT_DialpadHashEventFilter::UT_DialpadHashEventFilter()
       
    39     :
       
    40     m_dialPad(0), 
       
    41     m_eventFilter(0),
       
    42     m_lineEditMock(0)
       
    43 {
       
    44     
       
    45 }
       
    46 
       
    47 UT_DialpadHashEventFilter::~UT_DialpadHashEventFilter()
       
    48 {
       
    49     delete m_dialPad;
       
    50     delete m_eventFilter;
       
    51     delete m_lineEditMock;
       
    52 }
       
    53 
       
    54 void UT_DialpadHashEventFilter::init()
       
    55 {
       
    56     initialize();
       
    57     
       
    58     m_lineEditMock = new HbLineEdit();
       
    59     QT_TRAP_THROWING(SmcDefaultValue<HbLineEdit&>::SetL(*m_lineEditMock))
       
    60     
       
    61     XQAiwInterfaceDescriptor descriptor;
       
    62     QString dummyOperation;
       
    63     bool isEmbedded = false;
       
    64     QList<XQAiwInterfaceDescriptor> interfaceList;
       
    65     interfaceList.append(descriptor);
       
    66     /*EXPECT(XQApplicationManager, list).returns(interfaceList);
       
    67     QPointer<XQAiwRequest> aiwRequest(new XQAiwRequest(
       
    68         descriptor, dummyOperation, isEmbedded));
       
    69     EXPECT(XQApplicationManager, create).returns(aiwRequest.data());
       
    70     EXPECT(XQAiwRequest, send)
       
    71         .willOnce(invoke(setValidatorReturnValue))
       
    72         .returns(true);*/
       
    73     
       
    74     SmcDefaultValue<QString>::SetL(QString());
       
    75     HbMainWindow *dummyWindow = NULL;
       
    76     m_dialPad = new Dialpad(*dummyWindow);
       
    77     m_eventFilter = new DialpadHashEventFilter(m_dialPad);
       
    78     
       
    79     //QVERIFY(aiwRequest.isNull());
       
    80     QVERIFY(verify());
       
    81 }
       
    82 
       
    83 void UT_DialpadHashEventFilter::cleanup()
       
    84 {
       
    85     reset();
       
    86     
       
    87     SmcDefaultValue<QString>::Reset();
       
    88     SmcDefaultValue<HbLineEdit&>::Reset();
       
    89     delete m_dialPad;
       
    90     m_dialPad = NULL;
       
    91     delete m_eventFilter;
       
    92     m_eventFilter = NULL;
       
    93     delete m_lineEditMock;
       
    94     m_lineEditMock = NULL;
       
    95 }
       
    96 
       
    97 #ifdef Q_OS_SYMBIAN
       
    98 
       
    99 /*void setServiceRequestReturnValue(QVariant & returnValue)
       
   100 {
       
   101     returnValue.setValue<bool>(true);
       
   102 }*/
       
   103 
       
   104 void UT_DialpadHashEventFilter::testeventFilter()
       
   105 {
       
   106     // start long press timer
       
   107     EXPECT(XQAiwRequest, send).times(0);
       
   108     QKeyEvent keyEvent(
       
   109         QEvent::KeyPress,
       
   110         Qt::Key_NumberSign,
       
   111         Qt::NoModifier);    
       
   112     bool filtered = m_eventFilter->eventFilter(m_dialPad, &keyEvent);
       
   113     QVERIFY(!filtered);
       
   114     QVERIFY(verify());
       
   115     
       
   116     // stop long press timer
       
   117     QKeyEvent keyEvent2(
       
   118         QEvent::KeyRelease,
       
   119         Qt::Key_NumberSign,
       
   120         Qt::NoModifier);
       
   121     
       
   122     filtered = m_eventFilter->eventFilter(m_dialPad, &keyEvent2);
       
   123     QVERIFY(!filtered);
       
   124     QVERIFY(verify());
       
   125     
       
   126     // some other buttons pressed and released
       
   127     EXPECT(XQAiwRequest, send).times(0);
       
   128     QKeyEvent keyEvent3(
       
   129         QEvent::KeyPress,
       
   130         Qt::Key_3,
       
   131         Qt::NoModifier);
       
   132     // start long press timer
       
   133     filtered = m_eventFilter->eventFilter(m_dialPad, &keyEvent3);
       
   134     QVERIFY(!filtered);
       
   135     QVERIFY(verify());
       
   136     
       
   137     QKeyEvent keyEvent4(
       
   138         QEvent::FocusIn,
       
   139         Qt::Key_1,
       
   140         Qt::NoModifier);
       
   141     // stop long press timer
       
   142     filtered = m_eventFilter->eventFilter(m_dialPad, &keyEvent4);
       
   143     QVERIFY(!filtered);
       
   144     QVERIFY(verify());
       
   145     
       
   146 }
       
   147 
       
   148 void UT_DialpadHashEventFilter::testhandleLongKeyPress()
       
   149 {
       
   150     m_eventFilter->handleLongKeyPress();
       
   151     m_eventFilter->mKeyEvent = Qt::Key_NumberSign;
       
   152     m_eventFilter->handleLongKeyPress();
       
   153 }
       
   154 
       
   155 void UT_DialpadHashEventFilter::testhandleCallButtonPress()
       
   156 {   
       
   157     // inherited method not supported
       
   158     EXPECT(XQAiwRequest, send).times(0);
       
   159     bool callButtonPress = m_eventFilter->handleCallButtonPress();
       
   160     QVERIFY(!callButtonPress);
       
   161 }
       
   162 
       
   163 void UT_DialpadHashEventFilter::testhandleMailboxOperation()
       
   164 {
       
   165     m_eventFilter->handleMailboxOperation();
       
   166     
       
   167     // another call to test other note
       
   168     m_eventFilter->handleMailboxOperation();
       
   169 }
       
   170 
       
   171 #endif
       
   172 
       
   173 int main(int argc, char *argv[])
       
   174 {
       
   175     QCoreApplication app(argc, argv);
       
   176     UT_DialpadHashEventFilter tc;
       
   177     return QTest::qExec(&tc, argc, argv);
       
   178 }