1 /*
2 * Copyright (c) 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 #include "camera_preview_test.h"
16
17 using namespace testing::ext;
18
SetUpTestCase(void)19 void CameraPreviewTest::SetUpTestCase(void)
20 {
21 }
22
TearDownTestCase(void)23 void CameraPreviewTest::TearDownTestCase(void)
24 {
25 }
26
SetUp(void)27 void CameraPreviewTest::SetUp(void)
28 {
29 if (display_ == nullptr)
30 display_ = std::make_shared<TestDisplay>();
31 display_->Init();
32 }
33
TearDown(void)34 void CameraPreviewTest::TearDown(void)
35 {
36 display_->Close();
37 }
38
39 /**
40 * @tc.name: Preview
41 * @tc.desc: Preview stream, expected success.
42 * @tc.level: Level1
43 * @tc.size: MediumTest
44 * @tc.type: Function
45 */
46 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_0030, TestSize.Level1)
47 {
48 std::cout << "==========[test log] Preview stream, expected success." << std::endl;
49 // Get the stream manager
50 display_->AchieveStreamOperator();
51 // start stream
52 display_->intents = {PREVIEW};
53 display_->StartStream(display_->intents);
54 // Get preview
55 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
56 // release stream
57 display_->captureIds = {display_->CAPTURE_ID_PREVIEW};
58 display_->streamIds = {display_->STREAM_ID_PREVIEW};
59 display_->StopStream(display_->captureIds, display_->streamIds);
60 }
61
62 /**
63 * @tc.name: Preview
64 * @tc.desc: Preview, format error, expected return errorCode.
65 * @tc.level: Level2
66 * @tc.size: MediumTest
67 * @tc.type: Function
68 */
69 HWTEST_F(CameraPreviewTest, camera_preview_003, TestSize.Level2)
70 {
71 std::cout << "==========[test log] Preview, format error, expected return errorCode." << std::endl;
72 // Create and get streamOperator information
73 display_->AchieveStreamOperator();
74 // Create data stream
75 if (display_->streamCustomerPreview_ == nullptr) {
76 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
77 }
78 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
79 producer->SetQueueSize(8); // 8:set bufferQueue size
80 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
81 std::cout << "~~~~~~~" << std::endl;
82 }
83 std::vector<StreamInfo> streamInfos;
84 StreamInfo streamInfo = {};
85 streamInfo.streamId_ = 1001;
86 streamInfo.width_ = 640; // 640:picture width
87 streamInfo.height_ = 480; // 480:picture height
88 streamInfo.format_ = -1;
89 streamInfo.dataspace_ = 10; // 10:picture dataspace
90 streamInfo.intent_ = PREVIEW;
91 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
92 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
93 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
94 streamInfos.push_back(streamInfo);
95 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
96 EXPECT_EQ(true, display_->rc != HDI::Camera::V1_0::NO_ERROR);
97 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
98 std::cout << "==========[test log] CreateStreams success." << std::endl;
99 } else {
100 std::cout << "==========[test log] CreateStreams fail, rc = " << display_->rc << std::endl;
101 }
102 }
103
104 /**
105 * @tc.name: Preview
106 * @tc.desc: GetStreamOperator success.
107 * @tc.level: Level1
108 * @tc.size: MediumTest
109 * @tc.type: Function
110 */
111 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_0050, TestSize.Level1)
112 {
113 std::cout << "==========[test log] GetStreamOperator success." << std::endl;
114 // Get the configured cameraId
115 display_->cameraHost->GetCameraIds(display_->cameraIds);
116 std::cout << "cameraIds.front() = " << display_->cameraIds.front() << std::endl;
117 // Open the camera device and get the device
118 const OHOS::sptr<ICameraDeviceCallback> callback = new DemoCameraDeviceCallback();
119 display_->rc = (CamRetCode)display_->cameraHost->OpenCamera(display_->cameraIds.front(),
120 callback, display_->cameraDevice);
121 std::cout << "OpenCamera's RetCode = " << display_->rc << std::endl;
122 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
123 display_->AchieveStreamOperator();
124 }
125
126 /**
127 * @tc.name: Preview
128 * @tc.desc: GetStreamOperator, input nullptr.
129 * @tc.level: Level2
130 * @tc.size: MediumTest
131 * @tc.type: Function
132 */
133 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_0060, TestSize.Level2)
134 {
135 std::cout << "==========[test log] GetStreamOperator, input nullptr." << std::endl;
136 // Get the configured cameraId
137 display_->cameraHost->GetCameraIds(display_->cameraIds);
138 std::cout << "cameraIds.front() = " << display_->cameraIds.front() << std::endl;
139 // Open the camera device and get the device
140 const OHOS::sptr<ICameraDeviceCallback> callback = new DemoCameraDeviceCallback();
141 display_->rc = (CamRetCode)display_->cameraHost->OpenCamera(display_->cameraIds.front(),
142 callback, display_->cameraDevice);
143 std::cout << "OpenCamera's RetCode = " << display_->rc << std::endl;
144 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
145 // Create and get streamOperator information
146 OHOS::sptr<IStreamOperatorCallback> streamOperatorCallback = nullptr;
147 display_->rc = (CamRetCode)display_->cameraDevice->GetStreamOperator(streamOperatorCallback,
148 display_->streamOperator);
149 std::cout << "GetStreamOperator's RetCode = " << display_->rc << std::endl;
150 EXPECT_EQ(CamRetCode::INVALID_ARGUMENT, display_->rc);
151 }
152
153 /**
154 * @tc.name: Preview
155 * @tc.desc: GetStreamOperator, input normal.
156 * @tc.level: Level2
157 * @tc.size: MediumTest
158 * @tc.type: Function
159 */
160 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1000, TestSize.Level2)
161 {
162 std::cout << "==========[test log] GetStreamOperator, input nullptr." << std::endl;
163 // Get the configured cameraId
164 display_->cameraHost->GetCameraIds(display_->cameraIds);
165 std::cout << "cameraIds.front() = " << display_->cameraIds.front() << std::endl;
166 // Open the camera device and get the device
167 const OHOS::sptr<ICameraDeviceCallback> callback = new DemoCameraDeviceCallback();
168 display_->rc = (CamRetCode)display_->cameraHost->OpenCamera(display_->cameraIds.front(),
169 callback, display_->cameraDevice);
170 std::cout << "OpenCamera's RetCode = " << display_->rc << std::endl;
171 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
172 // Create and get streamOperator information
173 OHOS::sptr<IStreamOperatorCallback> streamOperatorCallback = new DemoStreamOperatorCallback();
174 display_->rc = (CamRetCode)display_->cameraDevice->GetStreamOperator(streamOperatorCallback,
175 display_->streamOperator);
176 std::cout << "GetStreamOperator's RetCode = " << display_->rc << std::endl;
177 EXPECT_EQ(HDI::Camera::V1_0::NO_ERROR, display_->rc);
178 }
179
180 /**
181 * @tc.name: Preview
182 * @tc.desc: CreateStreams, success.
183 * @tc.level: Level1
184 * @tc.size: MediumTest
185 * @tc.type: Function
186 */
187 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1010, TestSize.Level1)
188 {
189 std::cout << "==========[test log] CreateStreams, success." << std::endl;
190 // Create and get streamOperator information
191 display_->AchieveStreamOperator();
192 // Create data stream
193 if (display_->streamCustomerPreview_ == nullptr) {
194 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
195 }
196 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
197 producer->SetQueueSize(8); // 8:set bufferQueue size
198 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
199 std::cout << "~~~~~~~" << std::endl;
200 }
201
202 std::vector<StreamInfo> streamInfos;
203 StreamInfo streamInfo = {};
204 streamInfo.streamId_ = 1001;
205 streamInfo.width_ = 640; // 640:picture width
206 streamInfo.height_ = 480; // 480:picture height
207 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
208 streamInfo.dataspace_ = 8; // 8:picture dataspace
209 streamInfo.intent_ = PREVIEW;
210 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
211 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
212 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
213 std::vector<StreamInfo>().swap(streamInfos);
214 streamInfos.push_back(streamInfo);
215 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
216 std::cout << "CreateStreams's RetCode = " << display_->rc << std::endl;
217 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
218 std::cout << "==========[test log] CreateStreams, success." << std::endl;
219 // Submit stream information
220 display_->rc = (CamRetCode)display_->streamOperator->CommitStreams(NORMAL, display_->ability_);
221 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
222 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
223 std::cout << "==========[test log] CommitStreams success." << std::endl;
224 } else {
225 std::cout << "==========[test log] CommitStreams fail, rc = " << display_->rc << std::endl;
226 }
227 // capture
228 display_->StartCapture(1001, display_->CAPTURE_ID_PREVIEW, false, true);
229 // release stream
230 display_->captureIds = {display_->CAPTURE_ID_PREVIEW};
231 display_->streamIds = {1001};
232 display_->StopStream(display_->captureIds, display_->streamIds);
233 }
234
235 /**
236 * @tc.name: Preview
237 * @tc.desc: CreateStreams, StreamInfo->streamId = -1, return error.
238 * @tc.level: Level2
239 * @tc.size: MediumTest
240 * @tc.type: Function
241 */
242 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1020, TestSize.Level2)
243 {
244 std::cout << "==========[test log] CreateStreams, success." << std::endl;
245 // Create and get streamOperator information
246 display_->AchieveStreamOperator();
247 // Create data stream
248 if (display_->streamCustomerPreview_ == nullptr) {
249 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
250 }
251 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
252 producer->SetQueueSize(8); // 8:set bufferQueue size
253 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
254 std::cout << "~~~~~~~" << std::endl;
255 }
256 std::vector<StreamInfo> streamInfos;
257 StreamInfo streamInfo = {};
258 streamInfo.streamId_ = -1;
259 streamInfo.width_ = 640; // 640:picture width
260 streamInfo.height_ = 480; // 480:picture height
261 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
262 streamInfo.dataspace_ = 8; // 8:picture dataspace
263 streamInfo.intent_ = PREVIEW;
264 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
265 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
266 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
267 streamInfos.push_back(streamInfo);
268 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
269 std::cout << "CreateStreams's RetCode = " << display_->rc << std::endl;
270 EXPECT_EQ(false, display_->rc == HDI::Camera::V1_0::NO_ERROR);
271 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
272 std::cout << "==========[test log] CreateStreams success." << std::endl;
273 } else {
274 std::cout << "==========[test log] CreateStreams fail, rc = " << display_->rc << std::endl;
275 }
276 }
277
278 /**
279 * @tc.name: Preview
280 * @tc.desc: CreateStreams, StreamInfo->streamId = 2147483647, return success.
281 * @tc.level: Level2
282 * @tc.size: MediumTest
283 * @tc.type: Function
284 */
285 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1030, TestSize.Level2)
286 {
287 std::cout << "==========[test log] CreateStreams, StreamInfo->streamId = 2147483647,";
288 std::cout << "return success." << std::endl;
289 display_->AchieveStreamOperator();
290 // Create data stream
291 if (display_->streamCustomerPreview_ == nullptr) {
292 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
293 }
294 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
295 producer->SetQueueSize(8); // 8:set bufferQueue size
296 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
297 std::cout << "~~~~~~~" << std::endl;
298 }
299 std::vector<StreamInfo> streamInfos;
300 StreamInfo streamInfo = {};
301 streamInfo.streamId_ = 2147483647;
302 streamInfo.width_ = 640; // 640:picture width
303 streamInfo.height_ = 480; // 480:picture height
304 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
305 streamInfo.dataspace_ = 8; // 8:picture dataspace
306 streamInfo.intent_ = PREVIEW;
307 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
308 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
309 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
310 std::vector<StreamInfo>().swap(streamInfos);
311 streamInfos.push_back(streamInfo);
312 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
313 std::cout << "streamOperator->CreateStreams's RetCode = " << display_->rc << std::endl;
314 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
315 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
316 std::cout << "==========[test log] CreateStreams success." << std::endl;
317 } else {
318 std::cout << "==========[test log] CreateStreams fail, rc = " << display_->rc << std::endl;
319 }
320 // Submit stream information
321 display_->rc = (CamRetCode)display_->streamOperator->CommitStreams(NORMAL, display_->ability_);
322 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
323 std::cout << "==========[test log] CommitStreams success." << std::endl;
324 // capture
325 display_->StartCapture(2147483647, display_->CAPTURE_ID_PREVIEW, false, true);
326 // release stream
327 display_->captureIds = {display_->CAPTURE_ID_PREVIEW};
328 display_->streamIds = {2147483647};
329 display_->StopStream(display_->captureIds, display_->streamIds);
330 }
331
332 /**
333 * @tc.name: Preview
334 * @tc.desc: CreateStreams, StreamInfo->width = -1, return error.
335 * @tc.level: Level2
336 * @tc.size: MediumTest
337 * @tc.type: Function
338 */
339 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1040, TestSize.Level2)
340 {
341 std::cout << "==========[test log] CreateStreams, StreamInfo->width = -1, return error." << std::endl;
342 // Create and get streamOperator information
343 display_->AchieveStreamOperator();
344 // Create data stream
345 if (display_->streamCustomerPreview_ == nullptr) {
346 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
347 }
348 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
349 producer->SetQueueSize(8); // 8:set bufferQueue size
350 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
351 std::cout << "~~~~~~~" << std::endl;
352 }
353 std::vector<StreamInfo> streamInfos;
354 StreamInfo streamInfo = {};
355 streamInfo.streamId_ = 1001;
356 streamInfo.width_ = -1;
357 streamInfo.height_ = 480; // 480:picture height
358 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
359 streamInfo.dataspace_ = 8; // 8:picture dataspace
360 streamInfo.intent_ = PREVIEW;
361 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
362 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
363 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
364 std::vector<StreamInfo>().swap(streamInfos);
365 streamInfos.push_back(streamInfo);
366 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
367 std::cout << "streamOperator->CreateStreams's RetCode = " << display_->rc << std::endl;
368 EXPECT_EQ(true, display_->rc == INVALID_ARGUMENT);
369 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
370 std::cout << "==========[test log] CreateStreams success." << std::endl;
371 } else {
372 std::cout << "==========[test log] CreateStreams fail, rc = " << display_->rc << std::endl;
373 }
374 }
375
376 /**
377 * @tc.name: Preview
378 * @tc.desc: CreateStreams, StreamInfo->height = -1, return error.
379 * @tc.level: Level2
380 * @tc.size: MediumTest
381 * @tc.type: Function
382 */
383 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1060, TestSize.Level2)
384 {
385 std::cout << "==========[test log] CreateStreams, StreamInfo->height = -1, return error." << std::endl;
386 // Create and get streamOperator information
387 display_->AchieveStreamOperator();
388 // Create data stream
389 if (display_->streamCustomerPreview_ == nullptr) {
390 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
391 }
392 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
393 producer->SetQueueSize(8); // 8:set bufferQueue size
394 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
395 std::cout << "~~~~~~~" << std::endl;
396 }
397 std::vector<StreamInfo> streamInfos;
398 StreamInfo streamInfo = {};
399 streamInfo.streamId_ = 1001;
400 streamInfo.width_ = 640; // 640:picture width
401 streamInfo.height_ = -1;
402 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
403 streamInfo.dataspace_ = 8; // 8:picture dataspace
404 streamInfo.intent_ = PREVIEW;
405 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
406 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
407 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
408 std::vector<StreamInfo>().swap(streamInfos);
409 streamInfos.push_back(streamInfo);
410 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
411 std::cout << "streamOperator->CreateStreams's RetCode = " << display_->rc << std::endl;
412 EXPECT_EQ(CamRetCode::INVALID_ARGUMENT, display_->rc);
413 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
414 std::cout << "==========[test log] CreateStreams success." << std::endl;
415 } else {
416 std::cout << "==========[test log] CreateStreams fail, rc = " << display_->rc << std::endl;
417 }
418 }
419
420 /**
421 * @tc.name: Preview
422 * @tc.desc: CreateStreams, StreamInfo->format = -1, return error.
423 * @tc.level: Level2
424 * @tc.size: MediumTest
425 * @tc.type: Function
426 */
427 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1080, TestSize.Level2)
428 {
429 std::cout << "==========[test log] CreateStreams, StreamInfo->format = -1, return error." << std::endl;
430 display_->AchieveStreamOperator();
431 // Create data stream
432 if (display_->streamCustomerPreview_ == nullptr) {
433 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
434 }
435 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
436 producer->SetQueueSize(8); // 8:set bufferQueue size
437 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
438 std::cout << "~~~~~~~" << std::endl;
439 }
440 std::vector<StreamInfo> streamInfos;
441 StreamInfo streamInfo = {};
442 streamInfo.streamId_ = 1001;
443 streamInfo.width_ = 640; // 640:picture width
444 streamInfo.height_ = 480; // 480:picture height
445 streamInfo.format_ = -1;
446 streamInfo.dataspace_ = 8; // 8:picture dataspace
447 streamInfo.intent_ = PREVIEW;
448 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
449 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
450 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
451 std::vector<StreamInfo>().swap(streamInfos);
452 streamInfos.push_back(streamInfo);
453 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
454 std::cout << "streamOperator->CreateStreams's RetCode = " << display_->rc << std::endl;
455 EXPECT_EQ(CamRetCode::INVALID_ARGUMENT, display_->rc);
456 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
457 std::cout << "==========[test log] CreateStreams success." << std::endl;
458 } else {
459 std::cout << "==========[test log] CreateStreams fail, rc = " << display_->rc << std::endl;
460 }
461 }
462
463 /**
464 * @tc.name: Preview
465 * @tc.desc: CreateStreams, StreamInfo->dataspace = 2147483647, success.
466 * @tc.level: Level2
467 * @tc.size: MediumTest
468 * @tc.type: Function
469 */
470 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1110, TestSize.Level2)
471 {
472 std::cout << "==========[test log] CreateStreams, StreamInfo->dataspace = 2147483647, success." << std::endl;
473 // Create and get streamOperator information
474 display_->AchieveStreamOperator();
475 // Create data stream
476 if (display_->streamCustomerPreview_ == nullptr) {
477 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
478 }
479 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
480 producer->SetQueueSize(8); // 8:set bufferQueue size
481 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
482 std::cout << "~~~~~~~" << std::endl;
483 }
484 std::vector<StreamInfo> streamInfos;
485 StreamInfo streamInfo = {};
486 streamInfo.streamId_ = 1001;
487 streamInfo.width_ = 640; // 640:picture width
488 streamInfo.height_ = 480; // 480:picture height
489 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
490 streamInfo.dataspace_ = 2147483647;
491 streamInfo.intent_ = PREVIEW;
492 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
493 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
494 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
495 std::vector<StreamInfo>().swap(streamInfos);
496 streamInfos.push_back(streamInfo);
497 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
498 std::cout << "streamOperator->CreateStreams's RetCode = " << display_->rc << std::endl;
499 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
500 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
501 std::cout << "==========[test log] CreateStreams success." << std::endl;
502 } else {
503 std::cout << "==========[test log] CreateStreams fail, rc = " << display_->rc << std::endl;
504 }
505 // Submit stream information
506 display_->rc = (CamRetCode)display_->streamOperator->CommitStreams(NORMAL, display_->ability_);
507 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
508 std::cout << "==========[test log] CommitStreams success." << std::endl;
509 // capture
510 display_->StartCapture(1001, display_->CAPTURE_ID_PREVIEW, false, true);
511 // release stream
512 display_->captureIds = {display_->CAPTURE_ID_PREVIEW};
513 display_->streamIds = {1001};
514 display_->StopStream(display_->captureIds, display_->streamIds);
515 }
516
517 /**
518 * @tc.name: Preview
519 * @tc.desc: CreateStreams, StreamInfo->StreamIntent = PREVIEW, success.
520 * @tc.level: Level2
521 * @tc.size: MediumTest
522 * @tc.type: Function
523 */
524 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1120, TestSize.Level2)
525 {
526 std::cout << "==========[test log] CreateStreams, StreamInfo->StreamIntent = ";
527 std::cout << "PREVIEW, success." << std::endl;
528 // Get the stream manager
529 display_->AchieveStreamOperator();
530 // start stream
531 display_->intents = {PREVIEW};
532 display_->StartStream(display_->intents);
533 // capture
534 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
535 // release stream
536 display_->captureIds = {display_->CAPTURE_ID_PREVIEW};
537 display_->streamIds = {display_->STREAM_ID_PREVIEW};
538 display_->StopStream(display_->captureIds, display_->streamIds);
539 }
540
541 /**
542 * @tc.name: Preview
543 * @tc.desc: CreateStreams, StreamInfo->StreamIntent = VIDEO, success.
544 * @tc.level: Level2
545 * @tc.size: MediumTest
546 * @tc.type: Function
547 */
548 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1130, TestSize.Level2)
549 {
550 std::cout << "==========[test log] CreateStreams, StreamInfo->StreamIntent = VIDEO, success." << std::endl;
551 // Create and get streamOperator information
552 display_->AchieveStreamOperator();
553 // start stream
554 display_->intents = {PREVIEW, VIDEO};
555 display_->StartStream(display_->intents);
556 // Get preview
557 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
558 display_->StartCapture(display_->STREAM_ID_VIDEO, display_->CAPTURE_ID_VIDEO, false, true);
559 // release stream
560 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_VIDEO};
561 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_VIDEO};
562 display_->StopStream(display_->captureIds, display_->streamIds);
563 }
564
565 /**
566 * @tc.name: Preview
567 * @tc.desc: CreateStreams, StreamInfo->StreamIntent = STILL_CAPTURE, success.
568 * @tc.level: Level2
569 * @tc.size: MediumTest
570 * @tc.type: Function
571 */
572 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1140, TestSize.Level2)
573 {
574 std::cout << "==========[test log] CreateStreams, StreamInfo->StreamIntent = ";
575 std::cout << "STILL_CAPTURE, success." << std::endl;
576 // Get the stream manager
577 display_->AchieveStreamOperator();
578 // start stream
579 display_->intents = {PREVIEW, STILL_CAPTURE};
580 display_->StartStream(display_->intents);
581 // Get preview
582 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
583 display_->StartCapture(display_->STREAM_ID_CAPTURE, display_->CAPTURE_ID_CAPTURE, false, true);
584 // release stream
585 display_->captureIds = {display_->CAPTURE_ID_PREVIEW, display_->CAPTURE_ID_CAPTURE};
586 display_->streamIds = {display_->STREAM_ID_PREVIEW, display_->STREAM_ID_CAPTURE};
587 display_->StopStream(display_->captureIds, display_->streamIds);
588 }
589
590 /**
591 * @tc.name: Preview
592 * @tc.desc: CreateStreams, StreamInfo->StreamIntent = OHOS::POST_VIEW;, success.
593 * @tc.level: Level2
594 * @tc.size: MediumTest
595 * @tc.type: Function
596 */
597 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1150, TestSize.Level2)
598 {
599 std::cout << "==========[test log] CreateStreams, StreamInfo->StreamIntent = ";
600 std::cout << "POST_VIEW;, success." << std::endl;
601 // Create and get streamOperator information
602 display_->AchieveStreamOperator();
603 // Create preview stream
604 // std::shared_ptr<OHOS::IBufferProducer> producer = OHOS::IBufferProducer::CreateBufferQueue();
605 if (display_->streamCustomerPreview_ == nullptr) {
606 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
607 }
608 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
609 producer->SetQueueSize(8); // 8:set bufferQueue size
610 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
611 std::cout << "~~~~~~~" << std::endl;
612 }
613 std::vector<StreamInfo> streamInfos;
614 StreamInfo streamInfo = {};
615 streamInfo.streamId_ = 1001;
616 streamInfo.width_ = 640; // 640:picture width
617 streamInfo.height_ = 480; // 480:picture height
618 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
619 streamInfo.dataspace_ = 8; // 8:picture dataspace
620 streamInfo.intent_ = POST_VIEW;
621 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
622 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
623 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
624 std::vector<StreamInfo>().swap(streamInfos);
625 streamInfos.push_back(streamInfo);
626 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
627 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
628 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
629 std::cout << "==========[test log] CreateStreams success." << std::endl;
630 } else {
631 std::cout << "==========[test log] CreateStreams fail, rc = " << display_->rc << std::endl;
632 }
633 // release stream
634 std::vector<int> streamIds;
635 streamIds.push_back(streamInfo.streamId_);
636 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(streamIds);
637 std::cout << "ReleaseStreams's RetCode = " << display_->rc << std::endl;
638 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
639 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
640 std::cout << "==========[test log] ReleaseStreams success." << std::endl;
641 } else {
642 std::cout << "==========[test log] ReleaseStreams fail, rc = " << display_->rc << std::endl;
643 }
644 }
645
646 /**
647 * @tc.name: Preview
648 * @tc.desc: CreateStreams, StreamInfo->StreamIntent = OHOS::ANALYZE;, success.
649 * @tc.level: Level2
650 * @tc.size: MediumTest
651 * @tc.type: Function
652 */
653 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1160, TestSize.Level2)
654 {
655 std::cout << "==========[test log] CreateStreams, StreamInfo->StreamIntent = ";
656 std::cout << "ANALYZE;, success." << std::endl;
657 // Create and get streamOperator information
658 display_->AchieveStreamOperator();
659 // Create data stream
660 if (display_->streamCustomerPreview_ == nullptr) {
661 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
662 }
663 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
664 producer->SetQueueSize(8); // 8:set bufferQueue size
665 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
666 std::cout << "~~~~~~~" << std::endl;
667 }
668 std::vector<StreamInfo> streamInfos;
669 StreamInfo streamInfo = {};
670 streamInfo.streamId_ = 1001;
671 streamInfo.width_ = 640; // 640:picture width
672 streamInfo.height_ = 480; // 480:picture height
673 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
674 streamInfo.dataspace_ = 8; // 8:picture dataspace
675 streamInfo.intent_ = ANALYZE;
676 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
677 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
678 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
679 std::vector<StreamInfo>().swap(streamInfos);
680 streamInfos.push_back(streamInfo);
681 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
682 std::cout << "streamOperator->CreateStreams's RetCode = " << display_->rc << std::endl;
683 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
684 std::cout << "==========[test log] CreateStreams success." << std::endl;
685 // release stream
686 std::vector<int> streamIds;
687 streamIds.push_back(streamInfo.streamId_);
688 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(streamIds);
689 std::cout << "ReleaseStreams RetCode = " << display_->rc << std::endl;
690 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
691 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
692 std::cout << "==========[test log] ReleaseStreams success." << std::endl;
693 }
694 else {
695 std::cout << "==========[test log] ReleaseStreams fail, rc = " << display_->rc << std::endl;
696 }
697 }
698
699 /**
700 * @tc.name: Preview
701 * @tc.desc: CreateStreams, StreamInfo->StreamIntent = CUSTOM, not support.
702 * @tc.level: Level2
703 * @tc.size: MediumTest
704 * @tc.type: Function
705 */
706 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1170, TestSize.Level2)
707 {
708 std::cout << "==========[test log] CreateStreams, StreamInfo->StreamIntent = ";
709 std::cout << "Camera::CUSTOM, not support." << std::endl;
710 // Create and get streamOperator information
711 display_->AchieveStreamOperator();
712 // Create data stream
713 if (display_->streamCustomerPreview_ == nullptr) {
714 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
715 }
716 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
717 producer->SetQueueSize(8); // 8:set bufferQueue size
718 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
719 std::cout << "~~~~~~~" << std::endl;
720 }
721 std::vector<StreamInfo> streamInfos;
722 StreamInfo streamInfo = {};
723 streamInfo.streamId_ = 1001;
724 streamInfo.width_ = 640; // 640:picture width
725 streamInfo.height_ = 480; // 480:picture height
726 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
727 streamInfo.dataspace_ = 8; // 8:picture dataspace
728 streamInfo.intent_ = CUSTOM;
729 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
730 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
731 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
732 std::vector<StreamInfo>().swap(streamInfos);
733 streamInfos.push_back(streamInfo);
734 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
735 std::cout << "streamOperator->CreateStreams's RetCode = " << display_->rc << std::endl;
736 EXPECT_EQ(true, display_->rc != HDI::Camera::V1_0::NO_ERROR);
737 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
738 std::cout << "==========[test log] CreateStreams success." << std::endl;
739 } else {
740 std::cout << "==========[test log] CreateStreams fail, rc = " << display_->rc << std::endl;
741 }
742 }
743
744 /**
745 * @tc.name: Preview
746 * @tc.desc: CreateStreams, StreamInfo->tunneledMode = false, success.
747 * @tc.level: Level2
748 * @tc.size: MediumTest
749 * @tc.type: Function
750 */
751 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1180, TestSize.Level2)
752 {
753 std::cout << "==========[test log] CreateStreams, StreamInfo->tunneledMode = false, success." << std::endl;
754 // Create and get streamOperator information
755 display_->AchieveStreamOperator();
756 // Create data stream
757 if (display_->streamCustomerPreview_ == nullptr) {
758 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
759 }
760 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
761 producer->SetQueueSize(8); // 8:set bufferQueue size
762 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
763 std::cout << "~~~~~~~" << std::endl;
764 }
765 std::vector<StreamInfo> streamInfos;
766 StreamInfo streamInfo = {};
767 streamInfo.streamId_ = 1001;
768 streamInfo.width_ = 640; // 640:picture width
769 streamInfo.height_ = 480; // 480:picture height
770 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
771 streamInfo.dataspace_ = 8; // 8:picture dataspace
772 streamInfo.intent_ = PREVIEW;
773 streamInfo.tunneledMode_ = false;
774 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
775 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
776 std::vector<StreamInfo>().swap(streamInfos);
777 streamInfos.push_back(streamInfo);
778 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
779 std::cout << "streamOperator->CreateStreams's RetCode = " << display_->rc << std::endl;
780 EXPECT_EQ(true, display_->rc == INVALID_ARGUMENT);
781 if (display_->rc == INVALID_ARGUMENT) {
782 std::cout << "==========[test log] CreateStreams fail." << std::endl;
783 } else {
784 std::cout << "==========[test log] CreateStreams success"<< std::endl;
785 }
786 }
787
788 /**
789 * @tc.name: Preview
790 * @tc.desc: CreateStreams, StreamInfo->minFrameDuration = -1, return error.
791 * @tc.level: Level2
792 * @tc.size: MediumTest
793 * @tc.type: Function
794 */
795 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1190, TestSize.Level2)
796 {
797 std::cout << "==========[test log] CreateStreams, StreamInfo->minFrameDuration = -1, ";
798 std::cout << "return error." << std::endl;
799 // Create and get streamOperator information
800 display_->AchieveStreamOperator();
801 // Create data stream
802 if (display_->streamCustomerPreview_ == nullptr) {
803 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
804 }
805 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
806 producer->SetQueueSize(8); // 8:set bufferQueue size
807 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
808 std::cout << "~~~~~~~" << std::endl;
809 }
810 std::vector<StreamInfo> streamInfos;
811 StreamInfo streamInfo = {};
812 streamInfo.streamId_ = 1001;
813 streamInfo.width_ = 640; // 640:picture width
814 streamInfo.height_ = 480; // 480:picture height
815 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
816 streamInfo.dataspace_ = 8; // 8:picture dataspace
817 streamInfo.intent_ = PREVIEW;
818 streamInfo.tunneledMode_ = 0;
819 streamInfo.minFrameDuration_ = -1;
820 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
821 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
822 std::vector<StreamInfo>().swap(streamInfos);
823 streamInfos.push_back(streamInfo);
824 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
825 std::cout << "streamOperator->CreateStreams's RetCode = " << display_->rc << std::endl;
826 EXPECT_EQ(INVALID_ARGUMENT, display_->rc);
827 std::cout << "==========[test log] CreateStreams, failed." << std::endl;
828 }
829
830 /**
831 * @tc.name: Preview
832 * @tc.desc: CreateStreams, StreamInfo->minFrameDuration = 2147483647, success.
833 * @tc.level: Level2
834 * @tc.size: MediumTest
835 * @tc.type: Function
836 */
837 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1200, TestSize.Level2)
838 {
839 std::cout << "==========[test log] CreateStreams, StreamInfo->minFrameDuration = 2147483647, ";
840 std::cout << "success." << std::endl;
841 // Create and get streamOperator information
842 display_->AchieveStreamOperator();
843 // Create data stream
844 if (display_->streamCustomerPreview_ == nullptr) {
845 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
846 }
847 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
848 producer->SetQueueSize(8); // 8:set bufferQueue size
849 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
850 std::cout << "~~~~~~~" << std::endl; }
851
852 std::vector<StreamInfo> streamInfos;
853 StreamInfo streamInfo = {};
854 streamInfo.streamId_ = 1001;
855 streamInfo.width_ = 640; // 640:picture width
856 streamInfo.height_ = 480; // 480:picture height
857 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
858 streamInfo.dataspace_ = 8; // 8:picture dataspace
859 streamInfo.intent_ = PREVIEW;
860 streamInfo.tunneledMode_ = 0;
861 streamInfo.minFrameDuration_ = 2147483647;
862 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
863 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
864 std::vector<StreamInfo>().swap(streamInfos);
865 streamInfos.push_back(streamInfo);
866 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
867 std::cout << "streamOperator->CreateStreams's RetCode = " << display_->rc << std::endl;
868 EXPECT_EQ(false, display_->rc == HDI::Camera::V1_0::NO_ERROR);
869 std::cout << "==========[test log] CreateStreams, success." << std::endl;
870 }
871
872 /**
873 * @tc.name: Preview
874 * @tc.desc: Preview, CommitStreams Metadata = nullptr.
875 * @tc.level: Level2
876 * @tc.size: MediumTest
877 * @tc.type: Function
878 */
879 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_0070, TestSize.Level2)
880 {
881 std::cout << "==========[test log] Preview, CommitStreams Metadata = nullptr." << std::endl;
882 // Create and get streamOperator information
883 display_->AchieveStreamOperator();
884 if (display_->streamCustomerPreview_ == nullptr) {
885 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
886 }
887 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
888 producer->SetQueueSize(8); // 8:set bufferQueue size
889 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
890 std::cout << "~~~~~~~" << std::endl; }
891
892 std::vector<StreamInfo> streamInfos;
893 StreamInfo streamInfo = {};
894 streamInfo.streamId_ = 1001;
895 streamInfo.width_ = 640; // 640:picture width
896 streamInfo.height_ = 480; // 480:picture height
897 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
898 streamInfo.dataspace_ = 8; // 8:picture dataspace
899 streamInfo.intent_ = PREVIEW;
900 streamInfo.tunneledMode_ = 0;
901 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
902 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
903 std::vector<StreamInfo>().swap(streamInfos);
904 streamInfos.push_back(streamInfo);
905 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
906 // Distribution stream
907 std::vector<uint8_t> modeSetting = {};
908 display_->rc = (CamRetCode)display_->streamOperator->CommitStreams(NORMAL, modeSetting);
909 std::cout << "streamOperator->CommitStreams's RetCode = " << display_->rc << std::endl;
910 EXPECT_EQ(true, display_->rc != HDI::Camera::V1_0::NO_ERROR);
911 // release stream
912 std::vector<int> streamIds;
913 streamIds.push_back(-1);
914 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(streamIds);
915 }
916
917 /**
918 * @tc.name: Preview
919 * @tc.desc: Preview, CommitStreams without CreateStreams, expected fail.
920 * @tc.level: Level2
921 * @tc.size: MediumTest
922 * @tc.type: Function
923 */
924 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_0080, TestSize.Level2)
925 {
926 std::cout << "==========[test log] Preview, CommitStreams without CreateStreams, expected fail." << std::endl;
927 // Create and get streamOperator information
928 display_->AchieveStreamOperator();
929 // Distribution stream
930 display_->rc = (CamRetCode)display_->streamOperator->CommitStreams(NORMAL, display_->ability_);
931 std::cout << "streamOperator->CommitStreams's RetCode = " << display_->rc << std::endl;
932 EXPECT_EQ(true, display_->rc == INVALID_ARGUMENT);
933 // release stream
934 std::vector<int> streamIds;
935 streamIds.push_back(-1);
936 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(streamIds);
937 }
938
939 /**
940 * @tc.name: Preview
941 * @tc.desc: Preview and release streams, success.
942 * @tc.level: Level1
943 * @tc.size: MediumTest
944 * @tc.type: Function
945 */
946 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_0090, TestSize.Level1)
947 {
948 std::cout << "==========[test log] Preview and release streams, success." << std::endl;
949 // Create and get streamOperator information
950 display_->AchieveStreamOperator();
951 // Create data stream
952 if (display_->streamCustomerPreview_ == nullptr) {
953 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
954 }
955 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
956 producer->SetQueueSize(8); // 8:set bufferQueue size
957 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
958 std::cout << "~~~~~~~" << std::endl;
959 }
960 std::vector<StreamInfo> streamInfos;
961 StreamInfo streamInfo = {};
962 streamInfo.streamId_ = 1001;
963 streamInfo.width_ = 640; // 640:picture width
964 streamInfo.height_ = 480; // 480:picture height
965 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
966 streamInfo.dataspace_ = 8; // 8:picture dataspace
967 streamInfo.intent_ = PREVIEW;
968 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
969 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
970 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
971 std::vector<StreamInfo>().swap(streamInfos);
972 streamInfos.push_back(streamInfo);
973 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
974 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
975 // Distribution stream
976 display_->rc = (CamRetCode)display_->streamOperator->CommitStreams(NORMAL, display_->ability_);
977 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
978 // Get preview
979 int captureId = 2001;
980 CaptureInfo captureInfo = {};
981 captureInfo.streamIds_ = {1001};
982 captureInfo.captureSetting_ = display_->ability_;
983 captureInfo.enableShutterCallback_ = false;
984 display_->rc = (CamRetCode)display_->streamOperator->Capture(captureId, captureInfo, true);
985 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
986 sleep(3);
987 display_->streamOperator->CancelCapture(captureId);
988 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
989 // release stream
990 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(captureInfo.streamIds_);
991 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
992 }
993
994 /**
995 * @tc.name: Preview
996 * @tc.desc: ReleaseStreams-> streamID = -1, expected INVALID_ARGUMENT.
997 * @tc.level: Level2
998 * @tc.size: MediumTest
999 * @tc.type: Function
1000 */
1001 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1220, TestSize.Level2)
1002 {
1003 std::cout << "==========[test log] ReleaseStreams-> streamID = -1, expected success." << std::endl;
1004 // Create and get streamOperator information
1005 display_->AchieveStreamOperator();
1006 // Create preview stream
1007 // std::shared_ptr<OHOS::IBufferProducer> producer = OHOS::IBufferProducer::CreateBufferQueue();
1008 if (display_->streamCustomerPreview_ == nullptr) {
1009 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
1010 }
1011 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
1012 producer->SetQueueSize(8); // 8:set bufferQueue size
1013 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
1014 std::cout << "~~~~~~~" << std::endl;
1015 }
1016 std::vector<StreamInfo> streamInfos;
1017 StreamInfo streamInfo = {};
1018 streamInfo.streamId_ = 1001;
1019 streamInfo.width_ = 640; // 640:picture width
1020 streamInfo.height_ = 480; // 480:picture height
1021 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
1022 streamInfo.dataspace_ = 8; // 8:picture dataspace
1023 streamInfo.intent_ = PREVIEW;
1024 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
1025 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
1026 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
1027 std::vector<StreamInfo>().swap(streamInfos);
1028 streamInfos.push_back(streamInfo);
1029 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
1030 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1031 // Distribution stream
1032 display_->rc = (CamRetCode)display_->streamOperator->CommitStreams(NORMAL, display_->ability_);
1033 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1034 // Get preview
1035 int captureId = 2001;
1036 CaptureInfo captureInfo = {};
1037 captureInfo.streamIds_ = {1001};
1038 captureInfo.captureSetting_ = display_->ability_;
1039 captureInfo.enableShutterCallback_ = false;
1040 display_->rc = (CamRetCode)display_->streamOperator->Capture(captureId, captureInfo, true);
1041 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1042 sleep(3);
1043 display_->streamOperator->CancelCapture(captureId);
1044 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1045 // release stream
1046 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(
1047 {-1});
1048 std::cout << "streamOperator->ReleaseStreams's rc = " << display_->rc << std::endl;
1049 EXPECT_EQ(true, display_->rc == INVALID_ARGUMENT);
1050 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(
1051 {1001});
1052 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1053 std::cout << "streamOperator->ReleaseStreams's RetCode = " << display_->rc << std::endl;
1054 }
1055
1056 /**
1057 * @tc.name: Preview
1058 * @tc.desc: ReleaseStreams no exist streamID, expect success.
1059 * @tc.level: Level2
1060 * @tc.size: MediumTest
1061 * @tc.type: Function
1062 */
1063 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_0100, TestSize.Level2)
1064 {
1065 std::cout << "==========[test log] ReleaseStreams no exist streamID, expect success." << std::endl;
1066 // Create and get streamOperator information
1067 display_->AchieveStreamOperator();
1068 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(
1069 {9999});
1070 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1071 }
1072
1073 /**
1074 * @tc.name: Preview
1075 * @tc.desc: ReleaseStreams no exist streamID, expect success.
1076 * @tc.level: Level2
1077 * @tc.size: MediumTest
1078 * @tc.type: Function
1079 */
1080 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_0101, TestSize.Level2)
1081 {
1082 std::cout << "==========[test log] ReleaseStreams no exist streamID, expect success." << std::endl;
1083 // Create and get streamOperator information
1084 display_->AchieveStreamOperator();
1085 std::vector<std::shared_ptr<StreamInfo>> streamInfos;
1086 std::shared_ptr<StreamInfo> streamInfo = std::make_shared<StreamInfo>();
1087 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(
1088 {0});
1089 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1090 }
1091
1092 /**
1093 * @tc.name: Preview
1094 * @tc.desc: ReleaseStreams no exist streamID, expect success.
1095 * @tc.level: Level2
1096 * @tc.size: MediumTest
1097 * @tc.type: Function
1098 */
1099 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_0102, TestSize.Level2)
1100 {
1101 std::cout << "==========[test log] ReleaseStreams no exist streamID, expect success." << std::endl;
1102 // Create and get streamOperator information
1103 display_->AchieveStreamOperator();
1104 std::vector<std::shared_ptr<StreamInfo>> streamInfos;
1105 std::shared_ptr<StreamInfo> streamInfo = std::make_shared<StreamInfo>();
1106 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(
1107 {99999999});
1108 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1109 }
1110
1111 /**
1112 * @tc.name: Preview
1113 * @tc.desc: Preview, Capture->captureInfo->streamID = -1 ,return error.
1114 * @tc.level: Level2
1115 * @tc.size: MediumTest
1116 * @tc.type: Function
1117 */
1118 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1270, TestSize.Level2)
1119 {
1120 std::cout << "==========[test log] Preview, Capture->captureInfo->streamID = -1 ,return error." << std::endl;
1121 // Create and get streamOperator information
1122 display_->AchieveStreamOperator();
1123 // Create preview stream
1124 // std::shared_ptr<OHOS::IBufferProducer> producer = OHOS::IBufferProducer::CreateBufferQueue();
1125 if (display_->streamCustomerPreview_ == nullptr) {
1126 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
1127 }
1128 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
1129 producer->SetQueueSize(8); // 8:set bufferQueue size
1130 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
1131 std::cout << "~~~~~~~" << std::endl;
1132 }
1133
1134 std::vector<StreamInfo> streamInfos;
1135 StreamInfo streamInfo = {};
1136 streamInfo.streamId_ = 1001;
1137 streamInfo.width_ = 640; // 640:picture width
1138 streamInfo.height_ = 480; // 480:picture height
1139 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
1140 streamInfo.dataspace_ = 8; // 8:picture dataspace
1141 streamInfo.intent_ = PREVIEW;
1142 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
1143 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
1144 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
1145 std::vector<StreamInfo>().swap(streamInfos);
1146 streamInfos.push_back(streamInfo);
1147 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
1148 if (display_->rc != HDI::Camera::V1_0::NO_ERROR)
1149 std::cout << "==============[test log]CreateStreams failed!" << std::endl;
1150 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1151 // Distribution stream
1152 display_->rc = (CamRetCode)display_->streamOperator->CommitStreams(NORMAL, display_->ability_);
1153 if (display_->rc != HDI::Camera::V1_0::NO_ERROR)
1154 std::cout << "==============[test log]CommitStreams failed!" << std::endl;
1155 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1156 // Get preview
1157 int captureId = 2001;
1158 CaptureInfo captureInfo = {};
1159 captureInfo.streamIds_ = {-1};
1160 captureInfo.captureSetting_ = display_->ability_;
1161 captureInfo.enableShutterCallback_ = true;
1162 display_->rc = (CamRetCode)display_->streamOperator->Capture(captureId, captureInfo, true);
1163 std::cout << "streamOperator->Capture rc = " << display_->rc << std::endl;
1164 if (display_->rc == INVALID_ARGUMENT)
1165 std::cout << "============[test log]Capture failed " << std::endl;
1166 EXPECT_EQ(INVALID_ARGUMENT, display_->rc);
1167 }
1168
1169 /**
1170 * @tc.name: Preview
1171 * @tc.desc: Preview, Capture->captureInfo->streamID = 2147483647 ,return success.
1172 * @tc.level: Level2
1173 * @tc.size: MediumTest
1174 * @tc.type: Function
1175 */
1176 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1280, TestSize.Level2)
1177 {
1178 std::cout << "==========[test log] Preview, Capture->captureInfo->streamID = 2147483647 ,";
1179 std::cout << "return success." << std::endl;
1180 // Create and get streamOperator information
1181 display_->AchieveStreamOperator();
1182 // Create data stream
1183 if (display_->streamCustomerPreview_ == nullptr) {
1184 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
1185 }
1186 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
1187 producer->SetQueueSize(8); // 8:set bufferQueue size
1188 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
1189 std::cout << "~~~~~~~" << std::endl;
1190 }
1191
1192 std::vector<StreamInfo> streamInfos;
1193 StreamInfo streamInfo = {};
1194 streamInfo.streamId_ = 2147483647;
1195 streamInfo.width_ = 640; // 640:picture width
1196 streamInfo.height_ = 480; // 480:picture height
1197 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
1198 streamInfo.dataspace_ = 8; // 8:picture dataspace
1199 streamInfo.intent_ = PREVIEW;
1200 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
1201 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
1202 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
1203 std::vector<StreamInfo>().swap(streamInfos);
1204 streamInfos.push_back(streamInfo);
1205 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
1206 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1207 // Distribution stream
1208 display_->rc = (CamRetCode)display_->streamOperator->CommitStreams(NORMAL, display_->ability_);
1209 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1210 // Get preview
1211 int captureId = 2001;
1212 CaptureInfo captureInfo = {};
1213 captureInfo.streamIds_ = {2147483647};
1214 captureInfo.captureSetting_ = display_->ability_;
1215 captureInfo.enableShutterCallback_ = true;
1216 bool isStreaming = true;
1217 display_->rc = (CamRetCode)display_->streamOperator->Capture(captureId, captureInfo, isStreaming);
1218 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1219 sleep(3);
1220 display_->streamOperator->CancelCapture(captureId);
1221 // release stream
1222 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(captureInfo.streamIds_);
1223 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1224 }
1225
1226 /**
1227 * @tc.name: Preview
1228 * @tc.desc: Preview, Capture->captureInfo->enableShutterCallback = false ,return success.
1229 * @tc.level: Level2
1230 * @tc.size: MediumTest
1231 * @tc.type: Function
1232 */
1233 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1290, TestSize.Level2)
1234 {
1235 std::cout << "==========[test log] Preview, Capture->captureInfo->enableShutterCallback = false ,";
1236 std::cout << "return success." << std::endl;
1237 // Create and get streamOperator information
1238 display_->AchieveStreamOperator();
1239 // Create data stream
1240 display_->intents = {PREVIEW};
1241 display_->StartStream(display_->intents);
1242 // Get preview
1243 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
1244 // release stream
1245 display_->captureIds = {display_->CAPTURE_ID_PREVIEW};
1246 display_->streamIds = {display_->STREAM_ID_PREVIEW};
1247 display_->StopStream(display_->captureIds, display_->streamIds);
1248 }
1249
1250 /**
1251 * @tc.name: Preview
1252 * @tc.desc: Preview, Capture->isStreaming = false ,expected success.
1253 * @tc.level: Level2
1254 * @tc.size: MediumTest
1255 * @tc.type: Function
1256 */
1257 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1300, TestSize.Level2)
1258 {
1259 std::cout << "==========[test log] Preview, Capture->isStreaming = false ,expected success." << std::endl;
1260 // Create and get streamOperator information
1261 display_->AchieveStreamOperator();
1262 // Create data stream
1263 display_->intents = {PREVIEW};
1264 display_->StartStream(display_->intents);
1265 // Get preview
1266 int captureId = 2001;
1267 CaptureInfo captureInfo = {};
1268 captureInfo.streamIds_ = {display_->STREAM_ID_PREVIEW};
1269 captureInfo.captureSetting_ = display_->ability_;
1270 captureInfo.enableShutterCallback_ = true;
1271 display_->rc = (CamRetCode)display_->streamOperator->Capture(captureId, captureInfo, false);
1272 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1273 sleep(3);
1274 display_->streamOperator->CancelCapture(captureId);
1275 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1276 // release stream
1277 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(captureInfo.streamIds_);
1278 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1279 }
1280
1281 /**
1282 * @tc.name: Preview
1283 * @tc.desc: Preview, Capture->captureId = -1 ,return error.
1284 * @tc.level: Level2
1285 * @tc.size: MediumTest
1286 * @tc.type: Function
1287 */
1288 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1310, TestSize.Level2)
1289 {
1290 std::cout << "==========[test log] Preview, Capture->captureId = -1 ,return error." << std::endl;
1291 // Create and get streamOperator information
1292 display_->AchieveStreamOperator();
1293 // Create data stream
1294 display_->intents = {PREVIEW};
1295 display_->StartStream(display_->intents);
1296 // Get preview
1297 int captureId = -1;
1298 CaptureInfo captureInfo = {};
1299 captureInfo.streamIds_ = {display_->STREAM_ID_PREVIEW};
1300 captureInfo.captureSetting_ = display_->ability_;
1301 captureInfo.enableShutterCallback_ = false;
1302 bool isStreaming = true;
1303 display_->rc = (CamRetCode)display_->streamOperator->Capture(captureId, captureInfo, isStreaming);
1304 EXPECT_EQ(INVALID_ARGUMENT, display_->rc);
1305 }
1306
1307 /**
1308 * @tc.name: Preview
1309 * @tc.desc: Preview, Capture->captureInfo->enableShutterCallback = true ,return success.
1310 * @tc.level: Level2
1311 * @tc.size: MediumTest
1312 * @tc.type: Function
1313 */
1314 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1320, TestSize.Level2)
1315 {
1316 std::cout << "==========[test log] Preview, Capture->captureInfo->enableShutterCallback = true ,";
1317 std::cout << "return success." << std::endl;
1318 // Create and get streamOperator information
1319 display_->AchieveStreamOperator();
1320 // Create data stream
1321 display_->intents = {PREVIEW};
1322 display_->StartStream(display_->intents);
1323 // Get preview
1324 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, true, true);
1325 // release stream
1326 display_->captureIds = {display_->CAPTURE_ID_PREVIEW};
1327 display_->streamIds = {display_->STREAM_ID_PREVIEW};
1328 display_->StopStream(display_->captureIds, display_->streamIds);
1329 }
1330
1331 /**
1332 * @tc.name: Preview
1333 * @tc.desc: CancelCapture captureID = -1.
1334 * @tc.level: Level2
1335 * @tc.size: MediumTest
1336 * @tc.type: Function
1337 */
1338 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_1340, TestSize.Level2)
1339 {
1340 std::cout << "==========[test log] CancelCapture captureID = -1, expected fail." << std::endl;
1341 // Create and get streamOperator information
1342 display_->AchieveStreamOperator();
1343 // Create data stream
1344 if (display_->streamCustomerPreview_ == nullptr) {
1345 display_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
1346 }
1347 OHOS::sptr<OHOS::IBufferProducer> producer = display_->streamCustomerPreview_->CreateProducer();
1348 producer->SetQueueSize(8); // 8:set bufferQueue size
1349 if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
1350 std::cout << "~~~~~~~" << std::endl;
1351 }
1352
1353 std::vector<StreamInfo> streamInfos;
1354 StreamInfo streamInfo = {};
1355 streamInfo.streamId_ = 1001;
1356 streamInfo.width_ = 640; // 640:picture width
1357 streamInfo.height_ = 480; // 480:picture height
1358 streamInfo.format_ = PIXEL_FMT_RGBA_8888;
1359 streamInfo.dataspace_ = 8; // 8:picture dataspace
1360 streamInfo.intent_ = PREVIEW;
1361 streamInfo.tunneledMode_ = 5; // 5:tunnel mode
1362 streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
1363 ASSERT_NE(streamInfo.bufferQueue_, nullptr);
1364 std::vector<StreamInfo>().swap(streamInfos);
1365 streamInfos.push_back(streamInfo);
1366 display_->rc = (CamRetCode)display_->streamOperator->CreateStreams(streamInfos);
1367 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1368 // Distribution stream
1369 display_->rc = (CamRetCode)display_->streamOperator->CommitStreams(NORMAL, display_->ability_);
1370 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1371 // Get preview
1372 int captureId = 100;
1373 CaptureInfo captureInfo = {};
1374 captureInfo.streamIds_ = {1001};
1375 captureInfo.captureSetting_ = display_->ability_;
1376 captureInfo.enableShutterCallback_ = false;
1377 bool isStreaming = true;
1378 display_->rc = (CamRetCode)display_->streamOperator->Capture(captureId, captureInfo, isStreaming);
1379 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1380 sleep(3);
1381 display_->rc = (CamRetCode)display_->streamOperator->CancelCapture(-1);
1382 EXPECT_EQ(INVALID_ARGUMENT, display_->rc);
1383 display_->rc = (CamRetCode)display_->streamOperator->CancelCapture(captureId);
1384 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1385 // release stream
1386 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(captureInfo.streamIds_);
1387 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1388 }
1389
1390 /**
1391 * @tc.name: Preview
1392 * @tc.desc: CancelCapture without Create capture.
1393 * @tc.level: Level2
1394 * @tc.size: MediumTest
1395 * @tc.type: Function
1396 */
1397 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_0110, TestSize.Level2)
1398 {
1399 std::cout << "==========[test log] CancelCapture without Create capture ." << std::endl;
1400 // Create and get streamOperator information
1401 display_->AchieveStreamOperator();
1402 // Create data stream
1403 display_->intents = {PREVIEW};
1404 display_->StartStream(display_->intents);
1405 // Get preview
1406 int captureId = 100;
1407 display_->rc = (CamRetCode)display_->streamOperator->CancelCapture(captureId);
1408 if (display_->rc == HDI::Camera::V1_0::NO_ERROR) {
1409 std::cout << "==========[test log] CancelCapture success." << std::endl;
1410 }
1411 else {
1412 std::cout << "==========[test log] CancelCapture fail, rc = " << display_->rc << std::endl;
1413 }
1414 }
1415
1416 /**
1417 * @tc.name: Preview
1418 * @tc.desc: Release streams, then createCapture.
1419 * @tc.level: Level2
1420 * @tc.size: MediumTest
1421 * @tc.type: Function
1422 */
1423 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_0120, TestSize.Level2)
1424 {
1425 std::cout << "==========[test log] Create capture, then release streams." << std::endl;
1426 // Create and get streamOperator information
1427 display_->AchieveStreamOperator();
1428 // start stream
1429 display_->intents = {PREVIEW};
1430 display_->StartStream(display_->intents);
1431 // Get preview
1432 display_->StartCapture(display_->STREAM_ID_PREVIEW, display_->CAPTURE_ID_PREVIEW, false, true);
1433 // release stream
1434 display_->captureIds = {display_->CAPTURE_ID_PREVIEW};
1435 display_->streamIds = {display_->STREAM_ID_PREVIEW};
1436 display_->StopStream(display_->captureIds, display_->streamIds);
1437 }
1438
1439 /**
1440 * @tc.name: Preview
1441 * @tc.desc: The same CaptureID, Create capture twice, expected fail.
1442 * @tc.level: Level2
1443 * @tc.size: MediumTest
1444 * @tc.type: Function
1445 */
1446 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_0130, TestSize.Level2)
1447 {
1448 std::cout << "==========[test log] The same CaptureID, Create capture twice, expected fail." << std::endl;
1449 // Create and get streamOperator information
1450 display_->AchieveStreamOperator();
1451 // start stream
1452 display_->intents = {PREVIEW};
1453 display_->StartStream(display_->intents);
1454
1455 int captureId = display_->CAPTURE_ID_PREVIEW;
1456 CaptureInfo captureInfo = {};
1457 captureInfo.streamIds_ = {display_->STREAM_ID_PREVIEW};
1458 captureInfo.captureSetting_ = display_->ability_;
1459 captureInfo.enableShutterCallback_ = false;
1460 bool isStreaming = true;
1461 display_->rc = (CamRetCode)display_->streamOperator->Capture(captureId, captureInfo, isStreaming);
1462 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1463
1464 display_->rc = (CamRetCode)display_->streamOperator->Capture(captureId, captureInfo, isStreaming);
1465 EXPECT_EQ(false, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1466
1467 sleep(2);
1468 // cancel capture
1469 display_->rc = (CamRetCode)display_->streamOperator->CancelCapture(captureId);
1470 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1471
1472 // release stream
1473 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(captureInfo.streamIds_);
1474 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1475 }
1476
1477 /**
1478 * @tc.name: Preview
1479 * @tc.desc: Different captureIDs, Create capture,expected success.
1480 * @tc.level: Level2
1481 * @tc.size: MediumTest
1482 * @tc.type: Function
1483 */
1484 HWTEST_F(CameraPreviewTest, SUB_DriverSystem_CameraHdi_0140, TestSize.Level2)
1485 {
1486 std::cout << "==========[test log] Different captureIDs, Create capture,expected success." << std::endl;
1487 // Create and get streamOperator information
1488 display_->AchieveStreamOperator();
1489 // Create data stream
1490 display_->intents = {PREVIEW};
1491 display_->StartStream(display_->intents);
1492 // Get preview
1493 int captureId = display_->CAPTURE_ID_PREVIEW;
1494 CaptureInfo captureInfo = {};
1495 captureInfo.streamIds_ = {display_->STREAM_ID_PREVIEW};
1496 captureInfo.captureSetting_ = display_->ability_;
1497 captureInfo.enableShutterCallback_ = false;
1498 bool isStreaming = true;
1499 display_->rc = (CamRetCode)display_->streamOperator->Capture(captureId, captureInfo, isStreaming);
1500 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1501 display_->rc = (CamRetCode)display_->streamOperator->Capture(captureId + 1, captureInfo, isStreaming);
1502 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1503
1504 sleep(2);
1505 // cancel capture
1506 display_->streamOperator->CancelCapture(captureId);
1507 display_->streamOperator->CancelCapture(captureId + 1);
1508 // release stream
1509 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams(captureInfo.streamIds_);
1510 EXPECT_EQ(true, display_->rc == HDI::Camera::V1_0::NO_ERROR);
1511 }
1512
1513 /**
1514 * @tc.name: GetStreamAttributes
1515 * @tc.desc: GetStreamAttributes, success.
1516 * @tc.level: Level2
1517 * @tc.size: MediumTest
1518 * @tc.type: Function
1519 */
1520 HWTEST_F(CameraPreviewTest, camera_preview_094, TestSize.Level2)
1521 {
1522 display_->AchieveStreamOperator();
1523 // start stream
1524 display_->intents = {PREVIEW};
1525 display_->StartStream(display_->intents);
1526 std::vector<StreamAttribute> attributes;
1527 display_->rc = (CamRetCode)display_->streamOperator->GetStreamAttributes(attributes);
1528 EXPECT_EQ(display_->rc, HDI::Camera::V1_0::NO_ERROR);
1529 // release stream
1530 display_->rc = (CamRetCode)display_->streamOperator->ReleaseStreams({PREVIEW});
1531 EXPECT_EQ(display_->rc, HDI::Camera::V1_0::NO_ERROR);
1532 }