• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file expected in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "hdi_host_uttest.h"
16 
17 using namespace OHOS;
18 using namespace std;
19 using namespace testing::ext;
20 using namespace OHOS::Camera;
21 
SetUpTestCase(void)22 void HdiHostUtTest::SetUpTestCase(void) {}
TearDownTestCase(void)23 void HdiHostUtTest::TearDownTestCase(void) {}
SetUp(void)24 void HdiHostUtTest::SetUp(void)
25 {
26     cameraTest = std::make_shared<OHOS::Camera::Test>();
27     cameraTest->Init();
28 }
29 
TearDown(void)30 void HdiHostUtTest::TearDown(void)
31 {
32     cameraTest->Close();
33 }
34 
35 /**
36  * @tc.name: GitCameraIds
37  * @tc.desc: CamRetCode GetCameraIds([out] String[] ipds)
38  * @tc.size: MediumTest
39  * @tc.type: Function
40  */
41 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_001, TestSize.Level1)
42 {
43     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
44     if (cameraTest->cameraDevice == nullptr) {
45         cameraTest->rc = cameraTest->service->GetCameraIds(cameraTest->cameraIds);
46         EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
47         EXPECT_LT(0, cameraTest->cameraIds.size());
48         CAMERA_LOGE("check hdi_host: cameraIds.size() = %{public}zu", cameraTest->cameraIds.size());
49     }
50 }
51 
52 /**
53  * @tc.name: GetCameraAbility
54  * @tc.desc: GetCameraAbility, abnormal cameraId = ''
55  * @tc.size: MediumTest
56  * @tc.type: Function
57  */
58 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_002, TestSize.Level1)
59 {
60     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
61     if (cameraTest->cameraDevice == nullptr) {
62         std::string testCameraId = "";
63         cameraTest->rc = cameraTest->service->GetCameraAbility(testCameraId, cameraTest->abilityVec);
64         EXPECT_EQ(true, cameraTest->rc == INVALID_ARGUMENT);
65     }
66 }
67 
68 /**
69  * @tc.name: GetCameraAbility
70  * @tc.desc: GetCameraAbility, abnormal cameraId = ' '
71  * @tc.size: MediumTest
72  * @tc.type: Function
73  */
74 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_003, TestSize.Level1)
75 {
76     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
77     if (cameraTest->cameraDevice == nullptr) {
78         std::string testCameraId = "";
79         cameraTest->rc = cameraTest->service->GetCameraAbility(testCameraId, cameraTest->abilityVec);
80         EXPECT_EQ(true, cameraTest->rc == INVALID_ARGUMENT);
81     }
82 }
83 
84 /**
85  * @tc.name: OpenCamera
86  * @tc.desc: OpenCamera, normal cameraId
87  * @tc.size: MediumTest
88  * @tc.type: Function
89  */
90 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_004, TestSize.Level1)
91 {
92     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
93     if (cameraTest->cameraDevice == nullptr) {
94         cameraTest->service->GetCameraIds(cameraTest->cameraIds);
95         cameraTest->deviceCallback = new OHOS::Camera::Test::DemoCameraDeviceCallback();
96         cameraTest->rc = cameraTest->service->OpenCamera(cameraTest->cameraIds.front(), cameraTest->deviceCallback,
97             cameraTest->cameraDevice);
98         EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
99         if (cameraTest->rc != HDI::Camera::V1_0::NO_ERROR || cameraTest->cameraDevice == nullptr) {
100             CAMERA_LOGE("check hdi_host: OpenCamera failed");
101             return;
102         }
103     }
104 }
105 
106 /**
107  * @tc.name: OpenCamera
108  * @tc.desc: OpenCamera, cameraId is not found
109  * @tc.size: MediumTest
110  * @tc.type: Function
111  */
112 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_005, TestSize.Level1)
113 {
114     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
115     if (cameraTest->cameraDevice == nullptr) {
116         std::string testCameraId = "qwerty";
117         cameraTest->deviceCallback = new OHOS::Camera::Test::DemoCameraDeviceCallback();
118         cameraTest->rc = cameraTest->service->OpenCamera(testCameraId, cameraTest->deviceCallback,
119             cameraTest->cameraDevice);
120         EXPECT_EQ(true, cameraTest->rc == INVALID_ARGUMENT);
121     }
122 }
123 
124 /**
125  * @tc.name: OpenCamera
126  * @tc.desc: OpenCamera, cameraId is illegal
127  * @tc.size: MediumTest
128  * @tc.type: Function
129  */
130 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_006, TestSize.Level1)
131 {
132     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
133     if (cameraTest->cameraDevice == nullptr) {
134         std::string testCameraId = "1";
135         cameraTest->deviceCallback = new OHOS::Camera::Test::DemoCameraDeviceCallback();
136         cameraTest->rc = cameraTest->service->OpenCamera(testCameraId, cameraTest->deviceCallback,
137             cameraTest->cameraDevice);
138         EXPECT_EQ(true, cameraTest->rc == INVALID_ARGUMENT);
139     }
140 }
141 
142 /**
143  * @tc.name: OpenCamera cameraID & Callback input error
144  * @tc.desc: OpenCamera, cameraID is illegal, callback is null.
145  * @tc.size: MediumTest
146  * @tc.type: Function
147  */
148 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_007, TestSize.Level1)
149 {
150     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
151     if (cameraTest->cameraDevice == nullptr) {
152         std::string testCameraId = "1";
153         cameraTest->deviceCallback = nullptr;
154         cameraTest->rc = cameraTest->service->OpenCamera(testCameraId, cameraTest->deviceCallback,
155             cameraTest->cameraDevice);
156         EXPECT_EQ(true, cameraTest->rc == INVALID_ARGUMENT);
157     }
158 }
159 
160 /**
161  * @tc.name: OpenCamera
162  * @tc.desc: OpenCamera, cameraId is empty
163  * @tc.size: MediumTest
164  * @tc.type: Function
165  */
166 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_008, TestSize.Level1)
167 {
168     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
169     if (cameraTest->cameraDevice == nullptr) {
170         std::string testCameraId = "";
171         cameraTest->deviceCallback = new OHOS::Camera::Test::DemoCameraDeviceCallback();
172         cameraTest->rc = cameraTest->service->OpenCamera(testCameraId, cameraTest->deviceCallback,
173             cameraTest->cameraDevice);
174         EXPECT_EQ(true, cameraTest->rc == INVALID_ARGUMENT);
175     }
176 }
177 
178 /**
179  * @tc.name: OpenCamera cameraID & Callback input error
180  * @tc.desc: OpenCamera, cameraID is Empty, callback is null.
181  * @tc.size: MediumTest
182  * @tc.type: Function
183  */
184 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_009, TestSize.Level1)
185 {
186     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
187     if (cameraTest->cameraDevice == nullptr) {
188         std::string testCameraId = "";
189         cameraTest->deviceCallback = nullptr;
190         cameraTest->rc = cameraTest->service->OpenCamera(testCameraId, cameraTest->deviceCallback,
191             cameraTest->cameraDevice);
192         EXPECT_EQ(true, cameraTest->rc == INVALID_ARGUMENT);
193     }
194 }
195 
196 /**
197  * @tc.name: OpenCamera
198  * @tc.desc: OpenCamera, callback is null
199  * @tc.size: MediumTest
200  * @tc.type: Function
201  */
202 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_010, TestSize.Level1)
203 {
204     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
205     if (cameraTest->cameraDevice == nullptr) {
206         cameraTest->service->GetCameraIds(cameraTest->cameraIds);
207         cameraTest->deviceCallback = nullptr;
208         cameraTest->rc = cameraTest->service->OpenCamera(cameraTest->cameraIds.front(), cameraTest->deviceCallback,
209             cameraTest->cameraDevice);
210         EXPECT_EQ(true, cameraTest->rc == INVALID_ARGUMENT);
211     }
212 }
213 
214 /**
215  * @tc.name: OpenCamera
216  * @tc.desc: cameraId is not found, callback is null
217  * @tc.size: MediumTest
218  * @tc.type: Function
219  */
220 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_011, TestSize.Level1)
221 {
222     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
223     if (cameraTest->cameraDevice == nullptr) {
224         std::string testCameraId = "abc";
225         cameraTest->deviceCallback = nullptr;
226         cameraTest->rc = cameraTest->service->OpenCamera(testCameraId, cameraTest->deviceCallback,
227             cameraTest->cameraDevice);
228         EXPECT_EQ(true, cameraTest->rc == INVALID_ARGUMENT);
229     }
230 }
231 
232 /**
233  * @tc.name: SetFlashlight
234  * @tc.desc: SetFlashlight, normal cameraId
235  * @tc.size: MediumTest
236  * @tc.type: Function
237  */
238 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_012, TestSize.Level1)
239 {
240     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
241     if (cameraTest->cameraDevice == nullptr) {
242         cameraTest->service->GetCameraIds(cameraTest->cameraIds);
243         cameraTest->status = true;
244         cameraTest->rc = cameraTest->service->SetFlashlight(cameraTest->cameraIds.front(), cameraTest->status);
245         EXPECT_EQ(true, cameraTest->rc == HDI::Camera::V1_0::NO_ERROR);
246     }
247 }
248 
249 /**
250  * @tc.name: SetFlashlight
251  * @tc.desc: SetFlashlight, cameraId is not found
252  * @tc.size: MediumTest
253  * @tc.type: Function
254  */
255 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_013, TestSize.Level1)
256 {
257     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
258     if (cameraTest->cameraDevice == nullptr) {
259         std::string testCameraId = "abc";
260         cameraTest->status = true;
261         cameraTest->rc = cameraTest->service->SetFlashlight(testCameraId, cameraTest->status);
262         EXPECT_EQ(true, cameraTest->rc == INVALID_ARGUMENT);
263     }
264 }
265 
266 /**
267  * @tc.name: SetFlashlight
268  * @tc.desc: SetFlashlight, cameraId null
269  * @tc.size: MediumTest
270  * @tc.type: Function
271  */
272 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_014, TestSize.Level1)
273 {
274     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
275     if (cameraTest->cameraDevice == nullptr) {
276         std::string testCameraId = "";
277         cameraTest->status = true;
278         cameraTest->rc = cameraTest->service->SetFlashlight(testCameraId, cameraTest->status);
279         EXPECT_EQ(true, cameraTest->rc == INVALID_ARGUMENT);
280     }
281 }
282 
283 /**
284  * @tc.name: SetFlashlight
285  * @tc.desc: SetFlashlight, status is false
286  * @tc.size: MediumTest
287  * @tc.type: Function
288  */
289 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_015, TestSize.Level1)
290 {
291     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
292     if (cameraTest->cameraDevice == nullptr) {
293         cameraTest->service->GetCameraIds(cameraTest->cameraIds);
294         cameraTest->status = false;
295         cameraTest->rc = cameraTest->service->SetFlashlight(cameraTest->cameraIds.front(), cameraTest->status);
296         EXPECT_EQ(true, cameraTest->rc == HDI::Camera::V1_0::NO_ERROR);
297     }
298 }
299 
300 /**
301  * @tc.name: Open all Cameras
302  * @tc.desc: Open every Cameras what the getCameraId get.
303  * @tc.size: MediumTest
304  * @tc.type: Function
305  */
306 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_016, TestSize.Level1)
307 {
308     EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
309     if (cameraTest->cameraDevice == nullptr) {
310         cameraTest->rc = cameraTest->service->GetCameraIds(cameraTest->cameraIds);
311         EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
312         for (int i = 0; i < cameraTest->cameraIds.size(); i++) {
313             cameraTest->rc = cameraTest->service->GetCameraAbility(cameraTest->cameraIds[i], cameraTest->abilityVec);
314             CAMERA_LOGE("check hdi_host: cameraId = %{public}s", cameraTest->cameraIds[i].c_str());
315             EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
316         }
317     }
318 }
319 
320 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_017, TestSize.Level1)
321 {
322     cameraTest->service->GetCameraIds(cameraTest->cameraIds);
323     for (int i = 0; i < 10; i++) {
324         if (i % 2 == 0) {
325             cameraTest->status = true;
326         } else {
327             cameraTest->status = false;
328         }
329     }
330     cameraTest->rc = cameraTest->service->SetFlashlight(cameraTest->cameraIds.front(), cameraTest->status);
331     EXPECT_EQ(true, cameraTest->rc == HDI::Camera::V1_0::NO_ERROR);
332 }
333 
334 /**
335  * @tc.name: SetFlashlight
336  * @tc.desc: Open the camera, preview, the turn on the flashlight, expected return errorcode.
337  * @tc.size: MediumTest
338  * @tc.type: Function
339  */
340 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_018, TestSize.Level1)
341 {
342     cameraTest->Open();
343     cameraTest->intents = {PREVIEW};
344     cameraTest->StartStream(cameraTest->intents);
345     cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
346 
347     cameraTest->status = true;
348     cameraTest->rc = cameraTest->service->SetFlashlight(cameraTest->cameraIds.front(), cameraTest->status);
349     EXPECT_EQ(true, cameraTest->rc == HDI::Camera::V1_0::METHOD_NOT_SUPPORTED);
350     sleep(UT_SECOND_TIMES);
351     cameraTest->captureIds = {cameraTest->captureIdPreview};
352     cameraTest->streamIds = {cameraTest->streamIdPreview};
353     cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
354 }
355 
356 /**
357  * @tc.name: SetFlashlight
358  * @tc.desc: Open the camera, preview, the turn off the flashlight, expected return errorcode.
359  * @tc.size: MediumTest
360  * @tc.type: Function
361  */
362 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_019, TestSize.Level1)
363 {
364     cameraTest->Open();
365     cameraTest->intents = {PREVIEW};
366     cameraTest->StartStream(cameraTest->intents);
367     cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
368 
369     cameraTest->status = false;
370     cameraTest->rc = cameraTest->service->SetFlashlight(cameraTest->cameraIds.front(), cameraTest->status);
371     EXPECT_EQ(true, cameraTest->rc == HDI::Camera::V1_0::METHOD_NOT_SUPPORTED);
372     sleep(UT_SECOND_TIMES);
373     cameraTest->captureIds = {cameraTest->captureIdPreview};
374     cameraTest->streamIds = {cameraTest->streamIdPreview};
375     cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
376 }
377 
378 /**
379  * @tc.name: SetFlashlight
380  * @tc.desc: Open the camera, preview, the turn on the flashlight, expected return errorcode.
381  * @tc.size: MediumTest
382  * @tc.type: Function
383  */
384 HWTEST_F(HdiHostUtTest, Camera_Host_Hdi_020, TestSize.Level1)
385 {
386     cameraTest->service->GetCameraIds(cameraTest->cameraIds);
387     cameraTest->status = true;
388     cameraTest->rc = cameraTest->service->SetFlashlight(cameraTest->cameraIds.front(), cameraTest->status);
389     EXPECT_EQ(true, cameraTest->rc == HDI::Camera::V1_0::NO_ERROR);
390     sleep(UT_SLEEP_TIME);
391     cameraTest->Open();
392     sleep(UT_SLEEP_TIME);
393 }
394