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