|
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 #include <hbcolorscheme.h> |
|
26 #include <hbiconitem.h> |
|
27 |
|
28 #include "bubbletest.h" |
|
29 #include "bubblebutton.h" |
|
30 |
|
31 class TestBubbleButton : public BubbleButton |
|
32 { |
|
33 public: |
|
34 TestBubbleButton() {}; |
|
35 ~TestBubbleButton() {}; |
|
36 |
|
37 bool testSceneEvent(QEvent *event) { return BubbleButton::sceneEvent(event); }; |
|
38 }; |
|
39 |
|
40 class ut_BubbleButton : public QObject |
|
41 { |
|
42 Q_OBJECT |
|
43 |
|
44 private slots: |
|
45 void initTestCase(); |
|
46 void cleanupTestCase(); |
|
47 |
|
48 void testButtonType(); |
|
49 void testUpdatePrimitives(); |
|
50 void testSceneEvent(); |
|
51 |
|
52 private: |
|
53 TestBubbleButton *mButton; |
|
54 }; |
|
55 |
|
56 void ut_BubbleButton::initTestCase() |
|
57 { |
|
58 mButton = new TestBubbleButton(); |
|
59 mButton->setIcon(HbIcon(":/resources/qtg_mono_call.svg")); |
|
60 } |
|
61 |
|
62 void ut_BubbleButton::cleanupTestCase() |
|
63 { |
|
64 delete mButton; |
|
65 } |
|
66 |
|
67 void ut_BubbleButton::testButtonType() |
|
68 { |
|
69 QVERIFY(mButton->buttonType()==BubbleButton::DefaultButton); |
|
70 mButton->setButtonType(BubbleButton::GreenButton); |
|
71 QVERIFY(mButton->buttonType()==BubbleButton::GreenButton); |
|
72 mButton->setButtonType(BubbleButton::RedButton); |
|
73 QVERIFY(mButton->buttonType()==BubbleButton::RedButton); |
|
74 } |
|
75 |
|
76 void ut_BubbleButton::testUpdatePrimitives() |
|
77 { |
|
78 // function button |
|
79 HbFrameItem* frame = |
|
80 qgraphicsitem_cast<HbFrameItem*>( |
|
81 static_cast<HbWidget*>(mButton)->primitive("background")); |
|
82 QVERIFY(frame); |
|
83 |
|
84 HbIconItem* icon = |
|
85 qgraphicsitem_cast<HbIconItem*>( |
|
86 static_cast<HbWidget*>(mButton)->primitive("icon")); |
|
87 QVERIFY(icon); |
|
88 |
|
89 QColor iconColor; |
|
90 |
|
91 mButton->setVisible(false); |
|
92 mButton->setButtonType(BubbleButton::DefaultButton); |
|
93 mButton->setVisible(true); |
|
94 |
|
95 QVERIFY(frame->frameDrawer().frameGraphicsName()!="qtg_fr_btn_green_normal"); |
|
96 QVERIFY(frame->frameDrawer().frameGraphicsName()!="qtg_fr_btn_green_normal"); |
|
97 iconColor = HbColorScheme::color("qtc_button_normal"); |
|
98 QVERIFY(icon->color()==iconColor); |
|
99 mButton->setDown(true); |
|
100 QVERIFY(frame->frameDrawer().frameGraphicsName()!="qtg_fr_btn_green_pressed"); |
|
101 QVERIFY(frame->frameDrawer().frameGraphicsName()!="qtg_fr_btn_green_pressed"); |
|
102 iconColor = HbColorScheme::color("qtc_button_pressed"); |
|
103 QVERIFY(icon->color()==iconColor); |
|
104 |
|
105 |
|
106 mButton->setDown(false); |
|
107 mButton->setVisible(false); |
|
108 mButton->setButtonType(BubbleButton::RedButton); |
|
109 mButton->setVisible(true); |
|
110 |
|
111 QVERIFY(frame->frameDrawer().frameGraphicsName()=="qtg_fr_btn_red_normal"); |
|
112 iconColor = HbColorScheme::color("qtc_callhandling_reject_normal"); |
|
113 QVERIFY(icon->color()==iconColor); |
|
114 mButton->setDown(true); |
|
115 QVERIFY(frame->frameDrawer().frameGraphicsName()=="qtg_fr_btn_red_pressed"); |
|
116 iconColor = HbColorScheme::color("qtc_callhandling_reject_pressed"); |
|
117 QVERIFY(icon->color()==iconColor); |
|
118 |
|
119 mButton->setDown(false); |
|
120 mButton->setVisible(false); |
|
121 mButton->setButtonType(BubbleButton::GreenButton); |
|
122 mButton->setVisible(true); |
|
123 |
|
124 QVERIFY(frame->frameDrawer().frameGraphicsName()=="qtg_fr_btn_green_normal"); |
|
125 iconColor = HbColorScheme::color("qtc_callhandling_answer_normal"); |
|
126 QVERIFY(icon->color()==iconColor); |
|
127 mButton->setDown(true); |
|
128 QVERIFY(frame->frameDrawer().frameGraphicsName()=="qtg_fr_btn_green_pressed"); |
|
129 iconColor = HbColorScheme::color("qtc_callhandling_answer_pressed"); |
|
130 QVERIFY(icon->color()==iconColor); |
|
131 } |
|
132 |
|
133 void ut_BubbleButton::testSceneEvent() |
|
134 { |
|
135 QEvent event(QEvent::UngrabMouse); |
|
136 QSignalSpy spy( mButton, SIGNAL( clicked()) ); |
|
137 QSignalSpy spy2( mButton, SIGNAL( released()) ); |
|
138 mButton->setVisible(false); |
|
139 mButton->setDown(false); |
|
140 mButton->testSceneEvent(&event); |
|
141 QVERIFY(spy.count()==0); |
|
142 QVERIFY(spy2.count()==0); |
|
143 |
|
144 QEvent eventNone(QEvent::None); |
|
145 mButton->testSceneEvent(&eventNone); |
|
146 QVERIFY(spy.count()==0); |
|
147 QVERIFY(spy2.count()==0); |
|
148 |
|
149 mButton->setVisible(true); |
|
150 mButton->setDown(true); |
|
151 mButton->testSceneEvent(&event); |
|
152 QVERIFY(spy.count()==1); |
|
153 QVERIFY(spy2.count()==1); |
|
154 QVERIFY(mButton->isDown()==false); |
|
155 } |
|
156 |
|
157 BUBBLE_TEST_MAIN(ut_BubbleButton) |
|
158 #include "ut_bubblebutton.moc" |