• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 (cameraBase_ == nullptr)
30     cameraBase_ = std::make_shared<TestCameraBase>();
31     cameraBase_->Init();
32 }
33 
TearDown(void)34 void CameraPreviewTest::TearDown(void)
35 {
36     cameraBase_->Close();
37 }
38 
39 /**
40   * @tc.name: Preview
41   * @tc.desc: Preview, format error, expected return errorCode.
42   * @tc.level: Level2
43   * @tc.size: MediumTest
44   * @tc.type: Function
45   */
46 HWTEST_F(CameraPreviewTest, camera_preview_003, TestSize.Level2)
47 {
48     CAMERA_LOGD("Preview, format error, expected return errorCode.");
49     // Create and get streamOperator information
50     cameraBase_->AchieveStreamOperator();
51     // Create data stream
52     if (cameraBase_->streamCustomerPreview_ == nullptr) {
53         cameraBase_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
54     }
55     OHOS::sptr<OHOS::IBufferProducer> producer = cameraBase_->streamCustomerPreview_->CreateProducer();
56     producer->SetQueueSize(8); // 8:set bufferQueue size
57     if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
58         CAMERA_LOGE("~~~~~~~");
59     }
60     std::vector<StreamInfo> streamInfos;
61     StreamInfo streamInfo = {};
62     streamInfo.streamId_ = 1001;
63     streamInfo.width_ = 640; // 640:picture width
64     streamInfo.height_ = 480; // 480:picture height
65     streamInfo.format_ = -1;
66     streamInfo.dataspace_ = 10; // 10:picture dataspace
67     streamInfo.intent_ = PREVIEW;
68     streamInfo.tunneledMode_ = 5; // 5:tunnel mode
69     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
70     ASSERT_NE(streamInfo.bufferQueue_, nullptr);
71     streamInfos.push_back(streamInfo);
72     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CreateStreams(streamInfos);
73     EXPECT_EQ(true, cameraBase_->rc != HDI::Camera::V1_0::NO_ERROR);
74     if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
75         CAMERA_LOGI("CreateStreams success.");
76     } else {
77         CAMERA_LOGE("CreateStreams fail, rc = %{public}d", cameraBase_->rc);
78     }
79 }
80 
81 /**
82   * @tc.name: Preview
83   * @tc.desc: CreateStreams, success.
84   * @tc.level: Level1
85   * @tc.size: MediumTest
86   * @tc.type: Function
87   */
88 HWTEST_F(CameraPreviewTest, camera_preview_020, TestSize.Level1)
89 {
90     CAMERA_LOGD("CreateStreams, success.");
91     // Create and get streamOperator information
92     cameraBase_->AchieveStreamOperator();
93     // Create data stream
94     if (cameraBase_->streamCustomerPreview_ == nullptr) {
95         cameraBase_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
96     }
97     OHOS::sptr<OHOS::IBufferProducer> producer = cameraBase_->streamCustomerPreview_->CreateProducer();
98     producer->SetQueueSize(8); // 8:set bufferQueue size
99     if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
100         CAMERA_LOGE("~~~~~~~");
101     }
102 
103     std::vector<StreamInfo> streamInfos;
104     StreamInfo streamInfo = {};
105     streamInfo.streamId_ = 1001;
106     streamInfo.width_ = 640; // 640:picture width
107     streamInfo.height_ = 480; // 480:picture height
108     streamInfo.format_ = PIXEL_FMT_RGBA_8888;
109     streamInfo.dataspace_ = 8; // 8:picture dataspace
110     streamInfo.intent_ = PREVIEW;
111     streamInfo.tunneledMode_ = 5; // 5:tunnel mode
112     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
113     ASSERT_NE(streamInfo.bufferQueue_, nullptr);
114     std::vector<StreamInfo>().swap(streamInfos);
115     streamInfos.push_back(streamInfo);
116     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CreateStreams(streamInfos);
117     CAMERA_LOGD("CreateStreams's RetCode = %{public}d", cameraBase_->rc);
118     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
119     CAMERA_LOGD("CreateStreams, success.");
120     // Submit stream information
121     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CommitStreams(NORMAL, cameraBase_->ability_);
122     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
123     if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
124         CAMERA_LOGI("CommitStreams, success.");
125     } else {
126         CAMERA_LOGE("CommitStreams fail, rc = %{public}d", cameraBase_->rc);
127     }
128     // capture
129     cameraBase_->StartCapture(1001, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
130     // release stream
131     cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW};
132     cameraBase_->streamIds = {1001};
133     cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
134 }
135 
136 /**
137   * @tc.name: Preview
138   * @tc.desc: CreateStreams, StreamInfo->streamId = -1, return error.
139   * @tc.level: Level2
140   * @tc.size: MediumTest
141   * @tc.type: Function
142   */
143 HWTEST_F(CameraPreviewTest, camera_preview_021, TestSize.Level2)
144 {
145     CAMERA_LOGD("CreateStreams, success.");
146     // Create and get streamOperator information
147     cameraBase_->AchieveStreamOperator();
148     // Create data stream
149     if (cameraBase_->streamCustomerPreview_ == nullptr) {
150         cameraBase_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
151     }
152     OHOS::sptr<OHOS::IBufferProducer> producer = cameraBase_->streamCustomerPreview_->CreateProducer();
153     producer->SetQueueSize(8); // 8:set bufferQueue size
154     if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
155         CAMERA_LOGE("~~~~~~~");
156     }
157     std::vector<StreamInfo> streamInfos;
158     StreamInfo streamInfo = {};
159     streamInfo.streamId_ = -1;
160     streamInfo.width_ = 640; // 640:picture width
161     streamInfo.height_ = 480; // 480:picture height
162     streamInfo.format_ = PIXEL_FMT_RGBA_8888;
163     streamInfo.dataspace_ = 8; // 8:picture dataspace
164     streamInfo.intent_ = PREVIEW;
165     streamInfo.tunneledMode_ = 5; // 5:tunnel mode
166     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
167     ASSERT_NE(streamInfo.bufferQueue_, nullptr);
168     streamInfos.push_back(streamInfo);
169     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CreateStreams(streamInfos);
170     CAMERA_LOGD("CreateStreams's RetCode = %{public}d", cameraBase_->rc);
171     EXPECT_EQ(false, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
172     if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
173         CAMERA_LOGI("CreateStreams, success.");
174     } else {
175         CAMERA_LOGE("CreateStreams fail, rc = %{public}d", cameraBase_->rc);
176     }
177 }
178 
179 /**
180   * @tc.name: Preview
181   * @tc.desc: CreateStreams, StreamInfo->streamId = 2147483647, return success.
182   * @tc.level: Level2
183   * @tc.size: MediumTest
184   * @tc.type: Function
185   */
186 HWTEST_F(CameraPreviewTest, camera_preview_022, TestSize.Level2)
187 {
188     CAMERA_LOGD("CreateStreams, StreamInfo->streamId = 2147483647, return success.");
189     cameraBase_->AchieveStreamOperator();
190     // Create data stream
191     if (cameraBase_->streamCustomerPreview_ == nullptr) {
192         cameraBase_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
193     }
194     OHOS::sptr<OHOS::IBufferProducer> producer = cameraBase_->streamCustomerPreview_->CreateProducer();
195     producer->SetQueueSize(8); // 8:set bufferQueue size
196     if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
197         CAMERA_LOGE("~~~~~~~");
198     }
199     std::vector<StreamInfo> streamInfos;
200     StreamInfo streamInfo = {};
201     streamInfo.streamId_ = 2147483647;
202     streamInfo.width_ = 640; // 640:picture width
203     streamInfo.height_ = 480; // 480:picture height
204     streamInfo.format_ = PIXEL_FMT_RGBA_8888;
205     streamInfo.dataspace_ = 8; // 8:picture dataspace
206     streamInfo.intent_ = PREVIEW;
207     streamInfo.tunneledMode_ = 5; // 5:tunnel mode
208     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
209     ASSERT_NE(streamInfo.bufferQueue_, nullptr);
210     std::vector<StreamInfo>().swap(streamInfos);
211     streamInfos.push_back(streamInfo);
212     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CreateStreams(streamInfos);
213     CAMERA_LOGD("streamOperator->CreateStreams's RetCode = %{public}d", cameraBase_->rc);
214     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
215     if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
216         CAMERA_LOGI("CreateStreams, success.");
217     } else {
218         CAMERA_LOGE("CreateStreams fail, rc = %{public}d", cameraBase_->rc);
219     }
220     // Submit stream information
221     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CommitStreams(NORMAL, cameraBase_->ability_);
222     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
223     CAMERA_LOGD("CommitStreams success.");
224     // capture
225     cameraBase_->StartCapture(2147483647, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
226     // release stream
227     cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW};
228     cameraBase_->streamIds = {2147483647};
229     cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
230 }
231 
232 /**
233   * @tc.name: Preview
234   * @tc.desc: CreateStreams, StreamInfo->StreamIntent = VIDEO, success.
235   * @tc.level: Level2
236   * @tc.size: MediumTest
237   * @tc.type: Function
238   */
239 HWTEST_F(CameraPreviewTest, camera_preview_032, TestSize.Level2)
240 {
241     CAMERA_LOGD("CreateStreams, StreamInfo->StreamIntent = VIDEO, success.");
242     // Create and get streamOperator information
243     cameraBase_->AchieveStreamOperator();
244     // start stream
245     cameraBase_->intents = {PREVIEW, VIDEO};
246     cameraBase_->StartStream(cameraBase_->intents);
247     // Get preview
248     cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
249     cameraBase_->StartCapture(cameraBase_->STREAM_ID_VIDEO, cameraBase_->CAPTURE_ID_VIDEO, false, true);
250     // release stream
251     cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_VIDEO};
252     cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_VIDEO};
253     cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
254 }
255 
256 /**
257   * @tc.name: Preview
258   * @tc.desc: CreateStreams, StreamInfo->StreamIntent = STILL_CAPTURE, success.
259   * @tc.level: Level2
260   * @tc.size: MediumTest
261   * @tc.type: Function
262   */
263 HWTEST_F(CameraPreviewTest, camera_preview_033, TestSize.Level2)
264 {
265     CAMERA_LOGD("CreateStreams, StreamInfo->StreamIntent = STILL_CAPTURE, success.");
266     // Get the stream manager
267     cameraBase_->AchieveStreamOperator();
268     // start stream
269     cameraBase_->intents = {PREVIEW, STILL_CAPTURE};
270     cameraBase_->StartStream(cameraBase_->intents);
271     // Get preview
272     cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, false, true);
273     cameraBase_->StartCapture(cameraBase_->STREAM_ID_CAPTURE, cameraBase_->CAPTURE_ID_CAPTURE, false, true);
274     // release stream
275     cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW, cameraBase_->CAPTURE_ID_CAPTURE};
276     cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW, cameraBase_->STREAM_ID_CAPTURE};
277     cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
278 }
279 
280 /**
281   * @tc.name: Preview
282   * @tc.desc: CreateStreams, StreamInfo->StreamIntent = OHOS::POST_VIEW;, success.
283   * @tc.level: Level2
284   * @tc.size: MediumTest
285   * @tc.type: Function
286   */
287 HWTEST_F(CameraPreviewTest, camera_preview_034, TestSize.Level2)
288 {
289     CAMERA_LOGD("CreateStreams, StreamInfo->StreamIntent = POST_VIEW, success.");
290     // Create and get streamOperator information
291     cameraBase_->AchieveStreamOperator();
292     // Create preview stream
293     // std::shared_ptr<OHOS::IBufferProducer> producer = OHOS::IBufferProducer::CreateBufferQueue();
294     if (cameraBase_->streamCustomerPreview_ == nullptr) {
295         cameraBase_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
296     }
297     OHOS::sptr<OHOS::IBufferProducer> producer = cameraBase_->streamCustomerPreview_->CreateProducer();
298     producer->SetQueueSize(8); // 8:set bufferQueue size
299     if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
300         CAMERA_LOGE("~~~~~~~");
301     }
302     std::vector<StreamInfo> streamInfos;
303     StreamInfo streamInfo = {};
304     streamInfo.streamId_ = 1001;
305     streamInfo.width_ = 640; // 640:picture width
306     streamInfo.height_ = 480; // 480:picture height
307     streamInfo.format_ = PIXEL_FMT_RGBA_8888;
308     streamInfo.dataspace_ = 8; // 8:picture dataspace
309     streamInfo.intent_ = POST_VIEW;
310     streamInfo.tunneledMode_ = 5; // 5:tunnel mode
311     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
312     ASSERT_NE(streamInfo.bufferQueue_, nullptr);
313     std::vector<StreamInfo>().swap(streamInfos);
314     streamInfos.push_back(streamInfo);
315     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CreateStreams(streamInfos);
316     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
317     if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
318         CAMERA_LOGI("CreateStreams success.");
319     } else {
320         CAMERA_LOGE("CreateStreams fail, rc = %{public}d", cameraBase_->rc);
321     }
322     // release stream
323     std::vector<int> streamIds;
324     streamIds.push_back(streamInfo.streamId_);
325     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->ReleaseStreams(streamIds);
326     CAMERA_LOGD("ReleaseStreams's RetCode = %{public}d", cameraBase_->rc);
327     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
328     if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
329         CAMERA_LOGI("ReleaseStreams success.");
330     } else {
331         CAMERA_LOGE("ReleaseStreams fail, rc = %{public}d", cameraBase_->rc);
332     }
333 }
334 
335 /**
336   * @tc.name: Preview
337   * @tc.desc: CreateStreams, StreamInfo->StreamIntent = OHOS::ANALYZE;, success.
338   * @tc.level: Level2
339   * @tc.size: MediumTest
340   * @tc.type: Function
341   */
342 HWTEST_F(CameraPreviewTest, camera_preview_035, TestSize.Level2)
343 {
344     CAMERA_LOGD("CreateStreams, StreamInfo->StreamIntent = ANALYZE, success.");
345     // Create and get streamOperator information
346     cameraBase_->AchieveStreamOperator();
347     // Create data stream
348     if (cameraBase_->streamCustomerPreview_ == nullptr) {
349         cameraBase_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
350     }
351     OHOS::sptr<OHOS::IBufferProducer> producer = cameraBase_->streamCustomerPreview_->CreateProducer();
352     producer->SetQueueSize(8); // 8:set bufferQueue size
353     if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
354         CAMERA_LOGE("~~~~~~~");
355     }
356     std::vector<StreamInfo> streamInfos;
357     StreamInfo streamInfo = {};
358     streamInfo.streamId_ = 1001;
359     streamInfo.width_ = 640; // 640:picture width
360     streamInfo.height_ = 480; // 480:picture height
361     streamInfo.format_ = PIXEL_FMT_RGBA_8888;
362     streamInfo.dataspace_ = 8; // 8:picture dataspace
363     streamInfo.intent_ = ANALYZE;
364     streamInfo.tunneledMode_ = 5; // 5:tunnel mode
365     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
366     ASSERT_NE(streamInfo.bufferQueue_, nullptr);
367     std::vector<StreamInfo>().swap(streamInfos);
368     streamInfos.push_back(streamInfo);
369     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CreateStreams(streamInfos);
370     CAMERA_LOGD("streamOperator->CreateStreams's RetCode = %{public}d", cameraBase_->rc);
371     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
372     CAMERA_LOGD("CreateStreams success.");
373     // release stream
374     std::vector<int> streamIds;
375     streamIds.push_back(streamInfo.streamId_);
376     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->ReleaseStreams(streamIds);
377     CAMERA_LOGD("ReleaseStreams RetCode = %{public}d", cameraBase_->rc);
378     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
379     if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
380         CAMERA_LOGI("ReleaseStreams success.");
381     }
382     else {
383         CAMERA_LOGE("ReleaseStreams fail, rc = %{public}d", cameraBase_->rc);
384     }
385 }
386 
387 /**
388   * @tc.name: Preview
389   * @tc.desc: CreateStreams, StreamInfo->StreamIntent = CUSTOM, not support.
390   * @tc.level: Level2
391   * @tc.size: MediumTest
392   * @tc.type: Function
393   */
394 HWTEST_F(CameraPreviewTest, camera_preview_036, TestSize.Level2)
395 {
396     CAMERA_LOGD("CreateStreams, StreamInfo->StreamIntent = Camera::CUSTOM, not support.");
397     // Create and get streamOperator information
398     cameraBase_->AchieveStreamOperator();
399     // Create data stream
400     if (cameraBase_->streamCustomerPreview_ == nullptr) {
401         cameraBase_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
402     }
403     OHOS::sptr<OHOS::IBufferProducer> producer = cameraBase_->streamCustomerPreview_->CreateProducer();
404     producer->SetQueueSize(8); // 8:set bufferQueue size
405     if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
406         CAMERA_LOGE("~~~~~~~");
407     }
408     std::vector<StreamInfo> streamInfos;
409     StreamInfo streamInfo = {};
410     streamInfo.streamId_ = 1001;
411     streamInfo.width_ = 640; // 640:picture width
412     streamInfo.height_ = 480; // 480:picture height
413     streamInfo.format_ = PIXEL_FMT_RGBA_8888;
414     streamInfo.dataspace_ = 8; // 8:picture dataspace
415     streamInfo.intent_ = CUSTOM;
416     streamInfo.tunneledMode_ = 5; // 5:tunnel mode
417     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
418     ASSERT_NE(streamInfo.bufferQueue_, nullptr);
419     std::vector<StreamInfo>().swap(streamInfos);
420     streamInfos.push_back(streamInfo);
421     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CreateStreams(streamInfos);
422     CAMERA_LOGD("streamOperator->CreateStreams's RetCode = %{public}d", cameraBase_->rc);
423     EXPECT_EQ(true, cameraBase_->rc != HDI::Camera::V1_0::NO_ERROR);
424     if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
425         CAMERA_LOGI("CreateStreams success.");
426     } else {
427         CAMERA_LOGE("CreateStreams fail, rc = %{public}d", cameraBase_->rc);
428     }
429 }
430 
431 /**
432   * @tc.name: Preview
433   * @tc.desc: CreateStreams, StreamInfo->tunneledMode = false, success.
434   * @tc.level: Level2
435   * @tc.size: MediumTest
436   * @tc.type: Function
437   */
438 HWTEST_F(CameraPreviewTest, camera_preview_037, TestSize.Level2)
439 {
440     CAMERA_LOGD("CreateStreams, StreamInfo->tunneledMode = false, success.");
441     // Create and get streamOperator information
442     cameraBase_->AchieveStreamOperator();
443     // Create data stream
444     if (cameraBase_->streamCustomerPreview_ == nullptr) {
445         cameraBase_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
446     }
447     OHOS::sptr<OHOS::IBufferProducer> producer = cameraBase_->streamCustomerPreview_->CreateProducer();
448     producer->SetQueueSize(8); // 8:set bufferQueue size
449     if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
450         CAMERA_LOGE("~~~~~~~");
451     }
452     std::vector<StreamInfo> streamInfos;
453     StreamInfo streamInfo = {};
454     streamInfo.streamId_ = 1001;
455     streamInfo.width_ = 640; // 640:picture width
456     streamInfo.height_ = 480; // 480:picture height
457     streamInfo.format_ = PIXEL_FMT_RGBA_8888;
458     streamInfo.dataspace_ = 8; // 8:picture dataspace
459     streamInfo.intent_ = PREVIEW;
460     streamInfo.tunneledMode_ = false;
461     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
462     ASSERT_NE(streamInfo.bufferQueue_, nullptr);
463     std::vector<StreamInfo>().swap(streamInfos);
464     streamInfos.push_back(streamInfo);
465     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CreateStreams(streamInfos);
466     CAMERA_LOGD("streamOperator->CreateStreams's RetCode = %{public}d", cameraBase_->rc);
467     EXPECT_EQ(true, cameraBase_->rc == INVALID_ARGUMENT);
468     if (cameraBase_->rc == INVALID_ARGUMENT) {
469         CAMERA_LOGE("CreateStreams fail.");
470     } else {
471         CAMERA_LOGI("CreateStreams success.");
472     }
473 }
474 
475 /**
476   * @tc.name: Preview
477   * @tc.desc: CreateStreams, StreamInfo->minFrameDuration = -1, return error.
478   * @tc.level: Level2
479   * @tc.size: MediumTest
480   * @tc.type: Function
481   */
482 HWTEST_F(CameraPreviewTest, camera_preview_038, TestSize.Level2)
483 {
484     CAMERA_LOGD("CreateStreams, StreamInfo->minFrameDuration = -1, return error.");
485     // Create and get streamOperator information
486     cameraBase_->AchieveStreamOperator();
487     // Create data stream
488     if (cameraBase_->streamCustomerPreview_ == nullptr) {
489         cameraBase_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
490     }
491     OHOS::sptr<OHOS::IBufferProducer> producer = cameraBase_->streamCustomerPreview_->CreateProducer();
492     producer->SetQueueSize(8); // 8:set bufferQueue size
493     if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
494         CAMERA_LOGE("~~~~~~~");
495     }
496     std::vector<StreamInfo> streamInfos;
497     StreamInfo streamInfo = {};
498     streamInfo.streamId_ = 1001;
499     streamInfo.width_ = 640; // 640:picture width
500     streamInfo.height_ = 480; // 480:picture height
501     streamInfo.format_ = PIXEL_FMT_RGBA_8888;
502     streamInfo.dataspace_ = 8; // 8:picture dataspace
503     streamInfo.intent_ = PREVIEW;
504     streamInfo.tunneledMode_ = 0;
505     streamInfo.minFrameDuration_ = -1;
506     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
507     ASSERT_NE(streamInfo.bufferQueue_, nullptr);
508     std::vector<StreamInfo>().swap(streamInfos);
509     streamInfos.push_back(streamInfo);
510     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CreateStreams(streamInfos);
511     CAMERA_LOGD("streamOperator->CreateStreams's RetCode = %{public}d", cameraBase_->rc);
512     EXPECT_EQ(INVALID_ARGUMENT, cameraBase_->rc);
513     CAMERA_LOGD("CreateStreams, failed.");
514 }
515 
516 /**
517   * @tc.name: Preview
518   * @tc.desc: CreateStreams, StreamInfo->minFrameDuration = 2147483647, success.
519   * @tc.level: Level2
520   * @tc.size: MediumTest
521   * @tc.type: Function
522   */
523 HWTEST_F(CameraPreviewTest, camera_preview_039, TestSize.Level2)
524 {
525     CAMERA_LOGD("CreateStreams, StreamInfo->minFrameDuration = 2147483647, success.");
526     // Create and get streamOperator information
527     cameraBase_->AchieveStreamOperator();
528     // Create data stream
529     if (cameraBase_->streamCustomerPreview_ == nullptr) {
530         cameraBase_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
531     }
532     OHOS::sptr<OHOS::IBufferProducer> producer = cameraBase_->streamCustomerPreview_->CreateProducer();
533     producer->SetQueueSize(8); // 8:set bufferQueue size
534     if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
535         CAMERA_LOGE("~~~~~~~");
536     }
537 
538     std::vector<StreamInfo> streamInfos;
539     StreamInfo streamInfo = {};
540     streamInfo.streamId_ = 1001;
541     streamInfo.width_ = 640; // 640:picture width
542     streamInfo.height_ = 480; // 480:picture height
543     streamInfo.format_ = PIXEL_FMT_RGBA_8888;
544     streamInfo.dataspace_ = 8; // 8:picture dataspace
545     streamInfo.intent_ = PREVIEW;
546     streamInfo.tunneledMode_ = 0;
547     streamInfo.minFrameDuration_ = 2147483647;
548     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
549     ASSERT_NE(streamInfo.bufferQueue_, nullptr);
550     std::vector<StreamInfo>().swap(streamInfos);
551     streamInfos.push_back(streamInfo);
552     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CreateStreams(streamInfos);
553     CAMERA_LOGD("streamOperator->CreateStreams's RetCode = %{public}d", cameraBase_->rc);
554     EXPECT_EQ(false, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
555     CAMERA_LOGD("CreateStreams, success.");
556 }
557 
558 /**
559   * @tc.name: Preview
560   * @tc.desc: Preview, CommitStreams Metadata = nullptr.
561   * @tc.level: Level2
562   * @tc.size: MediumTest
563   * @tc.type: Function
564   */
565 HWTEST_F(CameraPreviewTest, camera_preview_040, TestSize.Level2)
566 {
567     CAMERA_LOGD("Preview, CommitStreams Metadata = nullptr.");
568     // Create and get streamOperator information
569     cameraBase_->AchieveStreamOperator();
570     if (cameraBase_->streamCustomerPreview_ == nullptr) {
571         cameraBase_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
572     }
573     OHOS::sptr<OHOS::IBufferProducer> producer = cameraBase_->streamCustomerPreview_->CreateProducer();
574     producer->SetQueueSize(8); // 8:set bufferQueue size
575     if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
576         CAMERA_LOGE("~~~~~~~");
577     }
578 
579     std::vector<StreamInfo> streamInfos;
580     StreamInfo streamInfo = {};
581     streamInfo.streamId_ = 1001;
582     streamInfo.width_ = 640; // 640:picture width
583     streamInfo.height_ = 480; // 480:picture height
584     streamInfo.format_ = PIXEL_FMT_RGBA_8888;
585     streamInfo.dataspace_ = 8; // 8:picture dataspace
586     streamInfo.intent_ = PREVIEW;
587     streamInfo.tunneledMode_ = 0;
588     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
589     ASSERT_NE(streamInfo.bufferQueue_, nullptr);
590     std::vector<StreamInfo>().swap(streamInfos);
591     streamInfos.push_back(streamInfo);
592     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CreateStreams(streamInfos);
593     // Distribution stream
594     std::vector<uint8_t> modeSetting = {};
595     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CommitStreams(NORMAL, modeSetting);
596     CAMERA_LOGD("streamOperator->CreateStreams's RetCode = %{public}d", cameraBase_->rc);
597     EXPECT_EQ(true, cameraBase_->rc != HDI::Camera::V1_0::NO_ERROR);
598     // release stream
599     std::vector<int> streamIds;
600     streamIds.push_back(-1);
601     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->ReleaseStreams(streamIds);
602 }
603 
604 /**
605   * @tc.name: Preview
606   * @tc.desc: Preview, CommitStreams without CreateStreams, expected fail.
607   * @tc.level: Level2
608   * @tc.size: MediumTest
609   * @tc.type: Function
610   */
611 HWTEST_F(CameraPreviewTest, camera_preview_050, TestSize.Level2)
612 {
613     CAMERA_LOGD("Preview, CommitStreams without CreateStreams, expected fail.");
614     // Create and get streamOperator information
615     cameraBase_->AchieveStreamOperator();
616     // Distribution stream
617     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CommitStreams(NORMAL, cameraBase_->ability_);
618     CAMERA_LOGD("streamOperator->CommitStreams's RetCode = %{public}d", cameraBase_->rc);
619     EXPECT_EQ(true, cameraBase_->rc == INVALID_ARGUMENT);
620     // release stream
621     std::vector<int> streamIds;
622     streamIds.push_back(-1);
623     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->ReleaseStreams(streamIds);
624 }
625 
626 /**
627   * @tc.name: Preview
628   * @tc.desc: Preview  and release streams, success.
629   * @tc.level: Level1
630   * @tc.size: MediumTest
631   * @tc.type: Function
632   */
633 HWTEST_F(CameraPreviewTest, camera_preview_060, TestSize.Level1)
634 {
635     CAMERA_LOGD("Preview  and release streams, success.");
636     // Create and get streamOperator information
637     cameraBase_->AchieveStreamOperator();
638     // Create data stream
639     if (cameraBase_->streamCustomerPreview_ == nullptr) {
640         cameraBase_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
641     }
642     OHOS::sptr<OHOS::IBufferProducer> producer = cameraBase_->streamCustomerPreview_->CreateProducer();
643     producer->SetQueueSize(8); // 8:set bufferQueue size
644     if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
645         CAMERA_LOGE("~~~~~~~");
646     }
647     std::vector<StreamInfo> streamInfos;
648     StreamInfo streamInfo = {};
649     streamInfo.streamId_ = 1001;
650     streamInfo.width_ = 640; // 640:picture width
651     streamInfo.height_ = 480; // 480:picture height
652     streamInfo.format_ = PIXEL_FMT_RGBA_8888;
653     streamInfo.dataspace_ = 8; // 8:picture dataspace
654     streamInfo.intent_ = PREVIEW;
655     streamInfo.tunneledMode_ = 5; // 5:tunnel mode
656     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
657     ASSERT_NE(streamInfo.bufferQueue_, nullptr);
658     std::vector<StreamInfo>().swap(streamInfos);
659     streamInfos.push_back(streamInfo);
660     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CreateStreams(streamInfos);
661     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
662     // Distribution stream
663     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CommitStreams(NORMAL, cameraBase_->ability_);
664     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
665     // Get preview
666     int captureId = 2001;
667     CaptureInfo captureInfo = {};
668     captureInfo.streamIds_ = {1001};
669     captureInfo.captureSetting_ = cameraBase_->ability_;
670     captureInfo.enableShutterCallback_ = false;
671     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->Capture(captureId, captureInfo, true);
672     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
673     sleep(3);
674     cameraBase_->streamOperator->CancelCapture(captureId);
675     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
676     // release stream
677     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->ReleaseStreams(captureInfo.streamIds_);
678     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
679 }
680 
681 /**
682   * @tc.name: Preview
683   * @tc.desc: ReleaseStreams-> streamID = -1, expected INVALID_ARGUMENT.
684   * @tc.level: Level2
685   * @tc.size: MediumTest
686   * @tc.type: Function
687   */
688 HWTEST_F(CameraPreviewTest, camera_preview_061, TestSize.Level2)
689 {
690     CAMERA_LOGD("ReleaseStreams-> streamID = -1, expected success.");
691     // Create and get streamOperator information
692     cameraBase_->AchieveStreamOperator();
693     // Create preview stream
694     // std::shared_ptr<OHOS::IBufferProducer> producer = OHOS::IBufferProducer::CreateBufferQueue();
695     if (cameraBase_->streamCustomerPreview_ == nullptr) {
696         cameraBase_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
697     }
698     OHOS::sptr<OHOS::IBufferProducer> producer = cameraBase_->streamCustomerPreview_->CreateProducer();
699     producer->SetQueueSize(8); // 8:set bufferQueue size
700     if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
701         CAMERA_LOGE("~~~~~~~");
702     }
703     std::vector<StreamInfo> streamInfos;
704     StreamInfo streamInfo = {};
705     streamInfo.streamId_ = 1001;
706     streamInfo.width_ = 640; // 640:picture width
707     streamInfo.height_ = 480; // 480:picture height
708     streamInfo.format_ = PIXEL_FMT_RGBA_8888;
709     streamInfo.dataspace_ = 8; // 8:picture dataspace
710     streamInfo.intent_ = PREVIEW;
711     streamInfo.tunneledMode_ = 5; // 5:tunnel mode
712     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
713     ASSERT_NE(streamInfo.bufferQueue_, nullptr);
714     std::vector<StreamInfo>().swap(streamInfos);
715     streamInfos.push_back(streamInfo);
716     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CreateStreams(streamInfos);
717     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
718     // Distribution stream
719     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CommitStreams(NORMAL, cameraBase_->ability_);
720     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
721     // Get preview
722     int captureId = 2001;
723     CaptureInfo captureInfo = {};
724     captureInfo.streamIds_ = {1001};
725     captureInfo.captureSetting_ = cameraBase_->ability_;
726     captureInfo.enableShutterCallback_ = false;
727     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->Capture(captureId, captureInfo, true);
728     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
729     sleep(3);
730     cameraBase_->streamOperator->CancelCapture(captureId);
731     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
732     // release stream
733     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->ReleaseStreams(
734         {-1});
735     CAMERA_LOGD("streamOperator->ReleaseStreams's rc = %{public}d", cameraBase_->rc);
736     EXPECT_EQ(true, cameraBase_->rc == INVALID_ARGUMENT);
737     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->ReleaseStreams(
738         {1001});
739     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
740     CAMERA_LOGD("streamOperator->ReleaseStreams's RetCode = %{public}d", cameraBase_->rc);
741 }
742 
743 /**
744   * @tc.name: Preview
745   * @tc.desc: ReleaseStreams no exist streamID, expect success.
746   * @tc.level: Level2
747   * @tc.size: MediumTest
748   * @tc.type: Function
749   */
750 HWTEST_F(CameraPreviewTest, camera_preview_062, TestSize.Level2)
751 {
752     CAMERA_LOGD("ReleaseStreams no exist streamID, expect success.");
753     // Create and get streamOperator information
754     cameraBase_->AchieveStreamOperator();
755     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->ReleaseStreams(
756         {9999});
757     CAMERA_LOGD("streamOperator->ReleaseStreams's RetCode = %{public}d", cameraBase_->rc);
758     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
759 }
760 
761 /**
762   * @tc.name: Preview
763   * @tc.desc: Preview, Capture->captureInfo->streamID = -1 ,return error.
764   * @tc.level: Level2
765   * @tc.size: MediumTest
766   * @tc.type: Function
767   */
768 HWTEST_F(CameraPreviewTest, camera_preview_070, TestSize.Level2)
769 {
770     CAMERA_LOGD("Preview, Capture->captureInfo->streamID = -1 ,return error.");
771     // Create and get streamOperator information
772     cameraBase_->AchieveStreamOperator();
773     // Create preview stream
774     // std::shared_ptr<OHOS::IBufferProducer> producer = OHOS::IBufferProducer::CreateBufferQueue();
775     if (cameraBase_->streamCustomerPreview_ == nullptr) {
776         cameraBase_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
777     }
778     OHOS::sptr<OHOS::IBufferProducer> producer = cameraBase_->streamCustomerPreview_->CreateProducer();
779     producer->SetQueueSize(8); // 8:set bufferQueue size
780     if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
781         CAMERA_LOGE("~~~~~~~");
782     }
783 
784     std::vector<StreamInfo> streamInfos;
785     StreamInfo streamInfo = {};
786     streamInfo.streamId_ = 1001;
787     streamInfo.width_ = 640; // 640:picture width
788     streamInfo.height_ = 480; // 480:picture height
789     streamInfo.format_ = PIXEL_FMT_RGBA_8888;
790     streamInfo.dataspace_ = 8; // 8:picture dataspace
791     streamInfo.intent_ = PREVIEW;
792     streamInfo.tunneledMode_ = 5; // 5:tunnel mode
793     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
794     ASSERT_NE(streamInfo.bufferQueue_, nullptr);
795     std::vector<StreamInfo>().swap(streamInfos);
796     streamInfos.push_back(streamInfo);
797     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CreateStreams(streamInfos);
798     if (cameraBase_->rc != HDI::Camera::V1_0::NO_ERROR) {
799         CAMERA_LOGE("CreateStreams failed!");
800     }
801     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
802     // Distribution stream
803     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CommitStreams(NORMAL, cameraBase_->ability_);
804     if (cameraBase_->rc != HDI::Camera::V1_0::NO_ERROR) {
805         CAMERA_LOGE("CommitStreams failed!");
806     }
807     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
808     // Get preview
809     int captureId = 2001;
810     CaptureInfo captureInfo = {};
811     captureInfo.streamIds_ = {-1};
812     captureInfo.captureSetting_ = cameraBase_->ability_;
813     captureInfo.enableShutterCallback_ = true;
814     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->Capture(captureId, captureInfo, true);
815     CAMERA_LOGD("streamOperator->Capture rc = %{public}d", cameraBase_->rc);
816     if (cameraBase_->rc == INVALID_ARGUMENT) {
817         CAMERA_LOGE("Capture failed!");
818     }
819     EXPECT_EQ(INVALID_ARGUMENT, cameraBase_->rc);
820 }
821 
822 /**
823   * @tc.name: Preview
824   * @tc.desc: Preview, Capture->isStreaming = false ,expected success.
825   * @tc.level: Level2
826   * @tc.size: MediumTest
827   * @tc.type: Function
828   */
829 HWTEST_F(CameraPreviewTest, camera_preview_073, TestSize.Level2)
830 {
831     CAMERA_LOGD("Preview, Capture->isStreaming = false ,expected success.");
832     // Create and get streamOperator information
833     cameraBase_->AchieveStreamOperator();
834     // Create data stream
835     cameraBase_->intents = {PREVIEW};
836     cameraBase_->StartStream(cameraBase_->intents);
837     // Get preview
838     int captureId = 2001;
839     CaptureInfo captureInfo = {};
840     captureInfo.streamIds_ = {cameraBase_->STREAM_ID_PREVIEW};
841     captureInfo.captureSetting_ = cameraBase_->ability_;
842     captureInfo.enableShutterCallback_ = true;
843     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->Capture(captureId, captureInfo, false);
844     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
845     sleep(3);
846     cameraBase_->streamOperator->CancelCapture(captureId);
847     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
848     // release stream
849     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->ReleaseStreams(captureInfo.streamIds_);
850     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
851 }
852 
853 /**
854   * @tc.name: Preview
855   * @tc.desc: Preview, Capture->captureId = -1 ,return error.
856   * @tc.level: Level2
857   * @tc.size: MediumTest
858   * @tc.type: Function
859   */
860 HWTEST_F(CameraPreviewTest, camera_preview_074, TestSize.Level2)
861 {
862     CAMERA_LOGD("Preview, Capture->captureId = -1 ,return error.");
863     // Create and get streamOperator information
864     cameraBase_->AchieveStreamOperator();
865     // Create data stream
866     cameraBase_->intents = {PREVIEW};
867     cameraBase_->StartStream(cameraBase_->intents);
868     // Get preview
869     int captureId = -1;
870     CaptureInfo captureInfo = {};
871     captureInfo.streamIds_ = {cameraBase_->STREAM_ID_PREVIEW};
872     captureInfo.captureSetting_ = cameraBase_->ability_;
873     captureInfo.enableShutterCallback_ = false;
874     bool isStreaming = true;
875     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->Capture(captureId, captureInfo, isStreaming);
876     EXPECT_EQ(INVALID_ARGUMENT, cameraBase_->rc);
877 }
878 
879 /**
880   * @tc.name: Preview
881   * @tc.desc: Preview, Capture->captureInfo->enableShutterCallback = true ,return success.
882   * @tc.level: Level2
883   * @tc.size: MediumTest
884   * @tc.type: Function
885   */
886 HWTEST_F(CameraPreviewTest, camera_preview_075, TestSize.Level2)
887 {
888     CAMERA_LOGD("Preview, Capture->captureInfo->enableShutterCallback = true, return success.");
889     // Create and get streamOperator information
890     cameraBase_->AchieveStreamOperator();
891     // Create data stream
892     cameraBase_->intents = {PREVIEW};
893     cameraBase_->StartStream(cameraBase_->intents);
894     // Get preview
895     cameraBase_->StartCapture(cameraBase_->STREAM_ID_PREVIEW, cameraBase_->CAPTURE_ID_PREVIEW, true, true);
896     // release stream
897     cameraBase_->captureIds = {cameraBase_->CAPTURE_ID_PREVIEW};
898     cameraBase_->streamIds = {cameraBase_->STREAM_ID_PREVIEW};
899     cameraBase_->StopStream(cameraBase_->captureIds, cameraBase_->streamIds);
900 }
901 
902 /**
903   * @tc.name: Preview
904   * @tc.desc: CancelCapture captureID = -1.
905   * @tc.level: Level2
906   * @tc.size: MediumTest
907   * @tc.type: Function
908   */
909 HWTEST_F(CameraPreviewTest, camera_preview_080, TestSize.Level2)
910 {
911     CAMERA_LOGD("CancelCapture captureID = -1, expected fail.");
912     // Create and get streamOperator information
913     cameraBase_->AchieveStreamOperator();
914     // Create data stream
915     if (cameraBase_->streamCustomerPreview_ == nullptr) {
916         cameraBase_->streamCustomerPreview_ = std::make_shared<StreamCustomer>();
917     }
918     OHOS::sptr<OHOS::IBufferProducer> producer = cameraBase_->streamCustomerPreview_->CreateProducer();
919     producer->SetQueueSize(8); // 8:set bufferQueue size
920     if (producer->GetQueueSize() != 8) { // 8:get bufferQueue size
921         CAMERA_LOGE("~~~~~~~");
922     }
923 
924     std::vector<StreamInfo> streamInfos;
925     StreamInfo streamInfo = {};
926     streamInfo.streamId_ = 1001;
927     streamInfo.width_ = 640; // 640:picture width
928     streamInfo.height_ = 480; // 480:picture height
929     streamInfo.format_ = PIXEL_FMT_RGBA_8888;
930     streamInfo.dataspace_ = 8; // 8:picture dataspace
931     streamInfo.intent_ = PREVIEW;
932     streamInfo.tunneledMode_ = 5; // 5:tunnel mode
933     streamInfo.bufferQueue_ = new BufferProducerSequenceable(producer);
934     ASSERT_NE(streamInfo.bufferQueue_, nullptr);
935     std::vector<StreamInfo>().swap(streamInfos);
936     streamInfos.push_back(streamInfo);
937     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CreateStreams(streamInfos);
938     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
939     // Distribution stream
940     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CommitStreams(NORMAL, cameraBase_->ability_);
941     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
942     // Get preview
943     int captureId = 100;
944     CaptureInfo captureInfo = {};
945     captureInfo.streamIds_ = {1001};
946     captureInfo.captureSetting_ = cameraBase_->ability_;
947     captureInfo.enableShutterCallback_ = false;
948     bool isStreaming = true;
949     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->Capture(captureId, captureInfo, isStreaming);
950     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
951     sleep(3);
952     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CancelCapture(-1);
953     EXPECT_EQ(INVALID_ARGUMENT, cameraBase_->rc);
954     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CancelCapture(captureId);
955     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
956     // release stream
957     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->ReleaseStreams(captureInfo.streamIds_);
958     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
959 }
960 
961 /**
962   * @tc.name: Preview
963   * @tc.desc: CancelCapture without Create capture.
964   * @tc.level: Level2
965   * @tc.size: MediumTest
966   * @tc.type: Function
967   */
968 HWTEST_F(CameraPreviewTest, camera_preview_090, TestSize.Level2)
969 {
970     CAMERA_LOGD("CancelCapture without Create capture.");
971     // Create and get streamOperator information
972     cameraBase_->AchieveStreamOperator();
973     // Create data stream
974     cameraBase_->intents = {PREVIEW};
975     cameraBase_->StartStream(cameraBase_->intents);
976     // Get preview
977     int captureId = 100;
978     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CancelCapture(captureId);
979     if (cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR) {
980         CAMERA_LOGI("CancelCapture success.");
981     } else {
982         CAMERA_LOGE("CancelCapture fail, rc = %{public}d", cameraBase_->rc);
983     }
984 }
985 
986 /**
987   * @tc.name: Preview
988   * @tc.desc: The same CaptureID, Create capture twice, expected fail.
989   * @tc.level: Level2
990   * @tc.size: MediumTest
991   * @tc.type: Function
992   */
993 HWTEST_F(CameraPreviewTest, camera_preview_092, TestSize.Level2)
994 {
995     CAMERA_LOGD("The same CaptureID, Create capture twice, expected fail.");
996     // Create and get streamOperator information
997     cameraBase_->AchieveStreamOperator();
998     // start stream
999     cameraBase_->intents = {PREVIEW};
1000     cameraBase_->StartStream(cameraBase_->intents);
1001 
1002     int captureId = cameraBase_->CAPTURE_ID_PREVIEW;
1003     CaptureInfo captureInfo = {};
1004     captureInfo.streamIds_ = {cameraBase_->STREAM_ID_PREVIEW};
1005     captureInfo.captureSetting_ = cameraBase_->ability_;
1006     captureInfo.enableShutterCallback_ = false;
1007     bool isStreaming = true;
1008     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->Capture(captureId, captureInfo, isStreaming);
1009     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
1010 
1011     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->Capture(captureId, captureInfo, isStreaming);
1012     EXPECT_EQ(false, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
1013 
1014     sleep(2);
1015     // cancel capture
1016     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->CancelCapture(captureId);
1017     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
1018 
1019     // release stream
1020     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->ReleaseStreams(captureInfo.streamIds_);
1021     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
1022 }
1023 
1024 /**
1025   * @tc.name: Preview
1026   * @tc.desc: Different captureIDs, Create capture,expected success.
1027   * @tc.level: Level2
1028   * @tc.size: MediumTest
1029   * @tc.type: Function
1030   */
1031 HWTEST_F(CameraPreviewTest, camera_preview_093, TestSize.Level2)
1032 {
1033     CAMERA_LOGD("Different captureIDs, Create capture,expected success.");
1034     // Create and get streamOperator information
1035     cameraBase_->AchieveStreamOperator();
1036     // Create data stream
1037     cameraBase_->intents = {PREVIEW};
1038     cameraBase_->StartStream(cameraBase_->intents);
1039     // Get preview
1040     int captureId = cameraBase_->CAPTURE_ID_PREVIEW;
1041     CaptureInfo captureInfo = {};
1042     captureInfo.streamIds_ = {cameraBase_->STREAM_ID_PREVIEW};
1043     captureInfo.captureSetting_ = cameraBase_->ability_;
1044     captureInfo.enableShutterCallback_ = false;
1045     bool isStreaming = true;
1046     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->Capture(captureId, captureInfo, isStreaming);
1047     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
1048     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->Capture(captureId + 1, captureInfo, isStreaming);
1049     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
1050 
1051     sleep(2);
1052     // cancel capture
1053     cameraBase_->streamOperator->CancelCapture(captureId);
1054     cameraBase_->streamOperator->CancelCapture(captureId + 1);
1055     // release stream
1056     cameraBase_->rc = (CamRetCode)cameraBase_->streamOperator->ReleaseStreams(captureInfo.streamIds_);
1057     EXPECT_EQ(true, cameraBase_->rc == HDI::Camera::V1_0::NO_ERROR);
1058 }
1059 
1060