1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file expected in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci#include "pipeline_test.h" 17094332d3Sopenharmony_ci 18094332d3Sopenharmony_ciusing namespace OHOS; 19094332d3Sopenharmony_ciusing namespace std; 20094332d3Sopenharmony_ciusing namespace testing::ext; 21094332d3Sopenharmony_ciusing namespace OHOS::Camera; 22094332d3Sopenharmony_ci 23094332d3Sopenharmony_civoid PipelineTest::SetUpTestCase(void) {} 24094332d3Sopenharmony_civoid PipelineTest::TearDownTestCase(void) {} 25094332d3Sopenharmony_civoid PipelineTest::SetUp(void) 26094332d3Sopenharmony_ci{ 27094332d3Sopenharmony_ci Test_ = std::make_shared<OHOS::Camera::Test>(); 28094332d3Sopenharmony_ci Test_->Init(); 29094332d3Sopenharmony_ci Test_->Open(); 30094332d3Sopenharmony_ci} 31094332d3Sopenharmony_civoid PipelineTest::TearDown(void) 32094332d3Sopenharmony_ci{ 33094332d3Sopenharmony_ci Test_->Close(); 34094332d3Sopenharmony_ci} 35094332d3Sopenharmony_ci 36094332d3Sopenharmony_ci/** 37094332d3Sopenharmony_ci * @tc.name: Check ppl 38094332d3Sopenharmony_ci * @tc.desc: preview success. 39094332d3Sopenharmony_ci * @tc.size: MediumTest 40094332d3Sopenharmony_ci * @tc.type: Function 41094332d3Sopenharmony_ci */ 42094332d3Sopenharmony_ciHWTEST_F(PipelineTest, Camera_Ppl_0001, TestSize.Level0) 43094332d3Sopenharmony_ci{ 44094332d3Sopenharmony_ci std::cout << "==========[test log]Check ppl: preview success." << std::endl; 45094332d3Sopenharmony_ci // Start stream 46094332d3Sopenharmony_ci Test_->intents = {Camera::PREVIEW}; 47094332d3Sopenharmony_ci Test_->StartStream(Test_->intents); 48094332d3Sopenharmony_ci // Get preview 49094332d3Sopenharmony_ci Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 50094332d3Sopenharmony_ci // Release stream 51094332d3Sopenharmony_ci Test_->captureIds = {Test_->captureId_preview}; 52094332d3Sopenharmony_ci Test_->streamIds = {Test_->streamId_preview}; 53094332d3Sopenharmony_ci Test_->StopStream(Test_->captureIds, Test_->streamIds); 54094332d3Sopenharmony_ci Test_->StopConsumer(Test_->intents); 55094332d3Sopenharmony_ci} 56094332d3Sopenharmony_ci 57094332d3Sopenharmony_ci/** 58094332d3Sopenharmony_ci * @tc.name: Check ppl 59094332d3Sopenharmony_ci * @tc.desc: preview + capture success. 60094332d3Sopenharmony_ci * @tc.size: MediumTest 61094332d3Sopenharmony_ci * @tc.type: Function 62094332d3Sopenharmony_ci */ 63094332d3Sopenharmony_ciHWTEST_F(PipelineTest, Camera_Ppl_0002, TestSize.Level1) 64094332d3Sopenharmony_ci{ 65094332d3Sopenharmony_ci std::cout << "==========[test log]Check ppl: preview + capture success." << std::endl; 66094332d3Sopenharmony_ci // Configure two stream information 67094332d3Sopenharmony_ci Test_->intents = {Camera::PREVIEW, Camera::STILL_CAPTURE}; 68094332d3Sopenharmony_ci Test_->StartStream(Test_->intents); 69094332d3Sopenharmony_ci // Capture preview stream 70094332d3Sopenharmony_ci Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 71094332d3Sopenharmony_ci // Capture camera stream, continuous capture 72094332d3Sopenharmony_ci Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true); 73094332d3Sopenharmony_ci // Post-processing 74094332d3Sopenharmony_ci Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture}; 75094332d3Sopenharmony_ci Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture}; 76094332d3Sopenharmony_ci Test_->StopStream(Test_->captureIds, Test_->streamIds); 77094332d3Sopenharmony_ci} 78094332d3Sopenharmony_ci 79094332d3Sopenharmony_ci/** 80094332d3Sopenharmony_ci * @tc.name: Check ppl 81094332d3Sopenharmony_ci * @tc.desc: preview + video success. 82094332d3Sopenharmony_ci * @tc.size: MediumTest 83094332d3Sopenharmony_ci * @tc.type: Function 84094332d3Sopenharmony_ci */ 85094332d3Sopenharmony_ciHWTEST_F(PipelineTest, Camera_Ppl_0003, TestSize.Level1) 86094332d3Sopenharmony_ci{ 87094332d3Sopenharmony_ci std::cout << "==========[test log]Check ppl:Check ppl: preview + video success." << std::endl; 88094332d3Sopenharmony_ci // Configure two stream information 89094332d3Sopenharmony_ci Test_->intents = {Camera::PREVIEW, Camera::VIDEO}; 90094332d3Sopenharmony_ci Test_->StartStream(Test_->intents); 91094332d3Sopenharmony_ci // Capture preview stream 92094332d3Sopenharmony_ci Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 93094332d3Sopenharmony_ci // Capture video stream 94094332d3Sopenharmony_ci Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true); 95094332d3Sopenharmony_ci // Post-processing 96094332d3Sopenharmony_ci Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video}; 97094332d3Sopenharmony_ci Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video}; 98094332d3Sopenharmony_ci Test_->StopStream(Test_->captureIds, Test_->streamIds); 99094332d3Sopenharmony_ci} 100094332d3Sopenharmony_ci 101094332d3Sopenharmony_ci/** 102094332d3Sopenharmony_ci * @tc.name: Check ppl 103094332d3Sopenharmony_ci * @tc.desc: video mode without preview, system not support, expected return fail. 104094332d3Sopenharmony_ci * @tc.size: MediumTest 105094332d3Sopenharmony_ci * @tc.type: Function 106094332d3Sopenharmony_ci */ 107094332d3Sopenharmony_ciHWTEST_F(PipelineTest, Camera_Ppl_0004, TestSize.Level2) 108094332d3Sopenharmony_ci{ 109094332d3Sopenharmony_ci std::cout << "==========[test log]Check ppl:Video mode no preview, not support, expected fail." << std::endl; 110094332d3Sopenharmony_ci EXPECT_EQ(true, Test_->cameraDevice != nullptr); 111094332d3Sopenharmony_ci Test_->CreateStreamOperatorCallback(); 112094332d3Sopenharmony_ci Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator); 113094332d3Sopenharmony_ci EXPECT_EQ(Test_->rc, Camera::NO_ERROR); 114094332d3Sopenharmony_ci if (Test_->rc == Camera::NO_ERROR) { 115094332d3Sopenharmony_ci std::cout << "==========[test log]Check ppl: GetStreamOperator success." << std::endl; 116094332d3Sopenharmony_ci } else { 117094332d3Sopenharmony_ci std::cout << "==========[test log]Check ppl: GetStreamOperator fail, rc = " << Test_->rc << std::endl; 118094332d3Sopenharmony_ci } 119094332d3Sopenharmony_ci Test_->streamInfo = std::make_shared<Camera::StreamInfo>(); 120094332d3Sopenharmony_ci Test_->streamInfo->streamId_ = Test_->streamId_video; 121094332d3Sopenharmony_ci Test_->streamInfo->width_ = 640; 122094332d3Sopenharmony_ci Test_->streamInfo->height_ = 480; 123094332d3Sopenharmony_ci Test_->StreamInfoFormat(); 124094332d3Sopenharmony_ci Test_->streamInfo->dataspace_ = 10; 125094332d3Sopenharmony_ci Test_->streamInfo->intent_ = Camera::VIDEO; 126094332d3Sopenharmony_ci Test_->streamInfo->tunneledMode_ = 5; 127094332d3Sopenharmony_ci std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer = 128094332d3Sopenharmony_ci std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 129094332d3Sopenharmony_ci#ifdef CAMERA_BUILT_ON_OHOS_LITE 130094332d3Sopenharmony_ci Test_->streamInfo->bufferQueue_ = consumer->CreateProducer([this](OHOS::SurfaceBuffer* buffer) { 131094332d3Sopenharmony_ci Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize()); 132094332d3Sopenharmony_ci }); 133094332d3Sopenharmony_ci#else 134094332d3Sopenharmony_ci Test_->streamInfo->bufferQueue_ = consumer->CreateProducer([this](void* addr, uint32_t size) { 135094332d3Sopenharmony_ci Test_->SaveYUV("preview", addr, size); 136094332d3Sopenharmony_ci }); 137094332d3Sopenharmony_ci#endif 138094332d3Sopenharmony_ci Test_->streamInfo->bufferQueue_->SetQueueSize(8); 139094332d3Sopenharmony_ci Test_->consumerMap_[Camera::PREVIEW] = consumer; 140094332d3Sopenharmony_ci std::vector<std::shared_ptr<Camera::StreamInfo>>().swap(Test_->streamInfos); 141094332d3Sopenharmony_ci Test_->streamInfos.push_back(Test_->streamInfo); 142094332d3Sopenharmony_ci Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos); 143094332d3Sopenharmony_ci EXPECT_EQ(Test_->rc, Camera::NO_ERROR); 144094332d3Sopenharmony_ci std::cout << "==========[test log]CreateStreams rc = " << Test_->rc << std::endl; 145094332d3Sopenharmony_ci Test_->rc = Test_->streamOperator->CommitStreams(Camera::NORMAL, Test_->ability); 146094332d3Sopenharmony_ci EXPECT_EQ(Test_->rc, Camera::INVALID_ARGUMENT); 147094332d3Sopenharmony_ci std::cout << "==========[test log]CommitStreams rc = " << Test_->rc << std::endl; 148094332d3Sopenharmony_ci // Post-processing 149094332d3Sopenharmony_ci Test_->streamIds = {Test_->streamId_video}; 150094332d3Sopenharmony_ci Test_->StopStream(Test_->captureIds, Test_->streamIds); 151094332d3Sopenharmony_ci} 152094332d3Sopenharmony_ci 153094332d3Sopenharmony_ci/** 154094332d3Sopenharmony_ci * @tc.name: Only Still_capture stream 155094332d3Sopenharmony_ci * @tc.desc: Only Still_capture stream, capture->isStreaming = false. 156094332d3Sopenharmony_ci * @tc.size: MediumTest 157094332d3Sopenharmony_ci * @tc.type: Function 158094332d3Sopenharmony_ci */ 159094332d3Sopenharmony_ciHWTEST_F(PipelineTest, Camera_Ppl_0005, TestSize.Level1) 160094332d3Sopenharmony_ci{ 161094332d3Sopenharmony_ci std::cout << "==========[test log]check ppl: Still_capture stream, capture->isStreaming = false." << std::endl; 162094332d3Sopenharmony_ci // Start stream 163094332d3Sopenharmony_ci Test_->intents = {Camera::STILL_CAPTURE}; 164094332d3Sopenharmony_ci Test_->StartStream(Test_->intents); 165094332d3Sopenharmony_ci // Start capture 166094332d3Sopenharmony_ci Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, false); 167094332d3Sopenharmony_ci // Post-processing 168094332d3Sopenharmony_ci Test_->streamIds = {Test_->streamId_capture}; 169094332d3Sopenharmony_ci Test_->StopStream(Test_->captureIds, Test_->streamIds); 170094332d3Sopenharmony_ci} 171094332d3Sopenharmony_ci 172094332d3Sopenharmony_ci/** 173094332d3Sopenharmony_ci * @tc.name: Only Still_capture stream 174094332d3Sopenharmony_ci * @tc.desc: Only Still_capture stream, capture->isStreaming = true. 175094332d3Sopenharmony_ci * @tc.size: MediumTest 176094332d3Sopenharmony_ci * @tc.type: Function 177094332d3Sopenharmony_ci */ 178094332d3Sopenharmony_ciHWTEST_F(PipelineTest, Camera_Ppl_0006, TestSize.Level1) 179094332d3Sopenharmony_ci{ 180094332d3Sopenharmony_ci std::cout << "==========[test log]check ppl: Still_capture stream, capture->isStreaming = true." << std::endl; 181094332d3Sopenharmony_ci // Start stream 182094332d3Sopenharmony_ci Test_->intents = {Camera::STILL_CAPTURE}; 183094332d3Sopenharmony_ci Test_->StartStream(Test_->intents); 184094332d3Sopenharmony_ci // Start capture 185094332d3Sopenharmony_ci Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true); 186094332d3Sopenharmony_ci // Post-processing 187094332d3Sopenharmony_ci Test_->captureIds = {Test_->captureId_capture}; 188094332d3Sopenharmony_ci Test_->streamIds = {Test_->streamId_capture}; 189094332d3Sopenharmony_ci Test_->StopStream(Test_->captureIds, Test_->streamIds); 190094332d3Sopenharmony_ci} 191094332d3Sopenharmony_ci 192094332d3Sopenharmony_ci#ifndef CAMERA_BUILT_ON_OHOS_LITE 193094332d3Sopenharmony_ci/** 194094332d3Sopenharmony_ci * @tc.name: Check ppl 195094332d3Sopenharmony_ci * @tc.desc: double preview streams. 196094332d3Sopenharmony_ci * @tc.size: MediumTest 197094332d3Sopenharmony_ci * @tc.type: Function 198094332d3Sopenharmony_ci */ 199094332d3Sopenharmony_ciHWTEST_F(PipelineTest, Camera_Ppl_0007, TestSize.Level1) 200094332d3Sopenharmony_ci{ 201094332d3Sopenharmony_ci std::cout << "==========[test log]Check ppl: double preview streams." << std::endl; 202094332d3Sopenharmony_ci // Create and get streamOperator information 203094332d3Sopenharmony_ci Test_->streamOperatorCallback = new StreamOperatorCallback(); 204094332d3Sopenharmony_ci Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator); 205094332d3Sopenharmony_ci EXPECT_EQ(Test_->rc, Camera::NO_ERROR); 206094332d3Sopenharmony_ci // Create data stream 1 207094332d3Sopenharmony_ci Test_->streamInfo = std::make_shared<StreamInfo>(); 208094332d3Sopenharmony_ci Test_->streamInfo->streamId_ = Test_->streamId_preview; 209094332d3Sopenharmony_ci Test_->streamInfo->width_ = 1280; 210094332d3Sopenharmony_ci Test_->streamInfo->height_ = 960; 211094332d3Sopenharmony_ci Test_->streamInfo->dataspace_ = 8; 212094332d3Sopenharmony_ci Test_->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP; 213094332d3Sopenharmony_ci Test_->streamInfo->intent_ = Camera::PREVIEW; 214094332d3Sopenharmony_ci std::shared_ptr<OHOS::Camera::Test::StreamConsumer> preview_consumer = 215094332d3Sopenharmony_ci std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 216094332d3Sopenharmony_ci Test_->streamInfo->bufferQueue_ = preview_consumer->CreateProducer([this](void* addr, uint32_t size) { 217094332d3Sopenharmony_ci Test_->SaveYUV("preview", addr, size); 218094332d3Sopenharmony_ci }); 219094332d3Sopenharmony_ci Test_->streamInfo->bufferQueue_->SetQueueSize(8); 220094332d3Sopenharmony_ci Test_->consumerMap_[Camera::PREVIEW] = preview_consumer; 221094332d3Sopenharmony_ci Test_->streamInfo->tunneledMode_ = 5; 222094332d3Sopenharmony_ci std::vector<std::shared_ptr<StreamInfo>>().swap(Test_->streamInfos); 223094332d3Sopenharmony_ci Test_->streamInfos.push_back(Test_->streamInfo); 224094332d3Sopenharmony_ci 225094332d3Sopenharmony_ci // Create data stream 2 226094332d3Sopenharmony_ci Test_->streamInfo2 = std::make_shared<StreamInfo>(); 227094332d3Sopenharmony_ci Test_->streamInfo2->streamId_ = Test_->streamId_preview_double; 228094332d3Sopenharmony_ci Test_->streamInfo2->width_ = 1280; 229094332d3Sopenharmony_ci Test_->streamInfo2->height_ = 960; 230094332d3Sopenharmony_ci Test_->streamInfo2->dataspace_ = 8; 231094332d3Sopenharmony_ci Test_->streamInfo2->format_ = PIXEL_FMT_YCRCB_420_SP; 232094332d3Sopenharmony_ci Test_->streamInfo2->intent_ = Camera::PREVIEW; 233094332d3Sopenharmony_ci std::shared_ptr<OHOS::Camera::Test::StreamConsumer> preview_consumer2 = 234094332d3Sopenharmony_ci std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 235094332d3Sopenharmony_ci Test_->streamInfo2->bufferQueue_ = preview_consumer2->CreateProducer([this](void* addr, uint32_t size) { 236094332d3Sopenharmony_ci Test_->SaveYUV("preview2", addr, size); 237094332d3Sopenharmony_ci }); 238094332d3Sopenharmony_ci Test_->streamInfo2->bufferQueue_->SetQueueSize(8); 239094332d3Sopenharmony_ci Test_->consumerMap_[Camera::PREVIEW] = preview_consumer2; 240094332d3Sopenharmony_ci Test_->streamInfo2->tunneledMode_ = 5; 241094332d3Sopenharmony_ci Test_->streamInfos.push_back(Test_->streamInfo2); 242094332d3Sopenharmony_ci 243094332d3Sopenharmony_ci Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos); 244094332d3Sopenharmony_ci EXPECT_EQ(Test_->rc, Camera::NO_ERROR); 245094332d3Sopenharmony_ci // Flow distribution 246094332d3Sopenharmony_ci Test_->rc = Test_->streamOperator->CommitStreams(Camera::NORMAL, Test_->ability); 247094332d3Sopenharmony_ci EXPECT_EQ(Test_->rc, Camera::NO_ERROR); 248094332d3Sopenharmony_ci // Get preview 249094332d3Sopenharmony_ci Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 250094332d3Sopenharmony_ci Test_->StartCapture(Test_->streamId_preview_double, Test_->captureId_preview_double, false, true); 251094332d3Sopenharmony_ci // Release stream 252094332d3Sopenharmony_ci Test_->captureIds = {Test_->captureId_preview, Test_->captureId_preview_double}; 253094332d3Sopenharmony_ci Test_->streamIds = {Test_->streamId_preview, Test_->streamId_preview_double}; 254094332d3Sopenharmony_ci Test_->StopStream(Test_->captureIds, Test_->streamIds); 255094332d3Sopenharmony_ci} 256094332d3Sopenharmony_ci#endif