1 /*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except 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
16 #include <gtest/gtest.h>
17 #include "dcameraprovidercase.h"
18 #include "dcameratest.h"
19 #include "dcamera_provider_callback_impl.h"
20 #include "dcamera_provider.h"
21
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace DistributedHardware {
26 class DCameraProviderTest : public testing::Test {
27 public:
28 static void SetUpTestCase(void);
29 static void TearDownTestCase(void);
30 void SetUp();
31 void TearDown();
32
33 std::shared_ptr<DCameraSourceDev> camDev_;
34 std::shared_ptr<ICameraStateListener> stateListener_;
35 sptr<IDCameraProviderCallback> hdiCallback_;
36 };
37
38 namespace {
39 const std::string testDeviceId = "bb536a637105409e904d4da83790a4a7";
40 const std::string testCameraDh = "camera_0";
41 const std::string testReqId = "0xFFFF";
42 const std::string testParam = R"({"CodecType": ["avenc_mpeg4"],
43 "OutputFormat": {"Photo":[4], "Preview":[2, 3], "Video":[2, 3]},
44 "Position": "BACK",
45 "ProtocolVer": "1.0",
46 "MetaData": "",
47 "Resolution": {
48 "2": ["1920*1080", "1504*720", "1440*1080", "1280*960", "1280*720", "1232*768", "1152*720", "960*720", "960*544",
49 "880*720", "720*720", "720*480", "640*480", "352*288", "320*240"],
50 "3": ["1920*1080", "1504*720", "1440*1080", "1280*960", "1280*720", "1232*768", "1152*720", "960*720", "960*544",
51 "880*720", "720*720", "720*480", "640*480", "352*288", "320*240"],
52 "4": ["3840*2160", "3264*2448", "3264*1840", "2304*1728", "2048*1536", "1920*1440", "1920*1080", "1744*1088",
53 "1280*720", "1232*768", "1152*720", "640*480", "320*240"]}})";
54 const int32_t TEST_WIDTH = 1920;
55 const int32_t TEST_HEIGTH = 1080;
56 const int32_t TEST_STREAMID = 2;
57 }
58
59 std::vector<DCStreamInfo> streamInfos;
60 std::vector<DCStreamInfo> streamInfos1;
61 std::vector<DCStreamInfo> streamInfos2;
62 std::vector<DCStreamInfo> streamInfos3;
63 std::vector<DCStreamInfo> streamInfos4;
64 std::vector<DCCaptureInfo> captureInfos;
65 std::vector<DCCaptureInfo> captureInfos1;
66 std::vector<DCCaptureInfo> captureInfos2;
67 std::vector<DCameraSettings> settings;
68 std::vector<int> streamIds;
69 DCameraSettings result;
70 DCameraSettings result1;
71 DCameraSettings result2;
72 DCameraSettings result3;
73 DCameraSettings result4;
74 DCameraSettings result5;
75 DCameraSettings result6;
76 DCStreamInfo streamInfo2;
77 DCStreamInfo streamInfo3;
78 DCStreamInfo streamInfo4;
79 DCStreamInfo streamInfo5;
80 DCCaptureInfo captureInfo2;
81 DCCaptureInfo captureInfo3;
82 DHBase dhBase;
83 DHBase dhBaseTest;
84 DCameraProvider cameraProvider;
85 DCameraBuffer buffer;
86 DCameraHDFEvent hdiEvent;
87
SetUpTestCase(void)88 void DCameraProviderTest::SetUpTestCase(void)
89 {
90 dhBase.deviceId_ = testDeviceId;
91 dhBase.dhId_ = testCameraDh;
92
93 hdiEvent.type_ = 0;
94 hdiEvent.result_ = 1;
95 hdiEvent.content_ = 9;
96
97 result.type_ = METADATA_RESULT;
98 result.value_ = "SettingValue";
99
100 DCStreamInfo streamInfo1;
101 streamInfo1.streamId_ = 1;
102 streamInfo1.width_ = TEST_WIDTH;
103 streamInfo1.height_ = TEST_HEIGTH;
104 streamInfo1.stride_ = 1;
105 streamInfo1.format_ = 1;
106 streamInfo1.dataspace_ = 1;
107 streamInfo1.encodeType_ = ENCODE_TYPE_JPEG;
108 streamInfo1.type_ = SNAPSHOT_FRAME;
109 streamInfos.push_back(streamInfo1);
110
111 streamIds.push_back(1);
112 streamIds.push_back(TEST_STREAMID);
113
114 DCCaptureInfo captureInfo1;
115 captureInfo1.streamIds_.push_back(1);
116 captureInfo1.width_ = TEST_WIDTH;
117 captureInfo1.height_ = TEST_HEIGTH;
118 captureInfo1.stride_ = 1;
119 captureInfo1.format_ = 1;
120 captureInfo1.dataspace_ = 1;
121 captureInfo1.encodeType_ = ENCODE_TYPE_H265;
122 captureInfo1.type_ = CONTINUOUS_FRAME;
123 captureInfos.push_back(captureInfo1);
124
125 settings.push_back(result);
126 }
127
TearDownTestCase(void)128 void DCameraProviderTest::TearDownTestCase(void) {}
129
SetUp(void)130 void DCameraProviderTest::SetUp(void)
131 {
132 stateListener_ = std::make_shared<HdiDCameraSourceStateListener>();
133 camDev_ = std::make_shared<HdiDCameraSourceDev>(testDeviceId, testCameraDh, stateListener_);
134 hdiCallback_ = new (std::nothrow)DCameraProviderCallbackImpl(testDeviceId, testCameraDh, camDev_);
135 }
136
TearDown(void)137 void DCameraProviderTest::TearDown(void)
138 {
139 hdiCallback_ = nullptr;
140 camDev_ = nullptr;
141 stateListener_ = nullptr;
142 dhBase.deviceId_.clear();
143 dhBase.dhId_.clear();
144 }
145
146 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_0100, TestSize.Level1)
147 {
148 dhBaseTest.deviceId_ = "";
149 dhBaseTest.dhId_ = testCameraDh;
150 int32_t ret = cameraProvider.EnableDCameraDevice(dhBaseTest, testParam, hdiCallback_);
151 EXPECT_EQ(2, ret) << "EnableDCameraDevice fail";
152 }
153
154 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_0200, TestSize.Level1)
155 {
156 int32_t ret = cameraProvider.OpenSession(dhBase);
157 EXPECT_NE(0, ret) << "OpenSession fail";
158 }
159
160 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_0300, TestSize.Level1)
161 {
162 int32_t ret = cameraProvider.ConfigureStreams(dhBase, streamInfos);
163 EXPECT_NE(0, ret) << "ConfigureStreams fail";
164 }
165
166 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_0400, TestSize.Level1)
167 {
168 int32_t ret = cameraProvider.StartCapture(dhBase, captureInfos);
169 EXPECT_NE(0, ret) << "StartCapture fail";
170 }
171
172 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_0500, TestSize.Level1)
173 {
174 int32_t ret = cameraProvider.OnSettingsResult(dhBase, result);
175 EXPECT_NE(0, ret) << "OnSettingsResult fail";
176 }
177
178 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_0600, TestSize.Level1)
179 {
180 result1.type_ = UPDATE_METADATA;
181 result1.value_ = "SettingValue";
182 int32_t ret = cameraProvider.OnSettingsResult(dhBase, result1);
183 EXPECT_NE(0, ret) << "OnSettingsResult fail";
184 }
185
186 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_0700, TestSize.Level1)
187 {
188 result2.type_ = ENABLE_METADATA;
189 result2.value_ = "SettingValue";
190 int32_t ret = cameraProvider.OnSettingsResult(dhBase, result2);
191 EXPECT_NE(0, ret) << "OnSettingsResult fail";
192 }
193
194 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_0800, TestSize.Level1)
195 {
196 result3.type_ = DISABLE_METADATA;
197 result3.value_ = "SettingValue";
198 int32_t ret = cameraProvider.OnSettingsResult(dhBase, result3);
199 EXPECT_NE(0, ret) << "OnSettingsResult fail";
200 }
201
202 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_0900, TestSize.Level1)
203 {
204 result4.type_ = SET_FLASH_LIGHT;
205 result4.value_ = "SettingValue";
206 int32_t ret = cameraProvider.OnSettingsResult(dhBase, result4);
207 EXPECT_NE(0, ret) << "OnSettingsResult fail";
208 }
209
210 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_1000, TestSize.Level1)
211 {
212 result5.type_ = FPS_RANGE;
213 result5.value_ = "SettingValue";
214 int32_t ret = cameraProvider.OnSettingsResult(dhBase, result5);
215 EXPECT_NE(0, ret) << "OnSettingsResult fail";
216 }
217
218 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_1100, TestSize.Level1)
219 {
220 result6.type_ = UPDATE_FRAME_METADATA;
221 result6.value_ = "SettingValue";
222 int32_t ret = cameraProvider.OnSettingsResult(dhBase, result6);
223 EXPECT_NE(0, ret) << "OnSettingsResult fail";
224 }
225
226 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_1200, TestSize.Level1)
227 {
228 int32_t ret = cameraProvider.UpdateSettings(dhBase, settings);
229 EXPECT_NE(0, ret) << "UpdateSettings fail";
230 }
231
232 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_1300, TestSize.Level1)
233 {
234 int32_t ret = cameraProvider.AcquireBuffer(dhBase, TEST_STREAMID, buffer);
235 EXPECT_NE(0, ret) << "AcquireBuffer fail";
236 }
237
238 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_1400, TestSize.Level1)
239 {
240 int32_t ret = cameraProvider.Notify(dhBase, hdiEvent);
241 EXPECT_EQ(2, ret) << "Notify fail";
242 }
243
244 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_1500, TestSize.Level1)
245 {
246 int32_t ret = cameraProvider.ShutterBuffer(dhBase, TEST_STREAMID, buffer);
247 EXPECT_NE(0, ret) << "ShutterBuffer fail";
248 }
249
250 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_1600, TestSize.Level1)
251 {
252 int32_t ret = cameraProvider.StopCapture(dhBase, streamIds);
253 EXPECT_NE(0, ret) << "StopCapture fail";
254 }
255
256 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_1700, TestSize.Level1)
257 {
258 int32_t ret = cameraProvider.ReleaseStreams(dhBase, streamIds);
259 EXPECT_NE(0, ret) << "ReleaseStreams fail";
260 }
261
262
263 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_1800, TestSize.Level1)
264 {
265 int32_t ret = cameraProvider.CloseSession(dhBase);
266 EXPECT_NE(0, ret) << "CloseSession fail";
267 }
268
269 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_1900, TestSize.Level1)
270 {
271 int32_t ret = cameraProvider.DisableDCameraDevice(dhBase);
272 EXPECT_EQ(2, ret) << "DisableDCameraDevice fail";
273 }
274
275 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_2000, TestSize.Level1)
276 {
277 int32_t ret = cameraProvider.OpenSession(dhBase);
278 EXPECT_NE(SUCCESS, ret) << "OpenSession fail";
279 }
280
281 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_2100, TestSize.Level1)
282 {
283 int32_t ret = cameraProvider.ConfigureStreams(dhBase, streamInfos);
284 EXPECT_NE(CAMERA_BUSY, ret) << "ConfigureStreams fail";
285 }
286
287 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_2200, TestSize.Level1)
288 {
289 int32_t ret = cameraProvider.StartCapture(dhBase, captureInfos);
290 EXPECT_EQ(INVALID_ARGUMENT, ret) << "StartCapture fail";
291 }
292
293 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_2300, TestSize.Level1)
294 {
295 int32_t ret = cameraProvider.OnSettingsResult(dhBase, result);
296 EXPECT_NE(METHOD_NOT_SUPPORTED, ret) << "OnSettingsResult fail";
297 }
298
299 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_2400, TestSize.Level1)
300 {
301 int32_t ret = cameraProvider.UpdateSettings(dhBase, settings);
302 EXPECT_NE(CAMERA_OFFLINE, ret) << "UpdateSettings fail";
303 }
304
305 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_2500, TestSize.Level1)
306 {
307 int32_t ret = cameraProvider.AcquireBuffer(dhBase, TEST_STREAMID, buffer);
308 EXPECT_NE(EXCEED_MAX_NUMBER, ret) << "AcquireBuffer fail";
309 }
310
311 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_2600, TestSize.Level1)
312 {
313 int32_t ret = cameraProvider.Notify(dhBase, hdiEvent);
314 EXPECT_NE(DEVICE_NOT_INIT, ret) << "Notify fail";
315 }
316
317 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_2700, TestSize.Level1)
318 {
319 int32_t ret = cameraProvider.ShutterBuffer(dhBase, TEST_STREAMID, buffer);
320 EXPECT_NE(FAILED, ret) << "ShutterBuffer fail";
321 }
322
323 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_2800, TestSize.Level1)
324 {
325 streamInfo2.streamId_ = 1;
326 streamInfo2.width_ = TEST_WIDTH;
327 streamInfo2.height_ = TEST_HEIGTH;
328 streamInfo2.stride_ = 1;
329 streamInfo2.format_ = 1;
330 streamInfo2.dataspace_ = 1;
331 streamInfo2.encodeType_ = ENCODE_TYPE_NULL;
332 streamInfo2.type_ = SNAPSHOT_FRAME;
333 streamInfos1.push_back(streamInfo2);
334 int32_t ret = cameraProvider.ConfigureStreams(dhBase, streamInfos1);
335 EXPECT_NE(0, ret) << "ConfigureStreams fail";
336 }
337
338 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_2900, TestSize.Level1)
339 {
340 streamInfo3.streamId_ = 1;
341 streamInfo3.width_ = TEST_WIDTH;
342 streamInfo3.height_ = TEST_HEIGTH;
343 streamInfo3.stride_ = 1;
344 streamInfo3.format_ = 1;
345 streamInfo3.dataspace_ = 1;
346 streamInfo3.encodeType_ = ENCODE_TYPE_H264;
347 streamInfo3.type_ = SNAPSHOT_FRAME;
348 streamInfos2.push_back(streamInfo3);
349 int32_t ret = cameraProvider.ConfigureStreams(dhBase, streamInfos2);
350 EXPECT_NE(0, ret) << "ConfigureStreams fail";
351 }
352
353 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_3000, TestSize.Level1)
354 {
355 streamInfo4.streamId_ = 1;
356 streamInfo4.width_ = TEST_WIDTH;
357 streamInfo4.height_ = TEST_HEIGTH;
358 streamInfo4.stride_ = 1;
359 streamInfo4.format_ = 1;
360 streamInfo4.dataspace_ = 1;
361 streamInfo4.encodeType_ = ENCODE_TYPE_H265;
362 streamInfo4.type_ = SNAPSHOT_FRAME;
363 streamInfos3.push_back(streamInfo4);
364 int32_t ret = cameraProvider.ConfigureStreams(dhBase, streamInfos3);
365 EXPECT_NE(0, ret) << "ConfigureStreams fail";
366 }
367
368 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_3100, TestSize.Level1)
369 {
370 streamInfo5.streamId_ = 1;
371 streamInfo5.width_ = TEST_WIDTH;
372 streamInfo5.height_ = TEST_HEIGTH;
373 streamInfo5.stride_ = 1;
374 streamInfo5.format_ = 1;
375 streamInfo5.dataspace_ = 1;
376 streamInfo5.encodeType_ = ENCODE_TYPE_JPEG;
377 streamInfo5.type_ = SNAPSHOT_FRAME;
378 streamInfos4.push_back(streamInfo5);
379 int32_t ret = cameraProvider.ConfigureStreams(dhBase, streamInfos4);
380 EXPECT_NE(0, ret) << "ConfigureStreams fail";
381 }
382
383 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_3200, TestSize.Level1)
384 {
385 captureInfo2.streamIds_.push_back(1);
386 captureInfo2.width_ = TEST_WIDTH;
387 captureInfo2.height_ = TEST_HEIGTH;
388 captureInfo2.stride_ = 1;
389 captureInfo2.format_ = 1;
390 captureInfo2.dataspace_ = 1;
391 captureInfo2.encodeType_ = ENCODE_TYPE_H265;
392 captureInfo2.type_ = CONTINUOUS_FRAME;
393 captureInfos1.push_back(captureInfo2);
394 int32_t ret = cameraProvider.StartCapture(dhBase, captureInfos1);
395 EXPECT_EQ(INVALID_ARGUMENT, ret) << "StartCapture fail";
396 }
397
398 HWTEST_F(DCameraProviderTest, SUB_DH_Dcamera_Hats_3300, TestSize.Level1)
399 {
400 captureInfo3.streamIds_.push_back(1);
401 captureInfo3.width_ = TEST_WIDTH;
402 captureInfo3.height_ = TEST_HEIGTH;
403 captureInfo3.stride_ = 1;
404 captureInfo3.format_ = 1;
405 captureInfo3.dataspace_ = 1;
406 captureInfo3.encodeType_ = ENCODE_TYPE_H265;
407 captureInfo3.type_ = SNAPSHOT_FRAME;
408 captureInfos2.push_back(captureInfo3);
409 int32_t ret = cameraProvider.StartCapture(dhBase, captureInfos2);
410 EXPECT_EQ(INVALID_ARGUMENT, ret) << "StartCapture fail";
411 }
412 }
413 }