1 /*
2 * Copyright (c) 2021-2022 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 "camera_framework_unittest.h"
17 #include "camera_util.h"
18 #include "gmock/gmock.h"
19 #include "input/camera_input.h"
20 #include "surface.h"
21 #include "test_common.h"
22
23 #include "ipc_skeleton.h"
24 #include "access_token.h"
25 #include "hap_token_info.h"
26 #include "accesstoken_kit.h"
27 #include "token_setproc.h"
28
29 using namespace testing::ext;
30 using ::testing::A;
31 using ::testing::InSequence;
32 using ::testing::Mock;
33 using ::testing::Return;
34 using ::testing::_;
35
36 namespace OHOS {
37 namespace CameraStandard {
38 class MockStreamOperator : public IRemoteStub<Camera::IStreamOperator> {
39 public:
MockStreamOperator()40 MockStreamOperator()
41 {
42 ON_CALL(*this, CreateStreams(_)).WillByDefault(Return(Camera::NO_ERROR));
43 ON_CALL(*this, ReleaseStreams(_)).WillByDefault(Return(Camera::NO_ERROR));
44 ON_CALL(*this, CommitStreams(_, _)).WillByDefault(Return(Camera::NO_ERROR));
45 ON_CALL(*this, Capture(_, _, _)).WillByDefault(Return(Camera::NO_ERROR));
46 ON_CALL(*this, CancelCapture(_)).WillByDefault(Return(Camera::NO_ERROR));
47 ON_CALL(*this, IsStreamsSupported(_, _, A<const std::shared_ptr<Camera::StreamInfo> &>(), _))
48 .WillByDefault(Return(Camera::NO_ERROR));
49 ON_CALL(*this, IsStreamsSupported(_, _, A<const std::vector<std::shared_ptr<Camera::StreamInfo>> &>(), _))
50 .WillByDefault(Return(Camera::NO_ERROR));
51 ON_CALL(*this, GetStreamAttributes(_)).WillByDefault(Return(Camera::NO_ERROR));
52 ON_CALL(*this, AttachBufferQueue(_, _)).WillByDefault(Return(Camera::NO_ERROR));
53 ON_CALL(*this, DetachBufferQueue(_)).WillByDefault(Return(Camera::NO_ERROR));
54 ON_CALL(*this, ChangeToOfflineStream(_, _, _)).WillByDefault(Return(Camera::NO_ERROR));
55 }
~MockStreamOperator()56 ~MockStreamOperator() {}
57 MOCK_METHOD1(CreateStreams, Camera::CamRetCode(
58 const std::vector<std::shared_ptr<Camera::StreamInfo>> &streamInfos));
59 MOCK_METHOD1(ReleaseStreams, Camera::CamRetCode(const std::vector<int> &streamIds));
60 MOCK_METHOD1(CancelCapture, Camera::CamRetCode(int captureId));
61 MOCK_METHOD1(GetStreamAttributes, Camera::CamRetCode(
62 std::vector<std::shared_ptr<Camera::StreamAttribute>> &attributes));
63 MOCK_METHOD1(DetachBufferQueue, Camera::CamRetCode(int streamId));
64 MOCK_METHOD2(CommitStreams, Camera::CamRetCode(Camera::OperationMode mode,
65 const std::shared_ptr<Camera::CameraMetadata> &modeSetting));
66 MOCK_METHOD2(AttachBufferQueue, Camera::CamRetCode(int streamId,
67 const OHOS::sptr<OHOS::IBufferProducer> &producer));
68 MOCK_METHOD3(Capture, Camera::CamRetCode(int captureId, const std::shared_ptr<Camera::CaptureInfo> &info,
69 bool isStreaming));
70 MOCK_METHOD3(ChangeToOfflineStream, Camera::CamRetCode(const std::vector<int> &streamIds,
71 OHOS::sptr<Camera::IStreamOperatorCallback> &callback,
72 OHOS::sptr<Camera::IOfflineStreamOperator> &offlineOperator));
73 MOCK_METHOD4(IsStreamsSupported, Camera::CamRetCode(Camera::OperationMode mode,
74 const std::shared_ptr<Camera::CameraMetadata> &modeSetting,
75 const std::shared_ptr<Camera::StreamInfo> &info, Camera::StreamSupportType &type));
76 MOCK_METHOD4(IsStreamsSupported, Camera::CamRetCode(Camera::OperationMode mode,
77 const std::shared_ptr<Camera::CameraMetadata> &modeSetting,
78 const std::vector<std::shared_ptr<Camera::StreamInfo>> &info, Camera::StreamSupportType &type));
79 };
80
81 class MockCameraDevice : public IRemoteStub<Camera::ICameraDevice> {
82 public:
MockCameraDevice()83 MockCameraDevice()
84 {
85 streamOperator = new MockStreamOperator();
86 ON_CALL(*this, GetStreamOperator).WillByDefault([this](
87 const OHOS::sptr<Camera::IStreamOperatorCallback> &callback,
88 OHOS::sptr<Camera::IStreamOperator> &pStreamOperator) {
89 pStreamOperator = streamOperator;
90 return Camera::NO_ERROR;
91 });
92 ON_CALL(*this, UpdateSettings(_)).WillByDefault(Return(Camera::NO_ERROR));
93 ON_CALL(*this, SetResultMode(_)).WillByDefault(Return(Camera::NO_ERROR));
94 ON_CALL(*this, GetEnabledResults(_)).WillByDefault(Return(Camera::NO_ERROR));
95 ON_CALL(*this, EnableResult(_)).WillByDefault(Return(Camera::NO_ERROR));
96 ON_CALL(*this, DisableResult(_)).WillByDefault(Return(Camera::NO_ERROR));
97 ON_CALL(*this, DisableResult(_)).WillByDefault(Return(Camera::NO_ERROR));
98 ON_CALL(*this, Close()).WillByDefault(Return());
99 }
~MockCameraDevice()100 ~MockCameraDevice() {}
101 MOCK_METHOD0(Close, void());
102 MOCK_METHOD1(UpdateSettings, Camera::CamRetCode(const std::shared_ptr<Camera::CameraSetting> &settings));
103 MOCK_METHOD1(SetResultMode, Camera::CamRetCode(const Camera::ResultCallbackMode &mode));
104 MOCK_METHOD1(GetEnabledResults, Camera::CamRetCode(std::vector<Camera::MetaType> &results));
105 MOCK_METHOD1(EnableResult, Camera::CamRetCode(const std::vector<Camera::MetaType> &results));
106 MOCK_METHOD1(DisableResult, Camera::CamRetCode(const std::vector<Camera::MetaType> &results));
107 MOCK_METHOD2(GetStreamOperator, Camera::CamRetCode(const OHOS::sptr<Camera::IStreamOperatorCallback> &callback,
108 OHOS::sptr<Camera::IStreamOperator> &pStreamOperator));
109 sptr<MockStreamOperator> streamOperator;
110 };
111
112 class MockHCameraHostManager : public HCameraHostManager {
113 public:
MockHCameraHostManager(StatusCallback * statusCallback)114 explicit MockHCameraHostManager(StatusCallback* statusCallback) : HCameraHostManager(statusCallback)
115 {
116 cameraDevice = new MockCameraDevice();
117 ON_CALL(*this, GetCameras).WillByDefault([this](std::vector<std::string> &cameraIds) {
118 cameraIds.emplace_back("cam0");
119 return CAMERA_OK;
120 });
121 ON_CALL(*this, GetCameraAbility).WillByDefault([this](std::string &cameraId,
122 std::shared_ptr<Camera::CameraMetadata> &ability) {
123 int32_t itemCount = 10;
124 int32_t dataSize = 100;
125 ability = std::make_shared<Camera::CameraMetadata>(itemCount, dataSize);
126 int32_t streams[9] = {
127 OHOS_CAMERA_FORMAT_YCRCB_420_SP, CameraFrameworkUnitTest::PREVIEW_DEFAULT_WIDTH,
128 CameraFrameworkUnitTest::PREVIEW_DEFAULT_HEIGHT, OHOS_CAMERA_FORMAT_YCRCB_420_SP,
129 CameraFrameworkUnitTest::VIDEO_DEFAULT_WIDTH, CameraFrameworkUnitTest::VIDEO_DEFAULT_HEIGHT,
130 OHOS_CAMERA_FORMAT_JPEG, CameraFrameworkUnitTest::PHOTO_DEFAULT_WIDTH,
131 CameraFrameworkUnitTest::PHOTO_DEFAULT_HEIGHT
132 };
133 ability->addEntry(OHOS_ABILITY_STREAM_AVAILABLE_BASIC_CONFIGURATIONS, streams,
134 sizeof(streams) / sizeof(streams[0]));
135 return CAMERA_OK;
136 });
137 ON_CALL(*this, OpenCameraDevice).WillByDefault([this](std::string &cameraId,
138 const sptr<Camera::ICameraDeviceCallback> &callback,
139 sptr<Camera::ICameraDevice> &pDevice) {
140 pDevice = cameraDevice;
141 return CAMERA_OK;
142 });
143 ON_CALL(*this, SetFlashlight(_, _)).WillByDefault(Return(CAMERA_OK));
144 ON_CALL(*this, SetCallback(_)).WillByDefault(Return(CAMERA_OK));
145 }
~MockHCameraHostManager()146 ~MockHCameraHostManager() {}
147 MOCK_METHOD1(GetCameras, int32_t(std::vector<std::string> &cameraIds));
148 MOCK_METHOD1(SetCallback, int32_t(sptr<Camera::ICameraHostCallback> &callback));
149 MOCK_METHOD2(GetCameraAbility, int32_t(std::string &cameraId, std::shared_ptr<Camera::CameraMetadata> &ability));
150 MOCK_METHOD2(SetFlashlight, int32_t(const std::string &cameraId, bool isEnable));
151 MOCK_METHOD3(OpenCameraDevice, int32_t(std::string &cameraId,
152 const sptr<Camera::ICameraDeviceCallback> &callback, sptr<Camera::ICameraDevice> &pDevice));
153 sptr<MockCameraDevice> cameraDevice;
154 };
155
156 class FakeHCameraService : public HCameraService {
157 public:
FakeHCameraService(sptr<HCameraHostManager> hostManager)158 explicit FakeHCameraService(sptr<HCameraHostManager> hostManager) : HCameraService(hostManager) {}
~FakeHCameraService()159 ~FakeHCameraService() {}
160 };
161
162 class FakeCameraManager : public CameraManager {
163 public:
FakeCameraManager(sptr<HCameraService> service)164 explicit FakeCameraManager(sptr<HCameraService> service) : CameraManager(service) {}
~FakeCameraManager()165 ~FakeCameraManager() {}
166 };
167
CreatePhotoOutput(int32_t width,int32_t height)168 sptr<CaptureOutput> CameraFrameworkUnitTest::CreatePhotoOutput(int32_t width, int32_t height)
169 {
170 sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
171 surface->SetDefaultWidthAndHeight(width, height);
172 surface->SetUserData(CameraManager::surfaceFormat, std::to_string(OHOS_CAMERA_FORMAT_JPEG));
173 return cameraManager->CreatePhotoOutput(surface);
174 }
175
CreatePreviewOutput(int32_t width,int32_t height)176 sptr<CaptureOutput> CameraFrameworkUnitTest::CreatePreviewOutput(int32_t width, int32_t height)
177 {
178 sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
179 surface->SetDefaultWidthAndHeight(width, height);
180 surface->SetUserData(CameraManager::surfaceFormat, std::to_string(OHOS_CAMERA_FORMAT_YCRCB_420_SP));
181 return cameraManager->CreatePreviewOutput(surface);
182 }
183
CreateVideoOutput(int32_t width,int32_t height)184 sptr<CaptureOutput> CameraFrameworkUnitTest::CreateVideoOutput(int32_t width, int32_t height)
185 {
186 sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
187 surface->SetDefaultWidthAndHeight(width, height);
188 surface->SetUserData(CameraManager::surfaceFormat, std::to_string(OHOS_CAMERA_FORMAT_YCRCB_420_SP));
189 return cameraManager->CreateVideoOutput(surface);
190 }
191
192 static std::string permissionName = "ohos.permission.CAMERA";
193 static OHOS::Security::AccessToken::HapInfoParams g_infoManagerTestInfoParms = {
194 .userID = 1,
195 .bundleName = permissionName,
196 .instIndex = 0,
197 .appIDDesc = "testtesttesttest"
198 };
199
200 static OHOS::Security::AccessToken::PermissionDef g_infoManagerTestPermDef1 = {
201 .permissionName = "ohos.permission.CAMERA",
202 .bundleName = "ohos.permission.CAMERA",
203 .grantMode = 1,
204 .availableLevel = OHOS::Security::AccessToken::ATokenAplEnum::APL_NORMAL,
205 .label = "label",
206 .labelId = 1,
207 .description = "camera test",
208 .descriptionId = 1
209 };
210
211 static OHOS::Security::AccessToken::PermissionStateFull g_infoManagerTestState1 = {
212 .permissionName = "ohos.permission.CAMERA",
213 .isGeneral = true,
214 .resDeviceID = {"local"},
215 .grantStatus = {OHOS::Security::AccessToken::PermissionState::PERMISSION_GRANTED},
216 .grantFlags = {1}
217 };
218
219 static OHOS::Security::AccessToken::HapPolicyParams g_infoManagerTestPolicyPrams = {
220 .apl = OHOS::Security::AccessToken::ATokenAplEnum::APL_NORMAL,
221 .domain = "test.domain",
222 .permList = {g_infoManagerTestPermDef1},
223 .permStateList = {g_infoManagerTestState1}
224 };
225
226 OHOS::Security::AccessToken::AccessTokenIDEx tokenIdEx = {0};
227
SetUpTestCase(void)228 void CameraFrameworkUnitTest::SetUpTestCase(void)
229 {
230 int32_t ret = -1;
231
232 /* Grant the permission so that create camera test can be success */
233 tokenIdEx = OHOS::Security::AccessToken::AccessTokenKit::AllocHapToken(
234 g_infoManagerTestInfoParms,
235 g_infoManagerTestPolicyPrams);
236 if (tokenIdEx.tokenIdExStruct.tokenID == 0) {
237 return;
238 }
239
240 (void)SetSelfTokenID(tokenIdEx.tokenIdExStruct.tokenID);
241
242 ret = Security::AccessToken::AccessTokenKit::GrantPermission(
243 tokenIdEx.tokenIdExStruct.tokenID,
244 permissionName, OHOS::Security::AccessToken::PERMISSION_USER_FIXED);
245 if (ret != 0) {
246 return;
247 }
248 }
249
TearDownTestCase(void)250 void CameraFrameworkUnitTest::TearDownTestCase(void)
251 {
252 (void)OHOS::Security::AccessToken::AccessTokenKit::DeleteToken(
253 tokenIdEx.tokenIdExStruct.tokenID);
254 }
255
SetUp()256 void CameraFrameworkUnitTest::SetUp()
257 {
258 mockCameraHostManager = new MockHCameraHostManager(nullptr);
259 mockCameraDevice = mockCameraHostManager->cameraDevice;
260 mockStreamOperator = mockCameraDevice->streamOperator;
261 cameraManager = new FakeCameraManager(new FakeHCameraService(mockCameraHostManager));
262 }
263
TearDown()264 void CameraFrameworkUnitTest::TearDown()
265 {
266 Mock::AllowLeak(mockCameraHostManager);
267 Mock::AllowLeak(mockCameraDevice);
268 Mock::AllowLeak(mockStreamOperator);
269 }
270
271 MATCHER_P(matchCaptureSetting, captureSetting, "Match Capture Setting")
272 {
273 return (arg->captureSetting_ == captureSetting);
274 }
275
276 /*
277 * Feature: Framework
278 * Function: Test get cameras
279 * SubFunction: NA
280 * FunctionPoints: NA
281 * EnvConditions: NA
282 * CaseDescription: Test get cameras
283 */
284 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_001, TestSize.Level0)
285 {
286 InSequence s;
287 EXPECT_CALL(*mockCameraHostManager, GetCameras(_));
288 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
289 std::vector<sptr<CameraInfo>> cameras = cameraManager->GetCameras();
290 ASSERT_TRUE(cameras.size() != 0);
291 }
292
293 /*
294 * Feature: Framework
295 * Function: Test create input
296 * SubFunction: NA
297 * FunctionPoints: NA
298 * EnvConditions: NA
299 * CaseDescription: Test create input
300 */
301 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_002, TestSize.Level0)
302 {
303 InSequence s;
304 EXPECT_CALL(*mockCameraHostManager, GetCameras(_));
305 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
306 std::vector<sptr<CameraInfo>> cameras = cameraManager->GetCameras();
307 ASSERT_TRUE(cameras.size() != 0);
308
309 sptr<CameraInput> input = cameraManager->CreateCameraInput(cameras[0]);
310 ASSERT_NE(input, nullptr);
311 ASSERT_NE(input->GetCameraDevice(), nullptr);
312
313 input->Release();
314 }
315
316 /*
317 * Feature: Framework
318 * Function: Test create session
319 * SubFunction: NA
320 * FunctionPoints: NA
321 * EnvConditions: NA
322 * CaseDescription: Test create session
323 */
324 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_003, TestSize.Level0)
325 {
326 sptr<CaptureSession> session = cameraManager->CreateCaptureSession();
327 ASSERT_NE(session, nullptr);
328 session->Release();
329 }
330
331 /*
332 * Feature: Framework
333 * Function: Test create preview output
334 * SubFunction: NA
335 * FunctionPoints: NA
336 * EnvConditions: NA
337 * CaseDescription: Test create preview output
338 */
339 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_004, TestSize.Level0)
340 {
341 int32_t width = PREVIEW_DEFAULT_WIDTH;
342 int32_t height = PREVIEW_DEFAULT_HEIGHT;
343 sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
344 surface->SetDefaultWidthAndHeight(width, height);
345 surface->SetUserData(CameraManager::surfaceFormat, std::to_string(OHOS_CAMERA_FORMAT_YCRCB_420_SP));
346 sptr<CaptureOutput> preview = cameraManager->CreatePreviewOutput(surface);
347 ASSERT_NE(preview, nullptr);
348 preview->Release();
349 }
350
351 /*
352 * Feature: Framework
353 * Function: Test create preview output with surface as null
354 * SubFunction: NA
355 * FunctionPoints: NA
356 * EnvConditions: NA
357 * CaseDescription: Test create preview output with surface as null
358 */
359 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_005, TestSize.Level0)
360 {
361 sptr<Surface> surface = nullptr;
362 sptr<CaptureOutput> preview = cameraManager->CreatePreviewOutput(surface);
363 ASSERT_EQ(preview, nullptr);
364 }
365
366 /*
367 * Feature: Framework
368 * Function: Test create preview output with buffer producer
369 * SubFunction: NA
370 * FunctionPoints: NA
371 * EnvConditions: NA
372 * CaseDescription: Test create preview output with buffer producer
373 */
374 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_006, TestSize.Level0)
375 {
376 int32_t width = PREVIEW_DEFAULT_WIDTH;
377 int32_t height = PREVIEW_DEFAULT_HEIGHT;
378 sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
379 surface->SetDefaultWidthAndHeight(width, height);
380 sptr<CaptureOutput> preview = cameraManager->CreatePreviewOutput(surface->GetProducer(),
381 OHOS_CAMERA_FORMAT_YCRCB_420_SP);
382 ASSERT_NE(preview, nullptr);
383 preview->Release();
384 }
385
386 /*
387 * Feature: Framework
388 * Function: Test create preview output with buffer producer as null
389 * SubFunction: NA
390 * FunctionPoints: NA
391 * EnvConditions: NA
392 * CaseDescription: Test create preview output with buffer producer as null
393 */
394 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_007, TestSize.Level0)
395 {
396 sptr<OHOS::IBufferProducer> producer = nullptr;
397 sptr<CaptureOutput> preview = cameraManager->CreatePreviewOutput(producer, OHOS_CAMERA_FORMAT_YCRCB_420_SP);
398 ASSERT_EQ(preview, nullptr);
399 }
400
401 /*
402 * Feature: Framework
403 * Function: Test create custom preview output
404 * SubFunction: NA
405 * FunctionPoints: NA
406 * EnvConditions: NA
407 * CaseDescription: Test create custom preview output
408 */
409 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_008, TestSize.Level0)
410 {
411 int32_t width = PREVIEW_DEFAULT_WIDTH;
412 int32_t height = PREVIEW_DEFAULT_HEIGHT;
413 sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
414 surface->SetDefaultWidthAndHeight(width, height);
415 surface->SetUserData(CameraManager::surfaceFormat, std::to_string(OHOS_CAMERA_FORMAT_YCRCB_420_SP));
416 sptr<CaptureOutput> preview = cameraManager->CreateCustomPreviewOutput(surface, width, height);
417 ASSERT_NE(preview, nullptr);
418 preview->Release();
419 }
420
421 /*
422 * Feature: Framework
423 * Function: Test create custom preview output with surface as null
424 * SubFunction: NA
425 * FunctionPoints: NA
426 * EnvConditions: NA
427 * CaseDescription: Test create custom preview output with surface as null
428 */
429 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_009, TestSize.Level0)
430 {
431 int32_t width = PREVIEW_DEFAULT_WIDTH;
432 int32_t height = PREVIEW_DEFAULT_HEIGHT;
433 sptr<Surface> surface = nullptr;
434 sptr<CaptureOutput> preview = cameraManager->CreateCustomPreviewOutput(surface, width, height);
435 ASSERT_EQ(preview, nullptr);
436 }
437
438 /*
439 * Feature: Framework
440 * Function: Test create custom preview output with width and height as 0
441 * SubFunction: NA
442 * FunctionPoints: NA
443 * EnvConditions: NA
444 * CaseDescription: Test create custom preview output with width and height as 0
445 */
446 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_010, TestSize.Level0)
447 {
448 int32_t width = 0;
449 int32_t height = 0;
450 sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
451 sptr<CaptureOutput> preview = cameraManager->CreateCustomPreviewOutput(surface, width, height);
452 ASSERT_EQ(preview, nullptr);
453 }
454
455
456 /*
457 * Feature: Framework
458 * Function: Test create photo output
459 * SubFunction: NA
460 * FunctionPoints: NA
461 * EnvConditions: NA
462 * CaseDescription: Test create photo output
463 */
464 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_011, TestSize.Level0)
465 {
466 int32_t width = PHOTO_DEFAULT_WIDTH;
467 int32_t height = PHOTO_DEFAULT_HEIGHT;
468 sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
469 surface->SetDefaultWidthAndHeight(width, height);
470 surface->SetUserData(CameraManager::surfaceFormat, std::to_string(OHOS_CAMERA_FORMAT_JPEG));
471 sptr<PhotoOutput> photo = cameraManager->CreatePhotoOutput(surface);
472 ASSERT_NE(photo, nullptr);
473 photo->Release();
474 }
475
476 /*
477 * Feature: Framework
478 * Function: Test create photo output with surface as null
479 * SubFunction: NA
480 * FunctionPoints: NA
481 * EnvConditions: NA
482 * CaseDescription: Test create photo output with surface as null
483 */
484 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_012, TestSize.Level0)
485 {
486 sptr<Surface> surface = nullptr;
487 sptr<PhotoOutput> photo = cameraManager->CreatePhotoOutput(surface);
488 ASSERT_EQ(photo, nullptr);
489 }
490
491 /*
492 * Feature: Framework
493 * Function: Test create photo output with buffer producer
494 * SubFunction: NA
495 * FunctionPoints: NA
496 * EnvConditions: NA
497 * CaseDescription: Test create photo output with buffer producer
498 */
499 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_013, TestSize.Level0)
500 {
501 int32_t width = PHOTO_DEFAULT_WIDTH;
502 int32_t height = PHOTO_DEFAULT_HEIGHT;
503 sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
504 surface->SetDefaultWidthAndHeight(width, height);
505 sptr<PhotoOutput> photo = cameraManager->CreatePhotoOutput(surface->GetProducer(), OHOS_CAMERA_FORMAT_JPEG);
506 ASSERT_NE(photo, nullptr);
507 photo->Release();
508 }
509
510 /*
511 * Feature: Framework
512 * Function: Test create photo output with buffer producer as null
513 * SubFunction: NA
514 * FunctionPoints: NA
515 * EnvConditions: NA
516 * CaseDescription: Test create photo output with buffer producer as null
517 */
518 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_014, TestSize.Level0)
519 {
520 sptr<OHOS::IBufferProducer> producer = nullptr;
521 sptr<PhotoOutput> photo = cameraManager->CreatePhotoOutput(producer, OHOS_CAMERA_FORMAT_JPEG);
522 ASSERT_EQ(photo, nullptr);
523 }
524
525 /*
526 * Feature: Framework
527 * Function: Test create video output
528 * SubFunction: NA
529 * FunctionPoints: NA
530 * EnvConditions: NA
531 * CaseDescription: Test create video output
532 */
533 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_015, TestSize.Level0)
534 {
535 int32_t width = VIDEO_DEFAULT_WIDTH;
536 int32_t height = VIDEO_DEFAULT_HEIGHT;
537 sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
538 surface->SetDefaultWidthAndHeight(width, height);
539 surface->SetUserData(CameraManager::surfaceFormat, std::to_string(OHOS_CAMERA_FORMAT_YCRCB_420_SP));
540 sptr<VideoOutput> video = cameraManager->CreateVideoOutput(surface);
541 ASSERT_NE(video, nullptr);
542 video->Release();
543 }
544
545 /*
546 * Feature: Framework
547 * Function: Test create video output with surface as null
548 * SubFunction: NA
549 * FunctionPoints: NA
550 * EnvConditions: NA
551 * CaseDescription: Test create video output with surface as null
552 */
553 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_016, TestSize.Level0)
554 {
555 sptr<Surface> surface = nullptr;
556 sptr<VideoOutput> video = cameraManager->CreateVideoOutput(surface);
557 ASSERT_EQ(video, nullptr);
558 }
559
560 /*
561 * Feature: Framework
562 * Function: Test create video output with buffer producer
563 * SubFunction: NA
564 * FunctionPoints: NA
565 * EnvConditions: NA
566 * CaseDescription: Test create video output with buffer producer
567 */
568 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_017, TestSize.Level0)
569 {
570 int32_t width = VIDEO_DEFAULT_WIDTH;
571 int32_t height = VIDEO_DEFAULT_HEIGHT;
572 sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
573 surface->SetDefaultWidthAndHeight(width, height);
574 sptr<VideoOutput> video = cameraManager->CreateVideoOutput(surface->GetProducer(), OHOS_CAMERA_FORMAT_YCRCB_420_SP);
575 ASSERT_NE(video, nullptr);
576 video->Release();
577 }
578
579 /*
580 * Feature: Framework
581 * Function: Test create video output with buffer producer as null
582 * SubFunction: NA
583 * FunctionPoints: NA
584 * EnvConditions: NA
585 * CaseDescription: Test create video output with buffer producer as null
586 */
587 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_018, TestSize.Level0)
588 {
589 sptr<OHOS::IBufferProducer> producer = nullptr;
590 sptr<VideoOutput> video = cameraManager->CreateVideoOutput(producer, OHOS_CAMERA_FORMAT_YCRCB_420_SP);
591 ASSERT_EQ(video, nullptr);
592 }
593
594 /*
595 * Feature: Framework
596 * Function: Test manager callback
597 * SubFunction: NA
598 * FunctionPoints: NA
599 * EnvConditions: NA
600 * CaseDescription: Test manager callback
601 */
602 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_019, TestSize.Level0)
603 {
604 std::shared_ptr<TestCameraMngerCallback> setCallback = std::make_shared<TestCameraMngerCallback>("MgrCallback");
605 cameraManager->SetCallback(setCallback);
606 std::shared_ptr<CameraManagerCallback> getCallback = cameraManager->GetApplicationCallback();
607 ASSERT_EQ(setCallback, getCallback);
608 }
609
610 /*
611 * Feature: Framework
612 * Function: Test set camera parameters
613 * SubFunction: NA
614 * FunctionPoints: NA
615 * EnvConditions: NA
616 * CaseDescription: Test set camera parameters
617 */
618 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_020, TestSize.Level0)
619 {
620 InSequence s;
621 EXPECT_CALL(*mockCameraHostManager, GetCameras(_));
622 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
623 std::vector<sptr<CameraInfo>> cameras = cameraManager->GetCameras();
624
625 sptr<CameraInput> input = cameraManager->CreateCameraInput(cameras[0]);
626 ASSERT_NE(input, nullptr);
627
628 input->LockForControl();
629
630 std::vector<float> zoomRatioRange = input->GetSupportedZoomRatioRange();
631 if (!zoomRatioRange.empty()) {
632 input->SetZoomRatio(zoomRatioRange[0]);
633 }
634
635 camera_flash_mode_enum_t flash = OHOS_CAMERA_FLASH_MODE_ALWAYS_OPEN;
636 input->SetFlashMode(flash);
637
638 camera_af_mode_t focus = OHOS_CAMERA_AF_MODE_AUTO;
639 input->SetFocusMode(focus);
640
641 camera_ae_mode_t exposure = OHOS_CAMERA_AE_MODE_ON;
642 input->SetExposureMode(exposure);
643
644 input->UnlockForControl();
645
646 if (!zoomRatioRange.empty()) {
647 EXPECT_TRUE(input->GetZoomRatio() == zoomRatioRange[0]);
648 }
649 EXPECT_TRUE(input->GetFlashMode() == flash);
650 EXPECT_TRUE(input->GetFocusMode() == focus);
651 EXPECT_TRUE(input->GetExposureMode() == exposure);
652 }
653
654 /*
655 * Feature: Framework
656 * Function: Test input callback
657 * SubFunction: NA
658 * FunctionPoints: NA
659 * EnvConditions: NA
660 * CaseDescription: Test input callback
661 */
662 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_021, TestSize.Level0)
663 {
664 InSequence s;
665 EXPECT_CALL(*mockCameraHostManager, GetCameras(_));
666 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
667 std::vector<sptr<CameraInfo>> cameras = cameraManager->GetCameras();
668
669 sptr<CameraInput> input = cameraManager->CreateCameraInput(cameras[0]);
670 ASSERT_NE(input, nullptr);
671
672 std::shared_ptr<TestDeviceCallback> setCallback = std::make_shared<TestDeviceCallback>("InputCallback");
673 input->SetErrorCallback(setCallback);
674 std::shared_ptr<ErrorCallback> getCallback = input->GetErrorCallback();
675 ASSERT_EQ(setCallback, getCallback);
676 }
677
678 /*
679 * Feature: Framework
680 * Function: Test preview callback
681 * SubFunction: NA
682 * FunctionPoints: NA
683 * EnvConditions: NA
684 * CaseDescription: Test preview callback
685 */
686 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_022, TestSize.Level0)
687 {
688 sptr<CaptureOutput> preview = CreatePreviewOutput();
689 ASSERT_NE(preview, nullptr);
690
691 std::shared_ptr<PreviewCallback> setCallback = std::make_shared<TestPreviewOutputCallback>("PreviewCallback");
692 ((sptr<PreviewOutput> &)preview)->SetCallback(setCallback);
693 std::shared_ptr<PreviewCallback> getCallback = ((sptr<PreviewOutput> &)preview)->GetApplicationCallback();
694 ASSERT_EQ(setCallback, getCallback);
695 }
696
697 /*
698 * Feature: Framework
699 * Function: Test photo callback
700 * SubFunction: NA
701 * FunctionPoints: NA
702 * EnvConditions: NA
703 * CaseDescription: Test photo callback
704 */
705 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_023, TestSize.Level0)
706 {
707 sptr<CaptureOutput> photo = CreatePhotoOutput();
708 ASSERT_NE(photo, nullptr);
709
710 std::shared_ptr<PhotoCallback> setCallback = std::make_shared<TestPhotoOutputCallback>("PhotoCallback");
711 ((sptr<PhotoOutput> &)photo)->SetCallback(setCallback);
712 std::shared_ptr<PhotoCallback> getCallback = ((sptr<PhotoOutput> &)photo)->GetApplicationCallback();
713 ASSERT_EQ(setCallback, getCallback);
714 }
715
716 /*
717 * Feature: Framework
718 * Function: Test video callback
719 * SubFunction: NA
720 * FunctionPoints: NA
721 * EnvConditions: NA
722 * CaseDescription: Test video callback
723 */
724 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_024, TestSize.Level0)
725 {
726 sptr<CaptureOutput> video = CreateVideoOutput();
727 ASSERT_NE(video, nullptr);
728
729 std::shared_ptr<VideoCallback> setCallback = std::make_shared<TestVideoOutputCallback>("VideoCallback");
730 ((sptr<VideoOutput> &)video)->SetCallback(setCallback);
731 std::shared_ptr<VideoCallback> getCallback = ((sptr<VideoOutput> &)video)->GetApplicationCallback();
732 ASSERT_EQ(setCallback, getCallback);
733 }
734
735 /*
736 * Feature: Framework
737 * Function: Test capture session add input with invalid value
738 * SubFunction: NA
739 * FunctionPoints: NA
740 * EnvConditions: NA
741 * CaseDescription: Test capture session add input with invalid value
742 */
743 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_025, TestSize.Level0)
744 {
745 sptr<CaptureSession> session = cameraManager->CreateCaptureSession();
746 ASSERT_NE(session, nullptr);
747
748 int32_t ret = session->BeginConfig();
749 EXPECT_TRUE(ret == 0);
750
751 sptr<CaptureInput> input = nullptr;
752 ret = session->AddInput(input);
753 EXPECT_TRUE(ret != 0);
754 }
755
756 /*
757 * Feature: Framework
758 * Function: Test capture session add output with invalid value
759 * SubFunction: NA
760 * FunctionPoints: NA
761 * EnvConditions: NA
762 * CaseDescription: Test capture session add output with invalid value
763 */
764 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_026, TestSize.Level0)
765 {
766 sptr<CaptureSession> session = cameraManager->CreateCaptureSession();
767 ASSERT_NE(session, nullptr);
768
769 int32_t ret = session->BeginConfig();
770 EXPECT_TRUE(ret == 0);
771
772 sptr<CaptureOutput> preview = nullptr;
773 ret = session->AddOutput(preview);
774 EXPECT_TRUE(ret != 0);
775 }
776
777 /*
778 * Feature: Framework
779 * Function: Test capture session commit config without adding input
780 * SubFunction: NA
781 * FunctionPoints: NA
782 * EnvConditions: NA
783 * CaseDescription: Test capture session commit config without adding input
784 */
785 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_027, TestSize.Level0)
786 {
787 sptr<CaptureSession> session = cameraManager->CreateCaptureSession();
788 ASSERT_NE(session, nullptr);
789
790 int32_t ret = session->BeginConfig();
791 EXPECT_TRUE(ret == 0);
792
793 sptr<CaptureOutput> preview = CreatePreviewOutput();
794 ASSERT_NE(preview, nullptr);
795
796 ret = session->AddOutput(preview);
797 EXPECT_TRUE(ret == 0);
798
799 ret = session->CommitConfig();
800 EXPECT_TRUE(ret != 0);
801 }
802
803 /*
804 * Feature: Framework
805 * Function: Test capture session commit config without adding output
806 * SubFunction: NA
807 * FunctionPoints: NA
808 * EnvConditions: NA
809 * CaseDescription: Test capture session commit config without adding output
810 */
811 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_028, TestSize.Level0)
812 {
813 InSequence s;
814 EXPECT_CALL(*mockCameraHostManager, GetCameras(_));
815 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
816 std::vector<sptr<CameraInfo>> cameras = cameraManager->GetCameras();
817
818 sptr<CaptureInput> input = cameraManager->CreateCameraInput(cameras[0]);
819 ASSERT_NE(input, nullptr);
820
821 sptr<CaptureSession> session = cameraManager->CreateCaptureSession();
822 ASSERT_NE(session, nullptr);
823
824 int32_t ret = session->BeginConfig();
825 EXPECT_TRUE(ret == 0);
826
827 ret = session->AddInput(input);
828 EXPECT_TRUE(ret == 0);
829
830 ret = session->CommitConfig();
831 EXPECT_TRUE(ret != 0);
832 }
833
834 /*
835 * Feature: Framework
836 * Function: Test capture session without begin config
837 * SubFunction: NA
838 * FunctionPoints: NA
839 * EnvConditions: NA
840 * CaseDescription: Test capture session without begin config
841 */
842 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_029, TestSize.Level0)
843 {
844 InSequence s;
845 EXPECT_CALL(*mockCameraHostManager, GetCameras(_));
846 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
847 std::vector<sptr<CameraInfo>> cameras = cameraManager->GetCameras();
848
849 sptr<CaptureInput> input = cameraManager->CreateCameraInput(cameras[0]);
850 ASSERT_NE(input, nullptr);
851
852 sptr<CaptureOutput> photo = CreatePhotoOutput();
853 ASSERT_NE(photo, nullptr);
854
855 sptr<CaptureOutput> preview = CreatePreviewOutput();
856 ASSERT_NE(preview, nullptr);
857
858 sptr<CaptureSession> session = cameraManager->CreateCaptureSession();
859 ASSERT_NE(session, nullptr);
860
861 int32_t ret = session->AddInput(input);
862 EXPECT_TRUE(ret != 0);
863
864 ret = session->AddOutput(preview);
865 EXPECT_TRUE(ret != 0);
866
867 ret = session->AddOutput(photo);
868 EXPECT_TRUE(ret != 0);
869
870 ret = session->CommitConfig();
871 EXPECT_TRUE(ret != 0);
872
873 ret = session->Start();
874 EXPECT_TRUE(ret != 0);
875
876 ret = ((sptr<PhotoOutput> &)photo)->Capture();
877 EXPECT_TRUE(ret != 0);
878
879 ret = session->Stop();
880 EXPECT_TRUE(ret != 0);
881 }
882
883 /*
884 * Feature: Framework
885 * Function: Test capture session start and stop without adding preview output
886 * SubFunction: NA
887 * FunctionPoints: NA
888 * EnvConditions: NA
889 * CaseDescription: Test capture session start and stop without adding preview output
890 */
891 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_030, TestSize.Level0)
892 {
893 InSequence s;
894 EXPECT_CALL(*mockCameraHostManager, GetCameras(_));
895 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
896 std::vector<sptr<CameraInfo>> cameras = cameraManager->GetCameras();
897
898 sptr<CaptureInput> input = cameraManager->CreateCameraInput(cameras[0]);
899 ASSERT_NE(input, nullptr);
900
901 sptr<CaptureOutput> photo = CreatePhotoOutput();
902 ASSERT_NE(photo, nullptr);
903
904 sptr<CaptureSession> session = cameraManager->CreateCaptureSession();
905 ASSERT_NE(session, nullptr);
906
907 int32_t ret = session->BeginConfig();
908 EXPECT_TRUE(ret == 0);
909
910 ret = session->AddInput(input);
911 EXPECT_TRUE(ret == 0);
912
913 ret = session->AddOutput(photo);
914 EXPECT_TRUE(ret == 0);
915
916 EXPECT_CALL(*mockCameraHostManager, OpenCameraDevice(_, _, _));
917 EXPECT_CALL(*mockCameraDevice, SetResultMode(Camera::ON_CHANGED));
918 EXPECT_CALL(*mockCameraDevice, GetStreamOperator(_, _));
919 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
920 #ifndef BALTIMORE_CAMERA
921 EXPECT_CALL(*mockStreamOperator, IsStreamsSupported(_, _,
922 A<const std::vector<std::shared_ptr<Camera::StreamInfo>> &>(), _));
923 #endif
924 EXPECT_CALL(*mockStreamOperator, CreateStreams(_));
925 EXPECT_CALL(*mockStreamOperator, CommitStreams(_, _));
926 ret = session->CommitConfig();
927 EXPECT_TRUE(ret == 0);
928
929 EXPECT_CALL(*mockStreamOperator, Capture(PREVIEW_CAPTURE_ID_START, _, true)).Times(0);
930 ret = session->Start();
931 EXPECT_TRUE(ret != 0);
932
933 EXPECT_CALL(*mockStreamOperator, CancelCapture(PREVIEW_CAPTURE_ID_START)).Times(0);
934 ret = session->Stop();
935 EXPECT_TRUE(ret != 0);
936
937 EXPECT_CALL(*mockStreamOperator, ReleaseStreams(_));
938 EXPECT_CALL(*mockCameraDevice, Close());
939 session->Release();
940 }
941
942 /*
943 * Feature: Framework
944 * Function: Test session with preview + photo
945 * SubFunction: NA
946 * FunctionPoints: NA
947 * EnvConditions: NA
948 * CaseDescription: Test session with preview + photo
949 */
950 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_031, TestSize.Level0)
951 {
952 InSequence s;
953 EXPECT_CALL(*mockCameraHostManager, GetCameras(_));
954 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
955 std::vector<sptr<CameraInfo>> cameras = cameraManager->GetCameras();
956
957 sptr<CaptureInput> input = cameraManager->CreateCameraInput(cameras[0]);
958 ASSERT_NE(input, nullptr);
959
960 sptr<CaptureOutput> preview = CreatePreviewOutput();
961 ASSERT_NE(preview, nullptr);
962
963 sptr<CaptureOutput> photo = CreatePhotoOutput();
964 ASSERT_NE(photo, nullptr);
965
966 sptr<CaptureSession> session = cameraManager->CreateCaptureSession();
967 ASSERT_NE(session, nullptr);
968
969 int32_t ret = session->BeginConfig();
970 EXPECT_TRUE(ret == 0);
971
972 ret = session->AddInput(input);
973 EXPECT_TRUE(ret == 0);
974
975 ret = session->AddOutput(preview);
976 EXPECT_TRUE(ret == 0);
977
978 ret = session->AddOutput(photo);
979 EXPECT_TRUE(ret == 0);
980
981 EXPECT_CALL(*mockCameraHostManager, OpenCameraDevice(_, _, _));
982 EXPECT_CALL(*mockCameraDevice, SetResultMode(Camera::ON_CHANGED));
983 EXPECT_CALL(*mockCameraDevice, GetStreamOperator(_, _));
984 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
985 #ifndef BALTIMORE_CAMERA
986 EXPECT_CALL(*mockStreamOperator, IsStreamsSupported(_, _,
987 A<const std::vector<std::shared_ptr<Camera::StreamInfo>> &>(), _));
988 #endif
989 EXPECT_CALL(*mockStreamOperator, CreateStreams(_));
990 EXPECT_CALL(*mockStreamOperator, CommitStreams(_, _));
991 ret = session->CommitConfig();
992 EXPECT_TRUE(ret == 0);
993
994 EXPECT_CALL(*mockStreamOperator, Capture(PREVIEW_CAPTURE_ID_START, _, true));
995 ret = session->Start();
996 EXPECT_TRUE(ret == 0);
997
998 EXPECT_CALL(*mockStreamOperator, Capture(PHOTO_CAPTURE_ID_START, _, false));
999 ret = ((sptr<PhotoOutput> &)photo)->Capture();
1000 EXPECT_TRUE(ret == 0);
1001
1002 EXPECT_CALL(*mockStreamOperator, CancelCapture(PREVIEW_CAPTURE_ID_START));
1003 ret = session->Stop();
1004 EXPECT_TRUE(ret == 0);
1005
1006 EXPECT_CALL(*mockStreamOperator, ReleaseStreams(_));
1007 EXPECT_CALL(*mockCameraDevice, Close());
1008 session->Release();
1009 }
1010
1011 /*
1012 * Feature: Framework
1013 * Function: Test session with preview + photo with camera configuration
1014 * SubFunction: NA
1015 * FunctionPoints: NA
1016 * EnvConditions: NA
1017 * CaseDescription: Test session with preview + photo with camera configuration
1018 */
1019 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_032, TestSize.Level0)
1020 {
1021 InSequence s;
1022 EXPECT_CALL(*mockCameraHostManager, GetCameras(_));
1023 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
1024 std::vector<sptr<CameraInfo>> cameras = cameraManager->GetCameras();
1025
1026 sptr<CaptureInput> input = cameraManager->CreateCameraInput(cameras[0]);
1027 ASSERT_NE(input, nullptr);
1028
1029 sptr<CameraInput> camInput = (sptr<CameraInput> &)input;
1030
1031 std::vector<float> zoomRatioRange = camInput->GetSupportedZoomRatioRange();
1032 if (!zoomRatioRange.empty()) {
1033 camInput->LockForControl();
1034 camInput->SetZoomRatio(zoomRatioRange[0]);
1035 camInput->UnlockForControl();
1036 }
1037
1038 sptr<CaptureOutput> preview = CreatePreviewOutput();
1039 ASSERT_NE(preview, nullptr);
1040
1041 sptr<CaptureOutput> photo = CreatePhotoOutput();
1042 ASSERT_NE(photo, nullptr);
1043
1044 sptr<CaptureSession> session = cameraManager->CreateCaptureSession();
1045 ASSERT_NE(session, nullptr);
1046
1047 int32_t ret = session->BeginConfig();
1048 EXPECT_TRUE(ret == 0);
1049
1050 ret = session->AddInput(input);
1051 EXPECT_TRUE(ret == 0);
1052
1053 ret = session->AddOutput(preview);
1054 EXPECT_TRUE(ret == 0);
1055
1056 ret = session->AddOutput(photo);
1057 EXPECT_TRUE(ret == 0);
1058
1059 EXPECT_CALL(*mockCameraHostManager, OpenCameraDevice(_, _, _));
1060 if (!zoomRatioRange.empty()) {
1061 EXPECT_CALL(*mockCameraDevice, UpdateSettings(_));
1062 }
1063 EXPECT_CALL(*mockCameraDevice, SetResultMode(Camera::ON_CHANGED));
1064 EXPECT_CALL(*mockCameraDevice, GetStreamOperator(_, _));
1065 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
1066 #ifndef BALTIMORE_CAMERA
1067 EXPECT_CALL(*mockStreamOperator, IsStreamsSupported(_, _,
1068 A<const std::vector<std::shared_ptr<Camera::StreamInfo>> &>(), _));
1069 #endif
1070 EXPECT_CALL(*mockStreamOperator, CreateStreams(_));
1071 EXPECT_CALL(*mockStreamOperator, CommitStreams(_, _));
1072 ret = session->CommitConfig();
1073 EXPECT_TRUE(ret == 0);
1074
1075 EXPECT_CALL(*mockStreamOperator, ReleaseStreams(_));
1076 EXPECT_CALL(*mockCameraDevice, Close());
1077 session->Release();
1078 }
1079
1080 /*
1081 * Feature: Framework
1082 * Function: Test session with preview + video
1083 * SubFunction: NA
1084 * FunctionPoints: NA
1085 * EnvConditions: NA
1086 * CaseDescription: Test session with preview + video
1087 */
1088 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_033, TestSize.Level0)
1089 {
1090 InSequence s;
1091 EXPECT_CALL(*mockCameraHostManager, GetCameras(_));
1092 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
1093 std::vector<sptr<CameraInfo>> cameras = cameraManager->GetCameras();
1094
1095 sptr<CaptureInput> input = cameraManager->CreateCameraInput(cameras[0]);
1096 ASSERT_NE(input, nullptr);
1097
1098 sptr<CaptureOutput> preview = CreatePreviewOutput();
1099 ASSERT_NE(preview, nullptr);
1100
1101 sptr<CaptureOutput> video = CreateVideoOutput();
1102 ASSERT_NE(video, nullptr);
1103
1104 sptr<CaptureSession> session = cameraManager->CreateCaptureSession();
1105 ASSERT_NE(session, nullptr);
1106
1107 int32_t ret = session->BeginConfig();
1108 EXPECT_TRUE(ret == 0);
1109
1110 ret = session->AddInput(input);
1111 EXPECT_TRUE(ret == 0);
1112
1113 ret = session->AddOutput(preview);
1114 EXPECT_TRUE(ret == 0);
1115
1116 ret = session->AddOutput(video);
1117 EXPECT_TRUE(ret == 0);
1118
1119 EXPECT_CALL(*mockCameraHostManager, OpenCameraDevice(_, _, _));
1120 EXPECT_CALL(*mockCameraDevice, SetResultMode(Camera::ON_CHANGED));
1121 EXPECT_CALL(*mockCameraDevice, GetStreamOperator(_, _));
1122 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
1123 #ifndef BALTIMORE_CAMERA
1124 EXPECT_CALL(*mockStreamOperator, IsStreamsSupported(_, _,
1125 A<const std::vector<std::shared_ptr<Camera::StreamInfo>> &>(), _));
1126 #endif
1127 EXPECT_CALL(*mockStreamOperator, CreateStreams(_));
1128 EXPECT_CALL(*mockStreamOperator, CommitStreams(_, _));
1129 ret = session->CommitConfig();
1130 EXPECT_TRUE(ret == 0);
1131
1132 EXPECT_CALL(*mockStreamOperator, Capture(PREVIEW_CAPTURE_ID_START, _, true));
1133 ret = session->Start();
1134 EXPECT_TRUE(ret == 0);
1135
1136 EXPECT_CALL(*mockStreamOperator, Capture(VIDEO_CAPTURE_ID_START, _, true));
1137 ret = ((sptr<VideoOutput> &)video)->Start();
1138 EXPECT_TRUE(ret == 0);
1139
1140 EXPECT_CALL(*mockStreamOperator, CancelCapture(VIDEO_CAPTURE_ID_START));
1141 ret = ((sptr<VideoOutput> &)video)->Stop();
1142 EXPECT_TRUE(ret == 0);
1143
1144 EXPECT_CALL(*mockStreamOperator, CancelCapture(PREVIEW_CAPTURE_ID_START));
1145 ret = session->Stop();
1146 EXPECT_TRUE(ret == 0);
1147
1148 EXPECT_CALL(*mockStreamOperator, ReleaseStreams(_));
1149 EXPECT_CALL(*mockCameraDevice, Close());
1150 session->Release();
1151 }
1152
1153 /*
1154 * Feature: Framework
1155 * Function: Test capture session remove output with null
1156 * SubFunction: NA
1157 * FunctionPoints: NA
1158 * EnvConditions: NA
1159 * CaseDescription: Test capture session remove output with null
1160 */
1161 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_034, TestSize.Level0)
1162 {
1163 sptr<CaptureSession> session = cameraManager->CreateCaptureSession();
1164 ASSERT_NE(session, nullptr);
1165
1166 int32_t ret = session->BeginConfig();
1167 EXPECT_TRUE(ret == 0);
1168
1169 sptr<CaptureOutput> output = nullptr;
1170 ret = session->RemoveOutput(output);
1171 EXPECT_TRUE(ret != 0);
1172 }
1173
1174 /*
1175 * Feature: Framework
1176 * Function: Test capture session remove output
1177 * SubFunction: NA
1178 * FunctionPoints: NA
1179 * EnvConditions: NA
1180 * CaseDescription: Test capture session remove output
1181 */
1182 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_035, TestSize.Level0)
1183 {
1184 sptr<CaptureSession> session = cameraManager->CreateCaptureSession();
1185 ASSERT_NE(session, nullptr);
1186
1187 sptr<CaptureOutput> video = CreateVideoOutput();
1188 ASSERT_NE(video, nullptr);
1189
1190 int32_t ret = session->BeginConfig();
1191 EXPECT_TRUE(ret == 0);
1192
1193 ret = session->AddOutput(video);
1194 EXPECT_TRUE(ret == 0);
1195
1196 ret = session->RemoveOutput(video);
1197 EXPECT_TRUE(ret == 0);
1198 }
1199
1200 /*
1201 * Feature: Framework
1202 * Function: Test capture session remove input with null
1203 * SubFunction: NA
1204 * FunctionPoints: NA
1205 * EnvConditions: NA
1206 * CaseDescription: Test capture session remove input with null
1207 */
1208 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_036, TestSize.Level0)
1209 {
1210 sptr<CaptureSession> session = cameraManager->CreateCaptureSession();
1211 ASSERT_NE(session, nullptr);
1212
1213 int32_t ret = session->BeginConfig();
1214 EXPECT_TRUE(ret == 0);
1215
1216 sptr<CaptureInput> input = nullptr;
1217 ret = session->RemoveInput(input);
1218 EXPECT_TRUE(ret != 0);
1219 }
1220
1221 /*
1222 * Feature: Framework
1223 * Function: Test capture session remove input
1224 * SubFunction: NA
1225 * FunctionPoints: NA
1226 * EnvConditions: NA
1227 * CaseDescription: Test capture session remove input
1228 */
1229 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_037, TestSize.Level0)
1230 {
1231 InSequence s;
1232 EXPECT_CALL(*mockCameraHostManager, GetCameras(_));
1233 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
1234 std::vector<sptr<CameraInfo>> cameras = cameraManager->GetCameras();
1235
1236 sptr<CaptureInput> input = cameraManager->CreateCameraInput(cameras[0]);
1237 ASSERT_NE(input, nullptr);
1238
1239 sptr<CaptureSession> session = cameraManager->CreateCaptureSession();
1240 ASSERT_NE(session, nullptr);
1241
1242 int32_t ret = session->BeginConfig();
1243 EXPECT_TRUE(ret == 0);
1244
1245 ret = session->AddInput(input);
1246 EXPECT_TRUE(ret == 0);
1247
1248 ret = session->RemoveInput(input);
1249 EXPECT_TRUE(ret == 0);
1250 }
1251
1252 /*
1253 * Feature: Framework
1254 * Function: Test photo capture with photo settings
1255 * SubFunction: NA
1256 * FunctionPoints: NA
1257 * EnvConditions: NA
1258 * CaseDescription: Test photo capture with photo settings
1259 */
1260 HWTEST_F(CameraFrameworkUnitTest, camera_framework_unittest_038, TestSize.Level0)
1261 {
1262 InSequence s;
1263 EXPECT_CALL(*mockCameraHostManager, GetCameras(_));
1264 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
1265 std::vector<sptr<CameraInfo>> cameras = cameraManager->GetCameras();
1266
1267 sptr<CaptureInput> input = cameraManager->CreateCameraInput(cameras[0]);
1268 ASSERT_NE(input, nullptr);
1269
1270 sptr<CaptureOutput> photo = CreatePhotoOutput();
1271 ASSERT_NE(photo, nullptr);
1272
1273 sptr<CaptureSession> session = cameraManager->CreateCaptureSession();
1274 ASSERT_NE(session, nullptr);
1275
1276 int32_t ret = session->BeginConfig();
1277 EXPECT_TRUE(ret == 0);
1278
1279 ret = session->AddInput(input);
1280 EXPECT_TRUE(ret == 0);
1281
1282 ret = session->AddOutput(photo);
1283 EXPECT_TRUE(ret == 0);
1284
1285 EXPECT_CALL(*mockCameraHostManager, OpenCameraDevice(_, _, _));
1286 EXPECT_CALL(*mockCameraDevice, SetResultMode(Camera::ON_CHANGED));
1287 EXPECT_CALL(*mockCameraDevice, GetStreamOperator(_, _));
1288 EXPECT_CALL(*mockCameraHostManager, GetCameraAbility(_, _));
1289 #ifndef BALTIMORE_CAMERA
1290 EXPECT_CALL(*mockStreamOperator, IsStreamsSupported(_, _,
1291 A<const std::vector<std::shared_ptr<Camera::StreamInfo>> &>(), _));
1292 #endif
1293 EXPECT_CALL(*mockStreamOperator, CreateStreams(_));
1294 EXPECT_CALL(*mockStreamOperator, CommitStreams(_, _));
1295 ret = session->CommitConfig();
1296 EXPECT_TRUE(ret == 0);
1297
1298 std::shared_ptr<PhotoCaptureSetting> photoSetting = std::make_shared<PhotoCaptureSetting>();
1299 photoSetting->SetRotation(PhotoCaptureSetting::Rotation_90);
1300 photoSetting->SetQuality(PhotoCaptureSetting::NORMAL_QUALITY);
1301 EXPECT_TRUE(photoSetting->GetRotation() == PhotoCaptureSetting::Rotation_90);
1302 EXPECT_TRUE(photoSetting->GetQuality() == PhotoCaptureSetting::NORMAL_QUALITY);
1303
1304 EXPECT_CALL(*mockStreamOperator, Capture(PHOTO_CAPTURE_ID_START,
1305 matchCaptureSetting(photoSetting->GetCaptureMetadataSetting()), false));
1306 ret = ((sptr<PhotoOutput> &)photo)->Capture(photoSetting);
1307 EXPECT_TRUE(ret == 0);
1308
1309 EXPECT_CALL(*mockStreamOperator, ReleaseStreams(_));
1310 EXPECT_CALL(*mockCameraDevice, Close());
1311 session->Release();
1312 }
1313 } // CameraStandard
1314 } // OHOS
1315