|
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 |
|
21 #include <hbapplication.h> |
|
22 #include <hbmainwindow.h> |
|
23 #include <hbaction.h> |
|
24 #include <hbtoolbar.h> |
|
25 #include <hbview.h> |
|
26 #include <hblineedit.h> |
|
27 #include <hbinstance.h> |
|
28 |
|
29 #ifdef Q_OS_SYMBIAN |
|
30 #include "xqservicerequest.h" |
|
31 #endif |
|
32 |
|
33 #include "dialpadtest.h" |
|
34 #include "dialpadtestutil.h" |
|
35 #include "dialpadvideomailboxeventfilter.h" |
|
36 #include "dialpad.h" |
|
37 #include "dialpadsymbianwrapper.h" |
|
38 |
|
39 const int WAIT_TIME = 300; |
|
40 QString mService; |
|
41 QString mMessage; |
|
42 bool mXQServiceConstructed; |
|
43 bool mSendCalled; |
|
44 |
|
45 DialpadSymbianWrapper::DialpadSymbianWrapper(QObject */*parent*/) : d_ptr(NULL) {} |
|
46 DialpadSymbianWrapper::~DialpadSymbianWrapper() {} |
|
47 int DialpadSymbianWrapper::getVideoMailboxNumber(QString &vmbxNumber) { vmbxNumber=QString("12345678"); return 0; } |
|
48 int DialpadSymbianWrapper::defineVideoMailboxNumber(QString &/*vmbxNumber*/) { return 0; } |
|
49 |
|
50 #ifdef Q_OS_SYMBIAN |
|
51 XQServiceRequest::XQServiceRequest(const QString& service, const QString& message, const bool& /*synchronous*/) { mService=service; mMessage=message; mXQServiceConstructed=true; } |
|
52 XQServiceRequest::~XQServiceRequest() {} |
|
53 bool XQServiceRequest::send(QVariant& /*retValue*/) { mSendCalled=true; return true; } |
|
54 void XQServiceRequest::addArg(const QVariant& /*v*/) {} |
|
55 #endif |
|
56 |
|
57 // helper class |
|
58 class KeyEventCatcher : public QObject |
|
59 { |
|
60 public: |
|
61 bool eventFilter(QObject* watched, QEvent * event) |
|
62 { |
|
63 Q_UNUSED(watched); |
|
64 |
|
65 if (event->type() == QEvent::KeyPress) { |
|
66 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); |
|
67 mKeyPresses.append(keyEvent->key()); |
|
68 return false; |
|
69 } else if (event->type() == QEvent::KeyRelease) { |
|
70 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); |
|
71 mKeyReleases.append(keyEvent->key()); |
|
72 return false; |
|
73 } |
|
74 return false; |
|
75 } |
|
76 |
|
77 public: |
|
78 QList<int> mKeyPresses; |
|
79 QList<int> mKeyReleases; |
|
80 }; |
|
81 |
|
82 // test cases |
|
83 class ut_DialpadVideoMailboxEventFilter : public QObject |
|
84 { |
|
85 Q_OBJECT |
|
86 |
|
87 private slots: |
|
88 void initTestCase(); |
|
89 void init(); |
|
90 void cleanupTestCase(); |
|
91 void cleanup(); |
|
92 |
|
93 // These are actual voice mailbox event filter unit tests |
|
94 void testNumericKeyTwoLongPress(); |
|
95 void testNumericKeyTwoShortPress(); |
|
96 void testNumericKeyTwoShortThenLongPress(); |
|
97 |
|
98 private: |
|
99 HbMainWindow* mMainWindow; |
|
100 Dialpad* mDialpad; |
|
101 DialpadVideoMailboxEventFilter *mEventFilter; |
|
102 KeyEventCatcher* mKeyCatcher; |
|
103 DialpadTestUtil* mUtil; |
|
104 }; |
|
105 |
|
106 void ut_DialpadVideoMailboxEventFilter::initTestCase() |
|
107 { |
|
108 mMainWindow = new HbMainWindow; |
|
109 |
|
110 mKeyCatcher = new KeyEventCatcher; |
|
111 mMainWindow->installEventFilter(mKeyCatcher); |
|
112 |
|
113 mUtil = new DialpadTestUtil(*mMainWindow); |
|
114 |
|
115 mDialpad = new Dialpad(); |
|
116 mEventFilter = new DialpadVideoMailboxEventFilter(mDialpad, this); |
|
117 hbInstance->allMainWindows().at(0)->installEventFilter(mEventFilter); |
|
118 |
|
119 QRectF rect(mMainWindow->contentsRect()); |
|
120 rect.setHeight(rect.height()*0.7); |
|
121 rect.moveTop((mMainWindow->contentsRect().height()-rect.height())/2); |
|
122 |
|
123 mDialpad->setPreferredSize(360,400); |
|
124 mDialpad->setPos(0,100); |
|
125 |
|
126 mMainWindow->show(); |
|
127 mDialpad->show(); |
|
128 mDialpad->hide(); |
|
129 } |
|
130 |
|
131 void ut_DialpadVideoMailboxEventFilter::init() |
|
132 { |
|
133 mService = QString(""); |
|
134 mMessage = QString(""); |
|
135 mXQServiceConstructed = false; |
|
136 mSendCalled = false; |
|
137 } |
|
138 |
|
139 void ut_DialpadVideoMailboxEventFilter::cleanupTestCase() |
|
140 { |
|
141 delete mDialpad; |
|
142 delete mMainWindow; |
|
143 delete mKeyCatcher; |
|
144 delete mUtil; |
|
145 } |
|
146 |
|
147 void ut_DialpadVideoMailboxEventFilter::cleanup() |
|
148 { |
|
149 mKeyCatcher->mKeyPresses.clear(); |
|
150 mKeyCatcher->mKeyReleases.clear(); |
|
151 mDialpad->editor().setText(QString()); |
|
152 QTest::qWait( WAIT_TIME ); // delay between tests |
|
153 } |
|
154 |
|
155 void ut_DialpadVideoMailboxEventFilter::testNumericKeyTwoLongPress() |
|
156 { |
|
157 mDialpad->openDialpad(); |
|
158 QTest::qWait(WAIT_TIME); |
|
159 mUtil->mouseClickDialpad(Qt::Key_2, DialpadTestUtil::Press); |
|
160 QTest::qWait(2000); |
|
161 mUtil->mouseClickDialpad(Qt::Key_2, DialpadTestUtil::Release); |
|
162 QTest::qWait(1000); |
|
163 QCOMPARE(mDialpad->editor().text(), QString("")); |
|
164 mDialpad->closeDialpad(); |
|
165 |
|
166 #ifdef Q_OS_SYMBIAN |
|
167 QVERIFY(mXQServiceConstructed == true); |
|
168 QVERIFY(mSendCalled == true); |
|
169 QCOMPARE(mService, QString("com.nokia.symbian.ICallDial")); |
|
170 QCOMPARE(mMessage, QString("dialVideo(QString)")); |
|
171 #endif |
|
172 } |
|
173 |
|
174 void ut_DialpadVideoMailboxEventFilter::testNumericKeyTwoShortPress() |
|
175 { |
|
176 mDialpad->openDialpad(); |
|
177 QTest::qWait(WAIT_TIME); |
|
178 mUtil->mouseClickDialpad(Qt::Key_2, DialpadTestUtil::Press); |
|
179 QTest::qWait(200); |
|
180 mUtil->mouseClickDialpad(Qt::Key_2, DialpadTestUtil::Release); |
|
181 QTest::qWait(1000); |
|
182 // Check that character '1' is in editor. |
|
183 QCOMPARE(mDialpad->editor().text(), QString("2")); |
|
184 } |
|
185 |
|
186 void ut_DialpadVideoMailboxEventFilter::testNumericKeyTwoShortThenLongPress() |
|
187 { |
|
188 // Then one short and one long press |
|
189 mDialpad->openDialpad(); |
|
190 QTest::qWait( WAIT_TIME ); |
|
191 mUtil->mouseClickDialpad(Qt::Key_2, DialpadTestUtil::Press); |
|
192 mUtil->mouseClickDialpad(Qt::Key_2, DialpadTestUtil::Release); |
|
193 mUtil->mouseClickDialpad(Qt::Key_2, DialpadTestUtil::Press); |
|
194 QTest::qWait(2000); |
|
195 mUtil->mouseClickDialpad(Qt::Key_2, DialpadTestUtil::Release); |
|
196 QTest::qWait(1000); |
|
197 QVERIFY(mDialpad->editor().text()=="22"); |
|
198 mDialpad->closeDialpad(); |
|
199 } |
|
200 |
|
201 DIALPAD_TEST_MAIN(ut_DialpadVideoMailboxEventFilter) |
|
202 #include "ut_dialpadvideomailboxeventfilter.moc" |