|
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 <QDate> |
|
18 #include <QTest> |
|
19 #include <QDebug> |
|
20 #include <QSignalSpy> |
|
21 |
|
22 #include "cxetestutils.h" |
|
23 #include "cxefakecameradevice.h" |
|
24 #include "cxefakecameradevicecontrol.h" |
|
25 #include "cxecameradevicecontrol.h" |
|
26 #include "cxestillcapturecontrolsymbian.h" |
|
27 #include "unittest_cxestillcapturecontrolsymbian.h" |
|
28 #include "cxefakeviewfindercontrol.h" |
|
29 #include "cxesettingsmodel.h" |
|
30 #include "cxesensoreventhandlersymbian.h" |
|
31 #include "cxefilenamegeneratorsymbian.h" |
|
32 #include "cxefakefilenamegenerator.h" |
|
33 #include "cxefakesensoreventhandler.h" |
|
34 #include "cxesettingsimp.h" |
|
35 #include "cxefakeautofocuscontrol.h" |
|
36 #include "cxefakesettings.h" |
|
37 #include "cxefakequalitypresets.h" |
|
38 #include "cxefakefilesavethread.h" |
|
39 |
|
40 UnitTestCxeStillCaptureControlSymbian::UnitTestCxeStillCaptureControlSymbian() |
|
41 : mFakeCameraDeviceControl(0) |
|
42 { |
|
43 qRegisterMetaType<CxeError::Id>("CxeError::Id"); |
|
44 } |
|
45 |
|
46 UnitTestCxeStillCaptureControlSymbian::~UnitTestCxeStillCaptureControlSymbian() |
|
47 { |
|
48 cleanup(); |
|
49 } |
|
50 void UnitTestCxeStillCaptureControlSymbian::init() |
|
51 { |
|
52 } |
|
53 |
|
54 void UnitTestCxeStillCaptureControlSymbian::cleanup() |
|
55 { |
|
56 } |
|
57 |
|
58 // Run before each individual test case |
|
59 void UnitTestCxeStillCaptureControlSymbian::initTestCase() |
|
60 { |
|
61 mFakeSettings = new CxeFakeSettings(); |
|
62 mFakeSettings->set(CxeSettingIds::IMAGE_QUALITY, 0); |
|
63 mFakeCameraDeviceControl = new CxeFakeCameraDeviceControl(); |
|
64 mFakeCameraDevice = new CxeFakeCameraDevice(); |
|
65 mFakeCameraDevice->newCamera(mFakeCameraDeviceControl->cameraIndex(), mFakeCameraDeviceControl); |
|
66 |
|
67 mViewfinderControl = new CxeFakeViewfinderControl(); |
|
68 mFilenameGenerator = new CxeFakeFilenameGenerator(); |
|
69 mSensorEventHandler = new CxeFakeSensorEventHandler(); |
|
70 mFakeAutoFocusControl = new CxeFakeAutoFocusControl(); |
|
71 mFakeQualityPresets = new CxeFakeQualityPresets(); |
|
72 mFakeFileSaveThread = new CxeFakeFileSaveThread(); |
|
73 |
|
74 mStillCaptureControl = new CxeStillCaptureControlSymbian( |
|
75 *mFakeCameraDevice, |
|
76 *mViewfinderControl, |
|
77 *mFakeCameraDeviceControl, |
|
78 *mFilenameGenerator, |
|
79 *mSensorEventHandler, |
|
80 *mFakeAutoFocusControl, |
|
81 *mFakeSettings, |
|
82 *mFakeQualityPresets, |
|
83 *mFakeFileSaveThread); |
|
84 |
|
85 // init supported qualities. |
|
86 mStillCaptureControl->supportedImageQualities(); |
|
87 |
|
88 mSpyState = new QSignalSpy(mStillCaptureControl, SIGNAL(stateChanged(CxeStillCaptureControl::State, CxeError::Id))); |
|
89 } |
|
90 |
|
91 // Run after each individual test case |
|
92 void UnitTestCxeStillCaptureControlSymbian::cleanupTestCase() |
|
93 { |
|
94 delete mFakeSettings; |
|
95 mFakeSettings = 0; |
|
96 delete mStillCaptureControl; |
|
97 mStillCaptureControl = 0; |
|
98 delete mSensorEventHandler; |
|
99 mSensorEventHandler = 0; |
|
100 delete mFilenameGenerator; |
|
101 mFilenameGenerator = 0; |
|
102 delete mViewfinderControl; |
|
103 mViewfinderControl = 0; |
|
104 delete mFakeCameraDeviceControl; |
|
105 mFakeCameraDeviceControl = 0; |
|
106 delete mFakeCameraDevice; |
|
107 mFakeCameraDevice = 0; |
|
108 delete mFakeAutoFocusControl; |
|
109 mFakeAutoFocusControl = 0; |
|
110 delete mSpyState; |
|
111 mSpyState = 0; |
|
112 delete mFakeQualityPresets; |
|
113 mFakeQualityPresets = 0; |
|
114 delete mFakeFileSaveThread; |
|
115 mFakeFileSaveThread = 0; |
|
116 } |
|
117 |
|
118 |
|
119 void UnitTestCxeStillCaptureControlSymbian::testCapture() |
|
120 { |
|
121 // deinitialize still capture control |
|
122 mStillCaptureControl->deinit(); |
|
123 // prepare still capture control |
|
124 mStillCaptureControl->init(); |
|
125 QVERIFY(mStillCaptureControl->state() == CxeStillCaptureControl::Ready); |
|
126 QVERIFY(mStillCaptureControl->mode() == CxeStillCaptureControl::SingleImageCapture); |
|
127 QVERIFY(mStillCaptureControl->imageCount() == 0); |
|
128 |
|
129 mStillCaptureControl->capture(); |
|
130 QVERIFY(mStillCaptureControl->state() == CxeStillCaptureControl::Capturing); |
|
131 QVERIFY(CxeTestUtils::waitForSignal(*mSpyState, 1000, 2)); |
|
132 } |
|
133 |
|
134 void UnitTestCxeStillCaptureControlSymbian::testState() |
|
135 { |
|
136 QVERIFY(mStillCaptureControl->state()); // Passed if not undefined state |
|
137 } |
|
138 |
|
139 void UnitTestCxeStillCaptureControlSymbian::testImageCount() |
|
140 { |
|
141 QCOMPARE(mStillCaptureControl->imageCount(), 0); |
|
142 } |
|
143 |
|
144 void UnitTestCxeStillCaptureControlSymbian::testReset() |
|
145 { |
|
146 mStillCaptureControl->reset(); |
|
147 QCOMPARE(mStillCaptureControl->imageCount(), 0); |
|
148 } |
|
149 |
|
150 void UnitTestCxeStillCaptureControlSymbian::testCancelAll() |
|
151 { |
|
152 mStillCaptureControl->cancelAll(); |
|
153 QCOMPARE(mStillCaptureControl->imageCount(), 0); |
|
154 } |
|
155 |
|
156 void UnitTestCxeStillCaptureControlSymbian::testSetMode() |
|
157 { |
|
158 QVERIFY(mStillCaptureControl->mode() == CxeStillCaptureControl::SingleImageCapture); |
|
159 mStillCaptureControl->setMode(CxeStillCaptureControl::BurstCapture); |
|
160 QCOMPARE(mStillCaptureControl->mode(), CxeStillCaptureControl::BurstCapture); |
|
161 } |
|
162 |
|
163 void UnitTestCxeStillCaptureControlSymbian::testMode() |
|
164 { |
|
165 QCOMPARE(mStillCaptureControl->mode(), CxeStillCaptureControl::BurstCapture); |
|
166 } |
|
167 |
|
168 void UnitTestCxeStillCaptureControlSymbian::testImageDataQueue() |
|
169 { |
|
170 // Passes if not a NULL pointer |
|
171 QVERIFY(&mStillCaptureControl->imageDataQueue()); |
|
172 } |
|
173 |
|
174 void UnitTestCxeStillCaptureControlSymbian::testInit() |
|
175 { |
|
176 QSignalSpy spy(mStillCaptureControl, SIGNAL(imagePrepareComplete(CxeError::Id))); |
|
177 mStillCaptureControl->deinit(); |
|
178 mSpyState->clear(); |
|
179 QVERIFY(mStillCaptureControl->state() == CxeStillCaptureControl::Uninitialized); |
|
180 mStillCaptureControl->init(); |
|
181 QVERIFY(mStillCaptureControl->state() == CxeStillCaptureControl::Ready); |
|
182 QVERIFY(CxeTestUtils::waitForSignal(*mSpyState, 1000)); |
|
183 QVERIFY(CxeTestUtils::waitForSignal(spy, 1000)); |
|
184 } |
|
185 |
|
186 void UnitTestCxeStillCaptureControlSymbian::testDeinit() |
|
187 { |
|
188 mStillCaptureControl->init(); |
|
189 mSpyState->clear(); |
|
190 QVERIFY(mStillCaptureControl->state() == CxeStillCaptureControl::Ready); |
|
191 mStillCaptureControl->deinit(); |
|
192 QVERIFY(mStillCaptureControl->state() == CxeStillCaptureControl::Uninitialized); |
|
193 QVERIFY(CxeTestUtils::waitForSignal(*mSpyState, 1000)); |
|
194 } |
|
195 |
|
196 |
|
197 void UnitTestCxeStillCaptureControlSymbian::testSupportedImageQualities() |
|
198 { |
|
199 int count = mStillCaptureControl->supportedImageQualities().count(); |
|
200 QVERIFY(count > 0); |
|
201 } |
|
202 |
|
203 // main() function - Need event loop for waiting signals, |
|
204 // so can't use QTEST_APPLESS_MAIN. |
|
205 QTEST_MAIN(UnitTestCxeStillCaptureControlSymbian); |