|
1 /* |
|
2 * Copyright (c) 2008, 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: test code |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtTest/QtTest> |
|
19 #include <QStateMachine> |
|
20 #include <QGraphicsSceneMouseEvent> |
|
21 |
|
22 #include <HbTouchArea> |
|
23 #include <HbFrameItem> |
|
24 |
|
25 #include "t_hsshortcutwidget.h" |
|
26 #include "hsshortcutwidget.h" |
|
27 #include "hsshortcutservice.h" |
|
28 #include "hsconfiguration.h" |
|
29 |
|
30 #include "caentry.h" |
|
31 #include "caservice.h" |
|
32 |
|
33 void TestShortcutWidget::initTestCase() |
|
34 { |
|
35 mMachine = new QStateMachine; |
|
36 mShortcutService = HsShortcutService::instance(mMachine); |
|
37 HsConfiguration::setInstance(new HsConfiguration); |
|
38 } |
|
39 |
|
40 void TestShortcutWidget::cleanupTestCase() |
|
41 { |
|
42 delete mMachine; |
|
43 } |
|
44 |
|
45 void TestShortcutWidget::testConstruction() |
|
46 { |
|
47 HSCONFIGURATION_SET(setShortcutLabelVisible, true); |
|
48 HsShortcutWidget *w = new HsShortcutWidget; |
|
49 QVERIFY(w->mBackground); |
|
50 QVERIFY(w->mIcon); |
|
51 QVERIFY(w->mText); |
|
52 QCOMPARE(w->mCaEntryId, -1); |
|
53 QCOMPARE(w->mCaEntryRole, ItemEntryRole); |
|
54 w->createPrimitives(); |
|
55 QVERIFY(w->mBackground); |
|
56 QVERIFY(w->mIcon); |
|
57 QVERIFY(w->mText); |
|
58 QCOMPARE(w->mCaEntryId, -1); |
|
59 QCOMPARE(w->mCaEntryRole, ItemEntryRole); |
|
60 |
|
61 w->setText("testing"); |
|
62 QCOMPARE(w->text(), QString("testing")); |
|
63 |
|
64 delete w; |
|
65 |
|
66 HSCONFIGURATION_SET(setShortcutLabelVisible, false); |
|
67 w = new HsShortcutWidget; |
|
68 QVERIFY(!w->mText); |
|
69 w->setText("testing"); |
|
70 QCOMPARE(w->text(), QString("")); |
|
71 delete w; |
|
72 } |
|
73 |
|
74 void TestShortcutWidget::testProperties() |
|
75 { |
|
76 HsShortcutWidget *w = new HsShortcutWidget; |
|
77 |
|
78 QCOMPARE(w->property("caEntryId").toInt(), -1); |
|
79 w->setProperty("caEntryId", 1); |
|
80 QCOMPARE(w->property("caEntryId").toInt(), 1); |
|
81 |
|
82 QCOMPARE(w->property("uid").toString(), QString()); |
|
83 w->setProperty("uid", "0xABBAACDC"); |
|
84 QCOMPARE(w->property("uid").toString(), QString("0xABBAACDC")); |
|
85 |
|
86 delete w; |
|
87 } |
|
88 |
|
89 void TestShortcutWidget::testSignals() |
|
90 { |
|
91 HsShortcutWidget *w = new HsShortcutWidget; |
|
92 |
|
93 QSignalSpy spy(w, SIGNAL(finished())); |
|
94 w->onInitialize(); |
|
95 QCOMPARE(spy.count(), 1); |
|
96 spy.clear(); |
|
97 |
|
98 CaEntry e; |
|
99 ChangeType c = RemoveChangeType; |
|
100 |
|
101 w->onEntryChanged(e, c); |
|
102 QCOMPARE(spy.count(), 1); |
|
103 spy.clear(); |
|
104 |
|
105 delete w; |
|
106 } |
|
107 |
|
108 void TestShortcutWidget::testShowHide() |
|
109 { |
|
110 HsShortcutWidget *w = new HsShortcutWidget; |
|
111 |
|
112 w->onShow(); |
|
113 QVERIFY(w->isVisible()); |
|
114 w->onHide(); |
|
115 |
|
116 w->mCaEntryFlags = MissingEntryFlag; |
|
117 w->onShow(); |
|
118 QVERIFY(!w->isVisible()); |
|
119 w->onHide(); |
|
120 |
|
121 delete w; |
|
122 } |
|
123 |
|
124 void TestShortcutWidget::testCaNotifier() |
|
125 { |
|
126 HSCONFIGURATION_SET(setShortcutLabelVisible, true); |
|
127 HsShortcutWidget *w = new HsShortcutWidget; |
|
128 |
|
129 w->createCaNotifier(); |
|
130 |
|
131 CaEntry e; |
|
132 ChangeType c = UpdateChangeType; |
|
133 w->onEntryChanged(e, c); |
|
134 QVERIFY(w->isVisible()); |
|
135 |
|
136 //Media detached |
|
137 QSignalSpy spy(w, SIGNAL(finished())); |
|
138 c = RemoveChangeType; |
|
139 e.setFlags(e.flags() | MissingEntryFlag); |
|
140 w->onEntryChanged(e, c); |
|
141 QVERIFY(!w->isVisible()); |
|
142 QCOMPARE(spy.count(), 0); |
|
143 spy.clear(); |
|
144 |
|
145 //Genuinely removed |
|
146 c = RemoveChangeType; |
|
147 //Remove MissingEntryFlag |
|
148 e.setFlags(e.flags() & ~MissingEntryFlag); |
|
149 w->onEntryChanged(e, c); |
|
150 QVERIFY(w->isVisible()); |
|
151 QCOMPARE(spy.count(), 1); |
|
152 spy.clear(); |
|
153 delete w; |
|
154 |
|
155 |
|
156 HSCONFIGURATION_SET(setShortcutLabelVisible, false); |
|
157 w = new HsShortcutWidget; |
|
158 w->createCaNotifier(); |
|
159 c = UpdateChangeType; |
|
160 w->onEntryChanged(e, c); |
|
161 QVERIFY(w->isVisible()); |
|
162 delete w; |
|
163 |
|
164 } |
|
165 |
|
166 void TestShortcutWidget::testUserInteraction() |
|
167 { |
|
168 HsShortcutWidget *w = new HsShortcutWidget; |
|
169 w->resize(100, 100); |
|
170 |
|
171 w->setBackgroundToNormal(); |
|
172 QCOMPARE(w->mBackground->frameDrawer().frameGraphicsName(), QLatin1String("qtg_fr_hsshortcut_normal")); |
|
173 |
|
174 w->setBackgroundToPressed(); |
|
175 QCOMPARE(w->mBackground->frameDrawer().frameGraphicsName(), QLatin1String("qtg_fr_hsitems_pressed")); |
|
176 |
|
177 w->launch(); |
|
178 |
|
179 delete w; |
|
180 } |
|
181 |
|
182 QTEST_MAIN(TestShortcutWidget) |