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 "image_sink_processor_test.h"
17
18 #include <chrono>
19 #include <securec.h>
20
21 #include "dscreen_constants.h"
22 #include "dscreen_errcode.h"
23 #include "iconsumer_surface.h"
24
25 using namespace testing::ext;
26
27 namespace OHOS {
28 namespace DistributedHardware {
29 constexpr static uint32_t VIDEO_DATA_NUM = 480;
SetUpTestCase(void)30 void ImageSinkProcessorTest::SetUpTestCase(void) {}
31
TearDownTestCase(void)32 void ImageSinkProcessorTest::TearDownTestCase(void) {}
33
SetUp(void)34 void ImageSinkProcessorTest::SetUp(void)
35 {
36 param_.screenWidth_ = VIDEO_DATA_NUM;
37 param_.screenHeight_ = VIDEO_DATA_NUM;
38 param_.videoWidth_ = VIDEO_DATA_NUM;
39 param_.videoHeight_ = VIDEO_DATA_NUM;
40 param_.fps_ = FPS;
41 param_.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
42 param_.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
43
44 processor_ = std::make_shared<ImageSinkProcessor>();
45 imageListener_ = std::make_shared<MockIImageSinkProcessorListener>();
46 processor_->imageDecoder_ = std::make_shared<ImageSinkDecoder>(imageListener_);
47 videoDecoder_ = MediaAVCodec::VideoDecoderFactory::CreateByMime(
48 std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC));
49 processor_->imageDecoder_->videoDecoder_ = videoDecoder_;
50 }
51
TearDown(void)52 void ImageSinkProcessorTest::TearDown(void)
53 {
54 if (videoDecoder_ != nullptr) {
55 videoDecoder_->Stop();
56 videoDecoder_->Release();
57 videoDecoder_ = nullptr;
58 }
59 }
60
61 /**
62 * @tc.name: configure_image_processor_test_001
63 * @tc.desc: Verify the ConfigureImageProcessor function.
64 * @tc.type: FUNC
65 * @tc.require: Issue Number
66 */
67 HWTEST_F(ImageSinkProcessorTest, configure_image_processor_test_001, TestSize.Level1)
68 {
69 EXPECT_EQ(DH_SUCCESS, processor_->ConfigureImageProcessor(param_, param_, imageListener_));
70 }
71
72 /**
73 * @tc.name: configure_image_processor_test_002
74 * @tc.desc: Verify the ConfigureImageProcessor function.
75 * @tc.type: FUNC
76 * @tc.require: Issue Number
77 */
78 HWTEST_F(ImageSinkProcessorTest, configure_image_processor_test_002, TestSize.Level1)
79 {
80 param_.codecType_ = VIDEO_CODEC_TYPE_INVALID;
81 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE,
82 processor_->ConfigureImageProcessor(param_, param_, imageListener_));
83 }
84
85 /**
86 * @tc.name: release_image_processor_test_001
87 * @tc.desc: Verify the ReleaseImageProcessor function.
88 * @tc.type: FUNC
89 * @tc.require: Issue Number
90 */
91 HWTEST_F(ImageSinkProcessorTest, release_image_processor_test_001, TestSize.Level1)
92 {
93 EXPECT_EQ(DH_SUCCESS, processor_->ReleaseImageProcessor());
94 }
95
96 /**
97 * @tc.name: release_image_processor_test_002
98 * @tc.desc: Verify the ReleaseImageProcessor function.
99 * @tc.type: FUNC
100 * @tc.require: Issue Number
101 */
102 HWTEST_F(ImageSinkProcessorTest, release_image_processor_test_002, TestSize.Level1)
103 {
104 processor_->imageDecoder_ = nullptr;
105 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, processor_->ReleaseImageProcessor());
106 }
107
108 /**
109 * @tc.name: start_image_processor_test_001
110 * @tc.desc: Verify the StartImageProcessor function.
111 * @tc.type: FUNC
112 * @tc.require: Issue Number
113 */
114 HWTEST_F(ImageSinkProcessorTest, start_image_processor_test_001, TestSize.Level1)
115 {
116 processor_->imageDecoder_->videoDecoder_ = nullptr;
117 EXPECT_NE(DH_SUCCESS, processor_->StartImageProcessor());
118 }
119
120 /**
121 * @tc.name: start_image_processor_test_002
122 * @tc.desc: Verify the StartImageProcessor function.
123 * @tc.type: FUNC
124 * @tc.require: Issue Number
125 */
126 HWTEST_F(ImageSinkProcessorTest, start_image_processor_test_002, TestSize.Level1)
127 {
128 processor_->imageDecoder_ = nullptr;
129 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, processor_->StartImageProcessor());
130 }
131
132 /**
133 * @tc.name: stop_image_processor_test_001
134 * @tc.desc: Verify the StopImageProcessor function.
135 * @tc.type: FUNC
136 * @tc.require: Issue Number
137 */
138 HWTEST_F(ImageSinkProcessorTest, stop_image_processor_test_001, TestSize.Level1)
139 {
140 EXPECT_EQ(ERR_DH_SCREEN_CODEC_FLUSH_FAILED, processor_->StopImageProcessor());
141 }
142
143 /**
144 * @tc.name: stop_image_processor_test_002
145 * @tc.desc: Verify the StopImageProcessor function.
146 * @tc.type: FUNC
147 * @tc.require: Issue Number
148 */
149 HWTEST_F(ImageSinkProcessorTest, stop_image_processor_test_002, TestSize.Level1)
150 {
151 processor_->imageDecoder_ = nullptr;
152 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, processor_->StopImageProcessor());
153 }
154
155 /**
156 * @tc.name: set_image_surface_test_001
157 * @tc.desc: Verify the StopImageProcessor function.
158 * @tc.type: FUNC
159 * @tc.require: Issue Number
160 */
161 HWTEST_F(ImageSinkProcessorTest, set_image_surface_test_001, TestSize.Level1)
162 {
163 sptr<IConsumerSurface> surface = IConsumerSurface::Create("test");
164 sptr<IBufferProducer> bp = surface->GetProducer();
165 sptr<Surface> pSurface = Surface::CreateSurfaceAsProducer(bp);
166 EXPECT_EQ(ERR_DH_SCREEN_CODEC_SURFACE_ERROR, processor_->SetImageSurface(pSurface));
167 }
168
169 /**
170 * @tc.name: set_image_surface_test_002
171 * @tc.desc: Verify the StopImageProcessor function.
172 * @tc.type: FUNC
173 * @tc.require: Issue Number
174 */
175 HWTEST_F(ImageSinkProcessorTest, set_image_surface_test_002, TestSize.Level1)
176 {
177 processor_->imageDecoder_ = nullptr;
178 sptr<IConsumerSurface> surface = IConsumerSurface::Create("test");
179 sptr<IBufferProducer> bp = surface->GetProducer();
180 sptr<Surface> pSurface = Surface::CreateSurfaceAsProducer(bp);
181 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, processor_->SetImageSurface(pSurface));
182 }
183
184 /**
185 * @tc.name: processimage_test_001
186 * @tc.desc: Verify the StopImageProcessor function.
187 * @tc.type: FUNC
188 * @tc.require: Issue Number
189 */
190 HWTEST_F(ImageSinkProcessorTest, processimage_test_001, TestSize.Level1)
191 {
192 std::shared_ptr<DataBuffer> data = std::make_shared<DataBuffer>(DATA_LEN);
193 EXPECT_EQ(DH_SUCCESS, processor_->ProcessImage(data));
194 }
195
196 /**
197 * @tc.name: processimage_test_002
198 * @tc.desc: Verify the StopImageProcessor function.
199 * @tc.type: FUNC
200 * @tc.require: Issue Number
201 */
202 HWTEST_F(ImageSinkProcessorTest, processimage_test_002, TestSize.Level1)
203 {
204 processor_->imageDecoder_ = nullptr;
205 std::shared_ptr<DataBuffer> data = std::make_shared<DataBuffer>(DATA_LEN);
206 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, processor_->ProcessImage(data));
207 }
208 } // namespace DistributedHardware
209 } // namespace OHOS
210