• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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 
16 #include <thread>
17 #include <unistd.h>
18 #include <vector>
19 #include <gtest/gtest.h>
20 #include "stream_pipeline_strategy.h"
21 #include "stream_pipeline_builder.h"
22 
23 using namespace testing::ext;
24 namespace OHOS::Camera {
25 class BuilderTest : public testing::Test {
26 public:
27     static void SetUpTestCase(void);
28     static void TearDownTestCase(void);
29 
30     void SetUp(void);
31     void TearDown(void);
32 protected:
33     std::shared_ptr<PipelineSpec> spec_ = nullptr;
34 };
35 
SetUpTestCase(void)36 void BuilderTest::SetUpTestCase(void)
37 {
38     std::cout << "Camera::Builder SetUpTestCase" << std::endl;
39 }
40 
TearDownTestCase(void)41 void BuilderTest::TearDownTestCase(void)
42 {
43     std::cout << "Camera::Builder TearDownTestCase" << std::endl;
44 }
45 
SetUp(void)46 void BuilderTest::SetUp(void)
47 {
48     std::cout << "Camera::Builder SetUp" << std::endl;
49 }
50 
TearDown(void)51 void BuilderTest::TearDown(void)
52 {
53     spec_.reset();
54     std::cout << "Camera::Builder TearDown.." << std::endl;
55 }
56 
57 HWTEST_F(BuilderTest, NormalTest, TestSize.Level0)
58 {
59     std::shared_ptr<HostStreamMgr> streamMgr = HostStreamMgr::Create();
60     streamMgr->CreateHostStream({
61                 .type_ = STILL_CAPTURE
62                 }, nullptr);
63     streamMgr->CreateHostStream({
64                 .type_ = PREVIEW
65                 }, nullptr);
66     std::unique_ptr<StreamPipelineStrategy> s = StreamPipelineStrategy::Create(streamMgr);
67     EXPECT_TRUE(s != nullptr);
68     spec_ = s->GeneratePipelineSpec(0);
69     EXPECT_TRUE(spec_ != nullptr);
70 
71     std::unique_ptr<StreamPipelineBuilder> b = StreamPipelineBuilder::Create(streamMgr);
72     EXPECT_TRUE(b != nullptr);
73     std::shared_ptr<Pipeline> pipeline = b->Build(spec_);
74     EXPECT_TRUE(pipeline != nullptr);
75 }
76 
77 HWTEST_F(BuilderTest, AbNormalTest, TestSize.Level0)
78 {
79     std::shared_ptr<HostStreamMgr> streamMgr = HostStreamMgr::Create();
80     streamMgr->CreateHostStream({
81                 .type_ = PREVIEW
82                 }, nullptr);
83     streamMgr->CreateHostStream({
84                 .type_ = STILL_CAPTURE
85                 }, nullptr);
86     std::unique_ptr<StreamPipelineBuilder> b = StreamPipelineBuilder::Create(streamMgr);
87     EXPECT_TRUE(b != nullptr);
88     std::shared_ptr<Pipeline> pipeline = b->Build(spec_);
89     EXPECT_TRUE(pipeline == nullptr);
90 }
91 }
92