1 /*
2 * Copyright (c) 2022 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 };
36
37 namespace {
38 const int32_t TEST_WIDTH = 1920;
39 const int32_t TEST_HEIGTH = 1080;
40 const int32_t TEST_WIDTH2 = 640;
41 const int32_t TEST_HEIGTH2 = 480;
42 const int32_t SLEEP_TIME = 200000;
43 }
44
SetUpTestCase(void)45 void DCameraPipelineSourceTest::SetUpTestCase(void)
46 {
47 }
48
TearDownTestCase(void)49 void DCameraPipelineSourceTest::TearDownTestCase(void)
50 {
51 }
52
SetUp(void)53 void DCameraPipelineSourceTest::SetUp(void)
54 {
55 testSourcePipeline_ = std::make_shared<DCameraPipelineSource>();
56 }
57
TearDown(void)58 void DCameraPipelineSourceTest::TearDown(void)
59 {
60 testSourcePipeline_ = nullptr;
61 }
62
63 /**
64 * @tc.name: dcamera_pipeline_source_test_001
65 * @tc.desc: Verify pipeline source CreateDataProcessPipeline normal.
66 * @tc.type: FUNC
67 * @tc.require: Issue Number
68 */
69 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_001, TestSize.Level1)
70 {
71 EXPECT_EQ(false, testSourcePipeline_ == nullptr);
72
73 std::shared_ptr<DataProcessListener> listener = std::make_shared<MockDCameraDataProcessListener>();
74 VideoConfigParams srcParams(VideoCodecType::CODEC_H264,
75 Videoformat::NV12,
76 DCAMERA_PRODUCER_FPS_DEFAULT,
77 TEST_WIDTH,
78 TEST_HEIGTH);
79 VideoConfigParams destParams(VideoCodecType::CODEC_H264,
80 Videoformat::NV21,
81 DCAMERA_PRODUCER_FPS_DEFAULT,
82 TEST_WIDTH2,
83 TEST_HEIGTH2);
84 int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener);
85 EXPECT_EQ(rc, DCAMERA_OK);
86 }
87
88 /**
89 * @tc.name: dcamera_pipeline_source_test_002
90 * @tc.desc: Verify pipeline source ProcessData normal.
91 * @tc.type: FUNC
92 * @tc.require: Issue Number
93 */
94 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_002, TestSize.Level1)
95 {
96 EXPECT_EQ(false, testSourcePipeline_ == nullptr);
97
98 std::shared_ptr<DataProcessListener> listener = std::make_shared<MockDCameraDataProcessListener>();
99 VideoConfigParams srcParams(VideoCodecType::CODEC_H264,
100 Videoformat::NV21,
101 DCAMERA_PRODUCER_FPS_DEFAULT,
102 TEST_WIDTH,
103 TEST_HEIGTH);
104 VideoConfigParams destParams(VideoCodecType::CODEC_H264,
105 Videoformat::NV21,
106 DCAMERA_PRODUCER_FPS_DEFAULT,
107 TEST_WIDTH,
108 TEST_HEIGTH);
109 int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener);
110 EXPECT_EQ(rc, DCAMERA_OK);
111
112 size_t capacity = 100;
113 std::vector<std::shared_ptr<DataBuffer>> buffers;
114 std::shared_ptr<DataBuffer> db = std::make_shared<DataBuffer>(capacity);
115 buffers.push_back(db);
116 rc = testSourcePipeline_->ProcessData(buffers);
117 EXPECT_EQ(rc, DCAMERA_OK);
118 usleep(SLEEP_TIME);
119 }
120
121 /**
122 * @tc.name: dcamera_pipeline_source_test_003
123 * @tc.desc: Verify pipeline source CreateDataProcessPipeline abnormal.
124 * @tc.type: FUNC
125 * @tc.require: Issue Number
126 */
127 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_003, TestSize.Level1)
128 {
129 EXPECT_EQ(false, testSourcePipeline_ == nullptr);
130
131 std::shared_ptr<DataProcessListener> listener = std::make_shared<MockDCameraDataProcessListener>();
132 VideoConfigParams srcParams(VideoCodecType::NO_CODEC,
133 Videoformat::NV21,
134 DCAMERA_PRODUCER_FPS_DEFAULT,
135 TEST_WIDTH,
136 TEST_HEIGTH);
137 VideoConfigParams destParams(VideoCodecType::CODEC_H264,
138 Videoformat::NV21,
139 DCAMERA_PRODUCER_FPS_DEFAULT,
140 TEST_WIDTH,
141 TEST_HEIGTH);
142 int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(
143 PipelineType::PHOTO_JPEG, srcParams, destParams, listener);
144 EXPECT_EQ(rc, DCAMERA_NOT_FOUND);
145 }
146
147 /**
148 * @tc.name: dcamera_pipeline_source_test_004
149 * @tc.desc: Verify pipeline source ProcessData abnormal.
150 * @tc.type: FUNC
151 * @tc.require: Issue Number
152 */
153 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_004, TestSize.Level1)
154 {
155 EXPECT_EQ(false, testSourcePipeline_ == nullptr);
156
157 std::shared_ptr<DataProcessListener> listener = std::make_shared<MockDCameraDataProcessListener>();
158 VideoConfigParams srcParams(VideoCodecType::NO_CODEC,
159 Videoformat::NV21,
160 DCAMERA_PRODUCER_FPS_DEFAULT,
161 TEST_WIDTH,
162 TEST_HEIGTH);
163 VideoConfigParams destParams(VideoCodecType::NO_CODEC,
164 Videoformat::NV21,
165 DCAMERA_PRODUCER_FPS_DEFAULT,
166 TEST_WIDTH,
167 TEST_HEIGTH);
168 int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener);
169 EXPECT_EQ(rc, DCAMERA_OK);
170
171 std::vector<std::shared_ptr<DataBuffer>> buffers;
172 rc = testSourcePipeline_->ProcessData(buffers);
173 EXPECT_EQ(rc, DCAMERA_BAD_VALUE);
174 }
175
176 /**
177 * @tc.name: dcamera_pipeline_source_test_005
178 * @tc.desc: Verify pipeline source ProcessData abnormal.
179 * @tc.type: FUNC
180 * @tc.require: Issue Number
181 */
182 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_005, TestSize.Level1)
183 {
184 EXPECT_EQ(false, testSourcePipeline_ == nullptr);
185
186 size_t capacity = 100;
187 std::vector<std::shared_ptr<DataBuffer>> buffers;
188 std::shared_ptr<DataBuffer> db = std::make_shared<DataBuffer>(capacity);
189 buffers.push_back(db);
190 int32_t rc = testSourcePipeline_->ProcessData(buffers);
191 EXPECT_EQ(rc, DCAMERA_INIT_ERR);
192 }
193 } // namespace DistributedHardware
194 } // namespace OHOS
195