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: Unit tests for PhoneUIQtView. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtTest/QtTest> |
|
19 #include <QtGui> |
|
20 #include <QVariant> |
|
21 #include <QKeyEvent> |
|
22 #include <hbapplication.h> |
|
23 #include "phoneuikeyeventadapter.h" |
|
24 #include "cphoneuicontroller_stub.h" |
|
25 #include "phoneconstants.h" |
|
26 |
|
27 |
|
28 //CONSTANTS |
|
29 |
|
30 |
|
31 #define PHONE_QT_TEST_MAIN(TestObject) \ |
|
32 int main(int argc, char *argv[]) \ |
|
33 { \ |
|
34 HbApplication app(argc, argv); \ |
|
35 TestObject tc; \ |
|
36 QResource::registerResource("../hbcore.rcc"); \ |
|
37 int ret = QTest::qExec(&tc, argc, argv); \ |
|
38 /* Core dump if HbIconLoader instance is not destroyed before the application instance. */ \ |
|
39 /* HbIconLoader uses QCoreApplication::aboutToQuit() signal to destroy itself. */ \ |
|
40 /* app.exec() where the signal is normally emitted is not called here. */ \ |
|
41 /* So, invoking the signal explicitly. */ \ |
|
42 QMetaObject::invokeMethod(&app, "aboutToQuit", Qt::DirectConnection); \ |
|
43 return ret; \ |
|
44 } |
|
45 |
|
46 class TestPhoneKeyEventAdapter : public QObject |
|
47 { |
|
48 Q_OBJECT |
|
49 |
|
50 public: |
|
51 TestPhoneKeyEventAdapter (); |
|
52 ~TestPhoneKeyEventAdapter (); |
|
53 |
|
54 |
|
55 public slots: |
|
56 void initTestCase (); |
|
57 void cleanupTestCase (); |
|
58 void init (); |
|
59 void cleanup (); |
|
60 |
|
61 private slots: |
|
62 void testKeyPressEvents(); |
|
63 void testKeyReleaseEvents(); |
|
64 void testKeyPressEventsByQtKeys(); |
|
65 void testLeave(); |
|
66 |
|
67 |
|
68 |
|
69 private: |
|
70 PhoneUIKeyEventAdapter *m_keyadapter; // class under test |
|
71 CPhoneUIController_Stub *m_uicontrol; |
|
72 |
|
73 }; |
|
74 |
|
75 |
|
76 TestPhoneKeyEventAdapter::TestPhoneKeyEventAdapter () |
|
77 { |
|
78 } |
|
79 |
|
80 TestPhoneKeyEventAdapter::~TestPhoneKeyEventAdapter () |
|
81 { |
|
82 } |
|
83 |
|
84 void TestPhoneKeyEventAdapter::initTestCase () |
|
85 { |
|
86 } |
|
87 |
|
88 void TestPhoneKeyEventAdapter::cleanupTestCase () |
|
89 { |
|
90 } |
|
91 |
|
92 void TestPhoneKeyEventAdapter::init () |
|
93 { |
|
94 m_uicontrol = new CPhoneUIController_Stub(); |
|
95 m_keyadapter = new PhoneUIKeyEventAdapter(*m_uicontrol); |
|
96 } |
|
97 |
|
98 void TestPhoneKeyEventAdapter::cleanup () |
|
99 { |
|
100 delete m_uicontrol; |
|
101 delete m_keyadapter; |
|
102 } |
|
103 |
|
104 void TestPhoneKeyEventAdapter::testKeyPressEvents () |
|
105 { |
|
106 quint32 scanCode = 123; |
|
107 quint32 code = 123; |
|
108 quint32 modifiers = 0; |
|
109 QKeyEvent *keyEvent = QKeyEvent::createExtendedKeyEvent( |
|
110 QEvent::KeyPress, 123, Qt::NoModifier, scanCode, code, modifiers ); |
|
111 |
|
112 m_keyadapter->keyPressed(keyEvent); |
|
113 |
|
114 QVERIFY( 0 == m_repeats ); |
|
115 QVERIFY( scanCode == m_scan_code_down ); |
|
116 QVERIFY( code == m_code_down ); |
|
117 |
|
118 delete keyEvent; |
|
119 } |
|
120 |
|
121 void TestPhoneKeyEventAdapter::testKeyReleaseEvents () |
|
122 { |
|
123 quint32 scanCode = 100; |
|
124 quint32 code = 100; |
|
125 quint32 modifiers = 0; |
|
126 QKeyEvent *keyEvent = QKeyEvent::createExtendedKeyEvent( |
|
127 QEvent::KeyRelease, code, Qt::NoModifier, scanCode, code, modifiers ); |
|
128 |
|
129 m_keyadapter->keyReleased(keyEvent); |
|
130 |
|
131 QVERIFY( 0 == m_repeats ); |
|
132 QVERIFY( scanCode == m_scan_code ); |
|
133 QVERIFY( code == m_code ); |
|
134 |
|
135 delete keyEvent; |
|
136 |
|
137 } |
|
138 |
|
139 void TestPhoneKeyEventAdapter::testKeyPressEventsByQtKeys () |
|
140 { |
|
141 quint32 scanCode = 100; |
|
142 quint32 code = 20; |
|
143 quint32 modifiers = 0; |
|
144 QKeyEvent *keyEvent = QKeyEvent::createExtendedKeyEvent( |
|
145 QEvent::KeyRelease, Qt::Key_Yes, Qt::NoModifier, scanCode, code, modifiers ); |
|
146 |
|
147 m_keyadapter->keyPressed(keyEvent); |
|
148 |
|
149 QVERIFY( 0 == m_repeats ); |
|
150 QVERIFY( EKeyYes == m_scan_code_down ); |
|
151 QVERIFY( EKeyYes == m_code_down ); |
|
152 |
|
153 delete keyEvent; |
|
154 |
|
155 keyEvent = QKeyEvent::createExtendedKeyEvent( |
|
156 QEvent::KeyRelease, Qt::Key_No, Qt::NoModifier, scanCode, code, modifiers ); |
|
157 |
|
158 m_keyadapter->keyPressed(keyEvent); |
|
159 |
|
160 QVERIFY( 0 == m_repeats ); |
|
161 QVERIFY( EKeyNo == m_scan_code_down ); |
|
162 QVERIFY( EKeyNo == m_code_down ); |
|
163 |
|
164 delete keyEvent; |
|
165 |
|
166 keyEvent = QKeyEvent::createExtendedKeyEvent( |
|
167 QEvent::KeyRelease, Qt::Key_NumberSign, Qt::NoModifier, scanCode, code, modifiers ); |
|
168 |
|
169 m_keyadapter->keyPressed(keyEvent); |
|
170 |
|
171 QVERIFY( 0 == m_repeats ); |
|
172 QVERIFY( KPhoneDtmfHashCharacter == m_scan_code_down ); |
|
173 QVERIFY( KPhoneDtmfHashCharacter == m_code_down ); |
|
174 |
|
175 delete keyEvent; |
|
176 |
|
177 } |
|
178 |
|
179 void TestPhoneKeyEventAdapter::testLeave () |
|
180 { |
|
181 m_leave = true; |
|
182 quint32 scanCode = 100; |
|
183 quint32 code = 20; |
|
184 quint32 modifiers = 0; |
|
185 QKeyEvent *keyEvent = QKeyEvent::createExtendedKeyEvent( |
|
186 QEvent::KeyRelease, 0, Qt::NoModifier, scanCode, code, modifiers ); |
|
187 |
|
188 m_keyadapter->keyPressed(keyEvent); |
|
189 |
|
190 QVERIFY( 0 == m_scan_code ); |
|
191 QVERIFY( 0 == m_code ); |
|
192 |
|
193 m_keyadapter->keyReleased(keyEvent); |
|
194 |
|
195 QVERIFY( 0 == m_scan_code ); |
|
196 QVERIFY( 0 == m_code ); |
|
197 |
|
198 m_leave = false; |
|
199 |
|
200 delete keyEvent; |
|
201 } |
|
202 |
|
203 PHONE_QT_TEST_MAIN(TestPhoneKeyEventAdapter) |
|
204 #include "unit_tests.moc" |
|