1 /* |
|
2 * Copyright (c) 2009-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 #include <QObject> |
|
18 #include <QTest> |
|
19 #include <QSignalSpy> |
|
20 |
|
21 #include "unittest_cxezoomcontrolsymbian.h" |
|
22 #include "cxezoomcontrolsymbian.h" |
|
23 #include "cxefakecameradevice.h" |
|
24 #include "cxefakesettings.h" |
|
25 #include "cxefakefeaturemanager.h" |
|
26 #include "cxefakecameradevicecontrol.h" |
|
27 #include "cxeerror.h" |
|
28 #include "cxezoomcontrolsymbian.h" |
|
29 #include "cxetestutils.h" |
|
30 |
|
31 |
|
32 UnitTestCxeZoomControlSymbian::UnitTestCxeZoomControlSymbian() |
|
33 : mZoomControl(NULL), mFakeCameraDevice(NULL), mFakeCameraDeviceControl(NULL), mFakeSettings(NULL), mFakeFeatureManager(NULL) |
|
34 { |
|
35 qRegisterMetaType<CxeError::Id>("CxeError::Id"); |
|
36 qRegisterMetaType<CxeZoomControl::State>("CxeZoomControl::State"); |
|
37 } |
|
38 |
|
39 UnitTestCxeZoomControlSymbian::~UnitTestCxeZoomControlSymbian() |
|
40 { |
|
41 |
|
42 } |
|
43 |
|
44 |
|
45 void UnitTestCxeZoomControlSymbian::init() |
|
46 { |
|
47 CX_DEBUG_ENTER_FUNCTION(); |
|
48 |
|
49 mFakeCameraDevice = new CxeFakeCameraDevice; |
|
50 mFakeCameraDevice->newCamera(Cxe::PrimaryCameraIndex, |
|
51 mFakeCameraDeviceControl); |
|
52 mFakeCameraDeviceControl = new CxeFakeCameraDeviceControl; |
|
53 mFakeCameraDeviceControl->setState(CxeCameraDeviceControl::Ready); |
|
54 |
|
55 mFakeFeatureManager = new CxeFakeFeatureManager(); |
|
56 |
|
57 mFakeSettings = new CxeFakeSettings(); |
|
58 |
|
59 mZoomControl = new CxeZoomControlSymbian(*mFakeCameraDevice, |
|
60 *mFakeCameraDeviceControl, |
|
61 *mFakeSettings, |
|
62 *mFakeFeatureManager); |
|
63 |
|
64 // init zoom control |
|
65 connect(this, SIGNAL(prepareZoom(int)), mZoomControl, SLOT(prepareZoomForStill(int))); |
|
66 |
|
67 // make sure that after creation we are in correct state |
|
68 QCOMPARE(mZoomControl->state(), CxeZoomControl::Idle); |
|
69 |
|
70 // after construction the initial values are 0 |
|
71 // other cases for min and max are tested as part of other testcases |
|
72 QCOMPARE(mZoomControl->min(),0); |
|
73 QCOMPARE(mZoomControl->max(),0); |
|
74 |
|
75 CX_DEBUG_EXIT_FUNCTION(); |
|
76 } |
|
77 |
|
78 void UnitTestCxeZoomControlSymbian::cleanup() |
|
79 { |
|
80 delete mZoomControl; |
|
81 mZoomControl = NULL; |
|
82 |
|
83 delete mFakeCameraDeviceControl; |
|
84 mFakeCameraDeviceControl = NULL; |
|
85 |
|
86 delete mFakeCameraDevice; |
|
87 mFakeCameraDevice = NULL; |
|
88 |
|
89 delete mFakeSettings; |
|
90 mFakeSettings = NULL; |
|
91 |
|
92 delete mFakeFeatureManager; |
|
93 mFakeFeatureManager = NULL; |
|
94 } |
|
95 |
|
96 void UnitTestCxeZoomControlSymbian::testZoomTo() |
|
97 { |
|
98 CX_DEBUG_ENTER_FUNCTION(); |
|
99 |
|
100 QSignalSpy spyStateChange(mZoomControl, SIGNAL(stateChanged(CxeZoomControl::State, |
|
101 CxeError::Id))); |
|
102 QSignalSpy spyZoomLevelChange(mZoomControl, |
|
103 SIGNAL(zoomLevelChanged(int))); |
|
104 QList<QVariant> spyArguments; |
|
105 |
|
106 // before prepare, this method should not do anything |
|
107 mZoomControl->zoomTo(mZoomControl->max()); |
|
108 QVERIFY(!CxeTestUtils::waitForSignal(spyZoomLevelChange, 1000)); |
|
109 QCOMPARE(mZoomControl->max(), 0); |
|
110 QCOMPARE(mZoomControl->min(), 0); |
|
111 QCOMPARE(mZoomControl->state(), CxeZoomControl::Idle); |
|
112 |
|
113 // call fakeclass to emit a signal to get the zoomcontrol initialized |
|
114 // and get zoom values |
|
115 mFakeCameraDeviceControl->setState(CxeCameraDeviceControl::Ready); |
|
116 emit prepareZoom(0); |
|
117 int min = mZoomControl->min(); |
|
118 int max = mZoomControl->max(); |
|
119 int middle = min + (max-min)/2; |
|
120 |
|
121 // clear signal spies (just to be sure) |
|
122 spyStateChange.clear(); |
|
123 spyZoomLevelChange.clear(); |
|
124 |
|
125 // zoom to middle |
|
126 mZoomControl->zoomTo(middle); |
|
127 // verify statechanges |
|
128 QVERIFY(CxeTestUtils::waitForSignal(spyStateChange, 1000, 2, false)); |
|
129 spyArguments = spyStateChange.takeFirst(); // first signal |
|
130 QCOMPARE(qvariant_cast<CxeZoomControl::State>(spyArguments.at(0)), |
|
131 CxeZoomControl::ZoomingIn); |
|
132 spyArguments = spyStateChange.takeFirst(); // second signal |
|
133 QCOMPARE(qvariant_cast<CxeZoomControl::State>(spyArguments.at(0)), |
|
134 CxeZoomControl::Ready); |
|
135 // verify current zoomlevel change |
|
136 QVERIFY(CxeTestUtils::waitForSignal(spyZoomLevelChange, 1000)); |
|
137 spyArguments = spyZoomLevelChange.takeFirst(); |
|
138 QCOMPARE(spyArguments.at(0).toInt(), middle); // mCurrentZoomLevel |
|
139 |
|
140 // clear signal spies |
|
141 spyStateChange.clear(); |
|
142 spyZoomLevelChange.clear(); |
|
143 |
|
144 // zoom to min |
|
145 mZoomControl->zoomTo(min); |
|
146 // verify statechanges |
|
147 QVERIFY(CxeTestUtils::waitForSignal(spyStateChange, 1000, 2, false)); |
|
148 spyArguments.clear(); |
|
149 spyArguments = spyStateChange.takeFirst(); // first signal |
|
150 QCOMPARE(qvariant_cast<CxeZoomControl::State>(spyArguments.at(0)), |
|
151 CxeZoomControl::ZoomingOut); |
|
152 spyArguments.clear(); |
|
153 spyArguments = spyStateChange.takeFirst(); // second signal |
|
154 QCOMPARE(qvariant_cast<CxeZoomControl::State>(spyArguments.at(0)), |
|
155 CxeZoomControl::Ready); |
|
156 // verify current zoomlevel change |
|
157 QVERIFY(CxeTestUtils::waitForSignal(spyZoomLevelChange, 1000)); |
|
158 spyArguments.clear(); |
|
159 spyArguments = spyZoomLevelChange.takeFirst(); |
|
160 QCOMPARE(spyArguments.at(0).toInt(), min); // mCurrentZoomLevel |
|
161 |
|
162 // clear signal spies |
|
163 spyStateChange.clear(); |
|
164 spyZoomLevelChange.clear(); |
|
165 |
|
166 // zoom to max |
|
167 mZoomControl->zoomTo(max); |
|
168 // verify statechanges |
|
169 QVERIFY(CxeTestUtils::waitForSignal(spyStateChange, 1000, 2, false)); |
|
170 spyArguments = spyStateChange.takeFirst(); // first signal |
|
171 QCOMPARE(qvariant_cast<CxeZoomControl::State>(spyArguments.at(0)), |
|
172 CxeZoomControl::ZoomingIn); |
|
173 spyArguments = spyStateChange.takeFirst(); // second signal |
|
174 QCOMPARE(qvariant_cast<CxeZoomControl::State>(spyArguments.at(0)), |
|
175 CxeZoomControl::Ready); |
|
176 // verify current zoomlevel change |
|
177 QVERIFY(CxeTestUtils::waitForSignal(spyZoomLevelChange, 1000)); |
|
178 spyArguments = spyZoomLevelChange.takeFirst(); |
|
179 QCOMPARE(spyArguments.at(0).toInt(), max); // mCurrentZoomLevel |
|
180 |
|
181 // clear signal spies |
|
182 spyStateChange.clear(); |
|
183 spyZoomLevelChange.clear(); |
|
184 |
|
185 // zoom to max+1 (nothing should happen, check that no signal is emitted) |
|
186 mZoomControl->zoomTo(max+1); |
|
187 QVERIFY(!CxeTestUtils::waitForSignal(spyZoomLevelChange, 1000)); |
|
188 QVERIFY(!CxeTestUtils::waitForSignal(spyStateChange, 1000)); |
|
189 |
|
190 |
|
191 CX_DEBUG_EXIT_FUNCTION(); |
|
192 } |
|
193 |
|
194 void UnitTestCxeZoomControlSymbian::testPrepareZoomControl() |
|
195 { |
|
196 QSignalSpy spyZoomLevelChange(mZoomControl, SIGNAL(zoomLevelChanged(int))); |
|
197 |
|
198 // setting the state of mFakeCameraDeviceControl emits stateChanged signal |
|
199 // that CxeZoomControlSymbian connects to prepareZoomControl slot |
|
200 |
|
201 // signal parameters that are not supposed to change zoom values |
|
202 mFakeCameraDeviceControl->setState(CxeCameraDeviceControl::Idle); |
|
203 emit prepareZoom(0); |
|
204 // zoomcontrol is in initial state and zoom values should not change |
|
205 QVERIFY(!CxeTestUtils::waitForSignal(spyZoomLevelChange, 1000)); |
|
206 QCOMPARE(mZoomControl->max(),0); |
|
207 QCOMPARE(mZoomControl->min(),0); |
|
208 QCOMPARE(mZoomControl->state(), CxeZoomControl::Idle); |
|
209 |
|
210 spyZoomLevelChange.clear(); |
|
211 |
|
212 // check that the zoom min and max values are updated |
|
213 // when slot is called with the Ready parameter |
|
214 mFakeCameraDeviceControl->setState(CxeCameraDeviceControl::Ready); |
|
215 emit prepareZoom(0); |
|
216 QVERIFY(CxeTestUtils::waitForSignal(spyZoomLevelChange, 1000)); |
|
217 QList<QVariant> spyArguments = spyZoomLevelChange.takeFirst(); |
|
218 QCOMPARE(spyArguments.at(0).toInt(), 0); // mCurrentZoomLevel should not change when prepare is called |
|
219 QVERIFY(mZoomControl->max() > 0); // Must be positive, or zero if not supported. |
|
220 QCOMPARE(mZoomControl->min(), 0); // Must be negative, or zero if macro zoom not supported |
|
221 QCOMPARE(mZoomControl->state(), CxeZoomControl::Ready); |
|
222 } |
|
223 |
|
224 void UnitTestCxeZoomControlSymbian::testPrepareForCameraDelete() |
|
225 { |
|
226 QSignalSpy spyZoomLevelChange(mZoomControl, SIGNAL(zoomLevelChanged(int))); |
|
227 |
|
228 // zoomcontrol needs to be prepared in order to delete camera |
|
229 // this emits a signal that calls prepareZoomControl |
|
230 mFakeCameraDeviceControl->setState(CxeCameraDeviceControl::Ready); |
|
231 emit prepareZoom(0); |
|
232 |
|
233 // call fakeclass method that emits a signal, |
|
234 // which is connected to prepareForCameraDelete slot in contructor |
|
235 // of CxeZoomControlSymbian |
|
236 mFakeCameraDevice->deleteCamera(); |
|
237 |
|
238 // check that after prepareForCameraDelete default values are set |
|
239 QCOMPARE(mZoomControl->max(),0); |
|
240 QCOMPARE(mZoomControl->min(),0); |
|
241 QCOMPARE(mZoomControl->state(),CxeZoomControl::Idle); |
|
242 // check signal is emitted, and current zoom level is reset |
|
243 QVERIFY(CxeTestUtils::waitForSignal(spyZoomLevelChange, 1000)); |
|
244 QList<QVariant> spyArguments = spyZoomLevelChange.takeFirst(); |
|
245 QCOMPARE(spyArguments.at(0).toInt(), 0); // mCurrentZoomLevel |
|
246 } |
|
247 |
|
248 QTEST_MAIN(UnitTestCxeZoomControlSymbian); |
|