|
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 <QTest> |
|
18 #include <QSignalSpy> |
|
19 |
|
20 #include "unittest_cxeenginesymbian.h" |
|
21 #include "cxeenginesymbianunit.h" |
|
22 #include "cxefakecameradevicecontrol.h" |
|
23 #include "cxefakestillcapturecontrol.h" |
|
24 #include "cxefakevideocapturecontrol.h" |
|
25 #include "cxefakeviewfindercontrol.h" |
|
26 #include "cxetestutils.h" |
|
27 #include "cxutils.h" |
|
28 |
|
29 UnitTestCxeEngineSymbian::UnitTestCxeEngineSymbian() |
|
30 : mEngine(NULL) |
|
31 { |
|
32 } |
|
33 |
|
34 UnitTestCxeEngineSymbian::~UnitTestCxeEngineSymbian() |
|
35 { |
|
36 delete mEngine; |
|
37 } |
|
38 |
|
39 // Run before each individual test case |
|
40 void UnitTestCxeEngineSymbian::init() |
|
41 { |
|
42 delete mEngine; |
|
43 mEngine = NULL; |
|
44 mEngine = new CxeEngineSymbianUnit(); |
|
45 mEngine->construct(); |
|
46 mEngine->initMode(Cxe::ImageMode); |
|
47 |
|
48 mCameraDeviceControl = qobject_cast<CxeFakeCameraDeviceControl*>( |
|
49 &mEngine->cameraDeviceControl()); |
|
50 mStillCaptureControl = qobject_cast<CxeFakeStillCaptureControl*>( |
|
51 &mEngine->stillCaptureControl()); |
|
52 mVideoCaptureControl = qobject_cast<CxeFakeVideoCaptureControl*>( |
|
53 &mEngine->videoCaptureControl()); |
|
54 mViewfinderControl = qobject_cast<CxeFakeViewfinderControl*>( |
|
55 &mEngine->viewfinderControl()); |
|
56 } |
|
57 |
|
58 // Run after each individual test case |
|
59 void UnitTestCxeEngineSymbian::cleanup() |
|
60 { |
|
61 delete mEngine; |
|
62 mEngine = NULL; |
|
63 mCameraDeviceControl = NULL; |
|
64 mStillCaptureControl = NULL; |
|
65 mVideoCaptureControl = NULL; |
|
66 mViewfinderControl = NULL; |
|
67 } |
|
68 |
|
69 void UnitTestCxeEngineSymbian::testCameraDeviceControl() |
|
70 { |
|
71 QVERIFY(&mEngine->cameraDeviceControl()); |
|
72 } |
|
73 |
|
74 void UnitTestCxeEngineSymbian::testViewfinderControl() |
|
75 { |
|
76 QVERIFY(&mEngine->viewfinderControl()); |
|
77 } |
|
78 |
|
79 void UnitTestCxeEngineSymbian::testStillCaptureControl() |
|
80 { |
|
81 QVERIFY(&mEngine->stillCaptureControl()); |
|
82 } |
|
83 |
|
84 void UnitTestCxeEngineSymbian::testVideoCaptureControl() |
|
85 { |
|
86 QVERIFY(&mEngine->videoCaptureControl()); |
|
87 } |
|
88 |
|
89 void UnitTestCxeEngineSymbian::testAutoFocusControl() |
|
90 { |
|
91 QVERIFY(&mEngine->autoFocusControl()); |
|
92 } |
|
93 |
|
94 void UnitTestCxeEngineSymbian::testZoomControl() |
|
95 { |
|
96 QVERIFY(&mEngine->zoomControl()); |
|
97 } |
|
98 |
|
99 void UnitTestCxeEngineSymbian::testSettings() |
|
100 { |
|
101 QVERIFY(&mEngine->settings()); |
|
102 } |
|
103 |
|
104 void UnitTestCxeEngineSymbian:: testSensorEventHandler() |
|
105 { |
|
106 QVERIFY(&mEngine->sensorEventHandler()); |
|
107 } |
|
108 |
|
109 void UnitTestCxeEngineSymbian::testFeatureManager() |
|
110 { |
|
111 QVERIFY(&mEngine->featureManager()); |
|
112 } |
|
113 |
|
114 void UnitTestCxeEngineSymbian::testMode() |
|
115 { |
|
116 QCOMPARE(mEngine->mode(), Cxe::ImageMode); |
|
117 } |
|
118 |
|
119 /*! |
|
120 Test that initMode() changes current mode |
|
121 */ |
|
122 void UnitTestCxeEngineSymbian::testInitMode1() |
|
123 { |
|
124 mEngine->initMode(Cxe::VideoMode); |
|
125 QCOMPARE(mEngine->mode(), Cxe::VideoMode); |
|
126 |
|
127 mEngine->initMode(Cxe::ImageMode); |
|
128 QCOMPARE(mEngine->mode(), Cxe::ImageMode); |
|
129 } |
|
130 |
|
131 /*! |
|
132 Test that initMode() calls reserve when needed |
|
133 */ |
|
134 void UnitTestCxeEngineSymbian::testInitMode2() |
|
135 { |
|
136 mCameraDeviceControl->setState(CxeCameraDeviceControl::Idle); |
|
137 mEngine->initMode(Cxe::ImageMode); |
|
138 |
|
139 // Verify that reseve() has been called using device control call history |
|
140 QVERIFY(mCameraDeviceControl->callHistory().indexOf( |
|
141 CxeFakeCameraDeviceControl::Reserve) >= 0); |
|
142 } |
|
143 |
|
144 /*! |
|
145 Test that deinit() and init() are called correctly when switching |
|
146 to video mode |
|
147 */ |
|
148 void UnitTestCxeEngineSymbian::testInitMode3() |
|
149 { |
|
150 mCameraDeviceControl->setState(CxeCameraDeviceControl::Ready); |
|
151 mStillCaptureControl->setState(CxeStillCaptureControl::Ready); |
|
152 mVideoCaptureControl->setState(CxeVideoCaptureControl::Idle); |
|
153 mEngine->initMode(Cxe::VideoMode); |
|
154 |
|
155 // Verify that init() and deinit() have been called using call histories |
|
156 QVERIFY(mStillCaptureControl->callHistory().indexOf( |
|
157 CxeFakeStillCaptureControl::Deinit) >= 0); |
|
158 QVERIFY(mVideoCaptureControl->callHistory().indexOf( |
|
159 CxeFakeVideoCaptureControl::Init) >= 0); |
|
160 |
|
161 // Verify that viewfinder was stopped |
|
162 QVERIFY(mViewfinderControl->callHistory().indexOf( |
|
163 CxeFakeViewfinderControl::Stop) >= 0); |
|
164 } |
|
165 |
|
166 /*! |
|
167 Test that deinit() and init() are called correctly when switching |
|
168 to still image mode |
|
169 */ |
|
170 void UnitTestCxeEngineSymbian::testInitMode4() |
|
171 { |
|
172 // First set the engine to video mode that a mode switch is really needed |
|
173 mEngine->initMode(Cxe::VideoMode); |
|
174 mCameraDeviceControl->setState(CxeCameraDeviceControl::Ready); |
|
175 mStillCaptureControl->setState(CxeStillCaptureControl::Uninitialized); |
|
176 mVideoCaptureControl->setState(CxeVideoCaptureControl::Initialized); |
|
177 |
|
178 mEngine->initMode(Cxe::ImageMode); |
|
179 |
|
180 // Verify that init() and deinit() have been called using call histories |
|
181 QVERIFY(mVideoCaptureControl->callHistory().indexOf( |
|
182 CxeFakeVideoCaptureControl::Deinit) >= 0); |
|
183 QVERIFY(mStillCaptureControl->callHistory().indexOf( |
|
184 CxeFakeStillCaptureControl::Init) >= 0); |
|
185 |
|
186 // Verify that viewfinder was stopped |
|
187 QVERIFY(mViewfinderControl->callHistory().indexOf( |
|
188 CxeFakeViewfinderControl::Stop) >= 0); |
|
189 } |
|
190 |
|
191 |
|
192 // main() function |
|
193 QTEST_MAIN(UnitTestCxeEngineSymbian); |