1 /*
2 * Copyright (c) 2022-2024 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 <gtest/gtest.h>
17
18 #include "dcamera_pipeline_source.h"
19 #include "distributed_camera_constants.h"
20 #include "distributed_camera_errno.h"
21 #include "mock_dcamera_data_process_listener.h"
22
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace DistributedHardware {
27 class DCameraPipelineSourceTest : public testing::Test {
28 public:
29 static void SetUpTestCase(void);
30 static void TearDownTestCase(void);
31 void SetUp();
32 void TearDown();
33
34 std::shared_ptr<IDataProcessPipeline> testSourcePipeline_;
35 std::shared_ptr<DCameraPipelineSource> testPipelineSource_;
36 };
37
38 namespace {
39 const int32_t TEST_WIDTH = 1920;
40 const int32_t TEST_HEIGTH = 1080;
41 const int32_t TEST_WIDTH2 = 640;
42 const int32_t TEST_HEIGTH2 = 480;
43 const int32_t SLEEP_TIME = 200000;
44 }
45
SetUpTestCase(void)46 void DCameraPipelineSourceTest::SetUpTestCase(void)
47 {
48 }
49
TearDownTestCase(void)50 void DCameraPipelineSourceTest::TearDownTestCase(void)
51 {
52 }
53
SetUp(void)54 void DCameraPipelineSourceTest::SetUp(void)
55 {
56 testSourcePipeline_ = std::make_shared<DCameraPipelineSource>();
57 testPipelineSource_ = std::make_shared<DCameraPipelineSource>();
58 }
59
TearDown(void)60 void DCameraPipelineSourceTest::TearDown(void)
61 {
62 testSourcePipeline_ = nullptr;
63 testPipelineSource_ = nullptr;
64 }
65
66 /**
67 * @tc.name: dcamera_pipeline_source_test_001
68 * @tc.desc: Verify pipeline source CreateDataProcessPipeline normal.
69 * @tc.type: FUNC
70 * @tc.require: Issue Number
71 */
72 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_001, TestSize.Level1)
73 {
74 EXPECT_EQ(false, testSourcePipeline_ == nullptr);
75
76 std::shared_ptr<DataProcessListener> listener = std::make_shared<MockDCameraDataProcessListener>();
77 VideoConfigParams srcParams(VideoCodecType::CODEC_H264,
78 Videoformat::NV12,
79 DCAMERA_PRODUCER_FPS_DEFAULT,
80 TEST_WIDTH,
81 TEST_HEIGTH);
82 VideoConfigParams destParams(VideoCodecType::CODEC_H264,
83 Videoformat::NV21,
84 DCAMERA_PRODUCER_FPS_DEFAULT,
85 TEST_WIDTH2,
86 TEST_HEIGTH2);
87 int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener);
88 EXPECT_EQ(rc, DCAMERA_OK);
89
90 rc = testSourcePipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, nullptr);
91 EXPECT_EQ(rc, DCAMERA_BAD_VALUE);
92 usleep(SLEEP_TIME);
93 }
94
95 /**
96 * @tc.name: dcamera_pipeline_source_test_002
97 * @tc.desc: Verify pipeline source ProcessData normal.
98 * @tc.type: FUNC
99 * @tc.require: Issue Number
100 */
101 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_002, TestSize.Level1)
102 {
103 EXPECT_EQ(false, testSourcePipeline_ == nullptr);
104
105 std::shared_ptr<DataProcessListener> listener = std::make_shared<MockDCameraDataProcessListener>();
106 VideoConfigParams srcParams(VideoCodecType::CODEC_H264,
107 Videoformat::NV21,
108 DCAMERA_PRODUCER_FPS_DEFAULT,
109 TEST_WIDTH,
110 TEST_HEIGTH);
111 VideoConfigParams destParams(VideoCodecType::CODEC_H264,
112 Videoformat::NV21,
113 DCAMERA_PRODUCER_FPS_DEFAULT,
114 TEST_WIDTH,
115 TEST_HEIGTH);
116 int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener);
117 EXPECT_EQ(rc, DCAMERA_OK);
118
119 size_t capacity = 100;
120 std::vector<std::shared_ptr<DataBuffer>> buffers;
121 std::shared_ptr<DataBuffer> db = std::make_shared<DataBuffer>(capacity);
122 buffers.push_back(db);
123 rc = testSourcePipeline_->ProcessData(buffers);
124 EXPECT_EQ(rc, DCAMERA_OK);
125 usleep(SLEEP_TIME);
126 }
127
128 /**
129 * @tc.name: dcamera_pipeline_source_test_003
130 * @tc.desc: Verify pipeline source CreateDataProcessPipeline abnormal.
131 * @tc.type: FUNC
132 * @tc.require: Issue Number
133 */
134 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_003, TestSize.Level1)
135 {
136 EXPECT_EQ(false, testSourcePipeline_ == nullptr);
137
138 std::shared_ptr<DataProcessListener> listener = std::make_shared<MockDCameraDataProcessListener>();
139 VideoConfigParams srcParams(VideoCodecType::NO_CODEC,
140 Videoformat::NV21,
141 DCAMERA_PRODUCER_FPS_DEFAULT,
142 TEST_WIDTH,
143 TEST_HEIGTH);
144 VideoConfigParams destParams(VideoCodecType::CODEC_H264,
145 Videoformat::NV21,
146 DCAMERA_PRODUCER_FPS_DEFAULT,
147 TEST_WIDTH,
148 TEST_HEIGTH);
149 int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(
150 PipelineType::PHOTO_JPEG, srcParams, destParams, listener);
151 EXPECT_EQ(rc, DCAMERA_NOT_FOUND);
152 }
153
154 /**
155 * @tc.name: dcamera_pipeline_source_test_004
156 * @tc.desc: Verify pipeline source ProcessData abnormal.
157 * @tc.type: FUNC
158 * @tc.require: Issue Number
159 */
160 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_004, TestSize.Level1)
161 {
162 EXPECT_EQ(false, testSourcePipeline_ == nullptr);
163
164 std::shared_ptr<DataProcessListener> listener = std::make_shared<MockDCameraDataProcessListener>();
165 VideoConfigParams srcParams(VideoCodecType::NO_CODEC,
166 Videoformat::NV21,
167 DCAMERA_PRODUCER_FPS_DEFAULT,
168 TEST_WIDTH,
169 TEST_HEIGTH);
170 VideoConfigParams destParams(VideoCodecType::NO_CODEC,
171 Videoformat::NV21,
172 DCAMERA_PRODUCER_FPS_DEFAULT,
173 TEST_WIDTH,
174 TEST_HEIGTH);
175 int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener);
176 EXPECT_EQ(rc, DCAMERA_OK);
177
178 std::vector<std::shared_ptr<DataBuffer>> buffers;
179 rc = testSourcePipeline_->ProcessData(buffers);
180 EXPECT_EQ(rc, DCAMERA_BAD_VALUE);
181 usleep(SLEEP_TIME);
182 }
183
184 /**
185 * @tc.name: dcamera_pipeline_source_test_005
186 * @tc.desc: Verify pipeline source ProcessData abnormal.
187 * @tc.type: FUNC
188 * @tc.require: Issue Number
189 */
190 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_005, TestSize.Level1)
191 {
192 EXPECT_EQ(false, testSourcePipeline_ == nullptr);
193
194 size_t capacity = 100;
195 std::vector<std::shared_ptr<DataBuffer>> buffers;
196 std::shared_ptr<DataBuffer> db = std::make_shared<DataBuffer>(capacity);
197 buffers.push_back(db);
198 int32_t rc = testSourcePipeline_->ProcessData(buffers);
199 EXPECT_EQ(rc, DCAMERA_INIT_ERR);
200
201 testPipelineSource_->piplineType_ = PipelineType::PHOTO_JPEG;
202 rc = testPipelineSource_->ProcessData(buffers);
203 EXPECT_EQ(rc, DCAMERA_NOT_FOUND);
204 }
205
206 /**
207 * @tc.name: dcamera_pipeline_source_test_006
208 * @tc.desc: Verify pipeline source OnError abnormal.
209 * @tc.type: FUNC
210 * @tc.require: Issue Number
211 */
212 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_006, TestSize.Level1)
213 {
214 EXPECT_EQ(false, testPipelineSource_ == nullptr);
215
216 DataProcessErrorType errorType = DataProcessErrorType::ERROR_PIPELINE_ENCODER;
217 testPipelineSource_->OnError(errorType);
218 EXPECT_TRUE(true);
219
220 testPipelineSource_->processListener_ = std::make_shared<MockDCameraDataProcessListener>();
221 testPipelineSource_->OnError(errorType);
222 EXPECT_TRUE(true);
223 }
224
225 /**
226 * @tc.name: dcamera_pipeline_source_test_007
227 * @tc.desc: Verify pipeline source OnError abnormal.
228 * @tc.type: FUNC
229 * @tc.require: Issue Number
230 */
231 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_007, TestSize.Level1)
232 {
233 EXPECT_EQ(false, testPipelineSource_ == nullptr);
234 std::string propertyName = "propertyName";
235 PropertyCarrier propertyCarrier;
236 int32_t rc1 = testPipelineSource_->GetProperty(propertyName, propertyCarrier);
237 EXPECT_EQ(DCAMERA_OK, rc1);
238 }
239
240 /**
241 * @tc.name: dcamera_pipeline_source_test_008
242 * @tc.desc: Verify pipeline source OnProcessedVideoBuffer abnormal.
243 * @tc.type: FUNC
244 * @tc.require: Issue Number
245 */
246 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_008, TestSize.Level1)
247 {
248 EXPECT_EQ(false, testPipelineSource_ == nullptr);
249
250 size_t i = 1;
251 std::shared_ptr<DataBuffer> videoResult = std::make_shared<DataBuffer>(i);
252 testPipelineSource_->processListener_ = nullptr;
253 testPipelineSource_->OnProcessedVideoBuffer(videoResult);
254 EXPECT_TRUE(true);
255 }
256 } // namespace DistributedHardware
257 } // namespace OHOS
258