author | hgs |
Wed, 18 Aug 2010 14:02:45 +0300 | |
changeset 51 | ccc0e7e3344f |
parent 43 | 0e652f8f1fbd |
permissions | -rw-r--r-- |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1 |
/* |
43 | 2 |
* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
3 |
* All rights reserved. |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
5 |
* under the terms of "Eclipse Public License v1.0" |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
8 |
* |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
9 |
* Initial Contributors: |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
10 |
* Nokia Corporation - initial contribution. |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
11 |
* |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
12 |
* Contributors: |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
* |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
14 |
* Description: |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
15 |
* |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
16 |
*/ |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
#include <QDate> |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
18 |
#include <QTest> |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
19 |
#include <QDebug> |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
20 |
#include <QSignalSpy> |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
21 |
#include <QThread> |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
22 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
23 |
#include "cxetestutils.h" |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
24 |
#include "cxefakecameradevicecontrol.h" |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
25 |
#include "cxefakecameradevice.h" |
43 | 26 |
#include "cxefakesettings.h" |
51 | 27 |
#include "cxeautofocuscontrolsymbianunit.h" |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
28 |
#include "unittest_cxeautofocuscontrolsymbian.h" |
51 | 29 |
#include "cxenamespace.h" |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
30 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
31 |
UnitTestCxeAutoFocusControlSymbian::UnitTestCxeAutoFocusControlSymbian() |
43 | 32 |
: mAutoFocusControl(NULL), |
33 |
mCameraDeviceControl(NULL), |
|
34 |
mCameraDevice(NULL), |
|
35 |
mFakeSettings(NULL) |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
36 |
{ |
51 | 37 |
qRegisterMetaType<CxeError::Id>("CxeError::Id"); |
38 |
qRegisterMetaType<CxeAutoFocusControl::State>("CxeAutoFocusControl::State"); |
|
39 |
qRegisterMetaType<CxeAutoFocusControl::Mode>("CxeAutoFocusControl::Mode"); |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
40 |
} |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
41 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
42 |
UnitTestCxeAutoFocusControlSymbian::~UnitTestCxeAutoFocusControlSymbian() |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
43 |
{ |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
44 |
} |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
45 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
46 |
// Run before each individual test case |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
47 |
void UnitTestCxeAutoFocusControlSymbian::init() |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
48 |
{ |
51 | 49 |
CX_DEBUG_ENTER_FUNCTION(); |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
50 |
|
43 | 51 |
mFakeSettings = new CxeFakeSettings(); |
52 |
||
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
53 |
mCameraDeviceControl = new CxeFakeCameraDeviceControl(); |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
54 |
mCameraDevice = new CxeFakeCameraDevice(); |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
55 |
mCameraDevice->newCamera(mCameraDeviceControl->cameraIndex(), mCameraDeviceControl); |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
56 |
|
51 | 57 |
mAutoFocusControl = new CxeAutoFocusControlSymbianUnit(*mCameraDevice, *mFakeSettings); |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
58 |
|
51 | 59 |
// make sure that initialization is correct |
60 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
61 |
QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Hyperfocal); |
|
62 |
QCOMPARE(mAutoFocusControl->isSoundEnabled(), false); |
|
63 |
QCOMPARE(mAutoFocusControl->supported(), true); |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
64 |
|
51 | 65 |
CX_DEBUG_EXIT_FUNCTION(); |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
66 |
} |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
67 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
68 |
// Run after each individual test case |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
69 |
void UnitTestCxeAutoFocusControlSymbian::cleanup() |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
70 |
{ |
51 | 71 |
CX_DEBUG_ENTER_FUNCTION(); |
72 |
||
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
73 |
delete mAutoFocusControl; |
43 | 74 |
mAutoFocusControl = NULL; |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
75 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
76 |
delete mCameraDeviceControl; |
43 | 77 |
mCameraDeviceControl = NULL; |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
78 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
79 |
delete mCameraDevice; |
43 | 80 |
mCameraDevice = NULL; |
81 |
||
82 |
delete mFakeSettings; |
|
83 |
mFakeSettings = NULL; |
|
84 |
||
51 | 85 |
CX_DEBUG_EXIT_FUNCTION(); |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
86 |
} |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
87 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
88 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
89 |
void UnitTestCxeAutoFocusControlSymbian::testStart() |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
90 |
{ |
51 | 91 |
// start takes a boolean input and returns CxeError |
92 |
// functionality depends on current state and current autofocus mode |
|
93 |
||
94 |
QSignalSpy stateSpy(mAutoFocusControl, |
|
95 |
SIGNAL(stateChanged(CxeAutoFocusControl::State, |
|
96 |
CxeError::Id))); |
|
97 |
||
98 |
CxeError::Id returnValue = CxeError::None; |
|
99 |
// 1) Default input after initialisation (fixed focus) -> nothing should happen |
|
100 |
returnValue = mAutoFocusControl->start(); |
|
101 |
// verifying the result: |
|
102 |
QVERIFY(returnValue == CxeError::None); |
|
103 |
QCOMPARE(mAutoFocusControl->isSoundEnabled(), true); // check for input paramete |
|
104 |
// no state changes |
|
105 |
QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
106 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
107 |
||
108 |
// 2) Input parameter false is handled correctly |
|
109 |
// prequisites: not fixed mode & unknown state -> normal functionality |
|
110 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); // non-fixed |
|
111 |
// function call |
|
112 |
returnValue = mAutoFocusControl->start(false); |
|
113 |
// verifying the result: |
|
114 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); |
|
115 |
QCOMPARE(returnValue, CxeError::None); |
|
116 |
QCOMPARE(mAutoFocusControl->isSoundEnabled(), false); // check for input parameter |
|
117 |
||
118 |
// 3) Autofocus is not ready (state is cancelling or in progress) |
|
119 |
// prequisites: |
|
120 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Macro); // non-fixed mode |
|
121 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); |
|
122 |
// start should return CxeError::InUse |
|
123 |
returnValue = mAutoFocusControl->start(); |
|
124 |
QCOMPARE(returnValue, CxeError::InUse); |
|
125 |
||
126 |
// 4) Camera has been released |
|
127 |
mAutoFocusControl->prepareForCameraDelete(); |
|
128 |
stateSpy.clear(); |
|
129 |
returnValue = mAutoFocusControl->start(); |
|
130 |
// result: no signal should be emitted |
|
131 |
QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
132 |
QCOMPARE(returnValue, CxeError::None); // should there be and error here? |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
133 |
} |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
134 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
135 |
void UnitTestCxeAutoFocusControlSymbian::testCancel() |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
136 |
{ |
51 | 137 |
// create signalspy to monitor that state changed signal |
138 |
QSignalSpy spy(mAutoFocusControl, |
|
139 |
SIGNAL(stateChanged(CxeAutoFocusControl::State, |
|
140 |
CxeError::Id))); |
|
141 |
||
142 |
// 1) after initialisation cancel does nothing |
|
143 |
mAutoFocusControl->cancel(); |
|
144 |
// no state changes |
|
145 |
QCOMPARE(spy.count(), 0); |
|
146 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
147 |
||
148 |
// 2) When in fixed focus mode, cancel does nothing |
|
149 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); // non fixed mode so that start works |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
150 |
mAutoFocusControl->start(); |
51 | 151 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
152 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Infinity); // fixed mode |
|
153 |
spy.clear(); |
|
154 |
mAutoFocusControl->cancel(); |
|
155 |
QCOMPARE(spy.count(), 0); |
|
156 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); |
|
157 |
||
158 |
// 3) InProgress state and "normal cancel" |
|
159 |
// set mode back to non fixed mode |
|
160 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
161 |
mAutoFocusControl->cancel(); |
51 | 162 |
// -> state is changed to Canceling |
163 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); |
|
164 |
// -> focustype set correctly |
|
165 |
QVERIFY(mAutoFocusControl->focusType() |
|
166 |
== CCamera::CCameraAdvancedSettings::EAutoFocusTypeOff); |
|
167 |
||
168 |
// 4) Canceling state (reached when calling canceling twice in a row, |
|
169 |
// now already in canceling state after previous test) |
|
170 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); |
|
171 |
mAutoFocusControl->cancel(); |
|
172 |
// -> state or focustype is not changing |
|
173 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); |
|
174 |
QVERIFY(mAutoFocusControl->focusType() |
|
175 |
== CCamera::CCameraAdvancedSettings::EAutoFocusTypeOff); |
|
176 |
||
177 |
// 5) Ready state (cancel called after start has been called and focus |
|
178 |
// found) |
|
179 |
// force state to ready in order to test canceling |
|
180 |
mAutoFocusControl->setState(CxeAutoFocusControl::Unknown); |
|
181 |
mAutoFocusControl->start(); // changes to in progress + sets focus type & range |
|
182 |
mAutoFocusControl->setState(CxeAutoFocusControl::Ready); |
|
183 |
mAutoFocusControl->cancel(); |
|
184 |
// state is changed to canceling |
|
185 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); |
|
186 |
||
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
187 |
} |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
188 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
189 |
|
43 | 190 |
void UnitTestCxeAutoFocusControlSymbian::testIsFixedFocusMode() |
191 |
{ |
|
51 | 192 |
// default value (hyperfocal) |
193 |
QCOMPARE(mAutoFocusControl->isFixedFocusMode(mAutoFocusControl->mode()), true); |
|
194 |
||
195 |
// set non fixed focus mode |
|
196 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); |
|
197 |
QCOMPARE(mAutoFocusControl->isFixedFocusMode(mAutoFocusControl->mode()), false); |
|
198 |
||
199 |
// set fixed focus mode |
|
200 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Infinity); |
|
201 |
QCOMPARE(mAutoFocusControl->isFixedFocusMode(mAutoFocusControl->mode()), true); |
|
202 |
||
43 | 203 |
} |
204 |
||
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
205 |
void UnitTestCxeAutoFocusControlSymbian::testSupported() |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
206 |
{ |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
207 |
bool supported = mAutoFocusControl->supported(); |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
208 |
QVERIFY(supported); |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
209 |
} |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
210 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
211 |
|
51 | 212 |
void UnitTestCxeAutoFocusControlSymbian::testPrepareForCameraDelete() |
213 |
{ |
|
214 |
// prepareCameraDelete calls prepareCameraRelease plus sets advanced |
|
215 |
// settings false (supported() will return false) |
|
216 |
// this test is for both methods |
|
217 |
||
218 |
// 1) initial values |
|
219 |
mAutoFocusControl->prepareForCameraDelete(); |
|
220 |
QCOMPARE(mAutoFocusControl->supported(), false); |
|
221 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
222 |
||
223 |
// 2) test prepareForCameraDelete with non-initial values |
|
224 |
mAutoFocusControl->handleCameraAllocated(CxeError::None); |
|
225 |
// force state to be something else than Unknown and check that it will be changed |
|
226 |
mAutoFocusControl->setState(CxeAutoFocusControl::Canceling); |
|
227 |
// force mCancelled to be false and check that it will be changed |
|
228 |
mAutoFocusControl->mCancelled = true; |
|
229 |
mAutoFocusControl->prepareForCameraDelete(); |
|
230 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
231 |
QCOMPARE(mAutoFocusControl->mCancelled, false); |
|
232 |
QCOMPARE(mAutoFocusControl->supported(), false); |
|
233 |
||
234 |
} |
|
235 |
||
236 |
void UnitTestCxeAutoFocusControlSymbian::testHandleCameraAllocated() |
|
237 |
{ |
|
238 |
// create signalspy to monitor that state changed signal |
|
239 |
QSignalSpy stateSpy(mAutoFocusControl, |
|
240 |
SIGNAL(stateChanged(CxeAutoFocusControl::State, |
|
241 |
CxeError::Id))); |
|
242 |
||
243 |
// 1) initial setup without an error (camera is allocated already) |
|
244 |
mAutoFocusControl->handleCameraAllocated(CxeError::None); |
|
245 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
246 |
QCOMPARE(mAutoFocusControl->supported(), true); |
|
247 |
||
248 |
// 2) release camera and call with an error code |
|
249 |
// -> supported should return false since initializeResources is not called in error case |
|
250 |
// -> state is not changed |
|
251 |
mAutoFocusControl->prepareForCameraDelete(); |
|
252 |
stateSpy.clear(); |
|
253 |
mAutoFocusControl->handleCameraAllocated(CxeError::General); |
|
254 |
QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
255 |
QCOMPARE(mAutoFocusControl->supported(), false); |
|
256 |
||
257 |
// 3) release camera and call without an error |
|
258 |
// (prepareForCameraDelete has been called in previous test) |
|
259 |
// -> resources are initialized i.e. supported returns true |
|
260 |
// first force state to something else so state change can be verified |
|
261 |
mAutoFocusControl->setState(CxeAutoFocusControl::Canceling); |
|
262 |
mAutoFocusControl->handleCameraAllocated(CxeError::None); |
|
263 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
264 |
QCOMPARE(mAutoFocusControl->supported(), true); |
|
265 |
||
266 |
} |
|
267 |
||
268 |
void UnitTestCxeAutoFocusControlSymbian::testPrepareForRelease() |
|
269 |
{ |
|
270 |
// see testPrepareForCameraDelete |
|
271 |
} |
|
272 |
||
273 |
void UnitTestCxeAutoFocusControlSymbian::testHandleCameraEvent() |
|
274 |
{ |
|
275 |
// handleCameraEvent handles callbacks and gets information about |
|
276 |
// focus events. handleCameraEvent calls private method handleAfEvent |
|
277 |
// for the focusing events that CxeAutoFocusControlSymbian needs |
|
278 |
||
279 |
// testing handleAfEvent is done by calling handleCameraEvent |
|
280 |
// and monitoring state changes after each "event" |
|
281 |
||
282 |
QSignalSpy stateSpy(mAutoFocusControl, |
|
283 |
SIGNAL(stateChanged(CxeAutoFocusControl::State, |
|
284 |
CxeError::Id))); |
|
285 |
||
286 |
||
287 |
// Input 1 ---------------------------------------------------- |
|
288 |
// Optimal focus was reached or couldn't be found |
|
289 |
int eventUid = KUidECamEventCameraSettingsOptimalFocusUidValue; |
|
290 |
int symbianError = 0; //KErrNone |
|
291 |
||
292 |
// AutofocusControl class is not InProgress or Canceling state |
|
293 |
// => event ignored, nothing is changed |
|
294 |
mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
295 |
QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
296 |
||
297 |
// AutoFocusControl is InProgress state (waiting for the focus) |
|
298 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); // not fixed focus |
|
299 |
mAutoFocusControl->start(); |
|
300 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
301 |
mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
302 |
// => state should change to Ready |
|
303 |
QVERIFY(CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
304 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Ready); |
|
305 |
||
306 |
// InProgress state but focus fails |
|
307 |
mAutoFocusControl->start(); |
|
308 |
stateSpy.clear(); |
|
309 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
310 |
mAutoFocusControl->handleCameraEvent(eventUid, -18); // KErrNotReady |
|
311 |
// => state should change to Failed |
|
312 |
QVERIFY(CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
313 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Failed); |
|
314 |
||
315 |
// AutoFocusControl is in Canceling state |
|
316 |
mAutoFocusControl->start(); |
|
317 |
mAutoFocusControl->cancel(); |
|
318 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); //verify start state |
|
319 |
stateSpy.clear(); |
|
320 |
mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
321 |
// => state should change to Unknown |
|
322 |
QVERIFY(CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
323 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
324 |
||
325 |
// cleanup and init to make sure that the dummy engine is not messed up |
|
326 |
// and we get to initial state |
|
327 |
cleanup(); |
|
328 |
init(); |
|
329 |
||
330 |
// Input 2 ----------------------------------------------------- |
|
331 |
// Notifies a change in autofocus type |
|
332 |
eventUid = KUidECamEventCameraSettingAutoFocusType2UidValue; |
|
333 |
symbianError = -18; // == KErrNotReady |
|
334 |
||
335 |
// InProgress: event is ignored |
|
336 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); // not fixed focus |
|
337 |
mAutoFocusControl->start(); |
|
338 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
339 |
stateSpy.clear(); |
|
340 |
mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
341 |
QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
342 |
||
343 |
// Canceling: |
|
344 |
// error parameter is ignored, state is not changed |
|
345 |
mAutoFocusControl->cancel(); |
|
346 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); //verify start state |
|
347 |
stateSpy.clear(); |
|
348 |
mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
349 |
QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
350 |
||
351 |
// cleanup and init to make sure that the dummy engine is not messed up |
|
352 |
// and we get to initial state |
|
353 |
cleanup(); |
|
354 |
init(); |
|
355 |
||
356 |
// Input 3 ----------------------------------------------------- |
|
357 |
// Focus range have changed |
|
358 |
eventUid = KUidECamEventCameraSettingFocusRangeUidValue; |
|
359 |
symbianError = -2; // == KErrGeneral |
|
360 |
||
361 |
// In any other state than InProgress this event is ignored |
|
362 |
stateSpy.clear(); |
|
363 |
mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
364 |
QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
365 |
||
366 |
// InProgress: because of the error parameter state changes to failed |
|
367 |
// (focus range change failed because of error) |
|
368 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); // not fixed focus |
|
369 |
mAutoFocusControl->start(); |
|
370 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
371 |
mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
372 |
// => state should change to Failed |
|
373 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Failed); |
|
374 |
} |
|
375 |
||
376 |
void UnitTestCxeAutoFocusControlSymbian::testHandleSceneChanged() |
|
377 |
{ |
|
378 |
// changes the autofocus settings to match the new scene settings |
|
379 |
QVariantMap scene; |
|
380 |
||
381 |
// changes focus if new scene setting defines fixed focus |
|
382 |
// otherwise sets the autofocus control to Unknown state (==initial state) |
|
383 |
||
384 |
// 1) change to a scene with fixed focus mode (Infinity & Hyperfocal) |
|
385 |
scene.insert(CxeSettingIds::FOCAL_RANGE, CxeAutoFocusControl::Infinity); |
|
386 |
mAutoFocusControl->handleSceneChanged(scene); |
|
387 |
// states are changed and mode is set correctly ->Unknown->InProgress |
|
388 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); // end state |
|
389 |
QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Infinity); |
|
390 |
||
391 |
// 2) change to non-fixed mode (like Macro) |
|
392 |
scene.clear(); |
|
393 |
scene.insert(CxeSettingIds::FOCAL_RANGE, CxeAutoFocusControl::Macro); |
|
394 |
mAutoFocusControl->handleSceneChanged(scene); |
|
395 |
// states are changed and mode is set correctly |
|
396 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
397 |
QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Macro); |
|
398 |
||
399 |
// 3) try with error input (scene does not contain focal_range) |
|
400 |
scene.clear(); |
|
401 |
// change the autofocuscontrol state from Unknown (last test) to |
|
402 |
// something else calling start() for example |
|
403 |
mAutoFocusControl->start(); |
|
404 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
405 |
mAutoFocusControl->handleSceneChanged(scene); |
|
406 |
// state is changed and mode is not changed |
|
407 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
408 |
QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Macro); |
|
409 |
||
410 |
} |
|
411 |
||
412 |
void UnitTestCxeAutoFocusControlSymbian::testHandleSettingValueChanged() |
|
413 |
{ |
|
414 |
// Autofocus mode needs to be updated when face trackin is actived in |
|
415 |
// scene mod which doesn't support facetracking |
|
416 |
||
417 |
QVariant on = QVariant(1); |
|
418 |
QVariant off = QVariant(0); |
|
419 |
||
420 |
// 1) check that mode does not change when some other setting value |
|
421 |
// than face tracking is given |
|
422 |
mAutoFocusControl->handleSettingValueChanged(CxeSettingIds::LIGHT_SENSITIVITY, on); |
|
423 |
QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Hyperfocal); |
|
424 |
||
425 |
// 2) check turning facetracking on, when mode is fixed |
|
426 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Infinity); |
|
427 |
mAutoFocusControl->handleSettingValueChanged(CxeSettingIds::FACE_TRACKING, on); |
|
428 |
QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Auto); |
|
429 |
QCOMPARE(mAutoFocusControl->mFaceTrackingOverride, true); |
|
430 |
||
431 |
// 3) check turning facetracking off will return the previous mode |
|
432 |
mAutoFocusControl->handleSettingValueChanged(CxeSettingIds::FACE_TRACKING, off); |
|
433 |
QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Infinity); |
|
434 |
QCOMPARE(mAutoFocusControl->mFaceTrackingOverride, false); |
|
435 |
||
436 |
// 4) check that turning facetracking off, when it is not on, won't |
|
437 |
// set the previous mode |
|
438 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Macro); |
|
439 |
mAutoFocusControl->handleSettingValueChanged(CxeSettingIds::FACE_TRACKING, off); |
|
440 |
QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Macro); |
|
441 |
QCOMPARE(mAutoFocusControl->mFaceTrackingOverride, false); |
|
442 |
||
443 |
||
444 |
} |
|
445 |
||
446 |
||
447 |
||
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
448 |
// main() function - Need event loop for waiting signals, |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
449 |
// so can't use QTEST_APPLESS_MAIN. |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
450 |
QTEST_MAIN(UnitTestCxeAutoFocusControlSymbian); |