author | hgs |
Mon, 23 Aug 2010 13:50:05 +0300 | |
changeset 52 | 7e18d488ac5f |
parent 46 | c826656d6714 |
permissions | -rw-r--r-- |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1 |
/* |
39 | 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" |
40 | 26 |
#include "cxefakesettings.h" |
46 | 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" |
46 | 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() |
40 | 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 |
{ |
46 | 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 |
{ |
46 | 49 |
CX_DEBUG_ENTER_FUNCTION(); |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
50 |
|
40 | 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 |
|
46 | 57 |
mAutoFocusControl = new CxeAutoFocusControlSymbianUnit(*mCameraDevice, *mFakeSettings); |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
58 |
|
46 | 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 |
|
46 | 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 |
{ |
46 | 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; |
40 | 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; |
40 | 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; |
40 | 80 |
mCameraDevice = NULL; |
81 |
||
82 |
delete mFakeSettings; |
|
83 |
mFakeSettings = NULL; |
|
84 |
||
46 | 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 |
{ |
46 | 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 |
|
52 | 109 |
// prerequisites : not fixed mode & unknown state -> normal functionality |
46 | 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) |
|
52 | 119 |
// prerequisites : |
46 | 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 |
|
52 | 127 |
// Cannot be tested like this since assertion crashes the function |
128 |
// AFTER prepareForCameraDelete CALL. |
|
129 |
/*mAutoFocusControl->prepareForCameraDelete(); |
|
46 | 130 |
stateSpy.clear(); |
131 |
returnValue = mAutoFocusControl->start(); |
|
132 |
// result: no signal should be emitted |
|
133 |
QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
134 |
QCOMPARE(returnValue, CxeError::None); // should there be and error here? |
|
52 | 135 |
*/ |
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
136 |
} |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
137 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
138 |
void UnitTestCxeAutoFocusControlSymbian::testCancel() |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
139 |
{ |
46 | 140 |
// create signalspy to monitor that state changed signal |
141 |
QSignalSpy spy(mAutoFocusControl, |
|
142 |
SIGNAL(stateChanged(CxeAutoFocusControl::State, |
|
143 |
CxeError::Id))); |
|
144 |
||
145 |
// 1) after initialisation cancel does nothing |
|
146 |
mAutoFocusControl->cancel(); |
|
147 |
// no state changes |
|
148 |
QCOMPARE(spy.count(), 0); |
|
149 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
150 |
||
151 |
// 2) When in fixed focus mode, cancel does nothing |
|
152 |
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
|
153 |
mAutoFocusControl->start(); |
46 | 154 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
155 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Infinity); // fixed mode |
|
156 |
spy.clear(); |
|
157 |
mAutoFocusControl->cancel(); |
|
158 |
QCOMPARE(spy.count(), 0); |
|
159 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); |
|
160 |
||
161 |
// 3) InProgress state and "normal cancel" |
|
162 |
// set mode back to non fixed mode |
|
163 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); |
|
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
164 |
mAutoFocusControl->cancel(); |
46 | 165 |
// -> state is changed to Canceling |
166 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); |
|
167 |
// -> focustype set correctly |
|
168 |
QVERIFY(mAutoFocusControl->focusType() |
|
169 |
== CCamera::CCameraAdvancedSettings::EAutoFocusTypeOff); |
|
170 |
||
171 |
// 4) Canceling state (reached when calling canceling twice in a row, |
|
172 |
// now already in canceling state after previous test) |
|
173 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); |
|
174 |
mAutoFocusControl->cancel(); |
|
175 |
// -> state or focustype is not changing |
|
176 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); |
|
177 |
QVERIFY(mAutoFocusControl->focusType() |
|
178 |
== CCamera::CCameraAdvancedSettings::EAutoFocusTypeOff); |
|
179 |
||
180 |
// 5) Ready state (cancel called after start has been called and focus |
|
181 |
// found) |
|
182 |
// force state to ready in order to test canceling |
|
183 |
mAutoFocusControl->setState(CxeAutoFocusControl::Unknown); |
|
184 |
mAutoFocusControl->start(); // changes to in progress + sets focus type & range |
|
185 |
mAutoFocusControl->setState(CxeAutoFocusControl::Ready); |
|
186 |
mAutoFocusControl->cancel(); |
|
187 |
// state is changed to canceling |
|
188 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); |
|
189 |
||
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
190 |
} |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
191 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
192 |
|
39 | 193 |
void UnitTestCxeAutoFocusControlSymbian::testIsFixedFocusMode() |
194 |
{ |
|
46 | 195 |
// default value (hyperfocal) |
196 |
QCOMPARE(mAutoFocusControl->isFixedFocusMode(mAutoFocusControl->mode()), true); |
|
197 |
||
198 |
// set non fixed focus mode |
|
199 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); |
|
200 |
QCOMPARE(mAutoFocusControl->isFixedFocusMode(mAutoFocusControl->mode()), false); |
|
201 |
||
202 |
// set fixed focus mode |
|
203 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Infinity); |
|
204 |
QCOMPARE(mAutoFocusControl->isFixedFocusMode(mAutoFocusControl->mode()), true); |
|
205 |
||
39 | 206 |
} |
207 |
||
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
208 |
void UnitTestCxeAutoFocusControlSymbian::testSupported() |
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 |
bool supported = mAutoFocusControl->supported(); |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
211 |
QVERIFY(supported); |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
212 |
} |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
213 |
|
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
214 |
|
46 | 215 |
void UnitTestCxeAutoFocusControlSymbian::testPrepareForCameraDelete() |
216 |
{ |
|
217 |
// prepareCameraDelete calls prepareCameraRelease plus sets advanced |
|
218 |
// settings false (supported() will return false) |
|
219 |
// this test is for both methods |
|
220 |
||
221 |
// 1) initial values |
|
222 |
mAutoFocusControl->prepareForCameraDelete(); |
|
223 |
QCOMPARE(mAutoFocusControl->supported(), false); |
|
224 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
225 |
||
226 |
// 2) test prepareForCameraDelete with non-initial values |
|
227 |
mAutoFocusControl->handleCameraAllocated(CxeError::None); |
|
228 |
// force state to be something else than Unknown and check that it will be changed |
|
229 |
mAutoFocusControl->setState(CxeAutoFocusControl::Canceling); |
|
230 |
// force mCancelled to be false and check that it will be changed |
|
231 |
mAutoFocusControl->mCancelled = true; |
|
232 |
mAutoFocusControl->prepareForCameraDelete(); |
|
233 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
234 |
QCOMPARE(mAutoFocusControl->mCancelled, false); |
|
235 |
QCOMPARE(mAutoFocusControl->supported(), false); |
|
236 |
||
237 |
} |
|
238 |
||
239 |
void UnitTestCxeAutoFocusControlSymbian::testHandleCameraAllocated() |
|
240 |
{ |
|
241 |
// create signalspy to monitor that state changed signal |
|
242 |
QSignalSpy stateSpy(mAutoFocusControl, |
|
243 |
SIGNAL(stateChanged(CxeAutoFocusControl::State, |
|
244 |
CxeError::Id))); |
|
245 |
||
246 |
// 1) initial setup without an error (camera is allocated already) |
|
247 |
mAutoFocusControl->handleCameraAllocated(CxeError::None); |
|
248 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
249 |
QCOMPARE(mAutoFocusControl->supported(), true); |
|
250 |
||
251 |
// 2) release camera and call with an error code |
|
252 |
// -> supported should return false since initializeResources is not called in error case |
|
253 |
// -> state is not changed |
|
254 |
mAutoFocusControl->prepareForCameraDelete(); |
|
255 |
stateSpy.clear(); |
|
256 |
mAutoFocusControl->handleCameraAllocated(CxeError::General); |
|
257 |
QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
258 |
QCOMPARE(mAutoFocusControl->supported(), false); |
|
259 |
||
260 |
// 3) release camera and call without an error |
|
261 |
// (prepareForCameraDelete has been called in previous test) |
|
262 |
// -> resources are initialized i.e. supported returns true |
|
263 |
// first force state to something else so state change can be verified |
|
264 |
mAutoFocusControl->setState(CxeAutoFocusControl::Canceling); |
|
265 |
mAutoFocusControl->handleCameraAllocated(CxeError::None); |
|
266 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
267 |
QCOMPARE(mAutoFocusControl->supported(), true); |
|
268 |
||
269 |
} |
|
270 |
||
271 |
void UnitTestCxeAutoFocusControlSymbian::testPrepareForRelease() |
|
272 |
{ |
|
273 |
// see testPrepareForCameraDelete |
|
274 |
} |
|
275 |
||
52 | 276 |
void UnitTestCxeAutoFocusControlSymbian::testHandleCameraEventOptimalFocus() |
46 | 277 |
{ |
278 |
// handleCameraEvent handles callbacks and gets information about |
|
279 |
// focus events. handleCameraEvent calls private method handleAfEvent |
|
280 |
// for the focusing events that CxeAutoFocusControlSymbian needs |
|
281 |
||
282 |
// testing handleAfEvent is done by calling handleCameraEvent |
|
283 |
// and monitoring state changes after each "event" |
|
284 |
||
285 |
QSignalSpy stateSpy(mAutoFocusControl, |
|
286 |
SIGNAL(stateChanged(CxeAutoFocusControl::State, |
|
287 |
CxeError::Id))); |
|
288 |
||
289 |
||
290 |
// Input 1 ---------------------------------------------------- |
|
291 |
// Optimal focus was reached or couldn't be found |
|
292 |
int eventUid = KUidECamEventCameraSettingsOptimalFocusUidValue; |
|
293 |
int symbianError = 0; //KErrNone |
|
294 |
||
295 |
// AutofocusControl class is not InProgress or Canceling state |
|
296 |
// => event ignored, nothing is changed |
|
297 |
mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
298 |
QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
299 |
||
300 |
// AutoFocusControl is InProgress state (waiting for the focus) |
|
301 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); // not fixed focus |
|
302 |
mAutoFocusControl->start(); |
|
303 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
304 |
mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
305 |
// => state should change to Ready |
|
306 |
QVERIFY(CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
307 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Ready); |
|
308 |
||
309 |
// InProgress state but focus fails |
|
310 |
mAutoFocusControl->start(); |
|
311 |
stateSpy.clear(); |
|
312 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
313 |
mAutoFocusControl->handleCameraEvent(eventUid, -18); // KErrNotReady |
|
314 |
// => state should change to Failed |
|
315 |
QVERIFY(CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
316 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Failed); |
|
317 |
||
318 |
// AutoFocusControl is in Canceling state |
|
319 |
mAutoFocusControl->start(); |
|
320 |
mAutoFocusControl->cancel(); |
|
321 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); //verify start state |
|
322 |
stateSpy.clear(); |
|
323 |
mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
324 |
// => state should change to Unknown |
|
325 |
QVERIFY(CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
326 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
52 | 327 |
} |
46 | 328 |
|
52 | 329 |
void UnitTestCxeAutoFocusControlSymbian::testHandleCameraEventAutofocusChanged() |
330 |
{ |
|
331 |
QSignalSpy stateSpy(mAutoFocusControl, |
|
332 |
SIGNAL(stateChanged(CxeAutoFocusControl::State, |
|
333 |
CxeError::Id))); |
|
46 | 334 |
// Input 2 ----------------------------------------------------- |
335 |
// Notifies a change in autofocus type |
|
52 | 336 |
int eventUid = KUidECamEventCameraSettingAutoFocusType2UidValue; |
337 |
int symbianError = -18; // == KErrNotReady |
|
46 | 338 |
|
339 |
// InProgress: event is ignored |
|
340 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); // not fixed focus |
|
341 |
mAutoFocusControl->start(); |
|
342 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
343 |
stateSpy.clear(); |
|
344 |
mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
345 |
QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
346 |
||
347 |
// Canceling: |
|
348 |
// error parameter is ignored, state is not changed |
|
349 |
mAutoFocusControl->cancel(); |
|
350 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); //verify start state |
|
351 |
stateSpy.clear(); |
|
352 |
mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
353 |
QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
354 |
||
52 | 355 |
} |
356 |
||
357 |
void UnitTestCxeAutoFocusControlSymbian::testHandleCameraEventFocusRangeChanged() |
|
358 |
{ |
|
359 |
QSignalSpy stateSpy(mAutoFocusControl, |
|
360 |
SIGNAL(stateChanged(CxeAutoFocusControl::State, |
|
361 |
CxeError::Id))); |
|
46 | 362 |
|
363 |
// Input 3 ----------------------------------------------------- |
|
364 |
// Focus range have changed |
|
52 | 365 |
int eventUid = KUidECamEventCameraSettingFocusRangeUidValue; |
366 |
int symbianError = -2; // == KErrGeneral |
|
46 | 367 |
|
368 |
// In any other state than InProgress this event is ignored |
|
369 |
stateSpy.clear(); |
|
370 |
mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
371 |
QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
372 |
||
373 |
// InProgress: because of the error parameter state changes to failed |
|
374 |
// (focus range change failed because of error) |
|
375 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); // not fixed focus |
|
376 |
mAutoFocusControl->start(); |
|
377 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
378 |
mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
379 |
// => state should change to Failed |
|
380 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Failed); |
|
381 |
} |
|
382 |
||
383 |
void UnitTestCxeAutoFocusControlSymbian::testHandleSceneChanged() |
|
384 |
{ |
|
385 |
// changes the autofocus settings to match the new scene settings |
|
386 |
QVariantMap scene; |
|
387 |
||
388 |
// changes focus if new scene setting defines fixed focus |
|
389 |
// otherwise sets the autofocus control to Unknown state (==initial state) |
|
390 |
||
391 |
// 1) change to a scene with fixed focus mode (Infinity & Hyperfocal) |
|
392 |
scene.insert(CxeSettingIds::FOCAL_RANGE, CxeAutoFocusControl::Infinity); |
|
393 |
mAutoFocusControl->handleSceneChanged(scene); |
|
394 |
// states are changed and mode is set correctly ->Unknown->InProgress |
|
395 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); // end state |
|
396 |
QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Infinity); |
|
397 |
||
398 |
// 2) change to non-fixed mode (like Macro) |
|
399 |
scene.clear(); |
|
400 |
scene.insert(CxeSettingIds::FOCAL_RANGE, CxeAutoFocusControl::Macro); |
|
401 |
mAutoFocusControl->handleSceneChanged(scene); |
|
402 |
// states are changed and mode is set correctly |
|
403 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
404 |
QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Macro); |
|
405 |
||
406 |
// 3) try with error input (scene does not contain focal_range) |
|
407 |
scene.clear(); |
|
408 |
// change the autofocuscontrol state from Unknown (last test) to |
|
409 |
// something else calling start() for example |
|
410 |
mAutoFocusControl->start(); |
|
411 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
412 |
mAutoFocusControl->handleSceneChanged(scene); |
|
413 |
// state is changed and mode is not changed |
|
414 |
QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
415 |
QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Macro); |
|
416 |
||
417 |
} |
|
418 |
||
419 |
void UnitTestCxeAutoFocusControlSymbian::testHandleSettingValueChanged() |
|
420 |
{ |
|
421 |
// Autofocus mode needs to be updated when face trackin is actived in |
|
422 |
// scene mod which doesn't support facetracking |
|
423 |
||
424 |
QVariant on = QVariant(1); |
|
425 |
QVariant off = QVariant(0); |
|
426 |
||
427 |
// 1) check that mode does not change when some other setting value |
|
428 |
// than face tracking is given |
|
429 |
mAutoFocusControl->handleSettingValueChanged(CxeSettingIds::LIGHT_SENSITIVITY, on); |
|
430 |
QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Hyperfocal); |
|
431 |
||
432 |
// 2) check turning facetracking on, when mode is fixed |
|
433 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Infinity); |
|
434 |
mAutoFocusControl->handleSettingValueChanged(CxeSettingIds::FACE_TRACKING, on); |
|
435 |
QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Auto); |
|
436 |
QCOMPARE(mAutoFocusControl->mFaceTrackingOverride, true); |
|
437 |
||
438 |
// 3) check turning facetracking off will return the previous mode |
|
439 |
mAutoFocusControl->handleSettingValueChanged(CxeSettingIds::FACE_TRACKING, off); |
|
440 |
QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Infinity); |
|
441 |
QCOMPARE(mAutoFocusControl->mFaceTrackingOverride, false); |
|
442 |
||
443 |
// 4) check that turning facetracking off, when it is not on, won't |
|
444 |
// set the previous mode |
|
445 |
mAutoFocusControl->setMode(CxeAutoFocusControl::Macro); |
|
446 |
mAutoFocusControl->handleSettingValueChanged(CxeSettingIds::FACE_TRACKING, off); |
|
447 |
QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Macro); |
|
448 |
QCOMPARE(mAutoFocusControl->mFaceTrackingOverride, false); |
|
449 |
||
450 |
||
451 |
} |
|
452 |
||
453 |
||
454 |
||
19
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
455 |
// main() function - Need event loop for waiting signals, |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
456 |
// so can't use QTEST_APPLESS_MAIN. |
d9aefe59d544
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
457 |
QTEST_MAIN(UnitTestCxeAutoFocusControlSymbian); |