• 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 "ipipeline_core.h"
21 
22 using namespace testing::ext;
23 namespace OHOS::Camera {
24 enum testStreamId {
25     PREVIEW_ID,
26     VIDEO_ID,
27     CAPTURE_ID,
28 };
29 class PipelineCoreTest : public testing::Test {
30 public:
31     static void SetUpTestCase(void);
32     static void TearDownTestCase(void);
33 
34     void SetUp(void);
35     void TearDown(void);
36 };
37 
SetUpTestCase(void)38 void PipelineCoreTest::SetUpTestCase(void)
39 {
40     std::cout << "Camera::PipelineCore SetUpTestCase" << std::endl;
41 }
42 
TearDownTestCase(void)43 void PipelineCoreTest::TearDownTestCase(void)
44 {
45     std::cout << "Camera::PipelineCore TearDownTestCase" << std::endl;
46 }
47 
SetUp(void)48 void PipelineCoreTest::SetUp(void)
49 {
50     std::cout << "Camera::PipelineCore SetUp" << std::endl;
51 }
52 
TearDown(void)53 void PipelineCoreTest::TearDown(void)
54 {
55     std::cout << "Camera::PipelineCore TearDown.." << std::endl;
56 }
57 
58 HWTEST_F(PipelineCoreTest, PipelineCore_NormalPreviewTest, TestSize.Level0)
59 {
60     RetCode re = RC_OK;
61     std::shared_ptr<IPipelineCore> core = IPipelineCore::Create();
62     EXPECT_TRUE(core != nullptr);
63     re = core->Init();
64     EXPECT_TRUE(re == RC_OK);
65     re = core->GetHostStreamMgr()->CreateHostStream({
66                 .type_ = PREVIEW,
67                 .streamId_ = PREVIEW_ID
68                 }, nullptr);
69     EXPECT_TRUE(re == RC_OK);
70     std::shared_ptr<IStreamPipelineCore> s = core->GetStreamPipelineCore();
71     EXPECT_TRUE(s != nullptr);
72     re = s->Init();
73     EXPECT_TRUE(re == RC_OK);
74     re = s->CreatePipeline(0);
75     EXPECT_TRUE(re == RC_OK);
76 }
77 
78 HWTEST_F(PipelineCoreTest, PipelineCore_NormalSnapshotTest, TestSize.Level0)
79 {
80     RetCode re = RC_OK;
81     std::shared_ptr<IPipelineCore> core = IPipelineCore::Create();
82     EXPECT_TRUE(core != nullptr);
83     re = core->Init();
84     EXPECT_TRUE(re == RC_OK);
85     re = core->GetHostStreamMgr()->CreateHostStream({
86                 .type_ = STILL_CAPTURE,
87                 .streamId_ = CAPTURE_ID
88                 }, nullptr);
89     EXPECT_TRUE(re == RC_OK);
90     std::shared_ptr<IStreamPipelineCore> s = core->GetStreamPipelineCore();
91     EXPECT_TRUE(s != nullptr);
92     re = s->Init();
93     EXPECT_TRUE(re == RC_OK);
94     re = s->CreatePipeline(0);
95     EXPECT_TRUE(re == RC_OK);
96 }
97 
98 HWTEST_F(PipelineCoreTest, PipelineCore_NormalPreviewSnapshotTest, TestSize.Level0)
99 {
100     RetCode re = RC_OK;
101     std::shared_ptr<IPipelineCore> core = IPipelineCore::Create();
102     EXPECT_TRUE(core != nullptr);
103     re = core->Init();
104     EXPECT_TRUE(re == RC_OK);
105     re = core->GetHostStreamMgr()->CreateHostStream({
106                 .type_ = PREVIEW,
107                 .streamId_ = PREVIEW_ID
108                 }, nullptr);
109     re = core->GetHostStreamMgr()->CreateHostStream({
110                 .type_ = STILL_CAPTURE,
111                 .streamId_ = CAPTURE_ID
112                 }, nullptr);
113     EXPECT_TRUE(re == RC_OK);
114     std::shared_ptr<IStreamPipelineCore> s = core->GetStreamPipelineCore();
115     EXPECT_TRUE(s != nullptr);
116     re = s->Init();
117     EXPECT_TRUE(re == RC_OK);
118     re = s->CreatePipeline(0);
119     EXPECT_TRUE(re == RC_OK);
120 }
121 
122 HWTEST_F(PipelineCoreTest, PipelineCore_NormalPreviewToSnapshotTest, TestSize.Level0)
123 {
124     RetCode re = RC_OK;
125     std::shared_ptr<IPipelineCore> core = IPipelineCore::Create();
126     EXPECT_TRUE(core != nullptr);
127     re = core->Init();
128     EXPECT_TRUE(re == RC_OK);
129     re = core->GetHostStreamMgr()->CreateHostStream({
130                 .type_ = PREVIEW,
131                 .streamId_ = PREVIEW_ID
132                 }, nullptr);
133     EXPECT_TRUE(re == RC_OK);
134     std::shared_ptr<IStreamPipelineCore> s = core->GetStreamPipelineCore();
135     EXPECT_TRUE(s != nullptr);
136     re = s->Init();
137     EXPECT_TRUE(re == RC_OK);
138     re = s->CreatePipeline(0);
139     EXPECT_TRUE(re == RC_OK);
140     re = core->GetHostStreamMgr()->CreateHostStream({
141                 .type_ = STILL_CAPTURE,
142                 .streamId_ = CAPTURE_ID
143                 }, nullptr);
144     EXPECT_TRUE(re == RC_OK);
145     re = s->CreatePipeline(0);
146     EXPECT_TRUE(re == RC_OK);
147 }
148 
149 HWTEST_F(PipelineCoreTest, PipelineCore_NormalSnapshotPreviewTest, TestSize.Level0)
150 {
151     RetCode re = RC_OK;
152     std::shared_ptr<IPipelineCore> core = IPipelineCore::Create();
153     EXPECT_TRUE(core != nullptr);
154     re = core->Init();
155     EXPECT_TRUE(re == RC_OK);
156     re = core->GetHostStreamMgr()->CreateHostStream({
157                 .type_ = STILL_CAPTURE,
158                 .streamId_ = CAPTURE_ID
159                 }, nullptr);
160     re = core->GetHostStreamMgr()->CreateHostStream({
161                 .type_ = PREVIEW,
162                 .streamId_ = PREVIEW_ID
163                 }, nullptr);
164     EXPECT_TRUE(re == RC_OK);
165     std::shared_ptr<IStreamPipelineCore> s = core->GetStreamPipelineCore();
166     EXPECT_TRUE(s != nullptr);
167     re = s->Init();
168     EXPECT_TRUE(re == RC_OK);
169     re = s->CreatePipeline(0);
170     EXPECT_TRUE(re == RC_OK);
171 }
172 
173 HWTEST_F(PipelineCoreTest, PipelineCore_NormalPreviewPreviewTest, TestSize.Level0)
174 {
175     RetCode re = RC_OK;
176     std::shared_ptr<IPipelineCore> core = IPipelineCore::Create();
177     EXPECT_TRUE(core != nullptr);
178     re = core->Init();
179     EXPECT_TRUE(re == RC_OK);
180     re = core->GetHostStreamMgr()->CreateHostStream({
181                 .type_ = PREVIEW,
182                 .streamId_ = PREVIEW_ID
183                 }, nullptr);
184     re = core->GetHostStreamMgr()->CreateHostStream({
185                 .type_ = PREVIEW,
186                 .streamId_ = 2000
187                 }, nullptr);
188     EXPECT_TRUE(re == RC_OK);
189     std::shared_ptr<IStreamPipelineCore> s = core->GetStreamPipelineCore();
190     EXPECT_TRUE(s != nullptr);
191     re = s->Init();
192     EXPECT_TRUE(re == RC_OK);
193     re = s->CreatePipeline(0);
194     EXPECT_TRUE(re == RC_OK);
195 }
196 
197 HWTEST_F(PipelineCoreTest, PipelineCore_NormalTest, TestSize.Level0)
198 {
199     RetCode re = RC_OK;
200     std::shared_ptr<IPipelineCore> core = IPipelineCore::Create();
201     EXPECT_TRUE(core != nullptr);
202     re = core->Init();
203     EXPECT_TRUE(re == RC_OK);
204     std::shared_ptr<IStreamPipelineCore> s = core->GetStreamPipelineCore();
205     EXPECT_TRUE(s != nullptr);
206     re = s->Init();
207     EXPECT_TRUE(re == RC_OK);
208     re = s->CreatePipeline(0);
209     EXPECT_TRUE(re != RC_OK);
210 }
211 
212 HWTEST_F(PipelineCoreTest, PipelineCore_AbNormalPreviewTest, TestSize.Level0)
213 {
214     RetCode re = RC_OK;
215     std::shared_ptr<IPipelineCore> core = IPipelineCore::Create();
216     EXPECT_TRUE(core != nullptr);
217     re = core->Init();
218     EXPECT_TRUE(re == RC_OK);
219     re = core->GetHostStreamMgr()->CreateHostStream({
220                 .type_ = PREVIEW
221                 }, nullptr);
222     EXPECT_TRUE(re == RC_OK);
223     std::shared_ptr<IStreamPipelineCore> s = core->GetStreamPipelineCore();
224     EXPECT_TRUE(s != nullptr);
225     re = s->Init();
226     EXPECT_TRUE(re == RC_OK);
227     re = s->CreatePipeline(2); // unsupportted mode
228     EXPECT_TRUE(re != RC_OK);
229 }
230 
231 HWTEST_F(PipelineCoreTest, PipelineCore_NormalPreviewSnapshotSingleConfigTest, TestSize.Level0)
232 {
233     RetCode re = RC_OK;
234     std::shared_ptr<IPipelineCore> core = IPipelineCore::Create();
235     EXPECT_TRUE(core != nullptr);
236     re = core->Init();
237     EXPECT_TRUE(re == RC_OK);
238     re = core->GetHostStreamMgr()->CreateHostStream({
239                 .type_ = PREVIEW,
240                 .streamId_ = PREVIEW_ID
241                 }, nullptr);
242     re = core->GetHostStreamMgr()->CreateHostStream({
243                 .type_ = STILL_CAPTURE,
244                 .streamId_ = CAPTURE_ID
245                 }, nullptr);
246     EXPECT_TRUE(re == RC_OK);
247     std::shared_ptr<IStreamPipelineCore> s = core->GetStreamPipelineCore();
248     EXPECT_TRUE(s != nullptr);
249     re = s->Init();
250     EXPECT_TRUE(re == RC_OK);
251     re = s->CreatePipeline(0);
252     EXPECT_TRUE(re == RC_OK);
253     CaptureMeta meta;
254     re = s->Config({0}, meta);
255     EXPECT_TRUE(re != RC_OK);
256     re = s->Config({3}, meta);
257     EXPECT_TRUE(re != RC_OK);
258 }
259 HWTEST_F(PipelineCoreTest, PipelineCore_NormalPreviewSnapshotConfigTest, TestSize.Level0)
260 {
261     RetCode re = RC_OK;
262     std::shared_ptr<IPipelineCore> core = IPipelineCore::Create();
263     EXPECT_TRUE(core != nullptr);
264     re = core->Init();
265     EXPECT_TRUE(re == RC_OK);
266     re = core->GetHostStreamMgr()->CreateHostStream({
267                 .type_ = PREVIEW,
268                 .streamId_ = PREVIEW_ID
269                 }, nullptr);
270     re = core->GetHostStreamMgr()->CreateHostStream({
271                 .type_ = STILL_CAPTURE,
272                 .streamId_ = CAPTURE_ID
273                 }, nullptr);
274     EXPECT_TRUE(re == RC_OK);
275     std::shared_ptr<IStreamPipelineCore> s = core->GetStreamPipelineCore();
276     CaptureMeta meta;
277     EXPECT_TRUE(s != nullptr);
278     re = s->Init();
279     EXPECT_TRUE(re == RC_OK);
280     re = s->CreatePipeline(0);
281     EXPECT_TRUE(re == RC_OK);
282     re = s->Config({0}, meta);
283     EXPECT_TRUE(re != RC_OK);
284     re = s->Config({3}, meta);
285     EXPECT_TRUE(re != RC_OK);
286 }
287 HWTEST_F(PipelineCoreTest, PipelineCore_NormalPreviewSnapshotDestroyTest, TestSize.Level0)
288 {
289     RetCode re = RC_OK;
290     std::shared_ptr<IPipelineCore> core = IPipelineCore::Create();
291     EXPECT_TRUE(core != nullptr);
292     re = core->Init();
293     EXPECT_TRUE(re == RC_OK);
294     re = core->GetHostStreamMgr()->CreateHostStream({
295                 .type_ = PREVIEW,
296                 .streamId_ = PREVIEW_ID
297                 }, nullptr);
298     re = core->GetHostStreamMgr()->CreateHostStream({
299                 .type_ = STILL_CAPTURE,
300                 .streamId_ = CAPTURE_ID
301                 }, nullptr);
302     EXPECT_TRUE(re == RC_OK);
303     std::shared_ptr<IStreamPipelineCore> s = core->GetStreamPipelineCore();
304     EXPECT_TRUE(s != nullptr);
305     re = s->Init();
306     EXPECT_TRUE(re == RC_OK);
307     re = s->CreatePipeline(0);
308     EXPECT_TRUE(re == RC_OK);
309     re = s->DestroyPipeline({0, 2});
310     EXPECT_TRUE(re == RC_OK);
311 }
312 }
313