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 "image_source_encoder_test.h"
17
18 using namespace testing::ext;
19
20 namespace OHOS {
21 namespace DistributedHardware {
SetUpTestCase(void)22 void ImageSourceEncoderTest::SetUpTestCase(void) {}
23
TearDownTestCase(void)24 void ImageSourceEncoderTest::TearDownTestCase(void) {}
25
SetUp(void)26 void ImageSourceEncoderTest::SetUp(void)
27 {
28 std::shared_ptr<IImageSourceProcessorListener> imageListener = nullptr;
29 encoder = std::make_shared<ImageSourceEncoder>(imageListener);
30 }
31
TearDown(void)32 void ImageSourceEncoderTest::TearDown(void) {}
33
34 /**
35 * @tc.name: ConfigureEncoder_001
36 * @tc.desc: Verify the ConfigureEncoder function.
37 * @tc.type: FUNC
38 * @tc.require: Issue Number
39 */
40 HWTEST_F(ImageSourceEncoderTest, ConfigureEncoder_001, TestSize.Level1)
41 {
42 VideoParam configParam;
43 configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
44 configParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
45
46 int32_t actual = encoder->ConfigureEncoder(configParam);
47 EXPECT_EQ(ERR_DH_SCREEN_CODEC_SURFACE_ERROR, actual);
48 }
49
50 /**
51 * @tc.name: ConfigureEncoder_002
52 * @tc.desc: Verify the ConfigureEncoder function.
53 * @tc.type: FUNC
54 * @tc.require: Issue Number
55 */
56 HWTEST_F(ImageSourceEncoderTest, ConfigureEncoder_002, TestSize.Level1)
57 {
58 VideoParam configParam;
59 configParam.codecType_ = -1;
60
61 int32_t actual = encoder->ConfigureEncoder(configParam);
62 EXPECT_EQ(ERR_DH_SCREEN_TRANS_CREATE_CODEC_FAILED, actual);
63 }
64
65 /**
66 * @tc.name: ConfigureEncoder_003
67 * @tc.desc: Verify the ConfigureEncoder function.
68 * @tc.type: FUNC
69 * @tc.require: Issue Number
70 */
71 HWTEST_F(ImageSourceEncoderTest, ConfigureEncoder_003, TestSize.Level1)
72 {
73 VideoParam configParam;
74 configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
75 configParam.videoFormat_ = -1;
76
77 int32_t actual = encoder->ConfigureEncoder(configParam);
78 EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM, actual);
79 }
80
81 /**
82 * @tc.name: ReleaseEncoder_001
83 * @tc.desc: Verify the ReleaseEncoder function.
84 * @tc.type: FUNC
85 * @tc.require: Issue Number
86 */
87 HWTEST_F(ImageSourceEncoderTest, ReleaseEncoder_001, TestSize.Level1)
88 {
89 int32_t actual = encoder->ReleaseEncoder();
90 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
91 }
92
93 /**
94 * @tc.name: ReleaseEncoder_002
95 * @tc.desc: Verify the ReleaseEncoder function.
96 * @tc.type: FUNC
97 * @tc.require: Issue Number
98 */
99 HWTEST_F(ImageSourceEncoderTest, ReleaseEncoder_002, TestSize.Level1)
100 {
101 encoder->videoEncoder_ = Media::VideoEncoderFactory::CreateByMime("video/avc");
102
103 int32_t actual = encoder->ReleaseEncoder();
104 EXPECT_EQ(DH_SUCCESS, actual);
105 }
106
107 /**
108 * @tc.name: StartEncoder_001
109 * @tc.desc: Verify the StartEncoder function.
110 * @tc.type: FUNC
111 * @tc.require: Issue Number
112 */
113 HWTEST_F(ImageSourceEncoderTest, StartEncoder_001, TestSize.Level1)
114 {
115 int32_t actual = encoder->StartEncoder();
116 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
117 }
118
119 /**
120 * @tc.name: StartEncoder_002
121 * @tc.desc: Verify the StartEncoder function.
122 * @tc.type: FUNC
123 * @tc.require: Issue Number
124 */
125 HWTEST_F(ImageSourceEncoderTest, StartEncoder_002, TestSize.Level1)
126 {
127 encoder->videoEncoder_ = Media::VideoEncoderFactory::CreateByMime("video/avc");
128
129 int32_t actual = encoder->StartEncoder();
130 EXPECT_EQ(ERR_DH_SCREEN_CODEC_PREPARE_FAILED, actual);
131 }
132
133 /**
134 * @tc.name: StopEncoder_001
135 * @tc.desc: Verify the StopEncoder function.
136 * @tc.type: FUNC
137 * @tc.require: Issue Number
138 */
139 HWTEST_F(ImageSourceEncoderTest, StopEncoder_001, TestSize.Level1)
140 {
141 int32_t actual = encoder->StopEncoder();
142 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
143 }
144
145 /**
146 * @tc.name: StopEncoder_002
147 * @tc.desc: Verify the StartEncoder function.
148 * @tc.type: FUNC
149 * @tc.require: Issue Number
150 */
151 HWTEST_F(ImageSourceEncoderTest, StopEncoder_002, TestSize.Level1)
152 {
153 encoder->videoEncoder_ = Media::VideoEncoderFactory::CreateByMime("video/avc");
154
155 int32_t actual = encoder->StopEncoder();
156 EXPECT_EQ(ERR_DH_SCREEN_CODEC_STOP_FAILED, actual);
157 }
158
159 /**
160 * @tc.name: InitVideoEncoder_001
161 * @tc.desc: Verify the InitVideoEncoder function.
162 * @tc.type: FUNC
163 * @tc.require: Issue Number
164 */
165 HWTEST_F(ImageSourceEncoderTest, InitVideoEncoder_001, TestSize.Level1)
166 {
167 VideoParam configParam;
168 configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
169
170 int32_t actual = encoder->InitVideoEncoder(configParam);
171 EXPECT_EQ(DH_SUCCESS, actual);
172 }
173
174 /**
175 * @tc.name: InitVideoEncoder_002
176 * @tc.desc: Verify the InitVideoEncoder function.
177 * @tc.type: FUNC
178 * @tc.require: Issue Number
179 */
180 HWTEST_F(ImageSourceEncoderTest, InitVideoEncoder_002, TestSize.Level1)
181 {
182 VideoParam configParam;
183 configParam.codecType_ = -1;
184
185 int32_t actual = encoder->InitVideoEncoder(configParam);
186 EXPECT_EQ(ERR_DH_SCREEN_TRANS_CREATE_CODEC_FAILED, actual);
187 }
188
189 /**
190 * @tc.name: InitVideoEncoder_003
191 * @tc.desc: Verify the InitVideoEncoder function.
192 * @tc.type: FUNC
193 * @tc.require: Issue Number
194 */
195 HWTEST_F(ImageSourceEncoderTest, InitVideoEncoder_003, TestSize.Level1)
196 {
197 VideoParam configParam;
198 configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H265;
199
200 int32_t actual = encoder->InitVideoEncoder(configParam);
201 EXPECT_EQ(DH_SUCCESS, actual);
202 }
203
204 /**
205 * @tc.name: InitVideoEncoder_004
206 * @tc.desc: Verify the InitVideoEncoder function.
207 * @tc.type: FUNC
208 * @tc.require: Issue Number
209 */
210 HWTEST_F(ImageSourceEncoderTest, InitVideoEncoder_004, TestSize.Level1)
211 {
212 VideoParam configParam;
213 configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_MPEG4;
214
215 int32_t actual = encoder->InitVideoEncoder(configParam);
216 EXPECT_EQ(DH_SUCCESS, actual);
217 }
218
219 /**
220 * @tc.name: SetEncoderFormat_001
221 * @tc.desc: Verify the SetEncoderFormat function.
222 * @tc.type: FUNC
223 * @tc.require: Issue Number
224 */
225 HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_001, TestSize.Level1)
226 {
227 VideoParam configParam;
228 int32_t actual = encoder->SetEncoderFormat(configParam);
229 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual);
230 }
231
232 /**
233 * @tc.name: SetEncoderFormat_002
234 * @tc.desc: Verify the SetEncoderFormat function.
235 * @tc.type: FUNC
236 * @tc.require: Issue Number
237 */
238 HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_002, TestSize.Level1)
239 {
240 VideoParam configParam;
241 configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
242 int32_t actual = encoder->InitVideoEncoder(configParam);
243 configParam.codecType_ = -1;
244 actual = encoder->SetEncoderFormat(configParam);
245 EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM, actual);
246 }
247
248 /**
249 * @tc.name: SetEncoderFormat_003
250 * @tc.desc: Verify the SetEncoderFormat function.
251 * @tc.type: FUNC
252 * @tc.require: Issue Number
253 */
254 HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_003, TestSize.Level1)
255 {
256 VideoParam configParam;
257 configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264;
258 configParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420;
259 int32_t actual = encoder->InitVideoEncoder(configParam);
260 actual = encoder->SetEncoderFormat(configParam);
261
262 EXPECT_EQ(DH_SUCCESS, actual);
263 }
264
265 /**
266 * @tc.name: SetEncoderFormat_004
267 * @tc.desc: Verify the SetEncoderFormat function.
268 * @tc.type: FUNC
269 * @tc.require: Issue Number
270 */
271 HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_004, TestSize.Level1)
272 {
273 VideoParam configParam;
274 configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H265;
275 configParam.videoFormat_ = VIDEO_DATA_FORMAT_NV12;
276 int32_t actual = encoder->InitVideoEncoder(configParam);
277 actual = encoder->SetEncoderFormat(configParam);
278
279 EXPECT_EQ(DH_SUCCESS, actual);
280 }
281
282 /**
283 * @tc.name: SetEncoderFormat_005
284 * @tc.desc: Verify the SetEncoderFormat function.
285 * @tc.type: FUNC
286 * @tc.require: Issue Number
287 */
288 HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_005, TestSize.Level1)
289 {
290 VideoParam configParam;
291 configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_MPEG4;
292 configParam.videoFormat_ = VIDEO_DATA_FORMAT_NV21;
293 int32_t actual = encoder->InitVideoEncoder(configParam);
294 actual = encoder->SetEncoderFormat(configParam);
295
296 EXPECT_EQ(DH_SUCCESS, actual);
297 }
298
299 /**
300 * @tc.name: SetEncoderFormat_006
301 * @tc.desc: Verify the SetEncoderFormat function.
302 * @tc.type: FUNC
303 * @tc.require: Issue Number
304 */
305 HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_006, TestSize.Level1)
306 {
307 VideoParam configParam;
308 configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_MPEG4;
309 configParam.videoFormat_ = VIDEO_DATA_FORMAT_RGBA8888;
310 int32_t actual = encoder->InitVideoEncoder(configParam);
311 actual = encoder->SetEncoderFormat(configParam);
312
313 EXPECT_EQ(DH_SUCCESS, actual);
314 }
315
316 /**
317 * @tc.name: SetEncoderFormat_007
318 * @tc.desc: Verify the SetEncoderFormat function.
319 * @tc.type: FUNC
320 * @tc.require: Issue Number
321 */
322 HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_007, TestSize.Level1)
323 {
324 VideoParam configParam;
325 configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_MPEG4;
326 configParam.videoFormat_ = -1;
327 int32_t actual = encoder->InitVideoEncoder(configParam);
328 actual = encoder->SetEncoderFormat(configParam);
329 EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM, actual);
330 }
331
332 } // DistributedHardware
333 } // OHOS