• 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 #include "stream_pipeline_dispatcher.h"
23 
24 using namespace testing::ext;
25 namespace OHOS::Camera {
26 class DispatcherTest : public testing::Test {
27 public:
28     static void SetUpTestCase(void);
29     static void TearDownTestCase(void);
30 
31     void SetUp(void);
32     void TearDown(void);
33 };
34 
SetUpTestCase(void)35 void DispatcherTest::SetUpTestCase(void)
36 {
37     std::cout << "Camera::DispatcherTest SetUpTestCase" << std::endl;
38 }
39 
TearDownTestCase(void)40 void DispatcherTest::TearDownTestCase(void)
41 {
42     std::cout << "Camera::DispatcherTest TearDownTestCase" << std::endl;
43 }
44 
SetUp(void)45 void DispatcherTest::SetUp(void)
46 {
47     std::cout << "Camera::DispatcherTest SetUp" << std::endl;
48 }
49 
TearDown(void)50 void DispatcherTest::TearDown(void)
51 {
52     std::cout << "Camera::DispatcherTest TearDown.." << std::endl;
53 }
54 
55 HWTEST_F(DispatcherTest, NormalTest, TestSize.Level0)
56 {
57     std::shared_ptr<HostStreamMgr> streamMgr = HostStreamMgr::Create();
58     streamMgr->CreateHostStream({
59                 .type_ = PREVIEW
60                 }, nullptr);
61     streamMgr->CreateHostStream({
62                 .type_ = STILL_CAPTURE
63                 }, nullptr);
64     std::unique_ptr<StreamPipelineStrategy> s = StreamPipelineStrategy::Create(streamMgr);
65     EXPECT_TRUE(s != nullptr);
66     std::shared_ptr<PipelineSpec> spec_ = s->GeneratePipelineSpec(0);
67     EXPECT_TRUE(spec_ != nullptr);
68 
69     std::unique_ptr<StreamPipelineBuilder> b = StreamPipelineBuilder::Create(streamMgr);
70     EXPECT_TRUE(b != nullptr);
71     std::shared_ptr<Pipeline> pipeline = b->Build(spec_);
72     EXPECT_TRUE(pipeline != nullptr);
73     std::unique_ptr<StreamPipelineDispatcher> d = StreamPipelineDispatcher::Create();
74     EXPECT_TRUE(d != nullptr);
75     RetCode re = d->Update(pipeline);
76     EXPECT_TRUE(re == RC_OK);
77 }
78 
79 HWTEST_F(DispatcherTest, ConfigTest, TestSize.Level0)
80 {
81     std::shared_ptr<HostStreamMgr> streamMgrConf = HostStreamMgr::Create();
82     streamMgrConf->CreateHostStream({
83                 .type_ = PREVIEW
84                 }, nullptr);
85     streamMgrConf->CreateHostStream({
86                 .type_ = STILL_CAPTURE
87                 }, nullptr);
88     std::unique_ptr<StreamPipelineStrategy> s = StreamPipelineStrategy::Create(streamMgrConf);
89     EXPECT_TRUE(s != nullptr);
90     std::shared_ptr<PipelineSpec> spec_ = s->GeneratePipelineSpec(0);
91     EXPECT_TRUE(spec_ != nullptr);
92 
93     std::unique_ptr<StreamPipelineBuilder> b = StreamPipelineBuilder::Create(streamMgrConf);
94     EXPECT_TRUE(b != nullptr);
95     std::shared_ptr<Pipeline> pipeline = b->Build(spec_);
96     EXPECT_TRUE(pipeline != nullptr);
97     std::unique_ptr<StreamPipelineDispatcher> d = StreamPipelineDispatcher::Create();
98     EXPECT_TRUE(d != nullptr);
99     RetCode re = d->Update(pipeline);
100     EXPECT_TRUE(re == RC_OK);
101 }
102 
103 HWTEST_F(DispatcherTest, AbConfigTest, TestSize.Level0)
104 {
105     std::shared_ptr<HostStreamMgr> streamMgrAbConf = HostStreamMgr::Create();
106     streamMgrAbConf->CreateHostStream({
107                 .type_ = PREVIEW
108                 }, nullptr);
109     streamMgrAbConf->CreateHostStream({
110                 .type_ = STILL_CAPTURE
111                 }, nullptr);
112     std::unique_ptr<StreamPipelineStrategy> s = StreamPipelineStrategy::Create(streamMgrAbConf);
113     EXPECT_TRUE(s != nullptr);
114     std::shared_ptr<PipelineSpec> spec_ = s->GeneratePipelineSpec(0);
115     EXPECT_TRUE(spec_ != nullptr);
116 
117     std::unique_ptr<StreamPipelineBuilder> b = StreamPipelineBuilder::Create(streamMgrAbConf);
118     EXPECT_TRUE(b != nullptr);
119     std::shared_ptr<Pipeline> pipeline = b->Build(spec_);
120     EXPECT_TRUE(pipeline != nullptr);
121     std::unique_ptr<StreamPipelineDispatcher> d = StreamPipelineDispatcher::Create();
122     EXPECT_TRUE(d != nullptr);
123     RetCode re = d->Update(pipeline);
124     EXPECT_TRUE(re == RC_OK);
125 }
126 }
127