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 "pipeline_test.h"
17
18 using namespace OHOS;
19 using namespace std;
20 using namespace testing::ext;
21 using namespace OHOS::Camera;
22
SetUpTestCase(void)23 void PipelineTest::SetUpTestCase(void) {}
TearDownTestCase(void)24 void PipelineTest::TearDownTestCase(void) {}
SetUp(void)25 void PipelineTest::SetUp(void)
26 {
27 Test_ = std::make_shared<OHOS::Camera::Test>();
28 Test_->Init();
29 Test_->Open();
30 }
TearDown(void)31 void PipelineTest::TearDown(void)
32 {
33 Test_->Close();
34 }
35
36 /**
37 * @tc.name: Check ppl
38 * @tc.desc: preview success.
39 * @tc.size: MediumTest
40 * @tc.type: Function
41 */
42 HWTEST_F(PipelineTest, Camera_Ppl_0001, TestSize.Level0)
43 {
44 std::cout << "==========[test log]Check ppl: preview success." << std::endl;
45 // Start stream
46 Test_->intents = {Camera::PREVIEW};
47 Test_->StartStream(Test_->intents);
48 // Get preview
49 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
50 // Release stream
51 Test_->captureIds = {Test_->captureId_preview};
52 Test_->streamIds = {Test_->streamId_preview};
53 Test_->StopStream(Test_->captureIds, Test_->streamIds);
54 Test_->StopConsumer(Test_->intents);
55 }
56
57 /**
58 * @tc.name: Check ppl
59 * @tc.desc: preview + capture success.
60 * @tc.size: MediumTest
61 * @tc.type: Function
62 */
63 HWTEST_F(PipelineTest, Camera_Ppl_0002, TestSize.Level1)
64 {
65 std::cout << "==========[test log]Check ppl: preview + capture success." << std::endl;
66 // Configure two stream information
67 Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE};
68 Test_->StartStream(Test_->intents);
69 // Capture preview stream
70 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
71 // Capture camera stream, continuous capture
72 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
73 // Post-processing
74 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture};
75 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture};
76 Test_->StopStream(Test_->captureIds, Test_->streamIds);
77 }
78
79 /**
80 * @tc.name: Check ppl
81 * @tc.desc: preview + video success.
82 * @tc.size: MediumTest
83 * @tc.type: Function
84 */
85 HWTEST_F(PipelineTest, Camera_Ppl_0003, TestSize.Level1)
86 {
87 std::cout << "==========[test log]Check ppl:Check ppl: preview + video success." << std::endl;
88 // Configure two stream information
89 Test_->intents = {Camera::PREVIEW, Camera::VIDEO};
90 Test_->StartStream(Test_->intents);
91 // Capture preview stream
92 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
93 // Capture video stream
94 Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true);
95 // Post-processing
96 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video};
97 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video};
98 Test_->StopStream(Test_->captureIds, Test_->streamIds);
99 }
100
101 /**
102 * @tc.name: Check ppl
103 * @tc.desc: video mode without preview, system not support, expected return fail.
104 * @tc.size: MediumTest
105 * @tc.type: Function
106 */
107 HWTEST_F(PipelineTest, Camera_Ppl_0004, TestSize.Level2)
108 {
109 std::cout << "==========[test log]Check ppl:Video mode no preview, not support, expected fail." << std::endl;
110 EXPECT_EQ(true, Test_->cameraDevice != nullptr);
111 Test_->CreateStreamOperatorCallback();
112 Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator);
113 EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
114 if (Test_->rc == Camera::NO_ERROR) {
115 std::cout << "==========[test log]Check ppl: GetStreamOperator success." << std::endl;
116 } else {
117 std::cout << "==========[test log]Check ppl: GetStreamOperator fail, rc = " << Test_->rc << std::endl;
118 }
119 Test_->streamInfo = std::make_shared<Camera::StreamInfo>();
120 Test_->streamInfo->streamId_ = Test_->streamId_video;
121 Test_->streamInfo->width_ = 640;
122 Test_->streamInfo->height_ = 480;
123 Test_->StreamInfoFormat();
124 Test_->streamInfo->dataspace_ = 10;
125 Test_->streamInfo->intent_ = Camera::VIDEO;
126 Test_->streamInfo->tunneledMode_ = 5;
127 std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
128 std::make_shared<OHOS::Camera::Test::StreamConsumer>();
129 #ifdef CAMERA_BUILT_ON_OHOS_LITE
__anon58e12a830102(OHOS::SurfaceBuffer* buffer) 130 Test_->streamInfo->bufferQueue_ = consumer->CreateProducer([this](OHOS::SurfaceBuffer* buffer) {
131 Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize());
132 });
133 #else
__anon58e12a830202(void* addr, uint32_t size) 134 Test_->streamInfo->bufferQueue_ = consumer->CreateProducer([this](void* addr, uint32_t size) {
135 Test_->SaveYUV("preview", addr, size);
136 });
137 #endif
138 Test_->streamInfo->bufferQueue_->SetQueueSize(8);
139 Test_->consumerMap_[Camera::PREVIEW] = consumer;
140 std::vector<std::shared_ptr<Camera::StreamInfo>>().swap(Test_->streamInfos);
141 Test_->streamInfos.push_back(Test_->streamInfo);
142 Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos);
143 EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
144 std::cout << "==========[test log]CreateStreams rc = " << Test_->rc << std::endl;
145 Test_->rc = Test_->streamOperator->CommitStreams(Camera::NORMAL, Test_->ability);
146 EXPECT_EQ(Test_->rc, Camera::INVALID_ARGUMENT);
147 std::cout << "==========[test log]CommitStreams rc = " << Test_->rc << std::endl;
148 // Post-processing
149 Test_->streamIds = {Test_->streamId_video};
150 Test_->StopStream(Test_->captureIds, Test_->streamIds);
151 }
152
153 /**
154 * @tc.name: Only Still_capture stream
155 * @tc.desc: Only Still_capture stream, capture->isStreaming = false.
156 * @tc.size: MediumTest
157 * @tc.type: Function
158 */
159 HWTEST_F(PipelineTest, Camera_Ppl_0005, TestSize.Level1)
160 {
161 std::cout << "==========[test log]check ppl: Still_capture stream, capture->isStreaming = false." << std::endl;
162 // Start stream
163 Test_->intents = {Camera::STILL_CAPTURE};
164 Test_->StartStream(Test_->intents);
165 // Start capture
166 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, false);
167 // Post-processing
168 Test_->streamIds = {Test_->streamId_capture};
169 Test_->StopStream(Test_->captureIds, Test_->streamIds);
170 }
171
172 /**
173 * @tc.name: Only Still_capture stream
174 * @tc.desc: Only Still_capture stream, capture->isStreaming = true.
175 * @tc.size: MediumTest
176 * @tc.type: Function
177 */
178 HWTEST_F(PipelineTest, Camera_Ppl_0006, TestSize.Level1)
179 {
180 std::cout << "==========[test log]check ppl: Still_capture stream, capture->isStreaming = true." << std::endl;
181 // Start stream
182 Test_->intents = {Camera::STILL_CAPTURE};
183 Test_->StartStream(Test_->intents);
184 // Start capture
185 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true);
186 // Post-processing
187 Test_->captureIds = {Test_->captureId_capture};
188 Test_->streamIds = {Test_->streamId_capture};
189 Test_->StopStream(Test_->captureIds, Test_->streamIds);
190 }
191
192 #ifndef CAMERA_BUILT_ON_OHOS_LITE
193 /**
194 * @tc.name: Check ppl
195 * @tc.desc: double preview streams.
196 * @tc.size: MediumTest
197 * @tc.type: Function
198 */
199 HWTEST_F(PipelineTest, Camera_Ppl_0007, TestSize.Level1)
200 {
201 std::cout << "==========[test log]Check ppl: double preview streams." << std::endl;
202 // Create and get streamOperator information
203 Test_->streamOperatorCallback = new StreamOperatorCallback();
204 Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator);
205 EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
206 // Create data stream 1
207 Test_->streamInfo = std::make_shared<StreamInfo>();
208 Test_->streamInfo->streamId_ = Test_->streamId_preview;
209 Test_->streamInfo->width_ = 1280;
210 Test_->streamInfo->height_ = 960;
211 Test_->streamInfo->dataspace_ = 8;
212 Test_->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
213 Test_->streamInfo->intent_ = Camera::PREVIEW;
214 std::shared_ptr<OHOS::Camera::Test::StreamConsumer> preview_consumer =
215 std::make_shared<OHOS::Camera::Test::StreamConsumer>();
__anon58e12a830302(void* addr, uint32_t size) 216 Test_->streamInfo->bufferQueue_ = preview_consumer->CreateProducer([this](void* addr, uint32_t size) {
217 Test_->SaveYUV("preview", addr, size);
218 });
219 Test_->streamInfo->bufferQueue_->SetQueueSize(8);
220 Test_->consumerMap_[Camera::PREVIEW] = preview_consumer;
221 Test_->streamInfo->tunneledMode_ = 5;
222 std::vector<std::shared_ptr<StreamInfo>>().swap(Test_->streamInfos);
223 Test_->streamInfos.push_back(Test_->streamInfo);
224
225 // Create data stream 2
226 Test_->streamInfo2 = std::make_shared<StreamInfo>();
227 Test_->streamInfo2->streamId_ = Test_->streamId_preview_double;
228 Test_->streamInfo2->width_ = 1280;
229 Test_->streamInfo2->height_ = 960;
230 Test_->streamInfo2->dataspace_ = 8;
231 Test_->streamInfo2->format_ = PIXEL_FMT_YCRCB_420_SP;
232 Test_->streamInfo2->intent_ = Camera::PREVIEW;
233 std::shared_ptr<OHOS::Camera::Test::StreamConsumer> preview_consumer2 =
234 std::make_shared<OHOS::Camera::Test::StreamConsumer>();
__anon58e12a830402(void* addr, uint32_t size) 235 Test_->streamInfo2->bufferQueue_ = preview_consumer2->CreateProducer([this](void* addr, uint32_t size) {
236 Test_->SaveYUV("preview2", addr, size);
237 });
238 Test_->streamInfo2->bufferQueue_->SetQueueSize(8);
239 Test_->consumerMap_[Camera::PREVIEW] = preview_consumer2;
240 Test_->streamInfo2->tunneledMode_ = 5;
241 Test_->streamInfos.push_back(Test_->streamInfo2);
242
243 Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos);
244 EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
245 // Flow distribution
246 Test_->rc = Test_->streamOperator->CommitStreams(Camera::NORMAL, Test_->ability);
247 EXPECT_EQ(Test_->rc, Camera::NO_ERROR);
248 // Get preview
249 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true);
250 Test_->StartCapture(Test_->streamId_preview_double, Test_->captureId_preview_double, false, true);
251 // Release stream
252 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_preview_double};
253 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_preview_double};
254 Test_->StopStream(Test_->captureIds, Test_->streamIds);
255 }
256 #endif