telutils/dialpad/tsrc/unit/ut_dialpadkeyhandler/ut_dialpadkeyhandler.cpp
changeset 27 7eb70891911c
child 32 1f002146abb4
equal deleted inserted replaced
23:427125ac6cb8 27:7eb70891911c
       
     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 #ifdef Q_OS_SYMBIAN
       
    22 #include <featmgr.h>
       
    23 #endif // Q_OS_SYMBIAN
       
    24 
       
    25 #include <smcmockclassincludes.h>
       
    26 #include "ut_dialpadkeyhandler.h"
       
    27 #include "dialpad.h"
       
    28 #include "dialpadkeyhandler.h"
       
    29 #include "dialpadtest.h"
       
    30 
       
    31 HbMainWindow *HbWidget::mainWindow() const
       
    32 {
       
    33     return 0;
       
    34 }
       
    35 
       
    36 
       
    37 void QObject::installEventFilter(QObject *obj)
       
    38 {
       
    39     SMC_MOCK_METHOD1( void, QObject *, obj )
       
    40 }
       
    41 
       
    42 
       
    43 UT_DialpadKeyHandler::UT_DialpadKeyHandler()
       
    44     :
       
    45     m_dialPad(0), 
       
    46     m_keyHandler(0)
       
    47 {
       
    48     
       
    49 }
       
    50 
       
    51 
       
    52 UT_DialpadKeyHandler::~UT_DialpadKeyHandler()
       
    53 {
       
    54     delete m_dialPad;
       
    55     delete m_keyHandler;
       
    56 }
       
    57 
       
    58 
       
    59 void UT_DialpadKeyHandler::init()
       
    60 {
       
    61     initialize();
       
    62     
       
    63     HbMainWindow *dummyWindow = 0;
       
    64     m_dialPad = new Dialpad(*dummyWindow);
       
    65 }
       
    66 
       
    67 
       
    68 void UT_DialpadKeyHandler::cleanup()
       
    69 {
       
    70     reset();
       
    71     
       
    72     delete m_dialPad;
       
    73     m_dialPad = NULL;
       
    74     delete m_keyHandler;
       
    75     m_keyHandler = NULL;
       
    76 }
       
    77 
       
    78 
       
    79 void UT_DialpadKeyHandler::t_constructionWithAllFilters()
       
    80 {
       
    81     EXPECT(QObject::installEventFilter).times(5);
       
    82     
       
    83     DialpadKeyHandler::DialpadKeyEventFilters filters(
       
    84         DialpadKeyHandler::VoiceMailbox |
       
    85         DialpadKeyHandler::VideoMailBox |
       
    86         DialpadKeyHandler::Bluetooth |
       
    87         DialpadKeyHandler::KeySequence |
       
    88         DialpadKeyHandler::EmergencyCall);
       
    89     
       
    90     m_keyHandler = new DialpadKeyHandler(m_dialPad, filters, this);
       
    91     
       
    92     QVERIFY(verify());
       
    93 }
       
    94 
       
    95 
       
    96 void UT_DialpadKeyHandler::t_constructionWithNoFilters()
       
    97 {
       
    98     EXPECT(QObject::installEventFilter).times(0);
       
    99     
       
   100     DialpadKeyHandler::DialpadKeyEventFilters filters;
       
   101     m_keyHandler = new DialpadKeyHandler(m_dialPad, filters, this);
       
   102     
       
   103     QVERIFY(verify());
       
   104 }
       
   105 
       
   106 
       
   107 void UT_DialpadKeyHandler::t_deprecatedConstructionWithVideoMailbox()
       
   108 {
       
   109 #ifdef Q_OS_SYMBIAN
       
   110     EXPECT(FeatureManager::FeatureSupported).returns(true);
       
   111     EXPECT(QObject::installEventFilter).times(4);
       
   112     
       
   113     HbMainWindow *dummyWindow = 0;
       
   114     m_keyHandler = new DialpadKeyHandler(m_dialPad, *dummyWindow, this);
       
   115     
       
   116     QVERIFY(verify());
       
   117 #endif // Q_OS_SYMBIAN
       
   118 }
       
   119 
       
   120 
       
   121 void UT_DialpadKeyHandler::t_deprecatedConstructionWithoutVideoMailbox()
       
   122 {
       
   123     EXPECT(FeatureManager::FeatureSupported).returns(false);
       
   124     EXPECT(QObject::installEventFilter).times(3);
       
   125     
       
   126     HbMainWindow *dummyWindow = 0;
       
   127     m_keyHandler = new DialpadKeyHandler(m_dialPad, *dummyWindow, this);
       
   128     
       
   129     QVERIFY(verify());
       
   130 }
       
   131 
       
   132 
       
   133 int main(int argc, char *argv[])
       
   134 {
       
   135     QCoreApplication app(argc, argv);
       
   136     UT_DialpadKeyHandler tc;
       
   137     return QTest::qExec(&tc, argc, argv);
       
   138 }