telutils/dialpad/tsrc/unit/ut_dialpadbutton/ut_dialpadbutton.cpp
branchRCL_3
changeset 20 987c9837762f
parent 19 7d48bed6ce0c
child 21 0a6dd2dc9970
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
     1 /*!
       
     2 * Copyright (c) 2009 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 <hbwidget.h>
       
    23 #include <hbframeitem.h>
       
    24 #include <hbframedrawer.h>
       
    25 
       
    26 #include "dialpadtest.h"
       
    27 #include "dialpadbutton.h"
       
    28 
       
    29 class TestDialpadButton : public DialpadButton
       
    30 {
       
    31 public:
       
    32     TestDialpadButton() {};
       
    33     ~TestDialpadButton() {};
       
    34 
       
    35     bool testSceneEvent(QEvent *event) { return DialpadButton::sceneEvent(event); };
       
    36 };
       
    37 
       
    38 class ut_DialpadButton : public QObject
       
    39 {
       
    40     Q_OBJECT
       
    41 
       
    42 private slots:
       
    43     void initTestCase();
       
    44     void cleanupTestCase();
       
    45 
       
    46     void testButtonType();
       
    47     void testUpdatePrimitives();
       
    48     void testSceneEvent();
       
    49 
       
    50 private:
       
    51     TestDialpadButton *mButton;
       
    52 };
       
    53 
       
    54 void ut_DialpadButton::initTestCase()
       
    55 {
       
    56     mButton = new TestDialpadButton();
       
    57 }
       
    58 
       
    59 void ut_DialpadButton::cleanupTestCase()
       
    60 {
       
    61     delete mButton;
       
    62 }
       
    63 
       
    64 void ut_DialpadButton::testButtonType()
       
    65 {
       
    66     QVERIFY(mButton->buttonType()==DialpadButton::FunctionButton);
       
    67     mButton->setButtonType(DialpadButton::CallButton);
       
    68     QVERIFY(mButton->buttonType()==DialpadButton::CallButton);
       
    69 }
       
    70 
       
    71 void ut_DialpadButton::testUpdatePrimitives()
       
    72 {
       
    73     // function button
       
    74 
       
    75     mButton->setEnabled(false);
       
    76     mButton->setButtonType(DialpadButton::FunctionButton);
       
    77     HbFrameItem* frame =
       
    78         qgraphicsitem_cast<HbFrameItem*>(static_cast<HbWidget*>(mButton)->primitive("background"));
       
    79     QVERIFY(frame->frameDrawer().frameGraphicsName()=="qtg_fr_input_btn_function_disabled");
       
    80 
       
    81     mButton->setEnabled(true);
       
    82     QVERIFY(frame->frameDrawer().frameGraphicsName()=="qtg_fr_input_btn_function_normal");
       
    83 
       
    84     mButton->setDown(true);
       
    85     QVERIFY(frame->frameDrawer().frameGraphicsName()=="qtg_fr_input_btn_function_pressed");
       
    86     mButton->setDown(false);
       
    87 
       
    88     // call button
       
    89     mButton->setEnabled(false);
       
    90     mButton->setButtonType(DialpadButton::CallButton);
       
    91     QVERIFY(frame->frameDrawer().frameGraphicsName()=="qtg_fr_input_btn_function_disabled");
       
    92 
       
    93     mButton->setEnabled(true);
       
    94     QVERIFY(frame->frameDrawer().frameGraphicsName()=="qtg_fr_btn_green_normal");
       
    95 
       
    96     mButton->setDown(true);
       
    97     QVERIFY(frame->frameDrawer().frameGraphicsName()=="qtg_fr_btn_green_pressed");
       
    98     mButton->setDown(false);
       
    99 }
       
   100 
       
   101 void ut_DialpadButton::testSceneEvent()
       
   102 {
       
   103     QEvent event(QEvent::UngrabMouse);
       
   104     QSignalSpy spy( mButton, SIGNAL( clicked()) );
       
   105     QSignalSpy spy2( mButton, SIGNAL( released()) );
       
   106     mButton->setVisible(false);
       
   107     mButton->setDown(false);
       
   108     mButton->testSceneEvent(&event);
       
   109     QVERIFY(spy.count()==0);
       
   110     QVERIFY(spy2.count()==0);
       
   111 
       
   112     QEvent eventNone(QEvent::None);
       
   113     mButton->testSceneEvent(&eventNone);
       
   114     QVERIFY(spy.count()==0);
       
   115     QVERIFY(spy2.count()==0);
       
   116 
       
   117     mButton->setVisible(true);
       
   118     mButton->setDown(true);
       
   119     mButton->testSceneEvent(&event);
       
   120     QVERIFY(spy.count()==1);
       
   121     QVERIFY(spy2.count()==1);
       
   122     QVERIFY(mButton->isDown()==false);
       
   123 }
       
   124 
       
   125 DIALPAD_TEST_MAIN(ut_DialpadButton)
       
   126 #include "ut_dialpadbutton.moc"