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 usleep(SLEEP_TIME);
90 }
91
92 /**
93 * @tc.name: dcamera_pipeline_source_test_002
94 * @tc.desc: Verify pipeline source ProcessData normal.
95 * @tc.type: FUNC
96 * @tc.require: Issue Number
97 */
98 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_002, TestSize.Level1)
99 {
100 EXPECT_EQ(false, testSourcePipeline_ == nullptr);
101
102 std::shared_ptr<DataProcessListener> listener = std::make_shared<MockDCameraDataProcessListener>();
103 VideoConfigParams srcParams(VideoCodecType::CODEC_H264,
104 Videoformat::NV21,
105 DCAMERA_PRODUCER_FPS_DEFAULT,
106 TEST_WIDTH,
107 TEST_HEIGTH);
108 VideoConfigParams destParams(VideoCodecType::CODEC_H264,
109 Videoformat::NV21,
110 DCAMERA_PRODUCER_FPS_DEFAULT,
111 TEST_WIDTH,
112 TEST_HEIGTH);
113 int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener);
114 EXPECT_EQ(rc, DCAMERA_OK);
115
116 size_t capacity = 100;
117 std::vector<std::shared_ptr<DataBuffer>> buffers;
118 std::shared_ptr<DataBuffer> db = std::make_shared<DataBuffer>(capacity);
119 buffers.push_back(db);
120 rc = testSourcePipeline_->ProcessData(buffers);
121 EXPECT_EQ(rc, DCAMERA_OK);
122 usleep(SLEEP_TIME);
123 }
124
125 /**
126 * @tc.name: dcamera_pipeline_source_test_003
127 * @tc.desc: Verify pipeline source CreateDataProcessPipeline abnormal.
128 * @tc.type: FUNC
129 * @tc.require: Issue Number
130 */
131 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_003, TestSize.Level1)
132 {
133 EXPECT_EQ(false, testSourcePipeline_ == nullptr);
134
135 std::shared_ptr<DataProcessListener> listener = std::make_shared<MockDCameraDataProcessListener>();
136 VideoConfigParams srcParams(VideoCodecType::NO_CODEC,
137 Videoformat::NV21,
138 DCAMERA_PRODUCER_FPS_DEFAULT,
139 TEST_WIDTH,
140 TEST_HEIGTH);
141 VideoConfigParams destParams(VideoCodecType::CODEC_H264,
142 Videoformat::NV21,
143 DCAMERA_PRODUCER_FPS_DEFAULT,
144 TEST_WIDTH,
145 TEST_HEIGTH);
146 int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(
147 PipelineType::PHOTO_JPEG, srcParams, destParams, listener);
148 EXPECT_EQ(rc, DCAMERA_NOT_FOUND);
149 }
150
151 /**
152 * @tc.name: dcamera_pipeline_source_test_004
153 * @tc.desc: Verify pipeline source ProcessData abnormal.
154 * @tc.type: FUNC
155 * @tc.require: Issue Number
156 */
157 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_004, TestSize.Level1)
158 {
159 EXPECT_EQ(false, testSourcePipeline_ == nullptr);
160
161 std::shared_ptr<DataProcessListener> listener = std::make_shared<MockDCameraDataProcessListener>();
162 VideoConfigParams srcParams(VideoCodecType::NO_CODEC,
163 Videoformat::NV21,
164 DCAMERA_PRODUCER_FPS_DEFAULT,
165 TEST_WIDTH,
166 TEST_HEIGTH);
167 VideoConfigParams destParams(VideoCodecType::NO_CODEC,
168 Videoformat::NV21,
169 DCAMERA_PRODUCER_FPS_DEFAULT,
170 TEST_WIDTH,
171 TEST_HEIGTH);
172 int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener);
173 EXPECT_EQ(rc, DCAMERA_OK);
174
175 std::vector<std::shared_ptr<DataBuffer>> buffers;
176 rc = testSourcePipeline_->ProcessData(buffers);
177 EXPECT_EQ(rc, DCAMERA_BAD_VALUE);
178 }
179
180 /**
181 * @tc.name: dcamera_pipeline_source_test_005
182 * @tc.desc: Verify pipeline source ProcessData abnormal.
183 * @tc.type: FUNC
184 * @tc.require: Issue Number
185 */
186 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_005, TestSize.Level1)
187 {
188 EXPECT_EQ(false, testSourcePipeline_ == nullptr);
189
190 size_t capacity = 100;
191 std::vector<std::shared_ptr<DataBuffer>> buffers;
192 std::shared_ptr<DataBuffer> db = std::make_shared<DataBuffer>(capacity);
193 buffers.push_back(db);
194 int32_t rc = testSourcePipeline_->ProcessData(buffers);
195 EXPECT_EQ(rc, DCAMERA_INIT_ERR);
196 }
197
198 /**
199 * @tc.name: dcamera_pipeline_source_test_006
200 * @tc.desc: Verify pipeline source OnError abnormal.
201 * @tc.type: FUNC
202 * @tc.require: Issue Number
203 */
204 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_006, TestSize.Level1)
205 {
206 EXPECT_EQ(false, testPipelineSource_ == nullptr);
207
208 DataProcessErrorType errorType = DataProcessErrorType::ERROR_PIPELINE_ENCODER;
209 testPipelineSource_->OnError(errorType);
210 EXPECT_TRUE(true);
211
212 testPipelineSource_->processListener_ = std::make_shared<MockDCameraDataProcessListener>();
213 testPipelineSource_->OnError(errorType);
214 EXPECT_TRUE(true);
215 }
216
217 /**
218 * @tc.name: dcamera_pipeline_source_test_007
219 * @tc.desc: Verify pipeline source OnError abnormal.
220 * @tc.type: FUNC
221 * @tc.require: Issue Number
222 */
223 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_007, TestSize.Level1)
224 {
225 EXPECT_EQ(false, testPipelineSource_ == nullptr);
226 std::string propertyName = "propertyName";
227 PropertyCarrier propertyCarrier;
228 int32_t rc1 = testPipelineSource_->GetProperty(propertyName, propertyCarrier);
229 EXPECT_EQ(DCAMERA_OK, rc1);
230 }
231
232 /**
233 * @tc.name: dcamera_pipeline_source_test_008
234 * @tc.desc: Verify pipeline source OnProcessedVideoBuffer abnormal.
235 * @tc.type: FUNC
236 * @tc.require: Issue Number
237 */
238 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_008, TestSize.Level1)
239 {
240 EXPECT_EQ(false, testPipelineSource_ == nullptr);
241
242 size_t i = 1;
243 std::shared_ptr<DataBuffer> videoResult = std::make_shared<DataBuffer>(i);
244 testPipelineSource_->processListener_ = nullptr;
245 testPipelineSource_->OnProcessedVideoBuffer(videoResult);
246 EXPECT_TRUE(true);
247 }
248 } // namespace DistributedHardware
249 } // namespace OHOS
250