29 #ifdef Q_OS_SYMBIAN |
29 #ifdef Q_OS_SYMBIAN |
30 #include "xqservicerequest.h" |
30 #include "xqservicerequest.h" |
31 #endif |
31 #endif |
32 |
32 |
33 #include "dialpadtest.h" |
33 #include "dialpadtest.h" |
|
34 #include "dialpadtestutil.h" |
34 #include "dialpadvoicemailboxeventfilter.h" |
35 #include "dialpadvoicemailboxeventfilter.h" |
35 #include "dialpad.h" |
36 #include "dialpad.h" |
36 #include "dialpadsymbianwrapper.h" |
37 #include "dialpadsymbianwrapper.h" |
37 |
38 |
38 const int WAIT_TIME = 300; |
39 const int WAIT_TIME = 300; |
101 void testNumericKeyOneLongPress(); |
94 void testNumericKeyOneLongPress(); |
102 void testNumericKeyOneShortPress(); |
95 void testNumericKeyOneShortPress(); |
103 void testNumericKeyOneShortThenLongPress(); |
96 void testNumericKeyOneShortThenLongPress(); |
104 |
97 |
105 private: |
98 private: |
106 QGraphicsWidget* getWidgetByName(const QString& name); |
|
107 void mouseClickDialpad(int key, MouseEventType type=Click, |
|
108 bool pause=true); |
|
109 |
|
110 private: |
|
111 HbMainWindow* mMainWindow; |
99 HbMainWindow* mMainWindow; |
112 Dialpad* mDialpad; |
100 Dialpad* mDialpad; |
113 DialpadVoiceMailboxEventFilter *mEventFilter; |
101 DialpadVoiceMailboxEventFilter *mEventFilter; |
114 KeyEventCatcher* mKeyCatcher; |
102 KeyEventCatcher* mKeyCatcher; |
115 QMap<int,QString> mKeyNames; |
103 DialpadTestUtil* mUtil; |
116 }; |
104 }; |
117 |
105 |
118 void ut_DialpadVoiceMailboxEventFilter::initTestCase() |
106 void ut_DialpadVoiceMailboxEventFilter::initTestCase() |
119 { |
107 { |
120 mMainWindow = new HbMainWindow; |
108 mMainWindow = new HbMainWindow; |
121 |
109 |
122 mKeyCatcher = new KeyEventCatcher; |
110 mKeyCatcher = new KeyEventCatcher; |
123 mMainWindow->installEventFilter(mKeyCatcher); |
111 mMainWindow->installEventFilter(mKeyCatcher); |
|
112 |
|
113 mUtil = new DialpadTestUtil(*mMainWindow); |
124 |
114 |
125 mDialpad = new Dialpad(); |
115 mDialpad = new Dialpad(); |
126 mEventFilter = new DialpadVoiceMailboxEventFilter(mDialpad, this); |
116 mEventFilter = new DialpadVoiceMailboxEventFilter(mDialpad, this); |
127 hbInstance->allMainWindows().at(0)->installEventFilter(mEventFilter); |
117 hbInstance->allMainWindows().at(0)->installEventFilter(mEventFilter); |
128 |
118 |
130 rect.setHeight(rect.height()*0.7); |
120 rect.setHeight(rect.height()*0.7); |
131 rect.moveTop((mMainWindow->contentsRect().height()-rect.height())/2); |
121 rect.moveTop((mMainWindow->contentsRect().height()-rect.height())/2); |
132 |
122 |
133 mDialpad->setPreferredSize(360,400); |
123 mDialpad->setPreferredSize(360,400); |
134 mDialpad->setPos(0,100); |
124 mDialpad->setPos(0,100); |
135 |
|
136 mKeyNames.insert(Qt::Key_1,"49"); |
|
137 mKeyNames.insert(Qt::Key_2,"50"); |
|
138 mKeyNames.insert(Qt::Key_3,"51"); |
|
139 mKeyNames.insert(Qt::Key_4,"52"); |
|
140 mKeyNames.insert(Qt::Key_5,"53"); |
|
141 mKeyNames.insert(Qt::Key_6,"54"); |
|
142 mKeyNames.insert(Qt::Key_7,"55"); |
|
143 mKeyNames.insert(Qt::Key_8,"56"); |
|
144 mKeyNames.insert(Qt::Key_9,"57"); |
|
145 mKeyNames.insert(Qt::Key_Asterisk,"42"); |
|
146 mKeyNames.insert(Qt::Key_0,"48"); |
|
147 mKeyNames.insert(Qt::Key_NumberSign,"35"); |
|
148 mKeyNames.insert(Qt::Key_Backspace,"16777219"); |
|
149 mKeyNames.insert(Qt::Key_Yes,"16842753"); |
|
150 |
125 |
151 mMainWindow->show(); |
126 mMainWindow->show(); |
152 mDialpad->show(); |
127 mDialpad->show(); |
153 mDialpad->hide(); |
128 mDialpad->hide(); |
154 } |
129 } |
164 void ut_DialpadVoiceMailboxEventFilter::cleanupTestCase() |
139 void ut_DialpadVoiceMailboxEventFilter::cleanupTestCase() |
165 { |
140 { |
166 delete mDialpad; |
141 delete mDialpad; |
167 delete mMainWindow; |
142 delete mMainWindow; |
168 delete mKeyCatcher; |
143 delete mKeyCatcher; |
|
144 delete mUtil; |
169 } |
145 } |
170 |
146 |
171 void ut_DialpadVoiceMailboxEventFilter::cleanup() |
147 void ut_DialpadVoiceMailboxEventFilter::cleanup() |
172 { |
148 { |
173 mKeyCatcher->mKeyPresses.clear(); |
149 mKeyCatcher->mKeyPresses.clear(); |
174 mKeyCatcher->mKeyReleases.clear(); |
150 mKeyCatcher->mKeyReleases.clear(); |
175 mDialpad->editor().setText(QString()); |
151 mDialpad->editor().setText(QString()); |
176 QTest::qWait( WAIT_TIME ); // delay between tests |
152 QTest::qWait( WAIT_TIME ); // delay between tests |
177 } |
153 } |
178 |
154 |
179 QGraphicsWidget* ut_DialpadVoiceMailboxEventFilter::getWidgetByName(const QString& name) |
|
180 { |
|
181 Q_ASSERT(mMainWindow!=0); |
|
182 |
|
183 QGraphicsWidget* widget = 0; |
|
184 |
|
185 QList<QGraphicsItem*> items = mMainWindow->scene()->items(); |
|
186 foreach (QGraphicsItem* item, items) { |
|
187 if (item->isWidget()) { |
|
188 QGraphicsWidget *w = static_cast<QGraphicsWidget*>(item); |
|
189 if (w->objectName()==name) { |
|
190 widget = w; |
|
191 } |
|
192 } |
|
193 } |
|
194 |
|
195 return widget; |
|
196 } |
|
197 |
|
198 void ut_DialpadVoiceMailboxEventFilter::mouseClickDialpad(int key, MouseEventType type, bool pause) |
|
199 { |
|
200 QString name = mKeyNames.value(key); |
|
201 |
|
202 QGraphicsWidget* widget = getWidgetByName(name); |
|
203 |
|
204 if ( widget ) { |
|
205 QPointF widgetPos = widget->scenePos() + |
|
206 widget->rect().center(); |
|
207 |
|
208 QPoint windowPos = mMainWindow->mapFromScene( widgetPos ); |
|
209 |
|
210 if (type==Press) { |
|
211 QTest::mousePress( mMainWindow->viewport(), Qt::LeftButton, |
|
212 0, windowPos ); |
|
213 } else if (type==Release) { |
|
214 QTest::mouseRelease( mMainWindow->viewport(), Qt::LeftButton, |
|
215 0, windowPos ); |
|
216 } else { |
|
217 QTest::mouseClick( mMainWindow->viewport(), Qt::LeftButton, |
|
218 0, windowPos ); |
|
219 } |
|
220 |
|
221 if (pause) { |
|
222 QTest::qWait( WAIT_TIME ); |
|
223 } |
|
224 } else { |
|
225 QFAIL( "Button could not be accessed!" ); |
|
226 } |
|
227 } |
|
228 |
|
229 |
|
230 void ut_DialpadVoiceMailboxEventFilter::testNumericKeyOneLongPress() |
155 void ut_DialpadVoiceMailboxEventFilter::testNumericKeyOneLongPress() |
231 { |
156 { |
232 mDialpad->openDialpad(); |
157 mDialpad->openDialpad(); |
233 QTest::qWait(WAIT_TIME); |
158 QTest::qWait(WAIT_TIME); |
234 mouseClickDialpad(Qt::Key_1, Press); |
159 mUtil->mouseClickDialpad(Qt::Key_1, DialpadTestUtil::Press); |
235 QTest::qWait(2000); |
160 QTest::qWait(2000); |
236 mouseClickDialpad(Qt::Key_1, Release); |
161 mUtil->mouseClickDialpad(Qt::Key_1, DialpadTestUtil::Release); |
237 QTest::qWait(1000); |
162 QTest::qWait(1000); |
238 QCOMPARE(mDialpad->editor().text(), QString("")); |
163 QCOMPARE(mDialpad->editor().text(), QString("")); |
239 mDialpad->closeDialpad(); |
164 mDialpad->closeDialpad(); |
240 |
165 |
241 #ifdef Q_OS_SYMBIAN |
166 #ifdef Q_OS_SYMBIAN |
248 |
173 |
249 void ut_DialpadVoiceMailboxEventFilter::testNumericKeyOneShortPress() |
174 void ut_DialpadVoiceMailboxEventFilter::testNumericKeyOneShortPress() |
250 { |
175 { |
251 mDialpad->openDialpad(); |
176 mDialpad->openDialpad(); |
252 QTest::qWait(WAIT_TIME); |
177 QTest::qWait(WAIT_TIME); |
253 mouseClickDialpad(Qt::Key_1, Press); |
178 mUtil->mouseClickDialpad(Qt::Key_1, DialpadTestUtil::Press); |
254 QTest::qWait(200); |
179 QTest::qWait(200); |
255 mouseClickDialpad(Qt::Key_1, Release); |
180 mUtil->mouseClickDialpad(Qt::Key_1, DialpadTestUtil::Release); |
256 QTest::qWait(1000); |
181 QTest::qWait(1000); |
257 // Check that character '1' is in editor. |
182 // Check that character '1' is in editor. |
258 QCOMPARE(mDialpad->editor().text(), QString("1")); |
183 QCOMPARE(mDialpad->editor().text(), QString("1")); |
259 } |
184 } |
260 |
185 |
261 void ut_DialpadVoiceMailboxEventFilter::testNumericKeyOneShortThenLongPress() |
186 void ut_DialpadVoiceMailboxEventFilter::testNumericKeyOneShortThenLongPress() |
262 { |
187 { |
263 // Then one short and one long press |
188 // Then one short and one long press |
264 mDialpad->openDialpad(); |
189 mDialpad->openDialpad(); |
265 QTest::qWait( WAIT_TIME ); |
190 QTest::qWait( WAIT_TIME ); |
266 mouseClickDialpad(Qt::Key_1, Press); |
191 mUtil->mouseClickDialpad(Qt::Key_1, DialpadTestUtil::Press); |
267 mouseClickDialpad(Qt::Key_1, Release); |
192 mUtil->mouseClickDialpad(Qt::Key_1, DialpadTestUtil::Release); |
268 mouseClickDialpad(Qt::Key_1, Press); |
193 mUtil->mouseClickDialpad(Qt::Key_1, DialpadTestUtil::Press); |
269 QTest::qWait(2000); |
194 QTest::qWait(2000); |
270 mouseClickDialpad(Qt::Key_1, Release); |
195 mUtil->mouseClickDialpad(Qt::Key_1, DialpadTestUtil::Release); |
271 QTest::qWait(1000); |
196 QTest::qWait(1000); |
272 QVERIFY(mDialpad->editor().text()=="11"); |
197 QVERIFY(mDialpad->editor().text()=="11"); |
273 mDialpad->closeDialpad(); |
198 mDialpad->closeDialpad(); |
274 } |
199 } |
275 |
200 |