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