|
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 <hbslider.h> |
|
21 #include <hbaction.h> |
|
22 #include "cxuitestbat.h" |
|
23 #include "cxeengine.h" |
|
24 #include "cxenamespace.h" |
|
25 #include "cxevideocapturecontrol.h" |
|
26 #include "cxeviewfindercontrol.h" |
|
27 #include "cxuiviewmanager.h" |
|
28 #include "cxutils.h" |
|
29 #include "cxuienums.h" |
|
30 #include "cxuicapturekeyhandler.h" |
|
31 #include "cxuidocumentloader.h" |
|
32 |
|
33 |
|
34 // Run before each test |
|
35 void TestCxUiBat::initTestCase() |
|
36 { |
|
37 |
|
38 mMainWindow = new HbMainWindow; |
|
39 mMainWindow->setOrientation(Qt::Horizontal); |
|
40 mEngine = CxeEngine::createEngine(); |
|
41 |
|
42 mKeyHandler = new CxuiCaptureKeyHandler(*mEngine); |
|
43 mViewManager = new CxuiViewManager(*mMainWindow, *mEngine, *mKeyHandler); |
|
44 |
|
45 mViewManager->prepareWindow(); |
|
46 mMainWindow->showFullScreen(); |
|
47 } |
|
48 |
|
49 // Run after each test |
|
50 void TestCxUiBat::cleanup() |
|
51 { |
|
52 //delete mEngine; |
|
53 } |
|
54 |
|
55 // Run after each test |
|
56 void TestCxUiBat::cleanupTestCase() |
|
57 { |
|
58 delete mMainWindow; |
|
59 delete mKeyHandler; |
|
60 delete mViewManager; |
|
61 //delete mEngine; |
|
62 } |
|
63 |
|
64 void TestCxUiBat::initStillImageMode() |
|
65 { |
|
66 mEngine->initMode( Cxe::ImageMode ); |
|
67 |
|
68 } |
|
69 |
|
70 void TestCxUiBat::sendCameraKeyEvent(QEvent::Type event) |
|
71 { |
|
72 CX_DEBUG_ENTER_FUNCTION(); |
|
73 QKeyEvent* captureKeyEvent; |
|
74 if (event == QEvent::None) { |
|
75 captureKeyEvent = QKeyEvent::createExtendedKeyEvent(QEvent::KeyPress, Qt::Key_unknown, 0, |
|
76 0xab, 0, 0); |
|
77 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
78 captureKeyEvent = QKeyEvent::createExtendedKeyEvent(QEvent::KeyRelease, Qt::Key_unknown, 0, |
|
79 0xab, 0, 0); |
|
80 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
81 |
|
82 } else { |
|
83 captureKeyEvent = QKeyEvent::createExtendedKeyEvent(event, Qt::Key_unknown, 0, 0xab, 0, 0); |
|
84 QApplication::postEvent(mMainWindow, captureKeyEvent); |
|
85 } |
|
86 CX_DEBUG_EXIT_FUNCTION(); |
|
87 } |
|
88 |
|
89 void TestCxUiBat::sendAutofocusKeyEvent(QEvent::Type event) |
|
90 { |
|
91 CX_DEBUG_ENTER_FUNCTION(); |
|
92 QKeyEvent* autofocusKeyEvent = QKeyEvent::createExtendedKeyEvent(event, Qt::Key_unknown, 0, |
|
93 0xe2, 0, 0); |
|
94 QApplication::postEvent(mMainWindow, autofocusKeyEvent); |
|
95 CX_DEBUG_EXIT_FUNCTION(); |
|
96 } |
|
97 |
|
98 void TestCxUiBat::initVideoMode() |
|
99 { |
|
100 mEngine->initMode( Cxe::VideoMode ); |
|
101 |
|
102 QSignalSpy deviceStateSpy(&mEngine->videoCaptureControl(), |
|
103 SIGNAL(stateChanged(CxeVideoCaptureControl::State, CxeError::Id))); |
|
104 QVERIFY( deviceStateSpy.isValid() ); |
|
105 |
|
106 QTest::qWait( 3000 ); |
|
107 |
|
108 QCOMPARE( deviceStateSpy.count(), 3 ); |
|
109 |
|
110 QList<QVariant> initModeArguments = deviceStateSpy.takeAt(0); |
|
111 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Open ); |
|
112 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
113 initModeArguments = deviceStateSpy.takeAt(0); |
|
114 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
115 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Preparing ); |
|
116 initModeArguments = deviceStateSpy.takeAt(0); |
|
117 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Ready ); |
|
118 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
119 } |
|
120 |
|
121 // Tests capture key in still mode |
|
122 void TestCxUiBat::testCaptureKeyInImageMode() |
|
123 { |
|
124 mEngine->initMode(Cxe::ImageMode); |
|
125 QTest::qWait(3000); |
|
126 // Test if we are in still VF |
|
127 QVERIFY(mMainWindow->currentViewIndex() == CxUi::StillPreCaptureView ); |
|
128 |
|
129 CX_DEBUG(("testCaptureKey in still capture mode")); |
|
130 sendCameraKeyEvent(); |
|
131 |
|
132 QSignalSpy deviceStateSpy(&mEngine->stillCaptureControl(), |
|
133 SIGNAL(snapshotReady(int, CxeError::Id))); |
|
134 QVERIFY( deviceStateSpy.isValid() ); |
|
135 QTest::qWait(2000); |
|
136 QCOMPARE( deviceStateSpy.count(), 1 ); |
|
137 if (deviceStateSpy.count() > 0) { |
|
138 // Expect zero error code |
|
139 QList<QVariant> initModeArguments = deviceStateSpy.takeFirst(); |
|
140 QVERIFY( initModeArguments.at(0).toInt() == 0 ); |
|
141 } |
|
142 QVERIFY( mMainWindow->currentViewIndex()== CxUi::StillPostCaptureView ); |
|
143 |
|
144 CX_DEBUG(("Test to get back viewfinder with capture key")); |
|
145 sendCameraKeyEvent(); |
|
146 QTest::qWait(1000); |
|
147 QVERIFY( mMainWindow->currentViewIndex()== CxUi::StillPreCaptureView ); |
|
148 |
|
149 // Test autofocus with halfkeypress and releasing |
|
150 CX_DEBUG(("testAutoFocus_1")); |
|
151 |
|
152 QSignalSpy autofocusStateSpy(&mEngine->autoFocusControl(), |
|
153 SIGNAL(stateChanged(CxeAutoFocusControl::State, CxeError::Id))); |
|
154 QVERIFY( autofocusStateSpy.isValid() ); |
|
155 |
|
156 // Test autofocus with halfkeypress and canceling it |
|
157 sendAutofocusKeyEvent(QEvent::KeyPress); |
|
158 CX_DEBUG(("testAutoFocus_2")); |
|
159 sendAutofocusKeyEvent(QEvent::KeyRelease); |
|
160 QTest::qWait(1000); |
|
161 |
|
162 QCOMPARE( autofocusStateSpy.count(), 3 ); |
|
163 if (autofocusStateSpy.count() > 0) { |
|
164 QList<QVariant> initModeArguments = autofocusStateSpy.takeFirst(); |
|
165 QVERIFY( initModeArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::InProgress ); |
|
166 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
167 CX_DEBUG(("testAutoFocus_2a")); |
|
168 initModeArguments = autofocusStateSpy.takeAt(0); |
|
169 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
170 QVERIFY( initModeArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::Canceling ); |
|
171 initModeArguments = autofocusStateSpy.takeAt(0); |
|
172 QVERIFY( initModeArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::Unknown ); |
|
173 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
174 } |
|
175 |
|
176 // Test autofocus with halfkeypress and capture focused image |
|
177 CX_DEBUG(("testAutoFocus_3")); |
|
178 |
|
179 sendAutofocusKeyEvent(QEvent::KeyPress); |
|
180 CX_DEBUG(("Capture autofocused image")); |
|
181 QTest::qWait(3000); |
|
182 sendCameraKeyEvent(); |
|
183 sendAutofocusKeyEvent(QEvent::KeyRelease); |
|
184 QTest::qWait(1000); |
|
185 |
|
186 QCOMPARE( autofocusStateSpy.count(), 2 ); |
|
187 if (autofocusStateSpy.count() > 0) { |
|
188 QList<QVariant> initModeArguments = autofocusStateSpy.takeFirst(); |
|
189 QVERIFY( initModeArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::InProgress ); |
|
190 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
191 initModeArguments = autofocusStateSpy.takeAt(0); |
|
192 QVERIFY( initModeArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::Ready || |
|
193 initModeArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::Failed ); |
|
194 |
|
195 } |
|
196 |
|
197 QCOMPARE( deviceStateSpy.count(), 1 ); |
|
198 if (deviceStateSpy.count() > 0) { |
|
199 // Expect zero error code |
|
200 QList<QVariant> initModeArguments = deviceStateSpy.takeFirst(); |
|
201 QVERIFY( initModeArguments.at(0).toInt() == 0 ); |
|
202 } |
|
203 QVERIFY( mMainWindow->currentViewIndex()== CxUi::StillPostCaptureView ); |
|
204 } |
|
205 |
|
206 // Tests capture key in video mode |
|
207 void TestCxUiBat::testCaptureKeyInVideoMode() |
|
208 { |
|
209 |
|
210 connect(this, SIGNAL(toPrecaptureView()), mViewManager, SLOT(changeToPrecaptureView())); |
|
211 QSignalSpy deviceStateSpy(&mEngine->videoCaptureControl(), |
|
212 SIGNAL(stateChanged(CxeVideoCaptureControl::State, CxeError::Id))); |
|
213 QVERIFY( deviceStateSpy.isValid() ); |
|
214 emit toPrecaptureView(); |
|
215 QTest::qWait(1500); |
|
216 // Test if we are in still VF |
|
217 QVERIFY(mMainWindow->currentViewIndex() == CxUi::VideoPreCaptureView ); |
|
218 |
|
219 |
|
220 // Generate camera key event to start recording |
|
221 CX_DEBUG(("Start video recording")); |
|
222 sendCameraKeyEvent(); |
|
223 QTest::qWait(5000); |
|
224 |
|
225 // Generate camera key event to stop recording |
|
226 CX_DEBUG(("Stop video recording")); |
|
227 sendCameraKeyEvent(); |
|
228 QTest::qWait(3000); |
|
229 |
|
230 QCOMPARE( deviceStateSpy.count(), 4 ); |
|
231 |
|
232 QList<QVariant> initModeArguments = deviceStateSpy.takeAt(0); |
|
233 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::PlayingStartSound ); |
|
234 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
235 initModeArguments = deviceStateSpy.takeAt(0); |
|
236 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
237 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Recording ); |
|
238 initModeArguments = deviceStateSpy.takeAt(0); |
|
239 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
240 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Stopping ); |
|
241 initModeArguments = deviceStateSpy.takeAt(0); |
|
242 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Idle ); |
|
243 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
244 |
|
245 QVERIFY( mMainWindow->currentViewIndex()== CxUi::VideoPostCaptureView ); |
|
246 |
|
247 CX_DEBUG(("Test to get back viewfinder with capture key")); |
|
248 sendCameraKeyEvent(); |
|
249 QTest::qWait(5000); |
|
250 QVERIFY( mMainWindow->currentViewIndex()== CxUi::VideoPreCaptureView ); |
|
251 |
|
252 QCOMPARE(deviceStateSpy.count(), 3); |
|
253 if (deviceStateSpy.count() > 0) { |
|
254 QList<QVariant> initModeArguments = deviceStateSpy.takeAt(0); |
|
255 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Open ); |
|
256 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
257 initModeArguments = deviceStateSpy.takeAt(0); |
|
258 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
259 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Preparing ); |
|
260 initModeArguments = deviceStateSpy.takeAt(0); |
|
261 QVERIFY( initModeArguments.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Ready ); |
|
262 QVERIFY( initModeArguments.at(1).toInt() == 0 ); |
|
263 } |
|
264 |
|
265 |
|
266 } |
|
267 |
|
268 // Tests only that correct view is activated |
|
269 void TestCxUiBat::testItemVisibilityInPrecaptureview() |
|
270 { |
|
271 CX_DEBUG(("testZoomInPrecaptureview")); |
|
272 mEngine->initMode(Cxe::ImageMode); |
|
273 emit toPrecaptureView(); |
|
274 QTest::qWait(1000); |
|
275 QVERIFY( mMainWindow->currentViewIndex()== CxUi::StillPreCaptureView ); |
|
276 |
|
277 QSignalSpy zoomStateSpy(&mEngine->zoomControl(), |
|
278 SIGNAL(stateChanged(CxeZoomControl::State, CxeError::Id))); |
|
279 QVERIFY( zoomStateSpy.isValid() ); |
|
280 |
|
281 QSignalSpy zoomLevelStateSpy(&mEngine->zoomControl(), |
|
282 SIGNAL(zoomLevelChanged(int))); |
|
283 QVERIFY( zoomLevelStateSpy.isValid() ); |
|
284 |
|
285 CX_DEBUG(("ShowControls")); |
|
286 QTest::mouseClick( mMainWindow->viewport(), Qt::LeftButton,0, QPoint(180,60),5 ); |
|
287 QTest::qWait(300); |
|
288 QCOMPARE(mMainWindow->isItemVisible(Hb::TitlePaneItem), true); |
|
289 QCOMPARE(mMainWindow->isItemVisible(Hb::NaviPaneItem), true); |
|
290 QCOMPARE(mMainWindow->isItemVisible(Hb::ToolBarItem), true); |
|
291 QCOMPARE(mMainWindow->isItemVisible(Hb::IndicatorItems), true); |
|
292 QCOMPARE(mMainWindow->isItemVisible(Hb::PrimarySoftKeyItem), true); |
|
293 QCOMPARE(mMainWindow->isItemVisible(Hb::SecondarySoftKeyItem), true); |
|
294 QCOMPARE(mMainWindow->isItemVisible(Hb::MiddleSoftKeyItem), true); |
|
295 QCOMPARE(mMainWindow->isItemVisible(Hb::SoftKeyItems), true); |
|
296 |
|
297 |
|
298 CX_DEBUG(("test Zoom slider - touch events control zoom level")); |
|
299 QTest::qWait(1000); |
|
300 |
|
301 HbAction *zoomAction = qobject_cast<HbAction *>(mViewManager->documentLoader()->findObject("cxui_action_zoom")); |
|
302 HbSlider *zoom = qobject_cast<HbSlider *>(mViewManager->documentLoader()->findWidget("zoom")); |
|
303 CX_DEBUG_ASSERT(zoomAction); |
|
304 CX_DEBUG_ASSERT(zoom); |
|
305 |
|
306 // trigger zoom action on toolbar |
|
307 zoomAction->trigger(); |
|
308 |
|
309 // get the zoom position |
|
310 QPoint centerPoint = zoom->geometry().toRect().center(); |
|
311 QPoint firstPoint = zoom->geometry().toRect().topLeft(); |
|
312 QPoint secondPoint = zoom->geometry().toRect().bottomRight(); |
|
313 |
|
314 CX_DEBUG( ("zoom slider coordinates topleft(%d,%d) and bottomright(%d,%d)", |
|
315 firstPoint.x(), firstPoint.y(), secondPoint.x(), secondPoint.y() )); |
|
316 |
|
317 firstPoint = (centerPoint - firstPoint); |
|
318 secondPoint = (secondPoint - centerPoint); |
|
319 |
|
320 CX_DEBUG( ("dragging zoom from (%d,%d) to (%d,%d)", |
|
321 firstPoint.x(), firstPoint.y(), |
|
322 secondPoint.x(), secondPoint.y() )); |
|
323 |
|
324 // click on zoom |
|
325 QTest::mousePress( mMainWindow->viewport(), Qt::LeftButton,0, firstPoint ); |
|
326 QTest::mouseMove ( mMainWindow->viewport(), secondPoint, 1000 ); |
|
327 QTest::mouseRelease( mMainWindow->viewport(), Qt::LeftButton,0, secondPoint); |
|
328 // At least ZoominIn/ZoominOut and Ready states are set |
|
329 QVERIFY(zoomStateSpy.count() > 2 ); |
|
330 // At least once zoom value has been changed. |
|
331 QVERIFY(zoomLevelStateSpy.count() > 2 ); |
|
332 |
|
333 CX_DEBUG( ("mouse click on (%d,%d)", centerPoint.x(), centerPoint.y() )); |
|
334 QTest::mouseClick( mMainWindow->viewport(), Qt::LeftButton,0, centerPoint); |
|
335 // At least ZoominIn/ZoominOut and Ready states are set |
|
336 QVERIFY(zoomStateSpy.count() > 2 ); |
|
337 // At least once zoom value has been changed. |
|
338 QVERIFY(zoomLevelStateSpy.count() > 2 ); |
|
339 QTest::qWait(1000); |
|
340 |
|
341 /*CX_DEBUG(("testFlash")); |
|
342 QTest::qWait(1000); |
|
343 QTest::mouseClick( mMainWindow->viewport(), Qt::LeftButton,0, QPoint(35,150)); |
|
344 QTest::qWait(1000); |
|
345 QTest::mouseClick( mMainWindow->viewport(), Qt::LeftButton,0, QPoint(185,150)); |
|
346 QTest::mouseClick( mMainWindow->viewport(), Qt::LeftButton,0, QPoint(35,150)); |
|
347 sendCameraKeyEvent(QEvent::KeyPress); |
|
348 sendCameraKeyEvent(QEvent::KeyRelease);*/ |
|
349 |
|
350 |
|
351 CX_DEBUG(("testGoToVideo")); |
|
352 QTest::mouseClick( mMainWindow->viewport(), Qt::LeftButton,0, QPoint(35,100), 500 ); |
|
353 QTest::qWait(3000); |
|
354 QVERIFY( mMainWindow->currentViewIndex()== CxUi::VideoPreCaptureView ); |
|
355 |
|
356 CX_DEBUG(("testGoToStill")); |
|
357 QTest::mouseClick( mMainWindow->viewport(), Qt::LeftButton,0, QPoint(180,60) ); |
|
358 QTest::qWait(1000); |
|
359 QTest::mouseClick( mMainWindow->viewport(), Qt::LeftButton,0, QPoint(35,100), 500 ); |
|
360 QTest::qWait(3000); |
|
361 QVERIFY( mMainWindow->currentViewIndex()== CxUi::StillPreCaptureView ); |
|
362 } |
|
363 |
|
364 // main() function non-GUI testing |
|
365 QTEST_MAIN( TestCxUiBat ); |