|
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 #include <HbMainWindow> |
|
21 #include <HbLineEdit> |
|
22 #ifdef Q_OS_SYMBIAN |
|
23 #include <xqaiwinterfacedescriptor.h> |
|
24 #include <xqaiwrequest.h> |
|
25 #endif |
|
26 #include "ut_dialpadkeysequenceeventfilter.h" |
|
27 #include "dialpadtest.h" |
|
28 #include "dialpadkeysequenceeventfilter.h" |
|
29 #include "dialpad.h" |
|
30 |
|
31 const QString KValidKeySequence("*#1#"); |
|
32 |
|
33 void setValidatorReturnValue(QVariant &returnValue) |
|
34 { |
|
35 returnValue.setValue<QString>(QRegExp::escape(KValidKeySequence)); |
|
36 } |
|
37 |
|
38 UT_DialpadKeySequenceEventFilter::UT_DialpadKeySequenceEventFilter() |
|
39 : |
|
40 m_dialPad(0), |
|
41 m_eventFilter(0), |
|
42 m_lineEditMock(0) |
|
43 { |
|
44 |
|
45 } |
|
46 |
|
47 UT_DialpadKeySequenceEventFilter::~UT_DialpadKeySequenceEventFilter() |
|
48 { |
|
49 delete m_dialPad; |
|
50 delete m_eventFilter; |
|
51 delete m_lineEditMock; |
|
52 } |
|
53 |
|
54 void UT_DialpadKeySequenceEventFilter::init() |
|
55 { |
|
56 initialize(); |
|
57 |
|
58 m_lineEditMock = new HbLineEdit(); |
|
59 QT_TRAP_THROWING(SmcDefaultValue<HbLineEdit&>::SetL(*m_lineEditMock)) |
|
60 |
|
61 XQAiwInterfaceDescriptor descriptor; |
|
62 QString dummyOperation; |
|
63 bool isEmbedded = false; |
|
64 QList<XQAiwInterfaceDescriptor> interfaceList; |
|
65 interfaceList.append(descriptor); |
|
66 EXPECT(XQApplicationManager, list).returns(interfaceList); |
|
67 QPointer<XQAiwRequest> aiwRequest(new XQAiwRequest( |
|
68 descriptor, dummyOperation, isEmbedded)); |
|
69 EXPECT(XQApplicationManager, create).returns(aiwRequest.data()); |
|
70 EXPECT(XQAiwRequest, send) |
|
71 .willOnce(invoke(setValidatorReturnValue)) |
|
72 .returns(true); |
|
73 |
|
74 SmcDefaultValue<QString>::SetL(QString()); |
|
75 HbMainWindow *dummyWindow = NULL; |
|
76 m_dialPad = new Dialpad(*dummyWindow); |
|
77 m_eventFilter = new DialpadKeySequenceEventFilter(m_dialPad); |
|
78 |
|
79 QVERIFY(aiwRequest.isNull()); |
|
80 QVERIFY(verify()); |
|
81 } |
|
82 |
|
83 void UT_DialpadKeySequenceEventFilter::cleanup() |
|
84 { |
|
85 reset(); |
|
86 |
|
87 SmcDefaultValue<QString>::Reset(); |
|
88 SmcDefaultValue<HbLineEdit&>::Reset(); |
|
89 delete m_dialPad; |
|
90 m_dialPad = NULL; |
|
91 delete m_eventFilter; |
|
92 m_eventFilter = NULL; |
|
93 delete m_lineEditMock; |
|
94 m_lineEditMock = NULL; |
|
95 } |
|
96 |
|
97 #ifdef Q_OS_SYMBIAN |
|
98 |
|
99 void setServiceRequestReturnValue(QVariant & returnValue) |
|
100 { |
|
101 returnValue.setValue<bool>(true); |
|
102 } |
|
103 |
|
104 void UT_DialpadKeySequenceEventFilter::eventFilterValidKeySequence() |
|
105 { |
|
106 EXPECT(HbLineEdit, text).returns(KValidKeySequence); |
|
107 EXPECT(XQAiwInterfaceDescriptor, isValid).returns(false); |
|
108 EXPECT(XQAiwInterfaceDescriptor, isValid).returns(true); |
|
109 XQAiwInterfaceDescriptor dummyDescriptor; |
|
110 QString dummyOperation; |
|
111 QPointer<XQAiwRequest> aiwRequest(new XQAiwRequest( |
|
112 dummyDescriptor, dummyOperation, false)); |
|
113 EXPECT(XQApplicationManager, create).returns(aiwRequest.data()); |
|
114 EXPECT(XQAiwRequest, send) |
|
115 .willOnce(invoke(setServiceRequestReturnValue)) |
|
116 .returns(true); |
|
117 QKeyEvent keyEvent( |
|
118 QEvent::KeyRelease, |
|
119 Qt::Key_NumberSign, |
|
120 Qt::NoModifier); |
|
121 bool filtered = m_eventFilter->eventFilter(m_dialPad, &keyEvent); |
|
122 QVERIFY(!filtered); |
|
123 QVERIFY(aiwRequest.isNull()); |
|
124 QVERIFY(verify()); |
|
125 } |
|
126 |
|
127 void UT_DialpadKeySequenceEventFilter::eventFilterNotAKeyEvent() |
|
128 { |
|
129 EXPECT(XQAiwRequest, send).times(0); |
|
130 QMouseEvent mouseEvent( |
|
131 QEvent::MouseMove, |
|
132 QPoint(), |
|
133 Qt::LeftButton, |
|
134 Qt::LeftButton, |
|
135 Qt::NoModifier); |
|
136 bool filtered = m_eventFilter->eventFilter(m_dialPad, &mouseEvent); |
|
137 QVERIFY(!filtered); |
|
138 QVERIFY(verify()); |
|
139 } |
|
140 |
|
141 void UT_DialpadKeySequenceEventFilter::eventFilterNotAHashKey() |
|
142 { |
|
143 EXPECT(XQAiwRequest, send).times(0); |
|
144 QKeyEvent keyEvent( |
|
145 QEvent::KeyRelease, |
|
146 Qt::Key_Escape, |
|
147 Qt::NoModifier); |
|
148 bool filtered = m_eventFilter->eventFilter(m_dialPad, &keyEvent); |
|
149 QVERIFY(!filtered); |
|
150 QVERIFY(verify()); |
|
151 } |
|
152 |
|
153 void UT_DialpadKeySequenceEventFilter::eventFilterNotValidKeySequence() |
|
154 { |
|
155 const QString KInvalidKeySequence1("*##"); |
|
156 const QString KInvalidKeySequence2("#1234#"); |
|
157 const QString KInvalidKeySequence3("**1234#"); |
|
158 const QString KInvalidKeySequence4("*#1234*"); |
|
159 |
|
160 EXPECT(XQAiwRequest, send).times(0); |
|
161 |
|
162 EXPECT(HbLineEdit, text).returns(KInvalidKeySequence1); |
|
163 QKeyEvent keyEvent( |
|
164 QEvent::KeyRelease, |
|
165 Qt::Key_NumberSign, |
|
166 Qt::NoModifier); |
|
167 bool filtered = m_eventFilter->eventFilter(m_dialPad, &keyEvent); |
|
168 QVERIFY(!filtered); |
|
169 |
|
170 EXPECT(HbLineEdit, text).returns(KInvalidKeySequence2); |
|
171 filtered = m_eventFilter->eventFilter(m_dialPad, &keyEvent); |
|
172 QVERIFY(!filtered); |
|
173 |
|
174 EXPECT(HbLineEdit, text).returns(KInvalidKeySequence3); |
|
175 filtered = m_eventFilter->eventFilter(m_dialPad, &keyEvent); |
|
176 QVERIFY(!filtered); |
|
177 |
|
178 EXPECT(HbLineEdit, text).returns(KInvalidKeySequence4); |
|
179 filtered = m_eventFilter->eventFilter(m_dialPad, &keyEvent); |
|
180 QVERIFY(!filtered); |
|
181 |
|
182 QVERIFY(verify()); |
|
183 } |
|
184 |
|
185 void UT_DialpadKeySequenceEventFilter::eventFilterServiceRequestFails() |
|
186 { |
|
187 // Qt Highway error while issuing service request |
|
188 EXPECT(HbLineEdit, text).returns(KValidKeySequence); |
|
189 EXPECT(XQAiwInterfaceDescriptor, isValid).returns(false); |
|
190 EXPECT(XQAiwInterfaceDescriptor, isValid).returns(true); |
|
191 XQAiwInterfaceDescriptor dummyDescriptor; |
|
192 QString dummyOperation; |
|
193 QPointer<XQAiwRequest> aiwRequest1(new XQAiwRequest( |
|
194 dummyDescriptor, dummyOperation, false)); |
|
195 EXPECT(XQApplicationManager, create).returns(aiwRequest1.data()); |
|
196 EXPECT(XQAiwRequest, send).returns(false); |
|
197 QKeyEvent keyEvent( |
|
198 QEvent::KeyRelease, |
|
199 Qt::Key_NumberSign, |
|
200 Qt::NoModifier); |
|
201 bool filtered = m_eventFilter->eventFilter(m_dialPad, &keyEvent); |
|
202 QVERIFY(!filtered); |
|
203 QVERIFY(aiwRequest1.isNull()); |
|
204 QVERIFY(verify()); |
|
205 |
|
206 // service provider fails to fulfill request |
|
207 EXPECT(HbLineEdit, text).returns(KValidKeySequence); |
|
208 EXPECT(XQAiwInterfaceDescriptor, isValid).returns(false); |
|
209 EXPECT(XQAiwInterfaceDescriptor, isValid).returns(true); |
|
210 QPointer<XQAiwRequest> aiwRequest2(new XQAiwRequest( |
|
211 dummyDescriptor, dummyOperation, false)); |
|
212 EXPECT(XQApplicationManager, create).returns(aiwRequest2.data()); |
|
213 EXPECT(XQAiwRequest, send).returns(true); |
|
214 filtered = m_eventFilter->eventFilter(m_dialPad, &keyEvent); |
|
215 QVERIFY(!filtered); |
|
216 QVERIFY(aiwRequest2.isNull()); |
|
217 QVERIFY(verify()); |
|
218 } |
|
219 |
|
220 #endif |
|
221 |
|
222 int main(int argc, char *argv[]) |
|
223 { |
|
224 QCoreApplication app(argc, argv); |
|
225 UT_DialpadKeySequenceEventFilter tc; |
|
226 return QTest::qExec(&tc, argc, argv); |
|
227 } |