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