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