|
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: |
|
15 * |
|
16 */ |
|
17 #include <QTest> |
|
18 #include <QSignalSpy> |
|
19 #include <hbmainwindow.h> |
|
20 #include "cxutils.h" |
|
21 //#include "cxuiviewmanager.h" |
|
22 #include "cxuifakeengine.h" |
|
23 #include "cxuitest.h" |
|
24 #include "cxuienums.h" |
|
25 //#include "cxeviewfindercontrol.h" |
|
26 |
|
27 |
|
28 // Tests only that correct view is activated |
|
29 void TestCxUi::testItemVisibilityInPrecaptureview() |
|
30 { |
|
31 CX_DEBUG(("testZoomInPrecaptureview")); |
|
32 mEngine->initMode(Cxe::ImageMode); |
|
33 emit toPrecaptureView(); |
|
34 QTest::qWait(1000); |
|
35 QVERIFY( mMainWindow->currentViewIndex()== CxUi::StillPreCaptureView ); |
|
36 //QVERIFY(mMainWindow->visibleItems().count() == 0); |
|
37 QTest::mousePress( mMainWindow->viewport(), Qt::LeftButton,0, QPoint(180,60), 5 ); |
|
38 //QVERIFY(mMainWindow->visibleItems().count() == 7); |
|
39 //mMainWindow->visibleItems(); |
|
40 QCOMPARE(mMainWindow->isItemVisible(Hb::TitlePaneItem), true); |
|
41 QCOMPARE(mMainWindow->isItemVisible(Hb::NaviPaneItem), true); |
|
42 QCOMPARE(mMainWindow->isItemVisible(Hb::ToolBarItem), true); |
|
43 QCOMPARE(mMainWindow->isItemVisible(Hb::IndicatorItems), true); |
|
44 QCOMPARE(mMainWindow->isItemVisible(Hb::PrimarySoftKeyItem), true); |
|
45 QCOMPARE(mMainWindow->isItemVisible(Hb::SecondarySoftKeyItem), true); |
|
46 QCOMPARE(mMainWindow->isItemVisible(Hb::MiddleSoftKeyItem), true); |
|
47 QCOMPARE(mMainWindow->isItemVisible(Hb::SoftKeyItems), true); |
|
48 QTest::mousePress( mMainWindow->viewport(), Qt::LeftButton,0, QPoint(35,150), 5 ); |
|
49 QCOMPARE(mMainWindow->visibleItems(), Hb::AllItems); |
|
50 QCOMPARE(mMainWindow->isItemVisible(Hb::TitlePaneItem), false); |
|
51 |
|
52 } |
|
53 |
|
54 // Tests only that correct view is activated |
|
55 void TestCxUi::testViewManager() |
|
56 { |
|
57 CX_DEBUG(("testViewManager")); |
|
58 mEngineFake->initModeFake(Cxe::ImageMode); |
|
59 |
|
60 connect(this, SIGNAL(toPostcaptureView()), mViewManager, SLOT(changeToPostView())); |
|
61 connect(this, SIGNAL(toPrecaptureView()), mViewManager, SLOT(changeToPreView())); |
|
62 |
|
63 // Test if we are in still VF |
|
64 QVERIFY(mMainWindow->currentViewIndex() == CxUi::StillPreCaptureView ); |
|
65 |
|
66 emit toPostcaptureView(); |
|
67 // Test if image review activated |
|
68 QVERIFY( mMainWindow->currentViewIndex()== CxUi::StillPostCaptureView ); |
|
69 |
|
70 emit toPrecaptureView(); |
|
71 // Test if still VF view active |
|
72 QVERIFY( mMainWindow->currentViewIndex()== CxUi::StillPreCaptureView ); |
|
73 |
|
74 mEngineFake->initModeFake(Cxe::VideoMode); |
|
75 emit toPrecaptureView(); |
|
76 // Test if video VF view active |
|
77 QVERIFY( mMainWindow->currentViewIndex() == CxUi::VideoPreCaptureView ); |
|
78 |
|
79 emit toPostcaptureView(); |
|
80 // Test if video review active |
|
81 QVERIFY( mMainWindow->currentViewIndex() == CxUi::VideoPostCaptureView ); |
|
82 |
|
83 emit toPrecaptureView(); |
|
84 // Test if video VF view active |
|
85 QVERIFY( mMainWindow->currentViewIndex() == CxUi::VideoPreCaptureView ); |
|
86 |
|
87 // Go back to original state... |
|
88 mEngineFake->initModeFake(Cxe::ImageMode); |
|
89 emit toPrecaptureView(); |
|
90 QTest::qWait(500); |
|
91 } |
|
92 |
|
93 // Tests capture key in still mode |
|
94 /* |
|
95 void TestCxUi::testCaptureKeyInImageMode() |
|
96 { |
|
97 mEngine->initMode(Cxe::ImageMode); |
|
98 QTest::qWait(1000); |
|
99 // Test if we are in still VF |
|
100 QVERIFY(mMainWindow->currentViewIndex() == CxUi::StillPreCaptureView ); |
|
101 |
|
102 CX_DEBUG(("testCaptureKey in still capture mode")); |
|
103 |
|
104 QKeyEvent* captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
105 QEvent::KeyPress, Qt::Key_unknown, 0, 0xab, 0,0); |
|
106 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
107 captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
108 QEvent::KeyRelease, Qt::Key_unknown, 0, 0xab, 0,0); |
|
109 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
110 QSignalSpy deviceStateSpy(&mEngine->stillCaptureControl(), |
|
111 SIGNAL(snapshotReady(int))); |
|
112 QVERIFY( deviceStateSpy.isValid() ); |
|
113 QTest::qWait(3000); |
|
114 QCOMPARE( deviceStateSpy.count(), 1 ); |
|
115 if (deviceStateSpy.count() > 0) { |
|
116 // Expect zero error code |
|
117 QList<QVariant> initModeArguments = deviceStateSpy.takeFirst(); |
|
118 QVERIFY( initModeArguments.at(0).toInt() == 0 ); |
|
119 } |
|
120 QVERIFY( mMainWindow->currentViewIndex()== CxUi::StillPostCaptureView ); |
|
121 |
|
122 CX_DEBUG(("Test to get back viewfinder with capture key")); |
|
123 captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
124 QEvent::KeyPress, Qt::Key_unknown, 0, 0xab, 0,0); |
|
125 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
126 captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
127 QEvent::KeyRelease, Qt::Key_unknown, 0, 0xab, 0,0); |
|
128 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
129 QTest::qWait(1000); |
|
130 QVERIFY( mMainWindow->currentViewIndex()== CxUi::StillPreCaptureView ); |
|
131 |
|
132 // Test autofocus with halfkeypress and releasing |
|
133 CX_DEBUG(("testAutoFocus_1")); |
|
134 |
|
135 QSignalSpy autofocusStateSpy(&mEngine->autoFocusControl(), |
|
136 SIGNAL(stateChanged(CxeAutoFocusControl::State,int))); |
|
137 QVERIFY( autofocusStateSpy.isValid() ); |
|
138 |
|
139 captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
140 QEvent::KeyPress, |
|
141 Qt::Key_unknown, |
|
142 0, |
|
143 0xe2, |
|
144 0, |
|
145 0); |
|
146 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
147 |
|
148 CX_DEBUG(("testAutoFocus cancel")); |
|
149 captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
150 QEvent::KeyRelease, |
|
151 Qt::Key_unknown, |
|
152 0, |
|
153 0xe2, |
|
154 0, |
|
155 0); |
|
156 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
157 QTest::qWait(100); |
|
158 |
|
159 QCOMPARE( autofocusStateSpy.count(), 3 ); |
|
160 if (autofocusStateSpy.count() > 0) { |
|
161 QList<QVariant> initModeArguments = autofocusStateSpy.takeFirst(); |
|
162 QVERIFY( initModeArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::InProgress ); |
|
163 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
164 CX_DEBUG(("testAutoFocus_2a")); |
|
165 initModeArguments = autofocusStateSpy.takeAt(0); |
|
166 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
167 QVERIFY( initModeArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::Canceling ); |
|
168 initModeArguments = autofocusStateSpy.takeAt(0); |
|
169 QVERIFY( initModeArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::Unknown ); |
|
170 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
171 } |
|
172 |
|
173 // Test autofocus with halfkeypress and capture focused image |
|
174 CX_DEBUG(("testAutoFocus_2")); |
|
175 |
|
176 captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
177 QEvent::KeyPress, |
|
178 Qt::Key_unknown, |
|
179 0, |
|
180 0xe2, |
|
181 0, |
|
182 0); |
|
183 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
184 captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
185 QEvent::KeyRelease, Qt::Key_unknown, 0, 0xab, 0,0); |
|
186 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
187 QTest::qWait(5000); |
|
188 |
|
189 QCOMPARE( autofocusStateSpy.count(), 2 ); |
|
190 if (autofocusStateSpy.count() > 0) { |
|
191 QList<QVariant> initModeArguments = autofocusStateSpy.takeFirst(); |
|
192 QVERIFY( initModeArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::InProgress ); |
|
193 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
194 initModeArguments = autofocusStateSpy.takeAt(0); |
|
195 QVERIFY( initModeArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::Ready || |
|
196 initModeArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::Failed ); |
|
197 |
|
198 } |
|
199 |
|
200 CX_DEBUG(("Capture autofocused image")); |
|
201 captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
202 QEvent::KeyPress, |
|
203 Qt::Key_unknown, |
|
204 0, |
|
205 0xab, |
|
206 0, |
|
207 0); |
|
208 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
209 captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
210 QEvent::KeyRelease, Qt::Key_unknown, 0, 0xab, 0,0); |
|
211 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
212 QTest::qWait(5000); |
|
213 |
|
214 QCOMPARE( deviceStateSpy.count(), 1 ); |
|
215 if (deviceStateSpy.count() > 0) { |
|
216 // Expect zero error code |
|
217 QList<QVariant> initModeArguments = deviceStateSpy.takeFirst(); |
|
218 QVERIFY( initModeArguments.at(0).toInt() == 0 ); |
|
219 } |
|
220 QVERIFY( mMainWindow->currentViewIndex()== CxUi::StillPostCaptureView ); |
|
221 |
|
222 } |
|
223 */ |
|
224 /* |
|
225 // Tests capture key in video mode |
|
226 void TestCxUi::testCaptureKeyInVideoMode() |
|
227 { |
|
228 connect(this, SIGNAL(toPrecaptureView()), mViewManager, SLOT(changeToPreView())); |
|
229 QSignalSpy deviceStateSpy(&mEngine->videoCaptureControl(), |
|
230 SIGNAL(stateChanged(CxeVideoCaptureControl::State, int))); |
|
231 QVERIFY( deviceStateSpy.isValid() ); |
|
232 emit toPrecaptureView(); |
|
233 QTest::qWait(500); |
|
234 // Test if we are in still VF |
|
235 QVERIFY(mMainWindow->currentViewIndex() == CxUi::VideoPreCaptureView ); |
|
236 |
|
237 // Generate camera key event to start recording |
|
238 CX_DEBUG(("Start video recording")); |
|
239 QKeyEvent* captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
240 QEvent::KeyPress, |
|
241 Qt::Key_unknown, |
|
242 0, |
|
243 0xab, |
|
244 0, |
|
245 0); |
|
246 |
|
247 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
248 captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
249 QEvent::KeyRelease, Qt::Key_unknown, 0, 0xab, 0,0); |
|
250 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
251 QTest::qWait(5000); |
|
252 |
|
253 // Generate camera key event to stop recording |
|
254 CX_DEBUG(("Stop video recording")); |
|
255 captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
256 QEvent::KeyPress, |
|
257 Qt::Key_unknown, |
|
258 0, |
|
259 0xab, |
|
260 0, |
|
261 0); |
|
262 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
263 captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
264 QEvent::KeyRelease, Qt::Key_unknown, 0, 0xab, 0,0); |
|
265 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
266 QTest::qWait(3000); |
|
267 |
|
268 QCOMPARE( deviceStateSpy.count(), 4 ); |
|
269 |
|
270 QList<QVariant> initModeArguments = deviceStateSpy.takeAt(0); |
|
271 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::PlayingStartSound ); |
|
272 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
273 initModeArguments = deviceStateSpy.takeAt(0); |
|
274 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
275 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Recording ); |
|
276 initModeArguments = deviceStateSpy.takeAt(0); |
|
277 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
278 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Stopping ); |
|
279 initModeArguments = deviceStateSpy.takeAt(0); |
|
280 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Idle ); |
|
281 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
282 |
|
283 QVERIFY( mMainWindow->currentViewIndex()== CxUi::VideoPostCaptureView ); |
|
284 |
|
285 CX_DEBUG(("Test to get back viewfinder with capture key")); |
|
286 captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
287 QEvent::KeyPress, Qt::Key_unknown, 0, 0xab, 0,0); |
|
288 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
289 captureKeyEvent = QKeyEvent::createExtendedKeyEvent( |
|
290 QEvent::KeyRelease, Qt::Key_unknown, 0, 0xab, 0,0); |
|
291 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
292 QTest::qWait(5000); |
|
293 QVERIFY( mMainWindow->currentViewIndex()== CxUi::VideoPreCaptureView ); |
|
294 |
|
295 QCOMPARE(deviceStateSpy.count(), 3); |
|
296 if (deviceStateSpy.count() > 0) { |
|
297 QList<QVariant> initModeArguments = deviceStateSpy.takeAt(0); |
|
298 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Open ); |
|
299 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
300 initModeArguments = deviceStateSpy.takeAt(0); |
|
301 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
302 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Preparing ); |
|
303 initModeArguments = deviceStateSpy.takeAt(0); |
|
304 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Ready ); |
|
305 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
306 } |
|
307 |
|
308 } |
|
309 */ |