1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file expected in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "logic_camera_test.h" 17 18constexpr int QUEUE_SIZE = 8; 19constexpr int DEFAULT_TEST_DATASPACE_VALUE = 8; 20constexpr int DEFAULT_TEST_TUNNELEDMODE_VALUE = 5; 21 22void UtestLogicCameraTest::SetUpTestCase(void) 23{} 24void UtestLogicCameraTest::TearDownTestCase(void) 25{} 26void UtestLogicCameraTest::SetUp(void) 27{ 28 if (cameraBase == nullptr) 29 cameraBase = std::make_shared<TestCameraBase>(); 30 cameraBase->FBInit(); 31 cameraBase->Init(); 32} 33void UtestLogicCameraTest::TearDown(void) 34{ 35 cameraBase->Close(); 36} 37 38/** 39 * @tc.name: test logic csamera 40 * @tc.desc: single stream 41 * @tc.level: Level0 42 * @tc.size: MediumTest 43 * @tc.type: Function 44 */ 45TEST_F(UtestLogicCameraTest, camera_logic_0001) 46{ 47 std::cout << "==========[test log] test single stream"<< std::endl; 48 // Get the stream manager 49 cameraBase->AchieveStreamOperator(); 50 // Configure preview stream information 51 std::shared_ptr<IBufferProducer> producer = IBufferProducer::CreateBufferQueue(); 52 producer->SetQueueSize(QUEUE_SIZE); 53 if (producer->GetQueueSize() != QUEUE_SIZE) { 54 std::cout << "~~~~~~~" << std::endl; 55 } 56 auto callback = [this](std::shared_ptr<SurfaceBuffer> b) { 57 cameraBase->BufferCallback(b, cameraBase->preview_mode); 58 return; 59 }; 60 producer->SetCallback(callback); 61 std::shared_ptr<StreamInfo> streamInfoPre = std::make_shared<StreamInfo>(); 62 streamInfoPre->streamId_ = cameraBase->STREAM_ID_PREVIEW; 63 streamInfoPre->width_ = DEFAULT_TEST_WIDTH_VALUE; 64 streamInfoPre->height_ = DEFAULT_TEST_HEIGHT_VALUE; 65 streamInfoPre->format_ = CAMERA_FORMAT_YUYV_422_PKG; 66 streamInfoPre->dataspace_ = DEFAULT_TEST_DATASPACE_VALUE; 67 streamInfoPre->intent_ = PREVIEW; 68 streamInfoPre->tunneledMode_ = DEFAULT_TEST_TUNNELEDMODE_VALUE; 69 streamInfoPre->bufferQueue_ = producer; 70 cameraBase->streamInfos.push_back(streamInfoPre); 71 cameraBase->rc = cameraBase->streamOperator->CreateStreams(cameraBase->streamInfos); 72 EXPECT_EQ(true, cameraBase->rc == NO_ERROR); 73 if (cameraBase->rc == NO_ERROR) { 74 std::cout << "==========[test log] CreateStreams success, streamId = "; 75 std::cout << cameraBase->STREAM_ID_CAPTURE, <<", intent = STILL_CAPTURE" << std::endl; 76 } else { 77 std::cout << "==========[test log] CreateStreams fail, rc = " << cameraBase->rc <<" , streamId = "; 78 std::cout << cameraBase->STREAM_ID_CAPTURE, <<", intent = STILL_CAPTURE" << std::endl; 79 } 80 // Submit stream information 81 cameraBase->rc = cameraBase->streamOperator->CommitStreams(DUAL, nullptr); 82 EXPECT_EQ(false, cameraBase->rc != NO_ERROR); 83 if (cameraBase->rc == NO_ERROR) { 84 std::cout << "==========[test log] CommitStreams DUAL success." << std::endl; 85 } else { 86 std::cout << "==========[test log] CommitStreams DUAL fail, rc = " << cameraBase->rc << std::endl; 87 } 88 // capture 89 cameraBase->StartCapture(cameraBase->STREAM_ID_PREVIEW, cameraBase->CAPTURE_ID_PREVIEW, false, true); 90 // post-processing 91 cameraBase->captureIds = {cameraBase->CAPTURE_ID_PREVIEW}; 92 cameraBase->streamIds = {cameraBase->STREAM_ID_PREVIEW}; 93 cameraBase->StopStream(cameraBase->captureIds, cameraBase->streamIds); 94}