• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #include "logic_camera_test.h"
17 
SetUpTestCase(void)18 void UtestLogicCameraTest::SetUpTestCase(void)
19 {}
TearDownTestCase(void)20 void UtestLogicCameraTest::TearDownTestCase(void)
21 {}
SetUp(void)22 void UtestLogicCameraTest::SetUp(void)
23 {
24     if (display_ == nullptr)
25     display_ = std::make_shared<TestDisplay>();
26     display_->FBInit();
27     display_->Init();
28 }
TearDown(void)29 void UtestLogicCameraTest::TearDown(void)
30 {
31     display_->Close();
32 }
33 
34 /**
35   * @tc.name: test logic csamera
36   * @tc.desc: single stream
37   * @tc.level: Level0
38   * @tc.size: MediumTest
39   * @tc.type: Function
40   */
TEST_F(UtestLogicCameraTest,camera_logic_0001)41 TEST_F(UtestLogicCameraTest, camera_logic_0001)
42 {
43     std::cout << "==========[test log] test single stream"<< std::endl;
44     // 获取流管理器
45     display_->AchieveStreamOperator();
46     // 配置预览流信息
47     std::shared_ptr<IBufferProducer> producer = IBufferProducer::CreateBufferQueue();
48     producer->SetQueueSize(8);
49     if (producer->GetQueueSize() != 8) {
50         std::cout << "~~~~~~~" << std::endl;
51     }
52     auto callback = [this](std::shared_ptr<SurfaceBuffer> b) {
53         display_->BufferCallback(b, display_->preview_mode);
54         return;
55     };
56     producer->SetCallback(callback);
57     std::shared_ptr<OHOS::Camera::StreamInfo> streamInfoPre = std::make_shared<OHOS::Camera::StreamInfo>();
58     streamInfoPre->streamId_ = display_->streamId_preview;
59     streamInfoPre->width_ = 640;
60     streamInfoPre->height_ = 480;
61     streamInfoPre->format_ = CAMERA_FORMAT_YUYV_422_PKG;
62     streamInfoPre->datasapce_ = 8;
63     streamInfoPre->intent_ = Camera::PREVIEW;
64     streamInfoPre->tunneledMode_ = 5;
65     streamInfoPre->bufferQueue_ = producer;
66     display_->streamInfos.push_back(streamInfoPre);
67     display_->rc = display_->streamOperator->CreateStreams(display_->streamInfos);
68     EXPECT_EQ(true, display_->rc == Camera::NO_ERROR);
69     if (display_->rc == Camera::NO_ERROR) {
70         std::cout << "==========[test log] CreateStreams success, streamId = ";
71         std::cout << display_->streamId_capture <<", intent = Camera::STILL_CAPTURE" << std::endl;
72     } else {
73         std::cout << "==========[test log] CreateStreams fail, rc = " << display_->rc <<" , streamId = ";
74         std::cout << display_->streamId_capture <<", intent = Camera::STILL_CAPTURE" << std::endl;
75     }
76     // 提交流信息
77     display_->rc = display_->streamOperator->CommitStreams(DUAL, nullptr);
78     EXPECT_EQ(false, display_->rc != Camera::NO_ERROR);
79     if (display_->rc == Camera::NO_ERROR) {
80         std::cout << "==========[test log] CommitStreams DUAL success." << std::endl;
81     } else {
82         std::cout << "==========[test log] CommitStreams DUAL fail, rc = " << display_->rc << std::endl;
83     }
84     // 捕获
85     display_->StartCapture(display_->streamId_preview, display_->captureId_preview, false, true);
86     // 后处理
87     display_->captureIds = {display_->captureId_preview};
88     display_->streamIds = {display_->streamId_preview};
89     display_->StopStream(display_->captureIds, display_->streamIds);
90 }